Socket
Socket
Sign inDemoInstall

zod

Package Overview
Dependencies
Maintainers
1
Versions
361
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod - npm Package Compare versions

Comparing version 1.7.1 to 2.0.0-alpha.1

lib/src/errorMap.d.ts

12

lib/src/helpers/maskUtil.d.ts
import { Primitive } from './primitive';
type AnyObject = {
declare type AnyObject = {
[k: string]: any;
};
type IsAny<T> = any extends T ? (T extends any ? true : false) : false;
type IsNever<T> = never extends T ? (T extends never ? true : false) : false;
type IsTrue<T> = true extends T ? (T extends true ? true : false) : false;
type IsObject<T> = T extends {
declare type IsAny<T> = any extends T ? (T extends any ? true : false) : false;
declare type IsNever<T> = never extends T ? (T extends never ? true : false) : false;
declare type IsTrue<T> = true extends T ? (T extends true ? true : false) : false;
declare type IsObject<T> = T extends {
[k: string]: any;
} ? (T extends Array<any> ? false : true) : false;
type IsObjectArray<T> = T extends Array<{
declare type IsObjectArray<T> = T extends Array<{
[k: string]: any;

@@ -13,0 +13,0 @@ }> ? true : false;

export declare class Mocker {
pick: (...args: any[]) => any;
readonly string: string;
readonly number: number;
readonly bigint: bigint;
readonly boolean: boolean;
readonly date: Date;
readonly null: null;
readonly undefined: undefined;
readonly stringOptional: any;
readonly stringNullable: any;
readonly numberOptional: any;
readonly numberNullable: any;
readonly booleanOptional: any;
readonly booleanNullable: any;
get string(): string;
get number(): number;
get bigint(): bigint;
get boolean(): boolean;
get date(): Date;
get null(): null;
get undefined(): undefined;
get stringOptional(): any;
get stringNullable(): any;
get numberOptional(): any;
get numberNullable(): any;
get booleanOptional(): any;
get booleanNullable(): any;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mocker = void 0;
function getRandomInt(max) {

@@ -22,3 +23,3 @@ return Math.floor(Math.random() * Math.floor(max));

},
enumerable: true,
enumerable: false,
configurable: true

@@ -30,3 +31,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -38,3 +39,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -46,3 +47,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -54,3 +55,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -62,3 +63,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -70,3 +71,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -78,3 +79,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -86,3 +87,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -94,3 +95,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -102,3 +103,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -110,3 +111,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -118,3 +119,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -121,0 +122,0 @@ });

import { ZodRawShape } from '../types/base';
import { ZodObject } from '../types/object';
export declare namespace objectUtil {
interface ZodObjectParams {
export interface ZodObjectParams {
strict: boolean;
}
type MergeObjectParams<First extends ZodObjectParams, Second extends ZodObjectParams> = {
export type MergeObjectParams<First extends ZodObjectParams, Second extends ZodObjectParams> = {
strict: First['strict'] extends false ? false : Second['strict'] extends false ? false : true;
};
type MergeShapes<U extends ZodRawShape, V extends ZodRawShape> = {
export type MergeShapes<U extends ZodRawShape, V extends ZodRawShape> = {
[k in Exclude<keyof U, keyof V>]: U[k];
} & V;
type Flatten<T extends object> = {
export type Flatten<T extends object> = {
[k in keyof T]: T[k];

@@ -32,11 +32,12 @@ };

}>;
type NoNeverKeys<T extends object> = {
export type NoNeverKeys<T extends object> = {
[k in keyof T]: T[k] extends never ? never : k;
}[keyof T];
type NoNever<T extends object> = {
export type NoNever<T extends object> = {
[k in NoNeverKeys<T>]: T[k];
};
type ObjectType<T extends ZodRawShape> = FlattenObject<ObjectIntersection<NoNever<T>>>;
const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U;
const mergeObjects: <FirstShape extends ZodRawShape, FirstParams extends ZodObjectParams>(first: ZodObject<FirstShape, FirstParams>) => <SecondShape extends ZodRawShape, SecondParams extends ZodObjectParams>(second: ZodObject<SecondShape, SecondParams>) => ZodObject<FirstShape & SecondShape, MergeObjectParams<FirstParams, SecondParams>>;
export type ObjectType<T extends ZodRawShape> = FlattenObject<ObjectIntersection<NoNever<T>>>;
export const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U;
export const mergeObjects: <FirstShape extends ZodRawShape, FirstParams extends ZodObjectParams>(first: ZodObject<FirstShape, FirstParams>) => <SecondShape extends ZodRawShape, SecondParams extends ZodObjectParams>(second: ZodObject<SecondShape, SecondParams>) => ZodObject<FirstShape & SecondShape, MergeObjectParams<FirstParams, SecondParams>>;
export {};
}

@@ -13,3 +13,11 @@ "use strict";

};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectUtil = void 0;
var base_1 = require("../types/base");

@@ -30,9 +38,9 @@ var intersection_1 = require("../types/intersection");

}
return __assign({}, first, second, sharedShape);
return __assign(__assign(__assign({}, first), second), sharedShape);
};
objectUtil.mergeObjects = function (first) { return function (second) {
var mergedShape = objectUtil.mergeShapes(first._def.shape, second._def.shape);
var mergedShape = objectUtil.mergeShapes(first._def.shape(), second._def.shape());
var merged = new object_1.ZodObject({
t: base_1.ZodTypes.object,
checks: (first._def.checks || []).concat((second._def.checks || [])),
checks: __spreadArrays((first._def.checks || []), (second._def.checks || [])),
// strict: first.params.strict && second.params.strict,

@@ -42,3 +50,3 @@ params: {

},
shape: mergedShape,
shape: function () { return mergedShape; },
});

@@ -45,0 +53,0 @@ return merged;

@@ -5,2 +5,5 @@ export declare namespace util {

const getObjectType: (value: unknown) => string | undefined;
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
const arrayToEnum: <T extends string, U extends [T, ...T[]]>(items: U) => { [k in U[number]]: k; };
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.util = void 0;
var util;

@@ -22,3 +23,14 @@ (function (util) {

};
// const infer = <T extends string, U extends [T, ...T[]]>(items: U): U => {
// return items;
// };
util.arrayToEnum = function (items) {
var obj = {};
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
var item = items_1[_i];
obj[item] = item;
}
return obj;
};
})(util = exports.util || (exports.util = {}));
//# sourceMappingURL=util.js.map

@@ -23,2 +23,3 @@ import { ZodString, ZodStringDef } from './types/string';

import { ZodError } from './ZodError';
import { toZod } from './toZod';
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef;

@@ -34,20 +35,28 @@ declare const stringType: () => ZodString;

declare const unknownType: () => ZodUnknown;
declare const arrayType: <T extends ZodType<any, import("./types/base").ZodTypeDef>>(schema: T) => ZodArray<T>;
declare const arrayType: <T extends ZodTypeAny>(schema: T) => ZodArray<T>;
declare const objectType: <T extends import("./types/base").ZodRawShape>(shape: T) => ZodObject<T, {
strict: true;
}>;
declare const unionType: <T extends [ZodType<any, import("./types/base").ZodTypeDef>, ZodType<any, import("./types/base").ZodTypeDef>, ...ZodType<any, import("./types/base").ZodTypeDef>[]]>(types: T) => ZodUnion<T>;
declare const intersectionType: <T extends ZodType<any, import("./types/base").ZodTypeDef>, U extends ZodType<any, import("./types/base").ZodTypeDef>>(left: T, right: U) => ZodIntersection<T, U>;
declare const tupleType: <T extends [] | [ZodType<any, import("./types/base").ZodTypeDef>, ...ZodType<any, import("./types/base").ZodTypeDef>[]]>(schemas: T) => ZodTuple<T>;
declare const recordType: <Value extends ZodType<any, import("./types/base").ZodTypeDef> = ZodType<any, import("./types/base").ZodTypeDef>>(valueType: Value) => ZodRecord<Value>;
declare const functionType: <T extends ZodTuple<any>, U extends ZodType<any, import("./types/base").ZodTypeDef>>(args: T, returns: U) => ZodFunction<T, U>;
declare const lazyType: <T extends ZodType<any, import("./types/base").ZodTypeDef>>(getter: () => T) => ZodLazy<T>;
declare const unionType: <T extends [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]]>(types: T) => ZodUnion<T>;
declare const intersectionType: <T extends ZodTypeAny, U extends ZodTypeAny>(left: T, right: U) => ZodIntersection<T, U>;
declare const tupleType: <T extends [] | [ZodTypeAny, ...ZodTypeAny[]]>(schemas: T) => ZodTuple<T>;
declare const recordType: <Value extends ZodTypeAny = ZodTypeAny>(valueType: Value) => ZodRecord<Value>;
declare const functionType: <T extends ZodTuple<any>, U extends ZodTypeAny>(args: T, returns: U) => ZodFunction<T, U>;
declare const literalType: <T extends import("./helpers/primitive").Primitive>(value: T) => ZodLiteral<T>;
declare const enumType: <U extends string, T extends [U, ...U[]]>(values: T) => ZodEnum<T>;
declare const promiseType: <T extends ZodType<any, import("./types/base").ZodTypeDef>>(schema: T) => ZodPromise<T>;
declare const promiseType: <T extends ZodTypeAny>(schema: T) => ZodPromise<T>;
declare const ostring: () => ZodUnion<[ZodString, ZodUndefined]>;
declare const onumber: () => ZodUnion<[ZodNumber, ZodUndefined]>;
declare const oboolean: () => ZodUnion<[ZodBoolean, ZodUndefined]>;
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, ostring, onumber, oboolean, };
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, literalType as literal, enumType as enum, promiseType as promise, ostring, onumber, oboolean, };
export { toZod };
export declare const lazy: {
object: <T extends import("./types/base").ZodRawShape>(shape: () => T) => ZodObject<T, {
strict: true;
}>;
};
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodType, ZodType as Schema, ZodTypeAny, ZodDef, ZodError, };
export declare type lazyobject<T extends object> = ZodObject<{
[k in keyof T]: ZodType<T[k], any>;
}>;
export { TypeOf, TypeOf as infer };
"use strict";
/* ZOD */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodError = exports.Schema = exports.ZodType = exports.ZodPromise = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.lazy = exports.oboolean = exports.onumber = exports.ostring = exports.promise = exports.enum = exports.literal = exports.function = exports.record = exports.tuple = exports.intersection = exports.union = exports.object = exports.array = exports.unknown = exports.any = exports.null = exports.undefined = exports.date = exports.boolean = exports.bigint = exports.number = exports.string = void 0;
var string_1 = require("./types/string");
exports.ZodString = string_1.ZodString;
Object.defineProperty(exports, "ZodString", { enumerable: true, get: function () { return string_1.ZodString; } });
var number_1 = require("./types/number");
exports.ZodNumber = number_1.ZodNumber;
Object.defineProperty(exports, "ZodNumber", { enumerable: true, get: function () { return number_1.ZodNumber; } });
var bigint_1 = require("./types/bigint");
exports.ZodBigInt = bigint_1.ZodBigInt;
Object.defineProperty(exports, "ZodBigInt", { enumerable: true, get: function () { return bigint_1.ZodBigInt; } });
var boolean_1 = require("./types/boolean");
exports.ZodBoolean = boolean_1.ZodBoolean;
Object.defineProperty(exports, "ZodBoolean", { enumerable: true, get: function () { return boolean_1.ZodBoolean; } });
var date_1 = require("./types/date");
exports.ZodDate = date_1.ZodDate;
Object.defineProperty(exports, "ZodDate", { enumerable: true, get: function () { return date_1.ZodDate; } });
var undefined_1 = require("./types/undefined");
exports.ZodUndefined = undefined_1.ZodUndefined;
Object.defineProperty(exports, "ZodUndefined", { enumerable: true, get: function () { return undefined_1.ZodUndefined; } });
var null_1 = require("./types/null");
exports.ZodNull = null_1.ZodNull;
Object.defineProperty(exports, "ZodNull", { enumerable: true, get: function () { return null_1.ZodNull; } });
var any_1 = require("./types/any");
exports.ZodAny = any_1.ZodAny;
Object.defineProperty(exports, "ZodAny", { enumerable: true, get: function () { return any_1.ZodAny; } });
var unknown_1 = require("./types/unknown");
exports.ZodUnknown = unknown_1.ZodUnknown;
Object.defineProperty(exports, "ZodUnknown", { enumerable: true, get: function () { return unknown_1.ZodUnknown; } });
var array_1 = require("./types/array");
exports.ZodArray = array_1.ZodArray;
Object.defineProperty(exports, "ZodArray", { enumerable: true, get: function () { return array_1.ZodArray; } });
var object_1 = require("./types/object");
exports.ZodObject = object_1.ZodObject;
Object.defineProperty(exports, "ZodObject", { enumerable: true, get: function () { return object_1.ZodObject; } });
var union_1 = require("./types/union");
exports.ZodUnion = union_1.ZodUnion;
Object.defineProperty(exports, "ZodUnion", { enumerable: true, get: function () { return union_1.ZodUnion; } });
var intersection_1 = require("./types/intersection");
exports.ZodIntersection = intersection_1.ZodIntersection;
Object.defineProperty(exports, "ZodIntersection", { enumerable: true, get: function () { return intersection_1.ZodIntersection; } });
var tuple_1 = require("./types/tuple");
exports.ZodTuple = tuple_1.ZodTuple;
Object.defineProperty(exports, "ZodTuple", { enumerable: true, get: function () { return tuple_1.ZodTuple; } });
var record_1 = require("./types/record");
exports.ZodRecord = record_1.ZodRecord;
Object.defineProperty(exports, "ZodRecord", { enumerable: true, get: function () { return record_1.ZodRecord; } });
var function_1 = require("./types/function");
exports.ZodFunction = function_1.ZodFunction;
Object.defineProperty(exports, "ZodFunction", { enumerable: true, get: function () { return function_1.ZodFunction; } });
var lazy_1 = require("./types/lazy");
exports.ZodLazy = lazy_1.ZodLazy;
Object.defineProperty(exports, "ZodLazy", { enumerable: true, get: function () { return lazy_1.ZodLazy; } });
var literal_1 = require("./types/literal");
exports.ZodLiteral = literal_1.ZodLiteral;
Object.defineProperty(exports, "ZodLiteral", { enumerable: true, get: function () { return literal_1.ZodLiteral; } });
var enum_1 = require("./types/enum");
exports.ZodEnum = enum_1.ZodEnum;
Object.defineProperty(exports, "ZodEnum", { enumerable: true, get: function () { return enum_1.ZodEnum; } });
var promise_1 = require("./types/promise");
exports.ZodPromise = promise_1.ZodPromise;
Object.defineProperty(exports, "ZodPromise", { enumerable: true, get: function () { return promise_1.ZodPromise; } });
var base_1 = require("./types/base");
exports.ZodType = base_1.ZodType;
exports.Schema = base_1.ZodType;
Object.defineProperty(exports, "ZodType", { enumerable: true, get: function () { return base_1.ZodType; } });
Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return base_1.ZodType; } });
var ZodError_1 = require("./ZodError");
exports.ZodError = ZodError_1.ZodError;
Object.defineProperty(exports, "ZodError", { enumerable: true, get: function () { return ZodError_1.ZodError; } });
var stringType = string_1.ZodString.create;

