dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
26 lines (25 loc) • 1.66 kB
TypeScript
import { z } from 'zod';
import type { AnyOfSchema, Schema } from '../../../../schema/index.js';
import type { Overwrite } from '../../../../types/overwrite.js';
import type { WithValidate } from '../utils.js';
import type { SchemaZodParser } from './schema.js';
import type { ZodParserOptions } from './types.js';
import type { WithDefault, WithOptional } from './utils.js';
export type AnyOfZodParser<SCHEMA extends AnyOfSchema, OPTIONS extends ZodParserOptions = {}> = AnyOfSchema extends SCHEMA ? z.ZodTypeAny : WithDefault<SCHEMA, OPTIONS, WithOptional<SCHEMA, OPTIONS, WithValidate<SCHEMA, SCHEMA['props'] extends {
discriminator: string;
} ? z.ZodDiscriminatedUnion<SCHEMA['props']['discriminator'], MapAnyOfZodParser<SCHEMA['elements'], Overwrite<OPTIONS, {
defined: true;
}>>> : SCHEMA['elements'] extends [infer SCHEMAS_HEAD, ...infer SCHEMAS_TAIL] ? SCHEMAS_HEAD extends Schema ? SCHEMAS_TAIL extends Schema[] ? z.ZodUnion<[
SchemaZodParser<SCHEMAS_HEAD, Overwrite<OPTIONS, {
defined: true;
}>>,
...MapAnyOfZodParser<SCHEMAS_TAIL, Overwrite<OPTIONS, {
defined: true;
}>>
]> : never : never : z.ZodTypeAny>>>;
type MapAnyOfZodParser<SCHEMAS extends Schema[], OPTIONS extends ZodParserOptions = {}, RESULTS extends z.ZodTypeAny[] = []> = SCHEMAS extends [infer SCHEMAS_HEAD, ...infer SCHEMAS_TAIL] ? SCHEMAS_HEAD extends Schema ? SCHEMAS_TAIL extends Schema[] ? MapAnyOfZodParser<SCHEMAS_TAIL, OPTIONS, [
...RESULTS,
SchemaZodParser<SCHEMAS_HEAD, OPTIONS>
]> : never : never : RESULTS;
export declare const anyOfZodParser: (schema: AnyOfSchema, options?: ZodParserOptions) => z.ZodTypeAny;
export {};