linkque-cli-v2 1.6.28 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/linkquejs.js +1639 -4239
  2. package/package.json +1 -1
  3. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-RTUO3ZWI.js → chunk-2QJITP7G.js} +2 -2
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-BQHLF2GE.js → chunk-3AP3LROQ.js} +301 -4019
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NA35NOK4.js → chunk-4GHCK6YF.js} +49 -1
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-BMMEXZ52.js → chunk-4JKRD3V2.js} +1 -1
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-TIXVMTXT.js → chunk-FC7MJHC3.js} +1 -1
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-GAYNLDWK.js +11166 -0
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-33Q6KVN2.js → chunk-XUFLSZM4.js} +196 -60
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{dist-JRQ7GIV4.js → dist-6U5W3RLM.js} +46 -31
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-generative-ai-5VYDRFFM.js → google-generative-ai-RT2OOQDJ.js} +1 -1
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-vertex-JO4CT7NF.js → google-vertex-HVFMVQVY.js} +1 -1
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-43TLMTO6.js → mistral-conversations-KIOTOF73.js} +4 -4
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{multipart-parser-HCLTR6CW.js → multipart-parser-TAD6XL3Q.js} +2 -2
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-UCKXDLYZ.js → otel-LQR5KPZ3.js} +2 -2
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +7810 -638
  17. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +4 -4
  18. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +4 -4
  19. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{src-MFXPXO5F.js → src-JSJTYJV5.js} +25 -25
  20. package/worker.js +70329 -75943
  21. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-KQTRZ2SZ.js +0 -19744
