Skip to content

fix(contract): add .contract.ref(by) — an x-domain-object-ref pragma for cross-service references - #135

Merged
uladkasach merged 1 commit into
mainfrom
vlad/fix-contract-refs
Jul 23, 2026
Merged

fix(contract): add .contract.ref(by) — an x-domain-object-ref pragma for cross-service references#135
uladkasach merged 1 commit into
mainfrom
vlad/fix-contract-refs

Conversation

@ehm-a-seaturtle

Copy link
Copy Markdown
Contributor

fix(contract): add .contract.ref(by) — an x-domain-object-ref pragma for cross-service references

  • .contract.ref('primary'|'unique'|'ref') returns a zod schema of only the referenced
    key fields, stamped with an x-domain-object-ref pragma that survives z.toJSONSchema()
  • lets a field REFERENCE another dobj by key (not compose the whole dobj), so a cross-service
    consumer can emit a typed RefBy* instead of an anonymous shape
  • unique-key recursion mirrors refByUnique (via shared hasDeclaredUniqueKey gate); primary stays
    a flat pick; ref degrades a union-of-one; cyclic/polymorphic unique graphs fail fast
  • new DomainObjectPragmaRef type + DomainObjectClass structural view, exported from the barrel
  • memoized per class+by (WeakMap), mirroring getContract
  • covered by unit tests, a full producer->wire->consumer roundtrip acceptance journey
    (single ref, array-of-refs, nested recursion, ref-union), and exhaustive snapshots

🐢🌊 surfed in by seaturtle[bot]

…for cross-service references

- .contract.ref('primary'|'unique'|'ref') returns a zod schema of only the referenced
  key fields, stamped with an x-domain-object-ref pragma that survives z.toJSONSchema()
- lets a field REFERENCE another dobj by key (not compose the whole dobj), so a cross-service
  consumer can emit a typed RefBy*<typeof X> instead of an anonymous shape
- unique-key recursion mirrors refByUnique (via shared hasDeclaredUniqueKey gate); primary stays
  a flat pick; ref degrades a union-of-one; cyclic/polymorphic unique graphs fail fast
- new DomainObjectPragmaRef type + DomainObjectClass structural view, exported from the barrel
- memoized per class+by (WeakMap), mirroring getContract
- covered by unit tests, a full producer->wire->consumer roundtrip acceptance journey
  (single ref, array-of-refs, nested recursion, ref-union), and exhaustive snapshots

Co-authored-by: Ulad Kasach <uladkasach@gmail.com>
@uladkasach
uladkasach force-pushed the vlad/fix-contract-refs branch from de45f49 to 4835b1c Compare July 23, 2026 02:01
@uladkasach
uladkasach merged commit fe25c3d into main Jul 23, 2026
16 checks passed
@uladkasach
uladkasach deleted the vlad/fix-contract-refs branch July 23, 2026 02:02
@rhelease rhelease Bot mentioned this pull request Jul 23, 2026
@rhelease

rhelease Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant