fncue

package
v0.0.362 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

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

View Source
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 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.

func (CuePackage) RelFiles

func (pkg CuePackage) RelFiles() []string

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) Exists

func (v *CueV) Exists() bool

func (*CueV) FillPath

func (v *CueV) FillPath(path cue.Path, rightSide interface{}) *CueV

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 Location

type Location interface {
	Abs(...string) string
}

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 Root

type Root interface {
	Abs() string
}

type WorkspaceLoader

type WorkspaceLoader interface {
	SnapshotDir(context.Context, schema.PackageName, memfs.SnapshotOpts) (*PackageContents, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL