Documentation
¶
Overview ¶
Implements loading of Namespace-specific dialect of Cue which includes: * a Golang-like module system where modules are loaded from source transparently when needed; * support for @fn() attributes allowing to access runtime data from the environment.
Index ¶
- Constants
- func CollectImports(ctx context.Context, resolver WorkspaceLoader, pkgname string, ...) error
- func DecodeToTypedProtoMessage[V proto.Message](v *CueV) (V, error)
- func Format(ctx context.Context, fsfs fnfs.ReadWriteFS, loc fnfs.Location, name string, ...) error
- func FormatSource(loc fnerrors.Location, w io.Writer, contents []byte) error
- func IsStandardImportPath(path string) bool
- func SerializedEval[V any](p *Partial, f func() (V, error)) (V, error)
- func SerializedEval3[V any, T any](p *Partial, f func() (V, T, error)) (V, T, error)
- func WalkAttrs(parent cue.Value, visit func(v cue.Value, key, value string) error) error
- func WrapCueError(e error, absPath func(string) string) error
- type CuePackage
- type CueV
- type EvalCtx
- type KeyAndPath
- type Location
- type PackageContents
- type Partial
- type Root
- type WorkspaceLoader
Constants ¶
const (
InputKeyword = "input"
AllocKeyword = "alloc"
PackageIKW = "package"
ServerDepIKw = "server_dep"
ImageIKw = "image"
VCSIKw = "vcs"
WorkspaceIKw = "workspace"
ProtoloadIKw = "protoload"
ServerPortAllocKw = "port"
ResourceIKw = "resource"
)
Variables ¶
This section is empty.
Functions ¶
func CollectImports ¶
func CollectImports(ctx context.Context, resolver WorkspaceLoader, pkgname string, m map[string]*CuePackage) error
Fills [m] with the transitive closure of packages and files imported by package [pkgname]. TODO: Use [snapshotCache] instead of re-parsing all packages directly.
func DecodeToTypedProtoMessage ¶ added in v0.0.72
func DecodeToTypedProtoMessage[V proto.Message](v *CueV) (V, error)
func Format ¶
func Format(ctx context.Context, fsfs fnfs.ReadWriteFS, loc fnfs.Location, name string, opts fnfs.WriteFileExtendedOpts) error
func FormatSource ¶
func FormatSource(loc fnerrors.Location, w io.Writer, contents []byte) error
func IsStandardImportPath ¶
func IsStandardImportPath(path string) bool
func SerializedEval ¶
func SerializedEval[V any](p *Partial, f func() (V, error)) (V, error)
func SerializedEval3 ¶
func SerializedEval3[V any, T any](p *Partial, f func() (V, T, error)) (V, T, error)
func WalkAttrs ¶
func WalkAttrs(parent cue.Value, visit func(v cue.Value, key, value string) error) error
func WrapCueError ¶
func WrapCueError(e error, absPath func(string) string) error
Wraps a Cue error to include error location information in the error message. Also supports Cue list-errors which are translated into multierr.Error.
Types ¶
type CuePackage ¶
type CuePackage struct {
*PackageContents
Files []string // Relative to RelPath
Imports []string // Top level import statements.
}
Represents an unparsed Cue package.
type CueV ¶
type CueV struct{ Val cue.Value }
func (*CueV) DecodeAs ¶
func (v *CueV) DecodeAs(msgtype protoreflect.MessageType) (proto.Message, error)
func (*CueV) DecodeToProtoMessage ¶
func (v *CueV) DecodeToProtoMessage(msg proto.Message) error
func (*CueV) LookupPath ¶
func (v *CueV) LookupPath(path string) *CueV
type EvalCtx ¶
type EvalCtx struct {
// contains filtered or unexported fields
}
Entry point to load Cue packages from a Namespace workspace.
func NewEvalCtx ¶
func NewEvalCtx(loader WorkspaceLoader, scope any) *EvalCtx
If set, "scope" are passed as a "Scope" BuildOption to "BuildInstance".
func (*EvalCtx) EvalPackage ¶
func (ev *EvalCtx) EvalPackage(ctx context.Context, pkgname string) (*Partial, error)
type KeyAndPath ¶
type KeyAndPath struct {
Key string
Target cue.Path
}
type PackageContents ¶
type PackageContents struct {
ModuleName string
// Snapshot rooted at the module [ModuleName] root.
Snapshot fs.FS
// Path within the module (within [FS]).
RelPath string
// Absolute path.
AbsPath string
}
type Partial ¶
type Partial struct {
CueV
Ctx *snapshotCache
Left []KeyAndPath
Package CuePackage
CueImports []CuePackage
}
Represents a Cue value alongside a list of keys that are *left* to be resolved and filled later.
func EvalWorkspace ¶
func EvalWorkspace(ctx context.Context, fsys fs.FS, dir string, files []string) (*Partial, error)
type WorkspaceLoader ¶
type WorkspaceLoader interface {
SnapshotDir(context.Context, schema.PackageName, memfs.SnapshotOpts) (*PackageContents, error)
}