catalog

package
v0.3.42 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCatalogNotFound = errors.New("catalog not found")
	// ErrCatalogNotManaged is returned by the lifecycle methods when the
	// Service sits over a provider that is not a CatalogManager — a static
	// schema, or a read-only view of one someone else writes.
	ErrCatalogNotManaged = errors.New("catalog provider does not manage catalogs")
	// ErrSchemaInvalid marks a load that failed because the source's OWN
	// declaration does not validate — not because the source could not be
	// reached. The boot path distinguishes the two: a schema a deployment can
	// fix by editing SDL must not cost it the stored model (and with it the
	// annotation overlay's anchors), so such a source is suspended rather than
	// removed.
	ErrSchemaInvalid = errors.New("catalog schema is invalid")
)
View Source
var ErrNoLogicalModel = errors.New("catalog provider has no logical model")

ErrNoLogicalModel is returned when a Provider cannot answer logical-model queries. The catalog storage always can; a static schema (a test fixture, a hand-assembled prelude) has no logical model behind it at all.

Functions

func QueryRequestInfo

func QueryRequestInfo(ss ast.SelectionSet) ([]sdl.QueryRequest, sdl.QueryType)

QueryRequestInfo recursively classifies an operation's selection set into typed query requests (meta, data, mutation, function, jq, h3).

Types

type Catalog

type Catalog = sources.Catalog

Aliases — canonical definitions live in pkg/catalog/sources/.

type CatalogChecker added in v0.3.42

type CatalogChecker interface {
	ExistsCatalog(name string) bool
}

CatalogChecker reports whether a catalog currently has an active engine. It is the gate the hard-remove UDF gets from the engine (Service implements it), declared here so both catalog storages take the same type.

type CatalogManager

type CatalogManager interface {
	// Load/Unload catalogs (for dynamic schema updates)
	AddCatalog(ctx context.Context, name string, catalog Catalog) error
	RemoveCatalog(ctx context.Context, name string) error
	ExistsCatalog(name string) bool
	// ReloadCatalog re-reads the source and recompiles it in full. The
	// storage's version gate decides whether anything is actually rewritten.
	ReloadCatalog(ctx context.Context, name string) error
	// SuspendCatalog removes a catalog from the active schema without deleting
	// the registration. Used when a hugr-app becomes unreachable.
	SuspendCatalog(ctx context.Context, name string) error
	// ReactivateCatalog re-compiles and re-applies a previously suspended catalog.
	// The catalog source must be updated before calling this.
	ReactivateCatalog(ctx context.Context, name string, catalog Catalog) error
	// IsSuspended returns true if the named catalog exists but is suspended.
	IsSuspended(name string) bool
}

type DataSourceInfo added in v0.3.42

type DataSourceInfo struct {
	Name            string
	Engine          string // the source's engine type string (@catalog engine)
	Description     string
	LongDescription string
	ReadOnly        bool
	AsModule        bool
	IsExtension     bool
	Modules         []string // modules this source contributes members to, sorted; "" = root
}

