resolve

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 27 Imported by: 1 module, 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 resolve turns pipe references (baseline §4) into loaded manifests: local project paths, `std:` and `builtin:` pipes, npm packages, git repositories and registry references, with a project-local cache (`.openflange/cache`), the `openflange.lock.yaml` lockfile, integrity hashing, locked verification, transitive resolution and cycle detection.

References and everything they point to are untrusted: paths cannot escape the project (or the fetched package they live in), fetches are bounded and HTTPS-only, npm installs never run lifecycle scripts, git clones never run hooks, no shell is involved, and nothing from a fetched package is executed by this package.

Index

Constants

View Source
const (
	LockFileName = "openflange.lock.yaml"
	LockSpec     = "openflange.org/lock/v0.1"
)

Lockfile constants.

View Source
const (
	MaxDependencies = 10000
	MaxDepth        = 64
)

Limits against resource exhaustion (lock/v0.1 §7).

View Source
const DefaultTimeout = 2 * time.Minute

DefaultTimeout bounds one fetch (npm install, git clone, HTTP request).

View Source
const MaxDefinitionBytes = 1 << 20

MaxDefinitionBytes bounds a remote pipe definition.

Variables

This section is empty.

Functions

func BytesIntegrity

func BytesIntegrity(data []byte) string

BytesIntegrity returns "sha256-<hex>" of data (used for remote definitions).

func FindLock

func FindLock(startDir string) string

FindLock walks up from startDir and returns the nearest lockfile path, or "" if there is none.

func FindRoot

func FindRoot(target string) string

FindRoot determines the project root for a target path: the nearest ancestor directory (starting at the target itself, or its directory when it is a file) that contains openflange.lock.yaml, openflange.yaml or .git; otherwise the current working directory if it contains the target; otherwise the target's directory.

func Integrity

func Integrity(m *manifest.Manifest) (string, error)

Integrity computes the lockfile integrity of a pipe (lock/v0.1 §4): "sha256-" followed by the lower-case hex SHA-256 of the byte string built as follows. Take the file set of m.Files() — the manifest plus every file its frontmatter references: implementation.path, a relative implementation.command[0] and every port schema.path (for a composite, the pipeline file; the pipes it uses are separate lock entries). Express each path relative to the manifest's directory with `/` separators and no leading `./`, sort the paths by their UTF-8 bytes, and for each file append

path + "\x00" + <decimal byte length of content> + "\x00" + content

with the content exactly as stored. A referenced file that is missing is an error (E_PATH), never an empty contribution. A builtin such as `std:filter` has a single file: the runner's canonical manifest, hashed under the path `OPENFLANGE.md`.

func IsCommit

func IsCommit(ref string) bool

IsCommit reports whether a git ref is a full 40-hex commit id.

func NpmInstallArgs

func NpmInstallArgs(prefix, pkg, spec string) []string

NpmInstallArgs returns the npm argument vector used to install pkg@spec into prefix. Lifecycle scripts are never run.

func RemoteBase

func RemoteBase(rawURL string) (base, id, host, hostport string, err error)

RemoteBase splits a remote pipe URL (`{base}/pipes/{id}`) into the server base URL, the pipe id and the server's host and host:port.

Types

type Dependency

type Dependency struct {
	// Resolved is the exact location: a path relative to the project root
	// (`pipes/lowercase`), `std:name@0.1.0`, `npm:pkg@1.2.3[#subpath]`,
	// `git:url#<commit>[:subpath]` or the https URL of a remote pipe.
	Resolved string
	// Version is the pipe contract version.
	Version string
	// Revision is the commit, npm dist integrity or remote-reported revision
	// ("" = null).
	Revision string
	// Integrity is `sha256-<hex>` (see Integrity).
	Integrity string
	// Dependencies are the lock keys of the direct dependencies.
	Dependencies []string
	// Extra holds `x-` extension keys of the entry; preserved on Save.
	Extra map[string]any
}

