contract

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package contract holds the projection contract data types and their shape validation (ADR-103). It is a leaf — it imports only pkg/types and vocabulary — so the payload registry can hold a registered type's contracts without importing pkg/projection, which reaches graph, message, and natsclient. pkg/projection re-exports every name here as an alias, so a contract literal written against pkg/projection compiles unchanged.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidContract = errors.New("projection: invalid contract")

ErrInvalidContract identifies a projection contract rejected before use.

Functions

func ValidateContracts

func ValidateContracts(contracts []Contract) error

ValidateContracts validates a complete, uniquely named contract set.

Types

type Contract

type Contract struct {
	Name            string           `json:"name"`
	MessageType     semtypes.Type    `json:"message_type"`
	EntityPattern   string           `json:"entity_pattern"`
	Groups          []PredicateGroup `json:"groups,omitempty"`
	BirthPredicates []string         `json:"birth_predicates,omitempty"`
	IndexingProfile string           `json:"indexing_profile,omitempty"`
}

Contract declares the graph shape emitted by one projection. It validates caller intent; it does not reserve predicates or prevent other writers.

MessageType is the registered payload type the contract is bound to, carried structured (on the wire as {"domain","category","version"}, the same shape EntityState.message_type has) so nothing parses a key. A contract registered with a payload type inherits that type when the field is zero; a contract naming another type is a registration error.

func (Contract) Clone

func (c Contract) Clone() Contract

Clone returns a copy of c whose groups, group predicates and birth predicates share no backing array with c, so a holder can keep it while the caller goes on changing its own.

func (Contract) Validate

func (c Contract) Validate() error

Validate checks one projection contract without consulting runtime state. Every predicate must be declared in the vocabulary.

func (Contract) ValidateShape

func (c Contract) ValidateShape() error

ValidateShape checks everything Validate does except predicate declaration (name, entity pattern, groups, birth predicates, profile). The payload registry uses it so a contract can be registered before the vocabulary is populated; predicate declaration stays at mutation-client construction.

type PredicateGroup

type PredicateGroup struct {
	Name       string    `json:"name"`
	Mode       WriteMode `json:"mode"`
	Predicates []string  `json:"predicates"`
}

PredicateGroup names predicates changed together through one operation.

type WriteMode

type WriteMode string

WriteMode states whether a predicate group is replaced as a complete set or appended as evidence. It is operation intent, not semantic ownership.

const (
	// ModeReconcile declares complete-set predicate reconciliation.
	ModeReconcile WriteMode = "reconcile"
	// ModeAppend declares set-valued predicate addition.
	ModeAppend WriteMode = "append"
)

Jump to

Keyboard shortcuts

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