pipelines

package
v0.162.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 36 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pipelines runs OpenFlange pipelines inside DataTug: it builds an OpenFlange engine for a project (its own pipes, the standard library, the registry and the DataTug builtins that read project queries and materialise pipeline datasets), validates and saves pipelines, and keeps the runs the CLI and the server start.

This file is the JSON contract of the server API and of `--json` on the command line. Every type here is stable: a member is added, never renamed or given another meaning. Paths in it are relative to the project folder; no value of it holds a secret, a credential or a connection string.

Index

Constants

View Source
const (
	BuiltinQuery         = "builtin:datatug/query"
	BuiltinDataset       = "builtin:datatug/dataset"
	BuiltinDatasetSource = "builtin:datatug/dataset-source"
)

Names of the DataTug builtins.

View Source
const (
	SeverityError   = "error"
	SeverityWarning = "warning"
)

Severities of a Problem.

View Source
const (
	PipeSourceStd     = "std"
	PipeSourceBuiltin = "builtin"
	PipeSourceProject = "project"
)

Pipe sources of a library entry.

View Source
const (
	StatePending   = "pending"
	StateRunning   = "running"
	StateCompleted = "completed"
	StateFailed    = "failed"
	StateCancelled = "cancelled"
)

Run and node states.

View Source
const (
	DirectionInputs  = "inputs"
	DirectionOutputs = "outputs"
)

Port directions.

View Source
const (
	DefaultQueryRows = 100_000
	MaxQueryRows     = 1_000_000
)

DefaultQueryRows and MaxQueryRows bound the rows `builtin:datatug/query` emits; they are the default and the maximum of its `limit` parameter.

View Source
const (
	QueryKindSaved = "query"
	QueryKindSQL   = "sql"
	QueryKindTugQL = "tugql"
)

Query kinds of a QueryRequest and of a recorded source.

View Source
const (
	// DefaultPreviewLimit and MaxPreviewLimit bound the items kept per port.
	DefaultPreviewLimit = 100
	MaxPreviewLimit     = 1000
	// MaxPreviewItemBytes bounds one previewed item; a larger item is
	// replaced by a note of its size.
	MaxPreviewItemBytes = 64 << 10
	// MaxLogEntries is the size of a run's diagnostics ring.
	MaxLogEntries = 1000
	// MaxRuns is the number of runs a Manager keeps; MaxActiveRuns the number
	// it runs at once.
	MaxRuns       = 50
	MaxActiveRuns = 8
)

Bounds of the run registry.

View Source
const CodeDraft = "W_DRAFT"

CodeDraft is the code of the warning a stored draft carries.

View Source
const LayoutSpec = pipeline.LayoutSpec

LayoutSpec is the `spec` of a layout file.

View Source
const MaxActiveTests = 2

MaxActiveTests is the number of pipe tests a Manager runs at once.

View Source
const MaxTestItems = 10_000

MaxTestItems is the number of items a pipe test keeps of each output.

Variables

View Source
var ErrHashMismatch = errors.New("the pipeline was changed by someone else")

ErrHashMismatch is returned by a conditional save whose condition does not hold.

View Source
var ErrNoPipelinesStore = errors.New("this project's store does not keep OpenFlange pipelines")

ErrNoPipelinesStore is returned for a project whose store keeps no pipelines.

Functions

func Drafts

func Drafts(dir string) []string

Drafts lists the ids of the pipelines of the project in dir that are stored as drafts, sorted. It reads the layout files only, so that a validation of the whole project can flag them.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err says that what was asked for is not there.

func ProjectPipeRef

func ProjectPipeRef(id string) string

ProjectPipeRef is the reference of a project pipe from a pipeline of the project.

Types

type Access

type Access struct {
	// Principal is the id of the session's principal, for people to read.
	Principal string
	// Context identifies the principal and the exact policies of the session
	// (accesspolicies.Fingerprint). Empty means the host has no session: it
	// then reads no rows unless it is the Operator.
	Context string
	// Operator is true for the local owner of the project: the person who
	// runs the host on their own machine with authority over the project
	// files. The operator reads every dataset of the project.
	Operator bool
}

Access is the session of a host, as far as pipeline datasets go. A dataset records the Access it was written under; its rows are read back only under the same Context, or by the Operator.

type AdapterCapability

type AdapterCapability struct {
	Adapter   string `json:"adapter"`
	Type      string `json:"type"`
	Language  string `json:"language,omitempty"`
	Location  string `json:"location"`
	Available bool   `json:"available"`
	Detail    string `json:"detail,omitempty"`
}

AdapterCapability says whether this host can run one kind of implementation.

type AllowedPipes

type AllowedPipes struct {
	Entry  string `json:"entry"`
	Source string `json:"source,omitempty"`
	Scope  string `json:"scope,omitempty"`
}

AllowedPipes is one entry of the operator's allow-list in force for a project: the entry in the syntax of the flag, where it was given (the flag, or a settings file and line) and its scope (`all` for every served project, `project` for this project's folder only).

type BatchContract

type BatchContract struct {
	MaxItems  int    `json:"maxItems"`
	MaxWaitMs int    `json:"maxWaitMs"`
	Delivery  string `json:"delivery,omitempty"`
}

BatchContract is the `batch` of a pipe manifest.

type Conversion

type Conversion struct {
	From       string `json:"from"`
	To         string `json:"to"`
	Conversion string `json:"conversion"`
	MediaType  string `json:"mediaType"`
}

