@lodashventure/medusa-quotation 0.0.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +454 -609
- package/.medusa/server/src/admin/index.mjs +454 -609
- package/.medusa/server/src/api/admin/quote-config/route.js +2 -2
- package/.medusa/server/src/api/admin/quote-seq/[id]/route.js +1 -1
- package/.medusa/server/src/api/admin/quote-seq/route.js +1 -1
- package/.medusa/server/src/api/admin/quote-store/route.js +1 -1
- package/.medusa/server/src/api/middlewares.js +1 -1
- package/.medusa/server/src/links/quote-cart.js +7 -3
- package/.medusa/server/src/links/quote-config-store.js +7 -3
- package/.medusa/server/src/links/quote-customer.js +7 -3
- package/.medusa/server/src/links/quote-order-change.js +7 -3
- package/.medusa/server/src/links/quote-order.js +7 -3
- package/.medusa/server/src/links/quote-seq-store.js +7 -3
- package/package.json +16 -13
|
@@ -2042,7 +2042,8 @@ var n = function(e2, o2) {
|
|
|
2042
2042
|
};
|
|
2043
2043
|
var util;
|
|
2044
2044
|
(function(util2) {
|
|
2045
|
-
util2.assertEqual = (
|
|
2045
|
+
util2.assertEqual = (_) => {
|
|
2046
|
+
};
|
|
2046
2047
|
function assertIs(_arg) {
|
|
2047
2048
|
}
|
|
2048
2049
|
util2.assertIs = assertIs;
|
|
@@ -2086,7 +2087,7 @@ var util;
|
|
|
2086
2087
|
}
|
|
2087
2088
|
return void 0;
|
|
2088
2089
|
};
|
|
2089
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
2090
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
2090
2091
|
function joinValues(array, separator = " | ") {
|
|
2091
2092
|
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
2092
2093
|
}
|
|
@@ -2138,7 +2139,7 @@ const getParsedType = (data) => {
|
|
|
2138
2139
|
case "string":
|
|
2139
2140
|
return ZodParsedType.string;
|
|
2140
2141
|
case "number":
|
|
2141
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
2142
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
2142
2143
|
case "boolean":
|
|
2143
2144
|
return ZodParsedType.boolean;
|
|
2144
2145
|
case "function":
|
|
@@ -2189,11 +2190,10 @@ const ZodIssueCode = util.arrayToEnum([
|
|
|
2189
2190
|
"not_multiple_of",
|
|
2190
2191
|
"not_finite"
|
|
2191
2192
|
]);
|
|
2192
|
-
const quotelessJson = (obj) => {
|
|
2193
|
-
const json = JSON.stringify(obj, null, 2);
|
|
2194
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
2195
|
-
};
|
|
2196
2193
|
class ZodError extends Error {
|
|
2194
|
+
get errors() {
|
|
2195
|
+
return this.issues;
|
|
2196
|
+
}
|
|
2197
2197
|
constructor(issues) {
|
|
2198
2198
|
super();
|
|
2199
2199
|
this.issues = [];
|
|
@@ -2212,9 +2212,6 @@ class ZodError extends Error {
|
|
|
2212
2212
|
this.name = "ZodError";
|
|
2213
2213
|
this.issues = issues;
|
|
2214
2214
|
}
|
|
2215
|
-
get errors() {
|
|
2216
|
-
return this.issues;
|
|
2217
|
-
}
|
|
2218
2215
|
format(_mapper) {
|
|
2219
2216
|
const mapper = _mapper || function(issue) {
|
|
2220
2217
|
return issue.message;
|
|
@@ -2251,6 +2248,11 @@ class ZodError extends Error {
|
|
|
2251
2248
|
processError(this);
|
|
2252
2249
|
return fieldErrors;
|
|
2253
2250
|
}
|
|
2251
|
+
static assert(value) {
|
|
2252
|
+
if (!(value instanceof ZodError)) {
|
|
2253
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2254
2256
|
toString() {
|
|
2255
2257
|
return this.message;
|
|
2256
2258
|
}
|
|
@@ -2265,8 +2267,9 @@ class ZodError extends Error {
|
|
|
2265
2267
|
const formErrors = [];
|
|
2266
2268
|
for (const sub of this.issues) {
|
|
2267
2269
|
if (sub.path.length > 0) {
|
|
2268
|
-
|
|
2269
|
-
fieldErrors[
|
|
2270
|
+
const firstEl = sub.path[0];
|
|
2271
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
2272
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
2270
2273
|
} else {
|
|
2271
2274
|
formErrors.push(mapper(sub));
|
|
2272
2275
|
}
|
|
@@ -2342,6 +2345,8 @@ const errorMap = (issue, _ctx) => {
|
|
|
2342
2345
|
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
2343
2346
|
else if (issue.type === "number")
|
|
2344
2347
|
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
2348
|
+
else if (issue.type === "bigint")
|
|
2349
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
2345
2350
|
else if (issue.type === "date")
|
|
2346
2351
|
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
2347
2352
|
else
|
|
@@ -2380,9 +2385,6 @@ const errorMap = (issue, _ctx) => {
|
|
|
2380
2385
|
return { message };
|
|
2381
2386
|
};
|
|
2382
2387
|
let overrideErrorMap = errorMap;
|
|
2383
|
-
function setErrorMap(map) {
|
|
2384
|
-
overrideErrorMap = map;
|
|
2385
|
-
}
|
|
2386
2388
|
function getErrorMap() {
|
|
2387
2389
|
return overrideErrorMap;
|
|
2388
2390
|
}
|
|
@@ -2393,6 +2395,13 @@ const makeIssue = (params) => {
|
|
|
2393
2395
|
...issueData,
|
|
2394
2396
|
path: fullPath
|
|
2395
2397
|
};
|
|
2398
|
+
if (issueData.message !== void 0) {
|
|
2399
|
+
return {
|
|
2400
|
+
...issueData,
|
|
2401
|
+
path: fullPath,
|
|
2402
|
+
message: issueData.message
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2396
2405
|
let errorMessage = "";
|
|
2397
2406
|
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
2398
2407
|
for (const map of maps) {
|
|
@@ -2401,20 +2410,23 @@ const makeIssue = (params) => {
|
|
|
2401
2410
|
return {
|
|
2402
2411
|
...issueData,
|
|
2403
2412
|
path: fullPath,
|
|
2404
|
-
message:
|
|
2413
|
+
message: errorMessage
|
|
2405
2414
|
};
|
|
2406
2415
|
};
|
|
2407
|
-
const EMPTY_PATH = [];
|
|
2408
2416
|
function addIssueToContext(ctx, issueData) {
|
|
2417
|
+
const overrideMap = getErrorMap();
|
|
2409
2418
|
const issue = makeIssue({
|
|
2410
2419
|
issueData,
|
|
2411
2420
|
data: ctx.data,
|
|
2412
2421
|
path: ctx.path,
|
|
2413
2422
|
errorMaps: [
|
|
2414
2423
|
ctx.common.contextualErrorMap,
|
|
2424
|
+
// contextual error map is first priority
|
|
2415
2425
|
ctx.schemaErrorMap,
|
|
2416
|
-
|
|
2417
|
-
|
|
2426
|
+
// then schema-bound map if available
|
|
2427
|
+
overrideMap,
|
|
2428
|
+
// then global override map
|
|
2429
|
+
overrideMap === errorMap ? void 0 : errorMap
|
|
2418
2430
|
// then global default map
|
|
2419
2431
|
].filter((x) => !!x)
|
|
2420
2432
|
});
|
|
@@ -2446,9 +2458,11 @@ class ParseStatus {
|
|
|
2446
2458
|
static async mergeObjectAsync(status, pairs) {
|
|
2447
2459
|
const syncPairs = [];
|
|
2448
2460
|
for (const pair of pairs) {
|
|
2461
|
+
const key = await pair.key;
|
|
2462
|
+
const value = await pair.value;
|
|
2449
2463
|
syncPairs.push({
|
|
2450
|
-
key
|
|
2451
|
-
value
|
|
2464
|
+
key,
|
|
2465
|
+
value
|
|
2452
2466
|
});
|
|
2453
2467
|
}
|
|
2454
2468
|
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
@@ -2484,7 +2498,7 @@ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
|
2484
2498
|
var errorUtil;
|
|
2485
2499
|
(function(errorUtil2) {
|
|
2486
2500
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
2487
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message
|
|
2501
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
|
|
2488
2502
|
})(errorUtil || (errorUtil = {}));
|
|
2489
2503
|
class ParseInputLazyPath {
|
|
2490
2504
|
constructor(parent, value, path, key) {
|
|
@@ -2496,7 +2510,7 @@ class ParseInputLazyPath {
|
|
|
2496
2510
|
}
|
|
2497
2511
|
get path() {
|
|
2498
2512
|
if (!this._cachedPath.length) {
|
|
2499
|
-
if (this._key
|
|
2513
|
+
if (Array.isArray(this._key)) {
|
|
2500
2514
|
this._cachedPath.push(...this._path, ...this._key);
|
|
2501
2515
|
} else {
|
|
2502
2516
|
this._cachedPath.push(...this._path, this._key);
|
|
@@ -2534,44 +2548,20 @@ function processCreateParams(params) {
|
|
|
2534
2548
|
if (errorMap2)
|
|
2535
2549
|
return { errorMap: errorMap2, description };
|
|
2536
2550
|
const customMap = (iss, ctx) => {
|
|
2537
|
-
|
|
2538
|
-
|
|
2551
|
+
const { message } = params;
|
|
2552
|
+
if (iss.code === "invalid_enum_value") {
|
|
2553
|
+
return { message: message ?? ctx.defaultError };
|
|
2554
|
+
}
|
|
2539
2555
|
if (typeof ctx.data === "undefined") {
|
|
2540
|
-
return { message:
|
|
2556
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
2541
2557
|
}
|
|
2542
|
-
|
|
2558
|
+
if (iss.code !== "invalid_type")
|
|
2559
|
+
return { message: ctx.defaultError };
|
|
2560
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
2543
2561
|
};
|
|
2544
2562
|
return { errorMap: customMap, description };
|
|
2545
2563
|
}
|
|
2546
2564
|
class ZodType {
|
|
2547
|
-
constructor(def) {
|
|
2548
|
-
this.spa = this.safeParseAsync;
|
|
2549
|
-
this._def = def;
|
|
2550
|
-
this.parse = this.parse.bind(this);
|
|
2551
|
-
this.safeParse = this.safeParse.bind(this);
|
|
2552
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
2553
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2554
|
-
this.spa = this.spa.bind(this);
|
|
2555
|
-
this.refine = this.refine.bind(this);
|
|
2556
|
-
this.refinement = this.refinement.bind(this);
|
|
2557
|
-
this.superRefine = this.superRefine.bind(this);
|
|
2558
|
-
this.optional = this.optional.bind(this);
|
|
2559
|
-
this.nullable = this.nullable.bind(this);
|
|
2560
|
-
this.nullish = this.nullish.bind(this);
|
|
2561
|
-
this.array = this.array.bind(this);
|
|
2562
|
-
this.promise = this.promise.bind(this);
|
|
2563
|
-
this.or = this.or.bind(this);
|
|
2564
|
-
this.and = this.and.bind(this);
|
|
2565
|
-
this.transform = this.transform.bind(this);
|
|
2566
|
-
this.brand = this.brand.bind(this);
|
|
2567
|
-
this.default = this.default.bind(this);
|
|
2568
|
-
this.catch = this.catch.bind(this);
|
|
2569
|
-
this.describe = this.describe.bind(this);
|
|
2570
|
-
this.pipe = this.pipe.bind(this);
|
|
2571
|
-
this.readonly = this.readonly.bind(this);
|
|
2572
|
-
this.isNullable = this.isNullable.bind(this);
|
|
2573
|
-
this.isOptional = this.isOptional.bind(this);
|
|
2574
|
-
}
|
|
2575
2565
|
get description() {
|
|
2576
2566
|
return this._def.description;
|
|
2577
2567
|
}
|
|
@@ -2619,14 +2609,13 @@ class ZodType {
|
|
|
2619
2609
|
throw result.error;
|
|
2620
2610
|
}
|
|
2621
2611
|
safeParse(data, params) {
|
|
2622
|
-
var _a;
|
|
2623
2612
|
const ctx = {
|
|
2624
2613
|
common: {
|
|
2625
2614
|
issues: [],
|
|
2626
|
-
async: (
|
|
2627
|
-
contextualErrorMap: params
|
|
2615
|
+
async: (params == null ? void 0 : params.async) ?? false,
|
|
2616
|
+
contextualErrorMap: params == null ? void 0 : params.errorMap
|
|
2628
2617
|
},
|
|
2629
|
-
path: (params
|
|
2618
|
+
path: (params == null ? void 0 : params.path) || [],
|
|
2630
2619
|
schemaErrorMap: this._def.errorMap,
|
|
2631
2620
|
parent: null,
|
|
2632
2621
|
data,
|
|
@@ -2635,6 +2624,43 @@ class ZodType {
|
|
|
2635
2624
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
2636
2625
|
return handleResult(ctx, result);
|
|
2637
2626
|
}
|
|
2627
|
+
"~validate"(data) {
|
|
2628
|
+
var _a, _b;
|
|
2629
|
+
const ctx = {
|
|
2630
|
+
common: {
|
|
2631
|
+
issues: [],
|
|
2632
|
+
async: !!this["~standard"].async
|
|
2633
|
+
},
|
|
2634
|
+
path: [],
|
|
2635
|
+
schemaErrorMap: this._def.errorMap,
|
|
2636
|
+
parent: null,
|
|
2637
|
+
data,
|
|
2638
|
+
parsedType: getParsedType(data)
|
|
2639
|
+
};
|
|
2640
|
+
if (!this["~standard"].async) {
|
|
2641
|
+
try {
|
|
2642
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
2643
|
+
return isValid(result) ? {
|
|
2644
|
+
value: result.value
|
|
2645
|
+
} : {
|
|
2646
|
+
issues: ctx.common.issues
|
|
2647
|
+
};
|
|
2648
|
+
} catch (err) {
|
|
2649
|
+
if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
|
|
2650
|
+
this["~standard"].async = true;
|
|
2651
|
+
}
|
|
2652
|
+
ctx.common = {
|
|
2653
|
+
issues: [],
|
|
2654
|
+
async: true
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
2659
|
+
value: result.value
|
|
2660
|
+
} : {
|
|
2661
|
+
issues: ctx.common.issues
|
|
2662
|
+
});
|
|
2663
|
+
}
|
|
2638
2664
|
async parseAsync(data, params) {
|
|
2639
2665
|
const result = await this.safeParseAsync(data, params);
|
|
2640
2666
|
if (result.success)
|
|
@@ -2645,10 +2671,10 @@ class ZodType {
|
|
|
2645
2671
|
const ctx = {
|
|
2646
2672
|
common: {
|
|
2647
2673
|
issues: [],
|
|
2648
|
-
contextualErrorMap: params
|
|
2674
|
+
contextualErrorMap: params == null ? void 0 : params.errorMap,
|
|
2649
2675
|
async: true
|
|
2650
2676
|
},
|
|
2651
|
-
path: (params
|
|
2677
|
+
path: (params == null ? void 0 : params.path) || [],
|
|
2652
2678
|
schemaErrorMap: this._def.errorMap,
|
|
2653
2679
|
parent: null,
|
|
2654
2680
|
data,
|
|
@@ -2712,6 +2738,39 @@ class ZodType {
|
|
|
2712
2738
|
superRefine(refinement) {
|
|
2713
2739
|
return this._refinement(refinement);
|
|
2714
2740
|
}
|
|
2741
|
+
constructor(def) {
|
|
2742
|
+
this.spa = this.safeParseAsync;
|
|
2743
|
+
this._def = def;
|
|
2744
|
+
this.parse = this.parse.bind(this);
|
|
2745
|
+
this.safeParse = this.safeParse.bind(this);
|
|
2746
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
2747
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2748
|
+
this.spa = this.spa.bind(this);
|
|
2749
|
+
this.refine = this.refine.bind(this);
|
|
2750
|
+
this.refinement = this.refinement.bind(this);
|
|
2751
|
+
this.superRefine = this.superRefine.bind(this);
|
|
2752
|
+
this.optional = this.optional.bind(this);
|
|
2753
|
+
this.nullable = this.nullable.bind(this);
|
|
2754
|
+
this.nullish = this.nullish.bind(this);
|
|
2755
|
+
this.array = this.array.bind(this);
|
|
2756
|
+
this.promise = this.promise.bind(this);
|
|
2757
|
+
this.or = this.or.bind(this);
|
|
2758
|
+
this.and = this.and.bind(this);
|
|
2759
|
+
this.transform = this.transform.bind(this);
|
|
2760
|
+
this.brand = this.brand.bind(this);
|
|
2761
|
+
this.default = this.default.bind(this);
|
|
2762
|
+
this.catch = this.catch.bind(this);
|
|
2763
|
+
this.describe = this.describe.bind(this);
|
|
2764
|
+
this.pipe = this.pipe.bind(this);
|
|
2765
|
+
this.readonly = this.readonly.bind(this);
|
|
2766
|
+
this.isNullable = this.isNullable.bind(this);
|
|
2767
|
+
this.isOptional = this.isOptional.bind(this);
|
|
2768
|
+
this["~standard"] = {
|
|
2769
|
+
version: 1,
|
|
2770
|
+
vendor: "zod",
|
|
2771
|
+
validate: (data) => this["~validate"](data)
|
|
2772
|
+
};
|
|
2773
|
+
}
|
|
2715
2774
|
optional() {
|
|
2716
2775
|
return ZodOptional.create(this, this._def);
|
|
2717
2776
|
}
|
|
@@ -2722,7 +2781,7 @@ class ZodType {
|
|
|
2722
2781
|
return this.nullable().optional();
|
|
2723
2782
|
}
|
|
2724
2783
|
array() {
|
|
2725
|
-
return ZodArray.create(this
|
|
2784
|
+
return ZodArray.create(this);
|
|
2726
2785
|
}
|
|
2727
2786
|
promise() {
|
|
2728
2787
|
return ZodPromise.create(this, this._def);
|
|
@@ -2787,35 +2846,45 @@ class ZodType {
|
|
|
2787
2846
|
}
|
|
2788
2847
|
}
|
|
2789
2848
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
2790
|
-
const cuid2Regex = /^[
|
|
2791
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
2849
|
+
const cuid2Regex = /^[0-9a-z]+$/;
|
|
2850
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
2792
2851
|
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
2793
|
-
const
|
|
2852
|
+
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
2853
|
+
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
2854
|
+
const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
2855
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
2794
2856
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
2795
2857
|
let emojiRegex;
|
|
2796
|
-
const ipv4Regex = /^((
|
|
2797
|
-
const
|
|
2798
|
-
const
|
|
2858
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
2859
|
+
const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
2860
|
+
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
2861
|
+
const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
2862
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
2863
|
+
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
2864
|
+
const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
2865
|
+
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
2866
|
+
function timeRegexSource(args) {
|
|
2867
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
2799
2868
|
if (args.precision) {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
2804
|
-
}
|
|
2805
|
-
} else if (args.precision === 0) {
|
|
2806
|
-
if (args.offset) {
|
|
2807
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
2808
|
-
} else {
|
|
2809
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
2810
|
-
}
|
|
2811
|
-
} else {
|
|
2812
|
-
if (args.offset) {
|
|
2813
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
2814
|
-
} else {
|
|
2815
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
2816
|
-
}
|
|
2869
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
2870
|
+
} else if (args.precision == null) {
|
|
2871
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
2817
2872
|
}
|
|
2818
|
-
|
|
2873
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
2874
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
2875
|
+
}
|
|
2876
|
+
function timeRegex(args) {
|
|
2877
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
2878
|
+
}
|
|
2879
|
+
function datetimeRegex(args) {
|
|
2880
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
2881
|
+
const opts = [];
|
|
2882
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
2883
|
+
if (args.offset)
|
|
2884
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
2885
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
2886
|
+
return new RegExp(`^${regex}$`);
|
|
2887
|
+
}
|
|
2819
2888
|
function isValidIP(ip, version) {
|
|
2820
2889
|
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
2821
2890
|
return true;
|
|
@@ -2825,6 +2894,37 @@ function isValidIP(ip, version) {
|
|
|
2825
2894
|
}
|
|
2826
2895
|
return false;
|
|
2827
2896
|
}
|
|
2897
|
+
function isValidJWT(jwt, alg) {
|
|
2898
|
+
if (!jwtRegex.test(jwt))
|
|
2899
|
+
return false;
|
|
2900
|
+
try {
|
|
2901
|
+
const [header] = jwt.split(".");
|
|
2902
|
+
if (!header)
|
|
2903
|
+
return false;
|
|
2904
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
2905
|
+
const decoded = JSON.parse(atob(base64));
|
|
2906
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
2907
|
+
return false;
|
|
2908
|
+
if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
|
|
2909
|
+
return false;
|
|
2910
|
+
if (!decoded.alg)
|
|
2911
|
+
return false;
|
|
2912
|
+
if (alg && decoded.alg !== alg)
|
|
2913
|
+
return false;
|
|
2914
|
+
return true;
|
|
2915
|
+
} catch {
|
|
2916
|
+
return false;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
function isValidCidr(ip, version) {
|
|
2920
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
2921
|
+
return true;
|
|
2922
|
+
}
|
|
2923
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
2924
|
+
return true;
|
|
2925
|
+
}
|
|
2926
|
+
return false;
|
|
2927
|
+
}
|
|
2828
2928
|
class ZodString extends ZodType {
|
|
2829
2929
|
_parse(input) {
|
|
2830
2930
|
if (this._def.coerce) {
|
|
@@ -2833,15 +2933,11 @@ class ZodString extends ZodType {
|
|
|
2833
2933
|
const parsedType = this._getType(input);
|
|
2834
2934
|
if (parsedType !== ZodParsedType.string) {
|
|
2835
2935
|
const ctx2 = this._getOrReturnCtx(input);
|
|
2836
|
-
addIssueToContext(
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
received: ctx2.parsedType
|
|
2842
|
-
}
|
|
2843
|
-
//
|
|
2844
|
-
);
|
|
2936
|
+
addIssueToContext(ctx2, {
|
|
2937
|
+
code: ZodIssueCode.invalid_type,
|
|
2938
|
+
expected: ZodParsedType.string,
|
|
2939
|
+
received: ctx2.parsedType
|
|
2940
|
+
});
|
|
2845
2941
|
return INVALID;
|
|
2846
2942
|
}
|
|
2847
2943
|
const status = new ParseStatus();
|
|
@@ -2932,6 +3028,16 @@ class ZodString extends ZodType {
|
|
|
2932
3028
|
});
|
|
2933
3029
|
status.dirty();
|
|
2934
3030
|
}
|
|
3031
|
+
} else if (check.kind === "nanoid") {
|
|
3032
|
+
if (!nanoidRegex.test(input.data)) {
|
|
3033
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3034
|
+
addIssueToContext(ctx, {
|
|
3035
|
+
validation: "nanoid",
|
|
3036
|
+
code: ZodIssueCode.invalid_string,
|
|
3037
|
+
message: check.message
|
|
3038
|
+
});
|
|
3039
|
+
status.dirty();
|
|
3040
|
+
}
|
|
2935
3041
|
} else if (check.kind === "cuid") {
|
|
2936
3042
|
if (!cuidRegex.test(input.data)) {
|
|
2937
3043
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -2965,7 +3071,7 @@ class ZodString extends ZodType {
|
|
|
2965
3071
|
} else if (check.kind === "url") {
|
|
2966
3072
|
try {
|
|
2967
3073
|
new URL(input.data);
|
|
2968
|
-
} catch
|
|
3074
|
+
} catch {
|
|
2969
3075
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
2970
3076
|
addIssueToContext(ctx, {
|
|
2971
3077
|
validation: "url",
|
|
@@ -3033,6 +3139,38 @@ class ZodString extends ZodType {
|
|
|
3033
3139
|
});
|
|
3034
3140
|
status.dirty();
|
|
3035
3141
|
}
|
|
3142
|
+
} else if (check.kind === "date") {
|
|
3143
|
+
const regex = dateRegex;
|
|
3144
|
+
if (!regex.test(input.data)) {
|
|
3145
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3146
|
+
addIssueToContext(ctx, {
|
|
3147
|
+
code: ZodIssueCode.invalid_string,
|
|
3148
|
+
validation: "date",
|
|
3149
|
+
message: check.message
|
|
3150
|
+
});
|
|
3151
|
+
status.dirty();
|
|
3152
|
+
}
|
|
3153
|
+
} else if (check.kind === "time") {
|
|
3154
|
+
const regex = timeRegex(check);
|
|
3155
|
+
if (!regex.test(input.data)) {
|
|
3156
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3157
|
+
addIssueToContext(ctx, {
|
|
3158
|
+
code: ZodIssueCode.invalid_string,
|
|
3159
|
+
validation: "time",
|
|
3160
|
+
message: check.message
|
|
3161
|
+
});
|
|
3162
|
+
status.dirty();
|
|
3163
|
+
}
|
|
3164
|
+
} else if (check.kind === "duration") {
|
|
3165
|
+
if (!durationRegex.test(input.data)) {
|
|
3166
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3167
|
+
addIssueToContext(ctx, {
|
|
3168
|
+
validation: "duration",
|
|
3169
|
+
code: ZodIssueCode.invalid_string,
|
|
3170
|
+
message: check.message
|
|
3171
|
+
});
|
|
3172
|
+
status.dirty();
|
|
3173
|
+
}
|
|
3036
3174
|
} else if (check.kind === "ip") {
|
|
3037
3175
|
if (!isValidIP(input.data, check.version)) {
|
|
3038
3176
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -3043,6 +3181,46 @@ class ZodString extends ZodType {
|
|
|
3043
3181
|
});
|
|
3044
3182
|
status.dirty();
|
|
3045
3183
|
}
|
|
3184
|
+
} else if (check.kind === "jwt") {
|
|
3185
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
3186
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3187
|
+
addIssueToContext(ctx, {
|
|
3188
|
+
validation: "jwt",
|
|
3189
|
+
code: ZodIssueCode.invalid_string,
|
|
3190
|
+
message: check.message
|
|
3191
|
+
});
|
|
3192
|
+
status.dirty();
|
|
3193
|
+
}
|
|
3194
|
+
} else if (check.kind === "cidr") {
|
|
3195
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
3196
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3197
|
+
addIssueToContext(ctx, {
|
|
3198
|
+
validation: "cidr",
|
|
3199
|
+
code: ZodIssueCode.invalid_string,
|
|
3200
|
+
message: check.message
|
|
3201
|
+
});
|
|
3202
|
+
status.dirty();
|
|
3203
|
+
}
|
|
3204
|
+
} else if (check.kind === "base64") {
|
|
3205
|
+
if (!base64Regex.test(input.data)) {
|
|
3206
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3207
|
+
addIssueToContext(ctx, {
|
|
3208
|
+
validation: "base64",
|
|
3209
|
+
code: ZodIssueCode.invalid_string,
|
|
3210
|
+
message: check.message
|
|
3211
|
+
});
|
|
3212
|
+
status.dirty();
|
|
3213
|
+
}
|
|
3214
|
+
} else if (check.kind === "base64url") {
|
|
3215
|
+
if (!base64urlRegex.test(input.data)) {
|
|
3216
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3217
|
+
addIssueToContext(ctx, {
|
|
3218
|
+
validation: "base64url",
|
|
3219
|
+
code: ZodIssueCode.invalid_string,
|
|
3220
|
+
message: check.message
|
|
3221
|
+
});
|
|
3222
|
+
status.dirty();
|
|
3223
|
+
}
|
|
3046
3224
|
} else {
|
|
3047
3225
|
util.assertNever(check);
|
|
3048
3226
|
}
|
|
@@ -3074,6 +3252,9 @@ class ZodString extends ZodType {
|
|
|
3074
3252
|
uuid(message) {
|
|
3075
3253
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
3076
3254
|
}
|
|
3255
|
+
nanoid(message) {
|
|
3256
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
3257
|
+
}
|
|
3077
3258
|
cuid(message) {
|
|
3078
3259
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
3079
3260
|
}
|
|
@@ -3083,26 +3264,62 @@ class ZodString extends ZodType {
|
|
|
3083
3264
|
ulid(message) {
|
|
3084
3265
|
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
3085
3266
|
}
|
|
3267
|
+
base64(message) {
|
|
3268
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
3269
|
+
}
|
|
3270
|
+
base64url(message) {
|
|
3271
|
+
return this._addCheck({
|
|
3272
|
+
kind: "base64url",
|
|
3273
|
+
...errorUtil.errToObj(message)
|
|
3274
|
+
});
|
|
3275
|
+
}
|
|
3276
|
+
jwt(options) {
|
|
3277
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
3278
|
+
}
|
|
3086
3279
|
ip(options) {
|
|
3087
3280
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
3088
3281
|
}
|
|
3282
|
+
cidr(options) {
|
|
3283
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
3284
|
+
}
|
|
3089
3285
|
datetime(options) {
|
|
3090
|
-
var _a;
|
|
3091
3286
|
if (typeof options === "string") {
|
|
3092
3287
|
return this._addCheck({
|
|
3093
3288
|
kind: "datetime",
|
|
3094
3289
|
precision: null,
|
|
3095
3290
|
offset: false,
|
|
3291
|
+
local: false,
|
|
3096
3292
|
message: options
|
|
3097
3293
|
});
|
|
3098
3294
|
}
|
|
3099
3295
|
return this._addCheck({
|
|
3100
3296
|
kind: "datetime",
|
|
3101
|
-
precision: typeof (options
|
|
3102
|
-
offset: (
|
|
3103
|
-
|
|
3297
|
+
precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
|
|
3298
|
+
offset: (options == null ? void 0 : options.offset) ?? false,
|
|
3299
|
+
local: (options == null ? void 0 : options.local) ?? false,
|
|
3300
|
+
...errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
3303
|
+
date(message) {
|
|
3304
|
+
return this._addCheck({ kind: "date", message });
|
|
3305
|
+
}
|
|
3306
|
+
time(options) {
|
|
3307
|
+
if (typeof options === "string") {
|
|
3308
|
+
return this._addCheck({
|
|
3309
|
+
kind: "time",
|
|
3310
|
+
precision: null,
|
|
3311
|
+
message: options
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
return this._addCheck({
|
|
3315
|
+
kind: "time",
|
|
3316
|
+
precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
|
|
3317
|
+
...errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
3104
3318
|
});
|
|
3105
3319
|
}
|
|
3320
|
+
duration(message) {
|
|
3321
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
3322
|
+
}
|
|
3106
3323
|
regex(regex, message) {
|
|
3107
3324
|
return this._addCheck({
|
|
3108
3325
|
kind: "regex",
|
|
@@ -3114,8 +3331,8 @@ class ZodString extends ZodType {
|
|
|
3114
3331
|
return this._addCheck({
|
|
3115
3332
|
kind: "includes",
|
|
3116
3333
|
value,
|
|
3117
|
-
position: options
|
|
3118
|
-
...errorUtil.errToObj(options
|
|
3334
|
+
position: options == null ? void 0 : options.position,
|
|
3335
|
+
...errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
3119
3336
|
});
|
|
3120
3337
|
}
|
|
3121
3338
|
startsWith(value, message) {
|
|
@@ -3154,8 +3371,7 @@ class ZodString extends ZodType {
|
|
|
3154
3371
|
});
|
|
3155
3372
|
}
|
|
3156
3373
|
/**
|
|
3157
|
-
*
|
|
3158
|
-
* @see {@link ZodString.min}
|
|
3374
|
+
* Equivalent to `.min(1)`
|
|
3159
3375
|
*/
|
|
3160
3376
|
nonempty(message) {
|
|
3161
3377
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -3181,6 +3397,15 @@ class ZodString extends ZodType {
|
|
|
3181
3397
|
get isDatetime() {
|
|
3182
3398
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
3183
3399
|
}
|
|
3400
|
+
get isDate() {
|
|
3401
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
3402
|
+
}
|
|
3403
|
+
get isTime() {
|
|
3404
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
3405
|
+
}
|
|
3406
|
+
get isDuration() {
|
|
3407
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
3408
|
+
}
|
|
3184
3409
|
get isEmail() {
|
|
3185
3410
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
3186
3411
|
}
|
|
@@ -3193,6 +3418,9 @@ class ZodString extends ZodType {
|
|
|
3193
3418
|
get isUUID() {
|
|
3194
3419
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
3195
3420
|
}
|
|
3421
|
+
get isNANOID() {
|
|
3422
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
3423
|
+
}
|
|
3196
3424
|
get isCUID() {
|
|
3197
3425
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
3198
3426
|
}
|
|
@@ -3205,6 +3433,15 @@ class ZodString extends ZodType {
|
|
|
3205
3433
|
get isIP() {
|
|
3206
3434
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
3207
3435
|
}
|
|
3436
|
+
get isCIDR() {
|
|
3437
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
3438
|
+
}
|
|
3439
|
+
get isBase64() {
|
|
3440
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
3441
|
+
}
|
|
3442
|
+
get isBase64url() {
|
|
3443
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
3444
|
+
}
|
|
3208
3445
|
get minLength() {
|
|
3209
3446
|
let min = null;
|
|
3210
3447
|
for (const ch of this._def.checks) {
|
|
@@ -3227,11 +3464,10 @@ class ZodString extends ZodType {
|
|
|
3227
3464
|
}
|
|
3228
3465
|
}
|
|
3229
3466
|
ZodString.create = (params) => {
|
|
3230
|
-
var _a;
|
|
3231
3467
|
return new ZodString({
|
|
3232
3468
|
checks: [],
|
|
3233
3469
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
3234
|
-
coerce: (
|
|
3470
|
+
coerce: (params == null ? void 0 : params.coerce) ?? false,
|
|
3235
3471
|
...processCreateParams(params)
|
|
3236
3472
|
});
|
|
3237
3473
|
};
|
|
@@ -3239,9 +3475,9 @@ function floatSafeRemainder(val, step) {
|
|
|
3239
3475
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
3240
3476
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
3241
3477
|
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
3242
|
-
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
3243
|
-
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
3244
|
-
return valInt % stepInt /
|
|
3478
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
3479
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
3480
|
+
return valInt % stepInt / 10 ** decCount;
|
|
3245
3481
|
}
|
|
3246
3482
|
class ZodNumber extends ZodType {
|
|
3247
3483
|
constructor() {
|
|
@@ -3451,7 +3687,8 @@ class ZodNumber extends ZodType {
|
|
|
3451
3687
|
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
3452
3688
|
}
|
|
3453
3689
|
get isFinite() {
|
|
3454
|
-
let max = null
|
|
3690
|
+
let max = null;
|
|
3691
|
+
let min = null;
|
|
3455
3692
|
for (const ch of this._def.checks) {
|
|
3456
3693
|
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
3457
3694
|
return true;
|
|
@@ -3470,7 +3707,7 @@ ZodNumber.create = (params) => {
|
|
|
3470
3707
|
return new ZodNumber({
|
|
3471
3708
|
checks: [],
|
|
3472
3709
|
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
3473
|
-
coerce: (params
|
|
3710
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
3474
3711
|
...processCreateParams(params)
|
|
3475
3712
|
});
|
|
3476
3713
|
};
|
|
@@ -3482,17 +3719,15 @@ class ZodBigInt extends ZodType {
|
|
|
3482
3719
|
}
|
|
3483
3720
|
_parse(input) {
|
|
3484
3721
|
if (this._def.coerce) {
|
|
3485
|
-
|
|
3722
|
+
try {
|
|
3723
|
+
input.data = BigInt(input.data);
|
|
3724
|
+
} catch {
|
|
3725
|
+
return this._getInvalidInput(input);
|
|
3726
|
+
}
|
|
3486
3727
|
}
|
|
3487
3728
|
const parsedType = this._getType(input);
|
|
3488
3729
|
if (parsedType !== ZodParsedType.bigint) {
|
|
3489
|
-
|
|
3490
|
-
addIssueToContext(ctx2, {
|
|
3491
|
-
code: ZodIssueCode.invalid_type,
|
|
3492
|
-
expected: ZodParsedType.bigint,
|
|
3493
|
-
received: ctx2.parsedType
|
|
3494
|
-
});
|
|
3495
|
-
return INVALID;
|
|
3730
|
+
return this._getInvalidInput(input);
|
|
3496
3731
|
}
|
|
3497
3732
|
let ctx = void 0;
|
|
3498
3733
|
const status = new ParseStatus();
|
|
@@ -3539,6 +3774,15 @@ class ZodBigInt extends ZodType {
|
|
|
3539
3774
|
}
|
|
3540
3775
|
return { status: status.value, value: input.data };
|
|
3541
3776
|
}
|
|
3777
|
+
_getInvalidInput(input) {
|
|
3778
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3779
|
+
addIssueToContext(ctx, {
|
|
3780
|
+
code: ZodIssueCode.invalid_type,
|
|
3781
|
+
expected: ZodParsedType.bigint,
|
|
3782
|
+
received: ctx.parsedType
|
|
3783
|
+
});
|
|
3784
|
+
return INVALID;
|
|
3785
|
+
}
|
|
3542
3786
|
gte(value, message) {
|
|
3543
3787
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
3544
3788
|
}
|
|
@@ -3632,11 +3876,10 @@ class ZodBigInt extends ZodType {
|
|
|
3632
3876
|
}
|
|
3633
3877
|
}
|
|
3634
3878
|
ZodBigInt.create = (params) => {
|
|
3635
|
-
var _a;
|
|
3636
3879
|
return new ZodBigInt({
|
|
3637
3880
|
checks: [],
|
|
3638
3881
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
3639
|
-
coerce: (
|
|
3882
|
+
coerce: (params == null ? void 0 : params.coerce) ?? false,
|
|
3640
3883
|
...processCreateParams(params)
|
|
3641
3884
|
});
|
|
3642
3885
|
};
|
|
@@ -3661,7 +3904,7 @@ class ZodBoolean extends ZodType {
|
|
|
3661
3904
|
ZodBoolean.create = (params) => {
|
|
3662
3905
|
return new ZodBoolean({
|
|
3663
3906
|
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
3664
|
-
coerce: (params
|
|
3907
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
3665
3908
|
...processCreateParams(params)
|
|
3666
3909
|
});
|
|
3667
3910
|
};
|
|
@@ -3680,7 +3923,7 @@ class ZodDate extends ZodType {
|
|
|
3680
3923
|
});
|
|
3681
3924
|
return INVALID;
|
|
3682
3925
|
}
|
|
3683
|
-
if (isNaN(input.data.getTime())) {
|
|
3926
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
3684
3927
|
const ctx2 = this._getOrReturnCtx(input);
|
|
3685
3928
|
addIssueToContext(ctx2, {
|
|
3686
3929
|
code: ZodIssueCode.invalid_date
|
|
@@ -3769,7 +4012,7 @@ class ZodDate extends ZodType {
|
|
|
3769
4012
|
ZodDate.create = (params) => {
|
|
3770
4013
|
return new ZodDate({
|
|
3771
4014
|
checks: [],
|
|
3772
|
-
coerce: (params
|
|
4015
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
3773
4016
|
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
3774
4017
|
...processCreateParams(params)
|
|
3775
4018
|
});
|
|
@@ -4044,7 +4287,8 @@ class ZodObject extends ZodType {
|
|
|
4044
4287
|
return this._cached;
|
|
4045
4288
|
const shape = this._def.shape();
|
|
4046
4289
|
const keys = util.objectKeys(shape);
|
|
4047
|
-
|
|
4290
|
+
this._cached = { shape, keys };
|
|
4291
|
+
return this._cached;
|
|
4048
4292
|
}
|
|
4049
4293
|
_parse(input) {
|
|
4050
4294
|
const parsedType = this._getType(input);
|
|
@@ -4117,9 +4361,10 @@ class ZodObject extends ZodType {
|
|
|
4117
4361
|
const syncPairs = [];
|
|
4118
4362
|
for (const pair of pairs) {
|
|
4119
4363
|
const key = await pair.key;
|
|
4364
|
+
const value = await pair.value;
|
|
4120
4365
|
syncPairs.push({
|
|
4121
4366
|
key,
|
|
4122
|
-
value
|
|
4367
|
+
value,
|
|
4123
4368
|
alwaysSet: pair.alwaysSet
|
|
4124
4369
|
});
|
|
4125
4370
|
}
|
|
@@ -4141,11 +4386,11 @@ class ZodObject extends ZodType {
|
|
|
4141
4386
|
unknownKeys: "strict",
|
|
4142
4387
|
...message !== void 0 ? {
|
|
4143
4388
|
errorMap: (issue, ctx) => {
|
|
4144
|
-
var _a, _b
|
|
4145
|
-
const defaultError = (
|
|
4389
|
+
var _a, _b;
|
|
4390
|
+
const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) ?? ctx.defaultError;
|
|
4146
4391
|
if (issue.code === "unrecognized_keys")
|
|
4147
4392
|
return {
|
|
4148
|
-
message:
|
|
4393
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
4149
4394
|
};
|
|
4150
4395
|
return {
|
|
4151
4396
|
message: defaultError
|
|
@@ -4276,11 +4521,11 @@ class ZodObject extends ZodType {
|
|
|
4276
4521
|
}
|
|
4277
4522
|
pick(mask) {
|
|
4278
4523
|
const shape = {};
|
|
4279
|
-
util.objectKeys(mask)
|
|
4524
|
+
for (const key of util.objectKeys(mask)) {
|
|
4280
4525
|
if (mask[key] && this.shape[key]) {
|
|
4281
4526
|
shape[key] = this.shape[key];
|
|
4282
4527
|
}
|
|
4283
|
-
}
|
|
4528
|
+
}
|
|
4284
4529
|
return new ZodObject({
|
|
4285
4530
|
...this._def,
|
|
4286
4531
|
shape: () => shape
|
|
@@ -4288,11 +4533,11 @@ class ZodObject extends ZodType {
|
|
|
4288
4533
|
}
|
|
4289
4534
|
omit(mask) {
|
|
4290
4535
|
const shape = {};
|
|
4291
|
-
util.objectKeys(this.shape)
|
|
4536
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4292
4537
|
if (!mask[key]) {
|
|
4293
4538
|
shape[key] = this.shape[key];
|
|
4294
4539
|
}
|
|
4295
|
-
}
|
|
4540
|
+
}
|
|
4296
4541
|
return new ZodObject({
|
|
4297
4542
|
...this._def,
|
|
4298
4543
|
shape: () => shape
|
|
@@ -4306,14 +4551,14 @@ class ZodObject extends ZodType {
|
|
|
4306
4551
|
}
|
|
4307
4552
|
partial(mask) {
|
|
4308
4553
|
const newShape = {};
|
|
4309
|
-
util.objectKeys(this.shape)
|
|
4554
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4310
4555
|
const fieldSchema = this.shape[key];
|
|
4311
4556
|
if (mask && !mask[key]) {
|
|
4312
4557
|
newShape[key] = fieldSchema;
|
|
4313
4558
|
} else {
|
|
4314
4559
|
newShape[key] = fieldSchema.optional();
|
|
4315
4560
|
}
|
|
4316
|
-
}
|
|
4561
|
+
}
|
|
4317
4562
|
return new ZodObject({
|
|
4318
4563
|
...this._def,
|
|
4319
4564
|
shape: () => newShape
|
|
@@ -4321,7 +4566,7 @@ class ZodObject extends ZodType {
|
|
|
4321
4566
|
}
|
|
4322
4567
|
required(mask) {
|
|
4323
4568
|
const newShape = {};
|
|
4324
|
-
util.objectKeys(this.shape)
|
|
4569
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4325
4570
|
if (mask && !mask[key]) {
|
|
4326
4571
|
newShape[key] = this.shape[key];
|
|
4327
4572
|
} else {
|
|
@@ -4332,7 +4577,7 @@ class ZodObject extends ZodType {
|
|
|
4332
4577
|
}
|
|
4333
4578
|
newShape[key] = newField;
|
|
4334
4579
|
}
|
|
4335
|
-
}
|
|
4580
|
+
}
|
|
4336
4581
|
return new ZodObject({
|
|
4337
4582
|
...this._def,
|
|
4338
4583
|
shape: () => newShape
|
|
@@ -4460,103 +4705,6 @@ ZodUnion.create = (types, params) => {
|
|
|
4460
4705
|
...processCreateParams(params)
|
|
4461
4706
|
});
|
|
4462
4707
|
};
|
|
4463
|
-
const getDiscriminator = (type) => {
|
|
4464
|
-
if (type instanceof ZodLazy) {
|
|
4465
|
-
return getDiscriminator(type.schema);
|
|
4466
|
-
} else if (type instanceof ZodEffects) {
|
|
4467
|
-
return getDiscriminator(type.innerType());
|
|
4468
|
-
} else if (type instanceof ZodLiteral) {
|
|
4469
|
-
return [type.value];
|
|
4470
|
-
} else if (type instanceof ZodEnum) {
|
|
4471
|
-
return type.options;
|
|
4472
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
4473
|
-
return Object.keys(type.enum);
|
|
4474
|
-
} else if (type instanceof ZodDefault) {
|
|
4475
|
-
return getDiscriminator(type._def.innerType);
|
|
4476
|
-
} else if (type instanceof ZodUndefined) {
|
|
4477
|
-
return [void 0];
|
|
4478
|
-
} else if (type instanceof ZodNull) {
|
|
4479
|
-
return [null];
|
|
4480
|
-
} else {
|
|
4481
|
-
return null;
|
|
4482
|
-
}
|
|
4483
|
-
};
|
|
4484
|
-
class ZodDiscriminatedUnion extends ZodType {
|
|
4485
|
-
_parse(input) {
|
|
4486
|
-
const { ctx } = this._processInputParams(input);
|
|
4487
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4488
|
-
addIssueToContext(ctx, {
|
|
4489
|
-
code: ZodIssueCode.invalid_type,
|
|
4490
|
-
expected: ZodParsedType.object,
|
|
4491
|
-
received: ctx.parsedType
|
|
4492
|
-
});
|
|
4493
|
-
return INVALID;
|
|
4494
|
-
}
|
|
4495
|
-
const discriminator = this.discriminator;
|
|
4496
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
4497
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
4498
|
-
if (!option) {
|
|
4499
|
-
addIssueToContext(ctx, {
|
|
4500
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
4501
|
-
options: Array.from(this.optionsMap.keys()),
|
|
4502
|
-
path: [discriminator]
|
|
4503
|
-
});
|
|
4504
|
-
return INVALID;
|
|
4505
|
-
}
|
|
4506
|
-
if (ctx.common.async) {
|
|
4507
|
-
return option._parseAsync({
|
|
4508
|
-
data: ctx.data,
|
|
4509
|
-
path: ctx.path,
|
|
4510
|
-
parent: ctx
|
|
4511
|
-
});
|
|
4512
|
-
} else {
|
|
4513
|
-
return option._parseSync({
|
|
4514
|
-
data: ctx.data,
|
|
4515
|
-
path: ctx.path,
|
|
4516
|
-
parent: ctx
|
|
4517
|
-
});
|
|
4518
|
-
}
|
|
4519
|
-
}
|
|
4520
|
-
get discriminator() {
|
|
4521
|
-
return this._def.discriminator;
|
|
4522
|
-
}
|
|
4523
|
-
get options() {
|
|
4524
|
-
return this._def.options;
|
|
4525
|
-
}
|
|
4526
|
-
get optionsMap() {
|
|
4527
|
-
return this._def.optionsMap;
|
|
4528
|
-
}
|
|
4529
|
-
/**
|
|
4530
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
4531
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
4532
|
-
* have a different value for each object in the union.
|
|
4533
|
-
* @param discriminator the name of the discriminator property
|
|
4534
|
-
* @param types an array of object schemas
|
|
4535
|
-
* @param params
|
|
4536
|
-
*/
|
|
4537
|
-
static create(discriminator, options, params) {
|
|
4538
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
4539
|
-
for (const type of options) {
|
|
4540
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
4541
|
-
if (!discriminatorValues) {
|
|
4542
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
4543
|
-
}
|
|
4544
|
-
for (const value of discriminatorValues) {
|
|
4545
|
-
if (optionsMap.has(value)) {
|
|
4546
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
4547
|
-
}
|
|
4548
|
-
optionsMap.set(value, type);
|
|
4549
|
-
}
|
|
4550
|
-
}
|
|
4551
|
-
return new ZodDiscriminatedUnion({
|
|
4552
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
4553
|
-
discriminator,
|
|
4554
|
-
options,
|
|
4555
|
-
optionsMap,
|
|
4556
|
-
...processCreateParams(params)
|
|
4557
|
-
});
|
|
4558
|
-
}
|
|
4559
|
-
}
|
|
4560
4708
|
function mergeValues(a2, b) {
|
|
4561
4709
|
const aType = getParsedType(a2);
|
|
4562
4710
|
const bType = getParsedType(b);
|
|
@@ -4715,58 +4863,6 @@ ZodTuple.create = (schemas, params) => {
|
|
|
4715
4863
|
...processCreateParams(params)
|
|
4716
4864
|
});
|
|
4717
4865
|
};
|
|
4718
|
-
class ZodRecord extends ZodType {
|
|
4719
|
-
get keySchema() {
|
|
4720
|
-
return this._def.keyType;
|
|
4721
|
-
}
|
|
4722
|
-
get valueSchema() {
|
|
4723
|
-
return this._def.valueType;
|
|
4724
|
-
}
|
|
4725
|
-
_parse(input) {
|
|
4726
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4727
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4728
|
-
addIssueToContext(ctx, {
|
|
4729
|
-
code: ZodIssueCode.invalid_type,
|
|
4730
|
-
expected: ZodParsedType.object,
|
|
4731
|
-
received: ctx.parsedType
|
|
4732
|
-
});
|
|
4733
|
-
return INVALID;
|
|
4734
|
-
}
|
|
4735
|
-
const pairs = [];
|
|
4736
|
-
const keyType = this._def.keyType;
|
|
4737
|
-
const valueType = this._def.valueType;
|
|
4738
|
-
for (const key in ctx.data) {
|
|
4739
|
-
pairs.push({
|
|
4740
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
4741
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
|
4742
|
-
});
|
|
4743
|
-
}
|
|
4744
|
-
if (ctx.common.async) {
|
|
4745
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
4746
|
-
} else {
|
|
4747
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
4748
|
-
}
|
|
4749
|
-
}
|
|
4750
|
-
get element() {
|
|
4751
|
-
return this._def.valueType;
|
|
4752
|
-
}
|
|
4753
|
-
static create(first, second, third) {
|
|
4754
|
-
if (second instanceof ZodType) {
|
|
4755
|
-
return new ZodRecord({
|
|
4756
|
-
keyType: first,
|
|
4757
|
-
valueType: second,
|
|
4758
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
4759
|
-
...processCreateParams(third)
|
|
4760
|
-
});
|
|
4761
|
-
}
|
|
4762
|
-
return new ZodRecord({
|
|
4763
|
-
keyType: ZodString.create(),
|
|
4764
|
-
valueType: first,
|
|
4765
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
4766
|
-
...processCreateParams(second)
|
|
4767
|
-
});
|
|
4768
|
-
}
|
|
4769
|
-
}
|
|
4770
4866
|
class ZodMap extends ZodType {
|
|
4771
4867
|
get keySchema() {
|
|
4772
4868
|
return this._def.keyType;
|
|
@@ -4918,121 +5014,6 @@ ZodSet.create = (valueType, params) => {
|
|
|
4918
5014
|
...processCreateParams(params)
|
|
4919
5015
|
});
|
|
4920
5016
|
};
|
|
4921
|
-
class ZodFunction extends ZodType {
|
|
4922
|
-
constructor() {
|
|
4923
|
-
super(...arguments);
|
|
4924
|
-
this.validate = this.implement;
|
|
4925
|
-
}
|
|
4926
|
-
_parse(input) {
|
|
4927
|
-
const { ctx } = this._processInputParams(input);
|
|
4928
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
4929
|
-
addIssueToContext(ctx, {
|
|
4930
|
-
code: ZodIssueCode.invalid_type,
|
|
4931
|
-
expected: ZodParsedType.function,
|
|
4932
|
-
received: ctx.parsedType
|
|
4933
|
-
});
|
|
4934
|
-
return INVALID;
|
|
4935
|
-
}
|
|
4936
|
-
function makeArgsIssue(args, error) {
|
|
4937
|
-
return makeIssue({
|
|
4938
|
-
data: args,
|
|
4939
|
-
path: ctx.path,
|
|
4940
|
-
errorMaps: [
|
|
4941
|
-
ctx.common.contextualErrorMap,
|
|
4942
|
-
ctx.schemaErrorMap,
|
|
4943
|
-
getErrorMap(),
|
|
4944
|
-
errorMap
|
|
4945
|
-
].filter((x) => !!x),
|
|
4946
|
-
issueData: {
|
|
4947
|
-
code: ZodIssueCode.invalid_arguments,
|
|
4948
|
-
argumentsError: error
|
|
4949
|
-
}
|
|
4950
|
-
});
|
|
4951
|
-
}
|
|
4952
|
-
function makeReturnsIssue(returns, error) {
|
|
4953
|
-
return makeIssue({
|
|
4954
|
-
data: returns,
|
|
4955
|
-
path: ctx.path,
|
|
4956
|
-
errorMaps: [
|
|
4957
|
-
ctx.common.contextualErrorMap,
|
|
4958
|
-
ctx.schemaErrorMap,
|
|
4959
|
-
getErrorMap(),
|
|
4960
|
-
errorMap
|
|
4961
|
-
].filter((x) => !!x),
|
|
4962
|
-
issueData: {
|
|
4963
|
-
code: ZodIssueCode.invalid_return_type,
|
|
4964
|
-
returnTypeError: error
|
|
4965
|
-
}
|
|
4966
|
-
});
|
|
4967
|
-
}
|
|
4968
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
4969
|
-
const fn = ctx.data;
|
|
4970
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
4971
|
-
const me = this;
|
|
4972
|
-
return OK(async function(...args) {
|
|
4973
|
-
const error = new ZodError([]);
|
|
4974
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => {
|
|
4975
|
-
error.addIssue(makeArgsIssue(args, e2));
|
|
4976
|
-
throw error;
|
|
4977
|
-
});
|
|
4978
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
4979
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => {
|
|
4980
|
-
error.addIssue(makeReturnsIssue(result, e2));
|
|
4981
|
-
throw error;
|
|
4982
|
-
});
|
|
4983
|
-
return parsedReturns;
|
|
4984
|
-
});
|
|
4985
|
-
} else {
|
|
4986
|
-
const me = this;
|
|
4987
|
-
return OK(function(...args) {
|
|
4988
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
4989
|
-
if (!parsedArgs.success) {
|
|
4990
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
4991
|
-
}
|
|
4992
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
4993
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
4994
|
-
if (!parsedReturns.success) {
|
|
4995
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
4996
|
-
}
|
|
4997
|
-
return parsedReturns.data;
|
|
4998
|
-
});
|
|
4999
|
-
}
|
|
5000
|
-
}
|
|
5001
|
-
parameters() {
|
|
5002
|
-
return this._def.args;
|
|
5003
|
-
}
|
|
5004
|
-
returnType() {
|
|
5005
|
-
return this._def.returns;
|
|
5006
|
-
}
|
|
5007
|
-
args(...items) {
|
|
5008
|
-
return new ZodFunction({
|
|
5009
|
-
...this._def,
|
|
5010
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
5011
|
-
});
|
|
5012
|
-
}
|
|
5013
|
-
returns(returnType) {
|
|
5014
|
-
return new ZodFunction({
|
|
5015
|
-
...this._def,
|
|
5016
|
-
returns: returnType
|
|
5017
|
-
});
|
|
5018
|
-
}
|
|
5019
|
-
implement(func) {
|
|
5020
|
-
const validatedFunc = this.parse(func);
|
|
5021
|
-
return validatedFunc;
|
|
5022
|
-
}
|
|
5023
|
-
strictImplement(func) {
|
|
5024
|
-
const validatedFunc = this.parse(func);
|
|
5025
|
-
return validatedFunc;
|
|
5026
|
-
}
|
|
5027
|
-
static create(args, returns, params) {
|
|
5028
|
-
return new ZodFunction({
|
|
5029
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
5030
|
-
returns: returns || ZodUnknown.create(),
|
|
5031
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
5032
|
-
...processCreateParams(params)
|
|
5033
|
-
});
|
|
5034
|
-
}
|
|
5035
|
-
}
|
|
5036
5017
|
class ZodLazy extends ZodType {
|
|
5037
5018
|
get schema() {
|
|
5038
5019
|
return this._def.getter();
|
|
@@ -5093,7 +5074,10 @@ class ZodEnum extends ZodType {
|
|
|
5093
5074
|
});
|
|
5094
5075
|
return INVALID;
|
|
5095
5076
|
}
|
|
5096
|
-
if (this.
|
|
5077
|
+
if (!this._cache) {
|
|
5078
|
+
this._cache = new Set(this._def.values);
|
|
5079
|
+
}
|
|
5080
|
+
if (!this._cache.has(input.data)) {
|
|
5097
5081
|
const ctx = this._getOrReturnCtx(input);
|
|
5098
5082
|
const expectedValues = this._def.values;
|
|
5099
5083
|
addIssueToContext(ctx, {
|
|
@@ -5129,11 +5113,17 @@ class ZodEnum extends ZodType {
|
|
|
5129
5113
|
}
|
|
5130
5114
|
return enumValues;
|
|
5131
5115
|
}
|
|
5132
|
-
extract(values) {
|
|
5133
|
-
return ZodEnum.create(values
|
|
5116
|
+
extract(values, newDef = this._def) {
|
|
5117
|
+
return ZodEnum.create(values, {
|
|
5118
|
+
...this._def,
|
|
5119
|
+
...newDef
|
|
5120
|
+
});
|
|
5134
5121
|
}
|
|
5135
|
-
exclude(values) {
|
|
5136
|
-
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt))
|
|
5122
|
+
exclude(values, newDef = this._def) {
|
|
5123
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
5124
|
+
...this._def,
|
|
5125
|
+
...newDef
|
|
5126
|
+
});
|
|
5137
5127
|
}
|
|
5138
5128
|
}
|
|
5139
5129
|
ZodEnum.create = createZodEnum;
|
|
@@ -5150,7 +5140,10 @@ class ZodNativeEnum extends ZodType {
|
|
|
5150
5140
|
});
|
|
5151
5141
|
return INVALID;
|
|
5152
5142
|
}
|
|
5153
|
-
if (
|
|
5143
|
+
if (!this._cache) {
|
|
5144
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
5145
|
+
}
|
|
5146
|
+
if (!this._cache.has(input.data)) {
|
|
5154
5147
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
5155
5148
|
addIssueToContext(ctx, {
|
|
5156
5149
|
received: ctx.data,
|
|
@@ -5228,26 +5221,38 @@ class ZodEffects extends ZodType {
|
|
|
5228
5221
|
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
5229
5222
|
if (effect.type === "preprocess") {
|
|
5230
5223
|
const processed = effect.transform(ctx.data, checkCtx);
|
|
5231
|
-
if (ctx.common.issues.length) {
|
|
5232
|
-
return {
|
|
5233
|
-
status: "dirty",
|
|
5234
|
-
value: ctx.data
|
|
5235
|
-
};
|
|
5236
|
-
}
|
|
5237
5224
|
if (ctx.common.async) {
|
|
5238
|
-
return Promise.resolve(processed).then((processed2) => {
|
|
5239
|
-
|
|
5225
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
5226
|
+
if (status.value === "aborted")
|
|
5227
|
+
return INVALID;
|
|
5228
|
+
const result = await this._def.schema._parseAsync({
|
|
5240
5229
|
data: processed2,
|
|
5241
5230
|
path: ctx.path,
|
|
5242
5231
|
parent: ctx
|
|
5243
5232
|
});
|
|
5233
|
+
if (result.status === "aborted")
|
|
5234
|
+
return INVALID;
|
|
5235
|
+
if (result.status === "dirty")
|
|
5236
|
+
return DIRTY(result.value);
|
|
5237
|
+
if (status.value === "dirty")
|
|
5238
|
+
return DIRTY(result.value);
|
|
5239
|
+
return result;
|
|
5244
5240
|
});
|
|
5245
5241
|
} else {
|
|
5246
|
-
|
|
5242
|
+
if (status.value === "aborted")
|
|
5243
|
+
return INVALID;
|
|
5244
|
+
const result = this._def.schema._parseSync({
|
|
5247
5245
|
data: processed,
|
|
5248
5246
|
path: ctx.path,
|
|
5249
5247
|
parent: ctx
|
|
5250
5248
|
});
|
|
5249
|
+
if (result.status === "aborted")
|
|
5250
|
+
return INVALID;
|
|
5251
|
+
if (result.status === "dirty")
|
|
5252
|
+
return DIRTY(result.value);
|
|
5253
|
+
if (status.value === "dirty")
|
|
5254
|
+
return DIRTY(result.value);
|
|
5255
|
+
return result;
|
|
5251
5256
|
}
|
|
5252
5257
|
}
|
|
5253
5258
|
if (effect.type === "refinement") {
|
|
@@ -5293,7 +5298,7 @@ class ZodEffects extends ZodType {
|
|
|
5293
5298
|
parent: ctx
|
|
5294
5299
|
});
|
|
5295
5300
|
if (!isValid(base))
|
|
5296
|
-
return
|
|
5301
|
+
return INVALID;
|
|
5297
5302
|
const result = effect.transform(base.value, checkCtx);
|
|
5298
5303
|
if (result instanceof Promise) {
|
|
5299
5304
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
@@ -5302,8 +5307,11 @@ class ZodEffects extends ZodType {
|
|
|
5302
5307
|
} else {
|
|
5303
5308
|
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
5304
5309
|
if (!isValid(base))
|
|
5305
|
-
return
|
|
5306
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
5310
|
+
return INVALID;
|
|
5311
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
5312
|
+
status: status.value,
|
|
5313
|
+
value: result
|
|
5314
|
+
}));
|
|
5307
5315
|
});
|
|
5308
5316
|
}
|
|
5309
5317
|
}
|
|
@@ -5463,7 +5471,6 @@ ZodNaN.create = (params) => {
|
|
|
5463
5471
|
...processCreateParams(params)
|
|
5464
5472
|
});
|
|
5465
5473
|
};
|
|
5466
|
-
const BRAND = Symbol("zod_brand");
|
|
5467
5474
|
class ZodBranded extends ZodType {
|
|
5468
5475
|
_parse(input) {
|
|
5469
5476
|
const { ctx } = this._processInputParams(input);
|
|
@@ -5536,10 +5543,16 @@ class ZodPipeline extends ZodType {
|
|
|
5536
5543
|
class ZodReadonly extends ZodType {
|
|
5537
5544
|
_parse(input) {
|
|
5538
5545
|
const result = this._def.innerType._parse(input);
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5546
|
+
const freeze = (data) => {
|
|
5547
|
+
if (isValid(data)) {
|
|
5548
|
+
data.value = Object.freeze(data.value);
|
|
5549
|
+
}
|
|
5550
|
+
return data;
|
|
5551
|
+
};
|
|
5552
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
5553
|
+
}
|
|
5554
|
+
unwrap() {
|
|
5555
|
+
return this._def.innerType;
|
|
5543
5556
|
}
|
|
5544
5557
|
}
|
|
5545
5558
|
ZodReadonly.create = (type, params) => {
|
|
@@ -5549,22 +5562,6 @@ ZodReadonly.create = (type, params) => {
|
|
|
5549
5562
|
...processCreateParams(params)
|
|
5550
5563
|
});
|
|
5551
5564
|
};
|
|
5552
|
-
const custom = (check, params = {}, fatal) => {
|
|
5553
|
-
if (check)
|
|
5554
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
5555
|
-
var _a, _b;
|
|
5556
|
-
if (!check(data)) {
|
|
5557
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
5558
|
-
const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
5559
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
5560
|
-
ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
|
|
5561
|
-
}
|
|
5562
|
-
});
|
|
5563
|
-
return ZodAny.create();
|
|
5564
|
-
};
|
|
5565
|
-
const late = {
|
|
5566
|
-
object: ZodObject.lazycreate
|
|
5567
|
-
};
|
|
5568
5565
|
var ZodFirstPartyTypeKind;
|
|
5569
5566
|
(function(ZodFirstPartyTypeKind2) {
|
|
5570
5567
|
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
@@ -5604,177 +5601,25 @@ var ZodFirstPartyTypeKind;
|
|
|
5604
5601
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
5605
5602
|
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
5606
5603
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
5607
|
-
const instanceOfType = (cls, params = {
|
|
5608
|
-
message: `Input not instance of ${cls.name}`
|
|
5609
|
-
}) => custom((data) => data instanceof cls, params);
|
|
5610
5604
|
const stringType = ZodString.create;
|
|
5611
5605
|
const numberType = ZodNumber.create;
|
|
5612
|
-
const nanType = ZodNaN.create;
|
|
5613
|
-
const bigIntType = ZodBigInt.create;
|
|
5614
5606
|
const booleanType = ZodBoolean.create;
|
|
5615
5607
|
const dateType = ZodDate.create;
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
const nullType = ZodNull.create;
|
|
5619
|
-
const anyType = ZodAny.create;
|
|
5620
|
-
const unknownType = ZodUnknown.create;
|
|
5621
|
-
const neverType = ZodNever.create;
|
|
5622
|
-
const voidType = ZodVoid.create;
|
|
5623
|
-
const arrayType = ZodArray.create;
|
|
5608
|
+
ZodNever.create;
|
|
5609
|
+
ZodArray.create;
|
|
5624
5610
|
const objectType = ZodObject.create;
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
const intersectionType = ZodIntersection.create;
|
|
5629
|
-
const tupleType = ZodTuple.create;
|
|
5630
|
-
const recordType = ZodRecord.create;
|
|
5631
|
-
const mapType = ZodMap.create;
|
|
5632
|
-
const setType = ZodSet.create;
|
|
5633
|
-
const functionType = ZodFunction.create;
|
|
5634
|
-
const lazyType = ZodLazy.create;
|
|
5635
|
-
const literalType = ZodLiteral.create;
|
|
5611
|
+
ZodUnion.create;
|
|
5612
|
+
ZodIntersection.create;
|
|
5613
|
+
ZodTuple.create;
|
|
5636
5614
|
const enumType = ZodEnum.create;
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
const
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
const onumber = () => numberType().optional();
|
|
5646
|
-
const oboolean = () => booleanType().optional();
|
|
5647
|
-
const coerce = {
|
|
5648
|
-
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
5649
|
-
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
5650
|
-
boolean: (arg) => ZodBoolean.create({
|
|
5651
|
-
...arg,
|
|
5652
|
-
coerce: true
|
|
5653
|
-
}),
|
|
5654
|
-
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
5655
|
-
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
5656
|
-
};
|
|
5657
|
-
const NEVER = INVALID;
|
|
5658
|
-
var z = /* @__PURE__ */ Object.freeze({
|
|
5659
|
-
__proto__: null,
|
|
5660
|
-
defaultErrorMap: errorMap,
|
|
5661
|
-
setErrorMap,
|
|
5662
|
-
getErrorMap,
|
|
5663
|
-
makeIssue,
|
|
5664
|
-
EMPTY_PATH,
|
|
5665
|
-
addIssueToContext,
|
|
5666
|
-
ParseStatus,
|
|
5667
|
-
INVALID,
|
|
5668
|
-
DIRTY,
|
|
5669
|
-
OK,
|
|
5670
|
-
isAborted,
|
|
5671
|
-
isDirty,
|
|
5672
|
-
isValid,
|
|
5673
|
-
isAsync,
|
|
5674
|
-
get util() {
|
|
5675
|
-
return util;
|
|
5676
|
-
},
|
|
5677
|
-
get objectUtil() {
|
|
5678
|
-
return objectUtil;
|
|
5679
|
-
},
|
|
5680
|
-
ZodParsedType,
|
|
5681
|
-
getParsedType,
|
|
5682
|
-
ZodType,
|
|
5683
|
-
ZodString,
|
|
5684
|
-
ZodNumber,
|
|
5685
|
-
ZodBigInt,
|
|
5686
|
-
ZodBoolean,
|
|
5687
|
-
ZodDate,
|
|
5688
|
-
ZodSymbol,
|
|
5689
|
-
ZodUndefined,
|
|
5690
|
-
ZodNull,
|
|
5691
|
-
ZodAny,
|
|
5692
|
-
ZodUnknown,
|
|
5693
|
-
ZodNever,
|
|
5694
|
-
ZodVoid,
|
|
5695
|
-
ZodArray,
|
|
5696
|
-
ZodObject,
|
|
5697
|
-
ZodUnion,
|
|
5698
|
-
ZodDiscriminatedUnion,
|
|
5699
|
-
ZodIntersection,
|
|
5700
|
-
ZodTuple,
|
|
5701
|
-
ZodRecord,
|
|
5702
|
-
ZodMap,
|
|
5703
|
-
ZodSet,
|
|
5704
|
-
ZodFunction,
|
|
5705
|
-
ZodLazy,
|
|
5706
|
-
ZodLiteral,
|
|
5707
|
-
ZodEnum,
|
|
5708
|
-
ZodNativeEnum,
|
|
5709
|
-
ZodPromise,
|
|
5710
|
-
ZodEffects,
|
|
5711
|
-
ZodTransformer: ZodEffects,
|
|
5712
|
-
ZodOptional,
|
|
5713
|
-
ZodNullable,
|
|
5714
|
-
ZodDefault,
|
|
5715
|
-
ZodCatch,
|
|
5716
|
-
ZodNaN,
|
|
5717
|
-
BRAND,
|
|
5718
|
-
ZodBranded,
|
|
5719
|
-
ZodPipeline,
|
|
5720
|
-
ZodReadonly,
|
|
5721
|
-
custom,
|
|
5722
|
-
Schema: ZodType,
|
|
5723
|
-
ZodSchema: ZodType,
|
|
5724
|
-
late,
|
|
5725
|
-
get ZodFirstPartyTypeKind() {
|
|
5726
|
-
return ZodFirstPartyTypeKind;
|
|
5727
|
-
},
|
|
5728
|
-
coerce,
|
|
5729
|
-
any: anyType,
|
|
5730
|
-
array: arrayType,
|
|
5731
|
-
bigint: bigIntType,
|
|
5732
|
-
boolean: booleanType,
|
|
5733
|
-
date: dateType,
|
|
5734
|
-
discriminatedUnion: discriminatedUnionType,
|
|
5735
|
-
effect: effectsType,
|
|
5736
|
-
"enum": enumType,
|
|
5737
|
-
"function": functionType,
|
|
5738
|
-
"instanceof": instanceOfType,
|
|
5739
|
-
intersection: intersectionType,
|
|
5740
|
-
lazy: lazyType,
|
|
5741
|
-
literal: literalType,
|
|
5742
|
-
map: mapType,
|
|
5743
|
-
nan: nanType,
|
|
5744
|
-
nativeEnum: nativeEnumType,
|
|
5745
|
-
never: neverType,
|
|
5746
|
-
"null": nullType,
|
|
5747
|
-
nullable: nullableType,
|
|
5748
|
-
number: numberType,
|
|
5749
|
-
object: objectType,
|
|
5750
|
-
oboolean,
|
|
5751
|
-
onumber,
|
|
5752
|
-
optional: optionalType,
|
|
5753
|
-
ostring,
|
|
5754
|
-
pipeline: pipelineType,
|
|
5755
|
-
preprocess: preprocessType,
|
|
5756
|
-
promise: promiseType,
|
|
5757
|
-
record: recordType,
|
|
5758
|
-
set: setType,
|
|
5759
|
-
strictObject: strictObjectType,
|
|
5760
|
-
string: stringType,
|
|
5761
|
-
symbol: symbolType,
|
|
5762
|
-
transformer: effectsType,
|
|
5763
|
-
tuple: tupleType,
|
|
5764
|
-
"undefined": undefinedType,
|
|
5765
|
-
union: unionType,
|
|
5766
|
-
unknown: unknownType,
|
|
5767
|
-
"void": voidType,
|
|
5768
|
-
NEVER,
|
|
5769
|
-
ZodIssueCode,
|
|
5770
|
-
quotelessJson,
|
|
5771
|
-
ZodError
|
|
5772
|
-
});
|
|
5773
|
-
const quoteSequenceSchema = z.object({
|
|
5774
|
-
start_date: z.date().optional(),
|
|
5775
|
-
end_date: z.date().optional(),
|
|
5776
|
-
next_seq: z.number().min(1, "Next sequence must be at least 1").optional(),
|
|
5777
|
-
auto_generate_dates: z.boolean().optional().default(true)
|
|
5615
|
+
ZodPromise.create;
|
|
5616
|
+
ZodOptional.create;
|
|
5617
|
+
ZodNullable.create;
|
|
5618
|
+
const quoteSequenceSchema = objectType({
|
|
5619
|
+
start_date: dateType().optional(),
|
|
5620
|
+
end_date: dateType().optional(),
|
|
5621
|
+
next_seq: numberType().min(1, "Next sequence must be at least 1").optional(),
|
|
5622
|
+
auto_generate_dates: booleanType().optional().default(true)
|
|
5778
5623
|
}).refine(
|
|
5779
5624
|
(data) => {
|
|
5780
5625
|
if (data.start_date && data.end_date) {
|
|
@@ -6172,10 +6017,10 @@ const ActiveSequenceDisplay = () => {
|
|
|
6172
6017
|
)
|
|
6173
6018
|
] });
|
|
6174
6019
|
};
|
|
6175
|
-
const quoteConfigSchema =
|
|
6176
|
-
prefix:
|
|
6177
|
-
suffix:
|
|
6178
|
-
seq_type:
|
|
6020
|
+
const quoteConfigSchema = objectType({
|
|
6021
|
+
prefix: stringType().min(1, "Prefix is required").max(10, "Prefix must be 10 characters or less"),
|
|
6022
|
+
suffix: stringType().max(10, "Suffix must be 10 characters or less").optional(),
|
|
6023
|
+
seq_type: enumType(["monthly", "yearly"], {
|
|
6179
6024
|
required_error: "Sequence type is required"
|
|
6180
6025
|
})
|
|
6181
6026
|
});
|