ADL 13 · Part II — Data, composition, and evolution

0.5.1 baseline + 0.6 edition note

Composition: objects, traits, $ref, and $merge

ADL 0.6.0 reference · Review draft 1 · November 14, 2026.

Contents · Source map · Evidence

The 0.6 edition note

This chapter retains the detailed language contract and its source-specific observations. Its chapter number and numbered sections remain stable. The 0.6 additions do not by themselves change this subject’s defaults or supply fresh execution evidence for it.

Reverification should cover reference expansion, merge precedence, and metadata propagation. Use the original examples and evidence links below to recover the earlier test context. The new edition’s source map records this chapter as inherited detail; the current draft does not claim those historical tests were rerun.

Retained reference detail

The numbered sections below are carried from 13-composition.md. Their original baseline and evidence remain attached to the source. Statements about “current” or “checked” behavior in this retained text refer to those original observations unless the edition note explicitly updates them. This is a consolidated draft, not a claim of complete re-verification.

13.1 Scope and authority

Composition lets an author declare a field, a field group, or a resource bundle once and apply it at several use sites. The resulting resource still has ordinary fields, permissions, scopes, indexes, and a state machine. Composition changes how the resource is authored; it does not create a new runtime resource kind.

The inherited body is v0.5.0 Chapter 13 (retired), converted from v0.3.1 Chapter 10. Its first five section subjects remain here. Draft 05 §8 adds traits, §21 governs identity, and §23.4 supplies six trait conformance cases. The signed decision log requires member provenance and ratifies TRAIT_MEMBER_CONFLICT for incompatible trait member types. The later Owner signature supersedes the delivery reports’ earlier “for ratification” status for that particular rule.

ConstructReusable contentApplication
propertiesOne field definitionField $ref
objectsNamed field group$merge, or a nested object’s $ref
traitsResource declarations across several construct kindsResource traits list
extendsDomain derivationOwned by ADL 14

ADL 4 owns file inclusion, environment substitution, and pipeline placement; ADL 10 owns field types and nested values; ADL 11 owns enum binding. ADL 8 owns imports, ADL 9 owns canonical bytes and digests, and ADL 14 owns domain derivation and resource subtyping. A local $ref is not an ADL 7 address, an import locator, or a record reference.

13.2 Reusable properties and objects

Declare reusable definitions in domain.properties and domain.objects. A property supplies one field body; an object supplies a mapping of field names to field bodies. The directive spelling uses the section name without a domain segment. This is a fragment from the complete object example:

properties:
  Email: { type: email, required: true, maxLength: 255 }
objects:
  First:
    shared: { type: string, maxLength: 10 }
    firstOnly: { type: string }
  Second:
    shared: { type: string, maxLength: 999 }
    secondOnly: { type: string }
  Address:
    city: { type: string }
    country: { type: string, maxLength: 2 }

Email, First, and Address are author-defined names. Similarly, Timestamp, SoftDelete, and other familiar field-group names are conventions, not platform-supplied definitions. Define them before relying on them.

The inherited source treats naming style and the presence of a property’s type as advisory. An empty property uses the field default string; this does not demonstrate that the author intended a string. Field constraints are interpreted by the field builder after reuse. Diagnostics may therefore name the resulting resource field rather than the definition site.

Objects are field groups, not trait substitutes carrying permissions or machines. Nested composition of definitions is not a recursive macro system. The checked object containing another $merge does not expand that inner merge. Keep definition bodies flat, and apply their groups at the resource.

13.3 Field references and nested object references

A field $ref substitutes the named definition. Sibling keys override keys in that definition after substitution. For example, this fragment retains Email’s type and maximum length while changing its requirement:

email: { $ref: '#/properties/Email', required: false }
Local pointer formMeaning at an ordinary definition use site
#/properties/NameOne reusable field definition
#/objects/NameA reusable field group; use a group-appropriate position
#/enums/NameEnum expansion into a string field’s member-name list

Enum expansion discards member presentation metadata; use the named binding forms in ADL 11 when labels, colors, icons, and other member metadata matter.

