Documentation
¶
Overview ¶
Package api defines implementation-independent contracts for compiling, executing, and debugging Ferret queries.
Runtime.Run and Session.Run return caller-owned, one-shot Output handles. A successful Run obtains a usable handle; Consume or Collect observes terminal execution, delivery, and cleanup errors. Close abandons unread output. Invocation contexts remain in effect until output is settled. Output.Metadata is immutable and local; Content is detached materialized data, also used by debugger events. See result.Output for consumption, presence, cancellation, and closure contracts.
Plan.Params and Runtime.Version retrieve metadata and may involve remote I/O. Both require non-nil caller contexts, and cancellation errors must preserve context.Canceled and context.DeadlineExceeded through errors.Is. The API imposes no transport-specific behavior or caching requirements.
Plan.Params returns a caller-owned snapshot; an empty parameter list is distinct from a metadata retrieval error. Runtime.Version returns an opaque Version for the represented runtime implementation, including the remote runtime for a remote adapter, rather than the host application, CLI, server, or transport.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOutputInUse is result.ErrInUse. Use errors.Is to identify a consumption // attempt rejected because another consumer owns the output. ErrOutputInUse = result.ErrInUse // ErrOutputClosed is result.ErrClosed. Use errors.Is to identify consumption // rejected after stopping begins, or interrupted by an explicit Close that // wins before outcome commitment. Close itself returns its cleanup outcome. ErrOutputClosed = result.ErrClosed )
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
Consumer receives borrowed, read-only chunks during Output.Consume. Copy retained bytes; see result.Consumer for callback and context requirements.
type Content ¶
Content is detached, caller-owned encoded data returned by Output.Collect or retained debugger events. A nil *Content means no content is available; a non-nil pointer, including &Content{}, means present content. See result.Content.
type Location ¶
Location represents the location of a specific point in a source file, including the file name and position.
type Metadata ¶
Metadata describes the complete encoded payload independently of content presence. See result.Metadata for length and immutability requirements.
type OptimizationLevel ¶
type OptimizationLevel int
const ( OptimizationNone OptimizationLevel = iota OptimizationBasic OptimizationFull OptimizationAggressive )
type Output ¶
Output is the caller-owned, one-shot consumable handle returned by execution. Consume or Collect observes completion and finalizes resources; Close abandons unread output. See result.Output for lifetime, presence, and error requirements.
type Plan ¶
type Plan interface {
io.Closer
// Params returns a caller-owned snapshot of the plan's parameter names.
// An empty list with a nil error means the plan has no parameters; failure
// to retrieve metadata returns an error.
//
// ctx must be non-nil. Cancellation errors must preserve context.Canceled
// and context.DeadlineExceeded through errors.Is. Retrieval may involve
// remote I/O; local implementations may return immediately. UAPI imposes
// no transport-specific behavior or caching requirements.
Params(ctx context.Context) ([]string, error)
NewSession(ctx context.Context, opts ...SessionOption) (Session, error)
NewDebugSession(ctx context.Context, opts ...SessionOption) (debugger.Session, error)
}
Plan represents a compiled program. Compilation finishes before a plan is returned. Plans support independent sessions and are not consumed by execution.
Close releases plan-owned resources and prevents subsequent session and debug-session creation. It is idempotent and retains its cleanup result, without requiring identical error-wrapper pointers. Close need not wait for constructors already started. It does not implicitly close or cancel returned sessions or debug sessions; callers remain responsible for their lifecycle.
Params, NewSession, and NewDebugSession use non-nil caller contexts for cancellation. Close does not cancel those contexts. Callers coordinate work and cleanup when sessions use plan-owned resources.
type PlanOption ¶
type PlanOption = func(PlanOptions) error
func WithOptimizationLevel ¶
func WithOptimizationLevel(level OptimizationLevel) PlanOption
WithOptimizationLevel sets the optimization level for the execution plan. The callback rejects unknown enum values before invoking the target setter; the runtime determines which known levels it supports.
type PlanOptions ¶
type PlanOptions interface {
SetOptimizationLevel(OptimizationLevel) error
}
type Position ¶
Position represents a specific point in a source file, defined by line and column numbers.
type Range ¶
Range represents a range of characters in a source file, including the location and span.
type Runtime ¶
type Runtime interface {
io.Closer
// Version reports the version of the runtime implementation represented by
// this Runtime. A remote adapter reports its remote runtime's version, not
// the version of the host application, CLI, daemon/server, or transport protocol.
//
// ctx must be non-nil. Cancellation errors must preserve context.Canceled
// and context.DeadlineExceeded through errors.Is. Retrieval may involve
// remote I/O; local implementations may return immediately. UAPI imposes
// no transport-specific behavior or caching requirements.
Version(ctx context.Context) (Version, error)
// Run starts execution and returns a usable, caller-owned Output with nil
// error. Success means a handle was obtained, not that execution or delivery
// completed. Execution is not deferred until consumption. Metadata is reliable
// before return without buffering solely to determine length.
//
// Admission or preparation failures return nil output and an error, preserving
// cleanup failures for resources already acquired. Never return a usable handle
// alongside a Run error or use a typed-nil implementation as an absent handle.
// Once a handle is returned, terminal execution, encoding, delivery, and
// output-owned cleanup errors are reported by Consume or Collect, preserving
// available content. Even absent content is observed through a usable handle.
//
// ctx must be non-nil and bounds the output's lifetime after return. Callers
// must not cancel it before settling the output. Consume or Collect finalizes
// resources; Close abandons unread output without certifying completion.
// Side-effect-only callers must consume to observe completion. See Output.
Run(ctx context.Context, src Source, opts ...SessionOption) (Output, error)
Compile(ctx context.Context, src Source, opts ...PlanOption) (Plan, error)
CompileDebug(ctx context.Context, src Source, opts ...PlanOption) (Plan, error)
}
Runtime compiles source into reusable plans. Callers own directly created plans and sessions and are responsible for their cleanup.
Close releases implementation-owned resources and is idempotent, retaining its cleanup result without requiring identical error-wrapper pointers. Owning runtimes reject subsequent work according to their closed-state semantics. Borrowing adapters may document a no-op Close that leaves the adapter and underlying runtime usable. Close does not implicitly cancel caller-owned work and need not wait for operations already started.
Run, Compile, CompileDebug, and Version use non-nil caller contexts for cancellation. Callers coordinate work and cleanup when descendants use parent-owned resources. Run owns its temporary session and plan; resources needed for consumption transfer to the returned Output, which finalizes them. Resources independent of consumption may be released earlier. Caller-owned descendants and borrowed parents retain their existing ownership.
type Session ¶
type Session interface {
io.Closer
// Run starts execution and returns a usable Output with nil error, rather than
// certifying execution or delivery success. Execution is not deferred until
// consumption. Metadata is reliable before return without buffering solely
// to determine length.
//
// Admission or preparation failures return nil output and an error, preserving
// cleanup failures for resources acquired by this invocation. Never return a
// usable handle alongside an error or represent absence using a typed nil.
// After a handle is returned, terminal execution, encoding, delivery, and
// output-owned cleanup errors belong to Consume or Collect, alongside any
// available content. An absent payload still has a usable output handle.
//
// ctx must be non-nil and bounds the output's lifetime after return. Keep it
// alive until the output is settled. Consume or Collect observes completion
// and finalizes output-owned resources without closing this session. Close on
// the output abandons it; side-effect-only callers must consume. See Output.
Run(ctx context.Context) (Output, error)
}
Session executes a compiled plan with per-session configuration. Run observes its non-nil context and returns a caller-owned consumable Output. Unless a stronger implementation contract explicitly allows otherwise, callers serialize Run and settle its output before reusing or closing the session. Output cleanup never closes this caller-owned session. Close is idempotent and retains its cleanup result, without requiring identical error-wrapper pointers.
type SessionOption ¶
type SessionOption = func(SessionOptions) error
SessionOption applies portable or application-specific session configuration. Implementations invoke non-nil callbacks once in order and join their returned errors. Callbacks may return errors immediately; runtime-specific validation may instead fail in the operation that uses the setting. See SessionOptions.
func WithFSRoot ¶
func WithFSRoot(root string) SessionOption
WithFSRoot selects the rooted filesystem used by one execution session. The runtime defines path validation and owns any filesystem resources created for the session. Validation and construction may occur when the root is applied.
func WithOutputContentType ¶
func WithOutputContentType(contentType string) SessionOption
WithOutputContentType selects the output codec content type for session results. Codec availability may be checked when output is encoded, after query execution. The selected representation is described by Output.Metadata().ContentType; encoding failures after a usable handle is returned belong to Consume or Collect.
func WithParam ¶
func WithParam(key string, value any) SessionOption
WithParam sets a session parameter for the execution. The runtime owns conversion and validation of the host value.
func WithParams ¶
func WithParams(params map[string]any) SessionOption
WithParams merges the provided parameter map into the session environment, overriding existing keys while preserving any other previously defined parameters. The runtime defines when values are converted or snapshotted.
type SessionOptions ¶
type SessionOptions interface {
SetParam(string, any) error
SetParams(map[string]any) error
// SetOutputContentType selects the encoded representation's media type,
// reported by Output.Metadata().ContentType. Codec availability may be
// validated during encoding and then reported through output consumption.
SetOutputContentType(string) error
SetFSRoot(string) error
}
SessionOptions configures a session directly or queues implementation options. Setters may report portable or application-level errors immediately and defer runtime-specific conversion and validation until the setting is used. A nil setter error does not certify that the runtime can use the value.
Invalid settings must fail the operation no later than their relevant point of use. Validation need not precede compilation, resource acquisition, or all query execution. Content codec availability may be checked during result encoding, after the query has run. Implementations document validation and mutable-input conversion or snapshot timing.
Later setters override earlier values; SetParams merges keys. Runtime-specific options reject incompatible targets.
type Source ¶
Source represents the input data for a Ferret query.
func NewAnonymousSource ¶
NewAnonymousSource creates a new anonymous Source instance with the given content.
type Span ¶
Span represents a range of characters in a source file, defined by start and end positions.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package debugger defines portable contracts and values for controlling and inspecting Ferret debug sessions, including events, breakpoints, frames, and values.
|
Package debugger defines portable contracts and values for controlling and inspecting Ferret debug sessions, including events, breakpoints, frames, and values. |
|
Package diagnostics defines the portable structured reporting model shared by Ferret runtimes and tooling.
|
Package diagnostics defines the portable structured reporting model shared by Ferret runtimes and tooling. |
|
Package result defines consumable encoded Output handles and detached Content.
|
Package result defines consumable encoded Output handles and detached Content. |
|
Package source defines portable Ferret source inputs and coordinates.
|
Package source defines portable Ferret source inputs and coordinates. |