Conversion is a lossless conversion the planner inserted on an edge.

type Dataset

type Dataset struct {
	pipedatasets.Provenance
	Freshness pipedatasets.Freshness `json:"freshness"`
	// Table is the SQL name of the dataset in `builtin:datatug/dataset-source`.
	Table string `json:"table"`
	// Readable is whether this session reads the rows of the dataset: it
	// wrote it under the same principal and policies, or it is the local
	// owner of the project. Unreadable is the reason when it does not.
	Readable   bool   `json:"readable"`
	Unreadable string `json:"unreadable,omitempty"`
}

Dataset is a pipeline dataset with its provenance and freshness.

type DatasetPreview

type DatasetPreview struct {
	Name      string                 `json:"name"`
	Items     []json.RawMessage      `json:"items"`
	Columns   []PreviewColumn        `json:"columns"`
	Limit     int                    `json:"limit"`
	Truncated bool                   `json:"truncated"`
	Rows      int64                  `json:"rows"`
	Freshness pipedatasets.Freshness `json:"freshness"`
}

DatasetPreview is the first rows of a pipeline dataset.

type ImportRequest

type ImportRequest struct {
	// Reference is `<publisher>/<name>[@range]`.
	Reference string `json:"reference"`
	// As is the id of the project pipe; the pipe's own id when empty.
	As string `json:"as,omitempty"`
	// Replace allows overwriting a project pipe of that id.
	Replace bool `json:"replace,omitempty"`
}

ImportRequest imports a registry pipe into the project's pipes/ folder.

type ImportResult

type ImportResult struct {
	Pipe PipeContract `json:"pipe"`
	// Lockfile is the lockfile that pins it, relative to the project folder.
	Lockfile string   `json:"lockfile"`
	Warnings []string `json:"warnings,omitempty"`
}

ImportResult is what an import did.

type ImportedPipe

type ImportedPipe struct {
	// Reference is the registry reference it was imported by.
	Reference string `json:"reference"`
	// Resolved is the exact distribution it was fetched from.
	Resolved  string `json:"resolved"`
	Version   string `json:"version"`
	Revision  string `json:"revision,omitempty"`
	Integrity string `json:"integrity"`
	// Modified is true when the files no longer hash to the locked integrity.
	Modified bool `json:"modified"`
}

ImportedPipe is the lockfile pin of a project pipe that came from the registry.

type Layout

type Layout struct {
	Nodes map[string]map[string]any `json:"nodes,omitempty"`
	// Extensions are the top-level `x-` keys.
	Extensions map[string]any `json:"extensions,omitempty"`
}

Layout is the content of pipeline.layout.yaml: positions by node id (or `inputs.<name>` / `outputs.<name>`), and the tool's own `x-` keys.

func (Layout) Validate

func (l Layout) Validate() error

Validate checks a layout against the OpenFlange layout specification: every position has numeric `x` and `y`, and every other key starts with `x-`.

func (Layout) YAML

func (l Layout) YAML() []byte

YAML renders the layout as pipeline.layout.yaml: `spec`, the positions sorted by id, then the extension keys.

type Library

type Library struct {
	Std     []PipeContract `json:"std"`
	Builtin []PipeContract `json:"builtin"`
	Project []PipeContract `json:"project"`
	// Adapters are the implementation kinds of this host, available or not.
	Adapters []AdapterCapability `json:"adapters"`
	// Features are the optional features of this host, by name.
	Features map[string]bool `json:"features"`
	// References are the reference schemes (npm, git, https, registry) this
	// host resolves.
	References map[string]bool `json:"references"`
	// Registry is the location of the registry index that search uses.
	Registry string `json:"registry"`
	// AllowPipes is the operator's allow-list in force for this project, on a
	// host that keeps one (the server); absent on a host where the person who
	// runs a pipeline grants permissions themselves (the command line).
	AllowPipes []AllowedPipes `json:"allowPipes,omitempty"`
	// AllowPipesEnforced is true on a host that keeps an allow-list, also
	// when the list is empty.
	AllowPipesEnforced bool `json:"allowPipesEnforced"`
}

Library is the pipes a pipeline of the project can use.

type LogEntry

type LogEntry struct {
	// Seq grows by one per entry of the run; ask for `since=<seq>` to get the rest.
	Seq     int64     `json:"seq"`
	Time    time.Time `json:"time"`
	Level   string    `json:"level"`
	Node    string    `json:"node,omitempty"`
	Message string    `json:"message"`
}

LogEntry is one diagnostic of a run.

type Logs

type Logs struct {
	RunID   string     `json:"runId"`
	Node    string     `json:"node,omitempty"`
	Entries []LogEntry `json:"entries"`
	// Next is the `since` of the next page.
	Next int64 `json:"next"`
	// Dropped is true when older entries were dropped: the log is a bounded ring.
	Dropped bool `json:"dropped"`
}

Logs is a page of diagnostics.

type Manager

type Manager struct {
	// RunTimeout, when positive, is the longest a run lasts: it is
	// cancelled then. Set it before the first run.
	RunTimeout time.Duration
	// contains filtered or unexported fields
}

Manager keeps the runs of one host: at most MaxRuns, the oldest ended run making room for a new one.

func NewManager

func NewManager() *Manager

NewManager creates an empty run registry.

func (*Manager) Get

