UNPKG

domain-objects

Version:

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

26 lines (25 loc) 1.61 kB
import { ConstraintError } from 'helpful-errors'; import type { DomainObjectConstructor } from '../../instantiation/DomainObjectConstructor'; /** * .what = error thrown when a nested domain object prop cannot be hydrated into a declared option * .why = every case here is a caller-fixable input problem (bad shape, ambiguity, or non-strict * schema), so we extend ConstraintError — exit code 2, http 400, and helpful metadata format */ export declare class NestedDomainObjectHydrationError extends ConstraintError { } /** * .what = hydrates each declared nested prop into its DomainObject instance, out of the declared option(s) * .why = a `.nested` declaration promises the nested value is a DomainObject; hydration honors that promise * on `.build`, so callers can pass plain (e.g. deserialized) objects and still receive typed instances * .how = * - single option → build directly into it * - multi-option + `_dobj` discriminator → build into the named option (try-each skipped) * - multi-option, no `_dobj` → disambiguate by strict-schema try-each (failfast on loose/absent schema, zero, or many fits) * .note = a null or absent (undefined/primitive) nested value is left untouched — a nested field may be * nullable or optional, and no DomainObject would validate a non-object, so hydration is a no-op there */ export declare const hydrateNestedDomainObjects: ({ props, nested, domainObjectName, }: { props: Record<string, any>; nested: Record<string, DomainObjectConstructor | DomainObjectConstructor[]>; domainObjectName: string; }) => Record<string, any>;