Dependency is one locked reference.

type Kind

type Kind string

Kind classifies a reference.

const (
	Local    Kind = "local"
	Std      Kind = "std"
	Builtin  Kind = "builtin"
	Npm      Kind = "npm"
	Git      Kind = "git"
	HTTP     Kind = "http"
	Registry Kind = "registry"
	Pypi     Kind = "pypi"
	Cran     Kind = "cran"
	Oci      Kind = "oci"
)

Reference kinds of the v0.1 baseline.

type Lockfile

type Lockfile struct {
	// Path is the lockfile's location.
	Path         string
	Dependencies map[string]*Dependency
	// Extra holds top-level `x-` extension keys; they are preserved on Save.
	Extra map[string]any
}

Lockfile is a parsed `openflange.lock.yaml`.

Keys (lock/v0.1 §3): every reference is keyed exactly as written, except that a relative path reference is rewritten relative to the project root (the lockfile's directory), beginning with `./` or `../` and using `/` separators (for example `./pipes/lowercase`), so that one pipe referenced from several directories has one entry. A relative reference inside a fetched package is written relative to that package's root.

func LoadLock

func LoadLock(path string) (*Lockfile, error)

LoadLock reads a lockfile. A missing file yields an error for which errors.Is(err, os.ErrNotExist) is true; a malformed file yields E_LOCK.

func (*Lockfile) Bytes

func (l *Lockfile) Bytes() []byte

Bytes renders the lockfile deterministically (sorted keys, quoted strings).

func (*Lockfile) Dir

func (l *Lockfile) Dir() string

Dir returns the lockfile's directory.

func (*Lockfile) Save

func (l *Lockfile) Save() error

Save writes the lockfile atomically (temporary file + rename, mode 0644).

type Ref

type Ref struct {
	// Raw is the reference exactly as written.
	Raw  string
	Kind Kind
	// Name is the std pipe name, the builtin `<runtime>/<name>`, the npm
	// package, the registry `<publisher>/<name>`, or the pypi/cran/oci payload.
	Name string
	// Range is the version range (std, npm, registry); "" = any.
	Range string
	// Path is the local path (Local).
	Path string
	// URL is the repository URL (Git) or the remote pipe URL (HTTP).
	URL string
	// GitRef is the branch, tag or commit of a git reference ("" = default
	// branch).
	GitRef string
	// Subpath is the manifest sub-path inside an npm package or git repo.
	Subpath string
	// PipeID is the remote pipe id of an HTTP reference.
	PipeID string
}

Ref is a parsed pipe reference.

func ParseRef

func ParseRef(ref string) (Ref, error)

ParseRef parses a pipe reference. Errors are E_REF (malformed) or E_PATH (unsafe sub-path).

type Remote

type Remote struct {
	URL string
	// Manifest is built from the served definition (no attribution check).
	Manifest *manifest.Manifest
	// Revision is the revision the server reports ("" if none).
	Revision string
	// Integrity is sha256 over the exact served response body.
	Integrity string
	// Body is the served definition.
	Body []byte
}

Remote is the fetched definition of a remote HTTP pipe.

type Resolver

type Resolver struct {
	// Registry provides `std:` and `builtin:` pipes.
	Registry *adapter.Registry
	// Root is the project root: local references may not escape it (E_PATH).
	// A local reference inside a fetched package may not escape that package.
	// Empty means unrestricted.
	Root string
	// CacheDir holds fetched packages (default: Root/.openflange/cache).
	CacheDir string
	// AllowNetwork permits npm installs, git fetches and HTTP requests. When
	// false only the cache is used.
	AllowNetwork bool
	// Index lazily loads the registry index for `<publisher>/<name>`
	// references. Nil means registry references report E_UNSUPPORTED (unless
	// they are pinned by the lockfile).
	Index func(ctx context.Context) (*registry.Index, error)
	// Lock is the project's lockfile, if any. Its entries pin what npm, git
	// and registry references resolve to.
	Lock *Lockfile
	// Locked enforces the lockfile: every reference must have an entry and
	// its content must hash to the locked integrity (E_LOCK otherwise).
	Locked bool
	// AllowInsecureGit permits file:// git URLs. For tests only.
	AllowInsecureGit bool
	// NpmPath and GitPath override the tools (default: looked up on PATH when
	// first needed).
	NpmPath, GitPath string
	// Timeout bounds one fetch (default DefaultTimeout).
	Timeout time.Duration
	// Offline forbids every network request, including the fetch of a remote
	// pipe's definition that a locked run otherwise performs (lock/v0.1 §6).
	Offline bool
	// Credentials returns the bearer token for the server of a remote pipe,
	// identified by its lower-case "host:port". May be nil. Tokens are only
	// ever sent over HTTPS (or to loopback) and never across a redirect.
	Credentials func(hostport string) (token string, ok bool)
	// Warn receives non-fatal messages (deprecations, references resolved
	// outside the lockfile). May be nil; calls may be concurrent.
	Warn func(msg string)
	// contains filtered or unexported fields
}

Resolver resolves pipe references for a project. It implements pipeline.Resolver and is safe for concurrent use. Configure the exported fields before first use and do not change them afterwards.

func (*Resolver) FetchRemote

func (r *Resolver) FetchRemote(ctx context.Context, rawURL string) (*Remote, error)

FetchRemote fetches and validates the definition of a remote HTTP pipe (`GET {base}/pipes/{id}`) with bounded, SSRF-safe HTTP. The returned manifest is the contract as the server describes it; Resolve turns it into a pipe that the HTTP Pipe Protocol adapter executes on that server.

func (*Resolver) GitCloneArgs

func (r *Resolver) GitCloneArgs(url, ref, dest string) []string

GitCloneArgs returns the git argument vector for a shallow clone of url at ref ("" = default branch) into dest.

func (*Resolver) Key

func (r *Resolver) Key(ref, fromDir string) string

Key returns the lockfile key of a reference written in a file of fromDir.

func (*Resolver) LocalKey

func (r *Resolver) LocalKey(p string) string

LocalKey returns the lock key of the local pipe at the absolute path p: its path relative to the project root, beginning with `./` or `../`, or — inside a fetched package — relative to that package's root.

func (*Resolver) LockAll

func (r *Resolver) LockAll(ctx context.Context, targets []string) (*Lockfile, error)

LockAll resolves every target (pipe directories, manifest files, pipeline files, or references) and, transitively, every `pipe:` reference of every pipeline file involved, and returns a complete lockfile for them. Existing entries of r.Lock stay pinned (npm versions, git commits, registry resolutions are not moved); local pipes are re-hashed; entries that are no longer referenced are pruned; `x-` keys are preserved. Composite cycles are E_CYCLE. All problems are returned together as an errs.List. Nothing is written: call Save on the result.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, ref, fromDir string) (*pipeline.Resolved, error)

Resolve implements pipeline.Resolver. With Locked set, the reference must be in the lockfile and its content must match the locked integrity. A remote HTTP pipe (`https://host/base/pipes/<id>`) resolves to its served definition, bound to an `http` implementation on that server; a locked run still fetches the definition, because its integrity is what the lockfile pins (lock/v0.1 §6).

func (*Resolver) Update

func (r *Resolver) Update(ctx context.Context, targets []string, refs ...string) (*Lockfile, error)

Update is LockAll, except that the named references (lock keys, or references as written) and everything reachable through them are re-resolved to the newest versions their references allow. Without refs every entry is re-resolved.

func (*Resolver) Verify

func (r *Resolver) Verify(ctx context.Context, targets []string) error

Verify checks, before anything runs, that the targets and everything they reference are in r.Lock and hash to their locked integrity (lock/v0.1 §6). A local target pipe is itself checked under its normalised key. Every violation is reported as E_LOCK in one errs.List.

Jump to

Keyboard shortcuts

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