@@ -81,4 +82,3 @@ exports.string = stringType;

exports.function = functionType;
var lazyType = lazy_1.ZodLazy.create;
exports.lazy = lazyType;
// const lazyType = ZodLazy.create;
// const lazyobjectType = ZodLazyObject.create;

@@ -98,2 +98,5 @@ // const recursionType = ZodObject.recursion;

exports.oboolean = oboolean;
exports.lazy = {
object: object_1.ZodObject.lazycreate,
};
//# sourceMappingURL=index.js.map
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var z = __importStar(require("./types/base"));
var array_1 = require("./types/array");
var object_1 = require("./types/object");
exports.applyMask = function (schema, mask, mode) {
var _def = schema._def;
var def = _def;
if (mask === true) {
return schema;
}
else if (typeof mask === 'object' && !Array.isArray(mask)) {
if (def.t === z.ZodTypes.array) {
if (def.type._def.t === z.ZodTypes.object) {
return new array_1.ZodArray({
t: z.ZodTypes.array,
nonempty: def.nonempty,
type: exports.applyMask(def.type, mask, mode),
});
}
else {
throw new Error("You can only " + mode + " arrays of objects.");
}
}
else if (def.t === z.ZodTypes.object) {
var modShape = {};
var shape = def.shape;
if (mode === 'pick') {
if (mask === true)
return shape;
for (var key in mask) {
if (!Object.keys(shape).includes(key))
throw new Error("Unknown key in pick: " + key);
modShape[key] = exports.applyMask(shape[key], mask[key], mode);
}
}
if (mode === 'omit') {
for (var maskKey in mask) {
if (!Object.keys(shape).includes(maskKey))
throw new Error("Unknown key in omit: " + maskKey);
}
for (var key in shape) {
if (mask[key] === true) {
continue;
}
else if (typeof mask[key] === 'object') {
modShape[key] = exports.applyMask(shape[key], mask[key], mode);
}
else {
modShape[key] = shape[key];
}
}
}
return new object_1.ZodObject({
t: z.ZodTypes.object,
params: def.params,
shape: modShape,
});
}
}
throw new Error("Invalid mask!\n\n" + JSON.stringify(mask, null, 2));
};
// import * as z from './types/base';
// import { ZodArray } from './types/array';
// import { ZodDef } from '.';
// import { ZodObject } from './types/object';
// export const applyMask = (schema: z.ZodTypeAny, mask: any, mode: 'omit' | 'pick'): any => {
// const _def = schema._def;
// const def: ZodDef = _def as any;
// if (mask === true) {
// return schema;
// } else if (typeof mask === 'object' && !Array.isArray(mask)) {
// if (def.t === z.ZodTypes.array) {
// if (def.type._def.t === z.ZodTypes.object) {
// return new ZodArray({
// t: z.ZodTypes.array,
// nonempty: def.nonempty,
// type: applyMask(def.type, mask, mode),
// });
// } else {
// throw new Error(`You can only ${mode} arrays of objects.`);
// }
// } else if (def.t === z.ZodTypes.object) {
// const modShape: any = {};
// const shape = def.shape;
// if (mode === 'pick') {
// if (mask === true) return shape;
// for (const key in mask) {
// if (!Object.keys(shape).includes(key)) throw new Error(`Unknown key in pick: ${key}`);
// modShape[key] = applyMask(shape[key], mask[key], mode);
// }
// }
// if (mode === 'omit') {
// for (const maskKey in mask) {
// if (!Object.keys(shape).includes(maskKey)) throw new Error(`Unknown key in omit: ${maskKey}`);
// }
// for (const key in shape) {
// if (mask[key] === true) {
// continue;
// } else if (typeof mask[key] === 'object') {
// modShape[key] = applyMask(shape[key], mask[key], mode);
// } else {
// modShape[key] = shape[key];
// }
// }
// }
// return new ZodObject({
// t: z.ZodTypes.object,
// params: def.params,
// shape: modShape,
// });
// }
// }
// throw new Error(`Invalid mask!\n\n${JSON.stringify(mask, null, 2)}`);
// };
//# sourceMappingURL=oldmasker.js.map
import * as z from './types/base';
import { ErrorMap } from './errorMap';
export declare type ParseParams = {
seen: {
seen?: {
schema: any;
objects: any[];
}[];
path?: (string | number)[];
errorMap?: ErrorMap;
};
export declare const ZodParser: (schemaDef: z.ZodTypeDef) => (obj: any, params?: ParseParams) => any;
export declare const getParsedType: (data: any) => ParsedType;
export declare const ParsedType: {
object: "object";
symbol: "symbol";
unknown: "unknown";
function: "function";
string: "string";
number: "number";
nan: "nan";
boolean: "boolean";
array: "array";
bigint: "bigint";
date: "date";
undefined: "undefined";
null: "null";
promise: "promise";
};
export declare type ParsedType = keyof typeof ParsedType;
export declare const ZodParser: (schemaDef: z.ZodTypeDef) => (obj: any, baseParams?: ParseParams) => any;
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -37,16 +68,85 @@ });

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodParser = exports.ParsedType = exports.getParsedType = void 0;
var z = __importStar(require("./types/base"));
var ZodError_1 = require("./ZodError");
var util_1 = require("./helpers/util");
exports.ZodParser = function (schemaDef) { return function (obj, params) {
if (params === void 0) { params = { seen: [] }; }
var errorMap_1 = require("./errorMap");
exports.getParsedType = function (data) {
if (typeof data === 'string')
return 'string';
if (typeof data === 'number') {
if (Number.isNaN(data))
return 'nan';
return 'number';
}
if (typeof data === 'boolean')
return 'boolean';
if (typeof data === 'bigint')
return 'bigint';
if (typeof data === 'symbol')
return 'symbol';
if (data instanceof Date)
return 'date';
if (typeof data === 'function')
return 'function';
if (data === undefined)
return 'undefined';
if (data === null)
return 'null';
if (typeof data === 'undefined')
return 'undefined';
if (typeof data === 'object') {
if (Array.isArray(data))
return 'array';
if (data.then &&
typeof data.then === 'function' &&
data.catch &&
typeof data.catch === 'function'
// && util.getObjectType(data) !== 'Promise'
) {
return 'promise';
}
return 'object';
}
return 'unknown';
};
exports.ParsedType = util_1.util.arrayToEnum([
'string',
'nan',
'number',
'boolean',
'date',
'bigint',
'symbol',
'function',
'undefined',
'null',
'array',
'object',
'unknown',
'promise',
]);
exports.ZodParser = function (schemaDef) { return function (obj, baseParams) {
if (baseParams === void 0) { baseParams = { seen: [], errorMap: errorMap_1.defaultErrorMap, path: [] }; }
var params = {
seen: baseParams.seen || [],
path: baseParams.path || [],
errorMap: baseParams.errorMap || errorMap_1.defaultErrorMap,
};
var makeError = function (errorData) {
var errorArg = __assign(__assign({}, errorData), { path: params.path });
var ctxArg = { metadata: {}, data: obj };
var defaultError = errorMap_1.defaultErrorMap === params.errorMap
? "Invalid value"
: errorMap_1.defaultErrorMap(errorArg, __assign(__assign({}, ctxArg), { defaultError: "Invalid value." }));
return __assign(__assign({}, errorData), { path: params.path, message: errorData.message || params.errorMap(errorArg, __assign(__assign({}, ctxArg), { defaultError: defaultError })) });
};
var def = schemaDef;

@@ -71,13 +171,33 @@ // const { seen } = params;

// }
var error = new ZodError_1.ZodError([]);
var parsedType = exports.getParsedType(obj);
// runs all invalid_type checks
// if (Object.keys(ParsedType).includes(def.t)) {
// if (parsedType !== def.t) {
// console.log(`def.t: ${def.t}`);
// console.log(`found: ${parsedType}`);
// error.addError(
// makeError({ code: ZodErrorCode.invalid_type, expected: def.t as ParsedType, received: parsedType }),
// );
// throw error;
// }
// }
switch (def.t) {
case z.ZodTypes.string:
if (typeof obj !== 'string')
throw ZodError_1.ZodError.fromString("Non-string type: " + typeof obj);
// error.addError()
if (parsedType !== exports.ParsedType.string) {
//throw ZodError.fromString(`Non-string type: ${typeof obj}`);
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.string, received: parsedType }));
throw error;
}
// return obj as any;
break;
case z.ZodTypes.number:
if (typeof obj !== 'number')
throw ZodError_1.ZodError.fromString("Non-number type: " + typeof obj);
if (parsedType !== exports.ParsedType.number) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.number, received: parsedType }));
throw error;
}
if (Number.isNaN(obj)) {
throw ZodError_1.ZodError.fromString("Non-number type: NaN");
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.number, received: exports.ParsedType.nan }));
throw error;
}

