Documentation
¶
Overview ¶
Package vuka is the runtime of Vuka programs: Result and Option.
Vuka code writes Result[User], Ok(u), Err(e), Some(x) and None unqualified; the transpiler points them here. Go code uses the package like any other.
Index ¶
- Variables
- func Arg[T any](c *Call, i int) T
- func As[T any](v any) T
- func AttrOf[T any](c *Call) (T, bool)
- func DeclareWith(b Bundle, d *Decl)
- func DecorateType(b Bundle, t *Type)
- func FieldAttrs[T any]() map[string][]any
- func FieldAttrsOf(t reflect.Type) map[string][]any
- func Instance[F any](s *Instances, build func() F) F
- func ObserveCalls(fn CallObserver) (stop func())
- func RegisterFields[T any](attrs map[string][]any)
- func RegisterFunc(fn any, attrs ...any)
- func RegisterType[T any](attrs ...any)
- func SortBy[T any](xs []T, orders ...Order[T])
- type Attrs
- type Bundle
- type Call
- type CallObserver
- type CompareRef
- type Decl
- type Decorated
- type Decorator
- type Field
- type FieldPath
- func (p FieldPath) Attr(ptr any) bool
- func (p FieldPath) Attrs() []any
- func (p FieldPath) Fields() []reflect.StructField
- func (p FieldPath) Index() [][]int
- func (p FieldPath) Names() []string
- func (p FieldPath) Root() reflect.Type
- func (p FieldPath) String() string
- func (p FieldPath) Value(root any) (any, bool)
- type File
- type Func
- type FuncRef
- type Instances
- type NoAdvice
- type NullableRef
- type Op
- type Option
- type Order
- type OrderedRef
- type Param
- type Pred
- type Ref
- func (r Ref[T, V]) Asc() Order[T]
- func (r Ref[T, V]) Attr(ptr any) bool
- func (r Ref[T, V]) Attrs() []any
- func (r Ref[T, V]) Desc() Order[T]
- func (r Ref[T, V]) Eq(v V) Pred[T]
- func (r Ref[T, V]) FieldPath() FieldPath
- func (r Ref[T, V]) Get(t T) V
- func (r Ref[T, V]) In(vs ...V) Pred[T]
- func (r Ref[T, V]) Lookup(t T) (V, bool)
- func (r Ref[T, V]) Name() string
- func (r Ref[T, V]) Ne(v V) Pred[T]
- func (r Ref[T, V]) Path() []string
- type Related
- type Result
- type Static
- type Statics
- type StringRef
- type Targets
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrNotFunc = errors.New("vuka: not a function")
ErrNotFunc is FuncOf's error for a value that is no function, or nil.
Functions ¶
func As ¶ added in v0.2.0
As converts a value held in an any back to T; nil is T's zero value. It panics, naming both types, when a decorator put something else there.
func DeclareWith ¶ added in v0.10.0
DeclareWith runs a function's bundle's declarers with d. Generated code calls it.
func DecorateType ¶ added in v0.10.0
DecorateType runs a type's bundle's type decorators with t. Generated code calls it.
func FieldAttrs ¶ added in v0.7.0
FieldAttrs is the typed attributes of T's fields, by field name: for
type Post struct {
Title string @Char{Max: 200}
}
FieldAttrs[Post]()["Title"] is []any{Char{Max: 200}}. It is nil for a type whose fields carry none.
func FieldAttrsOf ¶ added in v0.7.0
FieldAttrsOf is FieldAttrs for a reflect.Type.
func Instance ¶
Instance returns the instantiation of a generic decorated function whose type is F, building it the first time.
func ObserveCalls ¶ added in v0.14.0
func ObserveCalls(fn CallObserver) (stop func())
ObserveCalls has fn see the steps of every decorated call of the program: the hook of a tracer, or of a web framework's development toolbar timing each decorator. It returns what stops it.
func RegisterFields ¶ added in v0.7.0
RegisterFields records the typed attributes written on T's fields, by field name. Generated code calls it at init, for every struct with field attributes.
func RegisterFunc ¶ added in v0.16.0
RegisterFunc records the typed attributes of a function, or of a method given as its method expression ((*Board).Clear). Generated code calls it at init; Go code may too, for a declaration it writes by hand.
func RegisterType ¶ added in v0.16.0
RegisterType records the typed attributes of type T. Generated code calls it at init.
Types ¶
type Attrs ¶ added in v0.16.0
type Attrs []any
Attrs are a declaration's typed attributes, as the lookups return them.
func MethodAttrs ¶ added in v0.16.0
MethodAttrs are the typed attributes declared on method name of t (or of the type t points to), its bundles' included; not its type's, which TypeAttrs has. None for a method Vuka registered nothing for.
type Bundle ¶ added in v0.10.0
type Bundle struct {
// contains filtered or unexported fields
}
Bundle is a composed decorator: decorators and attributes applied as one, as Spring's @RestController stands for @Controller and @ResponseBody.
decorator ApiRoute(path string) = @web.Get(path) @web.Use(auth) @timed
declares a function returning a Bundle; @ApiRoute("/pets") on a function applies each of them, in order, as if written there. Plain Go builds one with Compose.
func Compose ¶ added in v0.10.0
Compose bundles decorators and attributes: each item is a call decorator (func(*Call)), a declarer (func(*Decl)), a type decorator (func(*Type)), another Bundle (its items, in place), or an attribute (any other value).
func Dual ¶ added in v0.30.0
Dual is a decorator for a function and for a type alike: written on a function it runs decl, on a type typ. web.Get is one: a route on a handler, a page on a component type.
type Call ¶ added in v0.2.0
type Call struct {
Name string
Receiver any // the receiver, for a method
Args []any // the arguments; a variadic parameter is one slice
Results []any // the results, once Next has run (or Return was called)
// contains filtered or unexported fields
}
Call is one call of a decorated function, passed down its decorators.
func NewCall ¶ added in v0.2.0
NewCall starts a call through chain, ending in invoke. Generated code calls it.
func (*Call) Attr ¶ added in v0.2.0
Attr fills ptr with the declaration's typed attribute of ptr's element type, reporting whether there is one: var r Route; c.Attr(&r).
func (*Call) Attrs ¶ added in v0.16.0
Attrs are the declaration's typed attributes, its bundles' included: on a method, its own (a type's call decorators advising it see the method's, not the type's).
func (*Call) Context ¶ added in v0.2.0
Context is the call's context.Context argument, or context.Background().
func (*Call) Next ¶ added in v0.2.0
func (c *Call) Next()
Next runs the rest of the chain: the next decorator, or the function itself. It can be called more than once.
func (*Call) ParamAttr ¶ added in v0.10.0
ParamAttr fills ptr with parameter i's typed attribute of ptr's element type, reporting whether there is one. i indexes c.Args:
func Create(@Valid in NewPet) error
for i := range c.Args {
var v Valid
if c.ParamAttr(i, &v) { … }
}
func (*Call) Return ¶ added in v0.2.0
Return sets the results without running the function; the rest of the chain is skipped unless Next is called.
type CallObserver ¶ added in v0.14.0
CallObserver sees a decorated call go through its steps, on the goroutine of the call: each decorator (d), and the function itself (d nil). What it returns, when not nil, is called once the step returns.
type CompareRef ¶ added in v0.7.0
CompareRef is a reference to a field whose type orders itself, such as time.Time.
func CompareRefOf ¶ added in v0.7.0
func CompareRefOf[T any, V interface{ Compare(V) int }](index [][]int, _ func(*T)) CompareRef[T, V]
func (CompareRef[T, V]) Asc ¶ added in v0.7.0
func (r CompareRef[T, V]) Asc() Order[T]
func (CompareRef[T, V]) Desc ¶ added in v0.7.0
func (r CompareRef[T, V]) Desc() Order[T]
func (CompareRef[T, V]) Ge ¶ added in v0.7.0
func (r CompareRef[T, V]) Ge(v V) Pred[T]
Ge is the predicate field >= v, by V's Compare.
func (CompareRef[T, V]) Gt ¶ added in v0.7.0
func (r CompareRef[T, V]) Gt(v V) Pred[T]
Gt is the predicate field > v, by V's Compare.
func (CompareRef[T, V]) Le ¶ added in v0.7.0
func (r CompareRef[T, V]) Le(v V) Pred[T]
Le is the predicate field <= v, by V's Compare.
func (CompareRef[T, V]) Lt ¶ added in v0.7.0
func (r CompareRef[T, V]) Lt(v V) Pred[T]
Lt is the predicate field < v, by V's Compare.
type Decl ¶ added in v0.6.0
type Decl struct {
Name string // "main.ShowPet", "PetAdmin.Index"
Pkg string // the package's import path
File string // the source file's base name, and the line of the name, for messages
Line int
Attrs []any // the declaration's typed attributes
// Func is the function, wrapped by the declaration's other decorators, so
// calling it runs them too. For a method it is the method expression:
// func(recv, args…).
Func any
Recv reflect.Type // the receiver type, for a method
Params []Param // the parameters, receiver excluded
Results []reflect.Type
Variadic bool
}
Decl describes a declaration for a declarer: a decorator of type func(d *vuka.Decl), which runs once at program start rather than around each call. Declarers register things — routes, commands, jobs — from the declarations they decorate:
func Get(path string) func(*vuka.Decl) {
return func(d *vuka.Decl) { routes[path] = d.Func }
}
func FuncDecl ¶ added in v0.6.0
FuncDecl describes a function for its declarers, given its parameters' names, or with d.Params holding each parameter's name and attributes. Generated code calls it.
func MethodDecl ¶ added in v0.6.0
MethodDecl describes a method, d.Func being its method expression. Generated code calls it.
type Decorated ¶
type Decorated[F any] struct { // contains filtered or unexported fields }
Decorated holds a decorated function, built from its decorators on first use. Vuka generates one per decorated function or method.
type Decorator ¶ added in v0.2.0
type Decorator func(c *Call)
Decorator wraps a call of any function: it runs code around c.Next(), may change c.Args before it, read or replace c.Results after it, call it again (retries) or not at all (caches). Written once, it decorates any function or method:
func logged(c *vuka.Call) {
fmt.Println("calling", c.Name, c.Args)
c.Next()
}
A decorator with parameters is a function returning one; it runs once per decorated function, so state it keeps isn't shared between functions.
type Field ¶ added in v0.3.0
type Field struct {
Name string
Type reflect.Type
Tag reflect.StructTag
Attrs []any // the field's typed attributes
Injected bool // a parameter of New: not blank, not tagged inject:"-"
}
Field is a field of a struct.
type FieldPath ¶ added in v0.7.0
type FieldPath struct {
// contains filtered or unexported fields
}
FieldPath is where a field reference leads from its root struct: one step per field written (Post.Author.Name has two), each step an index path that passes through embedded structs. Between steps it goes through a pointer or a Related value.
func (FieldPath) Attr ¶ added in v0.7.0
Attr fills ptr with the last field's typed attribute of ptr's element type.
func (FieldPath) Fields ¶ added in v0.7.0
func (p FieldPath) Fields() []reflect.StructField
Fields are the struct fields of each step.
type File ¶ added in v0.6.0
type File string
File names a file of the program's source tree. A string literal written where a decorator or typed attribute takes a File is checked when the program is compiled (it must exist, in the package's directory or below) and embedded into the binary; the File then holds "importpath:relative/path" and Bytes returns the embedded content:
func Template(view vuka.File) func(*vuka.Decl) { … view.Bytes() … }
@Template("views/pet.html")
func showPet(id int) Pet { … }
A .templ file may be in a subdirectory that is a package of its own (views/pets.templ with `package views`): its File is then that package's ("module/views:pets.templ"). With templ and github.com/vuka-lang/ui, the file's components are registered too: templx.Components(f).
func (File) Bytes ¶ added in v0.6.0
Bytes is the file's content: embedded, or for a File Vuka didn't embed (a conversion such as vuka.File("x.txt")) read from disk.
type Func ¶ added in v0.2.0
type Func struct {
Name string // "main.charge", "Store.Save"
Attrs []any // the declaration's typed attributes
// ParamAttrs are each parameter's typed attributes, receiver excluded:
// func Show(@Path("id") id int) has [][]any{{Path("id")}}. Nil when no
// parameter has any.
ParamAttrs [][]any
ErrIndex int // the trailing error result's index, or -1
CtxIndex int // the context.Context argument's index, or -1
Zero func() []any
}
Func describes a decorated function. Vuka generates one per function.
type FuncRef ¶ added in v0.16.0
type FuncRef struct {
Name string // the runtime's name for the code: "example.com/app.(*Board).Clear-fm"
// Recv is a method's receiver type as declared (Board for *Board) when
// Vuka registered the type or one of its methods; Method is the
// method's name.
Recv reflect.Type
Method string
// Attrs are the declaration's typed attributes: a method's own (its
// type's are TypeAttrs(Recv)).
Attrs Attrs
// Literal says fn is a function literal ("…(*Board).Render.func1"): it
// is no declaration and has no attributes, and what it calls is found
// only when it runs.
Literal bool
}
FuncRef is the declaration a function value's code belongs to, as FuncOf finds it.
func FuncOf ¶ added in v0.16.0
FuncOf finds the declaration fn's code belongs to: a function, a method expression ((*Board).Clear) or a method value (b.Clear). A function literal is reported as one (Literal); a function or method nothing registered has no Attrs. A method value made by reflection (reflect.Value.Method) names no declaration either: look it up with MethodAttrs. Answers are cached per function, so a lookup costs a map read after the first.
type Instances ¶
type Instances struct {
// contains filtered or unexported fields
}
Instances holds a generic decorated function's instantiations, each built from its decorators on first use.
type NoAdvice ¶ added in v0.10.0
type NoAdvice struct{}
NoAdvice, on a method, leaves it out of its type's advice: the call decorators written on the type, which wrap its other exported methods.
@logged
type Store struct{ … }
@vuka.NoAdvice
func (s *Store) Dump() string { … }
type NullableRef ¶ added in v0.7.0
NullableRef is a reference to a field that can be nil or None.
func NullableRefOf ¶ added in v0.7.0
func NullableRefOf[T, V any](index [][]int, _ func(*T)) NullableRef[T, V]
func (NullableRef[T, V]) IsNil ¶ added in v0.7.0
func (r NullableRef[T, V]) IsNil() Pred[T]
IsNil is the predicate that the field is nil or None (or that a nil pointer or relation is on the way).
func (NullableRef[T, V]) NotNil ¶ added in v0.7.0
func (r NullableRef[T, V]) NotNil() Pred[T]
NotNil is the predicate that the field is neither nil nor None.
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option is a value that may be absent. The zero Option is None.
func None ¶
None is an absent value. Vuka code writes plain None; the transpiler fills in T from where the value goes.
func (Option[T]) Unwrap ¶
func (o Option[T]) Unwrap() T
Unwrap is the value; it panics when o is None.
type Order ¶ added in v0.7.0
Order is an ordering of Ts by a field: Post.Views.Desc().
type OrderedRef ¶ added in v0.7.0
OrderedRef is a reference to a number field (or any cmp.Ordered type).
func OrderedRefOf ¶ added in v0.7.0
func OrderedRefOf[T any, V cmp.Ordered](index [][]int, _ func(*T)) OrderedRef[T, V]
func (OrderedRef[T, V]) Asc ¶ added in v0.7.0
func (r OrderedRef[T, V]) Asc() Order[T]
func (OrderedRef[T, V]) Desc ¶ added in v0.7.0
func (r OrderedRef[T, V]) Desc() Order[T]
func (OrderedRef[T, V]) Ge ¶ added in v0.7.0
func (r OrderedRef[T, V]) Ge(v V) Pred[T]
Ge is the predicate field >= v.
func (OrderedRef[T, V]) Gt ¶ added in v0.7.0
func (r OrderedRef[T, V]) Gt(v V) Pred[T]
Gt is the predicate field > v.
func (OrderedRef[T, V]) Le ¶ added in v0.7.0
func (r OrderedRef[T, V]) Le(v V) Pred[T]
Le is the predicate field <= v.
func (OrderedRef[T, V]) Lt ¶ added in v0.7.0
func (r OrderedRef[T, V]) Lt(v V) Pred[T]
Lt is the predicate field < v.
type Param ¶ added in v0.6.0
Param is a parameter of a declared function: its name as written ("" when unnamed), type, and the typed attributes written before it:
func Show(@Path("pet_id") id int)
type Pred ¶ added in v0.7.0
type Pred[T any] struct { Op Op Path FieldPath // the field tested; zero for and, or and not Value any // the operand: a V, a []V for in; nil for isnil, notnil and the combinations Preds []Pred[T] // the operands of and, or and not // contains filtered or unexported fields }
Pred is a condition on a T, built from field references — Post.Views.Gt(100), vuka.Or(…) — and kept as data, so a query builder can translate it (Op, the field's Path and attributes, the Value) or Match can test it in memory. Being typed by T, a Pred[User] can't be passed where a Pred[Post] is wanted.
type Ref ¶ added in v0.7.0
type Ref[T, V any] struct { // contains filtered or unexported fields }
Ref is a field reference: Post.Title in Vuka source, a typed handle on the Title field of Post, of type V. Through pointer, struct and Related fields it reaches further: Post.Author.Name. Its methods build predicates and orderings over T, or read the field.
Vuka picks the most capable kind for the field's type: StringRef for strings, OrderedRef for numbers, CompareRef for types with a Compare method (time.Time), NullableRef for pointers, slices, maps, interfaces and Options, and Ref for the rest.
func RefOf ¶ added in v0.7.0
RefOf, OrderedRefOf, StringRefOf, CompareRefOf and NullableRefOf make references; Vuka generates the calls. The function is never called: it is there so the compiler and the editor see the fields the reference names.
func (Ref[T, V]) Attr ¶ added in v0.7.0
Attr fills ptr with the field's typed attribute of ptr's element type.
func (Ref[T, V]) Get ¶ added in v0.7.0
func (r Ref[T, V]) Get(t T) V
Get is the field's value in t, or V's zero value when a nil pointer or relation is on the way.
func (Ref[T, V]) Lookup ¶ added in v0.7.0
Lookup is the field's value in t; false when a nil pointer or relation is on the way.
type Related ¶ added in v0.7.0
type Related[T any] interface{ Related() *T }
Related is implemented by a field type that refers to a T held elsewhere, such as a foreign key. A field reference continues through it into T's fields: with Author of a type implementing Related[User], Post.Author.Name is a Ref[Post, string]. Related returns nil when there is no T.
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result is a value or an error. It is Ok when it holds no error; the zero Result is Ok with T's zero value.
func (Result[T]) Unwrap ¶
func (r Result[T]) Unwrap() T
Unwrap is the value; it panics when r failed.
type Static ¶ added in v0.2.0
type Static[V any] struct { V V }
Static is the storage of a static field of a generic type: one per instantiation, so Model[User] and Model[Order] each have their own.
type Statics ¶ added in v0.2.0
type Statics struct {
// contains filtered or unexported fields
}
Statics holds one generic static field's instantiations.
type StringRef ¶ added in v0.7.0
type StringRef[T any, V ~string] struct{ OrderedRef[T, V] }
StringRef is a reference to a string field.
func StringRefOf ¶ added in v0.7.0
func (StringRef[T, V]) Contains ¶ added in v0.7.0
Contains is the predicate that the field contains s.
func (StringRef[T, V]) EndsWith ¶ added in v0.7.0
EndsWith is the predicate that the field ends with s.
func (StringRef[T, V]) StartsWith ¶ added in v0.7.0
StartsWith is the predicate that the field starts with s.
type Targets ¶ added in v0.10.0
type Targets uint16
Targets restricts where an attribute type may be written, as Java's @Target does. Written on the type, it makes any other use a compile error at the attribute:
@vuka.Targets(vuka.OnField)
type Char struct{ Max int }
Go code declares the same with a method whose result's length is the targets: func (Char) vukaTargets() [vuka.OnField]struct{} { return {} }.
type Type ¶ added in v0.2.0
type Type struct {
Name string // "main.User"
Reflect reflect.Type
Attrs []any // the declaration's typed attributes
New any // the constructor, for a struct; nil otherwise
Fields []Field // the struct's fields
}
Type describes a decorated type, for a type decorator:
func Model(t *vuka.Type) { registry[t.Name] = t.Reflect }
For a struct, New is a constructor taking each dependency field as a parameter (or the type's own static New, when it declares one), which is the shape dependency-injection containers take:
func Component(t *vuka.Type) { providers = append(providers, t.New) }
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vuka
module
|
|
|
vukavet
module
|
|
|
Package diag is the shape of every diagnostic the vuka toolchain reports: the transpiler, vuka vet, the editor and the libraries' boot-time checks.
|
Package diag is the shape of every diagnostic the vuka toolchain reports: the transpiler, vuka vet, the editor and the libraries' boot-time checks. |
|
Package docs holds the diagnostic catalogue: docs/errors/<code>.md, one page per code, rendered by the docs site and printed by `vuka explain`.
|
Package docs holds the diagnostic catalogue: docs/errors/<code>.md, one page per code, rendered by the docs site and printed by `vuka explain`. |
|
internal
|
|
|
format
Package format formats Vuka source: the Go in it exactly as gofmt does, and its JSX the way Prettier lays out markup, without changing what it renders.
|
Package format formats Vuka source: the Go in it exactly as gofmt does, and its JSX the way Prettier lays out markup, without changing what it renders. |
|
load
Package load finds Vuka packages in a module and supplies what transpiling them needs from the go command: build-context file selection, export data for imports, and the overlay that puts generated files in front of the compiler.
|
Package load finds Vuka packages in a module and supplies what transpiling them needs from the go command: build-context file selection, export data for imports, and the overlay that puts generated files in front of the compiler. |
|
tsprops
Package tsprops reads the props a client component declares — a Vue SFC's defineProps/defineModel/defineEmits, a React component's props parameter, a Svelte component's $props(), a vanilla island's mount(el, props, ctx) — from its source, without Node: a small reader of the TypeScript types people write for props.
|
Package tsprops reads the props a client component declares — a Vue SFC's defineProps/defineModel/defineEmits, a React component's props parameter, a Svelte component's $props(), a vanilla island's mount(el, props, ctx) — from its source, without Node: a small reader of the TypeScript types people write for props. |
|
Package transpile turns Vuka source into Go.
|
Package transpile turns Vuka source into Go. |
