domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
21 lines (20 loc) • 1.18 kB
TypeScript
import { MalfunctionError } from 'helpful-errors';
import type { DomainObject } from '../instantiation/DomainObject';
export declare class DomainObjectNotSafeToManipulateError extends MalfunctionError {
constructor({ unsafeKeys, className, }: {
unsafeKeys: string[];
className: string;
});
}
/**
* For internal use only. DomainObjects must have all nested domain objects defined in their `DomainObject.nested` definition. Otherwise, we could be dealing with a domain object that is not instantiated, and thus we will not appropriately serialize it.
*
* Therefore, if any DomainObject has nested objects that are not instantiated as DomainObjects, there is a risk that the nested object is really a nested, uninstantiated DomainObject - which would cause bugs if uncaught.
*
* @param obj - The domain object to validate
* @param options - Optional configuration
* @param options.onKeys - When provided, only validates the specified keys; otherwise validates all keys
*/
export declare const assertDomainObjectIsSafeToManipulate: <T extends Record<string, any>>(obj: DomainObject<T> & Record<string, any>, options?: {
onKeys?: string[];
}) => void;