@@ -87,4 +207,6 @@ // return obj as any;

case z.ZodTypes.bigint:
if (typeof obj !== 'bigint') {
throw ZodError_1.ZodError.fromString("Non-bigint type: " + typeof obj + ".");
if (parsedType !== exports.ParsedType.bigint) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.number, received: parsedType }));
throw error;
// throw ZodError.fromString(`Non-bigint type: ${typeof obj}.`);
}

@@ -94,14 +216,23 @@ // return obj;

case z.ZodTypes.boolean:
if (typeof obj !== 'boolean')
throw ZodError_1.ZodError.fromString("Non-boolean type: " + typeof obj);
if (parsedType !== exports.ParsedType.boolean) {
// throw ZodError.fromString(`Non-boolean type: ${typeof obj}`);
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.boolean, received: parsedType }));
throw error;
}
// return obj as any;
break;
case z.ZodTypes.undefined:
if (obj !== undefined)
throw ZodError_1.ZodError.fromString("Non-undefined type:Found: " + typeof obj);
if (parsedType !== exports.ParsedType.undefined) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.undefined, received: parsedType }));
throw error;
// throw ZodError.fromString(`Non-undefined type:Found: ${typeof obj}`);
}
// return undefined;
break;
case z.ZodTypes.null:
if (obj !== null)
throw ZodError_1.ZodError.fromString("Non-null type: " + typeof obj);
if (parsedType !== exports.ParsedType.null) {
// throw ZodError.fromString(`Non-null type: ${typeof obj}`);
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.null, received: parsedType }));
throw error;
}
break;

@@ -113,20 +244,28 @@ case z.ZodTypes.any:

case z.ZodTypes.array:
if (!Array.isArray(obj))
throw ZodError_1.ZodError.fromString("Non-array type: " + typeof obj);
var arrayError_1 = ZodError_1.ZodError.create([]);
if (parsedType !== exports.ParsedType.array) {
// throw ZodError.fromString(`Non-array type: ${typeof obj}`);
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.array, received: parsedType }));
throw error;
}
var data = obj;
// const arrayError = ZodError.create([]);
if (def.nonempty === true && obj.length === 0) {
throw ZodError_1.ZodError.fromString('Array cannot be empty');
error.addError(makeError({ code: ZodError_1.ZodErrorCode.nonempty_array_is_empty }));
throw error;
// throw ZodError.fromString('Array cannot be empty');
}
obj.map(function (item, i) {
data.map(function (item, i) {
try {
var parsedItem = def.type.parse(item, params);
var parsedItem = def.type.parse(item, __assign(__assign({}, params), { path: __spreadArrays(params.path, [i]) }));
return parsedItem;
}
catch (err) {
arrayError_1.mergeChild(i, err);
var zerr = err;
error.addErrors(zerr.errors);
// arrayError.mergeChild(i, err);
}
});
if (!arrayError_1.empty) {
if (!error.isEmpty) {
// throw ZodError.fromString(arrayErrors.join('\n\n'));
throw arrayError_1;
throw error;
}

@@ -136,9 +275,11 @@ break;

case z.ZodTypes.object:
if (typeof obj !== 'object')
throw ZodError_1.ZodError.fromString("Non-object type: " + typeof obj);
if (Array.isArray(obj))
throw ZodError_1.ZodError.fromString("Non-object type: array");
var shape = def.shape;
if (parsedType !== exports.ParsedType.object) {
// throw ZodError.fromString(`Non-object type: ${typeof obj}`);
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.object, received: parsedType }));
throw error;
}
console.log(def.shape);
var shape = def.shape();
if (def.params.strict) {
var shapeKeys_1 = Object.keys(def.shape);
var shapeKeys_1 = Object.keys(shape);
var objKeys = Object.keys(obj);

@@ -148,19 +289,24 @@ var extraKeys = objKeys.filter(function (k) { return shapeKeys_1.indexOf(k) === -1; });

// console.log(def);
throw ZodError_1.ZodError.fromString("Unexpected key(s) in object: " + extraKeys.map(function (k) { return "'" + k + "'"; }).join(', '));
error.addError(makeError({ code: ZodError_1.ZodErrorCode.unrecognized_keys, keys: extraKeys }));
// throw error;
// throw ZodError.fromString(`Unexpected key(s) in object: ${extraKeys.map(k => `'${k}'`).join(', ')}`);
}
}
var parsedObject = {};
var objectError = ZodError_1.ZodError.create([]);
// const parsedObject: any = {};
// const objectError = ZodError.create([]);
for (var key in shape) {
try {
var parsedEntry = def.shape[key].parse(obj[key], params);
parsedObject[key] = parsedEntry;
// const parsedEntry =
def.shape()[key].parse(obj[key], __assign(__assign({}, params), { path: __spreadArrays(params.path, [key]) }));
// parsedObject[key] = parsedEntry;
}
catch (err) {
objectError.mergeChild(key, err);
var zerr = err;
error.addErrors(zerr.errors);
// objectError.mergeChild(key, err);
}
}
if (!objectError.empty) {
throw objectError; //ZodError.fromString(objectErrors.join('\n'));
}
// if (!objectError.isEmpty) {
// throw objectError; //ZodError.fromString(objectErrors.join('\n'));
// }
// return parsedObject;

@@ -170,4 +316,5 @@ break;

var isValid = false;
// const unionErrors: string[] = [];
// unionError.addError('union', 'Error parsing union type.');
var unionErrors = [];
// unionError.addError('union', 'Error parsing union type.');
for (var _i = 0, _a = def.options; _i < _a.length; _i++) {

@@ -180,17 +327,34 @@ var option = _a[_i];

catch (err) {
unionErrors.push("\tunion option #" + def.options.indexOf(option) + ": " + err.message);
unionErrors.push(err);
// unionErrors.push(`\tunion option #${def.options.indexOf(option)}: ${err.message}`);
// isValid = false;
}
}
if (isValid === false) {
throw ZodError_1.ZodError.fromString('\n' + unionErrors.join('\n'));
// throw ZodError.fromString(
// `Error parsing union.\nReceived: ${JSON.stringify(obj, null, 2)}\nExpected: ${def.options
// .map(x => x._def.t)
// .join(' OR ')}`,
// );
// if all but one of the union types threw a type error
// merge in the one non-type-error ZodError the usual way
if (!isValid) {
var filteredErrors = unionErrors.filter(function (err) {
return err.errors[0].code !== 'invalid_type';
});
if (filteredErrors.length === 1) {
error.addErrors(filteredErrors[0].errors);
}
else {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_union,
suberrors: unionErrors,
}));
}
}
// if (!isValid) {
// throw ZodError.fromString('\n' + unionErrors.join('\n'));
// throw ZodError.fromString(
// `Error parsing union.\nReceived: ${JSON.stringify(obj, null, 2)}\nExpected: ${def.options
// .map(x => x._def.t)
// .join(' OR ')}`,
// );
// }
break;
case z.ZodTypes.intersection:
var errors = [];
// const errors: string[] = [];
try {

@@ -200,3 +364,4 @@ def.left.parse(obj, params);

catch (err) {
errors.push("Left side of intersection: " + err.message);
error.addErrors(err.errors);
// errors.push(`Left side of intersection: ${err.message}`);
}

@@ -207,33 +372,42 @@ try {

catch (err) {
errors.push("Right side of intersection: " + err.message);
error.addErrors(err.errors);
// errors.push(`Right side of intersection: ${err.message}`);
}
if (errors.length) {
throw ZodError_1.ZodError.fromString(errors.join('\n'));
}
// if (errors.length) {
// throw ZodError.fromString(errors.join('\n'));
// }
break;
case z.ZodTypes.tuple:
if (!Array.isArray(obj)) {
if (parsedType !== exports.ParsedType.array) {
// tupleError.addError('','Non-array type detected; invalid tuple.')
throw ZodError_1.ZodError.fromString('Non-array type detected; invalid tuple.');
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.array, received: parsedType }));
throw error;
// throw ZodError.fromString('Non-array type detected; invalid tuple.');
}
if (def.items.length !== obj.length) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_array_length, expected: def.items.length, received: obj.length }));
// tupleError.addError('',`Incorrect number of elements in tuple: expected ${def.items.length}, got ${obj.length}`)
throw ZodError_1.ZodError.fromString("Incorrect number of elements in tuple: expected " + def.items.length + ", got " + obj.length);
// throw ZodError.fromString(
// `Incorrect number of elements in tuple: expected ${def.items.length}, got ${obj.length}`,
// );
}
var tupleError = ZodError_1.ZodError.create([]);
// const data:any[] = obj;
// const tupleError = ZodError.create([]);
var parsedTuple = [];
for (var index in obj) {
var item = obj[index];
var tupleData = obj;
for (var index in tupleData) {
var item = tupleData[index];
var itemParser = def.items[index];
try {
parsedTuple.push(itemParser.parse(item, params));
parsedTuple.push(itemParser.parse(item, __assign(__assign({}, params), { path: __spreadArrays(params.path, [index]) })));
}
catch (err) {
console.log("mering child: " + index);
tupleError.mergeChild(index, err);
// console.log(`mering child: ${index}`);
error.addErrors(err.errors);
// tupleError.mergeChild(index, err);
}
}
if (!tupleError.empty) {
throw tupleError;
}
// if (!tupleError.isEmpty) {
// throw tupleError;
// }
// return parsedTuple as any;

@@ -251,8 +425,14 @@ break;

// if (['string','']typeof obj === 'object') throw ZodError.fromString(`Invalid type: ${object}.`);
if (obj !== def.value)
throw ZodError_1.ZodError.fromString(obj + " !== " + def.value);
if (obj !== def.value) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_literal_value, expected: def.value }));
// throw ZodError.fromString(`${obj} !== ${def.value}`);
}
break;
case z.ZodTypes.enum:
if (def.values.indexOf(obj) === -1) {
throw ZodError_1.ZodError.fromString("\"" + obj + "\" does not match any value in enum");
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_enum_value,
options: def.values,
}));
// throw ZodError.fromString(`"${obj}" does not match any value in enum`);
}