The inherited text calls these JSON Pointers rooted at the document. The checked implementation specifically looks up section/name in normalized domain definition tables: #/domain/properties/Email fails. It also does not decode general JSON Pointer escapes: a~1b fails for a definition named a/b, while the literal remainder a/b is accepted. This limited lookup must not be advertised as a general JSON Pointer implementation.

An external fields.yaml#/properties/Email reference, a #/resources/... reference, and a #/blocks/... reference used as a field definition fail with target-not-found errors. The content-field allowedBlocks position has a separate block-name lookup exception, owned by ADL 30; it does not make a block definition an ordinary field target.

Resolution of a referenced definition is single-level. If property A references property B, using A leaves the inner directive unresolved. The production parser reports Unresolved $ref. A cycle can produce the same error; the diagnostic does not distinguish a cycle from a missing target. AVOID chaining reusable property references. The independent modeller’s selected chain case retains an unresolved directive and only warns during model building, so its successful model construction is not proof of complete resolution.

A $ref may also occupy an entire nested object: block. This fragment uses the canonical component field type from ADL 10:

address:
  type: component
  object:
    $ref: '#/objects/Address'

The whole nested field group is substituted. The converted source’s example used type: object; the checked strict parser rejects that spelling, while component is accepted. This correction does not rename the object: key.

Observed limits. The production resolver accepts the sole nested-block reference above but rejects a nested-block reference with sibling fields and an individual $ref inside an inline nested object. The modeller resolves both of those latter forms. In the accepted baseline, the source retains the nested country’s maxLength: 2, but that constraint is absent from the bound nested field. Composition success does not establish nested validation coverage; ADL 10 records that separate limitation.

13.4 Merge field groups and resolve conflicts

$merge copies object fields into a resource’s object mapping. Its value is either one mapping containing $ref, or an ordered list of such mappings. This fragment applies two groups:

$merge:
  - { $ref: '#/objects/First' }
  - { $ref: '#/objects/Second' }

The inherited rule gives explicit resource fields precedence over merged fields, and gives the first object precedence over later objects. The example resolves shared.maxLength to 10; reversing the list resolves it to 999. An explicit shared: { type: string, required: true } replaces the merged field body and does not inherit either maximum length. This is field replacement, not constraint-by-constraint combination.

Authority conflict to resolve. The converted chapter and Draft 05 §8.2’s promise to preserve object behavior support the inherited first-wins rule. Draft 05 §21.4 nevertheless describes $merge lists as later-wins. Both the production parser and independent modeller execute first-wins in these probes. This draft preserves and labels the inherited rule; it does not silently convert §21.4’s conflicting sentence into a new precedence rule. The legacy revision record also states that the original last-wins prose was changed to match implementation in 2026-05. That history prevents treating the rewritten prose and the same implementation as independent corroboration.

After successful composition, consuming resource fields are expanded and their $ref/$merge directives are gone. Lookup definitions can remain in resolved source; “no directives anywhere in the document” would overstate the checked scanner, which validates the resource section. The source, bound model, emitted schema, and migration projection are distinct surfaces.

Editing a reused object can change every consuming resource at the next submission. The resulting field additions are ordinary resource changes to the migration planner; this chapter does not claim a single atomic migration merely because the author edited one definition. ADL 17 owns evolution and activation semantics.

13.5 Merge fields or nest a value

ChoiceResource shapeChecked storage shapeModeling consequence
$merge a groupSeveral ordinary fieldsSeparate columnsEach field can participate in the ordinary query/index contract
component with objectOne structured fieldOne JSON-bearing columnDo not assume ordinary column indexing or filtering for its members
repeater with objectOrdered collection of structured valuesOne structured-value columnArray and nested validation remain ADL 10 concerns

Use merged fields when the values belong to the resource’s relational shape. Use a nested component when the group is one value the resource carries. Changing between the forms changes the client-visible record shape and can require a storage migration. The inherited blanket “no querying inside JSON” statement is not a claim about every database’s capabilities; this chapter’s probes establish no nested-query API. ADL 15 and ADL 27 own the ADL index and query contracts.

13.6 Declare and apply traits

