export declare type AttrValue = any; export declare type AttrName = string; export declare type AttrConfig = WritableAttrConfig | CallableAttrConfig; export declare type AttrConfigSet = Record; export declare type AttrSet = Record; export interface BaseAttrConfig { hidden?: boolean; } export interface WritableAttrConfig extends BaseAttrConfig { normalizer?: NormalizerFn; immutable?: boolean; sanitizer: SanitizerFn; validator?: ValidatorFn; value: V; fn?: never; } export interface CallableAttrConfig extends BaseAttrConfig { fn: Fn; value?: never; } export declare type Fn = () => V; export declare type SanitizerFn = (value: unknown, name: AttrName) => V; export declare type NormalizerFn = (value: NonNullable, name: AttrName) => V; export declare type ValidatorFn = (value: NonNullable, name: AttrName) => boolean; declare type AsAttrName = T extends AttrName ? T : never; export declare type ResolveAttrName = AsAttrName; export declare type ResolveAttrSet = { [K in keyof ACS]: ACS[K] extends CallableAttrConfig ? ReturnType : ACS[K] extends WritableAttrConfig ? ACS[K]['value'] : never; }; export declare type ResolveCallableAttrName = AsAttrName<{ [K in keyof ACS]: ACS[K] extends CallableAttrConfig ? K : never; }[keyof ACS]>; export declare type ResolveCallableAttrConfigSet = Pick>; export declare type ResolveCallableAttrSet = ResolveAttrSet>; export declare type ResolveWritableAttrName = AsAttrName<{ [K in keyof ACS]: ACS[K] extends WritableAttrConfig ? K : never; }[keyof ACS]>; export declare type ResolveWritableAttrConfigSet = Pick>; export declare type ResolveWritableAttrSet = ResolveAttrSet>; export declare type ResolveHiddenAttrName = AsAttrName<{ [K in keyof ACS]: ACS[K]['hidden'] extends true ? K : never; }[keyof ACS]>; export declare type ResolveHiddenAttrConfigSet = Pick>; export declare type ResolveHiddenAttrSet = ResolveAttrSet>; export declare type ResolveVisibleAttrName = AsAttrName>>; export declare type ResolveVisibleAttrConfigSet = Pick>; export declare type ResolveVisibleAttrSet = ResolveAttrSet>; export declare type ResolveImmutableAttrName = AsAttrName<{ [K in keyof ACS]: ACS[K] extends WritableAttrConfig ? ACS[K]['immutable'] extends true ? K : never : never; }[keyof ACS]>; export declare type ResolveImmutableAttrConfigSet = Pick>; export declare type ResolveImmutableAttrSet = ResolveAttrSet>; export declare type ResolveMutableAttrName = AsAttrName, ResolveImmutableAttrName>>; export declare type ResolveMutableAttrConfigSet = Pick>; export declare type ResolveMutableAttrSet = ResolveAttrSet>; export declare type ResolveConstructorData = Partial> | Entity | string; export declare type ResolveFillData = Partial> | Entity | string; declare const EmptyObject: {}; export declare class Entity { #private; /** * Creates a new [[`Entity`]] instance. The `attrConfigSet` defines the attributes available on * the [[`Entity`]] instance. Values defined in `attrConfigSet` are trusted and therefore not * sanitized, normalized nor validated. Data provided via `data` must be compatible with the data * expected by [[`Entity.fill()`]] but, unlike [[`Entity.fill()`]], may also include values for * immutable attributes. * * @param attrConfigSet * @param data */ constructor(attrConfigSet: ACS, data?: ResolveConstructorData); /** * Returns the value of the attribute provided in `name`. * * @param name */ one>(name: K): ResolveAttrSet[K]; /** * Returns an attribute set of the attributes provided in `names`. * * @param names */ many[]>(names: N): Pick, typeof names[number]>; /** * Returns an attribute set of all attributes. */ all(): ResolveAttrSet; /** * Returns an attribute set of all callable (non-writable) attributes. */ callable(): ResolveCallableAttrSet; /** * Returns an attribute set an all writable (non-callable) attributes. */ writable(): ResolveWritableAttrSet; /** * Returns an attribute set of all attributes that have been configured as `immutable`. */ immutable(): ResolveImmutableAttrSet; /** * Returns an attribute set of all attributes that have not been configured as `immutable`. */ mutable(): ResolveMutableAttrSet; /** * Returns an attribute set of all attributes that have been configured as `hidden`. */ hidden(): ResolveHiddenAttrSet; /** * Returns an attribute set of all attributes that have not been configured as `hidden`. */ visible(): ResolveVisibleAttrSet; /** * Returns an attribute set of all attributes that have been modified since instantiation or the * last call to [[`Entity.clearModified()`]]. */ modified(): Partial>; /** * Sets the `value` for the attribute `name`. Values can only be set for mutable, writable * attributes. The value will be sanitized, normalized and validated. * * @param name * @param value */ set>(name: K, value: ResolveMutableAttrSet[K]): this; /** * Sets multiple attribute values using the provided `data`. The incoming data is parsed into an * attribute set using [[`Entity.parseData()`]], before being sanitized, normalized and validated. * * @param data */ fill(data: ResolveFillData): this; /** * Clears the modified attribute state. Typically used after calling an update/save endpoint to * signify that the instance is in sync with the upstream datasource. */ clearModified(): this; /** * Sanitizes a `value` using the configured `sanitizer` function for the attribute `name`. The * function will have `this` scoped to the [[`Entity`]] instance. * * @param name * @param value */ sanitize>(name: K, value: unknown): ResolveWritableAttrSet[K]; /** * Normalizes a `value` using the configured `normalizer` function for the attribute `name`. If * the attribute does not have a normalizer function configured then that value is returned as-is. * The function will have `this` scoped to the [[`Entity`]] instance. * * @param name * @param value */ normalize, V extends ResolveWritableAttrSet[K]>(name: K, value: V): V; /** * Validates a `value` using the configured `validator` function for the attribute `name`. If * the attribute does not have a validator function configured then that value is assumed valid. * The function will have `this` scoped to the [[`Entity`]] instance. * * @param name * @param value */ validate>(name: K, value: ResolveWritableAttrSet[K]): boolean; /** * Attempts to parse incoming data which may be an attribute set, an [[`Entity`]] instance or a * JSON string. * * @param data */ parseData(data: unknown): AttrSet; /** * Stringifies the instance to JSON. */ toString(): string; /** * Returns the data to expose when stringifying the instance to JSON. */ toJSON(): ResolveVisibleAttrSet; } export {};