@@ -262,4 +442,10 @@ // return obj;

case z.ZodTypes.function:
if (typeof obj !== 'function') {
throw ZodError_1.ZodError.fromString("Non-function type: \"" + typeof obj + "\"");
if (parsedType !== exports.ParsedType.function) {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_type,
expected: exports.ParsedType.function,
received: parsedType,
}));
throw error;
// throw ZodError.fromString(`Non-function type: "${typeof obj}"`);
}

@@ -273,9 +459,31 @@ var validatedFunc = function () {

def.args.parse(args);
var result = obj.apply(void 0, args);
}
catch (err) {
if (err instanceof ZodError_1.ZodError) {
var argsError = new ZodError_1.ZodError([]);
argsError.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_arguments,
suberrors: [err],
}));
throw argsError;
}
throw err;
}
var result = obj.apply(void 0, args);
try {
def.returns.parse(result);
return result;
}
catch (err) {
if (err instanceof ZodError_1.ZodError) {
var returnsError = new ZodError_1.ZodError([]);
returnsError.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_return_type,
suberrors: [err],
}));
throw returnsError;
}
throw err;
}
def.returns.parse(result);
return result;
};

@@ -285,48 +493,72 @@ return validatedFunc;

case z.ZodTypes.record:
if (typeof obj !== 'object')
throw ZodError_1.ZodError.fromString("Non-object type: " + typeof obj);
if (Array.isArray(obj))
throw ZodError_1.ZodError.fromString("Non-object type: array");
var parsedRecord = {};
var recordError = new ZodError_1.ZodError();
if (parsedType !== exports.ParsedType.object) {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_type,
expected: exports.ParsedType.object,
received: parsedType,
}));
throw error;
}
// if (typeof obj !== 'object') throw ZodError.fromString(`Non-object type: ${typeof obj}`);
// if (Array.isArray(obj)) throw ZodError.fromString(`Non-object type: array`);
// const parsedRecord: any = {};
// const recordError = new ZodError([]);
for (var key in obj) {
try {
parsedRecord[key] = def.valueType.parse(obj[key]);
// parsedRecord[key] =
def.valueType.parse(obj[key], __assign(__assign({}, params), { path: __spreadArrays(params.path, [key]) }));
}
catch (err) {
recordError.mergeChild(key, err);
error.addErrors(err.errors);
// recordError.mergeChild(key, err);
}
}
if (!recordError.empty)
throw recordError;
// if (!recordError.isEmpty) throw recordError;
// return parsedRecord;
break;
case z.ZodTypes.date:
if (obj instanceof Date) {
if (isNaN(obj.getTime())) {
// return obj;
// } else {
throw ZodError_1.ZodError.fromString("Invalid date.");
}
if (!(obj instanceof Date)) {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_type,
expected: exports.ParsedType.date,
received: parsedType,
}));
throw error;
}
else {
throw ZodError_1.ZodError.fromString("Non-Date type: " + typeof obj);
if (isNaN(obj.getTime())) {
// if (isNaN(obj.getTime())) {
// return obj;
// } else {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_date,
}));
throw error;
// throw ZodError.fromString(`Invalid date.`);
// }
}
break;
case z.ZodTypes.promise:
if (!obj.then || typeof obj.then !== 'function') {
console.log(JSON.stringify(obj, null, 2));
throw ZodError_1.ZodError.fromString("Non-Promise type: " + typeof obj);
if (parsedType !== exports.ParsedType.promise) {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_type,
expected: exports.ParsedType.promise,
received: parsedType,
}));
throw error;
}
if (!obj.catch || typeof obj.catch !== 'function') {
console.log(JSON.stringify(obj, null, 2));
throw ZodError_1.ZodError.fromString("Non-Promise type: " + typeof obj);
}
// if (!obj.then || typeof obj.then !== 'function') {
// console.log(JSON.stringify(obj, null, 2));
// throw ZodError.fromString(`Non-Promise type: ${typeof obj}`);
// }
// if (!obj.catch || typeof obj.catch !== 'function') {
// console.log(JSON.stringify(obj, null, 2));
// throw ZodError.fromString(`Non-Promise type: ${typeof obj}`);
// }
// if (util.getObjectType(obj) !== 'Promise') {
// throw ZodError.fromString(`Non-Promise type.`);
// }
if (def.checks) {
throw ZodError_1.ZodError.fromString("Can't apply custom validators to Promise schemas.");
}
return new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
// if (def.checks) {
// throw ZodError.fromString("Can't apply custom validators to Promise schemas.");
// }
return new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () {
var objValue, parsed;

@@ -339,3 +571,3 @@ return __generator(this, function (_a) {

try {
parsed = def.type.parse(objValue);
parsed = def.type.parse(objValue, params);
res(parsed);

@@ -360,7 +592,15 @@ }

if (!check.check(obj)) {
throw ZodError_1.ZodError.fromString(check.message || "Failed custom check.");
error.addError(makeError({
code: ZodError_1.ZodErrorCode.custom_error,
params: check.params,
message: check.message,
}));
// throw ZodError.fromString(check.message || `Failed custom check.`);
}
}
if (!error.isEmpty) {
throw error;
}
return obj;
}; };
//# sourceMappingURL=parser.js.map
"use strict";
// import * as z from '.';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var z = __importStar(require("."));
var ZodError_1 = require("./ZodError");
var Category = z.lazy.object(function () { return ({
name: z.string(),
subcategories: z.array(Category),
}); });
var errorMap = function (error, ctx) {
if (error.code === ZodError_1.ZodErrorCode.invalid_type) {
if (error.expected === 'string') {
return "This ain't no string!";
}
}
if (error.code === ZodError_1.ZodErrorCode.custom_error) {
return JSON.stringify(error.params, null, 2);
}
return ctx.defaultError;
};
errorMap;
try {
var checker = z.function(z.tuple([z.string()]), z.boolean()).implement(function (arg) {
return arg.length;
});
checker('12');
// z.string()
// .refinement({
// check: val => val.length > 12,
// // params: { test: 15 },
// message: 'Override!',
// })
// .parse('asdf', { errorMap });
}
catch (err) {
console.log(JSON.stringify(err.errors, null, 2));
}
try {
var validationSchema = z
.object({
firstName: z.string().optional(),
lastName: z.string().optional(),
email: z.string().email(),
password: z.string(),
confirmPassword: z.string(),
})
.refine(function (data) { return data.password === data.confirmPassword; }, 'Both password and confirmation must match');
validationSchema.parse({
firstName: 'zod',
lastName: '',
email: 'theba@zod.c',
password: 'thetetathea',
confirmPassword: 'thethtbet',
});
}
catch (err) {
console.log(JSON.stringify(err.errors, null, 2));
}
// z.number().parse('12', { errorMap });
// interface Category {
// name: string;
// subcategories: Category[];
// }
// const y = z.lazy(()=>z.string());
// const Category: z.lazyobject<Category> = z.lazy.object(() => ({
// name: z.string(),
// subcategories: z.array(Category),
// }));
// const STATUSES = ['Assigned', 'In Progress', 'On Location', 'Succeeded', 'Failed'] as const;

@@ -4,0 +88,0 @@ // const literals = STATUSES.map(z.literal);

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodAny = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -22,3 +22,3 @@ import * as z from './base';

nonempty: () => ZodNonEmptyArray<T>;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(schema: T_1) => ZodArray<T_1>;
static create: <T_1 extends z.ZodTypeAny>(schema: T_1) => ZodArray<T_1>;
}

@@ -25,0 +25,0 @@ export declare class ZodNonEmptyArray<T extends z.ZodTypeAny> extends z.ZodType<[T['_type'], ...T['_type'][]], ZodArrayDef<T>> {

@@ -26,10 +26,23 @@ "use strict";

};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodNonEmptyArray = exports.ZodArray = void 0;
var z = __importStar(require("./base"));

@@ -62,3 +75,3 @@ var undefined_1 = require("./undefined");

_this.nonempty = function () {
return new ZodNonEmptyArray(__assign({}, _this._def, { nonempty: true }));
return new ZodNonEmptyArray(__assign(__assign({}, _this._def), { nonempty: true }));
};

@@ -65,0 +78,0 @@ return _this;

@@ -30,4 +30,7 @@ import { ParseParams } from '../parser';

declare type Check<T> = {
check: (arg: T) => any;
message?: string;
check: (arg: T) => boolean;
params?: {
[k: string]: any;
};
};

