Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callable ¶
type Callable struct {
Resource // embeds mem.Resource (source text in Data)
// Compiled bytecode — Program.Write output. Nil until Compile.
Compiled []byte
// URI identity fields — compose the opaque URI:
// mem:callable/<FuncType>/<Name>
FuncType string // named Go type: "file.Reducer", "Predicate"
Name string // function name or <action>.<param> for lambdas
// Metadata captured at extraction time.
FuncName string // function name in synthetic file ("_callable" or original)
ParamNames []string // parameter names (excluding swallowed)
NumParams int // total params (for validation)
CompilerVersion uint32 // starlark.CompilerVersion at compile time
OriginalPos string // "recipe.star:42" (diagnostics only)
// contains filtered or unexported fields
}
Callable is a mem.Resource that holds a Starlark function extracted into a self-contained synthetic source file with compiled bytecode.
The URI is opaque: mem:callable/<FuncType>/<Name>. FuncType is the named Go type the callable satisfies (e.g., "file.Reducer", "Predicate"). Name is the function name or <action>.<param> for lambdas.
The Data field (inherited from Resource) holds the synthetic source text. The Compiled field holds serialized bytecode from Program.Write. Both are []byte — serializable, transferable, persistable.
Lifecycle:
- Extract(*starlark.Function) → Callable (Phase 2)
- Compile() → populates Compiled bytecode (Phase 3)
- Init(thread) → loads bytecode, extracts live fn (Phase 3)
- Fn() → returns live callable for adapter invocation
func NewCallable ¶
NewCallable creates a Callable with the given function type and name. The source text (Data) and compiled bytecode should be set by the extraction and compilation phases.
type Resource ¶
type Resource struct {
op.ResourceBase
ContentType string // "callable", "json", "template", etc.
Qualifier string // type-specific qualifier (e.g., "file.Reducer/myfn" for callables)
Data []byte // raw content
Hash string // SHA-256 of Data — metadata, NOT part of URI
}
Resource represents an in-memory data resource identified by a mem: URI.
Unlike file or git resources that reference external systems, a mem.Resource holds its content directly. The Data field contains the raw bytes (source text, JSON, template content, etc.). The ContentType field classifies the content for dispatch (e.g., "callable", "json", "template").
The URI is opaque: mem:<content-type>/<qualifier>. The content hash is stored as a metadata field for change detection — NOT part of the URI. Two resources with the same URI but different hashes trigger a catalog shadow.
func NewResource ¶
NewResource creates a mem.Resource with the given content type and qualifier. Data must be set separately; Hash is computed when ComputeHash is called.
func NewResourceWithData ¶
NewResourceWithData creates a mem.Resource with content and computes the hash.
func (*Resource) ComputeHash ¶
func (r *Resource) ComputeHash()
ComputeHash calculates the SHA-256 hash of Data and stores it in Hash.