@mastra/observability 0.0.0-feat-add-query-option-to-playground-20251209160219 → 0.0.0-feat-mcp-embedded-docs-tools-clean-20260102135536
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/CHANGELOG.md +312 -11
- package/dist/config.d.ts +105 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/exporters/default.d.ts +4 -3
- package/dist/exporters/default.d.ts.map +1 -1
- package/dist/index.cjs +4410 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4406 -145
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/model-tracing.d.ts +16 -3
- package/dist/model-tracing.d.ts.map +1 -1
- package/dist/span_processors/sensitive-data-filter.d.ts.map +1 -1
- package/dist/spans/base.d.ts +10 -18
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/spans/default.d.ts.map +1 -1
- package/dist/spans/index.d.ts +1 -0
- package/dist/spans/index.d.ts.map +1 -1
- package/dist/spans/serialization.d.ts +46 -0
- package/dist/spans/serialization.d.ts.map +1 -0
- package/dist/usage.d.ts +21 -0
- package/dist/usage.d.ts.map +1 -0
- package/package.json +8 -11
package/dist/index.js
CHANGED
|
@@ -1,12 +1,4056 @@
|
|
|
1
1
|
import { MastraBase } from '@mastra/core/base';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
3
|
import { ConsoleLogger, LogLevel, RegisteredLogger } from '@mastra/core/logger';
|
|
4
|
-
import { z } from 'zod';
|
|
5
4
|
import { TracingEventType, SpanType, InternalSpans } from '@mastra/core/observability';
|
|
6
5
|
import { fetchWithRetry, getNestedValue, setNestedValue } from '@mastra/core/utils';
|
|
7
6
|
import { TransformStream } from 'stream/web';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
15
|
+
var external_exports = {};
|
|
16
|
+
__export(external_exports, {
|
|
17
|
+
BRAND: () => BRAND,
|
|
18
|
+
DIRTY: () => DIRTY,
|
|
19
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
20
|
+
INVALID: () => INVALID,
|
|
21
|
+
NEVER: () => NEVER,
|
|
22
|
+
OK: () => OK,
|
|
23
|
+
ParseStatus: () => ParseStatus,
|
|
24
|
+
Schema: () => ZodType,
|
|
25
|
+
ZodAny: () => ZodAny,
|
|
26
|
+
ZodArray: () => ZodArray,
|
|
27
|
+
ZodBigInt: () => ZodBigInt,
|
|
28
|
+
ZodBoolean: () => ZodBoolean,
|
|
29
|
+
ZodBranded: () => ZodBranded,
|
|
30
|
+
ZodCatch: () => ZodCatch,
|
|
31
|
+
ZodDate: () => ZodDate,
|
|
32
|
+
ZodDefault: () => ZodDefault,
|
|
33
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
34
|
+
ZodEffects: () => ZodEffects,
|
|
35
|
+
ZodEnum: () => ZodEnum,
|
|
36
|
+
ZodError: () => ZodError,
|
|
37
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
38
|
+
ZodFunction: () => ZodFunction,
|
|
39
|
+
ZodIntersection: () => ZodIntersection,
|
|
40
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
41
|
+
ZodLazy: () => ZodLazy,
|
|
42
|
+
ZodLiteral: () => ZodLiteral,
|
|
43
|
+
ZodMap: () => ZodMap,
|
|
44
|
+
ZodNaN: () => ZodNaN,
|
|
45
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
46
|
+
ZodNever: () => ZodNever,
|
|
47
|
+
ZodNull: () => ZodNull,
|
|
48
|
+
ZodNullable: () => ZodNullable,
|
|
49
|
+
ZodNumber: () => ZodNumber,
|
|
50
|
+
ZodObject: () => ZodObject,
|
|
51
|
+
ZodOptional: () => ZodOptional,
|
|
52
|
+
ZodParsedType: () => ZodParsedType,
|
|
53
|
+
ZodPipeline: () => ZodPipeline,
|
|
54
|
+
ZodPromise: () => ZodPromise,
|
|
55
|
+
ZodReadonly: () => ZodReadonly,
|
|
56
|
+
ZodRecord: () => ZodRecord,
|
|
57
|
+
ZodSchema: () => ZodType,
|
|
58
|
+
ZodSet: () => ZodSet,
|
|
59
|
+
ZodString: () => ZodString,
|
|
60
|
+
ZodSymbol: () => ZodSymbol,
|
|
61
|
+
ZodTransformer: () => ZodEffects,
|
|
62
|
+
ZodTuple: () => ZodTuple,
|
|
63
|
+
ZodType: () => ZodType,
|
|
64
|
+
ZodUndefined: () => ZodUndefined,
|
|
65
|
+
ZodUnion: () => ZodUnion,
|
|
66
|
+
ZodUnknown: () => ZodUnknown,
|
|
67
|
+
ZodVoid: () => ZodVoid,
|
|
68
|
+
addIssueToContext: () => addIssueToContext,
|
|
69
|
+
any: () => anyType,
|
|
70
|
+
array: () => arrayType,
|
|
71
|
+
bigint: () => bigIntType,
|
|
72
|
+
boolean: () => booleanType,
|
|
73
|
+
coerce: () => coerce,
|
|
74
|
+
custom: () => custom,
|
|
75
|
+
date: () => dateType,
|
|
76
|
+
datetimeRegex: () => datetimeRegex,
|
|
77
|
+
defaultErrorMap: () => en_default,
|
|
78
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
79
|
+
effect: () => effectsType,
|
|
80
|
+
enum: () => enumType,
|
|
81
|
+
function: () => functionType,
|
|
82
|
+
getErrorMap: () => getErrorMap,
|
|
83
|
+
getParsedType: () => getParsedType,
|
|
84
|
+
instanceof: () => instanceOfType,
|
|
85
|
+
intersection: () => intersectionType,
|
|
86
|
+
isAborted: () => isAborted,
|
|
87
|
+
isAsync: () => isAsync,
|
|
88
|
+
isDirty: () => isDirty,
|
|
89
|
+
isValid: () => isValid,
|
|
90
|
+
late: () => late,
|
|
91
|
+
lazy: () => lazyType,
|
|
92
|
+
literal: () => literalType,
|
|
93
|
+
makeIssue: () => makeIssue,
|
|
94
|
+
map: () => mapType,
|
|
95
|
+
nan: () => nanType,
|
|
96
|
+
nativeEnum: () => nativeEnumType,
|
|
97
|
+
never: () => neverType,
|
|
98
|
+
null: () => nullType,
|
|
99
|
+
nullable: () => nullableType,
|
|
100
|
+
number: () => numberType,
|
|
101
|
+
object: () => objectType,
|
|
102
|
+
objectUtil: () => objectUtil,
|
|
103
|
+
oboolean: () => oboolean,
|
|
104
|
+
onumber: () => onumber,
|
|
105
|
+
optional: () => optionalType,
|
|
106
|
+
ostring: () => ostring,
|
|
107
|
+
pipeline: () => pipelineType,
|
|
108
|
+
preprocess: () => preprocessType,
|
|
109
|
+
promise: () => promiseType,
|
|
110
|
+
quotelessJson: () => quotelessJson,
|
|
111
|
+
record: () => recordType,
|
|
112
|
+
set: () => setType,
|
|
113
|
+
setErrorMap: () => setErrorMap,
|
|
114
|
+
strictObject: () => strictObjectType,
|
|
115
|
+
string: () => stringType,
|
|
116
|
+
symbol: () => symbolType,
|
|
117
|
+
transformer: () => effectsType,
|
|
118
|
+
tuple: () => tupleType,
|
|
119
|
+
undefined: () => undefinedType,
|
|
120
|
+
union: () => unionType,
|
|
121
|
+
unknown: () => unknownType,
|
|
122
|
+
util: () => util,
|
|
123
|
+
void: () => voidType
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
127
|
+
var util;
|
|
128
|
+
(function(util2) {
|
|
129
|
+
util2.assertEqual = (_) => {
|
|
130
|
+
};
|
|
131
|
+
function assertIs(_arg) {
|
|
132
|
+
}
|
|
133
|
+
util2.assertIs = assertIs;
|
|
134
|
+
function assertNever(_x) {
|
|
135
|
+
throw new Error();
|
|
136
|
+
}
|
|
137
|
+
util2.assertNever = assertNever;
|
|
138
|
+
util2.arrayToEnum = (items) => {
|
|
139
|
+
const obj = {};
|
|
140
|
+
for (const item of items) {
|
|
141
|
+
obj[item] = item;
|
|
142
|
+
}
|
|
143
|
+
return obj;
|
|
144
|
+
};
|
|
145
|
+
util2.getValidEnumValues = (obj) => {
|
|
146
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
147
|
+
const filtered = {};
|
|
148
|
+
for (const k of validKeys) {
|
|
149
|
+
filtered[k] = obj[k];
|
|
150
|
+
}
|
|
151
|
+
return util2.objectValues(filtered);
|
|
152
|
+
};
|
|
153
|
+
util2.objectValues = (obj) => {
|
|
154
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
155
|
+
return obj[e];
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
159
|
+
const keys = [];
|
|
160
|
+
for (const key in object) {
|
|
161
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
162
|
+
keys.push(key);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return keys;
|
|
166
|
+
};
|
|
167
|
+
util2.find = (arr, checker) => {
|
|
168
|
+
for (const item of arr) {
|
|
169
|
+
if (checker(item))
|
|
170
|
+
return item;
|
|
171
|
+
}
|
|
172
|
+
return void 0;
|
|
173
|
+
};
|
|
174
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
175
|
+
function joinValues(array, separator = " | ") {
|
|
176
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
177
|
+
}
|
|
178
|
+
util2.joinValues = joinValues;
|
|
179
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
180
|
+
if (typeof value === "bigint") {
|
|
181
|
+
return value.toString();
|
|
182
|
+
}
|
|
183
|
+
return value;
|
|
184
|
+
};
|
|
185
|
+
})(util || (util = {}));
|
|
186
|
+
var objectUtil;
|
|
187
|
+
(function(objectUtil2) {
|
|
188
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
189
|
+
return {
|
|
190
|
+
...first,
|
|
191
|
+
...second
|
|
192
|
+
// second overwrites first
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
})(objectUtil || (objectUtil = {}));
|
|
196
|
+
var ZodParsedType = util.arrayToEnum([
|
|
197
|
+
"string",
|
|
198
|
+
"nan",
|
|
199
|
+
"number",
|
|
200
|
+
"integer",
|
|
201
|
+
"float",
|
|
202
|
+
"boolean",
|
|
203
|
+
"date",
|
|
204
|
+
"bigint",
|
|
205
|
+
"symbol",
|
|
206
|
+
"function",
|
|
207
|
+
"undefined",
|
|
208
|
+
"null",
|
|
209
|
+
"array",
|
|
210
|
+
"object",
|
|
211
|
+
"unknown",
|
|
212
|
+
"promise",
|
|
213
|
+
"void",
|
|
214
|
+
"never",
|
|
215
|
+
"map",
|
|
216
|
+
"set"
|
|
217
|
+
]);
|
|
218
|
+
var getParsedType = (data) => {
|
|
219
|
+
const t = typeof data;
|
|
220
|
+
switch (t) {
|
|
221
|
+
case "undefined":
|
|
222
|
+
return ZodParsedType.undefined;
|
|
223
|
+
case "string":
|
|
224
|
+
return ZodParsedType.string;
|
|
225
|
+
case "number":
|
|
226
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
227
|
+
case "boolean":
|
|
228
|
+
return ZodParsedType.boolean;
|
|
229
|
+
case "function":
|
|
230
|
+
return ZodParsedType.function;
|
|
231
|
+
case "bigint":
|
|
232
|
+
return ZodParsedType.bigint;
|
|
233
|
+
case "symbol":
|
|
234
|
+
return ZodParsedType.symbol;
|
|
235
|
+
case "object":
|
|
236
|
+
if (Array.isArray(data)) {
|
|
237
|
+
return ZodParsedType.array;
|
|
238
|
+
}
|
|
239
|
+
if (data === null) {
|
|
240
|
+
return ZodParsedType.null;
|
|
241
|
+
}
|
|
242
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
243
|
+
return ZodParsedType.promise;
|
|
244
|
+
}
|
|
245
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
246
|
+
return ZodParsedType.map;
|
|
247
|
+
}
|
|
248
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
249
|
+
return ZodParsedType.set;
|
|
250
|
+
}
|
|
251
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
252
|
+
return ZodParsedType.date;
|
|
253
|
+
}
|
|
254
|
+
return ZodParsedType.object;
|
|
255
|
+
default:
|
|
256
|
+
return ZodParsedType.unknown;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
261
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
262
|
+
"invalid_type",
|
|
263
|
+
"invalid_literal",
|
|
264
|
+
"custom",
|
|
265
|
+
"invalid_union",
|
|
266
|
+
"invalid_union_discriminator",
|
|
267
|
+
"invalid_enum_value",
|
|
268
|
+
"unrecognized_keys",
|
|
269
|
+
"invalid_arguments",
|
|
270
|
+
"invalid_return_type",
|
|
271
|
+
"invalid_date",
|
|
272
|
+
"invalid_string",
|
|
273
|
+
"too_small",
|
|
274
|
+
"too_big",
|
|
275
|
+
"invalid_intersection_types",
|
|
276
|
+
"not_multiple_of",
|
|
277
|
+
"not_finite"
|
|
278
|
+
]);
|
|
279
|
+
var quotelessJson = (obj) => {
|
|
280
|
+
const json = JSON.stringify(obj, null, 2);
|
|
281
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
282
|
+
};
|
|
283
|
+
var ZodError = class _ZodError extends Error {
|
|
284
|
+
get errors() {
|
|
285
|
+
return this.issues;
|
|
286
|
+
}
|
|
287
|
+
constructor(issues) {
|
|
288
|
+
super();
|
|
289
|
+
this.issues = [];
|
|
290
|
+
this.addIssue = (sub) => {
|
|
291
|
+
this.issues = [...this.issues, sub];
|
|
292
|
+
};
|
|
293
|
+
this.addIssues = (subs = []) => {
|
|
294
|
+
this.issues = [...this.issues, ...subs];
|
|
295
|
+
};
|
|
296
|
+
const actualProto = new.target.prototype;
|
|
297
|
+
if (Object.setPrototypeOf) {
|
|
298
|
+
Object.setPrototypeOf(this, actualProto);
|
|
299
|
+
} else {
|
|
300
|
+
this.__proto__ = actualProto;
|
|
301
|
+
}
|
|
302
|
+
this.name = "ZodError";
|
|
303
|
+
this.issues = issues;
|
|
304
|
+
}
|
|
305
|
+
format(_mapper) {
|
|
306
|
+
const mapper = _mapper || function(issue) {
|
|
307
|
+
return issue.message;
|
|
308
|
+
};
|
|
309
|
+
const fieldErrors = { _errors: [] };
|
|
310
|
+
const processError = (error) => {
|
|
311
|
+
for (const issue of error.issues) {
|
|
312
|
+
if (issue.code === "invalid_union") {
|
|
313
|
+
issue.unionErrors.map(processError);
|
|
314
|
+
} else if (issue.code === "invalid_return_type") {
|
|
315
|
+
processError(issue.returnTypeError);
|
|
316
|
+
} else if (issue.code === "invalid_arguments") {
|
|
317
|
+
processError(issue.argumentsError);
|
|
318
|
+
} else if (issue.path.length === 0) {
|
|
319
|
+
fieldErrors._errors.push(mapper(issue));
|
|
320
|
+
} else {
|
|
321
|
+
let curr = fieldErrors;
|
|
322
|
+
let i = 0;
|
|
323
|
+
while (i < issue.path.length) {
|
|
324
|
+
const el = issue.path[i];
|
|
325
|
+
const terminal = i === issue.path.length - 1;
|
|
326
|
+
if (!terminal) {
|
|
327
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
328
|
+
} else {
|
|
329
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
330
|
+
curr[el]._errors.push(mapper(issue));
|
|
331
|
+
}
|
|
332
|
+
curr = curr[el];
|
|
333
|
+
i++;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
processError(this);
|
|
339
|
+
return fieldErrors;
|
|
340
|
+
}
|
|
341
|
+
static assert(value) {
|
|
342
|
+
if (!(value instanceof _ZodError)) {
|
|
343
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
toString() {
|
|
347
|
+
return this.message;
|
|
348
|
+
}
|
|
349
|
+
get message() {
|
|
350
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
351
|
+
}
|
|
352
|
+
get isEmpty() {
|
|
353
|
+
return this.issues.length === 0;
|
|
354
|
+
}
|
|
355
|
+
flatten(mapper = (issue) => issue.message) {
|
|
356
|
+
const fieldErrors = {};
|
|
357
|
+
const formErrors = [];
|
|
358
|
+
for (const sub of this.issues) {
|
|
359
|
+
if (sub.path.length > 0) {
|
|
360
|
+
const firstEl = sub.path[0];
|
|
361
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
362
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
363
|
+
} else {
|
|
364
|
+
formErrors.push(mapper(sub));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return { formErrors, fieldErrors };
|
|
368
|
+
}
|
|
369
|
+
get formErrors() {
|
|
370
|
+
return this.flatten();
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
ZodError.create = (issues) => {
|
|
374
|
+
const error = new ZodError(issues);
|
|
375
|
+
return error;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
379
|
+
var errorMap = (issue, _ctx) => {
|
|
380
|
+
let message;
|
|
381
|
+
switch (issue.code) {
|
|
382
|
+
case ZodIssueCode.invalid_type:
|
|
383
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
384
|
+
message = "Required";
|
|
385
|
+
} else {
|
|
386
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
case ZodIssueCode.invalid_literal:
|
|
390
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
391
|
+
break;
|
|
392
|
+
case ZodIssueCode.unrecognized_keys:
|
|
393
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
394
|
+
break;
|
|
395
|
+
case ZodIssueCode.invalid_union:
|
|
396
|
+
message = `Invalid input`;
|
|
397
|
+
break;
|
|
398
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
399
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
400
|
+
break;
|
|
401
|
+
case ZodIssueCode.invalid_enum_value:
|
|
402
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
403
|
+
break;
|
|
404
|
+
case ZodIssueCode.invalid_arguments:
|
|
405
|
+
message = `Invalid function arguments`;
|
|
406
|
+
break;
|
|
407
|
+
case ZodIssueCode.invalid_return_type:
|
|
408
|
+
message = `Invalid function return type`;
|
|
409
|
+
break;
|
|
410
|
+
case ZodIssueCode.invalid_date:
|
|
411
|
+
message = `Invalid date`;
|
|
412
|
+
break;
|
|
413
|
+
case ZodIssueCode.invalid_string:
|
|
414
|
+
if (typeof issue.validation === "object") {
|
|
415
|
+
if ("includes" in issue.validation) {
|
|
416
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
417
|
+
if (typeof issue.validation.position === "number") {
|
|
418
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
419
|
+
}
|
|
420
|
+
} else if ("startsWith" in issue.validation) {
|
|
421
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
422
|
+
} else if ("endsWith" in issue.validation) {
|
|
423
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
424
|
+
} else {
|
|
425
|
+
util.assertNever(issue.validation);
|
|
426
|
+
}
|
|
427
|
+
} else if (issue.validation !== "regex") {
|
|
428
|
+
message = `Invalid ${issue.validation}`;
|
|
429
|
+
} else {
|
|
430
|
+
message = "Invalid";
|
|
431
|
+
}
|
|
432
|
+
break;
|
|
433
|
+
case ZodIssueCode.too_small:
|
|
434
|
+
if (issue.type === "array")
|
|
435
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
436
|
+
else if (issue.type === "string")
|
|
437
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
438
|
+
else if (issue.type === "number")
|
|
439
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
440
|
+
else if (issue.type === "bigint")
|
|
441
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
442
|
+
else if (issue.type === "date")
|
|
443
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
444
|
+
else
|
|
445
|
+
message = "Invalid input";
|
|
446
|
+
break;
|
|
447
|
+
case ZodIssueCode.too_big:
|
|
448
|
+
if (issue.type === "array")
|
|
449
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
450
|
+
else if (issue.type === "string")
|
|
451
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
452
|
+
else if (issue.type === "number")
|
|
453
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
454
|
+
else if (issue.type === "bigint")
|
|
455
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
456
|
+
else if (issue.type === "date")
|
|
457
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
458
|
+
else
|
|
459
|
+
message = "Invalid input";
|
|
460
|
+
break;
|
|
461
|
+
case ZodIssueCode.custom:
|
|
462
|
+
message = `Invalid input`;
|
|
463
|
+
break;
|
|
464
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
465
|
+
message = `Intersection results could not be merged`;
|
|
466
|
+
break;
|
|
467
|
+
case ZodIssueCode.not_multiple_of:
|
|
468
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
469
|
+
break;
|
|
470
|
+
case ZodIssueCode.not_finite:
|
|
471
|
+
message = "Number must be finite";
|
|
472
|
+
break;
|
|
473
|
+
default:
|
|
474
|
+
message = _ctx.defaultError;
|
|
475
|
+
util.assertNever(issue);
|
|
476
|
+
}
|
|
477
|
+
return { message };
|
|
478
|
+
};
|
|
479
|
+
var en_default = errorMap;
|
|
480
|
+
|
|
481
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
482
|
+
var overrideErrorMap = en_default;
|
|
483
|
+
function setErrorMap(map) {
|
|
484
|
+
overrideErrorMap = map;
|
|
485
|
+
}
|
|
486
|
+
function getErrorMap() {
|
|
487
|
+
return overrideErrorMap;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
491
|
+
var makeIssue = (params) => {
|
|
492
|
+
const { data, path, errorMaps, issueData } = params;
|
|
493
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
494
|
+
const fullIssue = {
|
|
495
|
+
...issueData,
|
|
496
|
+
path: fullPath
|
|
497
|
+
};
|
|
498
|
+
if (issueData.message !== void 0) {
|
|
499
|
+
return {
|
|
500
|
+
...issueData,
|
|
501
|
+
path: fullPath,
|
|
502
|
+
message: issueData.message
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
let errorMessage = "";
|
|
506
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
507
|
+
for (const map of maps) {
|
|
508
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
...issueData,
|
|
512
|
+
path: fullPath,
|
|
513
|
+
message: errorMessage
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
var EMPTY_PATH = [];
|
|
517
|
+
function addIssueToContext(ctx, issueData) {
|
|
518
|
+
const overrideMap = getErrorMap();
|
|
519
|
+
const issue = makeIssue({
|
|
520
|
+
issueData,
|
|
521
|
+
data: ctx.data,
|
|
522
|
+
path: ctx.path,
|
|
523
|
+
errorMaps: [
|
|
524
|
+
ctx.common.contextualErrorMap,
|
|
525
|
+
// contextual error map is first priority
|
|
526
|
+
ctx.schemaErrorMap,
|
|
527
|
+
// then schema-bound map if available
|
|
528
|
+
overrideMap,
|
|
529
|
+
// then global override map
|
|
530
|
+
overrideMap === en_default ? void 0 : en_default
|
|
531
|
+
// then global default map
|
|
532
|
+
].filter((x) => !!x)
|
|
533
|
+
});
|
|
534
|
+
ctx.common.issues.push(issue);
|
|
535
|
+
}
|
|
536
|
+
var ParseStatus = class _ParseStatus {
|
|
537
|
+
constructor() {
|
|
538
|
+
this.value = "valid";
|
|
539
|
+
}
|
|
540
|
+
dirty() {
|
|
541
|
+
if (this.value === "valid")
|
|
542
|
+
this.value = "dirty";
|
|
543
|
+
}
|
|
544
|
+
abort() {
|
|
545
|
+
if (this.value !== "aborted")
|
|
546
|
+
this.value = "aborted";
|
|
547
|
+
}
|
|
548
|
+
static mergeArray(status, results) {
|
|
549
|
+
const arrayValue = [];
|
|
550
|
+
for (const s of results) {
|
|
551
|
+
if (s.status === "aborted")
|
|
552
|
+
return INVALID;
|
|
553
|
+
if (s.status === "dirty")
|
|
554
|
+
status.dirty();
|
|
555
|
+
arrayValue.push(s.value);
|
|
556
|
+
}
|
|
557
|
+
return { status: status.value, value: arrayValue };
|
|
558
|
+
}
|
|
559
|
+
static async mergeObjectAsync(status, pairs) {
|
|
560
|
+
const syncPairs = [];
|
|
561
|
+
for (const pair of pairs) {
|
|
562
|
+
const key = await pair.key;
|
|
563
|
+
const value = await pair.value;
|
|
564
|
+
syncPairs.push({
|
|
565
|
+
key,
|
|
566
|
+
value
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
570
|
+
}
|
|
571
|
+
static mergeObjectSync(status, pairs) {
|
|
572
|
+
const finalObject = {};
|
|
573
|
+
for (const pair of pairs) {
|
|
574
|
+
const { key, value } = pair;
|
|
575
|
+
if (key.status === "aborted")
|
|
576
|
+
return INVALID;
|
|
577
|
+
if (value.status === "aborted")
|
|
578
|
+
return INVALID;
|
|
579
|
+
if (key.status === "dirty")
|
|
580
|
+
status.dirty();
|
|
581
|
+
if (value.status === "dirty")
|
|
582
|
+
status.dirty();
|
|
583
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
584
|
+
finalObject[key.value] = value.value;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return { status: status.value, value: finalObject };
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
var INVALID = Object.freeze({
|
|
591
|
+
status: "aborted"
|
|
592
|
+
});
|
|
593
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
594
|
+
var OK = (value) => ({ status: "valid", value });
|
|
595
|
+
var isAborted = (x) => x.status === "aborted";
|
|
596
|
+
var isDirty = (x) => x.status === "dirty";
|
|
597
|
+
var isValid = (x) => x.status === "valid";
|
|
598
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
599
|
+
|
|
600
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
601
|
+
var errorUtil;
|
|
602
|
+
(function(errorUtil2) {
|
|
603
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
604
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
605
|
+
})(errorUtil || (errorUtil = {}));
|
|
606
|
+
|
|
607
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
608
|
+
var ParseInputLazyPath = class {
|
|
609
|
+
constructor(parent, value, path, key) {
|
|
610
|
+
this._cachedPath = [];
|
|
611
|
+
this.parent = parent;
|
|
612
|
+
this.data = value;
|
|
613
|
+
this._path = path;
|
|
614
|
+
this._key = key;
|
|
615
|
+
}
|
|
616
|
+
get path() {
|
|
617
|
+
if (!this._cachedPath.length) {
|
|
618
|
+
if (Array.isArray(this._key)) {
|
|
619
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
620
|
+
} else {
|
|
621
|
+
this._cachedPath.push(...this._path, this._key);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return this._cachedPath;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
var handleResult = (ctx, result) => {
|
|
628
|
+
if (isValid(result)) {
|
|
629
|
+
return { success: true, data: result.value };
|
|
630
|
+
} else {
|
|
631
|
+
if (!ctx.common.issues.length) {
|
|
632
|
+
throw new Error("Validation failed but no issues detected.");
|
|
633
|
+
}
|
|
634
|
+
return {
|
|
635
|
+
success: false,
|
|
636
|
+
get error() {
|
|
637
|
+
if (this._error)
|
|
638
|
+
return this._error;
|
|
639
|
+
const error = new ZodError(ctx.common.issues);
|
|
640
|
+
this._error = error;
|
|
641
|
+
return this._error;
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
function processCreateParams(params) {
|
|
647
|
+
if (!params)
|
|
648
|
+
return {};
|
|
649
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
650
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
651
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
652
|
+
}
|
|
653
|
+
if (errorMap2)
|
|
654
|
+
return { errorMap: errorMap2, description };
|
|
655
|
+
const customMap = (iss, ctx) => {
|
|
656
|
+
const { message } = params;
|
|
657
|
+
if (iss.code === "invalid_enum_value") {
|
|
658
|
+
return { message: message ?? ctx.defaultError };
|
|
659
|
+
}
|
|
660
|
+
if (typeof ctx.data === "undefined") {
|
|
661
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
662
|
+
}
|
|
663
|
+
if (iss.code !== "invalid_type")
|
|
664
|
+
return { message: ctx.defaultError };
|
|
665
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
666
|
+
};
|
|
667
|
+
return { errorMap: customMap, description };
|
|
668
|
+
}
|
|
669
|
+
var ZodType = class {
|
|
670
|
+
get description() {
|
|
671
|
+
return this._def.description;
|
|
672
|
+
}
|
|
673
|
+
_getType(input) {
|
|
674
|
+
return getParsedType(input.data);
|
|
675
|
+
}
|
|
676
|
+
_getOrReturnCtx(input, ctx) {
|
|
677
|
+
return ctx || {
|
|
678
|
+
common: input.parent.common,
|
|
679
|
+
data: input.data,
|
|
680
|
+
parsedType: getParsedType(input.data),
|
|
681
|
+
schemaErrorMap: this._def.errorMap,
|
|
682
|
+
path: input.path,
|
|
683
|
+
parent: input.parent
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
_processInputParams(input) {
|
|
687
|
+
return {
|
|
688
|
+
status: new ParseStatus(),
|
|
689
|
+
ctx: {
|
|
690
|
+
common: input.parent.common,
|
|
691
|
+
data: input.data,
|
|
692
|
+
parsedType: getParsedType(input.data),
|
|
693
|
+
schemaErrorMap: this._def.errorMap,
|
|
694
|
+
path: input.path,
|
|
695
|
+
parent: input.parent
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
_parseSync(input) {
|
|
700
|
+
const result = this._parse(input);
|
|
701
|
+
if (isAsync(result)) {
|
|
702
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
703
|
+
}
|
|
704
|
+
return result;
|
|
705
|
+
}
|
|
706
|
+
_parseAsync(input) {
|
|
707
|
+
const result = this._parse(input);
|
|
708
|
+
return Promise.resolve(result);
|
|
709
|
+
}
|
|
710
|
+
parse(data, params) {
|
|
711
|
+
const result = this.safeParse(data, params);
|
|
712
|
+
if (result.success)
|
|
713
|
+
return result.data;
|
|
714
|
+
throw result.error;
|
|
715
|
+
}
|
|
716
|
+
safeParse(data, params) {
|
|
717
|
+
const ctx = {
|
|
718
|
+
common: {
|
|
719
|
+
issues: [],
|
|
720
|
+
async: params?.async ?? false,
|
|
721
|
+
contextualErrorMap: params?.errorMap
|
|
722
|
+
},
|
|
723
|
+
path: params?.path || [],
|
|
724
|
+
schemaErrorMap: this._def.errorMap,
|
|
725
|
+
parent: null,
|
|
726
|
+
data,
|
|
727
|
+
parsedType: getParsedType(data)
|
|
728
|
+
};
|
|
729
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
730
|
+
return handleResult(ctx, result);
|
|
731
|
+
}
|
|
732
|
+
"~validate"(data) {
|
|
733
|
+
const ctx = {
|
|
734
|
+
common: {
|
|
735
|
+
issues: [],
|
|
736
|
+
async: !!this["~standard"].async
|
|
737
|
+
},
|
|
738
|
+
path: [],
|
|
739
|
+
schemaErrorMap: this._def.errorMap,
|
|
740
|
+
parent: null,
|
|
741
|
+
data,
|
|
742
|
+
parsedType: getParsedType(data)
|
|
743
|
+
};
|
|
744
|
+
if (!this["~standard"].async) {
|
|
745
|
+
try {
|
|
746
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
747
|
+
return isValid(result) ? {
|
|
748
|
+
value: result.value
|
|
749
|
+
} : {
|
|
750
|
+
issues: ctx.common.issues
|
|
751
|
+
};
|
|
752
|
+
} catch (err) {
|
|
753
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
754
|
+
this["~standard"].async = true;
|
|
755
|
+
}
|
|
756
|
+
ctx.common = {
|
|
757
|
+
issues: [],
|
|
758
|
+
async: true
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
763
|
+
value: result.value
|
|
764
|
+
} : {
|
|
765
|
+
issues: ctx.common.issues
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
async parseAsync(data, params) {
|
|
769
|
+
const result = await this.safeParseAsync(data, params);
|
|
770
|
+
if (result.success)
|
|
771
|
+
return result.data;
|
|
772
|
+
throw result.error;
|
|
773
|
+
}
|
|
774
|
+
async safeParseAsync(data, params) {
|
|
775
|
+
const ctx = {
|
|
776
|
+
common: {
|
|
777
|
+
issues: [],
|
|
778
|
+
contextualErrorMap: params?.errorMap,
|
|
779
|
+
async: true
|
|
780
|
+
},
|
|
781
|
+
path: params?.path || [],
|
|
782
|
+
schemaErrorMap: this._def.errorMap,
|
|
783
|
+
parent: null,
|
|
784
|
+
data,
|
|
785
|
+
parsedType: getParsedType(data)
|
|
786
|
+
};
|
|
787
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
788
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
789
|
+
return handleResult(ctx, result);
|
|
790
|
+
}
|
|
791
|
+
refine(check, message) {
|
|
792
|
+
const getIssueProperties = (val) => {
|
|
793
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
794
|
+
return { message };
|
|
795
|
+
} else if (typeof message === "function") {
|
|
796
|
+
return message(val);
|
|
797
|
+
} else {
|
|
798
|
+
return message;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
return this._refinement((val, ctx) => {
|
|
802
|
+
const result = check(val);
|
|
803
|
+
const setError = () => ctx.addIssue({
|
|
804
|
+
code: ZodIssueCode.custom,
|
|
805
|
+
...getIssueProperties(val)
|
|
806
|
+
});
|
|
807
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
808
|
+
return result.then((data) => {
|
|
809
|
+
if (!data) {
|
|
810
|
+
setError();
|
|
811
|
+
return false;
|
|
812
|
+
} else {
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
if (!result) {
|
|
818
|
+
setError();
|
|
819
|
+
return false;
|
|
820
|
+
} else {
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
refinement(check, refinementData) {
|
|
826
|
+
return this._refinement((val, ctx) => {
|
|
827
|
+
if (!check(val)) {
|
|
828
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
829
|
+
return false;
|
|
830
|
+
} else {
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
_refinement(refinement) {
|
|
836
|
+
return new ZodEffects({
|
|
837
|
+
schema: this,
|
|
838
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
839
|
+
effect: { type: "refinement", refinement }
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
superRefine(refinement) {
|
|
843
|
+
return this._refinement(refinement);
|
|
844
|
+
}
|
|
845
|
+
constructor(def) {
|
|
846
|
+
this.spa = this.safeParseAsync;
|
|
847
|
+
this._def = def;
|
|
848
|
+
this.parse = this.parse.bind(this);
|
|
849
|
+
this.safeParse = this.safeParse.bind(this);
|
|
850
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
851
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
852
|
+
this.spa = this.spa.bind(this);
|
|
853
|
+
this.refine = this.refine.bind(this);
|
|
854
|
+
this.refinement = this.refinement.bind(this);
|
|
855
|
+
this.superRefine = this.superRefine.bind(this);
|
|
856
|
+
this.optional = this.optional.bind(this);
|
|
857
|
+
this.nullable = this.nullable.bind(this);
|
|
858
|
+
this.nullish = this.nullish.bind(this);
|
|
859
|
+
this.array = this.array.bind(this);
|
|
860
|
+
this.promise = this.promise.bind(this);
|
|
861
|
+
this.or = this.or.bind(this);
|
|
862
|
+
this.and = this.and.bind(this);
|
|
863
|
+
this.transform = this.transform.bind(this);
|
|
864
|
+
this.brand = this.brand.bind(this);
|
|
865
|
+
this.default = this.default.bind(this);
|
|
866
|
+
this.catch = this.catch.bind(this);
|
|
867
|
+
this.describe = this.describe.bind(this);
|
|
868
|
+
this.pipe = this.pipe.bind(this);
|
|
869
|
+
this.readonly = this.readonly.bind(this);
|
|
870
|
+
this.isNullable = this.isNullable.bind(this);
|
|
871
|
+
this.isOptional = this.isOptional.bind(this);
|
|
872
|
+
this["~standard"] = {
|
|
873
|
+
version: 1,
|
|
874
|
+
vendor: "zod",
|
|
875
|
+
validate: (data) => this["~validate"](data)
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
optional() {
|
|
879
|
+
return ZodOptional.create(this, this._def);
|
|
880
|
+
}
|
|
881
|
+
nullable() {
|
|
882
|
+
return ZodNullable.create(this, this._def);
|
|
883
|
+
}
|
|
884
|
+
nullish() {
|
|
885
|
+
return this.nullable().optional();
|
|
886
|
+
}
|
|
887
|
+
array() {
|
|
888
|
+
return ZodArray.create(this);
|
|
889
|
+
}
|
|
890
|
+
promise() {
|
|
891
|
+
return ZodPromise.create(this, this._def);
|
|
892
|
+
}
|
|
893
|
+
or(option) {
|
|
894
|
+
return ZodUnion.create([this, option], this._def);
|
|
895
|
+
}
|
|
896
|
+
and(incoming) {
|
|
897
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
898
|
+
}
|
|
899
|
+
transform(transform) {
|
|
900
|
+
return new ZodEffects({
|
|
901
|
+
...processCreateParams(this._def),
|
|
902
|
+
schema: this,
|
|
903
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
904
|
+
effect: { type: "transform", transform }
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
default(def) {
|
|
908
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
909
|
+
return new ZodDefault({
|
|
910
|
+
...processCreateParams(this._def),
|
|
911
|
+
innerType: this,
|
|
912
|
+
defaultValue: defaultValueFunc,
|
|
913
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
brand() {
|
|
917
|
+
return new ZodBranded({
|
|
918
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
919
|
+
type: this,
|
|
920
|
+
...processCreateParams(this._def)
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
catch(def) {
|
|
924
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
925
|
+
return new ZodCatch({
|
|
926
|
+
...processCreateParams(this._def),
|
|
927
|
+
innerType: this,
|
|
928
|
+
catchValue: catchValueFunc,
|
|
929
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
describe(description) {
|
|
933
|
+
const This = this.constructor;
|
|
934
|
+
return new This({
|
|
935
|
+
...this._def,
|
|
936
|
+
description
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
pipe(target) {
|
|
940
|
+
return ZodPipeline.create(this, target);
|
|
941
|
+
}
|
|
942
|
+
readonly() {
|
|
943
|
+
return ZodReadonly.create(this);
|
|
944
|
+
}
|
|
945
|
+
isOptional() {
|
|
946
|
+
return this.safeParse(void 0).success;
|
|
947
|
+
}
|
|
948
|
+
isNullable() {
|
|
949
|
+
return this.safeParse(null).success;
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
953
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
954
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
955
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
956
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
957
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
958
|
+
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
959
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
960
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
961
|
+
var emojiRegex;
|
|
962
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
963
|
+
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
964
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
965
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
966
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
967
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
968
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
969
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
970
|
+
function timeRegexSource(args) {
|
|
971
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
972
|
+
if (args.precision) {
|
|
973
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
974
|
+
} else if (args.precision == null) {
|
|
975
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
976
|
+
}
|
|
977
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
978
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
979
|
+
}
|
|
980
|
+
function timeRegex(args) {
|
|
981
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
982
|
+
}
|
|
983
|
+
function datetimeRegex(args) {
|
|
984
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
985
|
+
const opts = [];
|
|
986
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
987
|
+
if (args.offset)
|
|
988
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
989
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
990
|
+
return new RegExp(`^${regex}$`);
|
|
991
|
+
}
|
|
992
|
+
function isValidIP(ip, version) {
|
|
993
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
994
|
+
return true;
|
|
995
|
+
}
|
|
996
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
997
|
+
return true;
|
|
998
|
+
}
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
function isValidJWT(jwt, alg) {
|
|
1002
|
+
if (!jwtRegex.test(jwt))
|
|
1003
|
+
return false;
|
|
1004
|
+
try {
|
|
1005
|
+
const [header] = jwt.split(".");
|
|
1006
|
+
if (!header)
|
|
1007
|
+
return false;
|
|
1008
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1009
|
+
const decoded = JSON.parse(atob(base64));
|
|
1010
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1011
|
+
return false;
|
|
1012
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1013
|
+
return false;
|
|
1014
|
+
if (!decoded.alg)
|
|
1015
|
+
return false;
|
|
1016
|
+
if (alg && decoded.alg !== alg)
|
|
1017
|
+
return false;
|
|
1018
|
+
return true;
|
|
1019
|
+
} catch {
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
function isValidCidr(ip, version) {
|
|
1024
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
return false;
|
|
1031
|
+
}
|
|
1032
|
+
var ZodString = class _ZodString extends ZodType {
|
|
1033
|
+
_parse(input) {
|
|
1034
|
+
if (this._def.coerce) {
|
|
1035
|
+
input.data = String(input.data);
|
|
1036
|
+
}
|
|
1037
|
+
const parsedType = this._getType(input);
|
|
1038
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1039
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1040
|
+
addIssueToContext(ctx2, {
|
|
1041
|
+
code: ZodIssueCode.invalid_type,
|
|
1042
|
+
expected: ZodParsedType.string,
|
|
1043
|
+
received: ctx2.parsedType
|
|
1044
|
+
});
|
|
1045
|
+
return INVALID;
|
|
1046
|
+
}
|
|
1047
|
+
const status = new ParseStatus();
|
|
1048
|
+
let ctx = void 0;
|
|
1049
|
+
for (const check of this._def.checks) {
|
|
1050
|
+
if (check.kind === "min") {
|
|
1051
|
+
if (input.data.length < check.value) {
|
|
1052
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1053
|
+
addIssueToContext(ctx, {
|
|
1054
|
+
code: ZodIssueCode.too_small,
|
|
1055
|
+
minimum: check.value,
|
|
1056
|
+
type: "string",
|
|
1057
|
+
inclusive: true,
|
|
1058
|
+
exact: false,
|
|
1059
|
+
message: check.message
|
|
1060
|
+
});
|
|
1061
|
+
status.dirty();
|
|
1062
|
+
}
|
|
1063
|
+
} else if (check.kind === "max") {
|
|
1064
|
+
if (input.data.length > check.value) {
|
|
1065
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1066
|
+
addIssueToContext(ctx, {
|
|
1067
|
+
code: ZodIssueCode.too_big,
|
|
1068
|
+
maximum: check.value,
|
|
1069
|
+
type: "string",
|
|
1070
|
+
inclusive: true,
|
|
1071
|
+
exact: false,
|
|
1072
|
+
message: check.message
|
|
1073
|
+
});
|
|
1074
|
+
status.dirty();
|
|
1075
|
+
}
|
|
1076
|
+
} else if (check.kind === "length") {
|
|
1077
|
+
const tooBig = input.data.length > check.value;
|
|
1078
|
+
const tooSmall = input.data.length < check.value;
|
|
1079
|
+
if (tooBig || tooSmall) {
|
|
1080
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1081
|
+
if (tooBig) {
|
|
1082
|
+
addIssueToContext(ctx, {
|
|
1083
|
+
code: ZodIssueCode.too_big,
|
|
1084
|
+
maximum: check.value,
|
|
1085
|
+
type: "string",
|
|
1086
|
+
inclusive: true,
|
|
1087
|
+
exact: true,
|
|
1088
|
+
message: check.message
|
|
1089
|
+
});
|
|
1090
|
+
} else if (tooSmall) {
|
|
1091
|
+
addIssueToContext(ctx, {
|
|
1092
|
+
code: ZodIssueCode.too_small,
|
|
1093
|
+
minimum: check.value,
|
|
1094
|
+
type: "string",
|
|
1095
|
+
inclusive: true,
|
|
1096
|
+
exact: true,
|
|
1097
|
+
message: check.message
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
status.dirty();
|
|
1101
|
+
}
|
|
1102
|
+
} else if (check.kind === "email") {
|
|
1103
|
+
if (!emailRegex.test(input.data)) {
|
|
1104
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1105
|
+
addIssueToContext(ctx, {
|
|
1106
|
+
validation: "email",
|
|
1107
|
+
code: ZodIssueCode.invalid_string,
|
|
1108
|
+
message: check.message
|
|
1109
|
+
});
|
|
1110
|
+
status.dirty();
|
|
1111
|
+
}
|
|
1112
|
+
} else if (check.kind === "emoji") {
|
|
1113
|
+
if (!emojiRegex) {
|
|
1114
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1115
|
+
}
|
|
1116
|
+
if (!emojiRegex.test(input.data)) {
|
|
1117
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1118
|
+
addIssueToContext(ctx, {
|
|
1119
|
+
validation: "emoji",
|
|
1120
|
+
code: ZodIssueCode.invalid_string,
|
|
1121
|
+
message: check.message
|
|
1122
|
+
});
|
|
1123
|
+
status.dirty();
|
|
1124
|
+
}
|
|
1125
|
+
} else if (check.kind === "uuid") {
|
|
1126
|
+
if (!uuidRegex.test(input.data)) {
|
|
1127
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1128
|
+
addIssueToContext(ctx, {
|
|
1129
|
+
validation: "uuid",
|
|
1130
|
+
code: ZodIssueCode.invalid_string,
|
|
1131
|
+
message: check.message
|
|
1132
|
+
});
|
|
1133
|
+
status.dirty();
|
|
1134
|
+
}
|
|
1135
|
+
} else if (check.kind === "nanoid") {
|
|
1136
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1137
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1138
|
+
addIssueToContext(ctx, {
|
|
1139
|
+
validation: "nanoid",
|
|
1140
|
+
code: ZodIssueCode.invalid_string,
|
|
1141
|
+
message: check.message
|
|
1142
|
+
});
|
|
1143
|
+
status.dirty();
|
|
1144
|
+
}
|
|
1145
|
+
} else if (check.kind === "cuid") {
|
|
1146
|
+
if (!cuidRegex.test(input.data)) {
|
|
1147
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1148
|
+
addIssueToContext(ctx, {
|
|
1149
|
+
validation: "cuid",
|
|
1150
|
+
code: ZodIssueCode.invalid_string,
|
|
1151
|
+
message: check.message
|
|
1152
|
+
});
|
|
1153
|
+
status.dirty();
|
|
1154
|
+
}
|
|
1155
|
+
} else if (check.kind === "cuid2") {
|
|
1156
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1157
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1158
|
+
addIssueToContext(ctx, {
|
|
1159
|
+
validation: "cuid2",
|
|
1160
|
+
code: ZodIssueCode.invalid_string,
|
|
1161
|
+
message: check.message
|
|
1162
|
+
});
|
|
1163
|
+
status.dirty();
|
|
1164
|
+
}
|
|
1165
|
+
} else if (check.kind === "ulid") {
|
|
1166
|
+
if (!ulidRegex.test(input.data)) {
|
|
1167
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1168
|
+
addIssueToContext(ctx, {
|
|
1169
|
+
validation: "ulid",
|
|
1170
|
+
code: ZodIssueCode.invalid_string,
|
|
1171
|
+
message: check.message
|
|
1172
|
+
});
|
|
1173
|
+
status.dirty();
|
|
1174
|
+
}
|
|
1175
|
+
} else if (check.kind === "url") {
|
|
1176
|
+
try {
|
|
1177
|
+
new URL(input.data);
|
|
1178
|
+
} catch {
|
|
1179
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1180
|
+
addIssueToContext(ctx, {
|
|
1181
|
+
validation: "url",
|
|
1182
|
+
code: ZodIssueCode.invalid_string,
|
|
1183
|
+
message: check.message
|
|
1184
|
+
});
|
|
1185
|
+
status.dirty();
|
|
1186
|
+
}
|
|
1187
|
+
} else if (check.kind === "regex") {
|
|
1188
|
+
check.regex.lastIndex = 0;
|
|
1189
|
+
const testResult = check.regex.test(input.data);
|
|
1190
|
+
if (!testResult) {
|
|
1191
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1192
|
+
addIssueToContext(ctx, {
|
|
1193
|
+
validation: "regex",
|
|
1194
|
+
code: ZodIssueCode.invalid_string,
|
|
1195
|
+
message: check.message
|
|
1196
|
+
});
|
|
1197
|
+
status.dirty();
|
|
1198
|
+
}
|
|
1199
|
+
} else if (check.kind === "trim") {
|
|
1200
|
+
input.data = input.data.trim();
|
|
1201
|
+
} else if (check.kind === "includes") {
|
|
1202
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1203
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1204
|
+
addIssueToContext(ctx, {
|
|
1205
|
+
code: ZodIssueCode.invalid_string,
|
|
1206
|
+
validation: { includes: check.value, position: check.position },
|
|
1207
|
+
message: check.message
|
|
1208
|
+
});
|
|
1209
|
+
status.dirty();
|
|
1210
|
+
}
|
|
1211
|
+
} else if (check.kind === "toLowerCase") {
|
|
1212
|
+
input.data = input.data.toLowerCase();
|
|
1213
|
+
} else if (check.kind === "toUpperCase") {
|
|
1214
|
+
input.data = input.data.toUpperCase();
|
|
1215
|
+
} else if (check.kind === "startsWith") {
|
|
1216
|
+
if (!input.data.startsWith(check.value)) {
|
|
1217
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1218
|
+
addIssueToContext(ctx, {
|
|
1219
|
+
code: ZodIssueCode.invalid_string,
|
|
1220
|
+
validation: { startsWith: check.value },
|
|
1221
|
+
message: check.message
|
|
1222
|
+
});
|
|
1223
|
+
status.dirty();
|
|
1224
|
+
}
|
|
1225
|
+
} else if (check.kind === "endsWith") {
|
|
1226
|
+
if (!input.data.endsWith(check.value)) {
|
|
1227
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1228
|
+
addIssueToContext(ctx, {
|
|
1229
|
+
code: ZodIssueCode.invalid_string,
|
|
1230
|
+
validation: { endsWith: check.value },
|
|
1231
|
+
message: check.message
|
|
1232
|
+
});
|
|
1233
|
+
status.dirty();
|
|
1234
|
+
}
|
|
1235
|
+
} else if (check.kind === "datetime") {
|
|
1236
|
+
const regex = datetimeRegex(check);
|
|
1237
|
+
if (!regex.test(input.data)) {
|
|
1238
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1239
|
+
addIssueToContext(ctx, {
|
|
1240
|
+
code: ZodIssueCode.invalid_string,
|
|
1241
|
+
validation: "datetime",
|
|
1242
|
+
message: check.message
|
|
1243
|
+
});
|
|
1244
|
+
status.dirty();
|
|
1245
|
+
}
|
|
1246
|
+
} else if (check.kind === "date") {
|
|
1247
|
+
const regex = dateRegex;
|
|
1248
|
+
if (!regex.test(input.data)) {
|
|
1249
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1250
|
+
addIssueToContext(ctx, {
|
|
1251
|
+
code: ZodIssueCode.invalid_string,
|
|
1252
|
+
validation: "date",
|
|
1253
|
+
message: check.message
|
|
1254
|
+
});
|
|
1255
|
+
status.dirty();
|
|
1256
|
+
}
|
|
1257
|
+
} else if (check.kind === "time") {
|
|
1258
|
+
const regex = timeRegex(check);
|
|
1259
|
+
if (!regex.test(input.data)) {
|
|
1260
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1261
|
+
addIssueToContext(ctx, {
|
|
1262
|
+
code: ZodIssueCode.invalid_string,
|
|
1263
|
+
validation: "time",
|
|
1264
|
+
message: check.message
|
|
1265
|
+
});
|
|
1266
|
+
status.dirty();
|
|
1267
|
+
}
|
|
1268
|
+
} else if (check.kind === "duration") {
|
|
1269
|
+
if (!durationRegex.test(input.data)) {
|
|
1270
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1271
|
+
addIssueToContext(ctx, {
|
|
1272
|
+
validation: "duration",
|
|
1273
|
+
code: ZodIssueCode.invalid_string,
|
|
1274
|
+
message: check.message
|
|
1275
|
+
});
|
|
1276
|
+
status.dirty();
|
|
1277
|
+
}
|
|
1278
|
+
} else if (check.kind === "ip") {
|
|
1279
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1280
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1281
|
+
addIssueToContext(ctx, {
|
|
1282
|
+
validation: "ip",
|
|
1283
|
+
code: ZodIssueCode.invalid_string,
|
|
1284
|
+
message: check.message
|
|
1285
|
+
});
|
|
1286
|
+
status.dirty();
|
|
1287
|
+
}
|
|
1288
|
+
} else if (check.kind === "jwt") {
|
|
1289
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1290
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1291
|
+
addIssueToContext(ctx, {
|
|
1292
|
+
validation: "jwt",
|
|
1293
|
+
code: ZodIssueCode.invalid_string,
|
|
1294
|
+
message: check.message
|
|
1295
|
+
});
|
|
1296
|
+
status.dirty();
|
|
1297
|
+
}
|
|
1298
|
+
} else if (check.kind === "cidr") {
|
|
1299
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1300
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1301
|
+
addIssueToContext(ctx, {
|
|
1302
|
+
validation: "cidr",
|
|
1303
|
+
code: ZodIssueCode.invalid_string,
|
|
1304
|
+
message: check.message
|
|
1305
|
+
});
|
|
1306
|
+
status.dirty();
|
|
1307
|
+
}
|
|
1308
|
+
} else if (check.kind === "base64") {
|
|
1309
|
+
if (!base64Regex.test(input.data)) {
|
|
1310
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1311
|
+
addIssueToContext(ctx, {
|
|
1312
|
+
validation: "base64",
|
|
1313
|
+
code: ZodIssueCode.invalid_string,
|
|
1314
|
+
message: check.message
|
|
1315
|
+
});
|
|
1316
|
+
status.dirty();
|
|
1317
|
+
}
|
|
1318
|
+
} else if (check.kind === "base64url") {
|
|
1319
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1320
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1321
|
+
addIssueToContext(ctx, {
|
|
1322
|
+
validation: "base64url",
|
|
1323
|
+
code: ZodIssueCode.invalid_string,
|
|
1324
|
+
message: check.message
|
|
1325
|
+
});
|
|
1326
|
+
status.dirty();
|
|
1327
|
+
}
|
|
1328
|
+
} else {
|
|
1329
|
+
util.assertNever(check);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return { status: status.value, value: input.data };
|
|
1333
|
+
}
|
|
1334
|
+
_regex(regex, validation, message) {
|
|
1335
|
+
return this.refinement((data) => regex.test(data), {
|
|
1336
|
+
validation,
|
|
1337
|
+
code: ZodIssueCode.invalid_string,
|
|
1338
|
+
...errorUtil.errToObj(message)
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
_addCheck(check) {
|
|
1342
|
+
return new _ZodString({
|
|
1343
|
+
...this._def,
|
|
1344
|
+
checks: [...this._def.checks, check]
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
email(message) {
|
|
1348
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1349
|
+
}
|
|
1350
|
+
url(message) {
|
|
1351
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1352
|
+
}
|
|
1353
|
+
emoji(message) {
|
|
1354
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1355
|
+
}
|
|
1356
|
+
uuid(message) {
|
|
1357
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1358
|
+
}
|
|
1359
|
+
nanoid(message) {
|
|
1360
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1361
|
+
}
|
|
1362
|
+
cuid(message) {
|
|
1363
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1364
|
+
}
|
|
1365
|
+
cuid2(message) {
|
|
1366
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1367
|
+
}
|
|
1368
|
+
ulid(message) {
|
|
1369
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1370
|
+
}
|
|
1371
|
+
base64(message) {
|
|
1372
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1373
|
+
}
|
|
1374
|
+
base64url(message) {
|
|
1375
|
+
return this._addCheck({
|
|
1376
|
+
kind: "base64url",
|
|
1377
|
+
...errorUtil.errToObj(message)
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
jwt(options) {
|
|
1381
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1382
|
+
}
|
|
1383
|
+
ip(options) {
|
|
1384
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1385
|
+
}
|
|
1386
|
+
cidr(options) {
|
|
1387
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1388
|
+
}
|
|
1389
|
+
datetime(options) {
|
|
1390
|
+
if (typeof options === "string") {
|
|
1391
|
+
return this._addCheck({
|
|
1392
|
+
kind: "datetime",
|
|
1393
|
+
precision: null,
|
|
1394
|
+
offset: false,
|
|
1395
|
+
local: false,
|
|
1396
|
+
message: options
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
return this._addCheck({
|
|
1400
|
+
kind: "datetime",
|
|
1401
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1402
|
+
offset: options?.offset ?? false,
|
|
1403
|
+
local: options?.local ?? false,
|
|
1404
|
+
...errorUtil.errToObj(options?.message)
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
date(message) {
|
|
1408
|
+
return this._addCheck({ kind: "date", message });
|
|
1409
|
+
}
|
|
1410
|
+
time(options) {
|
|
1411
|
+
if (typeof options === "string") {
|
|
1412
|
+
return this._addCheck({
|
|
1413
|
+
kind: "time",
|
|
1414
|
+
precision: null,
|
|
1415
|
+
message: options
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
return this._addCheck({
|
|
1419
|
+
kind: "time",
|
|
1420
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1421
|
+
...errorUtil.errToObj(options?.message)
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
duration(message) {
|
|
1425
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1426
|
+
}
|
|
1427
|
+
regex(regex, message) {
|
|
1428
|
+
return this._addCheck({
|
|
1429
|
+
kind: "regex",
|
|
1430
|
+
regex,
|
|
1431
|
+
...errorUtil.errToObj(message)
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
includes(value, options) {
|
|
1435
|
+
return this._addCheck({
|
|
1436
|
+
kind: "includes",
|
|
1437
|
+
value,
|
|
1438
|
+
position: options?.position,
|
|
1439
|
+
...errorUtil.errToObj(options?.message)
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
startsWith(value, message) {
|
|
1443
|
+
return this._addCheck({
|
|
1444
|
+
kind: "startsWith",
|
|
1445
|
+
value,
|
|
1446
|
+
...errorUtil.errToObj(message)
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
endsWith(value, message) {
|
|
1450
|
+
return this._addCheck({
|
|
1451
|
+
kind: "endsWith",
|
|
1452
|
+
value,
|
|
1453
|
+
...errorUtil.errToObj(message)
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
min(minLength, message) {
|
|
1457
|
+
return this._addCheck({
|
|
1458
|
+
kind: "min",
|
|
1459
|
+
value: minLength,
|
|
1460
|
+
...errorUtil.errToObj(message)
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
max(maxLength, message) {
|
|
1464
|
+
return this._addCheck({
|
|
1465
|
+
kind: "max",
|
|
1466
|
+
value: maxLength,
|
|
1467
|
+
...errorUtil.errToObj(message)
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
length(len, message) {
|
|
1471
|
+
return this._addCheck({
|
|
1472
|
+
kind: "length",
|
|
1473
|
+
value: len,
|
|
1474
|
+
...errorUtil.errToObj(message)
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Equivalent to `.min(1)`
|
|
1479
|
+
*/
|
|
1480
|
+
nonempty(message) {
|
|
1481
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1482
|
+
}
|
|
1483
|
+
trim() {
|
|
1484
|
+
return new _ZodString({
|
|
1485
|
+
...this._def,
|
|
1486
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
toLowerCase() {
|
|
1490
|
+
return new _ZodString({
|
|
1491
|
+
...this._def,
|
|
1492
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
toUpperCase() {
|
|
1496
|
+
return new _ZodString({
|
|
1497
|
+
...this._def,
|
|
1498
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
get isDatetime() {
|
|
1502
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1503
|
+
}
|
|
1504
|
+
get isDate() {
|
|
1505
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1506
|
+
}
|
|
1507
|
+
get isTime() {
|
|
1508
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1509
|
+
}
|
|
1510
|
+
get isDuration() {
|
|
1511
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1512
|
+
}
|
|
1513
|
+
get isEmail() {
|
|
1514
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1515
|
+
}
|
|
1516
|
+
get isURL() {
|
|
1517
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1518
|
+
}
|
|
1519
|
+
get isEmoji() {
|
|
1520
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1521
|
+
}
|
|
1522
|
+
get isUUID() {
|
|
1523
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1524
|
+
}
|
|
1525
|
+
get isNANOID() {
|
|
1526
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1527
|
+
}
|
|
1528
|
+
get isCUID() {
|
|
1529
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1530
|
+
}
|
|
1531
|
+
get isCUID2() {
|
|
1532
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1533
|
+
}
|
|
1534
|
+
get isULID() {
|
|
1535
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1536
|
+
}
|
|
1537
|
+
get isIP() {
|
|
1538
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1539
|
+
}
|
|
1540
|
+
get isCIDR() {
|
|
1541
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1542
|
+
}
|
|
1543
|
+
get isBase64() {
|
|
1544
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1545
|
+
}
|
|
1546
|
+
get isBase64url() {
|
|
1547
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1548
|
+
}
|
|
1549
|
+
get minLength() {
|
|
1550
|
+
let min = null;
|
|
1551
|
+
for (const ch of this._def.checks) {
|
|
1552
|
+
if (ch.kind === "min") {
|
|
1553
|
+
if (min === null || ch.value > min)
|
|
1554
|
+
min = ch.value;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
return min;
|
|
1558
|
+
}
|
|
1559
|
+
get maxLength() {
|
|
1560
|
+
let max = null;
|
|
1561
|
+
for (const ch of this._def.checks) {
|
|
1562
|
+
if (ch.kind === "max") {
|
|
1563
|
+
if (max === null || ch.value < max)
|
|
1564
|
+
max = ch.value;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return max;
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
ZodString.create = (params) => {
|
|
1571
|
+
return new ZodString({
|
|
1572
|
+
checks: [],
|
|
1573
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1574
|
+
coerce: params?.coerce ?? false,
|
|
1575
|
+
...processCreateParams(params)
|
|
1576
|
+
});
|
|
1577
|
+
};
|
|
1578
|
+
function floatSafeRemainder(val, step) {
|
|
1579
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1580
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1581
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1582
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1583
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1584
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1585
|
+
}
|
|
1586
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1587
|
+
constructor() {
|
|
1588
|
+
super(...arguments);
|
|
1589
|
+
this.min = this.gte;
|
|
1590
|
+
this.max = this.lte;
|
|
1591
|
+
this.step = this.multipleOf;
|
|
1592
|
+
}
|
|
1593
|
+
_parse(input) {
|
|
1594
|
+
if (this._def.coerce) {
|
|
1595
|
+
input.data = Number(input.data);
|
|
1596
|
+
}
|
|
1597
|
+
const parsedType = this._getType(input);
|
|
1598
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1599
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1600
|
+
addIssueToContext(ctx2, {
|
|
1601
|
+
code: ZodIssueCode.invalid_type,
|
|
1602
|
+
expected: ZodParsedType.number,
|
|
1603
|
+
received: ctx2.parsedType
|
|
1604
|
+
});
|
|
1605
|
+
return INVALID;
|
|
1606
|
+
}
|
|
1607
|
+
let ctx = void 0;
|
|
1608
|
+
const status = new ParseStatus();
|
|
1609
|
+
for (const check of this._def.checks) {
|
|
1610
|
+
if (check.kind === "int") {
|
|
1611
|
+
if (!util.isInteger(input.data)) {
|
|
1612
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1613
|
+
addIssueToContext(ctx, {
|
|
1614
|
+
code: ZodIssueCode.invalid_type,
|
|
1615
|
+
expected: "integer",
|
|
1616
|
+
received: "float",
|
|
1617
|
+
message: check.message
|
|
1618
|
+
});
|
|
1619
|
+
status.dirty();
|
|
1620
|
+
}
|
|
1621
|
+
} else if (check.kind === "min") {
|
|
1622
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1623
|
+
if (tooSmall) {
|
|
1624
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1625
|
+
addIssueToContext(ctx, {
|
|
1626
|
+
code: ZodIssueCode.too_small,
|
|
1627
|
+
minimum: check.value,
|
|
1628
|
+
type: "number",
|
|
1629
|
+
inclusive: check.inclusive,
|
|
1630
|
+
exact: false,
|
|
1631
|
+
message: check.message
|
|
1632
|
+
});
|
|
1633
|
+
status.dirty();
|
|
1634
|
+
}
|
|
1635
|
+
} else if (check.kind === "max") {
|
|
1636
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1637
|
+
if (tooBig) {
|
|
1638
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1639
|
+
addIssueToContext(ctx, {
|
|
1640
|
+
code: ZodIssueCode.too_big,
|
|
1641
|
+
maximum: check.value,
|
|
1642
|
+
type: "number",
|
|
1643
|
+
inclusive: check.inclusive,
|
|
1644
|
+
exact: false,
|
|
1645
|
+
message: check.message
|
|
1646
|
+
});
|
|
1647
|
+
status.dirty();
|
|
1648
|
+
}
|
|
1649
|
+
} else if (check.kind === "multipleOf") {
|
|
1650
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1651
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1652
|
+
addIssueToContext(ctx, {
|
|
1653
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1654
|
+
multipleOf: check.value,
|
|
1655
|
+
message: check.message
|
|
1656
|
+
});
|
|
1657
|
+
status.dirty();
|
|
1658
|
+
}
|
|
1659
|
+
} else if (check.kind === "finite") {
|
|
1660
|
+
if (!Number.isFinite(input.data)) {
|
|
1661
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1662
|
+
addIssueToContext(ctx, {
|
|
1663
|
+
code: ZodIssueCode.not_finite,
|
|
1664
|
+
message: check.message
|
|
1665
|
+
});
|
|
1666
|
+
status.dirty();
|
|
1667
|
+
}
|
|
1668
|
+
} else {
|
|
1669
|
+
util.assertNever(check);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
return { status: status.value, value: input.data };
|
|
1673
|
+
}
|
|
1674
|
+
gte(value, message) {
|
|
1675
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1676
|
+
}
|
|
1677
|
+
gt(value, message) {
|
|
1678
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1679
|
+
}
|
|
1680
|
+
lte(value, message) {
|
|
1681
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1682
|
+
}
|
|
1683
|
+
lt(value, message) {
|
|
1684
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1685
|
+
}
|
|
1686
|
+
setLimit(kind, value, inclusive, message) {
|
|
1687
|
+
return new _ZodNumber({
|
|
1688
|
+
...this._def,
|
|
1689
|
+
checks: [
|
|
1690
|
+
...this._def.checks,
|
|
1691
|
+
{
|
|
1692
|
+
kind,
|
|
1693
|
+
value,
|
|
1694
|
+
inclusive,
|
|
1695
|
+
message: errorUtil.toString(message)
|
|
1696
|
+
}
|
|
1697
|
+
]
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
_addCheck(check) {
|
|
1701
|
+
return new _ZodNumber({
|
|
1702
|
+
...this._def,
|
|
1703
|
+
checks: [...this._def.checks, check]
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
int(message) {
|
|
1707
|
+
return this._addCheck({
|
|
1708
|
+
kind: "int",
|
|
1709
|
+
message: errorUtil.toString(message)
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
positive(message) {
|
|
1713
|
+
return this._addCheck({
|
|
1714
|
+
kind: "min",
|
|
1715
|
+
value: 0,
|
|
1716
|
+
inclusive: false,
|
|
1717
|
+
message: errorUtil.toString(message)
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
negative(message) {
|
|
1721
|
+
return this._addCheck({
|
|
1722
|
+
kind: "max",
|
|
1723
|
+
value: 0,
|
|
1724
|
+
inclusive: false,
|
|
1725
|
+
message: errorUtil.toString(message)
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
nonpositive(message) {
|
|
1729
|
+
return this._addCheck({
|
|
1730
|
+
kind: "max",
|
|
1731
|
+
value: 0,
|
|
1732
|
+
inclusive: true,
|
|
1733
|
+
message: errorUtil.toString(message)
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
nonnegative(message) {
|
|
1737
|
+
return this._addCheck({
|
|
1738
|
+
kind: "min",
|
|
1739
|
+
value: 0,
|
|
1740
|
+
inclusive: true,
|
|
1741
|
+
message: errorUtil.toString(message)
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
multipleOf(value, message) {
|
|
1745
|
+
return this._addCheck({
|
|
1746
|
+
kind: "multipleOf",
|
|
1747
|
+
value,
|
|
1748
|
+
message: errorUtil.toString(message)
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
finite(message) {
|
|
1752
|
+
return this._addCheck({
|
|
1753
|
+
kind: "finite",
|
|
1754
|
+
message: errorUtil.toString(message)
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
safe(message) {
|
|
1758
|
+
return this._addCheck({
|
|
1759
|
+
kind: "min",
|
|
1760
|
+
inclusive: true,
|
|
1761
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1762
|
+
message: errorUtil.toString(message)
|
|
1763
|
+
})._addCheck({
|
|
1764
|
+
kind: "max",
|
|
1765
|
+
inclusive: true,
|
|
1766
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1767
|
+
message: errorUtil.toString(message)
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
get minValue() {
|
|
1771
|
+
let min = null;
|
|
1772
|
+
for (const ch of this._def.checks) {
|
|
1773
|
+
if (ch.kind === "min") {
|
|
1774
|
+
if (min === null || ch.value > min)
|
|
1775
|
+
min = ch.value;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return min;
|
|
1779
|
+
}
|
|
1780
|
+
get maxValue() {
|
|
1781
|
+
let max = null;
|
|
1782
|
+
for (const ch of this._def.checks) {
|
|
1783
|
+
if (ch.kind === "max") {
|
|
1784
|
+
if (max === null || ch.value < max)
|
|
1785
|
+
max = ch.value;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return max;
|
|
1789
|
+
}
|
|
1790
|
+
get isInt() {
|
|
1791
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1792
|
+
}
|
|
1793
|
+
get isFinite() {
|
|
1794
|
+
let max = null;
|
|
1795
|
+
let min = null;
|
|
1796
|
+
for (const ch of this._def.checks) {
|
|
1797
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1798
|
+
return true;
|
|
1799
|
+
} else if (ch.kind === "min") {
|
|
1800
|
+
if (min === null || ch.value > min)
|
|
1801
|
+
min = ch.value;
|
|
1802
|
+
} else if (ch.kind === "max") {
|
|
1803
|
+
if (max === null || ch.value < max)
|
|
1804
|
+
max = ch.value;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
ZodNumber.create = (params) => {
|
|
1811
|
+
return new ZodNumber({
|
|
1812
|
+
checks: [],
|
|
1813
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1814
|
+
coerce: params?.coerce || false,
|
|
1815
|
+
...processCreateParams(params)
|
|
1816
|
+
});
|
|
1817
|
+
};
|
|
1818
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1819
|
+
constructor() {
|
|
1820
|
+
super(...arguments);
|
|
1821
|
+
this.min = this.gte;
|
|
1822
|
+
this.max = this.lte;
|
|
1823
|
+
}
|
|
1824
|
+
_parse(input) {
|
|
1825
|
+
if (this._def.coerce) {
|
|
1826
|
+
try {
|
|
1827
|
+
input.data = BigInt(input.data);
|
|
1828
|
+
} catch {
|
|
1829
|
+
return this._getInvalidInput(input);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
const parsedType = this._getType(input);
|
|
1833
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
1834
|
+
return this._getInvalidInput(input);
|
|
1835
|
+
}
|
|
1836
|
+
let ctx = void 0;
|
|
1837
|
+
const status = new ParseStatus();
|
|
1838
|
+
for (const check of this._def.checks) {
|
|
1839
|
+
if (check.kind === "min") {
|
|
1840
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1841
|
+
if (tooSmall) {
|
|
1842
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1843
|
+
addIssueToContext(ctx, {
|
|
1844
|
+
code: ZodIssueCode.too_small,
|
|
1845
|
+
type: "bigint",
|
|
1846
|
+
minimum: check.value,
|
|
1847
|
+
inclusive: check.inclusive,
|
|
1848
|
+
message: check.message
|
|
1849
|
+
});
|
|
1850
|
+
status.dirty();
|
|
1851
|
+
}
|
|
1852
|
+
} else if (check.kind === "max") {
|
|
1853
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1854
|
+
if (tooBig) {
|
|
1855
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1856
|
+
addIssueToContext(ctx, {
|
|
1857
|
+
code: ZodIssueCode.too_big,
|
|
1858
|
+
type: "bigint",
|
|
1859
|
+
maximum: check.value,
|
|
1860
|
+
inclusive: check.inclusive,
|
|
1861
|
+
message: check.message
|
|
1862
|
+
});
|
|
1863
|
+
status.dirty();
|
|
1864
|
+
}
|
|
1865
|
+
} else if (check.kind === "multipleOf") {
|
|
1866
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1867
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1868
|
+
addIssueToContext(ctx, {
|
|
1869
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1870
|
+
multipleOf: check.value,
|
|
1871
|
+
message: check.message
|
|
1872
|
+
});
|
|
1873
|
+
status.dirty();
|
|
1874
|
+
}
|
|
1875
|
+
} else {
|
|
1876
|
+
util.assertNever(check);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
return { status: status.value, value: input.data };
|
|
1880
|
+
}
|
|
1881
|
+
_getInvalidInput(input) {
|
|
1882
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1883
|
+
addIssueToContext(ctx, {
|
|
1884
|
+
code: ZodIssueCode.invalid_type,
|
|
1885
|
+
expected: ZodParsedType.bigint,
|
|
1886
|
+
received: ctx.parsedType
|
|
1887
|
+
});
|
|
1888
|
+
return INVALID;
|
|
1889
|
+
}
|
|
1890
|
+
gte(value, message) {
|
|
1891
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1892
|
+
}
|
|
1893
|
+
gt(value, message) {
|
|
1894
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1895
|
+
}
|
|
1896
|
+
lte(value, message) {
|
|
1897
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1898
|
+
}
|
|
1899
|
+
lt(value, message) {
|
|
1900
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1901
|
+
}
|
|
1902
|
+
setLimit(kind, value, inclusive, message) {
|
|
1903
|
+
return new _ZodBigInt({
|
|
1904
|
+
...this._def,
|
|
1905
|
+
checks: [
|
|
1906
|
+
...this._def.checks,
|
|
1907
|
+
{
|
|
1908
|
+
kind,
|
|
1909
|
+
value,
|
|
1910
|
+
inclusive,
|
|
1911
|
+
message: errorUtil.toString(message)
|
|
1912
|
+
}
|
|
1913
|
+
]
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
_addCheck(check) {
|
|
1917
|
+
return new _ZodBigInt({
|
|
1918
|
+
...this._def,
|
|
1919
|
+
checks: [...this._def.checks, check]
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
positive(message) {
|
|
1923
|
+
return this._addCheck({
|
|
1924
|
+
kind: "min",
|
|
1925
|
+
value: BigInt(0),
|
|
1926
|
+
inclusive: false,
|
|
1927
|
+
message: errorUtil.toString(message)
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
negative(message) {
|
|
1931
|
+
return this._addCheck({
|
|
1932
|
+
kind: "max",
|
|
1933
|
+
value: BigInt(0),
|
|
1934
|
+
inclusive: false,
|
|
1935
|
+
message: errorUtil.toString(message)
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
nonpositive(message) {
|
|
1939
|
+
return this._addCheck({
|
|
1940
|
+
kind: "max",
|
|
1941
|
+
value: BigInt(0),
|
|
1942
|
+
inclusive: true,
|
|
1943
|
+
message: errorUtil.toString(message)
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
nonnegative(message) {
|
|
1947
|
+
return this._addCheck({
|
|
1948
|
+
kind: "min",
|
|
1949
|
+
value: BigInt(0),
|
|
1950
|
+
inclusive: true,
|
|
1951
|
+
message: errorUtil.toString(message)
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
multipleOf(value, message) {
|
|
1955
|
+
return this._addCheck({
|
|
1956
|
+
kind: "multipleOf",
|
|
1957
|
+
value,
|
|
1958
|
+
message: errorUtil.toString(message)
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
get minValue() {
|
|
1962
|
+
let min = null;
|
|
1963
|
+
for (const ch of this._def.checks) {
|
|
1964
|
+
if (ch.kind === "min") {
|
|
1965
|
+
if (min === null || ch.value > min)
|
|
1966
|
+
min = ch.value;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
return min;
|
|
1970
|
+
}
|
|
1971
|
+
get maxValue() {
|
|
1972
|
+
let max = null;
|
|
1973
|
+
for (const ch of this._def.checks) {
|
|
1974
|
+
if (ch.kind === "max") {
|
|
1975
|
+
if (max === null || ch.value < max)
|
|
1976
|
+
max = ch.value;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
return max;
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
ZodBigInt.create = (params) => {
|
|
1983
|
+
return new ZodBigInt({
|
|
1984
|
+
checks: [],
|
|
1985
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1986
|
+
coerce: params?.coerce ?? false,
|
|
1987
|
+
...processCreateParams(params)
|
|
1988
|
+
});
|
|
1989
|
+
};
|
|
1990
|
+
var ZodBoolean = class extends ZodType {
|
|
1991
|
+
_parse(input) {
|
|
1992
|
+
if (this._def.coerce) {
|
|
1993
|
+
input.data = Boolean(input.data);
|
|
1994
|
+
}
|
|
1995
|
+
const parsedType = this._getType(input);
|
|
1996
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
1997
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1998
|
+
addIssueToContext(ctx, {
|
|
1999
|
+
code: ZodIssueCode.invalid_type,
|
|
2000
|
+
expected: ZodParsedType.boolean,
|
|
2001
|
+
received: ctx.parsedType
|
|
2002
|
+
});
|
|
2003
|
+
return INVALID;
|
|
2004
|
+
}
|
|
2005
|
+
return OK(input.data);
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
ZodBoolean.create = (params) => {
|
|
2009
|
+
return new ZodBoolean({
|
|
2010
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2011
|
+
coerce: params?.coerce || false,
|
|
2012
|
+
...processCreateParams(params)
|
|
2013
|
+
});
|
|
2014
|
+
};
|
|
2015
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
2016
|
+
_parse(input) {
|
|
2017
|
+
if (this._def.coerce) {
|
|
2018
|
+
input.data = new Date(input.data);
|
|
2019
|
+
}
|
|
2020
|
+
const parsedType = this._getType(input);
|
|
2021
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2022
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2023
|
+
addIssueToContext(ctx2, {
|
|
2024
|
+
code: ZodIssueCode.invalid_type,
|
|
2025
|
+
expected: ZodParsedType.date,
|
|
2026
|
+
received: ctx2.parsedType
|
|
2027
|
+
});
|
|
2028
|
+
return INVALID;
|
|
2029
|
+
}
|
|
2030
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2031
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2032
|
+
addIssueToContext(ctx2, {
|
|
2033
|
+
code: ZodIssueCode.invalid_date
|
|
2034
|
+
});
|
|
2035
|
+
return INVALID;
|
|
2036
|
+
}
|
|
2037
|
+
const status = new ParseStatus();
|
|
2038
|
+
let ctx = void 0;
|
|
2039
|
+
for (const check of this._def.checks) {
|
|
2040
|
+
if (check.kind === "min") {
|
|
2041
|
+
if (input.data.getTime() < check.value) {
|
|
2042
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2043
|
+
addIssueToContext(ctx, {
|
|
2044
|
+
code: ZodIssueCode.too_small,
|
|
2045
|
+
message: check.message,
|
|
2046
|
+
inclusive: true,
|
|
2047
|
+
exact: false,
|
|
2048
|
+
minimum: check.value,
|
|
2049
|
+
type: "date"
|
|
2050
|
+
});
|
|
2051
|
+
status.dirty();
|
|
2052
|
+
}
|
|
2053
|
+
} else if (check.kind === "max") {
|
|
2054
|
+
if (input.data.getTime() > check.value) {
|
|
2055
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2056
|
+
addIssueToContext(ctx, {
|
|
2057
|
+
code: ZodIssueCode.too_big,
|
|
2058
|
+
message: check.message,
|
|
2059
|
+
inclusive: true,
|
|
2060
|
+
exact: false,
|
|
2061
|
+
maximum: check.value,
|
|
2062
|
+
type: "date"
|
|
2063
|
+
});
|
|
2064
|
+
status.dirty();
|
|
2065
|
+
}
|
|
2066
|
+
} else {
|
|
2067
|
+
util.assertNever(check);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
return {
|
|
2071
|
+
status: status.value,
|
|
2072
|
+
value: new Date(input.data.getTime())
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
_addCheck(check) {
|
|
2076
|
+
return new _ZodDate({
|
|
2077
|
+
...this._def,
|
|
2078
|
+
checks: [...this._def.checks, check]
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2081
|
+
min(minDate, message) {
|
|
2082
|
+
return this._addCheck({
|
|
2083
|
+
kind: "min",
|
|
2084
|
+
value: minDate.getTime(),
|
|
2085
|
+
message: errorUtil.toString(message)
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
max(maxDate, message) {
|
|
2089
|
+
return this._addCheck({
|
|
2090
|
+
kind: "max",
|
|
2091
|
+
value: maxDate.getTime(),
|
|
2092
|
+
message: errorUtil.toString(message)
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
get minDate() {
|
|
2096
|
+
let min = null;
|
|
2097
|
+
for (const ch of this._def.checks) {
|
|
2098
|
+
if (ch.kind === "min") {
|
|
2099
|
+
if (min === null || ch.value > min)
|
|
2100
|
+
min = ch.value;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
return min != null ? new Date(min) : null;
|
|
2104
|
+
}
|
|
2105
|
+
get maxDate() {
|
|
2106
|
+
let max = null;
|
|
2107
|
+
for (const ch of this._def.checks) {
|
|
2108
|
+
if (ch.kind === "max") {
|
|
2109
|
+
if (max === null || ch.value < max)
|
|
2110
|
+
max = ch.value;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
return max != null ? new Date(max) : null;
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
ZodDate.create = (params) => {
|
|
2117
|
+
return new ZodDate({
|
|
2118
|
+
checks: [],
|
|
2119
|
+
coerce: params?.coerce || false,
|
|
2120
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2121
|
+
...processCreateParams(params)
|
|
2122
|
+
});
|
|
2123
|
+
};
|
|
2124
|
+
var ZodSymbol = class extends ZodType {
|
|
2125
|
+
_parse(input) {
|
|
2126
|
+
const parsedType = this._getType(input);
|
|
2127
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2128
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2129
|
+
addIssueToContext(ctx, {
|
|
2130
|
+
code: ZodIssueCode.invalid_type,
|
|
2131
|
+
expected: ZodParsedType.symbol,
|
|
2132
|
+
received: ctx.parsedType
|
|
2133
|
+
});
|
|
2134
|
+
return INVALID;
|
|
2135
|
+
}
|
|
2136
|
+
return OK(input.data);
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
ZodSymbol.create = (params) => {
|
|
2140
|
+
return new ZodSymbol({
|
|
2141
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2142
|
+
...processCreateParams(params)
|
|
2143
|
+
});
|
|
2144
|
+
};
|
|
2145
|
+
var ZodUndefined = class extends ZodType {
|
|
2146
|
+
_parse(input) {
|
|
2147
|
+
const parsedType = this._getType(input);
|
|
2148
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2149
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2150
|
+
addIssueToContext(ctx, {
|
|
2151
|
+
code: ZodIssueCode.invalid_type,
|
|
2152
|
+
expected: ZodParsedType.undefined,
|
|
2153
|
+
received: ctx.parsedType
|
|
2154
|
+
});
|
|
2155
|
+
return INVALID;
|
|
2156
|
+
}
|
|
2157
|
+
return OK(input.data);
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
ZodUndefined.create = (params) => {
|
|
2161
|
+
return new ZodUndefined({
|
|
2162
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2163
|
+
...processCreateParams(params)
|
|
2164
|
+
});
|
|
2165
|
+
};
|
|
2166
|
+
var ZodNull = class extends ZodType {
|
|
2167
|
+
_parse(input) {
|
|
2168
|
+
const parsedType = this._getType(input);
|
|
2169
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2170
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2171
|
+
addIssueToContext(ctx, {
|
|
2172
|
+
code: ZodIssueCode.invalid_type,
|
|
2173
|
+
expected: ZodParsedType.null,
|
|
2174
|
+
received: ctx.parsedType
|
|
2175
|
+
});
|
|
2176
|
+
return INVALID;
|
|
2177
|
+
}
|
|
2178
|
+
return OK(input.data);
|
|
2179
|
+
}
|
|
2180
|
+
};
|
|
2181
|
+
ZodNull.create = (params) => {
|
|
2182
|
+
return new ZodNull({
|
|
2183
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2184
|
+
...processCreateParams(params)
|
|
2185
|
+
});
|
|
2186
|
+
};
|
|
2187
|
+
var ZodAny = class extends ZodType {
|
|
2188
|
+
constructor() {
|
|
2189
|
+
super(...arguments);
|
|
2190
|
+
this._any = true;
|
|
2191
|
+
}
|
|
2192
|
+
_parse(input) {
|
|
2193
|
+
return OK(input.data);
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
2196
|
+
ZodAny.create = (params) => {
|
|
2197
|
+
return new ZodAny({
|
|
2198
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2199
|
+
...processCreateParams(params)
|
|
2200
|
+
});
|
|
2201
|
+
};
|
|
2202
|
+
var ZodUnknown = class extends ZodType {
|
|
2203
|
+
constructor() {
|
|
2204
|
+
super(...arguments);
|
|
2205
|
+
this._unknown = true;
|
|
2206
|
+
}
|
|
2207
|
+
_parse(input) {
|
|
2208
|
+
return OK(input.data);
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
ZodUnknown.create = (params) => {
|
|
2212
|
+
return new ZodUnknown({
|
|
2213
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2214
|
+
...processCreateParams(params)
|
|
2215
|
+
});
|
|
2216
|
+
};
|
|
2217
|
+
var ZodNever = class extends ZodType {
|
|
2218
|
+
_parse(input) {
|
|
2219
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2220
|
+
addIssueToContext(ctx, {
|
|
2221
|
+
code: ZodIssueCode.invalid_type,
|
|
2222
|
+
expected: ZodParsedType.never,
|
|
2223
|
+
received: ctx.parsedType
|
|
2224
|
+
});
|
|
2225
|
+
return INVALID;
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2228
|
+
ZodNever.create = (params) => {
|
|
2229
|
+
return new ZodNever({
|
|
2230
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2231
|
+
...processCreateParams(params)
|
|
2232
|
+
});
|
|
2233
|
+
};
|
|
2234
|
+
var ZodVoid = class extends ZodType {
|
|
2235
|
+
_parse(input) {
|
|
2236
|
+
const parsedType = this._getType(input);
|
|
2237
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2238
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2239
|
+
addIssueToContext(ctx, {
|
|
2240
|
+
code: ZodIssueCode.invalid_type,
|
|
2241
|
+
expected: ZodParsedType.void,
|
|
2242
|
+
received: ctx.parsedType
|
|
2243
|
+
});
|
|
2244
|
+
return INVALID;
|
|
2245
|
+
}
|
|
2246
|
+
return OK(input.data);
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
ZodVoid.create = (params) => {
|
|
2250
|
+
return new ZodVoid({
|
|
2251
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2252
|
+
...processCreateParams(params)
|
|
2253
|
+
});
|
|
2254
|
+
};
|
|
2255
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
2256
|
+
_parse(input) {
|
|
2257
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2258
|
+
const def = this._def;
|
|
2259
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2260
|
+
addIssueToContext(ctx, {
|
|
2261
|
+
code: ZodIssueCode.invalid_type,
|
|
2262
|
+
expected: ZodParsedType.array,
|
|
2263
|
+
received: ctx.parsedType
|
|
2264
|
+
});
|
|
2265
|
+
return INVALID;
|
|
2266
|
+
}
|
|
2267
|
+
if (def.exactLength !== null) {
|
|
2268
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2269
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2270
|
+
if (tooBig || tooSmall) {
|
|
2271
|
+
addIssueToContext(ctx, {
|
|
2272
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2273
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2274
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2275
|
+
type: "array",
|
|
2276
|
+
inclusive: true,
|
|
2277
|
+
exact: true,
|
|
2278
|
+
message: def.exactLength.message
|
|
2279
|
+
});
|
|
2280
|
+
status.dirty();
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
if (def.minLength !== null) {
|
|
2284
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2285
|
+
addIssueToContext(ctx, {
|
|
2286
|
+
code: ZodIssueCode.too_small,
|
|
2287
|
+
minimum: def.minLength.value,
|
|
2288
|
+
type: "array",
|
|
2289
|
+
inclusive: true,
|
|
2290
|
+
exact: false,
|
|
2291
|
+
message: def.minLength.message
|
|
2292
|
+
});
|
|
2293
|
+
status.dirty();
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
if (def.maxLength !== null) {
|
|
2297
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2298
|
+
addIssueToContext(ctx, {
|
|
2299
|
+
code: ZodIssueCode.too_big,
|
|
2300
|
+
maximum: def.maxLength.value,
|
|
2301
|
+
type: "array",
|
|
2302
|
+
inclusive: true,
|
|
2303
|
+
exact: false,
|
|
2304
|
+
message: def.maxLength.message
|
|
2305
|
+
});
|
|
2306
|
+
status.dirty();
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
if (ctx.common.async) {
|
|
2310
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
2311
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2312
|
+
})).then((result2) => {
|
|
2313
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
const result = [...ctx.data].map((item, i) => {
|
|
2317
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2318
|
+
});
|
|
2319
|
+
return ParseStatus.mergeArray(status, result);
|
|
2320
|
+
}
|
|
2321
|
+
get element() {
|
|
2322
|
+
return this._def.type;
|
|
2323
|
+
}
|
|
2324
|
+
min(minLength, message) {
|
|
2325
|
+
return new _ZodArray({
|
|
2326
|
+
...this._def,
|
|
2327
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
max(maxLength, message) {
|
|
2331
|
+
return new _ZodArray({
|
|
2332
|
+
...this._def,
|
|
2333
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
length(len, message) {
|
|
2337
|
+
return new _ZodArray({
|
|
2338
|
+
...this._def,
|
|
2339
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
nonempty(message) {
|
|
2343
|
+
return this.min(1, message);
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
ZodArray.create = (schema, params) => {
|
|
2347
|
+
return new ZodArray({
|
|
2348
|
+
type: schema,
|
|
2349
|
+
minLength: null,
|
|
2350
|
+
maxLength: null,
|
|
2351
|
+
exactLength: null,
|
|
2352
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2353
|
+
...processCreateParams(params)
|
|
2354
|
+
});
|
|
2355
|
+
};
|
|
2356
|
+
function deepPartialify(schema) {
|
|
2357
|
+
if (schema instanceof ZodObject) {
|
|
2358
|
+
const newShape = {};
|
|
2359
|
+
for (const key in schema.shape) {
|
|
2360
|
+
const fieldSchema = schema.shape[key];
|
|
2361
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2362
|
+
}
|
|
2363
|
+
return new ZodObject({
|
|
2364
|
+
...schema._def,
|
|
2365
|
+
shape: () => newShape
|
|
2366
|
+
});
|
|
2367
|
+
} else if (schema instanceof ZodArray) {
|
|
2368
|
+
return new ZodArray({
|
|
2369
|
+
...schema._def,
|
|
2370
|
+
type: deepPartialify(schema.element)
|
|
2371
|
+
});
|
|
2372
|
+
} else if (schema instanceof ZodOptional) {
|
|
2373
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2374
|
+
} else if (schema instanceof ZodNullable) {
|
|
2375
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2376
|
+
} else if (schema instanceof ZodTuple) {
|
|
2377
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2378
|
+
} else {
|
|
2379
|
+
return schema;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
2383
|
+
constructor() {
|
|
2384
|
+
super(...arguments);
|
|
2385
|
+
this._cached = null;
|
|
2386
|
+
this.nonstrict = this.passthrough;
|
|
2387
|
+
this.augment = this.extend;
|
|
2388
|
+
}
|
|
2389
|
+
_getCached() {
|
|
2390
|
+
if (this._cached !== null)
|
|
2391
|
+
return this._cached;
|
|
2392
|
+
const shape = this._def.shape();
|
|
2393
|
+
const keys = util.objectKeys(shape);
|
|
2394
|
+
this._cached = { shape, keys };
|
|
2395
|
+
return this._cached;
|
|
2396
|
+
}
|
|
2397
|
+
_parse(input) {
|
|
2398
|
+
const parsedType = this._getType(input);
|
|
2399
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2400
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2401
|
+
addIssueToContext(ctx2, {
|
|
2402
|
+
code: ZodIssueCode.invalid_type,
|
|
2403
|
+
expected: ZodParsedType.object,
|
|
2404
|
+
received: ctx2.parsedType
|
|
2405
|
+
});
|
|
2406
|
+
return INVALID;
|
|
2407
|
+
}
|
|
2408
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2409
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2410
|
+
const extraKeys = [];
|
|
2411
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2412
|
+
for (const key in ctx.data) {
|
|
2413
|
+
if (!shapeKeys.includes(key)) {
|
|
2414
|
+
extraKeys.push(key);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
const pairs = [];
|
|
2419
|
+
for (const key of shapeKeys) {
|
|
2420
|
+
const keyValidator = shape[key];
|
|
2421
|
+
const value = ctx.data[key];
|
|
2422
|
+
pairs.push({
|
|
2423
|
+
key: { status: "valid", value: key },
|
|
2424
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2425
|
+
alwaysSet: key in ctx.data
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2429
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2430
|
+
if (unknownKeys === "passthrough") {
|
|
2431
|
+
for (const key of extraKeys) {
|
|
2432
|
+
pairs.push({
|
|
2433
|
+
key: { status: "valid", value: key },
|
|
2434
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
} else if (unknownKeys === "strict") {
|
|
2438
|
+
if (extraKeys.length > 0) {
|
|
2439
|
+
addIssueToContext(ctx, {
|
|
2440
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2441
|
+
keys: extraKeys
|
|
2442
|
+
});
|
|
2443
|
+
status.dirty();
|
|
2444
|
+
}
|
|
2445
|
+
} else if (unknownKeys === "strip") ; else {
|
|
2446
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2447
|
+
}
|
|
2448
|
+
} else {
|
|
2449
|
+
const catchall = this._def.catchall;
|
|
2450
|
+
for (const key of extraKeys) {
|
|
2451
|
+
const value = ctx.data[key];
|
|
2452
|
+
pairs.push({
|
|
2453
|
+
key: { status: "valid", value: key },
|
|
2454
|
+
value: catchall._parse(
|
|
2455
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2456
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
2457
|
+
),
|
|
2458
|
+
alwaysSet: key in ctx.data
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
if (ctx.common.async) {
|
|
2463
|
+
return Promise.resolve().then(async () => {
|
|
2464
|
+
const syncPairs = [];
|
|
2465
|
+
for (const pair of pairs) {
|
|
2466
|
+
const key = await pair.key;
|
|
2467
|
+
const value = await pair.value;
|
|
2468
|
+
syncPairs.push({
|
|
2469
|
+
key,
|
|
2470
|
+
value,
|
|
2471
|
+
alwaysSet: pair.alwaysSet
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2474
|
+
return syncPairs;
|
|
2475
|
+
}).then((syncPairs) => {
|
|
2476
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2477
|
+
});
|
|
2478
|
+
} else {
|
|
2479
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
get shape() {
|
|
2483
|
+
return this._def.shape();
|
|
2484
|
+
}
|
|
2485
|
+
strict(message) {
|
|
2486
|
+
return new _ZodObject({
|
|
2487
|
+
...this._def,
|
|
2488
|
+
unknownKeys: "strict",
|
|
2489
|
+
...message !== void 0 ? {
|
|
2490
|
+
errorMap: (issue, ctx) => {
|
|
2491
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2492
|
+
if (issue.code === "unrecognized_keys")
|
|
2493
|
+
return {
|
|
2494
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2495
|
+
};
|
|
2496
|
+
return {
|
|
2497
|
+
message: defaultError
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
} : {}
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
strip() {
|
|
2504
|
+
return new _ZodObject({
|
|
2505
|
+
...this._def,
|
|
2506
|
+
unknownKeys: "strip"
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
passthrough() {
|
|
2510
|
+
return new _ZodObject({
|
|
2511
|
+
...this._def,
|
|
2512
|
+
unknownKeys: "passthrough"
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
// const AugmentFactory =
|
|
2516
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2517
|
+
// <Augmentation extends ZodRawShape>(
|
|
2518
|
+
// augmentation: Augmentation
|
|
2519
|
+
// ): ZodObject<
|
|
2520
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2521
|
+
// Def["unknownKeys"],
|
|
2522
|
+
// Def["catchall"]
|
|
2523
|
+
// > => {
|
|
2524
|
+
// return new ZodObject({
|
|
2525
|
+
// ...def,
|
|
2526
|
+
// shape: () => ({
|
|
2527
|
+
// ...def.shape(),
|
|
2528
|
+
// ...augmentation,
|
|
2529
|
+
// }),
|
|
2530
|
+
// }) as any;
|
|
2531
|
+
// };
|
|
2532
|
+
extend(augmentation) {
|
|
2533
|
+
return new _ZodObject({
|
|
2534
|
+
...this._def,
|
|
2535
|
+
shape: () => ({
|
|
2536
|
+
...this._def.shape(),
|
|
2537
|
+
...augmentation
|
|
2538
|
+
})
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
/**
|
|
2542
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2543
|
+
* inferred type of merged objects. Please
|
|
2544
|
+
* upgrade if you are experiencing issues.
|
|
2545
|
+
*/
|
|
2546
|
+
merge(merging) {
|
|
2547
|
+
const merged = new _ZodObject({
|
|
2548
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2549
|
+
catchall: merging._def.catchall,
|
|
2550
|
+
shape: () => ({
|
|
2551
|
+
...this._def.shape(),
|
|
2552
|
+
...merging._def.shape()
|
|
2553
|
+
}),
|
|
2554
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2555
|
+
});
|
|
2556
|
+
return merged;
|
|
2557
|
+
}
|
|
2558
|
+
// merge<
|
|
2559
|
+
// Incoming extends AnyZodObject,
|
|
2560
|
+
// Augmentation extends Incoming["shape"],
|
|
2561
|
+
// NewOutput extends {
|
|
2562
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2563
|
+
// ? Augmentation[k]["_output"]
|
|
2564
|
+
// : k extends keyof Output
|
|
2565
|
+
// ? Output[k]
|
|
2566
|
+
// : never;
|
|
2567
|
+
// },
|
|
2568
|
+
// NewInput extends {
|
|
2569
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2570
|
+
// ? Augmentation[k]["_input"]
|
|
2571
|
+
// : k extends keyof Input
|
|
2572
|
+
// ? Input[k]
|
|
2573
|
+
// : never;
|
|
2574
|
+
// }
|
|
2575
|
+
// >(
|
|
2576
|
+
// merging: Incoming
|
|
2577
|
+
// ): ZodObject<
|
|
2578
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2579
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2580
|
+
// Incoming["_def"]["catchall"],
|
|
2581
|
+
// NewOutput,
|
|
2582
|
+
// NewInput
|
|
2583
|
+
// > {
|
|
2584
|
+
// const merged: any = new ZodObject({
|
|
2585
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2586
|
+
// catchall: merging._def.catchall,
|
|
2587
|
+
// shape: () =>
|
|
2588
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2589
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2590
|
+
// }) as any;
|
|
2591
|
+
// return merged;
|
|
2592
|
+
// }
|
|
2593
|
+
setKey(key, schema) {
|
|
2594
|
+
return this.augment({ [key]: schema });
|
|
2595
|
+
}
|
|
2596
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2597
|
+
// merging: Incoming
|
|
2598
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2599
|
+
// ZodObject<
|
|
2600
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2601
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2602
|
+
// Incoming["_def"]["catchall"]
|
|
2603
|
+
// > {
|
|
2604
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2605
|
+
// // this._def.shape(),
|
|
2606
|
+
// // merging._def.shape()
|
|
2607
|
+
// // );
|
|
2608
|
+
// const merged: any = new ZodObject({
|
|
2609
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2610
|
+
// catchall: merging._def.catchall,
|
|
2611
|
+
// shape: () =>
|
|
2612
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2613
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2614
|
+
// }) as any;
|
|
2615
|
+
// return merged;
|
|
2616
|
+
// }
|
|
2617
|
+
catchall(index) {
|
|
2618
|
+
return new _ZodObject({
|
|
2619
|
+
...this._def,
|
|
2620
|
+
catchall: index
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
pick(mask) {
|
|
2624
|
+
const shape = {};
|
|
2625
|
+
for (const key of util.objectKeys(mask)) {
|
|
2626
|
+
if (mask[key] && this.shape[key]) {
|
|
2627
|
+
shape[key] = this.shape[key];
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
return new _ZodObject({
|
|
2631
|
+
...this._def,
|
|
2632
|
+
shape: () => shape
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2635
|
+
omit(mask) {
|
|
2636
|
+
const shape = {};
|
|
2637
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2638
|
+
if (!mask[key]) {
|
|
2639
|
+
shape[key] = this.shape[key];
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
return new _ZodObject({
|
|
2643
|
+
...this._def,
|
|
2644
|
+
shape: () => shape
|
|
2645
|
+
});
|
|
2646
|
+
}
|
|
2647
|
+
/**
|
|
2648
|
+
* @deprecated
|
|
2649
|
+
*/
|
|
2650
|
+
deepPartial() {
|
|
2651
|
+
return deepPartialify(this);
|
|
2652
|
+
}
|
|
2653
|
+
partial(mask) {
|
|
2654
|
+
const newShape = {};
|
|
2655
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2656
|
+
const fieldSchema = this.shape[key];
|
|
2657
|
+
if (mask && !mask[key]) {
|
|
2658
|
+
newShape[key] = fieldSchema;
|
|
2659
|
+
} else {
|
|
2660
|
+
newShape[key] = fieldSchema.optional();
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
return new _ZodObject({
|
|
2664
|
+
...this._def,
|
|
2665
|
+
shape: () => newShape
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
required(mask) {
|
|
2669
|
+
const newShape = {};
|
|
2670
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2671
|
+
if (mask && !mask[key]) {
|
|
2672
|
+
newShape[key] = this.shape[key];
|
|
2673
|
+
} else {
|
|
2674
|
+
const fieldSchema = this.shape[key];
|
|
2675
|
+
let newField = fieldSchema;
|
|
2676
|
+
while (newField instanceof ZodOptional) {
|
|
2677
|
+
newField = newField._def.innerType;
|
|
2678
|
+
}
|
|
2679
|
+
newShape[key] = newField;
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
return new _ZodObject({
|
|
2683
|
+
...this._def,
|
|
2684
|
+
shape: () => newShape
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
keyof() {
|
|
2688
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2691
|
+
ZodObject.create = (shape, params) => {
|
|
2692
|
+
return new ZodObject({
|
|
2693
|
+
shape: () => shape,
|
|
2694
|
+
unknownKeys: "strip",
|
|
2695
|
+
catchall: ZodNever.create(),
|
|
2696
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2697
|
+
...processCreateParams(params)
|
|
2698
|
+
});
|
|
2699
|
+
};
|
|
2700
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2701
|
+
return new ZodObject({
|
|
2702
|
+
shape: () => shape,
|
|
2703
|
+
unknownKeys: "strict",
|
|
2704
|
+
catchall: ZodNever.create(),
|
|
2705
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2706
|
+
...processCreateParams(params)
|
|
2707
|
+
});
|
|
2708
|
+
};
|
|
2709
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2710
|
+
return new ZodObject({
|
|
2711
|
+
shape,
|
|
2712
|
+
unknownKeys: "strip",
|
|
2713
|
+
catchall: ZodNever.create(),
|
|
2714
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2715
|
+
...processCreateParams(params)
|
|
2716
|
+
});
|
|
2717
|
+
};
|
|
2718
|
+
var ZodUnion = class extends ZodType {
|
|
2719
|
+
_parse(input) {
|
|
2720
|
+
const { ctx } = this._processInputParams(input);
|
|
2721
|
+
const options = this._def.options;
|
|
2722
|
+
function handleResults(results) {
|
|
2723
|
+
for (const result of results) {
|
|
2724
|
+
if (result.result.status === "valid") {
|
|
2725
|
+
return result.result;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
for (const result of results) {
|
|
2729
|
+
if (result.result.status === "dirty") {
|
|
2730
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2731
|
+
return result.result;
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2735
|
+
addIssueToContext(ctx, {
|
|
2736
|
+
code: ZodIssueCode.invalid_union,
|
|
2737
|
+
unionErrors
|
|
2738
|
+
});
|
|
2739
|
+
return INVALID;
|
|
2740
|
+
}
|
|
2741
|
+
if (ctx.common.async) {
|
|
2742
|
+
return Promise.all(options.map(async (option) => {
|
|
2743
|
+
const childCtx = {
|
|
2744
|
+
...ctx,
|
|
2745
|
+
common: {
|
|
2746
|
+
...ctx.common,
|
|
2747
|
+
issues: []
|
|
2748
|
+
},
|
|
2749
|
+
parent: null
|
|
2750
|
+
};
|
|
2751
|
+
return {
|
|
2752
|
+
result: await option._parseAsync({
|
|
2753
|
+
data: ctx.data,
|
|
2754
|
+
path: ctx.path,
|
|
2755
|
+
parent: childCtx
|
|
2756
|
+
}),
|
|
2757
|
+
ctx: childCtx
|
|
2758
|
+
};
|
|
2759
|
+
})).then(handleResults);
|
|
2760
|
+
} else {
|
|
2761
|
+
let dirty = void 0;
|
|
2762
|
+
const issues = [];
|
|
2763
|
+
for (const option of options) {
|
|
2764
|
+
const childCtx = {
|
|
2765
|
+
...ctx,
|
|
2766
|
+
common: {
|
|
2767
|
+
...ctx.common,
|
|
2768
|
+
issues: []
|
|
2769
|
+
},
|
|
2770
|
+
parent: null
|
|
2771
|
+
};
|
|
2772
|
+
const result = option._parseSync({
|
|
2773
|
+
data: ctx.data,
|
|
2774
|
+
path: ctx.path,
|
|
2775
|
+
parent: childCtx
|
|
2776
|
+
});
|
|
2777
|
+
if (result.status === "valid") {
|
|
2778
|
+
return result;
|
|
2779
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
2780
|
+
dirty = { result, ctx: childCtx };
|
|
2781
|
+
}
|
|
2782
|
+
if (childCtx.common.issues.length) {
|
|
2783
|
+
issues.push(childCtx.common.issues);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
if (dirty) {
|
|
2787
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2788
|
+
return dirty.result;
|
|
2789
|
+
}
|
|
2790
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
2791
|
+
addIssueToContext(ctx, {
|
|
2792
|
+
code: ZodIssueCode.invalid_union,
|
|
2793
|
+
unionErrors
|
|
2794
|
+
});
|
|
2795
|
+
return INVALID;
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
get options() {
|
|
2799
|
+
return this._def.options;
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
ZodUnion.create = (types, params) => {
|
|
2803
|
+
return new ZodUnion({
|
|
2804
|
+
options: types,
|
|
2805
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2806
|
+
...processCreateParams(params)
|
|
2807
|
+
});
|
|
2808
|
+
};
|
|
2809
|
+
var getDiscriminator = (type) => {
|
|
2810
|
+
if (type instanceof ZodLazy) {
|
|
2811
|
+
return getDiscriminator(type.schema);
|
|
2812
|
+
} else if (type instanceof ZodEffects) {
|
|
2813
|
+
return getDiscriminator(type.innerType());
|
|
2814
|
+
} else if (type instanceof ZodLiteral) {
|
|
2815
|
+
return [type.value];
|
|
2816
|
+
} else if (type instanceof ZodEnum) {
|
|
2817
|
+
return type.options;
|
|
2818
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
2819
|
+
return util.objectValues(type.enum);
|
|
2820
|
+
} else if (type instanceof ZodDefault) {
|
|
2821
|
+
return getDiscriminator(type._def.innerType);
|
|
2822
|
+
} else if (type instanceof ZodUndefined) {
|
|
2823
|
+
return [void 0];
|
|
2824
|
+
} else if (type instanceof ZodNull) {
|
|
2825
|
+
return [null];
|
|
2826
|
+
} else if (type instanceof ZodOptional) {
|
|
2827
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2828
|
+
} else if (type instanceof ZodNullable) {
|
|
2829
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
2830
|
+
} else if (type instanceof ZodBranded) {
|
|
2831
|
+
return getDiscriminator(type.unwrap());
|
|
2832
|
+
} else if (type instanceof ZodReadonly) {
|
|
2833
|
+
return getDiscriminator(type.unwrap());
|
|
2834
|
+
} else if (type instanceof ZodCatch) {
|
|
2835
|
+
return getDiscriminator(type._def.innerType);
|
|
2836
|
+
} else {
|
|
2837
|
+
return [];
|
|
2838
|
+
}
|
|
2839
|
+
};
|
|
2840
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
2841
|
+
_parse(input) {
|
|
2842
|
+
const { ctx } = this._processInputParams(input);
|
|
2843
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2844
|
+
addIssueToContext(ctx, {
|
|
2845
|
+
code: ZodIssueCode.invalid_type,
|
|
2846
|
+
expected: ZodParsedType.object,
|
|
2847
|
+
received: ctx.parsedType
|
|
2848
|
+
});
|
|
2849
|
+
return INVALID;
|
|
2850
|
+
}
|
|
2851
|
+
const discriminator = this.discriminator;
|
|
2852
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
2853
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
2854
|
+
if (!option) {
|
|
2855
|
+
addIssueToContext(ctx, {
|
|
2856
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2857
|
+
options: Array.from(this.optionsMap.keys()),
|
|
2858
|
+
path: [discriminator]
|
|
2859
|
+
});
|
|
2860
|
+
return INVALID;
|
|
2861
|
+
}
|
|
2862
|
+
if (ctx.common.async) {
|
|
2863
|
+
return option._parseAsync({
|
|
2864
|
+
data: ctx.data,
|
|
2865
|
+
path: ctx.path,
|
|
2866
|
+
parent: ctx
|
|
2867
|
+
});
|
|
2868
|
+
} else {
|
|
2869
|
+
return option._parseSync({
|
|
2870
|
+
data: ctx.data,
|
|
2871
|
+
path: ctx.path,
|
|
2872
|
+
parent: ctx
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
get discriminator() {
|
|
2877
|
+
return this._def.discriminator;
|
|
2878
|
+
}
|
|
2879
|
+
get options() {
|
|
2880
|
+
return this._def.options;
|
|
2881
|
+
}
|
|
2882
|
+
get optionsMap() {
|
|
2883
|
+
return this._def.optionsMap;
|
|
2884
|
+
}
|
|
2885
|
+
/**
|
|
2886
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2887
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2888
|
+
* have a different value for each object in the union.
|
|
2889
|
+
* @param discriminator the name of the discriminator property
|
|
2890
|
+
* @param types an array of object schemas
|
|
2891
|
+
* @param params
|
|
2892
|
+
*/
|
|
2893
|
+
static create(discriminator, options, params) {
|
|
2894
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
2895
|
+
for (const type of options) {
|
|
2896
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2897
|
+
if (!discriminatorValues.length) {
|
|
2898
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2899
|
+
}
|
|
2900
|
+
for (const value of discriminatorValues) {
|
|
2901
|
+
if (optionsMap.has(value)) {
|
|
2902
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2903
|
+
}
|
|
2904
|
+
optionsMap.set(value, type);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
return new _ZodDiscriminatedUnion({
|
|
2908
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2909
|
+
discriminator,
|
|
2910
|
+
options,
|
|
2911
|
+
optionsMap,
|
|
2912
|
+
...processCreateParams(params)
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
};
|
|
2916
|
+
function mergeValues(a, b) {
|
|
2917
|
+
const aType = getParsedType(a);
|
|
2918
|
+
const bType = getParsedType(b);
|
|
2919
|
+
if (a === b) {
|
|
2920
|
+
return { valid: true, data: a };
|
|
2921
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2922
|
+
const bKeys = util.objectKeys(b);
|
|
2923
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2924
|
+
const newObj = { ...a, ...b };
|
|
2925
|
+
for (const key of sharedKeys) {
|
|
2926
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
2927
|
+
if (!sharedValue.valid) {
|
|
2928
|
+
return { valid: false };
|
|
2929
|
+
}
|
|
2930
|
+
newObj[key] = sharedValue.data;
|
|
2931
|
+
}
|
|
2932
|
+
return { valid: true, data: newObj };
|
|
2933
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2934
|
+
if (a.length !== b.length) {
|
|
2935
|
+
return { valid: false };
|
|
2936
|
+
}
|
|
2937
|
+
const newArray = [];
|
|
2938
|
+
for (let index = 0; index < a.length; index++) {
|
|
2939
|
+
const itemA = a[index];
|
|
2940
|
+
const itemB = b[index];
|
|
2941
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
2942
|
+
if (!sharedValue.valid) {
|
|
2943
|
+
return { valid: false };
|
|
2944
|
+
}
|
|
2945
|
+
newArray.push(sharedValue.data);
|
|
2946
|
+
}
|
|
2947
|
+
return { valid: true, data: newArray };
|
|
2948
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
2949
|
+
return { valid: true, data: a };
|
|
2950
|
+
} else {
|
|
2951
|
+
return { valid: false };
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
var ZodIntersection = class extends ZodType {
|
|
2955
|
+
_parse(input) {
|
|
2956
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2957
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2958
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2959
|
+
return INVALID;
|
|
2960
|
+
}
|
|
2961
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2962
|
+
if (!merged.valid) {
|
|
2963
|
+
addIssueToContext(ctx, {
|
|
2964
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
2965
|
+
});
|
|
2966
|
+
return INVALID;
|
|
2967
|
+
}
|
|
2968
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
2969
|
+
status.dirty();
|
|
2970
|
+
}
|
|
2971
|
+
return { status: status.value, value: merged.data };
|
|
2972
|
+
};
|
|
2973
|
+
if (ctx.common.async) {
|
|
2974
|
+
return Promise.all([
|
|
2975
|
+
this._def.left._parseAsync({
|
|
2976
|
+
data: ctx.data,
|
|
2977
|
+
path: ctx.path,
|
|
2978
|
+
parent: ctx
|
|
2979
|
+
}),
|
|
2980
|
+
this._def.right._parseAsync({
|
|
2981
|
+
data: ctx.data,
|
|
2982
|
+
path: ctx.path,
|
|
2983
|
+
parent: ctx
|
|
2984
|
+
})
|
|
2985
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
2986
|
+
} else {
|
|
2987
|
+
return handleParsed(this._def.left._parseSync({
|
|
2988
|
+
data: ctx.data,
|
|
2989
|
+
path: ctx.path,
|
|
2990
|
+
parent: ctx
|
|
2991
|
+
}), this._def.right._parseSync({
|
|
2992
|
+
data: ctx.data,
|
|
2993
|
+
path: ctx.path,
|
|
2994
|
+
parent: ctx
|
|
2995
|
+
}));
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3000
|
+
return new ZodIntersection({
|
|
3001
|
+
left,
|
|
3002
|
+
right,
|
|
3003
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3004
|
+
...processCreateParams(params)
|
|
3005
|
+
});
|
|
3006
|
+
};
|
|
3007
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3008
|
+
_parse(input) {
|
|
3009
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3010
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3011
|
+
addIssueToContext(ctx, {
|
|
3012
|
+
code: ZodIssueCode.invalid_type,
|
|
3013
|
+
expected: ZodParsedType.array,
|
|
3014
|
+
received: ctx.parsedType
|
|
3015
|
+
});
|
|
3016
|
+
return INVALID;
|
|
3017
|
+
}
|
|
3018
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3019
|
+
addIssueToContext(ctx, {
|
|
3020
|
+
code: ZodIssueCode.too_small,
|
|
3021
|
+
minimum: this._def.items.length,
|
|
3022
|
+
inclusive: true,
|
|
3023
|
+
exact: false,
|
|
3024
|
+
type: "array"
|
|
3025
|
+
});
|
|
3026
|
+
return INVALID;
|
|
3027
|
+
}
|
|
3028
|
+
const rest = this._def.rest;
|
|
3029
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3030
|
+
addIssueToContext(ctx, {
|
|
3031
|
+
code: ZodIssueCode.too_big,
|
|
3032
|
+
maximum: this._def.items.length,
|
|
3033
|
+
inclusive: true,
|
|
3034
|
+
exact: false,
|
|
3035
|
+
type: "array"
|
|
3036
|
+
});
|
|
3037
|
+
status.dirty();
|
|
3038
|
+
}
|
|
3039
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3040
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3041
|
+
if (!schema)
|
|
3042
|
+
return null;
|
|
3043
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3044
|
+
}).filter((x) => !!x);
|
|
3045
|
+
if (ctx.common.async) {
|
|
3046
|
+
return Promise.all(items).then((results) => {
|
|
3047
|
+
return ParseStatus.mergeArray(status, results);
|
|
3048
|
+
});
|
|
3049
|
+
} else {
|
|
3050
|
+
return ParseStatus.mergeArray(status, items);
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
get items() {
|
|
3054
|
+
return this._def.items;
|
|
3055
|
+
}
|
|
3056
|
+
rest(rest) {
|
|
3057
|
+
return new _ZodTuple({
|
|
3058
|
+
...this._def,
|
|
3059
|
+
rest
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
};
|
|
3063
|
+
ZodTuple.create = (schemas, params) => {
|
|
3064
|
+
if (!Array.isArray(schemas)) {
|
|
3065
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3066
|
+
}
|
|
3067
|
+
return new ZodTuple({
|
|
3068
|
+
items: schemas,
|
|
3069
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3070
|
+
rest: null,
|
|
3071
|
+
...processCreateParams(params)
|
|
3072
|
+
});
|
|
3073
|
+
};
|
|
3074
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3075
|
+
get keySchema() {
|
|
3076
|
+
return this._def.keyType;
|
|
3077
|
+
}
|
|
3078
|
+
get valueSchema() {
|
|
3079
|
+
return this._def.valueType;
|
|
3080
|
+
}
|
|
3081
|
+
_parse(input) {
|
|
3082
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3083
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3084
|
+
addIssueToContext(ctx, {
|
|
3085
|
+
code: ZodIssueCode.invalid_type,
|
|
3086
|
+
expected: ZodParsedType.object,
|
|
3087
|
+
received: ctx.parsedType
|
|
3088
|
+
});
|
|
3089
|
+
return INVALID;
|
|
3090
|
+
}
|
|
3091
|
+
const pairs = [];
|
|
3092
|
+
const keyType = this._def.keyType;
|
|
3093
|
+
const valueType = this._def.valueType;
|
|
3094
|
+
for (const key in ctx.data) {
|
|
3095
|
+
pairs.push({
|
|
3096
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3097
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3098
|
+
alwaysSet: key in ctx.data
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
if (ctx.common.async) {
|
|
3102
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3103
|
+
} else {
|
|
3104
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
get element() {
|
|
3108
|
+
return this._def.valueType;
|
|
3109
|
+
}
|
|
3110
|
+
static create(first, second, third) {
|
|
3111
|
+
if (second instanceof ZodType) {
|
|
3112
|
+
return new _ZodRecord({
|
|
3113
|
+
keyType: first,
|
|
3114
|
+
valueType: second,
|
|
3115
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3116
|
+
...processCreateParams(third)
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
return new _ZodRecord({
|
|
3120
|
+
keyType: ZodString.create(),
|
|
3121
|
+
valueType: first,
|
|
3122
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3123
|
+
...processCreateParams(second)
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
};
|
|
3127
|
+
var ZodMap = class extends ZodType {
|
|
3128
|
+
get keySchema() {
|
|
3129
|
+
return this._def.keyType;
|
|
3130
|
+
}
|
|
3131
|
+
get valueSchema() {
|
|
3132
|
+
return this._def.valueType;
|
|
3133
|
+
}
|
|
3134
|
+
_parse(input) {
|
|
3135
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3136
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3137
|
+
addIssueToContext(ctx, {
|
|
3138
|
+
code: ZodIssueCode.invalid_type,
|
|
3139
|
+
expected: ZodParsedType.map,
|
|
3140
|
+
received: ctx.parsedType
|
|
3141
|
+
});
|
|
3142
|
+
return INVALID;
|
|
3143
|
+
}
|
|
3144
|
+
const keyType = this._def.keyType;
|
|
3145
|
+
const valueType = this._def.valueType;
|
|
3146
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3147
|
+
return {
|
|
3148
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3149
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3150
|
+
};
|
|
3151
|
+
});
|
|
3152
|
+
if (ctx.common.async) {
|
|
3153
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3154
|
+
return Promise.resolve().then(async () => {
|
|
3155
|
+
for (const pair of pairs) {
|
|
3156
|
+
const key = await pair.key;
|
|
3157
|
+
const value = await pair.value;
|
|
3158
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3159
|
+
return INVALID;
|
|
3160
|
+
}
|
|
3161
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3162
|
+
status.dirty();
|
|
3163
|
+
}
|
|
3164
|
+
finalMap.set(key.value, value.value);
|
|
3165
|
+
}
|
|
3166
|
+
return { status: status.value, value: finalMap };
|
|
3167
|
+
});
|
|
3168
|
+
} else {
|
|
3169
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3170
|
+
for (const pair of pairs) {
|
|
3171
|
+
const key = pair.key;
|
|
3172
|
+
const value = pair.value;
|
|
3173
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3174
|
+
return INVALID;
|
|
3175
|
+
}
|
|
3176
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3177
|
+
status.dirty();
|
|
3178
|
+
}
|
|
3179
|
+
finalMap.set(key.value, value.value);
|
|
3180
|
+
}
|
|
3181
|
+
return { status: status.value, value: finalMap };
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
};
|
|
3185
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3186
|
+
return new ZodMap({
|
|
3187
|
+
valueType,
|
|
3188
|
+
keyType,
|
|
3189
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3190
|
+
...processCreateParams(params)
|
|
3191
|
+
});
|
|
3192
|
+
};
|
|
3193
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
3194
|
+
_parse(input) {
|
|
3195
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3196
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3197
|
+
addIssueToContext(ctx, {
|
|
3198
|
+
code: ZodIssueCode.invalid_type,
|
|
3199
|
+
expected: ZodParsedType.set,
|
|
3200
|
+
received: ctx.parsedType
|
|
3201
|
+
});
|
|
3202
|
+
return INVALID;
|
|
3203
|
+
}
|
|
3204
|
+
const def = this._def;
|
|
3205
|
+
if (def.minSize !== null) {
|
|
3206
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3207
|
+
addIssueToContext(ctx, {
|
|
3208
|
+
code: ZodIssueCode.too_small,
|
|
3209
|
+
minimum: def.minSize.value,
|
|
3210
|
+
type: "set",
|
|
3211
|
+
inclusive: true,
|
|
3212
|
+
exact: false,
|
|
3213
|
+
message: def.minSize.message
|
|
3214
|
+
});
|
|
3215
|
+
status.dirty();
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
if (def.maxSize !== null) {
|
|
3219
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3220
|
+
addIssueToContext(ctx, {
|
|
3221
|
+
code: ZodIssueCode.too_big,
|
|
3222
|
+
maximum: def.maxSize.value,
|
|
3223
|
+
type: "set",
|
|
3224
|
+
inclusive: true,
|
|
3225
|
+
exact: false,
|
|
3226
|
+
message: def.maxSize.message
|
|
3227
|
+
});
|
|
3228
|
+
status.dirty();
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
const valueType = this._def.valueType;
|
|
3232
|
+
function finalizeSet(elements2) {
|
|
3233
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
3234
|
+
for (const element of elements2) {
|
|
3235
|
+
if (element.status === "aborted")
|
|
3236
|
+
return INVALID;
|
|
3237
|
+
if (element.status === "dirty")
|
|
3238
|
+
status.dirty();
|
|
3239
|
+
parsedSet.add(element.value);
|
|
3240
|
+
}
|
|
3241
|
+
return { status: status.value, value: parsedSet };
|
|
3242
|
+
}
|
|
3243
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3244
|
+
if (ctx.common.async) {
|
|
3245
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3246
|
+
} else {
|
|
3247
|
+
return finalizeSet(elements);
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
min(minSize, message) {
|
|
3251
|
+
return new _ZodSet({
|
|
3252
|
+
...this._def,
|
|
3253
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3254
|
+
});
|
|
3255
|
+
}
|
|
3256
|
+
max(maxSize, message) {
|
|
3257
|
+
return new _ZodSet({
|
|
3258
|
+
...this._def,
|
|
3259
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3260
|
+
});
|
|
3261
|
+
}
|
|
3262
|
+
size(size, message) {
|
|
3263
|
+
return this.min(size, message).max(size, message);
|
|
3264
|
+
}
|
|
3265
|
+
nonempty(message) {
|
|
3266
|
+
return this.min(1, message);
|
|
3267
|
+
}
|
|
3268
|
+
};
|
|
3269
|
+
ZodSet.create = (valueType, params) => {
|
|
3270
|
+
return new ZodSet({
|
|
3271
|
+
valueType,
|
|
3272
|
+
minSize: null,
|
|
3273
|
+
maxSize: null,
|
|
3274
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3275
|
+
...processCreateParams(params)
|
|
3276
|
+
});
|
|
3277
|
+
};
|
|
3278
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3279
|
+
constructor() {
|
|
3280
|
+
super(...arguments);
|
|
3281
|
+
this.validate = this.implement;
|
|
3282
|
+
}
|
|
3283
|
+
_parse(input) {
|
|
3284
|
+
const { ctx } = this._processInputParams(input);
|
|
3285
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3286
|
+
addIssueToContext(ctx, {
|
|
3287
|
+
code: ZodIssueCode.invalid_type,
|
|
3288
|
+
expected: ZodParsedType.function,
|
|
3289
|
+
received: ctx.parsedType
|
|
3290
|
+
});
|
|
3291
|
+
return INVALID;
|
|
3292
|
+
}
|
|
3293
|
+
function makeArgsIssue(args, error) {
|
|
3294
|
+
return makeIssue({
|
|
3295
|
+
data: args,
|
|
3296
|
+
path: ctx.path,
|
|
3297
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3298
|
+
issueData: {
|
|
3299
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3300
|
+
argumentsError: error
|
|
3301
|
+
}
|
|
3302
|
+
});
|
|
3303
|
+
}
|
|
3304
|
+
function makeReturnsIssue(returns, error) {
|
|
3305
|
+
return makeIssue({
|
|
3306
|
+
data: returns,
|
|
3307
|
+
path: ctx.path,
|
|
3308
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3309
|
+
issueData: {
|
|
3310
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3311
|
+
returnTypeError: error
|
|
3312
|
+
}
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3315
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3316
|
+
const fn = ctx.data;
|
|
3317
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3318
|
+
const me = this;
|
|
3319
|
+
return OK(async function(...args) {
|
|
3320
|
+
const error = new ZodError([]);
|
|
3321
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3322
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
3323
|
+
throw error;
|
|
3324
|
+
});
|
|
3325
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3326
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3327
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
3328
|
+
throw error;
|
|
3329
|
+
});
|
|
3330
|
+
return parsedReturns;
|
|
3331
|
+
});
|
|
3332
|
+
} else {
|
|
3333
|
+
const me = this;
|
|
3334
|
+
return OK(function(...args) {
|
|
3335
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3336
|
+
if (!parsedArgs.success) {
|
|
3337
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3338
|
+
}
|
|
3339
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3340
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3341
|
+
if (!parsedReturns.success) {
|
|
3342
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3343
|
+
}
|
|
3344
|
+
return parsedReturns.data;
|
|
3345
|
+
});
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
parameters() {
|
|
3349
|
+
return this._def.args;
|
|
3350
|
+
}
|
|
3351
|
+
returnType() {
|
|
3352
|
+
return this._def.returns;
|
|
3353
|
+
}
|
|
3354
|
+
args(...items) {
|
|
3355
|
+
return new _ZodFunction({
|
|
3356
|
+
...this._def,
|
|
3357
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3358
|
+
});
|
|
3359
|
+
}
|
|
3360
|
+
returns(returnType) {
|
|
3361
|
+
return new _ZodFunction({
|
|
3362
|
+
...this._def,
|
|
3363
|
+
returns: returnType
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
implement(func) {
|
|
3367
|
+
const validatedFunc = this.parse(func);
|
|
3368
|
+
return validatedFunc;
|
|
3369
|
+
}
|
|
3370
|
+
strictImplement(func) {
|
|
3371
|
+
const validatedFunc = this.parse(func);
|
|
3372
|
+
return validatedFunc;
|
|
3373
|
+
}
|
|
3374
|
+
static create(args, returns, params) {
|
|
3375
|
+
return new _ZodFunction({
|
|
3376
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3377
|
+
returns: returns || ZodUnknown.create(),
|
|
3378
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3379
|
+
...processCreateParams(params)
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
};
|
|
3383
|
+
var ZodLazy = class extends ZodType {
|
|
3384
|
+
get schema() {
|
|
3385
|
+
return this._def.getter();
|
|
3386
|
+
}
|
|
3387
|
+
_parse(input) {
|
|
3388
|
+
const { ctx } = this._processInputParams(input);
|
|
3389
|
+
const lazySchema = this._def.getter();
|
|
3390
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
ZodLazy.create = (getter, params) => {
|
|
3394
|
+
return new ZodLazy({
|
|
3395
|
+
getter,
|
|
3396
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3397
|
+
...processCreateParams(params)
|
|
3398
|
+
});
|
|
3399
|
+
};
|
|
3400
|
+
var ZodLiteral = class extends ZodType {
|
|
3401
|
+
_parse(input) {
|
|
3402
|
+
if (input.data !== this._def.value) {
|
|
3403
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3404
|
+
addIssueToContext(ctx, {
|
|
3405
|
+
received: ctx.data,
|
|
3406
|
+
code: ZodIssueCode.invalid_literal,
|
|
3407
|
+
expected: this._def.value
|
|
3408
|
+
});
|
|
3409
|
+
return INVALID;
|
|
3410
|
+
}
|
|
3411
|
+
return { status: "valid", value: input.data };
|
|
3412
|
+
}
|
|
3413
|
+
get value() {
|
|
3414
|
+
return this._def.value;
|
|
3415
|
+
}
|
|
3416
|
+
};
|
|
3417
|
+
ZodLiteral.create = (value, params) => {
|
|
3418
|
+
return new ZodLiteral({
|
|
3419
|
+
value,
|
|
3420
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3421
|
+
...processCreateParams(params)
|
|
3422
|
+
});
|
|
3423
|
+
};
|
|
3424
|
+
function createZodEnum(values, params) {
|
|
3425
|
+
return new ZodEnum({
|
|
3426
|
+
values,
|
|
3427
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3428
|
+
...processCreateParams(params)
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3432
|
+
_parse(input) {
|
|
3433
|
+
if (typeof input.data !== "string") {
|
|
3434
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3435
|
+
const expectedValues = this._def.values;
|
|
3436
|
+
addIssueToContext(ctx, {
|
|
3437
|
+
expected: util.joinValues(expectedValues),
|
|
3438
|
+
received: ctx.parsedType,
|
|
3439
|
+
code: ZodIssueCode.invalid_type
|
|
3440
|
+
});
|
|
3441
|
+
return INVALID;
|
|
3442
|
+
}
|
|
3443
|
+
if (!this._cache) {
|
|
3444
|
+
this._cache = new Set(this._def.values);
|
|
3445
|
+
}
|
|
3446
|
+
if (!this._cache.has(input.data)) {
|
|
3447
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3448
|
+
const expectedValues = this._def.values;
|
|
3449
|
+
addIssueToContext(ctx, {
|
|
3450
|
+
received: ctx.data,
|
|
3451
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3452
|
+
options: expectedValues
|
|
3453
|
+
});
|
|
3454
|
+
return INVALID;
|
|
3455
|
+
}
|
|
3456
|
+
return OK(input.data);
|
|
3457
|
+
}
|
|
3458
|
+
get options() {
|
|
3459
|
+
return this._def.values;
|
|
3460
|
+
}
|
|
3461
|
+
get enum() {
|
|
3462
|
+
const enumValues = {};
|
|
3463
|
+
for (const val of this._def.values) {
|
|
3464
|
+
enumValues[val] = val;
|
|
3465
|
+
}
|
|
3466
|
+
return enumValues;
|
|
3467
|
+
}
|
|
3468
|
+
get Values() {
|
|
3469
|
+
const enumValues = {};
|
|
3470
|
+
for (const val of this._def.values) {
|
|
3471
|
+
enumValues[val] = val;
|
|
3472
|
+
}
|
|
3473
|
+
return enumValues;
|
|
3474
|
+
}
|
|
3475
|
+
get Enum() {
|
|
3476
|
+
const enumValues = {};
|
|
3477
|
+
for (const val of this._def.values) {
|
|
3478
|
+
enumValues[val] = val;
|
|
3479
|
+
}
|
|
3480
|
+
return enumValues;
|
|
3481
|
+
}
|
|
3482
|
+
extract(values, newDef = this._def) {
|
|
3483
|
+
return _ZodEnum.create(values, {
|
|
3484
|
+
...this._def,
|
|
3485
|
+
...newDef
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
exclude(values, newDef = this._def) {
|
|
3489
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3490
|
+
...this._def,
|
|
3491
|
+
...newDef
|
|
3492
|
+
});
|
|
3493
|
+
}
|
|
3494
|
+
};
|
|
3495
|
+
ZodEnum.create = createZodEnum;
|
|
3496
|
+
var ZodNativeEnum = class extends ZodType {
|
|
3497
|
+
_parse(input) {
|
|
3498
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3499
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3500
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3501
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3502
|
+
addIssueToContext(ctx, {
|
|
3503
|
+
expected: util.joinValues(expectedValues),
|
|
3504
|
+
received: ctx.parsedType,
|
|
3505
|
+
code: ZodIssueCode.invalid_type
|
|
3506
|
+
});
|
|
3507
|
+
return INVALID;
|
|
3508
|
+
}
|
|
3509
|
+
if (!this._cache) {
|
|
3510
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3511
|
+
}
|
|
3512
|
+
if (!this._cache.has(input.data)) {
|
|
3513
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3514
|
+
addIssueToContext(ctx, {
|
|
3515
|
+
received: ctx.data,
|
|
3516
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3517
|
+
options: expectedValues
|
|
3518
|
+
});
|
|
3519
|
+
return INVALID;
|
|
3520
|
+
}
|
|
3521
|
+
return OK(input.data);
|
|
3522
|
+
}
|
|
3523
|
+
get enum() {
|
|
3524
|
+
return this._def.values;
|
|
3525
|
+
}
|
|
3526
|
+
};
|
|
3527
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3528
|
+
return new ZodNativeEnum({
|
|
3529
|
+
values,
|
|
3530
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3531
|
+
...processCreateParams(params)
|
|
3532
|
+
});
|
|
3533
|
+
};
|
|
3534
|
+
var ZodPromise = class extends ZodType {
|
|
3535
|
+
unwrap() {
|
|
3536
|
+
return this._def.type;
|
|
3537
|
+
}
|
|
3538
|
+
_parse(input) {
|
|
3539
|
+
const { ctx } = this._processInputParams(input);
|
|
3540
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3541
|
+
addIssueToContext(ctx, {
|
|
3542
|
+
code: ZodIssueCode.invalid_type,
|
|
3543
|
+
expected: ZodParsedType.promise,
|
|
3544
|
+
received: ctx.parsedType
|
|
3545
|
+
});
|
|
3546
|
+
return INVALID;
|
|
3547
|
+
}
|
|
3548
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3549
|
+
return OK(promisified.then((data) => {
|
|
3550
|
+
return this._def.type.parseAsync(data, {
|
|
3551
|
+
path: ctx.path,
|
|
3552
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3553
|
+
});
|
|
3554
|
+
}));
|
|
3555
|
+
}
|
|
3556
|
+
};
|
|
3557
|
+
ZodPromise.create = (schema, params) => {
|
|
3558
|
+
return new ZodPromise({
|
|
3559
|
+
type: schema,
|
|
3560
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3561
|
+
...processCreateParams(params)
|
|
3562
|
+
});
|
|
3563
|
+
};
|
|
3564
|
+
var ZodEffects = class extends ZodType {
|
|
3565
|
+
innerType() {
|
|
3566
|
+
return this._def.schema;
|
|
3567
|
+
}
|
|
3568
|
+
sourceType() {
|
|
3569
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3570
|
+
}
|
|
3571
|
+
_parse(input) {
|
|
3572
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3573
|
+
const effect = this._def.effect || null;
|
|
3574
|
+
const checkCtx = {
|
|
3575
|
+
addIssue: (arg) => {
|
|
3576
|
+
addIssueToContext(ctx, arg);
|
|
3577
|
+
if (arg.fatal) {
|
|
3578
|
+
status.abort();
|
|
3579
|
+
} else {
|
|
3580
|
+
status.dirty();
|
|
3581
|
+
}
|
|
3582
|
+
},
|
|
3583
|
+
get path() {
|
|
3584
|
+
return ctx.path;
|
|
3585
|
+
}
|
|
3586
|
+
};
|
|
3587
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3588
|
+
if (effect.type === "preprocess") {
|
|
3589
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3590
|
+
if (ctx.common.async) {
|
|
3591
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3592
|
+
if (status.value === "aborted")
|
|
3593
|
+
return INVALID;
|
|
3594
|
+
const result = await this._def.schema._parseAsync({
|
|
3595
|
+
data: processed2,
|
|
3596
|
+
path: ctx.path,
|
|
3597
|
+
parent: ctx
|
|
3598
|
+
});
|
|
3599
|
+
if (result.status === "aborted")
|
|
3600
|
+
return INVALID;
|
|
3601
|
+
if (result.status === "dirty")
|
|
3602
|
+
return DIRTY(result.value);
|
|
3603
|
+
if (status.value === "dirty")
|
|
3604
|
+
return DIRTY(result.value);
|
|
3605
|
+
return result;
|
|
3606
|
+
});
|
|
3607
|
+
} else {
|
|
3608
|
+
if (status.value === "aborted")
|
|
3609
|
+
return INVALID;
|
|
3610
|
+
const result = this._def.schema._parseSync({
|
|
3611
|
+
data: processed,
|
|
3612
|
+
path: ctx.path,
|
|
3613
|
+
parent: ctx
|
|
3614
|
+
});
|
|
3615
|
+
if (result.status === "aborted")
|
|
3616
|
+
return INVALID;
|
|
3617
|
+
if (result.status === "dirty")
|
|
3618
|
+
return DIRTY(result.value);
|
|
3619
|
+
if (status.value === "dirty")
|
|
3620
|
+
return DIRTY(result.value);
|
|
3621
|
+
return result;
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
if (effect.type === "refinement") {
|
|
3625
|
+
const executeRefinement = (acc) => {
|
|
3626
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3627
|
+
if (ctx.common.async) {
|
|
3628
|
+
return Promise.resolve(result);
|
|
3629
|
+
}
|
|
3630
|
+
if (result instanceof Promise) {
|
|
3631
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3632
|
+
}
|
|
3633
|
+
return acc;
|
|
3634
|
+
};
|
|
3635
|
+
if (ctx.common.async === false) {
|
|
3636
|
+
const inner = this._def.schema._parseSync({
|
|
3637
|
+
data: ctx.data,
|
|
3638
|
+
path: ctx.path,
|
|
3639
|
+
parent: ctx
|
|
3640
|
+
});
|
|
3641
|
+
if (inner.status === "aborted")
|
|
3642
|
+
return INVALID;
|
|
3643
|
+
if (inner.status === "dirty")
|
|
3644
|
+
status.dirty();
|
|
3645
|
+
executeRefinement(inner.value);
|
|
3646
|
+
return { status: status.value, value: inner.value };
|
|
3647
|
+
} else {
|
|
3648
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3649
|
+
if (inner.status === "aborted")
|
|
3650
|
+
return INVALID;
|
|
3651
|
+
if (inner.status === "dirty")
|
|
3652
|
+
status.dirty();
|
|
3653
|
+
return executeRefinement(inner.value).then(() => {
|
|
3654
|
+
return { status: status.value, value: inner.value };
|
|
3655
|
+
});
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
if (effect.type === "transform") {
|
|
3660
|
+
if (ctx.common.async === false) {
|
|
3661
|
+
const base = this._def.schema._parseSync({
|
|
3662
|
+
data: ctx.data,
|
|
3663
|
+
path: ctx.path,
|
|
3664
|
+
parent: ctx
|
|
3665
|
+
});
|
|
3666
|
+
if (!isValid(base))
|
|
3667
|
+
return INVALID;
|
|
3668
|
+
const result = effect.transform(base.value, checkCtx);
|
|
3669
|
+
if (result instanceof Promise) {
|
|
3670
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3671
|
+
}
|
|
3672
|
+
return { status: status.value, value: result };
|
|
3673
|
+
} else {
|
|
3674
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
3675
|
+
if (!isValid(base))
|
|
3676
|
+
return INVALID;
|
|
3677
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3678
|
+
status: status.value,
|
|
3679
|
+
value: result
|
|
3680
|
+
}));
|
|
3681
|
+
});
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
util.assertNever(effect);
|
|
3685
|
+
}
|
|
3686
|
+
};
|
|
3687
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
3688
|
+
return new ZodEffects({
|
|
3689
|
+
schema,
|
|
3690
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3691
|
+
effect,
|
|
3692
|
+
...processCreateParams(params)
|
|
3693
|
+
});
|
|
3694
|
+
};
|
|
3695
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3696
|
+
return new ZodEffects({
|
|
3697
|
+
schema,
|
|
3698
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
3699
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3700
|
+
...processCreateParams(params)
|
|
3701
|
+
});
|
|
3702
|
+
};
|
|
3703
|
+
var ZodOptional = class extends ZodType {
|
|
3704
|
+
_parse(input) {
|
|
3705
|
+
const parsedType = this._getType(input);
|
|
3706
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
3707
|
+
return OK(void 0);
|
|
3708
|
+
}
|
|
3709
|
+
return this._def.innerType._parse(input);
|
|
3710
|
+
}
|
|
3711
|
+
unwrap() {
|
|
3712
|
+
return this._def.innerType;
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
ZodOptional.create = (type, params) => {
|
|
3716
|
+
return new ZodOptional({
|
|
3717
|
+
innerType: type,
|
|
3718
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3719
|
+
...processCreateParams(params)
|
|
3720
|
+
});
|
|
3721
|
+
};
|
|
3722
|
+
var ZodNullable = class extends ZodType {
|
|
3723
|
+
_parse(input) {
|
|
3724
|
+
const parsedType = this._getType(input);
|
|
3725
|
+
if (parsedType === ZodParsedType.null) {
|
|
3726
|
+
return OK(null);
|
|
3727
|
+
}
|
|
3728
|
+
return this._def.innerType._parse(input);
|
|
3729
|
+
}
|
|
3730
|
+
unwrap() {
|
|
3731
|
+
return this._def.innerType;
|
|
3732
|
+
}
|
|
3733
|
+
};
|
|
3734
|
+
ZodNullable.create = (type, params) => {
|
|
3735
|
+
return new ZodNullable({
|
|
3736
|
+
innerType: type,
|
|
3737
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3738
|
+
...processCreateParams(params)
|
|
3739
|
+
});
|
|
3740
|
+
};
|
|
3741
|
+
var ZodDefault = class extends ZodType {
|
|
3742
|
+
_parse(input) {
|
|
3743
|
+
const { ctx } = this._processInputParams(input);
|
|
3744
|
+
let data = ctx.data;
|
|
3745
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3746
|
+
data = this._def.defaultValue();
|
|
3747
|
+
}
|
|
3748
|
+
return this._def.innerType._parse({
|
|
3749
|
+
data,
|
|
3750
|
+
path: ctx.path,
|
|
3751
|
+
parent: ctx
|
|
3752
|
+
});
|
|
3753
|
+
}
|
|
3754
|
+
removeDefault() {
|
|
3755
|
+
return this._def.innerType;
|
|
3756
|
+
}
|
|
3757
|
+
};
|
|
3758
|
+
ZodDefault.create = (type, params) => {
|
|
3759
|
+
return new ZodDefault({
|
|
3760
|
+
innerType: type,
|
|
3761
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3762
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3763
|
+
...processCreateParams(params)
|
|
3764
|
+
});
|
|
3765
|
+
};
|
|
3766
|
+
var ZodCatch = class extends ZodType {
|
|
3767
|
+
_parse(input) {
|
|
3768
|
+
const { ctx } = this._processInputParams(input);
|
|
3769
|
+
const newCtx = {
|
|
3770
|
+
...ctx,
|
|
3771
|
+
common: {
|
|
3772
|
+
...ctx.common,
|
|
3773
|
+
issues: []
|
|
3774
|
+
}
|
|
3775
|
+
};
|
|
3776
|
+
const result = this._def.innerType._parse({
|
|
3777
|
+
data: newCtx.data,
|
|
3778
|
+
path: newCtx.path,
|
|
3779
|
+
parent: {
|
|
3780
|
+
...newCtx
|
|
3781
|
+
}
|
|
3782
|
+
});
|
|
3783
|
+
if (isAsync(result)) {
|
|
3784
|
+
return result.then((result2) => {
|
|
3785
|
+
return {
|
|
3786
|
+
status: "valid",
|
|
3787
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
3788
|
+
get error() {
|
|
3789
|
+
return new ZodError(newCtx.common.issues);
|
|
3790
|
+
},
|
|
3791
|
+
input: newCtx.data
|
|
3792
|
+
})
|
|
3793
|
+
};
|
|
3794
|
+
});
|
|
3795
|
+
} else {
|
|
3796
|
+
return {
|
|
3797
|
+
status: "valid",
|
|
3798
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3799
|
+
get error() {
|
|
3800
|
+
return new ZodError(newCtx.common.issues);
|
|
3801
|
+
},
|
|
3802
|
+
input: newCtx.data
|
|
3803
|
+
})
|
|
3804
|
+
};
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
removeCatch() {
|
|
3808
|
+
return this._def.innerType;
|
|
3809
|
+
}
|
|
3810
|
+
};
|
|
3811
|
+
ZodCatch.create = (type, params) => {
|
|
3812
|
+
return new ZodCatch({
|
|
3813
|
+
innerType: type,
|
|
3814
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3815
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3816
|
+
...processCreateParams(params)
|
|
3817
|
+
});
|
|
3818
|
+
};
|
|
3819
|
+
var ZodNaN = class extends ZodType {
|
|
3820
|
+
_parse(input) {
|
|
3821
|
+
const parsedType = this._getType(input);
|
|
3822
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
3823
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3824
|
+
addIssueToContext(ctx, {
|
|
3825
|
+
code: ZodIssueCode.invalid_type,
|
|
3826
|
+
expected: ZodParsedType.nan,
|
|
3827
|
+
received: ctx.parsedType
|
|
3828
|
+
});
|
|
3829
|
+
return INVALID;
|
|
3830
|
+
}
|
|
3831
|
+
return { status: "valid", value: input.data };
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
ZodNaN.create = (params) => {
|
|
3835
|
+
return new ZodNaN({
|
|
3836
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3837
|
+
...processCreateParams(params)
|
|
3838
|
+
});
|
|
3839
|
+
};
|
|
3840
|
+
var BRAND = Symbol("zod_brand");
|
|
3841
|
+
var ZodBranded = class extends ZodType {
|
|
3842
|
+
_parse(input) {
|
|
3843
|
+
const { ctx } = this._processInputParams(input);
|
|
3844
|
+
const data = ctx.data;
|
|
3845
|
+
return this._def.type._parse({
|
|
3846
|
+
data,
|
|
3847
|
+
path: ctx.path,
|
|
3848
|
+
parent: ctx
|
|
3849
|
+
});
|
|
3850
|
+
}
|
|
3851
|
+
unwrap() {
|
|
3852
|
+
return this._def.type;
|
|
3853
|
+
}
|
|
3854
|
+
};
|
|
3855
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
3856
|
+
_parse(input) {
|
|
3857
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3858
|
+
if (ctx.common.async) {
|
|
3859
|
+
const handleAsync = async () => {
|
|
3860
|
+
const inResult = await this._def.in._parseAsync({
|
|
3861
|
+
data: ctx.data,
|
|
3862
|
+
path: ctx.path,
|
|
3863
|
+
parent: ctx
|
|
3864
|
+
});
|
|
3865
|
+
if (inResult.status === "aborted")
|
|
3866
|
+
return INVALID;
|
|
3867
|
+
if (inResult.status === "dirty") {
|
|
3868
|
+
status.dirty();
|
|
3869
|
+
return DIRTY(inResult.value);
|
|
3870
|
+
} else {
|
|
3871
|
+
return this._def.out._parseAsync({
|
|
3872
|
+
data: inResult.value,
|
|
3873
|
+
path: ctx.path,
|
|
3874
|
+
parent: ctx
|
|
3875
|
+
});
|
|
3876
|
+
}
|
|
3877
|
+
};
|
|
3878
|
+
return handleAsync();
|
|
3879
|
+
} else {
|
|
3880
|
+
const inResult = this._def.in._parseSync({
|
|
3881
|
+
data: ctx.data,
|
|
3882
|
+
path: ctx.path,
|
|
3883
|
+
parent: ctx
|
|
3884
|
+
});
|
|
3885
|
+
if (inResult.status === "aborted")
|
|
3886
|
+
return INVALID;
|
|
3887
|
+
if (inResult.status === "dirty") {
|
|
3888
|
+
status.dirty();
|
|
3889
|
+
return {
|
|
3890
|
+
status: "dirty",
|
|
3891
|
+
value: inResult.value
|
|
3892
|
+
};
|
|
3893
|
+
} else {
|
|
3894
|
+
return this._def.out._parseSync({
|
|
3895
|
+
data: inResult.value,
|
|
3896
|
+
path: ctx.path,
|
|
3897
|
+
parent: ctx
|
|
3898
|
+
});
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
static create(a, b) {
|
|
3903
|
+
return new _ZodPipeline({
|
|
3904
|
+
in: a,
|
|
3905
|
+
out: b,
|
|
3906
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3907
|
+
});
|
|
3908
|
+
}
|
|
3909
|
+
};
|
|
3910
|
+
var ZodReadonly = class extends ZodType {
|
|
3911
|
+
_parse(input) {
|
|
3912
|
+
const result = this._def.innerType._parse(input);
|
|
3913
|
+
const freeze = (data) => {
|
|
3914
|
+
if (isValid(data)) {
|
|
3915
|
+
data.value = Object.freeze(data.value);
|
|
3916
|
+
}
|
|
3917
|
+
return data;
|
|
3918
|
+
};
|
|
3919
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3920
|
+
}
|
|
3921
|
+
unwrap() {
|
|
3922
|
+
return this._def.innerType;
|
|
3923
|
+
}
|
|
3924
|
+
};
|
|
3925
|
+
ZodReadonly.create = (type, params) => {
|
|
3926
|
+
return new ZodReadonly({
|
|
3927
|
+
innerType: type,
|
|
3928
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3929
|
+
...processCreateParams(params)
|
|
3930
|
+
});
|
|
3931
|
+
};
|
|
3932
|
+
function cleanParams(params, data) {
|
|
3933
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3934
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3935
|
+
return p2;
|
|
3936
|
+
}
|
|
3937
|
+
function custom(check, _params = {}, fatal) {
|
|
3938
|
+
if (check)
|
|
3939
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
3940
|
+
const r = check(data);
|
|
3941
|
+
if (r instanceof Promise) {
|
|
3942
|
+
return r.then((r2) => {
|
|
3943
|
+
if (!r2) {
|
|
3944
|
+
const params = cleanParams(_params, data);
|
|
3945
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
3946
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3947
|
+
}
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
if (!r) {
|
|
3951
|
+
const params = cleanParams(_params, data);
|
|
3952
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
3953
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3954
|
+
}
|
|
3955
|
+
return;
|
|
3956
|
+
});
|
|
3957
|
+
return ZodAny.create();
|
|
3958
|
+
}
|
|
3959
|
+
var late = {
|
|
3960
|
+
object: ZodObject.lazycreate
|
|
3961
|
+
};
|
|
3962
|
+
var ZodFirstPartyTypeKind;
|
|
3963
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
3964
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
3965
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
3966
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
3967
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
3968
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
3969
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
3970
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
3971
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
3972
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
3973
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
3974
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
3975
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
3976
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
3977
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
3978
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
3979
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
3980
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3981
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
3982
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
3983
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
3984
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
3985
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
3986
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
3987
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
3988
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
3989
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
3990
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
3991
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3992
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
3993
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
3994
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
3995
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
3996
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
3997
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
3998
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
3999
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4000
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4001
|
+
var instanceOfType = (cls, params = {
|
|
4002
|
+
message: `Input not instance of ${cls.name}`
|
|
4003
|
+
}) => custom((data) => data instanceof cls, params);
|
|
4004
|
+
var stringType = ZodString.create;
|
|
4005
|
+
var numberType = ZodNumber.create;
|
|
4006
|
+
var nanType = ZodNaN.create;
|
|
4007
|
+
var bigIntType = ZodBigInt.create;
|
|
4008
|
+
var booleanType = ZodBoolean.create;
|
|
4009
|
+
var dateType = ZodDate.create;
|
|
4010
|
+
var symbolType = ZodSymbol.create;
|
|
4011
|
+
var undefinedType = ZodUndefined.create;
|
|
4012
|
+
var nullType = ZodNull.create;
|
|
4013
|
+
var anyType = ZodAny.create;
|
|
4014
|
+
var unknownType = ZodUnknown.create;
|
|
4015
|
+
var neverType = ZodNever.create;
|
|
4016
|
+
var voidType = ZodVoid.create;
|
|
4017
|
+
var arrayType = ZodArray.create;
|
|
4018
|
+
var objectType = ZodObject.create;
|
|
4019
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
4020
|
+
var unionType = ZodUnion.create;
|
|
4021
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4022
|
+
var intersectionType = ZodIntersection.create;
|
|
4023
|
+
var tupleType = ZodTuple.create;
|
|
4024
|
+
var recordType = ZodRecord.create;
|
|
4025
|
+
var mapType = ZodMap.create;
|
|
4026
|
+
var setType = ZodSet.create;
|
|
4027
|
+
var functionType = ZodFunction.create;
|
|
4028
|
+
var lazyType = ZodLazy.create;
|
|
4029
|
+
var literalType = ZodLiteral.create;
|
|
4030
|
+
var enumType = ZodEnum.create;
|
|
4031
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
4032
|
+
var promiseType = ZodPromise.create;
|
|
4033
|
+
var effectsType = ZodEffects.create;
|
|
4034
|
+
var optionalType = ZodOptional.create;
|
|
4035
|
+
var nullableType = ZodNullable.create;
|
|
4036
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4037
|
+
var pipelineType = ZodPipeline.create;
|
|
4038
|
+
var ostring = () => stringType().optional();
|
|
4039
|
+
var onumber = () => numberType().optional();
|
|
4040
|
+
var oboolean = () => booleanType().optional();
|
|
4041
|
+
var coerce = {
|
|
4042
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4043
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4044
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
4045
|
+
...arg,
|
|
4046
|
+
coerce: true
|
|
4047
|
+
})),
|
|
4048
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4049
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4050
|
+
};
|
|
4051
|
+
var NEVER = INVALID;
|
|
4052
|
+
|
|
4053
|
+
// src/config.ts
|
|
10
4054
|
var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
11
4055
|
SamplingStrategyType2["ALWAYS"] = "always";
|
|
12
4056
|
SamplingStrategyType2["NEVER"] = "never";
|
|
@@ -14,31 +4058,38 @@ var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
|
14
4058
|
SamplingStrategyType2["CUSTOM"] = "custom";
|
|
15
4059
|
return SamplingStrategyType2;
|
|
16
4060
|
})(SamplingStrategyType || {});
|
|
17
|
-
var samplingStrategySchema =
|
|
18
|
-
|
|
19
|
-
type:
|
|
4061
|
+
var samplingStrategySchema = external_exports.discriminatedUnion("type", [
|
|
4062
|
+
external_exports.object({
|
|
4063
|
+
type: external_exports.literal("always" /* ALWAYS */)
|
|
20
4064
|
}),
|
|
21
|
-
|
|
22
|
-
type:
|
|
4065
|
+
external_exports.object({
|
|
4066
|
+
type: external_exports.literal("never" /* NEVER */)
|
|
23
4067
|
}),
|
|
24
|
-
|
|
25
|
-
type:
|
|
26
|
-
probability:
|
|
4068
|
+
external_exports.object({
|
|
4069
|
+
type: external_exports.literal("ratio" /* RATIO */),
|
|
4070
|
+
probability: external_exports.number().min(0, "Probability must be between 0 and 1").max(1, "Probability must be between 0 and 1")
|
|
27
4071
|
}),
|
|
28
|
-
|
|
29
|
-
type:
|
|
30
|
-
sampler:
|
|
4072
|
+
external_exports.object({
|
|
4073
|
+
type: external_exports.literal("custom" /* CUSTOM */),
|
|
4074
|
+
sampler: external_exports.function().args(external_exports.any().optional()).returns(external_exports.boolean())
|
|
31
4075
|
})
|
|
32
4076
|
]);
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
4077
|
+
var serializationOptionsSchema = external_exports.object({
|
|
4078
|
+
maxStringLength: external_exports.number().int().positive().optional(),
|
|
4079
|
+
maxDepth: external_exports.number().int().positive().optional(),
|
|
4080
|
+
maxArrayLength: external_exports.number().int().positive().optional(),
|
|
4081
|
+
maxObjectKeys: external_exports.number().int().positive().optional()
|
|
4082
|
+
}).optional();
|
|
4083
|
+
var observabilityInstanceConfigSchema = external_exports.object({
|
|
4084
|
+
name: external_exports.string().min(1, "Name is required"),
|
|
4085
|
+
serviceName: external_exports.string().min(1, "Service name is required"),
|
|
36
4086
|
sampling: samplingStrategySchema.optional(),
|
|
37
|
-
exporters:
|
|
38
|
-
bridge:
|
|
39
|
-
spanOutputProcessors:
|
|
40
|
-
includeInternalSpans:
|
|
41
|
-
requestContextKeys:
|
|
4087
|
+
exporters: external_exports.array(external_exports.any()).optional(),
|
|
4088
|
+
bridge: external_exports.any().optional(),
|
|
4089
|
+
spanOutputProcessors: external_exports.array(external_exports.any()).optional(),
|
|
4090
|
+
includeInternalSpans: external_exports.boolean().optional(),
|
|
4091
|
+
requestContextKeys: external_exports.array(external_exports.string()).optional(),
|
|
4092
|
+
serializationOptions: serializationOptionsSchema
|
|
42
4093
|
}).refine(
|
|
43
4094
|
(data) => {
|
|
44
4095
|
const hasExporters = data.exporters && data.exporters.length > 0;
|
|
@@ -49,14 +4100,15 @@ var observabilityInstanceConfigSchema = z.object({
|
|
|
49
4100
|
message: "At least one exporter or a bridge is required"
|
|
50
4101
|
}
|
|
51
4102
|
);
|
|
52
|
-
var observabilityConfigValueSchema =
|
|
53
|
-
serviceName:
|
|
4103
|
+
var observabilityConfigValueSchema = external_exports.object({
|
|
4104
|
+
serviceName: external_exports.string().min(1, "Service name is required"),
|
|
54
4105
|
sampling: samplingStrategySchema.optional(),
|
|
55
|
-
exporters:
|
|
56
|
-
bridge:
|
|
57
|
-
spanOutputProcessors:
|
|
58
|
-
includeInternalSpans:
|
|
59
|
-
requestContextKeys:
|
|
4106
|
+
exporters: external_exports.array(external_exports.any()).optional(),
|
|
4107
|
+
bridge: external_exports.any().optional(),
|
|
4108
|
+
spanOutputProcessors: external_exports.array(external_exports.any()).optional(),
|
|
4109
|
+
includeInternalSpans: external_exports.boolean().optional(),
|
|
4110
|
+
requestContextKeys: external_exports.array(external_exports.string()).optional(),
|
|
4111
|
+
serializationOptions: serializationOptionsSchema
|
|
60
4112
|
}).refine(
|
|
61
4113
|
(data) => {
|
|
62
4114
|
const hasExporters = data.exporters && data.exporters.length > 0;
|
|
@@ -67,12 +4119,12 @@ var observabilityConfigValueSchema = z.object({
|
|
|
67
4119
|
message: "At least one exporter or a bridge is required"
|
|
68
4120
|
}
|
|
69
4121
|
);
|
|
70
|
-
var observabilityRegistryConfigSchema =
|
|
71
|
-
default:
|
|
72
|
-
enabled:
|
|
4122
|
+
var observabilityRegistryConfigSchema = external_exports.object({
|
|
4123
|
+
default: external_exports.object({
|
|
4124
|
+
enabled: external_exports.boolean().optional()
|
|
73
4125
|
}).optional().nullable(),
|
|
74
|
-
configs:
|
|
75
|
-
configSelector:
|
|
4126
|
+
configs: external_exports.union([external_exports.record(external_exports.string(), external_exports.any()), external_exports.array(external_exports.any()), external_exports.null()]).optional(),
|
|
4127
|
+
configSelector: external_exports.function().optional()
|
|
76
4128
|
}).passthrough().refine(
|
|
77
4129
|
(data) => {
|
|
78
4130
|
const isDefaultEnabled = data.default?.enabled === true;
|
|
@@ -443,24 +4495,31 @@ var ConsoleExporter = class extends BaseExporter {
|
|
|
443
4495
|
this.logger.info("ConsoleExporter shutdown");
|
|
444
4496
|
}
|
|
445
4497
|
};
|
|
446
|
-
function resolveTracingStorageStrategy(config,
|
|
4498
|
+
function resolveTracingStorageStrategy(config, observability, storageName, logger) {
|
|
447
4499
|
if (config.strategy && config.strategy !== "auto") {
|
|
448
|
-
const hints =
|
|
4500
|
+
const hints = observability.tracingStrategy;
|
|
449
4501
|
if (hints.supported.includes(config.strategy)) {
|
|
450
4502
|
return config.strategy;
|
|
451
4503
|
}
|
|
452
4504
|
logger.warn("User-specified tracing strategy not supported by storage adapter, falling back to auto-selection", {
|
|
453
4505
|
userStrategy: config.strategy,
|
|
454
|
-
storageAdapter:
|
|
4506
|
+
storageAdapter: storageName,
|
|
455
4507
|
supportedStrategies: hints.supported,
|
|
456
4508
|
fallbackStrategy: hints.preferred
|
|
457
4509
|
});
|
|
458
4510
|
}
|
|
459
|
-
return
|
|
4511
|
+
return observability.tracingStrategy.preferred;
|
|
4512
|
+
}
|
|
4513
|
+
function getStringOrNull(value) {
|
|
4514
|
+
return typeof value === "string" ? value : null;
|
|
4515
|
+
}
|
|
4516
|
+
function getObjectOrNull(value) {
|
|
4517
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
460
4518
|
}
|
|
461
4519
|
var DefaultExporter = class extends BaseExporter {
|
|
462
4520
|
name = "mastra-default-observability-exporter";
|
|
463
4521
|
#storage;
|
|
4522
|
+
#observability;
|
|
464
4523
|
#config;
|
|
465
4524
|
#resolvedStrategy;
|
|
466
4525
|
buffer;
|
|
@@ -497,25 +4556,30 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
497
4556
|
/**
|
|
498
4557
|
* Initialize the exporter (called after all dependencies are ready)
|
|
499
4558
|
*/
|
|
500
|
-
init(options) {
|
|
4559
|
+
async init(options) {
|
|
501
4560
|
this.#storage = options.mastra?.getStorage();
|
|
502
4561
|
if (!this.#storage) {
|
|
503
4562
|
this.logger.warn("DefaultExporter disabled: Storage not available. Traces will not be persisted.");
|
|
504
4563
|
return;
|
|
505
4564
|
}
|
|
506
|
-
this
|
|
4565
|
+
this.#observability = await this.#storage.getStore("observability");
|
|
4566
|
+
if (!this.#observability) {
|
|
4567
|
+
this.logger.warn("DefaultExporter disabled: Observability storage not available. Traces will not be persisted.");
|
|
4568
|
+
return;
|
|
4569
|
+
}
|
|
4570
|
+
this.initializeStrategy(this.#observability, this.#storage.constructor.name);
|
|
507
4571
|
}
|
|
508
4572
|
/**
|
|
509
|
-
* Initialize the resolved strategy once
|
|
4573
|
+
* Initialize the resolved strategy once observability store is available
|
|
510
4574
|
*/
|
|
511
|
-
initializeStrategy(
|
|
4575
|
+
initializeStrategy(observability, storageName) {
|
|
512
4576
|
if (this.#strategyInitialized) return;
|
|
513
|
-
this.#resolvedStrategy = resolveTracingStorageStrategy(this.#config,
|
|
4577
|
+
this.#resolvedStrategy = resolveTracingStorageStrategy(this.#config, observability, storageName, this.logger);
|
|
514
4578
|
this.#strategyInitialized = true;
|
|
515
4579
|
this.logger.debug("tracing storage exporter initialized", {
|
|
516
4580
|
strategy: this.#resolvedStrategy,
|
|
517
4581
|
source: this.#config.strategy !== "auto" ? "user" : "auto",
|
|
518
|
-
storageAdapter:
|
|
4582
|
+
storageAdapter: storageName,
|
|
519
4583
|
maxBatchSize: this.#config.maxBatchSize,
|
|
520
4584
|
maxBatchWaitMs: this.#config.maxBatchWaitMs
|
|
521
4585
|
});
|
|
@@ -688,22 +4752,44 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
688
4752
|
}
|
|
689
4753
|
}
|
|
690
4754
|
buildCreateRecord(span) {
|
|
4755
|
+
const metadata = span.metadata ?? {};
|
|
691
4756
|
return {
|
|
692
4757
|
traceId: span.traceId,
|
|
693
4758
|
spanId: span.id,
|
|
694
4759
|
parentSpanId: span.parentSpanId ?? null,
|
|
695
4760
|
name: span.name,
|
|
696
|
-
|
|
4761
|
+
// Entity identification - from span
|
|
4762
|
+
entityType: span.entityType ?? null,
|
|
4763
|
+
entityId: span.entityId ?? null,
|
|
4764
|
+
entityName: span.entityName ?? null,
|
|
4765
|
+
// Identity & Tenancy - extracted from metadata if present
|
|
4766
|
+
userId: getStringOrNull(metadata.userId),
|
|
4767
|
+
organizationId: getStringOrNull(metadata.organizationId),
|
|
4768
|
+
resourceId: getStringOrNull(metadata.resourceId),
|
|
4769
|
+
// Correlation IDs - extracted from metadata if present
|
|
4770
|
+
runId: getStringOrNull(metadata.runId),
|
|
4771
|
+
sessionId: getStringOrNull(metadata.sessionId),
|
|
4772
|
+
threadId: getStringOrNull(metadata.threadId),
|
|
4773
|
+
requestId: getStringOrNull(metadata.requestId),
|
|
4774
|
+
// Deployment context - extracted from metadata if present
|
|
4775
|
+
environment: getStringOrNull(metadata.environment),
|
|
4776
|
+
source: getStringOrNull(metadata.source),
|
|
4777
|
+
serviceName: getStringOrNull(metadata.serviceName),
|
|
4778
|
+
scope: getObjectOrNull(metadata.scope),
|
|
4779
|
+
// Span data
|
|
697
4780
|
spanType: span.type,
|
|
698
4781
|
attributes: this.serializeAttributes(span),
|
|
699
4782
|
metadata: span.metadata ?? null,
|
|
4783
|
+
// Keep all metadata including extracted fields
|
|
4784
|
+
tags: span.tags ?? null,
|
|
700
4785
|
links: null,
|
|
4786
|
+
input: span.input ?? null,
|
|
4787
|
+
output: span.output ?? null,
|
|
4788
|
+
error: span.errorInfo ?? null,
|
|
4789
|
+
isEvent: span.isEvent,
|
|
4790
|
+
// Timestamps
|
|
701
4791
|
startedAt: span.startTime,
|
|
702
|
-
endedAt: span.endTime ?? null
|
|
703
|
-
input: span.input,
|
|
704
|
-
output: span.output,
|
|
705
|
-
error: span.errorInfo,
|
|
706
|
-
isEvent: span.isEvent
|
|
4792
|
+
endedAt: span.endTime ?? null
|
|
707
4793
|
};
|
|
708
4794
|
}
|
|
709
4795
|
buildUpdateRecord(span) {
|
|
@@ -716,36 +4802,36 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
716
4802
|
endedAt: span.endTime ?? null,
|
|
717
4803
|
input: span.input,
|
|
718
4804
|
output: span.output,
|
|
719
|
-
error: span.errorInfo
|
|
4805
|
+
error: span.errorInfo ?? null
|
|
720
4806
|
};
|
|
721
4807
|
}
|
|
722
4808
|
/**
|
|
723
4809
|
* Handles realtime strategy - processes each event immediately
|
|
724
4810
|
*/
|
|
725
|
-
async handleRealtimeEvent(event,
|
|
4811
|
+
async handleRealtimeEvent(event, observability) {
|
|
726
4812
|
const span = event.exportedSpan;
|
|
727
4813
|
const spanKey = this.buildSpanKey(span.traceId, span.id);
|
|
728
4814
|
if (span.isEvent) {
|
|
729
4815
|
if (event.type === TracingEventType.SPAN_ENDED) {
|
|
730
|
-
await
|
|
4816
|
+
await observability.createSpan({ span: this.buildCreateRecord(event.exportedSpan) });
|
|
731
4817
|
} else {
|
|
732
4818
|
this.logger.warn(`Tracing event type not implemented for event spans: ${event.type}`);
|
|
733
4819
|
}
|
|
734
4820
|
} else {
|
|
735
4821
|
switch (event.type) {
|
|
736
4822
|
case TracingEventType.SPAN_STARTED:
|
|
737
|
-
await
|
|
4823
|
+
await observability.createSpan({ span: this.buildCreateRecord(event.exportedSpan) });
|
|
738
4824
|
this.allCreatedSpans.add(spanKey);
|
|
739
4825
|
break;
|
|
740
4826
|
case TracingEventType.SPAN_UPDATED:
|
|
741
|
-
await
|
|
4827
|
+
await observability.updateSpan({
|
|
742
4828
|
traceId: span.traceId,
|
|
743
4829
|
spanId: span.id,
|
|
744
4830
|
updates: this.buildUpdateRecord(span)
|
|
745
4831
|
});
|
|
746
4832
|
break;
|
|
747
4833
|
case TracingEventType.SPAN_ENDED:
|
|
748
|
-
await
|
|
4834
|
+
await observability.updateSpan({
|
|
749
4835
|
traceId: span.traceId,
|
|
750
4836
|
spanId: span.id,
|
|
751
4837
|
updates: this.buildUpdateRecord(span)
|
|
@@ -799,8 +4885,8 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
799
4885
|
* Flushes the current buffer to storage with retry logic
|
|
800
4886
|
*/
|
|
801
4887
|
async flush() {
|
|
802
|
-
if (!this.#
|
|
803
|
-
this.logger.debug("Cannot flush traces.
|
|
4888
|
+
if (!this.#observability) {
|
|
4889
|
+
this.logger.debug("Cannot flush traces. Observability storage is not initialized");
|
|
804
4890
|
return;
|
|
805
4891
|
}
|
|
806
4892
|
if (this.#flushTimer) {
|
|
@@ -824,7 +4910,7 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
824
4910
|
totalSize: this.buffer.totalSize
|
|
825
4911
|
};
|
|
826
4912
|
this.resetBuffer();
|
|
827
|
-
await this.flushWithRetries(this.#
|
|
4913
|
+
await this.flushWithRetries(this.#observability, bufferCopy, 0);
|
|
828
4914
|
const elapsed = Date.now() - startTime;
|
|
829
4915
|
this.logger.debug("Batch flushed", {
|
|
830
4916
|
strategy: this.#resolvedStrategy,
|
|
@@ -837,11 +4923,11 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
837
4923
|
/**
|
|
838
4924
|
* Attempts to flush with exponential backoff retry logic
|
|
839
4925
|
*/
|
|
840
|
-
async flushWithRetries(
|
|
4926
|
+
async flushWithRetries(observability, buffer, attempt) {
|
|
841
4927
|
try {
|
|
842
4928
|
if (this.#resolvedStrategy === "batch-with-updates") {
|
|
843
4929
|
if (buffer.creates.length > 0) {
|
|
844
|
-
await
|
|
4930
|
+
await observability.batchCreateSpans({ records: buffer.creates });
|
|
845
4931
|
}
|
|
846
4932
|
if (buffer.updates.length > 0) {
|
|
847
4933
|
const sortedUpdates = buffer.updates.sort((a, b) => {
|
|
@@ -851,11 +4937,11 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
851
4937
|
if (spanCompare !== 0) return spanCompare;
|
|
852
4938
|
return a.sequenceNumber - b.sequenceNumber;
|
|
853
4939
|
});
|
|
854
|
-
await
|
|
4940
|
+
await observability.batchUpdateSpans({ records: sortedUpdates });
|
|
855
4941
|
}
|
|
856
4942
|
} else if (this.#resolvedStrategy === "insert-only") {
|
|
857
4943
|
if (buffer.insertOnly.length > 0) {
|
|
858
|
-
await
|
|
4944
|
+
await observability.batchCreateSpans({ records: buffer.insertOnly });
|
|
859
4945
|
}
|
|
860
4946
|
}
|
|
861
4947
|
for (const spanKey of buffer.completedSpans) {
|
|
@@ -871,7 +4957,7 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
871
4957
|
error: error instanceof Error ? error.message : String(error)
|
|
872
4958
|
});
|
|
873
4959
|
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
874
|
-
return this.flushWithRetries(
|
|
4960
|
+
return this.flushWithRetries(observability, buffer, attempt + 1);
|
|
875
4961
|
} else {
|
|
876
4962
|
this.logger.error("Batch flush failed after all retries, dropping batch", {
|
|
877
4963
|
finalAttempt: attempt + 1,
|
|
@@ -886,16 +4972,16 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
886
4972
|
}
|
|
887
4973
|
}
|
|
888
4974
|
async _exportTracingEvent(event) {
|
|
889
|
-
if (!this.#
|
|
890
|
-
this.logger.debug("Cannot store traces.
|
|
4975
|
+
if (!this.#observability) {
|
|
4976
|
+
this.logger.debug("Cannot store traces. Observability storage is not initialized");
|
|
891
4977
|
return;
|
|
892
4978
|
}
|
|
893
4979
|
if (!this.#strategyInitialized) {
|
|
894
|
-
this.initializeStrategy(this.#storage);
|
|
4980
|
+
this.initializeStrategy(this.#observability, this.#storage?.constructor.name ?? "Unknown");
|
|
895
4981
|
}
|
|
896
4982
|
switch (this.#resolvedStrategy) {
|
|
897
4983
|
case "realtime":
|
|
898
|
-
await this.handleRealtimeEvent(event, this.#
|
|
4984
|
+
await this.handleRealtimeEvent(event, this.#observability);
|
|
899
4985
|
break;
|
|
900
4986
|
case "batch-with-updates":
|
|
901
4987
|
this.handleBatchWithUpdatesEvent(event);
|
|
@@ -946,6 +5032,58 @@ var TestExporter = class extends BaseExporter {
|
|
|
946
5032
|
this.logger.info("TestExporter shutdown");
|
|
947
5033
|
}
|
|
948
5034
|
};
|
|
5035
|
+
|
|
5036
|
+
// src/usage.ts
|
|
5037
|
+
function extractUsageMetrics(usage, providerMetadata) {
|
|
5038
|
+
if (!usage) {
|
|
5039
|
+
return {};
|
|
5040
|
+
}
|
|
5041
|
+
const inputDetails = {};
|
|
5042
|
+
const outputDetails = {};
|
|
5043
|
+
let inputTokens = usage.inputTokens;
|
|
5044
|
+
const outputTokens = usage.outputTokens;
|
|
5045
|
+
if (usage.cachedInputTokens) {
|
|
5046
|
+
inputDetails.cacheRead = usage.cachedInputTokens;
|
|
5047
|
+
}
|
|
5048
|
+
if (usage.reasoningTokens) {
|
|
5049
|
+
outputDetails.reasoning = usage.reasoningTokens;
|
|
5050
|
+
}
|
|
5051
|
+
const anthropic = providerMetadata?.anthropic;
|
|
5052
|
+
if (anthropic) {
|
|
5053
|
+
if (anthropic.cacheReadInputTokens) {
|
|
5054
|
+
inputDetails.cacheRead = anthropic.cacheReadInputTokens;
|
|
5055
|
+
}
|
|
5056
|
+
if (anthropic.cacheCreationInputTokens) {
|
|
5057
|
+
inputDetails.cacheWrite = anthropic.cacheCreationInputTokens;
|
|
5058
|
+
}
|
|
5059
|
+
if (anthropic.cacheReadInputTokens || anthropic.cacheCreationInputTokens) {
|
|
5060
|
+
inputDetails.text = usage.inputTokens;
|
|
5061
|
+
inputTokens = (usage.inputTokens ?? 0) + (anthropic.cacheReadInputTokens ?? 0) + (anthropic.cacheCreationInputTokens ?? 0);
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
const google = providerMetadata?.google;
|
|
5065
|
+
if (google?.usageMetadata) {
|
|
5066
|
+
if (google.usageMetadata.cachedContentTokenCount) {
|
|
5067
|
+
inputDetails.cacheRead = google.usageMetadata.cachedContentTokenCount;
|
|
5068
|
+
}
|
|
5069
|
+
if (google.usageMetadata.thoughtsTokenCount) {
|
|
5070
|
+
outputDetails.reasoning = google.usageMetadata.thoughtsTokenCount;
|
|
5071
|
+
}
|
|
5072
|
+
}
|
|
5073
|
+
const result = {
|
|
5074
|
+
inputTokens,
|
|
5075
|
+
outputTokens
|
|
5076
|
+
};
|
|
5077
|
+
if (Object.keys(inputDetails).length > 0) {
|
|
5078
|
+
result.inputDetails = inputDetails;
|
|
5079
|
+
}
|
|
5080
|
+
if (Object.keys(outputDetails).length > 0) {
|
|
5081
|
+
result.outputDetails = outputDetails;
|
|
5082
|
+
}
|
|
5083
|
+
return result;
|
|
5084
|
+
}
|
|
5085
|
+
|
|
5086
|
+
// src/model-tracing.ts
|
|
949
5087
|
var ModelSpanTracker = class {
|
|
950
5088
|
#modelSpan;
|
|
951
5089
|
#currentStepSpan;
|
|
@@ -953,8 +5091,7 @@ var ModelSpanTracker = class {
|
|
|
953
5091
|
#accumulator = {};
|
|
954
5092
|
#stepIndex = 0;
|
|
955
5093
|
#chunkSequence = 0;
|
|
956
|
-
|
|
957
|
-
#completionStartTimeCaptured = false;
|
|
5094
|
+
#completionStartTime;
|
|
958
5095
|
/** Tracks tool output accumulators by toolCallId for consolidating sub-agent streams */
|
|
959
5096
|
#toolOutputAccumulators = /* @__PURE__ */ new Map();
|
|
960
5097
|
/** Tracks toolCallIds that had streaming output (to skip redundant tool-result spans) */
|
|
@@ -964,18 +5101,12 @@ var ModelSpanTracker = class {
|
|
|
964
5101
|
}
|
|
965
5102
|
/**
|
|
966
5103
|
* Capture the completion start time (time to first token) when the first content chunk arrives.
|
|
967
|
-
* This is used by observability providers like Langfuse to calculate TTFT metrics.
|
|
968
5104
|
*/
|
|
969
5105
|
#captureCompletionStartTime() {
|
|
970
|
-
if (this.#
|
|
5106
|
+
if (this.#completionStartTime) {
|
|
971
5107
|
return;
|
|
972
5108
|
}
|
|
973
|
-
this.#
|
|
974
|
-
this.#modelSpan.update({
|
|
975
|
-
attributes: {
|
|
976
|
-
completionStartTime: /* @__PURE__ */ new Date()
|
|
977
|
-
}
|
|
978
|
-
});
|
|
5109
|
+
this.#completionStartTime = /* @__PURE__ */ new Date();
|
|
979
5110
|
}
|
|
980
5111
|
/**
|
|
981
5112
|
* Get the tracing context for creating child spans.
|
|
@@ -993,10 +5124,16 @@ var ModelSpanTracker = class {
|
|
|
993
5124
|
this.#modelSpan?.error(options);
|
|
994
5125
|
}
|
|
995
5126
|
/**
|
|
996
|
-
* End the generation span
|
|
5127
|
+
* End the generation span with optional raw usage data.
|
|
5128
|
+
* If usage is provided, it will be converted to UsageStats with cache token details.
|
|
997
5129
|
*/
|
|
998
5130
|
endGeneration(options) {
|
|
999
|
-
|
|
5131
|
+
const { usage, providerMetadata, ...spanOptions } = options ?? {};
|
|
5132
|
+
if (spanOptions.attributes) {
|
|
5133
|
+
spanOptions.attributes.completionStartTime = this.#completionStartTime;
|
|
5134
|
+
spanOptions.attributes.usage = extractUsageMetrics(usage, providerMetadata);
|
|
5135
|
+
}
|
|
5136
|
+
this.#modelSpan?.end(spanOptions);
|
|
1000
5137
|
}
|
|
1001
5138
|
/**
|
|
1002
5139
|
* Update the generation span
|
|
@@ -1005,9 +5142,14 @@ var ModelSpanTracker = class {
|
|
|
1005
5142
|
this.#modelSpan?.update(options);
|
|
1006
5143
|
}
|
|
1007
5144
|
/**
|
|
1008
|
-
* Start a new Model execution step
|
|
5145
|
+
* Start a new Model execution step.
|
|
5146
|
+
* This should be called at the beginning of LLM execution to capture accurate startTime.
|
|
5147
|
+
* The step-start chunk payload can be passed later via updateStep() if needed.
|
|
1009
5148
|
*/
|
|
1010
|
-
|
|
5149
|
+
startStep(payload) {
|
|
5150
|
+
if (this.#currentStepSpan) {
|
|
5151
|
+
return;
|
|
5152
|
+
}
|
|
1011
5153
|
this.#currentStepSpan = this.#modelSpan?.createChildSpan({
|
|
1012
5154
|
name: `step: ${this.#stepIndex}`,
|
|
1013
5155
|
type: SpanType.MODEL_STEP,
|
|
@@ -1020,15 +5162,32 @@ var ModelSpanTracker = class {
|
|
|
1020
5162
|
});
|
|
1021
5163
|
this.#chunkSequence = 0;
|
|
1022
5164
|
}
|
|
5165
|
+
/**
|
|
5166
|
+
* Update the current step span with additional payload data.
|
|
5167
|
+
* Called when step-start chunk arrives with request/warnings info.
|
|
5168
|
+
*/
|
|
5169
|
+
updateStep(payload) {
|
|
5170
|
+
if (!this.#currentStepSpan || !payload) {
|
|
5171
|
+
return;
|
|
5172
|
+
}
|
|
5173
|
+
this.#currentStepSpan.update({
|
|
5174
|
+
input: payload.request,
|
|
5175
|
+
attributes: {
|
|
5176
|
+
...payload.messageId ? { messageId: payload.messageId } : {},
|
|
5177
|
+
...payload.warnings?.length ? { warnings: payload.warnings } : {}
|
|
5178
|
+
}
|
|
5179
|
+
});
|
|
5180
|
+
}
|
|
1023
5181
|
/**
|
|
1024
5182
|
* End the current Model execution step with token usage, finish reason, output, and metadata
|
|
1025
5183
|
*/
|
|
1026
5184
|
#endStepSpan(payload) {
|
|
1027
5185
|
if (!this.#currentStepSpan) return;
|
|
1028
5186
|
const output = payload.output;
|
|
1029
|
-
const { usage, ...otherOutput } = output;
|
|
5187
|
+
const { usage: rawUsage, ...otherOutput } = output;
|
|
1030
5188
|
const stepResult = payload.stepResult;
|
|
1031
5189
|
const metadata = payload.metadata;
|
|
5190
|
+
const usage = extractUsageMetrics(rawUsage, metadata?.providerMetadata);
|
|
1032
5191
|
const cleanMetadata = metadata ? { ...metadata } : void 0;
|
|
1033
5192
|
if (cleanMetadata?.request) {
|
|
1034
5193
|
delete cleanMetadata.request;
|
|
@@ -1053,7 +5212,7 @@ var ModelSpanTracker = class {
|
|
|
1053
5212
|
*/
|
|
1054
5213
|
#startChunkSpan(chunkType, initialData) {
|
|
1055
5214
|
if (!this.#currentStepSpan) {
|
|
1056
|
-
this
|
|
5215
|
+
this.startStep();
|
|
1057
5216
|
}
|
|
1058
5217
|
this.#currentChunkSpan = this.#currentStepSpan?.createChildSpan({
|
|
1059
5218
|
name: `chunk: '${chunkType}'`,
|
|
@@ -1093,7 +5252,7 @@ var ModelSpanTracker = class {
|
|
|
1093
5252
|
*/
|
|
1094
5253
|
#createEventSpan(chunkType, output) {
|
|
1095
5254
|
if (!this.#currentStepSpan) {
|
|
1096
|
-
this
|
|
5255
|
+
this.startStep();
|
|
1097
5256
|
}
|
|
1098
5257
|
const span = this.#currentStepSpan?.createEventSpan({
|
|
1099
5258
|
name: `chunk: '${chunkType}'`,
|
|
@@ -1212,7 +5371,7 @@ var ModelSpanTracker = class {
|
|
|
1212
5371
|
let acc = this.#toolOutputAccumulators.get(toolCallId);
|
|
1213
5372
|
if (!acc) {
|
|
1214
5373
|
if (!this.#currentStepSpan) {
|
|
1215
|
-
this
|
|
5374
|
+
this.startStep();
|
|
1216
5375
|
}
|
|
1217
5376
|
acc = {
|
|
1218
5377
|
toolName: toolName || "unknown",
|
|
@@ -1279,13 +5438,15 @@ var ModelSpanTracker = class {
|
|
|
1279
5438
|
* create MODEL_STEP and MODEL_CHUNK spans for each semantic unit in the stream.
|
|
1280
5439
|
*/
|
|
1281
5440
|
wrapStream(stream) {
|
|
1282
|
-
let captureCompletionStartTime = false;
|
|
1283
5441
|
return stream.pipeThrough(
|
|
1284
5442
|
new TransformStream({
|
|
1285
5443
|
transform: (chunk, controller) => {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
5444
|
+
switch (chunk.type) {
|
|
5445
|
+
case "text-delta":
|
|
5446
|
+
case "tool-call-delta":
|
|
5447
|
+
case "reasoning-delta":
|
|
5448
|
+
this.#captureCompletionStartTime();
|
|
5449
|
+
break;
|
|
1289
5450
|
}
|
|
1290
5451
|
controller.enqueue(chunk);
|
|
1291
5452
|
switch (chunk.type) {
|
|
@@ -1310,7 +5471,11 @@ var ModelSpanTracker = class {
|
|
|
1310
5471
|
this.#handleObjectChunk(chunk);
|
|
1311
5472
|
break;
|
|
1312
5473
|
case "step-start":
|
|
1313
|
-
this.#
|
|
5474
|
+
if (this.#currentStepSpan) {
|
|
5475
|
+
this.updateStep(chunk.payload);
|
|
5476
|
+
} else {
|
|
5477
|
+
this.startStep(chunk.payload);
|
|
5478
|
+
}
|
|
1314
5479
|
break;
|
|
1315
5480
|
case "step-finish":
|
|
1316
5481
|
this.#endStepSpan(chunk.payload);
|
|
@@ -1354,6 +5519,122 @@ var ModelSpanTracker = class {
|
|
|
1354
5519
|
}
|
|
1355
5520
|
};
|
|
1356
5521
|
|
|
5522
|
+
// src/spans/serialization.ts
|
|
5523
|
+
var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
|
|
5524
|
+
"logger",
|
|
5525
|
+
"experimental_providerMetadata",
|
|
5526
|
+
"providerMetadata",
|
|
5527
|
+
"steps",
|
|
5528
|
+
"tracingContext"
|
|
5529
|
+
]);
|
|
5530
|
+
var DEFAULT_DEEP_CLEAN_OPTIONS = Object.freeze({
|
|
5531
|
+
keysToStrip: DEFAULT_KEYS_TO_STRIP,
|
|
5532
|
+
maxDepth: 6,
|
|
5533
|
+
maxStringLength: 1024,
|
|
5534
|
+
maxArrayLength: 50,
|
|
5535
|
+
maxObjectKeys: 50
|
|
5536
|
+
});
|
|
5537
|
+
function mergeSerializationOptions(userOptions) {
|
|
5538
|
+
if (!userOptions) {
|
|
5539
|
+
return DEFAULT_DEEP_CLEAN_OPTIONS;
|
|
5540
|
+
}
|
|
5541
|
+
return {
|
|
5542
|
+
keysToStrip: DEFAULT_KEYS_TO_STRIP,
|
|
5543
|
+
maxDepth: userOptions.maxDepth ?? DEFAULT_DEEP_CLEAN_OPTIONS.maxDepth,
|
|
5544
|
+
maxStringLength: userOptions.maxStringLength ?? DEFAULT_DEEP_CLEAN_OPTIONS.maxStringLength,
|
|
5545
|
+
maxArrayLength: userOptions.maxArrayLength ?? DEFAULT_DEEP_CLEAN_OPTIONS.maxArrayLength,
|
|
5546
|
+
maxObjectKeys: userOptions.maxObjectKeys ?? DEFAULT_DEEP_CLEAN_OPTIONS.maxObjectKeys
|
|
5547
|
+
};
|
|
5548
|
+
}
|
|
5549
|
+
function truncateString(s, maxChars) {
|
|
5550
|
+
if (s.length <= maxChars) {
|
|
5551
|
+
return s;
|
|
5552
|
+
}
|
|
5553
|
+
return s.slice(0, maxChars) + "\u2026[truncated]";
|
|
5554
|
+
}
|
|
5555
|
+
function deepClean(value, options = DEFAULT_DEEP_CLEAN_OPTIONS) {
|
|
5556
|
+
const { keysToStrip, maxDepth, maxStringLength, maxArrayLength, maxObjectKeys } = options;
|
|
5557
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
5558
|
+
function helper(val, depth) {
|
|
5559
|
+
if (depth > maxDepth) {
|
|
5560
|
+
return "[MaxDepth]";
|
|
5561
|
+
}
|
|
5562
|
+
if (val === null || val === void 0) {
|
|
5563
|
+
return val;
|
|
5564
|
+
}
|
|
5565
|
+
if (typeof val === "string") {
|
|
5566
|
+
return truncateString(val, maxStringLength);
|
|
5567
|
+
}
|
|
5568
|
+
if (typeof val === "number" || typeof val === "boolean") {
|
|
5569
|
+
return val;
|
|
5570
|
+
}
|
|
5571
|
+
if (typeof val === "bigint") {
|
|
5572
|
+
return `${val}n`;
|
|
5573
|
+
}
|
|
5574
|
+
if (typeof val === "function") {
|
|
5575
|
+
return "[Function]";
|
|
5576
|
+
}
|
|
5577
|
+
if (typeof val === "symbol") {
|
|
5578
|
+
return val.description ? `[Symbol(${val.description})]` : "[Symbol]";
|
|
5579
|
+
}
|
|
5580
|
+
if (val instanceof Date) {
|
|
5581
|
+
return val;
|
|
5582
|
+
}
|
|
5583
|
+
if (val instanceof Error) {
|
|
5584
|
+
return {
|
|
5585
|
+
name: val.name,
|
|
5586
|
+
message: val.message ? truncateString(val.message, maxStringLength) : void 0
|
|
5587
|
+
};
|
|
5588
|
+
}
|
|
5589
|
+
if (typeof val === "object") {
|
|
5590
|
+
if (seen.has(val)) {
|
|
5591
|
+
return "[Circular]";
|
|
5592
|
+
}
|
|
5593
|
+
seen.add(val);
|
|
5594
|
+
}
|
|
5595
|
+
if (Array.isArray(val)) {
|
|
5596
|
+
const limitedArray = val.slice(0, maxArrayLength);
|
|
5597
|
+
const cleaned2 = limitedArray.map((item) => helper(item, depth + 1));
|
|
5598
|
+
if (val.length > maxArrayLength) {
|
|
5599
|
+
cleaned2.push(`[\u2026${val.length - maxArrayLength} more items]`);
|
|
5600
|
+
}
|
|
5601
|
+
return cleaned2;
|
|
5602
|
+
}
|
|
5603
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(val)) {
|
|
5604
|
+
return `[Buffer length=${val.length}]`;
|
|
5605
|
+
}
|
|
5606
|
+
if (ArrayBuffer.isView(val)) {
|
|
5607
|
+
const ctor = val.constructor?.name ?? "TypedArray";
|
|
5608
|
+
const byteLength = val.byteLength ?? "?";
|
|
5609
|
+
return `[${ctor} byteLength=${byteLength}]`;
|
|
5610
|
+
}
|
|
5611
|
+
if (val instanceof ArrayBuffer) {
|
|
5612
|
+
return `[ArrayBuffer byteLength=${val.byteLength}]`;
|
|
5613
|
+
}
|
|
5614
|
+
const cleaned = {};
|
|
5615
|
+
const entries = Object.entries(val);
|
|
5616
|
+
let keyCount = 0;
|
|
5617
|
+
for (const [key, v] of entries) {
|
|
5618
|
+
if (keysToStrip.has(key)) {
|
|
5619
|
+
continue;
|
|
5620
|
+
}
|
|
5621
|
+
if (keyCount >= maxObjectKeys) {
|
|
5622
|
+
cleaned["__truncated"] = `${entries.length - keyCount} more keys omitted`;
|
|
5623
|
+
break;
|
|
5624
|
+
}
|
|
5625
|
+
try {
|
|
5626
|
+
cleaned[key] = helper(v, depth + 1);
|
|
5627
|
+
keyCount++;
|
|
5628
|
+
} catch (error) {
|
|
5629
|
+
cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
|
|
5630
|
+
keyCount++;
|
|
5631
|
+
}
|
|
5632
|
+
}
|
|
5633
|
+
return cleaned;
|
|
5634
|
+
}
|
|
5635
|
+
return helper(value, 0);
|
|
5636
|
+
}
|
|
5637
|
+
|
|
1357
5638
|
// src/spans/base.ts
|
|
1358
5639
|
function isSpanInternal(spanType, flags) {
|
|
1359
5640
|
if (flags === void 0 || flags === InternalSpans.NONE) {
|
|
@@ -1413,13 +5694,23 @@ var BaseSpan = class {
|
|
|
1413
5694
|
metadata;
|
|
1414
5695
|
tags;
|
|
1415
5696
|
traceState;
|
|
5697
|
+
/** Entity type that created the span (e.g., agent, workflow) */
|
|
5698
|
+
entityType;
|
|
5699
|
+
/** Entity ID that created the span */
|
|
5700
|
+
entityId;
|
|
5701
|
+
/** Entity name that created the span */
|
|
5702
|
+
entityName;
|
|
1416
5703
|
/** Parent span ID (for root spans that are children of external spans) */
|
|
1417
5704
|
parentSpanId;
|
|
5705
|
+
/** Deep clean options for serialization */
|
|
5706
|
+
deepCleanOptions;
|
|
1418
5707
|
constructor(options, observabilityInstance) {
|
|
5708
|
+
const serializationOptions = observabilityInstance.getConfig().serializationOptions;
|
|
5709
|
+
this.deepCleanOptions = mergeSerializationOptions(serializationOptions);
|
|
1419
5710
|
this.name = options.name;
|
|
1420
5711
|
this.type = options.type;
|
|
1421
|
-
this.attributes = deepClean(options.attributes) || {};
|
|
1422
|
-
this.metadata = deepClean(options.metadata);
|
|
5712
|
+
this.attributes = deepClean(options.attributes, this.deepCleanOptions) || {};
|
|
5713
|
+
this.metadata = deepClean(options.metadata, this.deepCleanOptions);
|
|
1423
5714
|
this.parent = options.parent;
|
|
1424
5715
|
this.startTime = /* @__PURE__ */ new Date();
|
|
1425
5716
|
this.observabilityInstance = observabilityInstance;
|
|
@@ -1427,10 +5718,13 @@ var BaseSpan = class {
|
|
|
1427
5718
|
this.isInternal = isSpanInternal(this.type, options.tracingPolicy?.internal);
|
|
1428
5719
|
this.traceState = options.traceState;
|
|
1429
5720
|
this.tags = !options.parent && options.tags?.length ? options.tags : void 0;
|
|
5721
|
+
this.entityType = options.entityType;
|
|
5722
|
+
this.entityId = options.entityId;
|
|
5723
|
+
this.entityName = options.entityName;
|
|
1430
5724
|
if (this.isEvent) {
|
|
1431
|
-
this.output = deepClean(options.output);
|
|
5725
|
+
this.output = deepClean(options.output, this.deepCleanOptions);
|
|
1432
5726
|
} else {
|
|
1433
|
-
this.input = deepClean(options.input);
|
|
5727
|
+
this.input = deepClean(options.input, this.deepCleanOptions);
|
|
1434
5728
|
}
|
|
1435
5729
|
}
|
|
1436
5730
|
createChildSpan(options) {
|
|
@@ -1480,6 +5774,9 @@ var BaseSpan = class {
|
|
|
1480
5774
|
traceId: this.traceId,
|
|
1481
5775
|
name: this.name,
|
|
1482
5776
|
type: this.type,
|
|
5777
|
+
entityType: this.entityType,
|
|
5778
|
+
entityId: this.entityId,
|
|
5779
|
+
entityName: this.entityName,
|
|
1483
5780
|
attributes: this.attributes,
|
|
1484
5781
|
metadata: this.metadata,
|
|
1485
5782
|
startTime: this.startTime,
|
|
@@ -1520,46 +5817,6 @@ var BaseSpan = class {
|
|
|
1520
5817
|
return fn();
|
|
1521
5818
|
}
|
|
1522
5819
|
};
|
|
1523
|
-
var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
|
|
1524
|
-
"logger",
|
|
1525
|
-
"experimental_providerMetadata",
|
|
1526
|
-
"providerMetadata",
|
|
1527
|
-
"steps",
|
|
1528
|
-
"tracingContext"
|
|
1529
|
-
]);
|
|
1530
|
-
function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
|
|
1531
|
-
const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
|
|
1532
|
-
if (_depth > maxDepth) {
|
|
1533
|
-
return "[MaxDepth]";
|
|
1534
|
-
}
|
|
1535
|
-
if (value === null || typeof value !== "object") {
|
|
1536
|
-
try {
|
|
1537
|
-
JSON.stringify(value);
|
|
1538
|
-
return value;
|
|
1539
|
-
} catch (error) {
|
|
1540
|
-
return `[${error instanceof Error ? error.message : String(error)}]`;
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
if (_seen.has(value)) {
|
|
1544
|
-
return "[Circular]";
|
|
1545
|
-
}
|
|
1546
|
-
_seen.add(value);
|
|
1547
|
-
if (Array.isArray(value)) {
|
|
1548
|
-
return value.map((item) => deepClean(item, options, _seen, _depth + 1));
|
|
1549
|
-
}
|
|
1550
|
-
const cleaned = {};
|
|
1551
|
-
for (const [key, val] of Object.entries(value)) {
|
|
1552
|
-
if (keysToStrip.has(key)) {
|
|
1553
|
-
continue;
|
|
1554
|
-
}
|
|
1555
|
-
try {
|
|
1556
|
-
cleaned[key] = deepClean(val, options, _seen, _depth + 1);
|
|
1557
|
-
} catch (error) {
|
|
1558
|
-
cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
return cleaned;
|
|
1562
|
-
}
|
|
1563
5820
|
var DefaultSpan = class extends BaseSpan {
|
|
1564
5821
|
id;
|
|
1565
5822
|
traceId;
|
|
@@ -1599,13 +5856,13 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
1599
5856
|
}
|
|
1600
5857
|
this.endTime = /* @__PURE__ */ new Date();
|
|
1601
5858
|
if (options?.output !== void 0) {
|
|
1602
|
-
this.output = deepClean(options.output);
|
|
5859
|
+
this.output = deepClean(options.output, this.deepCleanOptions);
|
|
1603
5860
|
}
|
|
1604
5861
|
if (options?.attributes) {
|
|
1605
|
-
this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
|
|
5862
|
+
this.attributes = { ...this.attributes, ...deepClean(options.attributes, this.deepCleanOptions) };
|
|
1606
5863
|
}
|
|
1607
5864
|
if (options?.metadata) {
|
|
1608
|
-
this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
|
|
5865
|
+
this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
|
|
1609
5866
|
}
|
|
1610
5867
|
}
|
|
1611
5868
|
error(options) {
|
|
@@ -1623,10 +5880,10 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
1623
5880
|
message: error.message
|
|
1624
5881
|
};
|
|
1625
5882
|
if (attributes) {
|
|
1626
|
-
this.attributes = { ...this.attributes, ...deepClean(attributes) };
|
|
5883
|
+
this.attributes = { ...this.attributes, ...deepClean(attributes, this.deepCleanOptions) };
|
|
1627
5884
|
}
|
|
1628
5885
|
if (metadata) {
|
|
1629
|
-
this.metadata = { ...this.metadata, ...deepClean(metadata) };
|
|
5886
|
+
this.metadata = { ...this.metadata, ...deepClean(metadata, this.deepCleanOptions) };
|
|
1630
5887
|
}
|
|
1631
5888
|
if (endSpan) {
|
|
1632
5889
|
this.end();
|
|
@@ -1639,16 +5896,16 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
1639
5896
|
return;
|
|
1640
5897
|
}
|
|
1641
5898
|
if (options.input !== void 0) {
|
|
1642
|
-
this.input = deepClean(options.input);
|
|
5899
|
+
this.input = deepClean(options.input, this.deepCleanOptions);
|
|
1643
5900
|
}
|
|
1644
5901
|
if (options.output !== void 0) {
|
|
1645
|
-
this.output = deepClean(options.output);
|
|
5902
|
+
this.output = deepClean(options.output, this.deepCleanOptions);
|
|
1646
5903
|
}
|
|
1647
5904
|
if (options.attributes) {
|
|
1648
|
-
this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
|
|
5905
|
+
this.attributes = { ...this.attributes, ...deepClean(options.attributes, this.deepCleanOptions) };
|
|
1649
5906
|
}
|
|
1650
5907
|
if (options.metadata) {
|
|
1651
|
-
this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
|
|
5908
|
+
this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
|
|
1652
5909
|
}
|
|
1653
5910
|
}
|
|
1654
5911
|
get isValid() {
|
|
@@ -1739,7 +5996,8 @@ var BaseObservabilityInstance = class extends MastraBase {
|
|
|
1739
5996
|
spanOutputProcessors: config.spanOutputProcessors ?? [],
|
|
1740
5997
|
bridge: config.bridge ?? void 0,
|
|
1741
5998
|
includeInternalSpans: config.includeInternalSpans ?? false,
|
|
1742
|
-
requestContextKeys: config.requestContextKeys ?? []
|
|
5999
|
+
requestContextKeys: config.requestContextKeys ?? [],
|
|
6000
|
+
serializationOptions: config.serializationOptions
|
|
1743
6001
|
};
|
|
1744
6002
|
if (this.config.bridge?.init) {
|
|
1745
6003
|
this.config.bridge.init({ config: this.config });
|
|
@@ -2218,6 +6476,9 @@ var SensitiveDataFilter = class {
|
|
|
2218
6476
|
return "[Circular Reference]";
|
|
2219
6477
|
}
|
|
2220
6478
|
seen.add(obj);
|
|
6479
|
+
if (obj instanceof Date) {
|
|
6480
|
+
return obj;
|
|
6481
|
+
}
|
|
2221
6482
|
if (Array.isArray(obj)) {
|
|
2222
6483
|
return obj.map((item) => this.deepFilter(item, seen));
|
|
2223
6484
|
}
|
|
@@ -2437,6 +6698,6 @@ function buildTracingOptions(...updaters) {
|
|
|
2437
6698
|
return updaters.reduce((opts, updater) => updater(opts), {});
|
|
2438
6699
|
}
|
|
2439
6700
|
|
|
2440
|
-
export { BaseExporter, BaseObservabilityInstance, BaseSpan, CloudExporter, ConsoleExporter, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, ModelSpanTracker, NoOpSpan, Observability, SamplingStrategyType, SensitiveDataFilter, TestExporter, buildTracingOptions, deepClean, getExternalParentId, observabilityConfigValueSchema, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, samplingStrategySchema };
|
|
6701
|
+
export { BaseExporter, BaseObservabilityInstance, BaseSpan, CloudExporter, ConsoleExporter, DEFAULT_DEEP_CLEAN_OPTIONS, DEFAULT_KEYS_TO_STRIP, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, ModelSpanTracker, NoOpSpan, Observability, SamplingStrategyType, SensitiveDataFilter, TestExporter, buildTracingOptions, deepClean, getExternalParentId, mergeSerializationOptions, observabilityConfigValueSchema, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, samplingStrategySchema, serializationOptionsSchema, truncateString };
|
|
2441
6702
|
//# sourceMappingURL=index.js.map
|
|
2442
6703
|
//# sourceMappingURL=index.js.map
|