@@ -1,13 +1,118 @@
1
1
  import {
2
+ BRAND,
3
+ DIRTY,
4
+ EMPTY_PATH,
5
+ INVALID,
2
6
  NEVER,
7
+ OK,
8
+ ParseStatus,
9
+ ZodAny,
10
+ ZodArray,
11
+ ZodBigInt,
12
+ ZodBoolean,
13
+ ZodBranded,
14
+ ZodCatch,
15
+ ZodDate,
16
+ ZodDefault,
17
+ ZodDiscriminatedUnion,
18
+ ZodEffects,
19
+ ZodEnum,
20
+ ZodError,
21
+ ZodFirstPartyTypeKind,
22
+ ZodFunction,
23
+ ZodIntersection,
3
24
  ZodIssueCode,
25
+ ZodLazy,
26
+ ZodLiteral,
27
+ ZodMap,
28
+ ZodNaN,
29
+ ZodNativeEnum,
30
+ ZodNever,
31
+ ZodNull,
32
+ ZodNullable,
33
+ ZodNumber,
34
+ ZodObject,
35
+ ZodOptional,
36
+ ZodParsedType,
37
+ ZodPipeline,
38
+ ZodPromise,
39
+ ZodReadonly,
40
+ ZodRecord,
41
+ ZodSet,
42
+ ZodString,
43
+ ZodSymbol,
44
+ ZodTuple,
45
+ ZodType,
46
+ ZodUndefined,
47
+ ZodUnion,
48
+ ZodUnknown,
49
+ ZodVoid,
50
+ addIssueToContext,
51
+ anyType,
52
+ arrayType,
53
+ bigIntType,
54
+ booleanType,
55
+ coerce,
56
+ custom,
57
+ dateType,
58
+ datetimeRegex,
59
+ discriminatedUnionType,
60
+ effectsType,
61
+ en_default,
62
+ enumType,
63
+ functionType,
64
+ getErrorMap,
65
+ getParsedType,
66
+ instanceOfType,
67
+ intersectionType,
68
+ isAborted,
69
+ isAsync,
70
+ isDirty,
71
+ isValid,
72
+ late,
73
+ lazyType,
74
+ literalType,
75
+ makeIssue,
76
+ mapType,
77
+ nanType,
78
+ nativeEnumType,
79
+ neverType,
80
+ nullType,
81
+ nullableType,
82
+ numberType,
83
+ objectType,
84
+ objectUtil,
85
+ oboolean,
86
+ onumber,
87
+ optionalType,
88
+ ostring,
89
+ pipelineType,
90
+ preprocessType,
91
+ promiseType,
92
+ quotelessJson,
93
+ recordType,
94
+ setErrorMap,
95
+ setType,
96
+ strictObjectType,
97
+ stringType,
98
+ symbolType,
99
+ tupleType,
100
+ undefinedType,
101
+ unionType,
102
+ unknownType,
103
+ util,
104
+ voidType
105
+ } from "./chunk-XUFLSZM4.js";
106
+ import {
107
+ NEVER as NEVER2,
108
+ ZodIssueCode as ZodIssueCode2,
4
109
  _enum,
5
110
  _null,
6
111
  any,
7
112
  array,
8
113
  boolean,
9
114
  coerce_exports,
10
- custom,
115
+ custom as custom2,
11
116
  discriminatedUnion,
12
117
  intersection,
13
118
  iso_exports,
@@ -23,7 +128,7 @@ import {
23
128
  union,
24
129
  unknown,
25
130
  url
26
- } from "./chunk-KQTRZ2SZ.js";
131
+ } from "./chunk-GAYNLDWK.js";
27
132
  import {
28
133
  ROOT_CONTEXT,
29
134
  SpanKind,
@@ -1156,9 +1261,9 @@ var require_util = __commonJS({
1156
1261
  }
1157
1262
  }
1158
1263
  exports.eachItem = eachItem;
1159
- function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues: mergeValues2, resultToName }) {
1264
+ function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
1160
1265
  return (gen, from, to, toName) => {
1161
- const res = to === void 0 ? from : to instanceof codegen_1.Name ? (from instanceof codegen_1.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1.Name ? (mergeToName(gen, to, from), from) : mergeValues2(from, to);
1266
+ const res = to === void 0 ? from : to instanceof codegen_1.Name ? (from instanceof codegen_1.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
1162
1267
  return toName === codegen_1.Name && !(res instanceof codegen_1.Name) ? resultToName(gen, res) : res;
1163
1268
  };
1164
1269
  }
@@ -1882,8 +1987,8 @@ var require_keyword = __commonJS({
1882
1987
  var _a2;
1883
1988
  const { gen, keyword, schema, parentSchema, $data, it } = cxt;
1884
1989
  checkAsyncKeyword(it, def);
1885
- const validate2 = !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate;
1886
- const validateRef = useKeyword(gen, keyword, validate2);
1990
+ const validate = !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate;
1991
+ const validateRef = useKeyword(gen, keyword, validate);
1887
1992
  const valid = gen.let("valid");
1888
1993
  cxt.block$data(valid, validateKeyword);
1889
1994
  cxt.ok((_a2 = def.valid) !== null && _a2 !== void 0 ? _a2 : valid);
@@ -1894,13 +1999,13 @@ var require_keyword = __commonJS({
1894
1999
  modifyData(cxt);
1895
2000
  reportErrs(() => cxt.error());
1896
2001
  } else {
1897
- const ruleErrs = def.async ? validateAsync2() : validateSync();
2002
+ const ruleErrs = def.async ? validateAsync() : validateSync();
1898
2003
  if (def.modifying)
1899
2004
  modifyData(cxt);
1900
2005
  reportErrs(() => addErrs(cxt, ruleErrs));
1901
2006
  }
1902
2007
  }
1903
- function validateAsync2() {
2008
+ function validateAsync() {
1904
2009
  const ruleErrs = gen.let("ruleErrs", null);
1905
2010
  gen.try(() => assignValid((0, codegen_1._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1._)`${e}.errors`), () => gen.throw(e)));
1906
2011
  return ruleErrs;
@@ -2956,28 +3061,28 @@ var require_compile = __commonJS({
2956
3061
  if (this.opts.code.process)
2957
3062
  sourceCode = this.opts.code.process(sourceCode, sch);
2958
3063
  const makeValidate = new Function(`${names_1.default.self}`, `${names_1.default.scope}`, sourceCode);
2959
- const validate2 = makeValidate(this, this.scope.get());
2960
- this.scope.value(validateName, { ref: validate2 });
2961
- validate2.errors = null;
2962
- validate2.schema = sch.schema;
2963
- validate2.schemaEnv = sch;
3064
+ const validate = makeValidate(this, this.scope.get());
3065
+ this.scope.value(validateName, { ref: validate });
3066
+ validate.errors = null;
3067
+ validate.schema = sch.schema;
3068
+ validate.schemaEnv = sch;
2964
3069
  if (sch.$async)
2965
- validate2.$async = true;
3070
+ validate.$async = true;
2966
3071
  if (this.opts.code.source === true) {
2967
- validate2.source = { validateName, validateCode, scopeValues: gen._values };
3072
+ validate.source = { validateName, validateCode, scopeValues: gen._values };
2968
3073
  }
2969
3074
  if (this.opts.unevaluated) {
2970
3075
  const { props, items } = schemaCxt;
2971
- validate2.evaluated = {
3076
+ validate.evaluated = {
2972
3077
  props: props instanceof codegen_1.Name ? void 0 : props,
2973
3078
  items: items instanceof codegen_1.Name ? void 0 : items,
2974
3079
  dynamicProps: props instanceof codegen_1.Name,
2975
3080
  dynamicItems: items instanceof codegen_1.Name
2976
3081
  };
2977
- if (validate2.source)
2978
- validate2.source.evaluated = (0, codegen_1.stringify)(validate2.evaluated);
3082
+ if (validate.source)
3083
+ validate.source.evaluated = (0, codegen_1.stringify)(validate.evaluated);
2979
3084
  }
2980
- sch.validate = validate2;
3085
+ sch.validate = validate;
2981
3086
  return sch;
2982
3087
  } catch (e) {
2983
3088
  delete sch.validate;
@@ -8465,8 +8570,8 @@ var require_formats = __commonJS({
8465
8570
  "use strict";
8466
8571
  Object.defineProperty(exports, "__esModule", { value: true });
8467
8572
  exports.formatNames = exports.fastFormats = exports.fullFormats = void 0;
8468
- function fmtDef(validate2, compare) {
8469
- return { validate: validate2, compare };
8573
+ function fmtDef(validate, compare) {
8574
+ return { validate, compare };
8470
8575
  }
8471
8576
  exports.fullFormats = {
8472
8577
  // date: http://tools.ietf.org/html/rfc3339#section-5.6
@@ -22417,7 +22522,7 @@ var require_util5 = __commonJS({
22417
22522
  if (encoding === "failure") {
22418
22523
  encoding = "UTF-8";
22419
22524
  }
22420
- return decode2(bytes2, encoding);
22525
+ return decode(bytes2, encoding);
22421
22526
  }
22422
22527
  case "ArrayBuffer": {
22423
22528
  const sequence = combineByteSequences(bytes2);
@@ -22434,7 +22539,7 @@ var require_util5 = __commonJS({
22434
22539
  }
22435
22540
  }
22436
22541
  }
22437
- function decode2(ioQueue, encoding) {
22542
+ function decode(ioQueue, encoding) {
22438
22543
  const bytes2 = combineByteSequences(ioQueue);
22439
22544
  const BOMEncoding = BOMSniffing(bytes2);
22440
22545
  let slice = 0;
@@ -41091,14 +41196,14 @@ function getRunEmbeddedQuery(request2) {
41091
41196
  return value;
41092
41197
  }
41093
41198
 
41094
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/external.js
41199
+ // ../../node_modules/zod/v3/external.js
41095
41200
  var external_exports = {};
41096
41201
  __export(external_exports, {
41097
41202
  BRAND: () => BRAND,
41098
41203
  DIRTY: () => DIRTY,
41099
41204
  EMPTY_PATH: () => EMPTY_PATH,
41100
41205
  INVALID: () => INVALID,
41101
- NEVER: () => NEVER2,
41206
+ NEVER: () => NEVER,
41102
41207
  OK: () => OK,
41103
41208
  ParseStatus: () => ParseStatus,
41104
41209
  Schema: () => ZodType,
@@ -41117,7 +41222,7 @@ __export(external_exports, {
41117
41222
  ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
41118
41223
  ZodFunction: () => ZodFunction,
41119
41224
  ZodIntersection: () => ZodIntersection,
41120
- ZodIssueCode: () => ZodIssueCode2,
41225
+ ZodIssueCode: () => ZodIssueCode,
41121
41226
  ZodLazy: () => ZodLazy,
41122
41227
  ZodLiteral: () => ZodLiteral,
41123
41228
  ZodMap: () => ZodMap,
@@ -41151,7 +41256,7 @@ __export(external_exports, {
41151
41256
  bigint: () => bigIntType,
41152
41257
  boolean: () => booleanType,
41153
41258
  coerce: () => coerce,
41154
- custom: () => custom2,
41259
+ custom: () => custom,
41155
41260
  date: () => dateType,
41156
41261
  datetimeRegex: () => datetimeRegex,
41157
41262
  defaultErrorMap: () => en_default,
@@ -41203,3935 +41308,6 @@ __export(external_exports, {
41203
41308
  void: () => voidType
41204
41309
  });
41205
41310
 
41206
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/helpers/util.js
41207
- var util;
41208
- (function(util2) {
41209
- util2.assertEqual = (_) => {
41210
- };
41211
- function assertIs(_arg) {
41212
- }
41213
- util2.assertIs = assertIs;
41214
- function assertNever(_x) {
41215
- throw new Error();
41216
- }
41217
- util2.assertNever = assertNever;
41218
- util2.arrayToEnum = (items) => {
41219
- const obj = {};
41220
- for (const item of items) {
41221
- obj[item] = item;
41222
- }
41223
- return obj;
41224
- };
41225
- util2.getValidEnumValues = (obj) => {
41226
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
41227
- const filtered = {};
41228
- for (const k of validKeys) {
41229
- filtered[k] = obj[k];
41230
- }
41231
- return util2.objectValues(filtered);
41232
- };
41233
- util2.objectValues = (obj) => {
41234
- return util2.objectKeys(obj).map(function(e) {
41235
- return obj[e];
41236
- });
41237
- };
41238
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object3) => {
41239
- const keys2 = [];
41240
- for (const key in object3) {
41241
- if (Object.prototype.hasOwnProperty.call(object3, key)) {
41242
- keys2.push(key);
41243
- }
41244
- }
41245
- return keys2;
41246
- };
41247
- util2.find = (arr, checker) => {
41248
- for (const item of arr) {
41249
- if (checker(item))
41250
- return item;
41251
- }
41252
- return void 0;
41253
- };
41254
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
41255
- function joinValues(array2, separator = " | ") {
41256
- return array2.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
41257
- }
41258
- util2.joinValues = joinValues;
41259
- util2.jsonStringifyReplacer = (_, value) => {
41260
- if (typeof value === "bigint") {
41261
- return value.toString();
41262
- }
41263
- return value;
41264
- };
41265
- })(util || (util = {}));
41266
- var objectUtil;
41267
- (function(objectUtil2) {
41268
- objectUtil2.mergeShapes = (first, second) => {
41269
- return {
41270
- ...first,
41271
- ...second
41272
- // second overwrites first
41273
- };
41274
- };
41275
- })(objectUtil || (objectUtil = {}));
41276
- var ZodParsedType = util.arrayToEnum([
41277
- "string",
41278
- "nan",
41279
- "number",
41280
- "integer",
41281
- "float",
41282
- "boolean",
41283
- "date",
41284
- "bigint",
41285
- "symbol",
41286
- "function",
41287
- "undefined",
41288
- "null",
41289
- "array",
41290
- "object",
41291
- "unknown",
41292
- "promise",
41293
- "void",
41294
- "never",
41295
- "map",
41296
- "set"
41297
- ]);
41298
- var getParsedType = (data) => {
41299
- const t = typeof data;
41300
- switch (t) {
41301
- case "undefined":
41302
- return ZodParsedType.undefined;
41303
- case "string":
41304
- return ZodParsedType.string;
41305
- case "number":
41306
- return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
41307
- case "boolean":
41308
- return ZodParsedType.boolean;
41309
- case "function":
41310
- return ZodParsedType.function;
41311
- case "bigint":
41312
- return ZodParsedType.bigint;
41313
- case "symbol":
41314
- return ZodParsedType.symbol;
41315
- case "object":
41316
- if (Array.isArray(data)) {
41317
- return ZodParsedType.array;
41318
- }
41319
- if (data === null) {
41320
- return ZodParsedType.null;
41321
- }
41322
- if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
41323
- return ZodParsedType.promise;
41324
- }
41325
- if (typeof Map !== "undefined" && data instanceof Map) {
41326
- return ZodParsedType.map;
41327
- }
41328
- if (typeof Set !== "undefined" && data instanceof Set) {
41329
- return ZodParsedType.set;
41330
- }
41331
- if (typeof Date !== "undefined" && data instanceof Date) {
41332
- return ZodParsedType.date;
41333
- }
41334
- return ZodParsedType.object;
41335
- default:
41336
- return ZodParsedType.unknown;
41337
- }
41338
- };
41339
-
41340
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/ZodError.js
41341
- var ZodIssueCode2 = util.arrayToEnum([
41342
- "invalid_type",
41343
- "invalid_literal",
41344
- "custom",
41345
- "invalid_union",
41346
- "invalid_union_discriminator",
41347
- "invalid_enum_value",
41348
- "unrecognized_keys",
41349
- "invalid_arguments",
41350
- "invalid_return_type",
41351
- "invalid_date",
41352
- "invalid_string",
41353
- "too_small",
41354
- "too_big",
41355
- "invalid_intersection_types",
41356
- "not_multiple_of",
41357
- "not_finite"
41358
- ]);
41359
- var quotelessJson = (obj) => {
41360
- const json = JSON.stringify(obj, null, 2);
41361
- return json.replace(/"([^"]+)":/g, "$1:");
41362
- };
41363
- var ZodError = class _ZodError extends Error {
41364
- get errors() {
41365
- return this.issues;
41366
- }
41367
- constructor(issues) {
41368
- super();
41369
- this.issues = [];
41370
- this.addIssue = (sub) => {
41371
- this.issues = [...this.issues, sub];
41372
- };
41373
- this.addIssues = (subs = []) => {
41374
- this.issues = [...this.issues, ...subs];
41375
- };
41376
- const actualProto = new.target.prototype;
41377
- if (Object.setPrototypeOf) {
41378
- Object.setPrototypeOf(this, actualProto);
41379
- } else {
41380
- this.__proto__ = actualProto;
41381
- }
41382
- this.name = "ZodError";
41383
- this.issues = issues;
41384
- }
41385
- format(_mapper) {
41386
- const mapper = _mapper || function(issue3) {
41387
- return issue3.message;
41388
- };
41389
- const fieldErrors = { _errors: [] };
41390
- const processError = (error) => {
41391
- for (const issue3 of error.issues) {
41392
- if (issue3.code === "invalid_union") {
41393
- issue3.unionErrors.map(processError);
41394
- } else if (issue3.code === "invalid_return_type") {
41395
- processError(issue3.returnTypeError);
41396
- } else if (issue3.code === "invalid_arguments") {
41397
- processError(issue3.argumentsError);
41398
- } else if (issue3.path.length === 0) {
41399
- fieldErrors._errors.push(mapper(issue3));
41400
- } else {
41401
- let curr = fieldErrors;
41402
- let i = 0;
41403
- while (i < issue3.path.length) {
41404
- const el = issue3.path[i];
41405
- const terminal = i === issue3.path.length - 1;
41406
- if (!terminal) {
41407
- curr[el] = curr[el] || { _errors: [] };
41408
- } else {
41409
- curr[el] = curr[el] || { _errors: [] };
41410
- curr[el]._errors.push(mapper(issue3));
41411
- }
41412
- curr = curr[el];
41413
- i++;
41414
- }
41415
- }
41416
- }
41417
- };
41418
- processError(this);
41419
- return fieldErrors;
41420
- }
41421
- static assert(value) {
41422
- if (!(value instanceof _ZodError)) {
41423
- throw new Error(`Not a ZodError: ${value}`);
41424
- }
41425
- }
41426
- toString() {
41427
- return this.message;
41428
- }
41429
- get message() {
41430
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
41431
- }
41432
- get isEmpty() {
41433
- return this.issues.length === 0;
41434
- }
41435
- flatten(mapper = (issue3) => issue3.message) {
41436
- const fieldErrors = {};
41437
- const formErrors = [];
41438
- for (const sub of this.issues) {
41439
- if (sub.path.length > 0) {
41440
- const firstEl = sub.path[0];
41441
- fieldErrors[firstEl] = fieldErrors[firstEl] || [];
41442
- fieldErrors[firstEl].push(mapper(sub));
41443
- } else {
41444
- formErrors.push(mapper(sub));
41445
- }
41446
- }
41447
- return { formErrors, fieldErrors };
41448
- }
41449
- get formErrors() {
41450
- return this.flatten();
41451
- }
41452
- };
41453
- ZodError.create = (issues) => {
41454
- const error = new ZodError(issues);
41455
- return error;
41456
- };
41457
-
41458
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/locales/en.js
41459
- var errorMap = (issue3, _ctx) => {
41460
- let message;
41461
- switch (issue3.code) {
41462
- case ZodIssueCode2.invalid_type:
41463
- if (issue3.received === ZodParsedType.undefined) {
41464
- message = "Required";
41465
- } else {
41466
- message = `Expected ${issue3.expected}, received ${issue3.received}`;
41467
- }
41468
- break;
41469
- case ZodIssueCode2.invalid_literal:
41470
- message = `Invalid literal value, expected ${JSON.stringify(issue3.expected, util.jsonStringifyReplacer)}`;
41471
- break;
41472
- case ZodIssueCode2.unrecognized_keys:
41473
- message = `Unrecognized key(s) in object: ${util.joinValues(issue3.keys, ", ")}`;
41474
- break;
41475
- case ZodIssueCode2.invalid_union:
41476
- message = `Invalid input`;
41477
- break;
41478
- case ZodIssueCode2.invalid_union_discriminator:
41479
- message = `Invalid discriminator value. Expected ${util.joinValues(issue3.options)}`;
41480
- break;
41481
- case ZodIssueCode2.invalid_enum_value:
41482
- message = `Invalid enum value. Expected ${util.joinValues(issue3.options)}, received '${issue3.received}'`;
41483
- break;
41484
- case ZodIssueCode2.invalid_arguments:
41485
- message = `Invalid function arguments`;
41486
- break;
41487
- case ZodIssueCode2.invalid_return_type:
41488
- message = `Invalid function return type`;
41489
- break;
41490
- case ZodIssueCode2.invalid_date:
41491
- message = `Invalid date`;
41492
- break;
41493
- case ZodIssueCode2.invalid_string:
41494
- if (typeof issue3.validation === "object") {
41495
- if ("includes" in issue3.validation) {
41496
- message = `Invalid input: must include "${issue3.validation.includes}"`;
41497
- if (typeof issue3.validation.position === "number") {
41498
- message = `${message} at one or more positions greater than or equal to ${issue3.validation.position}`;
41499
- }
41500
- } else if ("startsWith" in issue3.validation) {
41501
- message = `Invalid input: must start with "${issue3.validation.startsWith}"`;
41502
- } else if ("endsWith" in issue3.validation) {
41503
- message = `Invalid input: must end with "${issue3.validation.endsWith}"`;
41504
- } else {
41505
- util.assertNever(issue3.validation);
41506
- }
41507
- } else if (issue3.validation !== "regex") {
41508
- message = `Invalid ${issue3.validation}`;
41509
- } else {
41510
- message = "Invalid";
41511
- }
41512
- break;
41513
- case ZodIssueCode2.too_small:
41514
- if (issue3.type === "array")
41515
- message = `Array must contain ${issue3.exact ? "exactly" : issue3.inclusive ? `at least` : `more than`} ${issue3.minimum} element(s)`;
41516
- else if (issue3.type === "string")
41517
- message = `String must contain ${issue3.exact ? "exactly" : issue3.inclusive ? `at least` : `over`} ${issue3.minimum} character(s)`;
41518
- else if (issue3.type === "number")
41519
- message = `Number must be ${issue3.exact ? `exactly equal to ` : issue3.inclusive ? `greater than or equal to ` : `greater than `}${issue3.minimum}`;
41520
- else if (issue3.type === "bigint")
41521
- message = `Number must be ${issue3.exact ? `exactly equal to ` : issue3.inclusive ? `greater than or equal to ` : `greater than `}${issue3.minimum}`;
41522
- else if (issue3.type === "date")
41523
- message = `Date must be ${issue3.exact ? `exactly equal to ` : issue3.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue3.minimum))}`;
41524
- else
41525
- message = "Invalid input";
41526
- break;
41527
- case ZodIssueCode2.too_big:
41528
- if (issue3.type === "array")
41529
- message = `Array must contain ${issue3.exact ? `exactly` : issue3.inclusive ? `at most` : `less than`} ${issue3.maximum} element(s)`;
41530
- else if (issue3.type === "string")
41531
- message = `String must contain ${issue3.exact ? `exactly` : issue3.inclusive ? `at most` : `under`} ${issue3.maximum} character(s)`;
41532
- else if (issue3.type === "number")
41533
- message = `Number must be ${issue3.exact ? `exactly` : issue3.inclusive ? `less than or equal to` : `less than`} ${issue3.maximum}`;
41534
- else if (issue3.type === "bigint")
41535
- message = `BigInt must be ${issue3.exact ? `exactly` : issue3.inclusive ? `less than or equal to` : `less than`} ${issue3.maximum}`;
41536
- else if (issue3.type === "date")
41537
- message = `Date must be ${issue3.exact ? `exactly` : issue3.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue3.maximum))}`;
41538
- else
41539
- message = "Invalid input";
41540
- break;
41541
- case ZodIssueCode2.custom:
41542
- message = `Invalid input`;
41543
- break;
41544
- case ZodIssueCode2.invalid_intersection_types:
41545
- message = `Intersection results could not be merged`;
41546
- break;
41547
- case ZodIssueCode2.not_multiple_of:
41548
- message = `Number must be a multiple of ${issue3.multipleOf}`;
41549
- break;
41550
- case ZodIssueCode2.not_finite:
41551
- message = "Number must be finite";
41552
- break;
41553
- default:
41554
- message = _ctx.defaultError;
41555
- util.assertNever(issue3);
41556
- }
41557
- return { message };
41558
- };
41559
- var en_default = errorMap;
41560
-
41561
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/errors.js
41562
- var overrideErrorMap = en_default;
41563
- function setErrorMap(map) {
41564
- overrideErrorMap = map;
41565
- }
41566
- function getErrorMap() {
41567
- return overrideErrorMap;
41568
- }
41569
-
41570
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/helpers/parseUtil.js
41571
- var makeIssue = (params) => {
41572
- const { data, path: path2, errorMaps, issueData } = params;
41573
- const fullPath = [...path2, ...issueData.path || []];
41574
- const fullIssue = {
41575
- ...issueData,
41576
- path: fullPath
41577
- };
41578
- if (issueData.message !== void 0) {
41579
- return {
41580
- ...issueData,
41581
- path: fullPath,
41582
- message: issueData.message
41583
- };
41584
- }
41585
- let errorMessage2 = "";
41586
- const maps = errorMaps.filter((m) => !!m).slice().reverse();
41587
- for (const map of maps) {
41588
- errorMessage2 = map(fullIssue, { data, defaultError: errorMessage2 }).message;
41589
- }
41590
- return {
41591
- ...issueData,
41592
- path: fullPath,
41593
- message: errorMessage2
41594
- };
41595
- };
41596
- var EMPTY_PATH = [];
41597
- function addIssueToContext(ctx, issueData) {
41598
- const overrideMap = getErrorMap();
41599
- const issue3 = makeIssue({
41600
- issueData,
41601
- data: ctx.data,
41602
- path: ctx.path,
41603
- errorMaps: [
41604
- ctx.common.contextualErrorMap,
41605
- // contextual error map is first priority
41606
- ctx.schemaErrorMap,
41607
- // then schema-bound map if available
41608
- overrideMap,
41609
- // then global override map
41610
- overrideMap === en_default ? void 0 : en_default
41611
- // then global default map
41612
- ].filter((x) => !!x)
41613
- });
41614
- ctx.common.issues.push(issue3);
41615
- }
41616
- var ParseStatus = class _ParseStatus {
41617
- constructor() {
41618
- this.value = "valid";
41619
- }
41620
- dirty() {
41621
- if (this.value === "valid")
41622
- this.value = "dirty";
41623
- }
41624
- abort() {
41625
- if (this.value !== "aborted")
41626
- this.value = "aborted";
41627
- }
41628
- static mergeArray(status, results) {
41629
- const arrayValue = [];
41630
- for (const s of results) {
41631
- if (s.status === "aborted")
41632
- return INVALID;
41633
- if (s.status === "dirty")
41634
- status.dirty();
41635
- arrayValue.push(s.value);
41636
- }
41637
- return { status: status.value, value: arrayValue };
41638
- }
41639
- static async mergeObjectAsync(status, pairs) {
41640
- const syncPairs = [];
41641
- for (const pair of pairs) {
41642
- const key = await pair.key;
41643
- const value = await pair.value;
41644
- syncPairs.push({
41645
- key,
41646
- value
41647
- });
41648
- }
41649
- return _ParseStatus.mergeObjectSync(status, syncPairs);
41650
- }
41651
- static mergeObjectSync(status, pairs) {
41652
- const finalObject = {};
41653
- for (const pair of pairs) {
41654
- const { key, value } = pair;
41655
- if (key.status === "aborted")
41656
- return INVALID;
41657
- if (value.status === "aborted")
41658
- return INVALID;
41659
- if (key.status === "dirty")
41660
- status.dirty();
41661
- if (value.status === "dirty")
41662
- status.dirty();
41663
- if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
41664
- finalObject[key.value] = value.value;
41665
- }
41666
- }
41667
- return { status: status.value, value: finalObject };
41668
- }
41669
- };
41670
- var INVALID = Object.freeze({
41671
- status: "aborted"
41672
- });
41673
- var DIRTY = (value) => ({ status: "dirty", value });
41674
- var OK = (value) => ({ status: "valid", value });
41675
- var isAborted = (x) => x.status === "aborted";
41676
- var isDirty = (x) => x.status === "dirty";
41677
- var isValid = (x) => x.status === "valid";
41678
- var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
41679
-
41680
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/helpers/errorUtil.js
41681
- var errorUtil;
41682
- (function(errorUtil2) {
41683
- errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
41684
- errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
41685
- })(errorUtil || (errorUtil = {}));
41686
-
41687
- // ../../node_modules/@ag-ui/core/node_modules/zod/v3/types.js
41688
- var ParseInputLazyPath = class {
41689
- constructor(parent, value, path2, key) {
41690
- this._cachedPath = [];
41691
- this.parent = parent;
41692
- this.data = value;
41693
- this._path = path2;
41694
- this._key = key;
41695
- }
41696
- get path() {
41697
- if (!this._cachedPath.length) {
41698
- if (Array.isArray(this._key)) {
41699
- this._cachedPath.push(...this._path, ...this._key);
41700
- } else {
41701
- this._cachedPath.push(...this._path, this._key);
41702
- }
41703
- }
41704
- return this._cachedPath;
41705
- }
41706
- };
41707
- var handleResult = (ctx, result) => {
41708
- if (isValid(result)) {
41709
- return { success: true, data: result.value };
41710
- } else {
41711
- if (!ctx.common.issues.length) {
41712
- throw new Error("Validation failed but no issues detected.");
41713
- }
41714
- return {
41715
- success: false,
41716
- get error() {
41717
- if (this._error)
41718
- return this._error;
41719
- const error = new ZodError(ctx.common.issues);
41720
- this._error = error;
41721
- return this._error;
41722
- }
41723
- };
41724
- }
41725
- };
41726
- function processCreateParams(params) {
41727
- if (!params)
41728
- return {};
41729
- const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
41730
- if (errorMap2 && (invalid_type_error || required_error)) {
41731
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
41732
- }
41733
- if (errorMap2)
41734
- return { errorMap: errorMap2, description };
41735
- const customMap = (iss, ctx) => {
41736
- const { message } = params;
41737
- if (iss.code === "invalid_enum_value") {
41738
- return { message: message ?? ctx.defaultError };
41739
- }
41740
- if (typeof ctx.data === "undefined") {
41741
- return { message: message ?? required_error ?? ctx.defaultError };
41742
- }
41743
- if (iss.code !== "invalid_type")
41744
- return { message: ctx.defaultError };
41745
- return { message: message ?? invalid_type_error ?? ctx.defaultError };
41746
- };
41747
- return { errorMap: customMap, description };
41748
- }
41749
- var ZodType = class {
41750
- get description() {
41751
- return this._def.description;
41752
- }
41753
- _getType(input) {
41754
- return getParsedType(input.data);
41755
- }
41756
- _getOrReturnCtx(input, ctx) {
41757
- return ctx || {
41758
- common: input.parent.common,
41759
- data: input.data,
41760
- parsedType: getParsedType(input.data),
41761
- schemaErrorMap: this._def.errorMap,
41762
- path: input.path,
41763
- parent: input.parent
41764
- };
41765
- }
41766
- _processInputParams(input) {
41767
- return {
41768
- status: new ParseStatus(),
41769
- ctx: {
41770
- common: input.parent.common,
41771
- data: input.data,
41772
- parsedType: getParsedType(input.data),
41773
- schemaErrorMap: this._def.errorMap,
41774
- path: input.path,
41775
- parent: input.parent
41776
- }
41777
- };
41778
- }
41779
- _parseSync(input) {
41780
- const result = this._parse(input);
41781
- if (isAsync(result)) {
41782
- throw new Error("Synchronous parse encountered promise.");
41783
- }
41784
- return result;
41785
- }
41786
- _parseAsync(input) {
41787
- const result = this._parse(input);
41788
- return Promise.resolve(result);
41789
- }
41790
- parse(data, params) {
41791
- const result = this.safeParse(data, params);
41792
- if (result.success)
41793
- return result.data;
41794
- throw result.error;
41795
- }
41796
- safeParse(data, params) {
41797
- const ctx = {
41798
- common: {
41799
- issues: [],
41800
- async: params?.async ?? false,
41801
- contextualErrorMap: params?.errorMap
41802
- },
41803
- path: params?.path || [],
41804
- schemaErrorMap: this._def.errorMap,
41805
- parent: null,
41806
- data,
41807
- parsedType: getParsedType(data)
41808
- };
41809
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
41810
- return handleResult(ctx, result);
41811
- }
41812
- "~validate"(data) {
41813
- const ctx = {
41814
- common: {
41815
- issues: [],
41816
- async: !!this["~standard"].async
41817
- },
41818
- path: [],
41819
- schemaErrorMap: this._def.errorMap,
41820
- parent: null,
41821
- data,
41822
- parsedType: getParsedType(data)
41823
- };
41824
- if (!this["~standard"].async) {
41825
- try {
41826
- const result = this._parseSync({ data, path: [], parent: ctx });
41827
- return isValid(result) ? {
41828
- value: result.value
41829
- } : {
41830
- issues: ctx.common.issues
41831
- };
41832
- } catch (err2) {
41833
- if (err2?.message?.toLowerCase()?.includes("encountered")) {
41834
- this["~standard"].async = true;
41835
- }
41836
- ctx.common = {
41837
- issues: [],
41838
- async: true
41839
- };
41840
- }
41841
- }
41842
- return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
41843
- value: result.value
41844
- } : {
41845
- issues: ctx.common.issues
41846
- });
41847
- }
41848
- async parseAsync(data, params) {
41849
- const result = await this.safeParseAsync(data, params);
41850
- if (result.success)
41851
- return result.data;
41852
- throw result.error;
41853
- }
41854
- async safeParseAsync(data, params) {
41855
- const ctx = {
41856
- common: {
41857
- issues: [],
41858
- contextualErrorMap: params?.errorMap,
41859
- async: true
41860
- },
41861
- path: params?.path || [],
41862
- schemaErrorMap: this._def.errorMap,
41863
- parent: null,
41864
- data,
41865
- parsedType: getParsedType(data)
41866
- };
41867
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
41868
- const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
41869
- return handleResult(ctx, result);
41870
- }
41871
- refine(check, message) {
41872
- const getIssueProperties = (val) => {
41873
- if (typeof message === "string" || typeof message === "undefined") {
41874
- return { message };
41875
- } else if (typeof message === "function") {
41876
- return message(val);
41877
- } else {
41878
- return message;
41879
- }
41880
- };
41881
- return this._refinement((val, ctx) => {
41882
- const result = check(val);
41883
- const setError = () => ctx.addIssue({
41884
- code: ZodIssueCode2.custom,
41885
- ...getIssueProperties(val)
41886
- });
41887
- if (typeof Promise !== "undefined" && result instanceof Promise) {
41888
- return result.then((data) => {
41889
- if (!data) {
41890
- setError();
41891
- return false;
41892
- } else {
41893
- return true;
41894
- }
41895
- });
41896
- }
41897
- if (!result) {
41898
- setError();
41899
- return false;
41900
- } else {
41901
- return true;
41902
- }
41903
- });
41904
- }
41905
- refinement(check, refinementData) {
41906
- return this._refinement((val, ctx) => {
41907
- if (!check(val)) {
41908
- ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
41909
- return false;
41910
- } else {
41911
- return true;
41912
- }
41913
- });
41914
- }
41915
- _refinement(refinement) {
41916
- return new ZodEffects({
41917
- schema: this,
41918
- typeName: ZodFirstPartyTypeKind.ZodEffects,
41919
- effect: { type: "refinement", refinement }
41920
- });
41921
- }
41922
- superRefine(refinement) {
41923
- return this._refinement(refinement);
41924
- }
41925
- constructor(def) {
41926
- this.spa = this.safeParseAsync;
41927
- this._def = def;
41928
- this.parse = this.parse.bind(this);
41929
- this.safeParse = this.safeParse.bind(this);
41930
- this.parseAsync = this.parseAsync.bind(this);
41931
- this.safeParseAsync = this.safeParseAsync.bind(this);
41932
- this.spa = this.spa.bind(this);
41933
- this.refine = this.refine.bind(this);
41934
- this.refinement = this.refinement.bind(this);
41935
- this.superRefine = this.superRefine.bind(this);
41936
- this.optional = this.optional.bind(this);
41937
- this.nullable = this.nullable.bind(this);
41938
- this.nullish = this.nullish.bind(this);
41939
- this.array = this.array.bind(this);
41940
- this.promise = this.promise.bind(this);
41941
- this.or = this.or.bind(this);
41942
- this.and = this.and.bind(this);
41943
- this.transform = this.transform.bind(this);
41944
- this.brand = this.brand.bind(this);
41945
- this.default = this.default.bind(this);
41946
- this.catch = this.catch.bind(this);
41947
- this.describe = this.describe.bind(this);
41948
- this.pipe = this.pipe.bind(this);
41949
- this.readonly = this.readonly.bind(this);
41950
- this.isNullable = this.isNullable.bind(this);
41951
- this.isOptional = this.isOptional.bind(this);
41952
- this["~standard"] = {
41953
- version: 1,
41954
- vendor: "zod",
41955
- validate: (data) => this["~validate"](data)
41956
- };
41957
- }
41958
- optional() {
41959
- return ZodOptional.create(this, this._def);
41960
- }
41961
- nullable() {
41962
- return ZodNullable.create(this, this._def);
41963
- }
41964
- nullish() {
41965
- return this.nullable().optional();
41966
- }
41967
- array() {
41968
- return ZodArray.create(this);
41969
- }
41970
- promise() {
41971
- return ZodPromise.create(this, this._def);
41972
- }
41973
- or(option) {
41974
- return ZodUnion.create([this, option], this._def);
41975
- }
41976
- and(incoming) {
41977
- return ZodIntersection.create(this, incoming, this._def);
41978
- }
41979
- transform(transform) {
41980
- return new ZodEffects({
41981
- ...processCreateParams(this._def),
41982
- schema: this,
41983
- typeName: ZodFirstPartyTypeKind.ZodEffects,
41984
- effect: { type: "transform", transform }
41985
- });
41986
- }
41987
- default(def) {
41988
- const defaultValueFunc = typeof def === "function" ? def : () => def;
41989
- return new ZodDefault({
41990
- ...processCreateParams(this._def),
41991
- innerType: this,
41992
- defaultValue: defaultValueFunc,
41993
- typeName: ZodFirstPartyTypeKind.ZodDefault
41994
- });
41995
- }
41996
- brand() {
41997
- return new ZodBranded({
41998
- typeName: ZodFirstPartyTypeKind.ZodBranded,
41999
- type: this,
42000
- ...processCreateParams(this._def)
42001
- });
42002
- }
42003
- catch(def) {
42004
- const catchValueFunc = typeof def === "function" ? def : () => def;
42005
- return new ZodCatch({
42006
- ...processCreateParams(this._def),
42007
- innerType: this,
42008
- catchValue: catchValueFunc,
42009
- typeName: ZodFirstPartyTypeKind.ZodCatch
42010
- });
42011
- }
42012
- describe(description) {
42013
- const This = this.constructor;
42014
- return new This({
42015
- ...this._def,
42016
- description
42017
- });
42018
- }
42019
- pipe(target) {
42020
- return ZodPipeline.create(this, target);
42021
- }
42022
- readonly() {
42023
- return ZodReadonly.create(this);
42024
- }
42025
- isOptional() {
42026
- return this.safeParse(void 0).success;
42027
- }
42028
- isNullable() {
42029
- return this.safeParse(null).success;
42030
- }
42031
- };
42032
- var cuidRegex = /^c[^\s-]{8,}$/i;
42033
- var cuid2Regex = /^[0-9a-z]+$/;
42034
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
42035
- 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;
42036
- var nanoidRegex = /^[a-z0-9_-]{21}$/i;
42037
- var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
42038
- 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)?)??$/;
42039
- var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
42040
- var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
42041
- var emojiRegex;
42042
- 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])$/;
42043
- 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])$/;
42044
- 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]))$/;
42045
- 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])$/;
42046
- var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
42047
- var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
42048
- 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])))`;
42049
- var dateRegex = new RegExp(`^${dateRegexSource}$`);
42050
- function timeRegexSource(args) {
42051
- let secondsRegexSource = `[0-5]\\d`;
42052
- if (args.precision) {
42053
- secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
42054
- } else if (args.precision == null) {
42055
- secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
42056
- }
42057
- const secondsQuantifier = args.precision ? "+" : "?";
42058
- return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
42059
- }
42060
- function timeRegex(args) {
42061
- return new RegExp(`^${timeRegexSource(args)}$`);
42062
- }
42063
- function datetimeRegex(args) {
42064
- let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
42065
- const opts = [];
42066
- opts.push(args.local ? `Z?` : `Z`);
42067
- if (args.offset)
42068
- opts.push(`([+-]\\d{2}:?\\d{2})`);
42069
- regex = `${regex}(${opts.join("|")})`;
42070
- return new RegExp(`^${regex}$`);
42071
- }
42072
- function isValidIP(ip, version) {
42073
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
42074
- return true;
42075
- }
42076
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
42077
- return true;
42078
- }
42079
- return false;
42080
- }
42081
- function isValidJWT(jwt, alg) {
42082
- if (!jwtRegex.test(jwt))
42083
- return false;
42084
- try {
42085
- const [header] = jwt.split(".");
42086
- if (!header)
42087
- return false;
42088
- const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
42089
- const decoded = JSON.parse(atob(base64));
42090
- if (typeof decoded !== "object" || decoded === null)
42091
- return false;
42092
- if ("typ" in decoded && decoded?.typ !== "JWT")
42093
- return false;
42094
- if (!decoded.alg)
42095
- return false;
42096
- if (alg && decoded.alg !== alg)
42097
- return false;
42098
- return true;
42099
- } catch {
42100
- return false;
42101
- }
42102
- }
42103
- function isValidCidr(ip, version) {
42104
- if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
42105
- return true;
42106
- }
42107
- if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
42108
- return true;
42109
- }
42110
- return false;
42111
- }
42112
- var ZodString = class _ZodString extends ZodType {
42113
- _parse(input) {
42114
- if (this._def.coerce) {
42115
- input.data = String(input.data);
42116
- }
42117
- const parsedType = this._getType(input);
42118
- if (parsedType !== ZodParsedType.string) {
42119
- const ctx2 = this._getOrReturnCtx(input);
42120
- addIssueToContext(ctx2, {
42121
- code: ZodIssueCode2.invalid_type,
42122
- expected: ZodParsedType.string,
42123
- received: ctx2.parsedType
42124
- });
42125
- return INVALID;
42126
- }
42127
- const status = new ParseStatus();
42128
- let ctx = void 0;
42129
- for (const check of this._def.checks) {
42130
- if (check.kind === "min") {
42131
- if (input.data.length < check.value) {
42132
- ctx = this._getOrReturnCtx(input, ctx);
42133
- addIssueToContext(ctx, {
42134
- code: ZodIssueCode2.too_small,
42135
- minimum: check.value,
42136
- type: "string",
42137
- inclusive: true,
42138
- exact: false,
42139
- message: check.message
42140
- });
42141
- status.dirty();
42142
- }
42143
- } else if (check.kind === "max") {
42144
- if (input.data.length > check.value) {
42145
- ctx = this._getOrReturnCtx(input, ctx);
42146
- addIssueToContext(ctx, {
42147
- code: ZodIssueCode2.too_big,
42148
- maximum: check.value,
42149
- type: "string",
42150
- inclusive: true,
42151
- exact: false,
42152
- message: check.message
42153
- });
42154
- status.dirty();
42155
- }
42156
- } else if (check.kind === "length") {
42157
- const tooBig = input.data.length > check.value;
42158
- const tooSmall = input.data.length < check.value;
42159
- if (tooBig || tooSmall) {
42160
- ctx = this._getOrReturnCtx(input, ctx);
42161
- if (tooBig) {
42162
- addIssueToContext(ctx, {
42163
- code: ZodIssueCode2.too_big,
42164
- maximum: check.value,
42165
- type: "string",
42166
- inclusive: true,
42167
- exact: true,
42168
- message: check.message
42169
- });
42170
- } else if (tooSmall) {
42171
- addIssueToContext(ctx, {
42172
- code: ZodIssueCode2.too_small,
42173
- minimum: check.value,
42174
- type: "string",
42175
- inclusive: true,
42176
- exact: true,
42177
- message: check.message
42178
- });
42179
- }
42180
- status.dirty();
42181
- }
42182
- } else if (check.kind === "email") {
42183
- if (!emailRegex.test(input.data)) {
42184
- ctx = this._getOrReturnCtx(input, ctx);
42185
- addIssueToContext(ctx, {
42186
- validation: "email",
42187
- code: ZodIssueCode2.invalid_string,
42188
- message: check.message
42189
- });
42190
- status.dirty();
42191
- }
42192
- } else if (check.kind === "emoji") {
42193
- if (!emojiRegex) {
42194
- emojiRegex = new RegExp(_emojiRegex, "u");
42195
- }
42196
- if (!emojiRegex.test(input.data)) {
42197
- ctx = this._getOrReturnCtx(input, ctx);
42198
- addIssueToContext(ctx, {
42199
- validation: "emoji",
42200
- code: ZodIssueCode2.invalid_string,
42201
- message: check.message
42202
- });
42203
- status.dirty();
42204
- }
42205
- } else if (check.kind === "uuid") {
42206
- if (!uuidRegex.test(input.data)) {
42207
- ctx = this._getOrReturnCtx(input, ctx);
42208
- addIssueToContext(ctx, {
42209
- validation: "uuid",
42210
- code: ZodIssueCode2.invalid_string,
42211
- message: check.message
42212
- });
42213
- status.dirty();
42214
- }
42215
- } else if (check.kind === "nanoid") {
42216
- if (!nanoidRegex.test(input.data)) {
42217
- ctx = this._getOrReturnCtx(input, ctx);
42218
- addIssueToContext(ctx, {
42219
- validation: "nanoid",
42220
- code: ZodIssueCode2.invalid_string,
42221
- message: check.message
42222
- });
42223
- status.dirty();
42224
- }
42225
- } else if (check.kind === "cuid") {
42226
- if (!cuidRegex.test(input.data)) {
42227
- ctx = this._getOrReturnCtx(input, ctx);
42228
- addIssueToContext(ctx, {
42229
- validation: "cuid",
42230
- code: ZodIssueCode2.invalid_string,
42231
- message: check.message
42232
- });
42233
- status.dirty();
42234
- }
42235
- } else if (check.kind === "cuid2") {
42236
- if (!cuid2Regex.test(input.data)) {
42237
- ctx = this._getOrReturnCtx(input, ctx);
42238
- addIssueToContext(ctx, {
42239
- validation: "cuid2",
42240
- code: ZodIssueCode2.invalid_string,
42241
- message: check.message
42242
- });
42243
- status.dirty();
42244
- }
42245
- } else if (check.kind === "ulid") {
42246
- if (!ulidRegex.test(input.data)) {
42247
- ctx = this._getOrReturnCtx(input, ctx);
42248
- addIssueToContext(ctx, {
42249
- validation: "ulid",
42250
- code: ZodIssueCode2.invalid_string,
42251
- message: check.message
42252
- });
42253
- status.dirty();
42254
- }
42255
- } else if (check.kind === "url") {
42256
- try {
42257
- new URL(input.data);
42258
- } catch {
42259
- ctx = this._getOrReturnCtx(input, ctx);
42260
- addIssueToContext(ctx, {
42261
- validation: "url",
42262
- code: ZodIssueCode2.invalid_string,
42263
- message: check.message
42264
- });
42265
- status.dirty();
42266
- }
42267
- } else if (check.kind === "regex") {
42268
- check.regex.lastIndex = 0;
42269
- const testResult = check.regex.test(input.data);
42270
- if (!testResult) {
42271
- ctx = this._getOrReturnCtx(input, ctx);
42272
- addIssueToContext(ctx, {
42273
- validation: "regex",
42274
- code: ZodIssueCode2.invalid_string,
42275
- message: check.message
42276
- });
42277
- status.dirty();
42278
- }
42279
- } else if (check.kind === "trim") {
42280
- input.data = input.data.trim();
42281
- } else if (check.kind === "includes") {
42282
- if (!input.data.includes(check.value, check.position)) {
42283
- ctx = this._getOrReturnCtx(input, ctx);
42284
- addIssueToContext(ctx, {
42285
- code: ZodIssueCode2.invalid_string,
42286
- validation: { includes: check.value, position: check.position },
42287
- message: check.message
42288
- });
42289
- status.dirty();
42290
- }
42291
- } else if (check.kind === "toLowerCase") {
42292
- input.data = input.data.toLowerCase();
42293
- } else if (check.kind === "toUpperCase") {
42294
- input.data = input.data.toUpperCase();
42295
- } else if (check.kind === "startsWith") {
42296
- if (!input.data.startsWith(check.value)) {
42297
- ctx = this._getOrReturnCtx(input, ctx);
42298
- addIssueToContext(ctx, {
42299
- code: ZodIssueCode2.invalid_string,
42300
- validation: { startsWith: check.value },
42301
- message: check.message
42302
- });
42303
- status.dirty();
42304
- }
42305
- } else if (check.kind === "endsWith") {
42306
- if (!input.data.endsWith(check.value)) {
42307
- ctx = this._getOrReturnCtx(input, ctx);
42308
- addIssueToContext(ctx, {
42309
- code: ZodIssueCode2.invalid_string,
42310
- validation: { endsWith: check.value },
42311
- message: check.message
42312
- });
42313
- status.dirty();
42314
- }
42315
- } else if (check.kind === "datetime") {
42316
- const regex = datetimeRegex(check);
42317
- if (!regex.test(input.data)) {
42318
- ctx = this._getOrReturnCtx(input, ctx);
42319
- addIssueToContext(ctx, {
42320
- code: ZodIssueCode2.invalid_string,
42321
- validation: "datetime",
42322
- message: check.message
42323
- });
42324
- status.dirty();
42325
- }
42326
- } else if (check.kind === "date") {
42327
- const regex = dateRegex;
42328
- if (!regex.test(input.data)) {
42329
- ctx = this._getOrReturnCtx(input, ctx);
42330
- addIssueToContext(ctx, {
42331
- code: ZodIssueCode2.invalid_string,
42332
- validation: "date",
42333
- message: check.message
42334
- });
42335
- status.dirty();
42336
- }
42337
- } else if (check.kind === "time") {
42338
- const regex = timeRegex(check);
42339
- if (!regex.test(input.data)) {
42340
- ctx = this._getOrReturnCtx(input, ctx);
42341
- addIssueToContext(ctx, {
42342
- code: ZodIssueCode2.invalid_string,
42343
- validation: "time",
42344
- message: check.message
42345
- });
42346
- status.dirty();
42347
- }
42348
- } else if (check.kind === "duration") {
42349
- if (!durationRegex.test(input.data)) {
42350
- ctx = this._getOrReturnCtx(input, ctx);
42351
- addIssueToContext(ctx, {
42352
- validation: "duration",
42353
- code: ZodIssueCode2.invalid_string,
42354
- message: check.message
42355
- });
42356
- status.dirty();
42357
- }
42358
- } else if (check.kind === "ip") {
42359
- if (!isValidIP(input.data, check.version)) {
42360
- ctx = this._getOrReturnCtx(input, ctx);
42361
- addIssueToContext(ctx, {
42362
- validation: "ip",
42363
- code: ZodIssueCode2.invalid_string,
42364
- message: check.message
42365
- });
42366
- status.dirty();
42367
- }
42368
- } else if (check.kind === "jwt") {
42369
- if (!isValidJWT(input.data, check.alg)) {
42370
- ctx = this._getOrReturnCtx(input, ctx);
42371
- addIssueToContext(ctx, {
42372
- validation: "jwt",
42373
- code: ZodIssueCode2.invalid_string,
42374
- message: check.message
42375
- });
42376
- status.dirty();
42377
- }
42378
- } else if (check.kind === "cidr") {
42379
- if (!isValidCidr(input.data, check.version)) {
42380
- ctx = this._getOrReturnCtx(input, ctx);
42381
- addIssueToContext(ctx, {
42382
- validation: "cidr",
42383
- code: ZodIssueCode2.invalid_string,
42384
- message: check.message
42385
- });
42386
- status.dirty();
42387
- }
42388
- } else if (check.kind === "base64") {
42389
- if (!base64Regex.test(input.data)) {
42390
- ctx = this._getOrReturnCtx(input, ctx);
42391
- addIssueToContext(ctx, {
42392
- validation: "base64",
42393
- code: ZodIssueCode2.invalid_string,
42394
- message: check.message
42395
- });
42396
- status.dirty();
42397
- }
42398
- } else if (check.kind === "base64url") {
42399
- if (!base64urlRegex.test(input.data)) {
42400
- ctx = this._getOrReturnCtx(input, ctx);
42401
- addIssueToContext(ctx, {
42402
- validation: "base64url",
42403
- code: ZodIssueCode2.invalid_string,
42404
- message: check.message
42405
- });
42406
- status.dirty();
42407
- }
42408
- } else {
42409
- util.assertNever(check);
42410
- }
42411
- }
42412
- return { status: status.value, value: input.data };
42413
- }
42414
- _regex(regex, validation, message) {
42415
- return this.refinement((data) => regex.test(data), {
42416
- validation,
42417
- code: ZodIssueCode2.invalid_string,
42418
- ...errorUtil.errToObj(message)
42419
- });
42420
- }
42421
- _addCheck(check) {
42422
- return new _ZodString({
42423
- ...this._def,
42424
- checks: [...this._def.checks, check]
42425
- });
42426
- }
42427
- email(message) {
42428
- return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
42429
- }
42430
- url(message) {
42431
- return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
42432
- }
42433
- emoji(message) {
42434
- return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
42435
- }
42436
- uuid(message) {
42437
- return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
42438
- }
42439
- nanoid(message) {
42440
- return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
42441
- }
42442
- cuid(message) {
42443
- return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
42444
- }
42445
- cuid2(message) {
42446
- return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
42447
- }
42448
- ulid(message) {
42449
- return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
42450
- }
42451
- base64(message) {
42452
- return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
42453
- }
42454
- base64url(message) {
42455
- return this._addCheck({
42456
- kind: "base64url",
42457
- ...errorUtil.errToObj(message)
42458
- });
42459
- }
42460
- jwt(options) {
42461
- return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
42462
- }
42463
- ip(options) {
42464
- return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
42465
- }
42466
- cidr(options) {
42467
- return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
42468
- }
42469
- datetime(options) {
42470
- if (typeof options === "string") {
42471
- return this._addCheck({
42472
- kind: "datetime",
42473
- precision: null,
42474
- offset: false,
42475
- local: false,
42476
- message: options
42477
- });
42478
- }
42479
- return this._addCheck({
42480
- kind: "datetime",
42481
- precision: typeof options?.precision === "undefined" ? null : options?.precision,
42482
- offset: options?.offset ?? false,
42483
- local: options?.local ?? false,
42484
- ...errorUtil.errToObj(options?.message)
42485
- });
42486
- }
42487
- date(message) {
42488
- return this._addCheck({ kind: "date", message });
42489
- }
42490
- time(options) {
42491
- if (typeof options === "string") {
42492
- return this._addCheck({
42493
- kind: "time",
42494
- precision: null,
42495
- message: options
42496
- });
42497
- }
42498
- return this._addCheck({
42499
- kind: "time",
42500
- precision: typeof options?.precision === "undefined" ? null : options?.precision,
42501
- ...errorUtil.errToObj(options?.message)
42502
- });
42503
- }
42504
- duration(message) {
42505
- return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
42506
- }
42507
- regex(regex, message) {
42508
- return this._addCheck({
42509
- kind: "regex",
42510
- regex,
42511
- ...errorUtil.errToObj(message)
42512
- });
42513
- }
42514
- includes(value, options) {
42515
- return this._addCheck({
42516
- kind: "includes",
42517
- value,
42518
- position: options?.position,
42519
- ...errorUtil.errToObj(options?.message)
42520
- });
42521
- }
42522
- startsWith(value, message) {
42523
- return this._addCheck({
42524
- kind: "startsWith",
42525
- value,
42526
- ...errorUtil.errToObj(message)
42527
- });
42528
- }
42529
- endsWith(value, message) {
42530
- return this._addCheck({
42531
- kind: "endsWith",
42532
- value,
42533
- ...errorUtil.errToObj(message)
42534
- });
42535
- }
42536
- min(minLength, message) {
42537
- return this._addCheck({
42538
- kind: "min",
42539
- value: minLength,
42540
- ...errorUtil.errToObj(message)
42541
- });
42542
- }
42543
- max(maxLength, message) {
42544
- return this._addCheck({
42545
- kind: "max",
42546
- value: maxLength,
42547
- ...errorUtil.errToObj(message)
42548
- });
42549
- }
42550
- length(len, message) {
42551
- return this._addCheck({
42552
- kind: "length",
42553
- value: len,
42554
- ...errorUtil.errToObj(message)
42555
- });
42556
- }
42557
- /**
42558
- * Equivalent to `.min(1)`
42559
- */
42560
- nonempty(message) {
42561
- return this.min(1, errorUtil.errToObj(message));
42562
- }
42563
- trim() {
42564
- return new _ZodString({
42565
- ...this._def,
42566
- checks: [...this._def.checks, { kind: "trim" }]
42567
- });
42568
- }
42569
- toLowerCase() {
42570
- return new _ZodString({
42571
- ...this._def,
42572
- checks: [...this._def.checks, { kind: "toLowerCase" }]
42573
- });
42574
- }
42575
- toUpperCase() {
42576
- return new _ZodString({
42577
- ...this._def,
42578
- checks: [...this._def.checks, { kind: "toUpperCase" }]
42579
- });
42580
- }
42581
- get isDatetime() {
42582
- return !!this._def.checks.find((ch2) => ch2.kind === "datetime");
42583
- }
42584
- get isDate() {
42585
- return !!this._def.checks.find((ch2) => ch2.kind === "date");
42586
- }
42587
- get isTime() {
42588
- return !!this._def.checks.find((ch2) => ch2.kind === "time");
42589
- }
42590
- get isDuration() {
42591
- return !!this._def.checks.find((ch2) => ch2.kind === "duration");
42592
- }
42593
- get isEmail() {
42594
- return !!this._def.checks.find((ch2) => ch2.kind === "email");
42595
- }
42596
- get isURL() {
42597
- return !!this._def.checks.find((ch2) => ch2.kind === "url");
42598
- }
42599
- get isEmoji() {
42600
- return !!this._def.checks.find((ch2) => ch2.kind === "emoji");
42601
- }
42602
- get isUUID() {
42603
- return !!this._def.checks.find((ch2) => ch2.kind === "uuid");
42604
- }
42605
- get isNANOID() {
42606
- return !!this._def.checks.find((ch2) => ch2.kind === "nanoid");
42607
- }
42608
- get isCUID() {
42609
- return !!this._def.checks.find((ch2) => ch2.kind === "cuid");
42610
- }
42611
- get isCUID2() {
42612
- return !!this._def.checks.find((ch2) => ch2.kind === "cuid2");
42613
- }
42614
- get isULID() {
42615
- return !!this._def.checks.find((ch2) => ch2.kind === "ulid");
42616
- }
42617
- get isIP() {
42618
- return !!this._def.checks.find((ch2) => ch2.kind === "ip");
42619
- }
42620
- get isCIDR() {
42621
- return !!this._def.checks.find((ch2) => ch2.kind === "cidr");
42622
- }
42623
- get isBase64() {
42624
- return !!this._def.checks.find((ch2) => ch2.kind === "base64");
42625
- }
42626
- get isBase64url() {
42627
- return !!this._def.checks.find((ch2) => ch2.kind === "base64url");
42628
- }
42629
- get minLength() {
42630
- let min = null;
42631
- for (const ch2 of this._def.checks) {
42632
- if (ch2.kind === "min") {
42633
- if (min === null || ch2.value > min)
42634
- min = ch2.value;
42635
- }
42636
- }
42637
- return min;
42638
- }
42639
- get maxLength() {
42640
- let max2 = null;
42641
- for (const ch2 of this._def.checks) {
42642
- if (ch2.kind === "max") {
42643
- if (max2 === null || ch2.value < max2)
42644
- max2 = ch2.value;
42645
- }
42646
- }
42647
- return max2;
42648
- }
42649
- };
42650
- ZodString.create = (params) => {
42651
- return new ZodString({
42652
- checks: [],
42653
- typeName: ZodFirstPartyTypeKind.ZodString,
42654
- coerce: params?.coerce ?? false,
42655
- ...processCreateParams(params)
42656
- });
42657
- };
42658
- function floatSafeRemainder(val, step) {
42659
- const valDecCount = (val.toString().split(".")[1] || "").length;
42660
- const stepDecCount = (step.toString().split(".")[1] || "").length;
42661
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
42662
- const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
42663
- const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
42664
- return valInt % stepInt / 10 ** decCount;
42665
- }
42666
- var ZodNumber = class _ZodNumber extends ZodType {
42667
- constructor() {
42668
- super(...arguments);
42669
- this.min = this.gte;
42670
- this.max = this.lte;
42671
- this.step = this.multipleOf;
42672
- }
42673
- _parse(input) {
42674
- if (this._def.coerce) {
42675
- input.data = Number(input.data);
42676
- }
42677
- const parsedType = this._getType(input);
42678
- if (parsedType !== ZodParsedType.number) {
42679
- const ctx2 = this._getOrReturnCtx(input);
42680
- addIssueToContext(ctx2, {
42681
- code: ZodIssueCode2.invalid_type,
42682
- expected: ZodParsedType.number,
42683
- received: ctx2.parsedType
42684
- });
42685
- return INVALID;
42686
- }
42687
- let ctx = void 0;
42688
- const status = new ParseStatus();
42689
- for (const check of this._def.checks) {
42690
- if (check.kind === "int") {
42691
- if (!util.isInteger(input.data)) {
42692
- ctx = this._getOrReturnCtx(input, ctx);
42693
- addIssueToContext(ctx, {
42694
- code: ZodIssueCode2.invalid_type,
42695
- expected: "integer",
42696
- received: "float",
42697
- message: check.message
42698
- });
42699
- status.dirty();
42700
- }
42701
- } else if (check.kind === "min") {
42702
- const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
42703
- if (tooSmall) {
42704
- ctx = this._getOrReturnCtx(input, ctx);
42705
- addIssueToContext(ctx, {
42706
- code: ZodIssueCode2.too_small,
42707
- minimum: check.value,
42708
- type: "number",
42709
- inclusive: check.inclusive,
42710
- exact: false,
42711
- message: check.message
42712
- });
42713
- status.dirty();
42714
- }
42715
- } else if (check.kind === "max") {
42716
- const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
42717
- if (tooBig) {
42718
- ctx = this._getOrReturnCtx(input, ctx);
42719
- addIssueToContext(ctx, {
42720
- code: ZodIssueCode2.too_big,
42721
- maximum: check.value,
42722
- type: "number",
42723
- inclusive: check.inclusive,
42724
- exact: false,
42725
- message: check.message
42726
- });
42727
- status.dirty();
42728
- }
42729
- } else if (check.kind === "multipleOf") {
42730
- if (floatSafeRemainder(input.data, check.value) !== 0) {
42731
- ctx = this._getOrReturnCtx(input, ctx);
42732
- addIssueToContext(ctx, {
42733
- code: ZodIssueCode2.not_multiple_of,
42734
- multipleOf: check.value,
42735
- message: check.message
42736
- });
42737
- status.dirty();
42738
- }
42739
- } else if (check.kind === "finite") {
42740
- if (!Number.isFinite(input.data)) {
42741
- ctx = this._getOrReturnCtx(input, ctx);
42742
- addIssueToContext(ctx, {
42743
- code: ZodIssueCode2.not_finite,
42744
- message: check.message
42745
- });
42746
- status.dirty();
42747
- }
42748
- } else {
42749
- util.assertNever(check);
42750
- }
42751
- }
42752
- return { status: status.value, value: input.data };
42753
- }
42754
- gte(value, message) {
42755
- return this.setLimit("min", value, true, errorUtil.toString(message));
42756
- }
42757
- gt(value, message) {
42758
- return this.setLimit("min", value, false, errorUtil.toString(message));
42759
- }
42760
- lte(value, message) {
42761
- return this.setLimit("max", value, true, errorUtil.toString(message));
42762
- }
42763
- lt(value, message) {
42764
- return this.setLimit("max", value, false, errorUtil.toString(message));
42765
- }
42766
- setLimit(kind, value, inclusive, message) {
42767
- return new _ZodNumber({
42768
- ...this._def,
42769
- checks: [
42770
- ...this._def.checks,
42771
- {
42772
- kind,
42773
- value,
42774
- inclusive,
42775
- message: errorUtil.toString(message)
42776
- }
42777
- ]
42778
- });
42779
- }
42780
- _addCheck(check) {
42781
- return new _ZodNumber({
42782
- ...this._def,
42783
- checks: [...this._def.checks, check]
42784
- });
42785
- }
42786
- int(message) {
42787
- return this._addCheck({
42788
- kind: "int",
42789
- message: errorUtil.toString(message)
42790
- });
42791
- }
42792
- positive(message) {
42793
- return this._addCheck({
42794
- kind: "min",
42795
- value: 0,
42796
- inclusive: false,
42797
- message: errorUtil.toString(message)
42798
- });
42799
- }
42800
- negative(message) {
42801
- return this._addCheck({
42802
- kind: "max",
42803
- value: 0,
42804
- inclusive: false,
42805
- message: errorUtil.toString(message)
42806
- });
42807
- }
42808
- nonpositive(message) {
42809
- return this._addCheck({
42810
- kind: "max",
42811
- value: 0,
42812
- inclusive: true,
42813
- message: errorUtil.toString(message)
42814
- });
42815
- }
42816
- nonnegative(message) {
42817
- return this._addCheck({
42818
- kind: "min",
42819
- value: 0,
42820
- inclusive: true,
42821
- message: errorUtil.toString(message)
42822
- });
42823
- }
42824
- multipleOf(value, message) {
42825
- return this._addCheck({
42826
- kind: "multipleOf",
42827
- value,
42828
- message: errorUtil.toString(message)
42829
- });
42830
- }
42831
- finite(message) {
42832
- return this._addCheck({
42833
- kind: "finite",
42834
- message: errorUtil.toString(message)
42835
- });
42836
- }
42837
- safe(message) {
42838
- return this._addCheck({
42839
- kind: "min",
42840
- inclusive: true,
42841
- value: Number.MIN_SAFE_INTEGER,
42842
- message: errorUtil.toString(message)
42843
- })._addCheck({
42844
- kind: "max",
42845
- inclusive: true,
42846
- value: Number.MAX_SAFE_INTEGER,
42847
- message: errorUtil.toString(message)
42848
- });
42849
- }
42850
- get minValue() {
42851
- let min = null;
42852
- for (const ch2 of this._def.checks) {
42853
- if (ch2.kind === "min") {
42854
- if (min === null || ch2.value > min)
42855
- min = ch2.value;
42856
- }
42857
- }
42858
- return min;
42859
- }
42860
- get maxValue() {
42861
- let max2 = null;
42862
- for (const ch2 of this._def.checks) {
42863
- if (ch2.kind === "max") {
42864
- if (max2 === null || ch2.value < max2)
42865
- max2 = ch2.value;
42866
- }
42867
- }
42868
- return max2;
42869
- }
42870
- get isInt() {
42871
- return !!this._def.checks.find((ch2) => ch2.kind === "int" || ch2.kind === "multipleOf" && util.isInteger(ch2.value));
42872
- }
42873
- get isFinite() {
42874
- let max2 = null;
42875
- let min = null;
42876
- for (const ch2 of this._def.checks) {
42877
- if (ch2.kind === "finite" || ch2.kind === "int" || ch2.kind === "multipleOf") {
42878
- return true;
42879
- } else if (ch2.kind === "min") {
42880
- if (min === null || ch2.value > min)
42881
- min = ch2.value;
42882
- } else if (ch2.kind === "max") {
42883
- if (max2 === null || ch2.value < max2)
42884
- max2 = ch2.value;
42885
- }
42886
- }
42887
- return Number.isFinite(min) && Number.isFinite(max2);
42888
- }
42889
- };
42890
- ZodNumber.create = (params) => {
42891
- return new ZodNumber({
42892
- checks: [],
42893
- typeName: ZodFirstPartyTypeKind.ZodNumber,
42894
- coerce: params?.coerce || false,
42895
- ...processCreateParams(params)
42896
- });
42897
- };
42898
- var ZodBigInt = class _ZodBigInt extends ZodType {
42899
- constructor() {
42900
- super(...arguments);
42901
- this.min = this.gte;
42902
- this.max = this.lte;
42903
- }
42904
- _parse(input) {
42905
- if (this._def.coerce) {
42906
- try {
42907
- input.data = BigInt(input.data);
42908
- } catch {
42909
- return this._getInvalidInput(input);
42910
- }
42911
- }
42912
- const parsedType = this._getType(input);
42913
- if (parsedType !== ZodParsedType.bigint) {
42914
- return this._getInvalidInput(input);
42915
- }
42916
- let ctx = void 0;
42917
- const status = new ParseStatus();
42918
- for (const check of this._def.checks) {
42919
- if (check.kind === "min") {
42920
- const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
42921
- if (tooSmall) {
42922
- ctx = this._getOrReturnCtx(input, ctx);
42923
- addIssueToContext(ctx, {
42924
- code: ZodIssueCode2.too_small,
42925
- type: "bigint",
42926
- minimum: check.value,
42927
- inclusive: check.inclusive,
42928
- message: check.message
42929
- });
42930
- status.dirty();
42931
- }
42932
- } else if (check.kind === "max") {
42933
- const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
42934
- if (tooBig) {
42935
- ctx = this._getOrReturnCtx(input, ctx);
42936
- addIssueToContext(ctx, {
42937
- code: ZodIssueCode2.too_big,
42938
- type: "bigint",
42939
- maximum: check.value,
42940
- inclusive: check.inclusive,
42941
- message: check.message
42942
- });
42943
- status.dirty();
42944
- }
42945
- } else if (check.kind === "multipleOf") {
42946
- if (input.data % check.value !== BigInt(0)) {
42947
- ctx = this._getOrReturnCtx(input, ctx);
42948
- addIssueToContext(ctx, {
42949
- code: ZodIssueCode2.not_multiple_of,
42950
- multipleOf: check.value,
42951
- message: check.message
42952
- });
42953
- status.dirty();
42954
- }
42955
- } else {
42956
- util.assertNever(check);
42957
- }
42958
- }
42959
- return { status: status.value, value: input.data };
42960
- }
42961
- _getInvalidInput(input) {
42962
- const ctx = this._getOrReturnCtx(input);
42963
- addIssueToContext(ctx, {
42964
- code: ZodIssueCode2.invalid_type,
42965
- expected: ZodParsedType.bigint,
42966
- received: ctx.parsedType
42967
- });
42968
- return INVALID;
42969
- }
42970
- gte(value, message) {
42971
- return this.setLimit("min", value, true, errorUtil.toString(message));
42972
- }
42973
- gt(value, message) {
42974
- return this.setLimit("min", value, false, errorUtil.toString(message));
42975
- }
42976
- lte(value, message) {
42977
- return this.setLimit("max", value, true, errorUtil.toString(message));
42978
- }
42979
- lt(value, message) {
42980
- return this.setLimit("max", value, false, errorUtil.toString(message));
42981
- }
42982
- setLimit(kind, value, inclusive, message) {
42983
- return new _ZodBigInt({
42984
- ...this._def,
42985
- checks: [
42986
- ...this._def.checks,
42987
- {
42988
- kind,
42989
- value,
42990
- inclusive,
42991
- message: errorUtil.toString(message)
42992
- }
42993
- ]
42994
- });
42995
- }
42996
- _addCheck(check) {
42997
- return new _ZodBigInt({
42998
- ...this._def,
42999
- checks: [...this._def.checks, check]
43000
- });
43001
- }
43002
- positive(message) {
43003
- return this._addCheck({
43004
- kind: "min",
43005
- value: BigInt(0),
43006
- inclusive: false,
43007
- message: errorUtil.toString(message)
43008
- });
43009
- }
43010
- negative(message) {
43011
- return this._addCheck({
43012
- kind: "max",
43013
- value: BigInt(0),
43014
- inclusive: false,
43015
- message: errorUtil.toString(message)
43016
- });
43017
- }
43018
- nonpositive(message) {
43019
- return this._addCheck({
43020
- kind: "max",
43021
- value: BigInt(0),
43022
- inclusive: true,
43023
- message: errorUtil.toString(message)
43024
- });
43025
- }
43026
- nonnegative(message) {
43027
- return this._addCheck({
43028
- kind: "min",
43029
- value: BigInt(0),
43030
- inclusive: true,
43031
- message: errorUtil.toString(message)
43032
- });
43033
- }
43034
- multipleOf(value, message) {
43035
- return this._addCheck({
43036
- kind: "multipleOf",
43037
- value,
43038
- message: errorUtil.toString(message)
43039
- });
43040
- }
43041
- get minValue() {
43042
- let min = null;
43043
- for (const ch2 of this._def.checks) {
43044
- if (ch2.kind === "min") {
43045
- if (min === null || ch2.value > min)
43046
- min = ch2.value;
43047
- }
43048
- }
43049
- return min;
43050
- }
43051
- get maxValue() {
43052
- let max2 = null;
43053
- for (const ch2 of this._def.checks) {
43054
- if (ch2.kind === "max") {
43055
- if (max2 === null || ch2.value < max2)
43056
- max2 = ch2.value;
43057
- }
43058
- }
43059
- return max2;
43060
- }
43061
- };
43062
- ZodBigInt.create = (params) => {
43063
- return new ZodBigInt({
43064
- checks: [],
43065
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
43066
- coerce: params?.coerce ?? false,
43067
- ...processCreateParams(params)
43068
- });
43069
- };
43070
- var ZodBoolean = class extends ZodType {
43071
- _parse(input) {
43072
- if (this._def.coerce) {
43073
- input.data = Boolean(input.data);
43074
- }
43075
- const parsedType = this._getType(input);
43076
- if (parsedType !== ZodParsedType.boolean) {
43077
- const ctx = this._getOrReturnCtx(input);
43078
- addIssueToContext(ctx, {
43079
- code: ZodIssueCode2.invalid_type,
43080
- expected: ZodParsedType.boolean,
43081
- received: ctx.parsedType
43082
- });
43083
- return INVALID;
43084
- }
43085
- return OK(input.data);
43086
- }
43087
- };
43088
- ZodBoolean.create = (params) => {
43089
- return new ZodBoolean({
43090
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
43091
- coerce: params?.coerce || false,
43092
- ...processCreateParams(params)
43093
- });
43094
- };
43095
- var ZodDate = class _ZodDate extends ZodType {
43096
- _parse(input) {
43097
- if (this._def.coerce) {
43098
- input.data = new Date(input.data);
43099
- }
43100
- const parsedType = this._getType(input);
43101
- if (parsedType !== ZodParsedType.date) {
43102
- const ctx2 = this._getOrReturnCtx(input);
43103
- addIssueToContext(ctx2, {
43104
- code: ZodIssueCode2.invalid_type,
43105
- expected: ZodParsedType.date,
43106
- received: ctx2.parsedType
43107
- });
43108
- return INVALID;
43109
- }
43110
- if (Number.isNaN(input.data.getTime())) {
43111
- const ctx2 = this._getOrReturnCtx(input);
43112
- addIssueToContext(ctx2, {
43113
- code: ZodIssueCode2.invalid_date
43114
- });
43115
- return INVALID;
43116
- }
43117
- const status = new ParseStatus();
43118
- let ctx = void 0;
43119
- for (const check of this._def.checks) {
43120
- if (check.kind === "min") {
43121
- if (input.data.getTime() < check.value) {
43122
- ctx = this._getOrReturnCtx(input, ctx);
43123
- addIssueToContext(ctx, {
43124
- code: ZodIssueCode2.too_small,
43125
- message: check.message,
43126
- inclusive: true,
43127
- exact: false,
43128
- minimum: check.value,
43129
- type: "date"
43130
- });
43131
- status.dirty();
43132
- }
43133
- } else if (check.kind === "max") {
43134
- if (input.data.getTime() > check.value) {
43135
- ctx = this._getOrReturnCtx(input, ctx);
43136
- addIssueToContext(ctx, {
43137
- code: ZodIssueCode2.too_big,
43138
- message: check.message,
43139
- inclusive: true,
43140
- exact: false,
43141
- maximum: check.value,
43142
- type: "date"
43143
- });
43144
- status.dirty();
43145
- }
43146
- } else {
43147
- util.assertNever(check);
43148
- }
43149
- }
43150
- return {
43151
- status: status.value,
43152
- value: new Date(input.data.getTime())
43153
- };
43154
- }
43155
- _addCheck(check) {
43156
- return new _ZodDate({
43157
- ...this._def,
43158
- checks: [...this._def.checks, check]
43159
- });
43160
- }
43161
- min(minDate, message) {
43162
- return this._addCheck({
43163
- kind: "min",
43164
- value: minDate.getTime(),
43165
- message: errorUtil.toString(message)
43166
- });
43167
- }
43168
- max(maxDate, message) {
43169
- return this._addCheck({
43170
- kind: "max",
43171
- value: maxDate.getTime(),
43172
- message: errorUtil.toString(message)
43173
- });
43174
- }
43175
- get minDate() {
43176
- let min = null;
43177
- for (const ch2 of this._def.checks) {
43178
- if (ch2.kind === "min") {
43179
- if (min === null || ch2.value > min)
43180
- min = ch2.value;
43181
- }
43182
- }
43183
- return min != null ? new Date(min) : null;
43184
- }
43185
- get maxDate() {
43186
- let max2 = null;
43187
- for (const ch2 of this._def.checks) {
43188
- if (ch2.kind === "max") {
43189
- if (max2 === null || ch2.value < max2)
43190
- max2 = ch2.value;
43191
- }
43192
- }
43193
- return max2 != null ? new Date(max2) : null;
43194
- }
43195
- };
43196
- ZodDate.create = (params) => {
43197
- return new ZodDate({
43198
- checks: [],
43199
- coerce: params?.coerce || false,
43200
- typeName: ZodFirstPartyTypeKind.ZodDate,
43201
- ...processCreateParams(params)
43202
- });
43203
- };
43204
- var ZodSymbol = class extends ZodType {
43205
- _parse(input) {
43206
- const parsedType = this._getType(input);
43207
- if (parsedType !== ZodParsedType.symbol) {
43208
- const ctx = this._getOrReturnCtx(input);
43209
- addIssueToContext(ctx, {
43210
- code: ZodIssueCode2.invalid_type,
43211
- expected: ZodParsedType.symbol,
43212
- received: ctx.parsedType
43213
- });
43214
- return INVALID;
43215
- }
43216
- return OK(input.data);
43217
- }
43218
- };
43219
- ZodSymbol.create = (params) => {
43220
- return new ZodSymbol({
43221
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
43222
- ...processCreateParams(params)
43223
- });
43224
- };
43225
- var ZodUndefined = class extends ZodType {
43226
- _parse(input) {
43227
- const parsedType = this._getType(input);
43228
- if (parsedType !== ZodParsedType.undefined) {
43229
- const ctx = this._getOrReturnCtx(input);
43230
- addIssueToContext(ctx, {
43231
- code: ZodIssueCode2.invalid_type,
43232
- expected: ZodParsedType.undefined,
43233
- received: ctx.parsedType
43234
- });
43235
- return INVALID;
43236
- }
43237
- return OK(input.data);
43238
- }
43239
- };
43240
- ZodUndefined.create = (params) => {
43241
- return new ZodUndefined({
43242
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
43243
- ...processCreateParams(params)
43244
- });
43245
- };
43246
- var ZodNull = class extends ZodType {
43247
- _parse(input) {
43248
- const parsedType = this._getType(input);
43249
- if (parsedType !== ZodParsedType.null) {
43250
- const ctx = this._getOrReturnCtx(input);
43251
- addIssueToContext(ctx, {
43252
- code: ZodIssueCode2.invalid_type,
43253
- expected: ZodParsedType.null,
43254
- received: ctx.parsedType
43255
- });
43256
- return INVALID;
43257
- }
43258
- return OK(input.data);
43259
- }
43260
- };
43261
- ZodNull.create = (params) => {
43262
- return new ZodNull({
43263
- typeName: ZodFirstPartyTypeKind.ZodNull,
43264
- ...processCreateParams(params)
43265
- });
43266
- };
43267
- var ZodAny = class extends ZodType {
43268
- constructor() {
43269
- super(...arguments);
43270
- this._any = true;
43271
- }
43272
- _parse(input) {
43273
- return OK(input.data);
43274
- }
43275
- };
43276
- ZodAny.create = (params) => {
43277
- return new ZodAny({
43278
- typeName: ZodFirstPartyTypeKind.ZodAny,
43279
- ...processCreateParams(params)
43280
- });
43281
- };
43282
- var ZodUnknown = class extends ZodType {
43283
- constructor() {
43284
- super(...arguments);
43285
- this._unknown = true;
43286
- }
43287
- _parse(input) {
43288
- return OK(input.data);
43289
- }
43290
- };
43291
- ZodUnknown.create = (params) => {
43292
- return new ZodUnknown({
43293
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
43294
- ...processCreateParams(params)
43295
- });
43296
- };
43297
- var ZodNever = class extends ZodType {
43298
- _parse(input) {
43299
- const ctx = this._getOrReturnCtx(input);
43300
- addIssueToContext(ctx, {
43301
- code: ZodIssueCode2.invalid_type,
43302
- expected: ZodParsedType.never,
43303
- received: ctx.parsedType
43304
- });
43305
- return INVALID;
43306
- }
43307
- };
43308
- ZodNever.create = (params) => {
43309
- return new ZodNever({
43310
- typeName: ZodFirstPartyTypeKind.ZodNever,
43311
- ...processCreateParams(params)
43312
- });
43313
- };
43314
- var ZodVoid = class extends ZodType {
43315
- _parse(input) {
43316
- const parsedType = this._getType(input);
43317
- if (parsedType !== ZodParsedType.undefined) {
43318
- const ctx = this._getOrReturnCtx(input);
43319
- addIssueToContext(ctx, {
43320
- code: ZodIssueCode2.invalid_type,
43321
- expected: ZodParsedType.void,
43322
- received: ctx.parsedType
43323
- });
43324
- return INVALID;
43325
- }
43326
- return OK(input.data);
43327
- }
43328
- };
43329
- ZodVoid.create = (params) => {
43330
- return new ZodVoid({
43331
- typeName: ZodFirstPartyTypeKind.ZodVoid,
43332
- ...processCreateParams(params)
43333
- });
43334
- };
43335
- var ZodArray = class _ZodArray extends ZodType {
43336
- _parse(input) {
43337
- const { ctx, status } = this._processInputParams(input);
43338
- const def = this._def;
43339
- if (ctx.parsedType !== ZodParsedType.array) {
43340
- addIssueToContext(ctx, {
43341
- code: ZodIssueCode2.invalid_type,
43342
- expected: ZodParsedType.array,
43343
- received: ctx.parsedType
43344
- });
43345
- return INVALID;
43346
- }
43347
- if (def.exactLength !== null) {
43348
- const tooBig = ctx.data.length > def.exactLength.value;
43349
- const tooSmall = ctx.data.length < def.exactLength.value;
43350
- if (tooBig || tooSmall) {
43351
- addIssueToContext(ctx, {
43352
- code: tooBig ? ZodIssueCode2.too_big : ZodIssueCode2.too_small,
43353
- minimum: tooSmall ? def.exactLength.value : void 0,
43354
- maximum: tooBig ? def.exactLength.value : void 0,
43355
- type: "array",
43356
- inclusive: true,
43357
- exact: true,
43358
- message: def.exactLength.message
43359
- });
43360
- status.dirty();
43361
- }
43362
- }
43363
- if (def.minLength !== null) {
43364
- if (ctx.data.length < def.minLength.value) {
43365
- addIssueToContext(ctx, {
43366
- code: ZodIssueCode2.too_small,
43367
- minimum: def.minLength.value,
43368
- type: "array",
43369
- inclusive: true,
43370
- exact: false,
43371
- message: def.minLength.message
43372
- });
43373
- status.dirty();
43374
- }
43375
- }
43376
- if (def.maxLength !== null) {
43377
- if (ctx.data.length > def.maxLength.value) {
43378
- addIssueToContext(ctx, {
43379
- code: ZodIssueCode2.too_big,
43380
- maximum: def.maxLength.value,
43381
- type: "array",
43382
- inclusive: true,
43383
- exact: false,
43384
- message: def.maxLength.message
43385
- });
43386
- status.dirty();
43387
- }
43388
- }
43389
- if (ctx.common.async) {
43390
- return Promise.all([...ctx.data].map((item, i) => {
43391
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
43392
- })).then((result2) => {
43393
- return ParseStatus.mergeArray(status, result2);
43394
- });
43395
- }
43396
- const result = [...ctx.data].map((item, i) => {
43397
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
43398
- });
43399
- return ParseStatus.mergeArray(status, result);
43400
- }
43401
- get element() {
43402
- return this._def.type;
43403
- }
43404
- min(minLength, message) {
43405
- return new _ZodArray({
43406
- ...this._def,
43407
- minLength: { value: minLength, message: errorUtil.toString(message) }
43408
- });
43409
- }
43410
- max(maxLength, message) {
43411
- return new _ZodArray({
43412
- ...this._def,
43413
- maxLength: { value: maxLength, message: errorUtil.toString(message) }
43414
- });
43415
- }
43416
- length(len, message) {
43417
- return new _ZodArray({
43418
- ...this._def,
43419
- exactLength: { value: len, message: errorUtil.toString(message) }
43420
- });
43421
- }
43422
- nonempty(message) {
43423
- return this.min(1, message);
43424
- }
43425
- };
43426
- ZodArray.create = (schema, params) => {
43427
- return new ZodArray({
43428
- type: schema,
43429
- minLength: null,
43430
- maxLength: null,
43431
- exactLength: null,
43432
- typeName: ZodFirstPartyTypeKind.ZodArray,
43433
- ...processCreateParams(params)
43434
- });
43435
- };
43436
- function deepPartialify(schema) {
43437
- if (schema instanceof ZodObject) {
43438
- const newShape = {};
43439
- for (const key in schema.shape) {
43440
- const fieldSchema = schema.shape[key];
43441
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
43442
- }
43443
- return new ZodObject({
43444
- ...schema._def,
43445
- shape: () => newShape
43446
- });
43447
- } else if (schema instanceof ZodArray) {
43448
- return new ZodArray({
43449
- ...schema._def,
43450
- type: deepPartialify(schema.element)
43451
- });
43452
- } else if (schema instanceof ZodOptional) {
43453
- return ZodOptional.create(deepPartialify(schema.unwrap()));
43454
- } else if (schema instanceof ZodNullable) {
43455
- return ZodNullable.create(deepPartialify(schema.unwrap()));
43456
- } else if (schema instanceof ZodTuple) {
43457
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
43458
- } else {
43459
- return schema;
43460
- }
43461
- }
43462
- var ZodObject = class _ZodObject extends ZodType {
43463
- constructor() {
43464
- super(...arguments);
43465
- this._cached = null;
43466
- this.nonstrict = this.passthrough;
43467
- this.augment = this.extend;
43468
- }
43469
- _getCached() {
43470
- if (this._cached !== null)
43471
- return this._cached;
43472
- const shape = this._def.shape();
43473
- const keys2 = util.objectKeys(shape);
43474
- this._cached = { shape, keys: keys2 };
43475
- return this._cached;
43476
- }
43477
- _parse(input) {
43478
- const parsedType = this._getType(input);
43479
- if (parsedType !== ZodParsedType.object) {
43480
- const ctx2 = this._getOrReturnCtx(input);
43481
- addIssueToContext(ctx2, {
43482
- code: ZodIssueCode2.invalid_type,
43483
- expected: ZodParsedType.object,
43484
- received: ctx2.parsedType
43485
- });
43486
- return INVALID;
43487
- }
43488
- const { status, ctx } = this._processInputParams(input);
43489
- const { shape, keys: shapeKeys } = this._getCached();
43490
- const extraKeys = [];
43491
- if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
43492
- for (const key in ctx.data) {
43493
- if (!shapeKeys.includes(key)) {
43494
- extraKeys.push(key);
43495
- }
43496
- }
43497
- }
43498
- const pairs = [];
43499
- for (const key of shapeKeys) {
43500
- const keyValidator = shape[key];
43501
- const value = ctx.data[key];
43502
- pairs.push({
43503
- key: { status: "valid", value: key },
43504
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
43505
- alwaysSet: key in ctx.data
43506
- });
43507
- }
43508
- if (this._def.catchall instanceof ZodNever) {
43509
- const unknownKeys = this._def.unknownKeys;
43510
- if (unknownKeys === "passthrough") {
43511
- for (const key of extraKeys) {
43512
- pairs.push({
43513
- key: { status: "valid", value: key },
43514
- value: { status: "valid", value: ctx.data[key] }
43515
- });
43516
- }
43517
- } else if (unknownKeys === "strict") {
43518
- if (extraKeys.length > 0) {
43519
- addIssueToContext(ctx, {
43520
- code: ZodIssueCode2.unrecognized_keys,
43521
- keys: extraKeys
43522
- });
43523
- status.dirty();
43524
- }
43525
- } else if (unknownKeys === "strip") {
43526
- } else {
43527
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
43528
- }
43529
- } else {
43530
- const catchall = this._def.catchall;
43531
- for (const key of extraKeys) {
43532
- const value = ctx.data[key];
43533
- pairs.push({
43534
- key: { status: "valid", value: key },
43535
- value: catchall._parse(
43536
- new ParseInputLazyPath(ctx, value, ctx.path, key)
43537
- //, ctx.child(key), value, getParsedType(value)
43538
- ),
43539
- alwaysSet: key in ctx.data
43540
- });
43541
- }
43542
- }
43543
- if (ctx.common.async) {
43544
- return Promise.resolve().then(async () => {
43545
- const syncPairs = [];
43546
- for (const pair of pairs) {
43547
- const key = await pair.key;
43548
- const value = await pair.value;
43549
- syncPairs.push({
43550
- key,
43551
- value,
43552
- alwaysSet: pair.alwaysSet
43553
- });
43554
- }
43555
- return syncPairs;
43556
- }).then((syncPairs) => {
43557
- return ParseStatus.mergeObjectSync(status, syncPairs);
43558
- });
43559
- } else {
43560
- return ParseStatus.mergeObjectSync(status, pairs);
43561
- }
43562
- }
43563
- get shape() {
43564
- return this._def.shape();
43565
- }
43566
- strict(message) {
43567
- errorUtil.errToObj;
43568
- return new _ZodObject({
43569
- ...this._def,
43570
- unknownKeys: "strict",
43571
- ...message !== void 0 ? {
43572
- errorMap: (issue3, ctx) => {
43573
- const defaultError = this._def.errorMap?.(issue3, ctx).message ?? ctx.defaultError;
43574
- if (issue3.code === "unrecognized_keys")
43575
- return {
43576
- message: errorUtil.errToObj(message).message ?? defaultError
43577
- };
43578
- return {
43579
- message: defaultError
43580
- };
43581
- }
43582
- } : {}
43583
- });
43584
- }
43585
- strip() {
43586
- return new _ZodObject({
43587
- ...this._def,
43588
- unknownKeys: "strip"
43589
- });
43590
- }
43591
- passthrough() {
43592
- return new _ZodObject({
43593
- ...this._def,
43594
- unknownKeys: "passthrough"
43595
- });
43596
- }
43597
- // const AugmentFactory =
43598
- // <Def extends ZodObjectDef>(def: Def) =>
43599
- // <Augmentation extends ZodRawShape>(
43600
- // augmentation: Augmentation
43601
- // ): ZodObject<
43602
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
43603
- // Def["unknownKeys"],
43604
- // Def["catchall"]
43605
- // > => {
43606
- // return new ZodObject({
43607
- // ...def,
43608
- // shape: () => ({
43609
- // ...def.shape(),
43610
- // ...augmentation,
43611
- // }),
43612
- // }) as any;
43613
- // };
43614
- extend(augmentation) {
43615
- return new _ZodObject({
43616
- ...this._def,
43617
- shape: () => ({
43618
- ...this._def.shape(),
43619
- ...augmentation
43620
- })
43621
- });
43622
- }
43623
- /**
43624
- * Prior to zod@1.0.12 there was a bug in the
43625
- * inferred type of merged objects. Please
43626
- * upgrade if you are experiencing issues.
43627
- */
43628
- merge(merging) {
43629
- const merged = new _ZodObject({
43630
- unknownKeys: merging._def.unknownKeys,
43631
- catchall: merging._def.catchall,
43632
- shape: () => ({
43633
- ...this._def.shape(),
43634
- ...merging._def.shape()
43635
- }),
43636
- typeName: ZodFirstPartyTypeKind.ZodObject
43637
- });
43638
- return merged;
43639
- }
43640
- // merge<
43641
- // Incoming extends AnyZodObject,
43642
- // Augmentation extends Incoming["shape"],
43643
- // NewOutput extends {
43644
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
43645
- // ? Augmentation[k]["_output"]
43646
- // : k extends keyof Output
43647
- // ? Output[k]
43648
- // : never;
43649
- // },
43650
- // NewInput extends {
43651
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
43652
- // ? Augmentation[k]["_input"]
43653
- // : k extends keyof Input
43654
- // ? Input[k]
43655
- // : never;
43656
- // }
43657
- // >(
43658
- // merging: Incoming
43659
- // ): ZodObject<
43660
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
43661
- // Incoming["_def"]["unknownKeys"],
43662
- // Incoming["_def"]["catchall"],
43663
- // NewOutput,
43664
- // NewInput
43665
- // > {
43666
- // const merged: any = new ZodObject({
43667
- // unknownKeys: merging._def.unknownKeys,
43668
- // catchall: merging._def.catchall,
43669
- // shape: () =>
43670
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
43671
- // typeName: ZodFirstPartyTypeKind.ZodObject,
43672
- // }) as any;
43673
- // return merged;
43674
- // }
43675
- setKey(key, schema) {
43676
- return this.augment({ [key]: schema });
43677
- }
43678
- // merge<Incoming extends AnyZodObject>(
43679
- // merging: Incoming
43680
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
43681
- // ZodObject<
43682
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
43683
- // Incoming["_def"]["unknownKeys"],
43684
- // Incoming["_def"]["catchall"]
43685
- // > {
43686
- // // const mergedShape = objectUtil.mergeShapes(
43687
- // // this._def.shape(),
43688
- // // merging._def.shape()
43689
- // // );
43690
- // const merged: any = new ZodObject({
43691
- // unknownKeys: merging._def.unknownKeys,
43692
- // catchall: merging._def.catchall,
43693
- // shape: () =>
43694
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
43695
- // typeName: ZodFirstPartyTypeKind.ZodObject,
43696
- // }) as any;
43697
- // return merged;
43698
- // }
43699
- catchall(index) {
43700
- return new _ZodObject({
43701
- ...this._def,
43702
- catchall: index
43703
- });
43704
- }
43705
- pick(mask) {
43706
- const shape = {};
43707
- for (const key of util.objectKeys(mask)) {
43708
- if (mask[key] && this.shape[key]) {
43709
- shape[key] = this.shape[key];
43710
- }
43711
- }
43712
- return new _ZodObject({
43713
- ...this._def,
43714
- shape: () => shape
43715
- });
43716
- }
43717
- omit(mask) {
43718
- const shape = {};
43719
- for (const key of util.objectKeys(this.shape)) {
43720
- if (!mask[key]) {
43721
- shape[key] = this.shape[key];
43722
- }
43723
- }
43724
- return new _ZodObject({
43725
- ...this._def,
43726
- shape: () => shape
43727
- });
43728
- }
43729
- /**
43730
- * @deprecated
43731
- */
43732
- deepPartial() {
43733
- return deepPartialify(this);
43734
- }
43735
- partial(mask) {
43736
- const newShape = {};
43737
- for (const key of util.objectKeys(this.shape)) {
43738
- const fieldSchema = this.shape[key];
43739
- if (mask && !mask[key]) {
43740
- newShape[key] = fieldSchema;
43741
- } else {
43742
- newShape[key] = fieldSchema.optional();
43743
- }
43744
- }
43745
- return new _ZodObject({
43746
- ...this._def,
43747
- shape: () => newShape
43748
- });
43749
- }
43750
- required(mask) {
43751
- const newShape = {};
43752
- for (const key of util.objectKeys(this.shape)) {
43753
- if (mask && !mask[key]) {
43754
- newShape[key] = this.shape[key];
43755
- } else {
43756
- const fieldSchema = this.shape[key];
43757
- let newField = fieldSchema;
43758
- while (newField instanceof ZodOptional) {
43759
- newField = newField._def.innerType;
43760
- }
43761
- newShape[key] = newField;
43762
- }
43763
- }
43764
- return new _ZodObject({
43765
- ...this._def,
43766
- shape: () => newShape
43767
- });
43768
- }
43769
- keyof() {
43770
- return createZodEnum(util.objectKeys(this.shape));
43771
- }
43772
- };
43773
- ZodObject.create = (shape, params) => {
43774
- return new ZodObject({
43775
- shape: () => shape,
43776
- unknownKeys: "strip",
43777
- catchall: ZodNever.create(),
43778
- typeName: ZodFirstPartyTypeKind.ZodObject,
43779
- ...processCreateParams(params)
43780
- });
43781
- };
43782
- ZodObject.strictCreate = (shape, params) => {
43783
- return new ZodObject({
43784
- shape: () => shape,
43785
- unknownKeys: "strict",
43786
- catchall: ZodNever.create(),
43787
- typeName: ZodFirstPartyTypeKind.ZodObject,
43788
- ...processCreateParams(params)
43789
- });
43790
- };
43791
- ZodObject.lazycreate = (shape, params) => {
43792
- return new ZodObject({
43793
- shape,
43794
- unknownKeys: "strip",
43795
- catchall: ZodNever.create(),
43796
- typeName: ZodFirstPartyTypeKind.ZodObject,
43797
- ...processCreateParams(params)
43798
- });
43799
- };
43800
- var ZodUnion = class extends ZodType {
43801
- _parse(input) {
43802
- const { ctx } = this._processInputParams(input);
43803
- const options = this._def.options;
43804
- function handleResults(results) {
43805
- for (const result of results) {
43806
- if (result.result.status === "valid") {
43807
- return result.result;
43808
- }
43809
- }
43810
- for (const result of results) {
43811
- if (result.result.status === "dirty") {
43812
- ctx.common.issues.push(...result.ctx.common.issues);
43813
- return result.result;
43814
- }
43815
- }
43816
- const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
43817
- addIssueToContext(ctx, {
43818
- code: ZodIssueCode2.invalid_union,
43819
- unionErrors
43820
- });
43821
- return INVALID;
43822
- }
43823
- if (ctx.common.async) {
43824
- return Promise.all(options.map(async (option) => {
43825
- const childCtx = {
43826
- ...ctx,
43827
- common: {
43828
- ...ctx.common,
43829
- issues: []
43830
- },
43831
- parent: null
43832
- };
43833
- return {
43834
- result: await option._parseAsync({
43835
- data: ctx.data,
43836
- path: ctx.path,
43837
- parent: childCtx
43838
- }),
43839
- ctx: childCtx
43840
- };
43841
- })).then(handleResults);
43842
- } else {
43843
- let dirty = void 0;
43844
- const issues = [];
43845
- for (const option of options) {
43846
- const childCtx = {
43847
- ...ctx,
43848
- common: {
43849
- ...ctx.common,
43850
- issues: []
43851
- },
43852
- parent: null
43853
- };
43854
- const result = option._parseSync({
43855
- data: ctx.data,
43856
- path: ctx.path,
43857
- parent: childCtx
43858
- });
43859
- if (result.status === "valid") {
43860
- return result;
43861
- } else if (result.status === "dirty" && !dirty) {
43862
- dirty = { result, ctx: childCtx };
43863
- }
43864
- if (childCtx.common.issues.length) {
43865
- issues.push(childCtx.common.issues);
43866
- }
43867
- }
43868
- if (dirty) {
43869
- ctx.common.issues.push(...dirty.ctx.common.issues);
43870
- return dirty.result;
43871
- }
43872
- const unionErrors = issues.map((issues2) => new ZodError(issues2));
43873
- addIssueToContext(ctx, {
43874
- code: ZodIssueCode2.invalid_union,
43875
- unionErrors
43876
- });
43877
- return INVALID;
43878
- }
43879
- }
43880
- get options() {
43881
- return this._def.options;
43882
- }
43883
- };
43884
- ZodUnion.create = (types, params) => {
43885
- return new ZodUnion({
43886
- options: types,
43887
- typeName: ZodFirstPartyTypeKind.ZodUnion,
43888
- ...processCreateParams(params)
43889
- });
43890
- };
43891
- var getDiscriminator = (type) => {
43892
- if (type instanceof ZodLazy) {
43893
- return getDiscriminator(type.schema);
43894
- } else if (type instanceof ZodEffects) {
43895
- return getDiscriminator(type.innerType());
43896
- } else if (type instanceof ZodLiteral) {
43897
- return [type.value];
43898
- } else if (type instanceof ZodEnum) {
43899
- return type.options;
43900
- } else if (type instanceof ZodNativeEnum) {
43901
- return util.objectValues(type.enum);
43902
- } else if (type instanceof ZodDefault) {
43903
- return getDiscriminator(type._def.innerType);
43904
- } else if (type instanceof ZodUndefined) {
43905
- return [void 0];
43906
- } else if (type instanceof ZodNull) {
43907
- return [null];
43908
- } else if (type instanceof ZodOptional) {
43909
- return [void 0, ...getDiscriminator(type.unwrap())];
43910
- } else if (type instanceof ZodNullable) {
43911
- return [null, ...getDiscriminator(type.unwrap())];
43912
- } else if (type instanceof ZodBranded) {
43913
- return getDiscriminator(type.unwrap());
43914
- } else if (type instanceof ZodReadonly) {
43915
- return getDiscriminator(type.unwrap());
43916
- } else if (type instanceof ZodCatch) {
43917
- return getDiscriminator(type._def.innerType);
43918
- } else {
43919
- return [];
43920
- }
43921
- };
43922
- var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
43923
- _parse(input) {
43924
- const { ctx } = this._processInputParams(input);
43925
- if (ctx.parsedType !== ZodParsedType.object) {
43926
- addIssueToContext(ctx, {
43927
- code: ZodIssueCode2.invalid_type,
43928
- expected: ZodParsedType.object,
43929
- received: ctx.parsedType
43930
- });
43931
- return INVALID;
43932
- }
43933
- const discriminator = this.discriminator;
43934
- const discriminatorValue = ctx.data[discriminator];
43935
- const option = this.optionsMap.get(discriminatorValue);
43936
- if (!option) {
43937
- addIssueToContext(ctx, {
43938
- code: ZodIssueCode2.invalid_union_discriminator,
43939
- options: Array.from(this.optionsMap.keys()),
43940
- path: [discriminator]
43941
- });
43942
- return INVALID;
43943
- }
43944
- if (ctx.common.async) {
43945
- return option._parseAsync({
43946
- data: ctx.data,
43947
- path: ctx.path,
43948
- parent: ctx
43949
- });
43950
- } else {
43951
- return option._parseSync({
43952
- data: ctx.data,
43953
- path: ctx.path,
43954
- parent: ctx
43955
- });
43956
- }
43957
- }
43958
- get discriminator() {
43959
- return this._def.discriminator;
43960
- }
43961
- get options() {
43962
- return this._def.options;
43963
- }
43964
- get optionsMap() {
43965
- return this._def.optionsMap;
43966
- }
43967
- /**
43968
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
43969
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
43970
- * have a different value for each object in the union.
43971
- * @param discriminator the name of the discriminator property
43972
- * @param types an array of object schemas
43973
- * @param params
43974
- */
43975
- static create(discriminator, options, params) {
43976
- const optionsMap = /* @__PURE__ */ new Map();
43977
- for (const type of options) {
43978
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
43979
- if (!discriminatorValues.length) {
43980
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
43981
- }
43982
- for (const value of discriminatorValues) {
43983
- if (optionsMap.has(value)) {
43984
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
43985
- }
43986
- optionsMap.set(value, type);
43987
- }
43988
- }
43989
- return new _ZodDiscriminatedUnion({
43990
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
43991
- discriminator,
43992
- options,
43993
- optionsMap,
43994
- ...processCreateParams(params)
43995
- });
43996
- }
43997
- };
43998
- function mergeValues(a, b) {
43999
- const aType = getParsedType(a);
44000
- const bType = getParsedType(b);
44001
- if (a === b) {
44002
- return { valid: true, data: a };
44003
- } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
44004
- const bKeys = util.objectKeys(b);
44005
- const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
44006
- const newObj = { ...a, ...b };
44007
- for (const key of sharedKeys) {
44008
- const sharedValue = mergeValues(a[key], b[key]);
44009
- if (!sharedValue.valid) {
44010
- return { valid: false };
44011
- }
44012
- newObj[key] = sharedValue.data;
44013
- }
44014
- return { valid: true, data: newObj };
44015
- } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
44016
- if (a.length !== b.length) {
44017
- return { valid: false };
44018
- }
44019
- const newArray = [];
44020
- for (let index = 0; index < a.length; index++) {
44021
- const itemA = a[index];
44022
- const itemB = b[index];
44023
- const sharedValue = mergeValues(itemA, itemB);
44024
- if (!sharedValue.valid) {
44025
- return { valid: false };
44026
- }
44027
- newArray.push(sharedValue.data);
44028
- }
44029
- return { valid: true, data: newArray };
44030
- } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
44031
- return { valid: true, data: a };
44032
- } else {
44033
- return { valid: false };
44034
- }
44035
- }
44036
- var ZodIntersection = class extends ZodType {
44037
- _parse(input) {
44038
- const { status, ctx } = this._processInputParams(input);
44039
- const handleParsed = (parsedLeft, parsedRight) => {
44040
- if (isAborted(parsedLeft) || isAborted(parsedRight)) {
44041
- return INVALID;
44042
- }
44043
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
44044
- if (!merged.valid) {
44045
- addIssueToContext(ctx, {
44046
- code: ZodIssueCode2.invalid_intersection_types
44047
- });
44048
- return INVALID;
44049
- }
44050
- if (isDirty(parsedLeft) || isDirty(parsedRight)) {
44051
- status.dirty();
44052
- }
44053
- return { status: status.value, value: merged.data };
44054
- };
44055
- if (ctx.common.async) {
44056
- return Promise.all([
44057
- this._def.left._parseAsync({
44058
- data: ctx.data,
44059
- path: ctx.path,
44060
- parent: ctx
44061
- }),
44062
- this._def.right._parseAsync({
44063
- data: ctx.data,
44064
- path: ctx.path,
44065
- parent: ctx
44066
- })
44067
- ]).then(([left, right]) => handleParsed(left, right));
44068
- } else {
44069
- return handleParsed(this._def.left._parseSync({
44070
- data: ctx.data,
44071
- path: ctx.path,
44072
- parent: ctx
44073
- }), this._def.right._parseSync({
44074
- data: ctx.data,
44075
- path: ctx.path,
44076
- parent: ctx
44077
- }));
44078
- }
44079
- }
44080
- };
44081
- ZodIntersection.create = (left, right, params) => {
44082
- return new ZodIntersection({
44083
- left,
44084
- right,
44085
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
44086
- ...processCreateParams(params)
44087
- });
44088
- };
44089
- var ZodTuple = class _ZodTuple extends ZodType {
44090
- _parse(input) {
44091
- const { status, ctx } = this._processInputParams(input);
44092
- if (ctx.parsedType !== ZodParsedType.array) {
44093
- addIssueToContext(ctx, {
44094
- code: ZodIssueCode2.invalid_type,
44095
- expected: ZodParsedType.array,
44096
- received: ctx.parsedType
44097
- });
44098
- return INVALID;
44099
- }
44100
- if (ctx.data.length < this._def.items.length) {
44101
- addIssueToContext(ctx, {
44102
- code: ZodIssueCode2.too_small,
44103
- minimum: this._def.items.length,
44104
- inclusive: true,
44105
- exact: false,
44106
- type: "array"
44107
- });
44108
- return INVALID;
44109
- }
44110
- const rest = this._def.rest;
44111
- if (!rest && ctx.data.length > this._def.items.length) {
44112
- addIssueToContext(ctx, {
44113
- code: ZodIssueCode2.too_big,
44114
- maximum: this._def.items.length,
44115
- inclusive: true,
44116
- exact: false,
44117
- type: "array"
44118
- });
44119
- status.dirty();
44120
- }
44121
- const items = [...ctx.data].map((item, itemIndex) => {
44122
- const schema = this._def.items[itemIndex] || this._def.rest;
44123
- if (!schema)
44124
- return null;
44125
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
44126
- }).filter((x) => !!x);
44127
- if (ctx.common.async) {
44128
- return Promise.all(items).then((results) => {
44129
- return ParseStatus.mergeArray(status, results);
44130
- });
44131
- } else {
44132
- return ParseStatus.mergeArray(status, items);
44133
- }
44134
- }
44135
- get items() {
44136
- return this._def.items;
44137
- }
44138
- rest(rest) {
44139
- return new _ZodTuple({
44140
- ...this._def,
44141
- rest
44142
- });
44143
- }
44144
- };
44145
- ZodTuple.create = (schemas, params) => {
44146
- if (!Array.isArray(schemas)) {
44147
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
44148
- }
44149
- return new ZodTuple({
44150
- items: schemas,
44151
- typeName: ZodFirstPartyTypeKind.ZodTuple,
44152
- rest: null,
44153
- ...processCreateParams(params)
44154
- });
44155
- };
44156
- var ZodRecord = class _ZodRecord extends ZodType {
44157
- get keySchema() {
44158
- return this._def.keyType;
44159
- }
44160
- get valueSchema() {
44161
- return this._def.valueType;
44162
- }
44163
- _parse(input) {
44164
- const { status, ctx } = this._processInputParams(input);
44165
- if (ctx.parsedType !== ZodParsedType.object) {
44166
- addIssueToContext(ctx, {
44167
- code: ZodIssueCode2.invalid_type,
44168
- expected: ZodParsedType.object,
44169
- received: ctx.parsedType
44170
- });
44171
- return INVALID;
44172
- }
44173
- const pairs = [];
44174
- const keyType = this._def.keyType;
44175
- const valueType3 = this._def.valueType;
44176
- for (const key in ctx.data) {
44177
- pairs.push({
44178
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
44179
- value: valueType3._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
44180
- alwaysSet: key in ctx.data
44181
- });
44182
- }
44183
- if (ctx.common.async) {
44184
- return ParseStatus.mergeObjectAsync(status, pairs);
44185
- } else {
44186
- return ParseStatus.mergeObjectSync(status, pairs);
44187
- }
44188
- }
44189
- get element() {
44190
- return this._def.valueType;
44191
- }
44192
- static create(first, second, third) {
44193
- if (second instanceof ZodType) {
44194
- return new _ZodRecord({
44195
- keyType: first,
44196
- valueType: second,
44197
- typeName: ZodFirstPartyTypeKind.ZodRecord,
44198
- ...processCreateParams(third)
44199
- });
44200
- }
44201
- return new _ZodRecord({
44202
- keyType: ZodString.create(),
44203
- valueType: first,
44204
- typeName: ZodFirstPartyTypeKind.ZodRecord,
44205
- ...processCreateParams(second)
44206
- });
44207
- }
44208
- };
44209
- var ZodMap = class extends ZodType {
44210
- get keySchema() {
44211
- return this._def.keyType;
44212
- }
44213
- get valueSchema() {
44214
- return this._def.valueType;
44215
- }
44216
- _parse(input) {
44217
- const { status, ctx } = this._processInputParams(input);
44218
- if (ctx.parsedType !== ZodParsedType.map) {
44219
- addIssueToContext(ctx, {
44220
- code: ZodIssueCode2.invalid_type,
44221
- expected: ZodParsedType.map,
44222
- received: ctx.parsedType
44223
- });
44224
- return INVALID;
44225
- }
44226
- const keyType = this._def.keyType;
44227
- const valueType3 = this._def.valueType;
44228
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
44229
- return {
44230
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
44231
- value: valueType3._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
44232
- };
44233
- });
44234
- if (ctx.common.async) {
44235
- const finalMap = /* @__PURE__ */ new Map();
44236
- return Promise.resolve().then(async () => {
44237
- for (const pair of pairs) {
44238
- const key = await pair.key;
44239
- const value = await pair.value;
44240
- if (key.status === "aborted" || value.status === "aborted") {
44241
- return INVALID;
44242
- }
44243
- if (key.status === "dirty" || value.status === "dirty") {
44244
- status.dirty();
44245
- }
44246
- finalMap.set(key.value, value.value);
44247
- }
44248
- return { status: status.value, value: finalMap };
44249
- });
44250
- } else {
44251
- const finalMap = /* @__PURE__ */ new Map();
44252
- for (const pair of pairs) {
44253
- const key = pair.key;
44254
- const value = pair.value;
44255
- if (key.status === "aborted" || value.status === "aborted") {
44256
- return INVALID;
44257
- }
44258
- if (key.status === "dirty" || value.status === "dirty") {
44259
- status.dirty();
44260
- }
44261
- finalMap.set(key.value, value.value);
44262
- }
44263
- return { status: status.value, value: finalMap };
44264
- }
44265
- }
44266
- };
44267
- ZodMap.create = (keyType, valueType3, params) => {
44268
- return new ZodMap({
44269
- valueType: valueType3,
44270
- keyType,
44271
- typeName: ZodFirstPartyTypeKind.ZodMap,
44272
- ...processCreateParams(params)
44273
- });
44274
- };
44275
- var ZodSet = class _ZodSet extends ZodType {
44276
- _parse(input) {
44277
- const { status, ctx } = this._processInputParams(input);
44278
- if (ctx.parsedType !== ZodParsedType.set) {
44279
- addIssueToContext(ctx, {
44280
- code: ZodIssueCode2.invalid_type,
44281
- expected: ZodParsedType.set,
44282
- received: ctx.parsedType
44283
- });
44284
- return INVALID;
44285
- }
44286
- const def = this._def;
44287
- if (def.minSize !== null) {
44288
- if (ctx.data.size < def.minSize.value) {
44289
- addIssueToContext(ctx, {
44290
- code: ZodIssueCode2.too_small,
44291
- minimum: def.minSize.value,
44292
- type: "set",
44293
- inclusive: true,
44294
- exact: false,
44295
- message: def.minSize.message
44296
- });
44297
- status.dirty();
44298
- }
44299
- }
44300
- if (def.maxSize !== null) {
44301
- if (ctx.data.size > def.maxSize.value) {
44302
- addIssueToContext(ctx, {
44303
- code: ZodIssueCode2.too_big,
44304
- maximum: def.maxSize.value,
44305
- type: "set",
44306
- inclusive: true,
44307
- exact: false,
44308
- message: def.maxSize.message
44309
- });
44310
- status.dirty();
44311
- }
44312
- }
44313
- const valueType3 = this._def.valueType;
44314
- function finalizeSet(elements2) {
44315
- const parsedSet = /* @__PURE__ */ new Set();
44316
- for (const element of elements2) {
44317
- if (element.status === "aborted")
44318
- return INVALID;
44319
- if (element.status === "dirty")
44320
- status.dirty();
44321
- parsedSet.add(element.value);
44322
- }
44323
- return { status: status.value, value: parsedSet };
44324
- }
44325
- const elements = [...ctx.data.values()].map((item, i) => valueType3._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
44326
- if (ctx.common.async) {
44327
- return Promise.all(elements).then((elements2) => finalizeSet(elements2));
44328
- } else {
44329
- return finalizeSet(elements);
44330
- }
44331
- }
44332
- min(minSize, message) {
44333
- return new _ZodSet({
44334
- ...this._def,
44335
- minSize: { value: minSize, message: errorUtil.toString(message) }
44336
- });
44337
- }
44338
- max(maxSize, message) {
44339
- return new _ZodSet({
44340
- ...this._def,
44341
- maxSize: { value: maxSize, message: errorUtil.toString(message) }
44342
- });
44343
- }
44344
- size(size, message) {
44345
- return this.min(size, message).max(size, message);
44346
- }
44347
- nonempty(message) {
44348
- return this.min(1, message);
44349
- }
44350
- };
44351
- ZodSet.create = (valueType3, params) => {
44352
- return new ZodSet({
44353
- valueType: valueType3,
44354
- minSize: null,
44355
- maxSize: null,
44356
- typeName: ZodFirstPartyTypeKind.ZodSet,
44357
- ...processCreateParams(params)
44358
- });
44359
- };
44360
- var ZodFunction = class _ZodFunction extends ZodType {
44361
- constructor() {
44362
- super(...arguments);
44363
- this.validate = this.implement;
44364
- }
44365
- _parse(input) {
44366
- const { ctx } = this._processInputParams(input);
44367
- if (ctx.parsedType !== ZodParsedType.function) {
44368
- addIssueToContext(ctx, {
44369
- code: ZodIssueCode2.invalid_type,
44370
- expected: ZodParsedType.function,
44371
- received: ctx.parsedType
44372
- });
44373
- return INVALID;
44374
- }
44375
- function makeArgsIssue(args, error) {
44376
- return makeIssue({
44377
- data: args,
44378
- path: ctx.path,
44379
- errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
44380
- issueData: {
44381
- code: ZodIssueCode2.invalid_arguments,
44382
- argumentsError: error
44383
- }
44384
- });
44385
- }
44386
- function makeReturnsIssue(returns, error) {
44387
- return makeIssue({
44388
- data: returns,
44389
- path: ctx.path,
44390
- errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
44391
- issueData: {
44392
- code: ZodIssueCode2.invalid_return_type,
44393
- returnTypeError: error
44394
- }
44395
- });
44396
- }
44397
- const params = { errorMap: ctx.common.contextualErrorMap };
44398
- const fn = ctx.data;
44399
- if (this._def.returns instanceof ZodPromise) {
44400
- const me = this;
44401
- return OK(async function(...args) {
44402
- const error = new ZodError([]);
44403
- const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
44404
- error.addIssue(makeArgsIssue(args, e));
44405
- throw error;
44406
- });
44407
- const result = await Reflect.apply(fn, this, parsedArgs);
44408
- const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
44409
- error.addIssue(makeReturnsIssue(result, e));
44410
- throw error;
44411
- });
44412
- return parsedReturns;
44413
- });
44414
- } else {
44415
- const me = this;
44416
- return OK(function(...args) {
44417
- const parsedArgs = me._def.args.safeParse(args, params);
44418
- if (!parsedArgs.success) {
44419
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
44420
- }
44421
- const result = Reflect.apply(fn, this, parsedArgs.data);
44422
- const parsedReturns = me._def.returns.safeParse(result, params);
44423
- if (!parsedReturns.success) {
44424
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
44425
- }
44426
- return parsedReturns.data;
44427
- });
44428
- }
44429
- }
44430
- parameters() {
44431
- return this._def.args;
44432
- }
44433
- returnType() {
44434
- return this._def.returns;
44435
- }
44436
- args(...items) {
44437
- return new _ZodFunction({
44438
- ...this._def,
44439
- args: ZodTuple.create(items).rest(ZodUnknown.create())
44440
- });
44441
- }
44442
- returns(returnType) {
44443
- return new _ZodFunction({
44444
- ...this._def,
44445
- returns: returnType
44446
- });
44447
- }
44448
- implement(func) {
44449
- const validatedFunc = this.parse(func);
44450
- return validatedFunc;
44451
- }
44452
- strictImplement(func) {
44453
- const validatedFunc = this.parse(func);
44454
- return validatedFunc;
44455
- }
44456
- static create(args, returns, params) {
44457
- return new _ZodFunction({
44458
- args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
44459
- returns: returns || ZodUnknown.create(),
44460
- typeName: ZodFirstPartyTypeKind.ZodFunction,
44461
- ...processCreateParams(params)
44462
- });
44463
- }
44464
- };
44465
- var ZodLazy = class extends ZodType {
44466
- get schema() {
44467
- return this._def.getter();
44468
- }
44469
- _parse(input) {
44470
- const { ctx } = this._processInputParams(input);
44471
- const lazySchema = this._def.getter();
44472
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
44473
- }
44474
- };
44475
- ZodLazy.create = (getter, params) => {
44476
- return new ZodLazy({
44477
- getter,
44478
- typeName: ZodFirstPartyTypeKind.ZodLazy,
44479
- ...processCreateParams(params)
44480
- });
44481
- };
44482
- var ZodLiteral = class extends ZodType {
44483
- _parse(input) {
44484
- if (input.data !== this._def.value) {
44485
- const ctx = this._getOrReturnCtx(input);
44486
- addIssueToContext(ctx, {
44487
- received: ctx.data,
44488
- code: ZodIssueCode2.invalid_literal,
44489
- expected: this._def.value
44490
- });
44491
- return INVALID;
44492
- }
44493
- return { status: "valid", value: input.data };
44494
- }
44495
- get value() {
44496
- return this._def.value;
44497
- }
44498
- };
44499
- ZodLiteral.create = (value, params) => {
44500
- return new ZodLiteral({
44501
- value,
44502
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
44503
- ...processCreateParams(params)
44504
- });
44505
- };
44506
- function createZodEnum(values, params) {
44507
- return new ZodEnum({
44508
- values,
44509
- typeName: ZodFirstPartyTypeKind.ZodEnum,
44510
- ...processCreateParams(params)
44511
- });
44512
- }
44513
- var ZodEnum = class _ZodEnum extends ZodType {
44514
- _parse(input) {
44515
- if (typeof input.data !== "string") {
44516
- const ctx = this._getOrReturnCtx(input);
44517
- const expectedValues = this._def.values;
44518
- addIssueToContext(ctx, {
44519
- expected: util.joinValues(expectedValues),
44520
- received: ctx.parsedType,
44521
- code: ZodIssueCode2.invalid_type
44522
- });
44523
- return INVALID;
44524
- }
44525
- if (!this._cache) {
44526
- this._cache = new Set(this._def.values);
44527
- }
44528
- if (!this._cache.has(input.data)) {
44529
- const ctx = this._getOrReturnCtx(input);
44530
- const expectedValues = this._def.values;
44531
- addIssueToContext(ctx, {
44532
- received: ctx.data,
44533
- code: ZodIssueCode2.invalid_enum_value,
44534
- options: expectedValues
44535
- });
44536
- return INVALID;
44537
- }
44538
- return OK(input.data);
44539
- }
44540
- get options() {
44541
- return this._def.values;
44542
- }
44543
- get enum() {
44544
- const enumValues = {};
44545
- for (const val of this._def.values) {
44546
- enumValues[val] = val;
44547
- }
44548
- return enumValues;
44549
- }
44550
- get Values() {
44551
- const enumValues = {};
44552
- for (const val of this._def.values) {
44553
- enumValues[val] = val;
44554
- }
44555
- return enumValues;
44556
- }
44557
- get Enum() {
44558
- const enumValues = {};
44559
- for (const val of this._def.values) {
44560
- enumValues[val] = val;
44561
- }
44562
- return enumValues;
44563
- }
44564
- extract(values, newDef = this._def) {
44565
- return _ZodEnum.create(values, {
44566
- ...this._def,
44567
- ...newDef
44568
- });
44569
- }
44570
- exclude(values, newDef = this._def) {
44571
- return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
44572
- ...this._def,
44573
- ...newDef
44574
- });
44575
- }
44576
- };
44577
- ZodEnum.create = createZodEnum;
44578
- var ZodNativeEnum = class extends ZodType {
44579
- _parse(input) {
44580
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
44581
- const ctx = this._getOrReturnCtx(input);
44582
- if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
44583
- const expectedValues = util.objectValues(nativeEnumValues);
44584
- addIssueToContext(ctx, {
44585
- expected: util.joinValues(expectedValues),
44586
- received: ctx.parsedType,
44587
- code: ZodIssueCode2.invalid_type
44588
- });
44589
- return INVALID;
44590
- }
44591
- if (!this._cache) {
44592
- this._cache = new Set(util.getValidEnumValues(this._def.values));
44593
- }
44594
- if (!this._cache.has(input.data)) {
44595
- const expectedValues = util.objectValues(nativeEnumValues);
44596
- addIssueToContext(ctx, {
44597
- received: ctx.data,
44598
- code: ZodIssueCode2.invalid_enum_value,
44599
- options: expectedValues
44600
- });
44601
- return INVALID;
44602
- }
44603
- return OK(input.data);
44604
- }
44605
- get enum() {
44606
- return this._def.values;
44607
- }
44608
- };
44609
- ZodNativeEnum.create = (values, params) => {
44610
- return new ZodNativeEnum({
44611
- values,
44612
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
44613
- ...processCreateParams(params)
44614
- });
44615
- };
44616
- var ZodPromise = class extends ZodType {
44617
- unwrap() {
44618
- return this._def.type;
44619
- }
44620
- _parse(input) {
44621
- const { ctx } = this._processInputParams(input);
44622
- if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
44623
- addIssueToContext(ctx, {
44624
- code: ZodIssueCode2.invalid_type,
44625
- expected: ZodParsedType.promise,
44626
- received: ctx.parsedType
44627
- });
44628
- return INVALID;
44629
- }
44630
- const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
44631
- return OK(promisified.then((data) => {
44632
- return this._def.type.parseAsync(data, {
44633
- path: ctx.path,
44634
- errorMap: ctx.common.contextualErrorMap
44635
- });
44636
- }));
44637
- }
44638
- };
44639
- ZodPromise.create = (schema, params) => {
44640
- return new ZodPromise({
44641
- type: schema,
44642
- typeName: ZodFirstPartyTypeKind.ZodPromise,
44643
- ...processCreateParams(params)
44644
- });
44645
- };
44646
- var ZodEffects = class extends ZodType {
44647
- innerType() {
44648
- return this._def.schema;
44649
- }
44650
- sourceType() {
44651
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
44652
- }
44653
- _parse(input) {
44654
- const { status, ctx } = this._processInputParams(input);
44655
- const effect = this._def.effect || null;
44656
- const checkCtx = {
44657
- addIssue: (arg) => {
44658
- addIssueToContext(ctx, arg);
44659
- if (arg.fatal) {
44660
- status.abort();
44661
- } else {
44662
- status.dirty();
44663
- }
44664
- },
44665
- get path() {
44666
- return ctx.path;
44667
- }
44668
- };
44669
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
44670
- if (effect.type === "preprocess") {
44671
- const processed = effect.transform(ctx.data, checkCtx);
44672
- if (ctx.common.async) {
44673
- return Promise.resolve(processed).then(async (processed2) => {
44674
- if (status.value === "aborted")
44675
- return INVALID;
44676
- const result = await this._def.schema._parseAsync({
44677
- data: processed2,
44678
- path: ctx.path,
44679
- parent: ctx
44680
- });
44681
- if (result.status === "aborted")
44682
- return INVALID;
44683
- if (result.status === "dirty")
44684
- return DIRTY(result.value);
44685
- if (status.value === "dirty")
44686
- return DIRTY(result.value);
44687
- return result;
44688
- });
44689
- } else {
44690
- if (status.value === "aborted")
44691
- return INVALID;
44692
- const result = this._def.schema._parseSync({
44693
- data: processed,
44694
- path: ctx.path,
44695
- parent: ctx
44696
- });
44697
- if (result.status === "aborted")
44698
- return INVALID;
44699
- if (result.status === "dirty")
44700
- return DIRTY(result.value);
44701
- if (status.value === "dirty")
44702
- return DIRTY(result.value);
44703
- return result;
44704
- }
44705
- }
44706
- if (effect.type === "refinement") {
44707
- const executeRefinement = (acc) => {
44708
- const result = effect.refinement(acc, checkCtx);
44709
- if (ctx.common.async) {
44710
- return Promise.resolve(result);
44711
- }
44712
- if (result instanceof Promise) {
44713
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
44714
- }
44715
- return acc;
44716
- };
44717
- if (ctx.common.async === false) {
44718
- const inner = this._def.schema._parseSync({
44719
- data: ctx.data,
44720
- path: ctx.path,
44721
- parent: ctx
44722
- });
44723
- if (inner.status === "aborted")
44724
- return INVALID;
44725
- if (inner.status === "dirty")
44726
- status.dirty();
44727
- executeRefinement(inner.value);
44728
- return { status: status.value, value: inner.value };
44729
- } else {
44730
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
44731
- if (inner.status === "aborted")
44732
- return INVALID;
44733
- if (inner.status === "dirty")
44734
- status.dirty();
44735
- return executeRefinement(inner.value).then(() => {
44736
- return { status: status.value, value: inner.value };
44737
- });
44738
- });
44739
- }
44740
- }
44741
- if (effect.type === "transform") {
44742
- if (ctx.common.async === false) {
44743
- const base = this._def.schema._parseSync({
44744
- data: ctx.data,
44745
- path: ctx.path,
44746
- parent: ctx
44747
- });
44748
- if (!isValid(base))
44749
- return INVALID;
44750
- const result = effect.transform(base.value, checkCtx);
44751
- if (result instanceof Promise) {
44752
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
44753
- }
44754
- return { status: status.value, value: result };
44755
- } else {
44756
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
44757
- if (!isValid(base))
44758
- return INVALID;
44759
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
44760
- status: status.value,
44761
- value: result
44762
- }));
44763
- });
44764
- }
44765
- }
44766
- util.assertNever(effect);
44767
- }
44768
- };
44769
- ZodEffects.create = (schema, effect, params) => {
44770
- return new ZodEffects({
44771
- schema,
44772
- typeName: ZodFirstPartyTypeKind.ZodEffects,
44773
- effect,
44774
- ...processCreateParams(params)
44775
- });
44776
- };
44777
- ZodEffects.createWithPreprocess = (preprocess2, schema, params) => {
44778
- return new ZodEffects({
44779
- schema,
44780
- effect: { type: "preprocess", transform: preprocess2 },
44781
- typeName: ZodFirstPartyTypeKind.ZodEffects,
44782
- ...processCreateParams(params)
44783
- });
44784
- };
44785
- var ZodOptional = class extends ZodType {
44786
- _parse(input) {
44787
- const parsedType = this._getType(input);
44788
- if (parsedType === ZodParsedType.undefined) {
44789
- return OK(void 0);
44790
- }
44791
- return this._def.innerType._parse(input);
44792
- }
44793
- unwrap() {
44794
- return this._def.innerType;
44795
- }
44796
- };
44797
- ZodOptional.create = (type, params) => {
44798
- return new ZodOptional({
44799
- innerType: type,
44800
- typeName: ZodFirstPartyTypeKind.ZodOptional,
44801
- ...processCreateParams(params)
44802
- });
44803
- };
44804
- var ZodNullable = class extends ZodType {
44805
- _parse(input) {
44806
- const parsedType = this._getType(input);
44807
- if (parsedType === ZodParsedType.null) {
44808
- return OK(null);
44809
- }
44810
- return this._def.innerType._parse(input);
44811
- }
44812
- unwrap() {
44813
- return this._def.innerType;
44814
- }
44815
- };
44816
- ZodNullable.create = (type, params) => {
44817
- return new ZodNullable({
44818
- innerType: type,
44819
- typeName: ZodFirstPartyTypeKind.ZodNullable,
44820
- ...processCreateParams(params)
44821
- });
44822
- };
44823
- var ZodDefault = class extends ZodType {
44824
- _parse(input) {
44825
- const { ctx } = this._processInputParams(input);
44826
- let data = ctx.data;
44827
- if (ctx.parsedType === ZodParsedType.undefined) {
44828
- data = this._def.defaultValue();
44829
- }
44830
- return this._def.innerType._parse({
44831
- data,
44832
- path: ctx.path,
44833
- parent: ctx
44834
- });
44835
- }
44836
- removeDefault() {
44837
- return this._def.innerType;
44838
- }
44839
- };
44840
- ZodDefault.create = (type, params) => {
44841
- return new ZodDefault({
44842
- innerType: type,
44843
- typeName: ZodFirstPartyTypeKind.ZodDefault,
44844
- defaultValue: typeof params.default === "function" ? params.default : () => params.default,
44845
- ...processCreateParams(params)
44846
- });
44847
- };
44848
- var ZodCatch = class extends ZodType {
44849
- _parse(input) {
44850
- const { ctx } = this._processInputParams(input);
44851
- const newCtx = {
44852
- ...ctx,
44853
- common: {
44854
- ...ctx.common,
44855
- issues: []
44856
- }
44857
- };
44858
- const result = this._def.innerType._parse({
44859
- data: newCtx.data,
44860
- path: newCtx.path,
44861
- parent: {
44862
- ...newCtx
44863
- }
44864
- });
44865
- if (isAsync(result)) {
44866
- return result.then((result2) => {
44867
- return {
44868
- status: "valid",
44869
- value: result2.status === "valid" ? result2.value : this._def.catchValue({
44870
- get error() {
44871
- return new ZodError(newCtx.common.issues);
44872
- },
44873
- input: newCtx.data
44874
- })
44875
- };
44876
- });
44877
- } else {
44878
- return {
44879
- status: "valid",
44880
- value: result.status === "valid" ? result.value : this._def.catchValue({
44881
- get error() {
44882
- return new ZodError(newCtx.common.issues);
44883
- },
44884
- input: newCtx.data
44885
- })
44886
- };
44887
- }
44888
- }
44889
- removeCatch() {
44890
- return this._def.innerType;
44891
- }
44892
- };
44893
- ZodCatch.create = (type, params) => {
44894
- return new ZodCatch({
44895
- innerType: type,
44896
- typeName: ZodFirstPartyTypeKind.ZodCatch,
44897
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
44898
- ...processCreateParams(params)
44899
- });
44900
- };
44901
- var ZodNaN = class extends ZodType {
44902
- _parse(input) {
44903
- const parsedType = this._getType(input);
44904
- if (parsedType !== ZodParsedType.nan) {
44905
- const ctx = this._getOrReturnCtx(input);
44906
- addIssueToContext(ctx, {
44907
- code: ZodIssueCode2.invalid_type,
44908
- expected: ZodParsedType.nan,
44909
- received: ctx.parsedType
44910
- });
44911
- return INVALID;
44912
- }
44913
- return { status: "valid", value: input.data };
44914
- }
44915
- };
44916
- ZodNaN.create = (params) => {
44917
- return new ZodNaN({
44918
- typeName: ZodFirstPartyTypeKind.ZodNaN,
44919
- ...processCreateParams(params)
44920
- });
44921
- };
44922
- var BRAND = Symbol("zod_brand");
44923
- var ZodBranded = class extends ZodType {
44924
- _parse(input) {
44925
- const { ctx } = this._processInputParams(input);
44926
- const data = ctx.data;
44927
- return this._def.type._parse({
44928
- data,
44929
- path: ctx.path,
44930
- parent: ctx
44931
- });
44932
- }
44933
- unwrap() {
44934
- return this._def.type;
44935
- }
44936
- };
44937
- var ZodPipeline = class _ZodPipeline extends ZodType {
44938
- _parse(input) {
44939
- const { status, ctx } = this._processInputParams(input);
44940
- if (ctx.common.async) {
44941
- const handleAsync = async () => {
44942
- const inResult = await this._def.in._parseAsync({
44943
- data: ctx.data,
44944
- path: ctx.path,
44945
- parent: ctx
44946
- });
44947
- if (inResult.status === "aborted")
44948
- return INVALID;
44949
- if (inResult.status === "dirty") {
44950
- status.dirty();
44951
- return DIRTY(inResult.value);
44952
- } else {
44953
- return this._def.out._parseAsync({
44954
- data: inResult.value,
44955
- path: ctx.path,
44956
- parent: ctx
44957
- });
44958
- }
44959
- };
44960
- return handleAsync();
44961
- } else {
44962
- const inResult = this._def.in._parseSync({
44963
- data: ctx.data,
44964
- path: ctx.path,
44965
- parent: ctx
44966
- });
44967
- if (inResult.status === "aborted")
44968
- return INVALID;
44969
- if (inResult.status === "dirty") {
44970
- status.dirty();
44971
- return {
44972
- status: "dirty",
44973
- value: inResult.value
44974
- };
44975
- } else {
44976
- return this._def.out._parseSync({
44977
- data: inResult.value,
44978
- path: ctx.path,
44979
- parent: ctx
44980
- });
44981
- }
44982
- }
44983
- }
44984
- static create(a, b) {
44985
- return new _ZodPipeline({
44986
- in: a,
44987
- out: b,
44988
- typeName: ZodFirstPartyTypeKind.ZodPipeline
44989
- });
44990
- }
44991
- };
44992
- var ZodReadonly = class extends ZodType {
44993
- _parse(input) {
44994
- const result = this._def.innerType._parse(input);
44995
- const freeze = (data) => {
44996
- if (isValid(data)) {
44997
- data.value = Object.freeze(data.value);
44998
- }
44999
- return data;
45000
- };
45001
- return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
45002
- }
45003
- unwrap() {
45004
- return this._def.innerType;
45005
- }
45006
- };
45007
- ZodReadonly.create = (type, params) => {
45008
- return new ZodReadonly({
45009
- innerType: type,
45010
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
45011
- ...processCreateParams(params)
45012
- });
45013
- };
45014
- function cleanParams(params, data) {
45015
- const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
45016
- const p2 = typeof p === "string" ? { message: p } : p;
45017
- return p2;
45018
- }
45019
- function custom2(check, _params = {}, fatal) {
45020
- if (check)
45021
- return ZodAny.create().superRefine((data, ctx) => {
45022
- const r = check(data);
45023
- if (r instanceof Promise) {
45024
- return r.then((r2) => {
45025
- if (!r2) {
45026
- const params = cleanParams(_params, data);
45027
- const _fatal = params.fatal ?? fatal ?? true;
45028
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
45029
- }
45030
- });
45031
- }
45032
- if (!r) {
45033
- const params = cleanParams(_params, data);
45034
- const _fatal = params.fatal ?? fatal ?? true;
45035
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
45036
- }
45037
- return;
45038
- });
45039
- return ZodAny.create();
45040
- }
45041
- var late = {
45042
- object: ZodObject.lazycreate
45043
- };
45044
- var ZodFirstPartyTypeKind;
45045
- (function(ZodFirstPartyTypeKind2) {
45046
- ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
45047
- ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
45048
- ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
45049
- ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
45050
- ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
45051
- ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
45052
- ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
45053
- ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
45054
- ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
45055
- ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
45056
- ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
45057
- ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
45058
- ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
45059
- ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
45060
- ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
45061
- ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
45062
- ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
45063
- ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
45064
- ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
45065
- ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
45066
- ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
45067
- ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
45068
- ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
45069
- ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
45070
- ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
45071
- ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
45072
- ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
45073
- ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
45074
- ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
45075
- ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
45076
- ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
45077
- ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
45078
- ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
45079
- ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
45080
- ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
45081
- ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
45082
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
45083
- var instanceOfType = (cls, params = {
45084
- message: `Input not instance of ${cls.name}`
45085
- }) => custom2((data) => data instanceof cls, params);
45086
- var stringType = ZodString.create;
45087
- var numberType = ZodNumber.create;
45088
- var nanType = ZodNaN.create;
45089
- var bigIntType = ZodBigInt.create;
45090
- var booleanType = ZodBoolean.create;
45091
- var dateType = ZodDate.create;
45092
- var symbolType = ZodSymbol.create;
45093
- var undefinedType = ZodUndefined.create;
45094
- var nullType = ZodNull.create;
45095
- var anyType = ZodAny.create;
45096
- var unknownType = ZodUnknown.create;
45097
- var neverType = ZodNever.create;
45098
- var voidType = ZodVoid.create;
45099
- var arrayType = ZodArray.create;
45100
- var objectType = ZodObject.create;
45101
- var strictObjectType = ZodObject.strictCreate;
45102
- var unionType = ZodUnion.create;
45103
- var discriminatedUnionType = ZodDiscriminatedUnion.create;
45104
- var intersectionType = ZodIntersection.create;
45105
- var tupleType = ZodTuple.create;
45106
- var recordType = ZodRecord.create;
45107
- var mapType = ZodMap.create;
45108
- var setType = ZodSet.create;
45109
- var functionType = ZodFunction.create;
45110
- var lazyType = ZodLazy.create;
45111
- var literalType = ZodLiteral.create;
45112
- var enumType = ZodEnum.create;
45113
- var nativeEnumType = ZodNativeEnum.create;
45114
- var promiseType = ZodPromise.create;
45115
- var effectsType = ZodEffects.create;
45116
- var optionalType = ZodOptional.create;
45117
- var nullableType = ZodNullable.create;
45118
- var preprocessType = ZodEffects.createWithPreprocess;
45119
- var pipelineType = ZodPipeline.create;
45120
- var ostring = () => stringType().optional();
45121
- var onumber = () => numberType().optional();
45122
- var oboolean = () => booleanType().optional();
45123
- var coerce = {
45124
- string: (arg) => ZodString.create({ ...arg, coerce: true }),
45125
- number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
45126
- boolean: (arg) => ZodBoolean.create({
45127
- ...arg,
45128
- coerce: true
45129
- }),
45130
- bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
45131
- date: (arg) => ZodDate.create({ ...arg, coerce: true })
45132
- };
45133
- var NEVER2 = INVALID;
45134
-
45135
41311
  // ../../node_modules/@ag-ui/core/dist/index.mjs
45136
41312
  var FunctionCallSchema = external_exports.object({
45137
41313
  name: external_exports.string(),
@@ -46195,6 +42371,11 @@ var ApassConfirmationFailedError = class extends Error {
46195
42371
  super("\u6388\u6743\u672A\u6210\u529F\uFF0C\u8BF7\u91CD\u65B0\u786E\u8BA4\u6388\u6743");
46196
42372
  }
46197
42373
  };
42374
+ var ApassIssueResultUnavailableError = class extends Error {
42375
+ constructor() {
42376
+ super("\u6682\u65E0\u53EF\u6062\u590D\u7684 APASS \u7B7E\u53D1\u7ED3\u679C");
42377
+ }
42378
+ };
46198
42379
  var ApassAuthorizationRequiredError = class extends Error {
46199
42380
  challenge;
46200
42381
  code = "APASS_AUTHORIZATION_REQUIRED";
@@ -46276,6 +42457,12 @@ async function invokeApassAuthorization(baseUrl, authorization, operation, body,
46276
42457
  });
46277
42458
  if (operation === "confirmAuth" && envelope.success === false && envelope.errorCode === "APASS_CONFIRM_FAILED")
46278
42459
  throw new ApassConfirmationFailedError();
42460
+ if (operation === "issueResult" && envelope.success === false && [
42461
+ "APASS_ISSUE_RESULT_UNAVAILABLE",
42462
+ "APASS_AUTH_SESSION_EXPIRED",
42463
+ "APASS_AUTH_POLICY_CHANGED"
42464
+ ].includes(String(envelope.errorCode)))
42465
+ throw new ApassIssueResultUnavailableError();
46279
42466
  if (operation === "confirmToken" && envelope.success === false && [
46280
42467
  "APASS_AUTH_POLICY_UNAVAILABLE",
46281
42468
  "APASS_IDENTITY_UNAVAILABLE",
@@ -46290,7 +42477,7 @@ async function invokeApassAuthorization(baseUrl, authorization, operation, body,
46290
42477
  return envelope.data;
46291
42478
  } catch (error) {
46292
42479
  report("failed");
46293
- if (error instanceof ApassTokenNotIssuedError || error instanceof ApassConfirmationFailedError)
42480
+ if (error instanceof ApassTokenNotIssuedError || error instanceof ApassConfirmationFailedError || error instanceof ApassIssueResultUnavailableError)
46294
42481
  throw error;
46295
42482
  signal?.throwIfAborted();
46296
42483
  throw new Error("APASS_AUTHORIZATION_FAILED");
@@ -46446,22 +42633,33 @@ function toAuthorizationChallenge(result, serviceName) {
46446
42633
  }
46447
42634
  async function confirmAuthorization(input, options) {
46448
42635
  if (input.authorizationKind === "apass") {
46449
- const result = await invokeApassAuthorization(options.baseUrl, options.authorizationHeader, "confirmAuth", { agentId: input.agentId, authSessionId: input.authSessionId }, options.fetch, void 0, (event) => options.log?.({
46450
- operation: "confirmAuth",
46451
- authorizationKind: "apass",
46452
- authSessionId: input.authSessionId,
46453
- agentId: input.agentId,
46454
- ...event
46455
- }));
46456
- if (result.status !== "confirmed" || result.authSessionId !== input.authSessionId)
46457
- throw failed();
46458
- return;
42636
+ throw failed();
46459
42637
  }
46460
42638
  await invoke(options, "confirmAuth", {
46461
42639
  agentId: input.agentId,
46462
42640
  authSessionId: input.authSessionId
46463
42641
  });
46464
42642
  }
42643
+ async function requestFunctionApassCredential(input, options, recoverOnly = false) {
42644
+ try {
42645
+ const body = {
42646
+ agentId: input.agentId,
42647
+ authSessionId: input.authSessionId,
42648
+ tokenStorage: "function"
42649
+ };
42650
+ const result = await invokeApassAuthorization(options.apassBaseUrl ?? options.baseUrl, options.authorizationHeader, recoverOnly ? "issueResult" : "confirmAuth", body, options.fetch);
42651
+ if (result.status !== "confirmed" || result.authSessionId !== input.authSessionId || typeof result.accessToken !== "string" || !result.accessToken.trim())
42652
+ throw failed();
42653
+ return {
42654
+ accessToken: result.accessToken,
42655
+ authSessionId: input.authSessionId
42656
+ };
42657
+ } catch (error) {
42658
+ if (recoverOnly && error instanceof ApassIssueResultUnavailableError)
42659
+ return void 0;
42660
+ throw error;
42661
+ }
42662
+ }
46465
42663
  function observeChallenge(options, event, value, challenge) {
46466
42664
  const data = value && typeof value === "object" ? value : {};
46467
42665
  const shape = (section) => {
@@ -47191,15 +43389,15 @@ function isObjectJsonSchema(value) {
47191
43389
  return isPlainRecord(value) && value.type === "object" && getJsonSchemaIssues(value).length === 0;
47192
43390
  }
47193
43391
  function validateJsonSchemaValue(schema, value, path2 = "$") {
47194
- let validate2;
43392
+ let validate;
47195
43393
  try {
47196
- validate2 = ajv.compile(schema);
43394
+ validate = ajv.compile(schema);
47197
43395
  } catch (error) {
47198
43396
  return [
47199
43397
  issue(path2, "INVALID_JSON_SCHEMA", error instanceof Error ? error.message : "schema is invalid")
47200
43398
  ];
47201
43399
  }
47202
- return validate2(value) ? [] : (validate2.errors ?? []).map(errorToIssue.bind(null, path2));
43400
+ return validate(value) ? [] : (validate.errors ?? []).map(errorToIssue.bind(null, path2));
47203
43401
  }
47204
43402
  function errorToIssue(root, error) {
47205
43403
  const suffix = error.instancePath.split("/").filter(Boolean).map((segment) => segment.replace(/~1/gu, "/").replace(/~0/gu, "~")).map((segment) => `[${JSON.stringify(segment)}]`).join("");
@@ -47832,19 +44030,22 @@ function optionalStandardSchema(schema) {
47832
44030
  properties: Object.fromEntries(Object.entries(schema.properties).map(([key, child]) => [key, optionalStandardSchema(child)]))
47833
44031
  };
47834
44032
  }
44033
+ var STANDARD_SURFACE_ID = "x-linkque-standard-surface-id";
47835
44034
  function standardCardBindingModel(message, allowPartialModel = false) {
47836
44035
  const surfaces = standardCardSurfaceSchemas(message);
47837
44036
  const fields = [];
47838
44037
  for (const [surfaceId, schema2] of surfaces) {
47839
44038
  for (const [key, valueSchema] of Object.entries(schema2.properties)) {
47840
- const path2 = "/" + [surfaceId, key].map(encodePointerSegment).join("/");
44039
+ const legacyPath = "/" + [surfaceId, key].map(encodePointerSegment).join("/");
44040
+ const path2 = surfaces.size === 1 ? "/" + encodePointerSegment(key) : legacyPath;
47841
44041
  if (!isSafeJsonPointer(path2))
47842
44042
  throw new Error(`\u65E0\u6548\u7684\u6807\u51C6\u5361\u7ED1\u5B9A\u8DEF\u5F84\uFF1A${path2}`);
47843
44043
  const type = valueSchema.type;
47844
44044
  if (type !== "array" && type !== "object" && type !== "string" && type !== "number" && type !== "integer" && type !== "boolean")
47845
44045
  throw new Error(`\u65E0\u6CD5\u786E\u5B9A\u6807\u51C6\u5361\u5B57\u6BB5\u7C7B\u578B\uFF1A${path2}`);
47846
44046
  fields.push({
47847
- fieldId: "field-" + sha256Hex(path2).slice(0, 32),
44047
+ // 保留既有标准卡的绑定身份,路径扁平化无需重新绑定。
44048
+ fieldId: "field-" + sha256Hex(legacyPath).slice(0, 32),
47848
44049
  path: path2,
47849
44050
  label: surfaces.size === 1 ? key : surfaceId + " / " + key,
47850
44051
  source: "business",
@@ -47854,6 +44055,16 @@ function standardCardBindingModel(message, allowPartialModel = false) {
47854
44055
  });
47855
44056
  }
47856
44057
  }
44058
+ if (surfaces.size === 1) {
44059
+ const [surfaceId, model] = surfaces.entries().next().value;
44060
+ return {
44061
+ fields,
44062
+ schema: {
44063
+ ...allowPartialModel ? optionalStandardSchema(model) : model,
44064
+ [STANDARD_SURFACE_ID]: surfaceId
44065
+ }
44066
+ };
44067
+ }
47857
44068
  const schema = {
47858
44069
  type: "object",
47859
44070
  properties: Object.fromEntries([...surfaces].map(([id2, item]) => [
@@ -47865,11 +44076,33 @@ function standardCardBindingModel(message, allowPartialModel = false) {
47865
44076
  };
47866
44077
  return { fields, schema };
47867
44078
  }
44079
+ function standardCardModelInputDataSchema(schema) {
44080
+ const { [STANDARD_SURFACE_ID]: surfaceId, ...modelSchema } = schema;
44081
+ if (typeof surfaceId !== "string" && isPlainRecord(modelSchema.properties)) {
44082
+ const properties = Object.values(modelSchema.properties);
44083
+ if (properties.length === 1 && isPlainRecord(properties[0])) {
44084
+ return optionalStandardSchema(properties[0]);
44085
+ }
44086
+ }
44087
+ return optionalStandardSchema(modelSchema);
44088
+ }
44089
+ function normalizeStandardCardData(schema, data) {
44090
+ const surfaceId = schema[STANDARD_SURFACE_ID];
44091
+ if (typeof surfaceId !== "string" || Object.keys(data).length !== 1 || !Object.prototype.hasOwnProperty.call(data, surfaceId))
44092
+ return data;
44093
+ const nested = data[surfaceId];
44094
+ if (!isPlainRecord(nested))
44095
+ return data;
44096
+ if (isPlainRecord(schema.properties) && Object.prototype.hasOwnProperty.call(schema.properties, surfaceId) && validateJsonSchemaValue2(schema, data).length === 0)
44097
+ return data;
44098
+ return nested;
44099
+ }
47868
44100
  function renderStandardCardData(message, data, allowPartialModel = false) {
47869
44101
  const datas = message.datas.filter((instruction) => !("updateDataModel" in instruction));
47870
44102
  const updates = [];
47871
- for (const [surfaceId, schema] of standardCardSurfaceSchemas(message)) {
47872
- const value = data[surfaceId] ?? {};
44103
+ const surfaces = standardCardSurfaceSchemas(message);
44104
+ for (const [surfaceId, schema] of surfaces) {
44105
+ const value = surfaces.size === 1 ? data : data[surfaceId] ?? {};
47873
44106
  const issues = validateJsonSchemaValue2(allowPartialModel ? optionalStandardSchema(schema) : schema, value);
47874
44107
  if (issues.length)
47875
44108
  throw new Error(`\u6807\u51C6\u5361\u6570\u636E\u4E0D\u5339\u914D\uFF1A${surfaceId} ${issues[0].path} ${issues[0].message}`);
@@ -49114,10 +45347,38 @@ function getA2UICardResourceConfigIssues(value) {
49114
45347
  validateResolverCoverage(fields, resolver, issues, card);
49115
45348
  return issues;
49116
45349
  }
45350
+ function getCardExecutionConfigIssues(value) {
45351
+ if (!isPlainRecord(value) || !("definitionRef" in value) && value.format !== "alipay-a2ui")
45352
+ return getA2UICardResourceConfigIssues(value);
45353
+ const standard = value.format === "alipay-a2ui";
45354
+ const ref = value.definitionRef;
45355
+ if ("definitionRef" in value) {
45356
+ if (!isPlainRecord(ref) || ref.format !== (standard ? "alipay-a2ui" : "linkque-a2ui") || typeof ref.objectName !== "string" || !ref.objectName || typeof ref.checksum !== "string" || !ref.checksum)
45357
+ return [
45358
+ issue2("config.definitionRef", "INVALID_CARD_DEFINITION_REF", "invalid card definition reference")
45359
+ ];
45360
+ } else if (!isPlainRecord(value.protocol) || !Array.isArray(value.protocol.datas)) {
45361
+ return [
45362
+ issue2("config.protocol", "INVALID_CARD_DEFINITION", "expected a standard card message")
45363
+ ];
45364
+ }
45365
+ if (value.schemaVersion !== "4")
45366
+ return [
45367
+ issue2("config.schemaVersion", "UNSUPPORTED_CARD_VERSION", "execution references require schemaVersion 4")
45368
+ ];
45369
+ const layout = standard ? "standard" : "referenced";
45370
+ if (value.dataMode === "pipeline")
45371
+ return getA2UICardResourceConfigV4PipelineIssues(value, layout);
45372
+ if (value.dataMode !== void 0 && value.dataMode !== "bindings" && value.dataMode !== "model")
45373
+ return [
45374
+ issue2("config.dataMode", "INVALID_DATA_MODE", "unsupported card data mode")
45375
+ ];
45376
+ return getA2UICardResourceConfigV3Issues(value, layout);
45377
+ }
49117
45378
  function getStandardCardExecutionIssues(value) {
49118
- return value.dataMode === "pipeline" ? getA2UICardResourceConfigV4PipelineIssues(value, true) : getA2UICardResourceConfigV3Issues(value, true);
45379
+ return value.dataMode === "pipeline" ? getA2UICardResourceConfigV4PipelineIssues(value, "resolvedStandard") : getA2UICardResourceConfigV3Issues(value, "resolvedStandard");
49119
45380
  }
49120
- function getA2UICardResourceConfigV4PipelineIssues(value, standard = false) {
45381
+ function getA2UICardResourceConfigV4PipelineIssues(value, layout = "inline") {
49121
45382
  const issues = [];
49122
45383
  exactKeys(value, [
49123
45384
  "schemaVersion",
@@ -49149,14 +45410,16 @@ function getA2UICardResourceConfigV4PipelineIssues(value, standard = false) {
49149
45410
  requiredString(value.whenToUse, "config.whenToUse", issues);
49150
45411
  optionalString(value.whenNotToUse, "config.whenNotToUse", issues);
49151
45412
  validateLooseJsonSchema(value.presentationInputSchema, "config.presentationInputSchema", issues);
49152
- const fields = validateFields(value.fields, "config.fields", issues, standard);
45413
+ const fields = layout === "standard" ? void 0 : validateFields(value.fields, "config.fields", issues, layout === "resolvedStandard");
49153
45414
  const pipelineSources = validatePipelineDataSources(value.dataSources, "config.dataSources", issues);
49154
45415
  if (value.argumentMode === "model" && pipelineSources) {
49155
45416
  validateModelPipelineArguments(value, pipelineSources, "config", issues);
49156
45417
  }
49157
45418
  validateDataTransform(value.dataTransform, "config.dataTransform", issues);
49158
- const dataModelSchema = validateLooseJsonSchema(value.dataModelSchema, "config.dataModelSchema", issues);
49159
- const card = standard ? void 0 : validateTemplate(value.a2uiTemplate, fields, issues);
45419
+ const dataModelSchema = layout !== "standard" && validateLooseJsonSchema(value.dataModelSchema, "config.dataModelSchema", issues);
45420
+ if (layout === "referenced")
45421
+ validateLooseJsonSchema(isPlainRecord(value.a2uiTemplate) ? value.a2uiTemplate.argsSchema : void 0, "config.a2uiTemplate.argsSchema", issues);
45422
+ const card = layout === "inline" ? validateTemplate(value.a2uiTemplate, fields, issues) : void 0;
49160
45423
  if (card) {
49161
45424
  issues.push(...getA2UIV4ProtocolIssues(card, "config.a2uiTemplate.content"), ...getPersistedV4ProtocolIssues(card, "config.a2uiTemplate.content"));
49162
45425
  }
@@ -49168,7 +45431,7 @@ function getA2UICardResourceConfigV4PipelineIssues(value, standard = false) {
49168
45431
  }
49169
45432
  return issues;
49170
45433
  }
49171
- function getA2UICardResourceConfigV3Issues(value, standard = false) {
45434
+ function getA2UICardResourceConfigV3Issues(value, layout = "inline") {
49172
45435
  const issues = [];
49173
45436
  if (value.actionBindings !== void 0) {
49174
45437
  issues.push(issue2("config.actionBindings", "LEGACY_PAYMENT_ACTION_BINDINGS_UNSUPPORTED", "payment actions must be defined inline in card JSON"));
@@ -49195,8 +45458,8 @@ function getA2UICardResourceConfigV3Issues(value, standard = false) {
49195
45458
  requiredString(value.description, "config.description", issues);
49196
45459
  requiredString(value.whenToUse, "config.whenToUse", issues);
49197
45460
  optionalString(value.whenNotToUse, "config.whenNotToUse", issues);
49198
- const fields = validateFields(value.fields, "config.fields", issues, standard);
49199
- if (value.schemaVersion === "4") {
45461
+ const fields = layout === "standard" ? void 0 : validateFields(value.fields, "config.fields", issues, layout === "resolvedStandard");
45462
+ if (value.schemaVersion === "4" && layout !== "standard") {
49200
45463
  validateBindingOutputSchemas(value.bindingOutputSchemas, fields, "config.bindingOutputSchemas", issues);
49201
45464
  }
49202
45465
  if (fields?.some((field) => field.source === "invocation")) {
@@ -49204,7 +45467,9 @@ function getA2UICardResourceConfigV3Issues(value, standard = false) {
49204
45467
  }
49205
45468
  const dataSources = validateDataSources(value.dataSources, "config.dataSources", issues);
49206
45469
  const bindings = validateV3OutputBindings(value.bindings, "config.bindings", issues);
49207
- const card = standard ? void 0 : validateTemplate(value.a2uiTemplate, fields, issues);
45470
+ if (layout === "referenced")
45471
+ validateLooseJsonSchema(isPlainRecord(value.a2uiTemplate) ? value.a2uiTemplate.argsSchema : void 0, "config.a2uiTemplate.argsSchema", issues);
45472
+ const card = layout === "inline" ? validateTemplate(value.a2uiTemplate, fields, issues) : void 0;
49208
45473
  if (value.schemaVersion === "4" && card) {
49209
45474
  issues.push(...getA2UIV4ProtocolIssues(card, "config.a2uiTemplate.content"));
49210
45475
  issues.push(...getPersistedV4ProtocolIssues(card, "config.a2uiTemplate.content"));
@@ -49212,7 +45477,10 @@ function getA2UICardResourceConfigV3Issues(value, standard = false) {
49212
45477
  if (value.schemaVersion === "4" && value.dataMode === "model") {
49213
45478
  validateLooseJsonSchema(value.modelInputSchema, "config.modelInputSchema", issues);
49214
45479
  } else if (fields && dataSources && bindings) {
49215
- validateV3Coverage(fields, dataSources, bindings, issues, { card });
45480
+ validateV3Coverage(fields, dataSources, bindings, issues, {
45481
+ card,
45482
+ requireComplete: layout !== "referenced"
45483
+ });
49216
45484
  }
49217
45485
  return issues;
49218
45486
  }
@@ -49222,6 +45490,7 @@ function validateDataSources(value, path2, issues, options = {}) {
49222
45490
  return void 0;
49223
45491
  }
49224
45492
  const ids = /* @__PURE__ */ new Set();
45493
+ const initialIssues = issues.length;
49225
45494
  value.forEach((candidate, index) => {
49226
45495
  const itemPath = `${path2}[${index}]`;
49227
45496
  if (!isPlainRecord(candidate)) {
@@ -49258,6 +45527,8 @@ function validateDataSources(value, path2, issues, options = {}) {
49258
45527
  validateLooseJsonSchema(candidate.outputSchema, `${itemPath}.outputSchema`, issues);
49259
45528
  }
49260
45529
  });
45530
+ if (issues.length !== initialIssues)
45531
+ return void 0;
49261
45532
  for (const [index, source] of value.entries()) {
49262
45533
  for (const dependency of source.dependsOn ?? []) {
49263
45534
  if (!ids.has(dependency) || dependency === source.sourceId) {
@@ -49301,6 +45572,7 @@ function validatePipelineDataSources(value, path2, issues) {
49301
45572
  return void 0;
49302
45573
  }
49303
45574
  const ids = /* @__PURE__ */ new Set();
45575
+ const initialIssues = issues.length;
49304
45576
  value.forEach((candidate, index) => {
49305
45577
  const itemPath = `${path2}[${index}]`;
49306
45578
  if (!isPlainRecord(candidate)) {
@@ -49344,7 +45616,7 @@ function validatePipelineDataSources(value, path2, issues) {
49344
45616
  validateLooseJsonSchema(candidate.inputSchema, `${itemPath}.inputSchema`, issues);
49345
45617
  validateLooseJsonSchema(candidate.outputSchema, `${itemPath}.outputSchema`, issues);
49346
45618
  });
49347
- return value;
45619
+ return issues.length === initialIssues ? value : void 0;
49348
45620
  }
49349
45621
  function validateDataTransform(value, path2, issues) {
49350
45622
  if (!isPlainRecord(value)) {
@@ -49379,6 +45651,7 @@ function validateV3OutputBindings(value, path2, issues) {
49379
45651
  issues.push(issue2(path2, "INVALID_OUTPUT_BINDINGS", "bindings must be an array"));
49380
45652
  return void 0;
49381
45653
  }
45654
+ const initialIssues = issues.length;
49382
45655
  const fields = /* @__PURE__ */ new Set();
49383
45656
  value.forEach((candidate, index) => {
49384
45657
  const itemPath = `${path2}[${index}]`;
@@ -49397,7 +45670,7 @@ function validateV3OutputBindings(value, path2, issues) {
49397
45670
  issues.push(issue2(`${itemPath}.sourceId`, "INVALID_SOURCE_ID", "sourceId is invalid"));
49398
45671
  validateTransformShape(candidate.transform, `${itemPath}.transform`, issues);
49399
45672
  });
49400
- return value;
45673
+ return issues.length === initialIssues ? value : void 0;
49401
45674
  }
49402
45675
  function validateV3Coverage(fields, dataSources, bindings, issues, options = {}) {
49403
45676
  const sourceIds = new Set(dataSources.map((source) => source.sourceId));
@@ -49446,6 +45719,7 @@ function validateFields(value, path2, issues, allowEmptyArrayItemSchema = false)
49446
45719
  issues.push(issue2(path2, "INVALID_FIELDS", `${path2} must be an array`));
49447
45720
  return void 0;
49448
45721
  }
45722
+ const initialIssues = issues.length;
49449
45723
  const ids = /* @__PURE__ */ new Set();
49450
45724
  const paths = /* @__PURE__ */ new Set();
49451
45725
  value.forEach((candidate, index) => {
@@ -49503,7 +45777,7 @@ function validateFields(value, path2, issues, allowEmptyArrayItemSchema = false)
49503
45777
  optionalString(candidate.consistencyGroup, `${itemPath}.consistencyGroup`, issues);
49504
45778
  validateFieldPresentation(candidate.presentation, itemPath, issues);
49505
45779
  });
49506
- return value;
45780
+ return issues.length === initialIssues ? value : void 0;
49507
45781
  }
49508
45782
  function validateFieldPresentation(value, itemPath, issues) {
49509
45783
  if (value === void 0)
@@ -50439,7 +46713,7 @@ async function createPresentationResult(resource, config, viewModel, cardProvide
50439
46713
  const standardCard = "format" in resource.config && resource.config.format === "alipay-a2ui";
50440
46714
  const payload = standardCard ? {
50441
46715
  format: "alipay-a2ui",
50442
- protocol: renderStandardCardData(JSON.parse(content), viewModel, "allowPartialModel" in resource.config && resource.config.allowPartialModel === true)
46716
+ protocol: renderStandardCardData(JSON.parse(content), viewModel, true)
50443
46717
  } : {
50444
46718
  protocol: injectResolvedViewModel(JSON.parse(content), viewModel)
50445
46719
  };
@@ -50505,15 +46779,35 @@ function projectPresentationReceiptForModel(receipt) {
50505
46779
  };
50506
46780
  }
50507
46781
  function parseCardConfig(resource) {
50508
- if ("format" in resource.config && resource.config.format === "alipay-a2ui") {
50509
- const stored = resource.config;
50510
- if (stored.schemaVersion !== "4" || !stored.revision || !Array.isArray(stored.dataSources))
50511
- throw new Error("\u6807\u51C6\u5361\u5C1A\u672A\u914D\u7F6E\u6267\u884C\u53C2\u6570");
50512
- const a2uiTemplate = { content: "", argsSchema: {} };
50513
- return stored.dataMode === "pipeline" ? { ...stored, fields: [], a2uiTemplate, dataModelSchema: {} } : { ...stored, fields: [], a2uiTemplate };
50514
- }
50515
- if ("definitionRef" in resource.config && resource.config.schemaVersion === "4")
50516
- return resource.config;
46782
+ const stored = resource.config;
46783
+ if ("definitionRef" in stored || "format" in stored && stored.format === "alipay-a2ui") {
46784
+ const issues = getCardExecutionConfigIssues(stored);
46785
+ if (issues.length)
46786
+ throw new Error(issues.map((issue3) => issue3.message).join("\uFF1B"));
46787
+ if ("format" in stored && stored.format === "alipay-a2ui") {
46788
+ const a2uiTemplate = { content: "", argsSchema: {} };
46789
+ const standard = stored;
46790
+ if (standard.dataMode === "model") {
46791
+ const schema = standard.modelInputSchema;
46792
+ const properties = schema.properties;
46793
+ const dataModel = properties?.dataModel;
46794
+ return {
46795
+ ...standard,
46796
+ fields: [],
46797
+ a2uiTemplate,
46798
+ modelInputSchema: dataModel ? {
46799
+ ...schema,
46800
+ properties: {
46801
+ ...properties,
46802
+ dataModel: standardCardModelInputDataSchema(dataModel)
46803
+ }
46804
+ } : schema
46805
+ };
46806
+ }
46807
+ return standard.dataMode === "pipeline" ? { ...standard, fields: [], a2uiTemplate, dataModelSchema: {} } : { ...standard, fields: [], a2uiTemplate };
46808
+ }
46809
+ return stored;
46810
+ }
50517
46811
  const parsed = parseA2UICardResourceConfig(resource.config);
50518
46812
  if (!parsed.success) {
50519
46813
  throw new Error(`Invalid CARD ${resource.resourceId}: ${parsed.issues.map((entry) => `${entry.path}: ${entry.message}`).join("; ")}`);
@@ -50527,7 +46821,7 @@ async function resolveStandardCardExecution(resource, config, provider, signal)
50527
46821
  if (!inline && !provider)
50528
46822
  throw new Error("\u6807\u51C6\u5361\u7F3A\u5C11\u7ED3\u6784\u8BFB\u53D6\u670D\u52A1");
50529
46823
  const content = inline ? JSON.stringify(inline) : await provider.loadDefinition(resource.resourceId, signal);
50530
- const { fields, schema } = standardCardBindingModel(JSON.parse(content), resource.config.allowPartialModel === true);
46824
+ const { fields, schema } = standardCardBindingModel(JSON.parse(content), true);
50531
46825
  const issues = getStandardCardExecutionIssues({
50532
46826
  ...resource.config,
50533
46827
  fields,
@@ -50539,7 +46833,7 @@ async function resolveStandardCardExecution(resource, config, provider, signal)
50539
46833
  const projections = resource.config.bindingOutputSchemas;
50540
46834
  const bindingFields = projections ? fields.map((field) => ({
50541
46835
  ...field,
50542
- valueSchema: projections[field.fieldId] ?? field.valueSchema
46836
+ valueSchema: projections[field.fieldId] ? optionalStandardSchema(projections[field.fieldId]) : field.valueSchema
50543
46837
  })) : fields;
50544
46838
  if (config.schemaVersion === "4" && config.dataMode === "pipeline")
50545
46839
  return { ...config, fields, a2uiTemplate, dataModelSchema: schema };
@@ -51023,6 +47317,8 @@ var ETelemetryContentSection;
51023
47317
  ETelemetryContentSection2["MCP_REQUESTED_INPUT"] = "mcp.requested_input";
51024
47318
  ETelemetryContentSection2["MCP_INPUT"] = "mcp.input";
51025
47319
  ETelemetryContentSection2["MCP_OUTPUT"] = "mcp.output";
47320
+ ETelemetryContentSection2["CARD_MCP_OUTPUT"] = "card.mcp.output";
47321
+ ETelemetryContentSection2["CARD_OUTPUT"] = "card.output";
51026
47322
  ETelemetryContentSection2["SKILL_INPUT"] = "skill.input";
51027
47323
  ETelemetryContentSection2["SKILL_OUTPUT"] = "skill.output";
51028
47324
  ETelemetryContentSection2["KNOWLEDGE_INPUT"] = "knowledge.input";
@@ -55418,7 +51714,7 @@ var LATEST_PROTOCOL_VERSION = "2025-11-25";
55418
51714
  var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
55419
51715
  var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
55420
51716
  var JSONRPC_VERSION = "2.0";
55421
- var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
51717
+ var AssertObjectSchema = custom2((v) => v !== null && (typeof v === "object" || typeof v === "function"));
55422
51718
  var ProgressTokenSchema = union([string(), number().int()]);
55423
51719
  var CursorSchema = string();
55424
51720
  var TaskCreationParamsSchema = looseObject({
@@ -59203,11 +55499,11 @@ async function pkceChallenge(length) {
59203
55499
  var SafeUrlSchema = url().superRefine((val, ctx) => {
59204
55500
  if (!URL.canParse(val)) {
59205
55501
  ctx.addIssue({
59206
- code: ZodIssueCode.custom,
55502
+ code: ZodIssueCode2.custom,
59207
55503
  message: "URL must be parseable",
59208
55504
  fatal: true
59209
55505
  });
59210
- return NEVER;
55506
+ return NEVER2;
59211
55507
  }
59212
55508
  }).refine((url2) => {
59213
55509
  const u = new URL(url2);
@@ -63645,6 +59941,7 @@ function validContext(value) {
63645
59941
  export {
63646
59942
  EXECUTION_SCENE_HEADER,
63647
59943
  EModelRequestSource,
59944
+ DataTransformError,
63648
59945
  DataTransformExecutor,
63649
59946
  EDebugLogScope,
63650
59947
  isDebugLoggingEnabled,
@@ -63660,25 +59957,10 @@ export {
63660
59957
  isSafeJsonPointer,
63661
59958
  readJsonPointer,
63662
59959
  writeJsonPointer,
63663
- require_codegen,
63664
- require_util,
63665
- require_names,
63666
- require_validate,
63667
- require_validation_error,
63668
- require_ref_error,
63669
- require_compile,
63670
- require_core,
63671
- require_ref,
63672
- require_core2,
63673
- require_validation,
63674
- require_dependencies,
63675
- require_applicator,
63676
- require_format2 as require_format,
63677
- require_metadata,
63678
- require_discriminator,
63679
59960
  validateJsonSchemaValue2 as validateJsonSchemaValue,
63680
59961
  projectCardData,
63681
59962
  normalizeCardDataValue,
59963
+ normalizeStandardCardData,
63682
59964
  createA2UICardPipelineModelInputSchema,
63683
59965
  executeA2UICardResolver,
63684
59966
  parseA2UIFunctionMcpExecuteRequest,
@@ -63781,6 +60063,7 @@ export {
63781
60063
  apassChallenge,
63782
60064
  invokeApassAuthorization,
63783
60065
  confirmAuthorization,
60066
+ requestFunctionApassCredential,
63784
60067
  isAuthorizationPause,
63785
60068
  AuthorizationExecution,
63786
60069
  CancellationScope,
@@ -63835,7 +60118,6 @@ export {
63835
60118
  normalizeScenarioRunErrorCode,
63836
60119
  authorizeAgentRun,
63837
60120
  createGatewayRunAuthorization,
63838
- require_dist,
63839
60121
  abortableDelay,
63840
60122
  RemoteGatewayMcpServerProvider,
63841
60123
  LinkqueKnowledgeSearchPort,