@cloudflare/vitest-pool-workers 0.12.6 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pool/index.mjs +4273 -205
- package/dist/pool/index.mjs.map +3 -3
- package/package.json +5 -5
package/dist/pool/index.mjs
CHANGED
|
@@ -10,6 +10,10 @@ var __esm = (fn, res) => function __init() {
|
|
|
10
10
|
var __commonJS = (cb, mod) => function __require() {
|
|
11
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
12
|
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
13
17
|
var __copyProps = (to, from, except, desc) => {
|
|
14
18
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
19
|
for (let key of __getOwnPropNames(from))
|
|
@@ -954,19 +958,19 @@ var require_range = __commonJS({
|
|
|
954
958
|
var replaceCaret = (comp, options) => {
|
|
955
959
|
debug("caret", comp, options);
|
|
956
960
|
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
957
|
-
const
|
|
961
|
+
const z = options.includePrerelease ? "-0" : "";
|
|
958
962
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
959
963
|
debug("caret", comp, _, M, m, p, pr);
|
|
960
964
|
let ret;
|
|
961
965
|
if (isX(M)) {
|
|
962
966
|
ret = "";
|
|
963
967
|
} else if (isX(m)) {
|
|
964
|
-
ret = `>=${M}.0.0${
|
|
968
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
965
969
|
} else if (isX(p)) {
|
|
966
970
|
if (M === "0") {
|
|
967
|
-
ret = `>=${M}.${m}.0${
|
|
971
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
968
972
|
} else {
|
|
969
|
-
ret = `>=${M}.${m}.0${
|
|
973
|
+
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
970
974
|
}
|
|
971
975
|
} else if (pr) {
|
|
972
976
|
debug("replaceCaret pr", pr);
|
|
@@ -983,9 +987,9 @@ var require_range = __commonJS({
|
|
|
983
987
|
debug("no pr");
|
|
984
988
|
if (M === "0") {
|
|
985
989
|
if (m === "0") {
|
|
986
|
-
ret = `>=${M}.${m}.${p}${
|
|
990
|
+
ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
|
|
987
991
|
} else {
|
|
988
|
-
ret = `>=${M}.${m}.${p}${
|
|
992
|
+
ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
|
|
989
993
|
}
|
|
990
994
|
} else {
|
|
991
995
|
ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
@@ -1140,7 +1144,7 @@ import events from "node:events";
|
|
|
1140
1144
|
import fs3 from "node:fs";
|
|
1141
1145
|
import path5 from "node:path";
|
|
1142
1146
|
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
1143
|
-
import
|
|
1147
|
+
import util3 from "node:util";
|
|
1144
1148
|
|
|
1145
1149
|
// ../../node_modules/.pnpm/birpc@0.2.14/node_modules/birpc/dist/index.mjs
|
|
1146
1150
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
@@ -1546,10 +1550,10 @@ init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
|
1546
1550
|
function stringify(value, reducers) {
|
|
1547
1551
|
const stringified = [];
|
|
1548
1552
|
const indexes = /* @__PURE__ */ new Map();
|
|
1549
|
-
const
|
|
1553
|
+
const custom2 = [];
|
|
1550
1554
|
if (reducers) {
|
|
1551
1555
|
for (const key of Object.getOwnPropertyNames(reducers)) {
|
|
1552
|
-
|
|
1556
|
+
custom2.push({ key, fn: reducers[key] });
|
|
1553
1557
|
}
|
|
1554
1558
|
}
|
|
1555
1559
|
const keys = [];
|
|
@@ -1566,7 +1570,7 @@ function stringify(value, reducers) {
|
|
|
1566
1570
|
if (indexes.has(thing)) return indexes.get(thing);
|
|
1567
1571
|
const index2 = p++;
|
|
1568
1572
|
indexes.set(thing, index2);
|
|
1569
|
-
for (const { key, fn } of
|
|
1573
|
+
for (const { key, fn } of custom2) {
|
|
1570
1574
|
const value2 = fn(thing);
|
|
1571
1575
|
if (value2) {
|
|
1572
1576
|
stringified[index2] = `["${key}",${flatten(value2)}]`;
|
|
@@ -2057,212 +2061,4271 @@ import {
|
|
|
2057
2061
|
parseWithRootPath,
|
|
2058
2062
|
PLUGINS
|
|
2059
2063
|
} from "miniflare";
|
|
2060
|
-
import { z } from "zod";
|
|
2061
2064
|
|
|
2062
|
-
//
|
|
2065
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/index.js
|
|
2063
2066
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2064
|
-
import path from "node:path";
|
|
2065
|
-
var WORKER_NAME_PREFIX = "vitest-pool-workers-";
|
|
2066
|
-
function isFileNotFoundError(e) {
|
|
2067
|
-
return typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT";
|
|
2068
|
-
}
|
|
2069
|
-
function getProjectPath(project) {
|
|
2070
|
-
return project.config.config ?? project.path;
|
|
2071
|
-
}
|
|
2072
|
-
function getRelativeProjectPath(project) {
|
|
2073
|
-
const projectPath = getProjectPath(project);
|
|
2074
|
-
if (typeof projectPath === "number") {
|
|
2075
|
-
return projectPath;
|
|
2076
|
-
} else {
|
|
2077
|
-
return path.relative("", projectPath);
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
2067
|
|
|
2081
|
-
//
|
|
2082
|
-
var
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2068
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
2069
|
+
var external_exports = {};
|
|
2070
|
+
__export(external_exports, {
|
|
2071
|
+
BRAND: () => BRAND,
|
|
2072
|
+
DIRTY: () => DIRTY,
|
|
2073
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
2074
|
+
INVALID: () => INVALID,
|
|
2075
|
+
NEVER: () => NEVER,
|
|
2076
|
+
OK: () => OK,
|
|
2077
|
+
ParseStatus: () => ParseStatus,
|
|
2078
|
+
Schema: () => ZodType,
|
|
2079
|
+
ZodAny: () => ZodAny,
|
|
2080
|
+
ZodArray: () => ZodArray,
|
|
2081
|
+
ZodBigInt: () => ZodBigInt,
|
|
2082
|
+
ZodBoolean: () => ZodBoolean,
|
|
2083
|
+
ZodBranded: () => ZodBranded,
|
|
2084
|
+
ZodCatch: () => ZodCatch,
|
|
2085
|
+
ZodDate: () => ZodDate,
|
|
2086
|
+
ZodDefault: () => ZodDefault,
|
|
2087
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
2088
|
+
ZodEffects: () => ZodEffects,
|
|
2089
|
+
ZodEnum: () => ZodEnum,
|
|
2090
|
+
ZodError: () => ZodError,
|
|
2091
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
2092
|
+
ZodFunction: () => ZodFunction,
|
|
2093
|
+
ZodIntersection: () => ZodIntersection,
|
|
2094
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
2095
|
+
ZodLazy: () => ZodLazy,
|
|
2096
|
+
ZodLiteral: () => ZodLiteral,
|
|
2097
|
+
ZodMap: () => ZodMap,
|
|
2098
|
+
ZodNaN: () => ZodNaN,
|
|
2099
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
2100
|
+
ZodNever: () => ZodNever,
|
|
2101
|
+
ZodNull: () => ZodNull,
|
|
2102
|
+
ZodNullable: () => ZodNullable,
|
|
2103
|
+
ZodNumber: () => ZodNumber,
|
|
2104
|
+
ZodObject: () => ZodObject,
|
|
2105
|
+
ZodOptional: () => ZodOptional,
|
|
2106
|
+
ZodParsedType: () => ZodParsedType,
|
|
2107
|
+
ZodPipeline: () => ZodPipeline,
|
|
2108
|
+
ZodPromise: () => ZodPromise,
|
|
2109
|
+
ZodReadonly: () => ZodReadonly,
|
|
2110
|
+
ZodRecord: () => ZodRecord,
|
|
2111
|
+
ZodSchema: () => ZodType,
|
|
2112
|
+
ZodSet: () => ZodSet,
|
|
2113
|
+
ZodString: () => ZodString,
|
|
2114
|
+
ZodSymbol: () => ZodSymbol,
|
|
2115
|
+
ZodTransformer: () => ZodEffects,
|
|
2116
|
+
ZodTuple: () => ZodTuple,
|
|
2117
|
+
ZodType: () => ZodType,
|
|
2118
|
+
ZodUndefined: () => ZodUndefined,
|
|
2119
|
+
ZodUnion: () => ZodUnion,
|
|
2120
|
+
ZodUnknown: () => ZodUnknown,
|
|
2121
|
+
ZodVoid: () => ZodVoid,
|
|
2122
|
+
addIssueToContext: () => addIssueToContext,
|
|
2123
|
+
any: () => anyType,
|
|
2124
|
+
array: () => arrayType,
|
|
2125
|
+
bigint: () => bigIntType,
|
|
2126
|
+
boolean: () => booleanType,
|
|
2127
|
+
coerce: () => coerce,
|
|
2128
|
+
custom: () => custom,
|
|
2129
|
+
date: () => dateType,
|
|
2130
|
+
datetimeRegex: () => datetimeRegex,
|
|
2131
|
+
defaultErrorMap: () => en_default,
|
|
2132
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
2133
|
+
effect: () => effectsType,
|
|
2134
|
+
enum: () => enumType,
|
|
2135
|
+
function: () => functionType,
|
|
2136
|
+
getErrorMap: () => getErrorMap,
|
|
2137
|
+
getParsedType: () => getParsedType,
|
|
2138
|
+
instanceof: () => instanceOfType,
|
|
2139
|
+
intersection: () => intersectionType,
|
|
2140
|
+
isAborted: () => isAborted,
|
|
2141
|
+
isAsync: () => isAsync,
|
|
2142
|
+
isDirty: () => isDirty,
|
|
2143
|
+
isValid: () => isValid,
|
|
2144
|
+
late: () => late,
|
|
2145
|
+
lazy: () => lazyType,
|
|
2146
|
+
literal: () => literalType,
|
|
2147
|
+
makeIssue: () => makeIssue,
|
|
2148
|
+
map: () => mapType,
|
|
2149
|
+
nan: () => nanType,
|
|
2150
|
+
nativeEnum: () => nativeEnumType,
|
|
2151
|
+
never: () => neverType,
|
|
2152
|
+
null: () => nullType,
|
|
2153
|
+
nullable: () => nullableType,
|
|
2154
|
+
number: () => numberType,
|
|
2155
|
+
object: () => objectType,
|
|
2156
|
+
objectUtil: () => objectUtil,
|
|
2157
|
+
oboolean: () => oboolean,
|
|
2158
|
+
onumber: () => onumber,
|
|
2159
|
+
optional: () => optionalType,
|
|
2160
|
+
ostring: () => ostring,
|
|
2161
|
+
pipeline: () => pipelineType,
|
|
2162
|
+
preprocess: () => preprocessType,
|
|
2163
|
+
promise: () => promiseType,
|
|
2164
|
+
quotelessJson: () => quotelessJson,
|
|
2165
|
+
record: () => recordType,
|
|
2166
|
+
set: () => setType,
|
|
2167
|
+
setErrorMap: () => setErrorMap,
|
|
2168
|
+
strictObject: () => strictObjectType,
|
|
2169
|
+
string: () => stringType,
|
|
2170
|
+
symbol: () => symbolType,
|
|
2171
|
+
transformer: () => effectsType,
|
|
2172
|
+
tuple: () => tupleType,
|
|
2173
|
+
undefined: () => undefinedType,
|
|
2174
|
+
union: () => unionType,
|
|
2175
|
+
unknown: () => unknownType,
|
|
2176
|
+
util: () => util,
|
|
2177
|
+
void: () => voidType
|
|
2138
2178
|
});
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2179
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2180
|
+
|
|
2181
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
2182
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2183
|
+
|
|
2184
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
2185
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2186
|
+
|
|
2187
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
2188
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2189
|
+
|
|
2190
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
2191
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2192
|
+
var util;
|
|
2193
|
+
(function(util4) {
|
|
2194
|
+
util4.assertEqual = (_) => {
|
|
2195
|
+
};
|
|
2196
|
+
function assertIs(_arg) {
|
|
2150
2197
|
}
|
|
2151
|
-
|
|
2152
|
-
function
|
|
2153
|
-
|
|
2154
|
-
value["script"] = "";
|
|
2155
|
-
delete value["scriptPath"];
|
|
2156
|
-
delete value["modules"];
|
|
2157
|
-
delete value["modulesRoot"];
|
|
2198
|
+
util4.assertIs = assertIs;
|
|
2199
|
+
function assertNever(_x) {
|
|
2200
|
+
throw new Error();
|
|
2158
2201
|
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2202
|
+
util4.assertNever = assertNever;
|
|
2203
|
+
util4.arrayToEnum = (items) => {
|
|
2204
|
+
const obj = {};
|
|
2205
|
+
for (const item of items) {
|
|
2206
|
+
obj[item] = item;
|
|
2207
|
+
}
|
|
2208
|
+
return obj;
|
|
2209
|
+
};
|
|
2210
|
+
util4.getValidEnumValues = (obj) => {
|
|
2211
|
+
const validKeys = util4.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
2212
|
+
const filtered = {};
|
|
2213
|
+
for (const k of validKeys) {
|
|
2214
|
+
filtered[k] = obj[k];
|
|
2215
|
+
}
|
|
2216
|
+
return util4.objectValues(filtered);
|
|
2217
|
+
};
|
|
2218
|
+
util4.objectValues = (obj) => {
|
|
2219
|
+
return util4.objectKeys(obj).map(function(e) {
|
|
2220
|
+
return obj[e];
|
|
2221
|
+
});
|
|
2222
|
+
};
|
|
2223
|
+
util4.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
2224
|
+
const keys = [];
|
|
2225
|
+
for (const key in object) {
|
|
2226
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
2227
|
+
keys.push(key);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
return keys;
|
|
2231
|
+
};
|
|
2232
|
+
util4.find = (arr, checker) => {
|
|
2233
|
+
for (const item of arr) {
|
|
2234
|
+
if (checker(item))
|
|
2235
|
+
return item;
|
|
2236
|
+
}
|
|
2237
|
+
return void 0;
|
|
2238
|
+
};
|
|
2239
|
+
util4.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
2240
|
+
function joinValues(array, separator = " | ") {
|
|
2241
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
2242
|
+
}
|
|
2243
|
+
util4.joinValues = joinValues;
|
|
2244
|
+
util4.jsonStringifyReplacer = (_, value) => {
|
|
2245
|
+
if (typeof value === "bigint") {
|
|
2246
|
+
return value.toString();
|
|
2167
2247
|
}
|
|
2248
|
+
return value;
|
|
2249
|
+
};
|
|
2250
|
+
})(util || (util = {}));
|
|
2251
|
+
var objectUtil;
|
|
2252
|
+
(function(objectUtil2) {
|
|
2253
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
2254
|
+
return {
|
|
2255
|
+
...first,
|
|
2256
|
+
...second
|
|
2257
|
+
// second overwrites first
|
|
2258
|
+
};
|
|
2259
|
+
};
|
|
2260
|
+
})(objectUtil || (objectUtil = {}));
|
|
2261
|
+
var ZodParsedType = util.arrayToEnum([
|
|
2262
|
+
"string",
|
|
2263
|
+
"nan",
|
|
2264
|
+
"number",
|
|
2265
|
+
"integer",
|
|
2266
|
+
"float",
|
|
2267
|
+
"boolean",
|
|
2268
|
+
"date",
|
|
2269
|
+
"bigint",
|
|
2270
|
+
"symbol",
|
|
2271
|
+
"function",
|
|
2272
|
+
"undefined",
|
|
2273
|
+
"null",
|
|
2274
|
+
"array",
|
|
2275
|
+
"object",
|
|
2276
|
+
"unknown",
|
|
2277
|
+
"promise",
|
|
2278
|
+
"void",
|
|
2279
|
+
"never",
|
|
2280
|
+
"map",
|
|
2281
|
+
"set"
|
|
2282
|
+
]);
|
|
2283
|
+
var getParsedType = (data) => {
|
|
2284
|
+
const t = typeof data;
|
|
2285
|
+
switch (t) {
|
|
2286
|
+
case "undefined":
|
|
2287
|
+
return ZodParsedType.undefined;
|
|
2288
|
+
case "string":
|
|
2289
|
+
return ZodParsedType.string;
|
|
2290
|
+
case "number":
|
|
2291
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
2292
|
+
case "boolean":
|
|
2293
|
+
return ZodParsedType.boolean;
|
|
2294
|
+
case "function":
|
|
2295
|
+
return ZodParsedType.function;
|
|
2296
|
+
case "bigint":
|
|
2297
|
+
return ZodParsedType.bigint;
|
|
2298
|
+
case "symbol":
|
|
2299
|
+
return ZodParsedType.symbol;
|
|
2300
|
+
case "object":
|
|
2301
|
+
if (Array.isArray(data)) {
|
|
2302
|
+
return ZodParsedType.array;
|
|
2303
|
+
}
|
|
2304
|
+
if (data === null) {
|
|
2305
|
+
return ZodParsedType.null;
|
|
2306
|
+
}
|
|
2307
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
2308
|
+
return ZodParsedType.promise;
|
|
2309
|
+
}
|
|
2310
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
2311
|
+
return ZodParsedType.map;
|
|
2312
|
+
}
|
|
2313
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
2314
|
+
return ZodParsedType.set;
|
|
2315
|
+
}
|
|
2316
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
2317
|
+
return ZodParsedType.date;
|
|
2318
|
+
}
|
|
2319
|
+
return ZodParsedType.object;
|
|
2320
|
+
default:
|
|
2321
|
+
return ZodParsedType.unknown;
|
|
2168
2322
|
}
|
|
2169
|
-
|
|
2170
|
-
|
|
2323
|
+
};
|
|
2324
|
+
|
|
2325
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
2326
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
2327
|
+
"invalid_type",
|
|
2328
|
+
"invalid_literal",
|
|
2329
|
+
"custom",
|
|
2330
|
+
"invalid_union",
|
|
2331
|
+
"invalid_union_discriminator",
|
|
2332
|
+
"invalid_enum_value",
|
|
2333
|
+
"unrecognized_keys",
|
|
2334
|
+
"invalid_arguments",
|
|
2335
|
+
"invalid_return_type",
|
|
2336
|
+
"invalid_date",
|
|
2337
|
+
"invalid_string",
|
|
2338
|
+
"too_small",
|
|
2339
|
+
"too_big",
|
|
2340
|
+
"invalid_intersection_types",
|
|
2341
|
+
"not_multiple_of",
|
|
2342
|
+
"not_finite"
|
|
2343
|
+
]);
|
|
2344
|
+
var quotelessJson = (obj) => {
|
|
2345
|
+
const json = JSON.stringify(obj, null, 2);
|
|
2346
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
2347
|
+
};
|
|
2348
|
+
var ZodError = class _ZodError extends Error {
|
|
2349
|
+
get errors() {
|
|
2350
|
+
return this.issues;
|
|
2351
|
+
}
|
|
2352
|
+
constructor(issues) {
|
|
2353
|
+
super();
|
|
2354
|
+
this.issues = [];
|
|
2355
|
+
this.addIssue = (sub) => {
|
|
2356
|
+
this.issues = [...this.issues, sub];
|
|
2357
|
+
};
|
|
2358
|
+
this.addIssues = (subs = []) => {
|
|
2359
|
+
this.issues = [...this.issues, ...subs];
|
|
2360
|
+
};
|
|
2361
|
+
const actualProto = new.target.prototype;
|
|
2362
|
+
if (Object.setPrototypeOf) {
|
|
2363
|
+
Object.setPrototypeOf(this, actualProto);
|
|
2364
|
+
} else {
|
|
2365
|
+
this.__proto__ = actualProto;
|
|
2366
|
+
}
|
|
2367
|
+
this.name = "ZodError";
|
|
2368
|
+
this.issues = issues;
|
|
2171
2369
|
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2370
|
+
format(_mapper) {
|
|
2371
|
+
const mapper = _mapper || function(issue) {
|
|
2372
|
+
return issue.message;
|
|
2373
|
+
};
|
|
2374
|
+
const fieldErrors = { _errors: [] };
|
|
2375
|
+
const processError = (error) => {
|
|
2376
|
+
for (const issue of error.issues) {
|
|
2377
|
+
if (issue.code === "invalid_union") {
|
|
2378
|
+
issue.unionErrors.map(processError);
|
|
2379
|
+
} else if (issue.code === "invalid_return_type") {
|
|
2380
|
+
processError(issue.returnTypeError);
|
|
2381
|
+
} else if (issue.code === "invalid_arguments") {
|
|
2382
|
+
processError(issue.argumentsError);
|
|
2383
|
+
} else if (issue.path.length === 0) {
|
|
2384
|
+
fieldErrors._errors.push(mapper(issue));
|
|
2385
|
+
} else {
|
|
2386
|
+
let curr = fieldErrors;
|
|
2387
|
+
let i = 0;
|
|
2388
|
+
while (i < issue.path.length) {
|
|
2389
|
+
const el = issue.path[i];
|
|
2390
|
+
const terminal = i === issue.path.length - 1;
|
|
2391
|
+
if (!terminal) {
|
|
2392
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
2393
|
+
} else {
|
|
2394
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
2395
|
+
curr[el]._errors.push(mapper(issue));
|
|
2396
|
+
}
|
|
2397
|
+
curr = curr[el];
|
|
2398
|
+
i++;
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
processError(this);
|
|
2404
|
+
return fieldErrors;
|
|
2174
2405
|
}
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
function filterTails(tails, userWorkers) {
|
|
2179
|
-
return tails?.filter((tailService) => {
|
|
2180
|
-
let name;
|
|
2181
|
-
if (typeof tailService === "string") {
|
|
2182
|
-
name = tailService;
|
|
2183
|
-
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
2184
|
-
name = tailService.name;
|
|
2185
|
-
} else {
|
|
2186
|
-
return true;
|
|
2406
|
+
static assert(value) {
|
|
2407
|
+
if (!(value instanceof _ZodError)) {
|
|
2408
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
2187
2409
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2410
|
+
}
|
|
2411
|
+
toString() {
|
|
2412
|
+
return this.message;
|
|
2413
|
+
}
|
|
2414
|
+
get message() {
|
|
2415
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
2416
|
+
}
|
|
2417
|
+
get isEmpty() {
|
|
2418
|
+
return this.issues.length === 0;
|
|
2419
|
+
}
|
|
2420
|
+
flatten(mapper = (issue) => issue.message) {
|
|
2421
|
+
const fieldErrors = {};
|
|
2422
|
+
const formErrors = [];
|
|
2423
|
+
for (const sub of this.issues) {
|
|
2424
|
+
if (sub.path.length > 0) {
|
|
2425
|
+
const firstEl = sub.path[0];
|
|
2426
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
2427
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
2428
|
+
} else {
|
|
2429
|
+
formErrors.push(mapper(sub));
|
|
2430
|
+
}
|
|
2193
2431
|
}
|
|
2194
|
-
return
|
|
2195
|
-
});
|
|
2196
|
-
}
|
|
2197
|
-
var remoteProxySessionsDataMap = /* @__PURE__ */ new Map();
|
|
2198
|
-
async function parseCustomPoolOptions(rootPath, value, opts) {
|
|
2199
|
-
const options = WorkersPoolOptionsSchema.parse(
|
|
2200
|
-
value,
|
|
2201
|
-
opts
|
|
2202
|
-
);
|
|
2203
|
-
options.miniflare ??= {};
|
|
2204
|
-
const errorRef = {};
|
|
2205
|
-
const workers = options.miniflare?.workers;
|
|
2206
|
-
const rootPathOption = getRootPath(options.miniflare);
|
|
2207
|
-
rootPath = path2.resolve(rootPath, rootPathOption);
|
|
2208
|
-
try {
|
|
2209
|
-
options.miniflare = parseWorkerOptions(
|
|
2210
|
-
rootPath,
|
|
2211
|
-
options.miniflare,
|
|
2212
|
-
/* withoutScript */
|
|
2213
|
-
true,
|
|
2214
|
-
// (script provided by runner)
|
|
2215
|
-
{ path: [...opts.path, "miniflare"] }
|
|
2216
|
-
);
|
|
2217
|
-
} catch (e) {
|
|
2218
|
-
coalesceZodErrors(errorRef, e);
|
|
2432
|
+
return { formErrors, fieldErrors };
|
|
2219
2433
|
}
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2434
|
+
get formErrors() {
|
|
2435
|
+
return this.flatten();
|
|
2436
|
+
}
|
|
2437
|
+
};
|
|
2438
|
+
ZodError.create = (issues) => {
|
|
2439
|
+
const error = new ZodError(issues);
|
|
2440
|
+
return error;
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
2444
|
+
var errorMap = (issue, _ctx) => {
|
|
2445
|
+
let message;
|
|
2446
|
+
switch (issue.code) {
|
|
2447
|
+
case ZodIssueCode.invalid_type:
|
|
2448
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
2449
|
+
message = "Required";
|
|
2450
|
+
} else {
|
|
2451
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
2452
|
+
}
|
|
2453
|
+
break;
|
|
2454
|
+
case ZodIssueCode.invalid_literal:
|
|
2455
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
2456
|
+
break;
|
|
2457
|
+
case ZodIssueCode.unrecognized_keys:
|
|
2458
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
2459
|
+
break;
|
|
2460
|
+
case ZodIssueCode.invalid_union:
|
|
2461
|
+
message = `Invalid input`;
|
|
2462
|
+
break;
|
|
2463
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
2464
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
2465
|
+
break;
|
|
2466
|
+
case ZodIssueCode.invalid_enum_value:
|
|
2467
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
2468
|
+
break;
|
|
2469
|
+
case ZodIssueCode.invalid_arguments:
|
|
2470
|
+
message = `Invalid function arguments`;
|
|
2471
|
+
break;
|
|
2472
|
+
case ZodIssueCode.invalid_return_type:
|
|
2473
|
+
message = `Invalid function return type`;
|
|
2474
|
+
break;
|
|
2475
|
+
case ZodIssueCode.invalid_date:
|
|
2476
|
+
message = `Invalid date`;
|
|
2477
|
+
break;
|
|
2478
|
+
case ZodIssueCode.invalid_string:
|
|
2479
|
+
if (typeof issue.validation === "object") {
|
|
2480
|
+
if ("includes" in issue.validation) {
|
|
2481
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
2482
|
+
if (typeof issue.validation.position === "number") {
|
|
2483
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
2233
2484
|
}
|
|
2234
|
-
)
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2485
|
+
} else if ("startsWith" in issue.validation) {
|
|
2486
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
2487
|
+
} else if ("endsWith" in issue.validation) {
|
|
2488
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
2489
|
+
} else {
|
|
2490
|
+
util.assertNever(issue.validation);
|
|
2491
|
+
}
|
|
2492
|
+
} else if (issue.validation !== "regex") {
|
|
2493
|
+
message = `Invalid ${issue.validation}`;
|
|
2494
|
+
} else {
|
|
2495
|
+
message = "Invalid";
|
|
2238
2496
|
}
|
|
2239
|
-
|
|
2497
|
+
break;
|
|
2498
|
+
case ZodIssueCode.too_small:
|
|
2499
|
+
if (issue.type === "array")
|
|
2500
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
2501
|
+
else if (issue.type === "string")
|
|
2502
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
2503
|
+
else if (issue.type === "number")
|
|
2504
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
2505
|
+
else if (issue.type === "bigint")
|
|
2506
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
2507
|
+
else if (issue.type === "date")
|
|
2508
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
2509
|
+
else
|
|
2510
|
+
message = "Invalid input";
|
|
2511
|
+
break;
|
|
2512
|
+
case ZodIssueCode.too_big:
|
|
2513
|
+
if (issue.type === "array")
|
|
2514
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
2515
|
+
else if (issue.type === "string")
|
|
2516
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
2517
|
+
else if (issue.type === "number")
|
|
2518
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
2519
|
+
else if (issue.type === "bigint")
|
|
2520
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
2521
|
+
else if (issue.type === "date")
|
|
2522
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
2523
|
+
else
|
|
2524
|
+
message = "Invalid input";
|
|
2525
|
+
break;
|
|
2526
|
+
case ZodIssueCode.custom:
|
|
2527
|
+
message = `Invalid input`;
|
|
2528
|
+
break;
|
|
2529
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
2530
|
+
message = `Intersection results could not be merged`;
|
|
2531
|
+
break;
|
|
2532
|
+
case ZodIssueCode.not_multiple_of:
|
|
2533
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
2534
|
+
break;
|
|
2535
|
+
case ZodIssueCode.not_finite:
|
|
2536
|
+
message = "Number must be finite";
|
|
2537
|
+
break;
|
|
2538
|
+
default:
|
|
2539
|
+
message = _ctx.defaultError;
|
|
2540
|
+
util.assertNever(issue);
|
|
2240
2541
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2542
|
+
return { message };
|
|
2543
|
+
};
|
|
2544
|
+
var en_default = errorMap;
|
|
2545
|
+
|
|
2546
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
2547
|
+
var overrideErrorMap = en_default;
|
|
2548
|
+
function setErrorMap(map) {
|
|
2549
|
+
overrideErrorMap = map;
|
|
2550
|
+
}
|
|
2551
|
+
function getErrorMap() {
|
|
2552
|
+
return overrideErrorMap;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
2556
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2557
|
+
var makeIssue = (params) => {
|
|
2558
|
+
const { data, path: path6, errorMaps, issueData } = params;
|
|
2559
|
+
const fullPath = [...path6, ...issueData.path || []];
|
|
2560
|
+
const fullIssue = {
|
|
2561
|
+
...issueData,
|
|
2562
|
+
path: fullPath
|
|
2563
|
+
};
|
|
2564
|
+
if (issueData.message !== void 0) {
|
|
2565
|
+
return {
|
|
2566
|
+
...issueData,
|
|
2567
|
+
path: fullPath,
|
|
2568
|
+
message: issueData.message
|
|
2569
|
+
};
|
|
2243
2570
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2571
|
+
let errorMessage = "";
|
|
2572
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
2573
|
+
for (const map of maps) {
|
|
2574
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
2575
|
+
}
|
|
2576
|
+
return {
|
|
2577
|
+
...issueData,
|
|
2578
|
+
path: fullPath,
|
|
2579
|
+
message: errorMessage
|
|
2580
|
+
};
|
|
2581
|
+
};
|
|
2582
|
+
var EMPTY_PATH = [];
|
|
2583
|
+
function addIssueToContext(ctx, issueData) {
|
|
2584
|
+
const overrideMap = getErrorMap();
|
|
2585
|
+
const issue = makeIssue({
|
|
2586
|
+
issueData,
|
|
2587
|
+
data: ctx.data,
|
|
2588
|
+
path: ctx.path,
|
|
2589
|
+
errorMaps: [
|
|
2590
|
+
ctx.common.contextualErrorMap,
|
|
2591
|
+
// contextual error map is first priority
|
|
2592
|
+
ctx.schemaErrorMap,
|
|
2593
|
+
// then schema-bound map if available
|
|
2594
|
+
overrideMap,
|
|
2595
|
+
// then global override map
|
|
2596
|
+
overrideMap === en_default ? void 0 : en_default
|
|
2597
|
+
// then global default map
|
|
2598
|
+
].filter((x) => !!x)
|
|
2599
|
+
});
|
|
2600
|
+
ctx.common.issues.push(issue);
|
|
2601
|
+
}
|
|
2602
|
+
var ParseStatus = class _ParseStatus {
|
|
2603
|
+
constructor() {
|
|
2604
|
+
this.value = "valid";
|
|
2605
|
+
}
|
|
2606
|
+
dirty() {
|
|
2607
|
+
if (this.value === "valid")
|
|
2608
|
+
this.value = "dirty";
|
|
2609
|
+
}
|
|
2610
|
+
abort() {
|
|
2611
|
+
if (this.value !== "aborted")
|
|
2612
|
+
this.value = "aborted";
|
|
2613
|
+
}
|
|
2614
|
+
static mergeArray(status, results) {
|
|
2615
|
+
const arrayValue = [];
|
|
2616
|
+
for (const s of results) {
|
|
2617
|
+
if (s.status === "aborted")
|
|
2618
|
+
return INVALID;
|
|
2619
|
+
if (s.status === "dirty")
|
|
2620
|
+
status.dirty();
|
|
2621
|
+
arrayValue.push(s.value);
|
|
2261
2622
|
}
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2623
|
+
return { status: status.value, value: arrayValue };
|
|
2624
|
+
}
|
|
2625
|
+
static async mergeObjectAsync(status, pairs) {
|
|
2626
|
+
const syncPairs = [];
|
|
2627
|
+
for (const pair of pairs) {
|
|
2628
|
+
const key = await pair.key;
|
|
2629
|
+
const value = await pair.value;
|
|
2630
|
+
syncPairs.push({
|
|
2631
|
+
key,
|
|
2632
|
+
value
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2635
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2636
|
+
}
|
|
2637
|
+
static mergeObjectSync(status, pairs) {
|
|
2638
|
+
const finalObject = {};
|
|
2639
|
+
for (const pair of pairs) {
|
|
2640
|
+
const { key, value } = pair;
|
|
2641
|
+
if (key.status === "aborted")
|
|
2642
|
+
return INVALID;
|
|
2643
|
+
if (value.status === "aborted")
|
|
2644
|
+
return INVALID;
|
|
2645
|
+
if (key.status === "dirty")
|
|
2646
|
+
status.dirty();
|
|
2647
|
+
if (value.status === "dirty")
|
|
2648
|
+
status.dirty();
|
|
2649
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
2650
|
+
finalObject[key.value] = value.value;
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
return { status: status.value, value: finalObject };
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
var INVALID = Object.freeze({
|
|
2657
|
+
status: "aborted"
|
|
2658
|
+
});
|
|
2659
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
2660
|
+
var OK = (value) => ({ status: "valid", value });
|
|
2661
|
+
var isAborted = (x) => x.status === "aborted";
|
|
2662
|
+
var isDirty = (x) => x.status === "dirty";
|
|
2663
|
+
var isValid = (x) => x.status === "valid";
|
|
2664
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
2665
|
+
|
|
2666
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
2667
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2668
|
+
|
|
2669
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
2670
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
2671
|
+
var errorUtil;
|
|
2672
|
+
(function(errorUtil2) {
|
|
2673
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
2674
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
2675
|
+
})(errorUtil || (errorUtil = {}));
|
|
2676
|
+
|
|
2677
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
2678
|
+
var ParseInputLazyPath = class {
|
|
2679
|
+
constructor(parent, value, path6, key) {
|
|
2680
|
+
this._cachedPath = [];
|
|
2681
|
+
this.parent = parent;
|
|
2682
|
+
this.data = value;
|
|
2683
|
+
this._path = path6;
|
|
2684
|
+
this._key = key;
|
|
2685
|
+
}
|
|
2686
|
+
get path() {
|
|
2687
|
+
if (!this._cachedPath.length) {
|
|
2688
|
+
if (Array.isArray(this._key)) {
|
|
2689
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
2690
|
+
} else {
|
|
2691
|
+
this._cachedPath.push(...this._path, this._key);
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
return this._cachedPath;
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
var handleResult = (ctx, result) => {
|
|
2698
|
+
if (isValid(result)) {
|
|
2699
|
+
return { success: true, data: result.value };
|
|
2700
|
+
} else {
|
|
2701
|
+
if (!ctx.common.issues.length) {
|
|
2702
|
+
throw new Error("Validation failed but no issues detected.");
|
|
2703
|
+
}
|
|
2704
|
+
return {
|
|
2705
|
+
success: false,
|
|
2706
|
+
get error() {
|
|
2707
|
+
if (this._error)
|
|
2708
|
+
return this._error;
|
|
2709
|
+
const error = new ZodError(ctx.common.issues);
|
|
2710
|
+
this._error = error;
|
|
2711
|
+
return this._error;
|
|
2712
|
+
}
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
};
|
|
2716
|
+
function processCreateParams(params) {
|
|
2717
|
+
if (!params)
|
|
2718
|
+
return {};
|
|
2719
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
2720
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
2721
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
2722
|
+
}
|
|
2723
|
+
if (errorMap2)
|
|
2724
|
+
return { errorMap: errorMap2, description };
|
|
2725
|
+
const customMap = (iss, ctx) => {
|
|
2726
|
+
const { message } = params;
|
|
2727
|
+
if (iss.code === "invalid_enum_value") {
|
|
2728
|
+
return { message: message ?? ctx.defaultError };
|
|
2729
|
+
}
|
|
2730
|
+
if (typeof ctx.data === "undefined") {
|
|
2731
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
2732
|
+
}
|
|
2733
|
+
if (iss.code !== "invalid_type")
|
|
2734
|
+
return { message: ctx.defaultError };
|
|
2735
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
2736
|
+
};
|
|
2737
|
+
return { errorMap: customMap, description };
|
|
2738
|
+
}
|
|
2739
|
+
var ZodType = class {
|
|
2740
|
+
get description() {
|
|
2741
|
+
return this._def.description;
|
|
2742
|
+
}
|
|
2743
|
+
_getType(input) {
|
|
2744
|
+
return getParsedType(input.data);
|
|
2745
|
+
}
|
|
2746
|
+
_getOrReturnCtx(input, ctx) {
|
|
2747
|
+
return ctx || {
|
|
2748
|
+
common: input.parent.common,
|
|
2749
|
+
data: input.data,
|
|
2750
|
+
parsedType: getParsedType(input.data),
|
|
2751
|
+
schemaErrorMap: this._def.errorMap,
|
|
2752
|
+
path: input.path,
|
|
2753
|
+
parent: input.parent
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
_processInputParams(input) {
|
|
2757
|
+
return {
|
|
2758
|
+
status: new ParseStatus(),
|
|
2759
|
+
ctx: {
|
|
2760
|
+
common: input.parent.common,
|
|
2761
|
+
data: input.data,
|
|
2762
|
+
parsedType: getParsedType(input.data),
|
|
2763
|
+
schemaErrorMap: this._def.errorMap,
|
|
2764
|
+
path: input.path,
|
|
2765
|
+
parent: input.parent
|
|
2766
|
+
}
|
|
2767
|
+
};
|
|
2768
|
+
}
|
|
2769
|
+
_parseSync(input) {
|
|
2770
|
+
const result = this._parse(input);
|
|
2771
|
+
if (isAsync(result)) {
|
|
2772
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
2773
|
+
}
|
|
2774
|
+
return result;
|
|
2775
|
+
}
|
|
2776
|
+
_parseAsync(input) {
|
|
2777
|
+
const result = this._parse(input);
|
|
2778
|
+
return Promise.resolve(result);
|
|
2779
|
+
}
|
|
2780
|
+
parse(data, params) {
|
|
2781
|
+
const result = this.safeParse(data, params);
|
|
2782
|
+
if (result.success)
|
|
2783
|
+
return result.data;
|
|
2784
|
+
throw result.error;
|
|
2785
|
+
}
|
|
2786
|
+
safeParse(data, params) {
|
|
2787
|
+
const ctx = {
|
|
2788
|
+
common: {
|
|
2789
|
+
issues: [],
|
|
2790
|
+
async: params?.async ?? false,
|
|
2791
|
+
contextualErrorMap: params?.errorMap
|
|
2792
|
+
},
|
|
2793
|
+
path: params?.path || [],
|
|
2794
|
+
schemaErrorMap: this._def.errorMap,
|
|
2795
|
+
parent: null,
|
|
2796
|
+
data,
|
|
2797
|
+
parsedType: getParsedType(data)
|
|
2798
|
+
};
|
|
2799
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
2800
|
+
return handleResult(ctx, result);
|
|
2801
|
+
}
|
|
2802
|
+
"~validate"(data) {
|
|
2803
|
+
const ctx = {
|
|
2804
|
+
common: {
|
|
2805
|
+
issues: [],
|
|
2806
|
+
async: !!this["~standard"].async
|
|
2807
|
+
},
|
|
2808
|
+
path: [],
|
|
2809
|
+
schemaErrorMap: this._def.errorMap,
|
|
2810
|
+
parent: null,
|
|
2811
|
+
data,
|
|
2812
|
+
parsedType: getParsedType(data)
|
|
2813
|
+
};
|
|
2814
|
+
if (!this["~standard"].async) {
|
|
2815
|
+
try {
|
|
2816
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
2817
|
+
return isValid(result) ? {
|
|
2818
|
+
value: result.value
|
|
2819
|
+
} : {
|
|
2820
|
+
issues: ctx.common.issues
|
|
2821
|
+
};
|
|
2822
|
+
} catch (err) {
|
|
2823
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
2824
|
+
this["~standard"].async = true;
|
|
2825
|
+
}
|
|
2826
|
+
ctx.common = {
|
|
2827
|
+
issues: [],
|
|
2828
|
+
async: true
|
|
2829
|
+
};
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
2833
|
+
value: result.value
|
|
2834
|
+
} : {
|
|
2835
|
+
issues: ctx.common.issues
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2838
|
+
async parseAsync(data, params) {
|
|
2839
|
+
const result = await this.safeParseAsync(data, params);
|
|
2840
|
+
if (result.success)
|
|
2841
|
+
return result.data;
|
|
2842
|
+
throw result.error;
|
|
2843
|
+
}
|
|
2844
|
+
async safeParseAsync(data, params) {
|
|
2845
|
+
const ctx = {
|
|
2846
|
+
common: {
|
|
2847
|
+
issues: [],
|
|
2848
|
+
contextualErrorMap: params?.errorMap,
|
|
2849
|
+
async: true
|
|
2850
|
+
},
|
|
2851
|
+
path: params?.path || [],
|
|
2852
|
+
schemaErrorMap: this._def.errorMap,
|
|
2853
|
+
parent: null,
|
|
2854
|
+
data,
|
|
2855
|
+
parsedType: getParsedType(data)
|
|
2856
|
+
};
|
|
2857
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
2858
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
2859
|
+
return handleResult(ctx, result);
|
|
2860
|
+
}
|
|
2861
|
+
refine(check, message) {
|
|
2862
|
+
const getIssueProperties = (val) => {
|
|
2863
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
2864
|
+
return { message };
|
|
2865
|
+
} else if (typeof message === "function") {
|
|
2866
|
+
return message(val);
|
|
2867
|
+
} else {
|
|
2868
|
+
return message;
|
|
2869
|
+
}
|
|
2870
|
+
};
|
|
2871
|
+
return this._refinement((val, ctx) => {
|
|
2872
|
+
const result = check(val);
|
|
2873
|
+
const setError = () => ctx.addIssue({
|
|
2874
|
+
code: ZodIssueCode.custom,
|
|
2875
|
+
...getIssueProperties(val)
|
|
2876
|
+
});
|
|
2877
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
2878
|
+
return result.then((data) => {
|
|
2879
|
+
if (!data) {
|
|
2880
|
+
setError();
|
|
2881
|
+
return false;
|
|
2882
|
+
} else {
|
|
2883
|
+
return true;
|
|
2884
|
+
}
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
if (!result) {
|
|
2888
|
+
setError();
|
|
2889
|
+
return false;
|
|
2890
|
+
} else {
|
|
2891
|
+
return true;
|
|
2892
|
+
}
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
refinement(check, refinementData) {
|
|
2896
|
+
return this._refinement((val, ctx) => {
|
|
2897
|
+
if (!check(val)) {
|
|
2898
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
2899
|
+
return false;
|
|
2900
|
+
} else {
|
|
2901
|
+
return true;
|
|
2902
|
+
}
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
_refinement(refinement) {
|
|
2906
|
+
return new ZodEffects({
|
|
2907
|
+
schema: this,
|
|
2908
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2909
|
+
effect: { type: "refinement", refinement }
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
superRefine(refinement) {
|
|
2913
|
+
return this._refinement(refinement);
|
|
2914
|
+
}
|
|
2915
|
+
constructor(def) {
|
|
2916
|
+
this.spa = this.safeParseAsync;
|
|
2917
|
+
this._def = def;
|
|
2918
|
+
this.parse = this.parse.bind(this);
|
|
2919
|
+
this.safeParse = this.safeParse.bind(this);
|
|
2920
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
2921
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2922
|
+
this.spa = this.spa.bind(this);
|
|
2923
|
+
this.refine = this.refine.bind(this);
|
|
2924
|
+
this.refinement = this.refinement.bind(this);
|
|
2925
|
+
this.superRefine = this.superRefine.bind(this);
|
|
2926
|
+
this.optional = this.optional.bind(this);
|
|
2927
|
+
this.nullable = this.nullable.bind(this);
|
|
2928
|
+
this.nullish = this.nullish.bind(this);
|
|
2929
|
+
this.array = this.array.bind(this);
|
|
2930
|
+
this.promise = this.promise.bind(this);
|
|
2931
|
+
this.or = this.or.bind(this);
|
|
2932
|
+
this.and = this.and.bind(this);
|
|
2933
|
+
this.transform = this.transform.bind(this);
|
|
2934
|
+
this.brand = this.brand.bind(this);
|
|
2935
|
+
this.default = this.default.bind(this);
|
|
2936
|
+
this.catch = this.catch.bind(this);
|
|
2937
|
+
this.describe = this.describe.bind(this);
|
|
2938
|
+
this.pipe = this.pipe.bind(this);
|
|
2939
|
+
this.readonly = this.readonly.bind(this);
|
|
2940
|
+
this.isNullable = this.isNullable.bind(this);
|
|
2941
|
+
this.isOptional = this.isOptional.bind(this);
|
|
2942
|
+
this["~standard"] = {
|
|
2943
|
+
version: 1,
|
|
2944
|
+
vendor: "zod",
|
|
2945
|
+
validate: (data) => this["~validate"](data)
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
optional() {
|
|
2949
|
+
return ZodOptional.create(this, this._def);
|
|
2950
|
+
}
|
|
2951
|
+
nullable() {
|
|
2952
|
+
return ZodNullable.create(this, this._def);
|
|
2953
|
+
}
|
|
2954
|
+
nullish() {
|
|
2955
|
+
return this.nullable().optional();
|
|
2956
|
+
}
|
|
2957
|
+
array() {
|
|
2958
|
+
return ZodArray.create(this);
|
|
2959
|
+
}
|
|
2960
|
+
promise() {
|
|
2961
|
+
return ZodPromise.create(this, this._def);
|
|
2962
|
+
}
|
|
2963
|
+
or(option) {
|
|
2964
|
+
return ZodUnion.create([this, option], this._def);
|
|
2965
|
+
}
|
|
2966
|
+
and(incoming) {
|
|
2967
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
2968
|
+
}
|
|
2969
|
+
transform(transform) {
|
|
2970
|
+
return new ZodEffects({
|
|
2971
|
+
...processCreateParams(this._def),
|
|
2972
|
+
schema: this,
|
|
2973
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2974
|
+
effect: { type: "transform", transform }
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
default(def) {
|
|
2978
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
2979
|
+
return new ZodDefault({
|
|
2980
|
+
...processCreateParams(this._def),
|
|
2981
|
+
innerType: this,
|
|
2982
|
+
defaultValue: defaultValueFunc,
|
|
2983
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
brand() {
|
|
2987
|
+
return new ZodBranded({
|
|
2988
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
2989
|
+
type: this,
|
|
2990
|
+
...processCreateParams(this._def)
|
|
2991
|
+
});
|
|
2992
|
+
}
|
|
2993
|
+
catch(def) {
|
|
2994
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
2995
|
+
return new ZodCatch({
|
|
2996
|
+
...processCreateParams(this._def),
|
|
2997
|
+
innerType: this,
|
|
2998
|
+
catchValue: catchValueFunc,
|
|
2999
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
describe(description) {
|
|
3003
|
+
const This = this.constructor;
|
|
3004
|
+
return new This({
|
|
3005
|
+
...this._def,
|
|
3006
|
+
description
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
pipe(target) {
|
|
3010
|
+
return ZodPipeline.create(this, target);
|
|
3011
|
+
}
|
|
3012
|
+
readonly() {
|
|
3013
|
+
return ZodReadonly.create(this);
|
|
3014
|
+
}
|
|
3015
|
+
isOptional() {
|
|
3016
|
+
return this.safeParse(void 0).success;
|
|
3017
|
+
}
|
|
3018
|
+
isNullable() {
|
|
3019
|
+
return this.safeParse(null).success;
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
3023
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
3024
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
3025
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
3026
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
3027
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
3028
|
+
var durationRegex = /^[-+]?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)?)??$/;
|
|
3029
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
3030
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
3031
|
+
var emojiRegex;
|
|
3032
|
+
var ipv4Regex = /^(?:(?: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])$/;
|
|
3033
|
+
var ipv4CidrRegex = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/;
|
|
3034
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
3035
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
3036
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
3037
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
3038
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
3039
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
3040
|
+
function timeRegexSource(args) {
|
|
3041
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
3042
|
+
if (args.precision) {
|
|
3043
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
3044
|
+
} else if (args.precision == null) {
|
|
3045
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
3046
|
+
}
|
|
3047
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
3048
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
3049
|
+
}
|
|
3050
|
+
function timeRegex(args) {
|
|
3051
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
3052
|
+
}
|
|
3053
|
+
function datetimeRegex(args) {
|
|
3054
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
3055
|
+
const opts = [];
|
|
3056
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
3057
|
+
if (args.offset)
|
|
3058
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
3059
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
3060
|
+
return new RegExp(`^${regex}$`);
|
|
3061
|
+
}
|
|
3062
|
+
function isValidIP(ip, version) {
|
|
3063
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
3064
|
+
return true;
|
|
3065
|
+
}
|
|
3066
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
3067
|
+
return true;
|
|
3068
|
+
}
|
|
3069
|
+
return false;
|
|
3070
|
+
}
|
|
3071
|
+
function isValidJWT(jwt, alg) {
|
|
3072
|
+
if (!jwtRegex.test(jwt))
|
|
3073
|
+
return false;
|
|
3074
|
+
try {
|
|
3075
|
+
const [header] = jwt.split(".");
|
|
3076
|
+
if (!header)
|
|
3077
|
+
return false;
|
|
3078
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
3079
|
+
const decoded = JSON.parse(atob(base64));
|
|
3080
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
3081
|
+
return false;
|
|
3082
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
3083
|
+
return false;
|
|
3084
|
+
if (!decoded.alg)
|
|
3085
|
+
return false;
|
|
3086
|
+
if (alg && decoded.alg !== alg)
|
|
3087
|
+
return false;
|
|
3088
|
+
return true;
|
|
3089
|
+
} catch {
|
|
3090
|
+
return false;
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
function isValidCidr(ip, version) {
|
|
3094
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
3095
|
+
return true;
|
|
3096
|
+
}
|
|
3097
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
3098
|
+
return true;
|
|
3099
|
+
}
|
|
3100
|
+
return false;
|
|
3101
|
+
}
|
|
3102
|
+
var ZodString = class _ZodString extends ZodType {
|
|
3103
|
+
_parse(input) {
|
|
3104
|
+
if (this._def.coerce) {
|
|
3105
|
+
input.data = String(input.data);
|
|
3106
|
+
}
|
|
3107
|
+
const parsedType = this._getType(input);
|
|
3108
|
+
if (parsedType !== ZodParsedType.string) {
|
|
3109
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
3110
|
+
addIssueToContext(ctx2, {
|
|
3111
|
+
code: ZodIssueCode.invalid_type,
|
|
3112
|
+
expected: ZodParsedType.string,
|
|
3113
|
+
received: ctx2.parsedType
|
|
3114
|
+
});
|
|
3115
|
+
return INVALID;
|
|
3116
|
+
}
|
|
3117
|
+
const status = new ParseStatus();
|
|
3118
|
+
let ctx = void 0;
|
|
3119
|
+
for (const check of this._def.checks) {
|
|
3120
|
+
if (check.kind === "min") {
|
|
3121
|
+
if (input.data.length < check.value) {
|
|
3122
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3123
|
+
addIssueToContext(ctx, {
|
|
3124
|
+
code: ZodIssueCode.too_small,
|
|
3125
|
+
minimum: check.value,
|
|
3126
|
+
type: "string",
|
|
3127
|
+
inclusive: true,
|
|
3128
|
+
exact: false,
|
|
3129
|
+
message: check.message
|
|
3130
|
+
});
|
|
3131
|
+
status.dirty();
|
|
3132
|
+
}
|
|
3133
|
+
} else if (check.kind === "max") {
|
|
3134
|
+
if (input.data.length > check.value) {
|
|
3135
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3136
|
+
addIssueToContext(ctx, {
|
|
3137
|
+
code: ZodIssueCode.too_big,
|
|
3138
|
+
maximum: check.value,
|
|
3139
|
+
type: "string",
|
|
3140
|
+
inclusive: true,
|
|
3141
|
+
exact: false,
|
|
3142
|
+
message: check.message
|
|
3143
|
+
});
|
|
3144
|
+
status.dirty();
|
|
3145
|
+
}
|
|
3146
|
+
} else if (check.kind === "length") {
|
|
3147
|
+
const tooBig = input.data.length > check.value;
|
|
3148
|
+
const tooSmall = input.data.length < check.value;
|
|
3149
|
+
if (tooBig || tooSmall) {
|
|
3150
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3151
|
+
if (tooBig) {
|
|
3152
|
+
addIssueToContext(ctx, {
|
|
3153
|
+
code: ZodIssueCode.too_big,
|
|
3154
|
+
maximum: check.value,
|
|
3155
|
+
type: "string",
|
|
3156
|
+
inclusive: true,
|
|
3157
|
+
exact: true,
|
|
3158
|
+
message: check.message
|
|
3159
|
+
});
|
|
3160
|
+
} else if (tooSmall) {
|
|
3161
|
+
addIssueToContext(ctx, {
|
|
3162
|
+
code: ZodIssueCode.too_small,
|
|
3163
|
+
minimum: check.value,
|
|
3164
|
+
type: "string",
|
|
3165
|
+
inclusive: true,
|
|
3166
|
+
exact: true,
|
|
3167
|
+
message: check.message
|
|
3168
|
+
});
|
|
3169
|
+
}
|
|
3170
|
+
status.dirty();
|
|
3171
|
+
}
|
|
3172
|
+
} else if (check.kind === "email") {
|
|
3173
|
+
if (!emailRegex.test(input.data)) {
|
|
3174
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3175
|
+
addIssueToContext(ctx, {
|
|
3176
|
+
validation: "email",
|
|
3177
|
+
code: ZodIssueCode.invalid_string,
|
|
3178
|
+
message: check.message
|
|
3179
|
+
});
|
|
3180
|
+
status.dirty();
|
|
3181
|
+
}
|
|
3182
|
+
} else if (check.kind === "emoji") {
|
|
3183
|
+
if (!emojiRegex) {
|
|
3184
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
3185
|
+
}
|
|
3186
|
+
if (!emojiRegex.test(input.data)) {
|
|
3187
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3188
|
+
addIssueToContext(ctx, {
|
|
3189
|
+
validation: "emoji",
|
|
3190
|
+
code: ZodIssueCode.invalid_string,
|
|
3191
|
+
message: check.message
|
|
3192
|
+
});
|
|
3193
|
+
status.dirty();
|
|
3194
|
+
}
|
|
3195
|
+
} else if (check.kind === "uuid") {
|
|
3196
|
+
if (!uuidRegex.test(input.data)) {
|
|
3197
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3198
|
+
addIssueToContext(ctx, {
|
|
3199
|
+
validation: "uuid",
|
|
3200
|
+
code: ZodIssueCode.invalid_string,
|
|
3201
|
+
message: check.message
|
|
3202
|
+
});
|
|
3203
|
+
status.dirty();
|
|
3204
|
+
}
|
|
3205
|
+
} else if (check.kind === "nanoid") {
|
|
3206
|
+
if (!nanoidRegex.test(input.data)) {
|
|
3207
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3208
|
+
addIssueToContext(ctx, {
|
|
3209
|
+
validation: "nanoid",
|
|
3210
|
+
code: ZodIssueCode.invalid_string,
|
|
3211
|
+
message: check.message
|
|
3212
|
+
});
|
|
3213
|
+
status.dirty();
|
|
3214
|
+
}
|
|
3215
|
+
} else if (check.kind === "cuid") {
|
|
3216
|
+
if (!cuidRegex.test(input.data)) {
|
|
3217
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3218
|
+
addIssueToContext(ctx, {
|
|
3219
|
+
validation: "cuid",
|
|
3220
|
+
code: ZodIssueCode.invalid_string,
|
|
3221
|
+
message: check.message
|
|
3222
|
+
});
|
|
3223
|
+
status.dirty();
|
|
3224
|
+
}
|
|
3225
|
+
} else if (check.kind === "cuid2") {
|
|
3226
|
+
if (!cuid2Regex.test(input.data)) {
|
|
3227
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3228
|
+
addIssueToContext(ctx, {
|
|
3229
|
+
validation: "cuid2",
|
|
3230
|
+
code: ZodIssueCode.invalid_string,
|
|
3231
|
+
message: check.message
|
|
3232
|
+
});
|
|
3233
|
+
status.dirty();
|
|
3234
|
+
}
|
|
3235
|
+
} else if (check.kind === "ulid") {
|
|
3236
|
+
if (!ulidRegex.test(input.data)) {
|
|
3237
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3238
|
+
addIssueToContext(ctx, {
|
|
3239
|
+
validation: "ulid",
|
|
3240
|
+
code: ZodIssueCode.invalid_string,
|
|
3241
|
+
message: check.message
|
|
3242
|
+
});
|
|
3243
|
+
status.dirty();
|
|
3244
|
+
}
|
|
3245
|
+
} else if (check.kind === "url") {
|
|
3246
|
+
try {
|
|
3247
|
+
new URL(input.data);
|
|
3248
|
+
} catch {
|
|
3249
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3250
|
+
addIssueToContext(ctx, {
|
|
3251
|
+
validation: "url",
|
|
3252
|
+
code: ZodIssueCode.invalid_string,
|
|
3253
|
+
message: check.message
|
|
3254
|
+
});
|
|
3255
|
+
status.dirty();
|
|
3256
|
+
}
|
|
3257
|
+
} else if (check.kind === "regex") {
|
|
3258
|
+
check.regex.lastIndex = 0;
|
|
3259
|
+
const testResult = check.regex.test(input.data);
|
|
3260
|
+
if (!testResult) {
|
|
3261
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3262
|
+
addIssueToContext(ctx, {
|
|
3263
|
+
validation: "regex",
|
|
3264
|
+
code: ZodIssueCode.invalid_string,
|
|
3265
|
+
message: check.message
|
|
3266
|
+
});
|
|
3267
|
+
status.dirty();
|
|
3268
|
+
}
|
|
3269
|
+
} else if (check.kind === "trim") {
|
|
3270
|
+
input.data = input.data.trim();
|
|
3271
|
+
} else if (check.kind === "includes") {
|
|
3272
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
3273
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3274
|
+
addIssueToContext(ctx, {
|
|
3275
|
+
code: ZodIssueCode.invalid_string,
|
|
3276
|
+
validation: { includes: check.value, position: check.position },
|
|
3277
|
+
message: check.message
|
|
3278
|
+
});
|
|
3279
|
+
status.dirty();
|
|
3280
|
+
}
|
|
3281
|
+
} else if (check.kind === "toLowerCase") {
|
|
3282
|
+
input.data = input.data.toLowerCase();
|
|
3283
|
+
} else if (check.kind === "toUpperCase") {
|
|
3284
|
+
input.data = input.data.toUpperCase();
|
|
3285
|
+
} else if (check.kind === "startsWith") {
|
|
3286
|
+
if (!input.data.startsWith(check.value)) {
|
|
3287
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3288
|
+
addIssueToContext(ctx, {
|
|
3289
|
+
code: ZodIssueCode.invalid_string,
|
|
3290
|
+
validation: { startsWith: check.value },
|
|
3291
|
+
message: check.message
|
|
3292
|
+
});
|
|
3293
|
+
status.dirty();
|
|
3294
|
+
}
|
|
3295
|
+
} else if (check.kind === "endsWith") {
|
|
3296
|
+
if (!input.data.endsWith(check.value)) {
|
|
3297
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3298
|
+
addIssueToContext(ctx, {
|
|
3299
|
+
code: ZodIssueCode.invalid_string,
|
|
3300
|
+
validation: { endsWith: check.value },
|
|
3301
|
+
message: check.message
|
|
3302
|
+
});
|
|
3303
|
+
status.dirty();
|
|
3304
|
+
}
|
|
3305
|
+
} else if (check.kind === "datetime") {
|
|
3306
|
+
const regex = datetimeRegex(check);
|
|
3307
|
+
if (!regex.test(input.data)) {
|
|
3308
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3309
|
+
addIssueToContext(ctx, {
|
|
3310
|
+
code: ZodIssueCode.invalid_string,
|
|
3311
|
+
validation: "datetime",
|
|
3312
|
+
message: check.message
|
|
3313
|
+
});
|
|
3314
|
+
status.dirty();
|
|
3315
|
+
}
|
|
3316
|
+
} else if (check.kind === "date") {
|
|
3317
|
+
const regex = dateRegex;
|
|
3318
|
+
if (!regex.test(input.data)) {
|
|
3319
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3320
|
+
addIssueToContext(ctx, {
|
|
3321
|
+
code: ZodIssueCode.invalid_string,
|
|
3322
|
+
validation: "date",
|
|
3323
|
+
message: check.message
|
|
3324
|
+
});
|
|
3325
|
+
status.dirty();
|
|
3326
|
+
}
|
|
3327
|
+
} else if (check.kind === "time") {
|
|
3328
|
+
const regex = timeRegex(check);
|
|
3329
|
+
if (!regex.test(input.data)) {
|
|
3330
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3331
|
+
addIssueToContext(ctx, {
|
|
3332
|
+
code: ZodIssueCode.invalid_string,
|
|
3333
|
+
validation: "time",
|
|
3334
|
+
message: check.message
|
|
3335
|
+
});
|
|
3336
|
+
status.dirty();
|
|
3337
|
+
}
|
|
3338
|
+
} else if (check.kind === "duration") {
|
|
3339
|
+
if (!durationRegex.test(input.data)) {
|
|
3340
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3341
|
+
addIssueToContext(ctx, {
|
|
3342
|
+
validation: "duration",
|
|
3343
|
+
code: ZodIssueCode.invalid_string,
|
|
3344
|
+
message: check.message
|
|
3345
|
+
});
|
|
3346
|
+
status.dirty();
|
|
3347
|
+
}
|
|
3348
|
+
} else if (check.kind === "ip") {
|
|
3349
|
+
if (!isValidIP(input.data, check.version)) {
|
|
3350
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3351
|
+
addIssueToContext(ctx, {
|
|
3352
|
+
validation: "ip",
|
|
3353
|
+
code: ZodIssueCode.invalid_string,
|
|
3354
|
+
message: check.message
|
|
3355
|
+
});
|
|
3356
|
+
status.dirty();
|
|
3357
|
+
}
|
|
3358
|
+
} else if (check.kind === "jwt") {
|
|
3359
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
3360
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3361
|
+
addIssueToContext(ctx, {
|
|
3362
|
+
validation: "jwt",
|
|
3363
|
+
code: ZodIssueCode.invalid_string,
|
|
3364
|
+
message: check.message
|
|
3365
|
+
});
|
|
3366
|
+
status.dirty();
|
|
3367
|
+
}
|
|
3368
|
+
} else if (check.kind === "cidr") {
|
|
3369
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
3370
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3371
|
+
addIssueToContext(ctx, {
|
|
3372
|
+
validation: "cidr",
|
|
3373
|
+
code: ZodIssueCode.invalid_string,
|
|
3374
|
+
message: check.message
|
|
3375
|
+
});
|
|
3376
|
+
status.dirty();
|
|
3377
|
+
}
|
|
3378
|
+
} else if (check.kind === "base64") {
|
|
3379
|
+
if (!base64Regex.test(input.data)) {
|
|
3380
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3381
|
+
addIssueToContext(ctx, {
|
|
3382
|
+
validation: "base64",
|
|
3383
|
+
code: ZodIssueCode.invalid_string,
|
|
3384
|
+
message: check.message
|
|
3385
|
+
});
|
|
3386
|
+
status.dirty();
|
|
3387
|
+
}
|
|
3388
|
+
} else if (check.kind === "base64url") {
|
|
3389
|
+
if (!base64urlRegex.test(input.data)) {
|
|
3390
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3391
|
+
addIssueToContext(ctx, {
|
|
3392
|
+
validation: "base64url",
|
|
3393
|
+
code: ZodIssueCode.invalid_string,
|
|
3394
|
+
message: check.message
|
|
3395
|
+
});
|
|
3396
|
+
status.dirty();
|
|
3397
|
+
}
|
|
3398
|
+
} else {
|
|
3399
|
+
util.assertNever(check);
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
return { status: status.value, value: input.data };
|
|
3403
|
+
}
|
|
3404
|
+
_regex(regex, validation, message) {
|
|
3405
|
+
return this.refinement((data) => regex.test(data), {
|
|
3406
|
+
validation,
|
|
3407
|
+
code: ZodIssueCode.invalid_string,
|
|
3408
|
+
...errorUtil.errToObj(message)
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
_addCheck(check) {
|
|
3412
|
+
return new _ZodString({
|
|
3413
|
+
...this._def,
|
|
3414
|
+
checks: [...this._def.checks, check]
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3417
|
+
email(message) {
|
|
3418
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
3419
|
+
}
|
|
3420
|
+
url(message) {
|
|
3421
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
3422
|
+
}
|
|
3423
|
+
emoji(message) {
|
|
3424
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
3425
|
+
}
|
|
3426
|
+
uuid(message) {
|
|
3427
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
3428
|
+
}
|
|
3429
|
+
nanoid(message) {
|
|
3430
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
3431
|
+
}
|
|
3432
|
+
cuid(message) {
|
|
3433
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
3434
|
+
}
|
|
3435
|
+
cuid2(message) {
|
|
3436
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
3437
|
+
}
|
|
3438
|
+
ulid(message) {
|
|
3439
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
3440
|
+
}
|
|
3441
|
+
base64(message) {
|
|
3442
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
3443
|
+
}
|
|
3444
|
+
base64url(message) {
|
|
3445
|
+
return this._addCheck({
|
|
3446
|
+
kind: "base64url",
|
|
3447
|
+
...errorUtil.errToObj(message)
|
|
3448
|
+
});
|
|
3449
|
+
}
|
|
3450
|
+
jwt(options) {
|
|
3451
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
3452
|
+
}
|
|
3453
|
+
ip(options) {
|
|
3454
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
3455
|
+
}
|
|
3456
|
+
cidr(options) {
|
|
3457
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
3458
|
+
}
|
|
3459
|
+
datetime(options) {
|
|
3460
|
+
if (typeof options === "string") {
|
|
3461
|
+
return this._addCheck({
|
|
3462
|
+
kind: "datetime",
|
|
3463
|
+
precision: null,
|
|
3464
|
+
offset: false,
|
|
3465
|
+
local: false,
|
|
3466
|
+
message: options
|
|
3467
|
+
});
|
|
3468
|
+
}
|
|
3469
|
+
return this._addCheck({
|
|
3470
|
+
kind: "datetime",
|
|
3471
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
3472
|
+
offset: options?.offset ?? false,
|
|
3473
|
+
local: options?.local ?? false,
|
|
3474
|
+
...errorUtil.errToObj(options?.message)
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3477
|
+
date(message) {
|
|
3478
|
+
return this._addCheck({ kind: "date", message });
|
|
3479
|
+
}
|
|
3480
|
+
time(options) {
|
|
3481
|
+
if (typeof options === "string") {
|
|
3482
|
+
return this._addCheck({
|
|
3483
|
+
kind: "time",
|
|
3484
|
+
precision: null,
|
|
3485
|
+
message: options
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
return this._addCheck({
|
|
3489
|
+
kind: "time",
|
|
3490
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
3491
|
+
...errorUtil.errToObj(options?.message)
|
|
3492
|
+
});
|
|
3493
|
+
}
|
|
3494
|
+
duration(message) {
|
|
3495
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
3496
|
+
}
|
|
3497
|
+
regex(regex, message) {
|
|
3498
|
+
return this._addCheck({
|
|
3499
|
+
kind: "regex",
|
|
3500
|
+
regex,
|
|
3501
|
+
...errorUtil.errToObj(message)
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
includes(value, options) {
|
|
3505
|
+
return this._addCheck({
|
|
3506
|
+
kind: "includes",
|
|
3507
|
+
value,
|
|
3508
|
+
position: options?.position,
|
|
3509
|
+
...errorUtil.errToObj(options?.message)
|
|
3510
|
+
});
|
|
3511
|
+
}
|
|
3512
|
+
startsWith(value, message) {
|
|
3513
|
+
return this._addCheck({
|
|
3514
|
+
kind: "startsWith",
|
|
3515
|
+
value,
|
|
3516
|
+
...errorUtil.errToObj(message)
|
|
3517
|
+
});
|
|
3518
|
+
}
|
|
3519
|
+
endsWith(value, message) {
|
|
3520
|
+
return this._addCheck({
|
|
3521
|
+
kind: "endsWith",
|
|
3522
|
+
value,
|
|
3523
|
+
...errorUtil.errToObj(message)
|
|
3524
|
+
});
|
|
3525
|
+
}
|
|
3526
|
+
min(minLength, message) {
|
|
3527
|
+
return this._addCheck({
|
|
3528
|
+
kind: "min",
|
|
3529
|
+
value: minLength,
|
|
3530
|
+
...errorUtil.errToObj(message)
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3533
|
+
max(maxLength, message) {
|
|
3534
|
+
return this._addCheck({
|
|
3535
|
+
kind: "max",
|
|
3536
|
+
value: maxLength,
|
|
3537
|
+
...errorUtil.errToObj(message)
|
|
3538
|
+
});
|
|
3539
|
+
}
|
|
3540
|
+
length(len, message) {
|
|
3541
|
+
return this._addCheck({
|
|
3542
|
+
kind: "length",
|
|
3543
|
+
value: len,
|
|
3544
|
+
...errorUtil.errToObj(message)
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
/**
|
|
3548
|
+
* Equivalent to `.min(1)`
|
|
3549
|
+
*/
|
|
3550
|
+
nonempty(message) {
|
|
3551
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
3552
|
+
}
|
|
3553
|
+
trim() {
|
|
3554
|
+
return new _ZodString({
|
|
3555
|
+
...this._def,
|
|
3556
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
3557
|
+
});
|
|
3558
|
+
}
|
|
3559
|
+
toLowerCase() {
|
|
3560
|
+
return new _ZodString({
|
|
3561
|
+
...this._def,
|
|
3562
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
3563
|
+
});
|
|
3564
|
+
}
|
|
3565
|
+
toUpperCase() {
|
|
3566
|
+
return new _ZodString({
|
|
3567
|
+
...this._def,
|
|
3568
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
get isDatetime() {
|
|
3572
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
3573
|
+
}
|
|
3574
|
+
get isDate() {
|
|
3575
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
3576
|
+
}
|
|
3577
|
+
get isTime() {
|
|
3578
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
3579
|
+
}
|
|
3580
|
+
get isDuration() {
|
|
3581
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
3582
|
+
}
|
|
3583
|
+
get isEmail() {
|
|
3584
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
3585
|
+
}
|
|
3586
|
+
get isURL() {
|
|
3587
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
3588
|
+
}
|
|
3589
|
+
get isEmoji() {
|
|
3590
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
3591
|
+
}
|
|
3592
|
+
get isUUID() {
|
|
3593
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
3594
|
+
}
|
|
3595
|
+
get isNANOID() {
|
|
3596
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
3597
|
+
}
|
|
3598
|
+
get isCUID() {
|
|
3599
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
3600
|
+
}
|
|
3601
|
+
get isCUID2() {
|
|
3602
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
3603
|
+
}
|
|
3604
|
+
get isULID() {
|
|
3605
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
3606
|
+
}
|
|
3607
|
+
get isIP() {
|
|
3608
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
3609
|
+
}
|
|
3610
|
+
get isCIDR() {
|
|
3611
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
3612
|
+
}
|
|
3613
|
+
get isBase64() {
|
|
3614
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
3615
|
+
}
|
|
3616
|
+
get isBase64url() {
|
|
3617
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
3618
|
+
}
|
|
3619
|
+
get minLength() {
|
|
3620
|
+
let min = null;
|
|
3621
|
+
for (const ch of this._def.checks) {
|
|
3622
|
+
if (ch.kind === "min") {
|
|
3623
|
+
if (min === null || ch.value > min)
|
|
3624
|
+
min = ch.value;
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
return min;
|
|
3628
|
+
}
|
|
3629
|
+
get maxLength() {
|
|
3630
|
+
let max = null;
|
|
3631
|
+
for (const ch of this._def.checks) {
|
|
3632
|
+
if (ch.kind === "max") {
|
|
3633
|
+
if (max === null || ch.value < max)
|
|
3634
|
+
max = ch.value;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
return max;
|
|
3638
|
+
}
|
|
3639
|
+
};
|
|
3640
|
+
ZodString.create = (params) => {
|
|
3641
|
+
return new ZodString({
|
|
3642
|
+
checks: [],
|
|
3643
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
3644
|
+
coerce: params?.coerce ?? false,
|
|
3645
|
+
...processCreateParams(params)
|
|
3646
|
+
});
|
|
3647
|
+
};
|
|
3648
|
+
function floatSafeRemainder(val, step) {
|
|
3649
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
3650
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
3651
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
3652
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
3653
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
3654
|
+
return valInt % stepInt / 10 ** decCount;
|
|
3655
|
+
}
|
|
3656
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
3657
|
+
constructor() {
|
|
3658
|
+
super(...arguments);
|
|
3659
|
+
this.min = this.gte;
|
|
3660
|
+
this.max = this.lte;
|
|
3661
|
+
this.step = this.multipleOf;
|
|
3662
|
+
}
|
|
3663
|
+
_parse(input) {
|
|
3664
|
+
if (this._def.coerce) {
|
|
3665
|
+
input.data = Number(input.data);
|
|
3666
|
+
}
|
|
3667
|
+
const parsedType = this._getType(input);
|
|
3668
|
+
if (parsedType !== ZodParsedType.number) {
|
|
3669
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
3670
|
+
addIssueToContext(ctx2, {
|
|
3671
|
+
code: ZodIssueCode.invalid_type,
|
|
3672
|
+
expected: ZodParsedType.number,
|
|
3673
|
+
received: ctx2.parsedType
|
|
3674
|
+
});
|
|
3675
|
+
return INVALID;
|
|
3676
|
+
}
|
|
3677
|
+
let ctx = void 0;
|
|
3678
|
+
const status = new ParseStatus();
|
|
3679
|
+
for (const check of this._def.checks) {
|
|
3680
|
+
if (check.kind === "int") {
|
|
3681
|
+
if (!util.isInteger(input.data)) {
|
|
3682
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3683
|
+
addIssueToContext(ctx, {
|
|
3684
|
+
code: ZodIssueCode.invalid_type,
|
|
3685
|
+
expected: "integer",
|
|
3686
|
+
received: "float",
|
|
3687
|
+
message: check.message
|
|
3688
|
+
});
|
|
3689
|
+
status.dirty();
|
|
3690
|
+
}
|
|
3691
|
+
} else if (check.kind === "min") {
|
|
3692
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
3693
|
+
if (tooSmall) {
|
|
3694
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3695
|
+
addIssueToContext(ctx, {
|
|
3696
|
+
code: ZodIssueCode.too_small,
|
|
3697
|
+
minimum: check.value,
|
|
3698
|
+
type: "number",
|
|
3699
|
+
inclusive: check.inclusive,
|
|
3700
|
+
exact: false,
|
|
3701
|
+
message: check.message
|
|
3702
|
+
});
|
|
3703
|
+
status.dirty();
|
|
3704
|
+
}
|
|
3705
|
+
} else if (check.kind === "max") {
|
|
3706
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
3707
|
+
if (tooBig) {
|
|
3708
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3709
|
+
addIssueToContext(ctx, {
|
|
3710
|
+
code: ZodIssueCode.too_big,
|
|
3711
|
+
maximum: check.value,
|
|
3712
|
+
type: "number",
|
|
3713
|
+
inclusive: check.inclusive,
|
|
3714
|
+
exact: false,
|
|
3715
|
+
message: check.message
|
|
3716
|
+
});
|
|
3717
|
+
status.dirty();
|
|
3718
|
+
}
|
|
3719
|
+
} else if (check.kind === "multipleOf") {
|
|
3720
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
3721
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3722
|
+
addIssueToContext(ctx, {
|
|
3723
|
+
code: ZodIssueCode.not_multiple_of,
|
|
3724
|
+
multipleOf: check.value,
|
|
3725
|
+
message: check.message
|
|
3726
|
+
});
|
|
3727
|
+
status.dirty();
|
|
3728
|
+
}
|
|
3729
|
+
} else if (check.kind === "finite") {
|
|
3730
|
+
if (!Number.isFinite(input.data)) {
|
|
3731
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3732
|
+
addIssueToContext(ctx, {
|
|
3733
|
+
code: ZodIssueCode.not_finite,
|
|
3734
|
+
message: check.message
|
|
3735
|
+
});
|
|
3736
|
+
status.dirty();
|
|
3737
|
+
}
|
|
3738
|
+
} else {
|
|
3739
|
+
util.assertNever(check);
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
return { status: status.value, value: input.data };
|
|
3743
|
+
}
|
|
3744
|
+
gte(value, message) {
|
|
3745
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
3746
|
+
}
|
|
3747
|
+
gt(value, message) {
|
|
3748
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
3749
|
+
}
|
|
3750
|
+
lte(value, message) {
|
|
3751
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
3752
|
+
}
|
|
3753
|
+
lt(value, message) {
|
|
3754
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
3755
|
+
}
|
|
3756
|
+
setLimit(kind, value, inclusive, message) {
|
|
3757
|
+
return new _ZodNumber({
|
|
3758
|
+
...this._def,
|
|
3759
|
+
checks: [
|
|
3760
|
+
...this._def.checks,
|
|
3761
|
+
{
|
|
3762
|
+
kind,
|
|
3763
|
+
value,
|
|
3764
|
+
inclusive,
|
|
3765
|
+
message: errorUtil.toString(message)
|
|
3766
|
+
}
|
|
3767
|
+
]
|
|
3768
|
+
});
|
|
3769
|
+
}
|
|
3770
|
+
_addCheck(check) {
|
|
3771
|
+
return new _ZodNumber({
|
|
3772
|
+
...this._def,
|
|
3773
|
+
checks: [...this._def.checks, check]
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
int(message) {
|
|
3777
|
+
return this._addCheck({
|
|
3778
|
+
kind: "int",
|
|
3779
|
+
message: errorUtil.toString(message)
|
|
3780
|
+
});
|
|
3781
|
+
}
|
|
3782
|
+
positive(message) {
|
|
3783
|
+
return this._addCheck({
|
|
3784
|
+
kind: "min",
|
|
3785
|
+
value: 0,
|
|
3786
|
+
inclusive: false,
|
|
3787
|
+
message: errorUtil.toString(message)
|
|
3788
|
+
});
|
|
3789
|
+
}
|
|
3790
|
+
negative(message) {
|
|
3791
|
+
return this._addCheck({
|
|
3792
|
+
kind: "max",
|
|
3793
|
+
value: 0,
|
|
3794
|
+
inclusive: false,
|
|
3795
|
+
message: errorUtil.toString(message)
|
|
3796
|
+
});
|
|
3797
|
+
}
|
|
3798
|
+
nonpositive(message) {
|
|
3799
|
+
return this._addCheck({
|
|
3800
|
+
kind: "max",
|
|
3801
|
+
value: 0,
|
|
3802
|
+
inclusive: true,
|
|
3803
|
+
message: errorUtil.toString(message)
|
|
3804
|
+
});
|
|
3805
|
+
}
|
|
3806
|
+
nonnegative(message) {
|
|
3807
|
+
return this._addCheck({
|
|
3808
|
+
kind: "min",
|
|
3809
|
+
value: 0,
|
|
3810
|
+
inclusive: true,
|
|
3811
|
+
message: errorUtil.toString(message)
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
multipleOf(value, message) {
|
|
3815
|
+
return this._addCheck({
|
|
3816
|
+
kind: "multipleOf",
|
|
3817
|
+
value,
|
|
3818
|
+
message: errorUtil.toString(message)
|
|
3819
|
+
});
|
|
3820
|
+
}
|
|
3821
|
+
finite(message) {
|
|
3822
|
+
return this._addCheck({
|
|
3823
|
+
kind: "finite",
|
|
3824
|
+
message: errorUtil.toString(message)
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
safe(message) {
|
|
3828
|
+
return this._addCheck({
|
|
3829
|
+
kind: "min",
|
|
3830
|
+
inclusive: true,
|
|
3831
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
3832
|
+
message: errorUtil.toString(message)
|
|
3833
|
+
})._addCheck({
|
|
3834
|
+
kind: "max",
|
|
3835
|
+
inclusive: true,
|
|
3836
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
3837
|
+
message: errorUtil.toString(message)
|
|
3838
|
+
});
|
|
3839
|
+
}
|
|
3840
|
+
get minValue() {
|
|
3841
|
+
let min = null;
|
|
3842
|
+
for (const ch of this._def.checks) {
|
|
3843
|
+
if (ch.kind === "min") {
|
|
3844
|
+
if (min === null || ch.value > min)
|
|
3845
|
+
min = ch.value;
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
return min;
|
|
3849
|
+
}
|
|
3850
|
+
get maxValue() {
|
|
3851
|
+
let max = null;
|
|
3852
|
+
for (const ch of this._def.checks) {
|
|
3853
|
+
if (ch.kind === "max") {
|
|
3854
|
+
if (max === null || ch.value < max)
|
|
3855
|
+
max = ch.value;
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
return max;
|
|
3859
|
+
}
|
|
3860
|
+
get isInt() {
|
|
3861
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
3862
|
+
}
|
|
3863
|
+
get isFinite() {
|
|
3864
|
+
let max = null;
|
|
3865
|
+
let min = null;
|
|
3866
|
+
for (const ch of this._def.checks) {
|
|
3867
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
3868
|
+
return true;
|
|
3869
|
+
} else if (ch.kind === "min") {
|
|
3870
|
+
if (min === null || ch.value > min)
|
|
3871
|
+
min = ch.value;
|
|
3872
|
+
} else if (ch.kind === "max") {
|
|
3873
|
+
if (max === null || ch.value < max)
|
|
3874
|
+
max = ch.value;
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
3878
|
+
}
|
|
3879
|
+
};
|
|
3880
|
+
ZodNumber.create = (params) => {
|
|
3881
|
+
return new ZodNumber({
|
|
3882
|
+
checks: [],
|
|
3883
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
3884
|
+
coerce: params?.coerce || false,
|
|
3885
|
+
...processCreateParams(params)
|
|
3886
|
+
});
|
|
3887
|
+
};
|
|
3888
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
3889
|
+
constructor() {
|
|
3890
|
+
super(...arguments);
|
|
3891
|
+
this.min = this.gte;
|
|
3892
|
+
this.max = this.lte;
|
|
3893
|
+
}
|
|
3894
|
+
_parse(input) {
|
|
3895
|
+
if (this._def.coerce) {
|
|
3896
|
+
try {
|
|
3897
|
+
input.data = BigInt(input.data);
|
|
3898
|
+
} catch {
|
|
3899
|
+
return this._getInvalidInput(input);
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
const parsedType = this._getType(input);
|
|
3903
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
3904
|
+
return this._getInvalidInput(input);
|
|
3905
|
+
}
|
|
3906
|
+
let ctx = void 0;
|
|
3907
|
+
const status = new ParseStatus();
|
|
3908
|
+
for (const check of this._def.checks) {
|
|
3909
|
+
if (check.kind === "min") {
|
|
3910
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
3911
|
+
if (tooSmall) {
|
|
3912
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3913
|
+
addIssueToContext(ctx, {
|
|
3914
|
+
code: ZodIssueCode.too_small,
|
|
3915
|
+
type: "bigint",
|
|
3916
|
+
minimum: check.value,
|
|
3917
|
+
inclusive: check.inclusive,
|
|
3918
|
+
message: check.message
|
|
3919
|
+
});
|
|
3920
|
+
status.dirty();
|
|
3921
|
+
}
|
|
3922
|
+
} else if (check.kind === "max") {
|
|
3923
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
3924
|
+
if (tooBig) {
|
|
3925
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3926
|
+
addIssueToContext(ctx, {
|
|
3927
|
+
code: ZodIssueCode.too_big,
|
|
3928
|
+
type: "bigint",
|
|
3929
|
+
maximum: check.value,
|
|
3930
|
+
inclusive: check.inclusive,
|
|
3931
|
+
message: check.message
|
|
3932
|
+
});
|
|
3933
|
+
status.dirty();
|
|
3934
|
+
}
|
|
3935
|
+
} else if (check.kind === "multipleOf") {
|
|
3936
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
3937
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3938
|
+
addIssueToContext(ctx, {
|
|
3939
|
+
code: ZodIssueCode.not_multiple_of,
|
|
3940
|
+
multipleOf: check.value,
|
|
3941
|
+
message: check.message
|
|
3942
|
+
});
|
|
3943
|
+
status.dirty();
|
|
3944
|
+
}
|
|
3945
|
+
} else {
|
|
3946
|
+
util.assertNever(check);
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
return { status: status.value, value: input.data };
|
|
3950
|
+
}
|
|
3951
|
+
_getInvalidInput(input) {
|
|
3952
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3953
|
+
addIssueToContext(ctx, {
|
|
3954
|
+
code: ZodIssueCode.invalid_type,
|
|
3955
|
+
expected: ZodParsedType.bigint,
|
|
3956
|
+
received: ctx.parsedType
|
|
3957
|
+
});
|
|
3958
|
+
return INVALID;
|
|
3959
|
+
}
|
|
3960
|
+
gte(value, message) {
|
|
3961
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
3962
|
+
}
|
|
3963
|
+
gt(value, message) {
|
|
3964
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
3965
|
+
}
|
|
3966
|
+
lte(value, message) {
|
|
3967
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
3968
|
+
}
|
|
3969
|
+
lt(value, message) {
|
|
3970
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
3971
|
+
}
|
|
3972
|
+
setLimit(kind, value, inclusive, message) {
|
|
3973
|
+
return new _ZodBigInt({
|
|
3974
|
+
...this._def,
|
|
3975
|
+
checks: [
|
|
3976
|
+
...this._def.checks,
|
|
3977
|
+
{
|
|
3978
|
+
kind,
|
|
3979
|
+
value,
|
|
3980
|
+
inclusive,
|
|
3981
|
+
message: errorUtil.toString(message)
|
|
3982
|
+
}
|
|
3983
|
+
]
|
|
3984
|
+
});
|
|
3985
|
+
}
|
|
3986
|
+
_addCheck(check) {
|
|
3987
|
+
return new _ZodBigInt({
|
|
3988
|
+
...this._def,
|
|
3989
|
+
checks: [...this._def.checks, check]
|
|
3990
|
+
});
|
|
3991
|
+
}
|
|
3992
|
+
positive(message) {
|
|
3993
|
+
return this._addCheck({
|
|
3994
|
+
kind: "min",
|
|
3995
|
+
value: BigInt(0),
|
|
3996
|
+
inclusive: false,
|
|
3997
|
+
message: errorUtil.toString(message)
|
|
3998
|
+
});
|
|
3999
|
+
}
|
|
4000
|
+
negative(message) {
|
|
4001
|
+
return this._addCheck({
|
|
4002
|
+
kind: "max",
|
|
4003
|
+
value: BigInt(0),
|
|
4004
|
+
inclusive: false,
|
|
4005
|
+
message: errorUtil.toString(message)
|
|
4006
|
+
});
|
|
4007
|
+
}
|
|
4008
|
+
nonpositive(message) {
|
|
4009
|
+
return this._addCheck({
|
|
4010
|
+
kind: "max",
|
|
4011
|
+
value: BigInt(0),
|
|
4012
|
+
inclusive: true,
|
|
4013
|
+
message: errorUtil.toString(message)
|
|
4014
|
+
});
|
|
4015
|
+
}
|
|
4016
|
+
nonnegative(message) {
|
|
4017
|
+
return this._addCheck({
|
|
4018
|
+
kind: "min",
|
|
4019
|
+
value: BigInt(0),
|
|
4020
|
+
inclusive: true,
|
|
4021
|
+
message: errorUtil.toString(message)
|
|
4022
|
+
});
|
|
4023
|
+
}
|
|
4024
|
+
multipleOf(value, message) {
|
|
4025
|
+
return this._addCheck({
|
|
4026
|
+
kind: "multipleOf",
|
|
4027
|
+
value,
|
|
4028
|
+
message: errorUtil.toString(message)
|
|
4029
|
+
});
|
|
4030
|
+
}
|
|
4031
|
+
get minValue() {
|
|
4032
|
+
let min = null;
|
|
4033
|
+
for (const ch of this._def.checks) {
|
|
4034
|
+
if (ch.kind === "min") {
|
|
4035
|
+
if (min === null || ch.value > min)
|
|
4036
|
+
min = ch.value;
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
return min;
|
|
4040
|
+
}
|
|
4041
|
+
get maxValue() {
|
|
4042
|
+
let max = null;
|
|
4043
|
+
for (const ch of this._def.checks) {
|
|
4044
|
+
if (ch.kind === "max") {
|
|
4045
|
+
if (max === null || ch.value < max)
|
|
4046
|
+
max = ch.value;
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
return max;
|
|
4050
|
+
}
|
|
4051
|
+
};
|
|
4052
|
+
ZodBigInt.create = (params) => {
|
|
4053
|
+
return new ZodBigInt({
|
|
4054
|
+
checks: [],
|
|
4055
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
4056
|
+
coerce: params?.coerce ?? false,
|
|
4057
|
+
...processCreateParams(params)
|
|
4058
|
+
});
|
|
4059
|
+
};
|
|
4060
|
+
var ZodBoolean = class extends ZodType {
|
|
4061
|
+
_parse(input) {
|
|
4062
|
+
if (this._def.coerce) {
|
|
4063
|
+
input.data = Boolean(input.data);
|
|
4064
|
+
}
|
|
4065
|
+
const parsedType = this._getType(input);
|
|
4066
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
4067
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4068
|
+
addIssueToContext(ctx, {
|
|
4069
|
+
code: ZodIssueCode.invalid_type,
|
|
4070
|
+
expected: ZodParsedType.boolean,
|
|
4071
|
+
received: ctx.parsedType
|
|
4072
|
+
});
|
|
4073
|
+
return INVALID;
|
|
4074
|
+
}
|
|
4075
|
+
return OK(input.data);
|
|
4076
|
+
}
|
|
4077
|
+
};
|
|
4078
|
+
ZodBoolean.create = (params) => {
|
|
4079
|
+
return new ZodBoolean({
|
|
4080
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
4081
|
+
coerce: params?.coerce || false,
|
|
4082
|
+
...processCreateParams(params)
|
|
4083
|
+
});
|
|
4084
|
+
};
|
|
4085
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
4086
|
+
_parse(input) {
|
|
4087
|
+
if (this._def.coerce) {
|
|
4088
|
+
input.data = new Date(input.data);
|
|
4089
|
+
}
|
|
4090
|
+
const parsedType = this._getType(input);
|
|
4091
|
+
if (parsedType !== ZodParsedType.date) {
|
|
4092
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
4093
|
+
addIssueToContext(ctx2, {
|
|
4094
|
+
code: ZodIssueCode.invalid_type,
|
|
4095
|
+
expected: ZodParsedType.date,
|
|
4096
|
+
received: ctx2.parsedType
|
|
4097
|
+
});
|
|
4098
|
+
return INVALID;
|
|
4099
|
+
}
|
|
4100
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
4101
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
4102
|
+
addIssueToContext(ctx2, {
|
|
4103
|
+
code: ZodIssueCode.invalid_date
|
|
4104
|
+
});
|
|
4105
|
+
return INVALID;
|
|
4106
|
+
}
|
|
4107
|
+
const status = new ParseStatus();
|
|
4108
|
+
let ctx = void 0;
|
|
4109
|
+
for (const check of this._def.checks) {
|
|
4110
|
+
if (check.kind === "min") {
|
|
4111
|
+
if (input.data.getTime() < check.value) {
|
|
4112
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
4113
|
+
addIssueToContext(ctx, {
|
|
4114
|
+
code: ZodIssueCode.too_small,
|
|
4115
|
+
message: check.message,
|
|
4116
|
+
inclusive: true,
|
|
4117
|
+
exact: false,
|
|
4118
|
+
minimum: check.value,
|
|
4119
|
+
type: "date"
|
|
4120
|
+
});
|
|
4121
|
+
status.dirty();
|
|
4122
|
+
}
|
|
4123
|
+
} else if (check.kind === "max") {
|
|
4124
|
+
if (input.data.getTime() > check.value) {
|
|
4125
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
4126
|
+
addIssueToContext(ctx, {
|
|
4127
|
+
code: ZodIssueCode.too_big,
|
|
4128
|
+
message: check.message,
|
|
4129
|
+
inclusive: true,
|
|
4130
|
+
exact: false,
|
|
4131
|
+
maximum: check.value,
|
|
4132
|
+
type: "date"
|
|
4133
|
+
});
|
|
4134
|
+
status.dirty();
|
|
4135
|
+
}
|
|
4136
|
+
} else {
|
|
4137
|
+
util.assertNever(check);
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
return {
|
|
4141
|
+
status: status.value,
|
|
4142
|
+
value: new Date(input.data.getTime())
|
|
4143
|
+
};
|
|
4144
|
+
}
|
|
4145
|
+
_addCheck(check) {
|
|
4146
|
+
return new _ZodDate({
|
|
4147
|
+
...this._def,
|
|
4148
|
+
checks: [...this._def.checks, check]
|
|
4149
|
+
});
|
|
4150
|
+
}
|
|
4151
|
+
min(minDate, message) {
|
|
4152
|
+
return this._addCheck({
|
|
4153
|
+
kind: "min",
|
|
4154
|
+
value: minDate.getTime(),
|
|
4155
|
+
message: errorUtil.toString(message)
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4158
|
+
max(maxDate, message) {
|
|
4159
|
+
return this._addCheck({
|
|
4160
|
+
kind: "max",
|
|
4161
|
+
value: maxDate.getTime(),
|
|
4162
|
+
message: errorUtil.toString(message)
|
|
4163
|
+
});
|
|
4164
|
+
}
|
|
4165
|
+
get minDate() {
|
|
4166
|
+
let min = null;
|
|
4167
|
+
for (const ch of this._def.checks) {
|
|
4168
|
+
if (ch.kind === "min") {
|
|
4169
|
+
if (min === null || ch.value > min)
|
|
4170
|
+
min = ch.value;
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
return min != null ? new Date(min) : null;
|
|
4174
|
+
}
|
|
4175
|
+
get maxDate() {
|
|
4176
|
+
let max = null;
|
|
4177
|
+
for (const ch of this._def.checks) {
|
|
4178
|
+
if (ch.kind === "max") {
|
|
4179
|
+
if (max === null || ch.value < max)
|
|
4180
|
+
max = ch.value;
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
return max != null ? new Date(max) : null;
|
|
4184
|
+
}
|
|
4185
|
+
};
|
|
4186
|
+
ZodDate.create = (params) => {
|
|
4187
|
+
return new ZodDate({
|
|
4188
|
+
checks: [],
|
|
4189
|
+
coerce: params?.coerce || false,
|
|
4190
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
4191
|
+
...processCreateParams(params)
|
|
4192
|
+
});
|
|
4193
|
+
};
|
|
4194
|
+
var ZodSymbol = class extends ZodType {
|
|
4195
|
+
_parse(input) {
|
|
4196
|
+
const parsedType = this._getType(input);
|
|
4197
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
4198
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4199
|
+
addIssueToContext(ctx, {
|
|
4200
|
+
code: ZodIssueCode.invalid_type,
|
|
4201
|
+
expected: ZodParsedType.symbol,
|
|
4202
|
+
received: ctx.parsedType
|
|
4203
|
+
});
|
|
4204
|
+
return INVALID;
|
|
4205
|
+
}
|
|
4206
|
+
return OK(input.data);
|
|
4207
|
+
}
|
|
4208
|
+
};
|
|
4209
|
+
ZodSymbol.create = (params) => {
|
|
4210
|
+
return new ZodSymbol({
|
|
4211
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
4212
|
+
...processCreateParams(params)
|
|
4213
|
+
});
|
|
4214
|
+
};
|
|
4215
|
+
var ZodUndefined = class extends ZodType {
|
|
4216
|
+
_parse(input) {
|
|
4217
|
+
const parsedType = this._getType(input);
|
|
4218
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
4219
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4220
|
+
addIssueToContext(ctx, {
|
|
4221
|
+
code: ZodIssueCode.invalid_type,
|
|
4222
|
+
expected: ZodParsedType.undefined,
|
|
4223
|
+
received: ctx.parsedType
|
|
4224
|
+
});
|
|
4225
|
+
return INVALID;
|
|
4226
|
+
}
|
|
4227
|
+
return OK(input.data);
|
|
4228
|
+
}
|
|
4229
|
+
};
|
|
4230
|
+
ZodUndefined.create = (params) => {
|
|
4231
|
+
return new ZodUndefined({
|
|
4232
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
4233
|
+
...processCreateParams(params)
|
|
4234
|
+
});
|
|
4235
|
+
};
|
|
4236
|
+
var ZodNull = class extends ZodType {
|
|
4237
|
+
_parse(input) {
|
|
4238
|
+
const parsedType = this._getType(input);
|
|
4239
|
+
if (parsedType !== ZodParsedType.null) {
|
|
4240
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4241
|
+
addIssueToContext(ctx, {
|
|
4242
|
+
code: ZodIssueCode.invalid_type,
|
|
4243
|
+
expected: ZodParsedType.null,
|
|
4244
|
+
received: ctx.parsedType
|
|
4245
|
+
});
|
|
4246
|
+
return INVALID;
|
|
4247
|
+
}
|
|
4248
|
+
return OK(input.data);
|
|
4249
|
+
}
|
|
4250
|
+
};
|
|
4251
|
+
ZodNull.create = (params) => {
|
|
4252
|
+
return new ZodNull({
|
|
4253
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
4254
|
+
...processCreateParams(params)
|
|
4255
|
+
});
|
|
4256
|
+
};
|
|
4257
|
+
var ZodAny = class extends ZodType {
|
|
4258
|
+
constructor() {
|
|
4259
|
+
super(...arguments);
|
|
4260
|
+
this._any = true;
|
|
4261
|
+
}
|
|
4262
|
+
_parse(input) {
|
|
4263
|
+
return OK(input.data);
|
|
4264
|
+
}
|
|
4265
|
+
};
|
|
4266
|
+
ZodAny.create = (params) => {
|
|
4267
|
+
return new ZodAny({
|
|
4268
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
4269
|
+
...processCreateParams(params)
|
|
4270
|
+
});
|
|
4271
|
+
};
|
|
4272
|
+
var ZodUnknown = class extends ZodType {
|
|
4273
|
+
constructor() {
|
|
4274
|
+
super(...arguments);
|
|
4275
|
+
this._unknown = true;
|
|
4276
|
+
}
|
|
4277
|
+
_parse(input) {
|
|
4278
|
+
return OK(input.data);
|
|
4279
|
+
}
|
|
4280
|
+
};
|
|
4281
|
+
ZodUnknown.create = (params) => {
|
|
4282
|
+
return new ZodUnknown({
|
|
4283
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
4284
|
+
...processCreateParams(params)
|
|
4285
|
+
});
|
|
4286
|
+
};
|
|
4287
|
+
var ZodNever = class extends ZodType {
|
|
4288
|
+
_parse(input) {
|
|
4289
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4290
|
+
addIssueToContext(ctx, {
|
|
4291
|
+
code: ZodIssueCode.invalid_type,
|
|
4292
|
+
expected: ZodParsedType.never,
|
|
4293
|
+
received: ctx.parsedType
|
|
4294
|
+
});
|
|
4295
|
+
return INVALID;
|
|
4296
|
+
}
|
|
4297
|
+
};
|
|
4298
|
+
ZodNever.create = (params) => {
|
|
4299
|
+
return new ZodNever({
|
|
4300
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
4301
|
+
...processCreateParams(params)
|
|
4302
|
+
});
|
|
4303
|
+
};
|
|
4304
|
+
var ZodVoid = class extends ZodType {
|
|
4305
|
+
_parse(input) {
|
|
4306
|
+
const parsedType = this._getType(input);
|
|
4307
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
4308
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4309
|
+
addIssueToContext(ctx, {
|
|
4310
|
+
code: ZodIssueCode.invalid_type,
|
|
4311
|
+
expected: ZodParsedType.void,
|
|
4312
|
+
received: ctx.parsedType
|
|
4313
|
+
});
|
|
4314
|
+
return INVALID;
|
|
4315
|
+
}
|
|
4316
|
+
return OK(input.data);
|
|
4317
|
+
}
|
|
4318
|
+
};
|
|
4319
|
+
ZodVoid.create = (params) => {
|
|
4320
|
+
return new ZodVoid({
|
|
4321
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
4322
|
+
...processCreateParams(params)
|
|
4323
|
+
});
|
|
4324
|
+
};
|
|
4325
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
4326
|
+
_parse(input) {
|
|
4327
|
+
const { ctx, status } = this._processInputParams(input);
|
|
4328
|
+
const def = this._def;
|
|
4329
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
4330
|
+
addIssueToContext(ctx, {
|
|
4331
|
+
code: ZodIssueCode.invalid_type,
|
|
4332
|
+
expected: ZodParsedType.array,
|
|
4333
|
+
received: ctx.parsedType
|
|
4334
|
+
});
|
|
4335
|
+
return INVALID;
|
|
4336
|
+
}
|
|
4337
|
+
if (def.exactLength !== null) {
|
|
4338
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
4339
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
4340
|
+
if (tooBig || tooSmall) {
|
|
4341
|
+
addIssueToContext(ctx, {
|
|
4342
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
4343
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
4344
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
4345
|
+
type: "array",
|
|
4346
|
+
inclusive: true,
|
|
4347
|
+
exact: true,
|
|
4348
|
+
message: def.exactLength.message
|
|
4349
|
+
});
|
|
4350
|
+
status.dirty();
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
if (def.minLength !== null) {
|
|
4354
|
+
if (ctx.data.length < def.minLength.value) {
|
|
4355
|
+
addIssueToContext(ctx, {
|
|
4356
|
+
code: ZodIssueCode.too_small,
|
|
4357
|
+
minimum: def.minLength.value,
|
|
4358
|
+
type: "array",
|
|
4359
|
+
inclusive: true,
|
|
4360
|
+
exact: false,
|
|
4361
|
+
message: def.minLength.message
|
|
4362
|
+
});
|
|
4363
|
+
status.dirty();
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
if (def.maxLength !== null) {
|
|
4367
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
4368
|
+
addIssueToContext(ctx, {
|
|
4369
|
+
code: ZodIssueCode.too_big,
|
|
4370
|
+
maximum: def.maxLength.value,
|
|
4371
|
+
type: "array",
|
|
4372
|
+
inclusive: true,
|
|
4373
|
+
exact: false,
|
|
4374
|
+
message: def.maxLength.message
|
|
4375
|
+
});
|
|
4376
|
+
status.dirty();
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
if (ctx.common.async) {
|
|
4380
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
4381
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
4382
|
+
})).then((result2) => {
|
|
4383
|
+
return ParseStatus.mergeArray(status, result2);
|
|
4384
|
+
});
|
|
4385
|
+
}
|
|
4386
|
+
const result = [...ctx.data].map((item, i) => {
|
|
4387
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
4388
|
+
});
|
|
4389
|
+
return ParseStatus.mergeArray(status, result);
|
|
4390
|
+
}
|
|
4391
|
+
get element() {
|
|
4392
|
+
return this._def.type;
|
|
4393
|
+
}
|
|
4394
|
+
min(minLength, message) {
|
|
4395
|
+
return new _ZodArray({
|
|
4396
|
+
...this._def,
|
|
4397
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
4398
|
+
});
|
|
4399
|
+
}
|
|
4400
|
+
max(maxLength, message) {
|
|
4401
|
+
return new _ZodArray({
|
|
4402
|
+
...this._def,
|
|
4403
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
4404
|
+
});
|
|
4405
|
+
}
|
|
4406
|
+
length(len, message) {
|
|
4407
|
+
return new _ZodArray({
|
|
4408
|
+
...this._def,
|
|
4409
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
4410
|
+
});
|
|
4411
|
+
}
|
|
4412
|
+
nonempty(message) {
|
|
4413
|
+
return this.min(1, message);
|
|
4414
|
+
}
|
|
4415
|
+
};
|
|
4416
|
+
ZodArray.create = (schema, params) => {
|
|
4417
|
+
return new ZodArray({
|
|
4418
|
+
type: schema,
|
|
4419
|
+
minLength: null,
|
|
4420
|
+
maxLength: null,
|
|
4421
|
+
exactLength: null,
|
|
4422
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
4423
|
+
...processCreateParams(params)
|
|
4424
|
+
});
|
|
4425
|
+
};
|
|
4426
|
+
function deepPartialify(schema) {
|
|
4427
|
+
if (schema instanceof ZodObject) {
|
|
4428
|
+
const newShape = {};
|
|
4429
|
+
for (const key in schema.shape) {
|
|
4430
|
+
const fieldSchema = schema.shape[key];
|
|
4431
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
4432
|
+
}
|
|
4433
|
+
return new ZodObject({
|
|
4434
|
+
...schema._def,
|
|
4435
|
+
shape: () => newShape
|
|
4436
|
+
});
|
|
4437
|
+
} else if (schema instanceof ZodArray) {
|
|
4438
|
+
return new ZodArray({
|
|
4439
|
+
...schema._def,
|
|
4440
|
+
type: deepPartialify(schema.element)
|
|
4441
|
+
});
|
|
4442
|
+
} else if (schema instanceof ZodOptional) {
|
|
4443
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
4444
|
+
} else if (schema instanceof ZodNullable) {
|
|
4445
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
4446
|
+
} else if (schema instanceof ZodTuple) {
|
|
4447
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
4448
|
+
} else {
|
|
4449
|
+
return schema;
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
4453
|
+
constructor() {
|
|
4454
|
+
super(...arguments);
|
|
4455
|
+
this._cached = null;
|
|
4456
|
+
this.nonstrict = this.passthrough;
|
|
4457
|
+
this.augment = this.extend;
|
|
4458
|
+
}
|
|
4459
|
+
_getCached() {
|
|
4460
|
+
if (this._cached !== null)
|
|
4461
|
+
return this._cached;
|
|
4462
|
+
const shape = this._def.shape();
|
|
4463
|
+
const keys = util.objectKeys(shape);
|
|
4464
|
+
this._cached = { shape, keys };
|
|
4465
|
+
return this._cached;
|
|
4466
|
+
}
|
|
4467
|
+
_parse(input) {
|
|
4468
|
+
const parsedType = this._getType(input);
|
|
4469
|
+
if (parsedType !== ZodParsedType.object) {
|
|
4470
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
4471
|
+
addIssueToContext(ctx2, {
|
|
4472
|
+
code: ZodIssueCode.invalid_type,
|
|
4473
|
+
expected: ZodParsedType.object,
|
|
4474
|
+
received: ctx2.parsedType
|
|
4475
|
+
});
|
|
4476
|
+
return INVALID;
|
|
4477
|
+
}
|
|
4478
|
+
const { status, ctx } = this._processInputParams(input);
|
|
4479
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
4480
|
+
const extraKeys = [];
|
|
4481
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
4482
|
+
for (const key in ctx.data) {
|
|
4483
|
+
if (!shapeKeys.includes(key)) {
|
|
4484
|
+
extraKeys.push(key);
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
const pairs = [];
|
|
4489
|
+
for (const key of shapeKeys) {
|
|
4490
|
+
const keyValidator = shape[key];
|
|
4491
|
+
const value = ctx.data[key];
|
|
4492
|
+
pairs.push({
|
|
4493
|
+
key: { status: "valid", value: key },
|
|
4494
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
4495
|
+
alwaysSet: key in ctx.data
|
|
4496
|
+
});
|
|
4497
|
+
}
|
|
4498
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
4499
|
+
const unknownKeys = this._def.unknownKeys;
|
|
4500
|
+
if (unknownKeys === "passthrough") {
|
|
4501
|
+
for (const key of extraKeys) {
|
|
4502
|
+
pairs.push({
|
|
4503
|
+
key: { status: "valid", value: key },
|
|
4504
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
4505
|
+
});
|
|
4506
|
+
}
|
|
4507
|
+
} else if (unknownKeys === "strict") {
|
|
4508
|
+
if (extraKeys.length > 0) {
|
|
4509
|
+
addIssueToContext(ctx, {
|
|
4510
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
4511
|
+
keys: extraKeys
|
|
4512
|
+
});
|
|
4513
|
+
status.dirty();
|
|
4514
|
+
}
|
|
4515
|
+
} else if (unknownKeys === "strip") {
|
|
4516
|
+
} else {
|
|
4517
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
4518
|
+
}
|
|
4519
|
+
} else {
|
|
4520
|
+
const catchall = this._def.catchall;
|
|
4521
|
+
for (const key of extraKeys) {
|
|
4522
|
+
const value = ctx.data[key];
|
|
4523
|
+
pairs.push({
|
|
4524
|
+
key: { status: "valid", value: key },
|
|
4525
|
+
value: catchall._parse(
|
|
4526
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
4527
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
4528
|
+
),
|
|
4529
|
+
alwaysSet: key in ctx.data
|
|
4530
|
+
});
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
if (ctx.common.async) {
|
|
4534
|
+
return Promise.resolve().then(async () => {
|
|
4535
|
+
const syncPairs = [];
|
|
4536
|
+
for (const pair of pairs) {
|
|
4537
|
+
const key = await pair.key;
|
|
4538
|
+
const value = await pair.value;
|
|
4539
|
+
syncPairs.push({
|
|
4540
|
+
key,
|
|
4541
|
+
value,
|
|
4542
|
+
alwaysSet: pair.alwaysSet
|
|
4543
|
+
});
|
|
4544
|
+
}
|
|
4545
|
+
return syncPairs;
|
|
4546
|
+
}).then((syncPairs) => {
|
|
4547
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
4548
|
+
});
|
|
4549
|
+
} else {
|
|
4550
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
get shape() {
|
|
4554
|
+
return this._def.shape();
|
|
4555
|
+
}
|
|
4556
|
+
strict(message) {
|
|
4557
|
+
errorUtil.errToObj;
|
|
4558
|
+
return new _ZodObject({
|
|
4559
|
+
...this._def,
|
|
4560
|
+
unknownKeys: "strict",
|
|
4561
|
+
...message !== void 0 ? {
|
|
4562
|
+
errorMap: (issue, ctx) => {
|
|
4563
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
4564
|
+
if (issue.code === "unrecognized_keys")
|
|
4565
|
+
return {
|
|
4566
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
4567
|
+
};
|
|
4568
|
+
return {
|
|
4569
|
+
message: defaultError
|
|
4570
|
+
};
|
|
4571
|
+
}
|
|
4572
|
+
} : {}
|
|
4573
|
+
});
|
|
4574
|
+
}
|
|
4575
|
+
strip() {
|
|
4576
|
+
return new _ZodObject({
|
|
4577
|
+
...this._def,
|
|
4578
|
+
unknownKeys: "strip"
|
|
4579
|
+
});
|
|
4580
|
+
}
|
|
4581
|
+
passthrough() {
|
|
4582
|
+
return new _ZodObject({
|
|
4583
|
+
...this._def,
|
|
4584
|
+
unknownKeys: "passthrough"
|
|
4585
|
+
});
|
|
4586
|
+
}
|
|
4587
|
+
// const AugmentFactory =
|
|
4588
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
4589
|
+
// <Augmentation extends ZodRawShape>(
|
|
4590
|
+
// augmentation: Augmentation
|
|
4591
|
+
// ): ZodObject<
|
|
4592
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
4593
|
+
// Def["unknownKeys"],
|
|
4594
|
+
// Def["catchall"]
|
|
4595
|
+
// > => {
|
|
4596
|
+
// return new ZodObject({
|
|
4597
|
+
// ...def,
|
|
4598
|
+
// shape: () => ({
|
|
4599
|
+
// ...def.shape(),
|
|
4600
|
+
// ...augmentation,
|
|
4601
|
+
// }),
|
|
4602
|
+
// }) as any;
|
|
4603
|
+
// };
|
|
4604
|
+
extend(augmentation) {
|
|
4605
|
+
return new _ZodObject({
|
|
4606
|
+
...this._def,
|
|
4607
|
+
shape: () => ({
|
|
4608
|
+
...this._def.shape(),
|
|
4609
|
+
...augmentation
|
|
4610
|
+
})
|
|
4611
|
+
});
|
|
4612
|
+
}
|
|
4613
|
+
/**
|
|
4614
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
4615
|
+
* inferred type of merged objects. Please
|
|
4616
|
+
* upgrade if you are experiencing issues.
|
|
4617
|
+
*/
|
|
4618
|
+
merge(merging) {
|
|
4619
|
+
const merged = new _ZodObject({
|
|
4620
|
+
unknownKeys: merging._def.unknownKeys,
|
|
4621
|
+
catchall: merging._def.catchall,
|
|
4622
|
+
shape: () => ({
|
|
4623
|
+
...this._def.shape(),
|
|
4624
|
+
...merging._def.shape()
|
|
4625
|
+
}),
|
|
4626
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
4627
|
+
});
|
|
4628
|
+
return merged;
|
|
4629
|
+
}
|
|
4630
|
+
// merge<
|
|
4631
|
+
// Incoming extends AnyZodObject,
|
|
4632
|
+
// Augmentation extends Incoming["shape"],
|
|
4633
|
+
// NewOutput extends {
|
|
4634
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
4635
|
+
// ? Augmentation[k]["_output"]
|
|
4636
|
+
// : k extends keyof Output
|
|
4637
|
+
// ? Output[k]
|
|
4638
|
+
// : never;
|
|
4639
|
+
// },
|
|
4640
|
+
// NewInput extends {
|
|
4641
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
4642
|
+
// ? Augmentation[k]["_input"]
|
|
4643
|
+
// : k extends keyof Input
|
|
4644
|
+
// ? Input[k]
|
|
4645
|
+
// : never;
|
|
4646
|
+
// }
|
|
4647
|
+
// >(
|
|
4648
|
+
// merging: Incoming
|
|
4649
|
+
// ): ZodObject<
|
|
4650
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
4651
|
+
// Incoming["_def"]["unknownKeys"],
|
|
4652
|
+
// Incoming["_def"]["catchall"],
|
|
4653
|
+
// NewOutput,
|
|
4654
|
+
// NewInput
|
|
4655
|
+
// > {
|
|
4656
|
+
// const merged: any = new ZodObject({
|
|
4657
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
4658
|
+
// catchall: merging._def.catchall,
|
|
4659
|
+
// shape: () =>
|
|
4660
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
4661
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
4662
|
+
// }) as any;
|
|
4663
|
+
// return merged;
|
|
4664
|
+
// }
|
|
4665
|
+
setKey(key, schema) {
|
|
4666
|
+
return this.augment({ [key]: schema });
|
|
4667
|
+
}
|
|
4668
|
+
// merge<Incoming extends AnyZodObject>(
|
|
4669
|
+
// merging: Incoming
|
|
4670
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
4671
|
+
// ZodObject<
|
|
4672
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
4673
|
+
// Incoming["_def"]["unknownKeys"],
|
|
4674
|
+
// Incoming["_def"]["catchall"]
|
|
4675
|
+
// > {
|
|
4676
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
4677
|
+
// // this._def.shape(),
|
|
4678
|
+
// // merging._def.shape()
|
|
4679
|
+
// // );
|
|
4680
|
+
// const merged: any = new ZodObject({
|
|
4681
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
4682
|
+
// catchall: merging._def.catchall,
|
|
4683
|
+
// shape: () =>
|
|
4684
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
4685
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
4686
|
+
// }) as any;
|
|
4687
|
+
// return merged;
|
|
4688
|
+
// }
|
|
4689
|
+
catchall(index) {
|
|
4690
|
+
return new _ZodObject({
|
|
4691
|
+
...this._def,
|
|
4692
|
+
catchall: index
|
|
4693
|
+
});
|
|
4694
|
+
}
|
|
4695
|
+
pick(mask) {
|
|
4696
|
+
const shape = {};
|
|
4697
|
+
for (const key of util.objectKeys(mask)) {
|
|
4698
|
+
if (mask[key] && this.shape[key]) {
|
|
4699
|
+
shape[key] = this.shape[key];
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
return new _ZodObject({
|
|
4703
|
+
...this._def,
|
|
4704
|
+
shape: () => shape
|
|
4705
|
+
});
|
|
4706
|
+
}
|
|
4707
|
+
omit(mask) {
|
|
4708
|
+
const shape = {};
|
|
4709
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4710
|
+
if (!mask[key]) {
|
|
4711
|
+
shape[key] = this.shape[key];
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
return new _ZodObject({
|
|
4715
|
+
...this._def,
|
|
4716
|
+
shape: () => shape
|
|
4717
|
+
});
|
|
4718
|
+
}
|
|
4719
|
+
/**
|
|
4720
|
+
* @deprecated
|
|
4721
|
+
*/
|
|
4722
|
+
deepPartial() {
|
|
4723
|
+
return deepPartialify(this);
|
|
4724
|
+
}
|
|
4725
|
+
partial(mask) {
|
|
4726
|
+
const newShape = {};
|
|
4727
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4728
|
+
const fieldSchema = this.shape[key];
|
|
4729
|
+
if (mask && !mask[key]) {
|
|
4730
|
+
newShape[key] = fieldSchema;
|
|
4731
|
+
} else {
|
|
4732
|
+
newShape[key] = fieldSchema.optional();
|
|
4733
|
+
}
|
|
4734
|
+
}
|
|
4735
|
+
return new _ZodObject({
|
|
4736
|
+
...this._def,
|
|
4737
|
+
shape: () => newShape
|
|
4738
|
+
});
|
|
4739
|
+
}
|
|
4740
|
+
required(mask) {
|
|
4741
|
+
const newShape = {};
|
|
4742
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4743
|
+
if (mask && !mask[key]) {
|
|
4744
|
+
newShape[key] = this.shape[key];
|
|
4745
|
+
} else {
|
|
4746
|
+
const fieldSchema = this.shape[key];
|
|
4747
|
+
let newField = fieldSchema;
|
|
4748
|
+
while (newField instanceof ZodOptional) {
|
|
4749
|
+
newField = newField._def.innerType;
|
|
4750
|
+
}
|
|
4751
|
+
newShape[key] = newField;
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
return new _ZodObject({
|
|
4755
|
+
...this._def,
|
|
4756
|
+
shape: () => newShape
|
|
4757
|
+
});
|
|
4758
|
+
}
|
|
4759
|
+
keyof() {
|
|
4760
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
4761
|
+
}
|
|
4762
|
+
};
|
|
4763
|
+
ZodObject.create = (shape, params) => {
|
|
4764
|
+
return new ZodObject({
|
|
4765
|
+
shape: () => shape,
|
|
4766
|
+
unknownKeys: "strip",
|
|
4767
|
+
catchall: ZodNever.create(),
|
|
4768
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
4769
|
+
...processCreateParams(params)
|
|
4770
|
+
});
|
|
4771
|
+
};
|
|
4772
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
4773
|
+
return new ZodObject({
|
|
4774
|
+
shape: () => shape,
|
|
4775
|
+
unknownKeys: "strict",
|
|
4776
|
+
catchall: ZodNever.create(),
|
|
4777
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
4778
|
+
...processCreateParams(params)
|
|
4779
|
+
});
|
|
4780
|
+
};
|
|
4781
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
4782
|
+
return new ZodObject({
|
|
4783
|
+
shape,
|
|
4784
|
+
unknownKeys: "strip",
|
|
4785
|
+
catchall: ZodNever.create(),
|
|
4786
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
4787
|
+
...processCreateParams(params)
|
|
4788
|
+
});
|
|
4789
|
+
};
|
|
4790
|
+
var ZodUnion = class extends ZodType {
|
|
4791
|
+
_parse(input) {
|
|
4792
|
+
const { ctx } = this._processInputParams(input);
|
|
4793
|
+
const options = this._def.options;
|
|
4794
|
+
function handleResults(results) {
|
|
4795
|
+
for (const result of results) {
|
|
4796
|
+
if (result.result.status === "valid") {
|
|
4797
|
+
return result.result;
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4800
|
+
for (const result of results) {
|
|
4801
|
+
if (result.result.status === "dirty") {
|
|
4802
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
4803
|
+
return result.result;
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
4807
|
+
addIssueToContext(ctx, {
|
|
4808
|
+
code: ZodIssueCode.invalid_union,
|
|
4809
|
+
unionErrors
|
|
4810
|
+
});
|
|
4811
|
+
return INVALID;
|
|
4812
|
+
}
|
|
4813
|
+
if (ctx.common.async) {
|
|
4814
|
+
return Promise.all(options.map(async (option) => {
|
|
4815
|
+
const childCtx = {
|
|
4816
|
+
...ctx,
|
|
4817
|
+
common: {
|
|
4818
|
+
...ctx.common,
|
|
4819
|
+
issues: []
|
|
4820
|
+
},
|
|
4821
|
+
parent: null
|
|
4822
|
+
};
|
|
4823
|
+
return {
|
|
4824
|
+
result: await option._parseAsync({
|
|
4825
|
+
data: ctx.data,
|
|
4826
|
+
path: ctx.path,
|
|
4827
|
+
parent: childCtx
|
|
4828
|
+
}),
|
|
4829
|
+
ctx: childCtx
|
|
4830
|
+
};
|
|
4831
|
+
})).then(handleResults);
|
|
4832
|
+
} else {
|
|
4833
|
+
let dirty = void 0;
|
|
4834
|
+
const issues = [];
|
|
4835
|
+
for (const option of options) {
|
|
4836
|
+
const childCtx = {
|
|
4837
|
+
...ctx,
|
|
4838
|
+
common: {
|
|
4839
|
+
...ctx.common,
|
|
4840
|
+
issues: []
|
|
4841
|
+
},
|
|
4842
|
+
parent: null
|
|
4843
|
+
};
|
|
4844
|
+
const result = option._parseSync({
|
|
4845
|
+
data: ctx.data,
|
|
4846
|
+
path: ctx.path,
|
|
4847
|
+
parent: childCtx
|
|
4848
|
+
});
|
|
4849
|
+
if (result.status === "valid") {
|
|
4850
|
+
return result;
|
|
4851
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
4852
|
+
dirty = { result, ctx: childCtx };
|
|
4853
|
+
}
|
|
4854
|
+
if (childCtx.common.issues.length) {
|
|
4855
|
+
issues.push(childCtx.common.issues);
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
if (dirty) {
|
|
4859
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
4860
|
+
return dirty.result;
|
|
4861
|
+
}
|
|
4862
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
4863
|
+
addIssueToContext(ctx, {
|
|
4864
|
+
code: ZodIssueCode.invalid_union,
|
|
4865
|
+
unionErrors
|
|
4866
|
+
});
|
|
4867
|
+
return INVALID;
|
|
4868
|
+
}
|
|
4869
|
+
}
|
|
4870
|
+
get options() {
|
|
4871
|
+
return this._def.options;
|
|
4872
|
+
}
|
|
4873
|
+
};
|
|
4874
|
+
ZodUnion.create = (types, params) => {
|
|
4875
|
+
return new ZodUnion({
|
|
4876
|
+
options: types,
|
|
4877
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
4878
|
+
...processCreateParams(params)
|
|
4879
|
+
});
|
|
4880
|
+
};
|
|
4881
|
+
var getDiscriminator = (type) => {
|
|
4882
|
+
if (type instanceof ZodLazy) {
|
|
4883
|
+
return getDiscriminator(type.schema);
|
|
4884
|
+
} else if (type instanceof ZodEffects) {
|
|
4885
|
+
return getDiscriminator(type.innerType());
|
|
4886
|
+
} else if (type instanceof ZodLiteral) {
|
|
4887
|
+
return [type.value];
|
|
4888
|
+
} else if (type instanceof ZodEnum) {
|
|
4889
|
+
return type.options;
|
|
4890
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
4891
|
+
return util.objectValues(type.enum);
|
|
4892
|
+
} else if (type instanceof ZodDefault) {
|
|
4893
|
+
return getDiscriminator(type._def.innerType);
|
|
4894
|
+
} else if (type instanceof ZodUndefined) {
|
|
4895
|
+
return [void 0];
|
|
4896
|
+
} else if (type instanceof ZodNull) {
|
|
4897
|
+
return [null];
|
|
4898
|
+
} else if (type instanceof ZodOptional) {
|
|
4899
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
4900
|
+
} else if (type instanceof ZodNullable) {
|
|
4901
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
4902
|
+
} else if (type instanceof ZodBranded) {
|
|
4903
|
+
return getDiscriminator(type.unwrap());
|
|
4904
|
+
} else if (type instanceof ZodReadonly) {
|
|
4905
|
+
return getDiscriminator(type.unwrap());
|
|
4906
|
+
} else if (type instanceof ZodCatch) {
|
|
4907
|
+
return getDiscriminator(type._def.innerType);
|
|
4908
|
+
} else {
|
|
4909
|
+
return [];
|
|
4910
|
+
}
|
|
4911
|
+
};
|
|
4912
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
4913
|
+
_parse(input) {
|
|
4914
|
+
const { ctx } = this._processInputParams(input);
|
|
4915
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4916
|
+
addIssueToContext(ctx, {
|
|
4917
|
+
code: ZodIssueCode.invalid_type,
|
|
4918
|
+
expected: ZodParsedType.object,
|
|
4919
|
+
received: ctx.parsedType
|
|
4920
|
+
});
|
|
4921
|
+
return INVALID;
|
|
4922
|
+
}
|
|
4923
|
+
const discriminator = this.discriminator;
|
|
4924
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
4925
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
4926
|
+
if (!option) {
|
|
4927
|
+
addIssueToContext(ctx, {
|
|
4928
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
4929
|
+
options: Array.from(this.optionsMap.keys()),
|
|
4930
|
+
path: [discriminator]
|
|
4931
|
+
});
|
|
4932
|
+
return INVALID;
|
|
4933
|
+
}
|
|
4934
|
+
if (ctx.common.async) {
|
|
4935
|
+
return option._parseAsync({
|
|
4936
|
+
data: ctx.data,
|
|
4937
|
+
path: ctx.path,
|
|
4938
|
+
parent: ctx
|
|
4939
|
+
});
|
|
4940
|
+
} else {
|
|
4941
|
+
return option._parseSync({
|
|
4942
|
+
data: ctx.data,
|
|
4943
|
+
path: ctx.path,
|
|
4944
|
+
parent: ctx
|
|
4945
|
+
});
|
|
4946
|
+
}
|
|
4947
|
+
}
|
|
4948
|
+
get discriminator() {
|
|
4949
|
+
return this._def.discriminator;
|
|
4950
|
+
}
|
|
4951
|
+
get options() {
|
|
4952
|
+
return this._def.options;
|
|
4953
|
+
}
|
|
4954
|
+
get optionsMap() {
|
|
4955
|
+
return this._def.optionsMap;
|
|
4956
|
+
}
|
|
4957
|
+
/**
|
|
4958
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
4959
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
4960
|
+
* have a different value for each object in the union.
|
|
4961
|
+
* @param discriminator the name of the discriminator property
|
|
4962
|
+
* @param types an array of object schemas
|
|
4963
|
+
* @param params
|
|
4964
|
+
*/
|
|
4965
|
+
static create(discriminator, options, params) {
|
|
4966
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
4967
|
+
for (const type of options) {
|
|
4968
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
4969
|
+
if (!discriminatorValues.length) {
|
|
4970
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
4971
|
+
}
|
|
4972
|
+
for (const value of discriminatorValues) {
|
|
4973
|
+
if (optionsMap.has(value)) {
|
|
4974
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
4975
|
+
}
|
|
4976
|
+
optionsMap.set(value, type);
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
return new _ZodDiscriminatedUnion({
|
|
4980
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
4981
|
+
discriminator,
|
|
4982
|
+
options,
|
|
4983
|
+
optionsMap,
|
|
4984
|
+
...processCreateParams(params)
|
|
4985
|
+
});
|
|
4986
|
+
}
|
|
4987
|
+
};
|
|
4988
|
+
function mergeValues(a, b) {
|
|
4989
|
+
const aType = getParsedType(a);
|
|
4990
|
+
const bType = getParsedType(b);
|
|
4991
|
+
if (a === b) {
|
|
4992
|
+
return { valid: true, data: a };
|
|
4993
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
4994
|
+
const bKeys = util.objectKeys(b);
|
|
4995
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
4996
|
+
const newObj = { ...a, ...b };
|
|
4997
|
+
for (const key of sharedKeys) {
|
|
4998
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
4999
|
+
if (!sharedValue.valid) {
|
|
5000
|
+
return { valid: false };
|
|
5001
|
+
}
|
|
5002
|
+
newObj[key] = sharedValue.data;
|
|
5003
|
+
}
|
|
5004
|
+
return { valid: true, data: newObj };
|
|
5005
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
5006
|
+
if (a.length !== b.length) {
|
|
5007
|
+
return { valid: false };
|
|
5008
|
+
}
|
|
5009
|
+
const newArray = [];
|
|
5010
|
+
for (let index = 0; index < a.length; index++) {
|
|
5011
|
+
const itemA = a[index];
|
|
5012
|
+
const itemB = b[index];
|
|
5013
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
5014
|
+
if (!sharedValue.valid) {
|
|
5015
|
+
return { valid: false };
|
|
5016
|
+
}
|
|
5017
|
+
newArray.push(sharedValue.data);
|
|
5018
|
+
}
|
|
5019
|
+
return { valid: true, data: newArray };
|
|
5020
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
5021
|
+
return { valid: true, data: a };
|
|
5022
|
+
} else {
|
|
5023
|
+
return { valid: false };
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
var ZodIntersection = class extends ZodType {
|
|
5027
|
+
_parse(input) {
|
|
5028
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5029
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
5030
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
5031
|
+
return INVALID;
|
|
5032
|
+
}
|
|
5033
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
5034
|
+
if (!merged.valid) {
|
|
5035
|
+
addIssueToContext(ctx, {
|
|
5036
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
5037
|
+
});
|
|
5038
|
+
return INVALID;
|
|
5039
|
+
}
|
|
5040
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
5041
|
+
status.dirty();
|
|
5042
|
+
}
|
|
5043
|
+
return { status: status.value, value: merged.data };
|
|
5044
|
+
};
|
|
5045
|
+
if (ctx.common.async) {
|
|
5046
|
+
return Promise.all([
|
|
5047
|
+
this._def.left._parseAsync({
|
|
5048
|
+
data: ctx.data,
|
|
5049
|
+
path: ctx.path,
|
|
5050
|
+
parent: ctx
|
|
5051
|
+
}),
|
|
5052
|
+
this._def.right._parseAsync({
|
|
5053
|
+
data: ctx.data,
|
|
5054
|
+
path: ctx.path,
|
|
5055
|
+
parent: ctx
|
|
5056
|
+
})
|
|
5057
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
5058
|
+
} else {
|
|
5059
|
+
return handleParsed(this._def.left._parseSync({
|
|
5060
|
+
data: ctx.data,
|
|
5061
|
+
path: ctx.path,
|
|
5062
|
+
parent: ctx
|
|
5063
|
+
}), this._def.right._parseSync({
|
|
5064
|
+
data: ctx.data,
|
|
5065
|
+
path: ctx.path,
|
|
5066
|
+
parent: ctx
|
|
5067
|
+
}));
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
};
|
|
5071
|
+
ZodIntersection.create = (left, right, params) => {
|
|
5072
|
+
return new ZodIntersection({
|
|
5073
|
+
left,
|
|
5074
|
+
right,
|
|
5075
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
5076
|
+
...processCreateParams(params)
|
|
5077
|
+
});
|
|
5078
|
+
};
|
|
5079
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
5080
|
+
_parse(input) {
|
|
5081
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5082
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
5083
|
+
addIssueToContext(ctx, {
|
|
5084
|
+
code: ZodIssueCode.invalid_type,
|
|
5085
|
+
expected: ZodParsedType.array,
|
|
5086
|
+
received: ctx.parsedType
|
|
5087
|
+
});
|
|
5088
|
+
return INVALID;
|
|
5089
|
+
}
|
|
5090
|
+
if (ctx.data.length < this._def.items.length) {
|
|
5091
|
+
addIssueToContext(ctx, {
|
|
5092
|
+
code: ZodIssueCode.too_small,
|
|
5093
|
+
minimum: this._def.items.length,
|
|
5094
|
+
inclusive: true,
|
|
5095
|
+
exact: false,
|
|
5096
|
+
type: "array"
|
|
5097
|
+
});
|
|
5098
|
+
return INVALID;
|
|
5099
|
+
}
|
|
5100
|
+
const rest = this._def.rest;
|
|
5101
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
5102
|
+
addIssueToContext(ctx, {
|
|
5103
|
+
code: ZodIssueCode.too_big,
|
|
5104
|
+
maximum: this._def.items.length,
|
|
5105
|
+
inclusive: true,
|
|
5106
|
+
exact: false,
|
|
5107
|
+
type: "array"
|
|
5108
|
+
});
|
|
5109
|
+
status.dirty();
|
|
5110
|
+
}
|
|
5111
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
5112
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
5113
|
+
if (!schema)
|
|
5114
|
+
return null;
|
|
5115
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
5116
|
+
}).filter((x) => !!x);
|
|
5117
|
+
if (ctx.common.async) {
|
|
5118
|
+
return Promise.all(items).then((results) => {
|
|
5119
|
+
return ParseStatus.mergeArray(status, results);
|
|
5120
|
+
});
|
|
5121
|
+
} else {
|
|
5122
|
+
return ParseStatus.mergeArray(status, items);
|
|
5123
|
+
}
|
|
5124
|
+
}
|
|
5125
|
+
get items() {
|
|
5126
|
+
return this._def.items;
|
|
5127
|
+
}
|
|
5128
|
+
rest(rest) {
|
|
5129
|
+
return new _ZodTuple({
|
|
5130
|
+
...this._def,
|
|
5131
|
+
rest
|
|
5132
|
+
});
|
|
5133
|
+
}
|
|
5134
|
+
};
|
|
5135
|
+
ZodTuple.create = (schemas, params) => {
|
|
5136
|
+
if (!Array.isArray(schemas)) {
|
|
5137
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
5138
|
+
}
|
|
5139
|
+
return new ZodTuple({
|
|
5140
|
+
items: schemas,
|
|
5141
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
5142
|
+
rest: null,
|
|
5143
|
+
...processCreateParams(params)
|
|
5144
|
+
});
|
|
5145
|
+
};
|
|
5146
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
5147
|
+
get keySchema() {
|
|
5148
|
+
return this._def.keyType;
|
|
5149
|
+
}
|
|
5150
|
+
get valueSchema() {
|
|
5151
|
+
return this._def.valueType;
|
|
5152
|
+
}
|
|
5153
|
+
_parse(input) {
|
|
5154
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5155
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
5156
|
+
addIssueToContext(ctx, {
|
|
5157
|
+
code: ZodIssueCode.invalid_type,
|
|
5158
|
+
expected: ZodParsedType.object,
|
|
5159
|
+
received: ctx.parsedType
|
|
5160
|
+
});
|
|
5161
|
+
return INVALID;
|
|
5162
|
+
}
|
|
5163
|
+
const pairs = [];
|
|
5164
|
+
const keyType = this._def.keyType;
|
|
5165
|
+
const valueType = this._def.valueType;
|
|
5166
|
+
for (const key in ctx.data) {
|
|
5167
|
+
pairs.push({
|
|
5168
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
5169
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
5170
|
+
alwaysSet: key in ctx.data
|
|
5171
|
+
});
|
|
5172
|
+
}
|
|
5173
|
+
if (ctx.common.async) {
|
|
5174
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
5175
|
+
} else {
|
|
5176
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
5177
|
+
}
|
|
5178
|
+
}
|
|
5179
|
+
get element() {
|
|
5180
|
+
return this._def.valueType;
|
|
5181
|
+
}
|
|
5182
|
+
static create(first, second, third) {
|
|
5183
|
+
if (second instanceof ZodType) {
|
|
5184
|
+
return new _ZodRecord({
|
|
5185
|
+
keyType: first,
|
|
5186
|
+
valueType: second,
|
|
5187
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
5188
|
+
...processCreateParams(third)
|
|
5189
|
+
});
|
|
5190
|
+
}
|
|
5191
|
+
return new _ZodRecord({
|
|
5192
|
+
keyType: ZodString.create(),
|
|
5193
|
+
valueType: first,
|
|
5194
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
5195
|
+
...processCreateParams(second)
|
|
5196
|
+
});
|
|
5197
|
+
}
|
|
5198
|
+
};
|
|
5199
|
+
var ZodMap = class extends ZodType {
|
|
5200
|
+
get keySchema() {
|
|
5201
|
+
return this._def.keyType;
|
|
5202
|
+
}
|
|
5203
|
+
get valueSchema() {
|
|
5204
|
+
return this._def.valueType;
|
|
5205
|
+
}
|
|
5206
|
+
_parse(input) {
|
|
5207
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5208
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
5209
|
+
addIssueToContext(ctx, {
|
|
5210
|
+
code: ZodIssueCode.invalid_type,
|
|
5211
|
+
expected: ZodParsedType.map,
|
|
5212
|
+
received: ctx.parsedType
|
|
5213
|
+
});
|
|
5214
|
+
return INVALID;
|
|
5215
|
+
}
|
|
5216
|
+
const keyType = this._def.keyType;
|
|
5217
|
+
const valueType = this._def.valueType;
|
|
5218
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
5219
|
+
return {
|
|
5220
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
5221
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
5222
|
+
};
|
|
5223
|
+
});
|
|
5224
|
+
if (ctx.common.async) {
|
|
5225
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
5226
|
+
return Promise.resolve().then(async () => {
|
|
5227
|
+
for (const pair of pairs) {
|
|
5228
|
+
const key = await pair.key;
|
|
5229
|
+
const value = await pair.value;
|
|
5230
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
5231
|
+
return INVALID;
|
|
5232
|
+
}
|
|
5233
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
5234
|
+
status.dirty();
|
|
5235
|
+
}
|
|
5236
|
+
finalMap.set(key.value, value.value);
|
|
5237
|
+
}
|
|
5238
|
+
return { status: status.value, value: finalMap };
|
|
5239
|
+
});
|
|
5240
|
+
} else {
|
|
5241
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
5242
|
+
for (const pair of pairs) {
|
|
5243
|
+
const key = pair.key;
|
|
5244
|
+
const value = pair.value;
|
|
5245
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
5246
|
+
return INVALID;
|
|
5247
|
+
}
|
|
5248
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
5249
|
+
status.dirty();
|
|
5250
|
+
}
|
|
5251
|
+
finalMap.set(key.value, value.value);
|
|
5252
|
+
}
|
|
5253
|
+
return { status: status.value, value: finalMap };
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
};
|
|
5257
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
5258
|
+
return new ZodMap({
|
|
5259
|
+
valueType,
|
|
5260
|
+
keyType,
|
|
5261
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
5262
|
+
...processCreateParams(params)
|
|
5263
|
+
});
|
|
5264
|
+
};
|
|
5265
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
5266
|
+
_parse(input) {
|
|
5267
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5268
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
5269
|
+
addIssueToContext(ctx, {
|
|
5270
|
+
code: ZodIssueCode.invalid_type,
|
|
5271
|
+
expected: ZodParsedType.set,
|
|
5272
|
+
received: ctx.parsedType
|
|
5273
|
+
});
|
|
5274
|
+
return INVALID;
|
|
5275
|
+
}
|
|
5276
|
+
const def = this._def;
|
|
5277
|
+
if (def.minSize !== null) {
|
|
5278
|
+
if (ctx.data.size < def.minSize.value) {
|
|
5279
|
+
addIssueToContext(ctx, {
|
|
5280
|
+
code: ZodIssueCode.too_small,
|
|
5281
|
+
minimum: def.minSize.value,
|
|
5282
|
+
type: "set",
|
|
5283
|
+
inclusive: true,
|
|
5284
|
+
exact: false,
|
|
5285
|
+
message: def.minSize.message
|
|
5286
|
+
});
|
|
5287
|
+
status.dirty();
|
|
5288
|
+
}
|
|
5289
|
+
}
|
|
5290
|
+
if (def.maxSize !== null) {
|
|
5291
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
5292
|
+
addIssueToContext(ctx, {
|
|
5293
|
+
code: ZodIssueCode.too_big,
|
|
5294
|
+
maximum: def.maxSize.value,
|
|
5295
|
+
type: "set",
|
|
5296
|
+
inclusive: true,
|
|
5297
|
+
exact: false,
|
|
5298
|
+
message: def.maxSize.message
|
|
5299
|
+
});
|
|
5300
|
+
status.dirty();
|
|
5301
|
+
}
|
|
5302
|
+
}
|
|
5303
|
+
const valueType = this._def.valueType;
|
|
5304
|
+
function finalizeSet(elements2) {
|
|
5305
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
5306
|
+
for (const element of elements2) {
|
|
5307
|
+
if (element.status === "aborted")
|
|
5308
|
+
return INVALID;
|
|
5309
|
+
if (element.status === "dirty")
|
|
5310
|
+
status.dirty();
|
|
5311
|
+
parsedSet.add(element.value);
|
|
5312
|
+
}
|
|
5313
|
+
return { status: status.value, value: parsedSet };
|
|
5314
|
+
}
|
|
5315
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
5316
|
+
if (ctx.common.async) {
|
|
5317
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
5318
|
+
} else {
|
|
5319
|
+
return finalizeSet(elements);
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5322
|
+
min(minSize, message) {
|
|
5323
|
+
return new _ZodSet({
|
|
5324
|
+
...this._def,
|
|
5325
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
5326
|
+
});
|
|
5327
|
+
}
|
|
5328
|
+
max(maxSize, message) {
|
|
5329
|
+
return new _ZodSet({
|
|
5330
|
+
...this._def,
|
|
5331
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
5332
|
+
});
|
|
5333
|
+
}
|
|
5334
|
+
size(size, message) {
|
|
5335
|
+
return this.min(size, message).max(size, message);
|
|
5336
|
+
}
|
|
5337
|
+
nonempty(message) {
|
|
5338
|
+
return this.min(1, message);
|
|
5339
|
+
}
|
|
5340
|
+
};
|
|
5341
|
+
ZodSet.create = (valueType, params) => {
|
|
5342
|
+
return new ZodSet({
|
|
5343
|
+
valueType,
|
|
5344
|
+
minSize: null,
|
|
5345
|
+
maxSize: null,
|
|
5346
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
5347
|
+
...processCreateParams(params)
|
|
5348
|
+
});
|
|
5349
|
+
};
|
|
5350
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
5351
|
+
constructor() {
|
|
5352
|
+
super(...arguments);
|
|
5353
|
+
this.validate = this.implement;
|
|
5354
|
+
}
|
|
5355
|
+
_parse(input) {
|
|
5356
|
+
const { ctx } = this._processInputParams(input);
|
|
5357
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
5358
|
+
addIssueToContext(ctx, {
|
|
5359
|
+
code: ZodIssueCode.invalid_type,
|
|
5360
|
+
expected: ZodParsedType.function,
|
|
5361
|
+
received: ctx.parsedType
|
|
5362
|
+
});
|
|
5363
|
+
return INVALID;
|
|
5364
|
+
}
|
|
5365
|
+
function makeArgsIssue(args, error) {
|
|
5366
|
+
return makeIssue({
|
|
5367
|
+
data: args,
|
|
5368
|
+
path: ctx.path,
|
|
5369
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
5370
|
+
issueData: {
|
|
5371
|
+
code: ZodIssueCode.invalid_arguments,
|
|
5372
|
+
argumentsError: error
|
|
5373
|
+
}
|
|
5374
|
+
});
|
|
5375
|
+
}
|
|
5376
|
+
function makeReturnsIssue(returns, error) {
|
|
5377
|
+
return makeIssue({
|
|
5378
|
+
data: returns,
|
|
5379
|
+
path: ctx.path,
|
|
5380
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
5381
|
+
issueData: {
|
|
5382
|
+
code: ZodIssueCode.invalid_return_type,
|
|
5383
|
+
returnTypeError: error
|
|
5384
|
+
}
|
|
5385
|
+
});
|
|
5386
|
+
}
|
|
5387
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
5388
|
+
const fn = ctx.data;
|
|
5389
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
5390
|
+
const me = this;
|
|
5391
|
+
return OK(async function(...args) {
|
|
5392
|
+
const error = new ZodError([]);
|
|
5393
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
5394
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
5395
|
+
throw error;
|
|
5396
|
+
});
|
|
5397
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
5398
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
5399
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
5400
|
+
throw error;
|
|
5401
|
+
});
|
|
5402
|
+
return parsedReturns;
|
|
5403
|
+
});
|
|
5404
|
+
} else {
|
|
5405
|
+
const me = this;
|
|
5406
|
+
return OK(function(...args) {
|
|
5407
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
5408
|
+
if (!parsedArgs.success) {
|
|
5409
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
5410
|
+
}
|
|
5411
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
5412
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
5413
|
+
if (!parsedReturns.success) {
|
|
5414
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
5415
|
+
}
|
|
5416
|
+
return parsedReturns.data;
|
|
5417
|
+
});
|
|
5418
|
+
}
|
|
5419
|
+
}
|
|
5420
|
+
parameters() {
|
|
5421
|
+
return this._def.args;
|
|
5422
|
+
}
|
|
5423
|
+
returnType() {
|
|
5424
|
+
return this._def.returns;
|
|
5425
|
+
}
|
|
5426
|
+
args(...items) {
|
|
5427
|
+
return new _ZodFunction({
|
|
5428
|
+
...this._def,
|
|
5429
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
5430
|
+
});
|
|
5431
|
+
}
|
|
5432
|
+
returns(returnType) {
|
|
5433
|
+
return new _ZodFunction({
|
|
5434
|
+
...this._def,
|
|
5435
|
+
returns: returnType
|
|
5436
|
+
});
|
|
5437
|
+
}
|
|
5438
|
+
implement(func) {
|
|
5439
|
+
const validatedFunc = this.parse(func);
|
|
5440
|
+
return validatedFunc;
|
|
5441
|
+
}
|
|
5442
|
+
strictImplement(func) {
|
|
5443
|
+
const validatedFunc = this.parse(func);
|
|
5444
|
+
return validatedFunc;
|
|
5445
|
+
}
|
|
5446
|
+
static create(args, returns, params) {
|
|
5447
|
+
return new _ZodFunction({
|
|
5448
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
5449
|
+
returns: returns || ZodUnknown.create(),
|
|
5450
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
5451
|
+
...processCreateParams(params)
|
|
5452
|
+
});
|
|
5453
|
+
}
|
|
5454
|
+
};
|
|
5455
|
+
var ZodLazy = class extends ZodType {
|
|
5456
|
+
get schema() {
|
|
5457
|
+
return this._def.getter();
|
|
5458
|
+
}
|
|
5459
|
+
_parse(input) {
|
|
5460
|
+
const { ctx } = this._processInputParams(input);
|
|
5461
|
+
const lazySchema = this._def.getter();
|
|
5462
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
5463
|
+
}
|
|
5464
|
+
};
|
|
5465
|
+
ZodLazy.create = (getter, params) => {
|
|
5466
|
+
return new ZodLazy({
|
|
5467
|
+
getter,
|
|
5468
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
5469
|
+
...processCreateParams(params)
|
|
5470
|
+
});
|
|
5471
|
+
};
|
|
5472
|
+
var ZodLiteral = class extends ZodType {
|
|
5473
|
+
_parse(input) {
|
|
5474
|
+
if (input.data !== this._def.value) {
|
|
5475
|
+
const ctx = this._getOrReturnCtx(input);
|
|
5476
|
+
addIssueToContext(ctx, {
|
|
5477
|
+
received: ctx.data,
|
|
5478
|
+
code: ZodIssueCode.invalid_literal,
|
|
5479
|
+
expected: this._def.value
|
|
5480
|
+
});
|
|
5481
|
+
return INVALID;
|
|
5482
|
+
}
|
|
5483
|
+
return { status: "valid", value: input.data };
|
|
5484
|
+
}
|
|
5485
|
+
get value() {
|
|
5486
|
+
return this._def.value;
|
|
5487
|
+
}
|
|
5488
|
+
};
|
|
5489
|
+
ZodLiteral.create = (value, params) => {
|
|
5490
|
+
return new ZodLiteral({
|
|
5491
|
+
value,
|
|
5492
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
5493
|
+
...processCreateParams(params)
|
|
5494
|
+
});
|
|
5495
|
+
};
|
|
5496
|
+
function createZodEnum(values, params) {
|
|
5497
|
+
return new ZodEnum({
|
|
5498
|
+
values,
|
|
5499
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
5500
|
+
...processCreateParams(params)
|
|
5501
|
+
});
|
|
5502
|
+
}
|
|
5503
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
5504
|
+
_parse(input) {
|
|
5505
|
+
if (typeof input.data !== "string") {
|
|
5506
|
+
const ctx = this._getOrReturnCtx(input);
|
|
5507
|
+
const expectedValues = this._def.values;
|
|
5508
|
+
addIssueToContext(ctx, {
|
|
5509
|
+
expected: util.joinValues(expectedValues),
|
|
5510
|
+
received: ctx.parsedType,
|
|
5511
|
+
code: ZodIssueCode.invalid_type
|
|
5512
|
+
});
|
|
5513
|
+
return INVALID;
|
|
5514
|
+
}
|
|
5515
|
+
if (!this._cache) {
|
|
5516
|
+
this._cache = new Set(this._def.values);
|
|
5517
|
+
}
|
|
5518
|
+
if (!this._cache.has(input.data)) {
|
|
5519
|
+
const ctx = this._getOrReturnCtx(input);
|
|
5520
|
+
const expectedValues = this._def.values;
|
|
5521
|
+
addIssueToContext(ctx, {
|
|
5522
|
+
received: ctx.data,
|
|
5523
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
5524
|
+
options: expectedValues
|
|
5525
|
+
});
|
|
5526
|
+
return INVALID;
|
|
5527
|
+
}
|
|
5528
|
+
return OK(input.data);
|
|
5529
|
+
}
|
|
5530
|
+
get options() {
|
|
5531
|
+
return this._def.values;
|
|
5532
|
+
}
|
|
5533
|
+
get enum() {
|
|
5534
|
+
const enumValues = {};
|
|
5535
|
+
for (const val of this._def.values) {
|
|
5536
|
+
enumValues[val] = val;
|
|
5537
|
+
}
|
|
5538
|
+
return enumValues;
|
|
5539
|
+
}
|
|
5540
|
+
get Values() {
|
|
5541
|
+
const enumValues = {};
|
|
5542
|
+
for (const val of this._def.values) {
|
|
5543
|
+
enumValues[val] = val;
|
|
5544
|
+
}
|
|
5545
|
+
return enumValues;
|
|
5546
|
+
}
|
|
5547
|
+
get Enum() {
|
|
5548
|
+
const enumValues = {};
|
|
5549
|
+
for (const val of this._def.values) {
|
|
5550
|
+
enumValues[val] = val;
|
|
5551
|
+
}
|
|
5552
|
+
return enumValues;
|
|
5553
|
+
}
|
|
5554
|
+
extract(values, newDef = this._def) {
|
|
5555
|
+
return _ZodEnum.create(values, {
|
|
5556
|
+
...this._def,
|
|
5557
|
+
...newDef
|
|
5558
|
+
});
|
|
5559
|
+
}
|
|
5560
|
+
exclude(values, newDef = this._def) {
|
|
5561
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
5562
|
+
...this._def,
|
|
5563
|
+
...newDef
|
|
5564
|
+
});
|
|
5565
|
+
}
|
|
5566
|
+
};
|
|
5567
|
+
ZodEnum.create = createZodEnum;
|
|
5568
|
+
var ZodNativeEnum = class extends ZodType {
|
|
5569
|
+
_parse(input) {
|
|
5570
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
5571
|
+
const ctx = this._getOrReturnCtx(input);
|
|
5572
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
5573
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
5574
|
+
addIssueToContext(ctx, {
|
|
5575
|
+
expected: util.joinValues(expectedValues),
|
|
5576
|
+
received: ctx.parsedType,
|
|
5577
|
+
code: ZodIssueCode.invalid_type
|
|
5578
|
+
});
|
|
5579
|
+
return INVALID;
|
|
5580
|
+
}
|
|
5581
|
+
if (!this._cache) {
|
|
5582
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
5583
|
+
}
|
|
5584
|
+
if (!this._cache.has(input.data)) {
|
|
5585
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
5586
|
+
addIssueToContext(ctx, {
|
|
5587
|
+
received: ctx.data,
|
|
5588
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
5589
|
+
options: expectedValues
|
|
5590
|
+
});
|
|
5591
|
+
return INVALID;
|
|
5592
|
+
}
|
|
5593
|
+
return OK(input.data);
|
|
5594
|
+
}
|
|
5595
|
+
get enum() {
|
|
5596
|
+
return this._def.values;
|
|
5597
|
+
}
|
|
5598
|
+
};
|
|
5599
|
+
ZodNativeEnum.create = (values, params) => {
|
|
5600
|
+
return new ZodNativeEnum({
|
|
5601
|
+
values,
|
|
5602
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
5603
|
+
...processCreateParams(params)
|
|
5604
|
+
});
|
|
5605
|
+
};
|
|
5606
|
+
var ZodPromise = class extends ZodType {
|
|
5607
|
+
unwrap() {
|
|
5608
|
+
return this._def.type;
|
|
5609
|
+
}
|
|
5610
|
+
_parse(input) {
|
|
5611
|
+
const { ctx } = this._processInputParams(input);
|
|
5612
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
5613
|
+
addIssueToContext(ctx, {
|
|
5614
|
+
code: ZodIssueCode.invalid_type,
|
|
5615
|
+
expected: ZodParsedType.promise,
|
|
5616
|
+
received: ctx.parsedType
|
|
5617
|
+
});
|
|
5618
|
+
return INVALID;
|
|
5619
|
+
}
|
|
5620
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
5621
|
+
return OK(promisified.then((data) => {
|
|
5622
|
+
return this._def.type.parseAsync(data, {
|
|
5623
|
+
path: ctx.path,
|
|
5624
|
+
errorMap: ctx.common.contextualErrorMap
|
|
5625
|
+
});
|
|
5626
|
+
}));
|
|
5627
|
+
}
|
|
5628
|
+
};
|
|
5629
|
+
ZodPromise.create = (schema, params) => {
|
|
5630
|
+
return new ZodPromise({
|
|
5631
|
+
type: schema,
|
|
5632
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
5633
|
+
...processCreateParams(params)
|
|
5634
|
+
});
|
|
5635
|
+
};
|
|
5636
|
+
var ZodEffects = class extends ZodType {
|
|
5637
|
+
innerType() {
|
|
5638
|
+
return this._def.schema;
|
|
5639
|
+
}
|
|
5640
|
+
sourceType() {
|
|
5641
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
5642
|
+
}
|
|
5643
|
+
_parse(input) {
|
|
5644
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5645
|
+
const effect = this._def.effect || null;
|
|
5646
|
+
const checkCtx = {
|
|
5647
|
+
addIssue: (arg) => {
|
|
5648
|
+
addIssueToContext(ctx, arg);
|
|
5649
|
+
if (arg.fatal) {
|
|
5650
|
+
status.abort();
|
|
5651
|
+
} else {
|
|
5652
|
+
status.dirty();
|
|
5653
|
+
}
|
|
5654
|
+
},
|
|
5655
|
+
get path() {
|
|
5656
|
+
return ctx.path;
|
|
5657
|
+
}
|
|
5658
|
+
};
|
|
5659
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
5660
|
+
if (effect.type === "preprocess") {
|
|
5661
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
5662
|
+
if (ctx.common.async) {
|
|
5663
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
5664
|
+
if (status.value === "aborted")
|
|
5665
|
+
return INVALID;
|
|
5666
|
+
const result = await this._def.schema._parseAsync({
|
|
5667
|
+
data: processed2,
|
|
5668
|
+
path: ctx.path,
|
|
5669
|
+
parent: ctx
|
|
5670
|
+
});
|
|
5671
|
+
if (result.status === "aborted")
|
|
5672
|
+
return INVALID;
|
|
5673
|
+
if (result.status === "dirty")
|
|
5674
|
+
return DIRTY(result.value);
|
|
5675
|
+
if (status.value === "dirty")
|
|
5676
|
+
return DIRTY(result.value);
|
|
5677
|
+
return result;
|
|
5678
|
+
});
|
|
5679
|
+
} else {
|
|
5680
|
+
if (status.value === "aborted")
|
|
5681
|
+
return INVALID;
|
|
5682
|
+
const result = this._def.schema._parseSync({
|
|
5683
|
+
data: processed,
|
|
5684
|
+
path: ctx.path,
|
|
5685
|
+
parent: ctx
|
|
5686
|
+
});
|
|
5687
|
+
if (result.status === "aborted")
|
|
5688
|
+
return INVALID;
|
|
5689
|
+
if (result.status === "dirty")
|
|
5690
|
+
return DIRTY(result.value);
|
|
5691
|
+
if (status.value === "dirty")
|
|
5692
|
+
return DIRTY(result.value);
|
|
5693
|
+
return result;
|
|
5694
|
+
}
|
|
5695
|
+
}
|
|
5696
|
+
if (effect.type === "refinement") {
|
|
5697
|
+
const executeRefinement = (acc) => {
|
|
5698
|
+
const result = effect.refinement(acc, checkCtx);
|
|
5699
|
+
if (ctx.common.async) {
|
|
5700
|
+
return Promise.resolve(result);
|
|
5701
|
+
}
|
|
5702
|
+
if (result instanceof Promise) {
|
|
5703
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
5704
|
+
}
|
|
5705
|
+
return acc;
|
|
5706
|
+
};
|
|
5707
|
+
if (ctx.common.async === false) {
|
|
5708
|
+
const inner = this._def.schema._parseSync({
|
|
5709
|
+
data: ctx.data,
|
|
5710
|
+
path: ctx.path,
|
|
5711
|
+
parent: ctx
|
|
5712
|
+
});
|
|
5713
|
+
if (inner.status === "aborted")
|
|
5714
|
+
return INVALID;
|
|
5715
|
+
if (inner.status === "dirty")
|
|
5716
|
+
status.dirty();
|
|
5717
|
+
executeRefinement(inner.value);
|
|
5718
|
+
return { status: status.value, value: inner.value };
|
|
5719
|
+
} else {
|
|
5720
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
5721
|
+
if (inner.status === "aborted")
|
|
5722
|
+
return INVALID;
|
|
5723
|
+
if (inner.status === "dirty")
|
|
5724
|
+
status.dirty();
|
|
5725
|
+
return executeRefinement(inner.value).then(() => {
|
|
5726
|
+
return { status: status.value, value: inner.value };
|
|
5727
|
+
});
|
|
5728
|
+
});
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
if (effect.type === "transform") {
|
|
5732
|
+
if (ctx.common.async === false) {
|
|
5733
|
+
const base = this._def.schema._parseSync({
|
|
5734
|
+
data: ctx.data,
|
|
5735
|
+
path: ctx.path,
|
|
5736
|
+
parent: ctx
|
|
5737
|
+
});
|
|
5738
|
+
if (!isValid(base))
|
|
5739
|
+
return INVALID;
|
|
5740
|
+
const result = effect.transform(base.value, checkCtx);
|
|
5741
|
+
if (result instanceof Promise) {
|
|
5742
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
5743
|
+
}
|
|
5744
|
+
return { status: status.value, value: result };
|
|
5745
|
+
} else {
|
|
5746
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
5747
|
+
if (!isValid(base))
|
|
5748
|
+
return INVALID;
|
|
5749
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
5750
|
+
status: status.value,
|
|
5751
|
+
value: result
|
|
5752
|
+
}));
|
|
5753
|
+
});
|
|
5754
|
+
}
|
|
5755
|
+
}
|
|
5756
|
+
util.assertNever(effect);
|
|
5757
|
+
}
|
|
5758
|
+
};
|
|
5759
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
5760
|
+
return new ZodEffects({
|
|
5761
|
+
schema,
|
|
5762
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
5763
|
+
effect,
|
|
5764
|
+
...processCreateParams(params)
|
|
5765
|
+
});
|
|
5766
|
+
};
|
|
5767
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
5768
|
+
return new ZodEffects({
|
|
5769
|
+
schema,
|
|
5770
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
5771
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
5772
|
+
...processCreateParams(params)
|
|
5773
|
+
});
|
|
5774
|
+
};
|
|
5775
|
+
var ZodOptional = class extends ZodType {
|
|
5776
|
+
_parse(input) {
|
|
5777
|
+
const parsedType = this._getType(input);
|
|
5778
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
5779
|
+
return OK(void 0);
|
|
5780
|
+
}
|
|
5781
|
+
return this._def.innerType._parse(input);
|
|
5782
|
+
}
|
|
5783
|
+
unwrap() {
|
|
5784
|
+
return this._def.innerType;
|
|
5785
|
+
}
|
|
5786
|
+
};
|
|
5787
|
+
ZodOptional.create = (type, params) => {
|
|
5788
|
+
return new ZodOptional({
|
|
5789
|
+
innerType: type,
|
|
5790
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
5791
|
+
...processCreateParams(params)
|
|
5792
|
+
});
|
|
5793
|
+
};
|
|
5794
|
+
var ZodNullable = class extends ZodType {
|
|
5795
|
+
_parse(input) {
|
|
5796
|
+
const parsedType = this._getType(input);
|
|
5797
|
+
if (parsedType === ZodParsedType.null) {
|
|
5798
|
+
return OK(null);
|
|
5799
|
+
}
|
|
5800
|
+
return this._def.innerType._parse(input);
|
|
5801
|
+
}
|
|
5802
|
+
unwrap() {
|
|
5803
|
+
return this._def.innerType;
|
|
5804
|
+
}
|
|
5805
|
+
};
|
|
5806
|
+
ZodNullable.create = (type, params) => {
|
|
5807
|
+
return new ZodNullable({
|
|
5808
|
+
innerType: type,
|
|
5809
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
5810
|
+
...processCreateParams(params)
|
|
5811
|
+
});
|
|
5812
|
+
};
|
|
5813
|
+
var ZodDefault = class extends ZodType {
|
|
5814
|
+
_parse(input) {
|
|
5815
|
+
const { ctx } = this._processInputParams(input);
|
|
5816
|
+
let data = ctx.data;
|
|
5817
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
5818
|
+
data = this._def.defaultValue();
|
|
5819
|
+
}
|
|
5820
|
+
return this._def.innerType._parse({
|
|
5821
|
+
data,
|
|
5822
|
+
path: ctx.path,
|
|
5823
|
+
parent: ctx
|
|
5824
|
+
});
|
|
5825
|
+
}
|
|
5826
|
+
removeDefault() {
|
|
5827
|
+
return this._def.innerType;
|
|
5828
|
+
}
|
|
5829
|
+
};
|
|
5830
|
+
ZodDefault.create = (type, params) => {
|
|
5831
|
+
return new ZodDefault({
|
|
5832
|
+
innerType: type,
|
|
5833
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
5834
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
5835
|
+
...processCreateParams(params)
|
|
5836
|
+
});
|
|
5837
|
+
};
|
|
5838
|
+
var ZodCatch = class extends ZodType {
|
|
5839
|
+
_parse(input) {
|
|
5840
|
+
const { ctx } = this._processInputParams(input);
|
|
5841
|
+
const newCtx = {
|
|
5842
|
+
...ctx,
|
|
5843
|
+
common: {
|
|
5844
|
+
...ctx.common,
|
|
5845
|
+
issues: []
|
|
5846
|
+
}
|
|
5847
|
+
};
|
|
5848
|
+
const result = this._def.innerType._parse({
|
|
5849
|
+
data: newCtx.data,
|
|
5850
|
+
path: newCtx.path,
|
|
5851
|
+
parent: {
|
|
5852
|
+
...newCtx
|
|
5853
|
+
}
|
|
5854
|
+
});
|
|
5855
|
+
if (isAsync(result)) {
|
|
5856
|
+
return result.then((result2) => {
|
|
5857
|
+
return {
|
|
5858
|
+
status: "valid",
|
|
5859
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
5860
|
+
get error() {
|
|
5861
|
+
return new ZodError(newCtx.common.issues);
|
|
5862
|
+
},
|
|
5863
|
+
input: newCtx.data
|
|
5864
|
+
})
|
|
5865
|
+
};
|
|
5866
|
+
});
|
|
5867
|
+
} else {
|
|
5868
|
+
return {
|
|
5869
|
+
status: "valid",
|
|
5870
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
5871
|
+
get error() {
|
|
5872
|
+
return new ZodError(newCtx.common.issues);
|
|
5873
|
+
},
|
|
5874
|
+
input: newCtx.data
|
|
5875
|
+
})
|
|
5876
|
+
};
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5879
|
+
removeCatch() {
|
|
5880
|
+
return this._def.innerType;
|
|
5881
|
+
}
|
|
5882
|
+
};
|
|
5883
|
+
ZodCatch.create = (type, params) => {
|
|
5884
|
+
return new ZodCatch({
|
|
5885
|
+
innerType: type,
|
|
5886
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
5887
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
5888
|
+
...processCreateParams(params)
|
|
5889
|
+
});
|
|
5890
|
+
};
|
|
5891
|
+
var ZodNaN = class extends ZodType {
|
|
5892
|
+
_parse(input) {
|
|
5893
|
+
const parsedType = this._getType(input);
|
|
5894
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
5895
|
+
const ctx = this._getOrReturnCtx(input);
|
|
5896
|
+
addIssueToContext(ctx, {
|
|
5897
|
+
code: ZodIssueCode.invalid_type,
|
|
5898
|
+
expected: ZodParsedType.nan,
|
|
5899
|
+
received: ctx.parsedType
|
|
5900
|
+
});
|
|
5901
|
+
return INVALID;
|
|
5902
|
+
}
|
|
5903
|
+
return { status: "valid", value: input.data };
|
|
5904
|
+
}
|
|
5905
|
+
};
|
|
5906
|
+
ZodNaN.create = (params) => {
|
|
5907
|
+
return new ZodNaN({
|
|
5908
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
5909
|
+
...processCreateParams(params)
|
|
5910
|
+
});
|
|
5911
|
+
};
|
|
5912
|
+
var BRAND = Symbol("zod_brand");
|
|
5913
|
+
var ZodBranded = class extends ZodType {
|
|
5914
|
+
_parse(input) {
|
|
5915
|
+
const { ctx } = this._processInputParams(input);
|
|
5916
|
+
const data = ctx.data;
|
|
5917
|
+
return this._def.type._parse({
|
|
5918
|
+
data,
|
|
5919
|
+
path: ctx.path,
|
|
5920
|
+
parent: ctx
|
|
5921
|
+
});
|
|
5922
|
+
}
|
|
5923
|
+
unwrap() {
|
|
5924
|
+
return this._def.type;
|
|
5925
|
+
}
|
|
5926
|
+
};
|
|
5927
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
5928
|
+
_parse(input) {
|
|
5929
|
+
const { status, ctx } = this._processInputParams(input);
|
|
5930
|
+
if (ctx.common.async) {
|
|
5931
|
+
const handleAsync = async () => {
|
|
5932
|
+
const inResult = await this._def.in._parseAsync({
|
|
5933
|
+
data: ctx.data,
|
|
5934
|
+
path: ctx.path,
|
|
5935
|
+
parent: ctx
|
|
5936
|
+
});
|
|
5937
|
+
if (inResult.status === "aborted")
|
|
5938
|
+
return INVALID;
|
|
5939
|
+
if (inResult.status === "dirty") {
|
|
5940
|
+
status.dirty();
|
|
5941
|
+
return DIRTY(inResult.value);
|
|
5942
|
+
} else {
|
|
5943
|
+
return this._def.out._parseAsync({
|
|
5944
|
+
data: inResult.value,
|
|
5945
|
+
path: ctx.path,
|
|
5946
|
+
parent: ctx
|
|
5947
|
+
});
|
|
5948
|
+
}
|
|
5949
|
+
};
|
|
5950
|
+
return handleAsync();
|
|
5951
|
+
} else {
|
|
5952
|
+
const inResult = this._def.in._parseSync({
|
|
5953
|
+
data: ctx.data,
|
|
5954
|
+
path: ctx.path,
|
|
5955
|
+
parent: ctx
|
|
5956
|
+
});
|
|
5957
|
+
if (inResult.status === "aborted")
|
|
5958
|
+
return INVALID;
|
|
5959
|
+
if (inResult.status === "dirty") {
|
|
5960
|
+
status.dirty();
|
|
5961
|
+
return {
|
|
5962
|
+
status: "dirty",
|
|
5963
|
+
value: inResult.value
|
|
5964
|
+
};
|
|
5965
|
+
} else {
|
|
5966
|
+
return this._def.out._parseSync({
|
|
5967
|
+
data: inResult.value,
|
|
5968
|
+
path: ctx.path,
|
|
5969
|
+
parent: ctx
|
|
5970
|
+
});
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
static create(a, b) {
|
|
5975
|
+
return new _ZodPipeline({
|
|
5976
|
+
in: a,
|
|
5977
|
+
out: b,
|
|
5978
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
5979
|
+
});
|
|
5980
|
+
}
|
|
5981
|
+
};
|
|
5982
|
+
var ZodReadonly = class extends ZodType {
|
|
5983
|
+
_parse(input) {
|
|
5984
|
+
const result = this._def.innerType._parse(input);
|
|
5985
|
+
const freeze = (data) => {
|
|
5986
|
+
if (isValid(data)) {
|
|
5987
|
+
data.value = Object.freeze(data.value);
|
|
5988
|
+
}
|
|
5989
|
+
return data;
|
|
5990
|
+
};
|
|
5991
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
5992
|
+
}
|
|
5993
|
+
unwrap() {
|
|
5994
|
+
return this._def.innerType;
|
|
5995
|
+
}
|
|
5996
|
+
};
|
|
5997
|
+
ZodReadonly.create = (type, params) => {
|
|
5998
|
+
return new ZodReadonly({
|
|
5999
|
+
innerType: type,
|
|
6000
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
6001
|
+
...processCreateParams(params)
|
|
6002
|
+
});
|
|
6003
|
+
};
|
|
6004
|
+
function cleanParams(params, data) {
|
|
6005
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
6006
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
6007
|
+
return p2;
|
|
6008
|
+
}
|
|
6009
|
+
function custom(check, _params = {}, fatal) {
|
|
6010
|
+
if (check)
|
|
6011
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
6012
|
+
const r = check(data);
|
|
6013
|
+
if (r instanceof Promise) {
|
|
6014
|
+
return r.then((r2) => {
|
|
6015
|
+
if (!r2) {
|
|
6016
|
+
const params = cleanParams(_params, data);
|
|
6017
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
6018
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
6019
|
+
}
|
|
6020
|
+
});
|
|
6021
|
+
}
|
|
6022
|
+
if (!r) {
|
|
6023
|
+
const params = cleanParams(_params, data);
|
|
6024
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
6025
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
6026
|
+
}
|
|
6027
|
+
return;
|
|
6028
|
+
});
|
|
6029
|
+
return ZodAny.create();
|
|
6030
|
+
}
|
|
6031
|
+
var late = {
|
|
6032
|
+
object: ZodObject.lazycreate
|
|
6033
|
+
};
|
|
6034
|
+
var ZodFirstPartyTypeKind;
|
|
6035
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
6036
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
6037
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
6038
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
6039
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
6040
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
6041
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
6042
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
6043
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
6044
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
6045
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
6046
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
6047
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
6048
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
6049
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
6050
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
6051
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
6052
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
6053
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
6054
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
6055
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
6056
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
6057
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
6058
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
6059
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
6060
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
6061
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
6062
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
6063
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
6064
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
6065
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
6066
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
6067
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
6068
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
6069
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
6070
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
6071
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
6072
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
6073
|
+
var instanceOfType = (cls, params = {
|
|
6074
|
+
message: `Input not instance of ${cls.name}`
|
|
6075
|
+
}) => custom((data) => data instanceof cls, params);
|
|
6076
|
+
var stringType = ZodString.create;
|
|
6077
|
+
var numberType = ZodNumber.create;
|
|
6078
|
+
var nanType = ZodNaN.create;
|
|
6079
|
+
var bigIntType = ZodBigInt.create;
|
|
6080
|
+
var booleanType = ZodBoolean.create;
|
|
6081
|
+
var dateType = ZodDate.create;
|
|
6082
|
+
var symbolType = ZodSymbol.create;
|
|
6083
|
+
var undefinedType = ZodUndefined.create;
|
|
6084
|
+
var nullType = ZodNull.create;
|
|
6085
|
+
var anyType = ZodAny.create;
|
|
6086
|
+
var unknownType = ZodUnknown.create;
|
|
6087
|
+
var neverType = ZodNever.create;
|
|
6088
|
+
var voidType = ZodVoid.create;
|
|
6089
|
+
var arrayType = ZodArray.create;
|
|
6090
|
+
var objectType = ZodObject.create;
|
|
6091
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
6092
|
+
var unionType = ZodUnion.create;
|
|
6093
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
6094
|
+
var intersectionType = ZodIntersection.create;
|
|
6095
|
+
var tupleType = ZodTuple.create;
|
|
6096
|
+
var recordType = ZodRecord.create;
|
|
6097
|
+
var mapType = ZodMap.create;
|
|
6098
|
+
var setType = ZodSet.create;
|
|
6099
|
+
var functionType = ZodFunction.create;
|
|
6100
|
+
var lazyType = ZodLazy.create;
|
|
6101
|
+
var literalType = ZodLiteral.create;
|
|
6102
|
+
var enumType = ZodEnum.create;
|
|
6103
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
6104
|
+
var promiseType = ZodPromise.create;
|
|
6105
|
+
var effectsType = ZodEffects.create;
|
|
6106
|
+
var optionalType = ZodOptional.create;
|
|
6107
|
+
var nullableType = ZodNullable.create;
|
|
6108
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
6109
|
+
var pipelineType = ZodPipeline.create;
|
|
6110
|
+
var ostring = () => stringType().optional();
|
|
6111
|
+
var onumber = () => numberType().optional();
|
|
6112
|
+
var oboolean = () => booleanType().optional();
|
|
6113
|
+
var coerce = {
|
|
6114
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
6115
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
6116
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
6117
|
+
...arg,
|
|
6118
|
+
coerce: true
|
|
6119
|
+
})),
|
|
6120
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
6121
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
6122
|
+
};
|
|
6123
|
+
var NEVER = INVALID;
|
|
6124
|
+
|
|
6125
|
+
// src/pool/helpers.ts
|
|
6126
|
+
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
6127
|
+
import path from "node:path";
|
|
6128
|
+
var WORKER_NAME_PREFIX = "vitest-pool-workers-";
|
|
6129
|
+
function isFileNotFoundError(e) {
|
|
6130
|
+
return typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT";
|
|
6131
|
+
}
|
|
6132
|
+
function getProjectPath(project) {
|
|
6133
|
+
return project.config.config ?? project.path;
|
|
6134
|
+
}
|
|
6135
|
+
function getRelativeProjectPath(project) {
|
|
6136
|
+
const projectPath = getProjectPath(project);
|
|
6137
|
+
if (typeof projectPath === "number") {
|
|
6138
|
+
return projectPath;
|
|
6139
|
+
} else {
|
|
6140
|
+
return path.relative("", projectPath);
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
|
|
6144
|
+
// src/pool/config.ts
|
|
6145
|
+
var PLUGIN_VALUES = Object.values(PLUGINS);
|
|
6146
|
+
var OPTIONS_PATH_ARRAY = ["test", "poolOptions", "workers"];
|
|
6147
|
+
var OPTIONS_PATH = OPTIONS_PATH_ARRAY.join(".");
|
|
6148
|
+
var WorkersPoolOptionsSchema = external_exports.object({
|
|
6149
|
+
/**
|
|
6150
|
+
* Entrypoint to Worker run in the same isolate/context as tests. This is
|
|
6151
|
+
* required to use `import { SELF } from "cloudflare:test"`, or Durable
|
|
6152
|
+
* Objects without an explicit `scriptName`. Note this goes through Vite
|
|
6153
|
+
* transforms and can be a TypeScript file. Note also
|
|
6154
|
+
* `import module from "<path-to-main>"` inside tests gives exactly the same
|
|
6155
|
+
* `module` instance as is used internally for the `SELF` and Durable Object
|
|
6156
|
+
* bindings.
|
|
6157
|
+
*/
|
|
6158
|
+
main: external_exports.ostring(),
|
|
6159
|
+
/**
|
|
6160
|
+
* Enables per-test isolated storage. If enabled, any writes to storage
|
|
6161
|
+
* performed in a test will be undone at the end of the test. The test storage
|
|
6162
|
+
* environment is copied from the containing suite, meaning `beforeAll()`
|
|
6163
|
+
* hooks can be used to seed data. If this is disabled, all tests will share
|
|
6164
|
+
* the same storage.
|
|
6165
|
+
*/
|
|
6166
|
+
isolatedStorage: external_exports.boolean().default(true),
|
|
6167
|
+
/**
|
|
6168
|
+
* Enables remote bindings to access remote resources configured
|
|
6169
|
+
* with `remote: true` in the wrangler configuration file.
|
|
6170
|
+
*/
|
|
6171
|
+
remoteBindings: external_exports.boolean().default(true),
|
|
6172
|
+
/**
|
|
6173
|
+
* Additional exports.
|
|
6174
|
+
* A map of module exports to be made available on the `ctx.exports`
|
|
6175
|
+
* that cannot be automatically inferred by analyzing the Worker source code.
|
|
6176
|
+
*
|
|
6177
|
+
* This is useful for exports that are re-exported implicitly, for example
|
|
6178
|
+
* through wildcard (`export * from "..."`) re-exports from virtual modules.
|
|
6179
|
+
*/
|
|
6180
|
+
additionalExports: external_exports.record(
|
|
6181
|
+
external_exports.string(),
|
|
6182
|
+
external_exports.union([
|
|
6183
|
+
external_exports.literal("WorkerEntrypoint"),
|
|
6184
|
+
external_exports.literal("DurableObject"),
|
|
6185
|
+
external_exports.literal("WorkflowEntrypoint")
|
|
6186
|
+
])
|
|
6187
|
+
).default({}),
|
|
6188
|
+
/**
|
|
6189
|
+
* If enabled, Workers will be run in a single shared worker instance.
|
|
6190
|
+
*/
|
|
6191
|
+
/**
|
|
6192
|
+
* Runs all tests in this project serially in the same worker, using the same
|
|
6193
|
+
* module cache. This can significantly speed up tests if you've got lots of
|
|
6194
|
+
* small test files.
|
|
6195
|
+
*/
|
|
6196
|
+
singleWorker: external_exports.boolean().default(false),
|
|
6197
|
+
miniflare: external_exports.object({
|
|
6198
|
+
workers: external_exports.array(external_exports.object({}).passthrough()).optional()
|
|
6199
|
+
}).passthrough().optional(),
|
|
6200
|
+
wrangler: external_exports.object({ configPath: external_exports.ostring(), environment: external_exports.ostring() }).optional()
|
|
6201
|
+
});
|
|
6202
|
+
function isZodErrorLike(value) {
|
|
6203
|
+
return typeof value === "object" && value !== null && "issues" in value && Array.isArray(value.issues);
|
|
6204
|
+
}
|
|
6205
|
+
function coalesceZodErrors(ref, thrown) {
|
|
6206
|
+
if (!isZodErrorLike(thrown)) {
|
|
6207
|
+
throw thrown;
|
|
6208
|
+
}
|
|
6209
|
+
if (ref.value === void 0) {
|
|
6210
|
+
ref.value = thrown;
|
|
6211
|
+
} else {
|
|
6212
|
+
ref.value.issues.push(...thrown.issues);
|
|
6213
|
+
}
|
|
6214
|
+
}
|
|
6215
|
+
function parseWorkerOptions(rootPath, value, withoutScript, opts) {
|
|
6216
|
+
if (withoutScript) {
|
|
6217
|
+
value["script"] = "";
|
|
6218
|
+
delete value["scriptPath"];
|
|
6219
|
+
delete value["modules"];
|
|
6220
|
+
delete value["modulesRoot"];
|
|
6221
|
+
}
|
|
6222
|
+
const result = {};
|
|
6223
|
+
const errorRef = {};
|
|
6224
|
+
for (const plugin of PLUGIN_VALUES) {
|
|
6225
|
+
try {
|
|
6226
|
+
const parsed = parseWithRootPath(rootPath, plugin.options, value, opts);
|
|
6227
|
+
Object.assign(result, parsed);
|
|
6228
|
+
} catch (e) {
|
|
6229
|
+
coalesceZodErrors(errorRef, e);
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
if (errorRef.value !== void 0) {
|
|
6233
|
+
throw errorRef.value;
|
|
6234
|
+
}
|
|
6235
|
+
if (withoutScript) {
|
|
6236
|
+
delete value["script"];
|
|
6237
|
+
}
|
|
6238
|
+
return result;
|
|
6239
|
+
}
|
|
6240
|
+
var log = new Log(LogLevel.WARN, { prefix: "vpw" });
|
|
6241
|
+
function filterTails(tails, userWorkers) {
|
|
6242
|
+
return tails?.filter((tailService) => {
|
|
6243
|
+
let name;
|
|
6244
|
+
if (typeof tailService === "string") {
|
|
6245
|
+
name = tailService;
|
|
6246
|
+
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
6247
|
+
name = tailService.name;
|
|
6248
|
+
} else {
|
|
6249
|
+
return true;
|
|
6250
|
+
}
|
|
6251
|
+
const found = userWorkers?.some((w) => w.name === name);
|
|
6252
|
+
if (!found) {
|
|
6253
|
+
log.warn(
|
|
6254
|
+
`Tail consumer "${name}" was not found in your config. Make sure you add it if you'd like to simulate receiving tail events locally.`
|
|
6255
|
+
);
|
|
6256
|
+
}
|
|
6257
|
+
return found;
|
|
6258
|
+
});
|
|
6259
|
+
}
|
|
6260
|
+
var remoteProxySessionsDataMap = /* @__PURE__ */ new Map();
|
|
6261
|
+
async function parseCustomPoolOptions(rootPath, value, opts) {
|
|
6262
|
+
const options = WorkersPoolOptionsSchema.parse(
|
|
6263
|
+
value,
|
|
6264
|
+
opts
|
|
6265
|
+
);
|
|
6266
|
+
options.miniflare ??= {};
|
|
6267
|
+
const errorRef = {};
|
|
6268
|
+
const workers = options.miniflare?.workers;
|
|
6269
|
+
const rootPathOption = getRootPath(options.miniflare);
|
|
6270
|
+
rootPath = path2.resolve(rootPath, rootPathOption);
|
|
6271
|
+
try {
|
|
6272
|
+
options.miniflare = parseWorkerOptions(
|
|
6273
|
+
rootPath,
|
|
6274
|
+
options.miniflare,
|
|
6275
|
+
/* withoutScript */
|
|
6276
|
+
true,
|
|
6277
|
+
// (script provided by runner)
|
|
6278
|
+
{ path: [...opts.path, "miniflare"] }
|
|
6279
|
+
);
|
|
6280
|
+
} catch (e) {
|
|
6281
|
+
coalesceZodErrors(errorRef, e);
|
|
6282
|
+
}
|
|
6283
|
+
options.miniflare.workers = [];
|
|
6284
|
+
if (workers !== void 0) {
|
|
6285
|
+
options.miniflare.workers = workers.map((worker, i) => {
|
|
6286
|
+
try {
|
|
6287
|
+
const workerRootPathOption = getRootPath(worker);
|
|
6288
|
+
const workerRootPath = path2.resolve(rootPath, workerRootPathOption);
|
|
6289
|
+
return parseWorkerOptions(
|
|
6290
|
+
workerRootPath,
|
|
6291
|
+
worker,
|
|
6292
|
+
/* withoutScript */
|
|
6293
|
+
false,
|
|
6294
|
+
{
|
|
6295
|
+
path: [...opts.path, "miniflare", "workers", i]
|
|
6296
|
+
}
|
|
6297
|
+
);
|
|
6298
|
+
} catch (e) {
|
|
6299
|
+
coalesceZodErrors(errorRef, e);
|
|
6300
|
+
return { script: "" };
|
|
6301
|
+
}
|
|
6302
|
+
});
|
|
6303
|
+
}
|
|
6304
|
+
if (errorRef.value !== void 0) {
|
|
6305
|
+
throw errorRef.value;
|
|
6306
|
+
}
|
|
6307
|
+
if (options.wrangler?.configPath !== void 0) {
|
|
6308
|
+
const configPath = path2.resolve(rootPath, options.wrangler.configPath);
|
|
6309
|
+
options.wrangler.configPath = configPath;
|
|
6310
|
+
const wrangler = await import("wrangler");
|
|
6311
|
+
const preExistingRemoteProxySessionData = options.wrangler?.configPath ? remoteProxySessionsDataMap.get(options.wrangler.configPath) : void 0;
|
|
6312
|
+
const remoteProxySessionData = options.remoteBindings ?? true ? await wrangler.maybeStartOrUpdateRemoteProxySession(
|
|
6313
|
+
{
|
|
6314
|
+
path: options.wrangler.configPath,
|
|
6315
|
+
environment: options.wrangler.environment
|
|
6316
|
+
},
|
|
6317
|
+
preExistingRemoteProxySessionData ?? null
|
|
6318
|
+
) : null;
|
|
6319
|
+
if (options.wrangler?.configPath && remoteProxySessionData) {
|
|
6320
|
+
remoteProxySessionsDataMap.set(
|
|
6321
|
+
options.wrangler.configPath,
|
|
6322
|
+
remoteProxySessionData
|
|
6323
|
+
);
|
|
6324
|
+
}
|
|
6325
|
+
const { workerOptions, externalWorkers, define, main } = wrangler.unstable_getMiniflareWorkerOptions(
|
|
6326
|
+
configPath,
|
|
6327
|
+
options.wrangler.environment,
|
|
6328
|
+
{
|
|
2266
6329
|
overrides: {
|
|
2267
6330
|
assets: options.miniflare.assets,
|
|
2268
6331
|
// doesn't work with containers yet so let's just disable it
|
|
@@ -2745,10 +6808,10 @@ import { createRequire } from "node:module";
|
|
|
2745
6808
|
import platformPath from "node:path";
|
|
2746
6809
|
import posixPath from "node:path/posix";
|
|
2747
6810
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
2748
|
-
import
|
|
6811
|
+
import util2 from "node:util";
|
|
2749
6812
|
import * as cjsModuleLexer from "cjs-module-lexer";
|
|
2750
6813
|
import { ModuleRuleTypeSchema, Response as Response2 } from "miniflare";
|
|
2751
|
-
var debuglog =
|
|
6814
|
+
var debuglog = util2.debuglog(
|
|
2752
6815
|
"vitest-pool-workers:module-fallback",
|
|
2753
6816
|
(log3) => debuglog = log3
|
|
2754
6817
|
);
|
|
@@ -2881,12 +6944,12 @@ function withSourceUrl(contents, url) {
|
|
|
2881
6944
|
function withImportMetaUrl(contents, url) {
|
|
2882
6945
|
return contents.replaceAll("import.meta.url", JSON.stringify(url.toString()));
|
|
2883
6946
|
}
|
|
2884
|
-
var
|
|
6947
|
+
var moduleExtensions = [".js", ".mjs", ".cjs", ".json"];
|
|
2885
6948
|
function maybeGetTargetFilePath(target) {
|
|
2886
6949
|
if (isFile(target)) {
|
|
2887
6950
|
return target;
|
|
2888
6951
|
}
|
|
2889
|
-
for (const extension of
|
|
6952
|
+
for (const extension of moduleExtensions) {
|
|
2890
6953
|
const targetWithExtension = target + extension;
|
|
2891
6954
|
if (fs2.existsSync(targetWithExtension)) {
|
|
2892
6955
|
return targetWithExtension;
|
|
@@ -3024,6 +7087,11 @@ async function load(vite, logBase, method, target, specifier, filePath) {
|
|
|
3024
7087
|
filePath = trimSuffix(disableCjsEsmShimSuffix, filePath);
|
|
3025
7088
|
}
|
|
3026
7089
|
const isEsm = filePath.endsWith(".mjs") || filePath.endsWith(".js") && isWithinTypeModuleContext(filePath);
|
|
7090
|
+
if (filePath.endsWith(".json")) {
|
|
7091
|
+
const json = fs2.readFileSync(filePath, "utf8");
|
|
7092
|
+
debuglog(logBase, "json:", filePath);
|
|
7093
|
+
return buildModuleResponse(target, { json });
|
|
7094
|
+
}
|
|
3027
7095
|
let contents = fs2.readFileSync(filePath, "utf8");
|
|
3028
7096
|
const targetUrl = pathToFileURL(target);
|
|
3029
7097
|
contents = withSourceUrl(contents, targetUrl);
|
|
@@ -3098,7 +7166,7 @@ function structuredSerializableStringify(value) {
|
|
|
3098
7166
|
function structuredSerializableParse(value) {
|
|
3099
7167
|
return parse(value, structuredSerializableRevivers);
|
|
3100
7168
|
}
|
|
3101
|
-
var debuglog2 =
|
|
7169
|
+
var debuglog2 = util3.debuglog(
|
|
3102
7170
|
"vitest-pool-workers:index",
|
|
3103
7171
|
(fn) => debuglog2 = fn
|
|
3104
7172
|
);
|
|
@@ -3530,7 +7598,7 @@ async function buildProjectMiniflareOptions(ctx, project) {
|
|
|
3530
7598
|
}
|
|
3531
7599
|
async function getProjectMiniflare(ctx, project) {
|
|
3532
7600
|
const mfOptions = await buildProjectMiniflareOptions(ctx, project);
|
|
3533
|
-
const changed = !
|
|
7601
|
+
const changed = !util3.isDeepStrictEqual(project.previousMfOptions, mfOptions);
|
|
3534
7602
|
project.previousMfOptions = mfOptions;
|
|
3535
7603
|
const previousSingleInstance = project.mf instanceof Miniflare;
|
|
3536
7604
|
const singleInstance = project.options.singleWorker || !project.options.isolatedStorage;
|
|
@@ -3640,7 +7708,7 @@ async function runTests(ctx, mf, workerName, project, config, files, invalidates
|
|
|
3640
7708
|
const maybeRule = compiledRules.find(
|
|
3641
7709
|
(rule) => testRegExps(rule.include, specifier)
|
|
3642
7710
|
);
|
|
3643
|
-
if (maybeRule !== void 0) {
|
|
7711
|
+
if (maybeRule !== void 0 && !specifier.includes("?")) {
|
|
3644
7712
|
const externalize = specifier + `?mf_vitest_force=${maybeRule.type}`;
|
|
3645
7713
|
return { externalize };
|
|
3646
7714
|
}
|