@@ -50,3 +53,4 @@ export interface ZodTypeDef {

check(u: Type | unknown): u is Type;
refine: <Val extends (arg: this["_type"]) => any>(check: Val, message?: string) => this;
refine: <Val extends (arg: this['_type']) => any>(check: Val, message?: string) => this;
refinement: (refinement: Check<this['_type']>) => this;
constructor(def: Def);

@@ -53,0 +57,0 @@ abstract toJSON: () => object;

@@ -13,3 +13,11 @@ "use strict";

};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodType = exports.ZodTypes = void 0;
var parser_1 = require("../parser");

@@ -58,5 +66,16 @@ var ZodTypes;

// console.log((this as any).constructor);
return new _this.constructor(__assign({}, _this._def, { checks: (_this._def.checks || []).concat([{ check: check, message: message }]) }));
return new _this.constructor(__assign(__assign({}, _this._def), { checks: __spreadArrays((_this._def.checks || []), [{ check: check, message: message }]) }));
// return this;
};
this.refinement = function (refinement) {
// const finalRefinement = {
// check: refinement.check,
// code: refinement.code || 'custom-refinement-failed',
// message: refinement.message,
// };
// const newChecks = [...this._def.checks || [], { check, message }];
// console.log((this as any).constructor);
return new _this.constructor(__assign(__assign({}, _this._def), { checks: __spreadArrays((_this._def.checks || []), [refinement]) }));
// return this;
};
this.parse = parser_1.ZodParser(def);

@@ -63,0 +82,0 @@ this._def = def;

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodBigInt = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodBoolean = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodDate = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -19,7 +19,7 @@ import * as z from './base';

toJSON: () => ZodEnumDef<T>;
readonly OptionsList: T;
readonly Values: Values<T>;
readonly Enum: Values<T>;
get OptionsList(): T;
get Values(): Values<T>;
get Enum(): Values<T>;
static create: <U extends string, T_1 extends [U, ...U[]]>(values: T_1) => ZodEnum<T_1>;
}
export {};

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodEnum = void 0;
var z = __importStar(require("./base"));

@@ -41,3 +54,3 @@ var undefined_1 = require("./undefined");

},
enumerable: true,
enumerable: false,
configurable: true

@@ -54,3 +67,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -67,3 +80,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -70,0 +83,0 @@ });

@@ -17,3 +17,3 @@ import * as z from './base';

validate: (func: TypeOfFunction<Args, Returns>) => TypeOfFunction<Args, Returns>;
static create: <T extends ZodTuple<any>, U extends z.ZodType<any, z.ZodTypeDef>>(args: T, returns: U) => ZodFunction<T, U>;
static create: <T extends ZodTuple<any>, U extends z.ZodTypeAny>(args: T, returns: U) => ZodFunction<T, U>;
optional: () => ZodUnion<[this, ZodUndefined]>;

@@ -20,0 +20,0 @@ nullable: () => ZodUnion<[this, ZodNull]>;

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodFunction = void 0;
var z = __importStar(require("./base"));

@@ -34,17 +47,13 @@ var undefined_1 = require("./undefined");

_this.implement = function (func) {
var validatedFunc = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
try {
_this._def.args.parse(args);
var result = func.apply(void 0, args);
_this._def.returns.parse(result);
return result;
}
catch (err) {
throw err;
}
};
var validatedFunc = _this.parse(func);
// const validatedFunc = (...args: any[]) => {
// try {
// this._def.args.parse(args as any);
// const result = func(...(args as any));
// this._def.returns.parse(result);
// return result;
// } catch (err) {
// throw err;
// }
// };
return validatedFunc;

@@ -51,0 +60,0 @@ };

@@ -18,3 +18,3 @@ import * as z from './base';

};
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>, U_1 extends z.ZodType<any, z.ZodTypeDef>>(left: T_1, right: U_1) => ZodIntersection<T_1, U_1>;
static create: <T_1 extends z.ZodTypeAny, U_1 extends z.ZodTypeAny>(left: T_1, right: U_1) => ZodIntersection<T_1, U_1>;
}

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodIntersection = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -10,7 +10,7 @@ import * as z from './base';

export declare class ZodLazy<T extends z.ZodTypeAny> extends z.ZodType<z.TypeOf<T>, ZodLazyDef<T>> {
readonly schema: T;
get schema(): T;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
toJSON: () => never;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(getter: () => T_1) => ZodLazy<T_1>;
static create: <T_1 extends z.ZodTypeAny>(getter: () => T_1) => ZodLazy<T_1>;
}

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodLazy = void 0;
var z = __importStar(require("./base"));

@@ -46,3 +59,3 @@ var undefined_1 = require("./undefined");

},
enumerable: true,
enumerable: false,
configurable: true

@@ -49,0 +62,0 @@ });

@@ -8,3 +8,3 @@ import * as z from './base';

export declare class ZodLazyObject<T extends ZodObject<any>> extends z.ZodType<z.TypeOf<T>, ZodLazyObjectDef<T>> {
readonly schema: T;
get schema(): T;
optional: () => this;

@@ -11,0 +11,0 @@ nullable: () => this;

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodLazyObject = void 0;
var z = __importStar(require("./base"));

@@ -52,3 +65,3 @@ var ZodLazyObject = /** @class */ (function (_super) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -55,0 +68,0 @@ });

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodLiteral = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodNull = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodNumber = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -6,5 +6,6 @@ import * as z from './base';