func (m *Manager) Get(id string) (*Run, error)

Get returns a run by id.

func (*Manager) List

func (m *Manager) List(pipelineID string) []RunStatus

List returns the status of every kept run, newest first; pipelineID, when given, selects the runs of one pipeline.

func (*Manager) ListProject

func (m *Manager) ListProject(project, pipelineID string, a Access) []RunStatus

ListProject is List for the runs of one project that a session reads (Run.MayRead): a host that serves several projects and sessions keeps their runs apart.

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context, w *Workspace, name string, req RunRequest) (*Run, error)

Refresh starts a run of the pipeline that wrote a pipeline dataset: a dataset is refreshed only by running its pipeline again.

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context) error

Shutdown cancels every run in progress and the work it tracks (Track), starts no other, and waits until they have ended (their processes stopped) or ctx is done.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, w *Workspace, pipelineID string, req RunRequest, o StartOptions) (*Run, error)

Start compiles the stored pipeline and starts running it. It returns as soon as the run exists; a pipeline that does not validate is not started and the error is its validation errors. ctx bounds the whole run, so a server passes one that outlives the request.

func (*Manager) Track

func (m *Manager) Track(ctx context.Context) (context.Context, func(), error)

Track starts work that stops with the host, such as the tests of pipes: the returned context is cancelled by Shutdown, which waits until done is called. It refuses work after Shutdown and beyond MaxActiveTests.

type NodeDocument

type NodeDocument struct {
	ID string `json:"id"`
	// Pipe is the reference, as written.
	Pipe string `json:"pipe"`
	// Inputs maps an input port to its sources, consumer side:
	// `inputs.<name>` or `<node>.outputs.<port>`. A variadic port has several.
	Inputs map[string][]string `json:"inputs,omitempty"`
	// Outputs holds the consumer-side controls of outputs.
	Outputs map[string]OutputControl `json:"outputs,omitempty"`
	// Parameters holds literal values and bindings: {"$param": name},
	// {"$env": NAME}, {"$expr": "<starlark>"}.
	Parameters map[string]any `json:"parameters,omitempty"`
	// Secrets maps a declared secret to {"$secret": REF}. A value is never stored.
	Secrets map[string]SecretRef `json:"secrets,omitempty"`
	// Grants are the permissions granted to this node.
	Grants json.RawMessage `json:"grants,omitempty"`
}

NodeDocument is one node of a pipeline, as written.

type NodeStatus

type NodeStatus struct {
	ID string `json:"id"`
	// Pipe is the reference as written; Adapter and Location say what runs it.
	Pipe       string `json:"pipe,omitempty"`
	Adapter    string `json:"adapter,omitempty"`
	Location   string `json:"location,omitempty"`
	State      string `json:"state"`
	DurationMs int64  `json:"durationMs"`
	RecordsIn  int64  `json:"recordsIn"`
	RecordsOut int64  `json:"recordsOut"`
	BytesIn    int64  `json:"bytesIn"`
	BytesOut   int64  `json:"bytesOut"`
	// Inputs and Outputs are the node's ports by name.
	Inputs  map[string]PortStatus `json:"inputs"`
	Outputs map[string]PortStatus `json:"outputs"`
	// Error is set on the node that failed the run.
	Error *Problem `json:"error,omitempty"`
	// Usage holds what the node reported about itself (a dataset written,
	// policy limitations applied).
	Usage map[string]any `json:"usage,omitempty"`
	// Logs is the number of diagnostics the node has emitted so far.
	Logs int `json:"logs"`
}

NodeStatus is the state of one node of a run. Nodes of a nested pipeline have the id `<outer>/<inner>`.

type Options

type Options struct {
	// Queries runs project queries for `builtin:datatug/query`. When nil the
	// pipe is listed as unsupported, with QueriesUnavailable as the reason,
	// and a pipeline that uses it does not validate.
	Queries            QueryRunner
	QueriesUnavailable string
	// Datasets is the project's pipeline datasets. When nil the dataset pipes
	// are unsupported, with DatasetsUnavailable as the reason.
	Datasets            *pipedatasets.Store
	DatasetsUnavailable string
	// Registry is the location of the OpenFlange registry index: a path, a
	// file:// URL or an https URL. Empty means $OPENFLANGE_REGISTRY, then the
	// default registry.
	Registry string
	// Offline forbids every fetch: the registry index must then be a local
	// path, and an import can only use what is already cached.
	Offline bool
	// CacheDir holds fetched packages. Empty means a folder of the person's
	// cache directory, outside the repository.
	CacheDir string
	// AllowPipes, when not nil, is the operator's allow-list: the host takes
	// no grants from the caller of a run, and a pipe that needs a permission
	// runs only when the list allows it, with exactly the permissions its
	// manifest declares. Nil means the caller grants (the command line).
	AllowPipes *pipeallow.List
	// Access is the session the host reads and writes pipeline datasets under.
	Access Access
	// Secrets resolves `{$secret: REF}`. Nil means no secret is available: a
	// pipeline never reads the environment of the host for one.
	Secrets func(ref string) (string, bool)
	// Env resolves `{$env: NAME}` bindings. Nil means none is set.
	Env func(name string) (string, bool)

	// FetchOnlyToImport resolves references only from the project, the
	// cache and the lockfile, except within Import and Search: nothing else
	// fetches, clones or reads a remote registry index (not a validation, a
	// contract, the library, a save, a run or a test). A server sets it: it
	// fetches only when asked to import or search.
	FetchOnlyToImport bool

	// AllowLocalGit accepts a registry pipe distributed from a file://
	// repository of this machine. It is for tests and local fixtures; a host
	// never sets it from a request.
	AllowLocalGit bool
}

