import { type AssessWithAssure } from 'type-fns'; import type { DomainObject } from '../instantiation/DomainObject'; import type { ConstructorOf, HasReadonly } from './HasReadonly.type'; /** * runtime type guard that asserts that all readonly keys (metadata + explicit readonly) * of a domain object have defined values * * note: this function requires that `metadata` is explicitly declared on the class. * if metadata is not explicitly declared, this function will throw an error to * prevent ambiguity about which keys are being checked. * * this is useful for narrowing types after persistence operations where readonly * attributes are expected to be populated * * for example: * ```ts * const cluster = new DeclaredAwsRdsCluster({ name: 'testdb' }); * // cluster.arn is string | undefined * // cluster.port is number | undefined * * const persisted = await persist(cluster); * if (hasReadonly({ of: DeclaredAwsRdsCluster })(persisted)) { * // persisted.arn is string (required) * // persisted.port is number (required) * } * * // or use .assure to throw if readonly keys are missing * const assured = hasReadonly({ of: DeclaredAwsRdsCluster }).assure(persisted); * // assured.arn is string (required) * // assured.port is number (required) * ``` */ export declare const hasReadonly: >>({ of: dobj, }: { of: TDobj; }) => AssessWithAssure, HasReadonly>;