Compose
in package
Composition orchestrator (SPEC §5, G5) — the parser's FIRST pass.
Byte-for-byte port of validator-ts/src/compose/compose.ts.
Resolution order (SPEC §5, verbatim): (1) $ref — expand file/path base, recursively (nested $ref included) into a single properties base. (2) $patch — overlay add/remove/replace and deep-path set on that base. (3) the result is the equivalent SINGLE SPEC (composition keys eliminated). (4) the field layer (validate/design/behavior/options) then applies to it.
G5 (SPEC §2): the parser expands composition first, producing a single spec, BEFORE applying the field layer — without composition a $ref-using spec cannot even be loaded. So composition is a pre-processing pass that runs BEFORE validation/render, not a validation step.
Composition priority: $ref = base (first), $patch = overlay (later) — base is laid down, patch overrides.
composeProperties is the entry point: it operates on a properties map (the composition entry point, SPEC §2) where $ref/$patch may sit alongside named child fields. composeSpec recurses the whole field tree so a $ref nested inside any child properties is expanded too. Both throw a ComposeLoadError for any unresolved composition (never valid:true).
Table of Contents
Methods
- properties() : array<string, mixed>
- Compose a properties map: expand $ref to a base, overlay $patch, return the single (composition-free) properties map. Named sibling keys follow declaration order — a key declared after $ref overrides the base; a key declared before it is overridden by the base.
- spec() : array<string, mixed>
- Compose a full field spec: expand a field-level $ref/$patch, then recurse into its properties (which may itself compose). Returns the single spec.
Methods
properties()
Compose a properties map: expand $ref to a base, overlay $patch, return the single (composition-free) properties map. Named sibling keys follow declaration order — a key declared after $ref overrides the base; a key declared before it is overridden by the base.
public
static properties(array<string, mixed> $properties, FileLoader $loader[, string $basepath = '' ]) : array<string, mixed>
Parameters
- $properties : array<string, mixed>
- $loader : FileLoader
- $basepath : string = ''
Return values
array<string, mixed>spec()
Compose a full field spec: expand a field-level $ref/$patch, then recurse into its properties (which may itself compose). Returns the single spec.
public
static spec(array<string, mixed> $spec, FileLoader $loader[, string $basepath = '' ]) : array<string, mixed>
Parameters
- $spec : array<string, mixed>
- $loader : FileLoader
- $basepath : string = ''