bookish-potato-dto
Version:
A TypeScript DTO (Data Transfer Object) parsing and validation library. Define a schema once — get runtime validation and a fully inferred TypeScript type for free.
37 lines (36 loc) • 2.05 kB
TypeScript
import { PropertyParser, Range } from '../types';
import { EnumAllowedGenericType, EnumType } from '../_types';
import type { DtoDefinition } from '../schema/dto-definition.type';
export declare abstract class PropertyParsers {
private static readonly cache;
/**
* Returns a cached parser or creates a new one.
* Can be used to cache parsers by key.
* @param key - unique key for the parser.
* @param factory - factory function to create a new parser.
*/
static CACHE_PARSER<T>(key: string, factory: () => PropertyParser<T>): PropertyParser<T>;
static get STRING(): PropertyParser<string>;
static STRING_IN_RANGE(range: Partial<Range>): PropertyParser<string>;
static STRING_REGEX(regex: RegExp): PropertyParser<string>;
static get NUMBER(): PropertyParser<number>;
static NUMBER_IN_RANGE(range: Partial<Range>): PropertyParser<number>;
static get STRING_TO_NUMBER(): PropertyParser<number>;
static STRING_TO_NUMBER_IN_RANGE(range: Partial<Range>): PropertyParser<number>;
static get INTEGER(): PropertyParser<number>;
static INTEGER_IN_RANGE(range: Partial<Range>): PropertyParser<number>;
static get STRING_TO_INTEGER(): PropertyParser<number>;
static STRING_TO_INTEGER_IN_RANGE(range: Partial<Range>): PropertyParser<number>;
static get BOOLEAN(): PropertyParser<boolean>;
static get STRING_TO_BOOLEAN(): PropertyParser<boolean>;
static get DATE(): PropertyParser<Date>;
static ARRAY<T>(parser: PropertyParser<T>): PropertyParser<T[]>;
static ARRAY_IN_RANGE<T>(parser: PropertyParser<T>, range: Partial<Range>): PropertyParser<T[]>;
static ENUM<T extends EnumAllowedGenericType>(enumType: EnumType<T>): PropertyParser<T>;
/**
* Returns a cached PropertyParser that delegates to schemaParseObject.
* Uses the DtoDefinition's stable _uuid as the cache key.
* Prefix avoids collision with PropertyParsers.ARRAY which also caches by parser.uuid.
*/
static DTO_DEFINITION(dto: DtoDefinition): PropertyParser<unknown>;
}