Options are what the host decides for a workspace.

type OutputControl

type OutputControl struct {
	// Discard drains the output; Enabled false leaves an optional output off.
	Discard bool  `json:"discard,omitempty"`
	Enabled *bool `json:"enabled,omitempty"`
}

OutputControl is a consumer-side control of a node output.

type ParameterContract

type ParameterContract struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Required    bool     `json:"required"`
	HasDefault  bool     `json:"hasDefault"`
	Default     any      `json:"default,omitempty"`
	Description string   `json:"description,omitempty"`
	Enum        []any    `json:"enum,omitempty"`
	Minimum     *float64 `json:"minimum,omitempty"`
	Maximum     *float64 `json:"maximum,omitempty"`
	MinLength   *int     `json:"minLength,omitempty"`
	MaxLength   *int     `json:"maxLength,omitempty"`
	Pattern     string   `json:"pattern,omitempty"`
}

ParameterContract is one parameter of a pipe.

type PipeContract

type PipeContract struct {
	// Ref is the reference to write in `nodes.<id>.pipe` of a pipeline of
	// this project: `std:filter`, `builtin:datatug/query`, `../../pipes/mask-email`.
	Ref string `json:"ref"`
	// Source is std, builtin or project.
	Source string `json:"source"`
	// ID and Version are the pipe's own.
	ID          string   `json:"id"`
	Version     string   `json:"version"`
	Title       string   `json:"title,omitempty"`
	Description string   `json:"description,omitempty"`
	License     string   `json:"license,omitempty"`
	Keywords    []string `json:"keywords,omitempty"`
	Maturity    string   `json:"maturity,omitempty"`
	// Kind is source, sink or pipe.
	Kind          string              `json:"kind"`
	Cardinality   string              `json:"cardinality,omitempty"`
	Deterministic bool                `json:"deterministic,omitempty"`
	Inputs        []PortContract      `json:"inputs"`
	Outputs       []PortContract      `json:"outputs"`
	Parameters    []ParameterContract `json:"parameters"`
	// Implementation is the implementation type (builtin, expression, script,
	// executable, pipeline, http) and Language its language, when it has one.
	Implementation string `json:"implementation"`
	Language       string `json:"language,omitempty"`
	// Location is where a node of this pipe runs: local-go, subprocess, remote-http.
	Location string `json:"location,omitempty"`
	// Permissions are what the pipe needs granted before it runs.
	Permissions any `json:"permissions,omitempty"`
	// Supported is false when this host cannot run the pipe; Unsupported says why.
	Supported   bool   `json:"supported"`
	Unsupported string `json:"unsupported,omitempty"`
	// Runtime is what the operator's allow-list names: the language of a
	// script (`python`, `r`, `node`), else the implementation type.
	Runtime string `json:"runtime"`
	// Runnable is whether a run started on this host may use the pipe: it is
	// supported and, where the host keeps an allow-list of pipes, it needs no
	// permission or is on the list. NotRunnable is the reason when it is
	// not; AllowWith is the flag of `datatug serve` that would allow it.
	Runnable    bool   `json:"runnable"`
	NotRunnable string `json:"notRunnable,omitempty"`
	AllowWith   string `json:"allowWith,omitempty"`
	// Batch is the batch mode the manifest declares, read-only: the
	// implementation gets its input in slices of at most maxItems items held
	// back for at most maxWaitMs milliseconds.
	Batch *BatchContract `json:"batch,omitempty"`
	// Files are the pipe's files (project pipes), relative to its folder.
	Files []string `json:"files,omitempty"`
	// Documentation is the Markdown body of the manifest (single-pipe answers).
	Documentation string `json:"documentation,omitempty"`
	// Imported is set for a project pipe that was imported from the registry.
	Imported *ImportedPipe `json:"imported,omitempty"`
	// Problems are the findings of a project pipe whose manifest is not valid.
	Problems []Problem `json:"problems,omitempty"`
}

PipeContract is a pipe of the library with everything a designer needs to place it: how to reference it, its ports and parameters, where it runs and whether this host can run it.

type Pipeline

type Pipeline struct {
	ID string `json:"id"`
	// YAML is pipeline.yaml as stored.
	YAML string `json:"yaml"`
	// Document is the structured form; nil when the file cannot be parsed
	// (Validation then says why).
	Document *PipelineDocument `json:"document"`
	// Manifest is the optional OPENFLANGE.md as stored.
	Manifest string `json:"manifest,omitempty"`
	// Layout is the stored layout; nil when there is none.
	Layout *Layout `json:"layout"`
	// Hash is `sha256-<hex>` over the pipeline file and its manifest. A save
	// can be made conditional on it, and a pipeline dataset is stale when its
	// pipeline no longer has the hash it was written under.
	Hash string `json:"hash"`
	// Draft is true for a pipeline stored as work in progress: it did not
	// validate when it was saved and does not run.
	Draft bool `json:"draft"`
	// Validation is the result of validating the stored pipeline.
	Validation *Validation `json:"validation,omitempty"`
}

Pipeline is one pipeline with everything the designer opens it with.

