UNPKG

@a2lix/schemql

Version:

A lightweight TypeScript library that enhances your SQL workflow by combining raw SQL with targeted type safety and schema validation

279 lines (268 loc) 11.9 kB
export { a as SchemQl, S as SchemQlAdapter } from './schemql-DJKXWmTu.js'; import '@standard-schema/spec'; /** The Standard Schema interface. */ interface StandardSchemaV1<Input = unknown, Output = Input> { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props<Input, Output>; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ interface Props<Input = unknown, Output = Input> { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>; /** Inferred types associated with the schema. */ readonly types?: Types<Input, Output> | undefined; } /** The result interface of the validate function. */ type Result<Output> = SuccessResult<Output> | FailureResult; /** The result interface if validation succeeds. */ interface SuccessResult<Output> { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray<Issue>; } /** The issue interface of the failure output. */ interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined; } /** The path segment interface of the issue. */ interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ interface Types<Input = unknown, Output = Input> { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"]; /** Infers the output type of a Standard Schema. */ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"]; } type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type MakePartial<T, K extends keyof T> = Omit<T, K> & InexactPartial<Pick<T, K>>; type InexactPartial<T> = { [P in keyof T]?: T[P] | undefined; }; type Identity<T> = T; type Flatten<T> = Identity<{ [k in keyof T]: T[k]; }>; type AnyFunc = (...args: any[]) => any; type MaybeAsync<T> = T | Promise<T>; type Primitive = string | number | symbol | bigint | boolean | null | undefined; type DiscriminatorMapElement = { values: Set<Primitive>; maps: DiscriminatorMap[]; }; type DiscriminatorMap = Map<PropertyKey, DiscriminatorMapElement>; type PrimitiveSet = Set<Primitive>; declare const version: { readonly major: 0; readonly minor: 5; readonly patch: number; }; interface ParseContext<T extends $ZodIssueBase = never> { /** Customize error messages. */ readonly error?: $ZodErrorMap<T>; /** Include the `input` field in issue objects. Default `false`. */ readonly reportInput?: boolean; /** Skip eval-based fast path. Default `false`. */ readonly noPrecompilation?: boolean; } /** @internal */ interface ParseContextInternal<T extends $ZodIssueBase = never> extends ParseContext<T> { readonly async?: boolean | undefined; } interface ParsePayload<T = unknown> { value: T; issues: $ZodRawIssue[]; } interface $ZodTypeDef { type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "interface" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "custom"; error?: $ZodErrorMap<never> | undefined; checks?: $ZodCheck<never>[]; } interface $ZodTypeInternals<out O = unknown, out I = unknown> extends $ZodType<O, I> { /** The `@zod/core` version of this schema */ version: typeof version; /** Schema internals. */ def: $ZodTypeDef; /** Randomly generated ID for this schema. */ id: string; /** The inferred output typre */ output: O; /** The inferred input type */ input: I; /** List of deferred initializers. */ deferred: AnyFunc[] | undefined; /** Parses input and runs all checks (refinements). */ run(payload: ParsePayload<any>, ctx: ParseContextInternal): MaybeAsync<ParsePayload>; /** Parses input, doesn't run checks. */ parse(payload: ParsePayload<any>, ctx: ParseContextInternal): MaybeAsync<ParsePayload>; /** Stores identifiers for the set of traits implemented by this schema. */ traits: Set<string>; /** Indicates that a schema output type should be considered optional inside objects. */ qout: "true" | undefined; /** Indicates that a schema input type should be considered optional inside objects. */ qin: "true" | undefined; /** A set of literal discriminators used for the fast path in discriminated unions. */ disc: DiscriminatorMap | undefined; /** The set of literal values that will pass validation. Must be an exhaustive set. Used to determine optionality in z.record(). * * Defined on: enum, const, literal, null, undefined * Passthrough: optional, nullable, branded, default, catch, pipe * Todo: unions? */ values: PrimitiveSet | undefined; /** This flag indicates that a schema validation can be represented with a regular expression. Used to determine allowable schemas in z.templateLiteral(). */ pattern: RegExp | undefined; /** The constructor function of this schema. */ constr: new (def: any) => any; /** A catchall object for computed metadata related to this schema. Commonly modified by checks using `onattach`. */ computed: Record<string, any>; /** The set of issues this schema might throw during type checking. */ isst: $ZodIssueBase; /** An optional method used to override `toJSONSchema` logic. */ toJSONSchema?: () => object; } interface $ZodType<out O = unknown, out I = unknown> { _zod: $ZodTypeInternals<O, I>; "~standard": StandardSchemaV1.Props<this["_zod"]["input"], this["_zod"]["output"]>; } declare const $ZodType: $constructor<$ZodType>; interface $ZodCheckDef { check: string; error?: $ZodErrorMap<never> | undefined; /** If true, no later checks will be executed if this check fails. Default `false`. */ abort?: boolean | undefined; } interface $ZodCheckInternals<T> { def: $ZodCheckDef; /** The set of issues this check might throw. */ issc?: $ZodIssueBase; check(payload: ParsePayload<T>): MaybeAsync<void>; onattach?(schema: $ZodType): void; when?: ((payload: ParsePayload) => boolean) | undefined; } interface $ZodCheck<in T = never> { _zod: $ZodCheckInternals<T>; } declare const $ZodCheck: $constructor<$ZodCheck<any>>; type $ZodStringFormats = "regex" | "email" | "url" | "emoji" | "uuid" | "guid" | "nanoid" | "guid" | "cuid" | "cuid2" | "ulid" | "xid" | "ksuid" | "datetime" | "date" | "time" | "duration" | "ipv4" | "ipv6" | "cidrv4" | "cidrv6" | "base64" | "base64url" | "json_string" | "e164" | "lowercase" | "uppercase" | "regex" | "jwt" | "starts_with" | "ends_with" | "includes"; interface $ZodIssueBase { readonly code?: string; readonly input?: unknown; readonly path: PropertyKey[]; readonly message: string; } interface $ZodIssueInvalidType<Input = unknown> extends $ZodIssueBase { readonly code: "invalid_type"; readonly expected: $ZodType["_zod"]["def"]["type"]; readonly input: Input; } interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase { readonly code: "too_big"; readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {}); readonly maximum: number | bigint; readonly inclusive?: boolean; readonly input: Input; } interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase { readonly code: "too_small"; readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {}); readonly minimum: number | bigint; readonly inclusive?: boolean; readonly input: Input; } interface $ZodIssueInvalidStringFormat extends $ZodIssueBase { readonly code: "invalid_format"; readonly format: $ZodStringFormats | (string & {}); readonly pattern?: string; readonly input: string; } interface $ZodIssueNotMultipleOf<Input extends number | bigint = number | bigint> extends $ZodIssueBase { readonly code: "not_multiple_of"; readonly divisor: number; readonly input: Input; } interface $ZodIssueUnrecognizedKeys extends $ZodIssueBase { readonly code: "unrecognized_keys"; readonly keys: string[]; readonly input: Record<string, unknown>; } interface $ZodIssueInvalidUnion extends $ZodIssueBase { readonly code: "invalid_union"; readonly errors: $ZodIssue[][]; readonly input: unknown; } interface $ZodIssueInvalidKey<Input = unknown> extends $ZodIssueBase { readonly code: "invalid_key"; readonly origin: "map" | "record"; readonly issues: $ZodIssue[]; readonly input: Input; } interface $ZodIssueInvalidElement<Input = unknown> extends $ZodIssueBase { readonly code: "invalid_element"; readonly origin: "map" | "set"; readonly key: unknown; readonly issues: $ZodIssue[]; readonly input: Input; } interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase { readonly code: "invalid_value"; readonly values: Primitive[]; readonly input: Input; } interface $ZodIssueCustom extends $ZodIssueBase { readonly code?: "custom"; readonly params?: Record<string, any> | undefined; readonly input: unknown; } type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom; type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never; type RawIssue<T extends $ZodIssueBase> = Flatten<MakePartial<T, "message" | "path"> & { /** The input data */ readonly input?: unknown; /** The schema or check that originated this issue. */ readonly inst?: $ZodType | $ZodCheck; /** @deprecated Internal use only. If `true`, Zod will continue executing validation despite this issue. */ readonly continue?: boolean | undefined; } & Record<string, any>>; interface $ZodErrorMap<T extends $ZodIssueBase = $ZodIssue> { (issue: $ZodRawIssue<T>): { message: string; } | string | undefined | null; } type ZodTrait = { _zod: { def: any; [k: string]: any; }; }; interface $constructor<T extends ZodTrait, D = T["_zod"]["def"]> { new (def: D): T; init(inst: T, def: D): asserts inst is T; } declare function $constructor<T extends ZodTrait, D = T["_zod"]["def"]>(name: string, initializer: (inst: T, def: D) => void): $constructor<T, D>; interface RefinementCtx<T = unknown> extends ParsePayload<T> { addIssue(arg: string | $ZodRawIssue | Partial<$ZodIssueCustom>): void; } declare const parseJsonPreprocessor: (value: any, ctx: RefinementCtx) => any; export { parseJsonPreprocessor };