UNPKG

domain-objects

Version:

A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.

15 lines (14 loc) 901 B
import type { ZodSchema } from 'zod'; import type { DomainObjectClass } from './DomainObjectClass'; import type { DomainObjectRefBy } from './DomainObjectPragma'; /** * .what = returns a dobj's `.contract.ref(by)`: a zod schema of only the referenced key fields, * stamped with an `x-domain-object-ref` pragma so a *reference* survives `z.toJSONSchema()` * .why = * - `.contract` embeds the WHOLE dobj (composition); a field that only *names* another dobj by * key needs a smaller, stamped form — this is that form * - lets a cross-service consumer emit a typed `RefBy*<typeof X>` instead of an anonymous shape * .note = memoized per class + per `by` (via getContractRefSeen), so repeated access — and any * nested-dobj recursion — returns the same stamped instance */ export declare const getContractRef: (dobj: DomainObjectClass, by: DomainObjectRefBy) => ZodSchema<any>;