namespace

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package namespace provides the isolation boundary for schemas. Each namespace maintains independent current and staged snapshots, with lock-free reads via atomic pointers and serialized writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Namespace

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

Namespace is an isolation boundary containing schemas.

Schemas within a namespace can import each other's files; cross-namespace imports are not allowed. However, type *resolution* may walk the namespace hierarchy via the parent pointer (see SetParent / Parent / Chain). Resolution chaining is distinct from imports: the chain is consulted on lookup miss, but no source file ever names another namespace. See docs/design/namespace-hierarchy.md for the full design.

Phase 1 ships the parent pointer and chain accessor; phase 2 wires the compiler and resolver to actually walk the chain.

func (*Namespace) AllCurrent

func (ns *Namespace) AllCurrent() map[string]*snapshot.Snapshot

AllCurrent returns a map of schema ID → current snapshot for all schemas that have a current version. Used for building the namespace resolver during compilation.

func (*Namespace) Chain added in v0.71.0

func (ns *Namespace) Chain() []*Namespace

Chain returns the resolution chain starting with this namespace and walking parent pointers to the root. The slice is ordered nearest-first (this namespace at index 0). Walks are bounded by chainMaxDepth as a defensive guard against cycles; the implicit __builtins__ and Google WKT tiers are not included (they are appended by the resolver).

Safe for concurrent use; the snapshot reflects parent pointers as seen at the moment of each Load.

func (*Namespace) Current

func (ns *Namespace) Current(schemaID string) *snapshot.Snapshot

Current returns the current snapshot for a schema, or nil if no version has been promoted.

func (*Namespace) DiscardStaging

func (ns *Namespace) DiscardStaging()

DiscardStaging clears all staged snapshots.

func (*Namespace) ID

func (ns *Namespace) ID() string

ID returns the namespace identifier.

func (*Namespace) Parent added in v0.71.0

func (ns *Namespace) Parent() *Namespace

Parent returns the namespace's parent in the resolution chain, or nil when this namespace is a root (resolution then falls back to the implicit __builtins__ namespace and then Google WKT — see decision D4). Safe for concurrent use.

func (*Namespace) Promote

func (ns *Namespace) Promote() []string

Promote atomically moves all staged snapshots to current. Returns the schema IDs that were promoted.

func (*Namespace) ProposedView

func (ns *Namespace) ProposedView() map[string]*snapshot.Snapshot

ProposedView returns the proposed state: staged if available, otherwise current. This is the view used for compiling against the staging environment.

func (*Namespace) SchemaIDs

func (ns *Namespace) SchemaIDs() []string

SchemaIDs returns all schema IDs in this namespace.

func (*Namespace) SetCurrent

func (ns *Namespace) SetCurrent(schemaID string, snap *snapshot.Snapshot) *snapshot.Snapshot

SetCurrent atomically swaps the current snapshot for a schema. Returns the previous snapshot (may be nil).

func (*Namespace) SetParent added in v0.71.0

func (ns *Namespace) SetParent(parent *Namespace)

SetParent atomically sets the resolution-chain parent. Pass nil to clear it. Safe for concurrent use, but callers are responsible for preventing cycles — the in-memory model trusts whatever the store layer admitted (see SetNamespaceParent in the store package, which enforces acyclicity via recursive CTE).

func (*Namespace) SetStaged

func (ns *Namespace) SetStaged(schemaID string, snap *snapshot.Snapshot)

SetStaged sets the staged snapshot for a schema.

func (*Namespace) Staged

func (ns *Namespace) Staged(schemaID string) *snapshot.Snapshot

Staged returns the staged snapshot for a schema, or nil if nothing is staged.

func (*Namespace) String

func (ns *Namespace) String() string

String returns a human-readable representation.

type Registry

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

Registry manages all namespaces. It is the top-level entry point for looking up and creating namespaces.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new namespace registry.

func (*Registry) Get

func (r *Registry) Get(id string) *Namespace

Get returns the namespace with the given ID, or nil if it doesn't exist.

func (*Registry) GetOrCreate

func (r *Registry) GetOrCreate(id string) *Namespace

GetOrCreate returns an existing namespace or creates a new one.

func (*Registry) Range

func (r *Registry) Range(fn func(ns *Namespace) bool)

Range iterates over all namespaces.

Jump to

Keyboard shortcuts

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