Declare a named trait under domain.traits; apply it with a resource’s ordered traits: [Timestamped, Reviewable] list. Traits are a 0.5.1 construct, so the complete example declares adl: "0.5.1". Cut -b is the historical delivery assignment, not a value to put in adl.

Draft 05 describes traits as spanning all resource construct kinds. The integrated Phase-13 guide and checked resolver implement a narrower vocabulary:

Trait keyChecked contribution
descriptionDescription of the trait itself, retained with its definition
objectResource field declarations
permissionsOperation rules and owner-field configuration
scopesNamed scopes
indexesOrdered index declarations
stateMachineOne complete machine; flat compatibility input is discussed in §13.9

The checked resolver rejects a trait’s hooks key, even though the broad Draft 05 wording could lead an author to expect it. Treat support for other resource keys as unresolved scope, not as an accepted example. Defining a trait’s description does not set the consuming resource’s description.

Trait application occurs after ordinary directives and before the resource model is built. Traits resolve away from the executable resource declaration; they are not runtime-addressable declarations. Retained model provenance and authoring metadata are explained in §13.11.

A trait MUST NOT apply another trait and takes no parameters. The checked parser rejects unknown names, duplicate application, nested traits, and parameters/params. A duplicate name is reported as TRAIT_CYCLE; this does not imply that recursive trait composition is supported.

The checked directive pass does not expand $ref or $merge supplied inside a trait body. They reach the resource after that pass and fail the unresolved directive check. Use complete field bodies in these trait examples; combining the two composition mechanisms at that position needs implementation work.

13.7 Trait precedence and member compatibility

The trait rules differ from object $merge:

  1. Explicit resource members beat trait contributions.
  2. Among compatible trait members, the later trait in the list wins.
  3. Incompatible member types across traits reject with TRAIT_MEMBER_CONFLICT.
  4. Permissions conjoin, and machines follow their whole-unit rules; neither is an ordinary replaceable field.

The Owner-ratified type-conflict rule narrows Draft 05’s unqualified later-wins sentence. The checked comparison uses the field’s declared type, defaulting an omitted type to string. It is not a general compatibility analysis of nested shapes, constraints, or database types.

The winning field replaces the earlier body. In the checked example, a later status: { type: string, maxLength: 12 } loses the earlier default: draft; reversing those traits restores the default and removes that maximum length. An explicit field wins over a compatible trait field and has explicit origin. Two traits with incompatible types are rejected before the explicit resource overlay, even when the resource also declares that field.

Named scopes follow later-trait then explicit-resource replacement in the checked resolver. Index lists append trait contributions in application order, then explicit indexes. Duplicate indexes remain in the model and produce duplicate CREATE INDEX IF NOT EXISTS statements in the selected SQLite case. Do not infer model-level deduplication from the guide’s comment about DDL deduplication. Full index semantics remain in ADL 15.

13.8 Permission conjunction

For an operation contributed by several traits or by a trait and its resource, every contributing rule must allow. A resource’s explicit rule does not replace a trait restriction. Role alternatives within one rule remain alternatives; the rule contributions themselves are joined by AND.

The example contributes update: [editor] from Reviewable and update: [owner, editor] from Post. Its effective policy is “editor AND (owner OR editor).” These observations use real owner identity against the record’s authorId, not an assumed role named owner:

CallerTrait ruleResource ruleObserved update
Editor, not the ownerAllowsAllows200
Owner with reader roleDeniesAllows403 FORBIDDEN
Reader, not the ownerDeniesDeniesDenied by checker

An explicit empty role list in a contributor denies everyone in the checked conjunction. Combining an AEL rule with a role-list rule preserves both rule types. The preliminary might_allow check can permit a request tentatively before a record is available; its result does not replace final allowed. ADL 21 owns the complete authorization semantics.

The first Phase-13 delivery rewrote permissions to an AEL string. The later guide integration superseded that approach with modeled conjuncts. Resolved source uses internal $all entries; schema output uses all entries and per-contributor origins. Draft 05 §23.4’s (first) && (second) states the conjunction intent; it must not be used as proof that the checked canonical serialization is that exact string. The internal representation is evidence, not an additional authoring form recommended by this chapter.

