@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
|
@@ -2037,7 +2037,8 @@ var n = function(e2, o2) {
|
|
|
2037
2037
|
};
|
|
2038
2038
|
var util;
|
|
2039
2039
|
(function(util2) {
|
|
2040
|
-
util2.assertEqual = (
|
|
2040
|
+
util2.assertEqual = (_) => {
|
|
2041
|
+
};
|
|
2041
2042
|
function assertIs(_arg) {
|
|
2042
2043
|
}
|
|
2043
2044
|
util2.assertIs = assertIs;
|
|
@@ -2081,7 +2082,7 @@ var util;
|
|
|
2081
2082
|
}
|
|
2082
2083
|
return void 0;
|
|
2083
2084
|
};
|
|
2084
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
2085
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
2085
2086
|
function joinValues(array, separator = " | ") {
|
|
2086
2087
|
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
2087
2088
|
}
|
|
@@ -2133,7 +2134,7 @@ const getParsedType = (data) => {
|
|
|
2133
2134
|
case "string":
|
|
2134
2135
|
return ZodParsedType.string;
|
|
2135
2136
|
case "number":
|
|
2136
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
2137
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
2137
2138
|
case "boolean":
|
|
2138
2139
|
return ZodParsedType.boolean;
|
|
2139
2140
|
case "function":
|
|
@@ -2184,11 +2185,10 @@ const ZodIssueCode = util.arrayToEnum([
|
|
|
2184
2185
|
"not_multiple_of",
|
|
2185
2186
|
"not_finite"
|
|
2186
2187
|
]);
|
|
2187
|
-
const quotelessJson = (obj) => {
|
|
2188
|
-
const json = JSON.stringify(obj, null, 2);
|
|
2189
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
2190
|
-
};
|
|
2191
2188
|
class ZodError extends Error {
|
|
2189
|
+
get errors() {
|
|
2190
|
+
return this.issues;
|
|
2191
|
+
}
|
|
2192
2192
|
constructor(issues) {
|
|
2193
2193
|
super();
|
|
2194
2194
|
this.issues = [];
|
|
@@ -2207,9 +2207,6 @@ class ZodError extends Error {
|
|
|
2207
2207
|
this.name = "ZodError";
|
|
2208
2208
|
this.issues = issues;
|
|
2209
2209
|
}
|
|
2210
|
-
get errors() {
|
|
2211
|
-
return this.issues;
|
|
2212
|
-
}
|
|
2213
2210
|
format(_mapper) {
|
|
2214
2211
|
const mapper = _mapper || function(issue) {
|
|
2215
2212
|
return issue.message;
|
|
@@ -2246,6 +2243,11 @@ class ZodError extends Error {
|
|
|
2246
2243
|
processError(this);
|
|
2247
2244
|
return fieldErrors;
|
|
2248
2245
|
}
|
|
2246
|
+
static assert(value) {
|
|
2247
|
+
if (!(value instanceof ZodError)) {
|
|
2248
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2249
2251
|
toString() {
|
|
2250
2252
|
return this.message;
|
|
2251
2253
|
}
|
|
@@ -2260,8 +2262,9 @@ class ZodError extends Error {
|
|
|
2260
2262
|
const formErrors = [];
|
|
2261
2263
|
for (const sub of this.issues) {
|
|
2262
2264
|
if (sub.path.length > 0) {
|
|
2263
|
-
|
|
2264
|
-
fieldErrors[
|
|
2265
|
+
const firstEl = sub.path[0];
|
|
2266
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
2267
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
2265
2268
|
} else {
|
|
2266
2269
|
formErrors.push(mapper(sub));
|
|
2267
2270
|
}
|
|
@@ -2337,6 +2340,8 @@ const errorMap = (issue, _ctx) => {
|
|
|
2337
2340
|
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
2338
2341
|
else if (issue.type === "number")
|
|
2339
2342
|
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
2343
|
+
else if (issue.type === "bigint")
|
|
2344
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
2340
2345
|
else if (issue.type === "date")
|
|
2341
2346
|
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
2342
2347
|
else
|
|
@@ -2375,9 +2380,6 @@ const errorMap = (issue, _ctx) => {
|
|
|
2375
2380
|
return { message };
|
|
2376
2381
|
};
|
|
2377
2382
|
let overrideErrorMap = errorMap;
|
|
2378
|
-
function setErrorMap(map) {
|
|
2379
|
-
overrideErrorMap = map;
|
|
2380
|
-
}
|
|
2381
2383
|
function getErrorMap() {
|
|
2382
2384
|
return overrideErrorMap;
|
|
2383
2385
|
}
|
|
@@ -2388,6 +2390,13 @@ const makeIssue = (params) => {
|
|
|
2388
2390
|
...issueData,
|
|
2389
2391
|
path: fullPath
|
|
2390
2392
|
};
|
|
2393
|
+
if (issueData.message !== void 0) {
|
|
2394
|
+
return {
|
|
2395
|
+
...issueData,
|
|
2396
|
+
path: fullPath,
|
|
2397
|
+
message: issueData.message
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2391
2400
|
let errorMessage = "";
|
|
2392
2401
|
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
2393
2402
|
for (const map of maps) {
|
|
@@ -2396,20 +2405,23 @@ const makeIssue = (params) => {
|
|
|
2396
2405
|
return {
|
|
2397
2406
|
...issueData,
|
|
2398
2407
|
path: fullPath,
|
|
2399
|
-
message:
|
|
2408
|
+
message: errorMessage
|
|
2400
2409
|
};
|
|
2401
2410
|
};
|
|
2402
|
-
const EMPTY_PATH = [];
|
|
2403
2411
|
function addIssueToContext(ctx, issueData) {
|
|
2412
|
+
const overrideMap = getErrorMap();
|
|
2404
2413
|
const issue = makeIssue({
|
|
2405
2414
|
issueData,
|
|
2406
2415
|
data: ctx.data,
|
|
2407
2416
|
path: ctx.path,
|
|
2408
2417
|
errorMaps: [
|
|
2409
2418
|
ctx.common.contextualErrorMap,
|
|
2419
|
+
// contextual error map is first priority
|
|
2410
2420
|
ctx.schemaErrorMap,
|
|
2411
|
-
|
|
2412
|
-
|
|
2421
|
+
// then schema-bound map if available
|
|
2422
|
+
overrideMap,
|
|
2423
|
+
// then global override map
|
|
2424
|
+
overrideMap === errorMap ? void 0 : errorMap
|
|
2413
2425
|
// then global default map
|
|
2414
2426
|
].filter((x) => !!x)
|
|
2415
2427
|
});
|
|
@@ -2441,9 +2453,11 @@ class ParseStatus {
|
|
|
2441
2453
|
static async mergeObjectAsync(status, pairs) {
|
|
2442
2454
|
const syncPairs = [];
|
|
2443
2455
|
for (const pair of pairs) {
|
|
2456
|
+
const key = await pair.key;
|
|
2457
|
+
const value = await pair.value;
|
|
2444
2458
|
syncPairs.push({
|
|
2445
|
-
key
|
|
2446
|
-
value
|
|
2459
|
+
key,
|
|
2460
|
+
value
|
|
2447
2461
|
});
|
|
2448
2462
|
}
|
|
2449
2463
|
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
@@ -2479,7 +2493,7 @@ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
|
2479
2493
|
var errorUtil;
|
|
2480
2494
|
(function(errorUtil2) {
|
|
2481
2495
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
2482
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message
|
|
2496
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
|
|
2483
2497
|
})(errorUtil || (errorUtil = {}));
|
|
2484
2498
|
class ParseInputLazyPath {
|
|
2485
2499
|
constructor(parent, value, path, key) {
|
|
@@ -2491,7 +2505,7 @@ class ParseInputLazyPath {
|
|
|
2491
2505
|
}
|
|
2492
2506
|
get path() {
|
|
2493
2507
|
if (!this._cachedPath.length) {
|
|
2494
|
-
if (this._key
|
|
2508
|
+
if (Array.isArray(this._key)) {
|
|
2495
2509
|
this._cachedPath.push(...this._path, ...this._key);
|
|
2496
2510
|
} else {
|
|
2497
2511
|
this._cachedPath.push(...this._path, this._key);
|
|
@@ -2529,44 +2543,20 @@ function processCreateParams(params) {
|
|
|
2529
2543
|
if (errorMap2)
|
|
2530
2544
|
return { errorMap: errorMap2, description };
|
|
2531
2545
|
const customMap = (iss, ctx) => {
|
|
2532
|
-
|
|
2533
|
-
|
|
2546
|
+
const { message } = params;
|
|
2547
|
+
if (iss.code === "invalid_enum_value") {
|
|
2548
|
+
return { message: message ?? ctx.defaultError };
|
|
2549
|
+
}
|
|
2534
2550
|
if (typeof ctx.data === "undefined") {
|
|
2535
|
-
return { message:
|
|
2551
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
2536
2552
|
}
|
|
2537
|
-
|
|
2553
|
+
if (iss.code !== "invalid_type")
|
|
2554
|
+
return { message: ctx.defaultError };
|
|
2555
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
2538
2556
|
};
|
|
2539
2557
|
return { errorMap: customMap, description };
|
|
2540
2558
|
}
|
|
2541
2559
|
class ZodType {
|
|
2542
|
-
constructor(def) {
|
|
2543
|
-
this.spa = this.safeParseAsync;
|
|
2544
|
-
this._def = def;
|
|
2545
|
-
this.parse = this.parse.bind(this);
|
|
2546
|
-
this.safeParse = this.safeParse.bind(this);
|
|
2547
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
2548
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2549
|
-
this.spa = this.spa.bind(this);
|
|
2550
|
-
this.refine = this.refine.bind(this);
|
|
2551
|
-
this.refinement = this.refinement.bind(this);
|
|
2552
|
-
this.superRefine = this.superRefine.bind(this);
|
|
2553
|
-
this.optional = this.optional.bind(this);
|
|
2554
|
-
this.nullable = this.nullable.bind(this);
|
|
2555
|
-
this.nullish = this.nullish.bind(this);
|
|
2556
|
-
this.array = this.array.bind(this);
|
|
2557
|
-
this.promise = this.promise.bind(this);
|
|
2558
|
-
this.or = this.or.bind(this);
|
|
2559
|
-
this.and = this.and.bind(this);
|
|
2560
|
-
this.transform = this.transform.bind(this);
|
|
2561
|
-
this.brand = this.brand.bind(this);
|
|
2562
|
-
this.default = this.default.bind(this);
|
|
2563
|
-
this.catch = this.catch.bind(this);
|
|
2564
|
-
this.describe = this.describe.bind(this);
|
|
2565
|
-
this.pipe = this.pipe.bind(this);
|
|
2566
|
-
this.readonly = this.readonly.bind(this);
|
|
2567
|
-
this.isNullable = this.isNullable.bind(this);
|
|
2568
|
-
this.isOptional = this.isOptional.bind(this);
|
|
2569
|
-
}
|
|
2570
2560
|
get description() {
|
|
2571
2561
|
return this._def.description;
|
|
2572
2562
|
}
|
|
@@ -2614,14 +2604,13 @@ class ZodType {
|
|
|
2614
2604
|
throw result.error;
|
|
2615
2605
|
}
|
|
2616
2606
|
safeParse(data, params) {
|
|
2617
|
-
var _a;
|
|
2618
2607
|
const ctx = {
|
|
2619
2608
|
common: {
|
|
2620
2609
|
issues: [],
|
|
2621
|
-
async: (
|
|
2622
|
-
contextualErrorMap: params
|
|
2610
|
+
async: (params == null ? void 0 : params.async) ?? false,
|
|
2611
|
+
contextualErrorMap: params == null ? void 0 : params.errorMap
|
|
2623
2612
|
},
|
|
2624
|
-
path: (params
|
|
2613
|
+
path: (params == null ? void 0 : params.path) || [],
|
|
2625
2614
|
schemaErrorMap: this._def.errorMap,
|
|
2626
2615
|
parent: null,
|
|
2627
2616
|
data,
|
|
@@ -2630,6 +2619,43 @@ class ZodType {
|
|
|
2630
2619
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
2631
2620
|
return handleResult(ctx, result);
|
|
2632
2621
|
}
|
|
2622
|
+
"~validate"(data) {
|
|
2623
|
+
var _a, _b;
|
|
2624
|
+
const ctx = {
|
|
2625
|
+
common: {
|
|
2626
|
+
issues: [],
|
|
2627
|
+
async: !!this["~standard"].async
|
|
2628
|
+
},
|
|
2629
|
+
path: [],
|
|
2630
|
+
schemaErrorMap: this._def.errorMap,
|
|
2631
|
+
parent: null,
|
|
2632
|
+
data,
|
|
2633
|
+
parsedType: getParsedType(data)
|
|
2634
|
+
};
|
|
2635
|
+
if (!this["~standard"].async) {
|
|
2636
|
+
try {
|
|
2637
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
2638
|
+
return isValid(result) ? {
|
|
2639
|
+
value: result.value
|
|
2640
|
+
} : {
|
|
2641
|
+
issues: ctx.common.issues
|
|
2642
|
+
};
|
|
2643
|
+
} catch (err) {
|
|
2644
|
+
if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
|
|
2645
|
+
this["~standard"].async = true;
|
|
2646
|
+
}
|
|
2647
|
+
ctx.common = {
|
|
2648
|
+
issues: [],
|
|
2649
|
+
async: true
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
2654
|
+
value: result.value
|
|
2655
|
+
} : {
|
|
2656
|
+
issues: ctx.common.issues
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2633
2659
|
async parseAsync(data, params) {
|
|
2634
2660
|
const result = await this.safeParseAsync(data, params);
|
|
2635
2661
|
if (result.success)
|
|
@@ -2640,10 +2666,10 @@ class ZodType {
|
|
|
2640
2666
|
const ctx = {
|
|
2641
2667
|
common: {
|
|
2642
2668
|
issues: [],
|
|
2643
|
-
contextualErrorMap: params
|
|
2669
|
+
contextualErrorMap: params == null ? void 0 : params.errorMap,
|
|
2644
2670
|
async: true
|
|
2645
2671
|
},
|
|
2646
|
-
path: (params
|
|
2672
|
+
path: (params == null ? void 0 : params.path) || [],
|
|
2647
2673
|
schemaErrorMap: this._def.errorMap,
|
|
2648
2674
|
parent: null,
|
|
2649
2675
|
data,
|
|
@@ -2707,6 +2733,39 @@ class ZodType {
|
|
|
2707
2733
|
superRefine(refinement) {
|
|
2708
2734
|
return this._refinement(refinement);
|
|
2709
2735
|
}
|
|
2736
|
+
constructor(def) {
|
|
2737
|
+
this.spa = this.safeParseAsync;
|
|
2738
|
+
this._def = def;
|
|
2739
|
+
this.parse = this.parse.bind(this);
|
|
2740
|
+
this.safeParse = this.safeParse.bind(this);
|
|
2741
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
2742
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2743
|
+
this.spa = this.spa.bind(this);
|
|
2744
|
+
this.refine = this.refine.bind(this);
|
|
2745
|
+
this.refinement = this.refinement.bind(this);
|
|
2746
|
+
this.superRefine = this.superRefine.bind(this);
|
|
2747
|
+
this.optional = this.optional.bind(this);
|
|
2748
|
+
this.nullable = this.nullable.bind(this);
|
|
2749
|
+
this.nullish = this.nullish.bind(this);
|
|
2750
|
+
this.array = this.array.bind(this);
|
|
2751
|
+
this.promise = this.promise.bind(this);
|
|
2752
|
+
this.or = this.or.bind(this);
|
|
2753
|
+
this.and = this.and.bind(this);
|
|
2754
|
+
this.transform = this.transform.bind(this);
|
|
2755
|
+
this.brand = this.brand.bind(this);
|
|
2756
|
+
this.default = this.default.bind(this);
|
|
2757
|
+
this.catch = this.catch.bind(this);
|
|
2758
|
+
this.describe = this.describe.bind(this);
|
|
2759
|
+
this.pipe = this.pipe.bind(this);
|
|
2760
|
+
this.readonly = this.readonly.bind(this);
|
|
2761
|
+
this.isNullable = this.isNullable.bind(this);
|
|
2762
|
+
this.isOptional = this.isOptional.bind(this);
|
|
2763
|
+
this["~standard"] = {
|
|
2764
|
+
version: 1,
|
|
2765
|
+
vendor: "zod",
|
|
2766
|
+
validate: (data) => this["~validate"](data)
|
|
2767
|
+
};
|
|
2768
|
+
}
|
|
2710
2769
|
optional() {
|
|
2711
2770
|
return ZodOptional.create(this, this._def);
|
|
2712
2771
|
}
|
|
@@ -2717,7 +2776,7 @@ class ZodType {
|
|
|
2717
2776
|
return this.nullable().optional();
|
|
2718
2777
|
}
|
|
2719
2778
|
array() {
|
|
2720
|
-
return ZodArray.create(this
|
|
2779
|
+
return ZodArray.create(this);
|
|
2721
2780
|
}
|
|
2722
2781
|
promise() {
|
|
2723
2782
|
return ZodPromise.create(this, this._def);
|
|
@@ -2782,35 +2841,45 @@ class ZodType {
|
|
|
2782
2841
|
}
|
|
2783
2842
|
}
|
|
2784
2843
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
2785
|
-
const cuid2Regex = /^[
|
|
2786
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
2844
|
+
const cuid2Regex = /^[0-9a-z]+$/;
|
|
2845
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
2787
2846
|
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;
|
|
2788
|
-
const
|
|
2847
|
+
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
2848
|
+
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
2849
|
+
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)?)??$/;
|
|
2850
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
2789
2851
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
2790
2852
|
let emojiRegex;
|
|
2791
|
-
const ipv4Regex = /^((
|
|
2792
|
-
const
|
|
2793
|
-
const
|
|
2853
|
+
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])$/;
|
|
2854
|
+
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])$/;
|
|
2855
|
+
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]))$/;
|
|
2856
|
+
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])$/;
|
|
2857
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
2858
|
+
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
2859
|
+
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])))`;
|
|
2860
|
+
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
2861
|
+
function timeRegexSource(args) {
|
|
2862
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
2794
2863
|
if (args.precision) {
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
2799
|
-
}
|
|
2800
|
-
} else if (args.precision === 0) {
|
|
2801
|
-
if (args.offset) {
|
|
2802
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
2803
|
-
} else {
|
|
2804
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
2805
|
-
}
|
|
2806
|
-
} else {
|
|
2807
|
-
if (args.offset) {
|
|
2808
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
2809
|
-
} else {
|
|
2810
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
2811
|
-
}
|
|
2864
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
2865
|
+
} else if (args.precision == null) {
|
|
2866
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
2812
2867
|
}
|
|
2813
|
-
|
|
2868
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
2869
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
2870
|
+
}
|
|
2871
|
+
function timeRegex(args) {
|
|
2872
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
2873
|
+
}
|
|
2874
|
+
function datetimeRegex(args) {
|
|
2875
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
2876
|
+
const opts = [];
|
|
2877
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
2878
|
+
if (args.offset)
|
|
2879
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
2880
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
2881
|
+
return new RegExp(`^${regex}$`);
|
|
2882
|
+
}
|
|
2814
2883
|
function isValidIP(ip, version) {
|
|
2815
2884
|
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
2816
2885
|
return true;
|
|
@@ -2820,6 +2889,37 @@ function isValidIP(ip, version) {
|
|
|
2820
2889
|
}
|
|
2821
2890
|
return false;
|
|
2822
2891
|
}
|
|
2892
|
+
function isValidJWT(jwt, alg) {
|
|
2893
|
+
if (!jwtRegex.test(jwt))
|
|
2894
|
+
return false;
|
|
2895
|
+
try {
|
|
2896
|
+
const [header] = jwt.split(".");
|
|
2897
|
+
if (!header)
|
|
2898
|
+
return false;
|
|
2899
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
2900
|
+
const decoded = JSON.parse(atob(base64));
|
|
2901
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
2902
|
+
return false;
|
|
2903
|
+
if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
|
|
2904
|
+
return false;
|
|
2905
|
+
if (!decoded.alg)
|
|
2906
|
+
return false;
|
|
2907
|
+
if (alg && decoded.alg !== alg)
|
|
2908
|
+
return false;
|
|
2909
|
+
return true;
|
|
2910
|
+
} catch {
|
|
2911
|
+
return false;
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
function isValidCidr(ip, version) {
|
|
2915
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
2916
|
+
return true;
|
|
2917
|
+
}
|
|
2918
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
2919
|
+
return true;
|
|
2920
|
+
}
|
|
2921
|
+
return false;
|
|
2922
|
+
}
|
|
2823
2923
|
class ZodString extends ZodType {
|
|
2824
2924
|
_parse(input) {
|
|
2825
2925
|
if (this._def.coerce) {
|
|
@@ -2828,15 +2928,11 @@ class ZodString extends ZodType {
|
|
|
2828
2928
|
const parsedType = this._getType(input);
|
|
2829
2929
|
if (parsedType !== ZodParsedType.string) {
|
|
2830
2930
|
const ctx2 = this._getOrReturnCtx(input);
|
|
2831
|
-
addIssueToContext(
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
received: ctx2.parsedType
|
|
2837
|
-
}
|
|
2838
|
-
//
|
|
2839
|
-
);
|
|
2931
|
+
addIssueToContext(ctx2, {
|
|
2932
|
+
code: ZodIssueCode.invalid_type,
|
|
2933
|
+
expected: ZodParsedType.string,
|
|
2934
|
+
received: ctx2.parsedType
|
|
2935
|
+
});
|
|
2840
2936
|
return INVALID;
|
|
2841
2937
|
}
|
|
2842
2938
|
const status = new ParseStatus();
|
|
@@ -2927,6 +3023,16 @@ class ZodString extends ZodType {
|
|
|
2927
3023
|
});
|
|
2928
3024
|
status.dirty();
|
|
2929
3025
|
}
|
|
3026
|
+
} else if (check.kind === "nanoid") {
|
|
3027
|
+
if (!nanoidRegex.test(input.data)) {
|
|
3028
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3029
|
+
addIssueToContext(ctx, {
|
|
3030
|
+
validation: "nanoid",
|
|
3031
|
+
code: ZodIssueCode.invalid_string,
|
|
3032
|
+
message: check.message
|
|
3033
|
+
});
|
|
3034
|
+
status.dirty();
|
|
3035
|
+
}
|
|
2930
3036
|
} else if (check.kind === "cuid") {
|
|
2931
3037
|
if (!cuidRegex.test(input.data)) {
|
|
2932
3038
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -2960,7 +3066,7 @@ class ZodString extends ZodType {
|
|
|
2960
3066
|
} else if (check.kind === "url") {
|
|
2961
3067
|
try {
|
|
2962
3068
|
new URL(input.data);
|
|
2963
|
-
} catch
|
|
3069
|
+
} catch {
|
|
2964
3070
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
2965
3071
|
addIssueToContext(ctx, {
|
|
2966
3072
|
validation: "url",
|
|
@@ -3028,6 +3134,38 @@ class ZodString extends ZodType {
|
|
|
3028
3134
|
});
|
|
3029
3135
|
status.dirty();
|
|
3030
3136
|
}
|
|
3137
|
+
} else if (check.kind === "date") {
|
|
3138
|
+
const regex = dateRegex;
|
|
3139
|
+
if (!regex.test(input.data)) {
|
|
3140
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3141
|
+
addIssueToContext(ctx, {
|
|
3142
|
+
code: ZodIssueCode.invalid_string,
|
|
3143
|
+
validation: "date",
|
|
3144
|
+
message: check.message
|
|
3145
|
+
});
|
|
3146
|
+
status.dirty();
|
|
3147
|
+
}
|
|
3148
|
+
} else if (check.kind === "time") {
|
|
3149
|
+
const regex = timeRegex(check);
|
|
3150
|
+
if (!regex.test(input.data)) {
|
|
3151
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3152
|
+
addIssueToContext(ctx, {
|
|
3153
|
+
code: ZodIssueCode.invalid_string,
|
|
3154
|
+
validation: "time",
|
|
3155
|
+
message: check.message
|
|
3156
|
+
});
|
|
3157
|
+
status.dirty();
|
|
3158
|
+
}
|
|
3159
|
+
} else if (check.kind === "duration") {
|
|
3160
|
+
if (!durationRegex.test(input.data)) {
|
|
3161
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3162
|
+
addIssueToContext(ctx, {
|
|
3163
|
+
validation: "duration",
|
|
3164
|
+
code: ZodIssueCode.invalid_string,
|
|
3165
|
+
message: check.message
|
|
3166
|
+
});
|
|
3167
|
+
status.dirty();
|
|
3168
|
+
}
|
|
3031
3169
|
} else if (check.kind === "ip") {
|
|
3032
3170
|
if (!isValidIP(input.data, check.version)) {
|
|
3033
3171
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -3038,6 +3176,46 @@ class ZodString extends ZodType {
|
|
|
3038
3176
|
});
|
|
3039
3177
|
status.dirty();
|
|
3040
3178
|
}
|
|
3179
|
+
} else if (check.kind === "jwt") {
|
|
3180
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
3181
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3182
|
+
addIssueToContext(ctx, {
|
|
3183
|
+
validation: "jwt",
|
|
3184
|
+
code: ZodIssueCode.invalid_string,
|
|
3185
|
+
message: check.message
|
|
3186
|
+
});
|
|
3187
|
+
status.dirty();
|
|
3188
|
+
}
|
|
3189
|
+
} else if (check.kind === "cidr") {
|
|
3190
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
3191
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3192
|
+
addIssueToContext(ctx, {
|
|
3193
|
+
validation: "cidr",
|
|
3194
|
+
code: ZodIssueCode.invalid_string,
|
|
3195
|
+
message: check.message
|
|
3196
|
+
});
|
|
3197
|
+
status.dirty();
|
|
3198
|
+
}
|
|
3199
|
+
} else if (check.kind === "base64") {
|
|
3200
|
+
if (!base64Regex.test(input.data)) {
|
|
3201
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3202
|
+
addIssueToContext(ctx, {
|
|
3203
|
+
validation: "base64",
|
|
3204
|
+
code: ZodIssueCode.invalid_string,
|
|
3205
|
+
message: check.message
|
|
3206
|
+
});
|
|
3207
|
+
status.dirty();
|
|
3208
|
+
}
|
|
3209
|
+
} else if (check.kind === "base64url") {
|
|
3210
|
+
if (!base64urlRegex.test(input.data)) {
|
|
3211
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
3212
|
+
addIssueToContext(ctx, {
|
|
3213
|
+
validation: "base64url",
|
|
3214
|
+
code: ZodIssueCode.invalid_string,
|
|
3215
|
+
message: check.message
|
|
3216
|
+
});
|
|
3217
|
+
status.dirty();
|
|
3218
|
+
}
|
|
3041
3219
|
} else {
|
|
3042
3220
|
util.assertNever(check);
|
|
3043
3221
|
}
|
|
@@ -3069,6 +3247,9 @@ class ZodString extends ZodType {
|
|
|
3069
3247
|
uuid(message) {
|
|
3070
3248
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
3071
3249
|
}
|
|
3250
|
+
nanoid(message) {
|
|
3251
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
3252
|
+
}
|
|
3072
3253
|
cuid(message) {
|
|
3073
3254
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
3074
3255
|
}
|
|
@@ -3078,26 +3259,62 @@ class ZodString extends ZodType {
|
|
|
3078
3259
|
ulid(message) {
|
|
3079
3260
|
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
3080
3261
|
}
|
|
3262
|
+
base64(message) {
|
|
3263
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
3264
|
+
}
|
|
3265
|
+
base64url(message) {
|
|
3266
|
+
return this._addCheck({
|
|
3267
|
+
kind: "base64url",
|
|
3268
|
+
...errorUtil.errToObj(message)
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
jwt(options) {
|
|
3272
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
3273
|
+
}
|
|
3081
3274
|
ip(options) {
|
|
3082
3275
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
3083
3276
|
}
|
|
3277
|
+
cidr(options) {
|
|
3278
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
3279
|
+
}
|
|
3084
3280
|
datetime(options) {
|
|
3085
|
-
var _a;
|
|
3086
3281
|
if (typeof options === "string") {
|
|
3087
3282
|
return this._addCheck({
|
|
3088
3283
|
kind: "datetime",
|
|
3089
3284
|
precision: null,
|
|
3090
3285
|
offset: false,
|
|
3286
|
+
local: false,
|
|
3091
3287
|
message: options
|
|
3092
3288
|
});
|
|
3093
3289
|
}
|
|
3094
3290
|
return this._addCheck({
|
|
3095
3291
|
kind: "datetime",
|
|
3096
|
-
precision: typeof (options
|
|
3097
|
-
offset: (
|
|
3098
|
-
|
|
3292
|
+
precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
|
|
3293
|
+
offset: (options == null ? void 0 : options.offset) ?? false,
|
|
3294
|
+
local: (options == null ? void 0 : options.local) ?? false,
|
|
3295
|
+
...errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
date(message) {
|
|
3299
|
+
return this._addCheck({ kind: "date", message });
|
|
3300
|
+
}
|
|
3301
|
+
time(options) {
|
|
3302
|
+
if (typeof options === "string") {
|
|
3303
|
+
return this._addCheck({
|
|
3304
|
+
kind: "time",
|
|
3305
|
+
precision: null,
|
|
3306
|
+
message: options
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
return this._addCheck({
|
|
3310
|
+
kind: "time",
|
|
3311
|
+
precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
|
|
3312
|
+
...errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
3099
3313
|
});
|
|
3100
3314
|
}
|
|
3315
|
+
duration(message) {
|
|
3316
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
3317
|
+
}
|
|
3101
3318
|
regex(regex, message) {
|
|
3102
3319
|
return this._addCheck({
|
|
3103
3320
|
kind: "regex",
|
|
@@ -3109,8 +3326,8 @@ class ZodString extends ZodType {
|
|
|
3109
3326
|
return this._addCheck({
|
|
3110
3327
|
kind: "includes",
|
|
3111
3328
|
value,
|
|
3112
|
-
position: options
|
|
3113
|
-
...errorUtil.errToObj(options
|
|
3329
|
+
position: options == null ? void 0 : options.position,
|
|
3330
|
+
...errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
3114
3331
|
});
|
|
3115
3332
|
}
|
|
3116
3333
|
startsWith(value, message) {
|
|
@@ -3149,8 +3366,7 @@ class ZodString extends ZodType {
|
|
|
3149
3366
|
});
|
|
3150
3367
|
}
|
|
3151
3368
|
/**
|
|
3152
|
-
*
|
|
3153
|
-
* @see {@link ZodString.min}
|
|
3369
|
+
* Equivalent to `.min(1)`
|
|
3154
3370
|
*/
|
|
3155
3371
|
nonempty(message) {
|
|
3156
3372
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -3176,6 +3392,15 @@ class ZodString extends ZodType {
|
|
|
3176
3392
|
get isDatetime() {
|
|
3177
3393
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
3178
3394
|
}
|
|
3395
|
+
get isDate() {
|
|
3396
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
3397
|
+
}
|
|
3398
|
+
get isTime() {
|
|
3399
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
3400
|
+
}
|
|
3401
|
+
get isDuration() {
|
|
3402
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
3403
|
+
}
|
|
3179
3404
|
get isEmail() {
|
|
3180
3405
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
3181
3406
|
}
|
|
@@ -3188,6 +3413,9 @@ class ZodString extends ZodType {
|
|
|
3188
3413
|
get isUUID() {
|
|
3189
3414
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
3190
3415
|
}
|
|
3416
|
+
get isNANOID() {
|
|
3417
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
3418
|
+
}
|
|
3191
3419
|
get isCUID() {
|
|
3192
3420
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
3193
3421
|
}
|
|
@@ -3200,6 +3428,15 @@ class ZodString extends ZodType {
|
|
|
3200
3428
|
get isIP() {
|
|
3201
3429
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
3202
3430
|
}
|
|
3431
|
+
get isCIDR() {
|
|
3432
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
3433
|
+
}
|
|
3434
|
+
get isBase64() {
|
|
3435
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
3436
|
+
}
|
|
3437
|
+
get isBase64url() {
|
|
3438
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
3439
|
+
}
|
|
3203
3440
|
get minLength() {
|
|
3204
3441
|
let min = null;
|
|
3205
3442
|
for (const ch of this._def.checks) {
|
|
@@ -3222,11 +3459,10 @@ class ZodString extends ZodType {
|
|
|
3222
3459
|
}
|
|
3223
3460
|
}
|
|
3224
3461
|
ZodString.create = (params) => {
|
|
3225
|
-
var _a;
|
|
3226
3462
|
return new ZodString({
|
|
3227
3463
|
checks: [],
|
|
3228
3464
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
3229
|
-
coerce: (
|
|
3465
|
+
coerce: (params == null ? void 0 : params.coerce) ?? false,
|
|
3230
3466
|
...processCreateParams(params)
|
|
3231
3467
|
});
|
|
3232
3468
|
};
|
|
@@ -3234,9 +3470,9 @@ function floatSafeRemainder(val, step) {
|
|
|
3234
3470
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
3235
3471
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
3236
3472
|
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
3237
|
-
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
3238
|
-
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
3239
|
-
return valInt % stepInt /
|
|
3473
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
3474
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
3475
|
+
return valInt % stepInt / 10 ** decCount;
|
|
3240
3476
|
}
|
|
3241
3477
|
class ZodNumber extends ZodType {
|
|
3242
3478
|
constructor() {
|
|
@@ -3446,7 +3682,8 @@ class ZodNumber extends ZodType {
|
|
|
3446
3682
|
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
3447
3683
|
}
|
|
3448
3684
|
get isFinite() {
|
|
3449
|
-
let max = null
|
|
3685
|
+
let max = null;
|
|
3686
|
+
let min = null;
|
|
3450
3687
|
for (const ch of this._def.checks) {
|
|
3451
3688
|
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
3452
3689
|
return true;
|
|
@@ -3465,7 +3702,7 @@ ZodNumber.create = (params) => {
|
|
|
3465
3702
|
return new ZodNumber({
|
|
3466
3703
|
checks: [],
|
|
3467
3704
|
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
3468
|
-
coerce: (params
|
|
3705
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
3469
3706
|
...processCreateParams(params)
|
|
3470
3707
|
});
|
|
3471
3708
|
};
|
|
@@ -3477,17 +3714,15 @@ class ZodBigInt extends ZodType {
|
|
|
3477
3714
|
}
|
|
3478
3715
|
_parse(input) {
|
|
3479
3716
|
if (this._def.coerce) {
|
|
3480
|
-
|
|
3717
|
+
try {
|
|
3718
|
+
input.data = BigInt(input.data);
|
|
3719
|
+
} catch {
|
|
3720
|
+
return this._getInvalidInput(input);
|
|
3721
|
+
}
|
|
3481
3722
|
}
|
|
3482
3723
|
const parsedType = this._getType(input);
|
|
3483
3724
|
if (parsedType !== ZodParsedType.bigint) {
|
|
3484
|
-
|
|
3485
|
-
addIssueToContext(ctx2, {
|
|
3486
|
-
code: ZodIssueCode.invalid_type,
|
|
3487
|
-
expected: ZodParsedType.bigint,
|
|
3488
|
-
received: ctx2.parsedType
|
|
3489
|
-
});
|
|
3490
|
-
return INVALID;
|
|
3725
|
+
return this._getInvalidInput(input);
|
|
3491
3726
|
}
|
|
3492
3727
|
let ctx = void 0;
|
|
3493
3728
|
const status = new ParseStatus();
|
|
@@ -3534,6 +3769,15 @@ class ZodBigInt extends ZodType {
|
|
|
3534
3769
|
}
|
|
3535
3770
|
return { status: status.value, value: input.data };
|
|
3536
3771
|
}
|
|
3772
|
+
_getInvalidInput(input) {
|
|
3773
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3774
|
+
addIssueToContext(ctx, {
|
|
3775
|
+
code: ZodIssueCode.invalid_type,
|
|
3776
|
+
expected: ZodParsedType.bigint,
|
|
3777
|
+
received: ctx.parsedType
|
|
3778
|
+
});
|
|
3779
|
+
return INVALID;
|
|
3780
|
+
}
|
|
3537
3781
|
gte(value, message) {
|
|
3538
3782
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
3539
3783
|
}
|
|
@@ -3627,11 +3871,10 @@ class ZodBigInt extends ZodType {
|
|
|
3627
3871
|
}
|
|
3628
3872
|
}
|
|
3629
3873
|
ZodBigInt.create = (params) => {
|
|
3630
|
-
var _a;
|
|
3631
3874
|
return new ZodBigInt({
|
|
3632
3875
|
checks: [],
|
|
3633
3876
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
3634
|
-
coerce: (
|
|
3877
|
+
coerce: (params == null ? void 0 : params.coerce) ?? false,
|
|
3635
3878
|
...processCreateParams(params)
|
|
3636
3879
|
});
|
|
3637
3880
|
};
|
|
@@ -3656,7 +3899,7 @@ class ZodBoolean extends ZodType {
|
|
|
3656
3899
|
ZodBoolean.create = (params) => {
|
|
3657
3900
|
return new ZodBoolean({
|
|
3658
3901
|
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
3659
|
-
coerce: (params
|
|
3902
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
3660
3903
|
...processCreateParams(params)
|
|
3661
3904
|
});
|
|
3662
3905
|
};
|
|
@@ -3675,7 +3918,7 @@ class ZodDate extends ZodType {
|
|
|
3675
3918
|
});
|
|
3676
3919
|
return INVALID;
|
|
3677
3920
|
}
|
|
3678
|
-
if (isNaN(input.data.getTime())) {
|
|
3921
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
3679
3922
|
const ctx2 = this._getOrReturnCtx(input);
|
|
3680
3923
|
addIssueToContext(ctx2, {
|
|
3681
3924
|
code: ZodIssueCode.invalid_date
|
|
@@ -3764,7 +4007,7 @@ class ZodDate extends ZodType {
|
|
|
3764
4007
|
ZodDate.create = (params) => {
|
|
3765
4008
|
return new ZodDate({
|
|
3766
4009
|
checks: [],
|
|
3767
|
-
coerce: (params
|
|
4010
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
3768
4011
|
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
3769
4012
|
...processCreateParams(params)
|
|
3770
4013
|
});
|
|
@@ -4039,7 +4282,8 @@ class ZodObject extends ZodType {
|
|
|
4039
4282
|
return this._cached;
|
|
4040
4283
|
const shape = this._def.shape();
|
|
4041
4284
|
const keys = util.objectKeys(shape);
|
|
4042
|
-
|
|
4285
|
+
this._cached = { shape, keys };
|
|
4286
|
+
return this._cached;
|
|
4043
4287
|
}
|
|
4044
4288
|
_parse(input) {
|
|
4045
4289
|
const parsedType = this._getType(input);
|
|
@@ -4112,9 +4356,10 @@ class ZodObject extends ZodType {
|
|
|
4112
4356
|
const syncPairs = [];
|
|
4113
4357
|
for (const pair of pairs) {
|
|
4114
4358
|
const key = await pair.key;
|
|
4359
|
+
const value = await pair.value;
|
|
4115
4360
|
syncPairs.push({
|
|
4116
4361
|
key,
|
|
4117
|
-
value
|
|
4362
|
+
value,
|
|
4118
4363
|
alwaysSet: pair.alwaysSet
|
|
4119
4364
|
});
|
|
4120
4365
|
}
|
|
@@ -4136,11 +4381,11 @@ class ZodObject extends ZodType {
|
|
|
4136
4381
|
unknownKeys: "strict",
|
|
4137
4382
|
...message !== void 0 ? {
|
|
4138
4383
|
errorMap: (issue, ctx) => {
|
|
4139
|
-
var _a, _b
|
|
4140
|
-
const defaultError = (
|
|
4384
|
+
var _a, _b;
|
|
4385
|
+
const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) ?? ctx.defaultError;
|
|
4141
4386
|
if (issue.code === "unrecognized_keys")
|
|
4142
4387
|
return {
|
|
4143
|
-
message:
|
|
4388
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
4144
4389
|
};
|
|
4145
4390
|
return {
|
|
4146
4391
|
message: defaultError
|
|
@@ -4271,11 +4516,11 @@ class ZodObject extends ZodType {
|
|
|
4271
4516
|
}
|
|
4272
4517
|
pick(mask) {
|
|
4273
4518
|
const shape = {};
|
|
4274
|
-
util.objectKeys(mask)
|
|
4519
|
+
for (const key of util.objectKeys(mask)) {
|
|
4275
4520
|
if (mask[key] && this.shape[key]) {
|
|
4276
4521
|
shape[key] = this.shape[key];
|
|
4277
4522
|
}
|
|
4278
|
-
}
|
|
4523
|
+
}
|
|
4279
4524
|
return new ZodObject({
|
|
4280
4525
|
...this._def,
|
|
4281
4526
|
shape: () => shape
|
|
@@ -4283,11 +4528,11 @@ class ZodObject extends ZodType {
|
|
|
4283
4528
|
}
|
|
4284
4529
|
omit(mask) {
|
|
4285
4530
|
const shape = {};
|
|
4286
|
-
util.objectKeys(this.shape)
|
|
4531
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4287
4532
|
if (!mask[key]) {
|
|
4288
4533
|
shape[key] = this.shape[key];
|
|
4289
4534
|
}
|
|
4290
|
-
}
|
|
4535
|
+
}
|
|
4291
4536
|
return new ZodObject({
|
|
4292
4537
|
...this._def,
|
|
4293
4538
|
shape: () => shape
|
|
@@ -4301,14 +4546,14 @@ class ZodObject extends ZodType {
|
|
|
4301
4546
|
}
|
|
4302
4547
|
partial(mask) {
|
|
4303
4548
|
const newShape = {};
|
|
4304
|
-
util.objectKeys(this.shape)
|
|
4549
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4305
4550
|
const fieldSchema = this.shape[key];
|
|
4306
4551
|
if (mask && !mask[key]) {
|
|
4307
4552
|
newShape[key] = fieldSchema;
|
|
4308
4553
|
} else {
|
|
4309
4554
|
newShape[key] = fieldSchema.optional();
|
|
4310
4555
|
}
|
|
4311
|
-
}
|
|
4556
|
+
}
|
|
4312
4557
|
return new ZodObject({
|
|
4313
4558
|
...this._def,
|
|
4314
4559
|
shape: () => newShape
|
|
@@ -4316,7 +4561,7 @@ class ZodObject extends ZodType {
|
|
|
4316
4561
|
}
|
|
4317
4562
|
required(mask) {
|
|
4318
4563
|
const newShape = {};
|
|
4319
|
-
util.objectKeys(this.shape)
|
|
4564
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
4320
4565
|
if (mask && !mask[key]) {
|
|
4321
4566
|
newShape[key] = this.shape[key];
|
|
4322
4567
|
} else {
|
|
@@ -4327,7 +4572,7 @@ class ZodObject extends ZodType {
|
|
|
4327
4572
|
}
|
|
4328
4573
|
newShape[key] = newField;
|
|
4329
4574
|
}
|
|
4330
|
-
}
|
|
4575
|
+
}
|
|
4331
4576
|
return new ZodObject({
|
|
4332
4577
|
...this._def,
|
|
4333
4578
|
shape: () => newShape
|
|
@@ -4455,103 +4700,6 @@ ZodUnion.create = (types, params) => {
|
|
|
4455
4700
|
...processCreateParams(params)
|
|
4456
4701
|
});
|
|
4457
4702
|
};
|
|
4458
|
-
const getDiscriminator = (type) => {
|
|
4459
|
-
if (type instanceof ZodLazy) {
|
|
4460
|
-
return getDiscriminator(type.schema);
|
|
4461
|
-
} else if (type instanceof ZodEffects) {
|
|
4462
|
-
return getDiscriminator(type.innerType());
|
|
4463
|
-
} else if (type instanceof ZodLiteral) {
|
|
4464
|
-
return [type.value];
|
|
4465
|
-
} else if (type instanceof ZodEnum) {
|
|
4466
|
-
return type.options;
|
|
4467
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
4468
|
-
return Object.keys(type.enum);
|
|
4469
|
-
} else if (type instanceof ZodDefault) {
|
|
4470
|
-
return getDiscriminator(type._def.innerType);
|
|
4471
|
-
} else if (type instanceof ZodUndefined) {
|
|
4472
|
-
return [void 0];
|
|
4473
|
-
} else if (type instanceof ZodNull) {
|
|
4474
|
-
return [null];
|
|
4475
|
-
} else {
|
|
4476
|
-
return null;
|
|
4477
|
-
}
|
|
4478
|
-
};
|
|
4479
|
-
class ZodDiscriminatedUnion extends ZodType {
|
|
4480
|
-
_parse(input) {
|
|
4481
|
-
const { ctx } = this._processInputParams(input);
|
|
4482
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4483
|
-
addIssueToContext(ctx, {
|
|
4484
|
-
code: ZodIssueCode.invalid_type,
|
|
4485
|
-
expected: ZodParsedType.object,
|
|
4486
|
-
received: ctx.parsedType
|
|
4487
|
-
});
|
|
4488
|
-
return INVALID;
|
|
4489
|
-
}
|
|
4490
|
-
const discriminator = this.discriminator;
|
|
4491
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
4492
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
4493
|
-
if (!option) {
|
|
4494
|
-
addIssueToContext(ctx, {
|
|
4495
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
4496
|
-
options: Array.from(this.optionsMap.keys()),
|
|
4497
|
-
path: [discriminator]
|
|
4498
|
-
});
|
|
4499
|
-
return INVALID;
|
|
4500
|
-
}
|
|
4501
|
-
if (ctx.common.async) {
|
|
4502
|
-
return option._parseAsync({
|
|
4503
|
-
data: ctx.data,
|
|
4504
|
-
path: ctx.path,
|
|
4505
|
-
parent: ctx
|
|
4506
|
-
});
|
|
4507
|
-
} else {
|
|
4508
|
-
return option._parseSync({
|
|
4509
|
-
data: ctx.data,
|
|
4510
|
-
path: ctx.path,
|
|
4511
|
-
parent: ctx
|
|
4512
|
-
});
|
|
4513
|
-
}
|
|
4514
|
-
}
|
|
4515
|
-
get discriminator() {
|
|
4516
|
-
return this._def.discriminator;
|
|
4517
|
-
}
|
|
4518
|
-
get options() {
|
|
4519
|
-
return this._def.options;
|
|
4520
|
-
}
|
|
4521
|
-
get optionsMap() {
|
|
4522
|
-
return this._def.optionsMap;
|
|
4523
|
-
}
|
|
4524
|
-
/**
|
|
4525
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
4526
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
4527
|
-
* have a different value for each object in the union.
|
|
4528
|
-
* @param discriminator the name of the discriminator property
|
|
4529
|
-
* @param types an array of object schemas
|
|
4530
|
-
* @param params
|
|
4531
|
-
*/
|
|
4532
|
-
static create(discriminator, options, params) {
|
|
4533
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
4534
|
-
for (const type of options) {
|
|
4535
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
4536
|
-
if (!discriminatorValues) {
|
|
4537
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
4538
|
-
}
|
|
4539
|
-
for (const value of discriminatorValues) {
|
|
4540
|
-
if (optionsMap.has(value)) {
|
|
4541
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
4542
|
-
}
|
|
4543
|
-
optionsMap.set(value, type);
|
|
4544
|
-
}
|
|
4545
|
-
}
|
|
4546
|
-
return new ZodDiscriminatedUnion({
|
|
4547
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
4548
|
-
discriminator,
|
|
4549
|
-
options,
|
|
4550
|
-
optionsMap,
|
|
4551
|
-
...processCreateParams(params)
|
|
4552
|
-
});
|
|
4553
|
-
}
|
|
4554
|
-
}
|
|
4555
4703
|
function mergeValues(a2, b) {
|
|
4556
4704
|
const aType = getParsedType(a2);
|
|
4557
4705
|
const bType = getParsedType(b);
|
|
@@ -4710,58 +4858,6 @@ ZodTuple.create = (schemas, params) => {
|
|
|
4710
4858
|
...processCreateParams(params)
|
|
4711
4859
|
});
|
|
4712
4860
|
};
|
|
4713
|
-
class ZodRecord extends ZodType {
|
|
4714
|
-
get keySchema() {
|
|
4715
|
-
return this._def.keyType;
|
|
4716
|
-
}
|
|
4717
|
-
get valueSchema() {
|
|
4718
|
-
return this._def.valueType;
|
|
4719
|
-
}
|
|
4720
|
-
_parse(input) {
|
|
4721
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4722
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4723
|
-
addIssueToContext(ctx, {
|
|
4724
|
-
code: ZodIssueCode.invalid_type,
|
|
4725
|
-
expected: ZodParsedType.object,
|
|
4726
|
-
received: ctx.parsedType
|
|
4727
|
-
});
|
|
4728
|
-
return INVALID;
|
|
4729
|
-
}
|
|
4730
|
-
const pairs = [];
|
|
4731
|
-
const keyType = this._def.keyType;
|
|
4732
|
-
const valueType = this._def.valueType;
|
|
4733
|
-
for (const key in ctx.data) {
|
|
4734
|
-
pairs.push({
|
|
4735
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
4736
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
|
4737
|
-
});
|
|
4738
|
-
}
|
|
4739
|
-
if (ctx.common.async) {
|
|
4740
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
4741
|
-
} else {
|
|
4742
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
4743
|
-
}
|
|
4744
|
-
}
|
|
4745
|
-
get element() {
|
|
4746
|
-
return this._def.valueType;
|
|
4747
|
-
}
|
|
4748
|
-
static create(first, second, third) {
|
|
4749
|
-
if (second instanceof ZodType) {
|
|
4750
|
-
return new ZodRecord({
|
|
4751
|
-
keyType: first,
|
|
4752
|
-
valueType: second,
|
|
4753
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
4754
|
-
...processCreateParams(third)
|
|
4755
|
-
});
|
|
4756
|
-
}
|
|
4757
|
-
return new ZodRecord({
|
|
4758
|
-
keyType: ZodString.create(),
|
|
4759
|
-
valueType: first,
|
|
4760
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
4761
|
-
...processCreateParams(second)
|
|
4762
|
-
});
|
|
4763
|
-
}
|
|
4764
|
-
}
|
|
4765
4861
|
class ZodMap extends ZodType {
|
|
4766
4862
|
get keySchema() {
|
|
4767
4863
|
return this._def.keyType;
|
|
@@ -4913,121 +5009,6 @@ ZodSet.create = (valueType, params) => {
|
|
|
4913
5009
|
...processCreateParams(params)
|
|
4914
5010
|
});
|
|
4915
5011
|
};
|
|
4916
|
-
class ZodFunction extends ZodType {
|
|
4917
|
-
constructor() {
|
|
4918
|
-
super(...arguments);
|
|
4919
|
-
this.validate = this.implement;
|
|
4920
|
-
}
|
|
4921
|
-
_parse(input) {
|
|
4922
|
-
const { ctx } = this._processInputParams(input);
|
|
4923
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
4924
|
-
addIssueToContext(ctx, {
|
|
4925
|
-
code: ZodIssueCode.invalid_type,
|
|
4926
|
-
expected: ZodParsedType.function,
|
|
4927
|
-
received: ctx.parsedType
|
|
4928
|
-
});
|
|
4929
|
-
return INVALID;
|
|
4930
|
-
}
|
|
4931
|
-
function makeArgsIssue(args, error) {
|
|
4932
|
-
return makeIssue({
|
|
4933
|
-
data: args,
|
|
4934
|
-
path: ctx.path,
|
|
4935
|
-
errorMaps: [
|
|
4936
|
-
ctx.common.contextualErrorMap,
|
|
4937
|
-
ctx.schemaErrorMap,
|
|
4938
|
-
getErrorMap(),
|
|
4939
|
-
errorMap
|
|
4940
|
-
].filter((x) => !!x),
|
|
4941
|
-
issueData: {
|
|
4942
|
-
code: ZodIssueCode.invalid_arguments,
|
|
4943
|
-
argumentsError: error
|
|
4944
|
-
}
|
|
4945
|
-
});
|
|
4946
|
-
}
|
|
4947
|
-
function makeReturnsIssue(returns, error) {
|
|
4948
|
-
return makeIssue({
|
|
4949
|
-
data: returns,
|
|
4950
|
-
path: ctx.path,
|
|
4951
|
-
errorMaps: [
|
|
4952
|
-
ctx.common.contextualErrorMap,
|
|
4953
|
-
ctx.schemaErrorMap,
|
|
4954
|
-
getErrorMap(),
|
|
4955
|
-
errorMap
|
|
4956
|
-
].filter((x) => !!x),
|
|
4957
|
-
issueData: {
|
|
4958
|
-
code: ZodIssueCode.invalid_return_type,
|
|
4959
|
-
returnTypeError: error
|
|
4960
|
-
}
|
|
4961
|
-
});
|
|
4962
|
-
}
|
|
4963
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
4964
|
-
const fn = ctx.data;
|
|
4965
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
4966
|
-
const me = this;
|
|
4967
|
-
return OK(async function(...args) {
|
|
4968
|
-
const error = new ZodError([]);
|
|
4969
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => {
|
|
4970
|
-
error.addIssue(makeArgsIssue(args, e2));
|
|
4971
|
-
throw error;
|
|
4972
|
-
});
|
|
4973
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
4974
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => {
|
|
4975
|
-
error.addIssue(makeReturnsIssue(result, e2));
|
|
4976
|
-
throw error;
|
|
4977
|
-
});
|
|
4978
|
-
return parsedReturns;
|
|
4979
|
-
});
|
|
4980
|
-
} else {
|
|
4981
|
-
const me = this;
|
|
4982
|
-
return OK(function(...args) {
|
|
4983
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
4984
|
-
if (!parsedArgs.success) {
|
|
4985
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
4986
|
-
}
|
|
4987
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
4988
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
4989
|
-
if (!parsedReturns.success) {
|
|
4990
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
4991
|
-
}
|
|
4992
|
-
return parsedReturns.data;
|
|
4993
|
-
});
|
|
4994
|
-
}
|
|
4995
|
-
}
|
|
4996
|
-
parameters() {
|
|
4997
|
-
return this._def.args;
|
|
4998
|
-
}
|
|
4999
|
-
returnType() {
|
|
5000
|
-
return this._def.returns;
|
|
5001
|
-
}
|
|
5002
|
-
args(...items) {
|
|
5003
|
-
return new ZodFunction({
|
|
5004
|
-
...this._def,
|
|
5005
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
5006
|
-
});
|
|
5007
|
-
}
|
|
5008
|
-
returns(returnType) {
|
|
5009
|
-
return new ZodFunction({
|
|
5010
|
-
...this._def,
|
|
5011
|
-
returns: returnType
|
|
5012
|
-
});
|
|
5013
|
-
}
|
|
5014
|
-
implement(func) {
|
|
5015
|
-
const validatedFunc = this.parse(func);
|
|
5016
|
-
return validatedFunc;
|
|
5017
|
-
}
|
|
5018
|
-
strictImplement(func) {
|
|
5019
|
-
const validatedFunc = this.parse(func);
|
|
5020
|
-
return validatedFunc;
|
|
5021
|
-
}
|
|
5022
|
-
static create(args, returns, params) {
|
|
5023
|
-
return new ZodFunction({
|
|
5024
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
5025
|
-
returns: returns || ZodUnknown.create(),
|
|
5026
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
5027
|
-
...processCreateParams(params)
|
|
5028
|
-
});
|
|
5029
|
-
}
|
|
5030
|
-
}
|
|
5031
5012
|
class ZodLazy extends ZodType {
|
|
5032
5013
|
get schema() {
|
|
5033
5014
|
return this._def.getter();
|
|
@@ -5088,7 +5069,10 @@ class ZodEnum extends ZodType {
|
|
|
5088
5069
|
});
|
|
5089
5070
|
return INVALID;
|
|
5090
5071
|
}
|
|
5091
|
-
if (this.
|
|
5072
|
+
if (!this._cache) {
|
|
5073
|
+
this._cache = new Set(this._def.values);
|
|
5074
|
+
}
|
|
5075
|
+
if (!this._cache.has(input.data)) {
|
|
5092
5076
|
const ctx = this._getOrReturnCtx(input);
|
|
5093
5077
|
const expectedValues = this._def.values;
|
|
5094
5078
|
addIssueToContext(ctx, {
|
|
@@ -5124,11 +5108,17 @@ class ZodEnum extends ZodType {
|
|
|
5124
5108
|
}
|
|
5125
5109
|
return enumValues;
|
|
5126
5110
|
}
|
|
5127
|
-
extract(values) {
|
|
5128
|
-
return ZodEnum.create(values
|
|
5111
|
+
extract(values, newDef = this._def) {
|
|
5112
|
+
return ZodEnum.create(values, {
|
|
5113
|
+
...this._def,
|
|
5114
|
+
...newDef
|
|
5115
|
+
});
|
|
5129
5116
|
}
|
|
5130
|
-
exclude(values) {
|
|
5131
|
-
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt))
|
|
5117
|
+
exclude(values, newDef = this._def) {
|
|
5118
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
5119
|
+
...this._def,
|
|
5120
|
+
...newDef
|
|
5121
|
+
});
|
|
5132
5122
|
}
|
|
5133
5123
|
}
|
|
5134
5124
|
ZodEnum.create = createZodEnum;
|
|
@@ -5145,7 +5135,10 @@ class ZodNativeEnum extends ZodType {
|
|
|
5145
5135
|
});
|
|
5146
5136
|
return INVALID;
|
|
5147
5137
|
}
|
|
5148
|
-
if (
|
|
5138
|
+
if (!this._cache) {
|
|
5139
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
5140
|
+
}
|
|
5141
|
+
if (!this._cache.has(input.data)) {
|
|
5149
5142
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
5150
5143
|
addIssueToContext(ctx, {
|
|
5151
5144
|
received: ctx.data,
|
|
@@ -5223,26 +5216,38 @@ class ZodEffects extends ZodType {
|
|
|
5223
5216
|
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
5224
5217
|
if (effect.type === "preprocess") {
|
|
5225
5218
|
const processed = effect.transform(ctx.data, checkCtx);
|
|
5226
|
-
if (ctx.common.issues.length) {
|
|
5227
|
-
return {
|
|
5228
|
-
status: "dirty",
|
|
5229
|
-
value: ctx.data
|
|
5230
|
-
};
|
|
5231
|
-
}
|
|
5232
5219
|
if (ctx.common.async) {
|
|
5233
|
-
return Promise.resolve(processed).then((processed2) => {
|
|
5234
|
-
|
|
5220
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
5221
|
+
if (status.value === "aborted")
|
|
5222
|
+
return INVALID;
|
|
5223
|
+
const result = await this._def.schema._parseAsync({
|
|
5235
5224
|
data: processed2,
|
|
5236
5225
|
path: ctx.path,
|
|
5237
5226
|
parent: ctx
|
|
5238
5227
|
});
|
|
5228
|
+
if (result.status === "aborted")
|
|
5229
|
+
return INVALID;
|
|
5230
|
+
if (result.status === "dirty")
|
|
5231
|
+
return DIRTY(result.value);
|
|
5232
|
+
if (status.value === "dirty")
|
|
5233
|
+
return DIRTY(result.value);
|
|
5234
|
+
return result;
|
|
5239
5235
|
});
|
|
5240
5236
|
} else {
|
|
5241
|
-
|
|
5237
|
+
if (status.value === "aborted")
|
|
5238
|
+
return INVALID;
|
|
5239
|
+
const result = this._def.schema._parseSync({
|
|
5242
5240
|
data: processed,
|
|
5243
5241
|
path: ctx.path,
|
|
5244
5242
|
parent: ctx
|
|
5245
5243
|
});
|
|
5244
|
+
if (result.status === "aborted")
|
|
5245
|
+
return INVALID;
|
|
5246
|
+
if (result.status === "dirty")
|
|
5247
|
+
return DIRTY(result.value);
|
|
5248
|
+
if (status.value === "dirty")
|
|
5249
|
+
return DIRTY(result.value);
|
|
5250
|
+
return result;
|
|
5246
5251
|
}
|
|
5247
5252
|
}
|
|
5248
5253
|
if (effect.type === "refinement") {
|
|
@@ -5288,7 +5293,7 @@ class ZodEffects extends ZodType {
|
|
|
5288
5293
|
parent: ctx
|
|
5289
5294
|
});
|
|
5290
5295
|
if (!isValid(base))
|
|
5291
|
-
return
|
|
5296
|
+
return INVALID;
|
|
5292
5297
|
const result = effect.transform(base.value, checkCtx);
|
|
5293
5298
|
if (result instanceof Promise) {
|
|
5294
5299
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
@@ -5297,8 +5302,11 @@ class ZodEffects extends ZodType {
|
|
|
5297
5302
|
} else {
|
|
5298
5303
|
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
5299
5304
|
if (!isValid(base))
|
|
5300
|
-
return
|
|
5301
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
5305
|
+
return INVALID;
|
|
5306
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
5307
|
+
status: status.value,
|
|
5308
|
+
value: result
|
|
5309
|
+
}));
|
|
5302
5310
|
});
|
|
5303
5311
|
}
|
|
5304
5312
|
}
|
|
@@ -5458,7 +5466,6 @@ ZodNaN.create = (params) => {
|
|
|
5458
5466
|
...processCreateParams(params)
|
|
5459
5467
|
});
|
|
5460
5468
|
};
|
|
5461
|
-
const BRAND = Symbol("zod_brand");
|
|
5462
5469
|
class ZodBranded extends ZodType {
|
|
5463
5470
|
_parse(input) {
|
|
5464
5471
|
const { ctx } = this._processInputParams(input);
|
|
@@ -5531,10 +5538,16 @@ class ZodPipeline extends ZodType {
|
|
|
5531
5538
|
class ZodReadonly extends ZodType {
|
|
5532
5539
|
_parse(input) {
|
|
5533
5540
|
const result = this._def.innerType._parse(input);
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5541
|
+
const freeze = (data) => {
|
|
5542
|
+
if (isValid(data)) {
|
|
5543
|
+
data.value = Object.freeze(data.value);
|
|
5544
|
+
}
|
|
5545
|
+
return data;
|
|
5546
|
+
};
|
|
5547
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
5548
|
+
}
|
|
5549
|
+
unwrap() {
|
|
5550
|
+
return this._def.innerType;
|
|
5538
5551
|
}
|
|
5539
5552
|
}
|
|
5540
5553
|
ZodReadonly.create = (type, params) => {
|
|
@@ -5544,22 +5557,6 @@ ZodReadonly.create = (type, params) => {
|
|
|
5544
5557
|
...processCreateParams(params)
|
|
5545
5558
|
});
|
|
5546
5559
|
};
|
|
5547
|
-
const custom = (check, params = {}, fatal) => {
|
|
5548
|
-
if (check)
|
|
5549
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
5550
|
-
var _a, _b;
|
|
5551
|
-
if (!check(data)) {
|
|
5552
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
5553
|
-
const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
5554
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
5555
|
-
ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
|
|
5556
|
-
}
|
|
5557
|
-
});
|
|
5558
|
-
return ZodAny.create();
|
|
5559
|
-
};
|
|
5560
|
-
const late = {
|
|
5561
|
-
object: ZodObject.lazycreate
|
|
5562
|
-
};
|
|
5563
5560
|
var ZodFirstPartyTypeKind;
|
|
5564
5561
|
(function(ZodFirstPartyTypeKind2) {
|
|
5565
5562
|
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
@@ -5599,177 +5596,25 @@ var ZodFirstPartyTypeKind;
|
|
|
5599
5596
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
5600
5597
|
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
5601
5598
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
5602
|
-
const instanceOfType = (cls, params = {
|
|
5603
|
-
message: `Input not instance of ${cls.name}`
|
|
5604
|
-
}) => custom((data) => data instanceof cls, params);
|
|
5605
5599
|
const stringType = ZodString.create;
|
|
5606
5600
|
const numberType = ZodNumber.create;
|
|
5607
|
-
const nanType = ZodNaN.create;
|
|
5608
|
-
const bigIntType = ZodBigInt.create;
|
|
5609
5601
|
const booleanType = ZodBoolean.create;
|
|
5610
5602
|
const dateType = ZodDate.create;
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
const nullType = ZodNull.create;
|
|
5614
|
-
const anyType = ZodAny.create;
|
|
5615
|
-
const unknownType = ZodUnknown.create;
|
|
5616
|
-
const neverType = ZodNever.create;
|
|
5617
|
-
const voidType = ZodVoid.create;
|
|
5618
|
-
const arrayType = ZodArray.create;
|
|
5603
|
+
ZodNever.create;
|
|
5604
|
+
ZodArray.create;
|
|
5619
5605
|
const objectType = ZodObject.create;
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
const intersectionType = ZodIntersection.create;
|
|
5624
|
-
const tupleType = ZodTuple.create;
|
|
5625
|
-
const recordType = ZodRecord.create;
|
|
5626
|
-
const mapType = ZodMap.create;
|
|
5627
|
-
const setType = ZodSet.create;
|
|
5628
|
-
const functionType = ZodFunction.create;
|
|
5629
|
-
const lazyType = ZodLazy.create;
|
|
5630
|
-
const literalType = ZodLiteral.create;
|
|
5606
|
+
ZodUnion.create;
|
|
5607
|
+
ZodIntersection.create;
|
|
5608
|
+
ZodTuple.create;
|
|
5631
5609
|
const enumType = ZodEnum.create;
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
const
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
const onumber = () => numberType().optional();
|
|
5641
|
-
const oboolean = () => booleanType().optional();
|
|
5642
|
-
const coerce = {
|
|
5643
|
-
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
5644
|
-
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
5645
|
-
boolean: (arg) => ZodBoolean.create({
|
|
5646
|
-
...arg,
|
|
5647
|
-
coerce: true
|
|
5648
|
-
}),
|
|
5649
|
-
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
5650
|
-
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
5651
|
-
};
|
|
5652
|
-
const NEVER = INVALID;
|
|
5653
|
-
var z = /* @__PURE__ */ Object.freeze({
|
|
5654
|
-
__proto__: null,
|
|
5655
|
-
defaultErrorMap: errorMap,
|
|
5656
|
-
setErrorMap,
|
|
5657
|
-
getErrorMap,
|
|
5658
|
-
makeIssue,
|
|
5659
|
-
EMPTY_PATH,
|
|
5660
|
-
addIssueToContext,
|
|
5661
|
-
ParseStatus,
|
|
5662
|
-
INVALID,
|
|
5663
|
-
DIRTY,
|
|
5664
|
-
OK,
|
|
5665
|
-
isAborted,
|
|
5666
|
-
isDirty,
|
|
5667
|
-
isValid,
|
|
5668
|
-
isAsync,
|
|
5669
|
-
get util() {
|
|
5670
|
-
return util;
|
|
5671
|
-
},
|
|
5672
|
-
get objectUtil() {
|
|
5673
|
-
return objectUtil;
|
|
5674
|
-
},
|
|
5675
|
-
ZodParsedType,
|
|
5676
|
-
getParsedType,
|
|
5677
|
-
ZodType,
|
|
5678
|
-
ZodString,
|
|
5679
|
-
ZodNumber,
|
|
5680
|
-
ZodBigInt,
|
|
5681
|
-
ZodBoolean,
|
|
5682
|
-
ZodDate,
|
|
5683
|
-
ZodSymbol,
|
|
5684
|
-
ZodUndefined,
|
|
5685
|
-
ZodNull,
|
|
5686
|
-
ZodAny,
|
|
5687
|
-
ZodUnknown,
|
|
5688
|
-
ZodNever,
|
|
5689
|
-
ZodVoid,
|
|
5690
|
-
ZodArray,
|
|
5691
|
-
ZodObject,
|
|
5692
|
-
ZodUnion,
|
|
5693
|
-
ZodDiscriminatedUnion,
|
|
5694
|
-
ZodIntersection,
|
|
5695
|
-
ZodTuple,
|
|
5696
|
-
ZodRecord,
|
|
5697
|
-
ZodMap,
|
|
5698
|
-
ZodSet,
|
|
5699
|
-
ZodFunction,
|
|
5700
|
-
ZodLazy,
|
|
5701
|
-
ZodLiteral,
|
|
5702
|
-
ZodEnum,
|
|
5703
|
-
ZodNativeEnum,
|
|
5704
|
-
ZodPromise,
|
|
5705
|
-
ZodEffects,
|
|
5706
|
-
ZodTransformer: ZodEffects,
|
|
5707
|
-
ZodOptional,
|
|
5708
|
-
ZodNullable,
|
|
5709
|
-
ZodDefault,
|
|
5710
|
-
ZodCatch,
|
|
5711
|
-
ZodNaN,
|
|
5712
|
-
BRAND,
|
|
5713
|
-
ZodBranded,
|
|
5714
|
-
ZodPipeline,
|
|
5715
|
-
ZodReadonly,
|
|
5716
|
-
custom,
|
|
5717
|
-
Schema: ZodType,
|
|
5718
|
-
ZodSchema: ZodType,
|
|
5719
|
-
late,
|
|
5720
|
-
get ZodFirstPartyTypeKind() {
|
|
5721
|
-
return ZodFirstPartyTypeKind;
|
|
5722
|
-
},
|
|
5723
|
-
coerce,
|
|
5724
|
-
any: anyType,
|
|
5725
|
-
array: arrayType,
|
|
5726
|
-
bigint: bigIntType,
|
|
5727
|
-
boolean: booleanType,
|
|
5728
|
-
date: dateType,
|
|
5729
|
-
discriminatedUnion: discriminatedUnionType,
|
|
5730
|
-
effect: effectsType,
|
|
5731
|
-
"enum": enumType,
|
|
5732
|
-
"function": functionType,
|
|
5733
|
-
"instanceof": instanceOfType,
|
|
5734
|
-
intersection: intersectionType,
|
|
5735
|
-
lazy: lazyType,
|
|
5736
|
-
literal: literalType,
|
|
5737
|
-
map: mapType,
|
|
5738
|
-
nan: nanType,
|
|
5739
|
-
nativeEnum: nativeEnumType,
|
|
5740
|
-
never: neverType,
|
|
5741
|
-
"null": nullType,
|
|
5742
|
-
nullable: nullableType,
|
|
5743
|
-
number: numberType,
|
|
5744
|
-
object: objectType,
|
|
5745
|
-
oboolean,
|
|
5746
|
-
onumber,
|
|
5747
|
-
optional: optionalType,
|
|
5748
|
-
ostring,
|
|
5749
|
-
pipeline: pipelineType,
|
|
5750
|
-
preprocess: preprocessType,
|
|
5751
|
-
promise: promiseType,
|
|
5752
|
-
record: recordType,
|
|
5753
|
-
set: setType,
|
|
5754
|
-
strictObject: strictObjectType,
|
|
5755
|
-
string: stringType,
|
|
5756
|
-
symbol: symbolType,
|
|
5757
|
-
transformer: effectsType,
|
|
5758
|
-
tuple: tupleType,
|
|
5759
|
-
"undefined": undefinedType,
|
|
5760
|
-
union: unionType,
|
|
5761
|
-
unknown: unknownType,
|
|
5762
|
-
"void": voidType,
|
|
5763
|
-
NEVER,
|
|
5764
|
-
ZodIssueCode,
|
|
5765
|
-
quotelessJson,
|
|
5766
|
-
ZodError
|
|
5767
|
-
});
|
|
5768
|
-
const quoteSequenceSchema = z.object({
|
|
5769
|
-
start_date: z.date().optional(),
|
|
5770
|
-
end_date: z.date().optional(),
|
|
5771
|
-
next_seq: z.number().min(1, "Next sequence must be at least 1").optional(),
|
|
5772
|
-
auto_generate_dates: z.boolean().optional().default(true)
|
|
5610
|
+
ZodPromise.create;
|
|
5611
|
+
ZodOptional.create;
|
|
5612
|
+
ZodNullable.create;
|
|
5613
|
+
const quoteSequenceSchema = objectType({
|
|
5614
|
+
start_date: dateType().optional(),
|
|
5615
|
+
end_date: dateType().optional(),
|
|
5616
|
+
next_seq: numberType().min(1, "Next sequence must be at least 1").optional(),
|
|
5617
|
+
auto_generate_dates: booleanType().optional().default(true)
|
|
5773
5618
|
}).refine(
|
|
5774
5619
|
(data) => {
|
|
5775
5620
|
if (data.start_date && data.end_date) {
|
|
@@ -6167,10 +6012,10 @@ const ActiveSequenceDisplay = () => {
|
|
|
6167
6012
|
)
|
|
6168
6013
|
] });
|
|
6169
6014
|
};
|
|
6170
|
-
const quoteConfigSchema =
|
|
6171
|
-
prefix:
|
|
6172
|
-
suffix:
|
|
6173
|
-
seq_type:
|
|
6015
|
+
const quoteConfigSchema = objectType({
|
|
6016
|
+
prefix: stringType().min(1, "Prefix is required").max(10, "Prefix must be 10 characters or less"),
|
|
6017
|
+
suffix: stringType().max(10, "Suffix must be 10 characters or less").optional(),
|
|
6018
|
+
seq_type: enumType(["monthly", "yearly"], {
|
|
6174
6019
|
required_error: "Sequence type is required"
|
|
6175
6020
|
})
|
|
6176
6021
|
});
|