UNPKG

typescript-domain

Version:

Decorator-based transformation of JSON or plain Javascript objects to classes

47 lines (46 loc) 2.06 kB
import type { Entity } from './entity'; import type { BasicTypes, DebugFunction } from './types'; export declare enum DEBUG_INFO { EMPTY = "value is undefined", NOT_ARRAY = "value is not array", NOT_BOOLEAN = "value is not a boolean", NOT_DATE = "value cannot be parsed to Date", NOT_ENUM = "value is not option of the enum", NOT_NUMBER = "value is not a number", NOT_STRING = "value is not a string", NOT_VALID_OBJECT = "object created from input is not valid" } export declare const validateValue: (value: unknown | null | undefined, type: BasicTypes | Object, array?: boolean, debugFunction?: DebugFunction, debugSkipUndef?: boolean) => { validatedValue: unknown; debugInfo: string | null; }; export declare class EntityValidation { static array<Input>(data: (Input | null)[] | undefined, type: BasicTypes | Object, debugFunction?: DebugFunction, debugSkipUndef?: boolean): { validatedValue: Input[]; debugInfo: DEBUG_INFO[]; }; static boolean(value: boolean | null | undefined): { validatedValue: boolean | null; debugInfo: DEBUG_INFO | null; }; static date(value: Date | number | string | null | undefined): { validatedValue: Date | null; debugInfo: DEBUG_INFO | null; }; static enum<Type>(value: Type | null | undefined, options: readonly Type[]): { validatedValue: Type | null; debugInfo: DEBUG_INFO | null; }; static number(value: number | null | undefined): { validatedValue: number | null; debugInfo: DEBUG_INFO | null; }; static object<Output extends Entity<T>, Input, T>(Type: new (data?: Input | null, debugFunction?: DebugFunction, debugSkipUndef?: boolean) => Output, data: Input | null | undefined, debugFunction?: DebugFunction, debugSkipUndef?: boolean): { validatedValue: Output | null; debugInfo: DEBUG_INFO | null; }; static string(value: string | null | undefined): { validatedValue: string | null; debugInfo: DEBUG_INFO | null; }; }