domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
25 lines (24 loc) • 1.52 kB
TypeScript
import type { DomainObject } from '../instantiation/DomainObject';
/**
* omits all readonly values on a domain object
*
* relevance:
* - often when submitting user-settable values, readonly values should be omitted
* - this provides an easy way to omit both metadata and explicit readonly properties
*
* features:
* - utilizes the `.metadata` property to identify metadata keys (applicable to all domain objects)
* - utilizes the `.readonly` property to identify explicit readonly keys (applicable to DomainEntity only)
* - supports nested readonly via dot-path keys (e.g. `'network.interface.privateIp'`), declared from the entity grain
* - recursive, applies omission deeply
*
* note:
* - both metadata and readonly are set by the persistence layer
* - metadata is a special subset of readonly: describes the persistence of the object (not the object itself)
* - readonly (non-metadata) describes intrinsic attributes of the object that the persistence layer sets
* - readonly (non-metadata) only applies to DomainEntity, due to their nature
* - a nested readonly key uses dot-path notation and is declared on the entity (the literal it points into is stateless and reusable, so it cannot self-declare readonly)
* - a nested readonly path applies to every element when it traverses an array of nested objects
* - for DomainEvent and DomainLiteral, this function behaves identically to omitMetadata
*/
export declare const omitReadonly: <T extends DomainObject<Record<string, any>>>(obj: T) => T;