// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/types/tuple.ts import { ZodTypes } from "../ZodTypes.ts"; import { ZodType, ZodTypeDef, ZodTypeAny } from "./base.ts"; // import { objectUtil } from '../helpers/objectUtil'; // import { ZodUnion } from './union'; // import { ZodUndefined } from './undefined'; // import { ZodNull } from './null'; // export type identity = T; // export type flatten = identity< // { [k in keyof T]: T[k] } // >; // type tupleOptionalKeys = { // [k in keyof T]?: undefined extends T[k] ? T[k] : unknown; // }; //[keyof T]; // type tupleRequiredKeys = { // [k in keyof T]: undefined extends T[k] ? unknown : T[k]; // }; // export type addTupleQuestionMarks = flatten< // tupleOptionalKeys & tupleRequiredKeys // >; // export type addTupleQuestionMarks = { // [k in tupleOptionalKeys]?: T[k]; // } & // { [k in tupleRequiredKeys]: T[k] }; // type test = [string, number | undefined] // type t2 = tupleOptionalKeys; // type t3 = tupleRequiredKeys; // type t4 = addTupleQuestionMarks; // const x:t4 = ['asdf']; // type t5 = string & unknown; export type OutputTypeOfTuple = { [k in keyof T]: T[k] extends ZodType ? T[k]["_output"] : never; }; export type InputTypeOfTuple = { [k in keyof T]: T[k] extends ZodType ? T[k]["_input"] : never; }; export interface ZodTupleDef< T extends [ZodTypeAny, ...ZodTypeAny[]] | [] = [ZodTypeAny, ...ZodTypeAny[]] > extends ZodTypeDef { t: ZodTypes.tuple; items: T; } export class ZodTuple< T extends [ZodTypeAny, ...ZodTypeAny[]] | [] = [ZodTypeAny, ...ZodTypeAny[]] > extends ZodType, ZodTupleDef, InputTypeOfTuple> { toJSON = () => ({ t: this._def.t, items: (this._def.items as any[]).map((item) => item.toJSON()), }); get items() { return this._def.items; } // opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]); // null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]); static create = ( schemas: T ): ZodTuple => { return new ZodTuple({ t: ZodTypes.tuple, items: schemas, }); }; }