keycontract

package
v6.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 14 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

Index

Constants

View Source
const (
	ContractVersionV01 = "0.1"
	ContractVersionV02 = "0.2"
)
View Source
const (
	// TransformTrim removes leading and trailing contract whitespace using the
	// explicit codepoint set documented in the v0.1 sidecar spec.
	TransformTrim = "trim"
	// TransformWildcardEmpty maps the empty string to "*". It does not trim by itself;
	// use TransformTrim before it when whitespace should be ignored.
	TransformWildcardEmpty = "wildcard_empty"
	// TransformLowercase applies ASCII-only lowercase. It does not use locale or
	// Unicode case folding; bytes outside A-Z are unchanged.
	TransformLowercase = "lowercase"
	// TransformURLEncode percent-encodes UTF-8 bytes with uppercase hex,
	// leaving only RFC 3986 unreserved bytes unchanged.
	TransformURLEncode = "url_encode"
)
View Source
const ContractVersion = "0.1"

ContractVersion is the original sidecar version supported by TableTheory.

Variables

This section is empty.

Functions

func DerivedKeyNames

func DerivedKeyNames(contract *Contract) []string

DerivedKeyNames returns sorted derived-key names for diagnostics.

func Evaluate

func Evaluate(contract *Contract, name string, input map[string]any) (string, error)

Evaluate finds and evaluates a named derived key in a contract.

func EvaluateDerivedKey

func EvaluateDerivedKey(key DerivedKey, input map[string]any) (string, error)

EvaluateDerivedKey evaluates one derived-key template. Output bytes are solely determined by the contract, input scalar values, and ordered transforms.

func GenerateTypeScript

func GenerateTypeScript(contract *Contract, opts GenerateTypeScriptOptions) (string, error)

GenerateTypeScript emits a TypeScript helper module for a sidecar contract.

func MarshalJSONStable

func MarshalJSONStable(contract *Contract) ([]byte, error)

MarshalJSONStable returns a deterministic JSON rendering suitable for generated helper modules and golden comparisons.

func VerifyFixtures

func VerifyFixtures(contract *Contract) error

VerifyFixtures evaluates all embedded fixtures and returns the first mismatch.

Types

type Contract

type Contract struct {
	Version     string          `yaml:"tabletheory_model_contract_version" json:"tabletheory_model_contract_version"`
	Namespace   string          `yaml:"namespace,omitempty" json:"namespace,omitempty"`
	DMSVersion  string          `yaml:"dms_version,omitempty" json:"dms_version,omitempty"`
	Models      []ModelContract `yaml:"models,omitempty" json:"models,omitempty"`
	DerivedKeys []DerivedKey    `yaml:"derived_keys" json:"derived_keys"`
}

Contract is the language-neutral TableTheory model-contract sidecar. It is intentionally separate from DMS v0.2 core so derived keys can be adopted additively without changing DMS model semantics.

func LoadFile

func LoadFile(path string) (*Contract, error)

LoadFile reads and parses a tabletheory_model_contract sidecar.

func ParseDocument

func ParseDocument(data []byte) (*Contract, error)

ParseDocument parses YAML or JSON tabletheory_model_contract sidecars.

func (*Contract) Validate

func (c *Contract) Validate() error

Validate checks structural sidecar invariants without interpreting product semantics. Product-specific authorization or route-token rules do not belong here.

type DerivedKey

type DerivedKey struct {
	Name        string    `yaml:"name" json:"name"`
	Helper      string    `yaml:"helper,omitempty" json:"helper,omitempty"`
	Description string    `yaml:"description,omitempty" json:"description,omitempty"`
	Join        string    `yaml:"join" json:"join"`
	Inputs      []Input   `yaml:"inputs,omitempty" json:"inputs,omitempty"`
	Segments    []Segment `yaml:"segments" json:"segments"`
	Fixtures    []Fixture `yaml:"fixtures,omitempty" json:"fixtures,omitempty"`
}

DerivedKey describes one derived key formula. The formula is product-agnostic: it is an ordered segment template plus input names, transforms, defaults, and omission rules.

func FindDerivedKey

func FindDerivedKey(contract *Contract, name string) (*DerivedKey, bool)

FindDerivedKey returns a derived-key definition by name.

type Fixture

type Fixture struct {
	Name        string         `yaml:"name" json:"name"`
	Description string         `yaml:"description,omitempty" json:"description,omitempty"`
	Input       map[string]any `yaml:"input" json:"input"`
	Expect      string         `yaml:"expect" json:"expect"`
}

Fixture is a golden input/output case for a derived key.

type GenerateTypeScriptOptions

type GenerateTypeScriptOptions struct {
	RuntimeImport string
}

GenerateTypeScriptOptions controls generated TypeScript helper output.

type Input

type Input struct {
	Name     string `yaml:"name" json:"name"`
	TSName   string `yaml:"ts_name,omitempty" json:"ts_name,omitempty"`
	Type     string `yaml:"type,omitempty" json:"type,omitempty"`
	Optional bool   `yaml:"optional,omitempty" json:"optional,omitempty"`
}

Input declares a named evaluator input and optional TypeScript helper metadata.

type ModelContract

type ModelContract struct {
	Name        string   `yaml:"name" json:"name"`
	DMSModel    string   `yaml:"dms_model,omitempty" json:"dms_model,omitempty"`
	Table       string   `yaml:"table,omitempty" json:"table,omitempty"`
	DerivedKeys []string `yaml:"derived_keys,omitempty" json:"derived_keys,omitempty"`
}

ModelContract links optional sidecar metadata to a DMS model. Runtime evaluation does not require this section; consumers can use it for discovery.

type OmitWhen

type OmitWhen struct {
	Values  []string `yaml:"values,omitempty" json:"values,omitempty"`
	Empty   bool     `yaml:"empty,omitempty" json:"empty,omitempty"`
	Default bool     `yaml:"default,omitempty" json:"default,omitempty"`
}

OmitWhen controls conditional omission after transforms and defaults have been applied. Comparisons are exact string comparisons.

type Segment

type Segment struct {
	Literal    *string     `yaml:"literal,omitempty" json:"literal,omitempty"`
	Default    *string     `yaml:"default,omitempty" json:"default,omitempty"`
	Value      ValueSource `yaml:"value,omitempty" json:"value,omitempty"`
	Name       string      `yaml:"name,omitempty" json:"name,omitempty"`
	Prefix     string      `yaml:"prefix,omitempty" json:"prefix,omitempty"`
	Suffix     string      `yaml:"suffix,omitempty" json:"suffix,omitempty"`
	Transforms []string    `yaml:"transforms,omitempty" json:"transforms,omitempty"`
	OmitWhen   OmitWhen    `yaml:"omit_when,omitempty" json:"omit_when,omitempty"`
	Optional   bool        `yaml:"optional,omitempty" json:"optional,omitempty"`
}

Segment is one ordered piece of a derived key.

type ValueSource

type ValueSource struct {
	Literal *string `yaml:"literal,omitempty" json:"literal,omitempty"`
	Input   string  `yaml:"input,omitempty" json:"input,omitempty"`
}

ValueSource identifies where a segment obtains its value. Use exactly one of input or literal unless the segment-level literal shortcut is used.

Jump to

Keyboard shortcuts

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