Documentation
¶
Overview ¶
Package adapter defines the runtime adapter contract of the OpenFlange reference runner: how an implementation type (builtin, expression, script, executable, http, pipeline, or anything registered from outside this module) is validated before execution and how it runs one node against bounded streams.
External code extends the runner in two ways:
- RegisterBuiltin adds an in-process pipe under a `std:` or `builtin:<runtime>/<name>` reference, with its own manifest. This is how DataTug registers `builtin:datatug/...` pipes and sources.
- Register adds an Adapter for an implementation type/language (for example the HTTP Pipe Protocol client, or a new script language).
Index ¶
- type Adapter
- type BatchAdapter
- type Builtin
- type Capabilities
- type Capability
- type Diagnostic
- type Host
- type IO
- func (io *IO) BatchIn(n *Node) stream.Reader
- func (io *IO) Connected(port string) bool
- func (io *IO) Enabled(port string) bool
- func (io *IO) In(port string) stream.Reader
- func (io *IO) Ins(port string) []stream.Reader
- func (io *IO) Logf(level, format string, args ...any)
- func (io *IO) Out(port string) stream.Writer
- func (io *IO) ReportUsage(u map[string]any)
- func (io *IO) SetSpool(f func(slice int, items []stream.Item) (kept bool, err error))
- type Location
- type Node
- type Params
- type PermissionDeriver
- type PortInfo
- type Registry
- func (r *Registry) Builtin(name string) (*Builtin, bool)
- func (r *Registry) BuiltinNames(prefix string) []string
- func (r *Registry) Capabilities() Capabilities
- func (r *Registry) HasFeature(name string) bool
- func (r *Registry) Lookup(impl *manifest.Implementation) (Adapter, error)
- func (r *Registry) Register(a Adapter)
- func (r *Registry) RegisterBuiltin(b *Builtin) error
- func (r *Registry) SetFeature(name string, supported bool)
- func (r *Registry) SetReference(scheme string, supported bool)
- type ScalarAdapter
- type ScalarFunc
- type SpoolSlot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
// Name identifies the adapter in plans and capability listings, e.g.
// "starlark", "exec", "builtin".
Name() string
// Supports reports whether this adapter handles the implementation.
Supports(impl *manifest.Implementation) bool
// Location reports where nodes of this implementation execute.
Location(impl *manifest.Implementation) Location
// Capabilities lists what the adapter can run on this machine.
Capabilities() []Capability
// Check validates a node before any execution starts: capability checks
// (does the interpreter exist?), script compilation, parameter sanity. It
// may store reusable state in n.Prepared. Errors should be *errs.Error.
Check(ctx context.Context, n *Node) error
// Run executes the node until its inputs are exhausted, ctx is cancelled
// or it fails. It must not close outputs (the runner does) and must return
// promptly when ctx is done. Returning stream.ErrClosed means "every
// consumer went away" and is treated as normal completion.
Run(ctx context.Context, n *Node, io *IO) error
}
Adapter runs nodes of one implementation family.
type BatchAdapter ¶
type BatchAdapter interface {
SupportsBatch(impl *manifest.Implementation) bool
}
BatchAdapter is an optional interface of adapters that can run pipes in batch mode (pipe/v0.1 section 5.7). The planner refuses a pipe that declares `batch` with E_UNSUPPORTED when its adapter does not implement the interface or reports false: a batch-mode pipe is never run unbatched.
Batch mode exists for implementations outside the runner: subprocesses (adapter/exec) and scripts (adapter/starlark). Builtins cannot declare it — a Go implementation already reads stream.Batch values and controls its own reads; one that wants size-or-wait grouping calls stream.NewSlicer itself.
The runner does the slicing: an adapter that reports true reads io.BatchIn(n) (or simply io.In of the single input), must hand every batch it reads to the implementation as one slice, and enforces `cardinality: one-to-one` per slice.
type Builtin ¶
type Builtin struct {
// Name is the full reference without version, e.g. "std:filter" or
// "builtin:datatug/query".
Name string
// Manifest is the pipe's contract. Its implementation must be
// {type: builtin, name: Name}.
Manifest *manifest.Manifest
// Check optionally validates a node before execution.
Check func(ctx context.Context, n *Node) error
// Run executes the node (same contract as Adapter.Run).
Run func(ctx context.Context, n *Node, io *IO) error
// Permissions optionally derives required permissions from the resolved
// parameters (e.g. std:file-source needs filesystem.read covering `path`).
// baseDir is the directory relative parameter paths resolve against. The
// planner enforces the result exactly like declared permissions.
Permissions func(params Params, baseDir string) manifest.Permissions
// this build; planning a node that uses it fails with E_UNSUPPORTED.
Unavailable string
}
Builtin is an in-process pipe registered under a `std:<name>` or `builtin:<runtime>/<name>` reference.
type Capabilities ¶
type Capabilities struct {
Specs []string `json:"specs"`
Adapters []Capability `json:"adapters"`
Std []string `json:"std"`
Builtins []string `json:"builtins"`
Features map[string]bool `json:"features"`
References map[string]bool `json:"references,omitempty"`
}
Capabilities is the capability report of a runner (`openflange version --capabilities`).
type Capability ¶
type Capability struct {
Adapter string `json:"adapter"`
Type string `json:"type"` // implementation type
Language string `json:"language,omitempty"` // for expression/script
Location Location `json:"location"`
Available bool `json:"available"`
// Batch reports that pipes of this implementation can declare batch mode.
Batch bool `json:"batch,omitempty"`
Detail string `json:"detail,omitempty"` // e.g. interpreter path or why unavailable
}
Capability is one thing a runner can execute.
type Diagnostic ¶
type Diagnostic struct {
Time time.Time `json:"time"`
Level string `json:"level"` // debug | info | warn | error
Node string `json:"node,omitempty"`
Message string `json:"message"`
}
Diagnostic is one out-of-band message; diagnostics never enter data streams.
type Host ¶
type Host interface {
// RunSub executes the nested plan n.Sub with the node's streams. Nested
// node reports are recorded under the node's ID.
RunSub(ctx context.Context, n *Node, io *IO) error
}
Host is implemented by the runner and lets adapters call back into it.
type IO ¶
type IO struct {
// Diag receives diagnostics (may be nil).
Diag func(Diagnostic)
// Usage receives adapter-reported usage counters that are merged into the
// node's run report (may be nil).
Usage func(map[string]any)
// Host is the runner (nil in bare unit tests).
Host Host
// Sliced is set by the runner for a node in batch mode: the node's input
// is already delivered in slices (see BatchIn).
Sliced bool
// Clock drives batch-mode waits created by BatchIn (default: real time).
Clock stream.Clock
// Spool is the runner's hook slot for SetSpool (nil in a bare IO).
Spool *SpoolSlot
// contains filtered or unexported fields
}
IO gives a running node its streams and side channels.
func (*IO) BatchIn ¶
BatchIn returns the single input of a node in batch mode as a stream of slices: every Read returns between 1 and n.Batch.MaxItems consecutive items, by the delivery rule of the specification (full, waited n.Batch.MaxWaitMs since the first pending item, or end of input; see stream.Slicer). Under the runner the input is already sliced and is returned as it is; in a bare IO (unit tests of an adapter) the reader is wrapped here. For a node that is not in batch mode it returns the plain reader of the node's first input.
func (*IO) In ¶
In returns the reader of an input port (the first producer of a variadic port). A disconnected port yields an empty stream.
func (*IO) Out ¶
Out returns the writer of an output port. Writing to a disabled output is a harmless no-op, but implementations should consult Enabled to skip work.
func (*IO) ReportUsage ¶
ReportUsage merges usage counters into the node's report.
func (*IO) SetSpool ¶
SetSpool registers f to receive the items of every slice of the node's batched input as they accumulate — in order, before the slice is returned by BatchIn's reader, also while the previous slice is still being processed. An adapter that delivers slices as files uses it to write the next file ahead of time. It must be called before the first Read.
When f returns kept == true it has stored the items and the runner does not hold them in memory: the reader then returns stream.SpooledBatch values, which carry the slice's item and byte counts but no items.
type Node ¶
type Node struct {
// ID is the node's path within the run, e.g. "mask" or "outer/mask".
ID string
Manifest *manifest.Manifest
// Params holds the resolved parameter values (defaults applied).
Params Params
// Secrets holds resolved secret values by declared name. Never log them.
Secrets map[string]string
// Grants are the permissions the consumer granted to this node.
Grants manifest.Permissions
// Inputs and Outputs describe every declared port; check Enabled.
Inputs map[string]PortInfo
Outputs map[string]PortInfo
// BaseDir is the directory of the pipeline file that contains the node
// (the working directory for a pipe run directly). Relative paths given
// as parameters (e.g. std:file-source `path`) resolve against it.
BaseDir string
// Batch holds the node's effective batch settings when its pipe declares
// batch mode (pipe/v0.1 section 5.7), nil otherwise. Under the runner the
// node's single input is then already delivered in slices: every Read of
// io.In(port) returns one slice of 1..Batch.MaxItems items (see IO.BatchIn).
Batch *manifest.Batch
// Sub is the compiled nested plan of a composite node (opaque here).
Sub any
// Prepared is adapter-private state produced by Adapter.Check, e.g. a
// compiled program. It may be shared by repeated runs of the same plan and
// must therefore be immutable or safe for concurrent use.
Prepared any
}
Node is everything an adapter needs to know about one node execution. It is immutable for the duration of the execution.
func (*Node) InputEnabled ¶
InputEnabled reports whether the named input is connected.
func (*Node) OutputEnabled ¶
OutputEnabled reports whether the named output is enabled.
type Params ¶
Params are resolved parameter values: string, bool, int64, float64, json.Number, []any, map[string]any or nil.
type PermissionDeriver ¶
type PermissionDeriver interface {
DerivedPermissions(m *manifest.Manifest, params Params, baseDir string) manifest.Permissions
}
PermissionDeriver is an optional interface of adapters whose nodes need permissions that depend on parameters.
type PortInfo ¶
type PortInfo struct {
Kind stream.Kind
Enabled bool // connected (inputs) / has a consumer or discard (outputs)
MediaType string // negotiated media type
Producers int // inputs: number of producers (variadic ports may have several)
}
PortInfo is the per-port execution configuration computed by the planner.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds adapters, builtin pipes and feature flags. It is safe for concurrent use.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a registry containing only the builtin adapter (with no builtins registered yet).
func (*Registry) BuiltinNames ¶
BuiltinNames lists registered builtins with the given prefix ("std:" or "builtin:"), sorted.
func (*Registry) Capabilities ¶
func (r *Registry) Capabilities() Capabilities
Capabilities reports everything the registry can run.
func (*Registry) HasFeature ¶
HasFeature reports whether a feature is supported.
func (*Registry) Lookup ¶
func (r *Registry) Lookup(impl *manifest.Implementation) (Adapter, error)
Lookup finds the adapter for an implementation, or E_UNSUPPORTED.
func (*Registry) Register ¶
Register adds an adapter. Later registrations take precedence, so an application can override a default adapter.
func (*Registry) RegisterBuiltin ¶
RegisterBuiltin adds or replaces a builtin pipe.
func (*Registry) SetFeature ¶
SetFeature declares support (or not) for a named feature that manifests can list under `requires` (e.g. "windows", "arrow").
func (*Registry) SetReference ¶
SetReference records whether a reference scheme (e.g. "npm", "git") is supported, for the capability report.
type ScalarAdapter ¶
type ScalarAdapter interface {
Scalar(ctx context.Context, n *Node) (ScalarFunc, error)
}
ScalarAdapter is an optional interface of adapters that can evaluate a function-like node without streams (see runner.NewFunc). Scalar returns (nil, nil) when the node has no such fast path.
type ScalarFunc ¶
type ScalarFunc interface {
Call(ctx context.Context, item stream.Item) (stream.Item, error)
Close()
}
ScalarFunc evaluates a function-like pipe for one item at a time, directly on the calling goroutine. It is not safe for concurrent use.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package composite is the adapter for `implementation: {type: pipeline}`: a pipe implemented by a nested pipeline file.
|
Package composite is the adapter for `implementation: {type: pipeline}`: a pipe implemented by a nested pipeline file. |
|
Package exec is the subprocess adapter: it runs `executable` implementations, and `script` implementations in r / python / node (sugar for an executable with the conventional interpreter), under the OpenFlange CLI protocol (openflange.org/cli/v0.1).
|
Package exec is the subprocess adapter: it runs `executable` implementations, and `script` implementations in r / python / node (sugar for an executable with the conventional interpreter), under the OpenFlange CLI protocol (openflange.org/cli/v0.1). |
|
Package httppipe is the HTTP Pipe Protocol client adapter (openflange.org/http/v0.1): it runs a node whose implementation is `type: http` — or whose pipe was referenced as `https://host/base/pipes/<id>` — on a remote server.
|
Package httppipe is the HTTP Pipe Protocol client adapter (openflange.org/http/v0.1): it runs a node whose implementation is `type: http` — or whose pipe was referenced as `https://host/base/pipes/<id>` — on a remote server. |
|
Package starlark implements the Starlark language binding of OpenFlange: `expression` and `script` implementations, the `$expr` parameter binding, and the expression engine used by the standard library (std:map, std:filter, ...).
|
Package starlark implements the Starlark language binding of OpenFlange: `expression` and `script` implementations, the `$expr` parameter binding, and the expression engine used by the standard library (std:map, std:filter, ...). |