feat(planning): grille hebdomadaire complète avec API et filtres
- Connexion API via proxy Angular (résolution CORS, base path /api) - Import CSS ng-zorro global pour les modales et composants - Filtres Camion/Show câblés sur l'affichage de la grille - Camions affichés via TrucksService (linkés au show du même créneau) - Panneau de détails : spectacles + camions du jour sélectionné - Modale de création de spectacle stylisée avec fond et centrage - Positionnement précis des events à la minute dans leur créneau - Auto-scroll vers l'heure courante au chargement - Ligne "maintenant" sur la colonne du jour actuel - Régénération des services OpenAPI (nouveaux noms de types) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+31
-92
@@ -42,7 +42,6 @@ exports._xid = _xid;
|
||||
exports._ksuid = _ksuid;
|
||||
exports._ipv4 = _ipv4;
|
||||
exports._ipv6 = _ipv6;
|
||||
exports._mac = _mac;
|
||||
exports._cidrv4 = _cidrv4;
|
||||
exports._cidrv6 = _cidrv6;
|
||||
exports._base64 = _base64;
|
||||
@@ -110,7 +109,6 @@ exports._normalize = _normalize;
|
||||
exports._trim = _trim;
|
||||
exports._toLowerCase = _toLowerCase;
|
||||
exports._toUpperCase = _toUpperCase;
|
||||
exports._slugify = _slugify;
|
||||
exports._array = _array;
|
||||
exports._union = _union;
|
||||
exports._discriminatedUnion = _discriminatedUnion;
|
||||
@@ -137,14 +135,9 @@ exports._lazy = _lazy;
|
||||
exports._promise = _promise;
|
||||
exports._custom = _custom;
|
||||
exports._refine = _refine;
|
||||
exports._superRefine = _superRefine;
|
||||
exports._check = _check;
|
||||
exports.describe = describe;
|
||||
exports.meta = meta;
|
||||
exports._stringbool = _stringbool;
|
||||
exports._stringFormat = _stringFormat;
|
||||
const checks = __importStar(require("./checks.cjs"));
|
||||
const registries = __importStar(require("./registries.cjs"));
|
||||
const schemas = __importStar(require("./schemas.cjs"));
|
||||
const util = __importStar(require("./util.cjs"));
|
||||
function _string(Class, params) {
|
||||
@@ -307,15 +300,6 @@ function _ipv6(Class, params) {
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
}
|
||||
function _mac(Class, params) {
|
||||
return new Class({
|
||||
type: "string",
|
||||
format: "mac",
|
||||
check: "string_format",
|
||||
abort: false,
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
}
|
||||
function _cidrv4(Class, params) {
|
||||
return new Class({
|
||||
type: "string",
|
||||
@@ -756,10 +740,6 @@ function _toLowerCase() {
|
||||
function _toUpperCase() {
|
||||
return _overwrite((input) => input.toUpperCase());
|
||||
}
|
||||
// slugify
|
||||
function _slugify() {
|
||||
return _overwrite((input) => util.slugify(input));
|
||||
}
|
||||
function _array(Class, element, params) {
|
||||
return new Class({
|
||||
type: "array",
|
||||
@@ -900,7 +880,7 @@ function _default(Class, innerType, defaultValue) {
|
||||
type: "default",
|
||||
innerType,
|
||||
get defaultValue() {
|
||||
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
|
||||
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -967,6 +947,13 @@ function _custom(Class, fn, _params) {
|
||||
});
|
||||
return schema;
|
||||
}
|
||||
// export function _refine<T>(
|
||||
// Class: util.SchemaClass<schemas.$ZodCustom>,
|
||||
// fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
|
||||
// _params: string | $ZodCustomParams = {}
|
||||
// ): checks.$ZodCheck<T> {
|
||||
// return _custom(Class, fn, _params);
|
||||
// }
|
||||
// same as _custom but defaults to abort:false
|
||||
function _refine(Class, fn, _params) {
|
||||
const schema = new Class({
|
||||
@@ -977,58 +964,6 @@ function _refine(Class, fn, _params) {
|
||||
});
|
||||
return schema;
|
||||
}
|
||||
function _superRefine(fn) {
|
||||
const ch = _check((payload) => {
|
||||
payload.addIssue = (issue) => {
|
||||
if (typeof issue === "string") {
|
||||
payload.issues.push(util.issue(issue, payload.value, ch._zod.def));
|
||||
}
|
||||
else {
|
||||
// for Zod 3 backwards compatibility
|
||||
const _issue = issue;
|
||||
if (_issue.fatal)
|
||||
_issue.continue = false;
|
||||
_issue.code ?? (_issue.code = "custom");
|
||||
_issue.input ?? (_issue.input = payload.value);
|
||||
_issue.inst ?? (_issue.inst = ch);
|
||||
_issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
|
||||
payload.issues.push(util.issue(_issue));
|
||||
}
|
||||
};
|
||||
return fn(payload.value, payload);
|
||||
});
|
||||
return ch;
|
||||
}
|
||||
function _check(fn, params) {
|
||||
const ch = new checks.$ZodCheck({
|
||||
check: "custom",
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
ch._zod.check = fn;
|
||||
return ch;
|
||||
}
|
||||
function describe(description) {
|
||||
const ch = new checks.$ZodCheck({ check: "describe" });
|
||||
ch._zod.onattach = [
|
||||
(inst) => {
|
||||
const existing = registries.globalRegistry.get(inst) ?? {};
|
||||
registries.globalRegistry.add(inst, { ...existing, description });
|
||||
},
|
||||
];
|
||||
ch._zod.check = () => { }; // no-op check
|
||||
return ch;
|
||||
}
|
||||
function meta(metadata) {
|
||||
const ch = new checks.$ZodCheck({ check: "meta" });
|
||||
ch._zod.onattach = [
|
||||
(inst) => {
|
||||
const existing = registries.globalRegistry.get(inst) ?? {};
|
||||
registries.globalRegistry.add(inst, { ...existing, ...metadata });
|
||||
},
|
||||
];
|
||||
ch._zod.check = () => { }; // no-op check
|
||||
return ch;
|
||||
}
|
||||
function _stringbool(Classes, _params) {
|
||||
const params = util.normalizeParams(_params);
|
||||
let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
|
||||
@@ -1039,16 +974,13 @@ function _stringbool(Classes, _params) {
|
||||
}
|
||||
const truthySet = new Set(truthyArray);
|
||||
const falsySet = new Set(falsyArray);
|
||||
const _Codec = Classes.Codec ?? schemas.$ZodCodec;
|
||||
const _Pipe = Classes.Pipe ?? schemas.$ZodPipe;
|
||||
const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
|
||||
const _String = Classes.String ?? schemas.$ZodString;
|
||||
const stringSchema = new _String({ type: "string", error: params.error });
|
||||
const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
|
||||
const codec = new _Codec({
|
||||
type: "pipe",
|
||||
in: stringSchema,
|
||||
out: booleanSchema,
|
||||
transform: ((input, payload) => {
|
||||
const _Transform = Classes.Transform ?? schemas.$ZodTransform;
|
||||
const tx = new _Transform({
|
||||
type: "transform",
|
||||
transform: (input, payload) => {
|
||||
let data = input;
|
||||
if (params.case !== "sensitive")
|
||||
data = data.toLowerCase();
|
||||
@@ -1064,23 +996,30 @@ function _stringbool(Classes, _params) {
|
||||
expected: "stringbool",
|
||||
values: [...truthySet, ...falsySet],
|
||||
input: payload.value,
|
||||
inst: codec,
|
||||
continue: false,
|
||||
inst: tx,
|
||||
});
|
||||
return {};
|
||||
}
|
||||
}),
|
||||
reverseTransform: ((input, _payload) => {
|
||||
if (input === true) {
|
||||
return truthyArray[0] || "true";
|
||||
}
|
||||
else {
|
||||
return falsyArray[0] || "false";
|
||||
}
|
||||
},
|
||||
error: params.error,
|
||||
});
|
||||
// params.error;
|
||||
const innerPipe = new _Pipe({
|
||||
type: "pipe",
|
||||
in: new _String({ type: "string", error: params.error }),
|
||||
out: tx,
|
||||
error: params.error,
|
||||
});
|
||||
const outerPipe = new _Pipe({
|
||||
type: "pipe",
|
||||
in: innerPipe,
|
||||
out: new _Boolean({
|
||||
type: "boolean",
|
||||
error: params.error,
|
||||
}),
|
||||
error: params.error,
|
||||
});
|
||||
return codec;
|
||||
return outerPipe;
|
||||
}
|
||||
function _stringFormat(Class, format, fnOrRegex, _params = {}) {
|
||||
const params = util.normalizeParams(_params);
|
||||
|
||||
+76
-94
@@ -1,7 +1,6 @@
|
||||
import * as checks from "./checks.cjs";
|
||||
import type * as core from "./core.cjs";
|
||||
import type * as errors from "./errors.cjs";
|
||||
import * as registries from "./registries.cjs";
|
||||
import * as schemas from "./schemas.cjs";
|
||||
import * as util from "./util.cjs";
|
||||
export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
|
||||
@@ -20,76 +19,73 @@ export type CheckTypeParams<T extends schemas.$ZodType & checks.$ZodCheck = sche
|
||||
export type $ZodStringParams = TypeParams<schemas.$ZodString<string>, "coerce">;
|
||||
export declare function _string<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
|
||||
export declare function _coercedString<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
|
||||
export type $ZodStringFormatParams = CheckTypeParams<schemas.$ZodStringFormat, "format" | "coerce" | "when" | "pattern">;
|
||||
export type $ZodStringFormatParams = CheckTypeParams<schemas.$ZodStringFormat, "format" | "coerce">;
|
||||
export type $ZodCheckStringFormatParams = CheckParams<checks.$ZodCheckStringFormat, "format">;
|
||||
export type $ZodEmailParams = StringFormatParams<schemas.$ZodEmail, "when">;
|
||||
export type $ZodCheckEmailParams = CheckStringFormatParams<schemas.$ZodEmail, "when">;
|
||||
export type $ZodEmailParams = StringFormatParams<schemas.$ZodEmail>;
|
||||
export type $ZodCheckEmailParams = CheckStringFormatParams<schemas.$ZodEmail>;
|
||||
export declare function _email<T extends schemas.$ZodEmail>(Class: util.SchemaClass<T>, params?: string | $ZodEmailParams | $ZodCheckEmailParams): T;
|
||||
export type $ZodGUIDParams = StringFormatParams<schemas.$ZodGUID, "pattern" | "when">;
|
||||
export type $ZodCheckGUIDParams = CheckStringFormatParams<schemas.$ZodGUID, "pattern" | "when">;
|
||||
export type $ZodGUIDParams = StringFormatParams<schemas.$ZodGUID, "pattern">;
|
||||
export type $ZodCheckGUIDParams = CheckStringFormatParams<schemas.$ZodGUID, "pattern">;
|
||||
export declare function _guid<T extends schemas.$ZodGUID>(Class: util.SchemaClass<T>, params?: string | $ZodGUIDParams | $ZodCheckGUIDParams): T;
|
||||
export type $ZodUUIDParams = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDParams = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDParams = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDParams = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuid<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDParams | $ZodCheckUUIDParams): T;
|
||||
export type $ZodUUIDv4Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv4Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDv4Params = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDv4Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuidv4<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv4Params | $ZodCheckUUIDv4Params): T;
|
||||
export type $ZodUUIDv6Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv6Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDv6Params = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDv6Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuidv6<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv6Params | $ZodCheckUUIDv6Params): T;
|
||||
export type $ZodUUIDv7Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv7Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDv7Params = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDv7Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuidv7<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv7Params | $ZodCheckUUIDv7Params): T;
|
||||
export type $ZodURLParams = StringFormatParams<schemas.$ZodURL, "when">;
|
||||
export type $ZodCheckURLParams = CheckStringFormatParams<schemas.$ZodURL, "when">;
|
||||
export type $ZodURLParams = StringFormatParams<schemas.$ZodURL>;
|
||||
export type $ZodCheckURLParams = CheckStringFormatParams<schemas.$ZodURL>;
|
||||
export declare function _url<T extends schemas.$ZodURL>(Class: util.SchemaClass<T>, params?: string | $ZodURLParams | $ZodCheckURLParams): T;
|
||||
export type $ZodEmojiParams = StringFormatParams<schemas.$ZodEmoji, "when">;
|
||||
export type $ZodCheckEmojiParams = CheckStringFormatParams<schemas.$ZodEmoji, "when">;
|
||||
export type $ZodEmojiParams = StringFormatParams<schemas.$ZodEmoji>;
|
||||
export type $ZodCheckEmojiParams = CheckStringFormatParams<schemas.$ZodEmoji>;
|
||||
export declare function _emoji<T extends schemas.$ZodEmoji>(Class: util.SchemaClass<T>, params?: string | $ZodEmojiParams | $ZodCheckEmojiParams): T;
|
||||
export type $ZodNanoIDParams = StringFormatParams<schemas.$ZodNanoID, "when">;
|
||||
export type $ZodCheckNanoIDParams = CheckStringFormatParams<schemas.$ZodNanoID, "when">;
|
||||
export type $ZodNanoIDParams = StringFormatParams<schemas.$ZodNanoID>;
|
||||
export type $ZodCheckNanoIDParams = CheckStringFormatParams<schemas.$ZodNanoID>;
|
||||
export declare function _nanoid<T extends schemas.$ZodNanoID>(Class: util.SchemaClass<T>, params?: string | $ZodNanoIDParams | $ZodCheckNanoIDParams): T;
|
||||
export type $ZodCUIDParams = StringFormatParams<schemas.$ZodCUID, "when">;
|
||||
export type $ZodCheckCUIDParams = CheckStringFormatParams<schemas.$ZodCUID, "when">;
|
||||
export type $ZodCUIDParams = StringFormatParams<schemas.$ZodCUID>;
|
||||
export type $ZodCheckCUIDParams = CheckStringFormatParams<schemas.$ZodCUID>;
|
||||
export declare function _cuid<T extends schemas.$ZodCUID>(Class: util.SchemaClass<T>, params?: string | $ZodCUIDParams | $ZodCheckCUIDParams): T;
|
||||
export type $ZodCUID2Params = StringFormatParams<schemas.$ZodCUID2, "when">;
|
||||
export type $ZodCheckCUID2Params = CheckStringFormatParams<schemas.$ZodCUID2, "when">;
|
||||
export type $ZodCUID2Params = StringFormatParams<schemas.$ZodCUID2>;
|
||||
export type $ZodCheckCUID2Params = CheckStringFormatParams<schemas.$ZodCUID2>;
|
||||
export declare function _cuid2<T extends schemas.$ZodCUID2>(Class: util.SchemaClass<T>, params?: string | $ZodCUID2Params | $ZodCheckCUID2Params): T;
|
||||
export type $ZodULIDParams = StringFormatParams<schemas.$ZodULID, "when">;
|
||||
export type $ZodCheckULIDParams = CheckStringFormatParams<schemas.$ZodULID, "when">;
|
||||
export type $ZodULIDParams = StringFormatParams<schemas.$ZodULID>;
|
||||
export type $ZodCheckULIDParams = CheckStringFormatParams<schemas.$ZodULID>;
|
||||
export declare function _ulid<T extends schemas.$ZodULID>(Class: util.SchemaClass<T>, params?: string | $ZodULIDParams | $ZodCheckULIDParams): T;
|
||||
export type $ZodXIDParams = StringFormatParams<schemas.$ZodXID, "when">;
|
||||
export type $ZodCheckXIDParams = CheckStringFormatParams<schemas.$ZodXID, "when">;
|
||||
export type $ZodXIDParams = StringFormatParams<schemas.$ZodXID>;
|
||||
export type $ZodCheckXIDParams = CheckStringFormatParams<schemas.$ZodXID>;
|
||||
export declare function _xid<T extends schemas.$ZodXID>(Class: util.SchemaClass<T>, params?: string | $ZodXIDParams | $ZodCheckXIDParams): T;
|
||||
export type $ZodKSUIDParams = StringFormatParams<schemas.$ZodKSUID, "when">;
|
||||
export type $ZodCheckKSUIDParams = CheckStringFormatParams<schemas.$ZodKSUID, "when">;
|
||||
export type $ZodKSUIDParams = StringFormatParams<schemas.$ZodKSUID>;
|
||||
export type $ZodCheckKSUIDParams = CheckStringFormatParams<schemas.$ZodKSUID>;
|
||||
export declare function _ksuid<T extends schemas.$ZodKSUID>(Class: util.SchemaClass<T>, params?: string | $ZodKSUIDParams | $ZodCheckKSUIDParams): T;
|
||||
export type $ZodIPv4Params = StringFormatParams<schemas.$ZodIPv4, "pattern" | "when" | "version">;
|
||||
export type $ZodCheckIPv4Params = CheckStringFormatParams<schemas.$ZodIPv4, "pattern" | "when" | "version">;
|
||||
export type $ZodIPv4Params = StringFormatParams<schemas.$ZodIPv4, "pattern">;
|
||||
export type $ZodCheckIPv4Params = CheckStringFormatParams<schemas.$ZodIPv4, "pattern">;
|
||||
export declare function _ipv4<T extends schemas.$ZodIPv4>(Class: util.SchemaClass<T>, params?: string | $ZodIPv4Params | $ZodCheckIPv4Params): T;
|
||||
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
||||
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
||||
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern">;
|
||||
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern">;
|
||||
export declare function _ipv6<T extends schemas.$ZodIPv6>(Class: util.SchemaClass<T>, params?: string | $ZodIPv6Params | $ZodCheckIPv6Params): T;
|
||||
export type $ZodMACParams = StringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
||||
export type $ZodCheckMACParams = CheckStringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
||||
export declare function _mac<T extends schemas.$ZodMAC>(Class: util.SchemaClass<T>, params?: string | $ZodMACParams | $ZodCheckMACParams): T;
|
||||
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
||||
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
||||
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern">;
|
||||
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern">;
|
||||
export declare function _cidrv4<T extends schemas.$ZodCIDRv4>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv4Params | $ZodCheckCIDRv4Params): T;
|
||||
export type $ZodCIDRv6Params = StringFormatParams<schemas.$ZodCIDRv6, "pattern" | "when">;
|
||||
export type $ZodCheckCIDRv6Params = CheckStringFormatParams<schemas.$ZodCIDRv6, "pattern" | "when">;
|
||||
export type $ZodCIDRv6Params = StringFormatParams<schemas.$ZodCIDRv6, "pattern">;
|
||||
export type $ZodCheckCIDRv6Params = CheckStringFormatParams<schemas.$ZodCIDRv6, "pattern">;
|
||||
export declare function _cidrv6<T extends schemas.$ZodCIDRv6>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv6Params | $ZodCheckCIDRv6Params): T;
|
||||
export type $ZodBase64Params = StringFormatParams<schemas.$ZodBase64, "pattern" | "when">;
|
||||
export type $ZodCheckBase64Params = CheckStringFormatParams<schemas.$ZodBase64, "pattern" | "when">;
|
||||
export type $ZodBase64Params = StringFormatParams<schemas.$ZodBase64, "pattern">;
|
||||
export type $ZodCheckBase64Params = CheckStringFormatParams<schemas.$ZodBase64, "pattern">;
|
||||
export declare function _base64<T extends schemas.$ZodBase64>(Class: util.SchemaClass<T>, params?: string | $ZodBase64Params | $ZodCheckBase64Params): T;
|
||||
export type $ZodBase64URLParams = StringFormatParams<schemas.$ZodBase64URL, "pattern" | "when">;
|
||||
export type $ZodCheckBase64URLParams = CheckStringFormatParams<schemas.$ZodBase64URL, "pattern" | "when">;
|
||||
export type $ZodBase64URLParams = StringFormatParams<schemas.$ZodBase64URL, "pattern">;
|
||||
export type $ZodCheckBase64URLParams = CheckStringFormatParams<schemas.$ZodBase64URL, "pattern">;
|
||||
export declare function _base64url<T extends schemas.$ZodBase64URL>(Class: util.SchemaClass<T>, params?: string | $ZodBase64URLParams | $ZodCheckBase64URLParams): T;
|
||||
export type $ZodE164Params = StringFormatParams<schemas.$ZodE164, "when">;
|
||||
export type $ZodCheckE164Params = CheckStringFormatParams<schemas.$ZodE164, "when">;
|
||||
export type $ZodE164Params = StringFormatParams<schemas.$ZodE164>;
|
||||
export type $ZodCheckE164Params = CheckStringFormatParams<schemas.$ZodE164>;
|
||||
export declare function _e164<T extends schemas.$ZodE164>(Class: util.SchemaClass<T>, params?: string | $ZodE164Params | $ZodCheckE164Params): T;
|
||||
export type $ZodJWTParams = StringFormatParams<schemas.$ZodJWT, "pattern" | "when">;
|
||||
export type $ZodCheckJWTParams = CheckStringFormatParams<schemas.$ZodJWT, "pattern" | "when">;
|
||||
export type $ZodJWTParams = StringFormatParams<schemas.$ZodJWT, "pattern">;
|
||||
export type $ZodCheckJWTParams = CheckStringFormatParams<schemas.$ZodJWT, "pattern">;
|
||||
export declare function _jwt<T extends schemas.$ZodJWT>(Class: util.SchemaClass<T>, params?: string | $ZodJWTParams | $ZodCheckJWTParams): T;
|
||||
export declare const TimePrecision: {
|
||||
readonly Any: null;
|
||||
@@ -98,21 +94,21 @@ export declare const TimePrecision: {
|
||||
readonly Millisecond: 3;
|
||||
readonly Microsecond: 6;
|
||||
};
|
||||
export type $ZodISODateTimeParams = StringFormatParams<schemas.$ZodISODateTime, "pattern" | "when">;
|
||||
export type $ZodCheckISODateTimeParams = CheckStringFormatParams<schemas.$ZodISODateTime, "pattern" | "when">;
|
||||
export type $ZodISODateTimeParams = StringFormatParams<schemas.$ZodISODateTime, "pattern">;
|
||||
export type $ZodCheckISODateTimeParams = CheckStringFormatParams<schemas.$ZodISODateTime, "pattern">;
|
||||
export declare function _isoDateTime<T extends schemas.$ZodISODateTime>(Class: util.SchemaClass<T>, params?: string | $ZodISODateTimeParams | $ZodCheckISODateTimeParams): T;
|
||||
export type $ZodISODateParams = StringFormatParams<schemas.$ZodISODate, "pattern" | "when">;
|
||||
export type $ZodCheckISODateParams = CheckStringFormatParams<schemas.$ZodISODate, "pattern" | "when">;
|
||||
export type $ZodISODateParams = StringFormatParams<schemas.$ZodISODate, "pattern">;
|
||||
export type $ZodCheckISODateParams = CheckStringFormatParams<schemas.$ZodISODate, "pattern">;
|
||||
export declare function _isoDate<T extends schemas.$ZodISODate>(Class: util.SchemaClass<T>, params?: string | $ZodISODateParams | $ZodCheckISODateParams): T;
|
||||
export type $ZodISOTimeParams = StringFormatParams<schemas.$ZodISOTime, "pattern" | "when">;
|
||||
export type $ZodCheckISOTimeParams = CheckStringFormatParams<schemas.$ZodISOTime, "pattern" | "when">;
|
||||
export type $ZodISOTimeParams = StringFormatParams<schemas.$ZodISOTime, "pattern">;
|
||||
export type $ZodCheckISOTimeParams = CheckStringFormatParams<schemas.$ZodISOTime, "pattern">;
|
||||
export declare function _isoTime<T extends schemas.$ZodISOTime>(Class: util.SchemaClass<T>, params?: string | $ZodISOTimeParams | $ZodCheckISOTimeParams): T;
|
||||
export type $ZodISODurationParams = StringFormatParams<schemas.$ZodISODuration, "when">;
|
||||
export type $ZodCheckISODurationParams = CheckStringFormatParams<schemas.$ZodISODuration, "when">;
|
||||
export type $ZodISODurationParams = StringFormatParams<schemas.$ZodISODuration>;
|
||||
export type $ZodCheckISODurationParams = CheckStringFormatParams<schemas.$ZodISODuration>;
|
||||
export declare function _isoDuration<T extends schemas.$ZodISODuration>(Class: util.SchemaClass<T>, params?: string | $ZodISODurationParams | $ZodCheckISODurationParams): T;
|
||||
export type $ZodNumberParams = TypeParams<schemas.$ZodNumber<number>, "coerce">;
|
||||
export type $ZodNumberFormatParams = CheckTypeParams<schemas.$ZodNumberFormat, "format" | "coerce">;
|
||||
export type $ZodCheckNumberFormatParams = CheckParams<checks.$ZodCheckNumberFormat, "format" | "when">;
|
||||
export type $ZodCheckNumberFormatParams = CheckParams<checks.$ZodCheckNumberFormat, "format">;
|
||||
export declare function _number<T extends schemas.$ZodNumber>(Class: util.SchemaClass<T>, params?: string | $ZodNumberParams): T;
|
||||
export declare function _coercedNumber<T extends schemas.$ZodNumber>(Class: util.SchemaClass<T>, params?: string | $ZodNumberParams): T;
|
||||
export declare function _int<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
@@ -125,7 +121,7 @@ export declare function _boolean<T extends schemas.$ZodBoolean>(Class: util.Sche
|
||||
export declare function _coercedBoolean<T extends schemas.$ZodBoolean>(Class: util.SchemaClass<T>, params?: string | $ZodBooleanParams): T;
|
||||
export type $ZodBigIntParams = TypeParams<schemas.$ZodBigInt<bigint>>;
|
||||
export type $ZodBigIntFormatParams = CheckTypeParams<schemas.$ZodBigIntFormat, "format" | "coerce">;
|
||||
export type $ZodCheckBigIntFormatParams = CheckParams<checks.$ZodCheckBigIntFormat, "format" | "when">;
|
||||
export type $ZodCheckBigIntFormatParams = CheckParams<checks.$ZodCheckBigIntFormat, "format">;
|
||||
export declare function _bigint<T extends schemas.$ZodBigInt>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntParams): T;
|
||||
export declare function _coercedBigint<T extends schemas.$ZodBigInt>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntParams): T;
|
||||
export declare function _int64<T extends schemas.$ZodBigIntFormat>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntFormatParams): T;
|
||||
@@ -149,13 +145,13 @@ export declare function _date<T extends schemas.$ZodDate>(Class: util.SchemaClas
|
||||
export declare function _coercedDate<T extends schemas.$ZodDate>(Class: util.SchemaClass<T>, params?: string | $ZodDateParams): T;
|
||||
export type $ZodNaNParams = TypeParams<schemas.$ZodNaN>;
|
||||
export declare function _nan<T extends schemas.$ZodNaN>(Class: util.SchemaClass<T>, params?: string | $ZodNaNParams): T;
|
||||
export type $ZodCheckLessThanParams = CheckParams<checks.$ZodCheckLessThan, "inclusive" | "value" | "when">;
|
||||
export type $ZodCheckLessThanParams = CheckParams<checks.$ZodCheckLessThan, "inclusive" | "value">;
|
||||
export declare function _lt(value: util.Numeric, params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan<util.Numeric>;
|
||||
export declare function _lte(value: util.Numeric, params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan<util.Numeric>;
|
||||
export {
|
||||
/** @deprecated Use `z.lte()` instead. */
|
||||
_lte as _max, };
|
||||
export type $ZodCheckGreaterThanParams = CheckParams<checks.$ZodCheckGreaterThan, "inclusive" | "value" | "when">;
|
||||
export type $ZodCheckGreaterThanParams = CheckParams<checks.$ZodCheckGreaterThan, "inclusive" | "value">;
|
||||
export declare function _gt(value: util.Numeric, params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export declare function _gte(value: util.Numeric, params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export {
|
||||
@@ -165,44 +161,43 @@ export declare function _positive(params?: string | $ZodCheckGreaterThanParams):
|
||||
export declare function _negative(params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan;
|
||||
export declare function _nonpositive(params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan;
|
||||
export declare function _nonnegative(params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export type $ZodCheckMultipleOfParams = CheckParams<checks.$ZodCheckMultipleOf, "value" | "when">;
|
||||
export type $ZodCheckMultipleOfParams = CheckParams<checks.$ZodCheckMultipleOf, "value">;
|
||||
export declare function _multipleOf(value: number | bigint, params?: string | $ZodCheckMultipleOfParams): checks.$ZodCheckMultipleOf;
|
||||
export type $ZodCheckMaxSizeParams = CheckParams<checks.$ZodCheckMaxSize, "maximum" | "when">;
|
||||
export type $ZodCheckMaxSizeParams = CheckParams<checks.$ZodCheckMaxSize, "maximum">;
|
||||
export declare function _maxSize(maximum: number, params?: string | $ZodCheckMaxSizeParams): checks.$ZodCheckMaxSize<util.HasSize>;
|
||||
export type $ZodCheckMinSizeParams = CheckParams<checks.$ZodCheckMinSize, "minimum" | "when">;
|
||||
export type $ZodCheckMinSizeParams = CheckParams<checks.$ZodCheckMinSize, "minimum">;
|
||||
export declare function _minSize(minimum: number, params?: string | $ZodCheckMinSizeParams): checks.$ZodCheckMinSize<util.HasSize>;
|
||||
export type $ZodCheckSizeEqualsParams = CheckParams<checks.$ZodCheckSizeEquals, "size" | "when">;
|
||||
export type $ZodCheckSizeEqualsParams = CheckParams<checks.$ZodCheckSizeEquals, "size">;
|
||||
export declare function _size(size: number, params?: string | $ZodCheckSizeEqualsParams): checks.$ZodCheckSizeEquals<util.HasSize>;
|
||||
export type $ZodCheckMaxLengthParams = CheckParams<checks.$ZodCheckMaxLength, "maximum" | "when">;
|
||||
export type $ZodCheckMaxLengthParams = CheckParams<checks.$ZodCheckMaxLength, "maximum">;
|
||||
export declare function _maxLength(maximum: number, params?: string | $ZodCheckMaxLengthParams): checks.$ZodCheckMaxLength<util.HasLength>;
|
||||
export type $ZodCheckMinLengthParams = CheckParams<checks.$ZodCheckMinLength, "minimum" | "when">;
|
||||
export type $ZodCheckMinLengthParams = CheckParams<checks.$ZodCheckMinLength, "minimum">;
|
||||
export declare function _minLength(minimum: number, params?: string | $ZodCheckMinLengthParams): checks.$ZodCheckMinLength<util.HasLength>;
|
||||
export type $ZodCheckLengthEqualsParams = CheckParams<checks.$ZodCheckLengthEquals, "length" | "when">;
|
||||
export type $ZodCheckLengthEqualsParams = CheckParams<checks.$ZodCheckLengthEquals, "length">;
|
||||
export declare function _length(length: number, params?: string | $ZodCheckLengthEqualsParams): checks.$ZodCheckLengthEquals<util.HasLength>;
|
||||
export type $ZodCheckRegexParams = CheckParams<checks.$ZodCheckRegex, "format" | "pattern" | "when">;
|
||||
export type $ZodCheckRegexParams = CheckParams<checks.$ZodCheckRegex, "format" | "pattern">;
|
||||
export declare function _regex(pattern: RegExp, params?: string | $ZodCheckRegexParams): checks.$ZodCheckRegex;
|
||||
export type $ZodCheckLowerCaseParams = CheckParams<checks.$ZodCheckLowerCase, "format" | "when">;
|
||||
export type $ZodCheckLowerCaseParams = CheckParams<checks.$ZodCheckLowerCase, "format">;
|
||||
export declare function _lowercase(params?: string | $ZodCheckLowerCaseParams): checks.$ZodCheckLowerCase;
|
||||
export type $ZodCheckUpperCaseParams = CheckParams<checks.$ZodCheckUpperCase, "format" | "when">;
|
||||
export type $ZodCheckUpperCaseParams = CheckParams<checks.$ZodCheckUpperCase, "format">;
|
||||
export declare function _uppercase(params?: string | $ZodCheckUpperCaseParams): checks.$ZodCheckUpperCase;
|
||||
export type $ZodCheckIncludesParams = CheckParams<checks.$ZodCheckIncludes, "includes" | "format" | "when" | "pattern">;
|
||||
export type $ZodCheckIncludesParams = CheckParams<checks.$ZodCheckIncludes, "includes" | "format" | "pattern">;
|
||||
export declare function _includes(includes: string, params?: string | $ZodCheckIncludesParams): checks.$ZodCheckIncludes;
|
||||
export type $ZodCheckStartsWithParams = CheckParams<checks.$ZodCheckStartsWith, "prefix" | "format" | "when" | "pattern">;
|
||||
export type $ZodCheckStartsWithParams = CheckParams<checks.$ZodCheckStartsWith, "prefix" | "format" | "pattern">;
|
||||
export declare function _startsWith(prefix: string, params?: string | $ZodCheckStartsWithParams): checks.$ZodCheckStartsWith;
|
||||
export type $ZodCheckEndsWithParams = CheckParams<checks.$ZodCheckEndsWith, "suffix" | "format" | "pattern" | "when">;
|
||||
export type $ZodCheckEndsWithParams = CheckParams<checks.$ZodCheckEndsWith, "suffix" | "format" | "pattern">;
|
||||
export declare function _endsWith(suffix: string, params?: string | $ZodCheckEndsWithParams): checks.$ZodCheckEndsWith;
|
||||
export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "property" | "schema" | "when">;
|
||||
export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "property" | "schema">;
|
||||
export declare function _property<K extends string, T extends schemas.$ZodType>(property: K, schema: T, params?: string | $ZodCheckPropertyParams): checks.$ZodCheckProperty<{
|
||||
[k in K]: core.output<T>;
|
||||
}>;
|
||||
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime" | "when">;
|
||||
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime">;
|
||||
export declare function _mime(types: util.MimeTypes[], params?: string | $ZodCheckMimeTypeParams): checks.$ZodCheckMimeType;
|
||||
export declare function _overwrite<T>(tx: (input: T) => T): checks.$ZodCheckOverwrite<T>;
|
||||
export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _trim(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
|
||||
export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
|
||||
export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
|
||||
export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
|
||||
@@ -215,7 +210,7 @@ export interface $ZodTypeDiscriminable extends schemas.$ZodType {
|
||||
_zod: $ZodTypeDiscriminableInternals;
|
||||
}
|
||||
export type $ZodDiscriminatedUnionParams = TypeParams<schemas.$ZodDiscriminatedUnion, "options" | "discriminator">;
|
||||
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]], Disc extends string>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: Disc, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types, Disc>;
|
||||
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]]>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: string, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types>;
|
||||
export type $ZodIntersectionParams = TypeParams<schemas.$ZodIntersection, "left" | "right">;
|
||||
export declare function _intersection<T extends schemas.$ZodObject, U extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodIntersection>, left: T, right: U): schemas.$ZodIntersection<T, U>;
|
||||
export type $ZodTupleParams = TypeParams<schemas.$ZodTuple, "items" | "rest">;
|
||||
@@ -270,20 +265,6 @@ export declare function _promise<T extends schemas.$ZodObject>(Class: util.Schem
|
||||
export type $ZodCustomParams = CheckTypeParams<schemas.$ZodCustom, "fn">;
|
||||
export declare function _custom<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
||||
export declare function _refine<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
||||
export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
/** The schema or check that originated this issue. */
|
||||
readonly inst?: schemas.$ZodType | checks.$ZodCheck;
|
||||
/** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
|
||||
readonly continue?: boolean | undefined;
|
||||
} & Record<string, unknown>> : never;
|
||||
export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
||||
addIssue(arg: string | $ZodSuperRefineIssue): void;
|
||||
}
|
||||
export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>): checks.$ZodCheck<T>;
|
||||
export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
|
||||
export declare function describe<T>(description: string): checks.$ZodCheck<T>;
|
||||
export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
|
||||
export interface $ZodStringBoolParams extends TypeParams {
|
||||
truthy?: string[];
|
||||
falsy?: string[];
|
||||
@@ -295,8 +276,9 @@ export interface $ZodStringBoolParams extends TypeParams {
|
||||
case?: "sensitive" | "insensitive" | undefined;
|
||||
}
|
||||
export declare function _stringbool(Classes: {
|
||||
Codec?: typeof schemas.$ZodCodec;
|
||||
Pipe?: typeof schemas.$ZodPipe;
|
||||
Boolean?: typeof schemas.$ZodBoolean;
|
||||
Transform?: typeof schemas.$ZodTransform;
|
||||
String?: typeof schemas.$ZodString;
|
||||
}, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
|
||||
}, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodPipe<schemas.$ZodString, schemas.$ZodTransform<boolean, string>>, schemas.$ZodBoolean<boolean>>;
|
||||
export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
|
||||
|
||||
+76
-94
@@ -1,7 +1,6 @@
|
||||
import * as checks from "./checks.js";
|
||||
import type * as core from "./core.js";
|
||||
import type * as errors from "./errors.js";
|
||||
import * as registries from "./registries.js";
|
||||
import * as schemas from "./schemas.js";
|
||||
import * as util from "./util.js";
|
||||
export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
|
||||
@@ -20,76 +19,73 @@ export type CheckTypeParams<T extends schemas.$ZodType & checks.$ZodCheck = sche
|
||||
export type $ZodStringParams = TypeParams<schemas.$ZodString<string>, "coerce">;
|
||||
export declare function _string<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
|
||||
export declare function _coercedString<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
|
||||
export type $ZodStringFormatParams = CheckTypeParams<schemas.$ZodStringFormat, "format" | "coerce" | "when" | "pattern">;
|
||||
export type $ZodStringFormatParams = CheckTypeParams<schemas.$ZodStringFormat, "format" | "coerce">;
|
||||
export type $ZodCheckStringFormatParams = CheckParams<checks.$ZodCheckStringFormat, "format">;
|
||||
export type $ZodEmailParams = StringFormatParams<schemas.$ZodEmail, "when">;
|
||||
export type $ZodCheckEmailParams = CheckStringFormatParams<schemas.$ZodEmail, "when">;
|
||||
export type $ZodEmailParams = StringFormatParams<schemas.$ZodEmail>;
|
||||
export type $ZodCheckEmailParams = CheckStringFormatParams<schemas.$ZodEmail>;
|
||||
export declare function _email<T extends schemas.$ZodEmail>(Class: util.SchemaClass<T>, params?: string | $ZodEmailParams | $ZodCheckEmailParams): T;
|
||||
export type $ZodGUIDParams = StringFormatParams<schemas.$ZodGUID, "pattern" | "when">;
|
||||
export type $ZodCheckGUIDParams = CheckStringFormatParams<schemas.$ZodGUID, "pattern" | "when">;
|
||||
export type $ZodGUIDParams = StringFormatParams<schemas.$ZodGUID, "pattern">;
|
||||
export type $ZodCheckGUIDParams = CheckStringFormatParams<schemas.$ZodGUID, "pattern">;
|
||||
export declare function _guid<T extends schemas.$ZodGUID>(Class: util.SchemaClass<T>, params?: string | $ZodGUIDParams | $ZodCheckGUIDParams): T;
|
||||
export type $ZodUUIDParams = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDParams = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDParams = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDParams = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuid<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDParams | $ZodCheckUUIDParams): T;
|
||||
export type $ZodUUIDv4Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv4Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDv4Params = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDv4Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuidv4<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv4Params | $ZodCheckUUIDv4Params): T;
|
||||
export type $ZodUUIDv6Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv6Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDv6Params = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDv6Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuidv6<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv6Params | $ZodCheckUUIDv6Params): T;
|
||||
export type $ZodUUIDv7Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv7Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodUUIDv7Params = StringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export type $ZodCheckUUIDv7Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern">;
|
||||
export declare function _uuidv7<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv7Params | $ZodCheckUUIDv7Params): T;
|
||||
export type $ZodURLParams = StringFormatParams<schemas.$ZodURL, "when">;
|
||||
export type $ZodCheckURLParams = CheckStringFormatParams<schemas.$ZodURL, "when">;
|
||||
export type $ZodURLParams = StringFormatParams<schemas.$ZodURL>;
|
||||
export type $ZodCheckURLParams = CheckStringFormatParams<schemas.$ZodURL>;
|
||||
export declare function _url<T extends schemas.$ZodURL>(Class: util.SchemaClass<T>, params?: string | $ZodURLParams | $ZodCheckURLParams): T;
|
||||
export type $ZodEmojiParams = StringFormatParams<schemas.$ZodEmoji, "when">;
|
||||
export type $ZodCheckEmojiParams = CheckStringFormatParams<schemas.$ZodEmoji, "when">;
|
||||
export type $ZodEmojiParams = StringFormatParams<schemas.$ZodEmoji>;
|
||||
export type $ZodCheckEmojiParams = CheckStringFormatParams<schemas.$ZodEmoji>;
|
||||
export declare function _emoji<T extends schemas.$ZodEmoji>(Class: util.SchemaClass<T>, params?: string | $ZodEmojiParams | $ZodCheckEmojiParams): T;
|
||||
export type $ZodNanoIDParams = StringFormatParams<schemas.$ZodNanoID, "when">;
|
||||
export type $ZodCheckNanoIDParams = CheckStringFormatParams<schemas.$ZodNanoID, "when">;
|
||||
export type $ZodNanoIDParams = StringFormatParams<schemas.$ZodNanoID>;
|
||||
export type $ZodCheckNanoIDParams = CheckStringFormatParams<schemas.$ZodNanoID>;
|
||||
export declare function _nanoid<T extends schemas.$ZodNanoID>(Class: util.SchemaClass<T>, params?: string | $ZodNanoIDParams | $ZodCheckNanoIDParams): T;
|
||||
export type $ZodCUIDParams = StringFormatParams<schemas.$ZodCUID, "when">;
|
||||
export type $ZodCheckCUIDParams = CheckStringFormatParams<schemas.$ZodCUID, "when">;
|
||||
export type $ZodCUIDParams = StringFormatParams<schemas.$ZodCUID>;
|
||||
export type $ZodCheckCUIDParams = CheckStringFormatParams<schemas.$ZodCUID>;
|
||||
export declare function _cuid<T extends schemas.$ZodCUID>(Class: util.SchemaClass<T>, params?: string | $ZodCUIDParams | $ZodCheckCUIDParams): T;
|
||||
export type $ZodCUID2Params = StringFormatParams<schemas.$ZodCUID2, "when">;
|
||||
export type $ZodCheckCUID2Params = CheckStringFormatParams<schemas.$ZodCUID2, "when">;
|
||||
export type $ZodCUID2Params = StringFormatParams<schemas.$ZodCUID2>;
|
||||
export type $ZodCheckCUID2Params = CheckStringFormatParams<schemas.$ZodCUID2>;
|
||||
export declare function _cuid2<T extends schemas.$ZodCUID2>(Class: util.SchemaClass<T>, params?: string | $ZodCUID2Params | $ZodCheckCUID2Params): T;
|
||||
export type $ZodULIDParams = StringFormatParams<schemas.$ZodULID, "when">;
|
||||
export type $ZodCheckULIDParams = CheckStringFormatParams<schemas.$ZodULID, "when">;
|
||||
export type $ZodULIDParams = StringFormatParams<schemas.$ZodULID>;
|
||||
export type $ZodCheckULIDParams = CheckStringFormatParams<schemas.$ZodULID>;
|
||||
export declare function _ulid<T extends schemas.$ZodULID>(Class: util.SchemaClass<T>, params?: string | $ZodULIDParams | $ZodCheckULIDParams): T;
|
||||
export type $ZodXIDParams = StringFormatParams<schemas.$ZodXID, "when">;
|
||||
export type $ZodCheckXIDParams = CheckStringFormatParams<schemas.$ZodXID, "when">;
|
||||
export type $ZodXIDParams = StringFormatParams<schemas.$ZodXID>;
|
||||
export type $ZodCheckXIDParams = CheckStringFormatParams<schemas.$ZodXID>;
|
||||
export declare function _xid<T extends schemas.$ZodXID>(Class: util.SchemaClass<T>, params?: string | $ZodXIDParams | $ZodCheckXIDParams): T;
|
||||
export type $ZodKSUIDParams = StringFormatParams<schemas.$ZodKSUID, "when">;
|
||||
export type $ZodCheckKSUIDParams = CheckStringFormatParams<schemas.$ZodKSUID, "when">;
|
||||
export type $ZodKSUIDParams = StringFormatParams<schemas.$ZodKSUID>;
|
||||
export type $ZodCheckKSUIDParams = CheckStringFormatParams<schemas.$ZodKSUID>;
|
||||
export declare function _ksuid<T extends schemas.$ZodKSUID>(Class: util.SchemaClass<T>, params?: string | $ZodKSUIDParams | $ZodCheckKSUIDParams): T;
|
||||
export type $ZodIPv4Params = StringFormatParams<schemas.$ZodIPv4, "pattern" | "when" | "version">;
|
||||
export type $ZodCheckIPv4Params = CheckStringFormatParams<schemas.$ZodIPv4, "pattern" | "when" | "version">;
|
||||
export type $ZodIPv4Params = StringFormatParams<schemas.$ZodIPv4, "pattern">;
|
||||
export type $ZodCheckIPv4Params = CheckStringFormatParams<schemas.$ZodIPv4, "pattern">;
|
||||
export declare function _ipv4<T extends schemas.$ZodIPv4>(Class: util.SchemaClass<T>, params?: string | $ZodIPv4Params | $ZodCheckIPv4Params): T;
|
||||
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
||||
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
||||
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern">;
|
||||
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern">;
|
||||
export declare function _ipv6<T extends schemas.$ZodIPv6>(Class: util.SchemaClass<T>, params?: string | $ZodIPv6Params | $ZodCheckIPv6Params): T;
|
||||
export type $ZodMACParams = StringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
||||
export type $ZodCheckMACParams = CheckStringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
||||
export declare function _mac<T extends schemas.$ZodMAC>(Class: util.SchemaClass<T>, params?: string | $ZodMACParams | $ZodCheckMACParams): T;
|
||||
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
||||
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
||||
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern">;
|
||||
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern">;
|
||||
export declare function _cidrv4<T extends schemas.$ZodCIDRv4>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv4Params | $ZodCheckCIDRv4Params): T;
|
||||
export type $ZodCIDRv6Params = StringFormatParams<schemas.$ZodCIDRv6, "pattern" | "when">;
|
||||
export type $ZodCheckCIDRv6Params = CheckStringFormatParams<schemas.$ZodCIDRv6, "pattern" | "when">;
|
||||
export type $ZodCIDRv6Params = StringFormatParams<schemas.$ZodCIDRv6, "pattern">;
|
||||
export type $ZodCheckCIDRv6Params = CheckStringFormatParams<schemas.$ZodCIDRv6, "pattern">;
|
||||
export declare function _cidrv6<T extends schemas.$ZodCIDRv6>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv6Params | $ZodCheckCIDRv6Params): T;
|
||||
export type $ZodBase64Params = StringFormatParams<schemas.$ZodBase64, "pattern" | "when">;
|
||||
export type $ZodCheckBase64Params = CheckStringFormatParams<schemas.$ZodBase64, "pattern" | "when">;
|
||||
export type $ZodBase64Params = StringFormatParams<schemas.$ZodBase64, "pattern">;
|
||||
export type $ZodCheckBase64Params = CheckStringFormatParams<schemas.$ZodBase64, "pattern">;
|
||||
export declare function _base64<T extends schemas.$ZodBase64>(Class: util.SchemaClass<T>, params?: string | $ZodBase64Params | $ZodCheckBase64Params): T;
|
||||
export type $ZodBase64URLParams = StringFormatParams<schemas.$ZodBase64URL, "pattern" | "when">;
|
||||
export type $ZodCheckBase64URLParams = CheckStringFormatParams<schemas.$ZodBase64URL, "pattern" | "when">;
|
||||
export type $ZodBase64URLParams = StringFormatParams<schemas.$ZodBase64URL, "pattern">;
|
||||
export type $ZodCheckBase64URLParams = CheckStringFormatParams<schemas.$ZodBase64URL, "pattern">;
|
||||
export declare function _base64url<T extends schemas.$ZodBase64URL>(Class: util.SchemaClass<T>, params?: string | $ZodBase64URLParams | $ZodCheckBase64URLParams): T;
|
||||
export type $ZodE164Params = StringFormatParams<schemas.$ZodE164, "when">;
|
||||
export type $ZodCheckE164Params = CheckStringFormatParams<schemas.$ZodE164, "when">;
|
||||
export type $ZodE164Params = StringFormatParams<schemas.$ZodE164>;
|
||||
export type $ZodCheckE164Params = CheckStringFormatParams<schemas.$ZodE164>;
|
||||
export declare function _e164<T extends schemas.$ZodE164>(Class: util.SchemaClass<T>, params?: string | $ZodE164Params | $ZodCheckE164Params): T;
|
||||
export type $ZodJWTParams = StringFormatParams<schemas.$ZodJWT, "pattern" | "when">;
|
||||
export type $ZodCheckJWTParams = CheckStringFormatParams<schemas.$ZodJWT, "pattern" | "when">;
|
||||
export type $ZodJWTParams = StringFormatParams<schemas.$ZodJWT, "pattern">;
|
||||
export type $ZodCheckJWTParams = CheckStringFormatParams<schemas.$ZodJWT, "pattern">;
|
||||
export declare function _jwt<T extends schemas.$ZodJWT>(Class: util.SchemaClass<T>, params?: string | $ZodJWTParams | $ZodCheckJWTParams): T;
|
||||
export declare const TimePrecision: {
|
||||
readonly Any: null;
|
||||
@@ -98,21 +94,21 @@ export declare const TimePrecision: {
|
||||
readonly Millisecond: 3;
|
||||
readonly Microsecond: 6;
|
||||
};
|
||||
export type $ZodISODateTimeParams = StringFormatParams<schemas.$ZodISODateTime, "pattern" | "when">;
|
||||
export type $ZodCheckISODateTimeParams = CheckStringFormatParams<schemas.$ZodISODateTime, "pattern" | "when">;
|
||||
export type $ZodISODateTimeParams = StringFormatParams<schemas.$ZodISODateTime, "pattern">;
|
||||
export type $ZodCheckISODateTimeParams = CheckStringFormatParams<schemas.$ZodISODateTime, "pattern">;
|
||||
export declare function _isoDateTime<T extends schemas.$ZodISODateTime>(Class: util.SchemaClass<T>, params?: string | $ZodISODateTimeParams | $ZodCheckISODateTimeParams): T;
|
||||
export type $ZodISODateParams = StringFormatParams<schemas.$ZodISODate, "pattern" | "when">;
|
||||
export type $ZodCheckISODateParams = CheckStringFormatParams<schemas.$ZodISODate, "pattern" | "when">;
|
||||
export type $ZodISODateParams = StringFormatParams<schemas.$ZodISODate, "pattern">;
|
||||
export type $ZodCheckISODateParams = CheckStringFormatParams<schemas.$ZodISODate, "pattern">;
|
||||
export declare function _isoDate<T extends schemas.$ZodISODate>(Class: util.SchemaClass<T>, params?: string | $ZodISODateParams | $ZodCheckISODateParams): T;
|
||||
export type $ZodISOTimeParams = StringFormatParams<schemas.$ZodISOTime, "pattern" | "when">;
|
||||
export type $ZodCheckISOTimeParams = CheckStringFormatParams<schemas.$ZodISOTime, "pattern" | "when">;
|
||||
export type $ZodISOTimeParams = StringFormatParams<schemas.$ZodISOTime, "pattern">;
|
||||
export type $ZodCheckISOTimeParams = CheckStringFormatParams<schemas.$ZodISOTime, "pattern">;
|
||||
export declare function _isoTime<T extends schemas.$ZodISOTime>(Class: util.SchemaClass<T>, params?: string | $ZodISOTimeParams | $ZodCheckISOTimeParams): T;
|
||||
export type $ZodISODurationParams = StringFormatParams<schemas.$ZodISODuration, "when">;
|
||||
export type $ZodCheckISODurationParams = CheckStringFormatParams<schemas.$ZodISODuration, "when">;
|
||||
export type $ZodISODurationParams = StringFormatParams<schemas.$ZodISODuration>;
|
||||
export type $ZodCheckISODurationParams = CheckStringFormatParams<schemas.$ZodISODuration>;
|
||||
export declare function _isoDuration<T extends schemas.$ZodISODuration>(Class: util.SchemaClass<T>, params?: string | $ZodISODurationParams | $ZodCheckISODurationParams): T;
|
||||
export type $ZodNumberParams = TypeParams<schemas.$ZodNumber<number>, "coerce">;
|
||||
export type $ZodNumberFormatParams = CheckTypeParams<schemas.$ZodNumberFormat, "format" | "coerce">;
|
||||
export type $ZodCheckNumberFormatParams = CheckParams<checks.$ZodCheckNumberFormat, "format" | "when">;
|
||||
export type $ZodCheckNumberFormatParams = CheckParams<checks.$ZodCheckNumberFormat, "format">;
|
||||
export declare function _number<T extends schemas.$ZodNumber>(Class: util.SchemaClass<T>, params?: string | $ZodNumberParams): T;
|
||||
export declare function _coercedNumber<T extends schemas.$ZodNumber>(Class: util.SchemaClass<T>, params?: string | $ZodNumberParams): T;
|
||||
export declare function _int<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
@@ -125,7 +121,7 @@ export declare function _boolean<T extends schemas.$ZodBoolean>(Class: util.Sche
|
||||
export declare function _coercedBoolean<T extends schemas.$ZodBoolean>(Class: util.SchemaClass<T>, params?: string | $ZodBooleanParams): T;
|
||||
export type $ZodBigIntParams = TypeParams<schemas.$ZodBigInt<bigint>>;
|
||||
export type $ZodBigIntFormatParams = CheckTypeParams<schemas.$ZodBigIntFormat, "format" | "coerce">;
|
||||
export type $ZodCheckBigIntFormatParams = CheckParams<checks.$ZodCheckBigIntFormat, "format" | "when">;
|
||||
export type $ZodCheckBigIntFormatParams = CheckParams<checks.$ZodCheckBigIntFormat, "format">;
|
||||
export declare function _bigint<T extends schemas.$ZodBigInt>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntParams): T;
|
||||
export declare function _coercedBigint<T extends schemas.$ZodBigInt>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntParams): T;
|
||||
export declare function _int64<T extends schemas.$ZodBigIntFormat>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntFormatParams): T;
|
||||
@@ -149,13 +145,13 @@ export declare function _date<T extends schemas.$ZodDate>(Class: util.SchemaClas
|
||||
export declare function _coercedDate<T extends schemas.$ZodDate>(Class: util.SchemaClass<T>, params?: string | $ZodDateParams): T;
|
||||
export type $ZodNaNParams = TypeParams<schemas.$ZodNaN>;
|
||||
export declare function _nan<T extends schemas.$ZodNaN>(Class: util.SchemaClass<T>, params?: string | $ZodNaNParams): T;
|
||||
export type $ZodCheckLessThanParams = CheckParams<checks.$ZodCheckLessThan, "inclusive" | "value" | "when">;
|
||||
export type $ZodCheckLessThanParams = CheckParams<checks.$ZodCheckLessThan, "inclusive" | "value">;
|
||||
export declare function _lt(value: util.Numeric, params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan<util.Numeric>;
|
||||
export declare function _lte(value: util.Numeric, params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan<util.Numeric>;
|
||||
export {
|
||||
/** @deprecated Use `z.lte()` instead. */
|
||||
_lte as _max, };
|
||||
export type $ZodCheckGreaterThanParams = CheckParams<checks.$ZodCheckGreaterThan, "inclusive" | "value" | "when">;
|
||||
export type $ZodCheckGreaterThanParams = CheckParams<checks.$ZodCheckGreaterThan, "inclusive" | "value">;
|
||||
export declare function _gt(value: util.Numeric, params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export declare function _gte(value: util.Numeric, params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export {
|
||||
@@ -165,44 +161,43 @@ export declare function _positive(params?: string | $ZodCheckGreaterThanParams):
|
||||
export declare function _negative(params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan;
|
||||
export declare function _nonpositive(params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan;
|
||||
export declare function _nonnegative(params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export type $ZodCheckMultipleOfParams = CheckParams<checks.$ZodCheckMultipleOf, "value" | "when">;
|
||||
export type $ZodCheckMultipleOfParams = CheckParams<checks.$ZodCheckMultipleOf, "value">;
|
||||
export declare function _multipleOf(value: number | bigint, params?: string | $ZodCheckMultipleOfParams): checks.$ZodCheckMultipleOf;
|
||||
export type $ZodCheckMaxSizeParams = CheckParams<checks.$ZodCheckMaxSize, "maximum" | "when">;
|
||||
export type $ZodCheckMaxSizeParams = CheckParams<checks.$ZodCheckMaxSize, "maximum">;
|
||||
export declare function _maxSize(maximum: number, params?: string | $ZodCheckMaxSizeParams): checks.$ZodCheckMaxSize<util.HasSize>;
|
||||
export type $ZodCheckMinSizeParams = CheckParams<checks.$ZodCheckMinSize, "minimum" | "when">;
|
||||
export type $ZodCheckMinSizeParams = CheckParams<checks.$ZodCheckMinSize, "minimum">;
|
||||
export declare function _minSize(minimum: number, params?: string | $ZodCheckMinSizeParams): checks.$ZodCheckMinSize<util.HasSize>;
|
||||
export type $ZodCheckSizeEqualsParams = CheckParams<checks.$ZodCheckSizeEquals, "size" | "when">;
|
||||
export type $ZodCheckSizeEqualsParams = CheckParams<checks.$ZodCheckSizeEquals, "size">;
|
||||
export declare function _size(size: number, params?: string | $ZodCheckSizeEqualsParams): checks.$ZodCheckSizeEquals<util.HasSize>;
|
||||
export type $ZodCheckMaxLengthParams = CheckParams<checks.$ZodCheckMaxLength, "maximum" | "when">;
|
||||
export type $ZodCheckMaxLengthParams = CheckParams<checks.$ZodCheckMaxLength, "maximum">;
|
||||
export declare function _maxLength(maximum: number, params?: string | $ZodCheckMaxLengthParams): checks.$ZodCheckMaxLength<util.HasLength>;
|
||||
export type $ZodCheckMinLengthParams = CheckParams<checks.$ZodCheckMinLength, "minimum" | "when">;
|
||||
export type $ZodCheckMinLengthParams = CheckParams<checks.$ZodCheckMinLength, "minimum">;
|
||||
export declare function _minLength(minimum: number, params?: string | $ZodCheckMinLengthParams): checks.$ZodCheckMinLength<util.HasLength>;
|
||||
export type $ZodCheckLengthEqualsParams = CheckParams<checks.$ZodCheckLengthEquals, "length" | "when">;
|
||||
export type $ZodCheckLengthEqualsParams = CheckParams<checks.$ZodCheckLengthEquals, "length">;
|
||||
export declare function _length(length: number, params?: string | $ZodCheckLengthEqualsParams): checks.$ZodCheckLengthEquals<util.HasLength>;
|
||||
export type $ZodCheckRegexParams = CheckParams<checks.$ZodCheckRegex, "format" | "pattern" | "when">;
|
||||
export type $ZodCheckRegexParams = CheckParams<checks.$ZodCheckRegex, "format" | "pattern">;
|
||||
export declare function _regex(pattern: RegExp, params?: string | $ZodCheckRegexParams): checks.$ZodCheckRegex;
|
||||
export type $ZodCheckLowerCaseParams = CheckParams<checks.$ZodCheckLowerCase, "format" | "when">;
|
||||
export type $ZodCheckLowerCaseParams = CheckParams<checks.$ZodCheckLowerCase, "format">;
|
||||
export declare function _lowercase(params?: string | $ZodCheckLowerCaseParams): checks.$ZodCheckLowerCase;
|
||||
export type $ZodCheckUpperCaseParams = CheckParams<checks.$ZodCheckUpperCase, "format" | "when">;
|
||||
export type $ZodCheckUpperCaseParams = CheckParams<checks.$ZodCheckUpperCase, "format">;
|
||||
export declare function _uppercase(params?: string | $ZodCheckUpperCaseParams): checks.$ZodCheckUpperCase;
|
||||
export type $ZodCheckIncludesParams = CheckParams<checks.$ZodCheckIncludes, "includes" | "format" | "when" | "pattern">;
|
||||
export type $ZodCheckIncludesParams = CheckParams<checks.$ZodCheckIncludes, "includes" | "format" | "pattern">;
|
||||
export declare function _includes(includes: string, params?: string | $ZodCheckIncludesParams): checks.$ZodCheckIncludes;
|
||||
export type $ZodCheckStartsWithParams = CheckParams<checks.$ZodCheckStartsWith, "prefix" | "format" | "when" | "pattern">;
|
||||
export type $ZodCheckStartsWithParams = CheckParams<checks.$ZodCheckStartsWith, "prefix" | "format" | "pattern">;
|
||||
export declare function _startsWith(prefix: string, params?: string | $ZodCheckStartsWithParams): checks.$ZodCheckStartsWith;
|
||||
export type $ZodCheckEndsWithParams = CheckParams<checks.$ZodCheckEndsWith, "suffix" | "format" | "pattern" | "when">;
|
||||
export type $ZodCheckEndsWithParams = CheckParams<checks.$ZodCheckEndsWith, "suffix" | "format" | "pattern">;
|
||||
export declare function _endsWith(suffix: string, params?: string | $ZodCheckEndsWithParams): checks.$ZodCheckEndsWith;
|
||||
export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "property" | "schema" | "when">;
|
||||
export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "property" | "schema">;
|
||||
export declare function _property<K extends string, T extends schemas.$ZodType>(property: K, schema: T, params?: string | $ZodCheckPropertyParams): checks.$ZodCheckProperty<{
|
||||
[k in K]: core.output<T>;
|
||||
}>;
|
||||
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime" | "when">;
|
||||
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime">;
|
||||
export declare function _mime(types: util.MimeTypes[], params?: string | $ZodCheckMimeTypeParams): checks.$ZodCheckMimeType;
|
||||
export declare function _overwrite<T>(tx: (input: T) => T): checks.$ZodCheckOverwrite<T>;
|
||||
export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _trim(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
|
||||
export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
|
||||
export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
|
||||
export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
|
||||
@@ -215,7 +210,7 @@ export interface $ZodTypeDiscriminable extends schemas.$ZodType {
|
||||
_zod: $ZodTypeDiscriminableInternals;
|
||||
}
|
||||
export type $ZodDiscriminatedUnionParams = TypeParams<schemas.$ZodDiscriminatedUnion, "options" | "discriminator">;
|
||||
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]], Disc extends string>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: Disc, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types, Disc>;
|
||||
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]]>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: string, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types>;
|
||||
export type $ZodIntersectionParams = TypeParams<schemas.$ZodIntersection, "left" | "right">;
|
||||
export declare function _intersection<T extends schemas.$ZodObject, U extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodIntersection>, left: T, right: U): schemas.$ZodIntersection<T, U>;
|
||||
export type $ZodTupleParams = TypeParams<schemas.$ZodTuple, "items" | "rest">;
|
||||
@@ -270,20 +265,6 @@ export declare function _promise<T extends schemas.$ZodObject>(Class: util.Schem
|
||||
export type $ZodCustomParams = CheckTypeParams<schemas.$ZodCustom, "fn">;
|
||||
export declare function _custom<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
||||
export declare function _refine<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
||||
export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
/** The schema or check that originated this issue. */
|
||||
readonly inst?: schemas.$ZodType | checks.$ZodCheck;
|
||||
/** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
|
||||
readonly continue?: boolean | undefined;
|
||||
} & Record<string, unknown>> : never;
|
||||
export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
||||
addIssue(arg: string | $ZodSuperRefineIssue): void;
|
||||
}
|
||||
export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>): checks.$ZodCheck<T>;
|
||||
export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
|
||||
export declare function describe<T>(description: string): checks.$ZodCheck<T>;
|
||||
export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
|
||||
export interface $ZodStringBoolParams extends TypeParams {
|
||||
truthy?: string[];
|
||||
falsy?: string[];
|
||||
@@ -295,8 +276,9 @@ export interface $ZodStringBoolParams extends TypeParams {
|
||||
case?: "sensitive" | "insensitive" | undefined;
|
||||
}
|
||||
export declare function _stringbool(Classes: {
|
||||
Codec?: typeof schemas.$ZodCodec;
|
||||
Pipe?: typeof schemas.$ZodPipe;
|
||||
Boolean?: typeof schemas.$ZodBoolean;
|
||||
Transform?: typeof schemas.$ZodTransform;
|
||||
String?: typeof schemas.$ZodString;
|
||||
}, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
|
||||
}, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodPipe<schemas.$ZodString, schemas.$ZodTransform<boolean, string>>, schemas.$ZodBoolean<boolean>>;
|
||||
export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
|
||||
|
||||
+31
-86
@@ -1,5 +1,4 @@
|
||||
import * as checks from "./checks.js";
|
||||
import * as registries from "./registries.js";
|
||||
import * as schemas from "./schemas.js";
|
||||
import * as util from "./util.js";
|
||||
export function _string(Class, params) {
|
||||
@@ -162,15 +161,6 @@ export function _ipv6(Class, params) {
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
}
|
||||
export function _mac(Class, params) {
|
||||
return new Class({
|
||||
type: "string",
|
||||
format: "mac",
|
||||
check: "string_format",
|
||||
abort: false,
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
}
|
||||
export function _cidrv4(Class, params) {
|
||||
return new Class({
|
||||
type: "string",
|
||||
@@ -617,10 +607,6 @@ export function _toLowerCase() {
|
||||
export function _toUpperCase() {
|
||||
return _overwrite((input) => input.toUpperCase());
|
||||
}
|
||||
// slugify
|
||||
export function _slugify() {
|
||||
return _overwrite((input) => util.slugify(input));
|
||||
}
|
||||
export function _array(Class, element, params) {
|
||||
return new Class({
|
||||
type: "array",
|
||||
@@ -761,7 +747,7 @@ export function _default(Class, innerType, defaultValue) {
|
||||
type: "default",
|
||||
innerType,
|
||||
get defaultValue() {
|
||||
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
|
||||
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -828,6 +814,13 @@ export function _custom(Class, fn, _params) {
|
||||
});
|
||||
return schema;
|
||||
}
|
||||
// export function _refine<T>(
|
||||
// Class: util.SchemaClass<schemas.$ZodCustom>,
|
||||
// fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
|
||||
// _params: string | $ZodCustomParams = {}
|
||||
// ): checks.$ZodCheck<T> {
|
||||
// return _custom(Class, fn, _params);
|
||||
// }
|
||||
// same as _custom but defaults to abort:false
|
||||
export function _refine(Class, fn, _params) {
|
||||
const schema = new Class({
|
||||
@@ -838,58 +831,6 @@ export function _refine(Class, fn, _params) {
|
||||
});
|
||||
return schema;
|
||||
}
|
||||
export function _superRefine(fn) {
|
||||
const ch = _check((payload) => {
|
||||
payload.addIssue = (issue) => {
|
||||
if (typeof issue === "string") {
|
||||
payload.issues.push(util.issue(issue, payload.value, ch._zod.def));
|
||||
}
|
||||
else {
|
||||
// for Zod 3 backwards compatibility
|
||||
const _issue = issue;
|
||||
if (_issue.fatal)
|
||||
_issue.continue = false;
|
||||
_issue.code ?? (_issue.code = "custom");
|
||||
_issue.input ?? (_issue.input = payload.value);
|
||||
_issue.inst ?? (_issue.inst = ch);
|
||||
_issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
|
||||
payload.issues.push(util.issue(_issue));
|
||||
}
|
||||
};
|
||||
return fn(payload.value, payload);
|
||||
});
|
||||
return ch;
|
||||
}
|
||||
export function _check(fn, params) {
|
||||
const ch = new checks.$ZodCheck({
|
||||
check: "custom",
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
ch._zod.check = fn;
|
||||
return ch;
|
||||
}
|
||||
export function describe(description) {
|
||||
const ch = new checks.$ZodCheck({ check: "describe" });
|
||||
ch._zod.onattach = [
|
||||
(inst) => {
|
||||
const existing = registries.globalRegistry.get(inst) ?? {};
|
||||
registries.globalRegistry.add(inst, { ...existing, description });
|
||||
},
|
||||
];
|
||||
ch._zod.check = () => { }; // no-op check
|
||||
return ch;
|
||||
}
|
||||
export function meta(metadata) {
|
||||
const ch = new checks.$ZodCheck({ check: "meta" });
|
||||
ch._zod.onattach = [
|
||||
(inst) => {
|
||||
const existing = registries.globalRegistry.get(inst) ?? {};
|
||||
registries.globalRegistry.add(inst, { ...existing, ...metadata });
|
||||
},
|
||||
];
|
||||
ch._zod.check = () => { }; // no-op check
|
||||
return ch;
|
||||
}
|
||||
export function _stringbool(Classes, _params) {
|
||||
const params = util.normalizeParams(_params);
|
||||
let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
|
||||
@@ -900,16 +841,13 @@ export function _stringbool(Classes, _params) {
|
||||
}
|
||||
const truthySet = new Set(truthyArray);
|
||||
const falsySet = new Set(falsyArray);
|
||||
const _Codec = Classes.Codec ?? schemas.$ZodCodec;
|
||||
const _Pipe = Classes.Pipe ?? schemas.$ZodPipe;
|
||||
const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
|
||||
const _String = Classes.String ?? schemas.$ZodString;
|
||||
const stringSchema = new _String({ type: "string", error: params.error });
|
||||
const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
|
||||
const codec = new _Codec({
|
||||
type: "pipe",
|
||||
in: stringSchema,
|
||||
out: booleanSchema,
|
||||
transform: ((input, payload) => {
|
||||
const _Transform = Classes.Transform ?? schemas.$ZodTransform;
|
||||
const tx = new _Transform({
|
||||
type: "transform",
|
||||
transform: (input, payload) => {
|
||||
let data = input;
|
||||
if (params.case !== "sensitive")
|
||||
data = data.toLowerCase();
|
||||
@@ -925,23 +863,30 @@ export function _stringbool(Classes, _params) {
|
||||
expected: "stringbool",
|
||||
values: [...truthySet, ...falsySet],
|
||||
input: payload.value,
|
||||
inst: codec,
|
||||
continue: false,
|
||||
inst: tx,
|
||||
});
|
||||
return {};
|
||||
}
|
||||
}),
|
||||
reverseTransform: ((input, _payload) => {
|
||||
if (input === true) {
|
||||
return truthyArray[0] || "true";
|
||||
}
|
||||
else {
|
||||
return falsyArray[0] || "false";
|
||||
}
|
||||
},
|
||||
error: params.error,
|
||||
});
|
||||
// params.error;
|
||||
const innerPipe = new _Pipe({
|
||||
type: "pipe",
|
||||
in: new _String({ type: "string", error: params.error }),
|
||||
out: tx,
|
||||
error: params.error,
|
||||
});
|
||||
const outerPipe = new _Pipe({
|
||||
type: "pipe",
|
||||
in: innerPipe,
|
||||
out: new _Boolean({
|
||||
type: "boolean",
|
||||
error: params.error,
|
||||
}),
|
||||
error: params.error,
|
||||
});
|
||||
return codec;
|
||||
return outerPipe;
|
||||
}
|
||||
export function _stringFormat(Class, format, fnOrRegex, _params = {}) {
|
||||
const params = util.normalizeParams(_params);
|
||||
|
||||
-4
@@ -151,7 +151,6 @@ exports.$ZodCheckNumberFormat = core.$constructor("$ZodCheckNumberFormat", (inst
|
||||
expected: origin,
|
||||
format: def.format,
|
||||
code: "invalid_type",
|
||||
continue: false,
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
@@ -269,7 +268,6 @@ exports.$ZodCheckMaxSize = core.$constructor("$ZodCheckMaxSize", (inst, def) =>
|
||||
origin: util.getSizableOrigin(input),
|
||||
code: "too_big",
|
||||
maximum: def.maximum,
|
||||
inclusive: true,
|
||||
input,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
@@ -297,7 +295,6 @@ exports.$ZodCheckMinSize = core.$constructor("$ZodCheckMinSize", (inst, def) =>
|
||||
origin: util.getSizableOrigin(input),
|
||||
code: "too_small",
|
||||
minimum: def.minimum,
|
||||
inclusive: true,
|
||||
input,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
@@ -583,7 +580,6 @@ exports.$ZodCheckMimeType = core.$constructor("$ZodCheckMimeType", (inst, def) =
|
||||
values: def.mime,
|
||||
input: payload.value.type,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
+2
-2
@@ -254,11 +254,11 @@ export interface $ZodCheckMimeTypeDef extends $ZodCheckDef {
|
||||
check: "mime_type";
|
||||
mime: util.MimeTypes[];
|
||||
}
|
||||
export interface $ZodCheckMimeTypeInternals<T extends schemas.File = schemas.File> extends $ZodCheckInternals<T> {
|
||||
export interface $ZodCheckMimeTypeInternals<T extends File = File> extends $ZodCheckInternals<T> {
|
||||
def: $ZodCheckMimeTypeDef;
|
||||
issc: errors.$ZodIssueInvalidValue;
|
||||
}
|
||||
export interface $ZodCheckMimeType<T extends schemas.File = schemas.File> extends $ZodCheck<T> {
|
||||
export interface $ZodCheckMimeType<T extends File = File> extends $ZodCheck<T> {
|
||||
_zod: $ZodCheckMimeTypeInternals<T>;
|
||||
}
|
||||
export declare const $ZodCheckMimeType: core.$constructor<$ZodCheckMimeType>;
|
||||
|
||||
+2
-2
@@ -254,11 +254,11 @@ export interface $ZodCheckMimeTypeDef extends $ZodCheckDef {
|
||||
check: "mime_type";
|
||||
mime: util.MimeTypes[];
|
||||
}
|
||||
export interface $ZodCheckMimeTypeInternals<T extends schemas.File = schemas.File> extends $ZodCheckInternals<T> {
|
||||
export interface $ZodCheckMimeTypeInternals<T extends File = File> extends $ZodCheckInternals<T> {
|
||||
def: $ZodCheckMimeTypeDef;
|
||||
issc: errors.$ZodIssueInvalidValue;
|
||||
}
|
||||
export interface $ZodCheckMimeType<T extends schemas.File = schemas.File> extends $ZodCheck<T> {
|
||||
export interface $ZodCheckMimeType<T extends File = File> extends $ZodCheck<T> {
|
||||
_zod: $ZodCheckMimeTypeInternals<T>;
|
||||
}
|
||||
export declare const $ZodCheckMimeType: core.$constructor<$ZodCheckMimeType>;
|
||||
|
||||
-4
@@ -125,7 +125,6 @@ export const $ZodCheckNumberFormat = /*@__PURE__*/ core.$constructor("$ZodCheckN
|
||||
expected: origin,
|
||||
format: def.format,
|
||||
code: "invalid_type",
|
||||
continue: false,
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
@@ -243,7 +242,6 @@ export const $ZodCheckMaxSize = /*@__PURE__*/ core.$constructor("$ZodCheckMaxSiz
|
||||
origin: util.getSizableOrigin(input),
|
||||
code: "too_big",
|
||||
maximum: def.maximum,
|
||||
inclusive: true,
|
||||
input,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
@@ -271,7 +269,6 @@ export const $ZodCheckMinSize = /*@__PURE__*/ core.$constructor("$ZodCheckMinSiz
|
||||
origin: util.getSizableOrigin(input),
|
||||
code: "too_small",
|
||||
minimum: def.minimum,
|
||||
inclusive: true,
|
||||
input,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
@@ -557,7 +554,6 @@ export const $ZodCheckMimeType = /*@__PURE__*/ core.$constructor("$ZodCheckMimeT
|
||||
values: def.mime,
|
||||
input: payload.value.type,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
+12
-28
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.globalConfig = exports.$ZodEncodeError = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0;
|
||||
exports.globalConfig = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0;
|
||||
exports.$constructor = $constructor;
|
||||
exports.config = config;
|
||||
/** A special constant with type `never` */
|
||||
@@ -9,30 +9,21 @@ exports.NEVER = Object.freeze({
|
||||
});
|
||||
function $constructor(name, initializer, params) {
|
||||
function init(inst, def) {
|
||||
if (!inst._zod) {
|
||||
Object.defineProperty(inst, "_zod", {
|
||||
value: {
|
||||
def,
|
||||
constr: _,
|
||||
traits: new Set(),
|
||||
},
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
if (inst._zod.traits.has(name)) {
|
||||
return;
|
||||
}
|
||||
var _a;
|
||||
Object.defineProperty(inst, "_zod", {
|
||||
value: inst._zod ?? {},
|
||||
enumerable: false,
|
||||
});
|
||||
(_a = inst._zod).traits ?? (_a.traits = new Set());
|
||||
inst._zod.traits.add(name);
|
||||
initializer(inst, def);
|
||||
// support prototype modifications
|
||||
const proto = _.prototype;
|
||||
const keys = Object.keys(proto);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
if (!(k in inst)) {
|
||||
inst[k] = proto[k].bind(inst);
|
||||
}
|
||||
for (const k in _.prototype) {
|
||||
if (!(k in inst))
|
||||
Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
|
||||
}
|
||||
inst._zod.constr = _;
|
||||
inst._zod.def = def;
|
||||
}
|
||||
// doesn't work if Parent has a constructor with arguments
|
||||
const Parent = params?.Parent ?? Object;
|
||||
@@ -68,13 +59,6 @@ class $ZodAsyncError extends Error {
|
||||
}
|
||||
}
|
||||
exports.$ZodAsyncError = $ZodAsyncError;
|
||||
class $ZodEncodeError extends Error {
|
||||
constructor(name) {
|
||||
super(`Encountered unidirectional transform during encode: ${name}`);
|
||||
this.name = "ZodEncodeError";
|
||||
}
|
||||
}
|
||||
exports.$ZodEncodeError = $ZodEncodeError;
|
||||
exports.globalConfig = {};
|
||||
function config(newConfig) {
|
||||
if (newConfig)
|
||||
|
||||
+2
-5
@@ -26,19 +26,16 @@ export type $ZodBranded<T extends schemas.SomeType, Brand extends string | numbe
|
||||
export declare class $ZodAsyncError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class $ZodEncodeError extends Error {
|
||||
constructor(name: string);
|
||||
}
|
||||
export type input<T> = T extends {
|
||||
_zod: {
|
||||
input: any;
|
||||
};
|
||||
} ? T["_zod"]["input"] : unknown;
|
||||
} ? Required<T["_zod"]>["input"] : unknown;
|
||||
export type output<T> = T extends {
|
||||
_zod: {
|
||||
output: any;
|
||||
};
|
||||
} ? T["_zod"]["output"] : unknown;
|
||||
} ? Required<T["_zod"]>["output"] : unknown;
|
||||
export type { output as infer };
|
||||
export interface $ZodConfig {
|
||||
/** Custom error map. Overrides `config().localeError`. */
|
||||
|
||||
+2
-5
@@ -26,19 +26,16 @@ export type $ZodBranded<T extends schemas.SomeType, Brand extends string | numbe
|
||||
export declare class $ZodAsyncError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class $ZodEncodeError extends Error {
|
||||
constructor(name: string);
|
||||
}
|
||||
export type input<T> = T extends {
|
||||
_zod: {
|
||||
input: any;
|
||||
};
|
||||
} ? T["_zod"]["input"] : unknown;
|
||||
} ? Required<T["_zod"]>["input"] : unknown;
|
||||
export type output<T> = T extends {
|
||||
_zod: {
|
||||
output: any;
|
||||
};
|
||||
} ? T["_zod"]["output"] : unknown;
|
||||
} ? Required<T["_zod"]>["output"] : unknown;
|
||||
export type { output as infer };
|
||||
export interface $ZodConfig {
|
||||
/** Custom error map. Overrides `config().localeError`. */
|
||||
|
||||
+11
-26
@@ -4,30 +4,21 @@ export const NEVER = Object.freeze({
|
||||
});
|
||||
export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) {
|
||||
function init(inst, def) {
|
||||
if (!inst._zod) {
|
||||
Object.defineProperty(inst, "_zod", {
|
||||
value: {
|
||||
def,
|
||||
constr: _,
|
||||
traits: new Set(),
|
||||
},
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
if (inst._zod.traits.has(name)) {
|
||||
return;
|
||||
}
|
||||
var _a;
|
||||
Object.defineProperty(inst, "_zod", {
|
||||
value: inst._zod ?? {},
|
||||
enumerable: false,
|
||||
});
|
||||
(_a = inst._zod).traits ?? (_a.traits = new Set());
|
||||
inst._zod.traits.add(name);
|
||||
initializer(inst, def);
|
||||
// support prototype modifications
|
||||
const proto = _.prototype;
|
||||
const keys = Object.keys(proto);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
if (!(k in inst)) {
|
||||
inst[k] = proto[k].bind(inst);
|
||||
}
|
||||
for (const k in _.prototype) {
|
||||
if (!(k in inst))
|
||||
Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
|
||||
}
|
||||
inst._zod.constr = _;
|
||||
inst._zod.def = def;
|
||||
}
|
||||
// doesn't work if Parent has a constructor with arguments
|
||||
const Parent = params?.Parent ?? Object;
|
||||
@@ -62,12 +53,6 @@ export class $ZodAsyncError extends Error {
|
||||
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
||||
}
|
||||
}
|
||||
export class $ZodEncodeError extends Error {
|
||||
constructor(name) {
|
||||
super(`Encountered unidirectional transform during encode: ${name}`);
|
||||
this.name = "ZodEncodeError";
|
||||
}
|
||||
}
|
||||
export const globalConfig = {};
|
||||
export function config(newConfig) {
|
||||
if (newConfig)
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ export declare class Doc {
|
||||
indented(fn: (doc: Doc) => void): void;
|
||||
write(fn: ModeWriter): void;
|
||||
write(line: string): void;
|
||||
compile(): any;
|
||||
compile(): Function;
|
||||
}
|
||||
export {};
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ export declare class Doc {
|
||||
indented(fn: (doc: Doc) => void): void;
|
||||
write(fn: ModeWriter): void;
|
||||
write(line: string): void;
|
||||
compile(): any;
|
||||
compile(): Function;
|
||||
}
|
||||
export {};
|
||||
|
||||
+19
-6
@@ -41,7 +41,13 @@ const initializer = (inst, def) => {
|
||||
value: def,
|
||||
enumerable: false,
|
||||
});
|
||||
inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
||||
Object.defineProperty(inst, "message", {
|
||||
get() {
|
||||
return JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
||||
},
|
||||
enumerable: true,
|
||||
// configurable: false,
|
||||
});
|
||||
Object.defineProperty(inst, "toString", {
|
||||
value: () => inst.message,
|
||||
enumerable: false,
|
||||
@@ -63,7 +69,11 @@ function flattenError(error, mapper = (issue) => issue.message) {
|
||||
}
|
||||
return { formErrors, fieldErrors };
|
||||
}
|
||||
function formatError(error, mapper = (issue) => issue.message) {
|
||||
function formatError(error, _mapper) {
|
||||
const mapper = _mapper ||
|
||||
function (issue) {
|
||||
return issue.message;
|
||||
};
|
||||
const fieldErrors = { _errors: [] };
|
||||
const processError = (error) => {
|
||||
for (const issue of error.issues) {
|
||||
@@ -101,7 +111,11 @@ function formatError(error, mapper = (issue) => issue.message) {
|
||||
processError(error);
|
||||
return fieldErrors;
|
||||
}
|
||||
function treeifyError(error, mapper = (issue) => issue.message) {
|
||||
function treeifyError(error, _mapper) {
|
||||
const mapper = _mapper ||
|
||||
function (issue) {
|
||||
return issue.message;
|
||||
};
|
||||
const result = { errors: [] };
|
||||
const processError = (error, path = []) => {
|
||||
var _a, _b;
|
||||
@@ -180,9 +194,8 @@ function treeifyError(error, mapper = (issue) => issue.message) {
|
||||
* ✖ Invalid input: expected number
|
||||
* ```
|
||||
*/
|
||||
function toDotPath(_path) {
|
||||
function toDotPath(path) {
|
||||
const segs = [];
|
||||
const path = _path.map((seg) => (typeof seg === "object" ? seg.key : seg));
|
||||
for (const seg of path) {
|
||||
if (typeof seg === "number")
|
||||
segs.push(`[${seg}]`);
|
||||
@@ -201,7 +214,7 @@ function toDotPath(_path) {
|
||||
function prettifyError(error) {
|
||||
const lines = [];
|
||||
// sort by path length
|
||||
const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
||||
const issues = [...error.issues].sort((a, b) => a.path.length - b.path.length);
|
||||
// Process each issue
|
||||
for (const issue of issues) {
|
||||
lines.push(`✖ ${issue.message}`);
|
||||
|
||||
+22
-24
@@ -1,7 +1,6 @@
|
||||
import type { $ZodCheck, $ZodStringFormats } from "./checks.cjs";
|
||||
import { $constructor } from "./core.cjs";
|
||||
import type { $ZodType } from "./schemas.cjs";
|
||||
import type { StandardSchemaV1 } from "./standard-schema.cjs";
|
||||
import * as util from "./util.cjs";
|
||||
export interface $ZodIssueBase {
|
||||
readonly code?: string;
|
||||
@@ -12,7 +11,7 @@ export interface $ZodIssueBase {
|
||||
export interface $ZodIssueInvalidType<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_type";
|
||||
readonly expected: $ZodType["_zod"]["def"]["type"];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "too_big";
|
||||
@@ -20,7 +19,7 @@ export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
|
||||
readonly maximum: number | bigint;
|
||||
readonly inclusive?: boolean;
|
||||
readonly exact?: boolean;
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "too_small";
|
||||
@@ -30,52 +29,51 @@ export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
|
||||
readonly inclusive?: boolean;
|
||||
/** True if the allowed value is fixed (e.g.` z.length(5)`), not a range (`z.minLength(5)`) */
|
||||
readonly exact?: boolean;
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueInvalidStringFormat extends $ZodIssueBase {
|
||||
readonly code: "invalid_format";
|
||||
readonly format: $ZodStringFormats | (string & {});
|
||||
readonly pattern?: string;
|
||||
readonly input?: string;
|
||||
readonly input: string;
|
||||
}
|
||||
export interface $ZodIssueNotMultipleOf<Input extends number | bigint = number | bigint> extends $ZodIssueBase {
|
||||
readonly code: "not_multiple_of";
|
||||
readonly divisor: number;
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueUnrecognizedKeys extends $ZodIssueBase {
|
||||
readonly code: "unrecognized_keys";
|
||||
readonly keys: string[];
|
||||
readonly input?: Record<string, unknown>;
|
||||
readonly input: Record<string, unknown>;
|
||||
}
|
||||
export interface $ZodIssueInvalidUnion extends $ZodIssueBase {
|
||||
readonly code: "invalid_union";
|
||||
readonly errors: $ZodIssue[][];
|
||||
readonly input?: unknown;
|
||||
readonly discriminator?: string | undefined;
|
||||
readonly input: unknown;
|
||||
}
|
||||
export interface $ZodIssueInvalidKey<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_key";
|
||||
readonly origin: "map" | "record";
|
||||
readonly issues: $ZodIssue[];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueInvalidElement<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_element";
|
||||
readonly origin: "map" | "set";
|
||||
readonly key: unknown;
|
||||
readonly issues: $ZodIssue[];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_value";
|
||||
readonly values: util.Primitive[];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueCustom extends $ZodIssueBase {
|
||||
readonly code: "custom";
|
||||
readonly params?: Record<string, any> | undefined;
|
||||
readonly input?: unknown;
|
||||
readonly input: unknown;
|
||||
}
|
||||
export interface $ZodIssueStringCommonFormats extends $ZodIssueInvalidStringFormat {
|
||||
format: Exclude<$ZodStringFormats, "regex" | "jwt" | "starts_with" | "ends_with" | "includes">;
|
||||
@@ -103,16 +101,15 @@ export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
|
||||
export type $ZodStringFormatIssues = $ZodIssueStringCommonFormats | $ZodIssueStringInvalidRegex | $ZodIssueStringInvalidJWT | $ZodIssueStringStartsWith | $ZodIssueStringEndsWith | $ZodIssueStringIncludes;
|
||||
export type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom;
|
||||
export type $ZodIssueCode = $ZodIssue["code"];
|
||||
export type $ZodInternalIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends $ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends $ZodIssueBase> = util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
/** The input data */
|
||||
readonly input: unknown;
|
||||
readonly input?: unknown;
|
||||
/** The schema or check that originated this issue. */
|
||||
readonly inst?: $ZodType | $ZodCheck;
|
||||
/** If `true`, Zod will continue executing checks/refinements after this issue. */
|
||||
/** @deprecated Internal use only. If `true`, Zod will continue executing validation despite this issue. */
|
||||
readonly continue?: boolean | undefined;
|
||||
} & Record<string, unknown>> : never;
|
||||
export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = $ZodInternalIssue<T>;
|
||||
} & Record<string, any>>;
|
||||
export interface $ZodErrorMap<T extends $ZodIssueBase = $ZodIssue> {
|
||||
(issue: $ZodRawIssue<T>): {
|
||||
message: string;
|
||||
@@ -153,9 +150,7 @@ export type $ZodFormattedError<T, U = string> = {
|
||||
} & util.Flatten<_ZodFormattedError<T, U>>;
|
||||
export declare function formatError<T>(error: $ZodError<T>): $ZodFormattedError<T>;
|
||||
export declare function formatError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodFormattedError<T, U>;
|
||||
export type $ZodErrorTree<T, U = string> = T extends util.Primitive ? {
|
||||
errors: U[];
|
||||
} : T extends [any, ...any[]] ? {
|
||||
export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]] ? {
|
||||
errors: U[];
|
||||
items?: {
|
||||
[K in keyof T]?: $ZodErrorTree<T[K], U>;
|
||||
@@ -205,6 +200,9 @@ export declare function treeifyError<T, U>(error: $ZodError<T>, mapper?: (issue:
|
||||
* ✖ Invalid input: expected number
|
||||
* ```
|
||||
*/
|
||||
export declare function toDotPath(_path: readonly (string | number | symbol | StandardSchemaV1.PathSegment)[]): string;
|
||||
export declare function prettifyError(error: StandardSchemaV1.FailureResult): string;
|
||||
export declare function toDotPath(path: (string | number | symbol)[]): string;
|
||||
interface BaseError {
|
||||
issues: $ZodIssueBase[];
|
||||
}
|
||||
export declare function prettifyError(error: BaseError): string;
|
||||
export {};
|
||||
|
||||
+22
-24
@@ -1,7 +1,6 @@
|
||||
import type { $ZodCheck, $ZodStringFormats } from "./checks.js";
|
||||
import { $constructor } from "./core.js";
|
||||
import type { $ZodType } from "./schemas.js";
|
||||
import type { StandardSchemaV1 } from "./standard-schema.js";
|
||||
import * as util from "./util.js";
|
||||
export interface $ZodIssueBase {
|
||||
readonly code?: string;
|
||||
@@ -12,7 +11,7 @@ export interface $ZodIssueBase {
|
||||
export interface $ZodIssueInvalidType<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_type";
|
||||
readonly expected: $ZodType["_zod"]["def"]["type"];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "too_big";
|
||||
@@ -20,7 +19,7 @@ export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
|
||||
readonly maximum: number | bigint;
|
||||
readonly inclusive?: boolean;
|
||||
readonly exact?: boolean;
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "too_small";
|
||||
@@ -30,52 +29,51 @@ export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
|
||||
readonly inclusive?: boolean;
|
||||
/** True if the allowed value is fixed (e.g.` z.length(5)`), not a range (`z.minLength(5)`) */
|
||||
readonly exact?: boolean;
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueInvalidStringFormat extends $ZodIssueBase {
|
||||
readonly code: "invalid_format";
|
||||
readonly format: $ZodStringFormats | (string & {});
|
||||
readonly pattern?: string;
|
||||
readonly input?: string;
|
||||
readonly input: string;
|
||||
}
|
||||
export interface $ZodIssueNotMultipleOf<Input extends number | bigint = number | bigint> extends $ZodIssueBase {
|
||||
readonly code: "not_multiple_of";
|
||||
readonly divisor: number;
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueUnrecognizedKeys extends $ZodIssueBase {
|
||||
readonly code: "unrecognized_keys";
|
||||
readonly keys: string[];
|
||||
readonly input?: Record<string, unknown>;
|
||||
readonly input: Record<string, unknown>;
|
||||
}
|
||||
export interface $ZodIssueInvalidUnion extends $ZodIssueBase {
|
||||
readonly code: "invalid_union";
|
||||
readonly errors: $ZodIssue[][];
|
||||
readonly input?: unknown;
|
||||
readonly discriminator?: string | undefined;
|
||||
readonly input: unknown;
|
||||
}
|
||||
export interface $ZodIssueInvalidKey<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_key";
|
||||
readonly origin: "map" | "record";
|
||||
readonly issues: $ZodIssue[];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueInvalidElement<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_element";
|
||||
readonly origin: "map" | "set";
|
||||
readonly key: unknown;
|
||||
readonly issues: $ZodIssue[];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
|
||||
readonly code: "invalid_value";
|
||||
readonly values: util.Primitive[];
|
||||
readonly input?: Input;
|
||||
readonly input: Input;
|
||||
}
|
||||
export interface $ZodIssueCustom extends $ZodIssueBase {
|
||||
readonly code: "custom";
|
||||
readonly params?: Record<string, any> | undefined;
|
||||
readonly input?: unknown;
|
||||
readonly input: unknown;
|
||||
}
|
||||
export interface $ZodIssueStringCommonFormats extends $ZodIssueInvalidStringFormat {
|
||||
format: Exclude<$ZodStringFormats, "regex" | "jwt" | "starts_with" | "ends_with" | "includes">;
|
||||
@@ -103,16 +101,15 @@ export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
|
||||
export type $ZodStringFormatIssues = $ZodIssueStringCommonFormats | $ZodIssueStringInvalidRegex | $ZodIssueStringInvalidJWT | $ZodIssueStringStartsWith | $ZodIssueStringEndsWith | $ZodIssueStringIncludes;
|
||||
export type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom;
|
||||
export type $ZodIssueCode = $ZodIssue["code"];
|
||||
export type $ZodInternalIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends $ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends $ZodIssueBase> = util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
/** The input data */
|
||||
readonly input: unknown;
|
||||
readonly input?: unknown;
|
||||
/** The schema or check that originated this issue. */
|
||||
readonly inst?: $ZodType | $ZodCheck;
|
||||
/** If `true`, Zod will continue executing checks/refinements after this issue. */
|
||||
/** @deprecated Internal use only. If `true`, Zod will continue executing validation despite this issue. */
|
||||
readonly continue?: boolean | undefined;
|
||||
} & Record<string, unknown>> : never;
|
||||
export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = $ZodInternalIssue<T>;
|
||||
} & Record<string, any>>;
|
||||
export interface $ZodErrorMap<T extends $ZodIssueBase = $ZodIssue> {
|
||||
(issue: $ZodRawIssue<T>): {
|
||||
message: string;
|
||||
@@ -153,9 +150,7 @@ export type $ZodFormattedError<T, U = string> = {
|
||||
} & util.Flatten<_ZodFormattedError<T, U>>;
|
||||
export declare function formatError<T>(error: $ZodError<T>): $ZodFormattedError<T>;
|
||||
export declare function formatError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodFormattedError<T, U>;
|
||||
export type $ZodErrorTree<T, U = string> = T extends util.Primitive ? {
|
||||
errors: U[];
|
||||
} : T extends [any, ...any[]] ? {
|
||||
export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]] ? {
|
||||
errors: U[];
|
||||
items?: {
|
||||
[K in keyof T]?: $ZodErrorTree<T[K], U>;
|
||||
@@ -205,6 +200,9 @@ export declare function treeifyError<T, U>(error: $ZodError<T>, mapper?: (issue:
|
||||
* ✖ Invalid input: expected number
|
||||
* ```
|
||||
*/
|
||||
export declare function toDotPath(_path: readonly (string | number | symbol | StandardSchemaV1.PathSegment)[]): string;
|
||||
export declare function prettifyError(error: StandardSchemaV1.FailureResult): string;
|
||||
export declare function toDotPath(path: (string | number | symbol)[]): string;
|
||||
interface BaseError {
|
||||
issues: $ZodIssueBase[];
|
||||
}
|
||||
export declare function prettifyError(error: BaseError): string;
|
||||
export {};
|
||||
|
||||
+19
-6
@@ -10,7 +10,13 @@ const initializer = (inst, def) => {
|
||||
value: def,
|
||||
enumerable: false,
|
||||
});
|
||||
inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
||||
Object.defineProperty(inst, "message", {
|
||||
get() {
|
||||
return JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
||||
},
|
||||
enumerable: true,
|
||||
// configurable: false,
|
||||
});
|
||||
Object.defineProperty(inst, "toString", {
|
||||
value: () => inst.message,
|
||||
enumerable: false,
|
||||
@@ -32,7 +38,11 @@ export function flattenError(error, mapper = (issue) => issue.message) {
|
||||
}
|
||||
return { formErrors, fieldErrors };
|
||||
}
|
||||
export function formatError(error, mapper = (issue) => issue.message) {
|
||||
export function formatError(error, _mapper) {
|
||||
const mapper = _mapper ||
|
||||
function (issue) {
|
||||
return issue.message;
|
||||
};
|
||||
const fieldErrors = { _errors: [] };
|
||||
const processError = (error) => {
|
||||
for (const issue of error.issues) {
|
||||
@@ -70,7 +80,11 @@ export function formatError(error, mapper = (issue) => issue.message) {
|
||||
processError(error);
|
||||
return fieldErrors;
|
||||
}
|
||||
export function treeifyError(error, mapper = (issue) => issue.message) {
|
||||
export function treeifyError(error, _mapper) {
|
||||
const mapper = _mapper ||
|
||||
function (issue) {
|
||||
return issue.message;
|
||||
};
|
||||
const result = { errors: [] };
|
||||
const processError = (error, path = []) => {
|
||||
var _a, _b;
|
||||
@@ -149,9 +163,8 @@ export function treeifyError(error, mapper = (issue) => issue.message) {
|
||||
* ✖ Invalid input: expected number
|
||||
* ```
|
||||
*/
|
||||
export function toDotPath(_path) {
|
||||
export function toDotPath(path) {
|
||||
const segs = [];
|
||||
const path = _path.map((seg) => (typeof seg === "object" ? seg.key : seg));
|
||||
for (const seg of path) {
|
||||
if (typeof seg === "number")
|
||||
segs.push(`[${seg}]`);
|
||||
@@ -170,7 +183,7 @@ export function toDotPath(_path) {
|
||||
export function prettifyError(error) {
|
||||
const lines = [];
|
||||
// sort by path length
|
||||
const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
||||
const issues = [...error.issues].sort((a, b) => a.path.length - b.path.length);
|
||||
// Process each issue
|
||||
for (const issue of issues) {
|
||||
lines.push(`✖ ${issue.message}`);
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ exports.regexes = __importStar(require("./regexes.cjs"));
|
||||
exports.locales = __importStar(require("../locales/index.cjs"));
|
||||
__exportStar(require("./registries.cjs"), exports);
|
||||
__exportStar(require("./doc.cjs"), exports);
|
||||
__exportStar(require("./function.cjs"), exports);
|
||||
__exportStar(require("./api.cjs"), exports);
|
||||
__exportStar(require("./to-json-schema.cjs"), exports);
|
||||
exports.JSONSchema = __importStar(require("./json-schema.cjs"));
|
||||
|
||||
+1
@@ -9,6 +9,7 @@ export * as regexes from "./regexes.cjs";
|
||||
export * as locales from "../locales/index.cjs";
|
||||
export * from "./registries.cjs";
|
||||
export * from "./doc.cjs";
|
||||
export * from "./function.cjs";
|
||||
export * from "./api.cjs";
|
||||
export * from "./to-json-schema.cjs";
|
||||
export * as JSONSchema from "./json-schema.cjs";
|
||||
|
||||
+1
@@ -9,6 +9,7 @@ export * as regexes from "./regexes.js";
|
||||
export * as locales from "../locales/index.js";
|
||||
export * from "./registries.js";
|
||||
export * from "./doc.js";
|
||||
export * from "./function.js";
|
||||
export * from "./api.js";
|
||||
export * from "./to-json-schema.js";
|
||||
export * as JSONSchema from "./json-schema.js";
|
||||
|
||||
+1
@@ -9,6 +9,7 @@ export * as regexes from "./regexes.js";
|
||||
export * as locales from "../locales/index.js";
|
||||
export * from "./registries.js";
|
||||
export * from "./doc.js";
|
||||
export * from "./function.js";
|
||||
export * from "./api.js";
|
||||
export * from "./to-json-schema.js";
|
||||
export * as JSONSchema from "./json-schema.js";
|
||||
|
||||
+3
-4
@@ -2,7 +2,7 @@ export type Schema = ObjectSchema | ArraySchema | StringSchema | NumberSchema |
|
||||
export type _JSONSchema = boolean | JSONSchema;
|
||||
export type JSONSchema = {
|
||||
[k: string]: unknown;
|
||||
$schema?: "https://json-schema.org/draft/2020-12/schema" | "http://json-schema.org/draft-07/schema#" | "http://json-schema.org/draft-04/schema#";
|
||||
$schema?: "https://json-schema.org/draft/2020-12/schema" | "http://json-schema.org/draft-07/schema#";
|
||||
$id?: string;
|
||||
$anchor?: string;
|
||||
$ref?: string;
|
||||
@@ -32,9 +32,9 @@ export type JSONSchema = {
|
||||
not?: _JSONSchema;
|
||||
multipleOf?: number;
|
||||
maximum?: number;
|
||||
exclusiveMaximum?: number | boolean;
|
||||
exclusiveMaximum?: number;
|
||||
minimum?: number;
|
||||
exclusiveMinimum?: number | boolean;
|
||||
exclusiveMinimum?: number;
|
||||
maxLength?: number;
|
||||
minLength?: number;
|
||||
pattern?: string;
|
||||
@@ -56,7 +56,6 @@ export type JSONSchema = {
|
||||
deprecated?: boolean;
|
||||
readOnly?: boolean;
|
||||
writeOnly?: boolean;
|
||||
nullable?: boolean;
|
||||
examples?: unknown[];
|
||||
format?: string;
|
||||
contentMediaType?: string;
|
||||
|
||||
+3
-4
@@ -2,7 +2,7 @@ export type Schema = ObjectSchema | ArraySchema | StringSchema | NumberSchema |
|
||||
export type _JSONSchema = boolean | JSONSchema;
|
||||
export type JSONSchema = {
|
||||
[k: string]: unknown;
|
||||
$schema?: "https://json-schema.org/draft/2020-12/schema" | "http://json-schema.org/draft-07/schema#" | "http://json-schema.org/draft-04/schema#";
|
||||
$schema?: "https://json-schema.org/draft/2020-12/schema" | "http://json-schema.org/draft-07/schema#";
|
||||
$id?: string;
|
||||
$anchor?: string;
|
||||
$ref?: string;
|
||||
@@ -32,9 +32,9 @@ export type JSONSchema = {
|
||||
not?: _JSONSchema;
|
||||
multipleOf?: number;
|
||||
maximum?: number;
|
||||
exclusiveMaximum?: number | boolean;
|
||||
exclusiveMaximum?: number;
|
||||
minimum?: number;
|
||||
exclusiveMinimum?: number | boolean;
|
||||
exclusiveMinimum?: number;
|
||||
maxLength?: number;
|
||||
minLength?: number;
|
||||
pattern?: string;
|
||||
@@ -56,7 +56,6 @@ export type JSONSchema = {
|
||||
deprecated?: boolean;
|
||||
readOnly?: boolean;
|
||||
writeOnly?: boolean;
|
||||
nullable?: boolean;
|
||||
examples?: unknown[];
|
||||
format?: string;
|
||||
contentMediaType?: string;
|
||||
|
||||
+1
-45
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.safeDecodeAsync = exports._safeDecodeAsync = exports.safeEncodeAsync = exports._safeEncodeAsync = exports.safeDecode = exports._safeDecode = exports.safeEncode = exports._safeEncode = exports.decodeAsync = exports._decodeAsync = exports.encodeAsync = exports._encodeAsync = exports.decode = exports._decode = exports.encode = exports._encode = exports.safeParseAsync = exports._safeParseAsync = exports.safeParse = exports._safeParse = exports.parseAsync = exports._parseAsync = exports.parse = exports._parse = void 0;
|
||||
exports.safeParseAsync = exports._safeParseAsync = exports.safeParse = exports._safeParse = exports.parseAsync = exports._parseAsync = exports.parse = exports._parse = void 0;
|
||||
const core = __importStar(require("./core.cjs"));
|
||||
const errors = __importStar(require("./errors.cjs"));
|
||||
const util = __importStar(require("./util.cjs"));
|
||||
@@ -85,47 +85,3 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
};
|
||||
exports._safeParseAsync = _safeParseAsync;
|
||||
exports.safeParseAsync = (0, exports._safeParseAsync)(errors.$ZodRealError);
|
||||
const _encode = (_Err) => (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return (0, exports._parse)(_Err)(schema, value, ctx);
|
||||
};
|
||||
exports._encode = _encode;
|
||||
exports.encode = (0, exports._encode)(errors.$ZodRealError);
|
||||
const _decode = (_Err) => (schema, value, _ctx) => {
|
||||
return (0, exports._parse)(_Err)(schema, value, _ctx);
|
||||
};
|
||||
exports._decode = _decode;
|
||||
exports.decode = (0, exports._decode)(errors.$ZodRealError);
|
||||
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return (0, exports._parseAsync)(_Err)(schema, value, ctx);
|
||||
};
|
||||
exports._encodeAsync = _encodeAsync;
|
||||
exports.encodeAsync = (0, exports._encodeAsync)(errors.$ZodRealError);
|
||||
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
return (0, exports._parseAsync)(_Err)(schema, value, _ctx);
|
||||
};
|
||||
exports._decodeAsync = _decodeAsync;
|
||||
exports.decodeAsync = (0, exports._decodeAsync)(errors.$ZodRealError);
|
||||
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return (0, exports._safeParse)(_Err)(schema, value, ctx);
|
||||
};
|
||||
exports._safeEncode = _safeEncode;
|
||||
exports.safeEncode = (0, exports._safeEncode)(errors.$ZodRealError);
|
||||
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
||||
return (0, exports._safeParse)(_Err)(schema, value, _ctx);
|
||||
};
|
||||
exports._safeDecode = _safeDecode;
|
||||
exports.safeDecode = (0, exports._safeDecode)(errors.$ZodRealError);
|
||||
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return (0, exports._safeParseAsync)(_Err)(schema, value, ctx);
|
||||
};
|
||||
exports._safeEncodeAsync = _safeEncodeAsync;
|
||||
exports.safeEncodeAsync = (0, exports._safeEncodeAsync)(errors.$ZodRealError);
|
||||
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
return (0, exports._safeParseAsync)(_Err)(schema, value, _ctx);
|
||||
};
|
||||
exports._safeDecodeAsync = _safeDecodeAsync;
|
||||
exports.safeDecodeAsync = (0, exports._safeDecodeAsync)(errors.$ZodRealError);
|
||||
|
||||
-24
@@ -23,27 +23,3 @@ export declare const safeParse: $SafeParse;
|
||||
export type $SafeParseAsync = <T extends schemas.$ZodType>(schema: T, value: unknown, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<util.SafeParseResult<core.output<T>>>;
|
||||
export declare const _safeParseAsync: (_Err: $ZodErrorClass) => $SafeParseAsync;
|
||||
export declare const safeParseAsync: $SafeParseAsync;
|
||||
export type $Encode = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => core.input<T>;
|
||||
export declare const _encode: (_Err: $ZodErrorClass) => $Encode;
|
||||
export declare const encode: $Encode;
|
||||
export type $Decode = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => core.output<T>;
|
||||
export declare const _decode: (_Err: $ZodErrorClass) => $Decode;
|
||||
export declare const decode: $Decode;
|
||||
export type $EncodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<core.input<T>>;
|
||||
export declare const _encodeAsync: (_Err: $ZodErrorClass) => $EncodeAsync;
|
||||
export declare const encodeAsync: $EncodeAsync;
|
||||
export type $DecodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<core.output<T>>;
|
||||
export declare const _decodeAsync: (_Err: $ZodErrorClass) => $DecodeAsync;
|
||||
export declare const decodeAsync: $DecodeAsync;
|
||||
export type $SafeEncode = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => util.SafeParseResult<core.input<T>>;
|
||||
export declare const _safeEncode: (_Err: $ZodErrorClass) => $SafeEncode;
|
||||
export declare const safeEncode: $SafeEncode;
|
||||
export type $SafeDecode = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => util.SafeParseResult<core.output<T>>;
|
||||
export declare const _safeDecode: (_Err: $ZodErrorClass) => $SafeDecode;
|
||||
export declare const safeDecode: $SafeDecode;
|
||||
export type $SafeEncodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<util.SafeParseResult<core.input<T>>>;
|
||||
export declare const _safeEncodeAsync: (_Err: $ZodErrorClass) => $SafeEncodeAsync;
|
||||
export declare const safeEncodeAsync: $SafeEncodeAsync;
|
||||
export type $SafeDecodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<util.SafeParseResult<core.output<T>>>;
|
||||
export declare const _safeDecodeAsync: (_Err: $ZodErrorClass) => $SafeDecodeAsync;
|
||||
export declare const safeDecodeAsync: $SafeDecodeAsync;
|
||||
|
||||
-24
@@ -23,27 +23,3 @@ export declare const safeParse: $SafeParse;
|
||||
export type $SafeParseAsync = <T extends schemas.$ZodType>(schema: T, value: unknown, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<util.SafeParseResult<core.output<T>>>;
|
||||
export declare const _safeParseAsync: (_Err: $ZodErrorClass) => $SafeParseAsync;
|
||||
export declare const safeParseAsync: $SafeParseAsync;
|
||||
export type $Encode = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => core.input<T>;
|
||||
export declare const _encode: (_Err: $ZodErrorClass) => $Encode;
|
||||
export declare const encode: $Encode;
|
||||
export type $Decode = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => core.output<T>;
|
||||
export declare const _decode: (_Err: $ZodErrorClass) => $Decode;
|
||||
export declare const decode: $Decode;
|
||||
export type $EncodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<core.input<T>>;
|
||||
export declare const _encodeAsync: (_Err: $ZodErrorClass) => $EncodeAsync;
|
||||
export declare const encodeAsync: $EncodeAsync;
|
||||
export type $DecodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<core.output<T>>;
|
||||
export declare const _decodeAsync: (_Err: $ZodErrorClass) => $DecodeAsync;
|
||||
export declare const decodeAsync: $DecodeAsync;
|
||||
export type $SafeEncode = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => util.SafeParseResult<core.input<T>>;
|
||||
export declare const _safeEncode: (_Err: $ZodErrorClass) => $SafeEncode;
|
||||
export declare const safeEncode: $SafeEncode;
|
||||
export type $SafeDecode = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => util.SafeParseResult<core.output<T>>;
|
||||
export declare const _safeDecode: (_Err: $ZodErrorClass) => $SafeDecode;
|
||||
export declare const safeDecode: $SafeDecode;
|
||||
export type $SafeEncodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.output<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<util.SafeParseResult<core.input<T>>>;
|
||||
export declare const _safeEncodeAsync: (_Err: $ZodErrorClass) => $SafeEncodeAsync;
|
||||
export declare const safeEncodeAsync: $SafeEncodeAsync;
|
||||
export type $SafeDecodeAsync = <T extends schemas.$ZodType>(schema: T, value: core.input<T>, _ctx?: schemas.ParseContext<errors.$ZodIssue>) => Promise<util.SafeParseResult<core.output<T>>>;
|
||||
export declare const _safeDecodeAsync: (_Err: $ZodErrorClass) => $SafeDecodeAsync;
|
||||
export declare const safeDecodeAsync: $SafeDecodeAsync;
|
||||
|
||||
-36
@@ -55,39 +55,3 @@ export const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
: { success: true, data: result.value };
|
||||
};
|
||||
export const safeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$ZodRealError);
|
||||
export const _encode = (_Err) => (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return _parse(_Err)(schema, value, ctx);
|
||||
};
|
||||
export const encode = /* @__PURE__*/ _encode(errors.$ZodRealError);
|
||||
export const _decode = (_Err) => (schema, value, _ctx) => {
|
||||
return _parse(_Err)(schema, value, _ctx);
|
||||
};
|
||||
export const decode = /* @__PURE__*/ _decode(errors.$ZodRealError);
|
||||
export const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return _parseAsync(_Err)(schema, value, ctx);
|
||||
};
|
||||
export const encodeAsync = /* @__PURE__*/ _encodeAsync(errors.$ZodRealError);
|
||||
export const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
return _parseAsync(_Err)(schema, value, _ctx);
|
||||
};
|
||||
export const decodeAsync = /* @__PURE__*/ _decodeAsync(errors.$ZodRealError);
|
||||
export const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return _safeParse(_Err)(schema, value, ctx);
|
||||
};
|
||||
export const safeEncode = /* @__PURE__*/ _safeEncode(errors.$ZodRealError);
|
||||
export const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
||||
return _safeParse(_Err)(schema, value, _ctx);
|
||||
};
|
||||
export const safeDecode = /* @__PURE__*/ _safeDecode(errors.$ZodRealError);
|
||||
export const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
||||
return _safeParseAsync(_Err)(schema, value, ctx);
|
||||
};
|
||||
export const safeEncodeAsync = /* @__PURE__*/ _safeEncodeAsync(errors.$ZodRealError);
|
||||
export const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
||||
return _safeParseAsync(_Err)(schema, value, _ctx);
|
||||
};
|
||||
export const safeDecodeAsync = /* @__PURE__*/ _safeDecodeAsync(errors.$ZodRealError);
|
||||
|
||||
+16
-78
@@ -1,34 +1,9 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sha384_hex = exports.sha256_base64url = exports.sha256_base64 = exports.sha256_hex = exports.sha1_base64url = exports.sha1_base64 = exports.sha1_hex = exports.md5_base64url = exports.md5_base64 = exports.md5_hex = exports.hex = exports.uppercase = exports.lowercase = exports.undefined = exports.null = exports.boolean = exports.number = exports.integer = exports.bigint = exports.string = exports.date = exports.e164 = exports.domain = exports.hostname = exports.base64url = exports.base64 = exports.cidrv6 = exports.cidrv4 = exports.mac = exports.ipv6 = exports.ipv4 = exports.browserEmail = exports.idnEmail = exports.unicodeEmail = exports.rfc5322Email = exports.html5Email = exports.email = exports.uuid7 = exports.uuid6 = exports.uuid4 = exports.uuid = exports.guid = exports.extendedDuration = exports.duration = exports.nanoid = exports.ksuid = exports.xid = exports.ulid = exports.cuid2 = exports.cuid = void 0;
|
||||
exports.sha512_base64url = exports.sha512_base64 = exports.sha512_hex = exports.sha384_base64url = exports.sha384_base64 = void 0;
|
||||
exports.uppercase = exports.lowercase = exports.undefined = exports.null = exports.boolean = exports.number = exports.integer = exports.bigint = exports.string = exports.date = exports.e164 = exports.domain = exports.hostname = exports.base64url = exports.base64 = exports.cidrv6 = exports.cidrv4 = exports.ipv6 = exports.ipv4 = exports._emoji = exports.browserEmail = exports.unicodeEmail = exports.rfc5322Email = exports.html5Email = exports.email = exports.uuid7 = exports.uuid6 = exports.uuid4 = exports.uuid = exports.guid = exports.extendedDuration = exports.duration = exports.nanoid = exports.ksuid = exports.xid = exports.ulid = exports.cuid2 = exports.cuid = void 0;
|
||||
exports.emoji = emoji;
|
||||
exports.time = time;
|
||||
exports.datetime = datetime;
|
||||
const util = __importStar(require("./util.cjs"));
|
||||
exports.cuid = /^[cC][^\s-]{8,}$/;
|
||||
exports.cuid2 = /^[0-9a-z]+$/;
|
||||
exports.ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
||||
@@ -41,12 +16,12 @@ exports.duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\
|
||||
exports.extendedDuration = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
||||
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
||||
exports.guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
||||
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
||||
/** Returns a regex for validating an RFC 4122 UUID.
|
||||
*
|
||||
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
||||
const uuid = (version) => {
|
||||
if (!version)
|
||||
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
||||
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
|
||||
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
||||
};
|
||||
exports.uuid = uuid;
|
||||
@@ -61,28 +36,23 @@ exports.html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9
|
||||
exports.rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
||||
exports.unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
||||
exports.idnEmail = exports.unicodeEmail;
|
||||
exports.browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
||||
const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||
exports._emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||
function emoji() {
|
||||
return new RegExp(_emoji, "u");
|
||||
return new RegExp(exports._emoji, "u");
|
||||
}
|
||||
exports.ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
||||
exports.ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
||||
const mac = (delimiter) => {
|
||||
const escapedDelim = util.escapeRegex(delimiter ?? ":");
|
||||
return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
|
||||
};
|
||||
exports.mac = mac;
|
||||
exports.ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/;
|
||||
exports.cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
||||
exports.cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
||||
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
||||
exports.base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
||||
exports.base64url = /^[A-Za-z0-9_-]*$/;
|
||||
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
||||
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
||||
exports.hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
||||
// export const hostname: RegExp =
|
||||
// /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
|
||||
exports.hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
||||
exports.domain = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
||||
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
||||
exports.e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
||||
@@ -109,9 +79,8 @@ function datetime(args) {
|
||||
const opts = ["Z"];
|
||||
if (args.local)
|
||||
opts.push("");
|
||||
// if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
|
||||
if (args.offset)
|
||||
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
||||
opts.push(`([+-]\\d{2}:\\d{2})`);
|
||||
const timeRegex = `${time}(?:${opts.join("|")})`;
|
||||
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
||||
}
|
||||
@@ -120,46 +89,15 @@ const string = (params) => {
|
||||
return new RegExp(`^${regex}$`);
|
||||
};
|
||||
exports.string = string;
|
||||
exports.bigint = /^-?\d+n?$/;
|
||||
exports.integer = /^-?\d+$/;
|
||||
exports.number = /^-?\d+(?:\.\d+)?/;
|
||||
exports.boolean = /^(?:true|false)$/i;
|
||||
const _null = /^null$/i;
|
||||
exports.bigint = /^\d+n?$/;
|
||||
exports.integer = /^\d+$/;
|
||||
exports.number = /^-?\d+(?:\.\d+)?/i;
|
||||
exports.boolean = /true|false/i;
|
||||
const _null = /null/i;
|
||||
exports.null = _null;
|
||||
const _undefined = /^undefined$/i;
|
||||
const _undefined = /undefined/i;
|
||||
exports.undefined = _undefined;
|
||||
// regex for string with no uppercase letters
|
||||
exports.lowercase = /^[^A-Z]*$/;
|
||||
// regex for string with no lowercase letters
|
||||
exports.uppercase = /^[^a-z]*$/;
|
||||
// regex for hexadecimal strings (any length)
|
||||
exports.hex = /^[0-9a-fA-F]*$/;
|
||||
// Hash regexes for different algorithms and encodings
|
||||
// Helper function to create base64 regex with exact length and padding
|
||||
function fixedBase64(bodyLength, padding) {
|
||||
return new RegExp(`^[A-Za-z0-9+/]{${bodyLength}}${padding}$`);
|
||||
}
|
||||
// Helper function to create base64url regex with exact length (no padding)
|
||||
function fixedBase64url(length) {
|
||||
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
||||
}
|
||||
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
||||
exports.md5_hex = /^[0-9a-fA-F]{32}$/;
|
||||
exports.md5_base64 = fixedBase64(22, "==");
|
||||
exports.md5_base64url = fixedBase64url(22);
|
||||
// SHA1 (20 bytes): base64 = 28 chars total (27 + "=")
|
||||
exports.sha1_hex = /^[0-9a-fA-F]{40}$/;
|
||||
exports.sha1_base64 = fixedBase64(27, "=");
|
||||
exports.sha1_base64url = fixedBase64url(27);
|
||||
// SHA256 (32 bytes): base64 = 44 chars total (43 + "=")
|
||||
exports.sha256_hex = /^[0-9a-fA-F]{64}$/;
|
||||
exports.sha256_base64 = fixedBase64(43, "=");
|
||||
exports.sha256_base64url = fixedBase64url(43);
|
||||
// SHA384 (48 bytes): base64 = 64 chars total (no padding)
|
||||
exports.sha384_hex = /^[0-9a-fA-F]{96}$/;
|
||||
exports.sha384_base64 = fixedBase64(64, "");
|
||||
exports.sha384_base64url = fixedBase64url(64);
|
||||
// SHA512 (64 bytes): base64 = 88 chars total (86 + "==")
|
||||
exports.sha512_hex = /^[0-9a-fA-F]{128}$/;
|
||||
exports.sha512_base64 = fixedBase64(86, "==");
|
||||
exports.sha512_base64url = fixedBase64url(86);
|
||||
|
||||
+2
-19
@@ -10,7 +10,7 @@ export declare const duration: RegExp;
|
||||
export declare const extendedDuration: RegExp;
|
||||
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
||||
export declare const guid: RegExp;
|
||||
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
||||
/** Returns a regex for validating an RFC 4122 UUID.
|
||||
*
|
||||
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
||||
export declare const uuid: (version?: number | undefined) => RegExp;
|
||||
@@ -25,12 +25,11 @@ export declare const html5Email: RegExp;
|
||||
export declare const rfc5322Email: RegExp;
|
||||
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
||||
export declare const unicodeEmail: RegExp;
|
||||
export declare const idnEmail: RegExp;
|
||||
export declare const browserEmail: RegExp;
|
||||
export declare const _emoji = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
|
||||
export declare function emoji(): RegExp;
|
||||
export declare const ipv4: RegExp;
|
||||
export declare const ipv6: RegExp;
|
||||
export declare const mac: (delimiter?: string) => RegExp;
|
||||
export declare const cidrv4: RegExp;
|
||||
export declare const cidrv6: RegExp;
|
||||
export declare const base64: RegExp;
|
||||
@@ -61,19 +60,3 @@ declare const _undefined: RegExp;
|
||||
export { _undefined as undefined };
|
||||
export declare const lowercase: RegExp;
|
||||
export declare const uppercase: RegExp;
|
||||
export declare const hex: RegExp;
|
||||
export declare const md5_hex: RegExp;
|
||||
export declare const md5_base64: RegExp;
|
||||
export declare const md5_base64url: RegExp;
|
||||
export declare const sha1_hex: RegExp;
|
||||
export declare const sha1_base64: RegExp;
|
||||
export declare const sha1_base64url: RegExp;
|
||||
export declare const sha256_hex: RegExp;
|
||||
export declare const sha256_base64: RegExp;
|
||||
export declare const sha256_base64url: RegExp;
|
||||
export declare const sha384_hex: RegExp;
|
||||
export declare const sha384_base64: RegExp;
|
||||
export declare const sha384_base64url: RegExp;
|
||||
export declare const sha512_hex: RegExp;
|
||||
export declare const sha512_base64: RegExp;
|
||||
export declare const sha512_base64url: RegExp;
|
||||
|
||||
+2
-19
@@ -10,7 +10,7 @@ export declare const duration: RegExp;
|
||||
export declare const extendedDuration: RegExp;
|
||||
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
||||
export declare const guid: RegExp;
|
||||
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
||||
/** Returns a regex for validating an RFC 4122 UUID.
|
||||
*
|
||||
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
||||
export declare const uuid: (version?: number | undefined) => RegExp;
|
||||
@@ -25,12 +25,11 @@ export declare const html5Email: RegExp;
|
||||
export declare const rfc5322Email: RegExp;
|
||||
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
||||
export declare const unicodeEmail: RegExp;
|
||||
export declare const idnEmail: RegExp;
|
||||
export declare const browserEmail: RegExp;
|
||||
export declare const _emoji = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
|
||||
export declare function emoji(): RegExp;
|
||||
export declare const ipv4: RegExp;
|
||||
export declare const ipv6: RegExp;
|
||||
export declare const mac: (delimiter?: string) => RegExp;
|
||||
export declare const cidrv4: RegExp;
|
||||
export declare const cidrv6: RegExp;
|
||||
export declare const base64: RegExp;
|
||||
@@ -61,19 +60,3 @@ declare const _undefined: RegExp;
|
||||
export { _undefined as undefined };
|
||||
export declare const lowercase: RegExp;
|
||||
export declare const uppercase: RegExp;
|
||||
export declare const hex: RegExp;
|
||||
export declare const md5_hex: RegExp;
|
||||
export declare const md5_base64: RegExp;
|
||||
export declare const md5_base64url: RegExp;
|
||||
export declare const sha1_hex: RegExp;
|
||||
export declare const sha1_base64: RegExp;
|
||||
export declare const sha1_base64url: RegExp;
|
||||
export declare const sha256_hex: RegExp;
|
||||
export declare const sha256_base64: RegExp;
|
||||
export declare const sha256_base64url: RegExp;
|
||||
export declare const sha384_hex: RegExp;
|
||||
export declare const sha384_base64: RegExp;
|
||||
export declare const sha384_base64url: RegExp;
|
||||
export declare const sha512_hex: RegExp;
|
||||
export declare const sha512_base64: RegExp;
|
||||
export declare const sha512_base64url: RegExp;
|
||||
|
||||
+14
-51
@@ -1,4 +1,3 @@
|
||||
import * as util from "./util.js";
|
||||
export const cuid = /^[cC][^\s-]{8,}$/;
|
||||
export const cuid2 = /^[0-9a-z]+$/;
|
||||
export const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
||||
@@ -11,12 +10,12 @@ export const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=
|
||||
export const extendedDuration = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
||||
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
||||
export const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
||||
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
||||
/** Returns a regex for validating an RFC 4122 UUID.
|
||||
*
|
||||
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
||||
export const uuid = (version) => {
|
||||
if (!version)
|
||||
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
||||
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
|
||||
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
||||
};
|
||||
export const uuid4 = /*@__PURE__*/ uuid(4);
|
||||
@@ -30,27 +29,23 @@ export const html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA
|
||||
export const rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
||||
export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
||||
export const idnEmail = unicodeEmail;
|
||||
export const browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
||||
const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||
export const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||
export function emoji() {
|
||||
return new RegExp(_emoji, "u");
|
||||
}
|
||||
export const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
||||
export const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
||||
export const mac = (delimiter) => {
|
||||
const escapedDelim = util.escapeRegex(delimiter ?? ":");
|
||||
return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
|
||||
};
|
||||
export const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/;
|
||||
export const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
||||
export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
||||
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
||||
export const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
||||
export const base64url = /^[A-Za-z0-9_-]*$/;
|
||||
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
||||
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
||||
export const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
||||
// export const hostname: RegExp =
|
||||
// /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
|
||||
export const hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
||||
export const domain = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
||||
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
||||
export const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
||||
@@ -77,9 +72,8 @@ export function datetime(args) {
|
||||
const opts = ["Z"];
|
||||
if (args.local)
|
||||
opts.push("");
|
||||
// if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
|
||||
if (args.offset)
|
||||
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
||||
opts.push(`([+-]\\d{2}:\\d{2})`);
|
||||
const timeRegex = `${time}(?:${opts.join("|")})`;
|
||||
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
||||
}
|
||||
@@ -87,46 +81,15 @@ export const string = (params) => {
|
||||
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
||||
return new RegExp(`^${regex}$`);
|
||||
};
|
||||
export const bigint = /^-?\d+n?$/;
|
||||
export const integer = /^-?\d+$/;
|
||||
export const number = /^-?\d+(?:\.\d+)?/;
|
||||
export const boolean = /^(?:true|false)$/i;
|
||||
const _null = /^null$/i;
|
||||
export const bigint = /^\d+n?$/;
|
||||
export const integer = /^\d+$/;
|
||||
export const number = /^-?\d+(?:\.\d+)?/i;
|
||||
export const boolean = /true|false/i;
|
||||
const _null = /null/i;
|
||||
export { _null as null };
|
||||
const _undefined = /^undefined$/i;
|
||||
const _undefined = /undefined/i;
|
||||
export { _undefined as undefined };
|
||||
// regex for string with no uppercase letters
|
||||
export const lowercase = /^[^A-Z]*$/;
|
||||
// regex for string with no lowercase letters
|
||||
export const uppercase = /^[^a-z]*$/;
|
||||
// regex for hexadecimal strings (any length)
|
||||
export const hex = /^[0-9a-fA-F]*$/;
|
||||
// Hash regexes for different algorithms and encodings
|
||||
// Helper function to create base64 regex with exact length and padding
|
||||
function fixedBase64(bodyLength, padding) {
|
||||
return new RegExp(`^[A-Za-z0-9+/]{${bodyLength}}${padding}$`);
|
||||
}
|
||||
// Helper function to create base64url regex with exact length (no padding)
|
||||
function fixedBase64url(length) {
|
||||
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
||||
}
|
||||
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
||||
export const md5_hex = /^[0-9a-fA-F]{32}$/;
|
||||
export const md5_base64 = /*@__PURE__*/ fixedBase64(22, "==");
|
||||
export const md5_base64url = /*@__PURE__*/ fixedBase64url(22);
|
||||
// SHA1 (20 bytes): base64 = 28 chars total (27 + "=")
|
||||
export const sha1_hex = /^[0-9a-fA-F]{40}$/;
|
||||
export const sha1_base64 = /*@__PURE__*/ fixedBase64(27, "=");
|
||||
export const sha1_base64url = /*@__PURE__*/ fixedBase64url(27);
|
||||
// SHA256 (32 bytes): base64 = 44 chars total (43 + "=")
|
||||
export const sha256_hex = /^[0-9a-fA-F]{64}$/;
|
||||
export const sha256_base64 = /*@__PURE__*/ fixedBase64(43, "=");
|
||||
export const sha256_base64url = /*@__PURE__*/ fixedBase64url(43);
|
||||
// SHA384 (48 bytes): base64 = 64 chars total (no padding)
|
||||
export const sha384_hex = /^[0-9a-fA-F]{96}$/;
|
||||
export const sha384_base64 = /*@__PURE__*/ fixedBase64(64, "");
|
||||
export const sha384_base64url = /*@__PURE__*/ fixedBase64url(64);
|
||||
// SHA512 (64 bytes): base64 = 88 chars total (86 + "==")
|
||||
export const sha512_hex = /^[0-9a-fA-F]{128}$/;
|
||||
export const sha512_base64 = /*@__PURE__*/ fixedBase64(86, "==");
|
||||
export const sha512_base64url = /*@__PURE__*/ fixedBase64url(86);
|
||||
|
||||
+4
-7
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
var _a;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.globalRegistry = exports.$ZodRegistry = exports.$input = exports.$output = void 0;
|
||||
exports.registry = registry;
|
||||
@@ -7,7 +6,7 @@ exports.$output = Symbol("ZodOutput");
|
||||
exports.$input = Symbol("ZodInput");
|
||||
class $ZodRegistry {
|
||||
constructor() {
|
||||
this._map = new WeakMap();
|
||||
this._map = new Map();
|
||||
this._idmap = new Map();
|
||||
}
|
||||
add(schema, ..._meta) {
|
||||
@@ -22,7 +21,7 @@ class $ZodRegistry {
|
||||
return this;
|
||||
}
|
||||
clear() {
|
||||
this._map = new WeakMap();
|
||||
this._map = new Map();
|
||||
this._idmap = new Map();
|
||||
return this;
|
||||
}
|
||||
@@ -41,8 +40,7 @@ class $ZodRegistry {
|
||||
if (p) {
|
||||
const pm = { ...(this.get(p) ?? {}) };
|
||||
delete pm.id; // do not inherit id
|
||||
const f = { ...pm, ...this._map.get(schema) };
|
||||
return Object.keys(f).length ? f : undefined;
|
||||
return { ...pm, ...this._map.get(schema) };
|
||||
}
|
||||
return this._map.get(schema);
|
||||
}
|
||||
@@ -55,5 +53,4 @@ exports.$ZodRegistry = $ZodRegistry;
|
||||
function registry() {
|
||||
return new $ZodRegistry();
|
||||
}
|
||||
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
||||
exports.globalRegistry = globalThis.__zod_globalRegistry;
|
||||
exports.globalRegistry = registry();
|
||||
|
||||
+2
-2
@@ -9,11 +9,11 @@ export type $replace<Meta, S extends $ZodType> = Meta extends $output ? core.out
|
||||
}) => $replace<R, S> : Meta extends object ? {
|
||||
[K in keyof Meta]: $replace<Meta[K], S>;
|
||||
} : Meta;
|
||||
type MetadataType = object | undefined;
|
||||
type MetadataType = Record<string, unknown> | undefined;
|
||||
export declare class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
|
||||
_meta: Meta;
|
||||
_schema: Schema;
|
||||
_map: WeakMap<Schema, $replace<Meta, Schema>>;
|
||||
_map: Map<Schema, $replace<Meta, Schema>>;
|
||||
_idmap: Map<string, Schema>;
|
||||
add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
|
||||
clear(): this;
|
||||
|
||||
+2
-2
@@ -9,11 +9,11 @@ export type $replace<Meta, S extends $ZodType> = Meta extends $output ? core.out
|
||||
}) => $replace<R, S> : Meta extends object ? {
|
||||
[K in keyof Meta]: $replace<Meta[K], S>;
|
||||
} : Meta;
|
||||
type MetadataType = object | undefined;
|
||||
type MetadataType = Record<string, unknown> | undefined;
|
||||
export declare class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
|
||||
_meta: Meta;
|
||||
_schema: Schema;
|
||||
_map: WeakMap<Schema, $replace<Meta, Schema>>;
|
||||
_map: Map<Schema, $replace<Meta, Schema>>;
|
||||
_idmap: Map<string, Schema>;
|
||||
add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
|
||||
clear(): this;
|
||||
|
||||
+4
-7
@@ -1,9 +1,8 @@
|
||||
var _a;
|
||||
export const $output = Symbol("ZodOutput");
|
||||
export const $input = Symbol("ZodInput");
|
||||
export class $ZodRegistry {
|
||||
constructor() {
|
||||
this._map = new WeakMap();
|
||||
this._map = new Map();
|
||||
this._idmap = new Map();
|
||||
}
|
||||
add(schema, ..._meta) {
|
||||
@@ -18,7 +17,7 @@ export class $ZodRegistry {
|
||||
return this;
|
||||
}
|
||||
clear() {
|
||||
this._map = new WeakMap();
|
||||
this._map = new Map();
|
||||
this._idmap = new Map();
|
||||
return this;
|
||||
}
|
||||
@@ -37,8 +36,7 @@ export class $ZodRegistry {
|
||||
if (p) {
|
||||
const pm = { ...(this.get(p) ?? {}) };
|
||||
delete pm.id; // do not inherit id
|
||||
const f = { ...pm, ...this._map.get(schema) };
|
||||
return Object.keys(f).length ? f : undefined;
|
||||
return { ...pm, ...this._map.get(schema) };
|
||||
}
|
||||
return this._map.get(schema);
|
||||
}
|
||||
@@ -50,5 +48,4 @@ export class $ZodRegistry {
|
||||
export function registry() {
|
||||
return new $ZodRegistry();
|
||||
}
|
||||
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
||||
export const globalRegistry = globalThis.__zod_globalRegistry;
|
||||
export const globalRegistry = /*@__PURE__*/ registry();
|
||||
|
||||
+199
-436
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObjectJIT = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodMAC = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
|
||||
exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = void 0;
|
||||
exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
|
||||
exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = void 0;
|
||||
exports.isValidBase64 = isValidBase64;
|
||||
exports.isValidBase64URL = isValidBase64URL;
|
||||
exports.isValidJWT = isValidJWT;
|
||||
@@ -46,6 +46,7 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
|
||||
if (inst._zod.traits.has("$ZodCheck")) {
|
||||
checks.unshift(inst);
|
||||
}
|
||||
//
|
||||
for (const ch of checks) {
|
||||
for (const fn of ch._zod.onattach) {
|
||||
fn(inst);
|
||||
@@ -102,47 +103,7 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
// const handleChecksResult = (
|
||||
// checkResult: ParsePayload,
|
||||
// originalResult: ParsePayload,
|
||||
// ctx: ParseContextInternal
|
||||
// ): util.MaybeAsync<ParsePayload> => {
|
||||
// // if the checks mutated the value && there are no issues, re-parse the result
|
||||
// if (checkResult.value !== originalResult.value && !checkResult.issues.length)
|
||||
// return inst._zod.parse(checkResult, ctx);
|
||||
// return originalResult;
|
||||
// };
|
||||
const handleCanaryResult = (canary, payload, ctx) => {
|
||||
// abort if the canary is aborted
|
||||
if (util.aborted(canary)) {
|
||||
canary.aborted = true;
|
||||
return canary;
|
||||
}
|
||||
// run checks first, then
|
||||
const checkResult = runChecks(payload, checks, ctx);
|
||||
if (checkResult instanceof Promise) {
|
||||
if (ctx.async === false)
|
||||
throw new core.$ZodAsyncError();
|
||||
return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
|
||||
}
|
||||
return inst._zod.parse(checkResult, ctx);
|
||||
};
|
||||
inst._zod.run = (payload, ctx) => {
|
||||
if (ctx.skipChecks) {
|
||||
return inst._zod.parse(payload, ctx);
|
||||
}
|
||||
if (ctx.direction === "backward") {
|
||||
// run canary
|
||||
// initial pass (no checks)
|
||||
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
||||
if (canary instanceof Promise) {
|
||||
return canary.then((canary) => {
|
||||
return handleCanaryResult(canary, payload, ctx);
|
||||
});
|
||||
}
|
||||
return handleCanaryResult(canary, payload, ctx);
|
||||
}
|
||||
// forward
|
||||
const result = inst._zod.parse(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
if (ctx.async === false)
|
||||
@@ -226,10 +187,9 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.check = (payload) => {
|
||||
try {
|
||||
// Trim whitespace from input
|
||||
const trimmed = payload.value.trim();
|
||||
// @ts-ignore
|
||||
const url = new URL(trimmed);
|
||||
const orig = payload.value;
|
||||
const url = new URL(orig);
|
||||
const href = url.href;
|
||||
if (def.hostname) {
|
||||
def.hostname.lastIndex = 0;
|
||||
if (!def.hostname.test(url.hostname)) {
|
||||
@@ -237,7 +197,7 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
|
||||
code: "invalid_format",
|
||||
format: "url",
|
||||
note: "Invalid hostname",
|
||||
pattern: def.hostname.source,
|
||||
pattern: regexes.hostname.source,
|
||||
input: payload.value,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
@@ -258,14 +218,12 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
// Set the output value based on normalize flag
|
||||
if (def.normalize) {
|
||||
// Use normalized URL
|
||||
payload.value = url.href;
|
||||
// payload.value = url.href;
|
||||
if (!orig.endsWith("/") && href.endsWith("/")) {
|
||||
payload.value = href.slice(0, -1);
|
||||
}
|
||||
else {
|
||||
// Preserve the original input (trimmed)
|
||||
payload.value = trimmed;
|
||||
payload.value = href;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -327,15 +285,20 @@ exports.$ZodISODuration = core.$constructor("$ZodISODuration", (inst, def) => {
|
||||
exports.$ZodIPv4 = core.$constructor("$ZodIPv4", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.ipv4);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `ipv4`;
|
||||
inst._zod.onattach.push((inst) => {
|
||||
const bag = inst._zod.bag;
|
||||
bag.format = `ipv4`;
|
||||
});
|
||||
});
|
||||
exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.ipv6);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `ipv6`;
|
||||
inst._zod.onattach.push((inst) => {
|
||||
const bag = inst._zod.bag;
|
||||
bag.format = `ipv6`;
|
||||
});
|
||||
inst._zod.check = (payload) => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
new URL(`http://[${payload.value}]`);
|
||||
// return;
|
||||
}
|
||||
@@ -350,11 +313,6 @@ exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
|
||||
}
|
||||
};
|
||||
});
|
||||
exports.$ZodMAC = core.$constructor("$ZodMAC", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `mac`;
|
||||
});
|
||||
exports.$ZodCIDRv4 = core.$constructor("$ZodCIDRv4", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.cidrv4);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
@@ -363,11 +321,8 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.check = (payload) => {
|
||||
const parts = payload.value.split("/");
|
||||
const [address, prefix] = payload.value.split("/");
|
||||
try {
|
||||
if (parts.length !== 2)
|
||||
throw new Error();
|
||||
const [address, prefix] = parts;
|
||||
if (!prefix)
|
||||
throw new Error();
|
||||
const prefixNum = Number(prefix);
|
||||
@@ -375,7 +330,6 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
|
||||
throw new Error();
|
||||
if (prefixNum < 0 || prefixNum > 128)
|
||||
throw new Error();
|
||||
// @ts-ignore
|
||||
new URL(`http://[${address}]`);
|
||||
}
|
||||
catch {
|
||||
@@ -396,7 +350,6 @@ function isValidBase64(data) {
|
||||
if (data.length % 4 !== 0)
|
||||
return false;
|
||||
try {
|
||||
// @ts-ignore
|
||||
atob(data);
|
||||
return true;
|
||||
}
|
||||
@@ -407,7 +360,9 @@ function isValidBase64(data) {
|
||||
exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.base64);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.contentEncoding = "base64";
|
||||
inst._zod.onattach.push((inst) => {
|
||||
inst._zod.bag.contentEncoding = "base64";
|
||||
});
|
||||
inst._zod.check = (payload) => {
|
||||
if (isValidBase64(payload.value))
|
||||
return;
|
||||
@@ -431,7 +386,9 @@ function isValidBase64URL(data) {
|
||||
exports.$ZodBase64URL = core.$constructor("$ZodBase64URL", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.base64url);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.contentEncoding = "base64url";
|
||||
inst._zod.onattach.push((inst) => {
|
||||
inst._zod.bag.contentEncoding = "base64url";
|
||||
});
|
||||
inst._zod.check = (payload) => {
|
||||
if (isValidBase64URL(payload.value))
|
||||
return;
|
||||
@@ -457,7 +414,6 @@ function isValidJWT(token, algorithm = null) {
|
||||
const [header] = tokensParts;
|
||||
if (!header)
|
||||
return false;
|
||||
// @ts-ignore
|
||||
const parsedHeader = JSON.parse(atob(header));
|
||||
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
|
||||
return false;
|
||||
@@ -529,9 +485,9 @@ exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
exports.$ZodNumberFormat = core.$constructor("$ZodNumberFormat", (inst, def) => {
|
||||
exports.$ZodNumberFormat = core.$constructor("$ZodNumber", (inst, def) => {
|
||||
checks.$ZodCheckNumberFormat.init(inst, def);
|
||||
exports.$ZodNumber.init(inst, def); // no format checks
|
||||
exports.$ZodNumber.init(inst, def); // no format checksp
|
||||
});
|
||||
exports.$ZodBoolean = core.$constructor("$ZodBoolean", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
@@ -574,7 +530,7 @@ exports.$ZodBigInt = core.$constructor("$ZodBigInt", (inst, def) => {
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
exports.$ZodBigIntFormat = core.$constructor("$ZodBigIntFormat", (inst, def) => {
|
||||
exports.$ZodBigIntFormat = core.$constructor("$ZodBigInt", (inst, def) => {
|
||||
checks.$ZodCheckBigIntFormat.init(inst, def);
|
||||
exports.$ZodBigInt.init(inst, def); // no format checks
|
||||
});
|
||||
@@ -728,88 +684,58 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
|
||||
return payload; //handleArrayResultsAsync(parseResults, final);
|
||||
};
|
||||
});
|
||||
function handlePropertyResult(result, final, key, input) {
|
||||
function handleObjectResult(result, final, key) {
|
||||
// if(isOptional)
|
||||
if (result.issues.length) {
|
||||
final.issues.push(...util.prefixIssues(key, result.issues));
|
||||
}
|
||||
if (result.value === undefined) {
|
||||
if (key in input) {
|
||||
final.value[key] = undefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
function normalizeDef(def) {
|
||||
const keys = Object.keys(def.shape);
|
||||
for (const k of keys) {
|
||||
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
|
||||
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
||||
}
|
||||
}
|
||||
const okeys = util.optionalKeys(def.shape);
|
||||
return {
|
||||
...def,
|
||||
keys,
|
||||
keySet: new Set(keys),
|
||||
numKeys: keys.length,
|
||||
optionalKeys: new Set(okeys),
|
||||
};
|
||||
}
|
||||
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
||||
const unrecognized = [];
|
||||
// iterate over input keys
|
||||
const keySet = def.keySet;
|
||||
const _catchall = def.catchall._zod;
|
||||
const t = _catchall.def.type;
|
||||
for (const key in input) {
|
||||
if (keySet.has(key))
|
||||
continue;
|
||||
if (t === "never") {
|
||||
unrecognized.push(key);
|
||||
continue;
|
||||
}
|
||||
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
|
||||
function handleOptionalObjectResult(result, final, key, input) {
|
||||
if (result.issues.length) {
|
||||
// validation failed against value schema
|
||||
if (input[key] === undefined) {
|
||||
// if input was undefined, ignore the error
|
||||
if (key in input) {
|
||||
final.value[key] = undefined;
|
||||
}
|
||||
else {
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
handlePropertyResult(r, payload, key, input);
|
||||
final.issues.push(...util.prefixIssues(key, result.issues));
|
||||
}
|
||||
}
|
||||
if (unrecognized.length) {
|
||||
payload.issues.push({
|
||||
code: "unrecognized_keys",
|
||||
keys: unrecognized,
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
else if (result.value === undefined) {
|
||||
// validation returned `undefined`
|
||||
if (key in input)
|
||||
final.value[key] = undefined;
|
||||
}
|
||||
else {
|
||||
// non-undefined value
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
if (!proms.length)
|
||||
return payload;
|
||||
return Promise.all(proms).then(() => {
|
||||
return payload;
|
||||
});
|
||||
}
|
||||
exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
|
||||
// requires cast because technically $ZodObject doesn't extend
|
||||
exports.$ZodType.init(inst, def);
|
||||
// const sh = def.shape;
|
||||
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
||||
if (!desc?.get) {
|
||||
const sh = def.shape;
|
||||
Object.defineProperty(def, "shape", {
|
||||
get: () => {
|
||||
const newSh = { ...sh };
|
||||
Object.defineProperty(def, "shape", {
|
||||
value: newSh,
|
||||
});
|
||||
return newSh;
|
||||
},
|
||||
});
|
||||
}
|
||||
const _normalized = util.cached(() => normalizeDef(def));
|
||||
const _normalized = util.cached(() => {
|
||||
const keys = Object.keys(def.shape);
|
||||
for (const k of keys) {
|
||||
if (!(def.shape[k] instanceof exports.$ZodType)) {
|
||||
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
||||
}
|
||||
}
|
||||
const okeys = util.optionalKeys(def.shape);
|
||||
return {
|
||||
shape: def.shape,
|
||||
keys,
|
||||
keySet: new Set(keys),
|
||||
numKeys: keys.length,
|
||||
optionalKeys: new Set(okeys),
|
||||
};
|
||||
});
|
||||
util.defineLazy(inst._zod, "propValues", () => {
|
||||
const shape = def.shape;
|
||||
const propValues = {};
|
||||
@@ -823,45 +749,6 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
|
||||
}
|
||||
return propValues;
|
||||
});
|
||||
const isObject = util.isObject;
|
||||
const catchall = def.catchall;
|
||||
let value;
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
value ?? (value = _normalized.value);
|
||||
const input = payload.value;
|
||||
if (!isObject(input)) {
|
||||
payload.issues.push({
|
||||
expected: "object",
|
||||
code: "invalid_type",
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
payload.value = {};
|
||||
const proms = [];
|
||||
const shape = value.shape;
|
||||
for (const key of value.keys) {
|
||||
const el = shape[key];
|
||||
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
|
||||
}
|
||||
else {
|
||||
handlePropertyResult(r, payload, key, input);
|
||||
}
|
||||
}
|
||||
if (!catchall) {
|
||||
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
||||
}
|
||||
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
||||
};
|
||||
});
|
||||
exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
// requires cast because technically $ZodObject doesn't extend
|
||||
exports.$ZodObject.init(inst, def);
|
||||
const superParse = inst._zod.parse;
|
||||
const _normalized = util.cached(() => normalizeDef(def));
|
||||
const generateFastpass = (shape) => {
|
||||
const doc = new doc_js_1.Doc(["shape", "payload", "ctx"]);
|
||||
const normalized = _normalized.value;
|
||||
@@ -876,29 +763,44 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
ids[key] = `key_${counter++}`;
|
||||
}
|
||||
// A: preserve key order {
|
||||
doc.write(`const newResult = {};`);
|
||||
doc.write(`const newResult = {}`);
|
||||
for (const key of normalized.keys) {
|
||||
const id = ids[key];
|
||||
const k = util.esc(key);
|
||||
doc.write(`const ${id} = ${parseStr(key)};`);
|
||||
doc.write(`
|
||||
if (normalized.optionalKeys.has(key)) {
|
||||
const id = ids[key];
|
||||
doc.write(`const ${id} = ${parseStr(key)};`);
|
||||
const k = util.esc(key);
|
||||
doc.write(`
|
||||
if (${id}.issues.length) {
|
||||
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
||||
...iss,
|
||||
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
||||
})));
|
||||
}
|
||||
|
||||
|
||||
if (${id}.value === undefined) {
|
||||
if (${k} in input) {
|
||||
newResult[${k}] = undefined;
|
||||
if (input[${k}] === undefined) {
|
||||
if (${k} in input) {
|
||||
newResult[${k}] = undefined;
|
||||
}
|
||||
} else {
|
||||
payload.issues = payload.issues.concat(
|
||||
${id}.issues.map((iss) => ({
|
||||
...iss,
|
||||
path: iss.path ? [${k}, ...iss.path] : [${k}],
|
||||
}))
|
||||
);
|
||||
}
|
||||
} else if (${id}.value === undefined) {
|
||||
if (${k} in input) newResult[${k}] = undefined;
|
||||
} else {
|
||||
newResult[${k}] = ${id}.value;
|
||||
}
|
||||
|
||||
`);
|
||||
`);
|
||||
}
|
||||
else {
|
||||
const id = ids[key];
|
||||
// const id = ids[key];
|
||||
doc.write(`const ${id} = ${parseStr(key)};`);
|
||||
doc.write(`
|
||||
if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
||||
...iss,
|
||||
path: iss.path ? [${util.esc(key)}, ...iss.path] : [${util.esc(key)}]
|
||||
})));`);
|
||||
doc.write(`newResult[${util.esc(key)}] = ${id}.value`);
|
||||
}
|
||||
}
|
||||
doc.write(`payload.value = newResult;`);
|
||||
doc.write(`return payload;`);
|
||||
@@ -924,16 +826,80 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
const proms = [];
|
||||
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
|
||||
// always synchronous
|
||||
if (!fastpass)
|
||||
fastpass = generateFastpass(def.shape);
|
||||
payload = fastpass(payload, ctx);
|
||||
if (!catchall)
|
||||
return payload;
|
||||
return handleCatchall([], input, payload, ctx, value, inst);
|
||||
}
|
||||
return superParse(payload, ctx);
|
||||
else {
|
||||
payload.value = {};
|
||||
const shape = value.shape;
|
||||
for (const key of value.keys) {
|
||||
const el = shape[key];
|
||||
// do not add omitted optional keys
|
||||
// if (!(key in input)) {
|
||||
// if (optionalKeys.has(key)) continue;
|
||||
// payload.issues.push({
|
||||
// code: "invalid_type",
|
||||
// path: [key],
|
||||
// expected: "nonoptional",
|
||||
// note: `Missing required key: "${key}"`,
|
||||
// input,
|
||||
// inst,
|
||||
// });
|
||||
// }
|
||||
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
||||
const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)));
|
||||
}
|
||||
else if (isOptional) {
|
||||
handleOptionalObjectResult(r, payload, key, input);
|
||||
}
|
||||
else {
|
||||
handleObjectResult(r, payload, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!catchall) {
|
||||
// return payload;
|
||||
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
||||
}
|
||||
const unrecognized = [];
|
||||
// iterate over input keys
|
||||
const keySet = value.keySet;
|
||||
const _catchall = catchall._zod;
|
||||
const t = _catchall.def.type;
|
||||
for (const key of Object.keys(input)) {
|
||||
if (keySet.has(key))
|
||||
continue;
|
||||
if (t === "never") {
|
||||
unrecognized.push(key);
|
||||
continue;
|
||||
}
|
||||
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => handleObjectResult(r, payload, key)));
|
||||
}
|
||||
else {
|
||||
handleObjectResult(r, payload, key);
|
||||
}
|
||||
}
|
||||
if (unrecognized.length) {
|
||||
payload.issues.push({
|
||||
code: "unrecognized_keys",
|
||||
keys: unrecognized,
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
}
|
||||
if (!proms.length)
|
||||
return payload;
|
||||
return Promise.all(proms).then(() => {
|
||||
return payload;
|
||||
});
|
||||
};
|
||||
});
|
||||
function handleUnionResults(results, final, inst, ctx) {
|
||||
@@ -943,11 +909,6 @@ function handleUnionResults(results, final, inst, ctx) {
|
||||
return final;
|
||||
}
|
||||
}
|
||||
const nonaborted = results.filter((r) => !util.aborted(r));
|
||||
if (nonaborted.length === 1) {
|
||||
final.value = nonaborted[0].value;
|
||||
return nonaborted[0];
|
||||
}
|
||||
final.issues.push({
|
||||
code: "invalid_union",
|
||||
input: final.value,
|
||||
@@ -973,12 +934,7 @@ exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const single = def.options.length === 1;
|
||||
const first = def.options[0]._zod.run;
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (single) {
|
||||
return first(payload, ctx);
|
||||
}
|
||||
let async = false;
|
||||
const results = [];
|
||||
for (const option of def.options) {
|
||||
@@ -1028,7 +984,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
||||
const opts = def.options;
|
||||
const map = new Map();
|
||||
for (const o of opts) {
|
||||
const values = o._zod.propValues?.[def.discriminator];
|
||||
const values = o._zod.propValues[def.discriminator];
|
||||
if (!values || values.size === 0)
|
||||
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
||||
for (const v of values) {
|
||||
@@ -1063,7 +1019,6 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
||||
code: "invalid_union",
|
||||
errors: [],
|
||||
note: "No matching discriminator",
|
||||
discriminator: def.discriminator,
|
||||
input,
|
||||
path: [def.discriminator],
|
||||
inst,
|
||||
@@ -1151,6 +1106,7 @@ function handleIntersectionResults(result, left, right) {
|
||||
exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
const items = def.items;
|
||||
const optStart = items.length - [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
const input = payload.value;
|
||||
if (!Array.isArray(input)) {
|
||||
@@ -1164,17 +1120,15 @@ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
|
||||
}
|
||||
payload.value = [];
|
||||
const proms = [];
|
||||
const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
|
||||
const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
|
||||
if (!def.rest) {
|
||||
const tooBig = input.length > items.length;
|
||||
const tooSmall = input.length < optStart - 1;
|
||||
if (tooBig || tooSmall) {
|
||||
payload.issues.push({
|
||||
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
||||
input,
|
||||
inst,
|
||||
origin: "array",
|
||||
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
@@ -1237,13 +1191,11 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
|
||||
return payload;
|
||||
}
|
||||
const proms = [];
|
||||
const values = def.keyType._zod.values;
|
||||
if (values) {
|
||||
if (def.keyType._zod.values) {
|
||||
const values = def.keyType._zod.values;
|
||||
payload.value = {};
|
||||
const recordKeys = new Set();
|
||||
for (const key of values) {
|
||||
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
||||
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
||||
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
||||
if (result instanceof Promise) {
|
||||
proms.push(result.then((result) => {
|
||||
@@ -1263,7 +1215,7 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
|
||||
}
|
||||
let unrecognized;
|
||||
for (const key in input) {
|
||||
if (!recordKeys.has(key)) {
|
||||
if (!values.has(key)) {
|
||||
unrecognized = unrecognized ?? [];
|
||||
unrecognized.push(key);
|
||||
}
|
||||
@@ -1288,8 +1240,8 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
|
||||
}
|
||||
if (keyResult.issues.length) {
|
||||
payload.issues.push({
|
||||
code: "invalid_key",
|
||||
origin: "record",
|
||||
code: "invalid_key",
|
||||
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
||||
input: key,
|
||||
path: [key],
|
||||
@@ -1360,8 +1312,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
|
||||
}
|
||||
else {
|
||||
final.issues.push({
|
||||
code: "invalid_key",
|
||||
origin: "map",
|
||||
code: "invalid_key",
|
||||
input,
|
||||
inst,
|
||||
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
||||
@@ -1422,15 +1374,14 @@ function handleSetResult(result, final) {
|
||||
exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
const values = util.getEnumValues(def.entries);
|
||||
const valuesSet = new Set(values);
|
||||
inst._zod.values = valuesSet;
|
||||
inst._zod.values = new Set(values);
|
||||
inst._zod.pattern = new RegExp(`^(${values
|
||||
.filter((k) => util.propertyKeyTypes.has(typeof k))
|
||||
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
|
||||
.join("|")})$`);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
if (valuesSet.has(input)) {
|
||||
if (inst._zod.values.has(input)) {
|
||||
return payload;
|
||||
}
|
||||
payload.issues.push({
|
||||
@@ -1444,17 +1395,13 @@ exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
|
||||
});
|
||||
exports.$ZodLiteral = core.$constructor("$ZodLiteral", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
if (def.values.length === 0) {
|
||||
throw new Error("Cannot create literal schema with no valid values");
|
||||
}
|
||||
const values = new Set(def.values);
|
||||
inst._zod.values = values;
|
||||
inst._zod.values = new Set(def.values);
|
||||
inst._zod.pattern = new RegExp(`^(${def.values
|
||||
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
|
||||
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
|
||||
.join("|")})$`);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
if (values.has(input)) {
|
||||
if (inst._zod.values.has(input)) {
|
||||
return payload;
|
||||
}
|
||||
payload.issues.push({
|
||||
@@ -1470,7 +1417,6 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
// @ts-ignore
|
||||
if (input instanceof File)
|
||||
return payload;
|
||||
payload.issues.push({
|
||||
@@ -1484,12 +1430,9 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
|
||||
});
|
||||
exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
throw new core.$ZodEncodeError(inst.constructor.name);
|
||||
}
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const _out = def.transform(payload.value, payload);
|
||||
if (ctx.async) {
|
||||
if (_ctx.async) {
|
||||
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
||||
return output.then((output) => {
|
||||
payload.value = output;
|
||||
@@ -1503,12 +1446,6 @@ exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
function handleOptionalResult(result, input) {
|
||||
if (result.issues.length && input === undefined) {
|
||||
return { issues: [], value: undefined };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.optin = "optional";
|
||||
@@ -1522,10 +1459,7 @@ exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
|
||||
});
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (def.innerType._zod.optin === "optional") {
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise)
|
||||
return result.then((r) => handleOptionalResult(r, payload.value));
|
||||
return handleOptionalResult(result, payload.value);
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
if (payload.value === undefined) {
|
||||
return payload;
|
||||
@@ -1545,7 +1479,6 @@ exports.$ZodNullable = core.$constructor("$ZodNullable", (inst, def) => {
|
||||
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
|
||||
});
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
// Forward direction (decode): allow null to pass through
|
||||
if (payload.value === null)
|
||||
return payload;
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
@@ -1557,18 +1490,13 @@ exports.$ZodDefault = core.$constructor("$ZodDefault", (inst, def) => {
|
||||
inst._zod.optin = "optional";
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
// Forward direction (decode): apply defaults for undefined input
|
||||
if (payload.value === undefined) {
|
||||
payload.value = def.defaultValue;
|
||||
/**
|
||||
* $ZodDefault returns the default value immediately in forward direction.
|
||||
* $ZodDefault always returns the default value immediately.
|
||||
* It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
|
||||
return payload;
|
||||
}
|
||||
// Forward direction: continue with default handling
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((result) => handleDefaultResult(result, def));
|
||||
@@ -1587,10 +1515,6 @@ exports.$ZodPrefault = core.$constructor("$ZodPrefault", (inst, def) => {
|
||||
inst._zod.optin = "optional";
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
// Forward direction (decode): apply prefault for undefined input
|
||||
if (payload.value === undefined) {
|
||||
payload.value = def.defaultValue;
|
||||
}
|
||||
@@ -1625,9 +1549,6 @@ function handleNonOptionalResult(payload, inst) {
|
||||
exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
throw new core.$ZodEncodeError("ZodSuccess");
|
||||
}
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((result) => {
|
||||
@@ -1641,14 +1562,10 @@ exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
|
||||
});
|
||||
exports.$ZodCatch = core.$constructor("$ZodCatch", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
||||
inst._zod.optin = "optional";
|
||||
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
// Forward direction (decode): apply catch logic
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((result) => {
|
||||
@@ -1700,94 +1617,27 @@ exports.$ZodPipe = core.$constructor("$ZodPipe", (inst, def) => {
|
||||
util.defineLazy(inst._zod, "values", () => def.in._zod.values);
|
||||
util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
||||
util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
const right = def.out._zod.run(payload, ctx);
|
||||
if (right instanceof Promise) {
|
||||
return right.then((right) => handlePipeResult(right, def.in, ctx));
|
||||
}
|
||||
return handlePipeResult(right, def.in, ctx);
|
||||
}
|
||||
const left = def.in._zod.run(payload, ctx);
|
||||
if (left instanceof Promise) {
|
||||
return left.then((left) => handlePipeResult(left, def.out, ctx));
|
||||
return left.then((left) => handlePipeResult(left, def, ctx));
|
||||
}
|
||||
return handlePipeResult(left, def.out, ctx);
|
||||
return handlePipeResult(left, def, ctx);
|
||||
};
|
||||
});
|
||||
function handlePipeResult(left, next, ctx) {
|
||||
if (left.issues.length) {
|
||||
// prevent further checks
|
||||
left.aborted = true;
|
||||
function handlePipeResult(left, def, ctx) {
|
||||
if (util.aborted(left)) {
|
||||
return left;
|
||||
}
|
||||
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
||||
}
|
||||
exports.$ZodCodec = core.$constructor("$ZodCodec", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
util.defineLazy(inst._zod, "values", () => def.in._zod.values);
|
||||
util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
||||
util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
const direction = ctx.direction || "forward";
|
||||
if (direction === "forward") {
|
||||
const left = def.in._zod.run(payload, ctx);
|
||||
if (left instanceof Promise) {
|
||||
return left.then((left) => handleCodecAResult(left, def, ctx));
|
||||
}
|
||||
return handleCodecAResult(left, def, ctx);
|
||||
}
|
||||
else {
|
||||
const right = def.out._zod.run(payload, ctx);
|
||||
if (right instanceof Promise) {
|
||||
return right.then((right) => handleCodecAResult(right, def, ctx));
|
||||
}
|
||||
return handleCodecAResult(right, def, ctx);
|
||||
}
|
||||
};
|
||||
});
|
||||
function handleCodecAResult(result, def, ctx) {
|
||||
if (result.issues.length) {
|
||||
// prevent further checks
|
||||
result.aborted = true;
|
||||
return result;
|
||||
}
|
||||
const direction = ctx.direction || "forward";
|
||||
if (direction === "forward") {
|
||||
const transformed = def.transform(result.value, result);
|
||||
if (transformed instanceof Promise) {
|
||||
return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
|
||||
}
|
||||
return handleCodecTxResult(result, transformed, def.out, ctx);
|
||||
}
|
||||
else {
|
||||
const transformed = def.reverseTransform(result.value, result);
|
||||
if (transformed instanceof Promise) {
|
||||
return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
|
||||
}
|
||||
return handleCodecTxResult(result, transformed, def.in, ctx);
|
||||
}
|
||||
}
|
||||
function handleCodecTxResult(left, value, nextSchema, ctx) {
|
||||
// Check if transform added any issues
|
||||
if (left.issues.length) {
|
||||
left.aborted = true;
|
||||
return left;
|
||||
}
|
||||
return nextSchema._zod.run({ value, issues: left.issues }, ctx);
|
||||
return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
|
||||
}
|
||||
exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
||||
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then(handleReadonlyResult);
|
||||
@@ -1803,8 +1653,7 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
|
||||
exports.$ZodType.init(inst, def);
|
||||
const regexParts = [];
|
||||
for (const part of def.parts) {
|
||||
if (typeof part === "object" && part !== null) {
|
||||
// is Zod schema
|
||||
if (part instanceof exports.$ZodType) {
|
||||
if (!part._zod.pattern) {
|
||||
// if (!source)
|
||||
throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
|
||||
@@ -1840,7 +1689,7 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
|
||||
input: payload.value,
|
||||
inst,
|
||||
code: "invalid_format",
|
||||
format: def.format ?? "template_literal",
|
||||
format: "template_literal",
|
||||
pattern: inst._zod.pattern.source,
|
||||
});
|
||||
return payload;
|
||||
@@ -1848,85 +1697,6 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
exports.$ZodFunction = core.$constructor("$ZodFunction", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._def = def;
|
||||
inst._zod.def = def;
|
||||
inst.implement = (func) => {
|
||||
if (typeof func !== "function") {
|
||||
throw new Error("implement() must be called with a function");
|
||||
}
|
||||
return function (...args) {
|
||||
const parsedArgs = inst._def.input ? (0, parse_js_1.parse)(inst._def.input, args) : args;
|
||||
const result = Reflect.apply(func, this, parsedArgs);
|
||||
if (inst._def.output) {
|
||||
return (0, parse_js_1.parse)(inst._def.output, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
inst.implementAsync = (func) => {
|
||||
if (typeof func !== "function") {
|
||||
throw new Error("implementAsync() must be called with a function");
|
||||
}
|
||||
return async function (...args) {
|
||||
const parsedArgs = inst._def.input ? await (0, parse_js_1.parseAsync)(inst._def.input, args) : args;
|
||||
const result = await Reflect.apply(func, this, parsedArgs);
|
||||
if (inst._def.output) {
|
||||
return await (0, parse_js_1.parseAsync)(inst._def.output, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
if (typeof payload.value !== "function") {
|
||||
payload.issues.push({
|
||||
code: "invalid_type",
|
||||
expected: "function",
|
||||
input: payload.value,
|
||||
inst,
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
// Check if output is a promise type to determine if we should use async implementation
|
||||
const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
|
||||
if (hasPromiseOutput) {
|
||||
payload.value = inst.implementAsync(payload.value);
|
||||
}
|
||||
else {
|
||||
payload.value = inst.implement(payload.value);
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
inst.input = (...args) => {
|
||||
const F = inst.constructor;
|
||||
if (Array.isArray(args[0])) {
|
||||
return new F({
|
||||
type: "function",
|
||||
input: new exports.$ZodTuple({
|
||||
type: "tuple",
|
||||
items: args[0],
|
||||
rest: args[1],
|
||||
}),
|
||||
output: inst._def.output,
|
||||
});
|
||||
}
|
||||
return new F({
|
||||
type: "function",
|
||||
input: args[0],
|
||||
output: inst._def.output,
|
||||
});
|
||||
};
|
||||
inst.output = (output) => {
|
||||
const F = inst.constructor;
|
||||
return new F({
|
||||
type: "function",
|
||||
input: inst._def.input,
|
||||
output,
|
||||
});
|
||||
};
|
||||
return inst;
|
||||
});
|
||||
exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
@@ -1935,18 +1705,11 @@ exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
|
||||
});
|
||||
exports.$ZodLazy = core.$constructor("$ZodLazy", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
// let _innerType!: any;
|
||||
// util.defineLazy(def, "getter", () => {
|
||||
// if (!_innerType) {
|
||||
// _innerType = def.getter();
|
||||
// }
|
||||
// return () => _innerType;
|
||||
// });
|
||||
util.defineLazy(inst._zod, "innerType", () => def.getter());
|
||||
util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
|
||||
util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
|
||||
util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
|
||||
util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
|
||||
util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
|
||||
util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
|
||||
util.defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
const inner = inst._zod.innerType;
|
||||
return inner._zod.run(payload, ctx);
|
||||
|
||||
+17
-99
@@ -15,18 +15,14 @@ export interface ParseContext<T extends errors.$ZodIssueBase = never> {
|
||||
/** @internal */
|
||||
export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> extends ParseContext<T> {
|
||||
readonly async?: boolean | undefined;
|
||||
readonly direction?: "forward" | "backward";
|
||||
readonly skipChecks?: boolean;
|
||||
}
|
||||
export interface ParsePayload<T = unknown> {
|
||||
value: T;
|
||||
issues: errors.$ZodRawIssue[];
|
||||
/** A may to mark a whole payload as aborted. Used in codecs/pipes. */
|
||||
aborted?: boolean;
|
||||
}
|
||||
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
||||
export interface $ZodTypeDef {
|
||||
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "function" | "custom";
|
||||
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "custom";
|
||||
error?: errors.$ZodErrorMap<never> | undefined;
|
||||
checks?: checks.$ZodCheck<never>[];
|
||||
}
|
||||
@@ -58,7 +54,6 @@ export interface _$ZodTypeInternals {
|
||||
* Todo: unions?
|
||||
*/
|
||||
values?: util.PrimitiveSet | undefined;
|
||||
/** Default value bubbled up from */
|
||||
/** @internal A set of literal discriminators used for the fast path in discriminated unions. */
|
||||
propValues?: util.PropValues | undefined;
|
||||
/** @internal This flag indicates that a schema validation can be represented with a regular expression. Used to determine allowable schemas in z.templateLiteral(). */
|
||||
@@ -153,7 +148,6 @@ export declare const $ZodEmail: core.$constructor<$ZodEmail>;
|
||||
export interface $ZodURLDef extends $ZodStringFormatDef<"url"> {
|
||||
hostname?: RegExp | undefined;
|
||||
protocol?: RegExp | undefined;
|
||||
normalize?: boolean | undefined;
|
||||
}
|
||||
export interface $ZodURLInternals extends $ZodStringFormatInternals<"url"> {
|
||||
def: $ZodURLDef;
|
||||
@@ -276,16 +270,6 @@ export interface $ZodIPv6 extends $ZodType {
|
||||
_zod: $ZodIPv6Internals;
|
||||
}
|
||||
export declare const $ZodIPv6: core.$constructor<$ZodIPv6>;
|
||||
export interface $ZodMACDef extends $ZodStringFormatDef<"mac"> {
|
||||
delimiter?: string;
|
||||
}
|
||||
export interface $ZodMACInternals extends $ZodStringFormatInternals<"mac"> {
|
||||
def: $ZodMACDef;
|
||||
}
|
||||
export interface $ZodMAC extends $ZodType {
|
||||
_zod: $ZodMACInternals;
|
||||
}
|
||||
export declare const $ZodMAC: core.$constructor<$ZodMAC>;
|
||||
export interface $ZodCIDRv4Def extends $ZodStringFormatDef<"cidrv4"> {
|
||||
version?: "v4";
|
||||
}
|
||||
@@ -594,15 +578,13 @@ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $Zod
|
||||
}
|
||||
export interface $ZodObjectInternals<
|
||||
/** @ts-ignore Cast variance */
|
||||
out Shape extends $ZodShape = $ZodShape, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
|
||||
out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
|
||||
def: $ZodObjectDef<Shape>;
|
||||
config: Config;
|
||||
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueUnrecognizedKeys;
|
||||
propValues: util.PropValues;
|
||||
output: $InferObjectOutput<Shape, Config["out"]>;
|
||||
input: $InferObjectInput<Shape, Config["in"]>;
|
||||
optin?: "optional" | undefined;
|
||||
optout?: "optional" | undefined;
|
||||
}
|
||||
export type $ZodLooseShape = Record<string, any>;
|
||||
export interface $ZodObject<
|
||||
@@ -611,7 +593,6 @@ out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>, out Params extends
|
||||
"~standard": $ZodStandardSchema<this>;
|
||||
}
|
||||
export declare const $ZodObject: core.$constructor<$ZodObject>;
|
||||
export declare const $ZodObjectJIT: core.$constructor<$ZodObject>;
|
||||
export type $InferUnionOutput<T extends SomeType> = T extends any ? core.output<T> : never;
|
||||
export type $InferUnionInput<T extends SomeType> = T extends any ? core.input<T> : never;
|
||||
export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeDef {
|
||||
@@ -634,16 +615,16 @@ export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]>
|
||||
_zod: $ZodUnionInternals<T>;
|
||||
}
|
||||
export declare const $ZodUnion: core.$constructor<$ZodUnion>;
|
||||
export interface $ZodDiscriminatedUnionDef<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodUnionDef<Options> {
|
||||
discriminator: Disc;
|
||||
export interface $ZodDiscriminatedUnionDef<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodUnionDef<Options> {
|
||||
discriminator: string;
|
||||
unionFallback?: boolean;
|
||||
}
|
||||
export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodUnionInternals<Options> {
|
||||
def: $ZodDiscriminatedUnionDef<Options, Disc>;
|
||||
export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodUnionInternals<Options> {
|
||||
def: $ZodDiscriminatedUnionDef<Options>;
|
||||
propValues: util.PropValues;
|
||||
}
|
||||
export interface $ZodDiscriminatedUnion<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodType {
|
||||
_zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
|
||||
export interface $ZodDiscriminatedUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType {
|
||||
_zod: $ZodDiscriminatedUnionInternals<T>;
|
||||
}
|
||||
export declare const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion>;
|
||||
export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right extends SomeType = $ZodType> extends $ZodTypeDef {
|
||||
@@ -651,13 +632,11 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
||||
left: Left;
|
||||
right: Right;
|
||||
}
|
||||
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends _$ZodTypeInternals {
|
||||
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
|
||||
def: $ZodIntersectionDef<A, B>;
|
||||
isst: never;
|
||||
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
||||
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
||||
output: core.output<A> & core.output<B>;
|
||||
input: core.input<A> & core.input<B>;
|
||||
}
|
||||
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
||||
_zod: $ZodIntersectionInternals<A, B>;
|
||||
@@ -690,11 +669,9 @@ type TupleOutputTypeWithOptionals<T extends util.TupleItems> = T extends readonl
|
||||
...infer Prefix extends SomeType[],
|
||||
infer Tail extends SomeType
|
||||
] ? Tail["_zod"]["optout"] extends "optional" ? [...TupleOutputTypeWithOptionals<Prefix>, core.output<Tail>?] : TupleOutputTypeNoOptionals<T> : [];
|
||||
export interface $ZodTupleInternals<T extends util.TupleItems = readonly $ZodType[], Rest extends SomeType | null = $ZodType | null> extends _$ZodTypeInternals {
|
||||
export interface $ZodTupleInternals<T extends util.TupleItems = readonly $ZodType[], Rest extends SomeType | null = $ZodType | null> extends $ZodTypeInternals<$InferTupleOutputType<T, Rest>, $InferTupleInputType<T, Rest>> {
|
||||
def: $ZodTupleDef<T, Rest>;
|
||||
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueTooBig<unknown[]> | errors.$ZodIssueTooSmall<unknown[]>;
|
||||
output: $InferTupleOutputType<T, Rest>;
|
||||
input: $InferTupleInputType<T, Rest>;
|
||||
}
|
||||
export interface $ZodTuple<T extends util.TupleItems = readonly $ZodType[], Rest extends SomeType | null = $ZodType | null> extends $ZodType {
|
||||
_zod: $ZodTupleInternals<T, Rest>;
|
||||
@@ -784,13 +761,9 @@ export interface $ZodLiteral<T extends util.Literal = util.Literal> extends $Zod
|
||||
_zod: $ZodLiteralInternals<T>;
|
||||
}
|
||||
export declare const $ZodLiteral: core.$constructor<$ZodLiteral>;
|
||||
type _File = typeof globalThis extends {
|
||||
File: infer F extends new (...args: any[]) => any;
|
||||
} ? InstanceType<F> : {};
|
||||
/** Do not reference this directly. */
|
||||
export interface File extends _File {
|
||||
readonly type: string;
|
||||
readonly size: number;
|
||||
declare global {
|
||||
interface File {
|
||||
}
|
||||
}
|
||||
export interface $ZodFileDef extends $ZodTypeDef {
|
||||
type: "file";
|
||||
@@ -928,7 +901,7 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
||||
innerType: T;
|
||||
catchValue: (ctx: $ZodCatchCtx) => unknown;
|
||||
}
|
||||
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T>> {
|
||||
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T> | util.Whatever> {
|
||||
def: $ZodCatchDef<T>;
|
||||
optin: T["_zod"]["optin"];
|
||||
optout: T["_zod"]["optout"];
|
||||
@@ -954,10 +927,6 @@ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType =
|
||||
type: "pipe";
|
||||
in: A;
|
||||
out: B;
|
||||
/** Only defined inside $ZodCodec instances. */
|
||||
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
||||
/** Only defined inside $ZodCodec instances. */
|
||||
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
||||
}
|
||||
export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
||||
def: $ZodPipeDef<A, B>;
|
||||
@@ -965,28 +934,11 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
|
||||
values: A["_zod"]["values"];
|
||||
optin: A["_zod"]["optin"];
|
||||
optout: B["_zod"]["optout"];
|
||||
propValues: A["_zod"]["propValues"];
|
||||
}
|
||||
export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
||||
_zod: $ZodPipeInternals<A, B>;
|
||||
}
|
||||
export declare const $ZodPipe: core.$constructor<$ZodPipe>;
|
||||
export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
|
||||
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
||||
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
||||
}
|
||||
export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
||||
def: $ZodCodecDef<A, B>;
|
||||
isst: never;
|
||||
values: A["_zod"]["values"];
|
||||
optin: A["_zod"]["optin"];
|
||||
optout: B["_zod"]["optout"];
|
||||
propValues: A["_zod"]["propValues"];
|
||||
}
|
||||
export interface $ZodCodec<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
||||
_zod: $ZodCodecInternals<A, B>;
|
||||
}
|
||||
export declare const $ZodCodec: core.$constructor<$ZodCodec>;
|
||||
export interface $ZodReadonlyDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
||||
type: "readonly";
|
||||
innerType: T;
|
||||
@@ -1006,7 +958,6 @@ export declare const $ZodReadonly: core.$constructor<$ZodReadonly>;
|
||||
export interface $ZodTemplateLiteralDef extends $ZodTypeDef {
|
||||
type: "template_literal";
|
||||
parts: $ZodTemplateLiteralPart[];
|
||||
format?: string | undefined;
|
||||
}
|
||||
export interface $ZodTemplateLiteralInternals<Template extends string = string> extends $ZodTypeInternals<Template, Template> {
|
||||
pattern: RegExp;
|
||||
@@ -1036,44 +987,11 @@ export type ConvertPartsToStringTuple<Parts extends $ZodTemplateLiteralPart[]> =
|
||||
export type ToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = ConcatenateTupleOfStrings<ConvertPartsToStringTuple<Parts>>;
|
||||
export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [] extends Parts ? `` : Parts extends [...infer Rest, infer Last extends $ZodTemplateLiteralPart] ? Rest extends $ZodTemplateLiteralPart[] ? AppendToTemplateLiteral<$PartsToTemplateLiteral<Rest>, Last> : never : never;
|
||||
export declare const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral>;
|
||||
export type $ZodFunctionArgs = $ZodType<unknown[], unknown[]>;
|
||||
export type $ZodFunctionIn = $ZodFunctionArgs;
|
||||
export type $ZodFunctionOut = $ZodType;
|
||||
export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => core.input<Returns>;
|
||||
export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => util.MaybeAsync<core.input<Returns>>;
|
||||
export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => core.output<Returns>;
|
||||
export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => util.MaybeAsync<core.output<Returns>>;
|
||||
export interface $ZodFunctionDef<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends $ZodFunctionOut = $ZodFunctionOut> extends $ZodTypeDef {
|
||||
type: "function";
|
||||
input: In;
|
||||
output: Out;
|
||||
}
|
||||
export interface $ZodFunctionInternals<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> extends $ZodTypeInternals<$InferOuterFunctionType<Args, Returns>, $InferInnerFunctionType<Args, Returns>> {
|
||||
def: $ZodFunctionDef<Args, Returns>;
|
||||
isst: errors.$ZodIssueInvalidType;
|
||||
}
|
||||
export interface $ZodFunction<Args extends $ZodFunctionIn = $ZodFunctionIn, Returns extends $ZodFunctionOut = $ZodFunctionOut> extends $ZodType<any, any, $ZodFunctionInternals<Args, Returns>> {
|
||||
/** @deprecated */
|
||||
_def: $ZodFunctionDef<Args, Returns>;
|
||||
_input: $InferInnerFunctionType<Args, Returns>;
|
||||
_output: $InferOuterFunctionType<Args, Returns>;
|
||||
implement<F extends $InferInnerFunctionType<Args, Returns>>(func: F): (...args: Parameters<this["_output"]>) => ReturnType<F> extends ReturnType<this["_output"]> ? ReturnType<F> : ReturnType<this["_output"]>;
|
||||
implementAsync<F extends $InferInnerFunctionTypeAsync<Args, Returns>>(func: F): F extends $InferOuterFunctionTypeAsync<Args, Returns> ? F : $InferOuterFunctionTypeAsync<Args, Returns>;
|
||||
input<const Items extends util.TupleItems, const Rest extends $ZodFunctionOut = $ZodFunctionOut>(args: Items, rest?: Rest): $ZodFunction<$ZodTuple<Items, Rest>, Returns>;
|
||||
input<NewArgs extends $ZodFunctionIn>(args: NewArgs): $ZodFunction<NewArgs, Returns>;
|
||||
input(...args: any[]): $ZodFunction<any, Returns>;
|
||||
output<NewReturns extends $ZodType>(output: NewReturns): $ZodFunction<Args, NewReturns>;
|
||||
}
|
||||
export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends $ZodType> {
|
||||
input?: I;
|
||||
output?: O;
|
||||
}
|
||||
export declare const $ZodFunction: core.$constructor<$ZodFunction>;
|
||||
export interface $ZodPromiseDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
||||
type: "promise";
|
||||
innerType: T;
|
||||
}
|
||||
export interface $ZodPromiseInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Promise<core.output<T>>, util.MaybeAsync<core.input<T>>> {
|
||||
export interface $ZodPromiseInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, util.MaybeAsync<core.input<T>>> {
|
||||
def: $ZodPromiseDef<T>;
|
||||
isst: never;
|
||||
}
|
||||
@@ -1119,5 +1037,5 @@ export interface $ZodCustom<O = unknown, I = unknown> extends $ZodType {
|
||||
_zod: $ZodCustomInternals<O, I>;
|
||||
}
|
||||
export declare const $ZodCustom: core.$constructor<$ZodCustom>;
|
||||
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodFunction | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
||||
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodMAC | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodJWT | $ZodCustomStringFormat<"hex"> | $ZodCustomStringFormat<util.HashFormat> | $ZodCustomStringFormat<"hostname">;
|
||||
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
||||
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodJWT;
|
||||
|
||||
+17
-99
@@ -15,18 +15,14 @@ export interface ParseContext<T extends errors.$ZodIssueBase = never> {
|
||||
/** @internal */
|
||||
export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> extends ParseContext<T> {
|
||||
readonly async?: boolean | undefined;
|
||||
readonly direction?: "forward" | "backward";
|
||||
readonly skipChecks?: boolean;
|
||||
}
|
||||
export interface ParsePayload<T = unknown> {
|
||||
value: T;
|
||||
issues: errors.$ZodRawIssue[];
|
||||
/** A may to mark a whole payload as aborted. Used in codecs/pipes. */
|
||||
aborted?: boolean;
|
||||
}
|
||||
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
||||
export interface $ZodTypeDef {
|
||||
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "function" | "custom";
|
||||
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "custom";
|
||||
error?: errors.$ZodErrorMap<never> | undefined;
|
||||
checks?: checks.$ZodCheck<never>[];
|
||||
}
|
||||
@@ -58,7 +54,6 @@ export interface _$ZodTypeInternals {
|
||||
* Todo: unions?
|
||||
*/
|
||||
values?: util.PrimitiveSet | undefined;
|
||||
/** Default value bubbled up from */
|
||||
/** @internal A set of literal discriminators used for the fast path in discriminated unions. */
|
||||
propValues?: util.PropValues | undefined;
|
||||
/** @internal This flag indicates that a schema validation can be represented with a regular expression. Used to determine allowable schemas in z.templateLiteral(). */
|
||||
@@ -153,7 +148,6 @@ export declare const $ZodEmail: core.$constructor<$ZodEmail>;
|
||||
export interface $ZodURLDef extends $ZodStringFormatDef<"url"> {
|
||||
hostname?: RegExp | undefined;
|
||||
protocol?: RegExp | undefined;
|
||||
normalize?: boolean | undefined;
|
||||
}
|
||||
export interface $ZodURLInternals extends $ZodStringFormatInternals<"url"> {
|
||||
def: $ZodURLDef;
|
||||
@@ -276,16 +270,6 @@ export interface $ZodIPv6 extends $ZodType {
|
||||
_zod: $ZodIPv6Internals;
|
||||
}
|
||||
export declare const $ZodIPv6: core.$constructor<$ZodIPv6>;
|
||||
export interface $ZodMACDef extends $ZodStringFormatDef<"mac"> {
|
||||
delimiter?: string;
|
||||
}
|
||||
export interface $ZodMACInternals extends $ZodStringFormatInternals<"mac"> {
|
||||
def: $ZodMACDef;
|
||||
}
|
||||
export interface $ZodMAC extends $ZodType {
|
||||
_zod: $ZodMACInternals;
|
||||
}
|
||||
export declare const $ZodMAC: core.$constructor<$ZodMAC>;
|
||||
export interface $ZodCIDRv4Def extends $ZodStringFormatDef<"cidrv4"> {
|
||||
version?: "v4";
|
||||
}
|
||||
@@ -594,15 +578,13 @@ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $Zod
|
||||
}
|
||||
export interface $ZodObjectInternals<
|
||||
/** @ts-ignore Cast variance */
|
||||
out Shape extends $ZodShape = $ZodShape, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
|
||||
out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
|
||||
def: $ZodObjectDef<Shape>;
|
||||
config: Config;
|
||||
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueUnrecognizedKeys;
|
||||
propValues: util.PropValues;
|
||||
output: $InferObjectOutput<Shape, Config["out"]>;
|
||||
input: $InferObjectInput<Shape, Config["in"]>;
|
||||
optin?: "optional" | undefined;
|
||||
optout?: "optional" | undefined;
|
||||
}
|
||||
export type $ZodLooseShape = Record<string, any>;
|
||||
export interface $ZodObject<
|
||||
@@ -611,7 +593,6 @@ out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>, out Params extends
|
||||
"~standard": $ZodStandardSchema<this>;
|
||||
}
|
||||
export declare const $ZodObject: core.$constructor<$ZodObject>;
|
||||
export declare const $ZodObjectJIT: core.$constructor<$ZodObject>;
|
||||
export type $InferUnionOutput<T extends SomeType> = T extends any ? core.output<T> : never;
|
||||
export type $InferUnionInput<T extends SomeType> = T extends any ? core.input<T> : never;
|
||||
export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeDef {
|
||||
@@ -634,16 +615,16 @@ export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]>
|
||||
_zod: $ZodUnionInternals<T>;
|
||||
}
|
||||
export declare const $ZodUnion: core.$constructor<$ZodUnion>;
|
||||
export interface $ZodDiscriminatedUnionDef<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodUnionDef<Options> {
|
||||
discriminator: Disc;
|
||||
export interface $ZodDiscriminatedUnionDef<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodUnionDef<Options> {
|
||||
discriminator: string;
|
||||
unionFallback?: boolean;
|
||||
}
|
||||
export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodUnionInternals<Options> {
|
||||
def: $ZodDiscriminatedUnionDef<Options, Disc>;
|
||||
export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodUnionInternals<Options> {
|
||||
def: $ZodDiscriminatedUnionDef<Options>;
|
||||
propValues: util.PropValues;
|
||||
}
|
||||
export interface $ZodDiscriminatedUnion<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodType {
|
||||
_zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
|
||||
export interface $ZodDiscriminatedUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType {
|
||||
_zod: $ZodDiscriminatedUnionInternals<T>;
|
||||
}
|
||||
export declare const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion>;
|
||||
export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right extends SomeType = $ZodType> extends $ZodTypeDef {
|
||||
@@ -651,13 +632,11 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
||||
left: Left;
|
||||
right: Right;
|
||||
}
|
||||
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends _$ZodTypeInternals {
|
||||
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
|
||||
def: $ZodIntersectionDef<A, B>;
|
||||
isst: never;
|
||||
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
||||
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
||||
output: core.output<A> & core.output<B>;
|
||||
input: core.input<A> & core.input<B>;
|
||||
}
|
||||
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
||||
_zod: $ZodIntersectionInternals<A, B>;
|
||||
@@ -690,11 +669,9 @@ type TupleOutputTypeWithOptionals<T extends util.TupleItems> = T extends readonl
|
||||
...infer Prefix extends SomeType[],
|
||||
infer Tail extends SomeType
|
||||
] ? Tail["_zod"]["optout"] extends "optional" ? [...TupleOutputTypeWithOptionals<Prefix>, core.output<Tail>?] : TupleOutputTypeNoOptionals<T> : [];
|
||||
export interface $ZodTupleInternals<T extends util.TupleItems = readonly $ZodType[], Rest extends SomeType | null = $ZodType | null> extends _$ZodTypeInternals {
|
||||
export interface $ZodTupleInternals<T extends util.TupleItems = readonly $ZodType[], Rest extends SomeType | null = $ZodType | null> extends $ZodTypeInternals<$InferTupleOutputType<T, Rest>, $InferTupleInputType<T, Rest>> {
|
||||
def: $ZodTupleDef<T, Rest>;
|
||||
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueTooBig<unknown[]> | errors.$ZodIssueTooSmall<unknown[]>;
|
||||
output: $InferTupleOutputType<T, Rest>;
|
||||
input: $InferTupleInputType<T, Rest>;
|
||||
}
|
||||
export interface $ZodTuple<T extends util.TupleItems = readonly $ZodType[], Rest extends SomeType | null = $ZodType | null> extends $ZodType {
|
||||
_zod: $ZodTupleInternals<T, Rest>;
|
||||
@@ -784,13 +761,9 @@ export interface $ZodLiteral<T extends util.Literal = util.Literal> extends $Zod
|
||||
_zod: $ZodLiteralInternals<T>;
|
||||
}
|
||||
export declare const $ZodLiteral: core.$constructor<$ZodLiteral>;
|
||||
type _File = typeof globalThis extends {
|
||||
File: infer F extends new (...args: any[]) => any;
|
||||
} ? InstanceType<F> : {};
|
||||
/** Do not reference this directly. */
|
||||
export interface File extends _File {
|
||||
readonly type: string;
|
||||
readonly size: number;
|
||||
declare global {
|
||||
interface File {
|
||||
}
|
||||
}
|
||||
export interface $ZodFileDef extends $ZodTypeDef {
|
||||
type: "file";
|
||||
@@ -928,7 +901,7 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
||||
innerType: T;
|
||||
catchValue: (ctx: $ZodCatchCtx) => unknown;
|
||||
}
|
||||
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T>> {
|
||||
export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T> | util.Whatever> {
|
||||
def: $ZodCatchDef<T>;
|
||||
optin: T["_zod"]["optin"];
|
||||
optout: T["_zod"]["optout"];
|
||||
@@ -954,10 +927,6 @@ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType =
|
||||
type: "pipe";
|
||||
in: A;
|
||||
out: B;
|
||||
/** Only defined inside $ZodCodec instances. */
|
||||
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
||||
/** Only defined inside $ZodCodec instances. */
|
||||
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
||||
}
|
||||
export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
||||
def: $ZodPipeDef<A, B>;
|
||||
@@ -965,28 +934,11 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
|
||||
values: A["_zod"]["values"];
|
||||
optin: A["_zod"]["optin"];
|
||||
optout: B["_zod"]["optout"];
|
||||
propValues: A["_zod"]["propValues"];
|
||||
}
|
||||
export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
||||
_zod: $ZodPipeInternals<A, B>;
|
||||
}
|
||||
export declare const $ZodPipe: core.$constructor<$ZodPipe>;
|
||||
export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
|
||||
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
||||
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
||||
}
|
||||
export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
||||
def: $ZodCodecDef<A, B>;
|
||||
isst: never;
|
||||
values: A["_zod"]["values"];
|
||||
optin: A["_zod"]["optin"];
|
||||
optout: B["_zod"]["optout"];
|
||||
propValues: A["_zod"]["propValues"];
|
||||
}
|
||||
export interface $ZodCodec<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
||||
_zod: $ZodCodecInternals<A, B>;
|
||||
}
|
||||
export declare const $ZodCodec: core.$constructor<$ZodCodec>;
|
||||
export interface $ZodReadonlyDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
||||
type: "readonly";
|
||||
innerType: T;
|
||||
@@ -1006,7 +958,6 @@ export declare const $ZodReadonly: core.$constructor<$ZodReadonly>;
|
||||
export interface $ZodTemplateLiteralDef extends $ZodTypeDef {
|
||||
type: "template_literal";
|
||||
parts: $ZodTemplateLiteralPart[];
|
||||
format?: string | undefined;
|
||||
}
|
||||
export interface $ZodTemplateLiteralInternals<Template extends string = string> extends $ZodTypeInternals<Template, Template> {
|
||||
pattern: RegExp;
|
||||
@@ -1036,44 +987,11 @@ export type ConvertPartsToStringTuple<Parts extends $ZodTemplateLiteralPart[]> =
|
||||
export type ToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = ConcatenateTupleOfStrings<ConvertPartsToStringTuple<Parts>>;
|
||||
export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [] extends Parts ? `` : Parts extends [...infer Rest, infer Last extends $ZodTemplateLiteralPart] ? Rest extends $ZodTemplateLiteralPart[] ? AppendToTemplateLiteral<$PartsToTemplateLiteral<Rest>, Last> : never : never;
|
||||
export declare const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral>;
|
||||
export type $ZodFunctionArgs = $ZodType<unknown[], unknown[]>;
|
||||
export type $ZodFunctionIn = $ZodFunctionArgs;
|
||||
export type $ZodFunctionOut = $ZodType;
|
||||
export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => core.input<Returns>;
|
||||
export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => util.MaybeAsync<core.input<Returns>>;
|
||||
export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => core.output<Returns>;
|
||||
export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => util.MaybeAsync<core.output<Returns>>;
|
||||
export interface $ZodFunctionDef<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends $ZodFunctionOut = $ZodFunctionOut> extends $ZodTypeDef {
|
||||
type: "function";
|
||||
input: In;
|
||||
output: Out;
|
||||
}
|
||||
export interface $ZodFunctionInternals<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> extends $ZodTypeInternals<$InferOuterFunctionType<Args, Returns>, $InferInnerFunctionType<Args, Returns>> {
|
||||
def: $ZodFunctionDef<Args, Returns>;
|
||||
isst: errors.$ZodIssueInvalidType;
|
||||
}
|
||||
export interface $ZodFunction<Args extends $ZodFunctionIn = $ZodFunctionIn, Returns extends $ZodFunctionOut = $ZodFunctionOut> extends $ZodType<any, any, $ZodFunctionInternals<Args, Returns>> {
|
||||
/** @deprecated */
|
||||
_def: $ZodFunctionDef<Args, Returns>;
|
||||
_input: $InferInnerFunctionType<Args, Returns>;
|
||||
_output: $InferOuterFunctionType<Args, Returns>;
|
||||
implement<F extends $InferInnerFunctionType<Args, Returns>>(func: F): (...args: Parameters<this["_output"]>) => ReturnType<F> extends ReturnType<this["_output"]> ? ReturnType<F> : ReturnType<this["_output"]>;
|
||||
implementAsync<F extends $InferInnerFunctionTypeAsync<Args, Returns>>(func: F): F extends $InferOuterFunctionTypeAsync<Args, Returns> ? F : $InferOuterFunctionTypeAsync<Args, Returns>;
|
||||
input<const Items extends util.TupleItems, const Rest extends $ZodFunctionOut = $ZodFunctionOut>(args: Items, rest?: Rest): $ZodFunction<$ZodTuple<Items, Rest>, Returns>;
|
||||
input<NewArgs extends $ZodFunctionIn>(args: NewArgs): $ZodFunction<NewArgs, Returns>;
|
||||
input(...args: any[]): $ZodFunction<any, Returns>;
|
||||
output<NewReturns extends $ZodType>(output: NewReturns): $ZodFunction<Args, NewReturns>;
|
||||
}
|
||||
export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends $ZodType> {
|
||||
input?: I;
|
||||
output?: O;
|
||||
}
|
||||
export declare const $ZodFunction: core.$constructor<$ZodFunction>;
|
||||
export interface $ZodPromiseDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
||||
type: "promise";
|
||||
innerType: T;
|
||||
}
|
||||
export interface $ZodPromiseInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Promise<core.output<T>>, util.MaybeAsync<core.input<T>>> {
|
||||
export interface $ZodPromiseInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, util.MaybeAsync<core.input<T>>> {
|
||||
def: $ZodPromiseDef<T>;
|
||||
isst: never;
|
||||
}
|
||||
@@ -1119,5 +1037,5 @@ export interface $ZodCustom<O = unknown, I = unknown> extends $ZodType {
|
||||
_zod: $ZodCustomInternals<O, I>;
|
||||
}
|
||||
export declare const $ZodCustom: core.$constructor<$ZodCustom>;
|
||||
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodFunction | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
||||
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodMAC | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodJWT | $ZodCustomStringFormat<"hex"> | $ZodCustomStringFormat<util.HashFormat> | $ZodCustomStringFormat<"hostname">;
|
||||
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
||||
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodJWT;
|
||||
|
||||
+198
-435
@@ -1,7 +1,7 @@
|
||||
import * as checks from "./checks.js";
|
||||
import * as core from "./core.js";
|
||||
import { Doc } from "./doc.js";
|
||||
import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
|
||||
import { safeParse, safeParseAsync } from "./parse.js";
|
||||
import * as regexes from "./regexes.js";
|
||||
import * as util from "./util.js";
|
||||
import { version } from "./versions.js";
|
||||
@@ -16,6 +16,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
|
||||
if (inst._zod.traits.has("$ZodCheck")) {
|
||||
checks.unshift(inst);
|
||||
}
|
||||
//
|
||||
for (const ch of checks) {
|
||||
for (const fn of ch._zod.onattach) {
|
||||
fn(inst);
|
||||
@@ -72,47 +73,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
// const handleChecksResult = (
|
||||
// checkResult: ParsePayload,
|
||||
// originalResult: ParsePayload,
|
||||
// ctx: ParseContextInternal
|
||||
// ): util.MaybeAsync<ParsePayload> => {
|
||||
// // if the checks mutated the value && there are no issues, re-parse the result
|
||||
// if (checkResult.value !== originalResult.value && !checkResult.issues.length)
|
||||
// return inst._zod.parse(checkResult, ctx);
|
||||
// return originalResult;
|
||||
// };
|
||||
const handleCanaryResult = (canary, payload, ctx) => {
|
||||
// abort if the canary is aborted
|
||||
if (util.aborted(canary)) {
|
||||
canary.aborted = true;
|
||||
return canary;
|
||||
}
|
||||
// run checks first, then
|
||||
const checkResult = runChecks(payload, checks, ctx);
|
||||
if (checkResult instanceof Promise) {
|
||||
if (ctx.async === false)
|
||||
throw new core.$ZodAsyncError();
|
||||
return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
|
||||
}
|
||||
return inst._zod.parse(checkResult, ctx);
|
||||
};
|
||||
inst._zod.run = (payload, ctx) => {
|
||||
if (ctx.skipChecks) {
|
||||
return inst._zod.parse(payload, ctx);
|
||||
}
|
||||
if (ctx.direction === "backward") {
|
||||
// run canary
|
||||
// initial pass (no checks)
|
||||
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
||||
if (canary instanceof Promise) {
|
||||
return canary.then((canary) => {
|
||||
return handleCanaryResult(canary, payload, ctx);
|
||||
});
|
||||
}
|
||||
return handleCanaryResult(canary, payload, ctx);
|
||||
}
|
||||
// forward
|
||||
const result = inst._zod.parse(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
if (ctx.async === false)
|
||||
@@ -195,10 +156,9 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.check = (payload) => {
|
||||
try {
|
||||
// Trim whitespace from input
|
||||
const trimmed = payload.value.trim();
|
||||
// @ts-ignore
|
||||
const url = new URL(trimmed);
|
||||
const orig = payload.value;
|
||||
const url = new URL(orig);
|
||||
const href = url.href;
|
||||
if (def.hostname) {
|
||||
def.hostname.lastIndex = 0;
|
||||
if (!def.hostname.test(url.hostname)) {
|
||||
@@ -206,7 +166,7 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
||||
code: "invalid_format",
|
||||
format: "url",
|
||||
note: "Invalid hostname",
|
||||
pattern: def.hostname.source,
|
||||
pattern: regexes.hostname.source,
|
||||
input: payload.value,
|
||||
inst,
|
||||
continue: !def.abort,
|
||||
@@ -227,14 +187,12 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
||||
});
|
||||
}
|
||||
}
|
||||
// Set the output value based on normalize flag
|
||||
if (def.normalize) {
|
||||
// Use normalized URL
|
||||
payload.value = url.href;
|
||||
// payload.value = url.href;
|
||||
if (!orig.endsWith("/") && href.endsWith("/")) {
|
||||
payload.value = href.slice(0, -1);
|
||||
}
|
||||
else {
|
||||
// Preserve the original input (trimmed)
|
||||
payload.value = trimmed;
|
||||
payload.value = href;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -296,15 +254,20 @@ export const $ZodISODuration = /*@__PURE__*/ core.$constructor("$ZodISODuration"
|
||||
export const $ZodIPv4 = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.ipv4);
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `ipv4`;
|
||||
inst._zod.onattach.push((inst) => {
|
||||
const bag = inst._zod.bag;
|
||||
bag.format = `ipv4`;
|
||||
});
|
||||
});
|
||||
export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.ipv6);
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `ipv6`;
|
||||
inst._zod.onattach.push((inst) => {
|
||||
const bag = inst._zod.bag;
|
||||
bag.format = `ipv6`;
|
||||
});
|
||||
inst._zod.check = (payload) => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
new URL(`http://[${payload.value}]`);
|
||||
// return;
|
||||
}
|
||||
@@ -319,11 +282,6 @@ export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def)
|
||||
}
|
||||
};
|
||||
});
|
||||
export const $ZodMAC = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `mac`;
|
||||
});
|
||||
export const $ZodCIDRv4 = /*@__PURE__*/ core.$constructor("$ZodCIDRv4", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.cidrv4);
|
||||
$ZodStringFormat.init(inst, def);
|
||||
@@ -332,11 +290,8 @@ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, d
|
||||
def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.check = (payload) => {
|
||||
const parts = payload.value.split("/");
|
||||
const [address, prefix] = payload.value.split("/");
|
||||
try {
|
||||
if (parts.length !== 2)
|
||||
throw new Error();
|
||||
const [address, prefix] = parts;
|
||||
if (!prefix)
|
||||
throw new Error();
|
||||
const prefixNum = Number(prefix);
|
||||
@@ -344,7 +299,6 @@ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, d
|
||||
throw new Error();
|
||||
if (prefixNum < 0 || prefixNum > 128)
|
||||
throw new Error();
|
||||
// @ts-ignore
|
||||
new URL(`http://[${address}]`);
|
||||
}
|
||||
catch {
|
||||
@@ -365,7 +319,6 @@ export function isValidBase64(data) {
|
||||
if (data.length % 4 !== 0)
|
||||
return false;
|
||||
try {
|
||||
// @ts-ignore
|
||||
atob(data);
|
||||
return true;
|
||||
}
|
||||
@@ -376,7 +329,9 @@ export function isValidBase64(data) {
|
||||
export const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.base64);
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.contentEncoding = "base64";
|
||||
inst._zod.onattach.push((inst) => {
|
||||
inst._zod.bag.contentEncoding = "base64";
|
||||
});
|
||||
inst._zod.check = (payload) => {
|
||||
if (isValidBase64(payload.value))
|
||||
return;
|
||||
@@ -400,7 +355,9 @@ export function isValidBase64URL(data) {
|
||||
export const $ZodBase64URL = /*@__PURE__*/ core.$constructor("$ZodBase64URL", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.base64url);
|
||||
$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.contentEncoding = "base64url";
|
||||
inst._zod.onattach.push((inst) => {
|
||||
inst._zod.bag.contentEncoding = "base64url";
|
||||
});
|
||||
inst._zod.check = (payload) => {
|
||||
if (isValidBase64URL(payload.value))
|
||||
return;
|
||||
@@ -426,7 +383,6 @@ export function isValidJWT(token, algorithm = null) {
|
||||
const [header] = tokensParts;
|
||||
if (!header)
|
||||
return false;
|
||||
// @ts-ignore
|
||||
const parsedHeader = JSON.parse(atob(header));
|
||||
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
|
||||
return false;
|
||||
@@ -498,9 +454,9 @@ export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, d
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
export const $ZodNumberFormat = /*@__PURE__*/ core.$constructor("$ZodNumberFormat", (inst, def) => {
|
||||
export const $ZodNumberFormat = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
|
||||
checks.$ZodCheckNumberFormat.init(inst, def);
|
||||
$ZodNumber.init(inst, def); // no format checks
|
||||
$ZodNumber.init(inst, def); // no format checksp
|
||||
});
|
||||
export const $ZodBoolean = /*@__PURE__*/ core.$constructor("$ZodBoolean", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
@@ -543,7 +499,7 @@ export const $ZodBigInt = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, d
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigIntFormat", (inst, def) => {
|
||||
export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, def) => {
|
||||
checks.$ZodCheckBigIntFormat.init(inst, def);
|
||||
$ZodBigInt.init(inst, def); // no format checks
|
||||
});
|
||||
@@ -697,88 +653,58 @@ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def
|
||||
return payload; //handleArrayResultsAsync(parseResults, final);
|
||||
};
|
||||
});
|
||||
function handlePropertyResult(result, final, key, input) {
|
||||
function handleObjectResult(result, final, key) {
|
||||
// if(isOptional)
|
||||
if (result.issues.length) {
|
||||
final.issues.push(...util.prefixIssues(key, result.issues));
|
||||
}
|
||||
if (result.value === undefined) {
|
||||
if (key in input) {
|
||||
final.value[key] = undefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
function normalizeDef(def) {
|
||||
const keys = Object.keys(def.shape);
|
||||
for (const k of keys) {
|
||||
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
|
||||
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
||||
}
|
||||
}
|
||||
const okeys = util.optionalKeys(def.shape);
|
||||
return {
|
||||
...def,
|
||||
keys,
|
||||
keySet: new Set(keys),
|
||||
numKeys: keys.length,
|
||||
optionalKeys: new Set(okeys),
|
||||
};
|
||||
}
|
||||
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
||||
const unrecognized = [];
|
||||
// iterate over input keys
|
||||
const keySet = def.keySet;
|
||||
const _catchall = def.catchall._zod;
|
||||
const t = _catchall.def.type;
|
||||
for (const key in input) {
|
||||
if (keySet.has(key))
|
||||
continue;
|
||||
if (t === "never") {
|
||||
unrecognized.push(key);
|
||||
continue;
|
||||
}
|
||||
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
|
||||
function handleOptionalObjectResult(result, final, key, input) {
|
||||
if (result.issues.length) {
|
||||
// validation failed against value schema
|
||||
if (input[key] === undefined) {
|
||||
// if input was undefined, ignore the error
|
||||
if (key in input) {
|
||||
final.value[key] = undefined;
|
||||
}
|
||||
else {
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
handlePropertyResult(r, payload, key, input);
|
||||
final.issues.push(...util.prefixIssues(key, result.issues));
|
||||
}
|
||||
}
|
||||
if (unrecognized.length) {
|
||||
payload.issues.push({
|
||||
code: "unrecognized_keys",
|
||||
keys: unrecognized,
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
else if (result.value === undefined) {
|
||||
// validation returned `undefined`
|
||||
if (key in input)
|
||||
final.value[key] = undefined;
|
||||
}
|
||||
else {
|
||||
// non-undefined value
|
||||
final.value[key] = result.value;
|
||||
}
|
||||
if (!proms.length)
|
||||
return payload;
|
||||
return Promise.all(proms).then(() => {
|
||||
return payload;
|
||||
});
|
||||
}
|
||||
export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
|
||||
// requires cast because technically $ZodObject doesn't extend
|
||||
$ZodType.init(inst, def);
|
||||
// const sh = def.shape;
|
||||
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
||||
if (!desc?.get) {
|
||||
const sh = def.shape;
|
||||
Object.defineProperty(def, "shape", {
|
||||
get: () => {
|
||||
const newSh = { ...sh };
|
||||
Object.defineProperty(def, "shape", {
|
||||
value: newSh,
|
||||
});
|
||||
return newSh;
|
||||
},
|
||||
});
|
||||
}
|
||||
const _normalized = util.cached(() => normalizeDef(def));
|
||||
const _normalized = util.cached(() => {
|
||||
const keys = Object.keys(def.shape);
|
||||
for (const k of keys) {
|
||||
if (!(def.shape[k] instanceof $ZodType)) {
|
||||
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
||||
}
|
||||
}
|
||||
const okeys = util.optionalKeys(def.shape);
|
||||
return {
|
||||
shape: def.shape,
|
||||
keys,
|
||||
keySet: new Set(keys),
|
||||
numKeys: keys.length,
|
||||
optionalKeys: new Set(okeys),
|
||||
};
|
||||
});
|
||||
util.defineLazy(inst._zod, "propValues", () => {
|
||||
const shape = def.shape;
|
||||
const propValues = {};
|
||||
@@ -792,45 +718,6 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
|
||||
}
|
||||
return propValues;
|
||||
});
|
||||
const isObject = util.isObject;
|
||||
const catchall = def.catchall;
|
||||
let value;
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
value ?? (value = _normalized.value);
|
||||
const input = payload.value;
|
||||
if (!isObject(input)) {
|
||||
payload.issues.push({
|
||||
expected: "object",
|
||||
code: "invalid_type",
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
payload.value = {};
|
||||
const proms = [];
|
||||
const shape = value.shape;
|
||||
for (const key of value.keys) {
|
||||
const el = shape[key];
|
||||
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
|
||||
}
|
||||
else {
|
||||
handlePropertyResult(r, payload, key, input);
|
||||
}
|
||||
}
|
||||
if (!catchall) {
|
||||
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
||||
}
|
||||
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
||||
};
|
||||
});
|
||||
export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
// requires cast because technically $ZodObject doesn't extend
|
||||
$ZodObject.init(inst, def);
|
||||
const superParse = inst._zod.parse;
|
||||
const _normalized = util.cached(() => normalizeDef(def));
|
||||
const generateFastpass = (shape) => {
|
||||
const doc = new Doc(["shape", "payload", "ctx"]);
|
||||
const normalized = _normalized.value;
|
||||
@@ -845,29 +732,44 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
||||
ids[key] = `key_${counter++}`;
|
||||
}
|
||||
// A: preserve key order {
|
||||
doc.write(`const newResult = {};`);
|
||||
doc.write(`const newResult = {}`);
|
||||
for (const key of normalized.keys) {
|
||||
const id = ids[key];
|
||||
const k = util.esc(key);
|
||||
doc.write(`const ${id} = ${parseStr(key)};`);
|
||||
doc.write(`
|
||||
if (normalized.optionalKeys.has(key)) {
|
||||
const id = ids[key];
|
||||
doc.write(`const ${id} = ${parseStr(key)};`);
|
||||
const k = util.esc(key);
|
||||
doc.write(`
|
||||
if (${id}.issues.length) {
|
||||
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
||||
...iss,
|
||||
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
||||
})));
|
||||
}
|
||||
|
||||
|
||||
if (${id}.value === undefined) {
|
||||
if (${k} in input) {
|
||||
newResult[${k}] = undefined;
|
||||
if (input[${k}] === undefined) {
|
||||
if (${k} in input) {
|
||||
newResult[${k}] = undefined;
|
||||
}
|
||||
} else {
|
||||
payload.issues = payload.issues.concat(
|
||||
${id}.issues.map((iss) => ({
|
||||
...iss,
|
||||
path: iss.path ? [${k}, ...iss.path] : [${k}],
|
||||
}))
|
||||
);
|
||||
}
|
||||
} else if (${id}.value === undefined) {
|
||||
if (${k} in input) newResult[${k}] = undefined;
|
||||
} else {
|
||||
newResult[${k}] = ${id}.value;
|
||||
}
|
||||
|
||||
`);
|
||||
`);
|
||||
}
|
||||
else {
|
||||
const id = ids[key];
|
||||
// const id = ids[key];
|
||||
doc.write(`const ${id} = ${parseStr(key)};`);
|
||||
doc.write(`
|
||||
if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
||||
...iss,
|
||||
path: iss.path ? [${util.esc(key)}, ...iss.path] : [${util.esc(key)}]
|
||||
})));`);
|
||||
doc.write(`newResult[${util.esc(key)}] = ${id}.value`);
|
||||
}
|
||||
}
|
||||
doc.write(`payload.value = newResult;`);
|
||||
doc.write(`return payload;`);
|
||||
@@ -893,16 +795,80 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
const proms = [];
|
||||
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
|
||||
// always synchronous
|
||||
if (!fastpass)
|
||||
fastpass = generateFastpass(def.shape);
|
||||
payload = fastpass(payload, ctx);
|
||||
if (!catchall)
|
||||
return payload;
|
||||
return handleCatchall([], input, payload, ctx, value, inst);
|
||||
}
|
||||
return superParse(payload, ctx);
|
||||
else {
|
||||
payload.value = {};
|
||||
const shape = value.shape;
|
||||
for (const key of value.keys) {
|
||||
const el = shape[key];
|
||||
// do not add omitted optional keys
|
||||
// if (!(key in input)) {
|
||||
// if (optionalKeys.has(key)) continue;
|
||||
// payload.issues.push({
|
||||
// code: "invalid_type",
|
||||
// path: [key],
|
||||
// expected: "nonoptional",
|
||||
// note: `Missing required key: "${key}"`,
|
||||
// input,
|
||||
// inst,
|
||||
// });
|
||||
// }
|
||||
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
||||
const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)));
|
||||
}
|
||||
else if (isOptional) {
|
||||
handleOptionalObjectResult(r, payload, key, input);
|
||||
}
|
||||
else {
|
||||
handleObjectResult(r, payload, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!catchall) {
|
||||
// return payload;
|
||||
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
||||
}
|
||||
const unrecognized = [];
|
||||
// iterate over input keys
|
||||
const keySet = value.keySet;
|
||||
const _catchall = catchall._zod;
|
||||
const t = _catchall.def.type;
|
||||
for (const key of Object.keys(input)) {
|
||||
if (keySet.has(key))
|
||||
continue;
|
||||
if (t === "never") {
|
||||
unrecognized.push(key);
|
||||
continue;
|
||||
}
|
||||
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
||||
if (r instanceof Promise) {
|
||||
proms.push(r.then((r) => handleObjectResult(r, payload, key)));
|
||||
}
|
||||
else {
|
||||
handleObjectResult(r, payload, key);
|
||||
}
|
||||
}
|
||||
if (unrecognized.length) {
|
||||
payload.issues.push({
|
||||
code: "unrecognized_keys",
|
||||
keys: unrecognized,
|
||||
input,
|
||||
inst,
|
||||
});
|
||||
}
|
||||
if (!proms.length)
|
||||
return payload;
|
||||
return Promise.all(proms).then(() => {
|
||||
return payload;
|
||||
});
|
||||
};
|
||||
});
|
||||
function handleUnionResults(results, final, inst, ctx) {
|
||||
@@ -912,11 +878,6 @@ function handleUnionResults(results, final, inst, ctx) {
|
||||
return final;
|
||||
}
|
||||
}
|
||||
const nonaborted = results.filter((r) => !util.aborted(r));
|
||||
if (nonaborted.length === 1) {
|
||||
final.value = nonaborted[0].value;
|
||||
return nonaborted[0];
|
||||
}
|
||||
final.issues.push({
|
||||
code: "invalid_union",
|
||||
input: final.value,
|
||||
@@ -942,12 +903,7 @@ export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const single = def.options.length === 1;
|
||||
const first = def.options[0]._zod.run;
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (single) {
|
||||
return first(payload, ctx);
|
||||
}
|
||||
let async = false;
|
||||
const results = [];
|
||||
for (const option of def.options) {
|
||||
@@ -997,7 +953,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
||||
const opts = def.options;
|
||||
const map = new Map();
|
||||
for (const o of opts) {
|
||||
const values = o._zod.propValues?.[def.discriminator];
|
||||
const values = o._zod.propValues[def.discriminator];
|
||||
if (!values || values.size === 0)
|
||||
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
||||
for (const v of values) {
|
||||
@@ -1032,7 +988,6 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
||||
code: "invalid_union",
|
||||
errors: [],
|
||||
note: "No matching discriminator",
|
||||
discriminator: def.discriminator,
|
||||
input,
|
||||
path: [def.discriminator],
|
||||
inst,
|
||||
@@ -1120,6 +1075,7 @@ function handleIntersectionResults(result, left, right) {
|
||||
export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
const items = def.items;
|
||||
const optStart = items.length - [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
const input = payload.value;
|
||||
if (!Array.isArray(input)) {
|
||||
@@ -1133,17 +1089,15 @@ export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def
|
||||
}
|
||||
payload.value = [];
|
||||
const proms = [];
|
||||
const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
|
||||
const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
|
||||
if (!def.rest) {
|
||||
const tooBig = input.length > items.length;
|
||||
const tooSmall = input.length < optStart - 1;
|
||||
if (tooBig || tooSmall) {
|
||||
payload.issues.push({
|
||||
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
||||
input,
|
||||
inst,
|
||||
origin: "array",
|
||||
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
@@ -1206,13 +1160,11 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
|
||||
return payload;
|
||||
}
|
||||
const proms = [];
|
||||
const values = def.keyType._zod.values;
|
||||
if (values) {
|
||||
if (def.keyType._zod.values) {
|
||||
const values = def.keyType._zod.values;
|
||||
payload.value = {};
|
||||
const recordKeys = new Set();
|
||||
for (const key of values) {
|
||||
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
||||
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
||||
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
||||
if (result instanceof Promise) {
|
||||
proms.push(result.then((result) => {
|
||||
@@ -1232,7 +1184,7 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
|
||||
}
|
||||
let unrecognized;
|
||||
for (const key in input) {
|
||||
if (!recordKeys.has(key)) {
|
||||
if (!values.has(key)) {
|
||||
unrecognized = unrecognized ?? [];
|
||||
unrecognized.push(key);
|
||||
}
|
||||
@@ -1257,8 +1209,8 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
|
||||
}
|
||||
if (keyResult.issues.length) {
|
||||
payload.issues.push({
|
||||
code: "invalid_key",
|
||||
origin: "record",
|
||||
code: "invalid_key",
|
||||
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
||||
input: key,
|
||||
path: [key],
|
||||
@@ -1329,8 +1281,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
|
||||
}
|
||||
else {
|
||||
final.issues.push({
|
||||
code: "invalid_key",
|
||||
origin: "map",
|
||||
code: "invalid_key",
|
||||
input,
|
||||
inst,
|
||||
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
||||
@@ -1391,15 +1343,14 @@ function handleSetResult(result, final) {
|
||||
export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
const values = util.getEnumValues(def.entries);
|
||||
const valuesSet = new Set(values);
|
||||
inst._zod.values = valuesSet;
|
||||
inst._zod.values = new Set(values);
|
||||
inst._zod.pattern = new RegExp(`^(${values
|
||||
.filter((k) => util.propertyKeyTypes.has(typeof k))
|
||||
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
|
||||
.join("|")})$`);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
if (valuesSet.has(input)) {
|
||||
if (inst._zod.values.has(input)) {
|
||||
return payload;
|
||||
}
|
||||
payload.issues.push({
|
||||
@@ -1413,17 +1364,13 @@ export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def)
|
||||
});
|
||||
export const $ZodLiteral = /*@__PURE__*/ core.$constructor("$ZodLiteral", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
if (def.values.length === 0) {
|
||||
throw new Error("Cannot create literal schema with no valid values");
|
||||
}
|
||||
const values = new Set(def.values);
|
||||
inst._zod.values = values;
|
||||
inst._zod.values = new Set(def.values);
|
||||
inst._zod.pattern = new RegExp(`^(${def.values
|
||||
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
|
||||
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
|
||||
.join("|")})$`);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
if (values.has(input)) {
|
||||
if (inst._zod.values.has(input)) {
|
||||
return payload;
|
||||
}
|
||||
payload.issues.push({
|
||||
@@ -1439,7 +1386,6 @@ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def)
|
||||
$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
// @ts-ignore
|
||||
if (input instanceof File)
|
||||
return payload;
|
||||
payload.issues.push({
|
||||
@@ -1453,12 +1399,9 @@ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def)
|
||||
});
|
||||
export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
throw new core.$ZodEncodeError(inst.constructor.name);
|
||||
}
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const _out = def.transform(payload.value, payload);
|
||||
if (ctx.async) {
|
||||
if (_ctx.async) {
|
||||
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
||||
return output.then((output) => {
|
||||
payload.value = output;
|
||||
@@ -1472,12 +1415,6 @@ export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (i
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
function handleOptionalResult(result, input) {
|
||||
if (result.issues.length && input === undefined) {
|
||||
return { issues: [], value: undefined };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
inst._zod.optin = "optional";
|
||||
@@ -1491,10 +1428,7 @@ export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (ins
|
||||
});
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (def.innerType._zod.optin === "optional") {
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise)
|
||||
return result.then((r) => handleOptionalResult(r, payload.value));
|
||||
return handleOptionalResult(result, payload.value);
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
if (payload.value === undefined) {
|
||||
return payload;
|
||||
@@ -1514,7 +1448,6 @@ export const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (ins
|
||||
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
|
||||
});
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
// Forward direction (decode): allow null to pass through
|
||||
if (payload.value === null)
|
||||
return payload;
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
@@ -1526,18 +1459,13 @@ export const $ZodDefault = /*@__PURE__*/ core.$constructor("$ZodDefault", (inst,
|
||||
inst._zod.optin = "optional";
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
// Forward direction (decode): apply defaults for undefined input
|
||||
if (payload.value === undefined) {
|
||||
payload.value = def.defaultValue;
|
||||
/**
|
||||
* $ZodDefault returns the default value immediately in forward direction.
|
||||
* $ZodDefault always returns the default value immediately.
|
||||
* It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
|
||||
return payload;
|
||||
}
|
||||
// Forward direction: continue with default handling
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((result) => handleDefaultResult(result, def));
|
||||
@@ -1556,10 +1484,6 @@ export const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (ins
|
||||
inst._zod.optin = "optional";
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
// Forward direction (decode): apply prefault for undefined input
|
||||
if (payload.value === undefined) {
|
||||
payload.value = def.defaultValue;
|
||||
}
|
||||
@@ -1594,9 +1518,6 @@ function handleNonOptionalResult(payload, inst) {
|
||||
export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
throw new core.$ZodEncodeError("ZodSuccess");
|
||||
}
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((result) => {
|
||||
@@ -1610,14 +1531,10 @@ export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst,
|
||||
});
|
||||
export const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
||||
inst._zod.optin = "optional";
|
||||
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
// Forward direction (decode): apply catch logic
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((result) => {
|
||||
@@ -1669,94 +1586,27 @@ export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def)
|
||||
util.defineLazy(inst._zod, "values", () => def.in._zod.values);
|
||||
util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
||||
util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
const right = def.out._zod.run(payload, ctx);
|
||||
if (right instanceof Promise) {
|
||||
return right.then((right) => handlePipeResult(right, def.in, ctx));
|
||||
}
|
||||
return handlePipeResult(right, def.in, ctx);
|
||||
}
|
||||
const left = def.in._zod.run(payload, ctx);
|
||||
if (left instanceof Promise) {
|
||||
return left.then((left) => handlePipeResult(left, def.out, ctx));
|
||||
return left.then((left) => handlePipeResult(left, def, ctx));
|
||||
}
|
||||
return handlePipeResult(left, def.out, ctx);
|
||||
return handlePipeResult(left, def, ctx);
|
||||
};
|
||||
});
|
||||
function handlePipeResult(left, next, ctx) {
|
||||
if (left.issues.length) {
|
||||
// prevent further checks
|
||||
left.aborted = true;
|
||||
function handlePipeResult(left, def, ctx) {
|
||||
if (util.aborted(left)) {
|
||||
return left;
|
||||
}
|
||||
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
||||
}
|
||||
export const $ZodCodec = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
util.defineLazy(inst._zod, "values", () => def.in._zod.values);
|
||||
util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
||||
util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
const direction = ctx.direction || "forward";
|
||||
if (direction === "forward") {
|
||||
const left = def.in._zod.run(payload, ctx);
|
||||
if (left instanceof Promise) {
|
||||
return left.then((left) => handleCodecAResult(left, def, ctx));
|
||||
}
|
||||
return handleCodecAResult(left, def, ctx);
|
||||
}
|
||||
else {
|
||||
const right = def.out._zod.run(payload, ctx);
|
||||
if (right instanceof Promise) {
|
||||
return right.then((right) => handleCodecAResult(right, def, ctx));
|
||||
}
|
||||
return handleCodecAResult(right, def, ctx);
|
||||
}
|
||||
};
|
||||
});
|
||||
function handleCodecAResult(result, def, ctx) {
|
||||
if (result.issues.length) {
|
||||
// prevent further checks
|
||||
result.aborted = true;
|
||||
return result;
|
||||
}
|
||||
const direction = ctx.direction || "forward";
|
||||
if (direction === "forward") {
|
||||
const transformed = def.transform(result.value, result);
|
||||
if (transformed instanceof Promise) {
|
||||
return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
|
||||
}
|
||||
return handleCodecTxResult(result, transformed, def.out, ctx);
|
||||
}
|
||||
else {
|
||||
const transformed = def.reverseTransform(result.value, result);
|
||||
if (transformed instanceof Promise) {
|
||||
return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
|
||||
}
|
||||
return handleCodecTxResult(result, transformed, def.in, ctx);
|
||||
}
|
||||
}
|
||||
function handleCodecTxResult(left, value, nextSchema, ctx) {
|
||||
// Check if transform added any issues
|
||||
if (left.issues.length) {
|
||||
left.aborted = true;
|
||||
return left;
|
||||
}
|
||||
return nextSchema._zod.run({ value, issues: left.issues }, ctx);
|
||||
return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
|
||||
}
|
||||
export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
||||
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
||||
util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
||||
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
if (ctx.direction === "backward") {
|
||||
return def.innerType._zod.run(payload, ctx);
|
||||
}
|
||||
const result = def.innerType._zod.run(payload, ctx);
|
||||
if (result instanceof Promise) {
|
||||
return result.then(handleReadonlyResult);
|
||||
@@ -1772,8 +1622,7 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
|
||||
$ZodType.init(inst, def);
|
||||
const regexParts = [];
|
||||
for (const part of def.parts) {
|
||||
if (typeof part === "object" && part !== null) {
|
||||
// is Zod schema
|
||||
if (part instanceof $ZodType) {
|
||||
if (!part._zod.pattern) {
|
||||
// if (!source)
|
||||
throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
|
||||
@@ -1809,7 +1658,7 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
|
||||
input: payload.value,
|
||||
inst,
|
||||
code: "invalid_format",
|
||||
format: def.format ?? "template_literal",
|
||||
format: "template_literal",
|
||||
pattern: inst._zod.pattern.source,
|
||||
});
|
||||
return payload;
|
||||
@@ -1817,85 +1666,6 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
export const $ZodFunction = /*@__PURE__*/ core.$constructor("$ZodFunction", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
inst._def = def;
|
||||
inst._zod.def = def;
|
||||
inst.implement = (func) => {
|
||||
if (typeof func !== "function") {
|
||||
throw new Error("implement() must be called with a function");
|
||||
}
|
||||
return function (...args) {
|
||||
const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
|
||||
const result = Reflect.apply(func, this, parsedArgs);
|
||||
if (inst._def.output) {
|
||||
return parse(inst._def.output, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
inst.implementAsync = (func) => {
|
||||
if (typeof func !== "function") {
|
||||
throw new Error("implementAsync() must be called with a function");
|
||||
}
|
||||
return async function (...args) {
|
||||
const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
|
||||
const result = await Reflect.apply(func, this, parsedArgs);
|
||||
if (inst._def.output) {
|
||||
return await parseAsync(inst._def.output, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
if (typeof payload.value !== "function") {
|
||||
payload.issues.push({
|
||||
code: "invalid_type",
|
||||
expected: "function",
|
||||
input: payload.value,
|
||||
inst,
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
// Check if output is a promise type to determine if we should use async implementation
|
||||
const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
|
||||
if (hasPromiseOutput) {
|
||||
payload.value = inst.implementAsync(payload.value);
|
||||
}
|
||||
else {
|
||||
payload.value = inst.implement(payload.value);
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
inst.input = (...args) => {
|
||||
const F = inst.constructor;
|
||||
if (Array.isArray(args[0])) {
|
||||
return new F({
|
||||
type: "function",
|
||||
input: new $ZodTuple({
|
||||
type: "tuple",
|
||||
items: args[0],
|
||||
rest: args[1],
|
||||
}),
|
||||
output: inst._def.output,
|
||||
});
|
||||
}
|
||||
return new F({
|
||||
type: "function",
|
||||
input: args[0],
|
||||
output: inst._def.output,
|
||||
});
|
||||
};
|
||||
inst.output = (output) => {
|
||||
const F = inst.constructor;
|
||||
return new F({
|
||||
type: "function",
|
||||
input: inst._def.input,
|
||||
output,
|
||||
});
|
||||
};
|
||||
return inst;
|
||||
});
|
||||
export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
@@ -1904,18 +1674,11 @@ export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst,
|
||||
});
|
||||
export const $ZodLazy = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
|
||||
$ZodType.init(inst, def);
|
||||
// let _innerType!: any;
|
||||
// util.defineLazy(def, "getter", () => {
|
||||
// if (!_innerType) {
|
||||
// _innerType = def.getter();
|
||||
// }
|
||||
// return () => _innerType;
|
||||
// });
|
||||
util.defineLazy(inst._zod, "innerType", () => def.getter());
|
||||
util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
|
||||
util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
|
||||
util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
|
||||
util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
|
||||
util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
|
||||
util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
|
||||
util.defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
|
||||
util.defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
const inner = inst._zod.innerType;
|
||||
return inner._zod.run(payload, ctx);
|
||||
|
||||
+120
-149
@@ -83,9 +83,7 @@ class JSONSchemaGenerator {
|
||||
else if (regexes.length > 1) {
|
||||
result.schema.allOf = [
|
||||
...regexes.map((regex) => ({
|
||||
...(this.target === "draft-7" || this.target === "draft-4" || this.target === "openapi-3.0"
|
||||
? { type: "string" }
|
||||
: {}),
|
||||
...(this.target === "draft-7" ? { type: "string" } : {}),
|
||||
pattern: regex.source,
|
||||
})),
|
||||
];
|
||||
@@ -100,36 +98,22 @@ class JSONSchemaGenerator {
|
||||
json.type = "integer";
|
||||
else
|
||||
json.type = "number";
|
||||
if (typeof exclusiveMinimum === "number") {
|
||||
if (this.target === "draft-4" || this.target === "openapi-3.0") {
|
||||
json.minimum = exclusiveMinimum;
|
||||
json.exclusiveMinimum = true;
|
||||
}
|
||||
else {
|
||||
json.exclusiveMinimum = exclusiveMinimum;
|
||||
}
|
||||
}
|
||||
if (typeof exclusiveMinimum === "number")
|
||||
json.exclusiveMinimum = exclusiveMinimum;
|
||||
if (typeof minimum === "number") {
|
||||
json.minimum = minimum;
|
||||
if (typeof exclusiveMinimum === "number" && this.target !== "draft-4") {
|
||||
if (typeof exclusiveMinimum === "number") {
|
||||
if (exclusiveMinimum >= minimum)
|
||||
delete json.minimum;
|
||||
else
|
||||
delete json.exclusiveMinimum;
|
||||
}
|
||||
}
|
||||
if (typeof exclusiveMaximum === "number") {
|
||||
if (this.target === "draft-4" || this.target === "openapi-3.0") {
|
||||
json.maximum = exclusiveMaximum;
|
||||
json.exclusiveMaximum = true;
|
||||
}
|
||||
else {
|
||||
json.exclusiveMaximum = exclusiveMaximum;
|
||||
}
|
||||
}
|
||||
if (typeof exclusiveMaximum === "number")
|
||||
json.exclusiveMaximum = exclusiveMaximum;
|
||||
if (typeof maximum === "number") {
|
||||
json.maximum = maximum;
|
||||
if (typeof exclusiveMaximum === "number" && this.target !== "draft-4") {
|
||||
if (typeof exclusiveMaximum === "number") {
|
||||
if (exclusiveMaximum <= maximum)
|
||||
delete json.maximum;
|
||||
else
|
||||
@@ -158,13 +142,7 @@ class JSONSchemaGenerator {
|
||||
break;
|
||||
}
|
||||
case "null": {
|
||||
if (this.target === "openapi-3.0") {
|
||||
_json.type = "string";
|
||||
_json.nullable = true;
|
||||
_json.enum = [null];
|
||||
}
|
||||
else
|
||||
_json.type = "null";
|
||||
_json.type = "null";
|
||||
break;
|
||||
}
|
||||
case "any": {
|
||||
@@ -252,19 +230,10 @@ class JSONSchemaGenerator {
|
||||
}
|
||||
case "union": {
|
||||
const json = _json;
|
||||
// Discriminated unions use oneOf (exactly one match) instead of anyOf (one or more matches)
|
||||
// because the discriminator field ensures mutual exclusivity between options in JSON Schema
|
||||
const isDiscriminated = def.discriminator !== undefined;
|
||||
const options = def.options.map((x, i) => this.process(x, {
|
||||
json.anyOf = def.options.map((x, i) => this.process(x, {
|
||||
...params,
|
||||
path: [...params.path, isDiscriminated ? "oneOf" : "anyOf", i],
|
||||
path: [...params.path, "anyOf", i],
|
||||
}));
|
||||
if (isDiscriminated) {
|
||||
json.oneOf = options;
|
||||
}
|
||||
else {
|
||||
json.anyOf = options;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "intersection": {
|
||||
@@ -288,42 +257,32 @@ class JSONSchemaGenerator {
|
||||
case "tuple": {
|
||||
const json = _json;
|
||||
json.type = "array";
|
||||
const prefixPath = this.target === "draft-2020-12" ? "prefixItems" : "items";
|
||||
const restPath = this.target === "draft-2020-12" ? "items" : this.target === "openapi-3.0" ? "items" : "additionalItems";
|
||||
const prefixItems = def.items.map((x, i) => this.process(x, {
|
||||
...params,
|
||||
path: [...params.path, prefixPath, i],
|
||||
}));
|
||||
const rest = def.rest
|
||||
? this.process(def.rest, {
|
||||
...params,
|
||||
path: [...params.path, restPath, ...(this.target === "openapi-3.0" ? [def.items.length] : [])],
|
||||
})
|
||||
: null;
|
||||
const prefixItems = def.items.map((x, i) => this.process(x, { ...params, path: [...params.path, "prefixItems", i] }));
|
||||
if (this.target === "draft-2020-12") {
|
||||
json.prefixItems = prefixItems;
|
||||
if (rest) {
|
||||
json.items = rest;
|
||||
}
|
||||
}
|
||||
else if (this.target === "openapi-3.0") {
|
||||
json.items = {
|
||||
anyOf: prefixItems,
|
||||
};
|
||||
if (rest) {
|
||||
json.items.anyOf.push(rest);
|
||||
}
|
||||
json.minItems = prefixItems.length;
|
||||
if (!rest) {
|
||||
json.maxItems = prefixItems.length;
|
||||
}
|
||||
}
|
||||
else {
|
||||
json.items = prefixItems;
|
||||
if (rest) {
|
||||
}
|
||||
if (def.rest) {
|
||||
const rest = this.process(def.rest, {
|
||||
...params,
|
||||
path: [...params.path, "items"],
|
||||
});
|
||||
if (this.target === "draft-2020-12") {
|
||||
json.items = rest;
|
||||
}
|
||||
else {
|
||||
json.additionalItems = rest;
|
||||
}
|
||||
}
|
||||
// additionalItems
|
||||
if (def.rest) {
|
||||
json.items = this.process(def.rest, {
|
||||
...params,
|
||||
path: [...params.path, "items"],
|
||||
});
|
||||
}
|
||||
// length
|
||||
const { minimum, maximum } = schema._zod.bag;
|
||||
if (typeof minimum === "number")
|
||||
@@ -335,12 +294,7 @@ class JSONSchemaGenerator {
|
||||
case "record": {
|
||||
const json = _json;
|
||||
json.type = "object";
|
||||
if (this.target === "draft-7" || this.target === "draft-2020-12") {
|
||||
json.propertyNames = this.process(def.keyType, {
|
||||
...params,
|
||||
path: [...params.path, "propertyNames"],
|
||||
});
|
||||
}
|
||||
json.propertyNames = this.process(def.keyType, { ...params, path: [...params.path, "propertyNames"] });
|
||||
json.additionalProperties = this.process(def.valueType, {
|
||||
...params,
|
||||
path: [...params.path, "additionalProperties"],
|
||||
@@ -400,12 +354,7 @@ class JSONSchemaGenerator {
|
||||
else if (vals.length === 1) {
|
||||
const val = vals[0];
|
||||
json.type = val === null ? "null" : typeof val;
|
||||
if (this.target === "draft-4" || this.target === "openapi-3.0") {
|
||||
json.enum = [val];
|
||||
}
|
||||
else {
|
||||
json.const = val;
|
||||
}
|
||||
json.const = val;
|
||||
}
|
||||
else {
|
||||
if (vals.every((v) => typeof v === "number"))
|
||||
@@ -460,13 +409,7 @@ class JSONSchemaGenerator {
|
||||
}
|
||||
case "nullable": {
|
||||
const inner = this.process(def.innerType, params);
|
||||
if (this.target === "openapi-3.0") {
|
||||
result.ref = def.innerType;
|
||||
_json.nullable = true;
|
||||
}
|
||||
else {
|
||||
_json.anyOf = [inner, { type: "null" }];
|
||||
}
|
||||
_json.anyOf = [inner, { type: "null" }];
|
||||
break;
|
||||
}
|
||||
case "nonoptional": {
|
||||
@@ -556,12 +499,6 @@ class JSONSchemaGenerator {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "function": {
|
||||
if (this.unrepresentable === "throw") {
|
||||
throw new Error("Function types cannot be represented in JSON Schema");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
def;
|
||||
}
|
||||
@@ -713,8 +650,7 @@ class JSONSchemaGenerator {
|
||||
flattenRef(ref, params);
|
||||
// merge referenced schema into current
|
||||
const refSchema = this.seen.get(ref).schema;
|
||||
if (refSchema.$ref &&
|
||||
(params.target === "draft-7" || params.target === "draft-4" || params.target === "openapi-3.0")) {
|
||||
if (refSchema.$ref && params.target === "draft-7") {
|
||||
schema.allOf = schema.allOf ?? [];
|
||||
schema.allOf.push(refSchema);
|
||||
}
|
||||
@@ -741,14 +677,7 @@ class JSONSchemaGenerator {
|
||||
else if (this.target === "draft-7") {
|
||||
result.$schema = "http://json-schema.org/draft-07/schema#";
|
||||
}
|
||||
else if (this.target === "draft-4") {
|
||||
result.$schema = "http://json-schema.org/draft-04/schema#";
|
||||
}
|
||||
else if (this.target === "openapi-3.0") {
|
||||
// OpenAPI 3.0 schema objects should not include a $schema property
|
||||
}
|
||||
else {
|
||||
// @ts-ignore
|
||||
console.warn(`Invalid target: ${this.target}`);
|
||||
}
|
||||
if (params.external?.uri) {
|
||||
@@ -829,55 +758,97 @@ function isTransforming(_schema, _ctx) {
|
||||
if (ctx.seen.has(_schema))
|
||||
return false;
|
||||
ctx.seen.add(_schema);
|
||||
const def = _schema._zod.def;
|
||||
if (def.type === "transform")
|
||||
return true;
|
||||
if (def.type === "array")
|
||||
return isTransforming(def.element, ctx);
|
||||
if (def.type === "set")
|
||||
return isTransforming(def.valueType, ctx);
|
||||
if (def.type === "lazy")
|
||||
return isTransforming(def.getter(), ctx);
|
||||
if (def.type === "promise" ||
|
||||
def.type === "optional" ||
|
||||
def.type === "nonoptional" ||
|
||||
def.type === "nullable" ||
|
||||
def.type === "readonly" ||
|
||||
def.type === "default" ||
|
||||
def.type === "prefault") {
|
||||
return isTransforming(def.innerType, ctx);
|
||||
}
|
||||
if (def.type === "intersection") {
|
||||
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
||||
}
|
||||
if (def.type === "record" || def.type === "map") {
|
||||
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
||||
}
|
||||
if (def.type === "pipe") {
|
||||
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
||||
}
|
||||
if (def.type === "object") {
|
||||
for (const key in def.shape) {
|
||||
if (isTransforming(def.shape[key], ctx))
|
||||
return true;
|
||||
const schema = _schema;
|
||||
const def = schema._zod.def;
|
||||
switch (def.type) {
|
||||
case "string":
|
||||
case "number":
|
||||
case "bigint":
|
||||
case "boolean":
|
||||
case "date":
|
||||
case "symbol":
|
||||
case "undefined":
|
||||
case "null":
|
||||
case "any":
|
||||
case "unknown":
|
||||
case "never":
|
||||
case "void":
|
||||
case "literal":
|
||||
case "enum":
|
||||
case "nan":
|
||||
case "file":
|
||||
case "template_literal":
|
||||
return false;
|
||||
case "array": {
|
||||
return isTransforming(def.element, ctx);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (def.type === "union") {
|
||||
for (const option of def.options) {
|
||||
if (isTransforming(option, ctx))
|
||||
return true;
|
||||
case "object": {
|
||||
for (const key in def.shape) {
|
||||
if (isTransforming(def.shape[key], ctx))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (def.type === "tuple") {
|
||||
for (const item of def.items) {
|
||||
if (isTransforming(item, ctx))
|
||||
return true;
|
||||
case "union": {
|
||||
for (const option of def.options) {
|
||||
if (isTransforming(option, ctx))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (def.rest && isTransforming(def.rest, ctx))
|
||||
case "intersection": {
|
||||
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
||||
}
|
||||
case "tuple": {
|
||||
for (const item of def.items) {
|
||||
if (isTransforming(item, ctx))
|
||||
return true;
|
||||
}
|
||||
if (def.rest && isTransforming(def.rest, ctx))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
case "record": {
|
||||
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
||||
}
|
||||
case "map": {
|
||||
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
||||
}
|
||||
case "set": {
|
||||
return isTransforming(def.valueType, ctx);
|
||||
}
|
||||
// inner types
|
||||
case "promise":
|
||||
case "optional":
|
||||
case "nonoptional":
|
||||
case "nullable":
|
||||
case "readonly":
|
||||
return isTransforming(def.innerType, ctx);
|
||||
case "lazy":
|
||||
return isTransforming(def.getter(), ctx);
|
||||
case "default": {
|
||||
return isTransforming(def.innerType, ctx);
|
||||
}
|
||||
case "prefault": {
|
||||
return isTransforming(def.innerType, ctx);
|
||||
}
|
||||
case "custom": {
|
||||
return false;
|
||||
}
|
||||
case "transform": {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
case "pipe": {
|
||||
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
||||
}
|
||||
case "success": {
|
||||
return false;
|
||||
}
|
||||
case "catch": {
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
def;
|
||||
}
|
||||
return false;
|
||||
throw new Error(`Unknown schema type: ${def.type}`);
|
||||
}
|
||||
|
||||
+3
-5
@@ -7,10 +7,8 @@ interface JSONSchemaGeneratorParams {
|
||||
metadata?: $ZodRegistry<Record<string, any>>;
|
||||
/** The JSON Schema version to target.
|
||||
* - `"draft-2020-12"` — Default. JSON Schema Draft 2020-12
|
||||
* - `"draft-7"` — JSON Schema Draft 7
|
||||
* - `"draft-4"` — JSON Schema Draft 4
|
||||
* - `"openapi-3.0"` — OpenAPI 3.0 Schema Object */
|
||||
target?: "draft-4" | "draft-7" | "draft-2020-12" | "openapi-3.0";
|
||||
* - `"draft-7"` — JSON Schema Draft 7 */
|
||||
target?: "draft-7" | "draft-2020-12";
|
||||
/** How to handle unrepresentable types.
|
||||
* - `"throw"` — Default. Unrepresentable types throw an error
|
||||
* - `"any"` — Unrepresentable types become `{}` */
|
||||
@@ -62,7 +60,7 @@ interface Seen {
|
||||
}
|
||||
export declare class JSONSchemaGenerator {
|
||||
metadataRegistry: $ZodRegistry<Record<string, any>>;
|
||||
target: "draft-4" | "draft-7" | "draft-2020-12" | "openapi-3.0";
|
||||
target: "draft-7" | "draft-2020-12";
|
||||
unrepresentable: "throw" | "any";
|
||||
override: (ctx: {
|
||||
zodSchema: schemas.$ZodTypes;
|
||||
|
||||
+3
-5
@@ -7,10 +7,8 @@ interface JSONSchemaGeneratorParams {
|
||||
metadata?: $ZodRegistry<Record<string, any>>;
|
||||
/** The JSON Schema version to target.
|
||||
* - `"draft-2020-12"` — Default. JSON Schema Draft 2020-12
|
||||
* - `"draft-7"` — JSON Schema Draft 7
|
||||
* - `"draft-4"` — JSON Schema Draft 4
|
||||
* - `"openapi-3.0"` — OpenAPI 3.0 Schema Object */
|
||||
target?: "draft-4" | "draft-7" | "draft-2020-12" | "openapi-3.0";
|
||||
* - `"draft-7"` — JSON Schema Draft 7 */
|
||||
target?: "draft-7" | "draft-2020-12";
|
||||
/** How to handle unrepresentable types.
|
||||
* - `"throw"` — Default. Unrepresentable types throw an error
|
||||
* - `"any"` — Unrepresentable types become `{}` */
|
||||
@@ -62,7 +60,7 @@ interface Seen {
|
||||
}
|
||||
export declare class JSONSchemaGenerator {
|
||||
metadataRegistry: $ZodRegistry<Record<string, any>>;
|
||||
target: "draft-4" | "draft-7" | "draft-2020-12" | "openapi-3.0";
|
||||
target: "draft-7" | "draft-2020-12";
|
||||
unrepresentable: "throw" | "any";
|
||||
override: (ctx: {
|
||||
zodSchema: schemas.$ZodTypes;
|
||||
|
||||
+120
-149
@@ -79,9 +79,7 @@ export class JSONSchemaGenerator {
|
||||
else if (regexes.length > 1) {
|
||||
result.schema.allOf = [
|
||||
...regexes.map((regex) => ({
|
||||
...(this.target === "draft-7" || this.target === "draft-4" || this.target === "openapi-3.0"
|
||||
? { type: "string" }
|
||||
: {}),
|
||||
...(this.target === "draft-7" ? { type: "string" } : {}),
|
||||
pattern: regex.source,
|
||||
})),
|
||||
];
|
||||
@@ -96,36 +94,22 @@ export class JSONSchemaGenerator {
|
||||
json.type = "integer";
|
||||
else
|
||||
json.type = "number";
|
||||
if (typeof exclusiveMinimum === "number") {
|
||||
if (this.target === "draft-4" || this.target === "openapi-3.0") {
|
||||
json.minimum = exclusiveMinimum;
|
||||
json.exclusiveMinimum = true;
|
||||
}
|
||||
else {
|
||||
json.exclusiveMinimum = exclusiveMinimum;
|
||||
}
|
||||
}
|
||||
if (typeof exclusiveMinimum === "number")
|
||||
json.exclusiveMinimum = exclusiveMinimum;
|
||||
if (typeof minimum === "number") {
|
||||
json.minimum = minimum;
|
||||
if (typeof exclusiveMinimum === "number" && this.target !== "draft-4") {
|
||||
if (typeof exclusiveMinimum === "number") {
|
||||
if (exclusiveMinimum >= minimum)
|
||||
delete json.minimum;
|
||||
else
|
||||
delete json.exclusiveMinimum;
|
||||
}
|
||||
}
|
||||
if (typeof exclusiveMaximum === "number") {
|
||||
if (this.target === "draft-4" || this.target === "openapi-3.0") {
|
||||
json.maximum = exclusiveMaximum;
|
||||
json.exclusiveMaximum = true;
|
||||
}
|
||||
else {
|
||||
json.exclusiveMaximum = exclusiveMaximum;
|
||||
}
|
||||
}
|
||||
if (typeof exclusiveMaximum === "number")
|
||||
json.exclusiveMaximum = exclusiveMaximum;
|
||||
if (typeof maximum === "number") {
|
||||
json.maximum = maximum;
|
||||
if (typeof exclusiveMaximum === "number" && this.target !== "draft-4") {
|
||||
if (typeof exclusiveMaximum === "number") {
|
||||
if (exclusiveMaximum <= maximum)
|
||||
delete json.maximum;
|
||||
else
|
||||
@@ -154,13 +138,7 @@ export class JSONSchemaGenerator {
|
||||
break;
|
||||
}
|
||||
case "null": {
|
||||
if (this.target === "openapi-3.0") {
|
||||
_json.type = "string";
|
||||
_json.nullable = true;
|
||||
_json.enum = [null];
|
||||
}
|
||||
else
|
||||
_json.type = "null";
|
||||
_json.type = "null";
|
||||
break;
|
||||
}
|
||||
case "any": {
|
||||
@@ -248,19 +226,10 @@ export class JSONSchemaGenerator {
|
||||
}
|
||||
case "union": {
|
||||
const json = _json;
|
||||
// Discriminated unions use oneOf (exactly one match) instead of anyOf (one or more matches)
|
||||
// because the discriminator field ensures mutual exclusivity between options in JSON Schema
|
||||
const isDiscriminated = def.discriminator !== undefined;
|
||||
const options = def.options.map((x, i) => this.process(x, {
|
||||
json.anyOf = def.options.map((x, i) => this.process(x, {
|
||||
...params,
|
||||
path: [...params.path, isDiscriminated ? "oneOf" : "anyOf", i],
|
||||
path: [...params.path, "anyOf", i],
|
||||
}));
|
||||
if (isDiscriminated) {
|
||||
json.oneOf = options;
|
||||
}
|
||||
else {
|
||||
json.anyOf = options;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "intersection": {
|
||||
@@ -284,42 +253,32 @@ export class JSONSchemaGenerator {
|
||||
case "tuple": {
|
||||
const json = _json;
|
||||
json.type = "array";
|
||||
const prefixPath = this.target === "draft-2020-12" ? "prefixItems" : "items";
|
||||
const restPath = this.target === "draft-2020-12" ? "items" : this.target === "openapi-3.0" ? "items" : "additionalItems";
|
||||
const prefixItems = def.items.map((x, i) => this.process(x, {
|
||||
...params,
|
||||
path: [...params.path, prefixPath, i],
|
||||
}));
|
||||
const rest = def.rest
|
||||
? this.process(def.rest, {
|
||||
...params,
|
||||
path: [...params.path, restPath, ...(this.target === "openapi-3.0" ? [def.items.length] : [])],
|
||||
})
|
||||
: null;
|
||||
const prefixItems = def.items.map((x, i) => this.process(x, { ...params, path: [...params.path, "prefixItems", i] }));
|
||||
if (this.target === "draft-2020-12") {
|
||||
json.prefixItems = prefixItems;
|
||||
if (rest) {
|
||||
json.items = rest;
|
||||
}
|
||||
}
|
||||
else if (this.target === "openapi-3.0") {
|
||||
json.items = {
|
||||
anyOf: prefixItems,
|
||||
};
|
||||
if (rest) {
|
||||
json.items.anyOf.push(rest);
|
||||
}
|
||||
json.minItems = prefixItems.length;
|
||||
if (!rest) {
|
||||
json.maxItems = prefixItems.length;
|
||||
}
|
||||
}
|
||||
else {
|
||||
json.items = prefixItems;
|
||||
if (rest) {
|
||||
}
|
||||
if (def.rest) {
|
||||
const rest = this.process(def.rest, {
|
||||
...params,
|
||||
path: [...params.path, "items"],
|
||||
});
|
||||
if (this.target === "draft-2020-12") {
|
||||
json.items = rest;
|
||||
}
|
||||
else {
|
||||
json.additionalItems = rest;
|
||||
}
|
||||
}
|
||||
// additionalItems
|
||||
if (def.rest) {
|
||||
json.items = this.process(def.rest, {
|
||||
...params,
|
||||
path: [...params.path, "items"],
|
||||
});
|
||||
}
|
||||
// length
|
||||
const { minimum, maximum } = schema._zod.bag;
|
||||
if (typeof minimum === "number")
|
||||
@@ -331,12 +290,7 @@ export class JSONSchemaGenerator {
|
||||
case "record": {
|
||||
const json = _json;
|
||||
json.type = "object";
|
||||
if (this.target === "draft-7" || this.target === "draft-2020-12") {
|
||||
json.propertyNames = this.process(def.keyType, {
|
||||
...params,
|
||||
path: [...params.path, "propertyNames"],
|
||||
});
|
||||
}
|
||||
json.propertyNames = this.process(def.keyType, { ...params, path: [...params.path, "propertyNames"] });
|
||||
json.additionalProperties = this.process(def.valueType, {
|
||||
...params,
|
||||
path: [...params.path, "additionalProperties"],
|
||||
@@ -396,12 +350,7 @@ export class JSONSchemaGenerator {
|
||||
else if (vals.length === 1) {
|
||||
const val = vals[0];
|
||||
json.type = val === null ? "null" : typeof val;
|
||||
if (this.target === "draft-4" || this.target === "openapi-3.0") {
|
||||
json.enum = [val];
|
||||
}
|
||||
else {
|
||||
json.const = val;
|
||||
}
|
||||
json.const = val;
|
||||
}
|
||||
else {
|
||||
if (vals.every((v) => typeof v === "number"))
|
||||
@@ -456,13 +405,7 @@ export class JSONSchemaGenerator {
|
||||
}
|
||||
case "nullable": {
|
||||
const inner = this.process(def.innerType, params);
|
||||
if (this.target === "openapi-3.0") {
|
||||
result.ref = def.innerType;
|
||||
_json.nullable = true;
|
||||
}
|
||||
else {
|
||||
_json.anyOf = [inner, { type: "null" }];
|
||||
}
|
||||
_json.anyOf = [inner, { type: "null" }];
|
||||
break;
|
||||
}
|
||||
case "nonoptional": {
|
||||
@@ -552,12 +495,6 @@ export class JSONSchemaGenerator {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "function": {
|
||||
if (this.unrepresentable === "throw") {
|
||||
throw new Error("Function types cannot be represented in JSON Schema");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
def;
|
||||
}
|
||||
@@ -709,8 +646,7 @@ export class JSONSchemaGenerator {
|
||||
flattenRef(ref, params);
|
||||
// merge referenced schema into current
|
||||
const refSchema = this.seen.get(ref).schema;
|
||||
if (refSchema.$ref &&
|
||||
(params.target === "draft-7" || params.target === "draft-4" || params.target === "openapi-3.0")) {
|
||||
if (refSchema.$ref && params.target === "draft-7") {
|
||||
schema.allOf = schema.allOf ?? [];
|
||||
schema.allOf.push(refSchema);
|
||||
}
|
||||
@@ -737,14 +673,7 @@ export class JSONSchemaGenerator {
|
||||
else if (this.target === "draft-7") {
|
||||
result.$schema = "http://json-schema.org/draft-07/schema#";
|
||||
}
|
||||
else if (this.target === "draft-4") {
|
||||
result.$schema = "http://json-schema.org/draft-04/schema#";
|
||||
}
|
||||
else if (this.target === "openapi-3.0") {
|
||||
// OpenAPI 3.0 schema objects should not include a $schema property
|
||||
}
|
||||
else {
|
||||
// @ts-ignore
|
||||
console.warn(`Invalid target: ${this.target}`);
|
||||
}
|
||||
if (params.external?.uri) {
|
||||
@@ -824,55 +753,97 @@ function isTransforming(_schema, _ctx) {
|
||||
if (ctx.seen.has(_schema))
|
||||
return false;
|
||||
ctx.seen.add(_schema);
|
||||
const def = _schema._zod.def;
|
||||
if (def.type === "transform")
|
||||
return true;
|
||||
if (def.type === "array")
|
||||
return isTransforming(def.element, ctx);
|
||||
if (def.type === "set")
|
||||
return isTransforming(def.valueType, ctx);
|
||||
if (def.type === "lazy")
|
||||
return isTransforming(def.getter(), ctx);
|
||||
if (def.type === "promise" ||
|
||||
def.type === "optional" ||
|
||||
def.type === "nonoptional" ||
|
||||
def.type === "nullable" ||
|
||||
def.type === "readonly" ||
|
||||
def.type === "default" ||
|
||||
def.type === "prefault") {
|
||||
return isTransforming(def.innerType, ctx);
|
||||
}
|
||||
if (def.type === "intersection") {
|
||||
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
||||
}
|
||||
if (def.type === "record" || def.type === "map") {
|
||||
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
||||
}
|
||||
if (def.type === "pipe") {
|
||||
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
||||
}
|
||||
if (def.type === "object") {
|
||||
for (const key in def.shape) {
|
||||
if (isTransforming(def.shape[key], ctx))
|
||||
return true;
|
||||
const schema = _schema;
|
||||
const def = schema._zod.def;
|
||||
switch (def.type) {
|
||||
case "string":
|
||||
case "number":
|
||||
case "bigint":
|
||||
case "boolean":
|
||||
case "date":
|
||||
case "symbol":
|
||||
case "undefined":
|
||||
case "null":
|
||||
case "any":
|
||||
case "unknown":
|
||||
case "never":
|
||||
case "void":
|
||||
case "literal":
|
||||
case "enum":
|
||||
case "nan":
|
||||
case "file":
|
||||
case "template_literal":
|
||||
return false;
|
||||
case "array": {
|
||||
return isTransforming(def.element, ctx);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (def.type === "union") {
|
||||
for (const option of def.options) {
|
||||
if (isTransforming(option, ctx))
|
||||
return true;
|
||||
case "object": {
|
||||
for (const key in def.shape) {
|
||||
if (isTransforming(def.shape[key], ctx))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (def.type === "tuple") {
|
||||
for (const item of def.items) {
|
||||
if (isTransforming(item, ctx))
|
||||
return true;
|
||||
case "union": {
|
||||
for (const option of def.options) {
|
||||
if (isTransforming(option, ctx))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (def.rest && isTransforming(def.rest, ctx))
|
||||
case "intersection": {
|
||||
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
||||
}
|
||||
case "tuple": {
|
||||
for (const item of def.items) {
|
||||
if (isTransforming(item, ctx))
|
||||
return true;
|
||||
}
|
||||
if (def.rest && isTransforming(def.rest, ctx))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
case "record": {
|
||||
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
||||
}
|
||||
case "map": {
|
||||
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
||||
}
|
||||
case "set": {
|
||||
return isTransforming(def.valueType, ctx);
|
||||
}
|
||||
// inner types
|
||||
case "promise":
|
||||
case "optional":
|
||||
case "nonoptional":
|
||||
case "nullable":
|
||||
case "readonly":
|
||||
return isTransforming(def.innerType, ctx);
|
||||
case "lazy":
|
||||
return isTransforming(def.getter(), ctx);
|
||||
case "default": {
|
||||
return isTransforming(def.innerType, ctx);
|
||||
}
|
||||
case "prefault": {
|
||||
return isTransforming(def.innerType, ctx);
|
||||
}
|
||||
case "custom": {
|
||||
return false;
|
||||
}
|
||||
case "transform": {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
case "pipe": {
|
||||
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
||||
}
|
||||
case "success": {
|
||||
return false;
|
||||
}
|
||||
case "catch": {
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
def;
|
||||
}
|
||||
return false;
|
||||
throw new Error(`Unknown schema type: ${def.type}`);
|
||||
}
|
||||
|
||||
+101
-231
@@ -14,18 +14,13 @@ exports.nullish = nullish;
|
||||
exports.cleanRegex = cleanRegex;
|
||||
exports.floatSafeRemainder = floatSafeRemainder;
|
||||
exports.defineLazy = defineLazy;
|
||||
exports.objectClone = objectClone;
|
||||
exports.assignProp = assignProp;
|
||||
exports.mergeDefs = mergeDefs;
|
||||
exports.cloneDef = cloneDef;
|
||||
exports.getElementAtPath = getElementAtPath;
|
||||
exports.promiseAllObject = promiseAllObject;
|
||||
exports.randomString = randomString;
|
||||
exports.esc = esc;
|
||||
exports.slugify = slugify;
|
||||
exports.isObject = isObject;
|
||||
exports.isPlainObject = isPlainObject;
|
||||
exports.shallowClone = shallowClone;
|
||||
exports.numKeys = numKeys;
|
||||
exports.escapeRegex = escapeRegex;
|
||||
exports.clone = clone;
|
||||
@@ -36,7 +31,6 @@ exports.optionalKeys = optionalKeys;
|
||||
exports.pick = pick;
|
||||
exports.omit = omit;
|
||||
exports.extend = extend;
|
||||
exports.safeExtend = safeExtend;
|
||||
exports.merge = merge;
|
||||
exports.partial = partial;
|
||||
exports.required = required;
|
||||
@@ -48,12 +42,6 @@ exports.getSizableOrigin = getSizableOrigin;
|
||||
exports.getLengthableOrigin = getLengthableOrigin;
|
||||
exports.issue = issue;
|
||||
exports.cleanEnum = cleanEnum;
|
||||
exports.base64ToUint8Array = base64ToUint8Array;
|
||||
exports.uint8ArrayToBase64 = uint8ArrayToBase64;
|
||||
exports.base64urlToUint8Array = base64urlToUint8Array;
|
||||
exports.uint8ArrayToBase64url = uint8ArrayToBase64url;
|
||||
exports.hexToUint8Array = hexToUint8Array;
|
||||
exports.uint8ArrayToHex = uint8ArrayToHex;
|
||||
// functions
|
||||
function assertEqual(val) {
|
||||
return val;
|
||||
@@ -104,33 +92,22 @@ function cleanRegex(source) {
|
||||
}
|
||||
function floatSafeRemainder(val, step) {
|
||||
const valDecCount = (val.toString().split(".")[1] || "").length;
|
||||
const stepString = step.toString();
|
||||
let stepDecCount = (stepString.split(".")[1] || "").length;
|
||||
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
||||
const match = stepString.match(/\d?e-(\d?)/);
|
||||
if (match?.[1]) {
|
||||
stepDecCount = Number.parseInt(match[1]);
|
||||
}
|
||||
}
|
||||
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
||||
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
||||
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
||||
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
||||
return (valInt % stepInt) / 10 ** decCount;
|
||||
}
|
||||
const EVALUATING = Symbol("evaluating");
|
||||
function defineLazy(object, key, getter) {
|
||||
let value = undefined;
|
||||
const set = false;
|
||||
Object.defineProperty(object, key, {
|
||||
get() {
|
||||
if (value === EVALUATING) {
|
||||
// Circular reference detected, return undefined to break the cycle
|
||||
return undefined;
|
||||
if (!set) {
|
||||
const value = getter();
|
||||
object[key] = value;
|
||||
return value;
|
||||
}
|
||||
if (value === undefined) {
|
||||
value = EVALUATING;
|
||||
value = getter();
|
||||
}
|
||||
return value;
|
||||
throw new Error("cached value already set");
|
||||
},
|
||||
set(v) {
|
||||
Object.defineProperty(object, key, {
|
||||
@@ -142,9 +119,6 @@ function defineLazy(object, key, getter) {
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
function objectClone(obj) {
|
||||
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
||||
}
|
||||
function assignProp(target, prop, value) {
|
||||
Object.defineProperty(target, prop, {
|
||||
value,
|
||||
@@ -153,17 +127,6 @@ function assignProp(target, prop, value) {
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
function mergeDefs(...defs) {
|
||||
const mergedDescriptors = {};
|
||||
for (const def of defs) {
|
||||
const descriptors = Object.getOwnPropertyDescriptors(def);
|
||||
Object.assign(mergedDescriptors, descriptors);
|
||||
}
|
||||
return Object.defineProperties({}, mergedDescriptors);
|
||||
}
|
||||
function cloneDef(schema) {
|
||||
return mergeDefs(schema._zod.def);
|
||||
}
|
||||
function getElementAtPath(obj, path) {
|
||||
if (!path)
|
||||
return obj;
|
||||
@@ -191,20 +154,13 @@ function randomString(length = 10) {
|
||||
function esc(str) {
|
||||
return JSON.stringify(str);
|
||||
}
|
||||
function slugify(input) {
|
||||
return input
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, "")
|
||||
.replace(/[\s_-]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
}
|
||||
exports.captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
||||
exports.captureStackTrace = Error.captureStackTrace
|
||||
? Error.captureStackTrace
|
||||
: (..._args) => { };
|
||||
function isObject(data) {
|
||||
return typeof data === "object" && data !== null && !Array.isArray(data);
|
||||
}
|
||||
exports.allowsEval = cached(() => {
|
||||
// @ts-ignore
|
||||
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
||||
return false;
|
||||
}
|
||||
@@ -224,8 +180,6 @@ function isPlainObject(o) {
|
||||
const ctor = o.constructor;
|
||||
if (ctor === undefined)
|
||||
return true;
|
||||
if (typeof ctor !== "function")
|
||||
return true;
|
||||
// modified prototype
|
||||
const prot = ctor.prototype;
|
||||
if (isObject(prot) === false)
|
||||
@@ -236,13 +190,6 @@ function isPlainObject(o) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function shallowClone(o) {
|
||||
if (isPlainObject(o))
|
||||
return { ...o };
|
||||
if (Array.isArray(o))
|
||||
return [...o];
|
||||
return o;
|
||||
}
|
||||
function numKeys(data) {
|
||||
let keyCount = 0;
|
||||
for (const key in data) {
|
||||
@@ -288,7 +235,6 @@ const getParsedType = (data) => {
|
||||
if (typeof Date !== "undefined" && data instanceof Date) {
|
||||
return "date";
|
||||
}
|
||||
// @ts-ignore
|
||||
if (typeof File !== "undefined" && data instanceof File) {
|
||||
return "file";
|
||||
}
|
||||
@@ -383,68 +329,44 @@ exports.BIGINT_FORMAT_RANGES = {
|
||||
uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt("18446744073709551615")],
|
||||
};
|
||||
function pick(schema, mask) {
|
||||
const currDef = schema._zod.def;
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const newShape = {};
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
newShape[key] = currDef.shape[key];
|
||||
}
|
||||
assignProp(this, "shape", newShape); // self-caching
|
||||
return newShape;
|
||||
},
|
||||
const newShape = {};
|
||||
const currDef = schema._zod.def; //.shape;
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// pick key
|
||||
newShape[key] = currDef.shape[key];
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape: newShape,
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
function omit(schema, mask) {
|
||||
const currDef = schema._zod.def;
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const newShape = { ...schema._zod.def.shape };
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
delete newShape[key];
|
||||
}
|
||||
assignProp(this, "shape", newShape); // self-caching
|
||||
return newShape;
|
||||
},
|
||||
const newShape = { ...schema._zod.def.shape };
|
||||
const currDef = schema._zod.def; //.shape;
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
delete newShape[key];
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape: newShape,
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
function extend(schema, shape) {
|
||||
if (!isPlainObject(shape)) {
|
||||
throw new Error("Invalid input to extend: expected a plain object");
|
||||
}
|
||||
const checks = schema._zod.def.checks;
|
||||
const hasChecks = checks && checks.length > 0;
|
||||
if (hasChecks) {
|
||||
throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
|
||||
}
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const _shape = { ...schema._zod.def.shape, ...shape };
|
||||
assignProp(this, "shape", _shape); // self-caching
|
||||
return _shape;
|
||||
},
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
function safeExtend(schema, shape) {
|
||||
if (!isPlainObject(shape)) {
|
||||
throw new Error("Invalid input to safeExtend: expected a plain object");
|
||||
}
|
||||
const def = {
|
||||
...schema._zod.def,
|
||||
get shape() {
|
||||
@@ -452,106 +374,95 @@ function safeExtend(schema, shape) {
|
||||
assignProp(this, "shape", _shape); // self-caching
|
||||
return _shape;
|
||||
},
|
||||
checks: schema._zod.def.checks,
|
||||
checks: [], // delete existing checks
|
||||
};
|
||||
return clone(schema, def);
|
||||
}
|
||||
function merge(a, b) {
|
||||
const def = mergeDefs(a._zod.def, {
|
||||
return clone(a, {
|
||||
...a._zod.def,
|
||||
get shape() {
|
||||
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
||||
assignProp(this, "shape", _shape); // self-caching
|
||||
return _shape;
|
||||
},
|
||||
get catchall() {
|
||||
return b._zod.def.catchall;
|
||||
},
|
||||
catchall: b._zod.def.catchall,
|
||||
checks: [], // delete existing checks
|
||||
});
|
||||
return clone(a, def);
|
||||
}
|
||||
function partial(Class, schema, mask) {
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in oldShape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in oldShape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
}
|
||||
assignProp(this, "shape", shape); // self-caching
|
||||
return shape;
|
||||
},
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape,
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
function required(Class, schema, mask) {
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
assignProp(this, "shape", shape); // self-caching
|
||||
return shape;
|
||||
},
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape,
|
||||
// optional: [],
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
||||
function aborted(x, startIndex = 0) {
|
||||
if (x.aborted === true)
|
||||
return true;
|
||||
for (let i = startIndex; i < x.issues.length; i++) {
|
||||
if (x.issues[i]?.continue !== true) {
|
||||
if (x.issues[i]?.continue !== true)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -590,7 +501,6 @@ function getSizableOrigin(input) {
|
||||
return "set";
|
||||
if (input instanceof Map)
|
||||
return "map";
|
||||
// @ts-ignore
|
||||
if (input instanceof File)
|
||||
return "file";
|
||||
return "unknown";
|
||||
@@ -622,46 +532,6 @@ function cleanEnum(obj) {
|
||||
})
|
||||
.map((el) => el[1]);
|
||||
}
|
||||
// Codec utility functions
|
||||
function base64ToUint8Array(base64) {
|
||||
const binaryString = atob(base64);
|
||||
const bytes = new Uint8Array(binaryString.length);
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
function uint8ArrayToBase64(bytes) {
|
||||
let binaryString = "";
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
binaryString += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binaryString);
|
||||
}
|
||||
function base64urlToUint8Array(base64url) {
|
||||
const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
||||
const padding = "=".repeat((4 - (base64.length % 4)) % 4);
|
||||
return base64ToUint8Array(base64 + padding);
|
||||
}
|
||||
function uint8ArrayToBase64url(bytes) {
|
||||
return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||
}
|
||||
function hexToUint8Array(hex) {
|
||||
const cleanHex = hex.replace(/^0x/, "");
|
||||
if (cleanHex.length % 2 !== 0) {
|
||||
throw new Error("Invalid hex string length");
|
||||
}
|
||||
const bytes = new Uint8Array(cleanHex.length / 2);
|
||||
for (let i = 0; i < cleanHex.length; i += 2) {
|
||||
bytes[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
function uint8ArrayToHex(bytes) {
|
||||
return Array.from(bytes)
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
}
|
||||
// instanceof
|
||||
class Class {
|
||||
constructor(..._args) { }
|
||||
|
||||
-15
@@ -6,9 +6,6 @@ export type JSONType = string | number | boolean | null | JSONType[] | {
|
||||
[key: string]: JSONType;
|
||||
};
|
||||
export type JWTAlgorithm = "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "PS256" | "PS384" | "PS512" | "EdDSA" | (string & {});
|
||||
export type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha384" | "sha512";
|
||||
export type HashEncoding = "hex" | "base64" | "base64url";
|
||||
export type HashFormat = `${HashAlgorithm}_${HashEncoding}`;
|
||||
export type IPVersion = "v4" | "v6";
|
||||
export type MimeTypes = "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "application/javascript" | "application/pdf" | "application/zip" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/octet-stream" | "application/graphql" | "text/html" | "text/plain" | "text/css" | "text/javascript" | "text/csv" | "image/png" | "image/jpeg" | "image/gif" | "image/svg+xml" | "image/webp" | "audio/mpeg" | "audio/ogg" | "audio/wav" | "audio/webm" | "video/mp4" | "video/webm" | "video/ogg" | "font/woff" | "font/woff2" | "font/ttf" | "font/otf" | "multipart/form-data" | (string & {});
|
||||
export type ParsedTypes = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "file" | "date" | "array" | "map" | "set" | "nan" | "null" | "promise";
|
||||
@@ -123,24 +120,19 @@ export declare function nullish(input: any): boolean;
|
||||
export declare function cleanRegex(source: string): string;
|
||||
export declare function floatSafeRemainder(val: number, step: number): number;
|
||||
export declare function defineLazy<T, K extends keyof T>(object: T, key: K, getter: () => T[K]): void;
|
||||
export declare function objectClone(obj: object): any;
|
||||
export declare function assignProp<T extends object, K extends PropertyKey>(target: T, prop: K, value: K extends keyof T ? T[K] : any): void;
|
||||
export declare function mergeDefs(...defs: Record<string, any>[]): any;
|
||||
export declare function cloneDef(schema: schemas.$ZodType): any;
|
||||
export declare function getElementAtPath(obj: any, path: (string | number)[] | null | undefined): any;
|
||||
export declare function promiseAllObject<T extends object>(promisesObj: T): Promise<{
|
||||
[k in keyof T]: Awaited<T[k]>;
|
||||
}>;
|
||||
export declare function randomString(length?: number): string;
|
||||
export declare function esc(str: string): string;
|
||||
export declare function slugify(input: string): string;
|
||||
export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
|
||||
export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
|
||||
export declare const allowsEval: {
|
||||
value: boolean;
|
||||
};
|
||||
export declare function isPlainObject(o: any): o is Record<PropertyKey, unknown>;
|
||||
export declare function shallowClone(o: any): any;
|
||||
export declare function numKeys(data: any): number;
|
||||
export declare const getParsedType: (data: any) => ParsedTypes;
|
||||
export declare const propertyKeyTypes: Set<string>;
|
||||
@@ -171,7 +163,6 @@ export declare const BIGINT_FORMAT_RANGES: Record<checks.$ZodBigIntFormats, [big
|
||||
export declare function pick(schema: schemas.$ZodObject, mask: Record<string, unknown>): any;
|
||||
export declare function omit(schema: schemas.$ZodObject, mask: object): any;
|
||||
export declare function extend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any;
|
||||
export declare function safeExtend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any;
|
||||
export declare function merge(a: schemas.$ZodObject, b: schemas.$ZodObject): any;
|
||||
export declare function partial(Class: SchemaClass<schemas.$ZodOptional> | null, schema: schemas.$ZodObject, mask: object | undefined): any;
|
||||
export declare function required(Class: SchemaClass<schemas.$ZodNonOptional>, schema: schemas.$ZodObject, mask: object | undefined): any;
|
||||
@@ -187,12 +178,6 @@ export declare function getLengthableOrigin(input: any): "array" | "string" | "u
|
||||
export declare function issue(_iss: string, input: any, inst: any): errors.$ZodRawIssue;
|
||||
export declare function issue(_iss: errors.$ZodRawIssue): errors.$ZodRawIssue;
|
||||
export declare function cleanEnum(obj: Record<string, EnumValue>): EnumValue[];
|
||||
export declare function base64ToUint8Array(base64: string): InstanceType<typeof Uint8Array>;
|
||||
export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
|
||||
export declare function base64urlToUint8Array(base64url: string): InstanceType<typeof Uint8Array>;
|
||||
export declare function uint8ArrayToBase64url(bytes: Uint8Array): string;
|
||||
export declare function hexToUint8Array(hex: string): InstanceType<typeof Uint8Array>;
|
||||
export declare function uint8ArrayToHex(bytes: Uint8Array): string;
|
||||
export declare abstract class Class {
|
||||
constructor(..._args: any[]);
|
||||
}
|
||||
|
||||
-15
@@ -6,9 +6,6 @@ export type JSONType = string | number | boolean | null | JSONType[] | {
|
||||
[key: string]: JSONType;
|
||||
};
|
||||
export type JWTAlgorithm = "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "PS256" | "PS384" | "PS512" | "EdDSA" | (string & {});
|
||||
export type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha384" | "sha512";
|
||||
export type HashEncoding = "hex" | "base64" | "base64url";
|
||||
export type HashFormat = `${HashAlgorithm}_${HashEncoding}`;
|
||||
export type IPVersion = "v4" | "v6";
|
||||
export type MimeTypes = "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "application/javascript" | "application/pdf" | "application/zip" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/octet-stream" | "application/graphql" | "text/html" | "text/plain" | "text/css" | "text/javascript" | "text/csv" | "image/png" | "image/jpeg" | "image/gif" | "image/svg+xml" | "image/webp" | "audio/mpeg" | "audio/ogg" | "audio/wav" | "audio/webm" | "video/mp4" | "video/webm" | "video/ogg" | "font/woff" | "font/woff2" | "font/ttf" | "font/otf" | "multipart/form-data" | (string & {});
|
||||
export type ParsedTypes = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "file" | "date" | "array" | "map" | "set" | "nan" | "null" | "promise";
|
||||
@@ -123,24 +120,19 @@ export declare function nullish(input: any): boolean;
|
||||
export declare function cleanRegex(source: string): string;
|
||||
export declare function floatSafeRemainder(val: number, step: number): number;
|
||||
export declare function defineLazy<T, K extends keyof T>(object: T, key: K, getter: () => T[K]): void;
|
||||
export declare function objectClone(obj: object): any;
|
||||
export declare function assignProp<T extends object, K extends PropertyKey>(target: T, prop: K, value: K extends keyof T ? T[K] : any): void;
|
||||
export declare function mergeDefs(...defs: Record<string, any>[]): any;
|
||||
export declare function cloneDef(schema: schemas.$ZodType): any;
|
||||
export declare function getElementAtPath(obj: any, path: (string | number)[] | null | undefined): any;
|
||||
export declare function promiseAllObject<T extends object>(promisesObj: T): Promise<{
|
||||
[k in keyof T]: Awaited<T[k]>;
|
||||
}>;
|
||||
export declare function randomString(length?: number): string;
|
||||
export declare function esc(str: string): string;
|
||||
export declare function slugify(input: string): string;
|
||||
export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
|
||||
export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
|
||||
export declare const allowsEval: {
|
||||
value: boolean;
|
||||
};
|
||||
export declare function isPlainObject(o: any): o is Record<PropertyKey, unknown>;
|
||||
export declare function shallowClone(o: any): any;
|
||||
export declare function numKeys(data: any): number;
|
||||
export declare const getParsedType: (data: any) => ParsedTypes;
|
||||
export declare const propertyKeyTypes: Set<string>;
|
||||
@@ -171,7 +163,6 @@ export declare const BIGINT_FORMAT_RANGES: Record<checks.$ZodBigIntFormats, [big
|
||||
export declare function pick(schema: schemas.$ZodObject, mask: Record<string, unknown>): any;
|
||||
export declare function omit(schema: schemas.$ZodObject, mask: object): any;
|
||||
export declare function extend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any;
|
||||
export declare function safeExtend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any;
|
||||
export declare function merge(a: schemas.$ZodObject, b: schemas.$ZodObject): any;
|
||||
export declare function partial(Class: SchemaClass<schemas.$ZodOptional> | null, schema: schemas.$ZodObject, mask: object | undefined): any;
|
||||
export declare function required(Class: SchemaClass<schemas.$ZodNonOptional>, schema: schemas.$ZodObject, mask: object | undefined): any;
|
||||
@@ -187,12 +178,6 @@ export declare function getLengthableOrigin(input: any): "array" | "string" | "u
|
||||
export declare function issue(_iss: string, input: any, inst: any): errors.$ZodRawIssue;
|
||||
export declare function issue(_iss: errors.$ZodRawIssue): errors.$ZodRawIssue;
|
||||
export declare function cleanEnum(obj: Record<string, EnumValue>): EnumValue[];
|
||||
export declare function base64ToUint8Array(base64: string): InstanceType<typeof Uint8Array>;
|
||||
export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
|
||||
export declare function base64urlToUint8Array(base64url: string): InstanceType<typeof Uint8Array>;
|
||||
export declare function uint8ArrayToBase64url(bytes: Uint8Array): string;
|
||||
export declare function hexToUint8Array(hex: string): InstanceType<typeof Uint8Array>;
|
||||
export declare function uint8ArrayToHex(bytes: Uint8Array): string;
|
||||
export declare abstract class Class {
|
||||
constructor(..._args: any[]);
|
||||
}
|
||||
|
||||
+101
-219
@@ -48,33 +48,22 @@ export function cleanRegex(source) {
|
||||
}
|
||||
export function floatSafeRemainder(val, step) {
|
||||
const valDecCount = (val.toString().split(".")[1] || "").length;
|
||||
const stepString = step.toString();
|
||||
let stepDecCount = (stepString.split(".")[1] || "").length;
|
||||
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
||||
const match = stepString.match(/\d?e-(\d?)/);
|
||||
if (match?.[1]) {
|
||||
stepDecCount = Number.parseInt(match[1]);
|
||||
}
|
||||
}
|
||||
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
||||
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
||||
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
||||
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
||||
return (valInt % stepInt) / 10 ** decCount;
|
||||
}
|
||||
const EVALUATING = Symbol("evaluating");
|
||||
export function defineLazy(object, key, getter) {
|
||||
let value = undefined;
|
||||
const set = false;
|
||||
Object.defineProperty(object, key, {
|
||||
get() {
|
||||
if (value === EVALUATING) {
|
||||
// Circular reference detected, return undefined to break the cycle
|
||||
return undefined;
|
||||
if (!set) {
|
||||
const value = getter();
|
||||
object[key] = value;
|
||||
return value;
|
||||
}
|
||||
if (value === undefined) {
|
||||
value = EVALUATING;
|
||||
value = getter();
|
||||
}
|
||||
return value;
|
||||
throw new Error("cached value already set");
|
||||
},
|
||||
set(v) {
|
||||
Object.defineProperty(object, key, {
|
||||
@@ -86,9 +75,6 @@ export function defineLazy(object, key, getter) {
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
export function objectClone(obj) {
|
||||
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
||||
}
|
||||
export function assignProp(target, prop, value) {
|
||||
Object.defineProperty(target, prop, {
|
||||
value,
|
||||
@@ -97,17 +83,6 @@ export function assignProp(target, prop, value) {
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
export function mergeDefs(...defs) {
|
||||
const mergedDescriptors = {};
|
||||
for (const def of defs) {
|
||||
const descriptors = Object.getOwnPropertyDescriptors(def);
|
||||
Object.assign(mergedDescriptors, descriptors);
|
||||
}
|
||||
return Object.defineProperties({}, mergedDescriptors);
|
||||
}
|
||||
export function cloneDef(schema) {
|
||||
return mergeDefs(schema._zod.def);
|
||||
}
|
||||
export function getElementAtPath(obj, path) {
|
||||
if (!path)
|
||||
return obj;
|
||||
@@ -135,20 +110,13 @@ export function randomString(length = 10) {
|
||||
export function esc(str) {
|
||||
return JSON.stringify(str);
|
||||
}
|
||||
export function slugify(input) {
|
||||
return input
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, "")
|
||||
.replace(/[\s_-]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
}
|
||||
export const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
||||
export const captureStackTrace = Error.captureStackTrace
|
||||
? Error.captureStackTrace
|
||||
: (..._args) => { };
|
||||
export function isObject(data) {
|
||||
return typeof data === "object" && data !== null && !Array.isArray(data);
|
||||
}
|
||||
export const allowsEval = cached(() => {
|
||||
// @ts-ignore
|
||||
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
||||
return false;
|
||||
}
|
||||
@@ -168,8 +136,6 @@ export function isPlainObject(o) {
|
||||
const ctor = o.constructor;
|
||||
if (ctor === undefined)
|
||||
return true;
|
||||
if (typeof ctor !== "function")
|
||||
return true;
|
||||
// modified prototype
|
||||
const prot = ctor.prototype;
|
||||
if (isObject(prot) === false)
|
||||
@@ -180,13 +146,6 @@ export function isPlainObject(o) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
export function shallowClone(o) {
|
||||
if (isPlainObject(o))
|
||||
return { ...o };
|
||||
if (Array.isArray(o))
|
||||
return [...o];
|
||||
return o;
|
||||
}
|
||||
export function numKeys(data) {
|
||||
let keyCount = 0;
|
||||
for (const key in data) {
|
||||
@@ -232,7 +191,6 @@ export const getParsedType = (data) => {
|
||||
if (typeof Date !== "undefined" && data instanceof Date) {
|
||||
return "date";
|
||||
}
|
||||
// @ts-ignore
|
||||
if (typeof File !== "undefined" && data instanceof File) {
|
||||
return "file";
|
||||
}
|
||||
@@ -326,68 +284,44 @@ export const BIGINT_FORMAT_RANGES = {
|
||||
uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt("18446744073709551615")],
|
||||
};
|
||||
export function pick(schema, mask) {
|
||||
const currDef = schema._zod.def;
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const newShape = {};
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
newShape[key] = currDef.shape[key];
|
||||
}
|
||||
assignProp(this, "shape", newShape); // self-caching
|
||||
return newShape;
|
||||
},
|
||||
const newShape = {};
|
||||
const currDef = schema._zod.def; //.shape;
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// pick key
|
||||
newShape[key] = currDef.shape[key];
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape: newShape,
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
export function omit(schema, mask) {
|
||||
const currDef = schema._zod.def;
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const newShape = { ...schema._zod.def.shape };
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
delete newShape[key];
|
||||
}
|
||||
assignProp(this, "shape", newShape); // self-caching
|
||||
return newShape;
|
||||
},
|
||||
const newShape = { ...schema._zod.def.shape };
|
||||
const currDef = schema._zod.def; //.shape;
|
||||
for (const key in mask) {
|
||||
if (!(key in currDef.shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
delete newShape[key];
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape: newShape,
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
export function extend(schema, shape) {
|
||||
if (!isPlainObject(shape)) {
|
||||
throw new Error("Invalid input to extend: expected a plain object");
|
||||
}
|
||||
const checks = schema._zod.def.checks;
|
||||
const hasChecks = checks && checks.length > 0;
|
||||
if (hasChecks) {
|
||||
throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
|
||||
}
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const _shape = { ...schema._zod.def.shape, ...shape };
|
||||
assignProp(this, "shape", _shape); // self-caching
|
||||
return _shape;
|
||||
},
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
export function safeExtend(schema, shape) {
|
||||
if (!isPlainObject(shape)) {
|
||||
throw new Error("Invalid input to safeExtend: expected a plain object");
|
||||
}
|
||||
const def = {
|
||||
...schema._zod.def,
|
||||
get shape() {
|
||||
@@ -395,106 +329,95 @@ export function safeExtend(schema, shape) {
|
||||
assignProp(this, "shape", _shape); // self-caching
|
||||
return _shape;
|
||||
},
|
||||
checks: schema._zod.def.checks,
|
||||
checks: [], // delete existing checks
|
||||
};
|
||||
return clone(schema, def);
|
||||
}
|
||||
export function merge(a, b) {
|
||||
const def = mergeDefs(a._zod.def, {
|
||||
return clone(a, {
|
||||
...a._zod.def,
|
||||
get shape() {
|
||||
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
||||
assignProp(this, "shape", _shape); // self-caching
|
||||
return _shape;
|
||||
},
|
||||
get catchall() {
|
||||
return b._zod.def.catchall;
|
||||
},
|
||||
catchall: b._zod.def.catchall,
|
||||
checks: [], // delete existing checks
|
||||
});
|
||||
return clone(a, def);
|
||||
}
|
||||
export function partial(Class, schema, mask) {
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in oldShape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in oldShape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
}
|
||||
assignProp(this, "shape", shape); // self-caching
|
||||
return shape;
|
||||
},
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// if (oldShape[key]!._zod.optin === "optional") continue;
|
||||
shape[key] = Class
|
||||
? new Class({
|
||||
type: "optional",
|
||||
innerType: oldShape[key],
|
||||
})
|
||||
: oldShape[key];
|
||||
}
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape,
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
export function required(Class, schema, mask) {
|
||||
const def = mergeDefs(schema._zod.def, {
|
||||
get shape() {
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
const oldShape = schema._zod.def.shape;
|
||||
const shape = { ...oldShape };
|
||||
if (mask) {
|
||||
for (const key in mask) {
|
||||
if (!(key in shape)) {
|
||||
throw new Error(`Unrecognized key: "${key}"`);
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
assignProp(this, "shape", shape); // self-caching
|
||||
return shape;
|
||||
},
|
||||
if (!mask[key])
|
||||
continue;
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const key in oldShape) {
|
||||
// overwrite with non-optional
|
||||
shape[key] = new Class({
|
||||
type: "nonoptional",
|
||||
innerType: oldShape[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
return clone(schema, {
|
||||
...schema._zod.def,
|
||||
shape,
|
||||
// optional: [],
|
||||
checks: [],
|
||||
});
|
||||
return clone(schema, def);
|
||||
}
|
||||
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
||||
export function aborted(x, startIndex = 0) {
|
||||
if (x.aborted === true)
|
||||
return true;
|
||||
for (let i = startIndex; i < x.issues.length; i++) {
|
||||
if (x.issues[i]?.continue !== true) {
|
||||
if (x.issues[i]?.continue !== true)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -533,7 +456,6 @@ export function getSizableOrigin(input) {
|
||||
return "set";
|
||||
if (input instanceof Map)
|
||||
return "map";
|
||||
// @ts-ignore
|
||||
if (input instanceof File)
|
||||
return "file";
|
||||
return "unknown";
|
||||
@@ -565,46 +487,6 @@ export function cleanEnum(obj) {
|
||||
})
|
||||
.map((el) => el[1]);
|
||||
}
|
||||
// Codec utility functions
|
||||
export function base64ToUint8Array(base64) {
|
||||
const binaryString = atob(base64);
|
||||
const bytes = new Uint8Array(binaryString.length);
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
export function uint8ArrayToBase64(bytes) {
|
||||
let binaryString = "";
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
binaryString += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binaryString);
|
||||
}
|
||||
export function base64urlToUint8Array(base64url) {
|
||||
const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
||||
const padding = "=".repeat((4 - (base64.length % 4)) % 4);
|
||||
return base64ToUint8Array(base64 + padding);
|
||||
}
|
||||
export function uint8ArrayToBase64url(bytes) {
|
||||
return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||
}
|
||||
export function hexToUint8Array(hex) {
|
||||
const cleanHex = hex.replace(/^0x/, "");
|
||||
if (cleanHex.length % 2 !== 0) {
|
||||
throw new Error("Invalid hex string length");
|
||||
}
|
||||
const bytes = new Uint8Array(cleanHex.length / 2);
|
||||
for (let i = 0; i < cleanHex.length; i += 2) {
|
||||
bytes[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
export function uint8ArrayToHex(bytes) {
|
||||
return Array.from(bytes)
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
}
|
||||
// instanceof
|
||||
export class Class {
|
||||
constructor(..._args) { }
|
||||
|
||||
+2
-2
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = void 0;
|
||||
exports.version = {
|
||||
major: 4,
|
||||
minor: 1,
|
||||
patch: 13,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
export declare const version: {
|
||||
readonly major: 4;
|
||||
readonly minor: 1;
|
||||
readonly minor: 0;
|
||||
readonly patch: number;
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
export declare const version: {
|
||||
readonly major: 4;
|
||||
readonly minor: 1;
|
||||
readonly minor: 0;
|
||||
readonly patch: number;
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
export const version = {
|
||||
major: 4,
|
||||
minor: 1,
|
||||
patch: 13,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user