type PipelineDocument

type PipelineDocument struct {
	// Parameters are the pipeline's own parameters, as declared.
	Parameters map[string]any `json:"parameters,omitempty"`
	Nodes      []NodeDocument `json:"nodes"`
	// Outputs maps a pipeline output to its one source.
	Outputs map[string]string `json:"outputs,omitempty"`
}

PipelineDocument is the structured form of pipeline.yaml. Saving it writes canonical YAML: the nodes in the order given here, every other key sorted.

func (PipelineDocument) YAML

func (d PipelineDocument) YAML() []byte

YAML renders the document as canonical pipeline.yaml: `spec` first, the nodes in their order, every other key sorted, consumer-side mappings only.

type PipelineSummary

type PipelineSummary struct {
	ID          string `json:"id"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	HasManifest bool   `json:"hasManifest"`
	HasLayout   bool   `json:"hasLayout"`
	// Draft is true for a pipeline stored as work in progress: it did not
	// validate when it was saved and does not run.
	Draft bool `json:"draft"`
	// Nodes is the number of nodes; -1 when the file cannot be parsed.
	Nodes int `json:"nodes"`
	// Hash is the digest of the pipeline definition (see Pipeline.Hash).
	Hash string `json:"hash"`
}

PipelineSummary is a pipeline in a listing.

type PortContract

type PortContract struct {
	Name        string   `json:"name"`
	Kind        string   `json:"kind"`
	Required    bool     `json:"required"`
	Variadic    bool     `json:"variadic,omitempty"`
	Description string   `json:"description,omitempty"`
	MediaTypes  []string `json:"mediaTypes"`
	// Schema is the port's schema as declared: {format, definition | path}.
	Schema any `json:"schema,omitempty"`
}

PortContract is one named input or output of a pipe.

type PortStatus

type PortStatus struct {
	// State is disconnected, connected, active, completed or failed.
	State   string `json:"state"`
	Records int64  `json:"records"`
	Bytes   int64  `json:"bytes"`
	// Preview is true when a preview of the port can be asked for.
	Preview bool `json:"preview"`
}

PortStatus is the state and the counters of one port.

type Preview

type Preview struct {
	RunID string `json:"runId"`
	// Node is "" for a port of the pipeline itself.
	Node      string `json:"node"`
	Port      string `json:"port"`
	Direction string `json:"direction"`
	// From is the output the items were captured at: the port itself, or the
	// producer of an input.
	From string `json:"from"`
	// Producers lists every producer of a variadic input; From is one of them.
	Producers []string `json:"producers,omitempty"`
	Kind      string   `json:"kind"`
	MediaType string   `json:"mediaType,omitempty"`
	// Items are JSON values for a records, values or windows port, and
	// strings for a text port. A binary port has no items.
	Items   []json.RawMessage `json:"items"`
	Columns []PreviewColumn   `json:"columns"`
	// Limit is the most items a preview keeps; Truncated is true when more
	// items passed the port than are here; Records is how many passed so far.
	Limit     int   `json:"limit"`
	Truncated bool  `json:"truncated"`
	Records   int64 `json:"records"`
	// Complete is true when the run has ended, so the preview will not grow.
	Complete bool `json:"complete"`
	// Redacted is the number of items in which a secret value was masked.
	Redacted int `json:"redacted,omitempty"`
}

Preview is the first items that passed one port of a run: a bounded sample, never the stream.

type PreviewColumn

type PreviewColumn struct {
	Name string `json:"name"`
	// Type is string, number, boolean, object, array, null or mixed.
	Type string `json:"type"`
}

PreviewColumn is one column of a preview, for a grid.

type Problem

type Problem struct {
	Code     string `json:"code"`
	Severity string `json:"severity"`
	Message  string `json:"message"`
	// Node and Port locate the problem in the graph.
	Node string `json:"node,omitempty"`
	Port string `json:"port,omitempty"`
	// File is relative to the project folder; Line and Column are 1-based.
	File   string `json:"file,omitempty"`
	Line   int    `json:"line,omitempty"`
	Column int    `json:"column,omitempty"`
	// Path is the YAML path, such as `nodes.mask.inputs.email`.
	Path string `json:"path,omitempty"`
	// Hint is a concrete suggestion, when there is one.
	Hint    string         `json:"hint,omitempty"`
	Details map[string]any `json:"details,omitempty"`
}

Problem is one validation or run-time finding: an OpenFlange error code (E_* / W_*), a message, and where it is.

func Problems

func Problems(err error) []Problem

Problems lists the findings of an error a method of this package returned, in the contract's form. An error that is not a finding of the engine yields none.

type Project

type Project struct {
	// ID is the project's id; Dir its folder.
	ID  string
	Dir string
	// Store is the project's store. It must keep pipelines
	// (datatug.PipelinesStore), as the file store does.
	Store any
}

Project is the DataTug project a workspace serves.

type QueryRequest

type QueryRequest struct {
	// Node is the pipeline node that asks.
	Node string
	// Exactly one of QueryID (a saved query), SQL and TugQL (inline text) is set.
	QueryID string
	SQL     string
	TugQL   string
	// Environment and Database name the project environment and catalog by
	// their ids; either may be empty where the host can resolve it.
	Environment string
	Database    string
	Variables   map[string]any
	// Limit is the most rows the node emits (1..MaxQueryRows).
	Limit int
}

QueryRequest is one read of `builtin:datatug/query`.

func (QueryRequest) Kind

func (r QueryRequest) Kind() string

Kind is the kind of the request.

type QueryResult

type QueryResult struct {
	// QueryID is the canonical id of the saved query that ran.
	QueryID     string
	Environment string
	// Connection is the id of the project database the query ran against.
	Connection string
	// Limitations are the policy effects the caller must be told about.
	Limitations []string
	// Truncated is true when the source had more rows than were emitted.
	Truncated bool
}

QueryResult is what a QueryRunner reports once the rows are emitted. It names things by their project ids and never holds a credential or a URL.

type QueryRunner

type QueryRunner interface {
	RunQuery(ctx context.Context, req QueryRequest, emit func(columns []string, rows []map[string]any) error) (QueryResult, error)
}

QueryRunner runs a query of the project through the host's own policy-enforced read path (pkg/secureread) and hands the rows to emit, in order, in as many calls as the host's executor allows. The CLI and the server each provide theirs; the pipelines package opens no connection.

type QueryRunnerFunc

type QueryRunnerFunc func(ctx context.Context, req QueryRequest, emit func(columns []string, rows []map[string]any) error) (QueryResult, error)

QueryRunnerFunc adapts a function to QueryRunner.

func (QueryRunnerFunc) RunQuery

func (f QueryRunnerFunc) RunQuery(ctx context.Context, req QueryRequest, emit func(columns []string, rows []map[string]any) error) (QueryResult, error)

RunQuery implements QueryRunner.

type RegistryPipe

type RegistryPipe struct {
	// ID is `<publisher>/<name>`, the reference to import it by.
	ID           string   `json:"id"`
	Title        string   `json:"title,omitempty"`
	Description  string   `json:"description,omitempty"`
	License      string   `json:"license,omitempty"`
	Keywords     []string `json:"keywords"`
	Languages    []string `json:"languages"`
	Runtimes     []string `json:"runtimes"`
	Latest       string   `json:"latest"`
	Distribution string   `json:"distribution"`
	Deprecated   bool     `json:"deprecated"`
	Score        int      `json:"score"`
}

RegistryPipe is one hit of a registry search.

type RegistrySearch

type RegistrySearch struct {
	// Registry is the location of the index that was searched.
	Registry string         `json:"registry"`
	Pipes    []RegistryPipe `json:"pipes"`
	Warnings []string       `json:"warnings,omitempty"`
}

RegistrySearch is the answer of a registry search.

type Run

type Run struct {
	// contains filtered or unexported fields
}

Run is one execution of a pipeline. Every method is safe for concurrent use.

func (*Run) Cancel

func (r *Run) Cancel()

Cancel asks the run to stop. The run ends as cancelled soon after.

func (*Run) Done

func (r *Run) Done() <-chan struct{}

Done is closed when the run has ended.

func (*Run) ID

func (r *Run) ID() string

ID is the run id.

func (*Run) Logs

func (r *Run) Logs(node string, since int64) Logs

Logs returns the diagnostics after seq `since`, of one node or (node "") of the whole run.

func (*Run) MayRead

func (r *Run) MayRead(a Access) bool

MayRead reports whether a session reads the run: its status, previews and logs. A run is read under the session that started it (the same principal and policies) or by the owner of the project; a run started with no session is the owner's alone.

func (*Run) Observe

func (r *Run) Observe(at runner.TapPoint, b stream.Batch) bool

Observe implements runner.Tap: it counts everything and keeps the first items.

func (*Run) PipelineID

func (r *Run) PipelineID() string

PipelineID is the id of the pipeline the run executes.

func (*Run) Preview

func (r *Run) Preview(node, direction, port string) (*Preview, error)

Preview is the bounded sample of one port. node is "" for a port of the pipeline itself; direction is inputs or outputs. An input shows what its producers emitted, in producer order.

func (*Run) Project

func (r *Run) Project() string

Project is the id of the project the pipeline belongs to.

func (*Run) Revision

func (r *Run) Revision() int64

Revision is the current revision of the run's status.

func (*Run) Status

func (r *Run) Status() RunStatus

Status is the current state of the run.

func (*Run) Wait

func (r *Run) Wait(ctx context.Context, since int64) RunStatus

Wait blocks until the run's revision is beyond since, the run has ended, or ctx is done; it returns the status then.

type RunRequest

type RunRequest struct {
	// Parameters are the values of the pipeline's own parameters.
	Parameters map[string]any `json:"parameters,omitempty"`
	// Grants are run-wide permission grants in the form of the command line:
	// `subprocess`, `network=host:port`, `fs.read=path`, `fs.write=path`,
	// `env=NAME`, `secret=NAME`, `remoteData=host`.
	Grants []string `json:"grants,omitempty"`
	// Inputs are the items of the pipeline's external inputs, by name.
	Inputs map[string][]json.RawMessage `json:"inputs,omitempty"`
	// PreviewLimit is the number of items kept per port (default 100, at most 1000).
	PreviewLimit int `json:"previewLimit,omitempty"`
	// CoerceParameters parses string values as the command line does.
	CoerceParameters bool `json:"-"`
}

RunRequest starts a run.

type RunStatus

type RunStatus struct {
	RunID      string `json:"runId"`
	PipelineID string `json:"pipelineId"`
	// PipelineHash is the digest of the definition the run executes.
	PipelineHash string     `json:"pipelineHash"`
	State        string     `json:"state"`
	Revision     int64      `json:"revision"`
	StartedAt    time.Time  `json:"startedAt"`
	FinishedAt   *time.Time `json:"finishedAt,omitempty"`
	DurationMs   int64      `json:"durationMs"`
	// Error is why the run failed or was cancelled.
	Error *Problem `json:"error,omitempty"`
	// PartialOutput is true when a run that did not complete had already
	// delivered output.
	PartialOutput bool `json:"partialOutput"`
	// Nodes are in execution order, nested nodes after their parent.
	Nodes []NodeStatus `json:"nodes"`
	// Inputs and Outputs are the pipeline's external ports.
	Inputs  map[string]PortStatus `json:"inputs"`
	Outputs map[string]PortStatus `json:"outputs"`
	// Conversions are the automatic conversions of this run's plan.
	Conversions []Conversion `json:"conversions"`
	// Datasets are the pipeline datasets the run wrote.
	Datasets []string `json:"datasets"`
	// PreviewLimit is the number of items kept per port.
	PreviewLimit int `json:"previewLimit"`
	// Logs is the number of diagnostics of the run so far.
	Logs int `json:"logs"`
}

RunStatus is the state of a run. Revision grows whenever anything in the status changes, so a client polls with `since=<revision>`.

func (RunStatus) Terminal

func (s RunStatus) Terminal() bool

Terminal reports whether the run has ended.

type SavePipelineRequest

type SavePipelineRequest struct {
	YAML     *string           `json:"yaml,omitempty"`
	Document *PipelineDocument `json:"document,omitempty"`
	// Manifest, when given, replaces OPENFLANGE.md; an empty string removes it.
	Manifest *string `json:"manifest,omitempty"`
	// Layout, when given, replaces the layout.
	Layout *Layout `json:"layout,omitempty"`
	// IfHash, when given, must be the stored pipeline's hash ("" for a
	// pipeline that must not exist yet); otherwise the save is refused.
	IfHash *string `json:"ifHash,omitempty"`
	// Draft keeps work in progress: a pipeline that does not validate is
	// refused unless Draft is set, and is then stored marked as a draft. A
	// draft is listed and read as one and does not run until it is saved
	// again and validates.
	Draft bool `json:"draft,omitempty"`
}

SavePipelineRequest saves a pipeline. Exactly one of YAML and Document is given.

type SearchQuery

type SearchQuery struct {
	Text              string
	Language          string
	Runtime           string
	License           string
	IncludeDeprecated bool
	// Limit is the most hits to return (default 50, at most 200).
	Limit int
}

SearchQuery selects registry pipes.

type SecretRef

type SecretRef struct {
	Secret string `json:"$secret"`
}

SecretRef names an entry of the runner's secret provider.

type StartOptions

type StartOptions struct {
	// Inputs and Outputs bind external ports to streams of the caller. An
	// output that is not bound is drained; its preview is still kept.
	Inputs  map[string]stream.Reader
	Outputs map[string]stream.Writer
	// DefaultOutput receives the pipeline's output when it has exactly one
	// and Outputs does not bind it: the standard output of a command.
	DefaultOutput stream.Writer
}

StartOptions are what the caller of Start binds itself.

type TestCase

type TestCase struct {
	File       string        `json:"file"`
	Name       string        `json:"name"`
	Line       int           `json:"line,omitempty"`
	Passed     bool          `json:"passed"`
	DurationMs int64         `json:"durationMs"`
	Status     string        `json:"status"`
	Error      string        `json:"error,omitempty"`
	Failures   []TestFailure `json:"failures,omitempty"`
}

TestCase is one portable test.

type TestFailure

type TestFailure struct {
	Port    string `json:"port,omitempty"`
	Message string `json:"message"`
	Diff    string `json:"diff,omitempty"`
}

TestFailure is one unmet expectation of a test.

type TestResult

type TestResult struct {
	Passed  int        `json:"passed"`
	Failed  int        `json:"failed"`
	Files   int        `json:"files"`
	Results []TestCase `json:"results"`
}

TestResult is the outcome of the portable tests of pipes.

type ValidateRequest

type ValidateRequest struct {
	// YAML or Document is a draft to validate instead of the stored file.
	YAML     *string           `json:"yaml,omitempty"`
	Document *PipelineDocument `json:"document,omitempty"`
	Manifest *string           `json:"manifest,omitempty"`
	// Parameters and Grants are those of a run (see RunRequest).
	Parameters map[string]any `json:"parameters,omitempty"`
	Grants     []string       `json:"grants,omitempty"`
	// CoerceParameters parses string values as the command line does.
	CoerceParameters bool `json:"-"`
	// contains filtered or unexported fields
}

ValidateRequest validates the stored pipeline, or a draft that is not saved.

type Validation

type Validation struct {
	OK       bool      `json:"ok"`
	Errors   []Problem `json:"errors"`
	Warnings []Problem `json:"warnings"`
	// Draft is true when the stored pipeline is marked as a draft; the
	// warnings then say so (`W_DRAFT`).
	Draft bool `json:"draft,omitempty"`
	// Plan is the execution plan of the OpenFlange Pipeline specification
	// (section 6.5): nodes with their adapter, location, enabled ports,
	// resolved parameters and grants, edges with media types, and the
	// conversions the planner inserted. Secret values are never part of it.
	Plan json.RawMessage `json:"plan,omitempty"`
}

Validation is every error and warning of a pipeline, and its execution plan when there is no error.

func ValidationOf

func ValidationOf(err error) (*Validation, bool)

ValidationOf returns the validation behind an error of a strict save.

type Workspace

type Workspace struct {
	Project Project
	Engine  *openflange.Engine
	// contains filtered or unexported fields
}

Workspace is one project's OpenFlange engine and its pipelines. It reads the project's files when asked, so open one per request or command; a run keeps the plan it compiled.

func Open

func Open(project Project, o Options) (*Workspace, error)

Open builds the engine of a project: the standard library and default adapters of the OpenFlange SDK, the DataTug builtins, and a resolver rooted at the project folder that honours the project's lockfile.

func (*Workspace) Access

func (w *Workspace) Access() Access

Access is the session the workspace reads and runs under.

func (*Workspace) Dataset

func (w *Workspace) Dataset(ctx context.Context, name string) (*Dataset, error)

Dataset returns one pipeline dataset.

func (*Workspace) DatasetPreview

func (w *Workspace) DatasetPreview(ctx context.Context, name string, limit int) (*DatasetPreview, error)

DatasetPreview returns the first rows of a pipeline dataset (default 100, at most MaxPreviewLimit).

func (*Workspace) Datasets

func (w *Workspace) Datasets(ctx context.Context) ([]Dataset, error)

Datasets lists the project's pipeline datasets, sorted by name. A host without a dataset store has none.

func (*Workspace) DeleteDataset

func (w *Workspace) DeleteDataset(name string) error

DeleteDataset removes a pipeline dataset: one this session wrote, or any for the owner of the project.

func (*Workspace) DeletePipeline

func (w *Workspace) DeletePipeline(ctx context.Context, id string) error

DeletePipeline removes a pipeline. Its pipeline datasets are kept: they are then reported as stale.

func (*Workspace) GetPipeline

func (w *Workspace) GetPipeline(ctx context.Context, id string) (*Pipeline, error)

GetPipeline returns a pipeline as stored, its structured form, its layout and the result of validating it.

func (*Workspace) Import

func (w *Workspace) Import(ctx context.Context, req ImportRequest) (*ImportResult, error)

Import fetches a registry pipe, copies its files into the project's pipes/ folder and pins it in the project's lockfile: the reference it came from, the exact distribution, its version and the integrity of its files.

func (*Workspace) IsDraft

func (w *Workspace) IsDraft(ctx context.Context, id string) bool

IsDraft reports whether the stored pipeline id is marked as a draft.

func (*Workspace) Library

func (w *Workspace) Library(ctx context.Context) (*Library, error)

Library lists every pipe a pipeline of the project can use, with its contract and whether this host can run it.

func (*Workspace) ListPipelines

func (w *Workspace) ListPipelines(ctx context.Context) ([]PipelineSummary, error)

ListPipelines lists the project's pipelines, sorted by id.

func (*Workspace) LockPath

func (w *Workspace) LockPath() string

LockPath is the project's OpenFlange lockfile, in the project root.

func (*Workspace) Pipe

func (w *Workspace) Pipe(ctx context.Context, ref string) (*PipeContract, error)

Pipe returns one pipe by its reference: `std:<name>`, `builtin:<name>`, the id of a project pipe, or a project pipe's reference.

func (*Workspace) PipelineHash

func (w *Workspace) PipelineHash(ctx context.Context, id string) string

PipelineHash is the digest of the stored definition of a pipeline, or "" when the pipeline is not there.

func (*Workspace) RegistryLocation

func (w *Workspace) RegistryLocation() string

RegistryLocation is where the registry index is read from.

func (*Workspace) SaveLayout

func (w *Workspace) SaveLayout(ctx context.Context, id string, layout Layout) error

SaveLayout writes only the layout of a pipeline that exists.

func (*Workspace) SavePipeline

func (w *Workspace) SavePipeline(ctx context.Context, id string, req SavePipelineRequest) (*Pipeline, error)

SavePipeline validates and writes a pipeline. It refuses a file that does not validate, unless the request keeps it as a draft: a draft is stored with a mark in its layout file and does not run.

func (*Workspace) Search

func (w *Workspace) Search(ctx context.Context, q SearchQuery) (*RegistrySearch, error)

Search searches the registry index.

func (*Workspace) TestPipes

func (w *Workspace) TestPipes(ctx context.Context, id string, grants []string, onResult func(TestCase)) (*TestResult, error)

TestPipes runs the portable tests of one project pipe, or of all of them when id is "". A test case is granted what the person who runs the tests grants (grants, as `--grant` takes them) on the command line, or what the operator's allow-list allows on a server, which takes no grants: never what its test file writes. On a server a case gets no environment variable and no secret, and it does not read or write project data.

func (*Workspace) Validate

func (w *Workspace) Validate(ctx context.Context, id string, req ValidateRequest) *Validation

Validate reports every error and warning of the stored pipeline, or of the draft in the request, and its plan when there is no error. The returned error is nil unless the request itself is unusable.

func (*Workspace) ValidatePipe

func (w *Workspace) ValidatePipe(ctx context.Context, id string) (*Validation, error)

ValidatePipe validates one pipe of the project's pipes/ folder on its own: its manifest, its implementation and, for a composite, its graph.

Jump to

Keyboard shortcuts

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