Alias boundary. The selected trait read: [editor] plus explicit resource get: ["*"] yields a public get policy in the checked model. The parser merges same-spelled keys before applying the read alias. Consequently a trait’s read restriction is not reliably enforced by mixing it with explicit get/list keys. Use consistent operation keys and review the effective policy; the interaction must be reconciled with ADL 21 before publication.

13.9 State machines merge as a unit

A resource has one surviving machine. A trait contributes its machine as an indivisible unit. A resource’s own machine replaces the trait machine completely, including its field binding, states, and transitions. Two traits both contributing machines reject with TRAIT_STATEMACHINE_CONFLICT, naming both contributors; later-wins does not select between machines.

Replacement of the machine does not remove the trait’s separately contributed fields. The checked replacement changes the machine from status to phase and states new/done, while the original status field remains. Authors must review those surviving fields and any permissions/scopes that still refer to the old machine.

Draft 05 §8.1 writes flat trait states and transitions, while the resource grammar uses stateMachine. The guide integration normalizes that flat input into one downstream stateMachine form: field status, a state marked initial: true, and transitions moved under their source state. The complete example uses stateMachine explicitly so the field binding and transition ownership are visible. The checked flat variant produces the same modeled machine. This is an editorial spelling choice for the examples, not a new ratification or a prohibition of the documented compatibility input.

After trait merging, Draft 05 §8.5 requires literal state references in inState, canTransition, and currentState to name surviving states; violations are TRAIT_STATE_REFERENCE_UNRESOLVED. Structural initial and transition-target references are also checked by the integrated guide. ADL 18 and ADL 22 own function meaning, state transitions, and the full machine grammar.

