agent-package-manager 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -15
- package/cli-contract.yaml +42 -25
- package/dist/{chunk-5XXBSF75.js → chunk-YZR4CVBR.js} +8 -1
- package/dist/{chunk-5XXBSF75.js.map → chunk-YZR4CVBR.js.map} +1 -1
- package/dist/cli/index.js +4362 -161
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
VERSION
|
|
4
|
-
|
|
3
|
+
VERSION,
|
|
4
|
+
__export
|
|
5
|
+
} from "../chunk-YZR4CVBR.js";
|
|
5
6
|
|
|
6
7
|
// src/generated/cli/program.ts
|
|
7
8
|
import { Command } from "commander";
|
|
@@ -27,10 +28,10 @@ function createProgram(handlers2, version) {
|
|
|
27
28
|
program2.command("materialize").description("Build resolved DSL and generate runtime artifacts.").option("--no-generate", "Skip agent-runtime generate step.", false).option("--no-lint", "Skip agent-contracts lint step.", false).option("--clean", "Clean build directory before materializing.", false).action(async (opts, cmd) => {
|
|
28
29
|
await handlers2.materialize(opts, cmd.optsWithGlobals());
|
|
29
30
|
});
|
|
30
|
-
program2.command("check").description("Run full verification pipeline for CI.").action(async (
|
|
31
|
-
await handlers2.check(cmd.optsWithGlobals());
|
|
31
|
+
program2.command("check").description("Run full verification pipeline for CI.").action(async (opts, cmd) => {
|
|
32
|
+
await handlers2.check({}, cmd.optsWithGlobals());
|
|
32
33
|
});
|
|
33
|
-
program2.command("publish").description("Publish a package
|
|
34
|
+
program2.command("publish").description("Publish a package to a registry repository.").argument("<path>", "Path to the local package directory to publish.").option("--version <semver>", "Override version for this publish.").option("-r, --registry <url>", "Target registry in the format github:<owner>/<repo>. Falls back to the default registry in agent-pkg.json if not specified.").option("--name <name>", "Override package name (defaults to id in agent-pkg.package.json).").option("--dry-run", "Show what would be published without making changes.", false).option("--no-push", "Commit locally but do not push to remote.", false).action(async (path, opts, cmd) => {
|
|
34
35
|
await handlers2.publish(path, opts, cmd.optsWithGlobals());
|
|
35
36
|
});
|
|
36
37
|
return program2;
|
|
@@ -116,32 +117,4073 @@ function parseRegistrySpec(spec) {
|
|
|
116
117
|
}
|
|
117
118
|
return { owner, repo };
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
|
|
120
|
+
function resolveRegistryForPackage(config, packageName) {
|
|
121
|
+
const pkg = config.packages[packageName];
|
|
122
|
+
const registryName = pkg?.registry || "default";
|
|
123
|
+
const registry = config.registries[registryName];
|
|
124
|
+
if (!registry) {
|
|
125
|
+
throw new Error(`Registry "${registryName}" not found in ${JSON.stringify(Object.keys(config.registries))}`);
|
|
126
|
+
}
|
|
127
|
+
return registry;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// node_modules/zod/v3/external.js
|
|
131
|
+
var external_exports = {};
|
|
132
|
+
__export(external_exports, {
|
|
133
|
+
BRAND: () => BRAND,
|
|
134
|
+
DIRTY: () => DIRTY,
|
|
135
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
136
|
+
INVALID: () => INVALID,
|
|
137
|
+
NEVER: () => NEVER,
|
|
138
|
+
OK: () => OK,
|
|
139
|
+
ParseStatus: () => ParseStatus,
|
|
140
|
+
Schema: () => ZodType,
|
|
141
|
+
ZodAny: () => ZodAny,
|
|
142
|
+
ZodArray: () => ZodArray,
|
|
143
|
+
ZodBigInt: () => ZodBigInt,
|
|
144
|
+
ZodBoolean: () => ZodBoolean,
|
|
145
|
+
ZodBranded: () => ZodBranded,
|
|
146
|
+
ZodCatch: () => ZodCatch,
|
|
147
|
+
ZodDate: () => ZodDate,
|
|
148
|
+
ZodDefault: () => ZodDefault,
|
|
149
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
150
|
+
ZodEffects: () => ZodEffects,
|
|
151
|
+
ZodEnum: () => ZodEnum,
|
|
152
|
+
ZodError: () => ZodError,
|
|
153
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
154
|
+
ZodFunction: () => ZodFunction,
|
|
155
|
+
ZodIntersection: () => ZodIntersection,
|
|
156
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
157
|
+
ZodLazy: () => ZodLazy,
|
|
158
|
+
ZodLiteral: () => ZodLiteral,
|
|
159
|
+
ZodMap: () => ZodMap,
|
|
160
|
+
ZodNaN: () => ZodNaN,
|
|
161
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
162
|
+
ZodNever: () => ZodNever,
|
|
163
|
+
ZodNull: () => ZodNull,
|
|
164
|
+
ZodNullable: () => ZodNullable,
|
|
165
|
+
ZodNumber: () => ZodNumber,
|
|
166
|
+
ZodObject: () => ZodObject,
|
|
167
|
+
ZodOptional: () => ZodOptional,
|
|
168
|
+
ZodParsedType: () => ZodParsedType,
|
|
169
|
+
ZodPipeline: () => ZodPipeline,
|
|
170
|
+
ZodPromise: () => ZodPromise,
|
|
171
|
+
ZodReadonly: () => ZodReadonly,
|
|
172
|
+
ZodRecord: () => ZodRecord,
|
|
173
|
+
ZodSchema: () => ZodType,
|
|
174
|
+
ZodSet: () => ZodSet,
|
|
175
|
+
ZodString: () => ZodString,
|
|
176
|
+
ZodSymbol: () => ZodSymbol,
|
|
177
|
+
ZodTransformer: () => ZodEffects,
|
|
178
|
+
ZodTuple: () => ZodTuple,
|
|
179
|
+
ZodType: () => ZodType,
|
|
180
|
+
ZodUndefined: () => ZodUndefined,
|
|
181
|
+
ZodUnion: () => ZodUnion,
|
|
182
|
+
ZodUnknown: () => ZodUnknown,
|
|
183
|
+
ZodVoid: () => ZodVoid,
|
|
184
|
+
addIssueToContext: () => addIssueToContext,
|
|
185
|
+
any: () => anyType,
|
|
186
|
+
array: () => arrayType,
|
|
187
|
+
bigint: () => bigIntType,
|
|
188
|
+
boolean: () => booleanType,
|
|
189
|
+
coerce: () => coerce,
|
|
190
|
+
custom: () => custom,
|
|
191
|
+
date: () => dateType,
|
|
192
|
+
datetimeRegex: () => datetimeRegex,
|
|
193
|
+
defaultErrorMap: () => en_default,
|
|
194
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
195
|
+
effect: () => effectsType,
|
|
196
|
+
enum: () => enumType,
|
|
197
|
+
function: () => functionType,
|
|
198
|
+
getErrorMap: () => getErrorMap,
|
|
199
|
+
getParsedType: () => getParsedType,
|
|
200
|
+
instanceof: () => instanceOfType,
|
|
201
|
+
intersection: () => intersectionType,
|
|
202
|
+
isAborted: () => isAborted,
|
|
203
|
+
isAsync: () => isAsync,
|
|
204
|
+
isDirty: () => isDirty,
|
|
205
|
+
isValid: () => isValid,
|
|
206
|
+
late: () => late,
|
|
207
|
+
lazy: () => lazyType,
|
|
208
|
+
literal: () => literalType,
|
|
209
|
+
makeIssue: () => makeIssue,
|
|
210
|
+
map: () => mapType,
|
|
211
|
+
nan: () => nanType,
|
|
212
|
+
nativeEnum: () => nativeEnumType,
|
|
213
|
+
never: () => neverType,
|
|
214
|
+
null: () => nullType,
|
|
215
|
+
nullable: () => nullableType,
|
|
216
|
+
number: () => numberType,
|
|
217
|
+
object: () => objectType,
|
|
218
|
+
objectUtil: () => objectUtil,
|
|
219
|
+
oboolean: () => oboolean,
|
|
220
|
+
onumber: () => onumber,
|
|
221
|
+
optional: () => optionalType,
|
|
222
|
+
ostring: () => ostring,
|
|
223
|
+
pipeline: () => pipelineType,
|
|
224
|
+
preprocess: () => preprocessType,
|
|
225
|
+
promise: () => promiseType,
|
|
226
|
+
quotelessJson: () => quotelessJson,
|
|
227
|
+
record: () => recordType,
|
|
228
|
+
set: () => setType,
|
|
229
|
+
setErrorMap: () => setErrorMap,
|
|
230
|
+
strictObject: () => strictObjectType,
|
|
231
|
+
string: () => stringType,
|
|
232
|
+
symbol: () => symbolType,
|
|
233
|
+
transformer: () => effectsType,
|
|
234
|
+
tuple: () => tupleType,
|
|
235
|
+
undefined: () => undefinedType,
|
|
236
|
+
union: () => unionType,
|
|
237
|
+
unknown: () => unknownType,
|
|
238
|
+
util: () => util,
|
|
239
|
+
void: () => voidType
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// node_modules/zod/v3/helpers/util.js
|
|
243
|
+
var util;
|
|
244
|
+
(function(util2) {
|
|
245
|
+
util2.assertEqual = (_) => {
|
|
246
|
+
};
|
|
247
|
+
function assertIs(_arg) {
|
|
248
|
+
}
|
|
249
|
+
util2.assertIs = assertIs;
|
|
250
|
+
function assertNever(_x) {
|
|
251
|
+
throw new Error();
|
|
252
|
+
}
|
|
253
|
+
util2.assertNever = assertNever;
|
|
254
|
+
util2.arrayToEnum = (items) => {
|
|
255
|
+
const obj = {};
|
|
256
|
+
for (const item of items) {
|
|
257
|
+
obj[item] = item;
|
|
258
|
+
}
|
|
259
|
+
return obj;
|
|
260
|
+
};
|
|
261
|
+
util2.getValidEnumValues = (obj) => {
|
|
262
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
263
|
+
const filtered = {};
|
|
264
|
+
for (const k of validKeys) {
|
|
265
|
+
filtered[k] = obj[k];
|
|
266
|
+
}
|
|
267
|
+
return util2.objectValues(filtered);
|
|
268
|
+
};
|
|
269
|
+
util2.objectValues = (obj) => {
|
|
270
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
271
|
+
return obj[e];
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
275
|
+
const keys = [];
|
|
276
|
+
for (const key in object) {
|
|
277
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
278
|
+
keys.push(key);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return keys;
|
|
282
|
+
};
|
|
283
|
+
util2.find = (arr, checker) => {
|
|
284
|
+
for (const item of arr) {
|
|
285
|
+
if (checker(item))
|
|
286
|
+
return item;
|
|
287
|
+
}
|
|
288
|
+
return void 0;
|
|
289
|
+
};
|
|
290
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
291
|
+
function joinValues(array, separator = " | ") {
|
|
292
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
293
|
+
}
|
|
294
|
+
util2.joinValues = joinValues;
|
|
295
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
296
|
+
if (typeof value === "bigint") {
|
|
297
|
+
return value.toString();
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
};
|
|
301
|
+
})(util || (util = {}));
|
|
302
|
+
var objectUtil;
|
|
303
|
+
(function(objectUtil2) {
|
|
304
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
305
|
+
return {
|
|
306
|
+
...first,
|
|
307
|
+
...second
|
|
308
|
+
// second overwrites first
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
})(objectUtil || (objectUtil = {}));
|
|
312
|
+
var ZodParsedType = util.arrayToEnum([
|
|
313
|
+
"string",
|
|
314
|
+
"nan",
|
|
315
|
+
"number",
|
|
316
|
+
"integer",
|
|
317
|
+
"float",
|
|
318
|
+
"boolean",
|
|
319
|
+
"date",
|
|
320
|
+
"bigint",
|
|
321
|
+
"symbol",
|
|
322
|
+
"function",
|
|
323
|
+
"undefined",
|
|
324
|
+
"null",
|
|
325
|
+
"array",
|
|
326
|
+
"object",
|
|
327
|
+
"unknown",
|
|
328
|
+
"promise",
|
|
329
|
+
"void",
|
|
330
|
+
"never",
|
|
331
|
+
"map",
|
|
332
|
+
"set"
|
|
333
|
+
]);
|
|
334
|
+
var getParsedType = (data) => {
|
|
335
|
+
const t = typeof data;
|
|
336
|
+
switch (t) {
|
|
337
|
+
case "undefined":
|
|
338
|
+
return ZodParsedType.undefined;
|
|
339
|
+
case "string":
|
|
340
|
+
return ZodParsedType.string;
|
|
341
|
+
case "number":
|
|
342
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
343
|
+
case "boolean":
|
|
344
|
+
return ZodParsedType.boolean;
|
|
345
|
+
case "function":
|
|
346
|
+
return ZodParsedType.function;
|
|
347
|
+
case "bigint":
|
|
348
|
+
return ZodParsedType.bigint;
|
|
349
|
+
case "symbol":
|
|
350
|
+
return ZodParsedType.symbol;
|
|
351
|
+
case "object":
|
|
352
|
+
if (Array.isArray(data)) {
|
|
353
|
+
return ZodParsedType.array;
|
|
354
|
+
}
|
|
355
|
+
if (data === null) {
|
|
356
|
+
return ZodParsedType.null;
|
|
357
|
+
}
|
|
358
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
359
|
+
return ZodParsedType.promise;
|
|
360
|
+
}
|
|
361
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
362
|
+
return ZodParsedType.map;
|
|
363
|
+
}
|
|
364
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
365
|
+
return ZodParsedType.set;
|
|
366
|
+
}
|
|
367
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
368
|
+
return ZodParsedType.date;
|
|
369
|
+
}
|
|
370
|
+
return ZodParsedType.object;
|
|
371
|
+
default:
|
|
372
|
+
return ZodParsedType.unknown;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// node_modules/zod/v3/ZodError.js
|
|
377
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
378
|
+
"invalid_type",
|
|
379
|
+
"invalid_literal",
|
|
380
|
+
"custom",
|
|
381
|
+
"invalid_union",
|
|
382
|
+
"invalid_union_discriminator",
|
|
383
|
+
"invalid_enum_value",
|
|
384
|
+
"unrecognized_keys",
|
|
385
|
+
"invalid_arguments",
|
|
386
|
+
"invalid_return_type",
|
|
387
|
+
"invalid_date",
|
|
388
|
+
"invalid_string",
|
|
389
|
+
"too_small",
|
|
390
|
+
"too_big",
|
|
391
|
+
"invalid_intersection_types",
|
|
392
|
+
"not_multiple_of",
|
|
393
|
+
"not_finite"
|
|
394
|
+
]);
|
|
395
|
+
var quotelessJson = (obj) => {
|
|
396
|
+
const json = JSON.stringify(obj, null, 2);
|
|
397
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
398
|
+
};
|
|
399
|
+
var ZodError = class _ZodError extends Error {
|
|
400
|
+
get errors() {
|
|
401
|
+
return this.issues;
|
|
402
|
+
}
|
|
403
|
+
constructor(issues) {
|
|
404
|
+
super();
|
|
405
|
+
this.issues = [];
|
|
406
|
+
this.addIssue = (sub) => {
|
|
407
|
+
this.issues = [...this.issues, sub];
|
|
408
|
+
};
|
|
409
|
+
this.addIssues = (subs = []) => {
|
|
410
|
+
this.issues = [...this.issues, ...subs];
|
|
411
|
+
};
|
|
412
|
+
const actualProto = new.target.prototype;
|
|
413
|
+
if (Object.setPrototypeOf) {
|
|
414
|
+
Object.setPrototypeOf(this, actualProto);
|
|
415
|
+
} else {
|
|
416
|
+
this.__proto__ = actualProto;
|
|
417
|
+
}
|
|
418
|
+
this.name = "ZodError";
|
|
419
|
+
this.issues = issues;
|
|
420
|
+
}
|
|
421
|
+
format(_mapper) {
|
|
422
|
+
const mapper = _mapper || function(issue) {
|
|
423
|
+
return issue.message;
|
|
424
|
+
};
|
|
425
|
+
const fieldErrors = { _errors: [] };
|
|
426
|
+
const processError = (error) => {
|
|
427
|
+
for (const issue of error.issues) {
|
|
428
|
+
if (issue.code === "invalid_union") {
|
|
429
|
+
issue.unionErrors.map(processError);
|
|
430
|
+
} else if (issue.code === "invalid_return_type") {
|
|
431
|
+
processError(issue.returnTypeError);
|
|
432
|
+
} else if (issue.code === "invalid_arguments") {
|
|
433
|
+
processError(issue.argumentsError);
|
|
434
|
+
} else if (issue.path.length === 0) {
|
|
435
|
+
fieldErrors._errors.push(mapper(issue));
|
|
436
|
+
} else {
|
|
437
|
+
let curr = fieldErrors;
|
|
438
|
+
let i = 0;
|
|
439
|
+
while (i < issue.path.length) {
|
|
440
|
+
const el = issue.path[i];
|
|
441
|
+
const terminal = i === issue.path.length - 1;
|
|
442
|
+
if (!terminal) {
|
|
443
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
444
|
+
} else {
|
|
445
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
446
|
+
curr[el]._errors.push(mapper(issue));
|
|
447
|
+
}
|
|
448
|
+
curr = curr[el];
|
|
449
|
+
i++;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
processError(this);
|
|
455
|
+
return fieldErrors;
|
|
456
|
+
}
|
|
457
|
+
static assert(value) {
|
|
458
|
+
if (!(value instanceof _ZodError)) {
|
|
459
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
toString() {
|
|
463
|
+
return this.message;
|
|
464
|
+
}
|
|
465
|
+
get message() {
|
|
466
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
467
|
+
}
|
|
468
|
+
get isEmpty() {
|
|
469
|
+
return this.issues.length === 0;
|
|
470
|
+
}
|
|
471
|
+
flatten(mapper = (issue) => issue.message) {
|
|
472
|
+
const fieldErrors = {};
|
|
473
|
+
const formErrors = [];
|
|
474
|
+
for (const sub of this.issues) {
|
|
475
|
+
if (sub.path.length > 0) {
|
|
476
|
+
const firstEl = sub.path[0];
|
|
477
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
478
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
479
|
+
} else {
|
|
480
|
+
formErrors.push(mapper(sub));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return { formErrors, fieldErrors };
|
|
484
|
+
}
|
|
485
|
+
get formErrors() {
|
|
486
|
+
return this.flatten();
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
ZodError.create = (issues) => {
|
|
490
|
+
const error = new ZodError(issues);
|
|
491
|
+
return error;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// node_modules/zod/v3/locales/en.js
|
|
495
|
+
var errorMap = (issue, _ctx) => {
|
|
496
|
+
let message;
|
|
497
|
+
switch (issue.code) {
|
|
498
|
+
case ZodIssueCode.invalid_type:
|
|
499
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
500
|
+
message = "Required";
|
|
501
|
+
} else {
|
|
502
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
505
|
+
case ZodIssueCode.invalid_literal:
|
|
506
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
507
|
+
break;
|
|
508
|
+
case ZodIssueCode.unrecognized_keys:
|
|
509
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
510
|
+
break;
|
|
511
|
+
case ZodIssueCode.invalid_union:
|
|
512
|
+
message = `Invalid input`;
|
|
513
|
+
break;
|
|
514
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
515
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
516
|
+
break;
|
|
517
|
+
case ZodIssueCode.invalid_enum_value:
|
|
518
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
519
|
+
break;
|
|
520
|
+
case ZodIssueCode.invalid_arguments:
|
|
521
|
+
message = `Invalid function arguments`;
|
|
522
|
+
break;
|
|
523
|
+
case ZodIssueCode.invalid_return_type:
|
|
524
|
+
message = `Invalid function return type`;
|
|
525
|
+
break;
|
|
526
|
+
case ZodIssueCode.invalid_date:
|
|
527
|
+
message = `Invalid date`;
|
|
528
|
+
break;
|
|
529
|
+
case ZodIssueCode.invalid_string:
|
|
530
|
+
if (typeof issue.validation === "object") {
|
|
531
|
+
if ("includes" in issue.validation) {
|
|
532
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
533
|
+
if (typeof issue.validation.position === "number") {
|
|
534
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
535
|
+
}
|
|
536
|
+
} else if ("startsWith" in issue.validation) {
|
|
537
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
538
|
+
} else if ("endsWith" in issue.validation) {
|
|
539
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
540
|
+
} else {
|
|
541
|
+
util.assertNever(issue.validation);
|
|
542
|
+
}
|
|
543
|
+
} else if (issue.validation !== "regex") {
|
|
544
|
+
message = `Invalid ${issue.validation}`;
|
|
545
|
+
} else {
|
|
546
|
+
message = "Invalid";
|
|
547
|
+
}
|
|
548
|
+
break;
|
|
549
|
+
case ZodIssueCode.too_small:
|
|
550
|
+
if (issue.type === "array")
|
|
551
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
552
|
+
else if (issue.type === "string")
|
|
553
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
554
|
+
else if (issue.type === "number")
|
|
555
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
556
|
+
else if (issue.type === "bigint")
|
|
557
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
558
|
+
else if (issue.type === "date")
|
|
559
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
560
|
+
else
|
|
561
|
+
message = "Invalid input";
|
|
562
|
+
break;
|
|
563
|
+
case ZodIssueCode.too_big:
|
|
564
|
+
if (issue.type === "array")
|
|
565
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
566
|
+
else if (issue.type === "string")
|
|
567
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
568
|
+
else if (issue.type === "number")
|
|
569
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
570
|
+
else if (issue.type === "bigint")
|
|
571
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
572
|
+
else if (issue.type === "date")
|
|
573
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
574
|
+
else
|
|
575
|
+
message = "Invalid input";
|
|
576
|
+
break;
|
|
577
|
+
case ZodIssueCode.custom:
|
|
578
|
+
message = `Invalid input`;
|
|
579
|
+
break;
|
|
580
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
581
|
+
message = `Intersection results could not be merged`;
|
|
582
|
+
break;
|
|
583
|
+
case ZodIssueCode.not_multiple_of:
|
|
584
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
585
|
+
break;
|
|
586
|
+
case ZodIssueCode.not_finite:
|
|
587
|
+
message = "Number must be finite";
|
|
588
|
+
break;
|
|
589
|
+
default:
|
|
590
|
+
message = _ctx.defaultError;
|
|
591
|
+
util.assertNever(issue);
|
|
592
|
+
}
|
|
593
|
+
return { message };
|
|
594
|
+
};
|
|
595
|
+
var en_default = errorMap;
|
|
596
|
+
|
|
597
|
+
// node_modules/zod/v3/errors.js
|
|
598
|
+
var overrideErrorMap = en_default;
|
|
599
|
+
function setErrorMap(map) {
|
|
600
|
+
overrideErrorMap = map;
|
|
601
|
+
}
|
|
602
|
+
function getErrorMap() {
|
|
603
|
+
return overrideErrorMap;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// node_modules/zod/v3/helpers/parseUtil.js
|
|
607
|
+
var makeIssue = (params) => {
|
|
608
|
+
const { data, path, errorMaps, issueData } = params;
|
|
609
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
610
|
+
const fullIssue = {
|
|
611
|
+
...issueData,
|
|
612
|
+
path: fullPath
|
|
613
|
+
};
|
|
614
|
+
if (issueData.message !== void 0) {
|
|
615
|
+
return {
|
|
616
|
+
...issueData,
|
|
617
|
+
path: fullPath,
|
|
618
|
+
message: issueData.message
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
let errorMessage = "";
|
|
622
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
623
|
+
for (const map of maps) {
|
|
624
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
...issueData,
|
|
628
|
+
path: fullPath,
|
|
629
|
+
message: errorMessage
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
var EMPTY_PATH = [];
|
|
633
|
+
function addIssueToContext(ctx, issueData) {
|
|
634
|
+
const overrideMap = getErrorMap();
|
|
635
|
+
const issue = makeIssue({
|
|
636
|
+
issueData,
|
|
637
|
+
data: ctx.data,
|
|
638
|
+
path: ctx.path,
|
|
639
|
+
errorMaps: [
|
|
640
|
+
ctx.common.contextualErrorMap,
|
|
641
|
+
// contextual error map is first priority
|
|
642
|
+
ctx.schemaErrorMap,
|
|
643
|
+
// then schema-bound map if available
|
|
644
|
+
overrideMap,
|
|
645
|
+
// then global override map
|
|
646
|
+
overrideMap === en_default ? void 0 : en_default
|
|
647
|
+
// then global default map
|
|
648
|
+
].filter((x) => !!x)
|
|
649
|
+
});
|
|
650
|
+
ctx.common.issues.push(issue);
|
|
651
|
+
}
|
|
652
|
+
var ParseStatus = class _ParseStatus {
|
|
653
|
+
constructor() {
|
|
654
|
+
this.value = "valid";
|
|
655
|
+
}
|
|
656
|
+
dirty() {
|
|
657
|
+
if (this.value === "valid")
|
|
658
|
+
this.value = "dirty";
|
|
659
|
+
}
|
|
660
|
+
abort() {
|
|
661
|
+
if (this.value !== "aborted")
|
|
662
|
+
this.value = "aborted";
|
|
663
|
+
}
|
|
664
|
+
static mergeArray(status, results) {
|
|
665
|
+
const arrayValue = [];
|
|
666
|
+
for (const s of results) {
|
|
667
|
+
if (s.status === "aborted")
|
|
668
|
+
return INVALID;
|
|
669
|
+
if (s.status === "dirty")
|
|
670
|
+
status.dirty();
|
|
671
|
+
arrayValue.push(s.value);
|
|
672
|
+
}
|
|
673
|
+
return { status: status.value, value: arrayValue };
|
|
674
|
+
}
|
|
675
|
+
static async mergeObjectAsync(status, pairs) {
|
|
676
|
+
const syncPairs = [];
|
|
677
|
+
for (const pair of pairs) {
|
|
678
|
+
const key = await pair.key;
|
|
679
|
+
const value = await pair.value;
|
|
680
|
+
syncPairs.push({
|
|
681
|
+
key,
|
|
682
|
+
value
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
686
|
+
}
|
|
687
|
+
static mergeObjectSync(status, pairs) {
|
|
688
|
+
const finalObject = {};
|
|
689
|
+
for (const pair of pairs) {
|
|
690
|
+
const { key, value } = pair;
|
|
691
|
+
if (key.status === "aborted")
|
|
692
|
+
return INVALID;
|
|
693
|
+
if (value.status === "aborted")
|
|
694
|
+
return INVALID;
|
|
695
|
+
if (key.status === "dirty")
|
|
696
|
+
status.dirty();
|
|
697
|
+
if (value.status === "dirty")
|
|
698
|
+
status.dirty();
|
|
699
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
700
|
+
finalObject[key.value] = value.value;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return { status: status.value, value: finalObject };
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
var INVALID = Object.freeze({
|
|
707
|
+
status: "aborted"
|
|
708
|
+
});
|
|
709
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
710
|
+
var OK = (value) => ({ status: "valid", value });
|
|
711
|
+
var isAborted = (x) => x.status === "aborted";
|
|
712
|
+
var isDirty = (x) => x.status === "dirty";
|
|
713
|
+
var isValid = (x) => x.status === "valid";
|
|
714
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
715
|
+
|
|
716
|
+
// node_modules/zod/v3/helpers/errorUtil.js
|
|
717
|
+
var errorUtil;
|
|
718
|
+
(function(errorUtil2) {
|
|
719
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
720
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
721
|
+
})(errorUtil || (errorUtil = {}));
|
|
722
|
+
|
|
723
|
+
// node_modules/zod/v3/types.js
|
|
724
|
+
var ParseInputLazyPath = class {
|
|
725
|
+
constructor(parent, value, path, key) {
|
|
726
|
+
this._cachedPath = [];
|
|
727
|
+
this.parent = parent;
|
|
728
|
+
this.data = value;
|
|
729
|
+
this._path = path;
|
|
730
|
+
this._key = key;
|
|
731
|
+
}
|
|
732
|
+
get path() {
|
|
733
|
+
if (!this._cachedPath.length) {
|
|
734
|
+
if (Array.isArray(this._key)) {
|
|
735
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
736
|
+
} else {
|
|
737
|
+
this._cachedPath.push(...this._path, this._key);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return this._cachedPath;
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
var handleResult = (ctx, result) => {
|
|
744
|
+
if (isValid(result)) {
|
|
745
|
+
return { success: true, data: result.value };
|
|
746
|
+
} else {
|
|
747
|
+
if (!ctx.common.issues.length) {
|
|
748
|
+
throw new Error("Validation failed but no issues detected.");
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
success: false,
|
|
752
|
+
get error() {
|
|
753
|
+
if (this._error)
|
|
754
|
+
return this._error;
|
|
755
|
+
const error = new ZodError(ctx.common.issues);
|
|
756
|
+
this._error = error;
|
|
757
|
+
return this._error;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
function processCreateParams(params) {
|
|
763
|
+
if (!params)
|
|
764
|
+
return {};
|
|
765
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
766
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
767
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
768
|
+
}
|
|
769
|
+
if (errorMap2)
|
|
770
|
+
return { errorMap: errorMap2, description };
|
|
771
|
+
const customMap = (iss, ctx) => {
|
|
772
|
+
const { message } = params;
|
|
773
|
+
if (iss.code === "invalid_enum_value") {
|
|
774
|
+
return { message: message ?? ctx.defaultError };
|
|
775
|
+
}
|
|
776
|
+
if (typeof ctx.data === "undefined") {
|
|
777
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
778
|
+
}
|
|
779
|
+
if (iss.code !== "invalid_type")
|
|
780
|
+
return { message: ctx.defaultError };
|
|
781
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
782
|
+
};
|
|
783
|
+
return { errorMap: customMap, description };
|
|
784
|
+
}
|
|
785
|
+
var ZodType = class {
|
|
786
|
+
get description() {
|
|
787
|
+
return this._def.description;
|
|
788
|
+
}
|
|
789
|
+
_getType(input) {
|
|
790
|
+
return getParsedType(input.data);
|
|
791
|
+
}
|
|
792
|
+
_getOrReturnCtx(input, ctx) {
|
|
793
|
+
return ctx || {
|
|
794
|
+
common: input.parent.common,
|
|
795
|
+
data: input.data,
|
|
796
|
+
parsedType: getParsedType(input.data),
|
|
797
|
+
schemaErrorMap: this._def.errorMap,
|
|
798
|
+
path: input.path,
|
|
799
|
+
parent: input.parent
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
_processInputParams(input) {
|
|
803
|
+
return {
|
|
804
|
+
status: new ParseStatus(),
|
|
805
|
+
ctx: {
|
|
806
|
+
common: input.parent.common,
|
|
807
|
+
data: input.data,
|
|
808
|
+
parsedType: getParsedType(input.data),
|
|
809
|
+
schemaErrorMap: this._def.errorMap,
|
|
810
|
+
path: input.path,
|
|
811
|
+
parent: input.parent
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
_parseSync(input) {
|
|
816
|
+
const result = this._parse(input);
|
|
817
|
+
if (isAsync(result)) {
|
|
818
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
819
|
+
}
|
|
820
|
+
return result;
|
|
821
|
+
}
|
|
822
|
+
_parseAsync(input) {
|
|
823
|
+
const result = this._parse(input);
|
|
824
|
+
return Promise.resolve(result);
|
|
825
|
+
}
|
|
826
|
+
parse(data, params) {
|
|
827
|
+
const result = this.safeParse(data, params);
|
|
828
|
+
if (result.success)
|
|
829
|
+
return result.data;
|
|
830
|
+
throw result.error;
|
|
831
|
+
}
|
|
832
|
+
safeParse(data, params) {
|
|
833
|
+
const ctx = {
|
|
834
|
+
common: {
|
|
835
|
+
issues: [],
|
|
836
|
+
async: params?.async ?? false,
|
|
837
|
+
contextualErrorMap: params?.errorMap
|
|
838
|
+
},
|
|
839
|
+
path: params?.path || [],
|
|
840
|
+
schemaErrorMap: this._def.errorMap,
|
|
841
|
+
parent: null,
|
|
842
|
+
data,
|
|
843
|
+
parsedType: getParsedType(data)
|
|
844
|
+
};
|
|
845
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
846
|
+
return handleResult(ctx, result);
|
|
847
|
+
}
|
|
848
|
+
"~validate"(data) {
|
|
849
|
+
const ctx = {
|
|
850
|
+
common: {
|
|
851
|
+
issues: [],
|
|
852
|
+
async: !!this["~standard"].async
|
|
853
|
+
},
|
|
854
|
+
path: [],
|
|
855
|
+
schemaErrorMap: this._def.errorMap,
|
|
856
|
+
parent: null,
|
|
857
|
+
data,
|
|
858
|
+
parsedType: getParsedType(data)
|
|
859
|
+
};
|
|
860
|
+
if (!this["~standard"].async) {
|
|
861
|
+
try {
|
|
862
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
863
|
+
return isValid(result) ? {
|
|
864
|
+
value: result.value
|
|
865
|
+
} : {
|
|
866
|
+
issues: ctx.common.issues
|
|
867
|
+
};
|
|
868
|
+
} catch (err) {
|
|
869
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
870
|
+
this["~standard"].async = true;
|
|
871
|
+
}
|
|
872
|
+
ctx.common = {
|
|
873
|
+
issues: [],
|
|
874
|
+
async: true
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
879
|
+
value: result.value
|
|
880
|
+
} : {
|
|
881
|
+
issues: ctx.common.issues
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
async parseAsync(data, params) {
|
|
885
|
+
const result = await this.safeParseAsync(data, params);
|
|
886
|
+
if (result.success)
|
|
887
|
+
return result.data;
|
|
888
|
+
throw result.error;
|
|
889
|
+
}
|
|
890
|
+
async safeParseAsync(data, params) {
|
|
891
|
+
const ctx = {
|
|
892
|
+
common: {
|
|
893
|
+
issues: [],
|
|
894
|
+
contextualErrorMap: params?.errorMap,
|
|
895
|
+
async: true
|
|
896
|
+
},
|
|
897
|
+
path: params?.path || [],
|
|
898
|
+
schemaErrorMap: this._def.errorMap,
|
|
899
|
+
parent: null,
|
|
900
|
+
data,
|
|
901
|
+
parsedType: getParsedType(data)
|
|
902
|
+
};
|
|
903
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
904
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
905
|
+
return handleResult(ctx, result);
|
|
906
|
+
}
|
|
907
|
+
refine(check, message) {
|
|
908
|
+
const getIssueProperties = (val) => {
|
|
909
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
910
|
+
return { message };
|
|
911
|
+
} else if (typeof message === "function") {
|
|
912
|
+
return message(val);
|
|
913
|
+
} else {
|
|
914
|
+
return message;
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
return this._refinement((val, ctx) => {
|
|
918
|
+
const result = check(val);
|
|
919
|
+
const setError = () => ctx.addIssue({
|
|
920
|
+
code: ZodIssueCode.custom,
|
|
921
|
+
...getIssueProperties(val)
|
|
922
|
+
});
|
|
923
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
924
|
+
return result.then((data) => {
|
|
925
|
+
if (!data) {
|
|
926
|
+
setError();
|
|
927
|
+
return false;
|
|
928
|
+
} else {
|
|
929
|
+
return true;
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
if (!result) {
|
|
934
|
+
setError();
|
|
935
|
+
return false;
|
|
936
|
+
} else {
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
refinement(check, refinementData) {
|
|
942
|
+
return this._refinement((val, ctx) => {
|
|
943
|
+
if (!check(val)) {
|
|
944
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
945
|
+
return false;
|
|
946
|
+
} else {
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
_refinement(refinement) {
|
|
952
|
+
return new ZodEffects({
|
|
953
|
+
schema: this,
|
|
954
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
955
|
+
effect: { type: "refinement", refinement }
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
superRefine(refinement) {
|
|
959
|
+
return this._refinement(refinement);
|
|
960
|
+
}
|
|
961
|
+
constructor(def) {
|
|
962
|
+
this.spa = this.safeParseAsync;
|
|
963
|
+
this._def = def;
|
|
964
|
+
this.parse = this.parse.bind(this);
|
|
965
|
+
this.safeParse = this.safeParse.bind(this);
|
|
966
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
967
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
968
|
+
this.spa = this.spa.bind(this);
|
|
969
|
+
this.refine = this.refine.bind(this);
|
|
970
|
+
this.refinement = this.refinement.bind(this);
|
|
971
|
+
this.superRefine = this.superRefine.bind(this);
|
|
972
|
+
this.optional = this.optional.bind(this);
|
|
973
|
+
this.nullable = this.nullable.bind(this);
|
|
974
|
+
this.nullish = this.nullish.bind(this);
|
|
975
|
+
this.array = this.array.bind(this);
|
|
976
|
+
this.promise = this.promise.bind(this);
|
|
977
|
+
this.or = this.or.bind(this);
|
|
978
|
+
this.and = this.and.bind(this);
|
|
979
|
+
this.transform = this.transform.bind(this);
|
|
980
|
+
this.brand = this.brand.bind(this);
|
|
981
|
+
this.default = this.default.bind(this);
|
|
982
|
+
this.catch = this.catch.bind(this);
|
|
983
|
+
this.describe = this.describe.bind(this);
|
|
984
|
+
this.pipe = this.pipe.bind(this);
|
|
985
|
+
this.readonly = this.readonly.bind(this);
|
|
986
|
+
this.isNullable = this.isNullable.bind(this);
|
|
987
|
+
this.isOptional = this.isOptional.bind(this);
|
|
988
|
+
this["~standard"] = {
|
|
989
|
+
version: 1,
|
|
990
|
+
vendor: "zod",
|
|
991
|
+
validate: (data) => this["~validate"](data)
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
optional() {
|
|
995
|
+
return ZodOptional.create(this, this._def);
|
|
996
|
+
}
|
|
997
|
+
nullable() {
|
|
998
|
+
return ZodNullable.create(this, this._def);
|
|
999
|
+
}
|
|
1000
|
+
nullish() {
|
|
1001
|
+
return this.nullable().optional();
|
|
1002
|
+
}
|
|
1003
|
+
array() {
|
|
1004
|
+
return ZodArray.create(this);
|
|
1005
|
+
}
|
|
1006
|
+
promise() {
|
|
1007
|
+
return ZodPromise.create(this, this._def);
|
|
1008
|
+
}
|
|
1009
|
+
or(option) {
|
|
1010
|
+
return ZodUnion.create([this, option], this._def);
|
|
1011
|
+
}
|
|
1012
|
+
and(incoming) {
|
|
1013
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
1014
|
+
}
|
|
1015
|
+
transform(transform) {
|
|
1016
|
+
return new ZodEffects({
|
|
1017
|
+
...processCreateParams(this._def),
|
|
1018
|
+
schema: this,
|
|
1019
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1020
|
+
effect: { type: "transform", transform }
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
default(def) {
|
|
1024
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1025
|
+
return new ZodDefault({
|
|
1026
|
+
...processCreateParams(this._def),
|
|
1027
|
+
innerType: this,
|
|
1028
|
+
defaultValue: defaultValueFunc,
|
|
1029
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
brand() {
|
|
1033
|
+
return new ZodBranded({
|
|
1034
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1035
|
+
type: this,
|
|
1036
|
+
...processCreateParams(this._def)
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
catch(def) {
|
|
1040
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1041
|
+
return new ZodCatch({
|
|
1042
|
+
...processCreateParams(this._def),
|
|
1043
|
+
innerType: this,
|
|
1044
|
+
catchValue: catchValueFunc,
|
|
1045
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
describe(description) {
|
|
1049
|
+
const This = this.constructor;
|
|
1050
|
+
return new This({
|
|
1051
|
+
...this._def,
|
|
1052
|
+
description
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
pipe(target) {
|
|
1056
|
+
return ZodPipeline.create(this, target);
|
|
1057
|
+
}
|
|
1058
|
+
readonly() {
|
|
1059
|
+
return ZodReadonly.create(this);
|
|
1060
|
+
}
|
|
1061
|
+
isOptional() {
|
|
1062
|
+
return this.safeParse(void 0).success;
|
|
1063
|
+
}
|
|
1064
|
+
isNullable() {
|
|
1065
|
+
return this.safeParse(null).success;
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1069
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
1070
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1071
|
+
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;
|
|
1072
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1073
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1074
|
+
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)?)??$/;
|
|
1075
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1076
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1077
|
+
var emojiRegex;
|
|
1078
|
+
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])$/;
|
|
1079
|
+
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])$/;
|
|
1080
|
+
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]))$/;
|
|
1081
|
+
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])$/;
|
|
1082
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1083
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1084
|
+
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])))`;
|
|
1085
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1086
|
+
function timeRegexSource(args) {
|
|
1087
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1088
|
+
if (args.precision) {
|
|
1089
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1090
|
+
} else if (args.precision == null) {
|
|
1091
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1092
|
+
}
|
|
1093
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1094
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1095
|
+
}
|
|
1096
|
+
function timeRegex(args) {
|
|
1097
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1098
|
+
}
|
|
1099
|
+
function datetimeRegex(args) {
|
|
1100
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1101
|
+
const opts = [];
|
|
1102
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1103
|
+
if (args.offset)
|
|
1104
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1105
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1106
|
+
return new RegExp(`^${regex}$`);
|
|
1107
|
+
}
|
|
1108
|
+
function isValidIP(ip, version) {
|
|
1109
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1112
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
function isValidJWT(jwt, alg) {
|
|
1118
|
+
if (!jwtRegex.test(jwt))
|
|
1119
|
+
return false;
|
|
1120
|
+
try {
|
|
1121
|
+
const [header] = jwt.split(".");
|
|
1122
|
+
if (!header)
|
|
1123
|
+
return false;
|
|
1124
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1125
|
+
const decoded = JSON.parse(atob(base64));
|
|
1126
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1127
|
+
return false;
|
|
1128
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1129
|
+
return false;
|
|
1130
|
+
if (!decoded.alg)
|
|
1131
|
+
return false;
|
|
1132
|
+
if (alg && decoded.alg !== alg)
|
|
1133
|
+
return false;
|
|
1134
|
+
return true;
|
|
1135
|
+
} catch {
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
function isValidCidr(ip, version) {
|
|
1140
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1141
|
+
return true;
|
|
1142
|
+
}
|
|
1143
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1144
|
+
return true;
|
|
1145
|
+
}
|
|
1146
|
+
return false;
|
|
1147
|
+
}
|
|
1148
|
+
var ZodString = class _ZodString extends ZodType {
|
|
1149
|
+
_parse(input) {
|
|
1150
|
+
if (this._def.coerce) {
|
|
1151
|
+
input.data = String(input.data);
|
|
1152
|
+
}
|
|
1153
|
+
const parsedType = this._getType(input);
|
|
1154
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1155
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1156
|
+
addIssueToContext(ctx2, {
|
|
1157
|
+
code: ZodIssueCode.invalid_type,
|
|
1158
|
+
expected: ZodParsedType.string,
|
|
1159
|
+
received: ctx2.parsedType
|
|
1160
|
+
});
|
|
1161
|
+
return INVALID;
|
|
1162
|
+
}
|
|
1163
|
+
const status = new ParseStatus();
|
|
1164
|
+
let ctx = void 0;
|
|
1165
|
+
for (const check of this._def.checks) {
|
|
1166
|
+
if (check.kind === "min") {
|
|
1167
|
+
if (input.data.length < check.value) {
|
|
1168
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1169
|
+
addIssueToContext(ctx, {
|
|
1170
|
+
code: ZodIssueCode.too_small,
|
|
1171
|
+
minimum: check.value,
|
|
1172
|
+
type: "string",
|
|
1173
|
+
inclusive: true,
|
|
1174
|
+
exact: false,
|
|
1175
|
+
message: check.message
|
|
1176
|
+
});
|
|
1177
|
+
status.dirty();
|
|
1178
|
+
}
|
|
1179
|
+
} else if (check.kind === "max") {
|
|
1180
|
+
if (input.data.length > check.value) {
|
|
1181
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1182
|
+
addIssueToContext(ctx, {
|
|
1183
|
+
code: ZodIssueCode.too_big,
|
|
1184
|
+
maximum: check.value,
|
|
1185
|
+
type: "string",
|
|
1186
|
+
inclusive: true,
|
|
1187
|
+
exact: false,
|
|
1188
|
+
message: check.message
|
|
1189
|
+
});
|
|
1190
|
+
status.dirty();
|
|
1191
|
+
}
|
|
1192
|
+
} else if (check.kind === "length") {
|
|
1193
|
+
const tooBig = input.data.length > check.value;
|
|
1194
|
+
const tooSmall = input.data.length < check.value;
|
|
1195
|
+
if (tooBig || tooSmall) {
|
|
1196
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1197
|
+
if (tooBig) {
|
|
1198
|
+
addIssueToContext(ctx, {
|
|
1199
|
+
code: ZodIssueCode.too_big,
|
|
1200
|
+
maximum: check.value,
|
|
1201
|
+
type: "string",
|
|
1202
|
+
inclusive: true,
|
|
1203
|
+
exact: true,
|
|
1204
|
+
message: check.message
|
|
1205
|
+
});
|
|
1206
|
+
} else if (tooSmall) {
|
|
1207
|
+
addIssueToContext(ctx, {
|
|
1208
|
+
code: ZodIssueCode.too_small,
|
|
1209
|
+
minimum: check.value,
|
|
1210
|
+
type: "string",
|
|
1211
|
+
inclusive: true,
|
|
1212
|
+
exact: true,
|
|
1213
|
+
message: check.message
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
status.dirty();
|
|
1217
|
+
}
|
|
1218
|
+
} else if (check.kind === "email") {
|
|
1219
|
+
if (!emailRegex.test(input.data)) {
|
|
1220
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1221
|
+
addIssueToContext(ctx, {
|
|
1222
|
+
validation: "email",
|
|
1223
|
+
code: ZodIssueCode.invalid_string,
|
|
1224
|
+
message: check.message
|
|
1225
|
+
});
|
|
1226
|
+
status.dirty();
|
|
1227
|
+
}
|
|
1228
|
+
} else if (check.kind === "emoji") {
|
|
1229
|
+
if (!emojiRegex) {
|
|
1230
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1231
|
+
}
|
|
1232
|
+
if (!emojiRegex.test(input.data)) {
|
|
1233
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1234
|
+
addIssueToContext(ctx, {
|
|
1235
|
+
validation: "emoji",
|
|
1236
|
+
code: ZodIssueCode.invalid_string,
|
|
1237
|
+
message: check.message
|
|
1238
|
+
});
|
|
1239
|
+
status.dirty();
|
|
1240
|
+
}
|
|
1241
|
+
} else if (check.kind === "uuid") {
|
|
1242
|
+
if (!uuidRegex.test(input.data)) {
|
|
1243
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1244
|
+
addIssueToContext(ctx, {
|
|
1245
|
+
validation: "uuid",
|
|
1246
|
+
code: ZodIssueCode.invalid_string,
|
|
1247
|
+
message: check.message
|
|
1248
|
+
});
|
|
1249
|
+
status.dirty();
|
|
1250
|
+
}
|
|
1251
|
+
} else if (check.kind === "nanoid") {
|
|
1252
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1253
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1254
|
+
addIssueToContext(ctx, {
|
|
1255
|
+
validation: "nanoid",
|
|
1256
|
+
code: ZodIssueCode.invalid_string,
|
|
1257
|
+
message: check.message
|
|
1258
|
+
});
|
|
1259
|
+
status.dirty();
|
|
1260
|
+
}
|
|
1261
|
+
} else if (check.kind === "cuid") {
|
|
1262
|
+
if (!cuidRegex.test(input.data)) {
|
|
1263
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1264
|
+
addIssueToContext(ctx, {
|
|
1265
|
+
validation: "cuid",
|
|
1266
|
+
code: ZodIssueCode.invalid_string,
|
|
1267
|
+
message: check.message
|
|
1268
|
+
});
|
|
1269
|
+
status.dirty();
|
|
1270
|
+
}
|
|
1271
|
+
} else if (check.kind === "cuid2") {
|
|
1272
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1273
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1274
|
+
addIssueToContext(ctx, {
|
|
1275
|
+
validation: "cuid2",
|
|
1276
|
+
code: ZodIssueCode.invalid_string,
|
|
1277
|
+
message: check.message
|
|
1278
|
+
});
|
|
1279
|
+
status.dirty();
|
|
1280
|
+
}
|
|
1281
|
+
} else if (check.kind === "ulid") {
|
|
1282
|
+
if (!ulidRegex.test(input.data)) {
|
|
1283
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1284
|
+
addIssueToContext(ctx, {
|
|
1285
|
+
validation: "ulid",
|
|
1286
|
+
code: ZodIssueCode.invalid_string,
|
|
1287
|
+
message: check.message
|
|
1288
|
+
});
|
|
1289
|
+
status.dirty();
|
|
1290
|
+
}
|
|
1291
|
+
} else if (check.kind === "url") {
|
|
1292
|
+
try {
|
|
1293
|
+
new URL(input.data);
|
|
1294
|
+
} catch {
|
|
1295
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1296
|
+
addIssueToContext(ctx, {
|
|
1297
|
+
validation: "url",
|
|
1298
|
+
code: ZodIssueCode.invalid_string,
|
|
1299
|
+
message: check.message
|
|
1300
|
+
});
|
|
1301
|
+
status.dirty();
|
|
1302
|
+
}
|
|
1303
|
+
} else if (check.kind === "regex") {
|
|
1304
|
+
check.regex.lastIndex = 0;
|
|
1305
|
+
const testResult = check.regex.test(input.data);
|
|
1306
|
+
if (!testResult) {
|
|
1307
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1308
|
+
addIssueToContext(ctx, {
|
|
1309
|
+
validation: "regex",
|
|
1310
|
+
code: ZodIssueCode.invalid_string,
|
|
1311
|
+
message: check.message
|
|
1312
|
+
});
|
|
1313
|
+
status.dirty();
|
|
1314
|
+
}
|
|
1315
|
+
} else if (check.kind === "trim") {
|
|
1316
|
+
input.data = input.data.trim();
|
|
1317
|
+
} else if (check.kind === "includes") {
|
|
1318
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1319
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1320
|
+
addIssueToContext(ctx, {
|
|
1321
|
+
code: ZodIssueCode.invalid_string,
|
|
1322
|
+
validation: { includes: check.value, position: check.position },
|
|
1323
|
+
message: check.message
|
|
1324
|
+
});
|
|
1325
|
+
status.dirty();
|
|
1326
|
+
}
|
|
1327
|
+
} else if (check.kind === "toLowerCase") {
|
|
1328
|
+
input.data = input.data.toLowerCase();
|
|
1329
|
+
} else if (check.kind === "toUpperCase") {
|
|
1330
|
+
input.data = input.data.toUpperCase();
|
|
1331
|
+
} else if (check.kind === "startsWith") {
|
|
1332
|
+
if (!input.data.startsWith(check.value)) {
|
|
1333
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1334
|
+
addIssueToContext(ctx, {
|
|
1335
|
+
code: ZodIssueCode.invalid_string,
|
|
1336
|
+
validation: { startsWith: check.value },
|
|
1337
|
+
message: check.message
|
|
1338
|
+
});
|
|
1339
|
+
status.dirty();
|
|
1340
|
+
}
|
|
1341
|
+
} else if (check.kind === "endsWith") {
|
|
1342
|
+
if (!input.data.endsWith(check.value)) {
|
|
1343
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1344
|
+
addIssueToContext(ctx, {
|
|
1345
|
+
code: ZodIssueCode.invalid_string,
|
|
1346
|
+
validation: { endsWith: check.value },
|
|
1347
|
+
message: check.message
|
|
1348
|
+
});
|
|
1349
|
+
status.dirty();
|
|
1350
|
+
}
|
|
1351
|
+
} else if (check.kind === "datetime") {
|
|
1352
|
+
const regex = datetimeRegex(check);
|
|
1353
|
+
if (!regex.test(input.data)) {
|
|
1354
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1355
|
+
addIssueToContext(ctx, {
|
|
1356
|
+
code: ZodIssueCode.invalid_string,
|
|
1357
|
+
validation: "datetime",
|
|
1358
|
+
message: check.message
|
|
1359
|
+
});
|
|
1360
|
+
status.dirty();
|
|
1361
|
+
}
|
|
1362
|
+
} else if (check.kind === "date") {
|
|
1363
|
+
const regex = dateRegex;
|
|
1364
|
+
if (!regex.test(input.data)) {
|
|
1365
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1366
|
+
addIssueToContext(ctx, {
|
|
1367
|
+
code: ZodIssueCode.invalid_string,
|
|
1368
|
+
validation: "date",
|
|
1369
|
+
message: check.message
|
|
1370
|
+
});
|
|
1371
|
+
status.dirty();
|
|
1372
|
+
}
|
|
1373
|
+
} else if (check.kind === "time") {
|
|
1374
|
+
const regex = timeRegex(check);
|
|
1375
|
+
if (!regex.test(input.data)) {
|
|
1376
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1377
|
+
addIssueToContext(ctx, {
|
|
1378
|
+
code: ZodIssueCode.invalid_string,
|
|
1379
|
+
validation: "time",
|
|
1380
|
+
message: check.message
|
|
1381
|
+
});
|
|
1382
|
+
status.dirty();
|
|
1383
|
+
}
|
|
1384
|
+
} else if (check.kind === "duration") {
|
|
1385
|
+
if (!durationRegex.test(input.data)) {
|
|
1386
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1387
|
+
addIssueToContext(ctx, {
|
|
1388
|
+
validation: "duration",
|
|
1389
|
+
code: ZodIssueCode.invalid_string,
|
|
1390
|
+
message: check.message
|
|
1391
|
+
});
|
|
1392
|
+
status.dirty();
|
|
1393
|
+
}
|
|
1394
|
+
} else if (check.kind === "ip") {
|
|
1395
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1396
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1397
|
+
addIssueToContext(ctx, {
|
|
1398
|
+
validation: "ip",
|
|
1399
|
+
code: ZodIssueCode.invalid_string,
|
|
1400
|
+
message: check.message
|
|
1401
|
+
});
|
|
1402
|
+
status.dirty();
|
|
1403
|
+
}
|
|
1404
|
+
} else if (check.kind === "jwt") {
|
|
1405
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1406
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1407
|
+
addIssueToContext(ctx, {
|
|
1408
|
+
validation: "jwt",
|
|
1409
|
+
code: ZodIssueCode.invalid_string,
|
|
1410
|
+
message: check.message
|
|
1411
|
+
});
|
|
1412
|
+
status.dirty();
|
|
1413
|
+
}
|
|
1414
|
+
} else if (check.kind === "cidr") {
|
|
1415
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1416
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1417
|
+
addIssueToContext(ctx, {
|
|
1418
|
+
validation: "cidr",
|
|
1419
|
+
code: ZodIssueCode.invalid_string,
|
|
1420
|
+
message: check.message
|
|
1421
|
+
});
|
|
1422
|
+
status.dirty();
|
|
1423
|
+
}
|
|
1424
|
+
} else if (check.kind === "base64") {
|
|
1425
|
+
if (!base64Regex.test(input.data)) {
|
|
1426
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1427
|
+
addIssueToContext(ctx, {
|
|
1428
|
+
validation: "base64",
|
|
1429
|
+
code: ZodIssueCode.invalid_string,
|
|
1430
|
+
message: check.message
|
|
1431
|
+
});
|
|
1432
|
+
status.dirty();
|
|
1433
|
+
}
|
|
1434
|
+
} else if (check.kind === "base64url") {
|
|
1435
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1436
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1437
|
+
addIssueToContext(ctx, {
|
|
1438
|
+
validation: "base64url",
|
|
1439
|
+
code: ZodIssueCode.invalid_string,
|
|
1440
|
+
message: check.message
|
|
1441
|
+
});
|
|
1442
|
+
status.dirty();
|
|
1443
|
+
}
|
|
1444
|
+
} else {
|
|
1445
|
+
util.assertNever(check);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
return { status: status.value, value: input.data };
|
|
1449
|
+
}
|
|
1450
|
+
_regex(regex, validation, message) {
|
|
1451
|
+
return this.refinement((data) => regex.test(data), {
|
|
1452
|
+
validation,
|
|
1453
|
+
code: ZodIssueCode.invalid_string,
|
|
1454
|
+
...errorUtil.errToObj(message)
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
_addCheck(check) {
|
|
1458
|
+
return new _ZodString({
|
|
1459
|
+
...this._def,
|
|
1460
|
+
checks: [...this._def.checks, check]
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
email(message) {
|
|
1464
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1465
|
+
}
|
|
1466
|
+
url(message) {
|
|
1467
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1468
|
+
}
|
|
1469
|
+
emoji(message) {
|
|
1470
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1471
|
+
}
|
|
1472
|
+
uuid(message) {
|
|
1473
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1474
|
+
}
|
|
1475
|
+
nanoid(message) {
|
|
1476
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1477
|
+
}
|
|
1478
|
+
cuid(message) {
|
|
1479
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1480
|
+
}
|
|
1481
|
+
cuid2(message) {
|
|
1482
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1483
|
+
}
|
|
1484
|
+
ulid(message) {
|
|
1485
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1486
|
+
}
|
|
1487
|
+
base64(message) {
|
|
1488
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1489
|
+
}
|
|
1490
|
+
base64url(message) {
|
|
1491
|
+
return this._addCheck({
|
|
1492
|
+
kind: "base64url",
|
|
1493
|
+
...errorUtil.errToObj(message)
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
jwt(options) {
|
|
1497
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1498
|
+
}
|
|
1499
|
+
ip(options) {
|
|
1500
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1501
|
+
}
|
|
1502
|
+
cidr(options) {
|
|
1503
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1504
|
+
}
|
|
1505
|
+
datetime(options) {
|
|
1506
|
+
if (typeof options === "string") {
|
|
1507
|
+
return this._addCheck({
|
|
1508
|
+
kind: "datetime",
|
|
1509
|
+
precision: null,
|
|
1510
|
+
offset: false,
|
|
1511
|
+
local: false,
|
|
1512
|
+
message: options
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
return this._addCheck({
|
|
1516
|
+
kind: "datetime",
|
|
1517
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1518
|
+
offset: options?.offset ?? false,
|
|
1519
|
+
local: options?.local ?? false,
|
|
1520
|
+
...errorUtil.errToObj(options?.message)
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
date(message) {
|
|
1524
|
+
return this._addCheck({ kind: "date", message });
|
|
1525
|
+
}
|
|
1526
|
+
time(options) {
|
|
1527
|
+
if (typeof options === "string") {
|
|
1528
|
+
return this._addCheck({
|
|
1529
|
+
kind: "time",
|
|
1530
|
+
precision: null,
|
|
1531
|
+
message: options
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
return this._addCheck({
|
|
1535
|
+
kind: "time",
|
|
1536
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1537
|
+
...errorUtil.errToObj(options?.message)
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
duration(message) {
|
|
1541
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1542
|
+
}
|
|
1543
|
+
regex(regex, message) {
|
|
1544
|
+
return this._addCheck({
|
|
1545
|
+
kind: "regex",
|
|
1546
|
+
regex,
|
|
1547
|
+
...errorUtil.errToObj(message)
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
includes(value, options) {
|
|
1551
|
+
return this._addCheck({
|
|
1552
|
+
kind: "includes",
|
|
1553
|
+
value,
|
|
1554
|
+
position: options?.position,
|
|
1555
|
+
...errorUtil.errToObj(options?.message)
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
startsWith(value, message) {
|
|
1559
|
+
return this._addCheck({
|
|
1560
|
+
kind: "startsWith",
|
|
1561
|
+
value,
|
|
1562
|
+
...errorUtil.errToObj(message)
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
endsWith(value, message) {
|
|
1566
|
+
return this._addCheck({
|
|
1567
|
+
kind: "endsWith",
|
|
1568
|
+
value,
|
|
1569
|
+
...errorUtil.errToObj(message)
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
min(minLength, message) {
|
|
1573
|
+
return this._addCheck({
|
|
1574
|
+
kind: "min",
|
|
1575
|
+
value: minLength,
|
|
1576
|
+
...errorUtil.errToObj(message)
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
max(maxLength, message) {
|
|
1580
|
+
return this._addCheck({
|
|
1581
|
+
kind: "max",
|
|
1582
|
+
value: maxLength,
|
|
1583
|
+
...errorUtil.errToObj(message)
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
length(len, message) {
|
|
1587
|
+
return this._addCheck({
|
|
1588
|
+
kind: "length",
|
|
1589
|
+
value: len,
|
|
1590
|
+
...errorUtil.errToObj(message)
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Equivalent to `.min(1)`
|
|
1595
|
+
*/
|
|
1596
|
+
nonempty(message) {
|
|
1597
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1598
|
+
}
|
|
1599
|
+
trim() {
|
|
1600
|
+
return new _ZodString({
|
|
1601
|
+
...this._def,
|
|
1602
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
toLowerCase() {
|
|
1606
|
+
return new _ZodString({
|
|
1607
|
+
...this._def,
|
|
1608
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
toUpperCase() {
|
|
1612
|
+
return new _ZodString({
|
|
1613
|
+
...this._def,
|
|
1614
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
get isDatetime() {
|
|
1618
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1619
|
+
}
|
|
1620
|
+
get isDate() {
|
|
1621
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1622
|
+
}
|
|
1623
|
+
get isTime() {
|
|
1624
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1625
|
+
}
|
|
1626
|
+
get isDuration() {
|
|
1627
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1628
|
+
}
|
|
1629
|
+
get isEmail() {
|
|
1630
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1631
|
+
}
|
|
1632
|
+
get isURL() {
|
|
1633
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1634
|
+
}
|
|
1635
|
+
get isEmoji() {
|
|
1636
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1637
|
+
}
|
|
1638
|
+
get isUUID() {
|
|
1639
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1640
|
+
}
|
|
1641
|
+
get isNANOID() {
|
|
1642
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1643
|
+
}
|
|
1644
|
+
get isCUID() {
|
|
1645
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1646
|
+
}
|
|
1647
|
+
get isCUID2() {
|
|
1648
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1649
|
+
}
|
|
1650
|
+
get isULID() {
|
|
1651
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1652
|
+
}
|
|
1653
|
+
get isIP() {
|
|
1654
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1655
|
+
}
|
|
1656
|
+
get isCIDR() {
|
|
1657
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1658
|
+
}
|
|
1659
|
+
get isBase64() {
|
|
1660
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1661
|
+
}
|
|
1662
|
+
get isBase64url() {
|
|
1663
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1664
|
+
}
|
|
1665
|
+
get minLength() {
|
|
1666
|
+
let min = null;
|
|
1667
|
+
for (const ch of this._def.checks) {
|
|
1668
|
+
if (ch.kind === "min") {
|
|
1669
|
+
if (min === null || ch.value > min)
|
|
1670
|
+
min = ch.value;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
return min;
|
|
1674
|
+
}
|
|
1675
|
+
get maxLength() {
|
|
1676
|
+
let max = null;
|
|
1677
|
+
for (const ch of this._def.checks) {
|
|
1678
|
+
if (ch.kind === "max") {
|
|
1679
|
+
if (max === null || ch.value < max)
|
|
1680
|
+
max = ch.value;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
return max;
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
ZodString.create = (params) => {
|
|
1687
|
+
return new ZodString({
|
|
1688
|
+
checks: [],
|
|
1689
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1690
|
+
coerce: params?.coerce ?? false,
|
|
1691
|
+
...processCreateParams(params)
|
|
1692
|
+
});
|
|
1693
|
+
};
|
|
1694
|
+
function floatSafeRemainder(val, step) {
|
|
1695
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1696
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1697
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1698
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1699
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1700
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1701
|
+
}
|
|
1702
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1703
|
+
constructor() {
|
|
1704
|
+
super(...arguments);
|
|
1705
|
+
this.min = this.gte;
|
|
1706
|
+
this.max = this.lte;
|
|
1707
|
+
this.step = this.multipleOf;
|
|
1708
|
+
}
|
|
1709
|
+
_parse(input) {
|
|
1710
|
+
if (this._def.coerce) {
|
|
1711
|
+
input.data = Number(input.data);
|
|
1712
|
+
}
|
|
1713
|
+
const parsedType = this._getType(input);
|
|
1714
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1715
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1716
|
+
addIssueToContext(ctx2, {
|
|
1717
|
+
code: ZodIssueCode.invalid_type,
|
|
1718
|
+
expected: ZodParsedType.number,
|
|
1719
|
+
received: ctx2.parsedType
|
|
1720
|
+
});
|
|
1721
|
+
return INVALID;
|
|
1722
|
+
}
|
|
1723
|
+
let ctx = void 0;
|
|
1724
|
+
const status = new ParseStatus();
|
|
1725
|
+
for (const check of this._def.checks) {
|
|
1726
|
+
if (check.kind === "int") {
|
|
1727
|
+
if (!util.isInteger(input.data)) {
|
|
1728
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1729
|
+
addIssueToContext(ctx, {
|
|
1730
|
+
code: ZodIssueCode.invalid_type,
|
|
1731
|
+
expected: "integer",
|
|
1732
|
+
received: "float",
|
|
1733
|
+
message: check.message
|
|
1734
|
+
});
|
|
1735
|
+
status.dirty();
|
|
1736
|
+
}
|
|
1737
|
+
} else if (check.kind === "min") {
|
|
1738
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1739
|
+
if (tooSmall) {
|
|
1740
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1741
|
+
addIssueToContext(ctx, {
|
|
1742
|
+
code: ZodIssueCode.too_small,
|
|
1743
|
+
minimum: check.value,
|
|
1744
|
+
type: "number",
|
|
1745
|
+
inclusive: check.inclusive,
|
|
1746
|
+
exact: false,
|
|
1747
|
+
message: check.message
|
|
1748
|
+
});
|
|
1749
|
+
status.dirty();
|
|
1750
|
+
}
|
|
1751
|
+
} else if (check.kind === "max") {
|
|
1752
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1753
|
+
if (tooBig) {
|
|
1754
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1755
|
+
addIssueToContext(ctx, {
|
|
1756
|
+
code: ZodIssueCode.too_big,
|
|
1757
|
+
maximum: check.value,
|
|
1758
|
+
type: "number",
|
|
1759
|
+
inclusive: check.inclusive,
|
|
1760
|
+
exact: false,
|
|
1761
|
+
message: check.message
|
|
1762
|
+
});
|
|
1763
|
+
status.dirty();
|
|
1764
|
+
}
|
|
1765
|
+
} else if (check.kind === "multipleOf") {
|
|
1766
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1767
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1768
|
+
addIssueToContext(ctx, {
|
|
1769
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1770
|
+
multipleOf: check.value,
|
|
1771
|
+
message: check.message
|
|
1772
|
+
});
|
|
1773
|
+
status.dirty();
|
|
1774
|
+
}
|
|
1775
|
+
} else if (check.kind === "finite") {
|
|
1776
|
+
if (!Number.isFinite(input.data)) {
|
|
1777
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1778
|
+
addIssueToContext(ctx, {
|
|
1779
|
+
code: ZodIssueCode.not_finite,
|
|
1780
|
+
message: check.message
|
|
1781
|
+
});
|
|
1782
|
+
status.dirty();
|
|
1783
|
+
}
|
|
1784
|
+
} else {
|
|
1785
|
+
util.assertNever(check);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return { status: status.value, value: input.data };
|
|
1789
|
+
}
|
|
1790
|
+
gte(value, message) {
|
|
1791
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1792
|
+
}
|
|
1793
|
+
gt(value, message) {
|
|
1794
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1795
|
+
}
|
|
1796
|
+
lte(value, message) {
|
|
1797
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1798
|
+
}
|
|
1799
|
+
lt(value, message) {
|
|
1800
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1801
|
+
}
|
|
1802
|
+
setLimit(kind, value, inclusive, message) {
|
|
1803
|
+
return new _ZodNumber({
|
|
1804
|
+
...this._def,
|
|
1805
|
+
checks: [
|
|
1806
|
+
...this._def.checks,
|
|
1807
|
+
{
|
|
1808
|
+
kind,
|
|
1809
|
+
value,
|
|
1810
|
+
inclusive,
|
|
1811
|
+
message: errorUtil.toString(message)
|
|
1812
|
+
}
|
|
1813
|
+
]
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
_addCheck(check) {
|
|
1817
|
+
return new _ZodNumber({
|
|
1818
|
+
...this._def,
|
|
1819
|
+
checks: [...this._def.checks, check]
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
int(message) {
|
|
1823
|
+
return this._addCheck({
|
|
1824
|
+
kind: "int",
|
|
1825
|
+
message: errorUtil.toString(message)
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
positive(message) {
|
|
1829
|
+
return this._addCheck({
|
|
1830
|
+
kind: "min",
|
|
1831
|
+
value: 0,
|
|
1832
|
+
inclusive: false,
|
|
1833
|
+
message: errorUtil.toString(message)
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
negative(message) {
|
|
1837
|
+
return this._addCheck({
|
|
1838
|
+
kind: "max",
|
|
1839
|
+
value: 0,
|
|
1840
|
+
inclusive: false,
|
|
1841
|
+
message: errorUtil.toString(message)
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
nonpositive(message) {
|
|
1845
|
+
return this._addCheck({
|
|
1846
|
+
kind: "max",
|
|
1847
|
+
value: 0,
|
|
1848
|
+
inclusive: true,
|
|
1849
|
+
message: errorUtil.toString(message)
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
nonnegative(message) {
|
|
1853
|
+
return this._addCheck({
|
|
1854
|
+
kind: "min",
|
|
1855
|
+
value: 0,
|
|
1856
|
+
inclusive: true,
|
|
1857
|
+
message: errorUtil.toString(message)
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
multipleOf(value, message) {
|
|
1861
|
+
return this._addCheck({
|
|
1862
|
+
kind: "multipleOf",
|
|
1863
|
+
value,
|
|
1864
|
+
message: errorUtil.toString(message)
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
finite(message) {
|
|
1868
|
+
return this._addCheck({
|
|
1869
|
+
kind: "finite",
|
|
1870
|
+
message: errorUtil.toString(message)
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
safe(message) {
|
|
1874
|
+
return this._addCheck({
|
|
1875
|
+
kind: "min",
|
|
1876
|
+
inclusive: true,
|
|
1877
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1878
|
+
message: errorUtil.toString(message)
|
|
1879
|
+
})._addCheck({
|
|
1880
|
+
kind: "max",
|
|
1881
|
+
inclusive: true,
|
|
1882
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1883
|
+
message: errorUtil.toString(message)
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
get minValue() {
|
|
1887
|
+
let min = null;
|
|
1888
|
+
for (const ch of this._def.checks) {
|
|
1889
|
+
if (ch.kind === "min") {
|
|
1890
|
+
if (min === null || ch.value > min)
|
|
1891
|
+
min = ch.value;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
return min;
|
|
1895
|
+
}
|
|
1896
|
+
get maxValue() {
|
|
1897
|
+
let max = null;
|
|
1898
|
+
for (const ch of this._def.checks) {
|
|
1899
|
+
if (ch.kind === "max") {
|
|
1900
|
+
if (max === null || ch.value < max)
|
|
1901
|
+
max = ch.value;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
return max;
|
|
1905
|
+
}
|
|
1906
|
+
get isInt() {
|
|
1907
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1908
|
+
}
|
|
1909
|
+
get isFinite() {
|
|
1910
|
+
let max = null;
|
|
1911
|
+
let min = null;
|
|
1912
|
+
for (const ch of this._def.checks) {
|
|
1913
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1914
|
+
return true;
|
|
1915
|
+
} else if (ch.kind === "min") {
|
|
1916
|
+
if (min === null || ch.value > min)
|
|
1917
|
+
min = ch.value;
|
|
1918
|
+
} else if (ch.kind === "max") {
|
|
1919
|
+
if (max === null || ch.value < max)
|
|
1920
|
+
max = ch.value;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
ZodNumber.create = (params) => {
|
|
1927
|
+
return new ZodNumber({
|
|
1928
|
+
checks: [],
|
|
1929
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1930
|
+
coerce: params?.coerce || false,
|
|
1931
|
+
...processCreateParams(params)
|
|
1932
|
+
});
|
|
1933
|
+
};
|
|
1934
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1935
|
+
constructor() {
|
|
1936
|
+
super(...arguments);
|
|
1937
|
+
this.min = this.gte;
|
|
1938
|
+
this.max = this.lte;
|
|
1939
|
+
}
|
|
1940
|
+
_parse(input) {
|
|
1941
|
+
if (this._def.coerce) {
|
|
1942
|
+
try {
|
|
1943
|
+
input.data = BigInt(input.data);
|
|
1944
|
+
} catch {
|
|
1945
|
+
return this._getInvalidInput(input);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
const parsedType = this._getType(input);
|
|
1949
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
1950
|
+
return this._getInvalidInput(input);
|
|
1951
|
+
}
|
|
1952
|
+
let ctx = void 0;
|
|
1953
|
+
const status = new ParseStatus();
|
|
1954
|
+
for (const check of this._def.checks) {
|
|
1955
|
+
if (check.kind === "min") {
|
|
1956
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1957
|
+
if (tooSmall) {
|
|
1958
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1959
|
+
addIssueToContext(ctx, {
|
|
1960
|
+
code: ZodIssueCode.too_small,
|
|
1961
|
+
type: "bigint",
|
|
1962
|
+
minimum: check.value,
|
|
1963
|
+
inclusive: check.inclusive,
|
|
1964
|
+
message: check.message
|
|
1965
|
+
});
|
|
1966
|
+
status.dirty();
|
|
1967
|
+
}
|
|
1968
|
+
} else if (check.kind === "max") {
|
|
1969
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1970
|
+
if (tooBig) {
|
|
1971
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1972
|
+
addIssueToContext(ctx, {
|
|
1973
|
+
code: ZodIssueCode.too_big,
|
|
1974
|
+
type: "bigint",
|
|
1975
|
+
maximum: check.value,
|
|
1976
|
+
inclusive: check.inclusive,
|
|
1977
|
+
message: check.message
|
|
1978
|
+
});
|
|
1979
|
+
status.dirty();
|
|
1980
|
+
}
|
|
1981
|
+
} else if (check.kind === "multipleOf") {
|
|
1982
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1983
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1984
|
+
addIssueToContext(ctx, {
|
|
1985
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1986
|
+
multipleOf: check.value,
|
|
1987
|
+
message: check.message
|
|
1988
|
+
});
|
|
1989
|
+
status.dirty();
|
|
1990
|
+
}
|
|
1991
|
+
} else {
|
|
1992
|
+
util.assertNever(check);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
return { status: status.value, value: input.data };
|
|
1996
|
+
}
|
|
1997
|
+
_getInvalidInput(input) {
|
|
1998
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1999
|
+
addIssueToContext(ctx, {
|
|
2000
|
+
code: ZodIssueCode.invalid_type,
|
|
2001
|
+
expected: ZodParsedType.bigint,
|
|
2002
|
+
received: ctx.parsedType
|
|
2003
|
+
});
|
|
2004
|
+
return INVALID;
|
|
2005
|
+
}
|
|
2006
|
+
gte(value, message) {
|
|
2007
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2008
|
+
}
|
|
2009
|
+
gt(value, message) {
|
|
2010
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2011
|
+
}
|
|
2012
|
+
lte(value, message) {
|
|
2013
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2014
|
+
}
|
|
2015
|
+
lt(value, message) {
|
|
2016
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2017
|
+
}
|
|
2018
|
+
setLimit(kind, value, inclusive, message) {
|
|
2019
|
+
return new _ZodBigInt({
|
|
2020
|
+
...this._def,
|
|
2021
|
+
checks: [
|
|
2022
|
+
...this._def.checks,
|
|
2023
|
+
{
|
|
2024
|
+
kind,
|
|
2025
|
+
value,
|
|
2026
|
+
inclusive,
|
|
2027
|
+
message: errorUtil.toString(message)
|
|
2028
|
+
}
|
|
2029
|
+
]
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
_addCheck(check) {
|
|
2033
|
+
return new _ZodBigInt({
|
|
2034
|
+
...this._def,
|
|
2035
|
+
checks: [...this._def.checks, check]
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
positive(message) {
|
|
2039
|
+
return this._addCheck({
|
|
2040
|
+
kind: "min",
|
|
2041
|
+
value: BigInt(0),
|
|
2042
|
+
inclusive: false,
|
|
2043
|
+
message: errorUtil.toString(message)
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
negative(message) {
|
|
2047
|
+
return this._addCheck({
|
|
2048
|
+
kind: "max",
|
|
2049
|
+
value: BigInt(0),
|
|
2050
|
+
inclusive: false,
|
|
2051
|
+
message: errorUtil.toString(message)
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
nonpositive(message) {
|
|
2055
|
+
return this._addCheck({
|
|
2056
|
+
kind: "max",
|
|
2057
|
+
value: BigInt(0),
|
|
2058
|
+
inclusive: true,
|
|
2059
|
+
message: errorUtil.toString(message)
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
nonnegative(message) {
|
|
2063
|
+
return this._addCheck({
|
|
2064
|
+
kind: "min",
|
|
2065
|
+
value: BigInt(0),
|
|
2066
|
+
inclusive: true,
|
|
2067
|
+
message: errorUtil.toString(message)
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
multipleOf(value, message) {
|
|
2071
|
+
return this._addCheck({
|
|
2072
|
+
kind: "multipleOf",
|
|
2073
|
+
value,
|
|
2074
|
+
message: errorUtil.toString(message)
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
get minValue() {
|
|
2078
|
+
let min = null;
|
|
2079
|
+
for (const ch of this._def.checks) {
|
|
2080
|
+
if (ch.kind === "min") {
|
|
2081
|
+
if (min === null || ch.value > min)
|
|
2082
|
+
min = ch.value;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
return min;
|
|
2086
|
+
}
|
|
2087
|
+
get maxValue() {
|
|
2088
|
+
let max = null;
|
|
2089
|
+
for (const ch of this._def.checks) {
|
|
2090
|
+
if (ch.kind === "max") {
|
|
2091
|
+
if (max === null || ch.value < max)
|
|
2092
|
+
max = ch.value;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
return max;
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
ZodBigInt.create = (params) => {
|
|
2099
|
+
return new ZodBigInt({
|
|
2100
|
+
checks: [],
|
|
2101
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2102
|
+
coerce: params?.coerce ?? false,
|
|
2103
|
+
...processCreateParams(params)
|
|
2104
|
+
});
|
|
2105
|
+
};
|
|
2106
|
+
var ZodBoolean = class extends ZodType {
|
|
2107
|
+
_parse(input) {
|
|
2108
|
+
if (this._def.coerce) {
|
|
2109
|
+
input.data = Boolean(input.data);
|
|
2110
|
+
}
|
|
2111
|
+
const parsedType = this._getType(input);
|
|
2112
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
2113
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2114
|
+
addIssueToContext(ctx, {
|
|
2115
|
+
code: ZodIssueCode.invalid_type,
|
|
2116
|
+
expected: ZodParsedType.boolean,
|
|
2117
|
+
received: ctx.parsedType
|
|
2118
|
+
});
|
|
2119
|
+
return INVALID;
|
|
2120
|
+
}
|
|
2121
|
+
return OK(input.data);
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
ZodBoolean.create = (params) => {
|
|
2125
|
+
return new ZodBoolean({
|
|
2126
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2127
|
+
coerce: params?.coerce || false,
|
|
2128
|
+
...processCreateParams(params)
|
|
2129
|
+
});
|
|
2130
|
+
};
|
|
2131
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
2132
|
+
_parse(input) {
|
|
2133
|
+
if (this._def.coerce) {
|
|
2134
|
+
input.data = new Date(input.data);
|
|
2135
|
+
}
|
|
2136
|
+
const parsedType = this._getType(input);
|
|
2137
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2138
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2139
|
+
addIssueToContext(ctx2, {
|
|
2140
|
+
code: ZodIssueCode.invalid_type,
|
|
2141
|
+
expected: ZodParsedType.date,
|
|
2142
|
+
received: ctx2.parsedType
|
|
2143
|
+
});
|
|
2144
|
+
return INVALID;
|
|
2145
|
+
}
|
|
2146
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2147
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2148
|
+
addIssueToContext(ctx2, {
|
|
2149
|
+
code: ZodIssueCode.invalid_date
|
|
2150
|
+
});
|
|
2151
|
+
return INVALID;
|
|
2152
|
+
}
|
|
2153
|
+
const status = new ParseStatus();
|
|
2154
|
+
let ctx = void 0;
|
|
2155
|
+
for (const check of this._def.checks) {
|
|
2156
|
+
if (check.kind === "min") {
|
|
2157
|
+
if (input.data.getTime() < check.value) {
|
|
2158
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2159
|
+
addIssueToContext(ctx, {
|
|
2160
|
+
code: ZodIssueCode.too_small,
|
|
2161
|
+
message: check.message,
|
|
2162
|
+
inclusive: true,
|
|
2163
|
+
exact: false,
|
|
2164
|
+
minimum: check.value,
|
|
2165
|
+
type: "date"
|
|
2166
|
+
});
|
|
2167
|
+
status.dirty();
|
|
2168
|
+
}
|
|
2169
|
+
} else if (check.kind === "max") {
|
|
2170
|
+
if (input.data.getTime() > check.value) {
|
|
2171
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2172
|
+
addIssueToContext(ctx, {
|
|
2173
|
+
code: ZodIssueCode.too_big,
|
|
2174
|
+
message: check.message,
|
|
2175
|
+
inclusive: true,
|
|
2176
|
+
exact: false,
|
|
2177
|
+
maximum: check.value,
|
|
2178
|
+
type: "date"
|
|
2179
|
+
});
|
|
2180
|
+
status.dirty();
|
|
2181
|
+
}
|
|
2182
|
+
} else {
|
|
2183
|
+
util.assertNever(check);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
return {
|
|
2187
|
+
status: status.value,
|
|
2188
|
+
value: new Date(input.data.getTime())
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
_addCheck(check) {
|
|
2192
|
+
return new _ZodDate({
|
|
2193
|
+
...this._def,
|
|
2194
|
+
checks: [...this._def.checks, check]
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
min(minDate, message) {
|
|
2198
|
+
return this._addCheck({
|
|
2199
|
+
kind: "min",
|
|
2200
|
+
value: minDate.getTime(),
|
|
2201
|
+
message: errorUtil.toString(message)
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
max(maxDate, message) {
|
|
2205
|
+
return this._addCheck({
|
|
2206
|
+
kind: "max",
|
|
2207
|
+
value: maxDate.getTime(),
|
|
2208
|
+
message: errorUtil.toString(message)
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
get minDate() {
|
|
2212
|
+
let min = null;
|
|
2213
|
+
for (const ch of this._def.checks) {
|
|
2214
|
+
if (ch.kind === "min") {
|
|
2215
|
+
if (min === null || ch.value > min)
|
|
2216
|
+
min = ch.value;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
return min != null ? new Date(min) : null;
|
|
2220
|
+
}
|
|
2221
|
+
get maxDate() {
|
|
2222
|
+
let max = null;
|
|
2223
|
+
for (const ch of this._def.checks) {
|
|
2224
|
+
if (ch.kind === "max") {
|
|
2225
|
+
if (max === null || ch.value < max)
|
|
2226
|
+
max = ch.value;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
return max != null ? new Date(max) : null;
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
ZodDate.create = (params) => {
|
|
2233
|
+
return new ZodDate({
|
|
2234
|
+
checks: [],
|
|
2235
|
+
coerce: params?.coerce || false,
|
|
2236
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2237
|
+
...processCreateParams(params)
|
|
2238
|
+
});
|
|
2239
|
+
};
|
|
2240
|
+
var ZodSymbol = class extends ZodType {
|
|
2241
|
+
_parse(input) {
|
|
2242
|
+
const parsedType = this._getType(input);
|
|
2243
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2244
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2245
|
+
addIssueToContext(ctx, {
|
|
2246
|
+
code: ZodIssueCode.invalid_type,
|
|
2247
|
+
expected: ZodParsedType.symbol,
|
|
2248
|
+
received: ctx.parsedType
|
|
2249
|
+
});
|
|
2250
|
+
return INVALID;
|
|
2251
|
+
}
|
|
2252
|
+
return OK(input.data);
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
ZodSymbol.create = (params) => {
|
|
2256
|
+
return new ZodSymbol({
|
|
2257
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2258
|
+
...processCreateParams(params)
|
|
2259
|
+
});
|
|
2260
|
+
};
|
|
2261
|
+
var ZodUndefined = class extends ZodType {
|
|
2262
|
+
_parse(input) {
|
|
2263
|
+
const parsedType = this._getType(input);
|
|
2264
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2265
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2266
|
+
addIssueToContext(ctx, {
|
|
2267
|
+
code: ZodIssueCode.invalid_type,
|
|
2268
|
+
expected: ZodParsedType.undefined,
|
|
2269
|
+
received: ctx.parsedType
|
|
2270
|
+
});
|
|
2271
|
+
return INVALID;
|
|
2272
|
+
}
|
|
2273
|
+
return OK(input.data);
|
|
2274
|
+
}
|
|
2275
|
+
};
|
|
2276
|
+
ZodUndefined.create = (params) => {
|
|
2277
|
+
return new ZodUndefined({
|
|
2278
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2279
|
+
...processCreateParams(params)
|
|
2280
|
+
});
|
|
2281
|
+
};
|
|
2282
|
+
var ZodNull = class extends ZodType {
|
|
2283
|
+
_parse(input) {
|
|
2284
|
+
const parsedType = this._getType(input);
|
|
2285
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2286
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2287
|
+
addIssueToContext(ctx, {
|
|
2288
|
+
code: ZodIssueCode.invalid_type,
|
|
2289
|
+
expected: ZodParsedType.null,
|
|
2290
|
+
received: ctx.parsedType
|
|
2291
|
+
});
|
|
2292
|
+
return INVALID;
|
|
2293
|
+
}
|
|
2294
|
+
return OK(input.data);
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
ZodNull.create = (params) => {
|
|
2298
|
+
return new ZodNull({
|
|
2299
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2300
|
+
...processCreateParams(params)
|
|
2301
|
+
});
|
|
2302
|
+
};
|
|
2303
|
+
var ZodAny = class extends ZodType {
|
|
2304
|
+
constructor() {
|
|
2305
|
+
super(...arguments);
|
|
2306
|
+
this._any = true;
|
|
2307
|
+
}
|
|
2308
|
+
_parse(input) {
|
|
2309
|
+
return OK(input.data);
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
ZodAny.create = (params) => {
|
|
2313
|
+
return new ZodAny({
|
|
2314
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2315
|
+
...processCreateParams(params)
|
|
2316
|
+
});
|
|
2317
|
+
};
|
|
2318
|
+
var ZodUnknown = class extends ZodType {
|
|
2319
|
+
constructor() {
|
|
2320
|
+
super(...arguments);
|
|
2321
|
+
this._unknown = true;
|
|
2322
|
+
}
|
|
2323
|
+
_parse(input) {
|
|
2324
|
+
return OK(input.data);
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
ZodUnknown.create = (params) => {
|
|
2328
|
+
return new ZodUnknown({
|
|
2329
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2330
|
+
...processCreateParams(params)
|
|
2331
|
+
});
|
|
2332
|
+
};
|
|
2333
|
+
var ZodNever = class extends ZodType {
|
|
2334
|
+
_parse(input) {
|
|
2335
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2336
|
+
addIssueToContext(ctx, {
|
|
2337
|
+
code: ZodIssueCode.invalid_type,
|
|
2338
|
+
expected: ZodParsedType.never,
|
|
2339
|
+
received: ctx.parsedType
|
|
2340
|
+
});
|
|
2341
|
+
return INVALID;
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
ZodNever.create = (params) => {
|
|
2345
|
+
return new ZodNever({
|
|
2346
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2347
|
+
...processCreateParams(params)
|
|
2348
|
+
});
|
|
2349
|
+
};
|
|
2350
|
+
var ZodVoid = class extends ZodType {
|
|
2351
|
+
_parse(input) {
|
|
2352
|
+
const parsedType = this._getType(input);
|
|
2353
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2354
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2355
|
+
addIssueToContext(ctx, {
|
|
2356
|
+
code: ZodIssueCode.invalid_type,
|
|
2357
|
+
expected: ZodParsedType.void,
|
|
2358
|
+
received: ctx.parsedType
|
|
2359
|
+
});
|
|
2360
|
+
return INVALID;
|
|
2361
|
+
}
|
|
2362
|
+
return OK(input.data);
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
ZodVoid.create = (params) => {
|
|
2366
|
+
return new ZodVoid({
|
|
2367
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2368
|
+
...processCreateParams(params)
|
|
2369
|
+
});
|
|
2370
|
+
};
|
|
2371
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
2372
|
+
_parse(input) {
|
|
2373
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2374
|
+
const def = this._def;
|
|
2375
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2376
|
+
addIssueToContext(ctx, {
|
|
2377
|
+
code: ZodIssueCode.invalid_type,
|
|
2378
|
+
expected: ZodParsedType.array,
|
|
2379
|
+
received: ctx.parsedType
|
|
2380
|
+
});
|
|
2381
|
+
return INVALID;
|
|
2382
|
+
}
|
|
2383
|
+
if (def.exactLength !== null) {
|
|
2384
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2385
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2386
|
+
if (tooBig || tooSmall) {
|
|
2387
|
+
addIssueToContext(ctx, {
|
|
2388
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2389
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2390
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2391
|
+
type: "array",
|
|
2392
|
+
inclusive: true,
|
|
2393
|
+
exact: true,
|
|
2394
|
+
message: def.exactLength.message
|
|
2395
|
+
});
|
|
2396
|
+
status.dirty();
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
if (def.minLength !== null) {
|
|
2400
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2401
|
+
addIssueToContext(ctx, {
|
|
2402
|
+
code: ZodIssueCode.too_small,
|
|
2403
|
+
minimum: def.minLength.value,
|
|
2404
|
+
type: "array",
|
|
2405
|
+
inclusive: true,
|
|
2406
|
+
exact: false,
|
|
2407
|
+
message: def.minLength.message
|
|
2408
|
+
});
|
|
2409
|
+
status.dirty();
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
if (def.maxLength !== null) {
|
|
2413
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2414
|
+
addIssueToContext(ctx, {
|
|
2415
|
+
code: ZodIssueCode.too_big,
|
|
2416
|
+
maximum: def.maxLength.value,
|
|
2417
|
+
type: "array",
|
|
2418
|
+
inclusive: true,
|
|
2419
|
+
exact: false,
|
|
2420
|
+
message: def.maxLength.message
|
|
2421
|
+
});
|
|
2422
|
+
status.dirty();
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
if (ctx.common.async) {
|
|
2426
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
2427
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2428
|
+
})).then((result2) => {
|
|
2429
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
const result = [...ctx.data].map((item, i) => {
|
|
2433
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2434
|
+
});
|
|
2435
|
+
return ParseStatus.mergeArray(status, result);
|
|
2436
|
+
}
|
|
2437
|
+
get element() {
|
|
2438
|
+
return this._def.type;
|
|
2439
|
+
}
|
|
2440
|
+
min(minLength, message) {
|
|
2441
|
+
return new _ZodArray({
|
|
2442
|
+
...this._def,
|
|
2443
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
max(maxLength, message) {
|
|
2447
|
+
return new _ZodArray({
|
|
2448
|
+
...this._def,
|
|
2449
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
length(len, message) {
|
|
2453
|
+
return new _ZodArray({
|
|
2454
|
+
...this._def,
|
|
2455
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2456
|
+
});
|
|
2457
|
+
}
|
|
2458
|
+
nonempty(message) {
|
|
2459
|
+
return this.min(1, message);
|
|
2460
|
+
}
|
|
2461
|
+
};
|
|
2462
|
+
ZodArray.create = (schema, params) => {
|
|
2463
|
+
return new ZodArray({
|
|
2464
|
+
type: schema,
|
|
2465
|
+
minLength: null,
|
|
2466
|
+
maxLength: null,
|
|
2467
|
+
exactLength: null,
|
|
2468
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2469
|
+
...processCreateParams(params)
|
|
2470
|
+
});
|
|
2471
|
+
};
|
|
2472
|
+
function deepPartialify(schema) {
|
|
2473
|
+
if (schema instanceof ZodObject) {
|
|
2474
|
+
const newShape = {};
|
|
2475
|
+
for (const key in schema.shape) {
|
|
2476
|
+
const fieldSchema = schema.shape[key];
|
|
2477
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2478
|
+
}
|
|
2479
|
+
return new ZodObject({
|
|
2480
|
+
...schema._def,
|
|
2481
|
+
shape: () => newShape
|
|
2482
|
+
});
|
|
2483
|
+
} else if (schema instanceof ZodArray) {
|
|
2484
|
+
return new ZodArray({
|
|
2485
|
+
...schema._def,
|
|
2486
|
+
type: deepPartialify(schema.element)
|
|
2487
|
+
});
|
|
2488
|
+
} else if (schema instanceof ZodOptional) {
|
|
2489
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2490
|
+
} else if (schema instanceof ZodNullable) {
|
|
2491
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2492
|
+
} else if (schema instanceof ZodTuple) {
|
|
2493
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2494
|
+
} else {
|
|
2495
|
+
return schema;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
2499
|
+
constructor() {
|
|
2500
|
+
super(...arguments);
|
|
2501
|
+
this._cached = null;
|
|
2502
|
+
this.nonstrict = this.passthrough;
|
|
2503
|
+
this.augment = this.extend;
|
|
2504
|
+
}
|
|
2505
|
+
_getCached() {
|
|
2506
|
+
if (this._cached !== null)
|
|
2507
|
+
return this._cached;
|
|
2508
|
+
const shape = this._def.shape();
|
|
2509
|
+
const keys = util.objectKeys(shape);
|
|
2510
|
+
this._cached = { shape, keys };
|
|
2511
|
+
return this._cached;
|
|
2512
|
+
}
|
|
2513
|
+
_parse(input) {
|
|
2514
|
+
const parsedType = this._getType(input);
|
|
2515
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2516
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2517
|
+
addIssueToContext(ctx2, {
|
|
2518
|
+
code: ZodIssueCode.invalid_type,
|
|
2519
|
+
expected: ZodParsedType.object,
|
|
2520
|
+
received: ctx2.parsedType
|
|
2521
|
+
});
|
|
2522
|
+
return INVALID;
|
|
2523
|
+
}
|
|
2524
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2525
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2526
|
+
const extraKeys = [];
|
|
2527
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2528
|
+
for (const key in ctx.data) {
|
|
2529
|
+
if (!shapeKeys.includes(key)) {
|
|
2530
|
+
extraKeys.push(key);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
const pairs = [];
|
|
2535
|
+
for (const key of shapeKeys) {
|
|
2536
|
+
const keyValidator = shape[key];
|
|
2537
|
+
const value = ctx.data[key];
|
|
2538
|
+
pairs.push({
|
|
2539
|
+
key: { status: "valid", value: key },
|
|
2540
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2541
|
+
alwaysSet: key in ctx.data
|
|
2542
|
+
});
|
|
2543
|
+
}
|
|
2544
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2545
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2546
|
+
if (unknownKeys === "passthrough") {
|
|
2547
|
+
for (const key of extraKeys) {
|
|
2548
|
+
pairs.push({
|
|
2549
|
+
key: { status: "valid", value: key },
|
|
2550
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2553
|
+
} else if (unknownKeys === "strict") {
|
|
2554
|
+
if (extraKeys.length > 0) {
|
|
2555
|
+
addIssueToContext(ctx, {
|
|
2556
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2557
|
+
keys: extraKeys
|
|
2558
|
+
});
|
|
2559
|
+
status.dirty();
|
|
2560
|
+
}
|
|
2561
|
+
} else if (unknownKeys === "strip") {
|
|
2562
|
+
} else {
|
|
2563
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2564
|
+
}
|
|
2565
|
+
} else {
|
|
2566
|
+
const catchall = this._def.catchall;
|
|
2567
|
+
for (const key of extraKeys) {
|
|
2568
|
+
const value = ctx.data[key];
|
|
2569
|
+
pairs.push({
|
|
2570
|
+
key: { status: "valid", value: key },
|
|
2571
|
+
value: catchall._parse(
|
|
2572
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2573
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
2574
|
+
),
|
|
2575
|
+
alwaysSet: key in ctx.data
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
if (ctx.common.async) {
|
|
2580
|
+
return Promise.resolve().then(async () => {
|
|
2581
|
+
const syncPairs = [];
|
|
2582
|
+
for (const pair of pairs) {
|
|
2583
|
+
const key = await pair.key;
|
|
2584
|
+
const value = await pair.value;
|
|
2585
|
+
syncPairs.push({
|
|
2586
|
+
key,
|
|
2587
|
+
value,
|
|
2588
|
+
alwaysSet: pair.alwaysSet
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
return syncPairs;
|
|
2592
|
+
}).then((syncPairs) => {
|
|
2593
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2594
|
+
});
|
|
2595
|
+
} else {
|
|
2596
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
get shape() {
|
|
2600
|
+
return this._def.shape();
|
|
2601
|
+
}
|
|
2602
|
+
strict(message) {
|
|
2603
|
+
errorUtil.errToObj;
|
|
2604
|
+
return new _ZodObject({
|
|
2605
|
+
...this._def,
|
|
2606
|
+
unknownKeys: "strict",
|
|
2607
|
+
...message !== void 0 ? {
|
|
2608
|
+
errorMap: (issue, ctx) => {
|
|
2609
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2610
|
+
if (issue.code === "unrecognized_keys")
|
|
2611
|
+
return {
|
|
2612
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2613
|
+
};
|
|
2614
|
+
return {
|
|
2615
|
+
message: defaultError
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
} : {}
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2621
|
+
strip() {
|
|
2622
|
+
return new _ZodObject({
|
|
2623
|
+
...this._def,
|
|
2624
|
+
unknownKeys: "strip"
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
passthrough() {
|
|
2628
|
+
return new _ZodObject({
|
|
2629
|
+
...this._def,
|
|
2630
|
+
unknownKeys: "passthrough"
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2633
|
+
// const AugmentFactory =
|
|
2634
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2635
|
+
// <Augmentation extends ZodRawShape>(
|
|
2636
|
+
// augmentation: Augmentation
|
|
2637
|
+
// ): ZodObject<
|
|
2638
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2639
|
+
// Def["unknownKeys"],
|
|
2640
|
+
// Def["catchall"]
|
|
2641
|
+
// > => {
|
|
2642
|
+
// return new ZodObject({
|
|
2643
|
+
// ...def,
|
|
2644
|
+
// shape: () => ({
|
|
2645
|
+
// ...def.shape(),
|
|
2646
|
+
// ...augmentation,
|
|
2647
|
+
// }),
|
|
2648
|
+
// }) as any;
|
|
2649
|
+
// };
|
|
2650
|
+
extend(augmentation) {
|
|
2651
|
+
return new _ZodObject({
|
|
2652
|
+
...this._def,
|
|
2653
|
+
shape: () => ({
|
|
2654
|
+
...this._def.shape(),
|
|
2655
|
+
...augmentation
|
|
2656
|
+
})
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2661
|
+
* inferred type of merged objects. Please
|
|
2662
|
+
* upgrade if you are experiencing issues.
|
|
2663
|
+
*/
|
|
2664
|
+
merge(merging) {
|
|
2665
|
+
const merged = new _ZodObject({
|
|
2666
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2667
|
+
catchall: merging._def.catchall,
|
|
2668
|
+
shape: () => ({
|
|
2669
|
+
...this._def.shape(),
|
|
2670
|
+
...merging._def.shape()
|
|
2671
|
+
}),
|
|
2672
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2673
|
+
});
|
|
2674
|
+
return merged;
|
|
2675
|
+
}
|
|
2676
|
+
// merge<
|
|
2677
|
+
// Incoming extends AnyZodObject,
|
|
2678
|
+
// Augmentation extends Incoming["shape"],
|
|
2679
|
+
// NewOutput extends {
|
|
2680
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2681
|
+
// ? Augmentation[k]["_output"]
|
|
2682
|
+
// : k extends keyof Output
|
|
2683
|
+
// ? Output[k]
|
|
2684
|
+
// : never;
|
|
2685
|
+
// },
|
|
2686
|
+
// NewInput extends {
|
|
2687
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2688
|
+
// ? Augmentation[k]["_input"]
|
|
2689
|
+
// : k extends keyof Input
|
|
2690
|
+
// ? Input[k]
|
|
2691
|
+
// : never;
|
|
2692
|
+
// }
|
|
2693
|
+
// >(
|
|
2694
|
+
// merging: Incoming
|
|
2695
|
+
// ): ZodObject<
|
|
2696
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2697
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2698
|
+
// Incoming["_def"]["catchall"],
|
|
2699
|
+
// NewOutput,
|
|
2700
|
+
// NewInput
|
|
2701
|
+
// > {
|
|
2702
|
+
// const merged: any = new ZodObject({
|
|
2703
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2704
|
+
// catchall: merging._def.catchall,
|
|
2705
|
+
// shape: () =>
|
|
2706
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2707
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2708
|
+
// }) as any;
|
|
2709
|
+
// return merged;
|
|
2710
|
+
// }
|
|
2711
|
+
setKey(key, schema) {
|
|
2712
|
+
return this.augment({ [key]: schema });
|
|
2713
|
+
}
|
|
2714
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2715
|
+
// merging: Incoming
|
|
2716
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2717
|
+
// ZodObject<
|
|
2718
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2719
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2720
|
+
// Incoming["_def"]["catchall"]
|
|
2721
|
+
// > {
|
|
2722
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2723
|
+
// // this._def.shape(),
|
|
2724
|
+
// // merging._def.shape()
|
|
2725
|
+
// // );
|
|
2726
|
+
// const merged: any = new ZodObject({
|
|
2727
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2728
|
+
// catchall: merging._def.catchall,
|
|
2729
|
+
// shape: () =>
|
|
2730
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2731
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2732
|
+
// }) as any;
|
|
2733
|
+
// return merged;
|
|
2734
|
+
// }
|
|
2735
|
+
catchall(index) {
|
|
2736
|
+
return new _ZodObject({
|
|
2737
|
+
...this._def,
|
|
2738
|
+
catchall: index
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
pick(mask) {
|
|
2742
|
+
const shape = {};
|
|
2743
|
+
for (const key of util.objectKeys(mask)) {
|
|
2744
|
+
if (mask[key] && this.shape[key]) {
|
|
2745
|
+
shape[key] = this.shape[key];
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
return new _ZodObject({
|
|
2749
|
+
...this._def,
|
|
2750
|
+
shape: () => shape
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
omit(mask) {
|
|
2754
|
+
const shape = {};
|
|
2755
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2756
|
+
if (!mask[key]) {
|
|
2757
|
+
shape[key] = this.shape[key];
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
return new _ZodObject({
|
|
2761
|
+
...this._def,
|
|
2762
|
+
shape: () => shape
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* @deprecated
|
|
2767
|
+
*/
|
|
2768
|
+
deepPartial() {
|
|
2769
|
+
return deepPartialify(this);
|
|
2770
|
+
}
|
|
2771
|
+
partial(mask) {
|
|
2772
|
+
const newShape = {};
|
|
2773
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2774
|
+
const fieldSchema = this.shape[key];
|
|
2775
|
+
if (mask && !mask[key]) {
|
|
2776
|
+
newShape[key] = fieldSchema;
|
|
2777
|
+
} else {
|
|
2778
|
+
newShape[key] = fieldSchema.optional();
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
return new _ZodObject({
|
|
2782
|
+
...this._def,
|
|
2783
|
+
shape: () => newShape
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
required(mask) {
|
|
2787
|
+
const newShape = {};
|
|
2788
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2789
|
+
if (mask && !mask[key]) {
|
|
2790
|
+
newShape[key] = this.shape[key];
|
|
2791
|
+
} else {
|
|
2792
|
+
const fieldSchema = this.shape[key];
|
|
2793
|
+
let newField = fieldSchema;
|
|
2794
|
+
while (newField instanceof ZodOptional) {
|
|
2795
|
+
newField = newField._def.innerType;
|
|
2796
|
+
}
|
|
2797
|
+
newShape[key] = newField;
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
return new _ZodObject({
|
|
2801
|
+
...this._def,
|
|
2802
|
+
shape: () => newShape
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
keyof() {
|
|
2806
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
2807
|
+
}
|
|
2808
|
+
};
|
|
2809
|
+
ZodObject.create = (shape, params) => {
|
|
2810
|
+
return new ZodObject({
|
|
2811
|
+
shape: () => shape,
|
|
2812
|
+
unknownKeys: "strip",
|
|
2813
|
+
catchall: ZodNever.create(),
|
|
2814
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2815
|
+
...processCreateParams(params)
|
|
2816
|
+
});
|
|
2817
|
+
};
|
|
2818
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2819
|
+
return new ZodObject({
|
|
2820
|
+
shape: () => shape,
|
|
2821
|
+
unknownKeys: "strict",
|
|
2822
|
+
catchall: ZodNever.create(),
|
|
2823
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2824
|
+
...processCreateParams(params)
|
|
2825
|
+
});
|
|
2826
|
+
};
|
|
2827
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2828
|
+
return new ZodObject({
|
|
2829
|
+
shape,
|
|
2830
|
+
unknownKeys: "strip",
|
|
2831
|
+
catchall: ZodNever.create(),
|
|
2832
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2833
|
+
...processCreateParams(params)
|
|
2834
|
+
});
|
|
2835
|
+
};
|
|
2836
|
+
var ZodUnion = class extends ZodType {
|
|
2837
|
+
_parse(input) {
|
|
2838
|
+
const { ctx } = this._processInputParams(input);
|
|
2839
|
+
const options = this._def.options;
|
|
2840
|
+
function handleResults(results) {
|
|
2841
|
+
for (const result of results) {
|
|
2842
|
+
if (result.result.status === "valid") {
|
|
2843
|
+
return result.result;
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
for (const result of results) {
|
|
2847
|
+
if (result.result.status === "dirty") {
|
|
2848
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2849
|
+
return result.result;
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2853
|
+
addIssueToContext(ctx, {
|
|
2854
|
+
code: ZodIssueCode.invalid_union,
|
|
2855
|
+
unionErrors
|
|
2856
|
+
});
|
|
2857
|
+
return INVALID;
|
|
2858
|
+
}
|
|
2859
|
+
if (ctx.common.async) {
|
|
2860
|
+
return Promise.all(options.map(async (option) => {
|
|
2861
|
+
const childCtx = {
|
|
2862
|
+
...ctx,
|
|
2863
|
+
common: {
|
|
2864
|
+
...ctx.common,
|
|
2865
|
+
issues: []
|
|
2866
|
+
},
|
|
2867
|
+
parent: null
|
|
2868
|
+
};
|
|
2869
|
+
return {
|
|
2870
|
+
result: await option._parseAsync({
|
|
2871
|
+
data: ctx.data,
|
|
2872
|
+
path: ctx.path,
|
|
2873
|
+
parent: childCtx
|
|
2874
|
+
}),
|
|
2875
|
+
ctx: childCtx
|
|
2876
|
+
};
|
|
2877
|
+
})).then(handleResults);
|
|
2878
|
+
} else {
|
|
2879
|
+
let dirty = void 0;
|
|
2880
|
+
const issues = [];
|
|
2881
|
+
for (const option of options) {
|
|
2882
|
+
const childCtx = {
|
|
2883
|
+
...ctx,
|
|
2884
|
+
common: {
|
|
2885
|
+
...ctx.common,
|
|
2886
|
+
issues: []
|
|
2887
|
+
},
|
|
2888
|
+
parent: null
|
|
2889
|
+
};
|
|
2890
|
+
const result = option._parseSync({
|
|
2891
|
+
data: ctx.data,
|
|
2892
|
+
path: ctx.path,
|
|
2893
|
+
parent: childCtx
|
|
2894
|
+
});
|
|
2895
|
+
if (result.status === "valid") {
|
|
2896
|
+
return result;
|
|
2897
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
2898
|
+
dirty = { result, ctx: childCtx };
|
|
2899
|
+
}
|
|
2900
|
+
if (childCtx.common.issues.length) {
|
|
2901
|
+
issues.push(childCtx.common.issues);
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
if (dirty) {
|
|
2905
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2906
|
+
return dirty.result;
|
|
2907
|
+
}
|
|
2908
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
2909
|
+
addIssueToContext(ctx, {
|
|
2910
|
+
code: ZodIssueCode.invalid_union,
|
|
2911
|
+
unionErrors
|
|
2912
|
+
});
|
|
2913
|
+
return INVALID;
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
get options() {
|
|
2917
|
+
return this._def.options;
|
|
2918
|
+
}
|
|
2919
|
+
};
|
|
2920
|
+
ZodUnion.create = (types, params) => {
|
|
2921
|
+
return new ZodUnion({
|
|
2922
|
+
options: types,
|
|
2923
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2924
|
+
...processCreateParams(params)
|
|
2925
|
+
});
|
|
2926
|
+
};
|
|
2927
|
+
var getDiscriminator = (type) => {
|
|
2928
|
+
if (type instanceof ZodLazy) {
|
|
2929
|
+
return getDiscriminator(type.schema);
|
|
2930
|
+
} else if (type instanceof ZodEffects) {
|
|
2931
|
+
return getDiscriminator(type.innerType());
|
|
2932
|
+
} else if (type instanceof ZodLiteral) {
|
|
2933
|
+
return [type.value];
|
|
2934
|
+
} else if (type instanceof ZodEnum) {
|
|
2935
|
+
return type.options;
|
|
2936
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
2937
|
+
return util.objectValues(type.enum);
|
|
2938
|
+
} else if (type instanceof ZodDefault) {
|
|
2939
|
+
return getDiscriminator(type._def.innerType);
|
|
2940
|
+
} else if (type instanceof ZodUndefined) {
|
|
2941
|
+
return [void 0];
|
|
2942
|
+
} else if (type instanceof ZodNull) {
|
|
2943
|
+
return [null];
|
|
2944
|
+
} else if (type instanceof ZodOptional) {
|
|
2945
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2946
|
+
} else if (type instanceof ZodNullable) {
|
|
2947
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
2948
|
+
} else if (type instanceof ZodBranded) {
|
|
2949
|
+
return getDiscriminator(type.unwrap());
|
|
2950
|
+
} else if (type instanceof ZodReadonly) {
|
|
2951
|
+
return getDiscriminator(type.unwrap());
|
|
2952
|
+
} else if (type instanceof ZodCatch) {
|
|
2953
|
+
return getDiscriminator(type._def.innerType);
|
|
2954
|
+
} else {
|
|
2955
|
+
return [];
|
|
2956
|
+
}
|
|
2957
|
+
};
|
|
2958
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
2959
|
+
_parse(input) {
|
|
2960
|
+
const { ctx } = this._processInputParams(input);
|
|
2961
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2962
|
+
addIssueToContext(ctx, {
|
|
2963
|
+
code: ZodIssueCode.invalid_type,
|
|
2964
|
+
expected: ZodParsedType.object,
|
|
2965
|
+
received: ctx.parsedType
|
|
2966
|
+
});
|
|
2967
|
+
return INVALID;
|
|
2968
|
+
}
|
|
2969
|
+
const discriminator = this.discriminator;
|
|
2970
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
2971
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
2972
|
+
if (!option) {
|
|
2973
|
+
addIssueToContext(ctx, {
|
|
2974
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2975
|
+
options: Array.from(this.optionsMap.keys()),
|
|
2976
|
+
path: [discriminator]
|
|
2977
|
+
});
|
|
2978
|
+
return INVALID;
|
|
2979
|
+
}
|
|
2980
|
+
if (ctx.common.async) {
|
|
2981
|
+
return option._parseAsync({
|
|
2982
|
+
data: ctx.data,
|
|
2983
|
+
path: ctx.path,
|
|
2984
|
+
parent: ctx
|
|
2985
|
+
});
|
|
2986
|
+
} else {
|
|
2987
|
+
return option._parseSync({
|
|
2988
|
+
data: ctx.data,
|
|
2989
|
+
path: ctx.path,
|
|
2990
|
+
parent: ctx
|
|
2991
|
+
});
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
get discriminator() {
|
|
2995
|
+
return this._def.discriminator;
|
|
2996
|
+
}
|
|
2997
|
+
get options() {
|
|
2998
|
+
return this._def.options;
|
|
2999
|
+
}
|
|
3000
|
+
get optionsMap() {
|
|
3001
|
+
return this._def.optionsMap;
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3005
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3006
|
+
* have a different value for each object in the union.
|
|
3007
|
+
* @param discriminator the name of the discriminator property
|
|
3008
|
+
* @param types an array of object schemas
|
|
3009
|
+
* @param params
|
|
3010
|
+
*/
|
|
3011
|
+
static create(discriminator, options, params) {
|
|
3012
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
3013
|
+
for (const type of options) {
|
|
3014
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3015
|
+
if (!discriminatorValues.length) {
|
|
3016
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3017
|
+
}
|
|
3018
|
+
for (const value of discriminatorValues) {
|
|
3019
|
+
if (optionsMap.has(value)) {
|
|
3020
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3021
|
+
}
|
|
3022
|
+
optionsMap.set(value, type);
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
return new _ZodDiscriminatedUnion({
|
|
3026
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3027
|
+
discriminator,
|
|
3028
|
+
options,
|
|
3029
|
+
optionsMap,
|
|
3030
|
+
...processCreateParams(params)
|
|
3031
|
+
});
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
function mergeValues(a, b) {
|
|
3035
|
+
const aType = getParsedType(a);
|
|
3036
|
+
const bType = getParsedType(b);
|
|
3037
|
+
if (a === b) {
|
|
3038
|
+
return { valid: true, data: a };
|
|
3039
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
3040
|
+
const bKeys = util.objectKeys(b);
|
|
3041
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3042
|
+
const newObj = { ...a, ...b };
|
|
3043
|
+
for (const key of sharedKeys) {
|
|
3044
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
3045
|
+
if (!sharedValue.valid) {
|
|
3046
|
+
return { valid: false };
|
|
3047
|
+
}
|
|
3048
|
+
newObj[key] = sharedValue.data;
|
|
3049
|
+
}
|
|
3050
|
+
return { valid: true, data: newObj };
|
|
3051
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
3052
|
+
if (a.length !== b.length) {
|
|
3053
|
+
return { valid: false };
|
|
3054
|
+
}
|
|
3055
|
+
const newArray = [];
|
|
3056
|
+
for (let index = 0; index < a.length; index++) {
|
|
3057
|
+
const itemA = a[index];
|
|
3058
|
+
const itemB = b[index];
|
|
3059
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
3060
|
+
if (!sharedValue.valid) {
|
|
3061
|
+
return { valid: false };
|
|
3062
|
+
}
|
|
3063
|
+
newArray.push(sharedValue.data);
|
|
3064
|
+
}
|
|
3065
|
+
return { valid: true, data: newArray };
|
|
3066
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
3067
|
+
return { valid: true, data: a };
|
|
3068
|
+
} else {
|
|
3069
|
+
return { valid: false };
|
|
3070
|
+
}
|
|
122
3071
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
3072
|
+
var ZodIntersection = class extends ZodType {
|
|
3073
|
+
_parse(input) {
|
|
3074
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3075
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3076
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3077
|
+
return INVALID;
|
|
3078
|
+
}
|
|
3079
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3080
|
+
if (!merged.valid) {
|
|
3081
|
+
addIssueToContext(ctx, {
|
|
3082
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
3083
|
+
});
|
|
3084
|
+
return INVALID;
|
|
3085
|
+
}
|
|
3086
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3087
|
+
status.dirty();
|
|
3088
|
+
}
|
|
3089
|
+
return { status: status.value, value: merged.data };
|
|
3090
|
+
};
|
|
3091
|
+
if (ctx.common.async) {
|
|
3092
|
+
return Promise.all([
|
|
3093
|
+
this._def.left._parseAsync({
|
|
3094
|
+
data: ctx.data,
|
|
3095
|
+
path: ctx.path,
|
|
3096
|
+
parent: ctx
|
|
3097
|
+
}),
|
|
3098
|
+
this._def.right._parseAsync({
|
|
3099
|
+
data: ctx.data,
|
|
3100
|
+
path: ctx.path,
|
|
3101
|
+
parent: ctx
|
|
3102
|
+
})
|
|
3103
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
3104
|
+
} else {
|
|
3105
|
+
return handleParsed(this._def.left._parseSync({
|
|
3106
|
+
data: ctx.data,
|
|
3107
|
+
path: ctx.path,
|
|
3108
|
+
parent: ctx
|
|
3109
|
+
}), this._def.right._parseSync({
|
|
3110
|
+
data: ctx.data,
|
|
3111
|
+
path: ctx.path,
|
|
3112
|
+
parent: ctx
|
|
3113
|
+
}));
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
};
|
|
3117
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3118
|
+
return new ZodIntersection({
|
|
3119
|
+
left,
|
|
3120
|
+
right,
|
|
3121
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3122
|
+
...processCreateParams(params)
|
|
3123
|
+
});
|
|
3124
|
+
};
|
|
3125
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3126
|
+
_parse(input) {
|
|
3127
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3128
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3129
|
+
addIssueToContext(ctx, {
|
|
3130
|
+
code: ZodIssueCode.invalid_type,
|
|
3131
|
+
expected: ZodParsedType.array,
|
|
3132
|
+
received: ctx.parsedType
|
|
3133
|
+
});
|
|
3134
|
+
return INVALID;
|
|
3135
|
+
}
|
|
3136
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3137
|
+
addIssueToContext(ctx, {
|
|
3138
|
+
code: ZodIssueCode.too_small,
|
|
3139
|
+
minimum: this._def.items.length,
|
|
3140
|
+
inclusive: true,
|
|
3141
|
+
exact: false,
|
|
3142
|
+
type: "array"
|
|
3143
|
+
});
|
|
3144
|
+
return INVALID;
|
|
3145
|
+
}
|
|
3146
|
+
const rest = this._def.rest;
|
|
3147
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3148
|
+
addIssueToContext(ctx, {
|
|
3149
|
+
code: ZodIssueCode.too_big,
|
|
3150
|
+
maximum: this._def.items.length,
|
|
3151
|
+
inclusive: true,
|
|
3152
|
+
exact: false,
|
|
3153
|
+
type: "array"
|
|
3154
|
+
});
|
|
3155
|
+
status.dirty();
|
|
3156
|
+
}
|
|
3157
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3158
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3159
|
+
if (!schema)
|
|
3160
|
+
return null;
|
|
3161
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3162
|
+
}).filter((x) => !!x);
|
|
3163
|
+
if (ctx.common.async) {
|
|
3164
|
+
return Promise.all(items).then((results) => {
|
|
3165
|
+
return ParseStatus.mergeArray(status, results);
|
|
3166
|
+
});
|
|
3167
|
+
} else {
|
|
3168
|
+
return ParseStatus.mergeArray(status, items);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
get items() {
|
|
3172
|
+
return this._def.items;
|
|
3173
|
+
}
|
|
3174
|
+
rest(rest) {
|
|
3175
|
+
return new _ZodTuple({
|
|
3176
|
+
...this._def,
|
|
3177
|
+
rest
|
|
3178
|
+
});
|
|
3179
|
+
}
|
|
3180
|
+
};
|
|
3181
|
+
ZodTuple.create = (schemas, params) => {
|
|
3182
|
+
if (!Array.isArray(schemas)) {
|
|
3183
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3184
|
+
}
|
|
3185
|
+
return new ZodTuple({
|
|
3186
|
+
items: schemas,
|
|
3187
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3188
|
+
rest: null,
|
|
3189
|
+
...processCreateParams(params)
|
|
3190
|
+
});
|
|
3191
|
+
};
|
|
3192
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3193
|
+
get keySchema() {
|
|
3194
|
+
return this._def.keyType;
|
|
3195
|
+
}
|
|
3196
|
+
get valueSchema() {
|
|
3197
|
+
return this._def.valueType;
|
|
3198
|
+
}
|
|
3199
|
+
_parse(input) {
|
|
3200
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3201
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3202
|
+
addIssueToContext(ctx, {
|
|
3203
|
+
code: ZodIssueCode.invalid_type,
|
|
3204
|
+
expected: ZodParsedType.object,
|
|
3205
|
+
received: ctx.parsedType
|
|
3206
|
+
});
|
|
3207
|
+
return INVALID;
|
|
3208
|
+
}
|
|
3209
|
+
const pairs = [];
|
|
3210
|
+
const keyType = this._def.keyType;
|
|
3211
|
+
const valueType = this._def.valueType;
|
|
3212
|
+
for (const key in ctx.data) {
|
|
3213
|
+
pairs.push({
|
|
3214
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3215
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3216
|
+
alwaysSet: key in ctx.data
|
|
3217
|
+
});
|
|
3218
|
+
}
|
|
3219
|
+
if (ctx.common.async) {
|
|
3220
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3221
|
+
} else {
|
|
3222
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
get element() {
|
|
3226
|
+
return this._def.valueType;
|
|
3227
|
+
}
|
|
3228
|
+
static create(first, second, third) {
|
|
3229
|
+
if (second instanceof ZodType) {
|
|
3230
|
+
return new _ZodRecord({
|
|
3231
|
+
keyType: first,
|
|
3232
|
+
valueType: second,
|
|
3233
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3234
|
+
...processCreateParams(third)
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
return new _ZodRecord({
|
|
3238
|
+
keyType: ZodString.create(),
|
|
3239
|
+
valueType: first,
|
|
3240
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3241
|
+
...processCreateParams(second)
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
};
|
|
3245
|
+
var ZodMap = class extends ZodType {
|
|
3246
|
+
get keySchema() {
|
|
3247
|
+
return this._def.keyType;
|
|
3248
|
+
}
|
|
3249
|
+
get valueSchema() {
|
|
3250
|
+
return this._def.valueType;
|
|
3251
|
+
}
|
|
3252
|
+
_parse(input) {
|
|
3253
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3254
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3255
|
+
addIssueToContext(ctx, {
|
|
3256
|
+
code: ZodIssueCode.invalid_type,
|
|
3257
|
+
expected: ZodParsedType.map,
|
|
3258
|
+
received: ctx.parsedType
|
|
3259
|
+
});
|
|
3260
|
+
return INVALID;
|
|
3261
|
+
}
|
|
3262
|
+
const keyType = this._def.keyType;
|
|
3263
|
+
const valueType = this._def.valueType;
|
|
3264
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3265
|
+
return {
|
|
3266
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3267
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3268
|
+
};
|
|
3269
|
+
});
|
|
3270
|
+
if (ctx.common.async) {
|
|
3271
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3272
|
+
return Promise.resolve().then(async () => {
|
|
3273
|
+
for (const pair of pairs) {
|
|
3274
|
+
const key = await pair.key;
|
|
3275
|
+
const value = await pair.value;
|
|
3276
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3277
|
+
return INVALID;
|
|
3278
|
+
}
|
|
3279
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3280
|
+
status.dirty();
|
|
3281
|
+
}
|
|
3282
|
+
finalMap.set(key.value, value.value);
|
|
3283
|
+
}
|
|
3284
|
+
return { status: status.value, value: finalMap };
|
|
3285
|
+
});
|
|
3286
|
+
} else {
|
|
3287
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3288
|
+
for (const pair of pairs) {
|
|
3289
|
+
const key = pair.key;
|
|
3290
|
+
const value = pair.value;
|
|
3291
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3292
|
+
return INVALID;
|
|
3293
|
+
}
|
|
3294
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3295
|
+
status.dirty();
|
|
3296
|
+
}
|
|
3297
|
+
finalMap.set(key.value, value.value);
|
|
3298
|
+
}
|
|
3299
|
+
return { status: status.value, value: finalMap };
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
};
|
|
3303
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3304
|
+
return new ZodMap({
|
|
3305
|
+
valueType,
|
|
3306
|
+
keyType,
|
|
3307
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3308
|
+
...processCreateParams(params)
|
|
3309
|
+
});
|
|
3310
|
+
};
|
|
3311
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
3312
|
+
_parse(input) {
|
|
3313
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3314
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3315
|
+
addIssueToContext(ctx, {
|
|
3316
|
+
code: ZodIssueCode.invalid_type,
|
|
3317
|
+
expected: ZodParsedType.set,
|
|
3318
|
+
received: ctx.parsedType
|
|
3319
|
+
});
|
|
3320
|
+
return INVALID;
|
|
3321
|
+
}
|
|
3322
|
+
const def = this._def;
|
|
3323
|
+
if (def.minSize !== null) {
|
|
3324
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3325
|
+
addIssueToContext(ctx, {
|
|
3326
|
+
code: ZodIssueCode.too_small,
|
|
3327
|
+
minimum: def.minSize.value,
|
|
3328
|
+
type: "set",
|
|
3329
|
+
inclusive: true,
|
|
3330
|
+
exact: false,
|
|
3331
|
+
message: def.minSize.message
|
|
3332
|
+
});
|
|
3333
|
+
status.dirty();
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
if (def.maxSize !== null) {
|
|
3337
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3338
|
+
addIssueToContext(ctx, {
|
|
3339
|
+
code: ZodIssueCode.too_big,
|
|
3340
|
+
maximum: def.maxSize.value,
|
|
3341
|
+
type: "set",
|
|
3342
|
+
inclusive: true,
|
|
3343
|
+
exact: false,
|
|
3344
|
+
message: def.maxSize.message
|
|
3345
|
+
});
|
|
3346
|
+
status.dirty();
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
const valueType = this._def.valueType;
|
|
3350
|
+
function finalizeSet(elements2) {
|
|
3351
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
3352
|
+
for (const element of elements2) {
|
|
3353
|
+
if (element.status === "aborted")
|
|
3354
|
+
return INVALID;
|
|
3355
|
+
if (element.status === "dirty")
|
|
3356
|
+
status.dirty();
|
|
3357
|
+
parsedSet.add(element.value);
|
|
3358
|
+
}
|
|
3359
|
+
return { status: status.value, value: parsedSet };
|
|
3360
|
+
}
|
|
3361
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3362
|
+
if (ctx.common.async) {
|
|
3363
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3364
|
+
} else {
|
|
3365
|
+
return finalizeSet(elements);
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
min(minSize, message) {
|
|
3369
|
+
return new _ZodSet({
|
|
3370
|
+
...this._def,
|
|
3371
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3372
|
+
});
|
|
3373
|
+
}
|
|
3374
|
+
max(maxSize, message) {
|
|
3375
|
+
return new _ZodSet({
|
|
3376
|
+
...this._def,
|
|
3377
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3378
|
+
});
|
|
3379
|
+
}
|
|
3380
|
+
size(size, message) {
|
|
3381
|
+
return this.min(size, message).max(size, message);
|
|
3382
|
+
}
|
|
3383
|
+
nonempty(message) {
|
|
3384
|
+
return this.min(1, message);
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
ZodSet.create = (valueType, params) => {
|
|
3388
|
+
return new ZodSet({
|
|
3389
|
+
valueType,
|
|
3390
|
+
minSize: null,
|
|
3391
|
+
maxSize: null,
|
|
3392
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3393
|
+
...processCreateParams(params)
|
|
3394
|
+
});
|
|
3395
|
+
};
|
|
3396
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3397
|
+
constructor() {
|
|
3398
|
+
super(...arguments);
|
|
3399
|
+
this.validate = this.implement;
|
|
3400
|
+
}
|
|
3401
|
+
_parse(input) {
|
|
3402
|
+
const { ctx } = this._processInputParams(input);
|
|
3403
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3404
|
+
addIssueToContext(ctx, {
|
|
3405
|
+
code: ZodIssueCode.invalid_type,
|
|
3406
|
+
expected: ZodParsedType.function,
|
|
3407
|
+
received: ctx.parsedType
|
|
3408
|
+
});
|
|
3409
|
+
return INVALID;
|
|
3410
|
+
}
|
|
3411
|
+
function makeArgsIssue(args, error) {
|
|
3412
|
+
return makeIssue({
|
|
3413
|
+
data: args,
|
|
3414
|
+
path: ctx.path,
|
|
3415
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3416
|
+
issueData: {
|
|
3417
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3418
|
+
argumentsError: error
|
|
3419
|
+
}
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
function makeReturnsIssue(returns, error) {
|
|
3423
|
+
return makeIssue({
|
|
3424
|
+
data: returns,
|
|
3425
|
+
path: ctx.path,
|
|
3426
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3427
|
+
issueData: {
|
|
3428
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3429
|
+
returnTypeError: error
|
|
3430
|
+
}
|
|
3431
|
+
});
|
|
3432
|
+
}
|
|
3433
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3434
|
+
const fn = ctx.data;
|
|
3435
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3436
|
+
const me = this;
|
|
3437
|
+
return OK(async function(...args) {
|
|
3438
|
+
const error = new ZodError([]);
|
|
3439
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3440
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
3441
|
+
throw error;
|
|
3442
|
+
});
|
|
3443
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3444
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3445
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
3446
|
+
throw error;
|
|
3447
|
+
});
|
|
3448
|
+
return parsedReturns;
|
|
3449
|
+
});
|
|
3450
|
+
} else {
|
|
3451
|
+
const me = this;
|
|
3452
|
+
return OK(function(...args) {
|
|
3453
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3454
|
+
if (!parsedArgs.success) {
|
|
3455
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3456
|
+
}
|
|
3457
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3458
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3459
|
+
if (!parsedReturns.success) {
|
|
3460
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3461
|
+
}
|
|
3462
|
+
return parsedReturns.data;
|
|
3463
|
+
});
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
parameters() {
|
|
3467
|
+
return this._def.args;
|
|
3468
|
+
}
|
|
3469
|
+
returnType() {
|
|
3470
|
+
return this._def.returns;
|
|
3471
|
+
}
|
|
3472
|
+
args(...items) {
|
|
3473
|
+
return new _ZodFunction({
|
|
3474
|
+
...this._def,
|
|
3475
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3476
|
+
});
|
|
3477
|
+
}
|
|
3478
|
+
returns(returnType) {
|
|
3479
|
+
return new _ZodFunction({
|
|
3480
|
+
...this._def,
|
|
3481
|
+
returns: returnType
|
|
3482
|
+
});
|
|
3483
|
+
}
|
|
3484
|
+
implement(func) {
|
|
3485
|
+
const validatedFunc = this.parse(func);
|
|
3486
|
+
return validatedFunc;
|
|
3487
|
+
}
|
|
3488
|
+
strictImplement(func) {
|
|
3489
|
+
const validatedFunc = this.parse(func);
|
|
3490
|
+
return validatedFunc;
|
|
3491
|
+
}
|
|
3492
|
+
static create(args, returns, params) {
|
|
3493
|
+
return new _ZodFunction({
|
|
3494
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3495
|
+
returns: returns || ZodUnknown.create(),
|
|
3496
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3497
|
+
...processCreateParams(params)
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
var ZodLazy = class extends ZodType {
|
|
3502
|
+
get schema() {
|
|
3503
|
+
return this._def.getter();
|
|
3504
|
+
}
|
|
3505
|
+
_parse(input) {
|
|
3506
|
+
const { ctx } = this._processInputParams(input);
|
|
3507
|
+
const lazySchema = this._def.getter();
|
|
3508
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3509
|
+
}
|
|
3510
|
+
};
|
|
3511
|
+
ZodLazy.create = (getter, params) => {
|
|
3512
|
+
return new ZodLazy({
|
|
3513
|
+
getter,
|
|
3514
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3515
|
+
...processCreateParams(params)
|
|
3516
|
+
});
|
|
3517
|
+
};
|
|
3518
|
+
var ZodLiteral = class extends ZodType {
|
|
3519
|
+
_parse(input) {
|
|
3520
|
+
if (input.data !== this._def.value) {
|
|
3521
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3522
|
+
addIssueToContext(ctx, {
|
|
3523
|
+
received: ctx.data,
|
|
3524
|
+
code: ZodIssueCode.invalid_literal,
|
|
3525
|
+
expected: this._def.value
|
|
3526
|
+
});
|
|
3527
|
+
return INVALID;
|
|
3528
|
+
}
|
|
3529
|
+
return { status: "valid", value: input.data };
|
|
3530
|
+
}
|
|
3531
|
+
get value() {
|
|
3532
|
+
return this._def.value;
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
ZodLiteral.create = (value, params) => {
|
|
3536
|
+
return new ZodLiteral({
|
|
3537
|
+
value,
|
|
3538
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3539
|
+
...processCreateParams(params)
|
|
3540
|
+
});
|
|
3541
|
+
};
|
|
3542
|
+
function createZodEnum(values, params) {
|
|
3543
|
+
return new ZodEnum({
|
|
3544
|
+
values,
|
|
3545
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3546
|
+
...processCreateParams(params)
|
|
3547
|
+
});
|
|
127
3548
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
3549
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3550
|
+
_parse(input) {
|
|
3551
|
+
if (typeof input.data !== "string") {
|
|
3552
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3553
|
+
const expectedValues = this._def.values;
|
|
3554
|
+
addIssueToContext(ctx, {
|
|
3555
|
+
expected: util.joinValues(expectedValues),
|
|
3556
|
+
received: ctx.parsedType,
|
|
3557
|
+
code: ZodIssueCode.invalid_type
|
|
3558
|
+
});
|
|
3559
|
+
return INVALID;
|
|
3560
|
+
}
|
|
3561
|
+
if (!this._cache) {
|
|
3562
|
+
this._cache = new Set(this._def.values);
|
|
3563
|
+
}
|
|
3564
|
+
if (!this._cache.has(input.data)) {
|
|
3565
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3566
|
+
const expectedValues = this._def.values;
|
|
3567
|
+
addIssueToContext(ctx, {
|
|
3568
|
+
received: ctx.data,
|
|
3569
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3570
|
+
options: expectedValues
|
|
3571
|
+
});
|
|
3572
|
+
return INVALID;
|
|
3573
|
+
}
|
|
3574
|
+
return OK(input.data);
|
|
134
3575
|
}
|
|
135
|
-
|
|
3576
|
+
get options() {
|
|
3577
|
+
return this._def.values;
|
|
3578
|
+
}
|
|
3579
|
+
get enum() {
|
|
3580
|
+
const enumValues = {};
|
|
3581
|
+
for (const val of this._def.values) {
|
|
3582
|
+
enumValues[val] = val;
|
|
3583
|
+
}
|
|
3584
|
+
return enumValues;
|
|
3585
|
+
}
|
|
3586
|
+
get Values() {
|
|
3587
|
+
const enumValues = {};
|
|
3588
|
+
for (const val of this._def.values) {
|
|
3589
|
+
enumValues[val] = val;
|
|
3590
|
+
}
|
|
3591
|
+
return enumValues;
|
|
3592
|
+
}
|
|
3593
|
+
get Enum() {
|
|
3594
|
+
const enumValues = {};
|
|
3595
|
+
for (const val of this._def.values) {
|
|
3596
|
+
enumValues[val] = val;
|
|
3597
|
+
}
|
|
3598
|
+
return enumValues;
|
|
3599
|
+
}
|
|
3600
|
+
extract(values, newDef = this._def) {
|
|
3601
|
+
return _ZodEnum.create(values, {
|
|
3602
|
+
...this._def,
|
|
3603
|
+
...newDef
|
|
3604
|
+
});
|
|
3605
|
+
}
|
|
3606
|
+
exclude(values, newDef = this._def) {
|
|
3607
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3608
|
+
...this._def,
|
|
3609
|
+
...newDef
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
};
|
|
3613
|
+
ZodEnum.create = createZodEnum;
|
|
3614
|
+
var ZodNativeEnum = class extends ZodType {
|
|
3615
|
+
_parse(input) {
|
|
3616
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3617
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3618
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3619
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3620
|
+
addIssueToContext(ctx, {
|
|
3621
|
+
expected: util.joinValues(expectedValues),
|
|
3622
|
+
received: ctx.parsedType,
|
|
3623
|
+
code: ZodIssueCode.invalid_type
|
|
3624
|
+
});
|
|
3625
|
+
return INVALID;
|
|
3626
|
+
}
|
|
3627
|
+
if (!this._cache) {
|
|
3628
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3629
|
+
}
|
|
3630
|
+
if (!this._cache.has(input.data)) {
|
|
3631
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3632
|
+
addIssueToContext(ctx, {
|
|
3633
|
+
received: ctx.data,
|
|
3634
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3635
|
+
options: expectedValues
|
|
3636
|
+
});
|
|
3637
|
+
return INVALID;
|
|
3638
|
+
}
|
|
3639
|
+
return OK(input.data);
|
|
3640
|
+
}
|
|
3641
|
+
get enum() {
|
|
3642
|
+
return this._def.values;
|
|
3643
|
+
}
|
|
3644
|
+
};
|
|
3645
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3646
|
+
return new ZodNativeEnum({
|
|
3647
|
+
values,
|
|
3648
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3649
|
+
...processCreateParams(params)
|
|
3650
|
+
});
|
|
3651
|
+
};
|
|
3652
|
+
var ZodPromise = class extends ZodType {
|
|
3653
|
+
unwrap() {
|
|
3654
|
+
return this._def.type;
|
|
3655
|
+
}
|
|
3656
|
+
_parse(input) {
|
|
3657
|
+
const { ctx } = this._processInputParams(input);
|
|
3658
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3659
|
+
addIssueToContext(ctx, {
|
|
3660
|
+
code: ZodIssueCode.invalid_type,
|
|
3661
|
+
expected: ZodParsedType.promise,
|
|
3662
|
+
received: ctx.parsedType
|
|
3663
|
+
});
|
|
3664
|
+
return INVALID;
|
|
3665
|
+
}
|
|
3666
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3667
|
+
return OK(promisified.then((data) => {
|
|
3668
|
+
return this._def.type.parseAsync(data, {
|
|
3669
|
+
path: ctx.path,
|
|
3670
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3671
|
+
});
|
|
3672
|
+
}));
|
|
3673
|
+
}
|
|
3674
|
+
};
|
|
3675
|
+
ZodPromise.create = (schema, params) => {
|
|
3676
|
+
return new ZodPromise({
|
|
3677
|
+
type: schema,
|
|
3678
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3679
|
+
...processCreateParams(params)
|
|
3680
|
+
});
|
|
3681
|
+
};
|
|
3682
|
+
var ZodEffects = class extends ZodType {
|
|
3683
|
+
innerType() {
|
|
3684
|
+
return this._def.schema;
|
|
3685
|
+
}
|
|
3686
|
+
sourceType() {
|
|
3687
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3688
|
+
}
|
|
3689
|
+
_parse(input) {
|
|
3690
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3691
|
+
const effect = this._def.effect || null;
|
|
3692
|
+
const checkCtx = {
|
|
3693
|
+
addIssue: (arg) => {
|
|
3694
|
+
addIssueToContext(ctx, arg);
|
|
3695
|
+
if (arg.fatal) {
|
|
3696
|
+
status.abort();
|
|
3697
|
+
} else {
|
|
3698
|
+
status.dirty();
|
|
3699
|
+
}
|
|
3700
|
+
},
|
|
3701
|
+
get path() {
|
|
3702
|
+
return ctx.path;
|
|
3703
|
+
}
|
|
3704
|
+
};
|
|
3705
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3706
|
+
if (effect.type === "preprocess") {
|
|
3707
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3708
|
+
if (ctx.common.async) {
|
|
3709
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3710
|
+
if (status.value === "aborted")
|
|
3711
|
+
return INVALID;
|
|
3712
|
+
const result = await this._def.schema._parseAsync({
|
|
3713
|
+
data: processed2,
|
|
3714
|
+
path: ctx.path,
|
|
3715
|
+
parent: ctx
|
|
3716
|
+
});
|
|
3717
|
+
if (result.status === "aborted")
|
|
3718
|
+
return INVALID;
|
|
3719
|
+
if (result.status === "dirty")
|
|
3720
|
+
return DIRTY(result.value);
|
|
3721
|
+
if (status.value === "dirty")
|
|
3722
|
+
return DIRTY(result.value);
|
|
3723
|
+
return result;
|
|
3724
|
+
});
|
|
3725
|
+
} else {
|
|
3726
|
+
if (status.value === "aborted")
|
|
3727
|
+
return INVALID;
|
|
3728
|
+
const result = this._def.schema._parseSync({
|
|
3729
|
+
data: processed,
|
|
3730
|
+
path: ctx.path,
|
|
3731
|
+
parent: ctx
|
|
3732
|
+
});
|
|
3733
|
+
if (result.status === "aborted")
|
|
3734
|
+
return INVALID;
|
|
3735
|
+
if (result.status === "dirty")
|
|
3736
|
+
return DIRTY(result.value);
|
|
3737
|
+
if (status.value === "dirty")
|
|
3738
|
+
return DIRTY(result.value);
|
|
3739
|
+
return result;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
if (effect.type === "refinement") {
|
|
3743
|
+
const executeRefinement = (acc) => {
|
|
3744
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3745
|
+
if (ctx.common.async) {
|
|
3746
|
+
return Promise.resolve(result);
|
|
3747
|
+
}
|
|
3748
|
+
if (result instanceof Promise) {
|
|
3749
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3750
|
+
}
|
|
3751
|
+
return acc;
|
|
3752
|
+
};
|
|
3753
|
+
if (ctx.common.async === false) {
|
|
3754
|
+
const inner = this._def.schema._parseSync({
|
|
3755
|
+
data: ctx.data,
|
|
3756
|
+
path: ctx.path,
|
|
3757
|
+
parent: ctx
|
|
3758
|
+
});
|
|
3759
|
+
if (inner.status === "aborted")
|
|
3760
|
+
return INVALID;
|
|
3761
|
+
if (inner.status === "dirty")
|
|
3762
|
+
status.dirty();
|
|
3763
|
+
executeRefinement(inner.value);
|
|
3764
|
+
return { status: status.value, value: inner.value };
|
|
3765
|
+
} else {
|
|
3766
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3767
|
+
if (inner.status === "aborted")
|
|
3768
|
+
return INVALID;
|
|
3769
|
+
if (inner.status === "dirty")
|
|
3770
|
+
status.dirty();
|
|
3771
|
+
return executeRefinement(inner.value).then(() => {
|
|
3772
|
+
return { status: status.value, value: inner.value };
|
|
3773
|
+
});
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
if (effect.type === "transform") {
|
|
3778
|
+
if (ctx.common.async === false) {
|
|
3779
|
+
const base = this._def.schema._parseSync({
|
|
3780
|
+
data: ctx.data,
|
|
3781
|
+
path: ctx.path,
|
|
3782
|
+
parent: ctx
|
|
3783
|
+
});
|
|
3784
|
+
if (!isValid(base))
|
|
3785
|
+
return INVALID;
|
|
3786
|
+
const result = effect.transform(base.value, checkCtx);
|
|
3787
|
+
if (result instanceof Promise) {
|
|
3788
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3789
|
+
}
|
|
3790
|
+
return { status: status.value, value: result };
|
|
3791
|
+
} else {
|
|
3792
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
3793
|
+
if (!isValid(base))
|
|
3794
|
+
return INVALID;
|
|
3795
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3796
|
+
status: status.value,
|
|
3797
|
+
value: result
|
|
3798
|
+
}));
|
|
3799
|
+
});
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
util.assertNever(effect);
|
|
3803
|
+
}
|
|
3804
|
+
};
|
|
3805
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
3806
|
+
return new ZodEffects({
|
|
3807
|
+
schema,
|
|
3808
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3809
|
+
effect,
|
|
3810
|
+
...processCreateParams(params)
|
|
3811
|
+
});
|
|
3812
|
+
};
|
|
3813
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3814
|
+
return new ZodEffects({
|
|
3815
|
+
schema,
|
|
3816
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
3817
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3818
|
+
...processCreateParams(params)
|
|
3819
|
+
});
|
|
3820
|
+
};
|
|
3821
|
+
var ZodOptional = class extends ZodType {
|
|
3822
|
+
_parse(input) {
|
|
3823
|
+
const parsedType = this._getType(input);
|
|
3824
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
3825
|
+
return OK(void 0);
|
|
3826
|
+
}
|
|
3827
|
+
return this._def.innerType._parse(input);
|
|
3828
|
+
}
|
|
3829
|
+
unwrap() {
|
|
3830
|
+
return this._def.innerType;
|
|
3831
|
+
}
|
|
3832
|
+
};
|
|
3833
|
+
ZodOptional.create = (type, params) => {
|
|
3834
|
+
return new ZodOptional({
|
|
3835
|
+
innerType: type,
|
|
3836
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3837
|
+
...processCreateParams(params)
|
|
3838
|
+
});
|
|
3839
|
+
};
|
|
3840
|
+
var ZodNullable = class extends ZodType {
|
|
3841
|
+
_parse(input) {
|
|
3842
|
+
const parsedType = this._getType(input);
|
|
3843
|
+
if (parsedType === ZodParsedType.null) {
|
|
3844
|
+
return OK(null);
|
|
3845
|
+
}
|
|
3846
|
+
return this._def.innerType._parse(input);
|
|
3847
|
+
}
|
|
3848
|
+
unwrap() {
|
|
3849
|
+
return this._def.innerType;
|
|
3850
|
+
}
|
|
3851
|
+
};
|
|
3852
|
+
ZodNullable.create = (type, params) => {
|
|
3853
|
+
return new ZodNullable({
|
|
3854
|
+
innerType: type,
|
|
3855
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3856
|
+
...processCreateParams(params)
|
|
3857
|
+
});
|
|
3858
|
+
};
|
|
3859
|
+
var ZodDefault = class extends ZodType {
|
|
3860
|
+
_parse(input) {
|
|
3861
|
+
const { ctx } = this._processInputParams(input);
|
|
3862
|
+
let data = ctx.data;
|
|
3863
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3864
|
+
data = this._def.defaultValue();
|
|
3865
|
+
}
|
|
3866
|
+
return this._def.innerType._parse({
|
|
3867
|
+
data,
|
|
3868
|
+
path: ctx.path,
|
|
3869
|
+
parent: ctx
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3872
|
+
removeDefault() {
|
|
3873
|
+
return this._def.innerType;
|
|
3874
|
+
}
|
|
3875
|
+
};
|
|
3876
|
+
ZodDefault.create = (type, params) => {
|
|
3877
|
+
return new ZodDefault({
|
|
3878
|
+
innerType: type,
|
|
3879
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3880
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3881
|
+
...processCreateParams(params)
|
|
3882
|
+
});
|
|
3883
|
+
};
|
|
3884
|
+
var ZodCatch = class extends ZodType {
|
|
3885
|
+
_parse(input) {
|
|
3886
|
+
const { ctx } = this._processInputParams(input);
|
|
3887
|
+
const newCtx = {
|
|
3888
|
+
...ctx,
|
|
3889
|
+
common: {
|
|
3890
|
+
...ctx.common,
|
|
3891
|
+
issues: []
|
|
3892
|
+
}
|
|
3893
|
+
};
|
|
3894
|
+
const result = this._def.innerType._parse({
|
|
3895
|
+
data: newCtx.data,
|
|
3896
|
+
path: newCtx.path,
|
|
3897
|
+
parent: {
|
|
3898
|
+
...newCtx
|
|
3899
|
+
}
|
|
3900
|
+
});
|
|
3901
|
+
if (isAsync(result)) {
|
|
3902
|
+
return result.then((result2) => {
|
|
3903
|
+
return {
|
|
3904
|
+
status: "valid",
|
|
3905
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
3906
|
+
get error() {
|
|
3907
|
+
return new ZodError(newCtx.common.issues);
|
|
3908
|
+
},
|
|
3909
|
+
input: newCtx.data
|
|
3910
|
+
})
|
|
3911
|
+
};
|
|
3912
|
+
});
|
|
3913
|
+
} else {
|
|
3914
|
+
return {
|
|
3915
|
+
status: "valid",
|
|
3916
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3917
|
+
get error() {
|
|
3918
|
+
return new ZodError(newCtx.common.issues);
|
|
3919
|
+
},
|
|
3920
|
+
input: newCtx.data
|
|
3921
|
+
})
|
|
3922
|
+
};
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
removeCatch() {
|
|
3926
|
+
return this._def.innerType;
|
|
3927
|
+
}
|
|
3928
|
+
};
|
|
3929
|
+
ZodCatch.create = (type, params) => {
|
|
3930
|
+
return new ZodCatch({
|
|
3931
|
+
innerType: type,
|
|
3932
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3933
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3934
|
+
...processCreateParams(params)
|
|
3935
|
+
});
|
|
3936
|
+
};
|
|
3937
|
+
var ZodNaN = class extends ZodType {
|
|
3938
|
+
_parse(input) {
|
|
3939
|
+
const parsedType = this._getType(input);
|
|
3940
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
3941
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3942
|
+
addIssueToContext(ctx, {
|
|
3943
|
+
code: ZodIssueCode.invalid_type,
|
|
3944
|
+
expected: ZodParsedType.nan,
|
|
3945
|
+
received: ctx.parsedType
|
|
3946
|
+
});
|
|
3947
|
+
return INVALID;
|
|
3948
|
+
}
|
|
3949
|
+
return { status: "valid", value: input.data };
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
ZodNaN.create = (params) => {
|
|
3953
|
+
return new ZodNaN({
|
|
3954
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3955
|
+
...processCreateParams(params)
|
|
3956
|
+
});
|
|
3957
|
+
};
|
|
3958
|
+
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
3959
|
+
var ZodBranded = class extends ZodType {
|
|
3960
|
+
_parse(input) {
|
|
3961
|
+
const { ctx } = this._processInputParams(input);
|
|
3962
|
+
const data = ctx.data;
|
|
3963
|
+
return this._def.type._parse({
|
|
3964
|
+
data,
|
|
3965
|
+
path: ctx.path,
|
|
3966
|
+
parent: ctx
|
|
3967
|
+
});
|
|
3968
|
+
}
|
|
3969
|
+
unwrap() {
|
|
3970
|
+
return this._def.type;
|
|
3971
|
+
}
|
|
3972
|
+
};
|
|
3973
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
3974
|
+
_parse(input) {
|
|
3975
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3976
|
+
if (ctx.common.async) {
|
|
3977
|
+
const handleAsync = async () => {
|
|
3978
|
+
const inResult = await this._def.in._parseAsync({
|
|
3979
|
+
data: ctx.data,
|
|
3980
|
+
path: ctx.path,
|
|
3981
|
+
parent: ctx
|
|
3982
|
+
});
|
|
3983
|
+
if (inResult.status === "aborted")
|
|
3984
|
+
return INVALID;
|
|
3985
|
+
if (inResult.status === "dirty") {
|
|
3986
|
+
status.dirty();
|
|
3987
|
+
return DIRTY(inResult.value);
|
|
3988
|
+
} else {
|
|
3989
|
+
return this._def.out._parseAsync({
|
|
3990
|
+
data: inResult.value,
|
|
3991
|
+
path: ctx.path,
|
|
3992
|
+
parent: ctx
|
|
3993
|
+
});
|
|
3994
|
+
}
|
|
3995
|
+
};
|
|
3996
|
+
return handleAsync();
|
|
3997
|
+
} else {
|
|
3998
|
+
const inResult = this._def.in._parseSync({
|
|
3999
|
+
data: ctx.data,
|
|
4000
|
+
path: ctx.path,
|
|
4001
|
+
parent: ctx
|
|
4002
|
+
});
|
|
4003
|
+
if (inResult.status === "aborted")
|
|
4004
|
+
return INVALID;
|
|
4005
|
+
if (inResult.status === "dirty") {
|
|
4006
|
+
status.dirty();
|
|
4007
|
+
return {
|
|
4008
|
+
status: "dirty",
|
|
4009
|
+
value: inResult.value
|
|
4010
|
+
};
|
|
4011
|
+
} else {
|
|
4012
|
+
return this._def.out._parseSync({
|
|
4013
|
+
data: inResult.value,
|
|
4014
|
+
path: ctx.path,
|
|
4015
|
+
parent: ctx
|
|
4016
|
+
});
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
static create(a, b) {
|
|
4021
|
+
return new _ZodPipeline({
|
|
4022
|
+
in: a,
|
|
4023
|
+
out: b,
|
|
4024
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
4025
|
+
});
|
|
4026
|
+
}
|
|
4027
|
+
};
|
|
4028
|
+
var ZodReadonly = class extends ZodType {
|
|
4029
|
+
_parse(input) {
|
|
4030
|
+
const result = this._def.innerType._parse(input);
|
|
4031
|
+
const freeze = (data) => {
|
|
4032
|
+
if (isValid(data)) {
|
|
4033
|
+
data.value = Object.freeze(data.value);
|
|
4034
|
+
}
|
|
4035
|
+
return data;
|
|
4036
|
+
};
|
|
4037
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
4038
|
+
}
|
|
4039
|
+
unwrap() {
|
|
4040
|
+
return this._def.innerType;
|
|
4041
|
+
}
|
|
4042
|
+
};
|
|
4043
|
+
ZodReadonly.create = (type, params) => {
|
|
4044
|
+
return new ZodReadonly({
|
|
4045
|
+
innerType: type,
|
|
4046
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
4047
|
+
...processCreateParams(params)
|
|
4048
|
+
});
|
|
4049
|
+
};
|
|
4050
|
+
function cleanParams(params, data) {
|
|
4051
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
4052
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4053
|
+
return p2;
|
|
4054
|
+
}
|
|
4055
|
+
function custom(check, _params = {}, fatal) {
|
|
4056
|
+
if (check)
|
|
4057
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
4058
|
+
const r = check(data);
|
|
4059
|
+
if (r instanceof Promise) {
|
|
4060
|
+
return r.then((r2) => {
|
|
4061
|
+
if (!r2) {
|
|
4062
|
+
const params = cleanParams(_params, data);
|
|
4063
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
4064
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4065
|
+
}
|
|
4066
|
+
});
|
|
4067
|
+
}
|
|
4068
|
+
if (!r) {
|
|
4069
|
+
const params = cleanParams(_params, data);
|
|
4070
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
4071
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4072
|
+
}
|
|
4073
|
+
return;
|
|
4074
|
+
});
|
|
4075
|
+
return ZodAny.create();
|
|
136
4076
|
}
|
|
4077
|
+
var late = {
|
|
4078
|
+
object: ZodObject.lazycreate
|
|
4079
|
+
};
|
|
4080
|
+
var ZodFirstPartyTypeKind;
|
|
4081
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
4082
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
4083
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
4084
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
4085
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
4086
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
4087
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
4088
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
4089
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
4090
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
4091
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
4092
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
4093
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
4094
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
4095
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
4096
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
4097
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
4098
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
4099
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4100
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4101
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4102
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4103
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4104
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4105
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4106
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4107
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4108
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4109
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4110
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4111
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4112
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4113
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4114
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4115
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4116
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4117
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4118
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4119
|
+
var instanceOfType = (cls, params = {
|
|
4120
|
+
message: `Input not instance of ${cls.name}`
|
|
4121
|
+
}) => custom((data) => data instanceof cls, params);
|
|
4122
|
+
var stringType = ZodString.create;
|
|
4123
|
+
var numberType = ZodNumber.create;
|
|
4124
|
+
var nanType = ZodNaN.create;
|
|
4125
|
+
var bigIntType = ZodBigInt.create;
|
|
4126
|
+
var booleanType = ZodBoolean.create;
|
|
4127
|
+
var dateType = ZodDate.create;
|
|
4128
|
+
var symbolType = ZodSymbol.create;
|
|
4129
|
+
var undefinedType = ZodUndefined.create;
|
|
4130
|
+
var nullType = ZodNull.create;
|
|
4131
|
+
var anyType = ZodAny.create;
|
|
4132
|
+
var unknownType = ZodUnknown.create;
|
|
4133
|
+
var neverType = ZodNever.create;
|
|
4134
|
+
var voidType = ZodVoid.create;
|
|
4135
|
+
var arrayType = ZodArray.create;
|
|
4136
|
+
var objectType = ZodObject.create;
|
|
4137
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
4138
|
+
var unionType = ZodUnion.create;
|
|
4139
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4140
|
+
var intersectionType = ZodIntersection.create;
|
|
4141
|
+
var tupleType = ZodTuple.create;
|
|
4142
|
+
var recordType = ZodRecord.create;
|
|
4143
|
+
var mapType = ZodMap.create;
|
|
4144
|
+
var setType = ZodSet.create;
|
|
4145
|
+
var functionType = ZodFunction.create;
|
|
4146
|
+
var lazyType = ZodLazy.create;
|
|
4147
|
+
var literalType = ZodLiteral.create;
|
|
4148
|
+
var enumType = ZodEnum.create;
|
|
4149
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
4150
|
+
var promiseType = ZodPromise.create;
|
|
4151
|
+
var effectsType = ZodEffects.create;
|
|
4152
|
+
var optionalType = ZodOptional.create;
|
|
4153
|
+
var nullableType = ZodNullable.create;
|
|
4154
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4155
|
+
var pipelineType = ZodPipeline.create;
|
|
4156
|
+
var ostring = () => stringType().optional();
|
|
4157
|
+
var onumber = () => numberType().optional();
|
|
4158
|
+
var oboolean = () => booleanType().optional();
|
|
4159
|
+
var coerce = {
|
|
4160
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4161
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4162
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
4163
|
+
...arg,
|
|
4164
|
+
coerce: true
|
|
4165
|
+
})),
|
|
4166
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4167
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4168
|
+
};
|
|
4169
|
+
var NEVER = INVALID;
|
|
137
4170
|
|
|
138
4171
|
// src/lib/types.ts
|
|
4172
|
+
var PackageManifestSchema = external_exports.strictObject({
|
|
4173
|
+
schemaVersion: external_exports.literal(1),
|
|
4174
|
+
id: external_exports.string().min(1),
|
|
4175
|
+
version: external_exports.string().min(1),
|
|
4176
|
+
description: external_exports.string().optional(),
|
|
4177
|
+
entrypoint: external_exports.string().min(1)
|
|
4178
|
+
});
|
|
139
4179
|
var CONFIG_FILE = "agent-pkg.json";
|
|
140
4180
|
var LOCK_FILE = "agent-pkg.lock.json";
|
|
141
4181
|
var DEFAULT_MODULES_DIR = "agent_modules";
|
|
142
4182
|
var DEFAULT_BUILD_DIR = ".agent-pkg/build";
|
|
143
4183
|
var DEFAULT_CACHE_DIR = ".agent-pkg/cache";
|
|
144
4184
|
var PACKAGE_MANIFEST_FILE = "agent-pkg.package.json";
|
|
4185
|
+
var REGISTRY_MANIFEST_FILE = "agent-pkg.registry.json";
|
|
4186
|
+
var DEFAULT_ENTRYPOINT = "agent-contracts.yaml";
|
|
145
4187
|
|
|
146
4188
|
// src/lib/commands/init.ts
|
|
147
4189
|
async function runInit(opts, projectDir) {
|
|
@@ -228,8 +4270,8 @@ active_guardrail_policy: default
|
|
|
228
4270
|
|
|
229
4271
|
// src/lib/commands/add.ts
|
|
230
4272
|
import { existsSync as existsSync4 } from "fs";
|
|
231
|
-
import { mkdir as mkdir3, rm, readFile as
|
|
232
|
-
import { join as
|
|
4273
|
+
import { mkdir as mkdir3, rm, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
4274
|
+
import { join as join6 } from "path";
|
|
233
4275
|
|
|
234
4276
|
// src/lib/config.ts
|
|
235
4277
|
import { readFile, writeFile as writeFile2 } from "fs/promises";
|
|
@@ -266,10 +4308,16 @@ function lockExists(projectDir) {
|
|
|
266
4308
|
return existsSync2(join2(projectDir, LOCK_FILE));
|
|
267
4309
|
}
|
|
268
4310
|
async function readPackageManifest(packageDir) {
|
|
269
|
-
const
|
|
270
|
-
if (!existsSync2(
|
|
271
|
-
const raw = await readFile(
|
|
272
|
-
|
|
4311
|
+
const filePath = join2(packageDir, PACKAGE_MANIFEST_FILE);
|
|
4312
|
+
if (!existsSync2(filePath)) return null;
|
|
4313
|
+
const raw = await readFile(filePath, "utf8");
|
|
4314
|
+
const parsed = PackageManifestSchema.safeParse(JSON.parse(raw));
|
|
4315
|
+
if (!parsed.success) {
|
|
4316
|
+
const issues = parsed.error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
4317
|
+
throw new Error(`Invalid ${PACKAGE_MANIFEST_FILE} in ${packageDir}:
|
|
4318
|
+
${issues}`);
|
|
4319
|
+
}
|
|
4320
|
+
return parsed.data;
|
|
273
4321
|
}
|
|
274
4322
|
async function readPackageJson(packageDir) {
|
|
275
4323
|
const path = join2(packageDir, "package.json");
|
|
@@ -302,6 +4350,9 @@ function getCacheBaseDir() {
|
|
|
302
4350
|
function getRepoCacheDir(owner, repo) {
|
|
303
4351
|
return join3(getCacheBaseDir(), "github.com", owner, repo);
|
|
304
4352
|
}
|
|
4353
|
+
function getWorkingCopyDir(owner, repo) {
|
|
4354
|
+
return join3(getCacheBaseDir(), "github.com", owner, `${repo}__work`);
|
|
4355
|
+
}
|
|
305
4356
|
function repoUrl(owner, repo) {
|
|
306
4357
|
return `https://github.com/${owner}/${repo}.git`;
|
|
307
4358
|
}
|
|
@@ -309,7 +4360,7 @@ async function ensureCloned(owner, repo) {
|
|
|
309
4360
|
const dir = getRepoCacheDir(owner, repo);
|
|
310
4361
|
if (existsSync3(join3(dir, "HEAD"))) {
|
|
311
4362
|
log.debug(`Cache hit: ${dir}`);
|
|
312
|
-
await
|
|
4363
|
+
await fetchAll(dir);
|
|
313
4364
|
return dir;
|
|
314
4365
|
}
|
|
315
4366
|
const parent = join3(dir, "..");
|
|
@@ -319,24 +4370,16 @@ async function ensureCloned(owner, repo) {
|
|
|
319
4370
|
await git(["clone", "--bare", url, dir]);
|
|
320
4371
|
return dir;
|
|
321
4372
|
}
|
|
322
|
-
async function
|
|
323
|
-
log.debug(`Fetching
|
|
324
|
-
await git(["fetch", "--
|
|
4373
|
+
async function fetchAll(repoPath) {
|
|
4374
|
+
log.debug(`Fetching in ${repoPath}`);
|
|
4375
|
+
await git(["fetch", "--prune", "--force"], repoPath);
|
|
325
4376
|
}
|
|
326
|
-
async function
|
|
327
|
-
|
|
328
|
-
return git(["rev-parse", `${tag}^{commit}`], repoPath);
|
|
4377
|
+
async function readFileFromRepo(repoPath, filePath, ref = "HEAD") {
|
|
4378
|
+
return git(["show", `${ref}:${filePath}`], repoPath);
|
|
329
4379
|
}
|
|
330
|
-
async function
|
|
331
|
-
|
|
332
|
-
const output = await git(["tag", "--list", `${prefix}*`], repoPath);
|
|
333
|
-
if (!output) return [];
|
|
334
|
-
return output.split("\n").filter((t) => t.startsWith(prefix)).sort();
|
|
335
|
-
}
|
|
336
|
-
async function extractPackageSimple(repoPath, tag, packagePath, destDir) {
|
|
337
|
-
log.debug(`Extracting ${packagePath} at ${tag} \u2192 ${destDir}`);
|
|
4380
|
+
async function extractPackageAtCommit(repoPath, commit, packagePath, destDir) {
|
|
4381
|
+
log.debug(`Extracting ${packagePath} at ${commit.slice(0, 12)} \u2192 ${destDir}`);
|
|
338
4382
|
await mkdir2(destDir, { recursive: true });
|
|
339
|
-
const commit = await resolveTag(repoPath, tag);
|
|
340
4383
|
const stripCount = packagePath.split("/").length;
|
|
341
4384
|
return new Promise((resolve2, reject) => {
|
|
342
4385
|
const gitProc = spawn(
|
|
@@ -366,20 +4409,114 @@ async function extractPackageSimple(repoPath, tag, packagePath, destDir) {
|
|
|
366
4409
|
});
|
|
367
4410
|
});
|
|
368
4411
|
}
|
|
369
|
-
async function
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
4412
|
+
async function ensureWorkingCopy(owner, repo) {
|
|
4413
|
+
const dir = getWorkingCopyDir(owner, repo);
|
|
4414
|
+
if (existsSync3(join3(dir, ".git"))) {
|
|
4415
|
+
log.debug(`Working copy hit: ${dir}`);
|
|
4416
|
+
await git(["fetch", "origin"], dir);
|
|
4417
|
+
await git(["reset", "--hard", "origin/main"], dir);
|
|
4418
|
+
await git(["clean", "-fd"], dir);
|
|
4419
|
+
return dir;
|
|
4420
|
+
}
|
|
4421
|
+
const parent = join3(dir, "..");
|
|
4422
|
+
await mkdir2(parent, { recursive: true });
|
|
4423
|
+
const url = repoUrl(owner, repo);
|
|
4424
|
+
log.step(`Cloning working copy: ${url}`);
|
|
4425
|
+
await git(["clone", url, dir]);
|
|
4426
|
+
await git(["config", "user.email", "agent-pkg@automated"], dir);
|
|
4427
|
+
await git(["config", "user.name", "agent-pkg"], dir);
|
|
4428
|
+
return dir;
|
|
374
4429
|
}
|
|
375
|
-
async function
|
|
4430
|
+
async function commitAll(cwd2, message) {
|
|
4431
|
+
await git(["add", "-A"], cwd2);
|
|
4432
|
+
const status = await git(["status", "--porcelain"], cwd2);
|
|
4433
|
+
if (!status) {
|
|
4434
|
+
throw new Error("Nothing to commit \u2014 no changes detected");
|
|
4435
|
+
}
|
|
4436
|
+
await git(["commit", "-m", message], cwd2);
|
|
376
4437
|
return git(["rev-parse", "HEAD"], cwd2);
|
|
377
4438
|
}
|
|
4439
|
+
async function pushBranch(cwd2, remote = "origin", branch = "main") {
|
|
4440
|
+
await git(["push", remote, branch], cwd2);
|
|
4441
|
+
}
|
|
4442
|
+
|
|
4443
|
+
// src/lib/registry.ts
|
|
4444
|
+
import { readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
|
|
4445
|
+
import { join as join4 } from "path";
|
|
4446
|
+
function createEmptyManifest(name) {
|
|
4447
|
+
return {
|
|
4448
|
+
schemaVersion: 1,
|
|
4449
|
+
name,
|
|
4450
|
+
packages: {}
|
|
4451
|
+
};
|
|
4452
|
+
}
|
|
4453
|
+
async function readManifestFromRepo(repoPath) {
|
|
4454
|
+
try {
|
|
4455
|
+
const content = await readFileFromRepo(repoPath, REGISTRY_MANIFEST_FILE);
|
|
4456
|
+
return JSON.parse(content);
|
|
4457
|
+
} catch {
|
|
4458
|
+
throw new Error(
|
|
4459
|
+
`Registry manifest (${REGISTRY_MANIFEST_FILE}) not found. The registry repository must contain an ${REGISTRY_MANIFEST_FILE} at its root.`
|
|
4460
|
+
);
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
async function readManifestFromDir(dir) {
|
|
4464
|
+
const path = join4(dir, REGISTRY_MANIFEST_FILE);
|
|
4465
|
+
const content = await readFile2(path, "utf8");
|
|
4466
|
+
return JSON.parse(content);
|
|
4467
|
+
}
|
|
4468
|
+
async function writeManifestToDir(dir, manifest) {
|
|
4469
|
+
const path = join4(dir, REGISTRY_MANIFEST_FILE);
|
|
4470
|
+
await writeFile3(path, JSON.stringify(manifest, null, 2) + "\n", "utf8");
|
|
4471
|
+
}
|
|
4472
|
+
function resolveVersionFromManifest(manifest, packageName, version) {
|
|
4473
|
+
const pkg = manifest.packages[packageName];
|
|
4474
|
+
if (!pkg) {
|
|
4475
|
+
const available = Object.keys(manifest.packages);
|
|
4476
|
+
throw new Error(
|
|
4477
|
+
`Package "${packageName}" not found in registry manifest. Available: ${available.join(", ") || "(none)"}`
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
4480
|
+
const ver = pkg.versions[version];
|
|
4481
|
+
if (!ver) {
|
|
4482
|
+
const available = Object.keys(pkg.versions);
|
|
4483
|
+
throw new Error(
|
|
4484
|
+
`Version "${version}" not found for package "${packageName}". Available: ${available.join(", ") || "(none)"}`
|
|
4485
|
+
);
|
|
4486
|
+
}
|
|
4487
|
+
return { commit: ver.commit, contentHash: ver.contentHash, path: pkg.path };
|
|
4488
|
+
}
|
|
4489
|
+
function listVersionsFromManifest(manifest, packageName) {
|
|
4490
|
+
const pkg = manifest.packages[packageName];
|
|
4491
|
+
if (!pkg) return [];
|
|
4492
|
+
return Object.keys(pkg.versions);
|
|
4493
|
+
}
|
|
4494
|
+
function addVersionToManifest(manifest, packageName, packagePath, version, commit, contentHash, description) {
|
|
4495
|
+
if (!manifest.packages[packageName]) {
|
|
4496
|
+
manifest.packages[packageName] = {
|
|
4497
|
+
path: packagePath,
|
|
4498
|
+
description,
|
|
4499
|
+
versions: {}
|
|
4500
|
+
};
|
|
4501
|
+
}
|
|
4502
|
+
const pkg = manifest.packages[packageName];
|
|
4503
|
+
if (pkg.versions[version]) {
|
|
4504
|
+
throw new Error(
|
|
4505
|
+
`Version "${version}" already exists for package "${packageName}". Bump the version before publishing.`
|
|
4506
|
+
);
|
|
4507
|
+
}
|
|
4508
|
+
pkg.versions[version] = {
|
|
4509
|
+
commit,
|
|
4510
|
+
contentHash,
|
|
4511
|
+
publishedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4512
|
+
};
|
|
4513
|
+
log.debug(`Registered ${packageName}@${version} in manifest`);
|
|
4514
|
+
}
|
|
378
4515
|
|
|
379
4516
|
// src/lib/hash.ts
|
|
380
4517
|
import { createHash } from "crypto";
|
|
381
|
-
import { readFile as
|
|
382
|
-
import { join as
|
|
4518
|
+
import { readFile as readFile3, readdir } from "fs/promises";
|
|
4519
|
+
import { join as join5, relative } from "path";
|
|
383
4520
|
async function hashDirectory(dirPath) {
|
|
384
4521
|
const files = await collectFiles(dirPath);
|
|
385
4522
|
files.sort();
|
|
@@ -387,7 +4524,7 @@ async function hashDirectory(dirPath) {
|
|
|
387
4524
|
for (const file of files) {
|
|
388
4525
|
const rel = relative(dirPath, file);
|
|
389
4526
|
hash.update(rel);
|
|
390
|
-
const content = await
|
|
4527
|
+
const content = await readFile3(file);
|
|
391
4528
|
hash.update(content);
|
|
392
4529
|
}
|
|
393
4530
|
return `sha256:${hash.digest("hex")}`;
|
|
@@ -396,7 +4533,7 @@ async function collectFiles(dir) {
|
|
|
396
4533
|
const results = [];
|
|
397
4534
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
398
4535
|
for (const entry of entries) {
|
|
399
|
-
const full =
|
|
4536
|
+
const full = join5(dir, entry.name);
|
|
400
4537
|
if (entry.isDirectory()) {
|
|
401
4538
|
results.push(...await collectFiles(full));
|
|
402
4539
|
} else if (entry.isFile()) {
|
|
@@ -418,10 +4555,8 @@ async function runAdd(input, projectDir) {
|
|
|
418
4555
|
}
|
|
419
4556
|
const packageName = input.alias || spec.name;
|
|
420
4557
|
let registry;
|
|
421
|
-
let packagePath;
|
|
422
4558
|
if (spec.owner && spec.repo) {
|
|
423
4559
|
registry = { type: "github", owner: spec.owner, repo: spec.repo };
|
|
424
|
-
packagePath = spec.path || `packages/${spec.name}`;
|
|
425
4560
|
} else {
|
|
426
4561
|
const registryName2 = input.registry || "default";
|
|
427
4562
|
registry = config.registries[registryName2];
|
|
@@ -430,29 +4565,33 @@ async function runAdd(input, projectDir) {
|
|
|
430
4565
|
`Registry "${registryName2}" not found. Available: ${Object.keys(config.registries).join(", ") || "(none \u2014 run init with --registry)"}`
|
|
431
4566
|
);
|
|
432
4567
|
}
|
|
433
|
-
const root = registry.packageRoot || "packages";
|
|
434
|
-
packagePath = `${root}/${spec.name}`;
|
|
435
4568
|
}
|
|
436
|
-
|
|
437
|
-
const tag = buildTag(spec.name, spec.version, tagFormat);
|
|
438
|
-
log.step(`Resolving ${spec.name}@${spec.version} (tag: ${tag})`);
|
|
4569
|
+
log.step(`Resolving ${spec.name}@${spec.version} from manifest`);
|
|
439
4570
|
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
440
|
-
const
|
|
441
|
-
|
|
4571
|
+
const manifest = await readManifestFromRepo(repoDir);
|
|
4572
|
+
const resolved = resolveVersionFromManifest(manifest, spec.name, spec.version);
|
|
4573
|
+
log.step(`Resolved commit: ${resolved.commit.slice(0, 12)}`);
|
|
442
4574
|
const modulesDir = config.install.modulesDir;
|
|
443
|
-
const installDir =
|
|
4575
|
+
const installDir = join6(projectDir, modulesDir, packageName);
|
|
444
4576
|
if (existsSync4(installDir)) {
|
|
445
4577
|
await rm(installDir, { recursive: true, force: true });
|
|
446
4578
|
}
|
|
447
4579
|
await mkdir3(installDir, { recursive: true });
|
|
448
|
-
log.step(`Extracting ${
|
|
449
|
-
await
|
|
4580
|
+
log.step(`Extracting ${resolved.path} \u2192 ${modulesDir}/${packageName}`);
|
|
4581
|
+
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
|
|
450
4582
|
const contentHash = await hashDirectory(installDir);
|
|
451
4583
|
log.debug(`Content hash: ${contentHash}`);
|
|
4584
|
+
if (contentHash !== resolved.contentHash) {
|
|
4585
|
+
log.warn(
|
|
4586
|
+
`Content hash mismatch: manifest=${resolved.contentHash}, extracted=${contentHash}. The registry manifest may be stale.`
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4589
|
+
const pkgManifest = await readPackageManifest(installDir);
|
|
4590
|
+
const entrypoint = pkgManifest?.entrypoint ?? DEFAULT_ENTRYPOINT;
|
|
452
4591
|
const registryName = input.registry || "default";
|
|
453
4592
|
config.packages[packageName] = {
|
|
454
4593
|
registry: registryName,
|
|
455
|
-
path:
|
|
4594
|
+
path: resolved.path,
|
|
456
4595
|
version: spec.version
|
|
457
4596
|
};
|
|
458
4597
|
if (!config.registries[registryName]) {
|
|
@@ -465,7 +4604,7 @@ async function runAdd(input, projectDir) {
|
|
|
465
4604
|
};
|
|
466
4605
|
}
|
|
467
4606
|
await writeProjectConfig(projectDir, config);
|
|
468
|
-
log.success(`Updated
|
|
4607
|
+
log.success(`Updated config with ${packageName}@${spec.version}`);
|
|
469
4608
|
let lock;
|
|
470
4609
|
try {
|
|
471
4610
|
lock = await readLockFile(projectDir);
|
|
@@ -486,33 +4625,32 @@ async function runAdd(input, projectDir) {
|
|
|
486
4625
|
};
|
|
487
4626
|
lock.packages[packageName] = {
|
|
488
4627
|
registry: registryName,
|
|
489
|
-
path:
|
|
4628
|
+
path: resolved.path,
|
|
490
4629
|
version: spec.version,
|
|
491
|
-
tag
|
|
492
|
-
commit,
|
|
4630
|
+
tag: `${spec.name}/v${spec.version}`,
|
|
4631
|
+
commit: resolved.commit,
|
|
493
4632
|
contentHash,
|
|
494
4633
|
installedTo: `${modulesDir}/${packageName}`,
|
|
495
|
-
entrypoint: `${modulesDir}/${packageName}
|
|
4634
|
+
entrypoint: `${modulesDir}/${packageName}/${entrypoint}`
|
|
496
4635
|
};
|
|
497
4636
|
await writeLockFile(projectDir, lock);
|
|
498
4637
|
log.success("Updated lock file");
|
|
499
|
-
await updateExtendsInYaml(projectDir, modulesDir, packageName);
|
|
4638
|
+
await updateExtendsInYaml(projectDir, modulesDir, packageName, entrypoint);
|
|
500
4639
|
const result = {
|
|
501
4640
|
package: packageName,
|
|
502
4641
|
version: spec.version,
|
|
503
|
-
|
|
504
|
-
commit,
|
|
4642
|
+
commit: resolved.commit,
|
|
505
4643
|
installedTo: `${modulesDir}/${packageName}`,
|
|
506
4644
|
materialized: false
|
|
507
4645
|
};
|
|
508
4646
|
log.success(`Added ${packageName}@${spec.version}`);
|
|
509
4647
|
console.log(JSON.stringify(result, null, 2));
|
|
510
4648
|
}
|
|
511
|
-
async function updateExtendsInYaml(projectDir, modulesDir, packageName) {
|
|
512
|
-
const yamlPath =
|
|
4649
|
+
async function updateExtendsInYaml(projectDir, modulesDir, packageName, entrypoint) {
|
|
4650
|
+
const yamlPath = join6(projectDir, "agent-contracts.yaml");
|
|
513
4651
|
if (!existsSync4(yamlPath)) return;
|
|
514
|
-
const content = await
|
|
515
|
-
const extendEntry = `./${modulesDir}/${packageName}
|
|
4652
|
+
const content = await readFile4(yamlPath, "utf8");
|
|
4653
|
+
const extendEntry = `./${modulesDir}/${packageName}/${entrypoint}`;
|
|
516
4654
|
if (content.includes(extendEntry)) return;
|
|
517
4655
|
const { parse, stringify } = await import("yaml");
|
|
518
4656
|
const doc = parse(content);
|
|
@@ -520,14 +4658,14 @@ async function updateExtendsInYaml(projectDir, modulesDir, packageName) {
|
|
|
520
4658
|
if (Array.isArray(doc.extends) && !doc.extends.includes(extendEntry)) {
|
|
521
4659
|
doc.extends.push(extendEntry);
|
|
522
4660
|
}
|
|
523
|
-
await
|
|
4661
|
+
await writeFile4(yamlPath, stringify(doc, { lineWidth: 0 }), "utf8");
|
|
524
4662
|
log.success(`Added extends entry: ${extendEntry}`);
|
|
525
4663
|
}
|
|
526
4664
|
|
|
527
4665
|
// src/lib/commands/sync.ts
|
|
528
4666
|
import { existsSync as existsSync5 } from "fs";
|
|
529
4667
|
import { mkdir as mkdir4, rm as rm2 } from "fs/promises";
|
|
530
|
-
import { join as
|
|
4668
|
+
import { join as join7 } from "path";
|
|
531
4669
|
async function runSync(input, projectDir) {
|
|
532
4670
|
const config = await readProjectConfig(projectDir);
|
|
533
4671
|
const lock = await readLockFile(projectDir);
|
|
@@ -538,7 +4676,7 @@ async function runSync(input, projectDir) {
|
|
|
538
4676
|
if (!regEntry) {
|
|
539
4677
|
throw new Error(`Registry "${entry.registry}" referenced by package "${name}" not found in lock file`);
|
|
540
4678
|
}
|
|
541
|
-
const installDir =
|
|
4679
|
+
const installDir = join7(projectDir, entry.installedTo);
|
|
542
4680
|
let currentHash = null;
|
|
543
4681
|
if (existsSync5(installDir)) {
|
|
544
4682
|
currentHash = await hashDirectory(installDir);
|
|
@@ -561,7 +4699,7 @@ async function runSync(input, projectDir) {
|
|
|
561
4699
|
await rm2(installDir, { recursive: true, force: true });
|
|
562
4700
|
}
|
|
563
4701
|
await mkdir4(installDir, { recursive: true });
|
|
564
|
-
await
|
|
4702
|
+
await extractPackageAtCommit(repoDir, entry.commit, entry.path, installDir);
|
|
565
4703
|
const newHash = await hashDirectory(installDir);
|
|
566
4704
|
if (newHash !== entry.contentHash) {
|
|
567
4705
|
log.warn(`${name}: restored hash ${newHash} differs from lock ${entry.contentHash}`);
|
|
@@ -586,7 +4724,7 @@ async function runSync(input, projectDir) {
|
|
|
586
4724
|
// src/lib/commands/update.ts
|
|
587
4725
|
import { existsSync as existsSync6 } from "fs";
|
|
588
4726
|
import { mkdir as mkdir5, rm as rm3 } from "fs/promises";
|
|
589
|
-
import { join as
|
|
4727
|
+
import { join as join8 } from "path";
|
|
590
4728
|
async function runUpdate(input, projectDir) {
|
|
591
4729
|
const config = await readProjectConfig(projectDir);
|
|
592
4730
|
const lock = await readLockFile(projectDir);
|
|
@@ -612,8 +4750,9 @@ async function runUpdate(input, projectDir) {
|
|
|
612
4750
|
continue;
|
|
613
4751
|
}
|
|
614
4752
|
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
615
|
-
const
|
|
616
|
-
const
|
|
4753
|
+
const manifest = await readManifestFromRepo(repoDir);
|
|
4754
|
+
const versionStrings = listVersionsFromManifest(manifest, name);
|
|
4755
|
+
const versions = versionStrings.map((v) => ({ raw: v, parts: parseSemver(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemver(a.parts, b.parts));
|
|
617
4756
|
const currentParts = parseSemver(pkg.version);
|
|
618
4757
|
if (!currentParts) {
|
|
619
4758
|
log.warn(`Cannot parse current version "${pkg.version}" for ${name}`);
|
|
@@ -664,21 +4803,21 @@ async function runUpdate(input, projectDir) {
|
|
|
664
4803
|
const registryName = pkg.registry || "default";
|
|
665
4804
|
const registry = config.registries[registryName];
|
|
666
4805
|
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
const installDir =
|
|
4806
|
+
const manifest = await readManifestFromRepo(repoDir);
|
|
4807
|
+
const resolved = resolveVersionFromManifest(manifest, u.package, u.toVersion);
|
|
4808
|
+
const installDir = join8(projectDir, config.install.modulesDir, u.package);
|
|
670
4809
|
if (existsSync6(installDir)) {
|
|
671
4810
|
await rm3(installDir, { recursive: true, force: true });
|
|
672
4811
|
}
|
|
673
4812
|
await mkdir5(installDir, { recursive: true });
|
|
674
|
-
await
|
|
4813
|
+
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
|
|
675
4814
|
const contentHash = await hashDirectory(installDir);
|
|
676
4815
|
config.packages[u.package].version = u.toVersion;
|
|
677
4816
|
lock.packages[u.package] = {
|
|
678
4817
|
...lock.packages[u.package],
|
|
679
4818
|
version: u.toVersion,
|
|
680
|
-
tag
|
|
681
|
-
commit,
|
|
4819
|
+
tag: `${u.package}/v${u.toVersion}`,
|
|
4820
|
+
commit: resolved.commit,
|
|
682
4821
|
contentHash
|
|
683
4822
|
};
|
|
684
4823
|
log.success(`Updated ${u.package} to ${u.toVersion}`);
|
|
@@ -701,8 +4840,8 @@ function compareSemver(a, b) {
|
|
|
701
4840
|
|
|
702
4841
|
// src/lib/commands/diff.ts
|
|
703
4842
|
import { existsSync as existsSync7 } from "fs";
|
|
704
|
-
import { readFile as
|
|
705
|
-
import { join as
|
|
4843
|
+
import { readFile as readFile5, mkdtemp, rm as rm4 } from "fs/promises";
|
|
4844
|
+
import { join as join9 } from "path";
|
|
706
4845
|
import { tmpdir } from "os";
|
|
707
4846
|
async function runDiff(input, projectDir) {
|
|
708
4847
|
const config = await readProjectConfig(projectDir);
|
|
@@ -715,33 +4854,34 @@ async function runDiff(input, projectDir) {
|
|
|
715
4854
|
const pkg = config.packages[name];
|
|
716
4855
|
const registry = resolveRegistryForPackage(config, name);
|
|
717
4856
|
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
4857
|
+
const manifest = await readManifestFromRepo(repoDir);
|
|
718
4858
|
let targetVersion;
|
|
719
4859
|
if (spec.version) {
|
|
720
4860
|
targetVersion = spec.version;
|
|
721
4861
|
} else {
|
|
722
|
-
const
|
|
723
|
-
const versions = tags.map((t) => parseTagVersion(t, name)).filter((v) => v !== null);
|
|
4862
|
+
const versions = listVersionsFromManifest(manifest, name);
|
|
724
4863
|
if (versions.length === 0) {
|
|
725
|
-
throw new Error(`No versions found for ${name}`);
|
|
4864
|
+
throw new Error(`No versions found for ${name} in registry manifest`);
|
|
726
4865
|
}
|
|
727
|
-
|
|
4866
|
+
const sorted = versions.map((v) => ({ raw: v, parts: parseSemverSimple(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemverSimple(a.parts, b.parts));
|
|
4867
|
+
targetVersion = sorted[sorted.length - 1].raw;
|
|
728
4868
|
}
|
|
729
4869
|
if (targetVersion === pkg.version) {
|
|
730
4870
|
log.info(`${name} is already at ${targetVersion}`);
|
|
731
4871
|
return;
|
|
732
4872
|
}
|
|
733
4873
|
log.step(`Comparing ${name} ${pkg.version} \u2192 ${targetVersion}`);
|
|
734
|
-
const
|
|
735
|
-
const tmpDir = await mkdtemp(
|
|
4874
|
+
const resolved = resolveVersionFromManifest(manifest, name, targetVersion);
|
|
4875
|
+
const tmpDir = await mkdtemp(join9(tmpdir(), "agent-pkg-diff-"));
|
|
736
4876
|
try {
|
|
737
|
-
const targetDir =
|
|
738
|
-
await
|
|
739
|
-
const currentDir =
|
|
4877
|
+
const targetDir = join9(tmpDir, "target");
|
|
4878
|
+
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
|
|
4879
|
+
const currentDir = join9(projectDir, config.install.modulesDir, name);
|
|
740
4880
|
if (!existsSync7(currentDir)) {
|
|
741
4881
|
throw new Error(`Current package not installed at ${currentDir}. Run sync first.`);
|
|
742
4882
|
}
|
|
743
|
-
const currentDsl = await loadYamlSafe(
|
|
744
|
-
const targetDsl = await loadYamlSafe(
|
|
4883
|
+
const currentDsl = await loadYamlSafe(join9(currentDir, "agent-contracts.yaml"));
|
|
4884
|
+
const targetDsl = await loadYamlSafe(join9(targetDir, "agent-contracts.yaml"));
|
|
745
4885
|
const changes = computeDslDiff(currentDsl, targetDsl);
|
|
746
4886
|
if (input.format === "json") {
|
|
747
4887
|
console.log(JSON.stringify({
|
|
@@ -813,37 +4953,47 @@ function printTextDiff(name, fromVersion, toVersion, changes) {
|
|
|
813
4953
|
async function loadYamlSafe(path) {
|
|
814
4954
|
if (!existsSync7(path)) return null;
|
|
815
4955
|
const { parse } = await import("yaml");
|
|
816
|
-
const content = await
|
|
4956
|
+
const content = await readFile5(path, "utf8");
|
|
817
4957
|
return parse(content) || {};
|
|
818
4958
|
}
|
|
4959
|
+
function parseSemverSimple(v) {
|
|
4960
|
+
const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
4961
|
+
if (!m) return null;
|
|
4962
|
+
return [+m[1], +m[2], +m[3]];
|
|
4963
|
+
}
|
|
4964
|
+
function compareSemverSimple(a, b) {
|
|
4965
|
+
if (a[0] !== b[0]) return a[0] - b[0];
|
|
4966
|
+
if (a[1] !== b[1]) return a[1] - b[1];
|
|
4967
|
+
return a[2] - b[2];
|
|
4968
|
+
}
|
|
819
4969
|
|
|
820
4970
|
// src/lib/commands/materialize.ts
|
|
821
4971
|
import { existsSync as existsSync8 } from "fs";
|
|
822
|
-
import { mkdir as mkdir6, rm as rm5, readFile as
|
|
823
|
-
import { join as
|
|
4972
|
+
import { mkdir as mkdir6, rm as rm5, readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
|
|
4973
|
+
import { join as join10 } from "path";
|
|
824
4974
|
import { execFile } from "child_process";
|
|
825
4975
|
async function runMaterialize(input, projectDir) {
|
|
826
4976
|
const config = await readProjectConfig(projectDir);
|
|
827
|
-
const buildDir =
|
|
4977
|
+
const buildDir = join10(projectDir, config.install.buildDir);
|
|
828
4978
|
if (input.clean && existsSync8(buildDir)) {
|
|
829
4979
|
await rm5(buildDir, { recursive: true, force: true });
|
|
830
4980
|
log.step("Cleaned build directory");
|
|
831
4981
|
}
|
|
832
4982
|
await mkdir6(buildDir, { recursive: true });
|
|
833
4983
|
log.step("Resolving agent-contracts.yaml");
|
|
834
|
-
const yamlPath =
|
|
4984
|
+
const yamlPath = join10(projectDir, "agent-contracts.yaml");
|
|
835
4985
|
if (!existsSync8(yamlPath)) {
|
|
836
4986
|
throw new Error("agent-contracts.yaml not found in project root");
|
|
837
4987
|
}
|
|
838
4988
|
const { parse, stringify } = await import("yaml");
|
|
839
|
-
const rootDoc = parse(await
|
|
4989
|
+
const rootDoc = parse(await readFile6(yamlPath, "utf8"));
|
|
840
4990
|
const resolved = await resolveExtends(rootDoc, projectDir);
|
|
841
4991
|
if (config.vars) {
|
|
842
4992
|
resolved.vars = { ...resolved.vars || {}, ...config.vars };
|
|
843
4993
|
}
|
|
844
4994
|
const resolvedYaml = stringify(resolved, { lineWidth: 0 });
|
|
845
|
-
const resolvedPath =
|
|
846
|
-
await
|
|
4995
|
+
const resolvedPath = join10(buildDir, "resolved.agent-contracts.yaml");
|
|
4996
|
+
await writeFile5(resolvedPath, resolvedYaml, "utf8");
|
|
847
4997
|
log.success(`Wrote ${resolvedPath}`);
|
|
848
4998
|
const resolvedHash = hashString(resolvedYaml);
|
|
849
4999
|
let validated = false;
|
|
@@ -864,7 +5014,7 @@ async function runMaterialize(input, projectDir) {
|
|
|
864
5014
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
865
5015
|
packages: Object.keys(config.packages)
|
|
866
5016
|
};
|
|
867
|
-
await
|
|
5017
|
+
await writeFile5(join10(buildDir, "package-manifest.json"), JSON.stringify(buildManifest, null, 2) + "\n", "utf8");
|
|
868
5018
|
const result = {
|
|
869
5019
|
resolvedDslPath: resolvedPath,
|
|
870
5020
|
resolvedDslHash: resolvedHash,
|
|
@@ -881,12 +5031,12 @@ async function resolveExtends(doc, baseDir) {
|
|
|
881
5031
|
const { parse } = await import("yaml");
|
|
882
5032
|
let merged = {};
|
|
883
5033
|
for (const ext of extends_) {
|
|
884
|
-
const extPath =
|
|
5034
|
+
const extPath = join10(baseDir, ext);
|
|
885
5035
|
if (!existsSync8(extPath)) {
|
|
886
5036
|
log.warn(`Extended file not found: ${extPath}`);
|
|
887
5037
|
continue;
|
|
888
5038
|
}
|
|
889
|
-
const extContent = await
|
|
5039
|
+
const extContent = await readFile6(extPath, "utf8");
|
|
890
5040
|
const extDoc = parse(extContent);
|
|
891
5041
|
if (extDoc) {
|
|
892
5042
|
merged = deepMerge(merged, extDoc);
|
|
@@ -897,12 +5047,12 @@ async function resolveExtends(doc, baseDir) {
|
|
|
897
5047
|
const refs = doc["$refs"];
|
|
898
5048
|
if (refs) {
|
|
899
5049
|
for (const ref of refs) {
|
|
900
|
-
const refPath =
|
|
5050
|
+
const refPath = join10(baseDir, ref);
|
|
901
5051
|
if (!existsSync8(refPath)) {
|
|
902
5052
|
log.warn(`Override file not found: ${refPath}`);
|
|
903
5053
|
continue;
|
|
904
5054
|
}
|
|
905
|
-
const refContent = await
|
|
5055
|
+
const refContent = await readFile6(refPath, "utf8");
|
|
906
5056
|
const refDoc = parse(refContent);
|
|
907
5057
|
if (refDoc) {
|
|
908
5058
|
merged = deepMerge(merged, refDoc);
|
|
@@ -946,7 +5096,7 @@ function runExternalTool(cmd, args, cwd2) {
|
|
|
946
5096
|
|
|
947
5097
|
// src/lib/commands/check.ts
|
|
948
5098
|
import { existsSync as existsSync9 } from "fs";
|
|
949
|
-
import { join as
|
|
5099
|
+
import { join as join11 } from "path";
|
|
950
5100
|
async function runCheck(projectDir) {
|
|
951
5101
|
const checks = [];
|
|
952
5102
|
checks.push(await checkConfigSchema(projectDir));
|
|
@@ -1030,7 +5180,7 @@ async function checkContentHashes(projectDir) {
|
|
|
1030
5180
|
try {
|
|
1031
5181
|
const lock = await readLockFile(projectDir);
|
|
1032
5182
|
for (const [name, entry] of Object.entries(lock.packages)) {
|
|
1033
|
-
const installDir =
|
|
5183
|
+
const installDir = join11(projectDir, entry.installedTo);
|
|
1034
5184
|
if (!existsSync9(installDir)) {
|
|
1035
5185
|
items.push({
|
|
1036
5186
|
name: `content_hash:${name}`,
|
|
@@ -1058,14 +5208,16 @@ async function checkContentHashes(projectDir) {
|
|
|
1058
5208
|
|
|
1059
5209
|
// src/lib/commands/publish.ts
|
|
1060
5210
|
import { existsSync as existsSync10 } from "fs";
|
|
1061
|
-
import {
|
|
5211
|
+
import { cp } from "fs/promises";
|
|
5212
|
+
import { join as join12, resolve, basename } from "path";
|
|
1062
5213
|
async function runPublish(input, projectDir) {
|
|
1063
|
-
const
|
|
1064
|
-
if (!existsSync10(
|
|
1065
|
-
throw new Error(`
|
|
5214
|
+
const sourceDir = resolve(projectDir, input.path);
|
|
5215
|
+
if (!existsSync10(sourceDir)) {
|
|
5216
|
+
throw new Error(`Source directory not found: ${input.path}`);
|
|
1066
5217
|
}
|
|
1067
|
-
const pkgJson = await readPackageJson(
|
|
1068
|
-
const manifest = await readPackageManifest(
|
|
5218
|
+
const pkgJson = await readPackageJson(sourceDir);
|
|
5219
|
+
const manifest = await readPackageManifest(sourceDir);
|
|
5220
|
+
const packageName = input.name || manifest?.id || pkgJson?.name?.split("/").pop() || basename(sourceDir);
|
|
1069
5221
|
const pkgJsonVersion = pkgJson?.version;
|
|
1070
5222
|
const manifestVersion = manifest?.version;
|
|
1071
5223
|
let version;
|
|
@@ -1076,63 +5228,108 @@ async function runPublish(input, projectDir) {
|
|
|
1076
5228
|
} else if (pkgJsonVersion) {
|
|
1077
5229
|
version = pkgJsonVersion;
|
|
1078
5230
|
} else {
|
|
1079
|
-
throw new Error(
|
|
5231
|
+
throw new Error(
|
|
5232
|
+
"Cannot determine version. Specify --version or set version in package.json / " + PACKAGE_MANIFEST_FILE
|
|
5233
|
+
);
|
|
1080
5234
|
}
|
|
1081
5235
|
if (pkgJsonVersion && manifestVersion && pkgJsonVersion !== manifestVersion) {
|
|
1082
5236
|
throw new Error(
|
|
1083
5237
|
`Version mismatch: package.json=${pkgJsonVersion}, ${PACKAGE_MANIFEST_FILE}=${manifestVersion}`
|
|
1084
5238
|
);
|
|
1085
5239
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
};
|
|
1104
|
-
log.info("Dry run \u2014 no changes made");
|
|
1105
|
-
console.log(JSON.stringify(result2, null, 2));
|
|
1106
|
-
return;
|
|
5240
|
+
let owner;
|
|
5241
|
+
let repo;
|
|
5242
|
+
if (input.registry) {
|
|
5243
|
+
({ owner, repo } = parseRegistrySpec(input.registry));
|
|
5244
|
+
} else {
|
|
5245
|
+
try {
|
|
5246
|
+
const config = await readProjectConfig(projectDir);
|
|
5247
|
+
const defaultReg = config.registries["default"];
|
|
5248
|
+
if (!defaultReg) {
|
|
5249
|
+
throw new Error("No default registry");
|
|
5250
|
+
}
|
|
5251
|
+
owner = defaultReg.owner;
|
|
5252
|
+
repo = defaultReg.repo;
|
|
5253
|
+
} catch {
|
|
5254
|
+
throw new Error(
|
|
5255
|
+
"Cannot determine target registry. Use --registry github:<owner>/<repo> or run from a project with agent-pkg.json that has a default registry."
|
|
5256
|
+
);
|
|
1107
5257
|
}
|
|
1108
5258
|
}
|
|
1109
|
-
const
|
|
5259
|
+
const description = manifest?.description || pkgJson?.description;
|
|
5260
|
+
const contentHash = await hashDirectory(sourceDir);
|
|
5261
|
+
log.step(`Publishing ${packageName}@${version} \u2192 github:${owner}/${repo}`);
|
|
5262
|
+
log.debug(`Source: ${sourceDir}`);
|
|
5263
|
+
log.debug(`Content hash: ${contentHash}`);
|
|
1110
5264
|
if (input.dryRun) {
|
|
1111
5265
|
const result2 = {
|
|
1112
5266
|
package: packageName,
|
|
1113
5267
|
version,
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
pushed: false
|
|
5268
|
+
registry: `github:${owner}/${repo}`,
|
|
5269
|
+
contentHash,
|
|
5270
|
+
pushed: false,
|
|
5271
|
+
dryRun: true
|
|
1117
5272
|
};
|
|
1118
5273
|
log.info("Dry run \u2014 no changes made");
|
|
1119
5274
|
console.log(JSON.stringify(result2, null, 2));
|
|
1120
5275
|
return;
|
|
1121
5276
|
}
|
|
1122
|
-
await
|
|
1123
|
-
|
|
5277
|
+
const workDir = await ensureWorkingCopy(owner, repo);
|
|
5278
|
+
let registryManifest;
|
|
5279
|
+
try {
|
|
5280
|
+
registryManifest = await readManifestFromDir(workDir);
|
|
5281
|
+
} catch {
|
|
5282
|
+
registryManifest = createEmptyManifest(`${owner}/${repo}`);
|
|
5283
|
+
}
|
|
5284
|
+
const existing = registryManifest.packages[packageName]?.versions[version];
|
|
5285
|
+
if (existing) {
|
|
5286
|
+
throw new Error(
|
|
5287
|
+
`Version "${version}" already exists for package "${packageName}". Bump the version before publishing.`
|
|
5288
|
+
);
|
|
5289
|
+
}
|
|
5290
|
+
const packageRoot = "packages";
|
|
5291
|
+
const packagePath = `${packageRoot}/${packageName}`;
|
|
5292
|
+
const destDir = join12(workDir, packagePath);
|
|
5293
|
+
await cp(sourceDir, destDir, {
|
|
5294
|
+
recursive: true,
|
|
5295
|
+
filter: (src) => {
|
|
5296
|
+
const name = basename(src);
|
|
5297
|
+
return name !== ".git" && name !== "node_modules" && name !== ".DS_Store";
|
|
5298
|
+
}
|
|
5299
|
+
});
|
|
5300
|
+
log.success(`Copied package files \u2192 ${packagePath}/`);
|
|
5301
|
+
const packageCommit = await commitAll(
|
|
5302
|
+
workDir,
|
|
5303
|
+
`Publish ${packageName}@${version}`
|
|
5304
|
+
);
|
|
5305
|
+
log.success(`Committed package files: ${packageCommit.slice(0, 12)}`);
|
|
5306
|
+
addVersionToManifest(
|
|
5307
|
+
registryManifest,
|
|
5308
|
+
packageName,
|
|
5309
|
+
packagePath,
|
|
5310
|
+
version,
|
|
5311
|
+
packageCommit,
|
|
5312
|
+
contentHash,
|
|
5313
|
+
description
|
|
5314
|
+
);
|
|
5315
|
+
await writeManifestToDir(workDir, registryManifest);
|
|
5316
|
+
log.success(`Updated ${REGISTRY_MANIFEST_FILE}`);
|
|
5317
|
+
const manifestCommit = await commitAll(
|
|
5318
|
+
workDir,
|
|
5319
|
+
`Register ${packageName}@${version} in manifest`
|
|
5320
|
+
);
|
|
5321
|
+
log.debug(`Manifest commit: ${manifestCommit.slice(0, 12)}`);
|
|
1124
5322
|
let pushed = false;
|
|
1125
5323
|
if (!input.noPush) {
|
|
1126
|
-
await
|
|
5324
|
+
await pushBranch(workDir);
|
|
1127
5325
|
pushed = true;
|
|
1128
|
-
log.success(
|
|
5326
|
+
log.success("Pushed to remote");
|
|
1129
5327
|
}
|
|
1130
|
-
const contentHash = await hashDirectory(packageDir);
|
|
1131
5328
|
const result = {
|
|
1132
5329
|
package: packageName,
|
|
1133
5330
|
version,
|
|
1134
|
-
|
|
1135
|
-
commit,
|
|
5331
|
+
registry: `github:${owner}/${repo}`,
|
|
5332
|
+
commit: packageCommit,
|
|
1136
5333
|
contentHash,
|
|
1137
5334
|
pushed
|
|
1138
5335
|
};
|
|
@@ -1161,11 +5358,12 @@ var handlers = {
|
|
|
1161
5358
|
console.error("\u2717 Package specifier is required. Usage: agent-pkg add <name>@<version>");
|
|
1162
5359
|
process.exit(1);
|
|
1163
5360
|
}
|
|
5361
|
+
const o = opts;
|
|
1164
5362
|
await runAdd({
|
|
1165
5363
|
packageSpec: pkg,
|
|
1166
5364
|
registry: opts.registry,
|
|
1167
5365
|
alias: opts.alias,
|
|
1168
|
-
noMaterialize:
|
|
5366
|
+
noMaterialize: o.materialize === false
|
|
1169
5367
|
}, cwd).catch(handleError);
|
|
1170
5368
|
},
|
|
1171
5369
|
sync: async (opts, globals) => {
|
|
@@ -1196,9 +5394,10 @@ var handlers = {
|
|
|
1196
5394
|
},
|
|
1197
5395
|
materialize: async (opts, globals) => {
|
|
1198
5396
|
setupGlobals(globals);
|
|
5397
|
+
const o = opts;
|
|
1199
5398
|
await runMaterialize({
|
|
1200
|
-
noGenerate:
|
|
1201
|
-
noLint:
|
|
5399
|
+
noGenerate: o.generate === false,
|
|
5400
|
+
noLint: o.lint === false,
|
|
1202
5401
|
clean: opts.clean
|
|
1203
5402
|
}, cwd).catch(handleError);
|
|
1204
5403
|
},
|
|
@@ -1212,12 +5411,14 @@ var handlers = {
|
|
|
1212
5411
|
console.error("\u2717 Package path is required. Usage: agent-pkg publish <path>");
|
|
1213
5412
|
process.exit(1);
|
|
1214
5413
|
}
|
|
5414
|
+
const o = opts;
|
|
1215
5415
|
await runPublish({
|
|
1216
5416
|
path,
|
|
1217
5417
|
version: opts.version,
|
|
5418
|
+
registry: opts.registry,
|
|
5419
|
+
name: opts.name,
|
|
1218
5420
|
dryRun: opts.dryRun,
|
|
1219
|
-
|
|
1220
|
-
noPush: opts.noPush
|
|
5421
|
+
noPush: o.push === false
|
|
1221
5422
|
}, cwd).catch(handleError);
|
|
1222
5423
|
}
|
|
1223
5424
|
};
|