UNPKG

@backland/schema

Version:

TypeScript schema declaration and validation library with static type inference

65 lines (64 loc) 1.93 kB
import { MaybePromise, PartialRequired, TypeDescription } from '@backland/utils'; export declare const tsfy_defaults: { iterationLimit: number; }; export type TSFYConfig = { context?: TSFYContext; iterationLimit?: number; many?: boolean; groupInTypeThreshold?: number; customParser?: TSFYCustomHandler; }; export interface TSFyResult { toString: _ToString; getParts: _GetParts; } export declare function tsfy(input: any, config?: TSFYConfig): TSFyResult; export type TSFYPart = string | TSFYRef | TSFYPart[]; export declare function getTSFyIdentifier(value: any): string | undefined; export type TSFYRef = { hash: string; identifier: string | undefined; parts: TSFYPart[]; result?: string; count: number; }; export type TSFYContext = { refs: Record<string, TSFYRef>; header: Record<string, string>; config: PartialRequired<TSFYConfig, 'customParser'>; }; export declare function createTSfyRef(hash: string, identifier?: string): TSFYRef; export declare function createTSFYContext(config: TSFYConfig): TSFYContext; export type TSFyChunkDefinition = { value?: string; identifier?: string; functionArguments?: TSFyTypeDef[]; functionResult?: TSFyTypeDef; }; export type TSFyTypeDef = { body: (TSFyChunkDefinition | string)[]; header?: Record<string, string>; }; export type TSFyHandlerUtils = { identifier: string | undefined; typeDescription: TypeDescription; hash: string; context: TSFYContext; existing: TSFYRef | undefined; currentRef: TSFYRef; value: any; }; export interface TSFYCustomHandler { (utils: TSFyHandlerUtils): MaybePromise<TSFYRef | undefined>; } export type _GetParts = () => Promise<{ header: Set<string>; body: string; footer: Set<string>; }>; export type _ToString = (options?: { prettier?: boolean; name?: string; wrapper?: [string, string]; }) => Promise<string>;