Observed limits. The implementation uses a regex over string leaves, not a complete AEL syntax analysis. Single-quoted inState('gone') is found, but double quotes, whitespace before (, and the selected currentState('gone') call evade this check. A description merely containing inState('gone') is rejected as though it were an executable state reference. The check returns early if no machine exists. These are admission defects; successful parsing of those cases does not validate the state references.

13.10 Diagnostics and incomplete validation

ConditionChecked production result
Missing ordinary reference or unsupported target sectionTarget-not-found error
Chained/cyclic or unsupported nested directiveUnresolved-directive error
Scalar $merge, invalid merge entryDeclaration rejection
Numeric $refGeneric JSON type exception captured by the adapter
Unknown traitTRAIT_UNKNOWN
Repeated trait in application listTRAIT_CYCLE
Trait applies another traitTRAIT_NESTED
Trait parameters or unknown key, including hooksUNKNOWN_KEY
Scalar trait body, scalar list, non-string list memberVALIDATION_ERROR
Incompatible field types across traitsTRAIT_MEMBER_CONFLICT
Two trait machinesTRAIT_STATEMACHINE_CONFLICT
Missing initial state, transition target, or detected literal stateTRAIT_STATE_REFERENCE_UNRESOLVED

The resolver validates trait keys more completely than their value shapes. The selected list-valued object, mapping-valued indexes, and string-valued permissions are accepted and their contributions ignored. A successful parse therefore does not prove that the intended fields, indexes, or restrictions entered the resource. Inspect the effective model and generated outputs.

The modeller handles ordinary object composition but does not implement trait expansion in the recorded source. It warns that domain/resource traits keys are unused and builds only explicit fields. Its CLI exits successfully for the incompatible-member and two-machine rejection fixtures. Its rejection of the dangling-state fixture arises from the explicit machine’s independent validation, not proof of trait processing. ADL 31 owns public error envelopes and ADL 2 owns conformance evidence conventions.

13.11 Provenance, persistence, and identity

The signed provenance rule requires the bound model to retain each merged member’s origin: explicit, trait:<name>, or extends:<base>. Trait expansion must not erase the information needed to explain an effective resource. Domain derivation’s use of the third kind remains in ADL 14.

The checked trait model records origin on fields, scopes, indexes, states, transitions, and operation permissions, including each permission conjunct. It also retains ordered trait definitions and bodies. Ordinary $ref and $merge uses remain labeled explicit; origin is not a complete source map back to every shared object or property. Nested member attribution should likewise be checked separately from its enclosing field.

Private $origin markers are removed from resolved source before its digest and serialization. Permission $all remains because it carries semantic restrictions. The Phase-13 follow-up persists _model_provenance beside the registry’s model projection and restores it onto the resolved model on reload. The metadata is excluded from the projection content hash; it is not authored ADL or part of either document digest. Older rows without that metadata can recover origin from authored source as a compatibility fallback.

Verified persistence. The object and trait models were stored, their authored text removed, and a new registry instance loaded them. Recorded model projections, permission behavior, trait bodies, and origins match before and after; hash verification succeeds. The actual schema action also returns the same output before and after authored-text removal. This verifies registry reload, not a newly executed full server restart.

Schema output exposes non-explicit field origins, declared trait names and descriptions, and permission-conjunct origins. It does not expose every stored origin or complete trait body on that surface; absence of explicit-field origin is not absence of model provenance. The original guide report’s authored-reparse explanation is historical: its later snapshot follow-up closes that debt for new snapshots.

The two complete sugar fixtures have equal resolved digests and equal generated SQLite/PostgreSQL DDL, while their source digests differ. Renaming the applied trait changes source identity and origin labels without changing the resolved digest. This equality applies to equivalent expanded declarations. Removing a contributing permission rule changes semantics, so a weaker explicit document is not a valid sugar-equivalence example. ADL 9 remains the owner of canonical byte-level requirements.

13.12 Complete examples and verification

The complete object example provides the definitions and uses shown in §§13.2–13.4. It declares the inherited language version 0.5.0, and both production and modeller accept it. Its resolved field catalog records the winning maximum length, sibling override, nested shape, and separate SQL columns.

The complete trait example is:

adl: "0.5.1"
domain:
  name: press
  version: "1.0.0"
  traits:
    Timestamped:
      description: Shared timestamps
      object:
        createdAt:
          type: datetime
          autoNow: create
        updatedAt:
          type: datetime
          autoNow: always
    Reviewable:
      description: Review state and policy
      object:
        status:
          type: string
          default: draft
      permissions:
        update:
        - editor
      scopes:
        drafts:
          filter: status = 'draft'
      indexes:
      - fields:
        - status
      stateMachine:
        field: status
        initial: draft
        states:
          draft:
            transitions:
              publish:
                to: published
          published: {}
  resources:
    Post:
      traits:
      - Timestamped
      - Reviewable
      object:
        id:
          type: integer
          primaryKey: true
        title:
          type: string
          required: true
        authorId:
          type: string
      permissions:
        read:
        - '*'
        create:
        - admin
        update:
        - owner
        - editor
        ownerField: authorId

This example supplies all referenced traits and fields. The create action generates timestamps and an initial draft state. The checked editor update succeeds; the owner-with-reader-role update is denied. Schema inspection shows the two update contributors and their origins. The composition catalog retains model, DDL, schema, and six governing-vector correspondences.

Other complete inputPurpose
sugar-traits.yamlMinimal field trait with no extra permission restriction
sugar-explicit.yamlEquivalent explicitly expanded resource
reject-member.yamlIncompatible trait member types; expected rejection
reject-machine.yamlTwo trait machines; expected rejection
reject-state.yamlReplaced machine leaves a trait permission naming a removed state

The verification record retains 64 adapter cases, fourteen CLI/modeller commands, twelve independent modeller observations, and 93 passing focused existing Release tests. The cases include two registry reloads and one disposable SQLite action sequence. Source revision ff1a97a0, compatible headers dcb5fa10, and executable hashes are recorded separately. Only the adapter was compiled; no fresh production HEAD build, PostgreSQL execution, or full transport test is claimed.

The verification record, including 29 reviewed sources, and reproduction instructions preserve the evidence. Publication review must resolve the $merge authority conflict, trait vocabulary and machine spelling, nested/directive limitations, permission aliases, and incomplete state/value-shape validation. This draft does not change production code or declare those gaps to be new language rules.