@rpgjs/client 5.0.0-alpha.23 → 5.0.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index30.js → Game/AnimationManager.js} +1 -1
- package/dist/Game/AnimationManager.js.map +1 -0
- package/dist/{index24.js → Game/Event.js} +2 -2
- package/dist/Game/Event.js.map +1 -0
- package/dist/{index29.js → Game/Map.js} +6 -6
- package/dist/Game/Map.js.map +1 -0
- package/dist/{index22.js → Game/Object.js} +4 -4
- package/dist/Game/Object.js.map +1 -0
- package/dist/{index23.js → Game/Player.js} +2 -2
- package/dist/Game/Player.js.map +1 -0
- package/dist/{index9.js → Gui/Gui.js} +10 -11
- package/dist/{index9.js.map → Gui/Gui.js.map} +1 -1
- package/dist/{index19.js → Resource.js} +1 -1
- package/dist/Resource.js.map +1 -0
- package/dist/RpgClientEngine.d.ts +66 -115
- package/dist/{index2.js → RpgClientEngine.js} +234 -176
- package/dist/RpgClientEngine.js.map +1 -0
- package/dist/{index18.js → Sound.js} +1 -1
- package/dist/Sound.js.map +1 -0
- package/dist/{index35.js → components/animations/animation.ce.js} +3 -3
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/{index34.js → components/animations/hit.ce.js} +1 -1
- package/dist/components/animations/hit.ce.js.map +1 -0
- package/dist/{index12.js → components/animations/index.js} +3 -3
- package/dist/components/animations/index.js.map +1 -0
- package/dist/{index17.js → components/character.ce.js} +4 -4
- package/dist/components/character.ce.js.map +1 -0
- package/dist/{index51.js → components/dynamics/parse-value.js} +1 -1
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/{index40.js → components/dynamics/text.ce.js} +2 -2
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/{index11.js → components/gui/box.ce.js} +8 -8
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/{index10.js → components/gui/dialogbox/index.ce.js} +4 -4
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/{index52.js → components/gui/dialogbox/itemMenu.ce.js} +1 -1
- package/dist/components/gui/dialogbox/itemMenu.ce.js.map +1 -0
- package/dist/{index47.js → components/gui/dialogbox/selection.ce.js} +4 -4
- package/dist/components/gui/dialogbox/selection.ce.js.map +1 -0
- package/dist/components/gui/mobile/index.d.ts +1 -1
- package/dist/{index25.js → components/gui/mobile/index.js} +5 -5
- package/dist/components/gui/mobile/index.js.map +1 -0
- package/dist/components/gui/mobile/mobile.ce.js +17 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/{index13.js → components/prebuilt/hp-bar.ce.js} +1 -1
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
- package/dist/{index14.js → components/prebuilt/light-halo.ce.js} +2 -3
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/{index26.js → components/scenes/canvas.ce.js} +6 -7
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/{index46.js → components/scenes/draw-map.ce.js} +3 -3
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/{index16.js → components/scenes/event-layer.ce.js} +4 -4
- package/dist/components/scenes/event-layer.ce.js.map +1 -0
- package/dist/{index6.js → core/inject.js} +2 -2
- package/dist/core/inject.js.map +1 -0
- package/dist/{index5.js → core/setup.js} +4 -4
- package/dist/core/setup.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -24
- package/dist/index.js.map +1 -1
- package/dist/{index8.js → module.js} +10 -5
- package/dist/module.js.map +1 -0
- package/dist/{index20.js → node_modules/.pnpm/@signe_di@2.6.0/node_modules/@signe/di/dist/index.js} +1 -1
- package/dist/node_modules/.pnpm/@signe_di@2.6.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/{index45.js → node_modules/.pnpm/@signe_reactive@2.6.0/node_modules/@signe/reactive/dist/index.js} +216 -11
- package/dist/node_modules/.pnpm/@signe_reactive@2.6.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/{index32.js → node_modules/.pnpm/@signe_room@2.6.0/node_modules/@signe/room/dist/index.js} +29 -30
- package/dist/node_modules/.pnpm/@signe_room@2.6.0/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/{index42.js → node_modules/.pnpm/@signe_sync@2.6.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js} +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.6.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/{index33.js → node_modules/.pnpm/@signe_sync@2.6.0/node_modules/@signe/sync/dist/client/index.js} +5 -5
- package/dist/node_modules/.pnpm/@signe_sync@2.6.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/{index28.js → node_modules/.pnpm/@signe_sync@2.6.0/node_modules/@signe/sync/dist/index.js} +3 -3
- package/dist/node_modules/.pnpm/@signe_sync@2.6.0/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/{index48.js → node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js} +1 -1
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
- package/dist/{index43.js → node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js} +2 -15
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
- package/dist/{index44.js → node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js} +2 -5
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
- package/dist/{index50.js → node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js} +813 -100
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
- package/dist/{index36.js → presets/animation.js} +1 -1
- package/dist/presets/animation.js.map +1 -0
- package/dist/{index39.js → presets/faceset.js} +1 -1
- package/dist/presets/faceset.js.map +1 -0
- package/dist/presets/index.js +14 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/{index37.js → presets/lpc.js} +1 -1
- package/dist/presets/lpc.js.map +1 -0
- package/dist/{index38.js → presets/rmspritesheet.js} +1 -1
- package/dist/presets/rmspritesheet.js.map +1 -0
- package/dist/{index27.js → services/AbstractSocket.js} +1 -1
- package/dist/services/AbstractSocket.js.map +1 -0
- package/dist/{index21.js → services/keyboardControls.js} +1 -1
- package/dist/services/keyboardControls.js.map +1 -0
- package/dist/{index7.js → services/loadMap.js} +2 -2
- package/dist/services/loadMap.js.map +1 -0
- package/dist/{index4.js → services/mmorpg.js} +6 -6
- package/dist/services/mmorpg.js.map +1 -0
- package/dist/services/standalone.d.ts +3 -0
- package/dist/{index3.js → services/standalone.js} +18 -12
- package/dist/services/standalone.js.map +1 -0
- package/package.json +9 -9
- package/src/Gui/Gui.ts +0 -1
- package/src/RpgClientEngine.ts +298 -182
- package/src/components/character.ce +2 -3
- package/src/components/gui/mobile/index.ts +1 -1
- package/src/components/gui/mobile/mobile.ce +73 -88
- package/src/components/prebuilt/light-halo.ce +2 -71
- package/src/components/scenes/canvas.ce +0 -10
- package/src/components/scenes/event-layer.ce +1 -0
- package/src/index.ts +2 -1
- package/src/module.ts +6 -1
- package/src/services/standalone.ts +16 -7
- package/vite.config.ts +4 -2
- package/dist/Game/TransitionManager.d.ts +0 -56
- package/dist/index10.js.map +0 -1
- package/dist/index11.js.map +0 -1
- package/dist/index12.js.map +0 -1
- package/dist/index13.js.map +0 -1
- package/dist/index14.js.map +0 -1
- package/dist/index15.js +0 -14
- package/dist/index15.js.map +0 -1
- package/dist/index16.js.map +0 -1
- package/dist/index17.js.map +0 -1
- package/dist/index18.js.map +0 -1
- package/dist/index19.js.map +0 -1
- package/dist/index2.js.map +0 -1
- package/dist/index20.js.map +0 -1
- package/dist/index21.js.map +0 -1
- package/dist/index22.js.map +0 -1
- package/dist/index23.js.map +0 -1
- package/dist/index24.js.map +0 -1
- package/dist/index25.js.map +0 -1
- package/dist/index26.js.map +0 -1
- package/dist/index27.js.map +0 -1
- package/dist/index28.js.map +0 -1
- package/dist/index29.js.map +0 -1
- package/dist/index3.js.map +0 -1
- package/dist/index30.js.map +0 -1
- package/dist/index31.js +0 -53
- package/dist/index31.js.map +0 -1
- package/dist/index32.js.map +0 -1
- package/dist/index33.js.map +0 -1
- package/dist/index34.js.map +0 -1
- package/dist/index35.js.map +0 -1
- package/dist/index36.js.map +0 -1
- package/dist/index37.js.map +0 -1
- package/dist/index38.js.map +0 -1
- package/dist/index39.js.map +0 -1
- package/dist/index4.js.map +0 -1
- package/dist/index40.js.map +0 -1
- package/dist/index41.js +0 -43
- package/dist/index41.js.map +0 -1
- package/dist/index42.js.map +0 -1
- package/dist/index43.js.map +0 -1
- package/dist/index44.js.map +0 -1
- package/dist/index45.js.map +0 -1
- package/dist/index46.js.map +0 -1
- package/dist/index47.js.map +0 -1
- package/dist/index48.js.map +0 -1
- package/dist/index49.js +0 -7
- package/dist/index49.js.map +0 -1
- package/dist/index5.js.map +0 -1
- package/dist/index50.js.map +0 -1
- package/dist/index51.js.map +0 -1
- package/dist/index52.js.map +0 -1
- package/dist/index53.js +0 -6
- package/dist/index53.js.map +0 -1
- package/dist/index54.js +0 -12
- package/dist/index54.js.map +0 -1
- package/dist/index55.js +0 -113
- package/dist/index55.js.map +0 -1
- package/dist/index56.js +0 -136
- package/dist/index56.js.map +0 -1
- package/dist/index57.js +0 -137
- package/dist/index57.js.map +0 -1
- package/dist/index58.js +0 -112
- package/dist/index58.js.map +0 -1
- package/dist/index59.js +0 -9
- package/dist/index59.js.map +0 -1
- package/dist/index6.js.map +0 -1
- package/dist/index7.js.map +0 -1
- package/dist/index8.js.map +0 -1
- package/src/Game/TransitionManager.ts +0 -75
|
@@ -1,10 +1,553 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var util;
|
|
2
|
+
(function (util) {
|
|
3
|
+
util.assertEqual = (val) => val;
|
|
4
|
+
function assertIs(_arg) { }
|
|
5
|
+
util.assertIs = assertIs;
|
|
6
|
+
function assertNever(_x) {
|
|
7
|
+
throw new Error();
|
|
8
|
+
}
|
|
9
|
+
util.assertNever = assertNever;
|
|
10
|
+
util.arrayToEnum = (items) => {
|
|
11
|
+
const obj = {};
|
|
12
|
+
for (const item of items) {
|
|
13
|
+
obj[item] = item;
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
};
|
|
17
|
+
util.getValidEnumValues = (obj) => {
|
|
18
|
+
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
19
|
+
const filtered = {};
|
|
20
|
+
for (const k of validKeys) {
|
|
21
|
+
filtered[k] = obj[k];
|
|
22
|
+
}
|
|
23
|
+
return util.objectValues(filtered);
|
|
24
|
+
};
|
|
25
|
+
util.objectValues = (obj) => {
|
|
26
|
+
return util.objectKeys(obj).map(function (e) {
|
|
27
|
+
return obj[e];
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
|
31
|
+
? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
|
|
32
|
+
: (object) => {
|
|
33
|
+
const keys = [];
|
|
34
|
+
for (const key in object) {
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
36
|
+
keys.push(key);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return keys;
|
|
40
|
+
};
|
|
41
|
+
util.find = (arr, checker) => {
|
|
42
|
+
for (const item of arr) {
|
|
43
|
+
if (checker(item))
|
|
44
|
+
return item;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
util.isInteger = typeof Number.isInteger === "function"
|
|
49
|
+
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
|
50
|
+
: (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
51
|
+
function joinValues(array, separator = " | ") {
|
|
52
|
+
return array
|
|
53
|
+
.map((val) => (typeof val === "string" ? `'${val}'` : val))
|
|
54
|
+
.join(separator);
|
|
55
|
+
}
|
|
56
|
+
util.joinValues = joinValues;
|
|
57
|
+
util.jsonStringifyReplacer = (_, value) => {
|
|
58
|
+
if (typeof value === "bigint") {
|
|
59
|
+
return value.toString();
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
};
|
|
63
|
+
})(util || (util = {}));
|
|
64
|
+
var objectUtil;
|
|
65
|
+
(function (objectUtil) {
|
|
66
|
+
objectUtil.mergeShapes = (first, second) => {
|
|
67
|
+
return {
|
|
68
|
+
...first,
|
|
69
|
+
...second, // second overwrites first
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
})(objectUtil || (objectUtil = {}));
|
|
73
|
+
const ZodParsedType = util.arrayToEnum([
|
|
74
|
+
"string",
|
|
75
|
+
"nan",
|
|
76
|
+
"number",
|
|
77
|
+
"integer",
|
|
78
|
+
"float",
|
|
79
|
+
"boolean",
|
|
80
|
+
"date",
|
|
81
|
+
"bigint",
|
|
82
|
+
"symbol",
|
|
83
|
+
"function",
|
|
84
|
+
"undefined",
|
|
85
|
+
"null",
|
|
86
|
+
"array",
|
|
87
|
+
"object",
|
|
88
|
+
"unknown",
|
|
89
|
+
"promise",
|
|
90
|
+
"void",
|
|
91
|
+
"never",
|
|
92
|
+
"map",
|
|
93
|
+
"set",
|
|
94
|
+
]);
|
|
95
|
+
const getParsedType = (data) => {
|
|
96
|
+
const t = typeof data;
|
|
97
|
+
switch (t) {
|
|
98
|
+
case "undefined":
|
|
99
|
+
return ZodParsedType.undefined;
|
|
100
|
+
case "string":
|
|
101
|
+
return ZodParsedType.string;
|
|
102
|
+
case "number":
|
|
103
|
+
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
104
|
+
case "boolean":
|
|
105
|
+
return ZodParsedType.boolean;
|
|
106
|
+
case "function":
|
|
107
|
+
return ZodParsedType.function;
|
|
108
|
+
case "bigint":
|
|
109
|
+
return ZodParsedType.bigint;
|
|
110
|
+
case "symbol":
|
|
111
|
+
return ZodParsedType.symbol;
|
|
112
|
+
case "object":
|
|
113
|
+
if (Array.isArray(data)) {
|
|
114
|
+
return ZodParsedType.array;
|
|
115
|
+
}
|
|
116
|
+
if (data === null) {
|
|
117
|
+
return ZodParsedType.null;
|
|
118
|
+
}
|
|
119
|
+
if (data.then &&
|
|
120
|
+
typeof data.then === "function" &&
|
|
121
|
+
data.catch &&
|
|
122
|
+
typeof data.catch === "function") {
|
|
123
|
+
return ZodParsedType.promise;
|
|
124
|
+
}
|
|
125
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
126
|
+
return ZodParsedType.map;
|
|
127
|
+
}
|
|
128
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
129
|
+
return ZodParsedType.set;
|
|
130
|
+
}
|
|
131
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
132
|
+
return ZodParsedType.date;
|
|
133
|
+
}
|
|
134
|
+
return ZodParsedType.object;
|
|
135
|
+
default:
|
|
136
|
+
return ZodParsedType.unknown;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const ZodIssueCode = util.arrayToEnum([
|
|
141
|
+
"invalid_type",
|
|
142
|
+
"invalid_literal",
|
|
143
|
+
"custom",
|
|
144
|
+
"invalid_union",
|
|
145
|
+
"invalid_union_discriminator",
|
|
146
|
+
"invalid_enum_value",
|
|
147
|
+
"unrecognized_keys",
|
|
148
|
+
"invalid_arguments",
|
|
149
|
+
"invalid_return_type",
|
|
150
|
+
"invalid_date",
|
|
151
|
+
"invalid_string",
|
|
152
|
+
"too_small",
|
|
153
|
+
"too_big",
|
|
154
|
+
"invalid_intersection_types",
|
|
155
|
+
"not_multiple_of",
|
|
156
|
+
"not_finite",
|
|
157
|
+
]);
|
|
158
|
+
const quotelessJson = (obj) => {
|
|
159
|
+
const json = JSON.stringify(obj, null, 2);
|
|
160
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
161
|
+
};
|
|
162
|
+
class ZodError extends Error {
|
|
163
|
+
get errors() {
|
|
164
|
+
return this.issues;
|
|
165
|
+
}
|
|
166
|
+
constructor(issues) {
|
|
167
|
+
super();
|
|
168
|
+
this.issues = [];
|
|
169
|
+
this.addIssue = (sub) => {
|
|
170
|
+
this.issues = [...this.issues, sub];
|
|
171
|
+
};
|
|
172
|
+
this.addIssues = (subs = []) => {
|
|
173
|
+
this.issues = [...this.issues, ...subs];
|
|
174
|
+
};
|
|
175
|
+
const actualProto = new.target.prototype;
|
|
176
|
+
if (Object.setPrototypeOf) {
|
|
177
|
+
// eslint-disable-next-line ban/ban
|
|
178
|
+
Object.setPrototypeOf(this, actualProto);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
this.__proto__ = actualProto;
|
|
182
|
+
}
|
|
183
|
+
this.name = "ZodError";
|
|
184
|
+
this.issues = issues;
|
|
185
|
+
}
|
|
186
|
+
format(_mapper) {
|
|
187
|
+
const mapper = _mapper ||
|
|
188
|
+
function (issue) {
|
|
189
|
+
return issue.message;
|
|
190
|
+
};
|
|
191
|
+
const fieldErrors = { _errors: [] };
|
|
192
|
+
const processError = (error) => {
|
|
193
|
+
for (const issue of error.issues) {
|
|
194
|
+
if (issue.code === "invalid_union") {
|
|
195
|
+
issue.unionErrors.map(processError);
|
|
196
|
+
}
|
|
197
|
+
else if (issue.code === "invalid_return_type") {
|
|
198
|
+
processError(issue.returnTypeError);
|
|
199
|
+
}
|
|
200
|
+
else if (issue.code === "invalid_arguments") {
|
|
201
|
+
processError(issue.argumentsError);
|
|
202
|
+
}
|
|
203
|
+
else if (issue.path.length === 0) {
|
|
204
|
+
fieldErrors._errors.push(mapper(issue));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
let curr = fieldErrors;
|
|
208
|
+
let i = 0;
|
|
209
|
+
while (i < issue.path.length) {
|
|
210
|
+
const el = issue.path[i];
|
|
211
|
+
const terminal = i === issue.path.length - 1;
|
|
212
|
+
if (!terminal) {
|
|
213
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
214
|
+
// if (typeof el === "string") {
|
|
215
|
+
// curr[el] = curr[el] || { _errors: [] };
|
|
216
|
+
// } else if (typeof el === "number") {
|
|
217
|
+
// const errorArray: any = [];
|
|
218
|
+
// errorArray._errors = [];
|
|
219
|
+
// curr[el] = curr[el] || errorArray;
|
|
220
|
+
// }
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
224
|
+
curr[el]._errors.push(mapper(issue));
|
|
225
|
+
}
|
|
226
|
+
curr = curr[el];
|
|
227
|
+
i++;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
processError(this);
|
|
233
|
+
return fieldErrors;
|
|
234
|
+
}
|
|
235
|
+
static assert(value) {
|
|
236
|
+
if (!(value instanceof ZodError)) {
|
|
237
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
toString() {
|
|
241
|
+
return this.message;
|
|
242
|
+
}
|
|
243
|
+
get message() {
|
|
244
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
245
|
+
}
|
|
246
|
+
get isEmpty() {
|
|
247
|
+
return this.issues.length === 0;
|
|
248
|
+
}
|
|
249
|
+
flatten(mapper = (issue) => issue.message) {
|
|
250
|
+
const fieldErrors = {};
|
|
251
|
+
const formErrors = [];
|
|
252
|
+
for (const sub of this.issues) {
|
|
253
|
+
if (sub.path.length > 0) {
|
|
254
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
255
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
formErrors.push(mapper(sub));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return { formErrors, fieldErrors };
|
|
262
|
+
}
|
|
263
|
+
get formErrors() {
|
|
264
|
+
return this.flatten();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
ZodError.create = (issues) => {
|
|
268
|
+
const error = new ZodError(issues);
|
|
269
|
+
return error;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const errorMap = (issue, _ctx) => {
|
|
273
|
+
let message;
|
|
274
|
+
switch (issue.code) {
|
|
275
|
+
case ZodIssueCode.invalid_type:
|
|
276
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
277
|
+
message = "Required";
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
case ZodIssueCode.invalid_literal:
|
|
284
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
285
|
+
break;
|
|
286
|
+
case ZodIssueCode.unrecognized_keys:
|
|
287
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
288
|
+
break;
|
|
289
|
+
case ZodIssueCode.invalid_union:
|
|
290
|
+
message = `Invalid input`;
|
|
291
|
+
break;
|
|
292
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
293
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
294
|
+
break;
|
|
295
|
+
case ZodIssueCode.invalid_enum_value:
|
|
296
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
297
|
+
break;
|
|
298
|
+
case ZodIssueCode.invalid_arguments:
|
|
299
|
+
message = `Invalid function arguments`;
|
|
300
|
+
break;
|
|
301
|
+
case ZodIssueCode.invalid_return_type:
|
|
302
|
+
message = `Invalid function return type`;
|
|
303
|
+
break;
|
|
304
|
+
case ZodIssueCode.invalid_date:
|
|
305
|
+
message = `Invalid date`;
|
|
306
|
+
break;
|
|
307
|
+
case ZodIssueCode.invalid_string:
|
|
308
|
+
if (typeof issue.validation === "object") {
|
|
309
|
+
if ("includes" in issue.validation) {
|
|
310
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
311
|
+
if (typeof issue.validation.position === "number") {
|
|
312
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else if ("startsWith" in issue.validation) {
|
|
316
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
317
|
+
}
|
|
318
|
+
else if ("endsWith" in issue.validation) {
|
|
319
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
util.assertNever(issue.validation);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (issue.validation !== "regex") {
|
|
326
|
+
message = `Invalid ${issue.validation}`;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
message = "Invalid";
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
case ZodIssueCode.too_small:
|
|
333
|
+
if (issue.type === "array")
|
|
334
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
335
|
+
else if (issue.type === "string")
|
|
336
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
337
|
+
else if (issue.type === "number")
|
|
338
|
+
message = `Number must be ${issue.exact
|
|
339
|
+
? `exactly equal to `
|
|
340
|
+
: issue.inclusive
|
|
341
|
+
? `greater than or equal to `
|
|
342
|
+
: `greater than `}${issue.minimum}`;
|
|
343
|
+
else if (issue.type === "date")
|
|
344
|
+
message = `Date must be ${issue.exact
|
|
345
|
+
? `exactly equal to `
|
|
346
|
+
: issue.inclusive
|
|
347
|
+
? `greater than or equal to `
|
|
348
|
+
: `greater than `}${new Date(Number(issue.minimum))}`;
|
|
349
|
+
else
|
|
350
|
+
message = "Invalid input";
|
|
351
|
+
break;
|
|
352
|
+
case ZodIssueCode.too_big:
|
|
353
|
+
if (issue.type === "array")
|
|
354
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
355
|
+
else if (issue.type === "string")
|
|
356
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
357
|
+
else if (issue.type === "number")
|
|
358
|
+
message = `Number must be ${issue.exact
|
|
359
|
+
? `exactly`
|
|
360
|
+
: issue.inclusive
|
|
361
|
+
? `less than or equal to`
|
|
362
|
+
: `less than`} ${issue.maximum}`;
|
|
363
|
+
else if (issue.type === "bigint")
|
|
364
|
+
message = `BigInt must be ${issue.exact
|
|
365
|
+
? `exactly`
|
|
366
|
+
: issue.inclusive
|
|
367
|
+
? `less than or equal to`
|
|
368
|
+
: `less than`} ${issue.maximum}`;
|
|
369
|
+
else if (issue.type === "date")
|
|
370
|
+
message = `Date must be ${issue.exact
|
|
371
|
+
? `exactly`
|
|
372
|
+
: issue.inclusive
|
|
373
|
+
? `smaller than or equal to`
|
|
374
|
+
: `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
375
|
+
else
|
|
376
|
+
message = "Invalid input";
|
|
377
|
+
break;
|
|
378
|
+
case ZodIssueCode.custom:
|
|
379
|
+
message = `Invalid input`;
|
|
380
|
+
break;
|
|
381
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
382
|
+
message = `Intersection results could not be merged`;
|
|
383
|
+
break;
|
|
384
|
+
case ZodIssueCode.not_multiple_of:
|
|
385
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
386
|
+
break;
|
|
387
|
+
case ZodIssueCode.not_finite:
|
|
388
|
+
message = "Number must be finite";
|
|
389
|
+
break;
|
|
390
|
+
default:
|
|
391
|
+
message = _ctx.defaultError;
|
|
392
|
+
util.assertNever(issue);
|
|
393
|
+
}
|
|
394
|
+
return { message };
|
|
395
|
+
};
|
|
7
396
|
|
|
397
|
+
let overrideErrorMap = errorMap;
|
|
398
|
+
function setErrorMap(map) {
|
|
399
|
+
overrideErrorMap = map;
|
|
400
|
+
}
|
|
401
|
+
function getErrorMap() {
|
|
402
|
+
return overrideErrorMap;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const makeIssue = (params) => {
|
|
406
|
+
const { data, path, errorMaps, issueData } = params;
|
|
407
|
+
const fullPath = [...path, ...(issueData.path || [])];
|
|
408
|
+
const fullIssue = {
|
|
409
|
+
...issueData,
|
|
410
|
+
path: fullPath,
|
|
411
|
+
};
|
|
412
|
+
if (issueData.message !== undefined) {
|
|
413
|
+
return {
|
|
414
|
+
...issueData,
|
|
415
|
+
path: fullPath,
|
|
416
|
+
message: issueData.message,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
let errorMessage = "";
|
|
420
|
+
const maps = errorMaps
|
|
421
|
+
.filter((m) => !!m)
|
|
422
|
+
.slice()
|
|
423
|
+
.reverse();
|
|
424
|
+
for (const map of maps) {
|
|
425
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
...issueData,
|
|
429
|
+
path: fullPath,
|
|
430
|
+
message: errorMessage,
|
|
431
|
+
};
|
|
432
|
+
};
|
|
433
|
+
const EMPTY_PATH = [];
|
|
434
|
+
function addIssueToContext(ctx, issueData) {
|
|
435
|
+
const overrideMap = getErrorMap();
|
|
436
|
+
const issue = makeIssue({
|
|
437
|
+
issueData: issueData,
|
|
438
|
+
data: ctx.data,
|
|
439
|
+
path: ctx.path,
|
|
440
|
+
errorMaps: [
|
|
441
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
442
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
443
|
+
overrideMap, // then global override map
|
|
444
|
+
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
445
|
+
].filter((x) => !!x),
|
|
446
|
+
});
|
|
447
|
+
ctx.common.issues.push(issue);
|
|
448
|
+
}
|
|
449
|
+
class ParseStatus {
|
|
450
|
+
constructor() {
|
|
451
|
+
this.value = "valid";
|
|
452
|
+
}
|
|
453
|
+
dirty() {
|
|
454
|
+
if (this.value === "valid")
|
|
455
|
+
this.value = "dirty";
|
|
456
|
+
}
|
|
457
|
+
abort() {
|
|
458
|
+
if (this.value !== "aborted")
|
|
459
|
+
this.value = "aborted";
|
|
460
|
+
}
|
|
461
|
+
static mergeArray(status, results) {
|
|
462
|
+
const arrayValue = [];
|
|
463
|
+
for (const s of results) {
|
|
464
|
+
if (s.status === "aborted")
|
|
465
|
+
return INVALID;
|
|
466
|
+
if (s.status === "dirty")
|
|
467
|
+
status.dirty();
|
|
468
|
+
arrayValue.push(s.value);
|
|
469
|
+
}
|
|
470
|
+
return { status: status.value, value: arrayValue };
|
|
471
|
+
}
|
|
472
|
+
static async mergeObjectAsync(status, pairs) {
|
|
473
|
+
const syncPairs = [];
|
|
474
|
+
for (const pair of pairs) {
|
|
475
|
+
const key = await pair.key;
|
|
476
|
+
const value = await pair.value;
|
|
477
|
+
syncPairs.push({
|
|
478
|
+
key,
|
|
479
|
+
value,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
483
|
+
}
|
|
484
|
+
static mergeObjectSync(status, pairs) {
|
|
485
|
+
const finalObject = {};
|
|
486
|
+
for (const pair of pairs) {
|
|
487
|
+
const { key, value } = pair;
|
|
488
|
+
if (key.status === "aborted")
|
|
489
|
+
return INVALID;
|
|
490
|
+
if (value.status === "aborted")
|
|
491
|
+
return INVALID;
|
|
492
|
+
if (key.status === "dirty")
|
|
493
|
+
status.dirty();
|
|
494
|
+
if (value.status === "dirty")
|
|
495
|
+
status.dirty();
|
|
496
|
+
if (key.value !== "__proto__" &&
|
|
497
|
+
(typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
498
|
+
finalObject[key.value] = value.value;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return { status: status.value, value: finalObject };
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const INVALID = Object.freeze({
|
|
505
|
+
status: "aborted",
|
|
506
|
+
});
|
|
507
|
+
const DIRTY = (value) => ({ status: "dirty", value });
|
|
508
|
+
const OK = (value) => ({ status: "valid", value });
|
|
509
|
+
const isAborted = (x) => x.status === "aborted";
|
|
510
|
+
const isDirty = (x) => x.status === "dirty";
|
|
511
|
+
const isValid = (x) => x.status === "valid";
|
|
512
|
+
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
513
|
+
|
|
514
|
+
/******************************************************************************
|
|
515
|
+
Copyright (c) Microsoft Corporation.
|
|
516
|
+
|
|
517
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
518
|
+
purpose with or without fee is hereby granted.
|
|
519
|
+
|
|
520
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
521
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
522
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
523
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
524
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
525
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
526
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
527
|
+
***************************************************************************** */
|
|
528
|
+
|
|
529
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
530
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
531
|
+
return state.get(receiver);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
535
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
536
|
+
return (state.set(receiver, value)), value;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
540
|
+
var e = new Error(message);
|
|
541
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
var errorUtil;
|
|
545
|
+
(function (errorUtil) {
|
|
546
|
+
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
547
|
+
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
548
|
+
})(errorUtil || (errorUtil = {}));
|
|
549
|
+
|
|
550
|
+
var _ZodEnum_cache, _ZodNativeEnum_cache;
|
|
8
551
|
class ParseInputLazyPath {
|
|
9
552
|
constructor(parent, value, path, key) {
|
|
10
553
|
this._cachedPath = [];
|
|
@@ -15,7 +558,7 @@ class ParseInputLazyPath {
|
|
|
15
558
|
}
|
|
16
559
|
get path() {
|
|
17
560
|
if (!this._cachedPath.length) {
|
|
18
|
-
if (
|
|
561
|
+
if (this._key instanceof Array) {
|
|
19
562
|
this._cachedPath.push(...this._path, ...this._key);
|
|
20
563
|
}
|
|
21
564
|
else {
|
|
@@ -55,16 +598,17 @@ function processCreateParams(params) {
|
|
|
55
598
|
if (errorMap)
|
|
56
599
|
return { errorMap: errorMap, description };
|
|
57
600
|
const customMap = (iss, ctx) => {
|
|
601
|
+
var _a, _b;
|
|
58
602
|
const { message } = params;
|
|
59
603
|
if (iss.code === "invalid_enum_value") {
|
|
60
|
-
return { message: message
|
|
604
|
+
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
61
605
|
}
|
|
62
606
|
if (typeof ctx.data === "undefined") {
|
|
63
|
-
return { message: message
|
|
607
|
+
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
64
608
|
}
|
|
65
609
|
if (iss.code !== "invalid_type")
|
|
66
610
|
return { message: ctx.defaultError };
|
|
67
|
-
return { message: message
|
|
611
|
+
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
68
612
|
};
|
|
69
613
|
return { errorMap: customMap, description };
|
|
70
614
|
}
|
|
@@ -116,13 +660,14 @@ class ZodType {
|
|
|
116
660
|
throw result.error;
|
|
117
661
|
}
|
|
118
662
|
safeParse(data, params) {
|
|
663
|
+
var _a;
|
|
119
664
|
const ctx = {
|
|
120
665
|
common: {
|
|
121
666
|
issues: [],
|
|
122
|
-
async: params
|
|
123
|
-
contextualErrorMap: params
|
|
667
|
+
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
668
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
124
669
|
},
|
|
125
|
-
path: params
|
|
670
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
126
671
|
schemaErrorMap: this._def.errorMap,
|
|
127
672
|
parent: null,
|
|
128
673
|
data,
|
|
@@ -132,6 +677,7 @@ class ZodType {
|
|
|
132
677
|
return handleResult(ctx, result);
|
|
133
678
|
}
|
|
134
679
|
"~validate"(data) {
|
|
680
|
+
var _a, _b;
|
|
135
681
|
const ctx = {
|
|
136
682
|
common: {
|
|
137
683
|
issues: [],
|
|
@@ -155,7 +701,7 @@ class ZodType {
|
|
|
155
701
|
};
|
|
156
702
|
}
|
|
157
703
|
catch (err) {
|
|
158
|
-
if (err
|
|
704
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
159
705
|
this["~standard"].async = true;
|
|
160
706
|
}
|
|
161
707
|
ctx.common = {
|
|
@@ -182,17 +728,19 @@ class ZodType {
|
|
|
182
728
|
const ctx = {
|
|
183
729
|
common: {
|
|
184
730
|
issues: [],
|
|
185
|
-
contextualErrorMap: params
|
|
731
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
186
732
|
async: true,
|
|
187
733
|
},
|
|
188
|
-
path: params
|
|
734
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
189
735
|
schemaErrorMap: this._def.errorMap,
|
|
190
736
|
parent: null,
|
|
191
737
|
data,
|
|
192
738
|
parsedType: getParsedType(data),
|
|
193
739
|
};
|
|
194
740
|
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
195
|
-
const result = await (isAsync(maybeAsyncResult)
|
|
741
|
+
const result = await (isAsync(maybeAsyncResult)
|
|
742
|
+
? maybeAsyncResult
|
|
743
|
+
: Promise.resolve(maybeAsyncResult));
|
|
196
744
|
return handleResult(ctx, result);
|
|
197
745
|
}
|
|
198
746
|
refine(check, message) {
|
|
@@ -236,7 +784,9 @@ class ZodType {
|
|
|
236
784
|
refinement(check, refinementData) {
|
|
237
785
|
return this._refinement((val, ctx) => {
|
|
238
786
|
if (!check(val)) {
|
|
239
|
-
ctx.addIssue(typeof refinementData === "function"
|
|
787
|
+
ctx.addIssue(typeof refinementData === "function"
|
|
788
|
+
? refinementData(val, ctx)
|
|
789
|
+
: refinementData);
|
|
240
790
|
return false;
|
|
241
791
|
}
|
|
242
792
|
else {
|
|
@@ -408,15 +958,15 @@ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z
|
|
|
408
958
|
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])))`;
|
|
409
959
|
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
410
960
|
function timeRegexSource(args) {
|
|
411
|
-
let
|
|
961
|
+
// let regex = `\\d{2}:\\d{2}:\\d{2}`;
|
|
962
|
+
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
412
963
|
if (args.precision) {
|
|
413
|
-
|
|
964
|
+
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
414
965
|
}
|
|
415
966
|
else if (args.precision == null) {
|
|
416
|
-
|
|
967
|
+
regex = `${regex}(\\.\\d+)?`;
|
|
417
968
|
}
|
|
418
|
-
|
|
419
|
-
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
969
|
+
return regex;
|
|
420
970
|
}
|
|
421
971
|
function timeRegex(args) {
|
|
422
972
|
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
@@ -445,8 +995,6 @@ function isValidJWT(jwt, alg) {
|
|
|
445
995
|
return false;
|
|
446
996
|
try {
|
|
447
997
|
const [header] = jwt.split(".");
|
|
448
|
-
if (!header)
|
|
449
|
-
return false;
|
|
450
998
|
// Convert base64url to base64
|
|
451
999
|
const base64 = header
|
|
452
1000
|
.replace(/-/g, "+")
|
|
@@ -455,15 +1003,13 @@ function isValidJWT(jwt, alg) {
|
|
|
455
1003
|
const decoded = JSON.parse(atob(base64));
|
|
456
1004
|
if (typeof decoded !== "object" || decoded === null)
|
|
457
1005
|
return false;
|
|
458
|
-
if (
|
|
459
|
-
return false;
|
|
460
|
-
if (!decoded.alg)
|
|
1006
|
+
if (!decoded.typ || !decoded.alg)
|
|
461
1007
|
return false;
|
|
462
1008
|
if (alg && decoded.alg !== alg)
|
|
463
1009
|
return false;
|
|
464
1010
|
return true;
|
|
465
1011
|
}
|
|
466
|
-
catch {
|
|
1012
|
+
catch (_a) {
|
|
467
1013
|
return false;
|
|
468
1014
|
}
|
|
469
1015
|
}
|
|
@@ -634,7 +1180,7 @@ class ZodString extends ZodType {
|
|
|
634
1180
|
try {
|
|
635
1181
|
new URL(input.data);
|
|
636
1182
|
}
|
|
637
|
-
catch {
|
|
1183
|
+
catch (_a) {
|
|
638
1184
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
639
1185
|
addIssueToContext(ctx, {
|
|
640
1186
|
validation: "url",
|
|
@@ -864,6 +1410,7 @@ class ZodString extends ZodType {
|
|
|
864
1410
|
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
865
1411
|
}
|
|
866
1412
|
datetime(options) {
|
|
1413
|
+
var _a, _b;
|
|
867
1414
|
if (typeof options === "string") {
|
|
868
1415
|
return this._addCheck({
|
|
869
1416
|
kind: "datetime",
|
|
@@ -875,10 +1422,10 @@ class ZodString extends ZodType {
|
|
|
875
1422
|
}
|
|
876
1423
|
return this._addCheck({
|
|
877
1424
|
kind: "datetime",
|
|
878
|
-
precision: typeof options
|
|
879
|
-
offset: options
|
|
880
|
-
local: options
|
|
881
|
-
...errorUtil.errToObj(options
|
|
1425
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1426
|
+
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1427
|
+
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
|
1428
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
882
1429
|
});
|
|
883
1430
|
}
|
|
884
1431
|
date(message) {
|
|
@@ -894,8 +1441,8 @@ class ZodString extends ZodType {
|
|
|
894
1441
|
}
|
|
895
1442
|
return this._addCheck({
|
|
896
1443
|
kind: "time",
|
|
897
|
-
precision: typeof options
|
|
898
|
-
...errorUtil.errToObj(options
|
|
1444
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1445
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
899
1446
|
});
|
|
900
1447
|
}
|
|
901
1448
|
duration(message) {
|
|
@@ -912,8 +1459,8 @@ class ZodString extends ZodType {
|
|
|
912
1459
|
return this._addCheck({
|
|
913
1460
|
kind: "includes",
|
|
914
1461
|
value: value,
|
|
915
|
-
position: options
|
|
916
|
-
...errorUtil.errToObj(options
|
|
1462
|
+
position: options === null || options === void 0 ? void 0 : options.position,
|
|
1463
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
917
1464
|
});
|
|
918
1465
|
}
|
|
919
1466
|
startsWith(value, message) {
|
|
@@ -1046,10 +1593,11 @@ class ZodString extends ZodType {
|
|
|
1046
1593
|
}
|
|
1047
1594
|
}
|
|
1048
1595
|
ZodString.create = (params) => {
|
|
1596
|
+
var _a;
|
|
1049
1597
|
return new ZodString({
|
|
1050
1598
|
checks: [],
|
|
1051
1599
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1052
|
-
coerce: params
|
|
1600
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1053
1601
|
...processCreateParams(params),
|
|
1054
1602
|
});
|
|
1055
1603
|
};
|
|
@@ -1058,9 +1606,9 @@ function floatSafeRemainder(val, step) {
|
|
|
1058
1606
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1059
1607
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1060
1608
|
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1061
|
-
const valInt =
|
|
1062
|
-
const stepInt =
|
|
1063
|
-
return (valInt % stepInt) / 10
|
|
1609
|
+
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1610
|
+
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1611
|
+
return (valInt % stepInt) / Math.pow(10, decCount);
|
|
1064
1612
|
}
|
|
1065
1613
|
class ZodNumber extends ZodType {
|
|
1066
1614
|
constructor() {
|
|
@@ -1099,7 +1647,9 @@ class ZodNumber extends ZodType {
|
|
|
1099
1647
|
}
|
|
1100
1648
|
}
|
|
1101
1649
|
else if (check.kind === "min") {
|
|
1102
|
-
const tooSmall = check.inclusive
|
|
1650
|
+
const tooSmall = check.inclusive
|
|
1651
|
+
? input.data < check.value
|
|
1652
|
+
: input.data <= check.value;
|
|
1103
1653
|
if (tooSmall) {
|
|
1104
1654
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1105
1655
|
addIssueToContext(ctx, {
|
|
@@ -1114,7 +1664,9 @@ class ZodNumber extends ZodType {
|
|
|
1114
1664
|
}
|
|
1115
1665
|
}
|
|
1116
1666
|
else if (check.kind === "max") {
|
|
1117
|
-
const tooBig = check.inclusive
|
|
1667
|
+
const tooBig = check.inclusive
|
|
1668
|
+
? input.data > check.value
|
|
1669
|
+
: input.data >= check.value;
|
|
1118
1670
|
if (tooBig) {
|
|
1119
1671
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1120
1672
|
addIssueToContext(ctx, {
|
|
@@ -1272,13 +1824,15 @@ class ZodNumber extends ZodType {
|
|
|
1272
1824
|
return max;
|
|
1273
1825
|
}
|
|
1274
1826
|
get isInt() {
|
|
1275
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" ||
|
|
1827
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" ||
|
|
1828
|
+
(ch.kind === "multipleOf" && util.isInteger(ch.value)));
|
|
1276
1829
|
}
|
|
1277
1830
|
get isFinite() {
|
|
1278
|
-
let max = null;
|
|
1279
|
-
let min = null;
|
|
1831
|
+
let max = null, min = null;
|
|
1280
1832
|
for (const ch of this._def.checks) {
|
|
1281
|
-
if (ch.kind === "finite" ||
|
|
1833
|
+
if (ch.kind === "finite" ||
|
|
1834
|
+
ch.kind === "int" ||
|
|
1835
|
+
ch.kind === "multipleOf") {
|
|
1282
1836
|
return true;
|
|
1283
1837
|
}
|
|
1284
1838
|
else if (ch.kind === "min") {
|
|
@@ -1297,7 +1851,7 @@ ZodNumber.create = (params) => {
|
|
|
1297
1851
|
return new ZodNumber({
|
|
1298
1852
|
checks: [],
|
|
1299
1853
|
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1300
|
-
coerce: params
|
|
1854
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1301
1855
|
...processCreateParams(params),
|
|
1302
1856
|
});
|
|
1303
1857
|
};
|
|
@@ -1312,7 +1866,7 @@ class ZodBigInt extends ZodType {
|
|
|
1312
1866
|
try {
|
|
1313
1867
|
input.data = BigInt(input.data);
|
|
1314
1868
|
}
|
|
1315
|
-
catch {
|
|
1869
|
+
catch (_a) {
|
|
1316
1870
|
return this._getInvalidInput(input);
|
|
1317
1871
|
}
|
|
1318
1872
|
}
|
|
@@ -1324,7 +1878,9 @@ class ZodBigInt extends ZodType {
|
|
|
1324
1878
|
const status = new ParseStatus();
|
|
1325
1879
|
for (const check of this._def.checks) {
|
|
1326
1880
|
if (check.kind === "min") {
|
|
1327
|
-
const tooSmall = check.inclusive
|
|
1881
|
+
const tooSmall = check.inclusive
|
|
1882
|
+
? input.data < check.value
|
|
1883
|
+
: input.data <= check.value;
|
|
1328
1884
|
if (tooSmall) {
|
|
1329
1885
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1330
1886
|
addIssueToContext(ctx, {
|
|
@@ -1338,7 +1894,9 @@ class ZodBigInt extends ZodType {
|
|
|
1338
1894
|
}
|
|
1339
1895
|
}
|
|
1340
1896
|
else if (check.kind === "max") {
|
|
1341
|
-
const tooBig = check.inclusive
|
|
1897
|
+
const tooBig = check.inclusive
|
|
1898
|
+
? input.data > check.value
|
|
1899
|
+
: input.data >= check.value;
|
|
1342
1900
|
if (tooBig) {
|
|
1343
1901
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1344
1902
|
addIssueToContext(ctx, {
|
|
@@ -1470,10 +2028,11 @@ class ZodBigInt extends ZodType {
|
|
|
1470
2028
|
}
|
|
1471
2029
|
}
|
|
1472
2030
|
ZodBigInt.create = (params) => {
|
|
2031
|
+
var _a;
|
|
1473
2032
|
return new ZodBigInt({
|
|
1474
2033
|
checks: [],
|
|
1475
2034
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1476
|
-
coerce: params
|
|
2035
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1477
2036
|
...processCreateParams(params),
|
|
1478
2037
|
});
|
|
1479
2038
|
};
|
|
@@ -1498,7 +2057,7 @@ class ZodBoolean extends ZodType {
|
|
|
1498
2057
|
ZodBoolean.create = (params) => {
|
|
1499
2058
|
return new ZodBoolean({
|
|
1500
2059
|
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1501
|
-
coerce: params
|
|
2060
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1502
2061
|
...processCreateParams(params),
|
|
1503
2062
|
});
|
|
1504
2063
|
};
|
|
@@ -1517,7 +2076,7 @@ class ZodDate extends ZodType {
|
|
|
1517
2076
|
});
|
|
1518
2077
|
return INVALID;
|
|
1519
2078
|
}
|
|
1520
|
-
if (
|
|
2079
|
+
if (isNaN(input.data.getTime())) {
|
|
1521
2080
|
const ctx = this._getOrReturnCtx(input);
|
|
1522
2081
|
addIssueToContext(ctx, {
|
|
1523
2082
|
code: ZodIssueCode.invalid_date,
|
|
@@ -1608,7 +2167,7 @@ class ZodDate extends ZodType {
|
|
|
1608
2167
|
ZodDate.create = (params) => {
|
|
1609
2168
|
return new ZodDate({
|
|
1610
2169
|
checks: [],
|
|
1611
|
-
coerce: params
|
|
2170
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1612
2171
|
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1613
2172
|
...processCreateParams(params),
|
|
1614
2173
|
});
|
|
@@ -1930,8 +2489,7 @@ class ZodObject extends ZodType {
|
|
|
1930
2489
|
return this._cached;
|
|
1931
2490
|
const shape = this._def.shape();
|
|
1932
2491
|
const keys = util.objectKeys(shape);
|
|
1933
|
-
this._cached = { shape, keys };
|
|
1934
|
-
return this._cached;
|
|
2492
|
+
return (this._cached = { shape, keys });
|
|
1935
2493
|
}
|
|
1936
2494
|
_parse(input) {
|
|
1937
2495
|
const parsedType = this._getType(input);
|
|
@@ -1947,7 +2505,8 @@ class ZodObject extends ZodType {
|
|
|
1947
2505
|
const { status, ctx } = this._processInputParams(input);
|
|
1948
2506
|
const { shape, keys: shapeKeys } = this._getCached();
|
|
1949
2507
|
const extraKeys = [];
|
|
1950
|
-
if (!(this._def.catchall instanceof ZodNever &&
|
|
2508
|
+
if (!(this._def.catchall instanceof ZodNever &&
|
|
2509
|
+
this._def.unknownKeys === "strip")) {
|
|
1951
2510
|
for (const key in ctx.data) {
|
|
1952
2511
|
if (!shapeKeys.includes(key)) {
|
|
1953
2512
|
extraKeys.push(key);
|
|
@@ -2035,10 +2594,11 @@ class ZodObject extends ZodType {
|
|
|
2035
2594
|
...(message !== undefined
|
|
2036
2595
|
? {
|
|
2037
2596
|
errorMap: (issue, ctx) => {
|
|
2038
|
-
|
|
2597
|
+
var _a, _b, _c, _d;
|
|
2598
|
+
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
2039
2599
|
if (issue.code === "unrecognized_keys")
|
|
2040
2600
|
return {
|
|
2041
|
-
message: errorUtil.errToObj(message).message
|
|
2601
|
+
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
|
|
2042
2602
|
};
|
|
2043
2603
|
return {
|
|
2044
2604
|
message: defaultError,
|
|
@@ -2170,11 +2730,11 @@ class ZodObject extends ZodType {
|
|
|
2170
2730
|
}
|
|
2171
2731
|
pick(mask) {
|
|
2172
2732
|
const shape = {};
|
|
2173
|
-
|
|
2733
|
+
util.objectKeys(mask).forEach((key) => {
|
|
2174
2734
|
if (mask[key] && this.shape[key]) {
|
|
2175
2735
|
shape[key] = this.shape[key];
|
|
2176
2736
|
}
|
|
2177
|
-
}
|
|
2737
|
+
});
|
|
2178
2738
|
return new ZodObject({
|
|
2179
2739
|
...this._def,
|
|
2180
2740
|
shape: () => shape,
|
|
@@ -2182,11 +2742,11 @@ class ZodObject extends ZodType {
|
|
|
2182
2742
|
}
|
|
2183
2743
|
omit(mask) {
|
|
2184
2744
|
const shape = {};
|
|
2185
|
-
|
|
2745
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2186
2746
|
if (!mask[key]) {
|
|
2187
2747
|
shape[key] = this.shape[key];
|
|
2188
2748
|
}
|
|
2189
|
-
}
|
|
2749
|
+
});
|
|
2190
2750
|
return new ZodObject({
|
|
2191
2751
|
...this._def,
|
|
2192
2752
|
shape: () => shape,
|
|
@@ -2200,7 +2760,7 @@ class ZodObject extends ZodType {
|
|
|
2200
2760
|
}
|
|
2201
2761
|
partial(mask) {
|
|
2202
2762
|
const newShape = {};
|
|
2203
|
-
|
|
2763
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2204
2764
|
const fieldSchema = this.shape[key];
|
|
2205
2765
|
if (mask && !mask[key]) {
|
|
2206
2766
|
newShape[key] = fieldSchema;
|
|
@@ -2208,7 +2768,7 @@ class ZodObject extends ZodType {
|
|
|
2208
2768
|
else {
|
|
2209
2769
|
newShape[key] = fieldSchema.optional();
|
|
2210
2770
|
}
|
|
2211
|
-
}
|
|
2771
|
+
});
|
|
2212
2772
|
return new ZodObject({
|
|
2213
2773
|
...this._def,
|
|
2214
2774
|
shape: () => newShape,
|
|
@@ -2216,7 +2776,7 @@ class ZodObject extends ZodType {
|
|
|
2216
2776
|
}
|
|
2217
2777
|
required(mask) {
|
|
2218
2778
|
const newShape = {};
|
|
2219
|
-
|
|
2779
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2220
2780
|
if (mask && !mask[key]) {
|
|
2221
2781
|
newShape[key] = this.shape[key];
|
|
2222
2782
|
}
|
|
@@ -2228,7 +2788,7 @@ class ZodObject extends ZodType {
|
|
|
2228
2788
|
}
|
|
2229
2789
|
newShape[key] = newField;
|
|
2230
2790
|
}
|
|
2231
|
-
}
|
|
2791
|
+
});
|
|
2232
2792
|
return new ZodObject({
|
|
2233
2793
|
...this._def,
|
|
2234
2794
|
shape: () => newShape,
|
|
@@ -2500,7 +3060,9 @@ function mergeValues(a, b) {
|
|
|
2500
3060
|
}
|
|
2501
3061
|
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2502
3062
|
const bKeys = util.objectKeys(b);
|
|
2503
|
-
const sharedKeys = util
|
|
3063
|
+
const sharedKeys = util
|
|
3064
|
+
.objectKeys(a)
|
|
3065
|
+
.filter((key) => bKeys.indexOf(key) !== -1);
|
|
2504
3066
|
const newObj = { ...a, ...b };
|
|
2505
3067
|
for (const key of sharedKeys) {
|
|
2506
3068
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
@@ -2527,7 +3089,9 @@ function mergeValues(a, b) {
|
|
|
2527
3089
|
}
|
|
2528
3090
|
return { valid: true, data: newArray };
|
|
2529
3091
|
}
|
|
2530
|
-
else if (aType === ZodParsedType.date &&
|
|
3092
|
+
else if (aType === ZodParsedType.date &&
|
|
3093
|
+
bType === ZodParsedType.date &&
|
|
3094
|
+
+a === +b) {
|
|
2531
3095
|
return { valid: true, data: a };
|
|
2532
3096
|
}
|
|
2533
3097
|
else {
|
|
@@ -2588,7 +3152,6 @@ ZodIntersection.create = (left, right, params) => {
|
|
|
2588
3152
|
...processCreateParams(params),
|
|
2589
3153
|
});
|
|
2590
3154
|
};
|
|
2591
|
-
// type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
|
|
2592
3155
|
class ZodTuple extends ZodType {
|
|
2593
3156
|
_parse(input) {
|
|
2594
3157
|
const { status, ctx } = this._processInputParams(input);
|
|
@@ -2885,7 +3448,12 @@ class ZodFunction extends ZodType {
|
|
|
2885
3448
|
return makeIssue({
|
|
2886
3449
|
data: args,
|
|
2887
3450
|
path: ctx.path,
|
|
2888
|
-
errorMaps: [
|
|
3451
|
+
errorMaps: [
|
|
3452
|
+
ctx.common.contextualErrorMap,
|
|
3453
|
+
ctx.schemaErrorMap,
|
|
3454
|
+
getErrorMap(),
|
|
3455
|
+
errorMap,
|
|
3456
|
+
].filter((x) => !!x),
|
|
2889
3457
|
issueData: {
|
|
2890
3458
|
code: ZodIssueCode.invalid_arguments,
|
|
2891
3459
|
argumentsError: error,
|
|
@@ -2896,7 +3464,12 @@ class ZodFunction extends ZodType {
|
|
|
2896
3464
|
return makeIssue({
|
|
2897
3465
|
data: returns,
|
|
2898
3466
|
path: ctx.path,
|
|
2899
|
-
errorMaps: [
|
|
3467
|
+
errorMaps: [
|
|
3468
|
+
ctx.common.contextualErrorMap,
|
|
3469
|
+
ctx.schemaErrorMap,
|
|
3470
|
+
getErrorMap(),
|
|
3471
|
+
errorMap,
|
|
3472
|
+
].filter((x) => !!x),
|
|
2900
3473
|
issueData: {
|
|
2901
3474
|
code: ZodIssueCode.invalid_return_type,
|
|
2902
3475
|
returnTypeError: error,
|
|
@@ -2912,7 +3485,9 @@ class ZodFunction extends ZodType {
|
|
|
2912
3485
|
const me = this;
|
|
2913
3486
|
return OK(async function (...args) {
|
|
2914
3487
|
const error = new ZodError([]);
|
|
2915
|
-
const parsedArgs = await me._def.args
|
|
3488
|
+
const parsedArgs = await me._def.args
|
|
3489
|
+
.parseAsync(args, params)
|
|
3490
|
+
.catch((e) => {
|
|
2916
3491
|
error.addIssue(makeArgsIssue(args, e));
|
|
2917
3492
|
throw error;
|
|
2918
3493
|
});
|
|
@@ -2973,7 +3548,9 @@ class ZodFunction extends ZodType {
|
|
|
2973
3548
|
}
|
|
2974
3549
|
static create(args, returns, params) {
|
|
2975
3550
|
return new ZodFunction({
|
|
2976
|
-
args: (args
|
|
3551
|
+
args: (args
|
|
3552
|
+
? args
|
|
3553
|
+
: ZodTuple.create([]).rest(ZodUnknown.create())),
|
|
2977
3554
|
returns: returns || ZodUnknown.create(),
|
|
2978
3555
|
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
2979
3556
|
...processCreateParams(params),
|
|
@@ -3029,6 +3606,10 @@ function createZodEnum(values, params) {
|
|
|
3029
3606
|
});
|
|
3030
3607
|
}
|
|
3031
3608
|
class ZodEnum extends ZodType {
|
|
3609
|
+
constructor() {
|
|
3610
|
+
super(...arguments);
|
|
3611
|
+
_ZodEnum_cache.set(this, void 0);
|
|
3612
|
+
}
|
|
3032
3613
|
_parse(input) {
|
|
3033
3614
|
if (typeof input.data !== "string") {
|
|
3034
3615
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3040,10 +3621,10 @@ class ZodEnum extends ZodType {
|
|
|
3040
3621
|
});
|
|
3041
3622
|
return INVALID;
|
|
3042
3623
|
}
|
|
3043
|
-
if (!this
|
|
3044
|
-
this
|
|
3624
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache)) {
|
|
3625
|
+
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values));
|
|
3045
3626
|
}
|
|
3046
|
-
if (!this.
|
|
3627
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache).has(input.data)) {
|
|
3047
3628
|
const ctx = this._getOrReturnCtx(input);
|
|
3048
3629
|
const expectedValues = this._def.values;
|
|
3049
3630
|
addIssueToContext(ctx, {
|
|
@@ -3092,12 +3673,18 @@ class ZodEnum extends ZodType {
|
|
|
3092
3673
|
});
|
|
3093
3674
|
}
|
|
3094
3675
|
}
|
|
3676
|
+
_ZodEnum_cache = new WeakMap();
|
|
3095
3677
|
ZodEnum.create = createZodEnum;
|
|
3096
3678
|
class ZodNativeEnum extends ZodType {
|
|
3679
|
+
constructor() {
|
|
3680
|
+
super(...arguments);
|
|
3681
|
+
_ZodNativeEnum_cache.set(this, void 0);
|
|
3682
|
+
}
|
|
3097
3683
|
_parse(input) {
|
|
3098
3684
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3099
3685
|
const ctx = this._getOrReturnCtx(input);
|
|
3100
|
-
if (ctx.parsedType !== ZodParsedType.string &&
|
|
3686
|
+
if (ctx.parsedType !== ZodParsedType.string &&
|
|
3687
|
+
ctx.parsedType !== ZodParsedType.number) {
|
|
3101
3688
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3102
3689
|
addIssueToContext(ctx, {
|
|
3103
3690
|
expected: util.joinValues(expectedValues),
|
|
@@ -3106,10 +3693,10 @@ class ZodNativeEnum extends ZodType {
|
|
|
3106
3693
|
});
|
|
3107
3694
|
return INVALID;
|
|
3108
3695
|
}
|
|
3109
|
-
if (!this
|
|
3110
|
-
this
|
|
3696
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
|
|
3697
|
+
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)));
|
|
3111
3698
|
}
|
|
3112
|
-
if (!this.
|
|
3699
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
|
|
3113
3700
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3114
3701
|
addIssueToContext(ctx, {
|
|
3115
3702
|
received: ctx.data,
|
|
@@ -3124,6 +3711,7 @@ class ZodNativeEnum extends ZodType {
|
|
|
3124
3711
|
return this._def.values;
|
|
3125
3712
|
}
|
|
3126
3713
|
}
|
|
3714
|
+
_ZodNativeEnum_cache = new WeakMap();
|
|
3127
3715
|
ZodNativeEnum.create = (values, params) => {
|
|
3128
3716
|
return new ZodNativeEnum({
|
|
3129
3717
|
values: values,
|
|
@@ -3137,7 +3725,8 @@ class ZodPromise extends ZodType {
|
|
|
3137
3725
|
}
|
|
3138
3726
|
_parse(input) {
|
|
3139
3727
|
const { ctx } = this._processInputParams(input);
|
|
3140
|
-
if (ctx.parsedType !== ZodParsedType.promise &&
|
|
3728
|
+
if (ctx.parsedType !== ZodParsedType.promise &&
|
|
3729
|
+
ctx.common.async === false) {
|
|
3141
3730
|
addIssueToContext(ctx, {
|
|
3142
3731
|
code: ZodIssueCode.invalid_type,
|
|
3143
3732
|
expected: ZodParsedType.promise,
|
|
@@ -3145,7 +3734,9 @@ class ZodPromise extends ZodType {
|
|
|
3145
3734
|
});
|
|
3146
3735
|
return INVALID;
|
|
3147
3736
|
}
|
|
3148
|
-
const promisified = ctx.parsedType === ZodParsedType.promise
|
|
3737
|
+
const promisified = ctx.parsedType === ZodParsedType.promise
|
|
3738
|
+
? ctx.data
|
|
3739
|
+
: Promise.resolve(ctx.data);
|
|
3149
3740
|
return OK(promisified.then((data) => {
|
|
3150
3741
|
return this._def.type.parseAsync(data, {
|
|
3151
3742
|
path: ctx.path,
|
|
@@ -3251,7 +3842,9 @@ class ZodEffects extends ZodType {
|
|
|
3251
3842
|
return { status: status.value, value: inner.value };
|
|
3252
3843
|
}
|
|
3253
3844
|
else {
|
|
3254
|
-
return this._def.schema
|
|
3845
|
+
return this._def.schema
|
|
3846
|
+
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
3847
|
+
.then((inner) => {
|
|
3255
3848
|
if (inner.status === "aborted")
|
|
3256
3849
|
return INVALID;
|
|
3257
3850
|
if (inner.status === "dirty")
|
|
@@ -3270,7 +3863,7 @@ class ZodEffects extends ZodType {
|
|
|
3270
3863
|
parent: ctx,
|
|
3271
3864
|
});
|
|
3272
3865
|
if (!isValid(base))
|
|
3273
|
-
return
|
|
3866
|
+
return base;
|
|
3274
3867
|
const result = effect.transform(base.value, checkCtx);
|
|
3275
3868
|
if (result instanceof Promise) {
|
|
3276
3869
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
@@ -3278,13 +3871,12 @@ class ZodEffects extends ZodType {
|
|
|
3278
3871
|
return { status: status.value, value: result };
|
|
3279
3872
|
}
|
|
3280
3873
|
else {
|
|
3281
|
-
return this._def.schema
|
|
3874
|
+
return this._def.schema
|
|
3875
|
+
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
3876
|
+
.then((base) => {
|
|
3282
3877
|
if (!isValid(base))
|
|
3283
|
-
return
|
|
3284
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3285
|
-
status: status.value,
|
|
3286
|
-
value: result,
|
|
3287
|
-
}));
|
|
3878
|
+
return base;
|
|
3879
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
|
|
3288
3880
|
});
|
|
3289
3881
|
}
|
|
3290
3882
|
}
|
|
@@ -3366,7 +3958,9 @@ ZodDefault.create = (type, params) => {
|
|
|
3366
3958
|
return new ZodDefault({
|
|
3367
3959
|
innerType: type,
|
|
3368
3960
|
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3369
|
-
defaultValue: typeof params.default === "function"
|
|
3961
|
+
defaultValue: typeof params.default === "function"
|
|
3962
|
+
? params.default
|
|
3963
|
+
: () => params.default,
|
|
3370
3964
|
...processCreateParams(params),
|
|
3371
3965
|
});
|
|
3372
3966
|
};
|
|
@@ -3532,7 +4126,9 @@ class ZodReadonly extends ZodType {
|
|
|
3532
4126
|
}
|
|
3533
4127
|
return data;
|
|
3534
4128
|
};
|
|
3535
|
-
return isAsync(result)
|
|
4129
|
+
return isAsync(result)
|
|
4130
|
+
? result.then((data) => freeze(data))
|
|
4131
|
+
: freeze(result);
|
|
3536
4132
|
}
|
|
3537
4133
|
unwrap() {
|
|
3538
4134
|
return this._def.innerType;
|
|
@@ -3553,7 +4149,11 @@ ZodReadonly.create = (type, params) => {
|
|
|
3553
4149
|
////////////////////////////////////////
|
|
3554
4150
|
////////////////////////////////////////
|
|
3555
4151
|
function cleanParams(params, data) {
|
|
3556
|
-
const p = typeof params === "function"
|
|
4152
|
+
const p = typeof params === "function"
|
|
4153
|
+
? params(data)
|
|
4154
|
+
: typeof params === "string"
|
|
4155
|
+
? { message: params }
|
|
4156
|
+
: params;
|
|
3557
4157
|
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3558
4158
|
return p2;
|
|
3559
4159
|
}
|
|
@@ -3571,19 +4171,21 @@ function custom(check, _params = {},
|
|
|
3571
4171
|
fatal) {
|
|
3572
4172
|
if (check)
|
|
3573
4173
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4174
|
+
var _a, _b;
|
|
3574
4175
|
const r = check(data);
|
|
3575
4176
|
if (r instanceof Promise) {
|
|
3576
4177
|
return r.then((r) => {
|
|
4178
|
+
var _a, _b;
|
|
3577
4179
|
if (!r) {
|
|
3578
4180
|
const params = cleanParams(_params, data);
|
|
3579
|
-
const _fatal = params.fatal
|
|
4181
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3580
4182
|
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3581
4183
|
}
|
|
3582
4184
|
});
|
|
3583
4185
|
}
|
|
3584
4186
|
if (!r) {
|
|
3585
4187
|
const params = cleanParams(_params, data);
|
|
3586
|
-
const _fatal = params.fatal
|
|
4188
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3587
4189
|
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3588
4190
|
}
|
|
3589
4191
|
return;
|
|
@@ -3686,5 +4288,116 @@ const coerce = {
|
|
|
3686
4288
|
};
|
|
3687
4289
|
const NEVER = INVALID;
|
|
3688
4290
|
|
|
3689
|
-
|
|
3690
|
-
|
|
4291
|
+
var z = /*#__PURE__*/Object.freeze({
|
|
4292
|
+
__proto__: null,
|
|
4293
|
+
defaultErrorMap: errorMap,
|
|
4294
|
+
setErrorMap: setErrorMap,
|
|
4295
|
+
getErrorMap: getErrorMap,
|
|
4296
|
+
makeIssue: makeIssue,
|
|
4297
|
+
EMPTY_PATH: EMPTY_PATH,
|
|
4298
|
+
addIssueToContext: addIssueToContext,
|
|
4299
|
+
ParseStatus: ParseStatus,
|
|
4300
|
+
INVALID: INVALID,
|
|
4301
|
+
DIRTY: DIRTY,
|
|
4302
|
+
OK: OK,
|
|
4303
|
+
isAborted: isAborted,
|
|
4304
|
+
isDirty: isDirty,
|
|
4305
|
+
isValid: isValid,
|
|
4306
|
+
isAsync: isAsync,
|
|
4307
|
+
get util () { return util; },
|
|
4308
|
+
get objectUtil () { return objectUtil; },
|
|
4309
|
+
ZodParsedType: ZodParsedType,
|
|
4310
|
+
getParsedType: getParsedType,
|
|
4311
|
+
ZodType: ZodType,
|
|
4312
|
+
datetimeRegex: datetimeRegex,
|
|
4313
|
+
ZodString: ZodString,
|
|
4314
|
+
ZodNumber: ZodNumber,
|
|
4315
|
+
ZodBigInt: ZodBigInt,
|
|
4316
|
+
ZodBoolean: ZodBoolean,
|
|
4317
|
+
ZodDate: ZodDate,
|
|
4318
|
+
ZodSymbol: ZodSymbol,
|
|
4319
|
+
ZodUndefined: ZodUndefined,
|
|
4320
|
+
ZodNull: ZodNull,
|
|
4321
|
+
ZodAny: ZodAny,
|
|
4322
|
+
ZodUnknown: ZodUnknown,
|
|
4323
|
+
ZodNever: ZodNever,
|
|
4324
|
+
ZodVoid: ZodVoid,
|
|
4325
|
+
ZodArray: ZodArray,
|
|
4326
|
+
ZodObject: ZodObject,
|
|
4327
|
+
ZodUnion: ZodUnion,
|
|
4328
|
+
ZodDiscriminatedUnion: ZodDiscriminatedUnion,
|
|
4329
|
+
ZodIntersection: ZodIntersection,
|
|
4330
|
+
ZodTuple: ZodTuple,
|
|
4331
|
+
ZodRecord: ZodRecord,
|
|
4332
|
+
ZodMap: ZodMap,
|
|
4333
|
+
ZodSet: ZodSet,
|
|
4334
|
+
ZodFunction: ZodFunction,
|
|
4335
|
+
ZodLazy: ZodLazy,
|
|
4336
|
+
ZodLiteral: ZodLiteral,
|
|
4337
|
+
ZodEnum: ZodEnum,
|
|
4338
|
+
ZodNativeEnum: ZodNativeEnum,
|
|
4339
|
+
ZodPromise: ZodPromise,
|
|
4340
|
+
ZodEffects: ZodEffects,
|
|
4341
|
+
ZodTransformer: ZodEffects,
|
|
4342
|
+
ZodOptional: ZodOptional,
|
|
4343
|
+
ZodNullable: ZodNullable,
|
|
4344
|
+
ZodDefault: ZodDefault,
|
|
4345
|
+
ZodCatch: ZodCatch,
|
|
4346
|
+
ZodNaN: ZodNaN,
|
|
4347
|
+
BRAND: BRAND,
|
|
4348
|
+
ZodBranded: ZodBranded,
|
|
4349
|
+
ZodPipeline: ZodPipeline,
|
|
4350
|
+
ZodReadonly: ZodReadonly,
|
|
4351
|
+
custom: custom,
|
|
4352
|
+
Schema: ZodType,
|
|
4353
|
+
ZodSchema: ZodType,
|
|
4354
|
+
late: late,
|
|
4355
|
+
get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
|
|
4356
|
+
coerce: coerce,
|
|
4357
|
+
any: anyType,
|
|
4358
|
+
array: arrayType,
|
|
4359
|
+
bigint: bigIntType,
|
|
4360
|
+
boolean: booleanType,
|
|
4361
|
+
date: dateType,
|
|
4362
|
+
discriminatedUnion: discriminatedUnionType,
|
|
4363
|
+
effect: effectsType,
|
|
4364
|
+
'enum': enumType,
|
|
4365
|
+
'function': functionType,
|
|
4366
|
+
'instanceof': instanceOfType,
|
|
4367
|
+
intersection: intersectionType,
|
|
4368
|
+
lazy: lazyType,
|
|
4369
|
+
literal: literalType,
|
|
4370
|
+
map: mapType,
|
|
4371
|
+
nan: nanType,
|
|
4372
|
+
nativeEnum: nativeEnumType,
|
|
4373
|
+
never: neverType,
|
|
4374
|
+
'null': nullType,
|
|
4375
|
+
nullable: nullableType,
|
|
4376
|
+
number: numberType,
|
|
4377
|
+
object: objectType,
|
|
4378
|
+
oboolean: oboolean,
|
|
4379
|
+
onumber: onumber,
|
|
4380
|
+
optional: optionalType,
|
|
4381
|
+
ostring: ostring,
|
|
4382
|
+
pipeline: pipelineType,
|
|
4383
|
+
preprocess: preprocessType,
|
|
4384
|
+
promise: promiseType,
|
|
4385
|
+
record: recordType,
|
|
4386
|
+
set: setType,
|
|
4387
|
+
strictObject: strictObjectType,
|
|
4388
|
+
string: stringType,
|
|
4389
|
+
symbol: symbolType,
|
|
4390
|
+
transformer: effectsType,
|
|
4391
|
+
tuple: tupleType,
|
|
4392
|
+
'undefined': undefinedType,
|
|
4393
|
+
union: unionType,
|
|
4394
|
+
unknown: unknownType,
|
|
4395
|
+
'void': voidType,
|
|
4396
|
+
NEVER: NEVER,
|
|
4397
|
+
ZodIssueCode: ZodIssueCode,
|
|
4398
|
+
quotelessJson: quotelessJson,
|
|
4399
|
+
ZodError: ZodError
|
|
4400
|
+
});
|
|
4401
|
+
|
|
4402
|
+
export { BRAND, DIRTY, EMPTY_PATH, INVALID, NEVER, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodBranded, ZodCatch, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPipeline, ZodPromise, ZodReadonly, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodSymbol, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, coerce, custom, dateType as date, datetimeRegex, z as default, errorMap as defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getErrorMap, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, pipelineType as pipeline, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, symbolType as symbol, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, util, voidType as void, z };
|
|
4403
|
+
//# sourceMappingURL=index.js.map
|