UNPKG

@hiki9/rich-domain

Version:

Rich Domain is a library that provides a set of tools to help you build complex business logic in NodeJS using Domain Driven Design principles.

46 lines 2.14 kB
import { ISnapshot, Primitives, WithoutEntityProps } from "../interface/types"; type DefaultValuesValidation<Props, Input, InputRequiredProps = Required<WithoutEntityProps<Input>>> = { [key in keyof InputRequiredProps]: Primitives | ((currentValue: InputRequiredProps[key] | undefined, props: Props) => InputRequiredProps[key]); }; type HookTypeValidationCallback = (value: any) => string | void | undefined; type HookTypeValidation<Props> = { [K in keyof Props]: HookTypeValidationCallback; }; export type HookConfigInput<Entity, Props, Input = Props> = { typeValidation?: HookTypeValidation<WithoutEntityProps<Props>>; onChange?: (entity: Entity, snapshot: ISnapshot<Props>) => void; onCreate?: (entity: Entity) => void; rules?: (data: Entity) => void; defaultValues?: DefaultValuesValidation<Props, Input>; }; type Values<T> = T[keyof T]; type OptionalKeys<T> = Values<{ [K in keyof T]: {} extends Pick<T, K> ? K : never; }>; type GetOnlyOptional<T> = Pick<T, OptionalKeys<T>>; export declare class EntityHook<Entity, Props, InputLikeProps = Props, Input = GetOnlyOptional<InputLikeProps>> { isHooksConfig: boolean; typeValidation?: HookTypeValidation<WithoutEntityProps<Props>>; onChange?: (entity: Entity, snapshot: ISnapshot<Props>) => void; onCreate?: (entity: Entity) => void; rules?: (data: Entity) => void; defaultValues?: DefaultValuesValidation<Props, Input>; constructor(config: HookConfigInput<Entity, Props, Input>); } type VoHookConfigInput<Props> = { typeValidation?: VoHookTypeValidation<Props>; rules?: (data: Props) => void; transformBeforeCreate?: (data: Props) => Props; }; type VoHookTypeValidation<Props> = Props extends Primitives ? HookTypeValidationCallback : { [key in keyof WithoutEntityProps<Props>]: HookTypeValidationCallback; }; export declare class VoHooks<Props> { isVoHookConfig: boolean; transformBeforeCreate?: (data: Props) => Props; typeValidation?: VoHookTypeValidation<Props>; rules?: (data: Props) => void; constructor(config: VoHookConfigInput<Props>); } export {}; //# sourceMappingURL=hooks.d.ts.map