DataSourceInfo describes one data source as a LOGICAL entity: what it is and what it contributes, never how to connect to it (the registry's type/path are connection details — path is a DSN — and stay out of introspection).

The flags were pointers while a second catalog storage existed that could not recover them from a compiled schema and had to report "not recorded". The storage records all three (data_source_meta, NOT NULL), so they are plain facts.

type ExtensionCatalog

type ExtensionCatalog = sources.ExtensionCatalog

type FunctionEntry added in v0.3.42

type FunctionEntry struct {
	Field      *ast.FieldDefinition
	Kind       sdl.ModuleObjectType // ModuleFunction | ModuleMutationFunction | ModuleSubscription
	Module     string
	DataSource string
	IsTable    bool
	// LongDescription is the curated long form; empty without a curation
	// layer. The short description lives on Field, already overlaid.
	LongDescription string
}

FunctionEntry describes one callable member of a module: a query function, a mutation function, or a subscription field.

type LogicalModel added in v0.3.42

type LogicalModel interface {
	// Module resolves a module by full dotted name ("" = root); nil when absent.
	Module(ctx context.Context, name string) *ModuleInfo
	// Modules iterates the DIRECT child modules of parent.
	Modules(ctx context.Context, parent string) iter.Seq[*ModuleInfo]
	// DataObject resolves a data object by GraphQL type name; nil for
	// non-data-object types.
	DataObject(ctx context.Context, name string) *sdl.Object
	// DataObjects iterates the data objects that are members of a module.
	DataObjects(ctx context.Context, module string) iter.Seq[*sdl.Object]
	// Function resolves a callable member of a module by field name, probing
	// the function, mutation-function and subscription roots in that order.
	Function(ctx context.Context, module, name string) *FunctionEntry
	// Functions iterates all callable members of a module (all three kinds).
	Functions(ctx context.Context, module string) iter.Seq[*FunctionEntry]
	// Relations iterates the logical edges of a data object, both directions.
	Relations(ctx context.Context, object string) iter.Seq[*RelationInfo]
	// DataSource resolves an ACTIVE data source by name; nil when absent.
	DataSource(ctx context.Context, name string) *DataSourceInfo
	// DataSources iterates the active data sources, ordered by name.
	DataSources(ctx context.Context) iter.Seq[*DataSourceInfo]
	// Type resolves a GraphQL type definition by name; nil when absent.
	// (Entity storage: the ForName resolution chain.)
	Type(ctx context.Context, name string) *ast.Definition
	// SourceTypes iterates the residual base types DEFINED BY SOURCES —
	// structural objects, inputs (incl. @args), enums, interfaces, unions
	// that are not data objects, module roots, or compiler-generated
	// helpers (filters, mutation inputs, aggregations). This is exactly
	// the content of the future entity-storage types table.
	SourceTypes(ctx context.Context) iter.Seq2[string, *ast.Definition]
	// SystemTypes iterates engine-defined types: scalars, the introspection
	// and hugr system SDL, scalar filter/aggregation inputs — the future
	// binary-owned static prelude. Compiler-DERIVED types (filters,
	// aggregations, mutation inputs, module roots) belong to neither set.
	SystemTypes(ctx context.Context) iter.Seq2[string, *ast.Definition]
}

LogicalModel is the narrow logical-model surface consumed by the _catalog introspection resolvers. It returns the UNFILTERED model — permission filtering is applied by consumers from the request context. The catalog storage implements it natively over the catalog.* tables.

func LogicalModelFromProvider added in v0.3.42

func LogicalModelFromProvider(p Provider) (LogicalModel, error)

LogicalModelFromProvider returns the provider's logical model. The catalog storage implements LogicalModel natively over the catalog.* tables — this is the seam that lets a consumer take a Provider and ask logical questions of it without importing the storage.

type Manager

type Manager interface {
	// Catalog lifecycle
	AddCatalog(ctx context.Context, name string, catalog Catalog) error
	RemoveCatalog(ctx context.Context, name string) error
	ExistsCatalog(name string) bool
	ReloadCatalog(ctx context.Context, name string) error
	Engine(name string) (engines.Engine, error)
	// RegisterEngine adds an engine for planner routing without compilation.
	// Used by cluster workers where schema is already compiled in CoreDB.
	RegisterEngine(name string, engine engines.Engine)
	// SuspendCatalog marks a catalog as suspended (unavailable).
	SuspendCatalog(ctx context.Context, name string) error
	// ReactivateCatalog reactivates a suspended catalog with a new source.
	ReactivateCatalog(ctx context.Context, name string, catalog Catalog) error
	// IsSuspended returns true if the catalog is suspended.
	IsSuspended(name string) bool
}

type ModuleInfo added in v0.3.42

type ModuleInfo struct {
	Name string // full dotted name; "" for the root module
	// Description is the CURATED text where a curation exists, the stored one
	// otherwise — the same overlay the entity views apply. LongDescription
	// exists only as curation and is empty without one.
	Description     string
	LongDescription string
	// RootTypes maps each PRESENT root kind to its type name
	// (sdl.ModuleTypeName). Key presence carries the information — a module
	// exists when at least one kind is present; the definition is resolved
	// LAZILY via Type(ctx, name) only when a consumer actually needs it (the
	// entity store synthesizes root types on demand — building five of them
	// per module lookup would defeat the on-the-fly model).
	RootTypes   map[sdl.ModuleObjectType]string
	DataSources []string // distinct data sources of direct members, sorted
}

ModuleInfo describes one node of the logical module tree.

type Operation

type Operation struct {
	// Enriched AST operation definition
	Definition *ast.OperationDefinition

	// All fragments from the document (needed by the planner for FragmentSpread resolution)
	Fragments ast.FragmentDefinitionList

	// Transformed variables
	Variables map[string]any

	// Classified top-level query requests from the selection set
	Queries []sdl.QueryRequest

	// Combined bitmask of all query types in the operation
	QueryType sdl.QueryType
}

Operation is the result of ParseQuery. Contains an enriched AST operation ready for the planner.

func ParseQuery

func ParseQuery(ctx context.Context, p Provider, query string, vars map[string]any, opts ...ParseOption) (*Operation, error)

ParseQuery is a universal pipeline for parsing and validating GraphQL queries.

Pipeline:

  1. VariableTransformer.TransformVariables(ctx, vars) — if set
  2. parser.ParseQuery(query) — gqlparser lexer + parser
  3. validator.Validate(ctx, provider, doc) — our Walker: enrichment + validation + permissions
  4. selectOperation(operations, operationName) — select operation
  5. QueryRequestInfo(op.SelectionSet) — classify queries

Returns: enriched Operation with filled field.Definition, field.ObjectDefinition etc.

type ParseOption

type ParseOption func(*parseConfig)

ParseOption configures ParseQuery.

func WithOperationName

func WithOperationName(name string) ParseOption

WithOperationName sets the operation name to select from the document. Default: "" (single operation).

func WithValidator

func WithValidator(v *validator.Validator) ParseOption

WithValidator sets the validator for ParseQuery. Default: validator.New(rules.DefaultRules()...).

func WithVariableTransformer

func WithVariableTransformer(t VariableTransformer) ParseOption

WithVariableTransformer sets the variable transformer. Default: nil (no transformation).

type Provider

type Provider base.Provider

type Querier

type Querier interface {
	Query(ctx context.Context, query string, vars map[string]any) (*types.Response, error)
}

Querier executes GraphQL queries. Used by VariableTransformer for the jq queryHugr function.

type RelationDirection added in v0.3.42

type RelationDirection string
const (
	RelationForward RelationDirection = "FORWARD"
	RelationBack    RelationDirection = "BACK"
)

type RelationInfo added in v0.3.42

type RelationInfo struct {
	Name            string
	Direction       RelationDirection
	Kind            RelationKind
	FieldName       string // the field ON the viewed object materializing the edge
	Description     string // per-endpoint description (same perspective as FieldName)
	DataObject      string // far data object type name (M2M: the far leg, not the junction)
	Through         string // M2M junction type name; "" otherwise
	SourceKeys      []string
	DestinationKeys []string
	DataSource      string // declaring data source
}

RelationInfo is one perspective on a logical edge between two data objects. FK and M2M edges are visible from both ends (FORWARD from the declaring side, BACK from the referenced side); JOIN edges are one-directional.

type RelationKind added in v0.3.42

type RelationKind string
const (
	RelationFK   RelationKind = "FK"
	RelationM2M  RelationKind = "M2M"
	RelationJoin RelationKind = "JOIN"
)

type ReloadableCatalog

type ReloadableCatalog = sources.ReloadableCatalog

type ReplacingCatalogManager added in v0.3.42

type ReplacingCatalogManager interface {
	ReplacesCatalogOnAdd() bool
}

ReplacingCatalogManager is optionally implemented by a CatalogManager whose AddCatalog REPLACES a catalog's stored schema in full: whatever the source stopped declaring is gone after the write, without a destructive pre-step.

It decides how a RELOAD of a still-attached source is staged. Against such a manager the source can be detached softly — the catalog is suspended, its rows survive, and the re-add's version gate decides whether anything is rewritten at all, so reloading an unchanged source costs a flag flip instead of a full recompile (and, with an embedder, a full re-embedding).

The catalog storage answers true: writeSource replaces a source's rows wholesale inside one transaction, so an entity the source stopped declaring cannot survive an add. A manager that cannot promise that must keep being dropped before it is re-added — which is why this is an optional interface and not an assumption.

type Service

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

Service holds dependencies for query parsing: Provider, Validator, VariableTransformer. Thread-safe (Provider and Validator are immutable after creation).

func NewService

func NewService(p Provider, opts ...ServiceOption) *Service

NewService creates a Service with the given provider and options.

The provider doubles as the catalog manager when it is one — the catalog storage is. Over a provider that is not (a static schema in a test, a cluster worker's read-only view), the lifecycle methods report ErrCatalogNotManaged and everything on the read path works unchanged.

func (*Service) AddCatalog

func (s *Service) AddCatalog(ctx context.Context, name string, catalog Catalog) error

func (*Service) Definitions

func (s *Service) Definitions(ctx context.Context) iter.Seq[*ast.Definition]

func (*Service) Description

func (s *Service) Description(ctx context.Context) string

func (*Service) DirectiveDefinitions

func (s *Service) DirectiveDefinitions(ctx context.Context) iter.Seq2[string, *ast.DirectiveDefinition]

func (*Service) DirectiveForName

func (s *Service) DirectiveForName(ctx context.Context, name string) *ast.DirectiveDefinition

func (*Service) Engine

func (s *Service) Engine(name string) (engines.Engine, error)

func (*Service) ExistsCatalog

func (s *Service) ExistsCatalog(name string) bool

func (*Service) ForName

func (s *Service) ForName(ctx context.Context, name string) *ast.Definition

func (*Service) Implements

func (s *Service) Implements(ctx context.Context, name string) iter.Seq[*ast.Definition]

func (*Service) IsSuspended added in v0.3.11

func (s *Service) IsSuspended(name string) bool

func (*Service) MutationType

func (s *Service) MutationType(ctx context.Context) *ast.Definition

func (*Service) ParseQuery

func (s *Service) ParseQuery(ctx context.Context, query string, vars map[string]any, operationName string) (*Operation, error)

ParseQuery parses a query using the service's dependencies.

func (*Service) PossibleTypes

func (s *Service) PossibleTypes(ctx context.Context, name string) iter.Seq[*ast.Definition]

func (*Service) Provider

func (s *Service) Provider() Provider

Provider returns the current Provider.

func (*Service) QueryType

func (s *Service) QueryType(ctx context.Context) *ast.Definition

func (*Service) ReactivateCatalog added in v0.3.11

func (s *Service) ReactivateCatalog(ctx context.Context, name string, catalog Catalog) error

func (*Service) RegisterEngine

func (s *Service) RegisterEngine(name string, engine engines.Engine)

RegisterEngine adds an engine reference for planner routing without going through catalog compilation. Used in read-only mode where schemas are already persisted by the writer node.

func (*Service) ReloadCatalog

func (s *Service) ReloadCatalog(ctx context.Context, name string) error

func (*Service) RemoveCatalog

func (s *Service) RemoveCatalog(ctx context.Context, name string) error

func (*Service) ReplacesCatalogOnAdd added in v0.3.42

func (s *Service) ReplacesCatalogOnAdd() bool

ReplacesCatalogOnAdd forwards the underlying manager's answer (false when it does not claim the property), so callers staging a reload can ask through the Manager interface — see ReplacingCatalogManager for what it decides.

func (*Service) SchemaProvider

func (s *Service) SchemaProvider() Provider

Schema access

func (*Service) SetProvider

func (s *Service) SetProvider(p Provider)

SetProvider replaces the Provider (e.g. on catalog change). NOT thread-safe — call under external lock.

func (*Service) SetVariableTransformer

func (s *Service) SetVariableTransformer(t VariableTransformer)

SetVariableTransformer sets the variable transformer.

func (*Service) SubscriptionType

func (s *Service) SubscriptionType(ctx context.Context) *ast.Definition

func (*Service) SuspendCatalog added in v0.3.11

func (s *Service) SuspendCatalog(ctx context.Context, name string) error

func (*Service) Types

func (s *Service) Types(ctx context.Context) iter.Seq2[string, *ast.Definition]

func (*Service) ValidateQuery

func (s *Service) ValidateQuery(ctx context.Context, query string) (*ast.QueryDocument, error)

ValidateQuery parses and validates/enriches a query, returning the full QueryDocument. Unlike ParseQuery it does not select an operation or classify queries. Useful when the caller needs to inspect/filter the enriched AST before execution.

type ServiceOption

type ServiceOption func(*Service)

ServiceOption configures a Service.

func WithServiceValidator

func WithServiceValidator(v *validator.Validator) ServiceOption

WithServiceValidator sets the validator for the service.

func WithServiceVarTransformer

func WithServiceVarTransformer(t VariableTransformer) ServiceOption

WithServiceVarTransformer sets the variable transformer for the service.

type VariableTransformer

type VariableTransformer interface {
	TransformVariables(ctx context.Context, vars map[string]any) (map[string]any, error)
}

VariableTransformer transforms query variables before parsing. The primary implementation is jqVariableTransformer (checks _jq key).

func NewJQVariableTransformer

func NewJQVariableTransformer(querier Querier) VariableTransformer

NewJQVariableTransformer creates a VariableTransformer that processes _jq expressions.

Directories

Path Synopsis
Package ingest is the WRITE side of the catalog: it takes one data source's SDL and turns it into the physical model the catalog storage persists.
Package ingest is the WRITE side of the catalog: it takes one data source's SDL and turns it into the physical model the catalog storage persists.
Package store is the entity-storage catalog provider (design 034).
Package store is the entity-storage catalog provider (design 034).

Jump to

Keyboard shortcuts

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