import { objectUtil } from '../helpers/objectUtil';
import { partialUtil } from '../helpers/partialUtil';
export interface ZodObjectDef<T extends z.ZodRawShape = z.ZodRawShape, Params extends ZodObjectParams = ZodObjectParams> extends z.ZodTypeDef {
t: z.ZodTypes.object;
shape: T;
shape: () => T;
params: Params;

@@ -15,2 +16,7 @@ }

}
declare type SetKey<Target extends object, Key extends string, Value extends any> = objectUtil.Flatten<{
[k in Exclude<keyof Target, Key>]: Target[k];
} & {
[k in Key]: Value;
}>;
declare type ZodObjectType<T extends z.ZodRawShape, Params extends ZodObjectParams> = Params['strict'] extends true ? objectUtil.ObjectType<T> : objectUtil.Flatten<objectUtil.ObjectType<T> & {

@@ -24,5 +30,5 @@ [k: string]: any;

readonly _shape: T;
private readonly _params;
readonly shape: T;
readonly params: Params;
readonly _params: Params;
get shape(): T;
get params(): Params;
toJSON: () => {

@@ -34,9 +40,7 @@ t: z.ZodTypes.object;

};
nonstrict: () => ZodObject<T, objectUtil.Flatten<{ [k in Exclude<keyof Params, "strict">]: Params[k]; } & {
strict: false;
}>>;
nonstrict: () => ZodObject<T, SetKey<Params, 'strict', false>>;
optional: () => ZodUnion<[this, ZodUndefined]>;
nullable: () => ZodUnion<[this, ZodNull]>;
augment: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params>;
extend: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params>;
augment: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, Params>;
extend: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, Params>;
/**

@@ -48,19 +52,10 @@ * Prior to zod@1.0.12 there was a bug in the

merge: <MergeShape extends z.ZodRawShape, MergeParams extends ZodObjectParams>(other: ZodObject<MergeShape, MergeParams>) => ZodObject<T & MergeShape, objectUtil.MergeObjectParams<Params, MergeParams>>;
pick: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k in keyof Mask]: k extends keyof T ? T[k] : never; }, Params>;
omit: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k in keyof T]: k extends keyof Mask ? never : T[k]; }, Params>;
pick: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }, Params>;
omit: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }, Params>;
partial: () => ZodObject<{ [k in keyof T]: ZodUnion<[T[k], ZodUndefined]>; }, Params>;
deepPartial: () => ZodObject<{ [k in keyof T]: {
object: T[k] extends ZodObject<infer Shape, infer Params_1> ? ZodUnion<[ZodObject<{ [k in keyof Shape]: {
object: Shape[k] extends ZodObject<infer Shape, infer Params_1> ? ZodUnion<[ZodObject<any, Params_1>, ZodUndefined]> : never;
rest: ZodUnion<[Shape[k], ZodUndefined]>;
}[Shape[k] extends ZodObject<any, {
strict: true;
}> ? "object" : "rest"]; }, Params_1>, ZodUndefined]> : never;
rest: ZodUnion<[T[k], ZodUndefined]>;
}[T[k] extends ZodObject<any, {
deepPartial: () => partialUtil.RootDeepPartial<ZodObject<T>>;
static create: <T_1 extends z.ZodRawShape>(shape: T_1) => ZodObject<T_1, {
strict: true;
}> ? "object" : "rest"]; }, {
strict: true;
}>;
static create: <T_1 extends z.ZodRawShape>(shape: T_1) => ZodObject<T_1, {
static lazycreate: <T_1 extends z.ZodRawShape>(shape: () => T_1) => ZodObject<T_1, {
strict: true;

@@ -67,0 +62,0 @@ }>;

@@ -26,10 +26,23 @@ "use strict";

};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodObject = void 0;
var z = __importStar(require("./base")); // change

@@ -45,3 +58,3 @@ var undefined_1 = require("./undefined");

var AugmentFactory = function (def) { return function (augmentation) {
return new ZodObject(__assign({}, def, { shape: __assign({}, def.shape, augmentation) }));
return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
}; };

@@ -52,6 +65,6 @@ // const infer = <T extends ZodObjectDef<any>>(def: T): T => def;

t: def.t,
shape: Object.assign({}, Object.keys(def.shape).map(function (k) {
shape: Object.assign({}, Object.keys(def.shape()).map(function (k) {
var _a;
return (_a = {},
_a[k] = def.shape[k].toJSON(),
_a[k] = def.shape()[k].toJSON(),
_a);

@@ -70,3 +83,3 @@ })),

t: z.ZodTypes.object,
params: __assign({}, _this._params, { strict: false }),
params: __assign(__assign({}, _this._params), { strict: false }),
});

@@ -102,5 +115,5 @@ };

Object.keys(mask).map(function (key) {
shape[key] = _this._def.shape[key];
shape[key] = _this.shape[key];
});
return new ZodObject(__assign({}, _this._def, { shape: shape }));
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return shape; } }));
};

@@ -110,8 +123,8 @@ // omitKeys = <OmitKeys extends (keyof T)[]>(...omit:OmitKeys):OmitKeys => omit;

var shape = {};
Object.keys(_this._def.shape).map(function (key) {
Object.keys(_this.shape).map(function (key) {
if (!Object.keys(mask).includes(key)) {
shape[key] = _this._def.shape[key];
shape[key] = _this.shape[key];
}
});
return new ZodObject(__assign({}, _this._def, { shape: shape }));
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return shape; } }));
};

@@ -123,6 +136,7 @@ _this.partial = function () {

}
return new ZodObject(__assign({}, _this._def, { shape: newShape }));
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
};
_this.deepPartial = function () {
var newShape = {};
// const shape = this.shape;
for (var key in _this.shape) {

@@ -137,3 +151,3 @@ var fieldSchema = _this.shape[key];

}
return new ZodObject(__assign({}, _this._def, { shape: newShape }));
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
};

@@ -144,5 +158,5 @@ return _this;

get: function () {
return this._def.shape;
return this._def.shape();
},
enumerable: true,
enumerable: false,
configurable: true

@@ -154,3 +168,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -197,2 +211,12 @@ });

// strict: true,
shape: function () { return shape; },
params: {
strict: true,
},
});
};
ZodObject.lazycreate = function (shape) {
return new ZodObject({
t: z.ZodTypes.object,
// strict: true,
shape: shape,

@@ -199,0 +223,0 @@ params: {

@@ -16,3 +16,3 @@ import * as z from './base';

nullable: () => ZodUnion<[this, ZodNull]>;
static create: <T_1 extends z.ZodType<any, z.ZodTypeDef>>(schema: T_1) => ZodPromise<T_1>;
static create: <T_1 extends z.ZodTypeAny>(schema: T_1) => ZodPromise<T_1>;
}

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodPromise = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -18,3 +18,3 @@ import * as z from './base';

nullable: () => ZodUnion<[this, ZodNull]>;
static create: <Value_1 extends z.ZodType<any, z.ZodTypeDef> = z.ZodType<any, z.ZodTypeDef>>(valueType: Value_1) => ZodRecord<Value_1>;
static create: <Value_1 extends z.ZodTypeAny = z.ZodTypeAny>(valueType: Value_1) => ZodRecord<Value_1>;
}

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodRecord = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodString = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -19,3 +19,3 @@ import * as z from './base';

nullable: () => ZodUnion<[this, ZodNull]>;
static create: <T_1 extends [] | [z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(schemas: T_1) => ZodTuple<T_1>;
static create: <T_1 extends [] | [z.ZodTypeAny, ...z.ZodTypeAny[]]>(schemas: T_1) => ZodTuple<T_1>;
}

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodTuple = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var union_1 = require("./union");

@@ -29,4 +29,4 @@ import * as z from './base';

nullable: () => ZodUnion<[this, ZodNull]>;
static create: <Key_1 extends RecordKey = ZodString, Value_1 extends z.ZodType<any, z.ZodTypeDef> = z.ZodType<any, z.ZodTypeDef>>(keyType: Key_1, valueType: Value_1) => ZodRecord<Key_1, Value_1>;
static create: <Key_1 extends RecordKey = ZodString, Value_1 extends z.ZodTypeAny = z.ZodTypeAny>(keyType: Key_1, valueType: Value_1) => ZodRecord<Key_1, Value_1>;
}
export {};

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodRecord = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodUndefined = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var union_1 = require("./union");

@@ -15,4 +15,4 @@ import * as z from './base';

};
static create: <T_1 extends [z.ZodType<any, z.ZodTypeDef>, z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(types: T_1) => ZodUnion<T_1>;
static make: <T_1 extends [z.ZodType<any, z.ZodTypeDef>, z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(...types: T_1) => ZodUnion<T_1>;
static create: <T_1 extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>(types: T_1) => ZodUnion<T_1>;
static make: <T_1 extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>(...types: T_1) => ZodUnion<T_1>;
}

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodUnion = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

@@ -15,10 +15,23 @@ "use strict";

})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodUnknown = void 0;
var z = __importStar(require("./base"));

@@ -25,0 +38,0 @@ var undefined_1 = require("./undefined");

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var z = __importStar(require("./types/base"));
var _1 = require(".");
var util_1 = require("./helpers/util");
var array_1 = require("./types/array");
var object_1 = require("./types/object");
var union_1 = require("./types/union");
var intersection_1 = require("./types/intersection");
var tuple_1 = require("./types/tuple");
var record_1 = require("./types/record");
var lazy_1 = require("./types/lazy");
var ZodError_1 = require("./ZodError");
exports.Visitor = function (visit) { return function (schema) {
var _def = schema._def;
var def = _def;
switch (def.t) {
case z.ZodTypes.string:
return visit(schema);
case z.ZodTypes.number:
return visit(schema);
case z.ZodTypes.bigint:
return visit(schema);
case z.ZodTypes.boolean:
return visit(schema);
case z.ZodTypes.date:
return visit(schema);
case z.ZodTypes.undefined:
return visit(schema);
case z.ZodTypes.null:
return visit(schema);
case z.ZodTypes.any:
return visit(schema);
case z.ZodTypes.unknown:
return visit(schema);
case z.ZodTypes.function:
return visit(schema);
case z.ZodTypes.array:
return visit(new array_1.ZodArray(__assign({}, def, { type: visit(def.type) })));
case z.ZodTypes.object:
var visitedShape = {};
for (var key in def.shape) {
visitedShape[key] = visit(def.shape[key]);
}
return visit(new object_1.ZodObject(__assign({}, def, { shape: visitedShape })));
case z.ZodTypes.union:
return visit(new union_1.ZodUnion(__assign({}, def, { options: def.options.map(function (option) { return visit(option); }) })));
case z.ZodTypes.intersection:
return visit(new intersection_1.ZodIntersection(__assign({}, def, { left: visit(def.left), right: visit(def.left) })));
case z.ZodTypes.tuple:
return visit(new tuple_1.ZodTuple(__assign({}, def, { items: def.items.map(function (item) { return visit(item); }) })));
case z.ZodTypes.record:
return visit(new record_1.ZodRecord(__assign({}, def, { valueType: visit(def.valueType) })));
case z.ZodTypes.lazy:
return visit(new lazy_1.ZodLazy(__assign({}, def, { getter: function () { return visit(def.getter()); } })));
case z.ZodTypes.literal:
return visit(schema);
case z.ZodTypes.enum:
return visit(schema);
case z.ZodTypes.promise:
return visit(new _1.ZodPromise(__assign({}, def, { type: visit(def.type) })));
default:
util_1.util.assertNever(def);
break;
}
throw ZodError_1.ZodError.fromString("Unknown schema type.");
}; };
// import * as z from './types/base';
// import { ZodDef, ZodPromise } from '.';
// import { util } from './helpers/util';
// import { ZodArray } from './types/array';
// import { ZodObject } from './types/object';
// import { ZodUnion } from './types/union';
// import { ZodIntersection } from './types/intersection';
// import { ZodTuple } from './types/tuple';
// import { ZodRecord } from './types/record';
// import { ZodLazy } from './types/lazy';
// import { ZodError } from './ZodError';
// export const Visitor = (visit: (_schema: z.ZodTypeAny) => z.ZodTypeAny) => (schema: z.ZodTypeAny) => {
// const _def = schema._def;
// const def: ZodDef = _def as any;
// switch (def.t) {
// case z.ZodTypes.string:
// return visit(schema);
// case z.ZodTypes.number:
// return visit(schema);
// case z.ZodTypes.bigint:
// return visit(schema);
// case z.ZodTypes.boolean:
// return visit(schema);
// case z.ZodTypes.date:
// return visit(schema);
// case z.ZodTypes.undefined:
// return visit(schema);
// case z.ZodTypes.null:
// return visit(schema);
// case z.ZodTypes.any:
// return visit(schema);
// case z.ZodTypes.unknown:
// return visit(schema);
// case z.ZodTypes.function:
// return visit(schema);
// case z.ZodTypes.array:
// return visit(
// new ZodArray({
// ...def,
// type: visit(def.type),
// }),
// );
// case z.ZodTypes.object:
// const visitedShape: any = {};
// for (const key in def.shape) {
// visitedShape[key] = visit(def.shape[key]);
// }
// return visit(
// new ZodObject({
// ...def,
// shape: visitedShape,
// }),
// );
// case z.ZodTypes.union:
// return visit(
// new ZodUnion({
// ...def,
// options: def.options.map(option => visit(option)) as any,
// }),
// );
// case z.ZodTypes.intersection:
// return visit(
// new ZodIntersection({
// ...def,
// left: visit(def.left),
// right: visit(def.left),
// }),
// );
// case z.ZodTypes.tuple:
// return visit(
// new ZodTuple({
// ...def,
// items: def.items.map(item => visit(item)) as any,
// }),
// );
// case z.ZodTypes.record:
// return visit(
// new ZodRecord({
// ...def,
// valueType: visit(def.valueType),
// }),
// );
// case z.ZodTypes.lazy:
// return visit(
// new ZodLazy({
// ...def,
// getter: () => visit(def.getter()),
// }),
// );
// case z.ZodTypes.literal:
// return visit(schema);
// case z.ZodTypes.enum:
// return visit(schema);
// case z.ZodTypes.promise:
// return visit(
// new ZodPromise({
// ...def,
// type: visit(def.type),
// }),
// );
// default:
// util.assertNever(def);
// break;
// }
// throw ZodError.fromString(`Unknown schema type.`);
// };
//# sourceMappingURL=visit.js.map

@@ -1,20 +0,79 @@

declare type ZodErrorArray = {
import { ParsedType } from './parser';
export declare const ZodErrorCode: {
invalid_type: "invalid_type";
nonempty_array_is_empty: "nonempty_array_is_empty";
custom_error: "custom_error";
invalid_union: "invalid_union";
invalid_array_length: "invalid_array_length";
array_empty: "array_empty";
invalid_literal_value: "invalid_literal_value";
invalid_enum_value: "invalid_enum_value";
unrecognized_keys: "unrecognized_keys";
invalid_arguments: "invalid_arguments";
invalid_return_type: "invalid_return_type";
invalid_date: "invalid_date";
};
export declare type ZodErrorCode = keyof typeof ZodErrorCode;
export declare type ZodSuberrorBase = {
path: (string | number)[];
code: ZodErrorCode;
message?: string;
suberrors?: ZodError[];
};
interface InvalidTypeError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_type;
expected: ParsedType;
received: ParsedType;
}
interface NonEmptyArrayIsEmptyError extends ZodSuberrorBase {
code: typeof ZodErrorCode.nonempty_array_is_empty;
}
interface UnrecognizedKeysError extends ZodSuberrorBase {
code: typeof ZodErrorCode.unrecognized_keys;
keys: string[];
}
interface InvalidUnionError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_union;
}
interface InvalidArrayLengthError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_array_length;
expected: number;
received: number;
}
interface InvalidLiteralValueError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_literal_value;
expected: string | number | boolean;
}
interface InvalidEnumValueError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_enum_value;
options: string[];
}
interface InvalidArgumentsError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_arguments;
}
interface InvalidReturnTypeError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_return_type;
}
interface InvalidDateError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_date;
}
interface CustomError extends ZodSuberrorBase {
code: typeof ZodErrorCode.custom_error;
params?: {
[k: string]: any;
};
}
export declare type ZodSuberrorOptionalMessage = InvalidTypeError | NonEmptyArrayIsEmptyError | UnrecognizedKeysError | InvalidUnionError | InvalidArrayLengthError | InvalidLiteralValueError | InvalidEnumValueError | InvalidArgumentsError | InvalidReturnTypeError | InvalidDateError | CustomError;
export declare type ZodSuberror = ZodSuberrorOptionalMessage & {
message: string;
}[];
};
export declare class ZodError extends Error {
errors: ZodErrorArray;
constructor();
static create: (errors: {
path: (string | number)[];
message: string;
}[]) => ZodError;
readonly message: string;
readonly empty: boolean;
static fromString: (message: string) => ZodError;
mergeChild: (pathElement: string | number, child: Error) => void;
bubbleUp: (pathElement: string | number) => ZodError;
addError: (path: string | number, message: string) => void;
merge: (error: ZodError) => void;
errors: ZodSuberror[];
constructor(errors: ZodSuberror[]);
static create: (errors: ZodSuberror[]) => ZodError;
get message(): string;
get isEmpty(): boolean;
addError: (sub: ZodSuberror) => void;
addErrors: (subs?: ZodSuberror[]) => void;
}
export {};

@@ -15,31 +15,43 @@ "use strict";

})();
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodError = exports.ZodErrorCode = void 0;
var util_1 = require("./helpers/util");
exports.ZodErrorCode = util_1.util.arrayToEnum([
'invalid_type',
'nonempty_array_is_empty',
'custom_error',
'invalid_union',
'invalid_array_length',
'array_empty',
'invalid_literal_value',
'invalid_enum_value',
'unrecognized_keys',
'invalid_arguments',
'invalid_return_type',
'invalid_date',
]);
var ZodError = /** @class */ (function (_super) {
__extends(ZodError, _super);
function ZodError() {
function ZodError(errors) {
var _newTarget = this.constructor;
var _this = _super.call(this) || this;
_this.errors = [];
_this.mergeChild = function (pathElement, child) {
if (child instanceof ZodError) {
_this.merge(child.bubbleUp(pathElement));
}
else {
_this.merge(ZodError.fromString(child.message).bubbleUp(pathElement));
}
_this.addError = function (sub) {
_this.errors = __spreadArrays(_this.errors, [sub]);
};
_this.bubbleUp = function (pathElement) {
return ZodError.create(_this.errors.map(function (err) {
return { path: [pathElement].concat(err.path), message: err.message };
}));
_this.addErrors = function (subs) {
if (subs === void 0) { subs = []; }
_this.errors = __spreadArrays(_this.errors, subs);
};
_this.addError = function (path, message) {
_this.errors = _this.errors.concat([{ path: path === '' ? [] : [path], message: message }]);
};
_this.merge = function (error) {
_this.errors = _this.errors.concat(error.errors);
};
// restore prototype chain
var actualProto = _newTarget.prototype;
Object.setPrototypeOf(_this, actualProto);
_this.errors = errors;
return _this;

@@ -56,25 +68,17 @@ }

},
enumerable: true,
enumerable: false,
configurable: true
});
Object.defineProperty(ZodError.prototype, "empty", {
Object.defineProperty(ZodError.prototype, "isEmpty", {
get: function () {
return this.errors.length === 0;
},
enumerable: true,
enumerable: false,
configurable: true
});
ZodError.create = function (errors) {
var error = new ZodError();
error.errors = errors;
var error = new ZodError(errors);
// error.errors = errors;
return error;
};
ZodError.fromString = function (message) {
return ZodError.create([
{
path: [],
message: message,
},
]);
};
return ZodError;

@@ -81,0 +85,0 @@ }(Error));

{
"name": "zod",
"version": "1.7.1",
"version": "2.0.0-alpha.1",
"description": "TypeScript-first schema declaration and validation library with static type inference",

@@ -56,4 +56,4 @@ "main": "./lib/src/index.js",

"tslint-config-prettier": "^1.18.0",
"typescript": "3.2"
"typescript": "3.9"
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc