@neofaceid/web-sdk 1.23.0 → 1.24.1
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.
|
@@ -565,31 +565,31 @@ function requireReactJsxRuntime_development() {
|
|
|
565
565
|
};
|
|
566
566
|
var specialPropKeyWarningShown;
|
|
567
567
|
var specialPropRefWarningShown;
|
|
568
|
-
function hasValidRef(
|
|
568
|
+
function hasValidRef(config2) {
|
|
569
569
|
{
|
|
570
|
-
if (hasOwnProperty.call(
|
|
571
|
-
var getter = Object.getOwnPropertyDescriptor(
|
|
570
|
+
if (hasOwnProperty.call(config2, "ref")) {
|
|
571
|
+
var getter = Object.getOwnPropertyDescriptor(config2, "ref").get;
|
|
572
572
|
if (getter && getter.isReactWarning) {
|
|
573
573
|
return false;
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
-
return
|
|
577
|
+
return config2.ref !== void 0;
|
|
578
578
|
}
|
|
579
|
-
function hasValidKey(
|
|
579
|
+
function hasValidKey(config2) {
|
|
580
580
|
{
|
|
581
|
-
if (hasOwnProperty.call(
|
|
582
|
-
var getter = Object.getOwnPropertyDescriptor(
|
|
581
|
+
if (hasOwnProperty.call(config2, "key")) {
|
|
582
|
+
var getter = Object.getOwnPropertyDescriptor(config2, "key").get;
|
|
583
583
|
if (getter && getter.isReactWarning) {
|
|
584
584
|
return false;
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
|
-
return
|
|
588
|
+
return config2.key !== void 0;
|
|
589
589
|
}
|
|
590
|
-
function warnIfStringRefCannotBeAutoConverted(
|
|
590
|
+
function warnIfStringRefCannotBeAutoConverted(config2, self) {
|
|
591
591
|
{
|
|
592
|
-
if (typeof
|
|
592
|
+
if (typeof config2.ref === "string" && ReactCurrentOwner.current && self) ;
|
|
593
593
|
}
|
|
594
594
|
}
|
|
595
595
|
function defineKeyPropWarningGetter(props, displayName) {
|
|
@@ -661,7 +661,7 @@ function requireReactJsxRuntime_development() {
|
|
|
661
661
|
}
|
|
662
662
|
return element;
|
|
663
663
|
};
|
|
664
|
-
function jsxDEV(type,
|
|
664
|
+
function jsxDEV(type, config2, maybeKey, source, self) {
|
|
665
665
|
{
|
|
666
666
|
var propName;
|
|
667
667
|
var props = {};
|
|
@@ -673,19 +673,19 @@ function requireReactJsxRuntime_development() {
|
|
|
673
673
|
}
|
|
674
674
|
key = "" + maybeKey;
|
|
675
675
|
}
|
|
676
|
-
if (hasValidKey(
|
|
676
|
+
if (hasValidKey(config2)) {
|
|
677
677
|
{
|
|
678
|
-
checkKeyStringCoercion(
|
|
678
|
+
checkKeyStringCoercion(config2.key);
|
|
679
679
|
}
|
|
680
|
-
key = "" +
|
|
680
|
+
key = "" + config2.key;
|
|
681
681
|
}
|
|
682
|
-
if (hasValidRef(
|
|
683
|
-
ref =
|
|
684
|
-
warnIfStringRefCannotBeAutoConverted(
|
|
682
|
+
if (hasValidRef(config2)) {
|
|
683
|
+
ref = config2.ref;
|
|
684
|
+
warnIfStringRefCannotBeAutoConverted(config2, self);
|
|
685
685
|
}
|
|
686
|
-
for (propName in
|
|
687
|
-
if (hasOwnProperty.call(
|
|
688
|
-
props[propName] =
|
|
686
|
+
for (propName in config2) {
|
|
687
|
+
if (hasOwnProperty.call(config2, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
688
|
+
props[propName] = config2[propName];
|
|
689
689
|
}
|
|
690
690
|
}
|
|
691
691
|
if (type && type.defaultProps) {
|
|
@@ -725,9 +725,9 @@ function requireReactJsxRuntime_development() {
|
|
|
725
725
|
{
|
|
726
726
|
propTypesMisspellWarningShown = false;
|
|
727
727
|
}
|
|
728
|
-
function isValidElement(
|
|
728
|
+
function isValidElement(object2) {
|
|
729
729
|
{
|
|
730
|
-
return typeof
|
|
730
|
+
return typeof object2 === "object" && object2 !== null && object2.$$typeof === REACT_ELEMENT_TYPE;
|
|
731
731
|
}
|
|
732
732
|
}
|
|
733
733
|
function getDeclarationErrorAddendum() {
|
|
@@ -1004,7 +1004,7 @@ const useCamera = () => {
|
|
|
1004
1004
|
};
|
|
1005
1005
|
const startCamera = useCallback(
|
|
1006
1006
|
async (constraints) => {
|
|
1007
|
-
var
|
|
1007
|
+
var _a2;
|
|
1008
1008
|
console.log("🎬 [useCamera] startCamera chamado", {
|
|
1009
1009
|
hasExistingStream: !!streamRef.current,
|
|
1010
1010
|
isInitializing: isInitializingRef.current
|
|
@@ -1046,7 +1046,7 @@ const useCamera = () => {
|
|
|
1046
1046
|
console.log("📋 [useCamera] Detalhes do erro:", {
|
|
1047
1047
|
name: error.name,
|
|
1048
1048
|
message: error.message,
|
|
1049
|
-
stack: (
|
|
1049
|
+
stack: (_a2 = error.stack) == null ? void 0 : _a2.substring(0, 200)
|
|
1050
1050
|
});
|
|
1051
1051
|
if (error.name === "NotAllowedError" || error.name === "PermissionDeniedError") {
|
|
1052
1052
|
throw new CameraPermissionDenied(
|
|
@@ -1163,6 +1163,4139 @@ class NeoFaceError extends Error {
|
|
|
1163
1163
|
}
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
|
+
function $constructor(name, initializer2, params) {
|
|
1167
|
+
function init2(inst, def) {
|
|
1168
|
+
if (!inst._zod) {
|
|
1169
|
+
Object.defineProperty(inst, "_zod", {
|
|
1170
|
+
value: {
|
|
1171
|
+
def,
|
|
1172
|
+
constr: _,
|
|
1173
|
+
traits: /* @__PURE__ */ new Set()
|
|
1174
|
+
},
|
|
1175
|
+
enumerable: false
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
if (inst._zod.traits.has(name)) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
inst._zod.traits.add(name);
|
|
1182
|
+
initializer2(inst, def);
|
|
1183
|
+
const proto = _.prototype;
|
|
1184
|
+
const keys = Object.keys(proto);
|
|
1185
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1186
|
+
const k = keys[i];
|
|
1187
|
+
if (!(k in inst)) {
|
|
1188
|
+
inst[k] = proto[k].bind(inst);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
const Parent = (params == null ? void 0 : params.Parent) ?? Object;
|
|
1193
|
+
class Definition extends Parent {
|
|
1194
|
+
}
|
|
1195
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
1196
|
+
function _(def) {
|
|
1197
|
+
var _a2;
|
|
1198
|
+
const inst = (params == null ? void 0 : params.Parent) ? new Definition() : this;
|
|
1199
|
+
init2(inst, def);
|
|
1200
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
1201
|
+
for (const fn of inst._zod.deferred) {
|
|
1202
|
+
fn();
|
|
1203
|
+
}
|
|
1204
|
+
return inst;
|
|
1205
|
+
}
|
|
1206
|
+
Object.defineProperty(_, "init", { value: init2 });
|
|
1207
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
1208
|
+
value: (inst) => {
|
|
1209
|
+
var _a2, _b;
|
|
1210
|
+
if ((params == null ? void 0 : params.Parent) && inst instanceof params.Parent)
|
|
1211
|
+
return true;
|
|
1212
|
+
return (_b = (_a2 = inst == null ? void 0 : inst._zod) == null ? void 0 : _a2.traits) == null ? void 0 : _b.has(name);
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
Object.defineProperty(_, "name", { value: name });
|
|
1216
|
+
return _;
|
|
1217
|
+
}
|
|
1218
|
+
class $ZodAsyncError extends Error {
|
|
1219
|
+
constructor() {
|
|
1220
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
class $ZodEncodeError extends Error {
|
|
1224
|
+
constructor(name) {
|
|
1225
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
1226
|
+
this.name = "ZodEncodeError";
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
const globalConfig$1 = {};
|
|
1230
|
+
function config(newConfig) {
|
|
1231
|
+
return globalConfig$1;
|
|
1232
|
+
}
|
|
1233
|
+
function getEnumValues(entries) {
|
|
1234
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
1235
|
+
const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
1236
|
+
return values;
|
|
1237
|
+
}
|
|
1238
|
+
function jsonStringifyReplacer(_, value) {
|
|
1239
|
+
if (typeof value === "bigint")
|
|
1240
|
+
return value.toString();
|
|
1241
|
+
return value;
|
|
1242
|
+
}
|
|
1243
|
+
function cached(getter) {
|
|
1244
|
+
return {
|
|
1245
|
+
get value() {
|
|
1246
|
+
{
|
|
1247
|
+
const value = getter();
|
|
1248
|
+
Object.defineProperty(this, "value", { value });
|
|
1249
|
+
return value;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function nullish(input) {
|
|
1255
|
+
return input === null || input === void 0;
|
|
1256
|
+
}
|
|
1257
|
+
function cleanRegex(source) {
|
|
1258
|
+
const start2 = source.startsWith("^") ? 1 : 0;
|
|
1259
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
1260
|
+
return source.slice(start2, end);
|
|
1261
|
+
}
|
|
1262
|
+
function floatSafeRemainder(val, step) {
|
|
1263
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1264
|
+
const stepString = step.toString();
|
|
1265
|
+
let stepDecCount = (stepString.split(".")[1] || "").length;
|
|
1266
|
+
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
|
1267
|
+
const match = stepString.match(/\d?e-(\d?)/);
|
|
1268
|
+
if (match == null ? void 0 : match[1]) {
|
|
1269
|
+
stepDecCount = Number.parseInt(match[1]);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1273
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1274
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1275
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1276
|
+
}
|
|
1277
|
+
const EVALUATING = Symbol("evaluating");
|
|
1278
|
+
function defineLazy(object2, key, getter) {
|
|
1279
|
+
let value = void 0;
|
|
1280
|
+
Object.defineProperty(object2, key, {
|
|
1281
|
+
get() {
|
|
1282
|
+
if (value === EVALUATING) {
|
|
1283
|
+
return void 0;
|
|
1284
|
+
}
|
|
1285
|
+
if (value === void 0) {
|
|
1286
|
+
value = EVALUATING;
|
|
1287
|
+
value = getter();
|
|
1288
|
+
}
|
|
1289
|
+
return value;
|
|
1290
|
+
},
|
|
1291
|
+
set(v) {
|
|
1292
|
+
Object.defineProperty(object2, key, {
|
|
1293
|
+
value: v
|
|
1294
|
+
// configurable: true,
|
|
1295
|
+
});
|
|
1296
|
+
},
|
|
1297
|
+
configurable: true
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
function assignProp(target, prop, value) {
|
|
1301
|
+
Object.defineProperty(target, prop, {
|
|
1302
|
+
value,
|
|
1303
|
+
writable: true,
|
|
1304
|
+
enumerable: true,
|
|
1305
|
+
configurable: true
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
function mergeDefs(...defs) {
|
|
1309
|
+
const mergedDescriptors = {};
|
|
1310
|
+
for (const def of defs) {
|
|
1311
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
1312
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
1313
|
+
}
|
|
1314
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
1315
|
+
}
|
|
1316
|
+
function esc(str) {
|
|
1317
|
+
return JSON.stringify(str);
|
|
1318
|
+
}
|
|
1319
|
+
function slugify(input) {
|
|
1320
|
+
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1321
|
+
}
|
|
1322
|
+
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
|
|
1323
|
+
};
|
|
1324
|
+
function isObject(data) {
|
|
1325
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
1326
|
+
}
|
|
1327
|
+
const allowsEval = cached(() => {
|
|
1328
|
+
var _a2;
|
|
1329
|
+
if (typeof navigator !== "undefined" && ((_a2 = navigator == null ? void 0 : navigator.userAgent) == null ? void 0 : _a2.includes("Cloudflare"))) {
|
|
1330
|
+
return false;
|
|
1331
|
+
}
|
|
1332
|
+
try {
|
|
1333
|
+
const F = Function;
|
|
1334
|
+
new F("");
|
|
1335
|
+
return true;
|
|
1336
|
+
} catch (_) {
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
function isPlainObject(o) {
|
|
1341
|
+
if (isObject(o) === false)
|
|
1342
|
+
return false;
|
|
1343
|
+
const ctor = o.constructor;
|
|
1344
|
+
if (ctor === void 0)
|
|
1345
|
+
return true;
|
|
1346
|
+
if (typeof ctor !== "function")
|
|
1347
|
+
return true;
|
|
1348
|
+
const prot = ctor.prototype;
|
|
1349
|
+
if (isObject(prot) === false)
|
|
1350
|
+
return false;
|
|
1351
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
return true;
|
|
1355
|
+
}
|
|
1356
|
+
function shallowClone(o) {
|
|
1357
|
+
if (isPlainObject(o))
|
|
1358
|
+
return { ...o };
|
|
1359
|
+
if (Array.isArray(o))
|
|
1360
|
+
return [...o];
|
|
1361
|
+
return o;
|
|
1362
|
+
}
|
|
1363
|
+
const propertyKeyTypes = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
|
|
1364
|
+
function escapeRegex(str) {
|
|
1365
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1366
|
+
}
|
|
1367
|
+
function clone(inst, def, params) {
|
|
1368
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
1369
|
+
if (!def || (params == null ? void 0 : params.parent))
|
|
1370
|
+
cl._zod.parent = inst;
|
|
1371
|
+
return cl;
|
|
1372
|
+
}
|
|
1373
|
+
function normalizeParams(_params) {
|
|
1374
|
+
const params = _params;
|
|
1375
|
+
if (!params)
|
|
1376
|
+
return {};
|
|
1377
|
+
if (typeof params === "string")
|
|
1378
|
+
return { error: () => params };
|
|
1379
|
+
if ((params == null ? void 0 : params.message) !== void 0) {
|
|
1380
|
+
if ((params == null ? void 0 : params.error) !== void 0)
|
|
1381
|
+
throw new Error("Cannot specify both `message` and `error` params");
|
|
1382
|
+
params.error = params.message;
|
|
1383
|
+
}
|
|
1384
|
+
delete params.message;
|
|
1385
|
+
if (typeof params.error === "string")
|
|
1386
|
+
return { ...params, error: () => params.error };
|
|
1387
|
+
return params;
|
|
1388
|
+
}
|
|
1389
|
+
function optionalKeys(shape) {
|
|
1390
|
+
return Object.keys(shape).filter((k) => {
|
|
1391
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
const NUMBER_FORMAT_RANGES = {
|
|
1395
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
1396
|
+
int32: [-2147483648, 2147483647],
|
|
1397
|
+
uint32: [0, 4294967295],
|
|
1398
|
+
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
1399
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
1400
|
+
};
|
|
1401
|
+
function pick(schema, mask) {
|
|
1402
|
+
const currDef = schema._zod.def;
|
|
1403
|
+
const checks = currDef.checks;
|
|
1404
|
+
const hasChecks = checks && checks.length > 0;
|
|
1405
|
+
if (hasChecks) {
|
|
1406
|
+
throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
1407
|
+
}
|
|
1408
|
+
const def = mergeDefs(schema._zod.def, {
|
|
1409
|
+
get shape() {
|
|
1410
|
+
const newShape = {};
|
|
1411
|
+
for (const key in mask) {
|
|
1412
|
+
if (!(key in currDef.shape)) {
|
|
1413
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
1414
|
+
}
|
|
1415
|
+
if (!mask[key])
|
|
1416
|
+
continue;
|
|
1417
|
+
newShape[key] = currDef.shape[key];
|
|
1418
|
+
}
|
|
1419
|
+
assignProp(this, "shape", newShape);
|
|
1420
|
+
return newShape;
|
|
1421
|
+
},
|
|
1422
|
+
checks: []
|
|
1423
|
+
});
|
|
1424
|
+
return clone(schema, def);
|
|
1425
|
+
}
|
|
1426
|
+
function omit(schema, mask) {
|
|
1427
|
+
const currDef = schema._zod.def;
|
|
1428
|
+
const checks = currDef.checks;
|
|
1429
|
+
const hasChecks = checks && checks.length > 0;
|
|
1430
|
+
if (hasChecks) {
|
|
1431
|
+
throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
1432
|
+
}
|
|
1433
|
+
const def = mergeDefs(schema._zod.def, {
|
|
1434
|
+
get shape() {
|
|
1435
|
+
const newShape = { ...schema._zod.def.shape };
|
|
1436
|
+
for (const key in mask) {
|
|
1437
|
+
if (!(key in currDef.shape)) {
|
|
1438
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
1439
|
+
}
|
|
1440
|
+
if (!mask[key])
|
|
1441
|
+
continue;
|
|
1442
|
+
delete newShape[key];
|
|
1443
|
+
}
|
|
1444
|
+
assignProp(this, "shape", newShape);
|
|
1445
|
+
return newShape;
|
|
1446
|
+
},
|
|
1447
|
+
checks: []
|
|
1448
|
+
});
|
|
1449
|
+
return clone(schema, def);
|
|
1450
|
+
}
|
|
1451
|
+
function extend(schema, shape) {
|
|
1452
|
+
if (!isPlainObject(shape)) {
|
|
1453
|
+
throw new Error("Invalid input to extend: expected a plain object");
|
|
1454
|
+
}
|
|
1455
|
+
const checks = schema._zod.def.checks;
|
|
1456
|
+
const hasChecks = checks && checks.length > 0;
|
|
1457
|
+
if (hasChecks) {
|
|
1458
|
+
const existingShape = schema._zod.def.shape;
|
|
1459
|
+
for (const key in shape) {
|
|
1460
|
+
if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) {
|
|
1461
|
+
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
const def = mergeDefs(schema._zod.def, {
|
|
1466
|
+
get shape() {
|
|
1467
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
1468
|
+
assignProp(this, "shape", _shape);
|
|
1469
|
+
return _shape;
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
return clone(schema, def);
|
|
1473
|
+
}
|
|
1474
|
+
function safeExtend(schema, shape) {
|
|
1475
|
+
if (!isPlainObject(shape)) {
|
|
1476
|
+
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
1477
|
+
}
|
|
1478
|
+
const def = mergeDefs(schema._zod.def, {
|
|
1479
|
+
get shape() {
|
|
1480
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
1481
|
+
assignProp(this, "shape", _shape);
|
|
1482
|
+
return _shape;
|
|
1483
|
+
}
|
|
1484
|
+
});
|
|
1485
|
+
return clone(schema, def);
|
|
1486
|
+
}
|
|
1487
|
+
function merge(a, b) {
|
|
1488
|
+
const def = mergeDefs(a._zod.def, {
|
|
1489
|
+
get shape() {
|
|
1490
|
+
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
1491
|
+
assignProp(this, "shape", _shape);
|
|
1492
|
+
return _shape;
|
|
1493
|
+
},
|
|
1494
|
+
get catchall() {
|
|
1495
|
+
return b._zod.def.catchall;
|
|
1496
|
+
},
|
|
1497
|
+
checks: []
|
|
1498
|
+
// delete existing checks
|
|
1499
|
+
});
|
|
1500
|
+
return clone(a, def);
|
|
1501
|
+
}
|
|
1502
|
+
function partial(Class, schema, mask) {
|
|
1503
|
+
const currDef = schema._zod.def;
|
|
1504
|
+
const checks = currDef.checks;
|
|
1505
|
+
const hasChecks = checks && checks.length > 0;
|
|
1506
|
+
if (hasChecks) {
|
|
1507
|
+
throw new Error(".partial() cannot be used on object schemas containing refinements");
|
|
1508
|
+
}
|
|
1509
|
+
const def = mergeDefs(schema._zod.def, {
|
|
1510
|
+
get shape() {
|
|
1511
|
+
const oldShape = schema._zod.def.shape;
|
|
1512
|
+
const shape = { ...oldShape };
|
|
1513
|
+
if (mask) {
|
|
1514
|
+
for (const key in mask) {
|
|
1515
|
+
if (!(key in oldShape)) {
|
|
1516
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
1517
|
+
}
|
|
1518
|
+
if (!mask[key])
|
|
1519
|
+
continue;
|
|
1520
|
+
shape[key] = Class ? new Class({
|
|
1521
|
+
type: "optional",
|
|
1522
|
+
innerType: oldShape[key]
|
|
1523
|
+
}) : oldShape[key];
|
|
1524
|
+
}
|
|
1525
|
+
} else {
|
|
1526
|
+
for (const key in oldShape) {
|
|
1527
|
+
shape[key] = Class ? new Class({
|
|
1528
|
+
type: "optional",
|
|
1529
|
+
innerType: oldShape[key]
|
|
1530
|
+
}) : oldShape[key];
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
assignProp(this, "shape", shape);
|
|
1534
|
+
return shape;
|
|
1535
|
+
},
|
|
1536
|
+
checks: []
|
|
1537
|
+
});
|
|
1538
|
+
return clone(schema, def);
|
|
1539
|
+
}
|
|
1540
|
+
function required(Class, schema, mask) {
|
|
1541
|
+
const def = mergeDefs(schema._zod.def, {
|
|
1542
|
+
get shape() {
|
|
1543
|
+
const oldShape = schema._zod.def.shape;
|
|
1544
|
+
const shape = { ...oldShape };
|
|
1545
|
+
if (mask) {
|
|
1546
|
+
for (const key in mask) {
|
|
1547
|
+
if (!(key in shape)) {
|
|
1548
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
1549
|
+
}
|
|
1550
|
+
if (!mask[key])
|
|
1551
|
+
continue;
|
|
1552
|
+
shape[key] = new Class({
|
|
1553
|
+
type: "nonoptional",
|
|
1554
|
+
innerType: oldShape[key]
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
} else {
|
|
1558
|
+
for (const key in oldShape) {
|
|
1559
|
+
shape[key] = new Class({
|
|
1560
|
+
type: "nonoptional",
|
|
1561
|
+
innerType: oldShape[key]
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
assignProp(this, "shape", shape);
|
|
1566
|
+
return shape;
|
|
1567
|
+
}
|
|
1568
|
+
});
|
|
1569
|
+
return clone(schema, def);
|
|
1570
|
+
}
|
|
1571
|
+
function aborted(x, startIndex = 0) {
|
|
1572
|
+
var _a2;
|
|
1573
|
+
if (x.aborted === true)
|
|
1574
|
+
return true;
|
|
1575
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
1576
|
+
if (((_a2 = x.issues[i]) == null ? void 0 : _a2.continue) !== true) {
|
|
1577
|
+
return true;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
return false;
|
|
1581
|
+
}
|
|
1582
|
+
function prefixIssues(path, issues) {
|
|
1583
|
+
return issues.map((iss) => {
|
|
1584
|
+
var _a2;
|
|
1585
|
+
(_a2 = iss).path ?? (_a2.path = []);
|
|
1586
|
+
iss.path.unshift(path);
|
|
1587
|
+
return iss;
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
function unwrapMessage(message) {
|
|
1591
|
+
return typeof message === "string" ? message : message == null ? void 0 : message.message;
|
|
1592
|
+
}
|
|
1593
|
+
function finalizeIssue(iss, ctx, config2) {
|
|
1594
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
1595
|
+
const full = { ...iss, path: iss.path ?? [] };
|
|
1596
|
+
if (!iss.message) {
|
|
1597
|
+
const message = unwrapMessage((_c = (_b = (_a2 = iss.inst) == null ? void 0 : _a2._zod.def) == null ? void 0 : _b.error) == null ? void 0 : _c.call(_b, iss)) ?? unwrapMessage((_d = ctx == null ? void 0 : ctx.error) == null ? void 0 : _d.call(ctx, iss)) ?? unwrapMessage((_e = config2.customError) == null ? void 0 : _e.call(config2, iss)) ?? unwrapMessage((_f = config2.localeError) == null ? void 0 : _f.call(config2, iss)) ?? "Invalid input";
|
|
1598
|
+
full.message = message;
|
|
1599
|
+
}
|
|
1600
|
+
delete full.inst;
|
|
1601
|
+
delete full.continue;
|
|
1602
|
+
if (!(ctx == null ? void 0 : ctx.reportInput)) {
|
|
1603
|
+
delete full.input;
|
|
1604
|
+
}
|
|
1605
|
+
return full;
|
|
1606
|
+
}
|
|
1607
|
+
function getLengthableOrigin(input) {
|
|
1608
|
+
if (Array.isArray(input))
|
|
1609
|
+
return "array";
|
|
1610
|
+
if (typeof input === "string")
|
|
1611
|
+
return "string";
|
|
1612
|
+
return "unknown";
|
|
1613
|
+
}
|
|
1614
|
+
function issue(...args) {
|
|
1615
|
+
const [iss, input, inst] = args;
|
|
1616
|
+
if (typeof iss === "string") {
|
|
1617
|
+
return {
|
|
1618
|
+
message: iss,
|
|
1619
|
+
code: "custom",
|
|
1620
|
+
input,
|
|
1621
|
+
inst
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
return { ...iss };
|
|
1625
|
+
}
|
|
1626
|
+
const initializer$1 = (inst, def) => {
|
|
1627
|
+
inst.name = "$ZodError";
|
|
1628
|
+
Object.defineProperty(inst, "_zod", {
|
|
1629
|
+
value: inst._zod,
|
|
1630
|
+
enumerable: false
|
|
1631
|
+
});
|
|
1632
|
+
Object.defineProperty(inst, "issues", {
|
|
1633
|
+
value: def,
|
|
1634
|
+
enumerable: false
|
|
1635
|
+
});
|
|
1636
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
1637
|
+
Object.defineProperty(inst, "toString", {
|
|
1638
|
+
value: () => inst.message,
|
|
1639
|
+
enumerable: false
|
|
1640
|
+
});
|
|
1641
|
+
};
|
|
1642
|
+
const $ZodError = $constructor("$ZodError", initializer$1);
|
|
1643
|
+
const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
|
|
1644
|
+
function flattenError(error, mapper = (issue2) => issue2.message) {
|
|
1645
|
+
const fieldErrors = {};
|
|
1646
|
+
const formErrors = [];
|
|
1647
|
+
for (const sub of error.issues) {
|
|
1648
|
+
if (sub.path.length > 0) {
|
|
1649
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
1650
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
1651
|
+
} else {
|
|
1652
|
+
formErrors.push(mapper(sub));
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return { formErrors, fieldErrors };
|
|
1656
|
+
}
|
|
1657
|
+
function formatError(error, mapper = (issue2) => issue2.message) {
|
|
1658
|
+
const fieldErrors = { _errors: [] };
|
|
1659
|
+
const processError = (error2) => {
|
|
1660
|
+
for (const issue2 of error2.issues) {
|
|
1661
|
+
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1662
|
+
issue2.errors.map((issues) => processError({ issues }));
|
|
1663
|
+
} else if (issue2.code === "invalid_key") {
|
|
1664
|
+
processError({ issues: issue2.issues });
|
|
1665
|
+
} else if (issue2.code === "invalid_element") {
|
|
1666
|
+
processError({ issues: issue2.issues });
|
|
1667
|
+
} else if (issue2.path.length === 0) {
|
|
1668
|
+
fieldErrors._errors.push(mapper(issue2));
|
|
1669
|
+
} else {
|
|
1670
|
+
let curr = fieldErrors;
|
|
1671
|
+
let i = 0;
|
|
1672
|
+
while (i < issue2.path.length) {
|
|
1673
|
+
const el = issue2.path[i];
|
|
1674
|
+
const terminal = i === issue2.path.length - 1;
|
|
1675
|
+
if (!terminal) {
|
|
1676
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
1677
|
+
} else {
|
|
1678
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
1679
|
+
curr[el]._errors.push(mapper(issue2));
|
|
1680
|
+
}
|
|
1681
|
+
curr = curr[el];
|
|
1682
|
+
i++;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1687
|
+
processError(error);
|
|
1688
|
+
return fieldErrors;
|
|
1689
|
+
}
|
|
1690
|
+
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
1691
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
1692
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
1693
|
+
if (result instanceof Promise) {
|
|
1694
|
+
throw new $ZodAsyncError();
|
|
1695
|
+
}
|
|
1696
|
+
if (result.issues.length) {
|
|
1697
|
+
const e = new ((_params == null ? void 0 : _params.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
1698
|
+
captureStackTrace(e, _params == null ? void 0 : _params.callee);
|
|
1699
|
+
throw e;
|
|
1700
|
+
}
|
|
1701
|
+
return result.value;
|
|
1702
|
+
};
|
|
1703
|
+
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
1704
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
1705
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
1706
|
+
if (result instanceof Promise)
|
|
1707
|
+
result = await result;
|
|
1708
|
+
if (result.issues.length) {
|
|
1709
|
+
const e = new ((params == null ? void 0 : params.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
1710
|
+
captureStackTrace(e, params == null ? void 0 : params.callee);
|
|
1711
|
+
throw e;
|
|
1712
|
+
}
|
|
1713
|
+
return result.value;
|
|
1714
|
+
};
|
|
1715
|
+
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
1716
|
+
const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
|
|
1717
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
1718
|
+
if (result instanceof Promise) {
|
|
1719
|
+
throw new $ZodAsyncError();
|
|
1720
|
+
}
|
|
1721
|
+
return result.issues.length ? {
|
|
1722
|
+
success: false,
|
|
1723
|
+
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
1724
|
+
} : { success: true, data: result.value };
|
|
1725
|
+
};
|
|
1726
|
+
const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
1727
|
+
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
1728
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
1729
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
1730
|
+
if (result instanceof Promise)
|
|
1731
|
+
result = await result;
|
|
1732
|
+
return result.issues.length ? {
|
|
1733
|
+
success: false,
|
|
1734
|
+
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
1735
|
+
} : { success: true, data: result.value };
|
|
1736
|
+
};
|
|
1737
|
+
const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
1738
|
+
const _encode = (_Err) => (schema, value, _ctx) => {
|
|
1739
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
1740
|
+
return _parse(_Err)(schema, value, ctx);
|
|
1741
|
+
};
|
|
1742
|
+
const _decode = (_Err) => (schema, value, _ctx) => {
|
|
1743
|
+
return _parse(_Err)(schema, value, _ctx);
|
|
1744
|
+
};
|
|
1745
|
+
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
1746
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
1747
|
+
return _parseAsync(_Err)(schema, value, ctx);
|
|
1748
|
+
};
|
|
1749
|
+
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
1750
|
+
return _parseAsync(_Err)(schema, value, _ctx);
|
|
1751
|
+
};
|
|
1752
|
+
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
|
1753
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
1754
|
+
return _safeParse(_Err)(schema, value, ctx);
|
|
1755
|
+
};
|
|
1756
|
+
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
|
1757
|
+
return _safeParse(_Err)(schema, value, _ctx);
|
|
1758
|
+
};
|
|
1759
|
+
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
1760
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
1761
|
+
return _safeParseAsync(_Err)(schema, value, ctx);
|
|
1762
|
+
};
|
|
1763
|
+
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
1764
|
+
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
1765
|
+
};
|
|
1766
|
+
const cuid = /^[cC][^\s-]{8,}$/;
|
|
1767
|
+
const cuid2 = /^[0-9a-z]+$/;
|
|
1768
|
+
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
1769
|
+
const xid = /^[0-9a-vA-V]{20}$/;
|
|
1770
|
+
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
1771
|
+
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
1772
|
+
const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
1773
|
+
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
1774
|
+
const uuid = (version2) => {
|
|
1775
|
+
if (!version2)
|
|
1776
|
+
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
1777
|
+
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version2}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
1778
|
+
};
|
|
1779
|
+
const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
1780
|
+
const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1781
|
+
function emoji() {
|
|
1782
|
+
return new RegExp(_emoji$1, "u");
|
|
1783
|
+
}
|
|
1784
|
+
const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1785
|
+
const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
1786
|
+
const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
1787
|
+
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1788
|
+
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
1789
|
+
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
1790
|
+
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
1791
|
+
const dateSource = `(?:(?:\\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])))`;
|
|
1792
|
+
const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
|
|
1793
|
+
function timeSource(args) {
|
|
1794
|
+
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
|
1795
|
+
const regex = typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
1796
|
+
return regex;
|
|
1797
|
+
}
|
|
1798
|
+
function time$1(args) {
|
|
1799
|
+
return new RegExp(`^${timeSource(args)}$`);
|
|
1800
|
+
}
|
|
1801
|
+
function datetime$1(args) {
|
|
1802
|
+
const time2 = timeSource({ precision: args.precision });
|
|
1803
|
+
const opts = ["Z"];
|
|
1804
|
+
if (args.local)
|
|
1805
|
+
opts.push("");
|
|
1806
|
+
if (args.offset)
|
|
1807
|
+
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
|
1808
|
+
const timeRegex = `${time2}(?:${opts.join("|")})`;
|
|
1809
|
+
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
1810
|
+
}
|
|
1811
|
+
const string$1 = (params) => {
|
|
1812
|
+
const regex = params ? `[\\s\\S]{${(params == null ? void 0 : params.minimum) ?? 0},${(params == null ? void 0 : params.maximum) ?? ""}}` : `[\\s\\S]*`;
|
|
1813
|
+
return new RegExp(`^${regex}$`);
|
|
1814
|
+
};
|
|
1815
|
+
const integer = /^-?\d+$/;
|
|
1816
|
+
const number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
1817
|
+
const boolean$1 = /^(?:true|false)$/i;
|
|
1818
|
+
const lowercase = /^[^A-Z]*$/;
|
|
1819
|
+
const uppercase = /^[^a-z]*$/;
|
|
1820
|
+
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
1821
|
+
var _a2;
|
|
1822
|
+
inst._zod ?? (inst._zod = {});
|
|
1823
|
+
inst._zod.def = def;
|
|
1824
|
+
(_a2 = inst._zod).onattach ?? (_a2.onattach = []);
|
|
1825
|
+
});
|
|
1826
|
+
const numericOriginMap = {
|
|
1827
|
+
number: "number",
|
|
1828
|
+
bigint: "bigint",
|
|
1829
|
+
object: "date"
|
|
1830
|
+
};
|
|
1831
|
+
const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (inst, def) => {
|
|
1832
|
+
$ZodCheck.init(inst, def);
|
|
1833
|
+
const origin = numericOriginMap[typeof def.value];
|
|
1834
|
+
inst._zod.onattach.push((inst2) => {
|
|
1835
|
+
const bag = inst2._zod.bag;
|
|
1836
|
+
const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
|
|
1837
|
+
if (def.value < curr) {
|
|
1838
|
+
if (def.inclusive)
|
|
1839
|
+
bag.maximum = def.value;
|
|
1840
|
+
else
|
|
1841
|
+
bag.exclusiveMaximum = def.value;
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
inst._zod.check = (payload) => {
|
|
1845
|
+
if (def.inclusive ? payload.value <= def.value : payload.value < def.value) {
|
|
1846
|
+
return;
|
|
1847
|
+
}
|
|
1848
|
+
payload.issues.push({
|
|
1849
|
+
origin,
|
|
1850
|
+
code: "too_big",
|
|
1851
|
+
maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
1852
|
+
input: payload.value,
|
|
1853
|
+
inclusive: def.inclusive,
|
|
1854
|
+
inst,
|
|
1855
|
+
continue: !def.abort
|
|
1856
|
+
});
|
|
1857
|
+
};
|
|
1858
|
+
});
|
|
1859
|
+
const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan", (inst, def) => {
|
|
1860
|
+
$ZodCheck.init(inst, def);
|
|
1861
|
+
const origin = numericOriginMap[typeof def.value];
|
|
1862
|
+
inst._zod.onattach.push((inst2) => {
|
|
1863
|
+
const bag = inst2._zod.bag;
|
|
1864
|
+
const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
|
|
1865
|
+
if (def.value > curr) {
|
|
1866
|
+
if (def.inclusive)
|
|
1867
|
+
bag.minimum = def.value;
|
|
1868
|
+
else
|
|
1869
|
+
bag.exclusiveMinimum = def.value;
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
inst._zod.check = (payload) => {
|
|
1873
|
+
if (def.inclusive ? payload.value >= def.value : payload.value > def.value) {
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
payload.issues.push({
|
|
1877
|
+
origin,
|
|
1878
|
+
code: "too_small",
|
|
1879
|
+
minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
1880
|
+
input: payload.value,
|
|
1881
|
+
inclusive: def.inclusive,
|
|
1882
|
+
inst,
|
|
1883
|
+
continue: !def.abort
|
|
1884
|
+
});
|
|
1885
|
+
};
|
|
1886
|
+
});
|
|
1887
|
+
const $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
|
|
1888
|
+
$ZodCheck.init(inst, def);
|
|
1889
|
+
inst._zod.onattach.push((inst2) => {
|
|
1890
|
+
var _a2;
|
|
1891
|
+
(_a2 = inst2._zod.bag).multipleOf ?? (_a2.multipleOf = def.value);
|
|
1892
|
+
});
|
|
1893
|
+
inst._zod.check = (payload) => {
|
|
1894
|
+
if (typeof payload.value !== typeof def.value)
|
|
1895
|
+
throw new Error("Cannot mix number and bigint in multiple_of check.");
|
|
1896
|
+
const isMultiple = typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0;
|
|
1897
|
+
if (isMultiple)
|
|
1898
|
+
return;
|
|
1899
|
+
payload.issues.push({
|
|
1900
|
+
origin: typeof payload.value,
|
|
1901
|
+
code: "not_multiple_of",
|
|
1902
|
+
divisor: def.value,
|
|
1903
|
+
input: payload.value,
|
|
1904
|
+
inst,
|
|
1905
|
+
continue: !def.abort
|
|
1906
|
+
});
|
|
1907
|
+
};
|
|
1908
|
+
});
|
|
1909
|
+
const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat", (inst, def) => {
|
|
1910
|
+
var _a2;
|
|
1911
|
+
$ZodCheck.init(inst, def);
|
|
1912
|
+
def.format = def.format || "float64";
|
|
1913
|
+
const isInt = (_a2 = def.format) == null ? void 0 : _a2.includes("int");
|
|
1914
|
+
const origin = isInt ? "int" : "number";
|
|
1915
|
+
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
|
|
1916
|
+
inst._zod.onattach.push((inst2) => {
|
|
1917
|
+
const bag = inst2._zod.bag;
|
|
1918
|
+
bag.format = def.format;
|
|
1919
|
+
bag.minimum = minimum;
|
|
1920
|
+
bag.maximum = maximum;
|
|
1921
|
+
if (isInt)
|
|
1922
|
+
bag.pattern = integer;
|
|
1923
|
+
});
|
|
1924
|
+
inst._zod.check = (payload) => {
|
|
1925
|
+
const input = payload.value;
|
|
1926
|
+
if (isInt) {
|
|
1927
|
+
if (!Number.isInteger(input)) {
|
|
1928
|
+
payload.issues.push({
|
|
1929
|
+
expected: origin,
|
|
1930
|
+
format: def.format,
|
|
1931
|
+
code: "invalid_type",
|
|
1932
|
+
continue: false,
|
|
1933
|
+
input,
|
|
1934
|
+
inst
|
|
1935
|
+
});
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
if (!Number.isSafeInteger(input)) {
|
|
1939
|
+
if (input > 0) {
|
|
1940
|
+
payload.issues.push({
|
|
1941
|
+
input,
|
|
1942
|
+
code: "too_big",
|
|
1943
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
1944
|
+
note: "Integers must be within the safe integer range.",
|
|
1945
|
+
inst,
|
|
1946
|
+
origin,
|
|
1947
|
+
inclusive: true,
|
|
1948
|
+
continue: !def.abort
|
|
1949
|
+
});
|
|
1950
|
+
} else {
|
|
1951
|
+
payload.issues.push({
|
|
1952
|
+
input,
|
|
1953
|
+
code: "too_small",
|
|
1954
|
+
minimum: Number.MIN_SAFE_INTEGER,
|
|
1955
|
+
note: "Integers must be within the safe integer range.",
|
|
1956
|
+
inst,
|
|
1957
|
+
origin,
|
|
1958
|
+
inclusive: true,
|
|
1959
|
+
continue: !def.abort
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
if (input < minimum) {
|
|
1966
|
+
payload.issues.push({
|
|
1967
|
+
origin: "number",
|
|
1968
|
+
input,
|
|
1969
|
+
code: "too_small",
|
|
1970
|
+
minimum,
|
|
1971
|
+
inclusive: true,
|
|
1972
|
+
inst,
|
|
1973
|
+
continue: !def.abort
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
if (input > maximum) {
|
|
1977
|
+
payload.issues.push({
|
|
1978
|
+
origin: "number",
|
|
1979
|
+
input,
|
|
1980
|
+
code: "too_big",
|
|
1981
|
+
maximum,
|
|
1982
|
+
inclusive: true,
|
|
1983
|
+
inst,
|
|
1984
|
+
continue: !def.abort
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
});
|
|
1989
|
+
const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
1990
|
+
var _a2;
|
|
1991
|
+
$ZodCheck.init(inst, def);
|
|
1992
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
1993
|
+
const val = payload.value;
|
|
1994
|
+
return !nullish(val) && val.length !== void 0;
|
|
1995
|
+
});
|
|
1996
|
+
inst._zod.onattach.push((inst2) => {
|
|
1997
|
+
const curr = inst2._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
|
|
1998
|
+
if (def.maximum < curr)
|
|
1999
|
+
inst2._zod.bag.maximum = def.maximum;
|
|
2000
|
+
});
|
|
2001
|
+
inst._zod.check = (payload) => {
|
|
2002
|
+
const input = payload.value;
|
|
2003
|
+
const length = input.length;
|
|
2004
|
+
if (length <= def.maximum)
|
|
2005
|
+
return;
|
|
2006
|
+
const origin = getLengthableOrigin(input);
|
|
2007
|
+
payload.issues.push({
|
|
2008
|
+
origin,
|
|
2009
|
+
code: "too_big",
|
|
2010
|
+
maximum: def.maximum,
|
|
2011
|
+
inclusive: true,
|
|
2012
|
+
input,
|
|
2013
|
+
inst,
|
|
2014
|
+
continue: !def.abort
|
|
2015
|
+
});
|
|
2016
|
+
};
|
|
2017
|
+
});
|
|
2018
|
+
const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
|
|
2019
|
+
var _a2;
|
|
2020
|
+
$ZodCheck.init(inst, def);
|
|
2021
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
2022
|
+
const val = payload.value;
|
|
2023
|
+
return !nullish(val) && val.length !== void 0;
|
|
2024
|
+
});
|
|
2025
|
+
inst._zod.onattach.push((inst2) => {
|
|
2026
|
+
const curr = inst2._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
|
|
2027
|
+
if (def.minimum > curr)
|
|
2028
|
+
inst2._zod.bag.minimum = def.minimum;
|
|
2029
|
+
});
|
|
2030
|
+
inst._zod.check = (payload) => {
|
|
2031
|
+
const input = payload.value;
|
|
2032
|
+
const length = input.length;
|
|
2033
|
+
if (length >= def.minimum)
|
|
2034
|
+
return;
|
|
2035
|
+
const origin = getLengthableOrigin(input);
|
|
2036
|
+
payload.issues.push({
|
|
2037
|
+
origin,
|
|
2038
|
+
code: "too_small",
|
|
2039
|
+
minimum: def.minimum,
|
|
2040
|
+
inclusive: true,
|
|
2041
|
+
input,
|
|
2042
|
+
inst,
|
|
2043
|
+
continue: !def.abort
|
|
2044
|
+
});
|
|
2045
|
+
};
|
|
2046
|
+
});
|
|
2047
|
+
const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
2048
|
+
var _a2;
|
|
2049
|
+
$ZodCheck.init(inst, def);
|
|
2050
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
2051
|
+
const val = payload.value;
|
|
2052
|
+
return !nullish(val) && val.length !== void 0;
|
|
2053
|
+
});
|
|
2054
|
+
inst._zod.onattach.push((inst2) => {
|
|
2055
|
+
const bag = inst2._zod.bag;
|
|
2056
|
+
bag.minimum = def.length;
|
|
2057
|
+
bag.maximum = def.length;
|
|
2058
|
+
bag.length = def.length;
|
|
2059
|
+
});
|
|
2060
|
+
inst._zod.check = (payload) => {
|
|
2061
|
+
const input = payload.value;
|
|
2062
|
+
const length = input.length;
|
|
2063
|
+
if (length === def.length)
|
|
2064
|
+
return;
|
|
2065
|
+
const origin = getLengthableOrigin(input);
|
|
2066
|
+
const tooBig = length > def.length;
|
|
2067
|
+
payload.issues.push({
|
|
2068
|
+
origin,
|
|
2069
|
+
...tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length },
|
|
2070
|
+
inclusive: true,
|
|
2071
|
+
exact: true,
|
|
2072
|
+
input: payload.value,
|
|
2073
|
+
inst,
|
|
2074
|
+
continue: !def.abort
|
|
2075
|
+
});
|
|
2076
|
+
};
|
|
2077
|
+
});
|
|
2078
|
+
const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
|
|
2079
|
+
var _a2, _b;
|
|
2080
|
+
$ZodCheck.init(inst, def);
|
|
2081
|
+
inst._zod.onattach.push((inst2) => {
|
|
2082
|
+
const bag = inst2._zod.bag;
|
|
2083
|
+
bag.format = def.format;
|
|
2084
|
+
if (def.pattern) {
|
|
2085
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
2086
|
+
bag.patterns.add(def.pattern);
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
if (def.pattern)
|
|
2090
|
+
(_a2 = inst._zod).check ?? (_a2.check = (payload) => {
|
|
2091
|
+
def.pattern.lastIndex = 0;
|
|
2092
|
+
if (def.pattern.test(payload.value))
|
|
2093
|
+
return;
|
|
2094
|
+
payload.issues.push({
|
|
2095
|
+
origin: "string",
|
|
2096
|
+
code: "invalid_format",
|
|
2097
|
+
format: def.format,
|
|
2098
|
+
input: payload.value,
|
|
2099
|
+
...def.pattern ? { pattern: def.pattern.toString() } : {},
|
|
2100
|
+
inst,
|
|
2101
|
+
continue: !def.abort
|
|
2102
|
+
});
|
|
2103
|
+
});
|
|
2104
|
+
else
|
|
2105
|
+
(_b = inst._zod).check ?? (_b.check = () => {
|
|
2106
|
+
});
|
|
2107
|
+
});
|
|
2108
|
+
const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
|
|
2109
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
2110
|
+
inst._zod.check = (payload) => {
|
|
2111
|
+
def.pattern.lastIndex = 0;
|
|
2112
|
+
if (def.pattern.test(payload.value))
|
|
2113
|
+
return;
|
|
2114
|
+
payload.issues.push({
|
|
2115
|
+
origin: "string",
|
|
2116
|
+
code: "invalid_format",
|
|
2117
|
+
format: "regex",
|
|
2118
|
+
input: payload.value,
|
|
2119
|
+
pattern: def.pattern.toString(),
|
|
2120
|
+
inst,
|
|
2121
|
+
continue: !def.abort
|
|
2122
|
+
});
|
|
2123
|
+
};
|
|
2124
|
+
});
|
|
2125
|
+
const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
|
|
2126
|
+
def.pattern ?? (def.pattern = lowercase);
|
|
2127
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
2128
|
+
});
|
|
2129
|
+
const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
|
|
2130
|
+
def.pattern ?? (def.pattern = uppercase);
|
|
2131
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
2132
|
+
});
|
|
2133
|
+
const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
|
|
2134
|
+
$ZodCheck.init(inst, def);
|
|
2135
|
+
const escapedRegex = escapeRegex(def.includes);
|
|
2136
|
+
const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
2137
|
+
def.pattern = pattern;
|
|
2138
|
+
inst._zod.onattach.push((inst2) => {
|
|
2139
|
+
const bag = inst2._zod.bag;
|
|
2140
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
2141
|
+
bag.patterns.add(pattern);
|
|
2142
|
+
});
|
|
2143
|
+
inst._zod.check = (payload) => {
|
|
2144
|
+
if (payload.value.includes(def.includes, def.position))
|
|
2145
|
+
return;
|
|
2146
|
+
payload.issues.push({
|
|
2147
|
+
origin: "string",
|
|
2148
|
+
code: "invalid_format",
|
|
2149
|
+
format: "includes",
|
|
2150
|
+
includes: def.includes,
|
|
2151
|
+
input: payload.value,
|
|
2152
|
+
inst,
|
|
2153
|
+
continue: !def.abort
|
|
2154
|
+
});
|
|
2155
|
+
};
|
|
2156
|
+
});
|
|
2157
|
+
const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
|
|
2158
|
+
$ZodCheck.init(inst, def);
|
|
2159
|
+
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
|
|
2160
|
+
def.pattern ?? (def.pattern = pattern);
|
|
2161
|
+
inst._zod.onattach.push((inst2) => {
|
|
2162
|
+
const bag = inst2._zod.bag;
|
|
2163
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
2164
|
+
bag.patterns.add(pattern);
|
|
2165
|
+
});
|
|
2166
|
+
inst._zod.check = (payload) => {
|
|
2167
|
+
if (payload.value.startsWith(def.prefix))
|
|
2168
|
+
return;
|
|
2169
|
+
payload.issues.push({
|
|
2170
|
+
origin: "string",
|
|
2171
|
+
code: "invalid_format",
|
|
2172
|
+
format: "starts_with",
|
|
2173
|
+
prefix: def.prefix,
|
|
2174
|
+
input: payload.value,
|
|
2175
|
+
inst,
|
|
2176
|
+
continue: !def.abort
|
|
2177
|
+
});
|
|
2178
|
+
};
|
|
2179
|
+
});
|
|
2180
|
+
const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
|
|
2181
|
+
$ZodCheck.init(inst, def);
|
|
2182
|
+
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
2183
|
+
def.pattern ?? (def.pattern = pattern);
|
|
2184
|
+
inst._zod.onattach.push((inst2) => {
|
|
2185
|
+
const bag = inst2._zod.bag;
|
|
2186
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
2187
|
+
bag.patterns.add(pattern);
|
|
2188
|
+
});
|
|
2189
|
+
inst._zod.check = (payload) => {
|
|
2190
|
+
if (payload.value.endsWith(def.suffix))
|
|
2191
|
+
return;
|
|
2192
|
+
payload.issues.push({
|
|
2193
|
+
origin: "string",
|
|
2194
|
+
code: "invalid_format",
|
|
2195
|
+
format: "ends_with",
|
|
2196
|
+
suffix: def.suffix,
|
|
2197
|
+
input: payload.value,
|
|
2198
|
+
inst,
|
|
2199
|
+
continue: !def.abort
|
|
2200
|
+
});
|
|
2201
|
+
};
|
|
2202
|
+
});
|
|
2203
|
+
const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
|
|
2204
|
+
$ZodCheck.init(inst, def);
|
|
2205
|
+
inst._zod.check = (payload) => {
|
|
2206
|
+
payload.value = def.tx(payload.value);
|
|
2207
|
+
};
|
|
2208
|
+
});
|
|
2209
|
+
class Doc {
|
|
2210
|
+
constructor(args = []) {
|
|
2211
|
+
this.content = [];
|
|
2212
|
+
this.indent = 0;
|
|
2213
|
+
if (this)
|
|
2214
|
+
this.args = args;
|
|
2215
|
+
}
|
|
2216
|
+
indented(fn) {
|
|
2217
|
+
this.indent += 1;
|
|
2218
|
+
fn(this);
|
|
2219
|
+
this.indent -= 1;
|
|
2220
|
+
}
|
|
2221
|
+
write(arg) {
|
|
2222
|
+
if (typeof arg === "function") {
|
|
2223
|
+
arg(this, { execution: "sync" });
|
|
2224
|
+
arg(this, { execution: "async" });
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
const content = arg;
|
|
2228
|
+
const lines = content.split("\n").filter((x) => x);
|
|
2229
|
+
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
|
2230
|
+
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
2231
|
+
for (const line of dedented) {
|
|
2232
|
+
this.content.push(line);
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
compile() {
|
|
2236
|
+
const F = Function;
|
|
2237
|
+
const args = this == null ? void 0 : this.args;
|
|
2238
|
+
const content = (this == null ? void 0 : this.content) ?? [``];
|
|
2239
|
+
const lines = [...content.map((x) => ` ${x}`)];
|
|
2240
|
+
return new F(...args, lines.join("\n"));
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
const version = {
|
|
2244
|
+
major: 4,
|
|
2245
|
+
minor: 3,
|
|
2246
|
+
patch: 6
|
|
2247
|
+
};
|
|
2248
|
+
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
2249
|
+
var _a3;
|
|
2250
|
+
var _a2;
|
|
2251
|
+
inst ?? (inst = {});
|
|
2252
|
+
inst._zod.def = def;
|
|
2253
|
+
inst._zod.bag = inst._zod.bag || {};
|
|
2254
|
+
inst._zod.version = version;
|
|
2255
|
+
const checks = [...inst._zod.def.checks ?? []];
|
|
2256
|
+
if (inst._zod.traits.has("$ZodCheck")) {
|
|
2257
|
+
checks.unshift(inst);
|
|
2258
|
+
}
|
|
2259
|
+
for (const ch of checks) {
|
|
2260
|
+
for (const fn of ch._zod.onattach) {
|
|
2261
|
+
fn(inst);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
if (checks.length === 0) {
|
|
2265
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
2266
|
+
(_a3 = inst._zod.deferred) == null ? void 0 : _a3.push(() => {
|
|
2267
|
+
inst._zod.run = inst._zod.parse;
|
|
2268
|
+
});
|
|
2269
|
+
} else {
|
|
2270
|
+
const runChecks = (payload, checks2, ctx) => {
|
|
2271
|
+
let isAborted = aborted(payload);
|
|
2272
|
+
let asyncResult;
|
|
2273
|
+
for (const ch of checks2) {
|
|
2274
|
+
if (ch._zod.def.when) {
|
|
2275
|
+
const shouldRun = ch._zod.def.when(payload);
|
|
2276
|
+
if (!shouldRun)
|
|
2277
|
+
continue;
|
|
2278
|
+
} else if (isAborted) {
|
|
2279
|
+
continue;
|
|
2280
|
+
}
|
|
2281
|
+
const currLen = payload.issues.length;
|
|
2282
|
+
const _ = ch._zod.check(payload);
|
|
2283
|
+
if (_ instanceof Promise && (ctx == null ? void 0 : ctx.async) === false) {
|
|
2284
|
+
throw new $ZodAsyncError();
|
|
2285
|
+
}
|
|
2286
|
+
if (asyncResult || _ instanceof Promise) {
|
|
2287
|
+
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
2288
|
+
await _;
|
|
2289
|
+
const nextLen = payload.issues.length;
|
|
2290
|
+
if (nextLen === currLen)
|
|
2291
|
+
return;
|
|
2292
|
+
if (!isAborted)
|
|
2293
|
+
isAborted = aborted(payload, currLen);
|
|
2294
|
+
});
|
|
2295
|
+
} else {
|
|
2296
|
+
const nextLen = payload.issues.length;
|
|
2297
|
+
if (nextLen === currLen)
|
|
2298
|
+
continue;
|
|
2299
|
+
if (!isAborted)
|
|
2300
|
+
isAborted = aborted(payload, currLen);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
if (asyncResult) {
|
|
2304
|
+
return asyncResult.then(() => {
|
|
2305
|
+
return payload;
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
return payload;
|
|
2309
|
+
};
|
|
2310
|
+
const handleCanaryResult = (canary, payload, ctx) => {
|
|
2311
|
+
if (aborted(canary)) {
|
|
2312
|
+
canary.aborted = true;
|
|
2313
|
+
return canary;
|
|
2314
|
+
}
|
|
2315
|
+
const checkResult = runChecks(payload, checks, ctx);
|
|
2316
|
+
if (checkResult instanceof Promise) {
|
|
2317
|
+
if (ctx.async === false)
|
|
2318
|
+
throw new $ZodAsyncError();
|
|
2319
|
+
return checkResult.then((checkResult2) => inst._zod.parse(checkResult2, ctx));
|
|
2320
|
+
}
|
|
2321
|
+
return inst._zod.parse(checkResult, ctx);
|
|
2322
|
+
};
|
|
2323
|
+
inst._zod.run = (payload, ctx) => {
|
|
2324
|
+
if (ctx.skipChecks) {
|
|
2325
|
+
return inst._zod.parse(payload, ctx);
|
|
2326
|
+
}
|
|
2327
|
+
if (ctx.direction === "backward") {
|
|
2328
|
+
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
|
2329
|
+
if (canary instanceof Promise) {
|
|
2330
|
+
return canary.then((canary2) => {
|
|
2331
|
+
return handleCanaryResult(canary2, payload, ctx);
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
2335
|
+
}
|
|
2336
|
+
const result = inst._zod.parse(payload, ctx);
|
|
2337
|
+
if (result instanceof Promise) {
|
|
2338
|
+
if (ctx.async === false)
|
|
2339
|
+
throw new $ZodAsyncError();
|
|
2340
|
+
return result.then((result2) => runChecks(result2, checks, ctx));
|
|
2341
|
+
}
|
|
2342
|
+
return runChecks(result, checks, ctx);
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
defineLazy(inst, "~standard", () => ({
|
|
2346
|
+
validate: (value) => {
|
|
2347
|
+
var _a4;
|
|
2348
|
+
try {
|
|
2349
|
+
const r = safeParse$1(inst, value);
|
|
2350
|
+
return r.success ? { value: r.data } : { issues: (_a4 = r.error) == null ? void 0 : _a4.issues };
|
|
2351
|
+
} catch (_) {
|
|
2352
|
+
return safeParseAsync$1(inst, value).then((r) => {
|
|
2353
|
+
var _a5;
|
|
2354
|
+
return r.success ? { value: r.data } : { issues: (_a5 = r.error) == null ? void 0 : _a5.issues };
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
},
|
|
2358
|
+
vendor: "zod",
|
|
2359
|
+
version: 1
|
|
2360
|
+
}));
|
|
2361
|
+
});
|
|
2362
|
+
const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
2363
|
+
var _a2;
|
|
2364
|
+
$ZodType.init(inst, def);
|
|
2365
|
+
inst._zod.pattern = [...((_a2 = inst == null ? void 0 : inst._zod.bag) == null ? void 0 : _a2.patterns) ?? []].pop() ?? string$1(inst._zod.bag);
|
|
2366
|
+
inst._zod.parse = (payload, _) => {
|
|
2367
|
+
if (def.coerce)
|
|
2368
|
+
try {
|
|
2369
|
+
payload.value = String(payload.value);
|
|
2370
|
+
} catch (_2) {
|
|
2371
|
+
}
|
|
2372
|
+
if (typeof payload.value === "string")
|
|
2373
|
+
return payload;
|
|
2374
|
+
payload.issues.push({
|
|
2375
|
+
expected: "string",
|
|
2376
|
+
code: "invalid_type",
|
|
2377
|
+
input: payload.value,
|
|
2378
|
+
inst
|
|
2379
|
+
});
|
|
2380
|
+
return payload;
|
|
2381
|
+
};
|
|
2382
|
+
});
|
|
2383
|
+
const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
|
|
2384
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
2385
|
+
$ZodString.init(inst, def);
|
|
2386
|
+
});
|
|
2387
|
+
const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
|
|
2388
|
+
def.pattern ?? (def.pattern = guid);
|
|
2389
|
+
$ZodStringFormat.init(inst, def);
|
|
2390
|
+
});
|
|
2391
|
+
const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
|
|
2392
|
+
if (def.version) {
|
|
2393
|
+
const versionMap = {
|
|
2394
|
+
v1: 1,
|
|
2395
|
+
v2: 2,
|
|
2396
|
+
v3: 3,
|
|
2397
|
+
v4: 4,
|
|
2398
|
+
v5: 5,
|
|
2399
|
+
v6: 6,
|
|
2400
|
+
v7: 7,
|
|
2401
|
+
v8: 8
|
|
2402
|
+
};
|
|
2403
|
+
const v = versionMap[def.version];
|
|
2404
|
+
if (v === void 0)
|
|
2405
|
+
throw new Error(`Invalid UUID version: "${def.version}"`);
|
|
2406
|
+
def.pattern ?? (def.pattern = uuid(v));
|
|
2407
|
+
} else
|
|
2408
|
+
def.pattern ?? (def.pattern = uuid());
|
|
2409
|
+
$ZodStringFormat.init(inst, def);
|
|
2410
|
+
});
|
|
2411
|
+
const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
2412
|
+
def.pattern ?? (def.pattern = email);
|
|
2413
|
+
$ZodStringFormat.init(inst, def);
|
|
2414
|
+
});
|
|
2415
|
+
const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
2416
|
+
$ZodStringFormat.init(inst, def);
|
|
2417
|
+
inst._zod.check = (payload) => {
|
|
2418
|
+
try {
|
|
2419
|
+
const trimmed = payload.value.trim();
|
|
2420
|
+
const url = new URL(trimmed);
|
|
2421
|
+
if (def.hostname) {
|
|
2422
|
+
def.hostname.lastIndex = 0;
|
|
2423
|
+
if (!def.hostname.test(url.hostname)) {
|
|
2424
|
+
payload.issues.push({
|
|
2425
|
+
code: "invalid_format",
|
|
2426
|
+
format: "url",
|
|
2427
|
+
note: "Invalid hostname",
|
|
2428
|
+
pattern: def.hostname.source,
|
|
2429
|
+
input: payload.value,
|
|
2430
|
+
inst,
|
|
2431
|
+
continue: !def.abort
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
if (def.protocol) {
|
|
2436
|
+
def.protocol.lastIndex = 0;
|
|
2437
|
+
if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
|
|
2438
|
+
payload.issues.push({
|
|
2439
|
+
code: "invalid_format",
|
|
2440
|
+
format: "url",
|
|
2441
|
+
note: "Invalid protocol",
|
|
2442
|
+
pattern: def.protocol.source,
|
|
2443
|
+
input: payload.value,
|
|
2444
|
+
inst,
|
|
2445
|
+
continue: !def.abort
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
if (def.normalize) {
|
|
2450
|
+
payload.value = url.href;
|
|
2451
|
+
} else {
|
|
2452
|
+
payload.value = trimmed;
|
|
2453
|
+
}
|
|
2454
|
+
return;
|
|
2455
|
+
} catch (_) {
|
|
2456
|
+
payload.issues.push({
|
|
2457
|
+
code: "invalid_format",
|
|
2458
|
+
format: "url",
|
|
2459
|
+
input: payload.value,
|
|
2460
|
+
inst,
|
|
2461
|
+
continue: !def.abort
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
});
|
|
2466
|
+
const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
|
|
2467
|
+
def.pattern ?? (def.pattern = emoji());
|
|
2468
|
+
$ZodStringFormat.init(inst, def);
|
|
2469
|
+
});
|
|
2470
|
+
const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
|
|
2471
|
+
def.pattern ?? (def.pattern = nanoid);
|
|
2472
|
+
$ZodStringFormat.init(inst, def);
|
|
2473
|
+
});
|
|
2474
|
+
const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
|
|
2475
|
+
def.pattern ?? (def.pattern = cuid);
|
|
2476
|
+
$ZodStringFormat.init(inst, def);
|
|
2477
|
+
});
|
|
2478
|
+
const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
|
|
2479
|
+
def.pattern ?? (def.pattern = cuid2);
|
|
2480
|
+
$ZodStringFormat.init(inst, def);
|
|
2481
|
+
});
|
|
2482
|
+
const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
|
|
2483
|
+
def.pattern ?? (def.pattern = ulid);
|
|
2484
|
+
$ZodStringFormat.init(inst, def);
|
|
2485
|
+
});
|
|
2486
|
+
const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
|
|
2487
|
+
def.pattern ?? (def.pattern = xid);
|
|
2488
|
+
$ZodStringFormat.init(inst, def);
|
|
2489
|
+
});
|
|
2490
|
+
const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
|
|
2491
|
+
def.pattern ?? (def.pattern = ksuid);
|
|
2492
|
+
$ZodStringFormat.init(inst, def);
|
|
2493
|
+
});
|
|
2494
|
+
const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
|
|
2495
|
+
def.pattern ?? (def.pattern = datetime$1(def));
|
|
2496
|
+
$ZodStringFormat.init(inst, def);
|
|
2497
|
+
});
|
|
2498
|
+
const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
|
|
2499
|
+
def.pattern ?? (def.pattern = date$1);
|
|
2500
|
+
$ZodStringFormat.init(inst, def);
|
|
2501
|
+
});
|
|
2502
|
+
const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
|
|
2503
|
+
def.pattern ?? (def.pattern = time$1(def));
|
|
2504
|
+
$ZodStringFormat.init(inst, def);
|
|
2505
|
+
});
|
|
2506
|
+
const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
|
|
2507
|
+
def.pattern ?? (def.pattern = duration$1);
|
|
2508
|
+
$ZodStringFormat.init(inst, def);
|
|
2509
|
+
});
|
|
2510
|
+
const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
|
|
2511
|
+
def.pattern ?? (def.pattern = ipv4);
|
|
2512
|
+
$ZodStringFormat.init(inst, def);
|
|
2513
|
+
inst._zod.bag.format = `ipv4`;
|
|
2514
|
+
});
|
|
2515
|
+
const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
|
|
2516
|
+
def.pattern ?? (def.pattern = ipv6);
|
|
2517
|
+
$ZodStringFormat.init(inst, def);
|
|
2518
|
+
inst._zod.bag.format = `ipv6`;
|
|
2519
|
+
inst._zod.check = (payload) => {
|
|
2520
|
+
try {
|
|
2521
|
+
new URL(`http://[${payload.value}]`);
|
|
2522
|
+
} catch {
|
|
2523
|
+
payload.issues.push({
|
|
2524
|
+
code: "invalid_format",
|
|
2525
|
+
format: "ipv6",
|
|
2526
|
+
input: payload.value,
|
|
2527
|
+
inst,
|
|
2528
|
+
continue: !def.abort
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
};
|
|
2532
|
+
});
|
|
2533
|
+
const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
|
|
2534
|
+
def.pattern ?? (def.pattern = cidrv4);
|
|
2535
|
+
$ZodStringFormat.init(inst, def);
|
|
2536
|
+
});
|
|
2537
|
+
const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
|
|
2538
|
+
def.pattern ?? (def.pattern = cidrv6);
|
|
2539
|
+
$ZodStringFormat.init(inst, def);
|
|
2540
|
+
inst._zod.check = (payload) => {
|
|
2541
|
+
const parts = payload.value.split("/");
|
|
2542
|
+
try {
|
|
2543
|
+
if (parts.length !== 2)
|
|
2544
|
+
throw new Error();
|
|
2545
|
+
const [address, prefix] = parts;
|
|
2546
|
+
if (!prefix)
|
|
2547
|
+
throw new Error();
|
|
2548
|
+
const prefixNum = Number(prefix);
|
|
2549
|
+
if (`${prefixNum}` !== prefix)
|
|
2550
|
+
throw new Error();
|
|
2551
|
+
if (prefixNum < 0 || prefixNum > 128)
|
|
2552
|
+
throw new Error();
|
|
2553
|
+
new URL(`http://[${address}]`);
|
|
2554
|
+
} catch {
|
|
2555
|
+
payload.issues.push({
|
|
2556
|
+
code: "invalid_format",
|
|
2557
|
+
format: "cidrv6",
|
|
2558
|
+
input: payload.value,
|
|
2559
|
+
inst,
|
|
2560
|
+
continue: !def.abort
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
});
|
|
2565
|
+
function isValidBase64(data) {
|
|
2566
|
+
if (data === "")
|
|
2567
|
+
return true;
|
|
2568
|
+
if (data.length % 4 !== 0)
|
|
2569
|
+
return false;
|
|
2570
|
+
try {
|
|
2571
|
+
atob(data);
|
|
2572
|
+
return true;
|
|
2573
|
+
} catch {
|
|
2574
|
+
return false;
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
|
|
2578
|
+
def.pattern ?? (def.pattern = base64);
|
|
2579
|
+
$ZodStringFormat.init(inst, def);
|
|
2580
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
2581
|
+
inst._zod.check = (payload) => {
|
|
2582
|
+
if (isValidBase64(payload.value))
|
|
2583
|
+
return;
|
|
2584
|
+
payload.issues.push({
|
|
2585
|
+
code: "invalid_format",
|
|
2586
|
+
format: "base64",
|
|
2587
|
+
input: payload.value,
|
|
2588
|
+
inst,
|
|
2589
|
+
continue: !def.abort
|
|
2590
|
+
});
|
|
2591
|
+
};
|
|
2592
|
+
});
|
|
2593
|
+
function isValidBase64URL(data) {
|
|
2594
|
+
if (!base64url.test(data))
|
|
2595
|
+
return false;
|
|
2596
|
+
const base642 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
|
|
2597
|
+
const padded = base642.padEnd(Math.ceil(base642.length / 4) * 4, "=");
|
|
2598
|
+
return isValidBase64(padded);
|
|
2599
|
+
}
|
|
2600
|
+
const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
|
|
2601
|
+
def.pattern ?? (def.pattern = base64url);
|
|
2602
|
+
$ZodStringFormat.init(inst, def);
|
|
2603
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
2604
|
+
inst._zod.check = (payload) => {
|
|
2605
|
+
if (isValidBase64URL(payload.value))
|
|
2606
|
+
return;
|
|
2607
|
+
payload.issues.push({
|
|
2608
|
+
code: "invalid_format",
|
|
2609
|
+
format: "base64url",
|
|
2610
|
+
input: payload.value,
|
|
2611
|
+
inst,
|
|
2612
|
+
continue: !def.abort
|
|
2613
|
+
});
|
|
2614
|
+
};
|
|
2615
|
+
});
|
|
2616
|
+
const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
|
|
2617
|
+
def.pattern ?? (def.pattern = e164);
|
|
2618
|
+
$ZodStringFormat.init(inst, def);
|
|
2619
|
+
});
|
|
2620
|
+
function isValidJWT(token, algorithm = null) {
|
|
2621
|
+
try {
|
|
2622
|
+
const tokensParts = token.split(".");
|
|
2623
|
+
if (tokensParts.length !== 3)
|
|
2624
|
+
return false;
|
|
2625
|
+
const [header] = tokensParts;
|
|
2626
|
+
if (!header)
|
|
2627
|
+
return false;
|
|
2628
|
+
const parsedHeader = JSON.parse(atob(header));
|
|
2629
|
+
if ("typ" in parsedHeader && (parsedHeader == null ? void 0 : parsedHeader.typ) !== "JWT")
|
|
2630
|
+
return false;
|
|
2631
|
+
if (!parsedHeader.alg)
|
|
2632
|
+
return false;
|
|
2633
|
+
if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
|
|
2634
|
+
return false;
|
|
2635
|
+
return true;
|
|
2636
|
+
} catch {
|
|
2637
|
+
return false;
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
2641
|
+
$ZodStringFormat.init(inst, def);
|
|
2642
|
+
inst._zod.check = (payload) => {
|
|
2643
|
+
if (isValidJWT(payload.value, def.alg))
|
|
2644
|
+
return;
|
|
2645
|
+
payload.issues.push({
|
|
2646
|
+
code: "invalid_format",
|
|
2647
|
+
format: "jwt",
|
|
2648
|
+
input: payload.value,
|
|
2649
|
+
inst,
|
|
2650
|
+
continue: !def.abort
|
|
2651
|
+
});
|
|
2652
|
+
};
|
|
2653
|
+
});
|
|
2654
|
+
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
2655
|
+
$ZodType.init(inst, def);
|
|
2656
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
|
|
2657
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2658
|
+
if (def.coerce)
|
|
2659
|
+
try {
|
|
2660
|
+
payload.value = Number(payload.value);
|
|
2661
|
+
} catch (_) {
|
|
2662
|
+
}
|
|
2663
|
+
const input = payload.value;
|
|
2664
|
+
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
|
|
2665
|
+
return payload;
|
|
2666
|
+
}
|
|
2667
|
+
const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
|
|
2668
|
+
payload.issues.push({
|
|
2669
|
+
expected: "number",
|
|
2670
|
+
code: "invalid_type",
|
|
2671
|
+
input,
|
|
2672
|
+
inst,
|
|
2673
|
+
...received ? { received } : {}
|
|
2674
|
+
});
|
|
2675
|
+
return payload;
|
|
2676
|
+
};
|
|
2677
|
+
});
|
|
2678
|
+
const $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumberFormat", (inst, def) => {
|
|
2679
|
+
$ZodCheckNumberFormat.init(inst, def);
|
|
2680
|
+
$ZodNumber.init(inst, def);
|
|
2681
|
+
});
|
|
2682
|
+
const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
2683
|
+
$ZodType.init(inst, def);
|
|
2684
|
+
inst._zod.pattern = boolean$1;
|
|
2685
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2686
|
+
if (def.coerce)
|
|
2687
|
+
try {
|
|
2688
|
+
payload.value = Boolean(payload.value);
|
|
2689
|
+
} catch (_) {
|
|
2690
|
+
}
|
|
2691
|
+
const input = payload.value;
|
|
2692
|
+
if (typeof input === "boolean")
|
|
2693
|
+
return payload;
|
|
2694
|
+
payload.issues.push({
|
|
2695
|
+
expected: "boolean",
|
|
2696
|
+
code: "invalid_type",
|
|
2697
|
+
input,
|
|
2698
|
+
inst
|
|
2699
|
+
});
|
|
2700
|
+
return payload;
|
|
2701
|
+
};
|
|
2702
|
+
});
|
|
2703
|
+
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
2704
|
+
$ZodType.init(inst, def);
|
|
2705
|
+
inst._zod.parse = (payload) => payload;
|
|
2706
|
+
});
|
|
2707
|
+
const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
2708
|
+
$ZodType.init(inst, def);
|
|
2709
|
+
inst._zod.parse = (payload) => payload;
|
|
2710
|
+
});
|
|
2711
|
+
const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
|
|
2712
|
+
$ZodType.init(inst, def);
|
|
2713
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2714
|
+
payload.issues.push({
|
|
2715
|
+
expected: "never",
|
|
2716
|
+
code: "invalid_type",
|
|
2717
|
+
input: payload.value,
|
|
2718
|
+
inst
|
|
2719
|
+
});
|
|
2720
|
+
return payload;
|
|
2721
|
+
};
|
|
2722
|
+
});
|
|
2723
|
+
function handleArrayResult(result, final, index) {
|
|
2724
|
+
if (result.issues.length) {
|
|
2725
|
+
final.issues.push(...prefixIssues(index, result.issues));
|
|
2726
|
+
}
|
|
2727
|
+
final.value[index] = result.value;
|
|
2728
|
+
}
|
|
2729
|
+
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
2730
|
+
$ZodType.init(inst, def);
|
|
2731
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2732
|
+
const input = payload.value;
|
|
2733
|
+
if (!Array.isArray(input)) {
|
|
2734
|
+
payload.issues.push({
|
|
2735
|
+
expected: "array",
|
|
2736
|
+
code: "invalid_type",
|
|
2737
|
+
input,
|
|
2738
|
+
inst
|
|
2739
|
+
});
|
|
2740
|
+
return payload;
|
|
2741
|
+
}
|
|
2742
|
+
payload.value = Array(input.length);
|
|
2743
|
+
const proms = [];
|
|
2744
|
+
for (let i = 0; i < input.length; i++) {
|
|
2745
|
+
const item = input[i];
|
|
2746
|
+
const result = def.element._zod.run({
|
|
2747
|
+
value: item,
|
|
2748
|
+
issues: []
|
|
2749
|
+
}, ctx);
|
|
2750
|
+
if (result instanceof Promise) {
|
|
2751
|
+
proms.push(result.then((result2) => handleArrayResult(result2, payload, i)));
|
|
2752
|
+
} else {
|
|
2753
|
+
handleArrayResult(result, payload, i);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
if (proms.length) {
|
|
2757
|
+
return Promise.all(proms).then(() => payload);
|
|
2758
|
+
}
|
|
2759
|
+
return payload;
|
|
2760
|
+
};
|
|
2761
|
+
});
|
|
2762
|
+
function handlePropertyResult(result, final, key, input, isOptionalOut) {
|
|
2763
|
+
if (result.issues.length) {
|
|
2764
|
+
if (isOptionalOut && !(key in input)) {
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
final.issues.push(...prefixIssues(key, result.issues));
|
|
2768
|
+
}
|
|
2769
|
+
if (result.value === void 0) {
|
|
2770
|
+
if (key in input) {
|
|
2771
|
+
final.value[key] = void 0;
|
|
2772
|
+
}
|
|
2773
|
+
} else {
|
|
2774
|
+
final.value[key] = result.value;
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
function normalizeDef(def) {
|
|
2778
|
+
var _a2, _b, _c, _d;
|
|
2779
|
+
const keys = Object.keys(def.shape);
|
|
2780
|
+
for (const k of keys) {
|
|
2781
|
+
if (!((_d = (_c = (_b = (_a2 = def.shape) == null ? void 0 : _a2[k]) == null ? void 0 : _b._zod) == null ? void 0 : _c.traits) == null ? void 0 : _d.has("$ZodType"))) {
|
|
2782
|
+
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
const okeys = optionalKeys(def.shape);
|
|
2786
|
+
return {
|
|
2787
|
+
...def,
|
|
2788
|
+
keys,
|
|
2789
|
+
keySet: new Set(keys),
|
|
2790
|
+
numKeys: keys.length,
|
|
2791
|
+
optionalKeys: new Set(okeys)
|
|
2792
|
+
};
|
|
2793
|
+
}
|
|
2794
|
+
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
2795
|
+
const unrecognized = [];
|
|
2796
|
+
const keySet = def.keySet;
|
|
2797
|
+
const _catchall = def.catchall._zod;
|
|
2798
|
+
const t = _catchall.def.type;
|
|
2799
|
+
const isOptionalOut = _catchall.optout === "optional";
|
|
2800
|
+
for (const key in input) {
|
|
2801
|
+
if (keySet.has(key))
|
|
2802
|
+
continue;
|
|
2803
|
+
if (t === "never") {
|
|
2804
|
+
unrecognized.push(key);
|
|
2805
|
+
continue;
|
|
2806
|
+
}
|
|
2807
|
+
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
2808
|
+
if (r instanceof Promise) {
|
|
2809
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input, isOptionalOut)));
|
|
2810
|
+
} else {
|
|
2811
|
+
handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
if (unrecognized.length) {
|
|
2815
|
+
payload.issues.push({
|
|
2816
|
+
code: "unrecognized_keys",
|
|
2817
|
+
keys: unrecognized,
|
|
2818
|
+
input,
|
|
2819
|
+
inst
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
if (!proms.length)
|
|
2823
|
+
return payload;
|
|
2824
|
+
return Promise.all(proms).then(() => {
|
|
2825
|
+
return payload;
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2828
|
+
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
2829
|
+
$ZodType.init(inst, def);
|
|
2830
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
2831
|
+
if (!(desc == null ? void 0 : desc.get)) {
|
|
2832
|
+
const sh = def.shape;
|
|
2833
|
+
Object.defineProperty(def, "shape", {
|
|
2834
|
+
get: () => {
|
|
2835
|
+
const newSh = { ...sh };
|
|
2836
|
+
Object.defineProperty(def, "shape", {
|
|
2837
|
+
value: newSh
|
|
2838
|
+
});
|
|
2839
|
+
return newSh;
|
|
2840
|
+
}
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
const _normalized = cached(() => normalizeDef(def));
|
|
2844
|
+
defineLazy(inst._zod, "propValues", () => {
|
|
2845
|
+
const shape = def.shape;
|
|
2846
|
+
const propValues = {};
|
|
2847
|
+
for (const key in shape) {
|
|
2848
|
+
const field = shape[key]._zod;
|
|
2849
|
+
if (field.values) {
|
|
2850
|
+
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
2851
|
+
for (const v of field.values)
|
|
2852
|
+
propValues[key].add(v);
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
return propValues;
|
|
2856
|
+
});
|
|
2857
|
+
const isObject$1 = isObject;
|
|
2858
|
+
const catchall = def.catchall;
|
|
2859
|
+
let value;
|
|
2860
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2861
|
+
value ?? (value = _normalized.value);
|
|
2862
|
+
const input = payload.value;
|
|
2863
|
+
if (!isObject$1(input)) {
|
|
2864
|
+
payload.issues.push({
|
|
2865
|
+
expected: "object",
|
|
2866
|
+
code: "invalid_type",
|
|
2867
|
+
input,
|
|
2868
|
+
inst
|
|
2869
|
+
});
|
|
2870
|
+
return payload;
|
|
2871
|
+
}
|
|
2872
|
+
payload.value = {};
|
|
2873
|
+
const proms = [];
|
|
2874
|
+
const shape = value.shape;
|
|
2875
|
+
for (const key of value.keys) {
|
|
2876
|
+
const el = shape[key];
|
|
2877
|
+
const isOptionalOut = el._zod.optout === "optional";
|
|
2878
|
+
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2879
|
+
if (r instanceof Promise) {
|
|
2880
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input, isOptionalOut)));
|
|
2881
|
+
} else {
|
|
2882
|
+
handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
if (!catchall) {
|
|
2886
|
+
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
2887
|
+
}
|
|
2888
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
2889
|
+
};
|
|
2890
|
+
});
|
|
2891
|
+
const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
|
|
2892
|
+
$ZodObject.init(inst, def);
|
|
2893
|
+
const superParse = inst._zod.parse;
|
|
2894
|
+
const _normalized = cached(() => normalizeDef(def));
|
|
2895
|
+
const generateFastpass = (shape) => {
|
|
2896
|
+
var _a2;
|
|
2897
|
+
const doc = new Doc(["shape", "payload", "ctx"]);
|
|
2898
|
+
const normalized = _normalized.value;
|
|
2899
|
+
const parseStr = (key) => {
|
|
2900
|
+
const k = esc(key);
|
|
2901
|
+
return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
2902
|
+
};
|
|
2903
|
+
doc.write(`const input = payload.value;`);
|
|
2904
|
+
const ids = /* @__PURE__ */ Object.create(null);
|
|
2905
|
+
let counter = 0;
|
|
2906
|
+
for (const key of normalized.keys) {
|
|
2907
|
+
ids[key] = `key_${counter++}`;
|
|
2908
|
+
}
|
|
2909
|
+
doc.write(`const newResult = {};`);
|
|
2910
|
+
for (const key of normalized.keys) {
|
|
2911
|
+
const id = ids[key];
|
|
2912
|
+
const k = esc(key);
|
|
2913
|
+
const schema = shape[key];
|
|
2914
|
+
const isOptionalOut = ((_a2 = schema == null ? void 0 : schema._zod) == null ? void 0 : _a2.optout) === "optional";
|
|
2915
|
+
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
2916
|
+
if (isOptionalOut) {
|
|
2917
|
+
doc.write(`
|
|
2918
|
+
if (${id}.issues.length) {
|
|
2919
|
+
if (${k} in input) {
|
|
2920
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
2921
|
+
...iss,
|
|
2922
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
2923
|
+
})));
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
if (${id}.value === undefined) {
|
|
2928
|
+
if (${k} in input) {
|
|
2929
|
+
newResult[${k}] = undefined;
|
|
2930
|
+
}
|
|
2931
|
+
} else {
|
|
2932
|
+
newResult[${k}] = ${id}.value;
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
`);
|
|
2936
|
+
} else {
|
|
2937
|
+
doc.write(`
|
|
2938
|
+
if (${id}.issues.length) {
|
|
2939
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
2940
|
+
...iss,
|
|
2941
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
2942
|
+
})));
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
if (${id}.value === undefined) {
|
|
2946
|
+
if (${k} in input) {
|
|
2947
|
+
newResult[${k}] = undefined;
|
|
2948
|
+
}
|
|
2949
|
+
} else {
|
|
2950
|
+
newResult[${k}] = ${id}.value;
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
`);
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
doc.write(`payload.value = newResult;`);
|
|
2957
|
+
doc.write(`return payload;`);
|
|
2958
|
+
const fn = doc.compile();
|
|
2959
|
+
return (payload, ctx) => fn(shape, payload, ctx);
|
|
2960
|
+
};
|
|
2961
|
+
let fastpass;
|
|
2962
|
+
const isObject$1 = isObject;
|
|
2963
|
+
const jit = !globalConfig$1.jitless;
|
|
2964
|
+
const allowsEval$1 = allowsEval;
|
|
2965
|
+
const fastEnabled = jit && allowsEval$1.value;
|
|
2966
|
+
const catchall = def.catchall;
|
|
2967
|
+
let value;
|
|
2968
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2969
|
+
value ?? (value = _normalized.value);
|
|
2970
|
+
const input = payload.value;
|
|
2971
|
+
if (!isObject$1(input)) {
|
|
2972
|
+
payload.issues.push({
|
|
2973
|
+
expected: "object",
|
|
2974
|
+
code: "invalid_type",
|
|
2975
|
+
input,
|
|
2976
|
+
inst
|
|
2977
|
+
});
|
|
2978
|
+
return payload;
|
|
2979
|
+
}
|
|
2980
|
+
if (jit && fastEnabled && (ctx == null ? void 0 : ctx.async) === false && ctx.jitless !== true) {
|
|
2981
|
+
if (!fastpass)
|
|
2982
|
+
fastpass = generateFastpass(def.shape);
|
|
2983
|
+
payload = fastpass(payload, ctx);
|
|
2984
|
+
if (!catchall)
|
|
2985
|
+
return payload;
|
|
2986
|
+
return handleCatchall([], input, payload, ctx, value, inst);
|
|
2987
|
+
}
|
|
2988
|
+
return superParse(payload, ctx);
|
|
2989
|
+
};
|
|
2990
|
+
});
|
|
2991
|
+
function handleUnionResults(results, final, inst, ctx) {
|
|
2992
|
+
for (const result of results) {
|
|
2993
|
+
if (result.issues.length === 0) {
|
|
2994
|
+
final.value = result.value;
|
|
2995
|
+
return final;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
const nonaborted = results.filter((r) => !aborted(r));
|
|
2999
|
+
if (nonaborted.length === 1) {
|
|
3000
|
+
final.value = nonaborted[0].value;
|
|
3001
|
+
return nonaborted[0];
|
|
3002
|
+
}
|
|
3003
|
+
final.issues.push({
|
|
3004
|
+
code: "invalid_union",
|
|
3005
|
+
input: final.value,
|
|
3006
|
+
inst,
|
|
3007
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
3008
|
+
});
|
|
3009
|
+
return final;
|
|
3010
|
+
}
|
|
3011
|
+
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
3012
|
+
$ZodType.init(inst, def);
|
|
3013
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
|
|
3014
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
3015
|
+
defineLazy(inst._zod, "values", () => {
|
|
3016
|
+
if (def.options.every((o) => o._zod.values)) {
|
|
3017
|
+
return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
3018
|
+
}
|
|
3019
|
+
return void 0;
|
|
3020
|
+
});
|
|
3021
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
3022
|
+
if (def.options.every((o) => o._zod.pattern)) {
|
|
3023
|
+
const patterns = def.options.map((o) => o._zod.pattern);
|
|
3024
|
+
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
3025
|
+
}
|
|
3026
|
+
return void 0;
|
|
3027
|
+
});
|
|
3028
|
+
const single = def.options.length === 1;
|
|
3029
|
+
const first = def.options[0]._zod.run;
|
|
3030
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3031
|
+
if (single) {
|
|
3032
|
+
return first(payload, ctx);
|
|
3033
|
+
}
|
|
3034
|
+
let async = false;
|
|
3035
|
+
const results = [];
|
|
3036
|
+
for (const option of def.options) {
|
|
3037
|
+
const result = option._zod.run({
|
|
3038
|
+
value: payload.value,
|
|
3039
|
+
issues: []
|
|
3040
|
+
}, ctx);
|
|
3041
|
+
if (result instanceof Promise) {
|
|
3042
|
+
results.push(result);
|
|
3043
|
+
async = true;
|
|
3044
|
+
} else {
|
|
3045
|
+
if (result.issues.length === 0)
|
|
3046
|
+
return result;
|
|
3047
|
+
results.push(result);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
if (!async)
|
|
3051
|
+
return handleUnionResults(results, payload, inst, ctx);
|
|
3052
|
+
return Promise.all(results).then((results2) => {
|
|
3053
|
+
return handleUnionResults(results2, payload, inst, ctx);
|
|
3054
|
+
});
|
|
3055
|
+
};
|
|
3056
|
+
});
|
|
3057
|
+
const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
|
|
3058
|
+
$ZodType.init(inst, def);
|
|
3059
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3060
|
+
const input = payload.value;
|
|
3061
|
+
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
3062
|
+
const right = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
3063
|
+
const async = left instanceof Promise || right instanceof Promise;
|
|
3064
|
+
if (async) {
|
|
3065
|
+
return Promise.all([left, right]).then(([left2, right2]) => {
|
|
3066
|
+
return handleIntersectionResults(payload, left2, right2);
|
|
3067
|
+
});
|
|
3068
|
+
}
|
|
3069
|
+
return handleIntersectionResults(payload, left, right);
|
|
3070
|
+
};
|
|
3071
|
+
});
|
|
3072
|
+
function mergeValues(a, b) {
|
|
3073
|
+
if (a === b) {
|
|
3074
|
+
return { valid: true, data: a };
|
|
3075
|
+
}
|
|
3076
|
+
if (a instanceof Date && b instanceof Date && +a === +b) {
|
|
3077
|
+
return { valid: true, data: a };
|
|
3078
|
+
}
|
|
3079
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
3080
|
+
const bKeys = Object.keys(b);
|
|
3081
|
+
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3082
|
+
const newObj = { ...a, ...b };
|
|
3083
|
+
for (const key of sharedKeys) {
|
|
3084
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
3085
|
+
if (!sharedValue.valid) {
|
|
3086
|
+
return {
|
|
3087
|
+
valid: false,
|
|
3088
|
+
mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3091
|
+
newObj[key] = sharedValue.data;
|
|
3092
|
+
}
|
|
3093
|
+
return { valid: true, data: newObj };
|
|
3094
|
+
}
|
|
3095
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
3096
|
+
if (a.length !== b.length) {
|
|
3097
|
+
return { valid: false, mergeErrorPath: [] };
|
|
3098
|
+
}
|
|
3099
|
+
const newArray = [];
|
|
3100
|
+
for (let index = 0; index < a.length; index++) {
|
|
3101
|
+
const itemA = a[index];
|
|
3102
|
+
const itemB = b[index];
|
|
3103
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
3104
|
+
if (!sharedValue.valid) {
|
|
3105
|
+
return {
|
|
3106
|
+
valid: false,
|
|
3107
|
+
mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
newArray.push(sharedValue.data);
|
|
3111
|
+
}
|
|
3112
|
+
return { valid: true, data: newArray };
|
|
3113
|
+
}
|
|
3114
|
+
return { valid: false, mergeErrorPath: [] };
|
|
3115
|
+
}
|
|
3116
|
+
function handleIntersectionResults(result, left, right) {
|
|
3117
|
+
const unrecKeys = /* @__PURE__ */ new Map();
|
|
3118
|
+
let unrecIssue;
|
|
3119
|
+
for (const iss of left.issues) {
|
|
3120
|
+
if (iss.code === "unrecognized_keys") {
|
|
3121
|
+
unrecIssue ?? (unrecIssue = iss);
|
|
3122
|
+
for (const k of iss.keys) {
|
|
3123
|
+
if (!unrecKeys.has(k))
|
|
3124
|
+
unrecKeys.set(k, {});
|
|
3125
|
+
unrecKeys.get(k).l = true;
|
|
3126
|
+
}
|
|
3127
|
+
} else {
|
|
3128
|
+
result.issues.push(iss);
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
for (const iss of right.issues) {
|
|
3132
|
+
if (iss.code === "unrecognized_keys") {
|
|
3133
|
+
for (const k of iss.keys) {
|
|
3134
|
+
if (!unrecKeys.has(k))
|
|
3135
|
+
unrecKeys.set(k, {});
|
|
3136
|
+
unrecKeys.get(k).r = true;
|
|
3137
|
+
}
|
|
3138
|
+
} else {
|
|
3139
|
+
result.issues.push(iss);
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
|
|
3143
|
+
if (bothKeys.length && unrecIssue) {
|
|
3144
|
+
result.issues.push({ ...unrecIssue, keys: bothKeys });
|
|
3145
|
+
}
|
|
3146
|
+
if (aborted(result))
|
|
3147
|
+
return result;
|
|
3148
|
+
const merged = mergeValues(left.value, right.value);
|
|
3149
|
+
if (!merged.valid) {
|
|
3150
|
+
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
3151
|
+
}
|
|
3152
|
+
result.value = merged.data;
|
|
3153
|
+
return result;
|
|
3154
|
+
}
|
|
3155
|
+
const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
3156
|
+
$ZodType.init(inst, def);
|
|
3157
|
+
const values = getEnumValues(def.entries);
|
|
3158
|
+
const valuesSet = new Set(values);
|
|
3159
|
+
inst._zod.values = valuesSet;
|
|
3160
|
+
inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
|
|
3161
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
3162
|
+
const input = payload.value;
|
|
3163
|
+
if (valuesSet.has(input)) {
|
|
3164
|
+
return payload;
|
|
3165
|
+
}
|
|
3166
|
+
payload.issues.push({
|
|
3167
|
+
code: "invalid_value",
|
|
3168
|
+
values,
|
|
3169
|
+
input,
|
|
3170
|
+
inst
|
|
3171
|
+
});
|
|
3172
|
+
return payload;
|
|
3173
|
+
};
|
|
3174
|
+
});
|
|
3175
|
+
const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
|
|
3176
|
+
$ZodType.init(inst, def);
|
|
3177
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3178
|
+
if (ctx.direction === "backward") {
|
|
3179
|
+
throw new $ZodEncodeError(inst.constructor.name);
|
|
3180
|
+
}
|
|
3181
|
+
const _out = def.transform(payload.value, payload);
|
|
3182
|
+
if (ctx.async) {
|
|
3183
|
+
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
3184
|
+
return output.then((output2) => {
|
|
3185
|
+
payload.value = output2;
|
|
3186
|
+
return payload;
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
if (_out instanceof Promise) {
|
|
3190
|
+
throw new $ZodAsyncError();
|
|
3191
|
+
}
|
|
3192
|
+
payload.value = _out;
|
|
3193
|
+
return payload;
|
|
3194
|
+
};
|
|
3195
|
+
});
|
|
3196
|
+
function handleOptionalResult(result, input) {
|
|
3197
|
+
if (result.issues.length && input === void 0) {
|
|
3198
|
+
return { issues: [], value: void 0 };
|
|
3199
|
+
}
|
|
3200
|
+
return result;
|
|
3201
|
+
}
|
|
3202
|
+
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
3203
|
+
$ZodType.init(inst, def);
|
|
3204
|
+
inst._zod.optin = "optional";
|
|
3205
|
+
inst._zod.optout = "optional";
|
|
3206
|
+
defineLazy(inst._zod, "values", () => {
|
|
3207
|
+
return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
3208
|
+
});
|
|
3209
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
3210
|
+
const pattern = def.innerType._zod.pattern;
|
|
3211
|
+
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
3212
|
+
});
|
|
3213
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3214
|
+
if (def.innerType._zod.optin === "optional") {
|
|
3215
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
3216
|
+
if (result instanceof Promise)
|
|
3217
|
+
return result.then((r) => handleOptionalResult(r, payload.value));
|
|
3218
|
+
return handleOptionalResult(result, payload.value);
|
|
3219
|
+
}
|
|
3220
|
+
if (payload.value === void 0) {
|
|
3221
|
+
return payload;
|
|
3222
|
+
}
|
|
3223
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3224
|
+
};
|
|
3225
|
+
});
|
|
3226
|
+
const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
|
|
3227
|
+
$ZodOptional.init(inst, def);
|
|
3228
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
3229
|
+
defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
|
|
3230
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3231
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3232
|
+
};
|
|
3233
|
+
});
|
|
3234
|
+
const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
|
|
3235
|
+
$ZodType.init(inst, def);
|
|
3236
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
3237
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
3238
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
3239
|
+
const pattern = def.innerType._zod.pattern;
|
|
3240
|
+
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
3241
|
+
});
|
|
3242
|
+
defineLazy(inst._zod, "values", () => {
|
|
3243
|
+
return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
|
|
3244
|
+
});
|
|
3245
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3246
|
+
if (payload.value === null)
|
|
3247
|
+
return payload;
|
|
3248
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3249
|
+
};
|
|
3250
|
+
});
|
|
3251
|
+
const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
|
|
3252
|
+
$ZodType.init(inst, def);
|
|
3253
|
+
inst._zod.optin = "optional";
|
|
3254
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
3255
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3256
|
+
if (ctx.direction === "backward") {
|
|
3257
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3258
|
+
}
|
|
3259
|
+
if (payload.value === void 0) {
|
|
3260
|
+
payload.value = def.defaultValue;
|
|
3261
|
+
return payload;
|
|
3262
|
+
}
|
|
3263
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
3264
|
+
if (result instanceof Promise) {
|
|
3265
|
+
return result.then((result2) => handleDefaultResult(result2, def));
|
|
3266
|
+
}
|
|
3267
|
+
return handleDefaultResult(result, def);
|
|
3268
|
+
};
|
|
3269
|
+
});
|
|
3270
|
+
function handleDefaultResult(payload, def) {
|
|
3271
|
+
if (payload.value === void 0) {
|
|
3272
|
+
payload.value = def.defaultValue;
|
|
3273
|
+
}
|
|
3274
|
+
return payload;
|
|
3275
|
+
}
|
|
3276
|
+
const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
|
|
3277
|
+
$ZodType.init(inst, def);
|
|
3278
|
+
inst._zod.optin = "optional";
|
|
3279
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
3280
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3281
|
+
if (ctx.direction === "backward") {
|
|
3282
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3283
|
+
}
|
|
3284
|
+
if (payload.value === void 0) {
|
|
3285
|
+
payload.value = def.defaultValue;
|
|
3286
|
+
}
|
|
3287
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3288
|
+
};
|
|
3289
|
+
});
|
|
3290
|
+
const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
|
|
3291
|
+
$ZodType.init(inst, def);
|
|
3292
|
+
defineLazy(inst._zod, "values", () => {
|
|
3293
|
+
const v = def.innerType._zod.values;
|
|
3294
|
+
return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
|
|
3295
|
+
});
|
|
3296
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3297
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
3298
|
+
if (result instanceof Promise) {
|
|
3299
|
+
return result.then((result2) => handleNonOptionalResult(result2, inst));
|
|
3300
|
+
}
|
|
3301
|
+
return handleNonOptionalResult(result, inst);
|
|
3302
|
+
};
|
|
3303
|
+
});
|
|
3304
|
+
function handleNonOptionalResult(payload, inst) {
|
|
3305
|
+
if (!payload.issues.length && payload.value === void 0) {
|
|
3306
|
+
payload.issues.push({
|
|
3307
|
+
code: "invalid_type",
|
|
3308
|
+
expected: "nonoptional",
|
|
3309
|
+
input: payload.value,
|
|
3310
|
+
inst
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
return payload;
|
|
3314
|
+
}
|
|
3315
|
+
const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
3316
|
+
$ZodType.init(inst, def);
|
|
3317
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
3318
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
3319
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
3320
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3321
|
+
if (ctx.direction === "backward") {
|
|
3322
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3323
|
+
}
|
|
3324
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
3325
|
+
if (result instanceof Promise) {
|
|
3326
|
+
return result.then((result2) => {
|
|
3327
|
+
payload.value = result2.value;
|
|
3328
|
+
if (result2.issues.length) {
|
|
3329
|
+
payload.value = def.catchValue({
|
|
3330
|
+
...payload,
|
|
3331
|
+
error: {
|
|
3332
|
+
issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
3333
|
+
},
|
|
3334
|
+
input: payload.value
|
|
3335
|
+
});
|
|
3336
|
+
payload.issues = [];
|
|
3337
|
+
}
|
|
3338
|
+
return payload;
|
|
3339
|
+
});
|
|
3340
|
+
}
|
|
3341
|
+
payload.value = result.value;
|
|
3342
|
+
if (result.issues.length) {
|
|
3343
|
+
payload.value = def.catchValue({
|
|
3344
|
+
...payload,
|
|
3345
|
+
error: {
|
|
3346
|
+
issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
3347
|
+
},
|
|
3348
|
+
input: payload.value
|
|
3349
|
+
});
|
|
3350
|
+
payload.issues = [];
|
|
3351
|
+
}
|
|
3352
|
+
return payload;
|
|
3353
|
+
};
|
|
3354
|
+
});
|
|
3355
|
+
const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
|
|
3356
|
+
$ZodType.init(inst, def);
|
|
3357
|
+
defineLazy(inst._zod, "values", () => def.in._zod.values);
|
|
3358
|
+
defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
|
3359
|
+
defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
|
3360
|
+
defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
|
3361
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3362
|
+
if (ctx.direction === "backward") {
|
|
3363
|
+
const right = def.out._zod.run(payload, ctx);
|
|
3364
|
+
if (right instanceof Promise) {
|
|
3365
|
+
return right.then((right2) => handlePipeResult(right2, def.in, ctx));
|
|
3366
|
+
}
|
|
3367
|
+
return handlePipeResult(right, def.in, ctx);
|
|
3368
|
+
}
|
|
3369
|
+
const left = def.in._zod.run(payload, ctx);
|
|
3370
|
+
if (left instanceof Promise) {
|
|
3371
|
+
return left.then((left2) => handlePipeResult(left2, def.out, ctx));
|
|
3372
|
+
}
|
|
3373
|
+
return handlePipeResult(left, def.out, ctx);
|
|
3374
|
+
};
|
|
3375
|
+
});
|
|
3376
|
+
function handlePipeResult(left, next, ctx) {
|
|
3377
|
+
if (left.issues.length) {
|
|
3378
|
+
left.aborted = true;
|
|
3379
|
+
return left;
|
|
3380
|
+
}
|
|
3381
|
+
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
|
3382
|
+
}
|
|
3383
|
+
const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
|
|
3384
|
+
$ZodType.init(inst, def);
|
|
3385
|
+
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
3386
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
3387
|
+
defineLazy(inst._zod, "optin", () => {
|
|
3388
|
+
var _a2, _b;
|
|
3389
|
+
return (_b = (_a2 = def.innerType) == null ? void 0 : _a2._zod) == null ? void 0 : _b.optin;
|
|
3390
|
+
});
|
|
3391
|
+
defineLazy(inst._zod, "optout", () => {
|
|
3392
|
+
var _a2, _b;
|
|
3393
|
+
return (_b = (_a2 = def.innerType) == null ? void 0 : _a2._zod) == null ? void 0 : _b.optout;
|
|
3394
|
+
});
|
|
3395
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3396
|
+
if (ctx.direction === "backward") {
|
|
3397
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3398
|
+
}
|
|
3399
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
3400
|
+
if (result instanceof Promise) {
|
|
3401
|
+
return result.then(handleReadonlyResult);
|
|
3402
|
+
}
|
|
3403
|
+
return handleReadonlyResult(result);
|
|
3404
|
+
};
|
|
3405
|
+
});
|
|
3406
|
+
function handleReadonlyResult(payload) {
|
|
3407
|
+
payload.value = Object.freeze(payload.value);
|
|
3408
|
+
return payload;
|
|
3409
|
+
}
|
|
3410
|
+
const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
3411
|
+
$ZodCheck.init(inst, def);
|
|
3412
|
+
$ZodType.init(inst, def);
|
|
3413
|
+
inst._zod.parse = (payload, _) => {
|
|
3414
|
+
return payload;
|
|
3415
|
+
};
|
|
3416
|
+
inst._zod.check = (payload) => {
|
|
3417
|
+
const input = payload.value;
|
|
3418
|
+
const r = def.fn(input);
|
|
3419
|
+
if (r instanceof Promise) {
|
|
3420
|
+
return r.then((r2) => handleRefineResult(r2, payload, input, inst));
|
|
3421
|
+
}
|
|
3422
|
+
handleRefineResult(r, payload, input, inst);
|
|
3423
|
+
return;
|
|
3424
|
+
};
|
|
3425
|
+
});
|
|
3426
|
+
function handleRefineResult(result, payload, input, inst) {
|
|
3427
|
+
if (!result) {
|
|
3428
|
+
const _iss = {
|
|
3429
|
+
code: "custom",
|
|
3430
|
+
input,
|
|
3431
|
+
inst,
|
|
3432
|
+
// incorporates params.error into issue reporting
|
|
3433
|
+
path: [...inst._zod.def.path ?? []],
|
|
3434
|
+
// incorporates params.error into issue reporting
|
|
3435
|
+
continue: !inst._zod.def.abort
|
|
3436
|
+
// params: inst._zod.def.params,
|
|
3437
|
+
};
|
|
3438
|
+
if (inst._zod.def.params)
|
|
3439
|
+
_iss.params = inst._zod.def.params;
|
|
3440
|
+
payload.issues.push(issue(_iss));
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
var _a;
|
|
3444
|
+
class $ZodRegistry {
|
|
3445
|
+
constructor() {
|
|
3446
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
3447
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
3448
|
+
}
|
|
3449
|
+
add(schema, ..._meta) {
|
|
3450
|
+
const meta = _meta[0];
|
|
3451
|
+
this._map.set(schema, meta);
|
|
3452
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
3453
|
+
this._idmap.set(meta.id, schema);
|
|
3454
|
+
}
|
|
3455
|
+
return this;
|
|
3456
|
+
}
|
|
3457
|
+
clear() {
|
|
3458
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
3459
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
3460
|
+
return this;
|
|
3461
|
+
}
|
|
3462
|
+
remove(schema) {
|
|
3463
|
+
const meta = this._map.get(schema);
|
|
3464
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
3465
|
+
this._idmap.delete(meta.id);
|
|
3466
|
+
}
|
|
3467
|
+
this._map.delete(schema);
|
|
3468
|
+
return this;
|
|
3469
|
+
}
|
|
3470
|
+
get(schema) {
|
|
3471
|
+
const p = schema._zod.parent;
|
|
3472
|
+
if (p) {
|
|
3473
|
+
const pm = { ...this.get(p) ?? {} };
|
|
3474
|
+
delete pm.id;
|
|
3475
|
+
const f = { ...pm, ...this._map.get(schema) };
|
|
3476
|
+
return Object.keys(f).length ? f : void 0;
|
|
3477
|
+
}
|
|
3478
|
+
return this._map.get(schema);
|
|
3479
|
+
}
|
|
3480
|
+
has(schema) {
|
|
3481
|
+
return this._map.has(schema);
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
function registry() {
|
|
3485
|
+
return new $ZodRegistry();
|
|
3486
|
+
}
|
|
3487
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
3488
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
3489
|
+
// @__NO_SIDE_EFFECTS__
|
|
3490
|
+
function _string(Class, params) {
|
|
3491
|
+
return new Class({
|
|
3492
|
+
type: "string",
|
|
3493
|
+
...normalizeParams(params)
|
|
3494
|
+
});
|
|
3495
|
+
}
|
|
3496
|
+
// @__NO_SIDE_EFFECTS__
|
|
3497
|
+
function _email(Class, params) {
|
|
3498
|
+
return new Class({
|
|
3499
|
+
type: "string",
|
|
3500
|
+
format: "email",
|
|
3501
|
+
check: "string_format",
|
|
3502
|
+
abort: false,
|
|
3503
|
+
...normalizeParams(params)
|
|
3504
|
+
});
|
|
3505
|
+
}
|
|
3506
|
+
// @__NO_SIDE_EFFECTS__
|
|
3507
|
+
function _guid(Class, params) {
|
|
3508
|
+
return new Class({
|
|
3509
|
+
type: "string",
|
|
3510
|
+
format: "guid",
|
|
3511
|
+
check: "string_format",
|
|
3512
|
+
abort: false,
|
|
3513
|
+
...normalizeParams(params)
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3516
|
+
// @__NO_SIDE_EFFECTS__
|
|
3517
|
+
function _uuid(Class, params) {
|
|
3518
|
+
return new Class({
|
|
3519
|
+
type: "string",
|
|
3520
|
+
format: "uuid",
|
|
3521
|
+
check: "string_format",
|
|
3522
|
+
abort: false,
|
|
3523
|
+
...normalizeParams(params)
|
|
3524
|
+
});
|
|
3525
|
+
}
|
|
3526
|
+
// @__NO_SIDE_EFFECTS__
|
|
3527
|
+
function _uuidv4(Class, params) {
|
|
3528
|
+
return new Class({
|
|
3529
|
+
type: "string",
|
|
3530
|
+
format: "uuid",
|
|
3531
|
+
check: "string_format",
|
|
3532
|
+
abort: false,
|
|
3533
|
+
version: "v4",
|
|
3534
|
+
...normalizeParams(params)
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
// @__NO_SIDE_EFFECTS__
|
|
3538
|
+
function _uuidv6(Class, params) {
|
|
3539
|
+
return new Class({
|
|
3540
|
+
type: "string",
|
|
3541
|
+
format: "uuid",
|
|
3542
|
+
check: "string_format",
|
|
3543
|
+
abort: false,
|
|
3544
|
+
version: "v6",
|
|
3545
|
+
...normalizeParams(params)
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
// @__NO_SIDE_EFFECTS__
|
|
3549
|
+
function _uuidv7(Class, params) {
|
|
3550
|
+
return new Class({
|
|
3551
|
+
type: "string",
|
|
3552
|
+
format: "uuid",
|
|
3553
|
+
check: "string_format",
|
|
3554
|
+
abort: false,
|
|
3555
|
+
version: "v7",
|
|
3556
|
+
...normalizeParams(params)
|
|
3557
|
+
});
|
|
3558
|
+
}
|
|
3559
|
+
// @__NO_SIDE_EFFECTS__
|
|
3560
|
+
function _url(Class, params) {
|
|
3561
|
+
return new Class({
|
|
3562
|
+
type: "string",
|
|
3563
|
+
format: "url",
|
|
3564
|
+
check: "string_format",
|
|
3565
|
+
abort: false,
|
|
3566
|
+
...normalizeParams(params)
|
|
3567
|
+
});
|
|
3568
|
+
}
|
|
3569
|
+
// @__NO_SIDE_EFFECTS__
|
|
3570
|
+
function _emoji(Class, params) {
|
|
3571
|
+
return new Class({
|
|
3572
|
+
type: "string",
|
|
3573
|
+
format: "emoji",
|
|
3574
|
+
check: "string_format",
|
|
3575
|
+
abort: false,
|
|
3576
|
+
...normalizeParams(params)
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3579
|
+
// @__NO_SIDE_EFFECTS__
|
|
3580
|
+
function _nanoid(Class, params) {
|
|
3581
|
+
return new Class({
|
|
3582
|
+
type: "string",
|
|
3583
|
+
format: "nanoid",
|
|
3584
|
+
check: "string_format",
|
|
3585
|
+
abort: false,
|
|
3586
|
+
...normalizeParams(params)
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
// @__NO_SIDE_EFFECTS__
|
|
3590
|
+
function _cuid(Class, params) {
|
|
3591
|
+
return new Class({
|
|
3592
|
+
type: "string",
|
|
3593
|
+
format: "cuid",
|
|
3594
|
+
check: "string_format",
|
|
3595
|
+
abort: false,
|
|
3596
|
+
...normalizeParams(params)
|
|
3597
|
+
});
|
|
3598
|
+
}
|
|
3599
|
+
// @__NO_SIDE_EFFECTS__
|
|
3600
|
+
function _cuid2(Class, params) {
|
|
3601
|
+
return new Class({
|
|
3602
|
+
type: "string",
|
|
3603
|
+
format: "cuid2",
|
|
3604
|
+
check: "string_format",
|
|
3605
|
+
abort: false,
|
|
3606
|
+
...normalizeParams(params)
|
|
3607
|
+
});
|
|
3608
|
+
}
|
|
3609
|
+
// @__NO_SIDE_EFFECTS__
|
|
3610
|
+
function _ulid(Class, params) {
|
|
3611
|
+
return new Class({
|
|
3612
|
+
type: "string",
|
|
3613
|
+
format: "ulid",
|
|
3614
|
+
check: "string_format",
|
|
3615
|
+
abort: false,
|
|
3616
|
+
...normalizeParams(params)
|
|
3617
|
+
});
|
|
3618
|
+
}
|
|
3619
|
+
// @__NO_SIDE_EFFECTS__
|
|
3620
|
+
function _xid(Class, params) {
|
|
3621
|
+
return new Class({
|
|
3622
|
+
type: "string",
|
|
3623
|
+
format: "xid",
|
|
3624
|
+
check: "string_format",
|
|
3625
|
+
abort: false,
|
|
3626
|
+
...normalizeParams(params)
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
// @__NO_SIDE_EFFECTS__
|
|
3630
|
+
function _ksuid(Class, params) {
|
|
3631
|
+
return new Class({
|
|
3632
|
+
type: "string",
|
|
3633
|
+
format: "ksuid",
|
|
3634
|
+
check: "string_format",
|
|
3635
|
+
abort: false,
|
|
3636
|
+
...normalizeParams(params)
|
|
3637
|
+
});
|
|
3638
|
+
}
|
|
3639
|
+
// @__NO_SIDE_EFFECTS__
|
|
3640
|
+
function _ipv4(Class, params) {
|
|
3641
|
+
return new Class({
|
|
3642
|
+
type: "string",
|
|
3643
|
+
format: "ipv4",
|
|
3644
|
+
check: "string_format",
|
|
3645
|
+
abort: false,
|
|
3646
|
+
...normalizeParams(params)
|
|
3647
|
+
});
|
|
3648
|
+
}
|
|
3649
|
+
// @__NO_SIDE_EFFECTS__
|
|
3650
|
+
function _ipv6(Class, params) {
|
|
3651
|
+
return new Class({
|
|
3652
|
+
type: "string",
|
|
3653
|
+
format: "ipv6",
|
|
3654
|
+
check: "string_format",
|
|
3655
|
+
abort: false,
|
|
3656
|
+
...normalizeParams(params)
|
|
3657
|
+
});
|
|
3658
|
+
}
|
|
3659
|
+
// @__NO_SIDE_EFFECTS__
|
|
3660
|
+
function _cidrv4(Class, params) {
|
|
3661
|
+
return new Class({
|
|
3662
|
+
type: "string",
|
|
3663
|
+
format: "cidrv4",
|
|
3664
|
+
check: "string_format",
|
|
3665
|
+
abort: false,
|
|
3666
|
+
...normalizeParams(params)
|
|
3667
|
+
});
|
|
3668
|
+
}
|
|
3669
|
+
// @__NO_SIDE_EFFECTS__
|
|
3670
|
+
function _cidrv6(Class, params) {
|
|
3671
|
+
return new Class({
|
|
3672
|
+
type: "string",
|
|
3673
|
+
format: "cidrv6",
|
|
3674
|
+
check: "string_format",
|
|
3675
|
+
abort: false,
|
|
3676
|
+
...normalizeParams(params)
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
// @__NO_SIDE_EFFECTS__
|
|
3680
|
+
function _base64(Class, params) {
|
|
3681
|
+
return new Class({
|
|
3682
|
+
type: "string",
|
|
3683
|
+
format: "base64",
|
|
3684
|
+
check: "string_format",
|
|
3685
|
+
abort: false,
|
|
3686
|
+
...normalizeParams(params)
|
|
3687
|
+
});
|
|
3688
|
+
}
|
|
3689
|
+
// @__NO_SIDE_EFFECTS__
|
|
3690
|
+
function _base64url(Class, params) {
|
|
3691
|
+
return new Class({
|
|
3692
|
+
type: "string",
|
|
3693
|
+
format: "base64url",
|
|
3694
|
+
check: "string_format",
|
|
3695
|
+
abort: false,
|
|
3696
|
+
...normalizeParams(params)
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
// @__NO_SIDE_EFFECTS__
|
|
3700
|
+
function _e164(Class, params) {
|
|
3701
|
+
return new Class({
|
|
3702
|
+
type: "string",
|
|
3703
|
+
format: "e164",
|
|
3704
|
+
check: "string_format",
|
|
3705
|
+
abort: false,
|
|
3706
|
+
...normalizeParams(params)
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
// @__NO_SIDE_EFFECTS__
|
|
3710
|
+
function _jwt(Class, params) {
|
|
3711
|
+
return new Class({
|
|
3712
|
+
type: "string",
|
|
3713
|
+
format: "jwt",
|
|
3714
|
+
check: "string_format",
|
|
3715
|
+
abort: false,
|
|
3716
|
+
...normalizeParams(params)
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
// @__NO_SIDE_EFFECTS__
|
|
3720
|
+
function _isoDateTime(Class, params) {
|
|
3721
|
+
return new Class({
|
|
3722
|
+
type: "string",
|
|
3723
|
+
format: "datetime",
|
|
3724
|
+
check: "string_format",
|
|
3725
|
+
offset: false,
|
|
3726
|
+
local: false,
|
|
3727
|
+
precision: null,
|
|
3728
|
+
...normalizeParams(params)
|
|
3729
|
+
});
|
|
3730
|
+
}
|
|
3731
|
+
// @__NO_SIDE_EFFECTS__
|
|
3732
|
+
function _isoDate(Class, params) {
|
|
3733
|
+
return new Class({
|
|
3734
|
+
type: "string",
|
|
3735
|
+
format: "date",
|
|
3736
|
+
check: "string_format",
|
|
3737
|
+
...normalizeParams(params)
|
|
3738
|
+
});
|
|
3739
|
+
}
|
|
3740
|
+
// @__NO_SIDE_EFFECTS__
|
|
3741
|
+
function _isoTime(Class, params) {
|
|
3742
|
+
return new Class({
|
|
3743
|
+
type: "string",
|
|
3744
|
+
format: "time",
|
|
3745
|
+
check: "string_format",
|
|
3746
|
+
precision: null,
|
|
3747
|
+
...normalizeParams(params)
|
|
3748
|
+
});
|
|
3749
|
+
}
|
|
3750
|
+
// @__NO_SIDE_EFFECTS__
|
|
3751
|
+
function _isoDuration(Class, params) {
|
|
3752
|
+
return new Class({
|
|
3753
|
+
type: "string",
|
|
3754
|
+
format: "duration",
|
|
3755
|
+
check: "string_format",
|
|
3756
|
+
...normalizeParams(params)
|
|
3757
|
+
});
|
|
3758
|
+
}
|
|
3759
|
+
// @__NO_SIDE_EFFECTS__
|
|
3760
|
+
function _number(Class, params) {
|
|
3761
|
+
return new Class({
|
|
3762
|
+
type: "number",
|
|
3763
|
+
checks: [],
|
|
3764
|
+
...normalizeParams(params)
|
|
3765
|
+
});
|
|
3766
|
+
}
|
|
3767
|
+
// @__NO_SIDE_EFFECTS__
|
|
3768
|
+
function _int(Class, params) {
|
|
3769
|
+
return new Class({
|
|
3770
|
+
type: "number",
|
|
3771
|
+
check: "number_format",
|
|
3772
|
+
abort: false,
|
|
3773
|
+
format: "safeint",
|
|
3774
|
+
...normalizeParams(params)
|
|
3775
|
+
});
|
|
3776
|
+
}
|
|
3777
|
+
// @__NO_SIDE_EFFECTS__
|
|
3778
|
+
function _boolean(Class, params) {
|
|
3779
|
+
return new Class({
|
|
3780
|
+
type: "boolean",
|
|
3781
|
+
...normalizeParams(params)
|
|
3782
|
+
});
|
|
3783
|
+
}
|
|
3784
|
+
// @__NO_SIDE_EFFECTS__
|
|
3785
|
+
function _any(Class) {
|
|
3786
|
+
return new Class({
|
|
3787
|
+
type: "any"
|
|
3788
|
+
});
|
|
3789
|
+
}
|
|
3790
|
+
// @__NO_SIDE_EFFECTS__
|
|
3791
|
+
function _unknown(Class) {
|
|
3792
|
+
return new Class({
|
|
3793
|
+
type: "unknown"
|
|
3794
|
+
});
|
|
3795
|
+
}
|
|
3796
|
+
// @__NO_SIDE_EFFECTS__
|
|
3797
|
+
function _never(Class, params) {
|
|
3798
|
+
return new Class({
|
|
3799
|
+
type: "never",
|
|
3800
|
+
...normalizeParams(params)
|
|
3801
|
+
});
|
|
3802
|
+
}
|
|
3803
|
+
// @__NO_SIDE_EFFECTS__
|
|
3804
|
+
function _lt(value, params) {
|
|
3805
|
+
return new $ZodCheckLessThan({
|
|
3806
|
+
check: "less_than",
|
|
3807
|
+
...normalizeParams(params),
|
|
3808
|
+
value,
|
|
3809
|
+
inclusive: false
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3812
|
+
// @__NO_SIDE_EFFECTS__
|
|
3813
|
+
function _lte(value, params) {
|
|
3814
|
+
return new $ZodCheckLessThan({
|
|
3815
|
+
check: "less_than",
|
|
3816
|
+
...normalizeParams(params),
|
|
3817
|
+
value,
|
|
3818
|
+
inclusive: true
|
|
3819
|
+
});
|
|
3820
|
+
}
|
|
3821
|
+
// @__NO_SIDE_EFFECTS__
|
|
3822
|
+
function _gt(value, params) {
|
|
3823
|
+
return new $ZodCheckGreaterThan({
|
|
3824
|
+
check: "greater_than",
|
|
3825
|
+
...normalizeParams(params),
|
|
3826
|
+
value,
|
|
3827
|
+
inclusive: false
|
|
3828
|
+
});
|
|
3829
|
+
}
|
|
3830
|
+
// @__NO_SIDE_EFFECTS__
|
|
3831
|
+
function _gte(value, params) {
|
|
3832
|
+
return new $ZodCheckGreaterThan({
|
|
3833
|
+
check: "greater_than",
|
|
3834
|
+
...normalizeParams(params),
|
|
3835
|
+
value,
|
|
3836
|
+
inclusive: true
|
|
3837
|
+
});
|
|
3838
|
+
}
|
|
3839
|
+
// @__NO_SIDE_EFFECTS__
|
|
3840
|
+
function _multipleOf(value, params) {
|
|
3841
|
+
return new $ZodCheckMultipleOf({
|
|
3842
|
+
check: "multiple_of",
|
|
3843
|
+
...normalizeParams(params),
|
|
3844
|
+
value
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3847
|
+
// @__NO_SIDE_EFFECTS__
|
|
3848
|
+
function _maxLength(maximum, params) {
|
|
3849
|
+
const ch = new $ZodCheckMaxLength({
|
|
3850
|
+
check: "max_length",
|
|
3851
|
+
...normalizeParams(params),
|
|
3852
|
+
maximum
|
|
3853
|
+
});
|
|
3854
|
+
return ch;
|
|
3855
|
+
}
|
|
3856
|
+
// @__NO_SIDE_EFFECTS__
|
|
3857
|
+
function _minLength(minimum, params) {
|
|
3858
|
+
return new $ZodCheckMinLength({
|
|
3859
|
+
check: "min_length",
|
|
3860
|
+
...normalizeParams(params),
|
|
3861
|
+
minimum
|
|
3862
|
+
});
|
|
3863
|
+
}
|
|
3864
|
+
// @__NO_SIDE_EFFECTS__
|
|
3865
|
+
function _length(length, params) {
|
|
3866
|
+
return new $ZodCheckLengthEquals({
|
|
3867
|
+
check: "length_equals",
|
|
3868
|
+
...normalizeParams(params),
|
|
3869
|
+
length
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3872
|
+
// @__NO_SIDE_EFFECTS__
|
|
3873
|
+
function _regex(pattern, params) {
|
|
3874
|
+
return new $ZodCheckRegex({
|
|
3875
|
+
check: "string_format",
|
|
3876
|
+
format: "regex",
|
|
3877
|
+
...normalizeParams(params),
|
|
3878
|
+
pattern
|
|
3879
|
+
});
|
|
3880
|
+
}
|
|
3881
|
+
// @__NO_SIDE_EFFECTS__
|
|
3882
|
+
function _lowercase(params) {
|
|
3883
|
+
return new $ZodCheckLowerCase({
|
|
3884
|
+
check: "string_format",
|
|
3885
|
+
format: "lowercase",
|
|
3886
|
+
...normalizeParams(params)
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
// @__NO_SIDE_EFFECTS__
|
|
3890
|
+
function _uppercase(params) {
|
|
3891
|
+
return new $ZodCheckUpperCase({
|
|
3892
|
+
check: "string_format",
|
|
3893
|
+
format: "uppercase",
|
|
3894
|
+
...normalizeParams(params)
|
|
3895
|
+
});
|
|
3896
|
+
}
|
|
3897
|
+
// @__NO_SIDE_EFFECTS__
|
|
3898
|
+
function _includes(includes, params) {
|
|
3899
|
+
return new $ZodCheckIncludes({
|
|
3900
|
+
check: "string_format",
|
|
3901
|
+
format: "includes",
|
|
3902
|
+
...normalizeParams(params),
|
|
3903
|
+
includes
|
|
3904
|
+
});
|
|
3905
|
+
}
|
|
3906
|
+
// @__NO_SIDE_EFFECTS__
|
|
3907
|
+
function _startsWith(prefix, params) {
|
|
3908
|
+
return new $ZodCheckStartsWith({
|
|
3909
|
+
check: "string_format",
|
|
3910
|
+
format: "starts_with",
|
|
3911
|
+
...normalizeParams(params),
|
|
3912
|
+
prefix
|
|
3913
|
+
});
|
|
3914
|
+
}
|
|
3915
|
+
// @__NO_SIDE_EFFECTS__
|
|
3916
|
+
function _endsWith(suffix, params) {
|
|
3917
|
+
return new $ZodCheckEndsWith({
|
|
3918
|
+
check: "string_format",
|
|
3919
|
+
format: "ends_with",
|
|
3920
|
+
...normalizeParams(params),
|
|
3921
|
+
suffix
|
|
3922
|
+
});
|
|
3923
|
+
}
|
|
3924
|
+
// @__NO_SIDE_EFFECTS__
|
|
3925
|
+
function _overwrite(tx) {
|
|
3926
|
+
return new $ZodCheckOverwrite({
|
|
3927
|
+
check: "overwrite",
|
|
3928
|
+
tx
|
|
3929
|
+
});
|
|
3930
|
+
}
|
|
3931
|
+
// @__NO_SIDE_EFFECTS__
|
|
3932
|
+
function _normalize(form) {
|
|
3933
|
+
return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
|
|
3934
|
+
}
|
|
3935
|
+
// @__NO_SIDE_EFFECTS__
|
|
3936
|
+
function _trim() {
|
|
3937
|
+
return /* @__PURE__ */ _overwrite((input) => input.trim());
|
|
3938
|
+
}
|
|
3939
|
+
// @__NO_SIDE_EFFECTS__
|
|
3940
|
+
function _toLowerCase() {
|
|
3941
|
+
return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
|
|
3942
|
+
}
|
|
3943
|
+
// @__NO_SIDE_EFFECTS__
|
|
3944
|
+
function _toUpperCase() {
|
|
3945
|
+
return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
|
|
3946
|
+
}
|
|
3947
|
+
// @__NO_SIDE_EFFECTS__
|
|
3948
|
+
function _slugify() {
|
|
3949
|
+
return /* @__PURE__ */ _overwrite((input) => slugify(input));
|
|
3950
|
+
}
|
|
3951
|
+
// @__NO_SIDE_EFFECTS__
|
|
3952
|
+
function _array(Class, element, params) {
|
|
3953
|
+
return new Class({
|
|
3954
|
+
type: "array",
|
|
3955
|
+
element,
|
|
3956
|
+
// get element() {
|
|
3957
|
+
// return element;
|
|
3958
|
+
// },
|
|
3959
|
+
...normalizeParams(params)
|
|
3960
|
+
});
|
|
3961
|
+
}
|
|
3962
|
+
// @__NO_SIDE_EFFECTS__
|
|
3963
|
+
function _refine(Class, fn, _params) {
|
|
3964
|
+
const schema = new Class({
|
|
3965
|
+
type: "custom",
|
|
3966
|
+
check: "custom",
|
|
3967
|
+
fn,
|
|
3968
|
+
...normalizeParams(_params)
|
|
3969
|
+
});
|
|
3970
|
+
return schema;
|
|
3971
|
+
}
|
|
3972
|
+
// @__NO_SIDE_EFFECTS__
|
|
3973
|
+
function _superRefine(fn) {
|
|
3974
|
+
const ch = /* @__PURE__ */ _check((payload) => {
|
|
3975
|
+
payload.addIssue = (issue$1) => {
|
|
3976
|
+
if (typeof issue$1 === "string") {
|
|
3977
|
+
payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
|
|
3978
|
+
} else {
|
|
3979
|
+
const _issue = issue$1;
|
|
3980
|
+
if (_issue.fatal)
|
|
3981
|
+
_issue.continue = false;
|
|
3982
|
+
_issue.code ?? (_issue.code = "custom");
|
|
3983
|
+
_issue.input ?? (_issue.input = payload.value);
|
|
3984
|
+
_issue.inst ?? (_issue.inst = ch);
|
|
3985
|
+
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
3986
|
+
payload.issues.push(issue(_issue));
|
|
3987
|
+
}
|
|
3988
|
+
};
|
|
3989
|
+
return fn(payload.value, payload);
|
|
3990
|
+
});
|
|
3991
|
+
return ch;
|
|
3992
|
+
}
|
|
3993
|
+
// @__NO_SIDE_EFFECTS__
|
|
3994
|
+
function _check(fn, params) {
|
|
3995
|
+
const ch = new $ZodCheck({
|
|
3996
|
+
check: "custom",
|
|
3997
|
+
...normalizeParams(params)
|
|
3998
|
+
});
|
|
3999
|
+
ch._zod.check = fn;
|
|
4000
|
+
return ch;
|
|
4001
|
+
}
|
|
4002
|
+
function initializeContext(params) {
|
|
4003
|
+
let target = (params == null ? void 0 : params.target) ?? "draft-2020-12";
|
|
4004
|
+
if (target === "draft-4")
|
|
4005
|
+
target = "draft-04";
|
|
4006
|
+
if (target === "draft-7")
|
|
4007
|
+
target = "draft-07";
|
|
4008
|
+
return {
|
|
4009
|
+
processors: params.processors ?? {},
|
|
4010
|
+
metadataRegistry: (params == null ? void 0 : params.metadata) ?? globalRegistry,
|
|
4011
|
+
target,
|
|
4012
|
+
unrepresentable: (params == null ? void 0 : params.unrepresentable) ?? "throw",
|
|
4013
|
+
override: (params == null ? void 0 : params.override) ?? (() => {
|
|
4014
|
+
}),
|
|
4015
|
+
io: (params == null ? void 0 : params.io) ?? "output",
|
|
4016
|
+
counter: 0,
|
|
4017
|
+
seen: /* @__PURE__ */ new Map(),
|
|
4018
|
+
cycles: (params == null ? void 0 : params.cycles) ?? "ref",
|
|
4019
|
+
reused: (params == null ? void 0 : params.reused) ?? "inline",
|
|
4020
|
+
external: (params == null ? void 0 : params.external) ?? void 0
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
4024
|
+
var _a3, _b;
|
|
4025
|
+
var _a2;
|
|
4026
|
+
const def = schema._zod.def;
|
|
4027
|
+
const seen = ctx.seen.get(schema);
|
|
4028
|
+
if (seen) {
|
|
4029
|
+
seen.count++;
|
|
4030
|
+
const isCycle = _params.schemaPath.includes(schema);
|
|
4031
|
+
if (isCycle) {
|
|
4032
|
+
seen.cycle = _params.path;
|
|
4033
|
+
}
|
|
4034
|
+
return seen.schema;
|
|
4035
|
+
}
|
|
4036
|
+
const result = { schema: {}, count: 1, cycle: void 0, path: _params.path };
|
|
4037
|
+
ctx.seen.set(schema, result);
|
|
4038
|
+
const overrideSchema = (_b = (_a3 = schema._zod).toJSONSchema) == null ? void 0 : _b.call(_a3);
|
|
4039
|
+
if (overrideSchema) {
|
|
4040
|
+
result.schema = overrideSchema;
|
|
4041
|
+
} else {
|
|
4042
|
+
const params = {
|
|
4043
|
+
..._params,
|
|
4044
|
+
schemaPath: [..._params.schemaPath, schema],
|
|
4045
|
+
path: _params.path
|
|
4046
|
+
};
|
|
4047
|
+
if (schema._zod.processJSONSchema) {
|
|
4048
|
+
schema._zod.processJSONSchema(ctx, result.schema, params);
|
|
4049
|
+
} else {
|
|
4050
|
+
const _json = result.schema;
|
|
4051
|
+
const processor = ctx.processors[def.type];
|
|
4052
|
+
if (!processor) {
|
|
4053
|
+
throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
|
|
4054
|
+
}
|
|
4055
|
+
processor(schema, ctx, _json, params);
|
|
4056
|
+
}
|
|
4057
|
+
const parent = schema._zod.parent;
|
|
4058
|
+
if (parent) {
|
|
4059
|
+
if (!result.ref)
|
|
4060
|
+
result.ref = parent;
|
|
4061
|
+
process$1(parent, ctx, params);
|
|
4062
|
+
ctx.seen.get(parent).isParent = true;
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
const meta = ctx.metadataRegistry.get(schema);
|
|
4066
|
+
if (meta)
|
|
4067
|
+
Object.assign(result.schema, meta);
|
|
4068
|
+
if (ctx.io === "input" && isTransforming(schema)) {
|
|
4069
|
+
delete result.schema.examples;
|
|
4070
|
+
delete result.schema.default;
|
|
4071
|
+
}
|
|
4072
|
+
if (ctx.io === "input" && result.schema._prefault)
|
|
4073
|
+
(_a2 = result.schema).default ?? (_a2.default = result.schema._prefault);
|
|
4074
|
+
delete result.schema._prefault;
|
|
4075
|
+
const _result = ctx.seen.get(schema);
|
|
4076
|
+
return _result.schema;
|
|
4077
|
+
}
|
|
4078
|
+
function extractDefs(ctx, schema) {
|
|
4079
|
+
var _a2, _b, _c, _d;
|
|
4080
|
+
const root = ctx.seen.get(schema);
|
|
4081
|
+
if (!root)
|
|
4082
|
+
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
4083
|
+
const idToSchema = /* @__PURE__ */ new Map();
|
|
4084
|
+
for (const entry of ctx.seen.entries()) {
|
|
4085
|
+
const id = (_a2 = ctx.metadataRegistry.get(entry[0])) == null ? void 0 : _a2.id;
|
|
4086
|
+
if (id) {
|
|
4087
|
+
const existing = idToSchema.get(id);
|
|
4088
|
+
if (existing && existing !== entry[0]) {
|
|
4089
|
+
throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
|
|
4090
|
+
}
|
|
4091
|
+
idToSchema.set(id, entry[0]);
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
const makeURI = (entry) => {
|
|
4095
|
+
var _a3;
|
|
4096
|
+
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
4097
|
+
if (ctx.external) {
|
|
4098
|
+
const externalId = (_a3 = ctx.external.registry.get(entry[0])) == null ? void 0 : _a3.id;
|
|
4099
|
+
const uriGenerator = ctx.external.uri ?? ((id2) => id2);
|
|
4100
|
+
if (externalId) {
|
|
4101
|
+
return { ref: uriGenerator(externalId) };
|
|
4102
|
+
}
|
|
4103
|
+
const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
|
|
4104
|
+
entry[1].defId = id;
|
|
4105
|
+
return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
|
|
4106
|
+
}
|
|
4107
|
+
if (entry[1] === root) {
|
|
4108
|
+
return { ref: "#" };
|
|
4109
|
+
}
|
|
4110
|
+
const uriPrefix = `#`;
|
|
4111
|
+
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
4112
|
+
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
|
|
4113
|
+
return { defId, ref: defUriPrefix + defId };
|
|
4114
|
+
};
|
|
4115
|
+
const extractToDef = (entry) => {
|
|
4116
|
+
if (entry[1].schema.$ref) {
|
|
4117
|
+
return;
|
|
4118
|
+
}
|
|
4119
|
+
const seen = entry[1];
|
|
4120
|
+
const { ref, defId } = makeURI(entry);
|
|
4121
|
+
seen.def = { ...seen.schema };
|
|
4122
|
+
if (defId)
|
|
4123
|
+
seen.defId = defId;
|
|
4124
|
+
const schema2 = seen.schema;
|
|
4125
|
+
for (const key in schema2) {
|
|
4126
|
+
delete schema2[key];
|
|
4127
|
+
}
|
|
4128
|
+
schema2.$ref = ref;
|
|
4129
|
+
};
|
|
4130
|
+
if (ctx.cycles === "throw") {
|
|
4131
|
+
for (const entry of ctx.seen.entries()) {
|
|
4132
|
+
const seen = entry[1];
|
|
4133
|
+
if (seen.cycle) {
|
|
4134
|
+
throw new Error(`Cycle detected: #/${(_b = seen.cycle) == null ? void 0 : _b.join("/")}/<root>
|
|
4135
|
+
|
|
4136
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
for (const entry of ctx.seen.entries()) {
|
|
4141
|
+
const seen = entry[1];
|
|
4142
|
+
if (schema === entry[0]) {
|
|
4143
|
+
extractToDef(entry);
|
|
4144
|
+
continue;
|
|
4145
|
+
}
|
|
4146
|
+
if (ctx.external) {
|
|
4147
|
+
const ext = (_c = ctx.external.registry.get(entry[0])) == null ? void 0 : _c.id;
|
|
4148
|
+
if (schema !== entry[0] && ext) {
|
|
4149
|
+
extractToDef(entry);
|
|
4150
|
+
continue;
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
const id = (_d = ctx.metadataRegistry.get(entry[0])) == null ? void 0 : _d.id;
|
|
4154
|
+
if (id) {
|
|
4155
|
+
extractToDef(entry);
|
|
4156
|
+
continue;
|
|
4157
|
+
}
|
|
4158
|
+
if (seen.cycle) {
|
|
4159
|
+
extractToDef(entry);
|
|
4160
|
+
continue;
|
|
4161
|
+
}
|
|
4162
|
+
if (seen.count > 1) {
|
|
4163
|
+
if (ctx.reused === "ref") {
|
|
4164
|
+
extractToDef(entry);
|
|
4165
|
+
continue;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
function finalize(ctx, schema) {
|
|
4171
|
+
var _a2, _b, _c;
|
|
4172
|
+
const root = ctx.seen.get(schema);
|
|
4173
|
+
if (!root)
|
|
4174
|
+
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
4175
|
+
const flattenRef = (zodSchema) => {
|
|
4176
|
+
const seen = ctx.seen.get(zodSchema);
|
|
4177
|
+
if (seen.ref === null)
|
|
4178
|
+
return;
|
|
4179
|
+
const schema2 = seen.def ?? seen.schema;
|
|
4180
|
+
const _cached = { ...schema2 };
|
|
4181
|
+
const ref = seen.ref;
|
|
4182
|
+
seen.ref = null;
|
|
4183
|
+
if (ref) {
|
|
4184
|
+
flattenRef(ref);
|
|
4185
|
+
const refSeen = ctx.seen.get(ref);
|
|
4186
|
+
const refSchema = refSeen.schema;
|
|
4187
|
+
if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
|
|
4188
|
+
schema2.allOf = schema2.allOf ?? [];
|
|
4189
|
+
schema2.allOf.push(refSchema);
|
|
4190
|
+
} else {
|
|
4191
|
+
Object.assign(schema2, refSchema);
|
|
4192
|
+
}
|
|
4193
|
+
Object.assign(schema2, _cached);
|
|
4194
|
+
const isParentRef = zodSchema._zod.parent === ref;
|
|
4195
|
+
if (isParentRef) {
|
|
4196
|
+
for (const key in schema2) {
|
|
4197
|
+
if (key === "$ref" || key === "allOf")
|
|
4198
|
+
continue;
|
|
4199
|
+
if (!(key in _cached)) {
|
|
4200
|
+
delete schema2[key];
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
if (refSchema.$ref && refSeen.def) {
|
|
4205
|
+
for (const key in schema2) {
|
|
4206
|
+
if (key === "$ref" || key === "allOf")
|
|
4207
|
+
continue;
|
|
4208
|
+
if (key in refSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(refSeen.def[key])) {
|
|
4209
|
+
delete schema2[key];
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
const parent = zodSchema._zod.parent;
|
|
4215
|
+
if (parent && parent !== ref) {
|
|
4216
|
+
flattenRef(parent);
|
|
4217
|
+
const parentSeen = ctx.seen.get(parent);
|
|
4218
|
+
if (parentSeen == null ? void 0 : parentSeen.schema.$ref) {
|
|
4219
|
+
schema2.$ref = parentSeen.schema.$ref;
|
|
4220
|
+
if (parentSeen.def) {
|
|
4221
|
+
for (const key in schema2) {
|
|
4222
|
+
if (key === "$ref" || key === "allOf")
|
|
4223
|
+
continue;
|
|
4224
|
+
if (key in parentSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(parentSeen.def[key])) {
|
|
4225
|
+
delete schema2[key];
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
}
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
ctx.override({
|
|
4232
|
+
zodSchema,
|
|
4233
|
+
jsonSchema: schema2,
|
|
4234
|
+
path: seen.path ?? []
|
|
4235
|
+
});
|
|
4236
|
+
};
|
|
4237
|
+
for (const entry of [...ctx.seen.entries()].reverse()) {
|
|
4238
|
+
flattenRef(entry[0]);
|
|
4239
|
+
}
|
|
4240
|
+
const result = {};
|
|
4241
|
+
if (ctx.target === "draft-2020-12") {
|
|
4242
|
+
result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
4243
|
+
} else if (ctx.target === "draft-07") {
|
|
4244
|
+
result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
4245
|
+
} else if (ctx.target === "draft-04") {
|
|
4246
|
+
result.$schema = "http://json-schema.org/draft-04/schema#";
|
|
4247
|
+
} else if (ctx.target === "openapi-3.0") ;
|
|
4248
|
+
else ;
|
|
4249
|
+
if ((_a2 = ctx.external) == null ? void 0 : _a2.uri) {
|
|
4250
|
+
const id = (_b = ctx.external.registry.get(schema)) == null ? void 0 : _b.id;
|
|
4251
|
+
if (!id)
|
|
4252
|
+
throw new Error("Schema is missing an `id` property");
|
|
4253
|
+
result.$id = ctx.external.uri(id);
|
|
4254
|
+
}
|
|
4255
|
+
Object.assign(result, root.def ?? root.schema);
|
|
4256
|
+
const defs = ((_c = ctx.external) == null ? void 0 : _c.defs) ?? {};
|
|
4257
|
+
for (const entry of ctx.seen.entries()) {
|
|
4258
|
+
const seen = entry[1];
|
|
4259
|
+
if (seen.def && seen.defId) {
|
|
4260
|
+
defs[seen.defId] = seen.def;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
if (ctx.external) ;
|
|
4264
|
+
else {
|
|
4265
|
+
if (Object.keys(defs).length > 0) {
|
|
4266
|
+
if (ctx.target === "draft-2020-12") {
|
|
4267
|
+
result.$defs = defs;
|
|
4268
|
+
} else {
|
|
4269
|
+
result.definitions = defs;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
try {
|
|
4274
|
+
const finalized = JSON.parse(JSON.stringify(result));
|
|
4275
|
+
Object.defineProperty(finalized, "~standard", {
|
|
4276
|
+
value: {
|
|
4277
|
+
...schema["~standard"],
|
|
4278
|
+
jsonSchema: {
|
|
4279
|
+
input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
|
|
4280
|
+
output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
|
|
4281
|
+
}
|
|
4282
|
+
},
|
|
4283
|
+
enumerable: false,
|
|
4284
|
+
writable: false
|
|
4285
|
+
});
|
|
4286
|
+
return finalized;
|
|
4287
|
+
} catch (_err) {
|
|
4288
|
+
throw new Error("Error converting schema to JSON.");
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
function isTransforming(_schema, _ctx) {
|
|
4292
|
+
const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
|
|
4293
|
+
if (ctx.seen.has(_schema))
|
|
4294
|
+
return false;
|
|
4295
|
+
ctx.seen.add(_schema);
|
|
4296
|
+
const def = _schema._zod.def;
|
|
4297
|
+
if (def.type === "transform")
|
|
4298
|
+
return true;
|
|
4299
|
+
if (def.type === "array")
|
|
4300
|
+
return isTransforming(def.element, ctx);
|
|
4301
|
+
if (def.type === "set")
|
|
4302
|
+
return isTransforming(def.valueType, ctx);
|
|
4303
|
+
if (def.type === "lazy")
|
|
4304
|
+
return isTransforming(def.getter(), ctx);
|
|
4305
|
+
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") {
|
|
4306
|
+
return isTransforming(def.innerType, ctx);
|
|
4307
|
+
}
|
|
4308
|
+
if (def.type === "intersection") {
|
|
4309
|
+
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
4310
|
+
}
|
|
4311
|
+
if (def.type === "record" || def.type === "map") {
|
|
4312
|
+
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
4313
|
+
}
|
|
4314
|
+
if (def.type === "pipe") {
|
|
4315
|
+
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
4316
|
+
}
|
|
4317
|
+
if (def.type === "object") {
|
|
4318
|
+
for (const key in def.shape) {
|
|
4319
|
+
if (isTransforming(def.shape[key], ctx))
|
|
4320
|
+
return true;
|
|
4321
|
+
}
|
|
4322
|
+
return false;
|
|
4323
|
+
}
|
|
4324
|
+
if (def.type === "union") {
|
|
4325
|
+
for (const option of def.options) {
|
|
4326
|
+
if (isTransforming(option, ctx))
|
|
4327
|
+
return true;
|
|
4328
|
+
}
|
|
4329
|
+
return false;
|
|
4330
|
+
}
|
|
4331
|
+
if (def.type === "tuple") {
|
|
4332
|
+
for (const item of def.items) {
|
|
4333
|
+
if (isTransforming(item, ctx))
|
|
4334
|
+
return true;
|
|
4335
|
+
}
|
|
4336
|
+
if (def.rest && isTransforming(def.rest, ctx))
|
|
4337
|
+
return true;
|
|
4338
|
+
return false;
|
|
4339
|
+
}
|
|
4340
|
+
return false;
|
|
4341
|
+
}
|
|
4342
|
+
const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
4343
|
+
const ctx = initializeContext({ ...params, processors });
|
|
4344
|
+
process$1(schema, ctx);
|
|
4345
|
+
extractDefs(ctx, schema);
|
|
4346
|
+
return finalize(ctx, schema);
|
|
4347
|
+
};
|
|
4348
|
+
const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
|
|
4349
|
+
const { libraryOptions, target } = params ?? {};
|
|
4350
|
+
const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
|
|
4351
|
+
process$1(schema, ctx);
|
|
4352
|
+
extractDefs(ctx, schema);
|
|
4353
|
+
return finalize(ctx, schema);
|
|
4354
|
+
};
|
|
4355
|
+
const formatMap = {
|
|
4356
|
+
guid: "uuid",
|
|
4357
|
+
url: "uri",
|
|
4358
|
+
datetime: "date-time",
|
|
4359
|
+
json_string: "json-string",
|
|
4360
|
+
regex: ""
|
|
4361
|
+
// do not set
|
|
4362
|
+
};
|
|
4363
|
+
const stringProcessor = (schema, ctx, _json, _params) => {
|
|
4364
|
+
const json = _json;
|
|
4365
|
+
json.type = "string";
|
|
4366
|
+
const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
|
|
4367
|
+
if (typeof minimum === "number")
|
|
4368
|
+
json.minLength = minimum;
|
|
4369
|
+
if (typeof maximum === "number")
|
|
4370
|
+
json.maxLength = maximum;
|
|
4371
|
+
if (format) {
|
|
4372
|
+
json.format = formatMap[format] ?? format;
|
|
4373
|
+
if (json.format === "")
|
|
4374
|
+
delete json.format;
|
|
4375
|
+
if (format === "time") {
|
|
4376
|
+
delete json.format;
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
if (contentEncoding)
|
|
4380
|
+
json.contentEncoding = contentEncoding;
|
|
4381
|
+
if (patterns && patterns.size > 0) {
|
|
4382
|
+
const regexes = [...patterns];
|
|
4383
|
+
if (regexes.length === 1)
|
|
4384
|
+
json.pattern = regexes[0].source;
|
|
4385
|
+
else if (regexes.length > 1) {
|
|
4386
|
+
json.allOf = [
|
|
4387
|
+
...regexes.map((regex) => ({
|
|
4388
|
+
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
4389
|
+
pattern: regex.source
|
|
4390
|
+
}))
|
|
4391
|
+
];
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
};
|
|
4395
|
+
const numberProcessor = (schema, ctx, _json, _params) => {
|
|
4396
|
+
const json = _json;
|
|
4397
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
4398
|
+
if (typeof format === "string" && format.includes("int"))
|
|
4399
|
+
json.type = "integer";
|
|
4400
|
+
else
|
|
4401
|
+
json.type = "number";
|
|
4402
|
+
if (typeof exclusiveMinimum === "number") {
|
|
4403
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
4404
|
+
json.minimum = exclusiveMinimum;
|
|
4405
|
+
json.exclusiveMinimum = true;
|
|
4406
|
+
} else {
|
|
4407
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
if (typeof minimum === "number") {
|
|
4411
|
+
json.minimum = minimum;
|
|
4412
|
+
if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
|
|
4413
|
+
if (exclusiveMinimum >= minimum)
|
|
4414
|
+
delete json.minimum;
|
|
4415
|
+
else
|
|
4416
|
+
delete json.exclusiveMinimum;
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
if (typeof exclusiveMaximum === "number") {
|
|
4420
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
4421
|
+
json.maximum = exclusiveMaximum;
|
|
4422
|
+
json.exclusiveMaximum = true;
|
|
4423
|
+
} else {
|
|
4424
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
if (typeof maximum === "number") {
|
|
4428
|
+
json.maximum = maximum;
|
|
4429
|
+
if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
|
|
4430
|
+
if (exclusiveMaximum <= maximum)
|
|
4431
|
+
delete json.maximum;
|
|
4432
|
+
else
|
|
4433
|
+
delete json.exclusiveMaximum;
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
if (typeof multipleOf === "number")
|
|
4437
|
+
json.multipleOf = multipleOf;
|
|
4438
|
+
};
|
|
4439
|
+
const booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4440
|
+
json.type = "boolean";
|
|
4441
|
+
};
|
|
4442
|
+
const neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4443
|
+
json.not = {};
|
|
4444
|
+
};
|
|
4445
|
+
const anyProcessor = (_schema, _ctx, _json, _params) => {
|
|
4446
|
+
};
|
|
4447
|
+
const unknownProcessor = (_schema, _ctx, _json, _params) => {
|
|
4448
|
+
};
|
|
4449
|
+
const enumProcessor = (schema, _ctx, json, _params) => {
|
|
4450
|
+
const def = schema._zod.def;
|
|
4451
|
+
const values = getEnumValues(def.entries);
|
|
4452
|
+
if (values.every((v) => typeof v === "number"))
|
|
4453
|
+
json.type = "number";
|
|
4454
|
+
if (values.every((v) => typeof v === "string"))
|
|
4455
|
+
json.type = "string";
|
|
4456
|
+
json.enum = values;
|
|
4457
|
+
};
|
|
4458
|
+
const customProcessor = (_schema, ctx, _json, _params) => {
|
|
4459
|
+
if (ctx.unrepresentable === "throw") {
|
|
4460
|
+
throw new Error("Custom types cannot be represented in JSON Schema");
|
|
4461
|
+
}
|
|
4462
|
+
};
|
|
4463
|
+
const transformProcessor = (_schema, ctx, _json, _params) => {
|
|
4464
|
+
if (ctx.unrepresentable === "throw") {
|
|
4465
|
+
throw new Error("Transforms cannot be represented in JSON Schema");
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
4468
|
+
const arrayProcessor = (schema, ctx, _json, params) => {
|
|
4469
|
+
const json = _json;
|
|
4470
|
+
const def = schema._zod.def;
|
|
4471
|
+
const { minimum, maximum } = schema._zod.bag;
|
|
4472
|
+
if (typeof minimum === "number")
|
|
4473
|
+
json.minItems = minimum;
|
|
4474
|
+
if (typeof maximum === "number")
|
|
4475
|
+
json.maxItems = maximum;
|
|
4476
|
+
json.type = "array";
|
|
4477
|
+
json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
|
|
4478
|
+
};
|
|
4479
|
+
const objectProcessor = (schema, ctx, _json, params) => {
|
|
4480
|
+
var _a2;
|
|
4481
|
+
const json = _json;
|
|
4482
|
+
const def = schema._zod.def;
|
|
4483
|
+
json.type = "object";
|
|
4484
|
+
json.properties = {};
|
|
4485
|
+
const shape = def.shape;
|
|
4486
|
+
for (const key in shape) {
|
|
4487
|
+
json.properties[key] = process$1(shape[key], ctx, {
|
|
4488
|
+
...params,
|
|
4489
|
+
path: [...params.path, "properties", key]
|
|
4490
|
+
});
|
|
4491
|
+
}
|
|
4492
|
+
const allKeys = new Set(Object.keys(shape));
|
|
4493
|
+
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
4494
|
+
const v = def.shape[key]._zod;
|
|
4495
|
+
if (ctx.io === "input") {
|
|
4496
|
+
return v.optin === void 0;
|
|
4497
|
+
} else {
|
|
4498
|
+
return v.optout === void 0;
|
|
4499
|
+
}
|
|
4500
|
+
}));
|
|
4501
|
+
if (requiredKeys.size > 0) {
|
|
4502
|
+
json.required = Array.from(requiredKeys);
|
|
4503
|
+
}
|
|
4504
|
+
if (((_a2 = def.catchall) == null ? void 0 : _a2._zod.def.type) === "never") {
|
|
4505
|
+
json.additionalProperties = false;
|
|
4506
|
+
} else if (!def.catchall) {
|
|
4507
|
+
if (ctx.io === "output")
|
|
4508
|
+
json.additionalProperties = false;
|
|
4509
|
+
} else if (def.catchall) {
|
|
4510
|
+
json.additionalProperties = process$1(def.catchall, ctx, {
|
|
4511
|
+
...params,
|
|
4512
|
+
path: [...params.path, "additionalProperties"]
|
|
4513
|
+
});
|
|
4514
|
+
}
|
|
4515
|
+
};
|
|
4516
|
+
const unionProcessor = (schema, ctx, json, params) => {
|
|
4517
|
+
const def = schema._zod.def;
|
|
4518
|
+
const isExclusive = def.inclusive === false;
|
|
4519
|
+
const options = def.options.map((x, i) => process$1(x, ctx, {
|
|
4520
|
+
...params,
|
|
4521
|
+
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
4522
|
+
}));
|
|
4523
|
+
if (isExclusive) {
|
|
4524
|
+
json.oneOf = options;
|
|
4525
|
+
} else {
|
|
4526
|
+
json.anyOf = options;
|
|
4527
|
+
}
|
|
4528
|
+
};
|
|
4529
|
+
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
4530
|
+
const def = schema._zod.def;
|
|
4531
|
+
const a = process$1(def.left, ctx, {
|
|
4532
|
+
...params,
|
|
4533
|
+
path: [...params.path, "allOf", 0]
|
|
4534
|
+
});
|
|
4535
|
+
const b = process$1(def.right, ctx, {
|
|
4536
|
+
...params,
|
|
4537
|
+
path: [...params.path, "allOf", 1]
|
|
4538
|
+
});
|
|
4539
|
+
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
|
|
4540
|
+
const allOf = [
|
|
4541
|
+
...isSimpleIntersection(a) ? a.allOf : [a],
|
|
4542
|
+
...isSimpleIntersection(b) ? b.allOf : [b]
|
|
4543
|
+
];
|
|
4544
|
+
json.allOf = allOf;
|
|
4545
|
+
};
|
|
4546
|
+
const nullableProcessor = (schema, ctx, json, params) => {
|
|
4547
|
+
const def = schema._zod.def;
|
|
4548
|
+
const inner = process$1(def.innerType, ctx, params);
|
|
4549
|
+
const seen = ctx.seen.get(schema);
|
|
4550
|
+
if (ctx.target === "openapi-3.0") {
|
|
4551
|
+
seen.ref = def.innerType;
|
|
4552
|
+
json.nullable = true;
|
|
4553
|
+
} else {
|
|
4554
|
+
json.anyOf = [inner, { type: "null" }];
|
|
4555
|
+
}
|
|
4556
|
+
};
|
|
4557
|
+
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
4558
|
+
const def = schema._zod.def;
|
|
4559
|
+
process$1(def.innerType, ctx, params);
|
|
4560
|
+
const seen = ctx.seen.get(schema);
|
|
4561
|
+
seen.ref = def.innerType;
|
|
4562
|
+
};
|
|
4563
|
+
const defaultProcessor = (schema, ctx, json, params) => {
|
|
4564
|
+
const def = schema._zod.def;
|
|
4565
|
+
process$1(def.innerType, ctx, params);
|
|
4566
|
+
const seen = ctx.seen.get(schema);
|
|
4567
|
+
seen.ref = def.innerType;
|
|
4568
|
+
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
4569
|
+
};
|
|
4570
|
+
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
4571
|
+
const def = schema._zod.def;
|
|
4572
|
+
process$1(def.innerType, ctx, params);
|
|
4573
|
+
const seen = ctx.seen.get(schema);
|
|
4574
|
+
seen.ref = def.innerType;
|
|
4575
|
+
if (ctx.io === "input")
|
|
4576
|
+
json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
|
|
4577
|
+
};
|
|
4578
|
+
const catchProcessor = (schema, ctx, json, params) => {
|
|
4579
|
+
const def = schema._zod.def;
|
|
4580
|
+
process$1(def.innerType, ctx, params);
|
|
4581
|
+
const seen = ctx.seen.get(schema);
|
|
4582
|
+
seen.ref = def.innerType;
|
|
4583
|
+
let catchValue;
|
|
4584
|
+
try {
|
|
4585
|
+
catchValue = def.catchValue(void 0);
|
|
4586
|
+
} catch {
|
|
4587
|
+
throw new Error("Dynamic catch values are not supported in JSON Schema");
|
|
4588
|
+
}
|
|
4589
|
+
json.default = catchValue;
|
|
4590
|
+
};
|
|
4591
|
+
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
4592
|
+
const def = schema._zod.def;
|
|
4593
|
+
const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
|
|
4594
|
+
process$1(innerType, ctx, params);
|
|
4595
|
+
const seen = ctx.seen.get(schema);
|
|
4596
|
+
seen.ref = innerType;
|
|
4597
|
+
};
|
|
4598
|
+
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
4599
|
+
const def = schema._zod.def;
|
|
4600
|
+
process$1(def.innerType, ctx, params);
|
|
4601
|
+
const seen = ctx.seen.get(schema);
|
|
4602
|
+
seen.ref = def.innerType;
|
|
4603
|
+
json.readOnly = true;
|
|
4604
|
+
};
|
|
4605
|
+
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
4606
|
+
const def = schema._zod.def;
|
|
4607
|
+
process$1(def.innerType, ctx, params);
|
|
4608
|
+
const seen = ctx.seen.get(schema);
|
|
4609
|
+
seen.ref = def.innerType;
|
|
4610
|
+
};
|
|
4611
|
+
const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
|
|
4612
|
+
$ZodISODateTime.init(inst, def);
|
|
4613
|
+
ZodStringFormat.init(inst, def);
|
|
4614
|
+
});
|
|
4615
|
+
function datetime(params) {
|
|
4616
|
+
return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
|
|
4617
|
+
}
|
|
4618
|
+
const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
|
|
4619
|
+
$ZodISODate.init(inst, def);
|
|
4620
|
+
ZodStringFormat.init(inst, def);
|
|
4621
|
+
});
|
|
4622
|
+
function date(params) {
|
|
4623
|
+
return /* @__PURE__ */ _isoDate(ZodISODate, params);
|
|
4624
|
+
}
|
|
4625
|
+
const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
|
|
4626
|
+
$ZodISOTime.init(inst, def);
|
|
4627
|
+
ZodStringFormat.init(inst, def);
|
|
4628
|
+
});
|
|
4629
|
+
function time(params) {
|
|
4630
|
+
return /* @__PURE__ */ _isoTime(ZodISOTime, params);
|
|
4631
|
+
}
|
|
4632
|
+
const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
|
|
4633
|
+
$ZodISODuration.init(inst, def);
|
|
4634
|
+
ZodStringFormat.init(inst, def);
|
|
4635
|
+
});
|
|
4636
|
+
function duration(params) {
|
|
4637
|
+
return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
|
|
4638
|
+
}
|
|
4639
|
+
const initializer = (inst, issues) => {
|
|
4640
|
+
$ZodError.init(inst, issues);
|
|
4641
|
+
inst.name = "ZodError";
|
|
4642
|
+
Object.defineProperties(inst, {
|
|
4643
|
+
format: {
|
|
4644
|
+
value: (mapper) => formatError(inst, mapper)
|
|
4645
|
+
// enumerable: false,
|
|
4646
|
+
},
|
|
4647
|
+
flatten: {
|
|
4648
|
+
value: (mapper) => flattenError(inst, mapper)
|
|
4649
|
+
// enumerable: false,
|
|
4650
|
+
},
|
|
4651
|
+
addIssue: {
|
|
4652
|
+
value: (issue2) => {
|
|
4653
|
+
inst.issues.push(issue2);
|
|
4654
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
4655
|
+
}
|
|
4656
|
+
// enumerable: false,
|
|
4657
|
+
},
|
|
4658
|
+
addIssues: {
|
|
4659
|
+
value: (issues2) => {
|
|
4660
|
+
inst.issues.push(...issues2);
|
|
4661
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
4662
|
+
}
|
|
4663
|
+
// enumerable: false,
|
|
4664
|
+
},
|
|
4665
|
+
isEmpty: {
|
|
4666
|
+
get() {
|
|
4667
|
+
return inst.issues.length === 0;
|
|
4668
|
+
}
|
|
4669
|
+
// enumerable: false,
|
|
4670
|
+
}
|
|
4671
|
+
});
|
|
4672
|
+
};
|
|
4673
|
+
const ZodRealError = $constructor("ZodError", initializer, {
|
|
4674
|
+
Parent: Error
|
|
4675
|
+
});
|
|
4676
|
+
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
4677
|
+
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
4678
|
+
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
4679
|
+
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
4680
|
+
const encode = /* @__PURE__ */ _encode(ZodRealError);
|
|
4681
|
+
const decode = /* @__PURE__ */ _decode(ZodRealError);
|
|
4682
|
+
const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
4683
|
+
const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
4684
|
+
const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
4685
|
+
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
4686
|
+
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
4687
|
+
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
4688
|
+
const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
4689
|
+
$ZodType.init(inst, def);
|
|
4690
|
+
Object.assign(inst["~standard"], {
|
|
4691
|
+
jsonSchema: {
|
|
4692
|
+
input: createStandardJSONSchemaMethod(inst, "input"),
|
|
4693
|
+
output: createStandardJSONSchemaMethod(inst, "output")
|
|
4694
|
+
}
|
|
4695
|
+
});
|
|
4696
|
+
inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
|
|
4697
|
+
inst.def = def;
|
|
4698
|
+
inst.type = def.type;
|
|
4699
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
4700
|
+
inst.check = (...checks) => {
|
|
4701
|
+
return inst.clone(mergeDefs(def, {
|
|
4702
|
+
checks: [
|
|
4703
|
+
...def.checks ?? [],
|
|
4704
|
+
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch)
|
|
4705
|
+
]
|
|
4706
|
+
}), {
|
|
4707
|
+
parent: true
|
|
4708
|
+
});
|
|
4709
|
+
};
|
|
4710
|
+
inst.with = inst.check;
|
|
4711
|
+
inst.clone = (def2, params) => clone(inst, def2, params);
|
|
4712
|
+
inst.brand = () => inst;
|
|
4713
|
+
inst.register = ((reg, meta) => {
|
|
4714
|
+
reg.add(inst, meta);
|
|
4715
|
+
return inst;
|
|
4716
|
+
});
|
|
4717
|
+
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
4718
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
4719
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
4720
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
4721
|
+
inst.spa = inst.safeParseAsync;
|
|
4722
|
+
inst.encode = (data, params) => encode(inst, data, params);
|
|
4723
|
+
inst.decode = (data, params) => decode(inst, data, params);
|
|
4724
|
+
inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
|
|
4725
|
+
inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
|
|
4726
|
+
inst.safeEncode = (data, params) => safeEncode(inst, data, params);
|
|
4727
|
+
inst.safeDecode = (data, params) => safeDecode(inst, data, params);
|
|
4728
|
+
inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
|
|
4729
|
+
inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
|
|
4730
|
+
inst.refine = (check, params) => inst.check(refine(check, params));
|
|
4731
|
+
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
|
|
4732
|
+
inst.overwrite = (fn) => inst.check(/* @__PURE__ */ _overwrite(fn));
|
|
4733
|
+
inst.optional = () => optional(inst);
|
|
4734
|
+
inst.exactOptional = () => exactOptional(inst);
|
|
4735
|
+
inst.nullable = () => nullable(inst);
|
|
4736
|
+
inst.nullish = () => optional(nullable(inst));
|
|
4737
|
+
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
4738
|
+
inst.array = () => array(inst);
|
|
4739
|
+
inst.or = (arg) => union([inst, arg]);
|
|
4740
|
+
inst.and = (arg) => intersection(inst, arg);
|
|
4741
|
+
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
4742
|
+
inst.default = (def2) => _default(inst, def2);
|
|
4743
|
+
inst.prefault = (def2) => prefault(inst, def2);
|
|
4744
|
+
inst.catch = (params) => _catch(inst, params);
|
|
4745
|
+
inst.pipe = (target) => pipe(inst, target);
|
|
4746
|
+
inst.readonly = () => readonly(inst);
|
|
4747
|
+
inst.describe = (description) => {
|
|
4748
|
+
const cl = inst.clone();
|
|
4749
|
+
globalRegistry.add(cl, { description });
|
|
4750
|
+
return cl;
|
|
4751
|
+
};
|
|
4752
|
+
Object.defineProperty(inst, "description", {
|
|
4753
|
+
get() {
|
|
4754
|
+
var _a2;
|
|
4755
|
+
return (_a2 = globalRegistry.get(inst)) == null ? void 0 : _a2.description;
|
|
4756
|
+
},
|
|
4757
|
+
configurable: true
|
|
4758
|
+
});
|
|
4759
|
+
inst.meta = (...args) => {
|
|
4760
|
+
if (args.length === 0) {
|
|
4761
|
+
return globalRegistry.get(inst);
|
|
4762
|
+
}
|
|
4763
|
+
const cl = inst.clone();
|
|
4764
|
+
globalRegistry.add(cl, args[0]);
|
|
4765
|
+
return cl;
|
|
4766
|
+
};
|
|
4767
|
+
inst.isOptional = () => inst.safeParse(void 0).success;
|
|
4768
|
+
inst.isNullable = () => inst.safeParse(null).success;
|
|
4769
|
+
inst.apply = (fn) => fn(inst);
|
|
4770
|
+
return inst;
|
|
4771
|
+
});
|
|
4772
|
+
const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
|
|
4773
|
+
$ZodString.init(inst, def);
|
|
4774
|
+
ZodType.init(inst, def);
|
|
4775
|
+
inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
|
|
4776
|
+
const bag = inst._zod.bag;
|
|
4777
|
+
inst.format = bag.format ?? null;
|
|
4778
|
+
inst.minLength = bag.minimum ?? null;
|
|
4779
|
+
inst.maxLength = bag.maximum ?? null;
|
|
4780
|
+
inst.regex = (...args) => inst.check(/* @__PURE__ */ _regex(...args));
|
|
4781
|
+
inst.includes = (...args) => inst.check(/* @__PURE__ */ _includes(...args));
|
|
4782
|
+
inst.startsWith = (...args) => inst.check(/* @__PURE__ */ _startsWith(...args));
|
|
4783
|
+
inst.endsWith = (...args) => inst.check(/* @__PURE__ */ _endsWith(...args));
|
|
4784
|
+
inst.min = (...args) => inst.check(/* @__PURE__ */ _minLength(...args));
|
|
4785
|
+
inst.max = (...args) => inst.check(/* @__PURE__ */ _maxLength(...args));
|
|
4786
|
+
inst.length = (...args) => inst.check(/* @__PURE__ */ _length(...args));
|
|
4787
|
+
inst.nonempty = (...args) => inst.check(/* @__PURE__ */ _minLength(1, ...args));
|
|
4788
|
+
inst.lowercase = (params) => inst.check(/* @__PURE__ */ _lowercase(params));
|
|
4789
|
+
inst.uppercase = (params) => inst.check(/* @__PURE__ */ _uppercase(params));
|
|
4790
|
+
inst.trim = () => inst.check(/* @__PURE__ */ _trim());
|
|
4791
|
+
inst.normalize = (...args) => inst.check(/* @__PURE__ */ _normalize(...args));
|
|
4792
|
+
inst.toLowerCase = () => inst.check(/* @__PURE__ */ _toLowerCase());
|
|
4793
|
+
inst.toUpperCase = () => inst.check(/* @__PURE__ */ _toUpperCase());
|
|
4794
|
+
inst.slugify = () => inst.check(/* @__PURE__ */ _slugify());
|
|
4795
|
+
});
|
|
4796
|
+
const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
|
|
4797
|
+
$ZodString.init(inst, def);
|
|
4798
|
+
_ZodString.init(inst, def);
|
|
4799
|
+
inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
|
|
4800
|
+
inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
|
|
4801
|
+
inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
|
|
4802
|
+
inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
|
|
4803
|
+
inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
|
|
4804
|
+
inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
|
|
4805
|
+
inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
|
|
4806
|
+
inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
|
|
4807
|
+
inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
|
|
4808
|
+
inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
|
|
4809
|
+
inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
|
|
4810
|
+
inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
|
|
4811
|
+
inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
|
|
4812
|
+
inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
|
|
4813
|
+
inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
|
|
4814
|
+
inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
|
|
4815
|
+
inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
|
|
4816
|
+
inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
|
|
4817
|
+
inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
|
|
4818
|
+
inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
|
|
4819
|
+
inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
|
|
4820
|
+
inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
|
|
4821
|
+
inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
|
|
4822
|
+
inst.datetime = (params) => inst.check(datetime(params));
|
|
4823
|
+
inst.date = (params) => inst.check(date(params));
|
|
4824
|
+
inst.time = (params) => inst.check(time(params));
|
|
4825
|
+
inst.duration = (params) => inst.check(duration(params));
|
|
4826
|
+
});
|
|
4827
|
+
function string(params) {
|
|
4828
|
+
return /* @__PURE__ */ _string(ZodString, params);
|
|
4829
|
+
}
|
|
4830
|
+
const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
|
|
4831
|
+
$ZodStringFormat.init(inst, def);
|
|
4832
|
+
_ZodString.init(inst, def);
|
|
4833
|
+
});
|
|
4834
|
+
const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
|
|
4835
|
+
$ZodEmail.init(inst, def);
|
|
4836
|
+
ZodStringFormat.init(inst, def);
|
|
4837
|
+
});
|
|
4838
|
+
const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
|
|
4839
|
+
$ZodGUID.init(inst, def);
|
|
4840
|
+
ZodStringFormat.init(inst, def);
|
|
4841
|
+
});
|
|
4842
|
+
const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
|
|
4843
|
+
$ZodUUID.init(inst, def);
|
|
4844
|
+
ZodStringFormat.init(inst, def);
|
|
4845
|
+
});
|
|
4846
|
+
const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
|
|
4847
|
+
$ZodURL.init(inst, def);
|
|
4848
|
+
ZodStringFormat.init(inst, def);
|
|
4849
|
+
});
|
|
4850
|
+
const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
|
|
4851
|
+
$ZodEmoji.init(inst, def);
|
|
4852
|
+
ZodStringFormat.init(inst, def);
|
|
4853
|
+
});
|
|
4854
|
+
const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
|
|
4855
|
+
$ZodNanoID.init(inst, def);
|
|
4856
|
+
ZodStringFormat.init(inst, def);
|
|
4857
|
+
});
|
|
4858
|
+
const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
|
|
4859
|
+
$ZodCUID.init(inst, def);
|
|
4860
|
+
ZodStringFormat.init(inst, def);
|
|
4861
|
+
});
|
|
4862
|
+
const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
|
|
4863
|
+
$ZodCUID2.init(inst, def);
|
|
4864
|
+
ZodStringFormat.init(inst, def);
|
|
4865
|
+
});
|
|
4866
|
+
const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
|
|
4867
|
+
$ZodULID.init(inst, def);
|
|
4868
|
+
ZodStringFormat.init(inst, def);
|
|
4869
|
+
});
|
|
4870
|
+
const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
|
|
4871
|
+
$ZodXID.init(inst, def);
|
|
4872
|
+
ZodStringFormat.init(inst, def);
|
|
4873
|
+
});
|
|
4874
|
+
const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
|
|
4875
|
+
$ZodKSUID.init(inst, def);
|
|
4876
|
+
ZodStringFormat.init(inst, def);
|
|
4877
|
+
});
|
|
4878
|
+
const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
|
|
4879
|
+
$ZodIPv4.init(inst, def);
|
|
4880
|
+
ZodStringFormat.init(inst, def);
|
|
4881
|
+
});
|
|
4882
|
+
const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
|
|
4883
|
+
$ZodIPv6.init(inst, def);
|
|
4884
|
+
ZodStringFormat.init(inst, def);
|
|
4885
|
+
});
|
|
4886
|
+
const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
|
|
4887
|
+
$ZodCIDRv4.init(inst, def);
|
|
4888
|
+
ZodStringFormat.init(inst, def);
|
|
4889
|
+
});
|
|
4890
|
+
const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
|
|
4891
|
+
$ZodCIDRv6.init(inst, def);
|
|
4892
|
+
ZodStringFormat.init(inst, def);
|
|
4893
|
+
});
|
|
4894
|
+
const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
|
|
4895
|
+
$ZodBase64.init(inst, def);
|
|
4896
|
+
ZodStringFormat.init(inst, def);
|
|
4897
|
+
});
|
|
4898
|
+
const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
|
|
4899
|
+
$ZodBase64URL.init(inst, def);
|
|
4900
|
+
ZodStringFormat.init(inst, def);
|
|
4901
|
+
});
|
|
4902
|
+
const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
|
|
4903
|
+
$ZodE164.init(inst, def);
|
|
4904
|
+
ZodStringFormat.init(inst, def);
|
|
4905
|
+
});
|
|
4906
|
+
const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
|
|
4907
|
+
$ZodJWT.init(inst, def);
|
|
4908
|
+
ZodStringFormat.init(inst, def);
|
|
4909
|
+
});
|
|
4910
|
+
const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
|
|
4911
|
+
$ZodNumber.init(inst, def);
|
|
4912
|
+
ZodType.init(inst, def);
|
|
4913
|
+
inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
|
|
4914
|
+
inst.gt = (value, params) => inst.check(/* @__PURE__ */ _gt(value, params));
|
|
4915
|
+
inst.gte = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
|
|
4916
|
+
inst.min = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
|
|
4917
|
+
inst.lt = (value, params) => inst.check(/* @__PURE__ */ _lt(value, params));
|
|
4918
|
+
inst.lte = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
|
|
4919
|
+
inst.max = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
|
|
4920
|
+
inst.int = (params) => inst.check(int(params));
|
|
4921
|
+
inst.safe = (params) => inst.check(int(params));
|
|
4922
|
+
inst.positive = (params) => inst.check(/* @__PURE__ */ _gt(0, params));
|
|
4923
|
+
inst.nonnegative = (params) => inst.check(/* @__PURE__ */ _gte(0, params));
|
|
4924
|
+
inst.negative = (params) => inst.check(/* @__PURE__ */ _lt(0, params));
|
|
4925
|
+
inst.nonpositive = (params) => inst.check(/* @__PURE__ */ _lte(0, params));
|
|
4926
|
+
inst.multipleOf = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
4927
|
+
inst.step = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
4928
|
+
inst.finite = () => inst;
|
|
4929
|
+
const bag = inst._zod.bag;
|
|
4930
|
+
inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
4931
|
+
inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
4932
|
+
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
|
|
4933
|
+
inst.isFinite = true;
|
|
4934
|
+
inst.format = bag.format ?? null;
|
|
4935
|
+
});
|
|
4936
|
+
function number(params) {
|
|
4937
|
+
return /* @__PURE__ */ _number(ZodNumber, params);
|
|
4938
|
+
}
|
|
4939
|
+
const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
|
|
4940
|
+
$ZodNumberFormat.init(inst, def);
|
|
4941
|
+
ZodNumber.init(inst, def);
|
|
4942
|
+
});
|
|
4943
|
+
function int(params) {
|
|
4944
|
+
return /* @__PURE__ */ _int(ZodNumberFormat, params);
|
|
4945
|
+
}
|
|
4946
|
+
const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
4947
|
+
$ZodBoolean.init(inst, def);
|
|
4948
|
+
ZodType.init(inst, def);
|
|
4949
|
+
inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
|
|
4950
|
+
});
|
|
4951
|
+
function boolean(params) {
|
|
4952
|
+
return /* @__PURE__ */ _boolean(ZodBoolean, params);
|
|
4953
|
+
}
|
|
4954
|
+
const ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
4955
|
+
$ZodAny.init(inst, def);
|
|
4956
|
+
ZodType.init(inst, def);
|
|
4957
|
+
inst._zod.processJSONSchema = (ctx, json, params) => anyProcessor();
|
|
4958
|
+
});
|
|
4959
|
+
function any() {
|
|
4960
|
+
return /* @__PURE__ */ _any(ZodAny);
|
|
4961
|
+
}
|
|
4962
|
+
const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
4963
|
+
$ZodUnknown.init(inst, def);
|
|
4964
|
+
ZodType.init(inst, def);
|
|
4965
|
+
inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
|
|
4966
|
+
});
|
|
4967
|
+
function unknown() {
|
|
4968
|
+
return /* @__PURE__ */ _unknown(ZodUnknown);
|
|
4969
|
+
}
|
|
4970
|
+
const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
4971
|
+
$ZodNever.init(inst, def);
|
|
4972
|
+
ZodType.init(inst, def);
|
|
4973
|
+
inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
|
|
4974
|
+
});
|
|
4975
|
+
function never(params) {
|
|
4976
|
+
return /* @__PURE__ */ _never(ZodNever, params);
|
|
4977
|
+
}
|
|
4978
|
+
const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
4979
|
+
$ZodArray.init(inst, def);
|
|
4980
|
+
ZodType.init(inst, def);
|
|
4981
|
+
inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
|
|
4982
|
+
inst.element = def.element;
|
|
4983
|
+
inst.min = (minLength, params) => inst.check(/* @__PURE__ */ _minLength(minLength, params));
|
|
4984
|
+
inst.nonempty = (params) => inst.check(/* @__PURE__ */ _minLength(1, params));
|
|
4985
|
+
inst.max = (maxLength, params) => inst.check(/* @__PURE__ */ _maxLength(maxLength, params));
|
|
4986
|
+
inst.length = (len, params) => inst.check(/* @__PURE__ */ _length(len, params));
|
|
4987
|
+
inst.unwrap = () => inst.element;
|
|
4988
|
+
});
|
|
4989
|
+
function array(element, params) {
|
|
4990
|
+
return /* @__PURE__ */ _array(ZodArray, element, params);
|
|
4991
|
+
}
|
|
4992
|
+
const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
4993
|
+
$ZodObjectJIT.init(inst, def);
|
|
4994
|
+
ZodType.init(inst, def);
|
|
4995
|
+
inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
|
|
4996
|
+
defineLazy(inst, "shape", () => {
|
|
4997
|
+
return def.shape;
|
|
4998
|
+
});
|
|
4999
|
+
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
5000
|
+
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
5001
|
+
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
5002
|
+
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
5003
|
+
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
5004
|
+
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: void 0 });
|
|
5005
|
+
inst.extend = (incoming) => {
|
|
5006
|
+
return extend(inst, incoming);
|
|
5007
|
+
};
|
|
5008
|
+
inst.safeExtend = (incoming) => {
|
|
5009
|
+
return safeExtend(inst, incoming);
|
|
5010
|
+
};
|
|
5011
|
+
inst.merge = (other) => merge(inst, other);
|
|
5012
|
+
inst.pick = (mask) => pick(inst, mask);
|
|
5013
|
+
inst.omit = (mask) => omit(inst, mask);
|
|
5014
|
+
inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
|
|
5015
|
+
inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
|
|
5016
|
+
});
|
|
5017
|
+
function object(shape, params) {
|
|
5018
|
+
const def = {
|
|
5019
|
+
type: "object",
|
|
5020
|
+
shape: shape ?? {},
|
|
5021
|
+
...normalizeParams(params)
|
|
5022
|
+
};
|
|
5023
|
+
return new ZodObject(def);
|
|
5024
|
+
}
|
|
5025
|
+
const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
|
|
5026
|
+
$ZodUnion.init(inst, def);
|
|
5027
|
+
ZodType.init(inst, def);
|
|
5028
|
+
inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
|
|
5029
|
+
inst.options = def.options;
|
|
5030
|
+
});
|
|
5031
|
+
function union(options, params) {
|
|
5032
|
+
return new ZodUnion({
|
|
5033
|
+
type: "union",
|
|
5034
|
+
options,
|
|
5035
|
+
...normalizeParams(params)
|
|
5036
|
+
});
|
|
5037
|
+
}
|
|
5038
|
+
const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
5039
|
+
$ZodIntersection.init(inst, def);
|
|
5040
|
+
ZodType.init(inst, def);
|
|
5041
|
+
inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
|
|
5042
|
+
});
|
|
5043
|
+
function intersection(left, right) {
|
|
5044
|
+
return new ZodIntersection({
|
|
5045
|
+
type: "intersection",
|
|
5046
|
+
left,
|
|
5047
|
+
right
|
|
5048
|
+
});
|
|
5049
|
+
}
|
|
5050
|
+
const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
5051
|
+
$ZodEnum.init(inst, def);
|
|
5052
|
+
ZodType.init(inst, def);
|
|
5053
|
+
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
|
|
5054
|
+
inst.enum = def.entries;
|
|
5055
|
+
inst.options = Object.values(def.entries);
|
|
5056
|
+
const keys = new Set(Object.keys(def.entries));
|
|
5057
|
+
inst.extract = (values, params) => {
|
|
5058
|
+
const newEntries = {};
|
|
5059
|
+
for (const value of values) {
|
|
5060
|
+
if (keys.has(value)) {
|
|
5061
|
+
newEntries[value] = def.entries[value];
|
|
5062
|
+
} else
|
|
5063
|
+
throw new Error(`Key ${value} not found in enum`);
|
|
5064
|
+
}
|
|
5065
|
+
return new ZodEnum({
|
|
5066
|
+
...def,
|
|
5067
|
+
checks: [],
|
|
5068
|
+
...normalizeParams(params),
|
|
5069
|
+
entries: newEntries
|
|
5070
|
+
});
|
|
5071
|
+
};
|
|
5072
|
+
inst.exclude = (values, params) => {
|
|
5073
|
+
const newEntries = { ...def.entries };
|
|
5074
|
+
for (const value of values) {
|
|
5075
|
+
if (keys.has(value)) {
|
|
5076
|
+
delete newEntries[value];
|
|
5077
|
+
} else
|
|
5078
|
+
throw new Error(`Key ${value} not found in enum`);
|
|
5079
|
+
}
|
|
5080
|
+
return new ZodEnum({
|
|
5081
|
+
...def,
|
|
5082
|
+
checks: [],
|
|
5083
|
+
...normalizeParams(params),
|
|
5084
|
+
entries: newEntries
|
|
5085
|
+
});
|
|
5086
|
+
};
|
|
5087
|
+
});
|
|
5088
|
+
function _enum(values, params) {
|
|
5089
|
+
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
5090
|
+
return new ZodEnum({
|
|
5091
|
+
type: "enum",
|
|
5092
|
+
entries,
|
|
5093
|
+
...normalizeParams(params)
|
|
5094
|
+
});
|
|
5095
|
+
}
|
|
5096
|
+
const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
5097
|
+
$ZodTransform.init(inst, def);
|
|
5098
|
+
ZodType.init(inst, def);
|
|
5099
|
+
inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
|
|
5100
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
5101
|
+
if (_ctx.direction === "backward") {
|
|
5102
|
+
throw new $ZodEncodeError(inst.constructor.name);
|
|
5103
|
+
}
|
|
5104
|
+
payload.addIssue = (issue$1) => {
|
|
5105
|
+
if (typeof issue$1 === "string") {
|
|
5106
|
+
payload.issues.push(issue(issue$1, payload.value, def));
|
|
5107
|
+
} else {
|
|
5108
|
+
const _issue = issue$1;
|
|
5109
|
+
if (_issue.fatal)
|
|
5110
|
+
_issue.continue = false;
|
|
5111
|
+
_issue.code ?? (_issue.code = "custom");
|
|
5112
|
+
_issue.input ?? (_issue.input = payload.value);
|
|
5113
|
+
_issue.inst ?? (_issue.inst = inst);
|
|
5114
|
+
payload.issues.push(issue(_issue));
|
|
5115
|
+
}
|
|
5116
|
+
};
|
|
5117
|
+
const output = def.transform(payload.value, payload);
|
|
5118
|
+
if (output instanceof Promise) {
|
|
5119
|
+
return output.then((output2) => {
|
|
5120
|
+
payload.value = output2;
|
|
5121
|
+
return payload;
|
|
5122
|
+
});
|
|
5123
|
+
}
|
|
5124
|
+
payload.value = output;
|
|
5125
|
+
return payload;
|
|
5126
|
+
};
|
|
5127
|
+
});
|
|
5128
|
+
function transform(fn) {
|
|
5129
|
+
return new ZodTransform({
|
|
5130
|
+
type: "transform",
|
|
5131
|
+
transform: fn
|
|
5132
|
+
});
|
|
5133
|
+
}
|
|
5134
|
+
const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
5135
|
+
$ZodOptional.init(inst, def);
|
|
5136
|
+
ZodType.init(inst, def);
|
|
5137
|
+
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
|
|
5138
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5139
|
+
});
|
|
5140
|
+
function optional(innerType) {
|
|
5141
|
+
return new ZodOptional({
|
|
5142
|
+
type: "optional",
|
|
5143
|
+
innerType
|
|
5144
|
+
});
|
|
5145
|
+
}
|
|
5146
|
+
const ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
|
|
5147
|
+
$ZodExactOptional.init(inst, def);
|
|
5148
|
+
ZodType.init(inst, def);
|
|
5149
|
+
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
|
|
5150
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5151
|
+
});
|
|
5152
|
+
function exactOptional(innerType) {
|
|
5153
|
+
return new ZodExactOptional({
|
|
5154
|
+
type: "optional",
|
|
5155
|
+
innerType
|
|
5156
|
+
});
|
|
5157
|
+
}
|
|
5158
|
+
const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
|
|
5159
|
+
$ZodNullable.init(inst, def);
|
|
5160
|
+
ZodType.init(inst, def);
|
|
5161
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
|
|
5162
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5163
|
+
});
|
|
5164
|
+
function nullable(innerType) {
|
|
5165
|
+
return new ZodNullable({
|
|
5166
|
+
type: "nullable",
|
|
5167
|
+
innerType
|
|
5168
|
+
});
|
|
5169
|
+
}
|
|
5170
|
+
const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
|
|
5171
|
+
$ZodDefault.init(inst, def);
|
|
5172
|
+
ZodType.init(inst, def);
|
|
5173
|
+
inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
|
|
5174
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5175
|
+
inst.removeDefault = inst.unwrap;
|
|
5176
|
+
});
|
|
5177
|
+
function _default(innerType, defaultValue) {
|
|
5178
|
+
return new ZodDefault({
|
|
5179
|
+
type: "default",
|
|
5180
|
+
innerType,
|
|
5181
|
+
get defaultValue() {
|
|
5182
|
+
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
|
|
5183
|
+
}
|
|
5184
|
+
});
|
|
5185
|
+
}
|
|
5186
|
+
const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
|
|
5187
|
+
$ZodPrefault.init(inst, def);
|
|
5188
|
+
ZodType.init(inst, def);
|
|
5189
|
+
inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
|
|
5190
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5191
|
+
});
|
|
5192
|
+
function prefault(innerType, defaultValue) {
|
|
5193
|
+
return new ZodPrefault({
|
|
5194
|
+
type: "prefault",
|
|
5195
|
+
innerType,
|
|
5196
|
+
get defaultValue() {
|
|
5197
|
+
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
|
|
5198
|
+
}
|
|
5199
|
+
});
|
|
5200
|
+
}
|
|
5201
|
+
const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
|
|
5202
|
+
$ZodNonOptional.init(inst, def);
|
|
5203
|
+
ZodType.init(inst, def);
|
|
5204
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
|
|
5205
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5206
|
+
});
|
|
5207
|
+
function nonoptional(innerType, params) {
|
|
5208
|
+
return new ZodNonOptional({
|
|
5209
|
+
type: "nonoptional",
|
|
5210
|
+
innerType,
|
|
5211
|
+
...normalizeParams(params)
|
|
5212
|
+
});
|
|
5213
|
+
}
|
|
5214
|
+
const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
|
|
5215
|
+
$ZodCatch.init(inst, def);
|
|
5216
|
+
ZodType.init(inst, def);
|
|
5217
|
+
inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
|
|
5218
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5219
|
+
inst.removeCatch = inst.unwrap;
|
|
5220
|
+
});
|
|
5221
|
+
function _catch(innerType, catchValue) {
|
|
5222
|
+
return new ZodCatch({
|
|
5223
|
+
type: "catch",
|
|
5224
|
+
innerType,
|
|
5225
|
+
catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
|
|
5226
|
+
});
|
|
5227
|
+
}
|
|
5228
|
+
const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
5229
|
+
$ZodPipe.init(inst, def);
|
|
5230
|
+
ZodType.init(inst, def);
|
|
5231
|
+
inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
|
|
5232
|
+
inst.in = def.in;
|
|
5233
|
+
inst.out = def.out;
|
|
5234
|
+
});
|
|
5235
|
+
function pipe(in_, out) {
|
|
5236
|
+
return new ZodPipe({
|
|
5237
|
+
type: "pipe",
|
|
5238
|
+
in: in_,
|
|
5239
|
+
out
|
|
5240
|
+
// ...util.normalizeParams(params),
|
|
5241
|
+
});
|
|
5242
|
+
}
|
|
5243
|
+
const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
5244
|
+
$ZodReadonly.init(inst, def);
|
|
5245
|
+
ZodType.init(inst, def);
|
|
5246
|
+
inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
|
|
5247
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
5248
|
+
});
|
|
5249
|
+
function readonly(innerType) {
|
|
5250
|
+
return new ZodReadonly({
|
|
5251
|
+
type: "readonly",
|
|
5252
|
+
innerType
|
|
5253
|
+
});
|
|
5254
|
+
}
|
|
5255
|
+
const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
5256
|
+
$ZodCustom.init(inst, def);
|
|
5257
|
+
ZodType.init(inst, def);
|
|
5258
|
+
inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
|
|
5259
|
+
});
|
|
5260
|
+
function refine(fn, _params = {}) {
|
|
5261
|
+
return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
|
|
5262
|
+
}
|
|
5263
|
+
function superRefine(fn) {
|
|
5264
|
+
return /* @__PURE__ */ _superRefine(fn);
|
|
5265
|
+
}
|
|
5266
|
+
object({
|
|
5267
|
+
success: boolean(),
|
|
5268
|
+
accessToken: string().optional(),
|
|
5269
|
+
alias: string().optional(),
|
|
5270
|
+
user: object({
|
|
5271
|
+
id: string(),
|
|
5272
|
+
email: string(),
|
|
5273
|
+
role: string(),
|
|
5274
|
+
validated: boolean(),
|
|
5275
|
+
active: boolean()
|
|
5276
|
+
}).optional(),
|
|
5277
|
+
person: object({
|
|
5278
|
+
id: string(),
|
|
5279
|
+
name: string(),
|
|
5280
|
+
birth_date: string()
|
|
5281
|
+
}).optional(),
|
|
5282
|
+
confidence_score: number().optional(),
|
|
5283
|
+
recognition_id: string().optional(),
|
|
5284
|
+
task_id: string().optional(),
|
|
5285
|
+
status: string().optional(),
|
|
5286
|
+
message: string().optional()
|
|
5287
|
+
});
|
|
5288
|
+
object({
|
|
5289
|
+
success: boolean(),
|
|
5290
|
+
message: string(),
|
|
5291
|
+
person_id: string().optional(),
|
|
5292
|
+
user_id: string().optional(),
|
|
5293
|
+
person_validated: boolean().optional(),
|
|
5294
|
+
face_processing: any().optional(),
|
|
5295
|
+
onboarding_link: string().optional(),
|
|
5296
|
+
task_id: string().optional(),
|
|
5297
|
+
status: string().optional()
|
|
5298
|
+
});
|
|
1166
5299
|
const __vite_import_meta_env__ = {};
|
|
1167
5300
|
const ENVIRONMENT_URLS = {
|
|
1168
5301
|
development: "http://localhost:8000",
|
|
@@ -1416,17 +5549,30 @@ const completeOnboarding = async (applicationToken, onboardingToken, faceImage,
|
|
|
1416
5549
|
const compressedFace = await compressImage(faceImage);
|
|
1417
5550
|
const compressedDocument = await compressImage(documentImage);
|
|
1418
5551
|
try {
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1421
|
-
|
|
5552
|
+
const faceBase64 = await new Promise((resolve, reject) => {
|
|
5553
|
+
const reader = new FileReader();
|
|
5554
|
+
reader.onload = () => resolve(reader.result);
|
|
5555
|
+
reader.onerror = reject;
|
|
5556
|
+
reader.readAsDataURL(compressedFace);
|
|
5557
|
+
});
|
|
5558
|
+
const documentBase64 = await new Promise((resolve, reject) => {
|
|
5559
|
+
const reader = new FileReader();
|
|
5560
|
+
reader.onload = () => resolve(reader.result);
|
|
5561
|
+
reader.onerror = reject;
|
|
5562
|
+
reader.readAsDataURL(compressedDocument);
|
|
5563
|
+
});
|
|
1422
5564
|
const response = await fetch(
|
|
1423
5565
|
`${getApiBaseUrl()}/api/v1/onboardings/${encodeURIComponent(onboardingToken)}/complete`,
|
|
1424
5566
|
{
|
|
1425
5567
|
method: "POST",
|
|
1426
5568
|
headers: {
|
|
5569
|
+
"Content-Type": "application/json",
|
|
1427
5570
|
"X-App-Token": applicationToken
|
|
1428
5571
|
},
|
|
1429
|
-
body:
|
|
5572
|
+
body: JSON.stringify({
|
|
5573
|
+
face_image: faceBase64,
|
|
5574
|
+
document_image: documentBase64
|
|
5575
|
+
}),
|
|
1430
5576
|
signal: controller.signal
|
|
1431
5577
|
}
|
|
1432
5578
|
);
|
|
@@ -1474,36 +5620,42 @@ const completeOnboardingWithData = async (applicationToken, onboardingToken, per
|
|
|
1474
5620
|
}
|
|
1475
5621
|
const controller = createTimeoutController();
|
|
1476
5622
|
try {
|
|
1477
|
-
const
|
|
5623
|
+
const faceImagesBase64 = await Promise.all(
|
|
5624
|
+
personImages.map(async (img) => {
|
|
5625
|
+
const compressed = await compressImage(img);
|
|
5626
|
+
return new Promise((resolve, reject) => {
|
|
5627
|
+
const reader = new FileReader();
|
|
5628
|
+
reader.onload = () => resolve(reader.result);
|
|
5629
|
+
reader.onerror = reject;
|
|
5630
|
+
reader.readAsDataURL(compressed);
|
|
5631
|
+
});
|
|
5632
|
+
})
|
|
5633
|
+
);
|
|
1478
5634
|
const compressedDocument = await compressImage(documentImage);
|
|
1479
|
-
const
|
|
1480
|
-
|
|
1481
|
-
|
|
5635
|
+
const documentBase64 = await new Promise((resolve, reject) => {
|
|
5636
|
+
const reader = new FileReader();
|
|
5637
|
+
reader.onload = () => resolve(reader.result);
|
|
5638
|
+
reader.onerror = reject;
|
|
5639
|
+
reader.readAsDataURL(compressedDocument);
|
|
1482
5640
|
});
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
}
|
|
1493
|
-
if (personData.cnpj) {
|
|
1494
|
-
formData.append("cnpj", personData.cnpj);
|
|
1495
|
-
}
|
|
1496
|
-
if (personData.email) {
|
|
1497
|
-
formData.append("email", personData.email);
|
|
1498
|
-
}
|
|
5641
|
+
const body = {
|
|
5642
|
+
person_images: faceImagesBase64,
|
|
5643
|
+
document_image: documentBase64,
|
|
5644
|
+
name: personData.name,
|
|
5645
|
+
birth_date: personData.birth_date,
|
|
5646
|
+
cpf: personData.cpf,
|
|
5647
|
+
cnpj: personData.cnpj,
|
|
5648
|
+
email: personData.email
|
|
5649
|
+
};
|
|
1499
5650
|
const response = await fetch(
|
|
1500
5651
|
`${getApiBaseUrl()}/api/v1/onboardings/${encodeURIComponent(onboardingToken)}/complete`,
|
|
1501
5652
|
{
|
|
1502
5653
|
method: "POST",
|
|
1503
5654
|
headers: {
|
|
5655
|
+
"Content-Type": "application/json",
|
|
1504
5656
|
"X-App-Token": applicationToken
|
|
1505
5657
|
},
|
|
1506
|
-
body:
|
|
5658
|
+
body: JSON.stringify(body),
|
|
1507
5659
|
signal: controller.signal
|
|
1508
5660
|
}
|
|
1509
5661
|
);
|
|
@@ -1549,14 +5701,24 @@ const recognize = async (image, applicationToken) => {
|
|
|
1549
5701
|
const controller = createTimeoutController();
|
|
1550
5702
|
const compressedImage = await compressImage(image);
|
|
1551
5703
|
try {
|
|
1552
|
-
const
|
|
1553
|
-
|
|
5704
|
+
const base64Image = await new Promise((resolve, reject) => {
|
|
5705
|
+
const reader = new FileReader();
|
|
5706
|
+
reader.onload = () => {
|
|
5707
|
+
const result = reader.result;
|
|
5708
|
+
resolve(result.split(",")[1]);
|
|
5709
|
+
};
|
|
5710
|
+
reader.onerror = reject;
|
|
5711
|
+
reader.readAsDataURL(compressedImage);
|
|
5712
|
+
});
|
|
1554
5713
|
const response = await fetch(`${getApiBaseUrl()}/api/v1/external/recognition/face/`, {
|
|
1555
5714
|
method: "POST",
|
|
1556
5715
|
headers: {
|
|
5716
|
+
"Content-Type": "application/json",
|
|
1557
5717
|
"X-App-Token": applicationToken
|
|
1558
5718
|
},
|
|
1559
|
-
body:
|
|
5719
|
+
body: JSON.stringify({
|
|
5720
|
+
face_frames: base64Image
|
|
5721
|
+
}),
|
|
1560
5722
|
signal: controller.signal
|
|
1561
5723
|
});
|
|
1562
5724
|
if (!response.ok) {
|
|
@@ -1587,7 +5749,7 @@ const recognize = async (image, applicationToken) => {
|
|
|
1587
5749
|
}
|
|
1588
5750
|
};
|
|
1589
5751
|
const loginWithBiometric = async (image, applicationToken) => {
|
|
1590
|
-
var
|
|
5752
|
+
var _a2, _b, _c, _d, _e;
|
|
1591
5753
|
ensureSecureContext();
|
|
1592
5754
|
const controller = createTimeoutController();
|
|
1593
5755
|
const compressedImage = await compressImage(image);
|
|
@@ -1626,7 +5788,7 @@ const loginWithBiometric = async (image, applicationToken) => {
|
|
|
1626
5788
|
accessToken: data.accessToken || data.access_token || "",
|
|
1627
5789
|
alias: data.alias,
|
|
1628
5790
|
user: {
|
|
1629
|
-
id: ((
|
|
5791
|
+
id: ((_a2 = data.user) == null ? void 0 : _a2.id) || "",
|
|
1630
5792
|
email: ((_b = data.user) == null ? void 0 : _b.email) || "",
|
|
1631
5793
|
role: ((_c = data.user) == null ? void 0 : _c.role) || "",
|
|
1632
5794
|
validated: ((_d = data.user) == null ? void 0 : _d.validated) || false,
|
|
@@ -1658,16 +5820,26 @@ const recognizeBiometric = async (image, applicationToken, livenessCheck = true,
|
|
|
1658
5820
|
const controller = createTimeoutController();
|
|
1659
5821
|
const compressedImage = await compressImage(image);
|
|
1660
5822
|
try {
|
|
1661
|
-
const
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
5823
|
+
const base64Image = await new Promise((resolve, reject) => {
|
|
5824
|
+
const reader = new FileReader();
|
|
5825
|
+
reader.onload = () => {
|
|
5826
|
+
const result = reader.result;
|
|
5827
|
+
resolve(result.split(",")[1]);
|
|
5828
|
+
};
|
|
5829
|
+
reader.onerror = reject;
|
|
5830
|
+
reader.readAsDataURL(compressedImage);
|
|
5831
|
+
});
|
|
1665
5832
|
const response = await fetch(`${getApiBaseUrl()}/api/v1/external/recognition/biometric/`, {
|
|
1666
5833
|
method: "POST",
|
|
1667
5834
|
headers: {
|
|
5835
|
+
"Content-Type": "application/json",
|
|
1668
5836
|
"X-App-Token": applicationToken
|
|
1669
5837
|
},
|
|
1670
|
-
body:
|
|
5838
|
+
body: JSON.stringify({
|
|
5839
|
+
face_frames: base64Image,
|
|
5840
|
+
liveness_check: livenessCheck,
|
|
5841
|
+
confidence_threshold: confidenceThreshold
|
|
5842
|
+
}),
|
|
1671
5843
|
signal: controller.signal
|
|
1672
5844
|
});
|
|
1673
5845
|
if (!response.ok) {
|
|
@@ -1744,7 +5916,7 @@ const simpleIdentification = async (documentType, documentNumber, applicationTok
|
|
|
1744
5916
|
}
|
|
1745
5917
|
};
|
|
1746
5918
|
const recognizeByPurpose = async (image, applicationToken, purpose, confidenceThreshold = 0.8, signature, sessionData) => {
|
|
1747
|
-
var
|
|
5919
|
+
var _a2;
|
|
1748
5920
|
ensureSecureContext();
|
|
1749
5921
|
const controller = createTimeoutController();
|
|
1750
5922
|
const compressedImage = await compressImage(image);
|
|
@@ -1785,7 +5957,7 @@ const recognizeByPurpose = async (image, applicationToken, purpose, confidenceTh
|
|
|
1785
5957
|
const data = await response.json();
|
|
1786
5958
|
return {
|
|
1787
5959
|
success: data.success,
|
|
1788
|
-
personName: data.person_name || ((
|
|
5960
|
+
personName: data.person_name || ((_a2 = data.person) == null ? void 0 : _a2.name),
|
|
1789
5961
|
email: data.email || (sessionData == null ? void 0 : sessionData.email),
|
|
1790
5962
|
cpf: data.cpf || (sessionData == null ? void 0 : sessionData.cpf),
|
|
1791
5963
|
confidenceScore: data.confidence_score,
|
|
@@ -1919,7 +6091,7 @@ const checkUserExistence = async (params) => {
|
|
|
1919
6091
|
}
|
|
1920
6092
|
};
|
|
1921
6093
|
const registerPersonWithBiometric = async (personData, facePhotos, applicationToken, options) => {
|
|
1922
|
-
var
|
|
6094
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
1923
6095
|
ensureSecureContext();
|
|
1924
6096
|
if (!facePhotos || facePhotos.length === 0) {
|
|
1925
6097
|
throw new NeoFaceError(
|
|
@@ -2030,7 +6202,7 @@ const registerPersonWithBiometric = async (personData, facePhotos, applicationTo
|
|
|
2030
6202
|
}
|
|
2031
6203
|
}
|
|
2032
6204
|
const data = await response.json();
|
|
2033
|
-
if (response.status === 202 && ((
|
|
6205
|
+
if (response.status === 202 && ((_a2 = data.data) == null ? void 0 : _a2.task_id)) {
|
|
2034
6206
|
return {
|
|
2035
6207
|
success: data.success,
|
|
2036
6208
|
message: data.message || "Registration is being processed. You will receive an email when completed.",
|
|
@@ -2067,7 +6239,7 @@ const registerPersonWithBiometric = async (personData, facePhotos, applicationTo
|
|
|
2067
6239
|
throw new NeoFaceError("Unknown error occurred", ErrorType.NETWORK_ERROR);
|
|
2068
6240
|
}
|
|
2069
6241
|
};
|
|
2070
|
-
const loginWithEmail = async (
|
|
6242
|
+
const loginWithEmail = async (email2, password, applicationToken) => {
|
|
2071
6243
|
const controller = createTimeoutController();
|
|
2072
6244
|
try {
|
|
2073
6245
|
const response = await fetch(`${getApiBaseUrl()}/api/v1/auth/login/`, {
|
|
@@ -2076,7 +6248,7 @@ const loginWithEmail = async (email, password, applicationToken) => {
|
|
|
2076
6248
|
"Content-Type": "application/json",
|
|
2077
6249
|
"X-App-Token": applicationToken
|
|
2078
6250
|
},
|
|
2079
|
-
body: JSON.stringify({ email, password }),
|
|
6251
|
+
body: JSON.stringify({ email: email2, password }),
|
|
2080
6252
|
signal: controller.signal
|
|
2081
6253
|
});
|
|
2082
6254
|
if (!response.ok) {
|
|
@@ -2113,7 +6285,7 @@ const loginWithEmail = async (email, password, applicationToken) => {
|
|
|
2113
6285
|
}
|
|
2114
6286
|
};
|
|
2115
6287
|
const identifyPerson = async (image, applicationToken) => {
|
|
2116
|
-
var
|
|
6288
|
+
var _a2, _b, _c, _d;
|
|
2117
6289
|
ensureSecureContext();
|
|
2118
6290
|
const controller = createTimeoutController();
|
|
2119
6291
|
const compressedImage = await compressDocumentImage(image);
|
|
@@ -2149,7 +6321,7 @@ const identifyPerson = async (image, applicationToken) => {
|
|
|
2149
6321
|
if (response.status === 202 || data.data && data.data.task_id) {
|
|
2150
6322
|
return {
|
|
2151
6323
|
success: true,
|
|
2152
|
-
taskId: ((
|
|
6324
|
+
taskId: ((_a2 = data.data) == null ? void 0 : _a2.task_id) || data.task_id,
|
|
2153
6325
|
status: ((_b = data.data) == null ? void 0 : _b.status) || "processing",
|
|
2154
6326
|
message: data.message || "Identification scheduled"
|
|
2155
6327
|
};
|
|
@@ -2424,7 +6596,7 @@ const recordFaceVideo = async (options = {}) => {
|
|
|
2424
6596
|
});
|
|
2425
6597
|
};
|
|
2426
6598
|
const pollTaskStatus = async (taskId, applicationToken, options = {}) => {
|
|
2427
|
-
var
|
|
6599
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2428
6600
|
const { maxAttempts = 60, intervalMs = 1e3, onStatusChange } = options;
|
|
2429
6601
|
let attempts = 0;
|
|
2430
6602
|
while (attempts < maxAttempts) {
|
|
@@ -2441,7 +6613,7 @@ const pollTaskStatus = async (taskId, applicationToken, options = {}) => {
|
|
|
2441
6613
|
throw new NeoFaceError(`Task status check failed: ${response.status}`, ErrorType.NETWORK);
|
|
2442
6614
|
}
|
|
2443
6615
|
const data = await response.json();
|
|
2444
|
-
const status = ((
|
|
6616
|
+
const status = ((_a2 = data.data) == null ? void 0 : _a2.status) || "unknown";
|
|
2445
6617
|
if (onStatusChange) {
|
|
2446
6618
|
const progress = (_c = (_b = data.data) == null ? void 0 : _b.progress) == null ? void 0 : _c.percentage;
|
|
2447
6619
|
onStatusChange(status, progress);
|
|
@@ -2470,7 +6642,7 @@ const pollTaskStatus = async (taskId, applicationToken, options = {}) => {
|
|
|
2470
6642
|
throw new NeoFaceError("Task status polling timed out", ErrorType.NETWORK);
|
|
2471
6643
|
};
|
|
2472
6644
|
const startProofOfLife = async (videoBase64, applicationToken) => {
|
|
2473
|
-
var
|
|
6645
|
+
var _a2;
|
|
2474
6646
|
ensureSecureContext();
|
|
2475
6647
|
const controller = createTimeoutController();
|
|
2476
6648
|
try {
|
|
@@ -2500,7 +6672,7 @@ const startProofOfLife = async (videoBase64, applicationToken) => {
|
|
|
2500
6672
|
throw new NeoFaceError(`Server returned status ${response.status}`, ErrorType.NETWORK);
|
|
2501
6673
|
}
|
|
2502
6674
|
const data = await response.json();
|
|
2503
|
-
if (!data.success || !((
|
|
6675
|
+
if (!data.success || !((_a2 = data.data) == null ? void 0 : _a2.task_id)) {
|
|
2504
6676
|
throw new NeoFaceError(
|
|
2505
6677
|
data.message || "Failed to start proof of life",
|
|
2506
6678
|
ErrorType.RECOGNITION_FAILED
|
|
@@ -2530,8 +6702,8 @@ const videoToBase64 = async (videoBlob) => {
|
|
|
2530
6702
|
const reader = new FileReader();
|
|
2531
6703
|
reader.onload = () => {
|
|
2532
6704
|
const result = reader.result;
|
|
2533
|
-
const
|
|
2534
|
-
resolve(
|
|
6705
|
+
const base642 = result.includes(",") ? result.split(",")[1] : result;
|
|
6706
|
+
resolve(base642);
|
|
2535
6707
|
};
|
|
2536
6708
|
reader.onerror = () => reject(new NeoFaceError("Failed to convert video to base64", ErrorType.CAPTURE_ERROR));
|
|
2537
6709
|
reader.readAsDataURL(videoBlob);
|
|
@@ -2547,7 +6719,7 @@ const blobToBase64 = (blob) => new Promise((resolve, reject) => {
|
|
|
2547
6719
|
reader.readAsDataURL(blob);
|
|
2548
6720
|
});
|
|
2549
6721
|
const registerDocumentByImage = async (personId, jwtToken, images) => {
|
|
2550
|
-
var
|
|
6722
|
+
var _a2, _b;
|
|
2551
6723
|
ensureSecureContext();
|
|
2552
6724
|
if (!personId) {
|
|
2553
6725
|
throw new NeoFaceError("personId is required", ErrorType.VALIDATION_ERROR);
|
|
@@ -2584,7 +6756,7 @@ const registerDocumentByImage = async (personId, jwtToken, images) => {
|
|
|
2584
6756
|
}
|
|
2585
6757
|
return {
|
|
2586
6758
|
success: true,
|
|
2587
|
-
taskId: ((
|
|
6759
|
+
taskId: ((_a2 = data.data) == null ? void 0 : _a2.task_id) ?? "",
|
|
2588
6760
|
status: ((_b = data.data) == null ? void 0 : _b.status) ?? "processing",
|
|
2589
6761
|
message: data.message ?? "Documents submitted for processing"
|
|
2590
6762
|
};
|
|
@@ -2628,7 +6800,7 @@ const getTaskStatus = async (taskId) => {
|
|
|
2628
6800
|
}
|
|
2629
6801
|
};
|
|
2630
6802
|
const identifyPersonAsync = async (image, applicationToken, options = {}) => {
|
|
2631
|
-
var
|
|
6803
|
+
var _a2, _b;
|
|
2632
6804
|
const { maxRetries = 30, interval = 2e3 } = options;
|
|
2633
6805
|
const initialResponse = await identifyPerson(image, applicationToken);
|
|
2634
6806
|
if (initialResponse.person) {
|
|
@@ -2648,7 +6820,7 @@ const identifyPersonAsync = async (image, applicationToken, options = {}) => {
|
|
|
2648
6820
|
return {
|
|
2649
6821
|
personFound: true,
|
|
2650
6822
|
person: {
|
|
2651
|
-
name: ((
|
|
6823
|
+
name: ((_a2 = status.result.person) == null ? void 0 : _a2.name) || "Pessoa identificada",
|
|
2652
6824
|
birth_date: ((_b = status.result.person) == null ? void 0 : _b.birth_date) || ""
|
|
2653
6825
|
}
|
|
2654
6826
|
};
|
|
@@ -2662,7 +6834,7 @@ const identifyPersonAsync = async (image, applicationToken, options = {}) => {
|
|
|
2662
6834
|
}
|
|
2663
6835
|
throw new NeoFaceError("Timed out waiting for identification", ErrorType.NETWORK_ERROR);
|
|
2664
6836
|
};
|
|
2665
|
-
async function requestPasswordReset(
|
|
6837
|
+
async function requestPasswordReset(email2, applicationToken) {
|
|
2666
6838
|
const baseUrl = getBaseUrl();
|
|
2667
6839
|
const response = await fetch(`${baseUrl}/api/v1/user/password/reset/request/`, {
|
|
2668
6840
|
method: "POST",
|
|
@@ -2670,7 +6842,7 @@ async function requestPasswordReset(email, applicationToken) {
|
|
|
2670
6842
|
"Content-Type": "application/json",
|
|
2671
6843
|
"X-App-Token": applicationToken
|
|
2672
6844
|
},
|
|
2673
|
-
body: JSON.stringify({ email })
|
|
6845
|
+
body: JSON.stringify({ email: email2 })
|
|
2674
6846
|
});
|
|
2675
6847
|
if (!response.ok) {
|
|
2676
6848
|
const errorData = await response.json();
|
|
@@ -2917,8 +7089,8 @@ function FaceCaptureModal({ accessToken, onClose, onSuccess }) {
|
|
|
2917
7089
|
const loadModels = async () => {
|
|
2918
7090
|
try {
|
|
2919
7091
|
await Promise.all([
|
|
2920
|
-
faceapi.nets.tinyFaceDetector.loadFromUri("
|
|
2921
|
-
faceapi.nets.faceLandmark68Net.loadFromUri("
|
|
7092
|
+
faceapi.nets.tinyFaceDetector.loadFromUri("/models"),
|
|
7093
|
+
faceapi.nets.faceLandmark68Net.loadFromUri("/models")
|
|
2922
7094
|
]);
|
|
2923
7095
|
} catch (error) {
|
|
2924
7096
|
console.error("Failed to load face-api.js models:", error);
|
|
@@ -2968,8 +7140,8 @@ function FaceCaptureModal({ accessToken, onClose, onSuccess }) {
|
|
|
2968
7140
|
canvasRef.current.height = videoRef.current.videoHeight;
|
|
2969
7141
|
context.drawImage(videoRef.current, 0, 0, canvasRef.current.width, canvasRef.current.height);
|
|
2970
7142
|
const blob = await new Promise((resolve, reject) => {
|
|
2971
|
-
var
|
|
2972
|
-
(
|
|
7143
|
+
var _a2;
|
|
7144
|
+
(_a2 = canvasRef.current) == null ? void 0 : _a2.toBlob(
|
|
2973
7145
|
(b) => {
|
|
2974
7146
|
if (b) resolve(b);
|
|
2975
7147
|
else reject(new Error("Failed to convert canvas to blob"));
|
|
@@ -3123,22 +7295,22 @@ class ForgotPasswordModal {
|
|
|
3123
7295
|
closeBtn.addEventListener("click", this.close.bind(this));
|
|
3124
7296
|
}
|
|
3125
7297
|
async handleSubmit(e) {
|
|
3126
|
-
var
|
|
7298
|
+
var _a2, _b, _c, _d;
|
|
3127
7299
|
e.preventDefault();
|
|
3128
|
-
const emailInput = (
|
|
7300
|
+
const emailInput = (_a2 = this.modalElement) == null ? void 0 : _a2.querySelector(
|
|
3129
7301
|
"#neoface-forgot-email"
|
|
3130
7302
|
);
|
|
3131
7303
|
const submitBtn = (_b = this.modalElement) == null ? void 0 : _b.querySelector(
|
|
3132
7304
|
".neoface-forgot-btn-primary"
|
|
3133
7305
|
);
|
|
3134
7306
|
const errorEl = (_c = this.modalElement) == null ? void 0 : _c.querySelector("#neoface-forgot-error");
|
|
3135
|
-
const
|
|
3136
|
-
if (!
|
|
7307
|
+
const email2 = (_d = emailInput == null ? void 0 : emailInput.value) == null ? void 0 : _d.trim();
|
|
7308
|
+
if (!email2) return;
|
|
3137
7309
|
submitBtn.disabled = true;
|
|
3138
7310
|
submitBtn.textContent = "Enviando...";
|
|
3139
7311
|
errorEl.style.display = "none";
|
|
3140
7312
|
try {
|
|
3141
|
-
await requestPasswordReset(
|
|
7313
|
+
await requestPasswordReset(email2, this.applicationToken);
|
|
3142
7314
|
this.renderSuccess();
|
|
3143
7315
|
} catch (error) {
|
|
3144
7316
|
submitBtn.disabled = false;
|
|
@@ -3392,7 +7564,7 @@ const modalReducer = (state, action) => {
|
|
|
3392
7564
|
case "ERROR":
|
|
3393
7565
|
return { status: "error", message: action.message, retryable: action.retryable ?? true };
|
|
3394
7566
|
case "RESET":
|
|
3395
|
-
return
|
|
7567
|
+
return createInitialState();
|
|
3396
7568
|
default:
|
|
3397
7569
|
return state;
|
|
3398
7570
|
}
|
|
@@ -3406,19 +7578,25 @@ const livenessInstructions = {
|
|
|
3406
7578
|
complete: "Processando..."
|
|
3407
7579
|
};
|
|
3408
7580
|
const generateRandomStepSequence = () => {
|
|
3409
|
-
|
|
7581
|
+
const middleSteps = ["up", "down", "left", "right"];
|
|
7582
|
+
for (let i = middleSteps.length - 1; i > 0; i--) {
|
|
7583
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
7584
|
+
[middleSteps[i], middleSteps[j]] = [middleSteps[j], middleSteps[i]];
|
|
7585
|
+
}
|
|
7586
|
+
return ["center", ...middleSteps, "complete"];
|
|
3410
7587
|
};
|
|
3411
|
-
const
|
|
7588
|
+
const createInitialState = () => {
|
|
3412
7589
|
const sequence = generateRandomStepSequence();
|
|
3413
7590
|
return {
|
|
3414
7591
|
status: "liveness",
|
|
7592
|
+
// Mantido liveness para não quebrar o fluxo atual por enquanto
|
|
3415
7593
|
step: sequence[0],
|
|
3416
7594
|
capturedPhotos: [],
|
|
3417
7595
|
stepSequence: sequence,
|
|
3418
7596
|
currentStepIndex: 0,
|
|
3419
7597
|
stepProgress: 0
|
|
3420
7598
|
};
|
|
3421
|
-
}
|
|
7599
|
+
};
|
|
3422
7600
|
const CALIBRATION = {
|
|
3423
7601
|
PITCH_DEAD_ZONE: 8,
|
|
3424
7602
|
YAW_DEAD_ZONE: 10,
|
|
@@ -3458,7 +7636,7 @@ function BiometricRegistrationModal({
|
|
|
3458
7636
|
const stepTimeoutTimerRef = useRef(null);
|
|
3459
7637
|
const detectionStartedRef = useRef(false);
|
|
3460
7638
|
const captureStateRef = useRef(null);
|
|
3461
|
-
const [state, dispatch] = useReducer(modalReducer,
|
|
7639
|
+
const [state, dispatch] = useReducer(modalReducer, void 0, createInitialState);
|
|
3462
7640
|
const [faceDetected, setFaceDetected] = useState(false);
|
|
3463
7641
|
const [faceDistance, setFaceDistance] = useState("ok");
|
|
3464
7642
|
const [cameraReady, setCameraReady] = useState(false);
|
|
@@ -3605,7 +7783,7 @@ function BiometricRegistrationModal({
|
|
|
3605
7783
|
useEffect(() => {
|
|
3606
7784
|
const loadModels = async () => {
|
|
3607
7785
|
try {
|
|
3608
|
-
const MODEL_URL = "
|
|
7786
|
+
const MODEL_URL = "/models";
|
|
3609
7787
|
const timeout = new Promise(
|
|
3610
7788
|
(_, reject) => setTimeout(() => reject(new Error("Timeout ao carregar modelos")), 1e4)
|
|
3611
7789
|
);
|
|
@@ -3908,17 +8086,23 @@ function BiometricRegistrationModal({
|
|
|
3908
8086
|
);
|
|
3909
8087
|
};
|
|
3910
8088
|
const processRegistration = async (photos) => {
|
|
3911
|
-
var
|
|
8089
|
+
var _a2;
|
|
3912
8090
|
try {
|
|
3913
8091
|
dispatch({ type: "START_PROCESSING" });
|
|
3914
8092
|
if (applicationToken && photos.length > 0) {
|
|
3915
8093
|
try {
|
|
3916
8094
|
const { identifyPersonAsync: identifyPersonAsync2 } = await Promise.resolve().then(() => api);
|
|
3917
|
-
const
|
|
3918
|
-
|
|
8095
|
+
const timeoutPromise = new Promise(
|
|
8096
|
+
(resolve) => setTimeout(() => resolve(null), 5e3)
|
|
8097
|
+
);
|
|
8098
|
+
const result2 = await Promise.race([
|
|
8099
|
+
identifyPersonAsync2(photos[0], applicationToken, { maxRetries: 3, interval: 1e3 }),
|
|
8100
|
+
timeoutPromise
|
|
8101
|
+
]);
|
|
8102
|
+
if (result2 && result2.personFound) {
|
|
3919
8103
|
dispatch({
|
|
3920
8104
|
type: "DUPLICATE",
|
|
3921
|
-
personName: ((
|
|
8105
|
+
personName: ((_a2 = result2.person) == null ? void 0 : _a2.name) || "Pessoa identificada"
|
|
3922
8106
|
});
|
|
3923
8107
|
return;
|
|
3924
8108
|
}
|
|
@@ -4991,21 +9175,21 @@ class BiometricCaptureModal {
|
|
|
4991
9175
|
const cancelBtn = this.modal.querySelector(".neofaceid-cancel-btn");
|
|
4992
9176
|
const captureBtn = this.modal.querySelector(".neofaceid-capture-btn");
|
|
4993
9177
|
closeBtn == null ? void 0 : closeBtn.addEventListener("click", () => {
|
|
4994
|
-
var
|
|
9178
|
+
var _a2, _b;
|
|
4995
9179
|
this.close();
|
|
4996
|
-
(_b = (
|
|
9180
|
+
(_b = (_a2 = this.options).onCancel) == null ? void 0 : _b.call(_a2);
|
|
4997
9181
|
});
|
|
4998
9182
|
cancelBtn == null ? void 0 : cancelBtn.addEventListener("click", () => {
|
|
4999
|
-
var
|
|
9183
|
+
var _a2, _b;
|
|
5000
9184
|
this.close();
|
|
5001
|
-
(_b = (
|
|
9185
|
+
(_b = (_a2 = this.options).onCancel) == null ? void 0 : _b.call(_a2);
|
|
5002
9186
|
});
|
|
5003
9187
|
captureBtn == null ? void 0 : captureBtn.addEventListener("click", () => {
|
|
5004
9188
|
this.captureImage();
|
|
5005
9189
|
});
|
|
5006
9190
|
this.modal.addEventListener("click", (e) => {
|
|
5007
|
-
var
|
|
5008
|
-
if (e.target === ((
|
|
9191
|
+
var _a2, _b, _c;
|
|
9192
|
+
if (e.target === ((_a2 = this.modal) == null ? void 0 : _a2.querySelector(".neofaceid-modal-overlay"))) {
|
|
5009
9193
|
this.close();
|
|
5010
9194
|
(_c = (_b = this.options).onCancel) == null ? void 0 : _c.call(_b);
|
|
5011
9195
|
}
|
|
@@ -6102,16 +10286,16 @@ class EmailPasswordModal {
|
|
|
6102
10286
|
};
|
|
6103
10287
|
errorDiv.style.display = "none";
|
|
6104
10288
|
errorDiv.textContent = "";
|
|
6105
|
-
const
|
|
10289
|
+
const email2 = emailInput.value.trim();
|
|
6106
10290
|
const password = passwordInput.value.trim();
|
|
6107
|
-
if (!
|
|
10291
|
+
if (!email2 || !password) {
|
|
6108
10292
|
showError("Preencha o email e a senha para continuar.");
|
|
6109
10293
|
return;
|
|
6110
10294
|
}
|
|
6111
10295
|
submitBtn.disabled = true;
|
|
6112
10296
|
submitBtn.textContent = "Entrando...";
|
|
6113
10297
|
try {
|
|
6114
|
-
const result = await loginWithEmail(
|
|
10298
|
+
const result = await loginWithEmail(email2, password, this.options.applicationToken);
|
|
6115
10299
|
this.options.onSuccess(result);
|
|
6116
10300
|
this.close();
|
|
6117
10301
|
} catch (error) {
|
|
@@ -6143,7 +10327,7 @@ async function preloadFaceDetectionModels() {
|
|
|
6143
10327
|
if (modelsLoading) return modelsLoading;
|
|
6144
10328
|
modelsLoading = (async () => {
|
|
6145
10329
|
try {
|
|
6146
|
-
const MODEL_URL = "
|
|
10330
|
+
const MODEL_URL = "/models";
|
|
6147
10331
|
await faceapi.nets.tinyFaceDetector.loadFromUri(MODEL_URL);
|
|
6148
10332
|
modelsLoaded = true;
|
|
6149
10333
|
console.log("✅ Face detection models preloaded");
|
|
@@ -6877,8 +11061,8 @@ async function loadFaceApiModels() {
|
|
|
6877
11061
|
}
|
|
6878
11062
|
try {
|
|
6879
11063
|
await Promise.all([
|
|
6880
|
-
faceapi2.nets.tinyFaceDetector.loadFromUri("
|
|
6881
|
-
faceapi2.nets.faceLandmark68Net.loadFromUri("
|
|
11064
|
+
faceapi2.nets.tinyFaceDetector.loadFromUri("/models"),
|
|
11065
|
+
faceapi2.nets.faceLandmark68Net.loadFromUri("/models")
|
|
6882
11066
|
]);
|
|
6883
11067
|
} catch (error) {
|
|
6884
11068
|
console.warn("Não foi possível carregar modelos do face-api.js:", error);
|
|
@@ -6902,8 +11086,8 @@ const biometricDetection = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.
|
|
|
6902
11086
|
initializeBiometricDetection,
|
|
6903
11087
|
isAdvancedDetectionAvailable
|
|
6904
11088
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
6905
|
-
const VERSION = "1.
|
|
6906
|
-
const RELEASE_DATE = "2026-03-
|
|
11089
|
+
const VERSION = "1.24.1";
|
|
11090
|
+
const RELEASE_DATE = "2026-03-28";
|
|
6907
11091
|
class OnboardingCaptureModal {
|
|
6908
11092
|
constructor(options) {
|
|
6909
11093
|
__publicField(this, "overlay", null);
|
|
@@ -7135,13 +11319,13 @@ class NeoFaceID {
|
|
|
7135
11319
|
* @param config Configuration object
|
|
7136
11320
|
* @throws NeoFaceError if signature format is invalid
|
|
7137
11321
|
*/
|
|
7138
|
-
constructor(
|
|
11322
|
+
constructor(config2) {
|
|
7139
11323
|
__publicField(this, "appToken");
|
|
7140
11324
|
__publicField(this, "signature");
|
|
7141
11325
|
__publicField(this, "sessionData");
|
|
7142
|
-
this.appToken =
|
|
7143
|
-
this.signature =
|
|
7144
|
-
this.sessionData =
|
|
11326
|
+
this.appToken = config2.appToken;
|
|
11327
|
+
this.signature = config2.signature;
|
|
11328
|
+
this.sessionData = config2.sessionData;
|
|
7145
11329
|
if (this.signature && !this.validateSignatureFormat(this.signature)) {
|
|
7146
11330
|
throw new NeoFaceError(
|
|
7147
11331
|
"Invalid signature format. Expected HMAC-SHA256 hex string (minimum 64 characters)",
|
|
@@ -7639,11 +11823,11 @@ class DocumentCaptureModal {
|
|
|
7639
11823
|
});
|
|
7640
11824
|
}
|
|
7641
11825
|
render() {
|
|
7642
|
-
var
|
|
11826
|
+
var _a2;
|
|
7643
11827
|
if (!this.overlay) {
|
|
7644
11828
|
this.createOverlay();
|
|
7645
11829
|
}
|
|
7646
|
-
const content = (
|
|
11830
|
+
const content = (_a2 = this.overlay) == null ? void 0 : _a2.querySelector(".neoface-doc-content");
|
|
7647
11831
|
if (!content) return;
|
|
7648
11832
|
switch (this.currentStep) {
|
|
7649
11833
|
case "select":
|
|
@@ -7861,8 +12045,8 @@ class DocumentCaptureModal {
|
|
|
7861
12045
|
`;
|
|
7862
12046
|
}
|
|
7863
12047
|
bindSelectEvents() {
|
|
7864
|
-
var
|
|
7865
|
-
const options = (
|
|
12048
|
+
var _a2;
|
|
12049
|
+
const options = (_a2 = this.overlay) == null ? void 0 : _a2.querySelectorAll(".neoface-doc-select-option");
|
|
7866
12050
|
options == null ? void 0 : options.forEach((option) => {
|
|
7867
12051
|
option.addEventListener("click", () => {
|
|
7868
12052
|
const type = option.getAttribute("data-type");
|
|
@@ -7874,8 +12058,8 @@ class DocumentCaptureModal {
|
|
|
7874
12058
|
this.bindCloseEvent();
|
|
7875
12059
|
}
|
|
7876
12060
|
bindCaptureEvents() {
|
|
7877
|
-
var
|
|
7878
|
-
const captureBtn = (
|
|
12061
|
+
var _a2, _b, _c, _d;
|
|
12062
|
+
const captureBtn = (_a2 = this.overlay) == null ? void 0 : _a2.querySelector(".neoface-doc-capture-btn");
|
|
7879
12063
|
const backBtn = (_b = this.overlay) == null ? void 0 : _b.querySelector(".neoface-doc-back-btn");
|
|
7880
12064
|
const uploadBtn = (_c = this.overlay) == null ? void 0 : _c.querySelector(".neoface-doc-upload-btn");
|
|
7881
12065
|
const fileInput = (_d = this.overlay) == null ? void 0 : _d.querySelector(".neoface-doc-file-input");
|
|
@@ -7886,9 +12070,9 @@ class DocumentCaptureModal {
|
|
|
7886
12070
|
this.bindCloseEvent();
|
|
7887
12071
|
}
|
|
7888
12072
|
async handleFileUpload(event) {
|
|
7889
|
-
var
|
|
12073
|
+
var _a2, _b;
|
|
7890
12074
|
const input = event.target;
|
|
7891
|
-
const file = (
|
|
12075
|
+
const file = (_a2 = input.files) == null ? void 0 : _a2[0];
|
|
7892
12076
|
if (!file) return;
|
|
7893
12077
|
const loadingEl = (_b = this.overlay) == null ? void 0 : _b.querySelector(".neoface-doc-loading");
|
|
7894
12078
|
if (loadingEl) loadingEl.style.display = "flex";
|
|
@@ -7959,8 +12143,8 @@ class DocumentCaptureModal {
|
|
|
7959
12143
|
});
|
|
7960
12144
|
}
|
|
7961
12145
|
bindPreviewEvents() {
|
|
7962
|
-
var
|
|
7963
|
-
const confirmBtn = (
|
|
12146
|
+
var _a2, _b, _c;
|
|
12147
|
+
const confirmBtn = (_a2 = this.overlay) == null ? void 0 : _a2.querySelector(".neoface-doc-confirm-btn");
|
|
7964
12148
|
const retakeBtn = (_b = this.overlay) == null ? void 0 : _b.querySelector(".neoface-doc-retake-btn");
|
|
7965
12149
|
confirmBtn == null ? void 0 : confirmBtn.addEventListener("click", () => this.handleConfirm());
|
|
7966
12150
|
retakeBtn == null ? void 0 : retakeBtn.addEventListener("click", () => this.handleRetake());
|
|
@@ -7972,12 +12156,12 @@ class DocumentCaptureModal {
|
|
|
7972
12156
|
this.bindCloseEvent();
|
|
7973
12157
|
}
|
|
7974
12158
|
bindCloseEvent() {
|
|
7975
|
-
var
|
|
7976
|
-
const closeBtn = (
|
|
12159
|
+
var _a2;
|
|
12160
|
+
const closeBtn = (_a2 = this.overlay) == null ? void 0 : _a2.querySelector(".neoface-doc-close-btn");
|
|
7977
12161
|
closeBtn == null ? void 0 : closeBtn.addEventListener("click", () => this.handleCancel());
|
|
7978
12162
|
}
|
|
7979
12163
|
async startCamera() {
|
|
7980
|
-
var
|
|
12164
|
+
var _a2, _b, _c;
|
|
7981
12165
|
try {
|
|
7982
12166
|
const constraints = {
|
|
7983
12167
|
video: {
|
|
@@ -7988,7 +12172,7 @@ class DocumentCaptureModal {
|
|
|
7988
12172
|
audio: false
|
|
7989
12173
|
};
|
|
7990
12174
|
this.stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7991
|
-
this.video = (
|
|
12175
|
+
this.video = (_a2 = this.overlay) == null ? void 0 : _a2.querySelector(".neoface-doc-video");
|
|
7992
12176
|
this.canvas = (_b = this.overlay) == null ? void 0 : _b.querySelector(".neoface-doc-canvas");
|
|
7993
12177
|
if (this.video) {
|
|
7994
12178
|
this.video.muted = true;
|
|
@@ -8027,9 +12211,9 @@ class DocumentCaptureModal {
|
|
|
8027
12211
|
}
|
|
8028
12212
|
}
|
|
8029
12213
|
async handleCapture() {
|
|
8030
|
-
var
|
|
12214
|
+
var _a2;
|
|
8031
12215
|
if (!this.video || !this.canvas) return;
|
|
8032
|
-
const loading = (
|
|
12216
|
+
const loading = (_a2 = this.overlay) == null ? void 0 : _a2.querySelector(".neoface-doc-loading");
|
|
8033
12217
|
if (loading) loading.style.display = "flex";
|
|
8034
12218
|
const ctx = this.canvas.getContext("2d");
|
|
8035
12219
|
if (!ctx) return;
|
|
@@ -8103,14 +12287,14 @@ class DocumentCaptureModal {
|
|
|
8103
12287
|
this.render();
|
|
8104
12288
|
}
|
|
8105
12289
|
handleConfirm() {
|
|
8106
|
-
var
|
|
12290
|
+
var _a2, _b;
|
|
8107
12291
|
const docInfo = this.selectedDocument ? DOCUMENT_INFO[this.selectedDocument] : null;
|
|
8108
12292
|
if (this.currentStep === "preview-front") {
|
|
8109
12293
|
if (docInfo == null ? void 0 : docInfo.hasBack) {
|
|
8110
12294
|
this.currentStep = "back";
|
|
8111
12295
|
this.render();
|
|
8112
12296
|
} else {
|
|
8113
|
-
(
|
|
12297
|
+
(_a2 = this.resolvePromise) == null ? void 0 : _a2.call(this, {
|
|
8114
12298
|
success: true,
|
|
8115
12299
|
documentType: this.selectedDocument || void 0,
|
|
8116
12300
|
frontImage: this.frontBlob,
|
|
@@ -8129,8 +12313,8 @@ class DocumentCaptureModal {
|
|
|
8129
12313
|
}
|
|
8130
12314
|
}
|
|
8131
12315
|
handleCancel() {
|
|
8132
|
-
var
|
|
8133
|
-
(_b = (
|
|
12316
|
+
var _a2, _b, _c;
|
|
12317
|
+
(_b = (_a2 = this.options).onCancel) == null ? void 0 : _b.call(_a2);
|
|
8134
12318
|
(_c = this.resolvePromise) == null ? void 0 : _c.call(this, {
|
|
8135
12319
|
success: false,
|
|
8136
12320
|
frontImage: null,
|
|
@@ -8747,4 +12931,3 @@ export {
|
|
|
8747
12931
|
validateOnboardingToken,
|
|
8748
12932
|
validateToken
|
|
8749
12933
|
};
|
|
8750
|
-
//# sourceMappingURL=neoface-id-sdk.es.js.map
|