intention-coding 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,4445 @@
1
+ import { FastMCP } from "fastmcp";
2
+ import fs_0, { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
3
+ import { join } from "path";
4
+ var __webpack_require__ = {};
5
+ (()=>{
6
+ __webpack_require__.d = (exports, definition)=>{
7
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
8
+ enumerable: true,
9
+ get: definition[key]
10
+ });
11
+ };
12
+ })();
13
+ (()=>{
14
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.r = (exports)=>{
18
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
19
+ value: 'Module'
20
+ });
21
+ Object.defineProperty(exports, '__esModule', {
22
+ value: true
23
+ });
24
+ };
25
+ })();
26
+ var external_namespaceObject = {};
27
+ __webpack_require__.r(external_namespaceObject);
28
+ __webpack_require__.d(external_namespaceObject, {
29
+ BRAND: ()=>BRAND,
30
+ DIRTY: ()=>DIRTY,
31
+ EMPTY_PATH: ()=>EMPTY_PATH,
32
+ INVALID: ()=>INVALID,
33
+ NEVER: ()=>NEVER,
34
+ OK: ()=>OK,
35
+ ParseStatus: ()=>ParseStatus,
36
+ Schema: ()=>ZodType,
37
+ ZodAny: ()=>ZodAny,
38
+ ZodArray: ()=>ZodArray,
39
+ ZodBigInt: ()=>ZodBigInt,
40
+ ZodBoolean: ()=>ZodBoolean,
41
+ ZodBranded: ()=>ZodBranded,
42
+ ZodCatch: ()=>ZodCatch,
43
+ ZodDate: ()=>ZodDate,
44
+ ZodDefault: ()=>ZodDefault,
45
+ ZodDiscriminatedUnion: ()=>ZodDiscriminatedUnion,
46
+ ZodEffects: ()=>ZodEffects,
47
+ ZodEnum: ()=>ZodEnum,
48
+ ZodError: ()=>ZodError,
49
+ ZodFirstPartyTypeKind: ()=>types_ZodFirstPartyTypeKind,
50
+ ZodFunction: ()=>ZodFunction,
51
+ ZodIntersection: ()=>ZodIntersection,
52
+ ZodIssueCode: ()=>ZodIssueCode,
53
+ ZodLazy: ()=>ZodLazy,
54
+ ZodLiteral: ()=>ZodLiteral,
55
+ ZodMap: ()=>ZodMap,
56
+ ZodNaN: ()=>ZodNaN,
57
+ ZodNativeEnum: ()=>ZodNativeEnum,
58
+ ZodNever: ()=>ZodNever,
59
+ ZodNull: ()=>ZodNull,
60
+ ZodNullable: ()=>ZodNullable,
61
+ ZodNumber: ()=>ZodNumber,
62
+ ZodObject: ()=>ZodObject,
63
+ ZodOptional: ()=>ZodOptional,
64
+ ZodParsedType: ()=>ZodParsedType,
65
+ ZodPipeline: ()=>ZodPipeline,
66
+ ZodPromise: ()=>ZodPromise,
67
+ ZodReadonly: ()=>ZodReadonly,
68
+ ZodRecord: ()=>ZodRecord,
69
+ ZodSchema: ()=>ZodType,
70
+ ZodSet: ()=>ZodSet,
71
+ ZodString: ()=>ZodString,
72
+ ZodSymbol: ()=>ZodSymbol,
73
+ ZodTransformer: ()=>ZodEffects,
74
+ ZodTuple: ()=>ZodTuple,
75
+ ZodType: ()=>ZodType,
76
+ ZodUndefined: ()=>ZodUndefined,
77
+ ZodUnion: ()=>ZodUnion,
78
+ ZodUnknown: ()=>ZodUnknown,
79
+ ZodVoid: ()=>ZodVoid,
80
+ addIssueToContext: ()=>addIssueToContext,
81
+ any: ()=>anyType,
82
+ array: ()=>arrayType,
83
+ bigint: ()=>bigIntType,
84
+ boolean: ()=>booleanType,
85
+ coerce: ()=>coerce,
86
+ custom: ()=>custom,
87
+ date: ()=>dateType,
88
+ datetimeRegex: ()=>datetimeRegex,
89
+ defaultErrorMap: ()=>en,
90
+ discriminatedUnion: ()=>discriminatedUnionType,
91
+ effect: ()=>effectsType,
92
+ enum: ()=>enumType,
93
+ function: ()=>functionType,
94
+ getErrorMap: ()=>getErrorMap,
95
+ getParsedType: ()=>getParsedType,
96
+ instanceof: ()=>instanceOfType,
97
+ intersection: ()=>intersectionType,
98
+ isAborted: ()=>isAborted,
99
+ isAsync: ()=>isAsync,
100
+ isDirty: ()=>isDirty,
101
+ isValid: ()=>isValid,
102
+ late: ()=>late,
103
+ lazy: ()=>lazyType,
104
+ literal: ()=>literalType,
105
+ makeIssue: ()=>makeIssue,
106
+ map: ()=>mapType,
107
+ nan: ()=>nanType,
108
+ nativeEnum: ()=>nativeEnumType,
109
+ never: ()=>neverType,
110
+ null: ()=>nullType,
111
+ nullable: ()=>nullableType,
112
+ number: ()=>numberType,
113
+ object: ()=>objectType,
114
+ objectUtil: ()=>util_objectUtil,
115
+ oboolean: ()=>oboolean,
116
+ onumber: ()=>onumber,
117
+ optional: ()=>optionalType,
118
+ ostring: ()=>ostring,
119
+ pipeline: ()=>pipelineType,
120
+ preprocess: ()=>preprocessType,
121
+ promise: ()=>promiseType,
122
+ quotelessJson: ()=>quotelessJson,
123
+ record: ()=>recordType,
124
+ set: ()=>setType,
125
+ setErrorMap: ()=>setErrorMap,
126
+ strictObject: ()=>strictObjectType,
127
+ string: ()=>stringType,
128
+ symbol: ()=>symbolType,
129
+ transformer: ()=>effectsType,
130
+ tuple: ()=>tupleType,
131
+ undefined: ()=>undefinedType,
132
+ union: ()=>unionType,
133
+ unknown: ()=>unknownType,
134
+ util: ()=>util_util,
135
+ void: ()=>voidType
136
+ });
137
+ const SERVICE_CONFIG = {
138
+ name: "intention-coding",
139
+ version: "1.0.0",
140
+ description: "\u8F6F\u4EF6\u5DE5\u7A0B\u5316\u7684\u9700\u6C42\u5206\u6790\uFF0C\u529F\u80FD\u8BBE\u8BA1\uFF0C\u4EE3\u7801\u7F16\u5199\uFF0C\u6D4B\u8BD5\u8FD0\u884C\u548C\u53D1\u5E03\u90E8\u7F72"
141
+ };
142
+ var util_util;
143
+ (function(util) {
144
+ util.assertEqual = (_)=>{};
145
+ function assertIs(_arg) {}
146
+ util.assertIs = assertIs;
147
+ function assertNever(_x) {
148
+ throw new Error();
149
+ }
150
+ util.assertNever = assertNever;
151
+ util.arrayToEnum = (items)=>{
152
+ const obj = {};
153
+ for (const item of items)obj[item] = item;
154
+ return obj;
155
+ };
156
+ util.getValidEnumValues = (obj)=>{
157
+ const validKeys = util.objectKeys(obj).filter((k)=>"number" != typeof obj[obj[k]]);
158
+ const filtered = {};
159
+ for (const k of validKeys)filtered[k] = obj[k];
160
+ return util.objectValues(filtered);
161
+ };
162
+ util.objectValues = (obj)=>util.objectKeys(obj).map(function(e) {
163
+ return obj[e];
164
+ });
165
+ util.objectKeys = "function" == typeof Object.keys ? (obj)=>Object.keys(obj) : (object)=>{
166
+ const keys = [];
167
+ for(const key in object)if (Object.prototype.hasOwnProperty.call(object, key)) keys.push(key);
168
+ return keys;
169
+ };
170
+ util.find = (arr, checker)=>{
171
+ for (const item of arr)if (checker(item)) return item;
172
+ };
173
+ util.isInteger = "function" == typeof Number.isInteger ? (val)=>Number.isInteger(val) : (val)=>"number" == typeof val && Number.isFinite(val) && Math.floor(val) === val;
174
+ function joinValues(array, separator = " | ") {
175
+ return array.map((val)=>"string" == typeof val ? `'${val}'` : val).join(separator);
176
+ }
177
+ util.joinValues = joinValues;
178
+ util.jsonStringifyReplacer = (_, value)=>{
179
+ if ("bigint" == typeof value) return value.toString();
180
+ return value;
181
+ };
182
+ })(util_util || (util_util = {}));
183
+ var util_objectUtil;
184
+ (function(objectUtil) {
185
+ objectUtil.mergeShapes = (first, second)=>({
186
+ ...first,
187
+ ...second
188
+ });
189
+ })(util_objectUtil || (util_objectUtil = {}));
190
+ const ZodParsedType = util_util.arrayToEnum([
191
+ "string",
192
+ "nan",
193
+ "number",
194
+ "integer",
195
+ "float",
196
+ "boolean",
197
+ "date",
198
+ "bigint",
199
+ "symbol",
200
+ "function",
201
+ "undefined",
202
+ "null",
203
+ "array",
204
+ "object",
205
+ "unknown",
206
+ "promise",
207
+ "void",
208
+ "never",
209
+ "map",
210
+ "set"
211
+ ]);
212
+ const getParsedType = (data)=>{
213
+ const t = typeof data;
214
+ switch(t){
215
+ case "undefined":
216
+ return ZodParsedType.undefined;
217
+ case "string":
218
+ return ZodParsedType.string;
219
+ case "number":
220
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
221
+ case "boolean":
222
+ return ZodParsedType.boolean;
223
+ case "function":
224
+ return ZodParsedType.function;
225
+ case "bigint":
226
+ return ZodParsedType.bigint;
227
+ case "symbol":
228
+ return ZodParsedType.symbol;
229
+ case "object":
230
+ if (Array.isArray(data)) return ZodParsedType.array;
231
+ if (null === data) return ZodParsedType.null;
232
+ if (data.then && "function" == typeof data.then && data.catch && "function" == typeof data.catch) return ZodParsedType.promise;
233
+ if ("undefined" != typeof Map && data instanceof Map) return ZodParsedType.map;
234
+ if ("undefined" != typeof Set && data instanceof Set) return ZodParsedType.set;
235
+ if ("undefined" != typeof Date && data instanceof Date) return ZodParsedType.date;
236
+ return ZodParsedType.object;
237
+ default:
238
+ return ZodParsedType.unknown;
239
+ }
240
+ };
241
+ const ZodIssueCode = util_util.arrayToEnum([
242
+ "invalid_type",
243
+ "invalid_literal",
244
+ "custom",
245
+ "invalid_union",
246
+ "invalid_union_discriminator",
247
+ "invalid_enum_value",
248
+ "unrecognized_keys",
249
+ "invalid_arguments",
250
+ "invalid_return_type",
251
+ "invalid_date",
252
+ "invalid_string",
253
+ "too_small",
254
+ "too_big",
255
+ "invalid_intersection_types",
256
+ "not_multiple_of",
257
+ "not_finite"
258
+ ]);
259
+ const quotelessJson = (obj)=>{
260
+ const json = JSON.stringify(obj, null, 2);
261
+ return json.replace(/"([^"]+)":/g, "$1:");
262
+ };
263
+ class ZodError extends Error {
264
+ get errors() {
265
+ return this.issues;
266
+ }
267
+ constructor(issues){
268
+ super();
269
+ this.issues = [];
270
+ this.addIssue = (sub)=>{
271
+ this.issues = [
272
+ ...this.issues,
273
+ sub
274
+ ];
275
+ };
276
+ this.addIssues = (subs = [])=>{
277
+ this.issues = [
278
+ ...this.issues,
279
+ ...subs
280
+ ];
281
+ };
282
+ const actualProto = new.target.prototype;
283
+ if (Object.setPrototypeOf) Object.setPrototypeOf(this, actualProto);
284
+ else this.__proto__ = actualProto;
285
+ this.name = "ZodError";
286
+ this.issues = issues;
287
+ }
288
+ format(_mapper) {
289
+ const mapper = _mapper || function(issue) {
290
+ return issue.message;
291
+ };
292
+ const fieldErrors = {
293
+ _errors: []
294
+ };
295
+ const processError = (error)=>{
296
+ for (const issue of error.issues)if ("invalid_union" === issue.code) issue.unionErrors.map(processError);
297
+ else if ("invalid_return_type" === issue.code) processError(issue.returnTypeError);
298
+ else if ("invalid_arguments" === issue.code) processError(issue.argumentsError);
299
+ else if (0 === issue.path.length) fieldErrors._errors.push(mapper(issue));
300
+ else {
301
+ let curr = fieldErrors;
302
+ let i = 0;
303
+ while(i < issue.path.length){
304
+ const el = issue.path[i];
305
+ const terminal = i === issue.path.length - 1;
306
+ if (terminal) {
307
+ curr[el] = curr[el] || {
308
+ _errors: []
309
+ };
310
+ curr[el]._errors.push(mapper(issue));
311
+ } else curr[el] = curr[el] || {
312
+ _errors: []
313
+ };
314
+ curr = curr[el];
315
+ i++;
316
+ }
317
+ }
318
+ };
319
+ processError(this);
320
+ return fieldErrors;
321
+ }
322
+ static assert(value) {
323
+ if (!(value instanceof ZodError)) throw new Error(`Not a ZodError: ${value}`);
324
+ }
325
+ toString() {
326
+ return this.message;
327
+ }
328
+ get message() {
329
+ return JSON.stringify(this.issues, util_util.jsonStringifyReplacer, 2);
330
+ }
331
+ get isEmpty() {
332
+ return 0 === this.issues.length;
333
+ }
334
+ flatten(mapper = (issue)=>issue.message) {
335
+ const fieldErrors = {};
336
+ const formErrors = [];
337
+ for (const sub of this.issues)if (sub.path.length > 0) {
338
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
339
+ fieldErrors[sub.path[0]].push(mapper(sub));
340
+ } else formErrors.push(mapper(sub));
341
+ return {
342
+ formErrors,
343
+ fieldErrors
344
+ };
345
+ }
346
+ get formErrors() {
347
+ return this.flatten();
348
+ }
349
+ }
350
+ ZodError.create = (issues)=>{
351
+ const error = new ZodError(issues);
352
+ return error;
353
+ };
354
+ const en_errorMap = (issue, _ctx)=>{
355
+ let message;
356
+ switch(issue.code){
357
+ case ZodIssueCode.invalid_type:
358
+ message = issue.received === ZodParsedType.undefined ? "Required" : `Expected ${issue.expected}, received ${issue.received}`;
359
+ break;
360
+ case ZodIssueCode.invalid_literal:
361
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_util.jsonStringifyReplacer)}`;
362
+ break;
363
+ case ZodIssueCode.unrecognized_keys:
364
+ message = `Unrecognized key(s) in object: ${util_util.joinValues(issue.keys, ", ")}`;
365
+ break;
366
+ case ZodIssueCode.invalid_union:
367
+ message = "Invalid input";
368
+ break;
369
+ case ZodIssueCode.invalid_union_discriminator:
370
+ message = `Invalid discriminator value. Expected ${util_util.joinValues(issue.options)}`;
371
+ break;
372
+ case ZodIssueCode.invalid_enum_value:
373
+ message = `Invalid enum value. Expected ${util_util.joinValues(issue.options)}, received '${issue.received}'`;
374
+ break;
375
+ case ZodIssueCode.invalid_arguments:
376
+ message = "Invalid function arguments";
377
+ break;
378
+ case ZodIssueCode.invalid_return_type:
379
+ message = "Invalid function return type";
380
+ break;
381
+ case ZodIssueCode.invalid_date:
382
+ message = "Invalid date";
383
+ break;
384
+ case ZodIssueCode.invalid_string:
385
+ if ("object" == typeof issue.validation) if ("includes" in issue.validation) {
386
+ message = `Invalid input: must include "${issue.validation.includes}"`;
387
+ if ("number" == typeof issue.validation.position) message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
388
+ } else if ("startsWith" in issue.validation) message = `Invalid input: must start with "${issue.validation.startsWith}"`;
389
+ else if ("endsWith" in issue.validation) message = `Invalid input: must end with "${issue.validation.endsWith}"`;
390
+ else util_util.assertNever(issue.validation);
391
+ else message = "regex" !== issue.validation ? `Invalid ${issue.validation}` : "Invalid";
392
+ break;
393
+ case ZodIssueCode.too_small:
394
+ message = "array" === issue.type ? `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than"} ${issue.minimum} element(s)` : "string" === issue.type ? `String must contain ${issue.exact ? "exactly" : issue.inclusive ? "at least" : "over"} ${issue.minimum} character(s)` : "number" === issue.type ? `Number must be ${issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than "}${issue.minimum}` : "date" === issue.type ? `Date must be ${issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(issue.minimum))}` : "Invalid input";
395
+ break;
396
+ case ZodIssueCode.too_big:
397
+ message = "array" === issue.type ? `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? "at most" : "less than"} ${issue.maximum} element(s)` : "string" === issue.type ? `String must contain ${issue.exact ? "exactly" : issue.inclusive ? "at most" : "under"} ${issue.maximum} character(s)` : "number" === issue.type ? `Number must be ${issue.exact ? "exactly" : issue.inclusive ? "less than or equal to" : "less than"} ${issue.maximum}` : "bigint" === issue.type ? `BigInt must be ${issue.exact ? "exactly" : issue.inclusive ? "less than or equal to" : "less than"} ${issue.maximum}` : "date" === issue.type ? `Date must be ${issue.exact ? "exactly" : issue.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(issue.maximum))}` : "Invalid input";
398
+ break;
399
+ case ZodIssueCode.custom:
400
+ message = "Invalid input";
401
+ break;
402
+ case ZodIssueCode.invalid_intersection_types:
403
+ message = "Intersection results could not be merged";
404
+ break;
405
+ case ZodIssueCode.not_multiple_of:
406
+ message = `Number must be a multiple of ${issue.multipleOf}`;
407
+ break;
408
+ case ZodIssueCode.not_finite:
409
+ message = "Number must be finite";
410
+ break;
411
+ default:
412
+ message = _ctx.defaultError;
413
+ util_util.assertNever(issue);
414
+ }
415
+ return {
416
+ message
417
+ };
418
+ };
419
+ const en = en_errorMap;
420
+ let overrideErrorMap = en;
421
+ function setErrorMap(map) {
422
+ overrideErrorMap = map;
423
+ }
424
+ function getErrorMap() {
425
+ return overrideErrorMap;
426
+ }
427
+ const makeIssue = (params)=>{
428
+ const { data, path, errorMaps, issueData } = params;
429
+ const fullPath = [
430
+ ...path,
431
+ ...issueData.path || []
432
+ ];
433
+ const fullIssue = {
434
+ ...issueData,
435
+ path: fullPath
436
+ };
437
+ if (void 0 !== issueData.message) return {
438
+ ...issueData,
439
+ path: fullPath,
440
+ message: issueData.message
441
+ };
442
+ let errorMessage = "";
443
+ const maps = errorMaps.filter((m)=>!!m).slice().reverse();
444
+ for (const map of maps)errorMessage = map(fullIssue, {
445
+ data,
446
+ defaultError: errorMessage
447
+ }).message;
448
+ return {
449
+ ...issueData,
450
+ path: fullPath,
451
+ message: errorMessage
452
+ };
453
+ };
454
+ const EMPTY_PATH = [];
455
+ function addIssueToContext(ctx, issueData) {
456
+ const overrideMap = getErrorMap();
457
+ const issue = makeIssue({
458
+ issueData: issueData,
459
+ data: ctx.data,
460
+ path: ctx.path,
461
+ errorMaps: [
462
+ ctx.common.contextualErrorMap,
463
+ ctx.schemaErrorMap,
464
+ overrideMap,
465
+ overrideMap === en ? void 0 : en
466
+ ].filter((x)=>!!x)
467
+ });
468
+ ctx.common.issues.push(issue);
469
+ }
470
+ class ParseStatus {
471
+ constructor(){
472
+ this.value = "valid";
473
+ }
474
+ dirty() {
475
+ if ("valid" === this.value) this.value = "dirty";
476
+ }
477
+ abort() {
478
+ if ("aborted" !== this.value) this.value = "aborted";
479
+ }
480
+ static mergeArray(status, results) {
481
+ const arrayValue = [];
482
+ for (const s of results){
483
+ if ("aborted" === s.status) return INVALID;
484
+ if ("dirty" === s.status) status.dirty();
485
+ arrayValue.push(s.value);
486
+ }
487
+ return {
488
+ status: status.value,
489
+ value: arrayValue
490
+ };
491
+ }
492
+ static async mergeObjectAsync(status, pairs) {
493
+ const syncPairs = [];
494
+ for (const pair of pairs){
495
+ const key = await pair.key;
496
+ const value = await pair.value;
497
+ syncPairs.push({
498
+ key,
499
+ value
500
+ });
501
+ }
502
+ return ParseStatus.mergeObjectSync(status, syncPairs);
503
+ }
504
+ static mergeObjectSync(status, pairs) {
505
+ const finalObject = {};
506
+ for (const pair of pairs){
507
+ const { key, value } = pair;
508
+ if ("aborted" === key.status) return INVALID;
509
+ if ("aborted" === value.status) return INVALID;
510
+ if ("dirty" === key.status) status.dirty();
511
+ if ("dirty" === value.status) status.dirty();
512
+ if ("__proto__" !== key.value && (void 0 !== value.value || pair.alwaysSet)) finalObject[key.value] = value.value;
513
+ }
514
+ return {
515
+ status: status.value,
516
+ value: finalObject
517
+ };
518
+ }
519
+ }
520
+ const INVALID = Object.freeze({
521
+ status: "aborted"
522
+ });
523
+ const DIRTY = (value)=>({
524
+ status: "dirty",
525
+ value
526
+ });
527
+ const OK = (value)=>({
528
+ status: "valid",
529
+ value
530
+ });
531
+ const isAborted = (x)=>"aborted" === x.status;
532
+ const isDirty = (x)=>"dirty" === x.status;
533
+ const isValid = (x)=>"valid" === x.status;
534
+ const isAsync = (x)=>"undefined" != typeof Promise && x instanceof Promise;
535
+ var errorUtil_errorUtil;
536
+ (function(errorUtil) {
537
+ errorUtil.errToObj = (message)=>"string" == typeof message ? {
538
+ message
539
+ } : message || {};
540
+ errorUtil.toString = (message)=>"string" == typeof message ? message : message?.message;
541
+ })(errorUtil_errorUtil || (errorUtil_errorUtil = {}));
542
+ class ParseInputLazyPath {
543
+ constructor(parent, value, path, key){
544
+ this._cachedPath = [];
545
+ this.parent = parent;
546
+ this.data = value;
547
+ this._path = path;
548
+ this._key = key;
549
+ }
550
+ get path() {
551
+ if (!this._cachedPath.length) if (Array.isArray(this._key)) this._cachedPath.push(...this._path, ...this._key);
552
+ else this._cachedPath.push(...this._path, this._key);
553
+ return this._cachedPath;
554
+ }
555
+ }
556
+ const handleResult = (ctx, result)=>{
557
+ if (isValid(result)) return {
558
+ success: true,
559
+ data: result.value
560
+ };
561
+ if (!ctx.common.issues.length) throw new Error("Validation failed but no issues detected.");
562
+ return {
563
+ success: false,
564
+ get error () {
565
+ if (this._error) return this._error;
566
+ const error = new ZodError(ctx.common.issues);
567
+ this._error = error;
568
+ return this._error;
569
+ }
570
+ };
571
+ };
572
+ function processCreateParams(params) {
573
+ if (!params) return {};
574
+ const { errorMap, invalid_type_error, required_error, description } = params;
575
+ if (errorMap && (invalid_type_error || required_error)) throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');
576
+ if (errorMap) return {
577
+ errorMap: errorMap,
578
+ description
579
+ };
580
+ const customMap = (iss, ctx)=>{
581
+ const { message } = params;
582
+ if ("invalid_enum_value" === iss.code) return {
583
+ message: message ?? ctx.defaultError
584
+ };
585
+ if (void 0 === ctx.data) return {
586
+ message: message ?? required_error ?? ctx.defaultError
587
+ };
588
+ if ("invalid_type" !== iss.code) return {
589
+ message: ctx.defaultError
590
+ };
591
+ return {
592
+ message: message ?? invalid_type_error ?? ctx.defaultError
593
+ };
594
+ };
595
+ return {
596
+ errorMap: customMap,
597
+ description
598
+ };
599
+ }
600
+ class ZodType {
601
+ get description() {
602
+ return this._def.description;
603
+ }
604
+ _getType(input) {
605
+ return getParsedType(input.data);
606
+ }
607
+ _getOrReturnCtx(input, ctx) {
608
+ return ctx || {
609
+ common: input.parent.common,
610
+ data: input.data,
611
+ parsedType: getParsedType(input.data),
612
+ schemaErrorMap: this._def.errorMap,
613
+ path: input.path,
614
+ parent: input.parent
615
+ };
616
+ }
617
+ _processInputParams(input) {
618
+ return {
619
+ status: new ParseStatus(),
620
+ ctx: {
621
+ common: input.parent.common,
622
+ data: input.data,
623
+ parsedType: getParsedType(input.data),
624
+ schemaErrorMap: this._def.errorMap,
625
+ path: input.path,
626
+ parent: input.parent
627
+ }
628
+ };
629
+ }
630
+ _parseSync(input) {
631
+ const result = this._parse(input);
632
+ if (isAsync(result)) throw new Error("Synchronous parse encountered promise.");
633
+ return result;
634
+ }
635
+ _parseAsync(input) {
636
+ const result = this._parse(input);
637
+ return Promise.resolve(result);
638
+ }
639
+ parse(data, params) {
640
+ const result = this.safeParse(data, params);
641
+ if (result.success) return result.data;
642
+ throw result.error;
643
+ }
644
+ safeParse(data, params) {
645
+ const ctx = {
646
+ common: {
647
+ issues: [],
648
+ async: params?.async ?? false,
649
+ contextualErrorMap: params?.errorMap
650
+ },
651
+ path: params?.path || [],
652
+ schemaErrorMap: this._def.errorMap,
653
+ parent: null,
654
+ data,
655
+ parsedType: getParsedType(data)
656
+ };
657
+ const result = this._parseSync({
658
+ data,
659
+ path: ctx.path,
660
+ parent: ctx
661
+ });
662
+ return handleResult(ctx, result);
663
+ }
664
+ "~validate"(data) {
665
+ const ctx = {
666
+ common: {
667
+ issues: [],
668
+ async: !!this["~standard"].async
669
+ },
670
+ path: [],
671
+ schemaErrorMap: this._def.errorMap,
672
+ parent: null,
673
+ data,
674
+ parsedType: getParsedType(data)
675
+ };
676
+ if (!this["~standard"].async) try {
677
+ const result = this._parseSync({
678
+ data,
679
+ path: [],
680
+ parent: ctx
681
+ });
682
+ return isValid(result) ? {
683
+ value: result.value
684
+ } : {
685
+ issues: ctx.common.issues
686
+ };
687
+ } catch (err) {
688
+ if (err?.message?.toLowerCase()?.includes("encountered")) this["~standard"].async = true;
689
+ ctx.common = {
690
+ issues: [],
691
+ async: true
692
+ };
693
+ }
694
+ return this._parseAsync({
695
+ data,
696
+ path: [],
697
+ parent: ctx
698
+ }).then((result)=>isValid(result) ? {
699
+ value: result.value
700
+ } : {
701
+ issues: ctx.common.issues
702
+ });
703
+ }
704
+ async parseAsync(data, params) {
705
+ const result = await this.safeParseAsync(data, params);
706
+ if (result.success) return result.data;
707
+ throw result.error;
708
+ }
709
+ async safeParseAsync(data, params) {
710
+ const ctx = {
711
+ common: {
712
+ issues: [],
713
+ contextualErrorMap: params?.errorMap,
714
+ async: true
715
+ },
716
+ path: params?.path || [],
717
+ schemaErrorMap: this._def.errorMap,
718
+ parent: null,
719
+ data,
720
+ parsedType: getParsedType(data)
721
+ };
722
+ const maybeAsyncResult = this._parse({
723
+ data,
724
+ path: ctx.path,
725
+ parent: ctx
726
+ });
727
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
728
+ return handleResult(ctx, result);
729
+ }
730
+ refine(check, message) {
731
+ const getIssueProperties = (val)=>{
732
+ if ("string" == typeof message || void 0 === message) return {
733
+ message
734
+ };
735
+ if ("function" == typeof message) return message(val);
736
+ return message;
737
+ };
738
+ return this._refinement((val, ctx)=>{
739
+ const result = check(val);
740
+ const setError = ()=>ctx.addIssue({
741
+ code: ZodIssueCode.custom,
742
+ ...getIssueProperties(val)
743
+ });
744
+ if ("undefined" != typeof Promise && result instanceof Promise) return result.then((data)=>{
745
+ if (data) return true;
746
+ setError();
747
+ return false;
748
+ });
749
+ if (result) return true;
750
+ setError();
751
+ return false;
752
+ });
753
+ }
754
+ refinement(check, refinementData) {
755
+ return this._refinement((val, ctx)=>{
756
+ if (check(val)) return true;
757
+ ctx.addIssue("function" == typeof refinementData ? refinementData(val, ctx) : refinementData);
758
+ return false;
759
+ });
760
+ }
761
+ _refinement(refinement) {
762
+ return new ZodEffects({
763
+ schema: this,
764
+ typeName: types_ZodFirstPartyTypeKind.ZodEffects,
765
+ effect: {
766
+ type: "refinement",
767
+ refinement
768
+ }
769
+ });
770
+ }
771
+ superRefine(refinement) {
772
+ return this._refinement(refinement);
773
+ }
774
+ constructor(def){
775
+ this.spa = this.safeParseAsync;
776
+ this._def = def;
777
+ this.parse = this.parse.bind(this);
778
+ this.safeParse = this.safeParse.bind(this);
779
+ this.parseAsync = this.parseAsync.bind(this);
780
+ this.safeParseAsync = this.safeParseAsync.bind(this);
781
+ this.spa = this.spa.bind(this);
782
+ this.refine = this.refine.bind(this);
783
+ this.refinement = this.refinement.bind(this);
784
+ this.superRefine = this.superRefine.bind(this);
785
+ this.optional = this.optional.bind(this);
786
+ this.nullable = this.nullable.bind(this);
787
+ this.nullish = this.nullish.bind(this);
788
+ this.array = this.array.bind(this);
789
+ this.promise = this.promise.bind(this);
790
+ this.or = this.or.bind(this);
791
+ this.and = this.and.bind(this);
792
+ this.transform = this.transform.bind(this);
793
+ this.brand = this.brand.bind(this);
794
+ this.default = this.default.bind(this);
795
+ this.catch = this.catch.bind(this);
796
+ this.describe = this.describe.bind(this);
797
+ this.pipe = this.pipe.bind(this);
798
+ this.readonly = this.readonly.bind(this);
799
+ this.isNullable = this.isNullable.bind(this);
800
+ this.isOptional = this.isOptional.bind(this);
801
+ this["~standard"] = {
802
+ version: 1,
803
+ vendor: "zod",
804
+ validate: (data)=>this["~validate"](data)
805
+ };
806
+ }
807
+ optional() {
808
+ return ZodOptional.create(this, this._def);
809
+ }
810
+ nullable() {
811
+ return ZodNullable.create(this, this._def);
812
+ }
813
+ nullish() {
814
+ return this.nullable().optional();
815
+ }
816
+ array() {
817
+ return ZodArray.create(this);
818
+ }
819
+ promise() {
820
+ return ZodPromise.create(this, this._def);
821
+ }
822
+ or(option) {
823
+ return ZodUnion.create([
824
+ this,
825
+ option
826
+ ], this._def);
827
+ }
828
+ and(incoming) {
829
+ return ZodIntersection.create(this, incoming, this._def);
830
+ }
831
+ transform(transform) {
832
+ return new ZodEffects({
833
+ ...processCreateParams(this._def),
834
+ schema: this,
835
+ typeName: types_ZodFirstPartyTypeKind.ZodEffects,
836
+ effect: {
837
+ type: "transform",
838
+ transform
839
+ }
840
+ });
841
+ }
842
+ default(def) {
843
+ const defaultValueFunc = "function" == typeof def ? def : ()=>def;
844
+ return new ZodDefault({
845
+ ...processCreateParams(this._def),
846
+ innerType: this,
847
+ defaultValue: defaultValueFunc,
848
+ typeName: types_ZodFirstPartyTypeKind.ZodDefault
849
+ });
850
+ }
851
+ brand() {
852
+ return new ZodBranded({
853
+ typeName: types_ZodFirstPartyTypeKind.ZodBranded,
854
+ type: this,
855
+ ...processCreateParams(this._def)
856
+ });
857
+ }
858
+ catch(def) {
859
+ const catchValueFunc = "function" == typeof def ? def : ()=>def;
860
+ return new ZodCatch({
861
+ ...processCreateParams(this._def),
862
+ innerType: this,
863
+ catchValue: catchValueFunc,
864
+ typeName: types_ZodFirstPartyTypeKind.ZodCatch
865
+ });
866
+ }
867
+ describe(description) {
868
+ const This = this.constructor;
869
+ return new This({
870
+ ...this._def,
871
+ description
872
+ });
873
+ }
874
+ pipe(target) {
875
+ return ZodPipeline.create(this, target);
876
+ }
877
+ readonly() {
878
+ return ZodReadonly.create(this);
879
+ }
880
+ isOptional() {
881
+ return this.safeParse(void 0).success;
882
+ }
883
+ isNullable() {
884
+ return this.safeParse(null).success;
885
+ }
886
+ }
887
+ const cuidRegex = /^c[^\s-]{8,}$/i;
888
+ const cuid2Regex = /^[0-9a-z]+$/;
889
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
890
+ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
891
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
892
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
893
+ const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
894
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
895
+ const _emojiRegex = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
896
+ let emojiRegex;
897
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
898
+ const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
899
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
900
+ const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
901
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
902
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
903
+ const dateRegexSource = "((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))";
904
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
905
+ function timeRegexSource(args) {
906
+ let secondsRegexSource = "[0-5]\\d";
907
+ if (args.precision) secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
908
+ else if (null == args.precision) secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
909
+ const secondsQuantifier = args.precision ? "+" : "?";
910
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
911
+ }
912
+ function timeRegex(args) {
913
+ return new RegExp(`^${timeRegexSource(args)}$`);
914
+ }
915
+ function datetimeRegex(args) {
916
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
917
+ const opts = [];
918
+ opts.push(args.local ? "Z?" : "Z");
919
+ if (args.offset) opts.push("([+-]\\d{2}:?\\d{2})");
920
+ regex = `${regex}(${opts.join("|")})`;
921
+ return new RegExp(`^${regex}$`);
922
+ }
923
+ function isValidIP(ip, version) {
924
+ if (("v4" === version || !version) && ipv4Regex.test(ip)) return true;
925
+ if (("v6" === version || !version) && ipv6Regex.test(ip)) return true;
926
+ return false;
927
+ }
928
+ function isValidJWT(jwt, alg) {
929
+ if (!jwtRegex.test(jwt)) return false;
930
+ try {
931
+ const [header] = jwt.split(".");
932
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
933
+ const decoded = JSON.parse(atob(base64));
934
+ if ("object" != typeof decoded || null === decoded) return false;
935
+ if ("typ" in decoded && decoded?.typ !== "JWT") return false;
936
+ if (!decoded.alg) return false;
937
+ if (alg && decoded.alg !== alg) return false;
938
+ return true;
939
+ } catch {
940
+ return false;
941
+ }
942
+ }
943
+ function isValidCidr(ip, version) {
944
+ if (("v4" === version || !version) && ipv4CidrRegex.test(ip)) return true;
945
+ if (("v6" === version || !version) && ipv6CidrRegex.test(ip)) return true;
946
+ return false;
947
+ }
948
+ class ZodString extends ZodType {
949
+ _parse(input) {
950
+ if (this._def.coerce) input.data = String(input.data);
951
+ const parsedType = this._getType(input);
952
+ if (parsedType !== ZodParsedType.string) {
953
+ const ctx = this._getOrReturnCtx(input);
954
+ addIssueToContext(ctx, {
955
+ code: ZodIssueCode.invalid_type,
956
+ expected: ZodParsedType.string,
957
+ received: ctx.parsedType
958
+ });
959
+ return INVALID;
960
+ }
961
+ const status = new ParseStatus();
962
+ let ctx;
963
+ for (const check of this._def.checks)if ("min" === check.kind) {
964
+ if (input.data.length < check.value) {
965
+ ctx = this._getOrReturnCtx(input, ctx);
966
+ addIssueToContext(ctx, {
967
+ code: ZodIssueCode.too_small,
968
+ minimum: check.value,
969
+ type: "string",
970
+ inclusive: true,
971
+ exact: false,
972
+ message: check.message
973
+ });
974
+ status.dirty();
975
+ }
976
+ } else if ("max" === check.kind) {
977
+ if (input.data.length > check.value) {
978
+ ctx = this._getOrReturnCtx(input, ctx);
979
+ addIssueToContext(ctx, {
980
+ code: ZodIssueCode.too_big,
981
+ maximum: check.value,
982
+ type: "string",
983
+ inclusive: true,
984
+ exact: false,
985
+ message: check.message
986
+ });
987
+ status.dirty();
988
+ }
989
+ } else if ("length" === check.kind) {
990
+ const tooBig = input.data.length > check.value;
991
+ const tooSmall = input.data.length < check.value;
992
+ if (tooBig || tooSmall) {
993
+ ctx = this._getOrReturnCtx(input, ctx);
994
+ if (tooBig) addIssueToContext(ctx, {
995
+ code: ZodIssueCode.too_big,
996
+ maximum: check.value,
997
+ type: "string",
998
+ inclusive: true,
999
+ exact: true,
1000
+ message: check.message
1001
+ });
1002
+ else if (tooSmall) addIssueToContext(ctx, {
1003
+ code: ZodIssueCode.too_small,
1004
+ minimum: check.value,
1005
+ type: "string",
1006
+ inclusive: true,
1007
+ exact: true,
1008
+ message: check.message
1009
+ });
1010
+ status.dirty();
1011
+ }
1012
+ } else if ("email" === check.kind) {
1013
+ if (!emailRegex.test(input.data)) {
1014
+ ctx = this._getOrReturnCtx(input, ctx);
1015
+ addIssueToContext(ctx, {
1016
+ validation: "email",
1017
+ code: ZodIssueCode.invalid_string,
1018
+ message: check.message
1019
+ });
1020
+ status.dirty();
1021
+ }
1022
+ } else if ("emoji" === check.kind) {
1023
+ if (!emojiRegex) emojiRegex = new RegExp(_emojiRegex, "u");
1024
+ if (!emojiRegex.test(input.data)) {
1025
+ ctx = this._getOrReturnCtx(input, ctx);
1026
+ addIssueToContext(ctx, {
1027
+ validation: "emoji",
1028
+ code: ZodIssueCode.invalid_string,
1029
+ message: check.message
1030
+ });
1031
+ status.dirty();
1032
+ }
1033
+ } else if ("uuid" === check.kind) {
1034
+ if (!uuidRegex.test(input.data)) {
1035
+ ctx = this._getOrReturnCtx(input, ctx);
1036
+ addIssueToContext(ctx, {
1037
+ validation: "uuid",
1038
+ code: ZodIssueCode.invalid_string,
1039
+ message: check.message
1040
+ });
1041
+ status.dirty();
1042
+ }
1043
+ } else if ("nanoid" === check.kind) {
1044
+ if (!nanoidRegex.test(input.data)) {
1045
+ ctx = this._getOrReturnCtx(input, ctx);
1046
+ addIssueToContext(ctx, {
1047
+ validation: "nanoid",
1048
+ code: ZodIssueCode.invalid_string,
1049
+ message: check.message
1050
+ });
1051
+ status.dirty();
1052
+ }
1053
+ } else if ("cuid" === check.kind) {
1054
+ if (!cuidRegex.test(input.data)) {
1055
+ ctx = this._getOrReturnCtx(input, ctx);
1056
+ addIssueToContext(ctx, {
1057
+ validation: "cuid",
1058
+ code: ZodIssueCode.invalid_string,
1059
+ message: check.message
1060
+ });
1061
+ status.dirty();
1062
+ }
1063
+ } else if ("cuid2" === check.kind) {
1064
+ if (!cuid2Regex.test(input.data)) {
1065
+ ctx = this._getOrReturnCtx(input, ctx);
1066
+ addIssueToContext(ctx, {
1067
+ validation: "cuid2",
1068
+ code: ZodIssueCode.invalid_string,
1069
+ message: check.message
1070
+ });
1071
+ status.dirty();
1072
+ }
1073
+ } else if ("ulid" === check.kind) {
1074
+ if (!ulidRegex.test(input.data)) {
1075
+ ctx = this._getOrReturnCtx(input, ctx);
1076
+ addIssueToContext(ctx, {
1077
+ validation: "ulid",
1078
+ code: ZodIssueCode.invalid_string,
1079
+ message: check.message
1080
+ });
1081
+ status.dirty();
1082
+ }
1083
+ } else if ("url" === check.kind) try {
1084
+ new URL(input.data);
1085
+ } catch {
1086
+ ctx = this._getOrReturnCtx(input, ctx);
1087
+ addIssueToContext(ctx, {
1088
+ validation: "url",
1089
+ code: ZodIssueCode.invalid_string,
1090
+ message: check.message
1091
+ });
1092
+ status.dirty();
1093
+ }
1094
+ else if ("regex" === check.kind) {
1095
+ check.regex.lastIndex = 0;
1096
+ const testResult = check.regex.test(input.data);
1097
+ if (!testResult) {
1098
+ ctx = this._getOrReturnCtx(input, ctx);
1099
+ addIssueToContext(ctx, {
1100
+ validation: "regex",
1101
+ code: ZodIssueCode.invalid_string,
1102
+ message: check.message
1103
+ });
1104
+ status.dirty();
1105
+ }
1106
+ } else if ("trim" === check.kind) input.data = input.data.trim();
1107
+ else if ("includes" === check.kind) {
1108
+ if (!input.data.includes(check.value, check.position)) {
1109
+ ctx = this._getOrReturnCtx(input, ctx);
1110
+ addIssueToContext(ctx, {
1111
+ code: ZodIssueCode.invalid_string,
1112
+ validation: {
1113
+ includes: check.value,
1114
+ position: check.position
1115
+ },
1116
+ message: check.message
1117
+ });
1118
+ status.dirty();
1119
+ }
1120
+ } else if ("toLowerCase" === check.kind) input.data = input.data.toLowerCase();
1121
+ else if ("toUpperCase" === check.kind) input.data = input.data.toUpperCase();
1122
+ else if ("startsWith" === check.kind) {
1123
+ if (!input.data.startsWith(check.value)) {
1124
+ ctx = this._getOrReturnCtx(input, ctx);
1125
+ addIssueToContext(ctx, {
1126
+ code: ZodIssueCode.invalid_string,
1127
+ validation: {
1128
+ startsWith: check.value
1129
+ },
1130
+ message: check.message
1131
+ });
1132
+ status.dirty();
1133
+ }
1134
+ } else if ("endsWith" === check.kind) {
1135
+ if (!input.data.endsWith(check.value)) {
1136
+ ctx = this._getOrReturnCtx(input, ctx);
1137
+ addIssueToContext(ctx, {
1138
+ code: ZodIssueCode.invalid_string,
1139
+ validation: {
1140
+ endsWith: check.value
1141
+ },
1142
+ message: check.message
1143
+ });
1144
+ status.dirty();
1145
+ }
1146
+ } else if ("datetime" === check.kind) {
1147
+ const regex = datetimeRegex(check);
1148
+ if (!regex.test(input.data)) {
1149
+ ctx = this._getOrReturnCtx(input, ctx);
1150
+ addIssueToContext(ctx, {
1151
+ code: ZodIssueCode.invalid_string,
1152
+ validation: "datetime",
1153
+ message: check.message
1154
+ });
1155
+ status.dirty();
1156
+ }
1157
+ } else if ("date" === check.kind) {
1158
+ const regex = dateRegex;
1159
+ if (!regex.test(input.data)) {
1160
+ ctx = this._getOrReturnCtx(input, ctx);
1161
+ addIssueToContext(ctx, {
1162
+ code: ZodIssueCode.invalid_string,
1163
+ validation: "date",
1164
+ message: check.message
1165
+ });
1166
+ status.dirty();
1167
+ }
1168
+ } else if ("time" === check.kind) {
1169
+ const regex = timeRegex(check);
1170
+ if (!regex.test(input.data)) {
1171
+ ctx = this._getOrReturnCtx(input, ctx);
1172
+ addIssueToContext(ctx, {
1173
+ code: ZodIssueCode.invalid_string,
1174
+ validation: "time",
1175
+ message: check.message
1176
+ });
1177
+ status.dirty();
1178
+ }
1179
+ } else if ("duration" === check.kind) {
1180
+ if (!durationRegex.test(input.data)) {
1181
+ ctx = this._getOrReturnCtx(input, ctx);
1182
+ addIssueToContext(ctx, {
1183
+ validation: "duration",
1184
+ code: ZodIssueCode.invalid_string,
1185
+ message: check.message
1186
+ });
1187
+ status.dirty();
1188
+ }
1189
+ } else if ("ip" === check.kind) {
1190
+ if (!isValidIP(input.data, check.version)) {
1191
+ ctx = this._getOrReturnCtx(input, ctx);
1192
+ addIssueToContext(ctx, {
1193
+ validation: "ip",
1194
+ code: ZodIssueCode.invalid_string,
1195
+ message: check.message
1196
+ });
1197
+ status.dirty();
1198
+ }
1199
+ } else if ("jwt" === check.kind) {
1200
+ if (!isValidJWT(input.data, check.alg)) {
1201
+ ctx = this._getOrReturnCtx(input, ctx);
1202
+ addIssueToContext(ctx, {
1203
+ validation: "jwt",
1204
+ code: ZodIssueCode.invalid_string,
1205
+ message: check.message
1206
+ });
1207
+ status.dirty();
1208
+ }
1209
+ } else if ("cidr" === check.kind) {
1210
+ if (!isValidCidr(input.data, check.version)) {
1211
+ ctx = this._getOrReturnCtx(input, ctx);
1212
+ addIssueToContext(ctx, {
1213
+ validation: "cidr",
1214
+ code: ZodIssueCode.invalid_string,
1215
+ message: check.message
1216
+ });
1217
+ status.dirty();
1218
+ }
1219
+ } else if ("base64" === check.kind) {
1220
+ if (!base64Regex.test(input.data)) {
1221
+ ctx = this._getOrReturnCtx(input, ctx);
1222
+ addIssueToContext(ctx, {
1223
+ validation: "base64",
1224
+ code: ZodIssueCode.invalid_string,
1225
+ message: check.message
1226
+ });
1227
+ status.dirty();
1228
+ }
1229
+ } else if ("base64url" === check.kind) {
1230
+ if (!base64urlRegex.test(input.data)) {
1231
+ ctx = this._getOrReturnCtx(input, ctx);
1232
+ addIssueToContext(ctx, {
1233
+ validation: "base64url",
1234
+ code: ZodIssueCode.invalid_string,
1235
+ message: check.message
1236
+ });
1237
+ status.dirty();
1238
+ }
1239
+ } else util_util.assertNever(check);
1240
+ return {
1241
+ status: status.value,
1242
+ value: input.data
1243
+ };
1244
+ }
1245
+ _regex(regex, validation, message) {
1246
+ return this.refinement((data)=>regex.test(data), {
1247
+ validation,
1248
+ code: ZodIssueCode.invalid_string,
1249
+ ...errorUtil_errorUtil.errToObj(message)
1250
+ });
1251
+ }
1252
+ _addCheck(check) {
1253
+ return new ZodString({
1254
+ ...this._def,
1255
+ checks: [
1256
+ ...this._def.checks,
1257
+ check
1258
+ ]
1259
+ });
1260
+ }
1261
+ email(message) {
1262
+ return this._addCheck({
1263
+ kind: "email",
1264
+ ...errorUtil_errorUtil.errToObj(message)
1265
+ });
1266
+ }
1267
+ url(message) {
1268
+ return this._addCheck({
1269
+ kind: "url",
1270
+ ...errorUtil_errorUtil.errToObj(message)
1271
+ });
1272
+ }
1273
+ emoji(message) {
1274
+ return this._addCheck({
1275
+ kind: "emoji",
1276
+ ...errorUtil_errorUtil.errToObj(message)
1277
+ });
1278
+ }
1279
+ uuid(message) {
1280
+ return this._addCheck({
1281
+ kind: "uuid",
1282
+ ...errorUtil_errorUtil.errToObj(message)
1283
+ });
1284
+ }
1285
+ nanoid(message) {
1286
+ return this._addCheck({
1287
+ kind: "nanoid",
1288
+ ...errorUtil_errorUtil.errToObj(message)
1289
+ });
1290
+ }
1291
+ cuid(message) {
1292
+ return this._addCheck({
1293
+ kind: "cuid",
1294
+ ...errorUtil_errorUtil.errToObj(message)
1295
+ });
1296
+ }
1297
+ cuid2(message) {
1298
+ return this._addCheck({
1299
+ kind: "cuid2",
1300
+ ...errorUtil_errorUtil.errToObj(message)
1301
+ });
1302
+ }
1303
+ ulid(message) {
1304
+ return this._addCheck({
1305
+ kind: "ulid",
1306
+ ...errorUtil_errorUtil.errToObj(message)
1307
+ });
1308
+ }
1309
+ base64(message) {
1310
+ return this._addCheck({
1311
+ kind: "base64",
1312
+ ...errorUtil_errorUtil.errToObj(message)
1313
+ });
1314
+ }
1315
+ base64url(message) {
1316
+ return this._addCheck({
1317
+ kind: "base64url",
1318
+ ...errorUtil_errorUtil.errToObj(message)
1319
+ });
1320
+ }
1321
+ jwt(options) {
1322
+ return this._addCheck({
1323
+ kind: "jwt",
1324
+ ...errorUtil_errorUtil.errToObj(options)
1325
+ });
1326
+ }
1327
+ ip(options) {
1328
+ return this._addCheck({
1329
+ kind: "ip",
1330
+ ...errorUtil_errorUtil.errToObj(options)
1331
+ });
1332
+ }
1333
+ cidr(options) {
1334
+ return this._addCheck({
1335
+ kind: "cidr",
1336
+ ...errorUtil_errorUtil.errToObj(options)
1337
+ });
1338
+ }
1339
+ datetime(options) {
1340
+ if ("string" == typeof options) return this._addCheck({
1341
+ kind: "datetime",
1342
+ precision: null,
1343
+ offset: false,
1344
+ local: false,
1345
+ message: options
1346
+ });
1347
+ return this._addCheck({
1348
+ kind: "datetime",
1349
+ precision: void 0 === options?.precision ? null : options?.precision,
1350
+ offset: options?.offset ?? false,
1351
+ local: options?.local ?? false,
1352
+ ...errorUtil_errorUtil.errToObj(options?.message)
1353
+ });
1354
+ }
1355
+ date(message) {
1356
+ return this._addCheck({
1357
+ kind: "date",
1358
+ message
1359
+ });
1360
+ }
1361
+ time(options) {
1362
+ if ("string" == typeof options) return this._addCheck({
1363
+ kind: "time",
1364
+ precision: null,
1365
+ message: options
1366
+ });
1367
+ return this._addCheck({
1368
+ kind: "time",
1369
+ precision: void 0 === options?.precision ? null : options?.precision,
1370
+ ...errorUtil_errorUtil.errToObj(options?.message)
1371
+ });
1372
+ }
1373
+ duration(message) {
1374
+ return this._addCheck({
1375
+ kind: "duration",
1376
+ ...errorUtil_errorUtil.errToObj(message)
1377
+ });
1378
+ }
1379
+ regex(regex, message) {
1380
+ return this._addCheck({
1381
+ kind: "regex",
1382
+ regex: regex,
1383
+ ...errorUtil_errorUtil.errToObj(message)
1384
+ });
1385
+ }
1386
+ includes(value, options) {
1387
+ return this._addCheck({
1388
+ kind: "includes",
1389
+ value: value,
1390
+ position: options?.position,
1391
+ ...errorUtil_errorUtil.errToObj(options?.message)
1392
+ });
1393
+ }
1394
+ startsWith(value, message) {
1395
+ return this._addCheck({
1396
+ kind: "startsWith",
1397
+ value: value,
1398
+ ...errorUtil_errorUtil.errToObj(message)
1399
+ });
1400
+ }
1401
+ endsWith(value, message) {
1402
+ return this._addCheck({
1403
+ kind: "endsWith",
1404
+ value: value,
1405
+ ...errorUtil_errorUtil.errToObj(message)
1406
+ });
1407
+ }
1408
+ min(minLength, message) {
1409
+ return this._addCheck({
1410
+ kind: "min",
1411
+ value: minLength,
1412
+ ...errorUtil_errorUtil.errToObj(message)
1413
+ });
1414
+ }
1415
+ max(maxLength, message) {
1416
+ return this._addCheck({
1417
+ kind: "max",
1418
+ value: maxLength,
1419
+ ...errorUtil_errorUtil.errToObj(message)
1420
+ });
1421
+ }
1422
+ length(len, message) {
1423
+ return this._addCheck({
1424
+ kind: "length",
1425
+ value: len,
1426
+ ...errorUtil_errorUtil.errToObj(message)
1427
+ });
1428
+ }
1429
+ nonempty(message) {
1430
+ return this.min(1, errorUtil_errorUtil.errToObj(message));
1431
+ }
1432
+ trim() {
1433
+ return new ZodString({
1434
+ ...this._def,
1435
+ checks: [
1436
+ ...this._def.checks,
1437
+ {
1438
+ kind: "trim"
1439
+ }
1440
+ ]
1441
+ });
1442
+ }
1443
+ toLowerCase() {
1444
+ return new ZodString({
1445
+ ...this._def,
1446
+ checks: [
1447
+ ...this._def.checks,
1448
+ {
1449
+ kind: "toLowerCase"
1450
+ }
1451
+ ]
1452
+ });
1453
+ }
1454
+ toUpperCase() {
1455
+ return new ZodString({
1456
+ ...this._def,
1457
+ checks: [
1458
+ ...this._def.checks,
1459
+ {
1460
+ kind: "toUpperCase"
1461
+ }
1462
+ ]
1463
+ });
1464
+ }
1465
+ get isDatetime() {
1466
+ return !!this._def.checks.find((ch)=>"datetime" === ch.kind);
1467
+ }
1468
+ get isDate() {
1469
+ return !!this._def.checks.find((ch)=>"date" === ch.kind);
1470
+ }
1471
+ get isTime() {
1472
+ return !!this._def.checks.find((ch)=>"time" === ch.kind);
1473
+ }
1474
+ get isDuration() {
1475
+ return !!this._def.checks.find((ch)=>"duration" === ch.kind);
1476
+ }
1477
+ get isEmail() {
1478
+ return !!this._def.checks.find((ch)=>"email" === ch.kind);
1479
+ }
1480
+ get isURL() {
1481
+ return !!this._def.checks.find((ch)=>"url" === ch.kind);
1482
+ }
1483
+ get isEmoji() {
1484
+ return !!this._def.checks.find((ch)=>"emoji" === ch.kind);
1485
+ }
1486
+ get isUUID() {
1487
+ return !!this._def.checks.find((ch)=>"uuid" === ch.kind);
1488
+ }
1489
+ get isNANOID() {
1490
+ return !!this._def.checks.find((ch)=>"nanoid" === ch.kind);
1491
+ }
1492
+ get isCUID() {
1493
+ return !!this._def.checks.find((ch)=>"cuid" === ch.kind);
1494
+ }
1495
+ get isCUID2() {
1496
+ return !!this._def.checks.find((ch)=>"cuid2" === ch.kind);
1497
+ }
1498
+ get isULID() {
1499
+ return !!this._def.checks.find((ch)=>"ulid" === ch.kind);
1500
+ }
1501
+ get isIP() {
1502
+ return !!this._def.checks.find((ch)=>"ip" === ch.kind);
1503
+ }
1504
+ get isCIDR() {
1505
+ return !!this._def.checks.find((ch)=>"cidr" === ch.kind);
1506
+ }
1507
+ get isBase64() {
1508
+ return !!this._def.checks.find((ch)=>"base64" === ch.kind);
1509
+ }
1510
+ get isBase64url() {
1511
+ return !!this._def.checks.find((ch)=>"base64url" === ch.kind);
1512
+ }
1513
+ get minLength() {
1514
+ let min = null;
1515
+ for (const ch of this._def.checks)if ("min" === ch.kind) {
1516
+ if (null === min || ch.value > min) min = ch.value;
1517
+ }
1518
+ return min;
1519
+ }
1520
+ get maxLength() {
1521
+ let max = null;
1522
+ for (const ch of this._def.checks)if ("max" === ch.kind) {
1523
+ if (null === max || ch.value < max) max = ch.value;
1524
+ }
1525
+ return max;
1526
+ }
1527
+ }
1528
+ ZodString.create = (params)=>new ZodString({
1529
+ checks: [],
1530
+ typeName: types_ZodFirstPartyTypeKind.ZodString,
1531
+ coerce: params?.coerce ?? false,
1532
+ ...processCreateParams(params)
1533
+ });
1534
+ function floatSafeRemainder(val, step) {
1535
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1536
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1537
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1538
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1539
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1540
+ return valInt % stepInt / 10 ** decCount;
1541
+ }
1542
+ class ZodNumber extends ZodType {
1543
+ constructor(){
1544
+ super(...arguments);
1545
+ this.min = this.gte;
1546
+ this.max = this.lte;
1547
+ this.step = this.multipleOf;
1548
+ }
1549
+ _parse(input) {
1550
+ if (this._def.coerce) input.data = Number(input.data);
1551
+ const parsedType = this._getType(input);
1552
+ if (parsedType !== ZodParsedType.number) {
1553
+ const ctx = this._getOrReturnCtx(input);
1554
+ addIssueToContext(ctx, {
1555
+ code: ZodIssueCode.invalid_type,
1556
+ expected: ZodParsedType.number,
1557
+ received: ctx.parsedType
1558
+ });
1559
+ return INVALID;
1560
+ }
1561
+ let ctx;
1562
+ const status = new ParseStatus();
1563
+ for (const check of this._def.checks)if ("int" === check.kind) {
1564
+ if (!util_util.isInteger(input.data)) {
1565
+ ctx = this._getOrReturnCtx(input, ctx);
1566
+ addIssueToContext(ctx, {
1567
+ code: ZodIssueCode.invalid_type,
1568
+ expected: "integer",
1569
+ received: "float",
1570
+ message: check.message
1571
+ });
1572
+ status.dirty();
1573
+ }
1574
+ } else if ("min" === check.kind) {
1575
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1576
+ if (tooSmall) {
1577
+ ctx = this._getOrReturnCtx(input, ctx);
1578
+ addIssueToContext(ctx, {
1579
+ code: ZodIssueCode.too_small,
1580
+ minimum: check.value,
1581
+ type: "number",
1582
+ inclusive: check.inclusive,
1583
+ exact: false,
1584
+ message: check.message
1585
+ });
1586
+ status.dirty();
1587
+ }
1588
+ } else if ("max" === check.kind) {
1589
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1590
+ if (tooBig) {
1591
+ ctx = this._getOrReturnCtx(input, ctx);
1592
+ addIssueToContext(ctx, {
1593
+ code: ZodIssueCode.too_big,
1594
+ maximum: check.value,
1595
+ type: "number",
1596
+ inclusive: check.inclusive,
1597
+ exact: false,
1598
+ message: check.message
1599
+ });
1600
+ status.dirty();
1601
+ }
1602
+ } else if ("multipleOf" === check.kind) {
1603
+ if (0 !== floatSafeRemainder(input.data, check.value)) {
1604
+ ctx = this._getOrReturnCtx(input, ctx);
1605
+ addIssueToContext(ctx, {
1606
+ code: ZodIssueCode.not_multiple_of,
1607
+ multipleOf: check.value,
1608
+ message: check.message
1609
+ });
1610
+ status.dirty();
1611
+ }
1612
+ } else if ("finite" === check.kind) {
1613
+ if (!Number.isFinite(input.data)) {
1614
+ ctx = this._getOrReturnCtx(input, ctx);
1615
+ addIssueToContext(ctx, {
1616
+ code: ZodIssueCode.not_finite,
1617
+ message: check.message
1618
+ });
1619
+ status.dirty();
1620
+ }
1621
+ } else util_util.assertNever(check);
1622
+ return {
1623
+ status: status.value,
1624
+ value: input.data
1625
+ };
1626
+ }
1627
+ gte(value, message) {
1628
+ return this.setLimit("min", value, true, errorUtil_errorUtil.toString(message));
1629
+ }
1630
+ gt(value, message) {
1631
+ return this.setLimit("min", value, false, errorUtil_errorUtil.toString(message));
1632
+ }
1633
+ lte(value, message) {
1634
+ return this.setLimit("max", value, true, errorUtil_errorUtil.toString(message));
1635
+ }
1636
+ lt(value, message) {
1637
+ return this.setLimit("max", value, false, errorUtil_errorUtil.toString(message));
1638
+ }
1639
+ setLimit(kind, value, inclusive, message) {
1640
+ return new ZodNumber({
1641
+ ...this._def,
1642
+ checks: [
1643
+ ...this._def.checks,
1644
+ {
1645
+ kind,
1646
+ value,
1647
+ inclusive,
1648
+ message: errorUtil_errorUtil.toString(message)
1649
+ }
1650
+ ]
1651
+ });
1652
+ }
1653
+ _addCheck(check) {
1654
+ return new ZodNumber({
1655
+ ...this._def,
1656
+ checks: [
1657
+ ...this._def.checks,
1658
+ check
1659
+ ]
1660
+ });
1661
+ }
1662
+ int(message) {
1663
+ return this._addCheck({
1664
+ kind: "int",
1665
+ message: errorUtil_errorUtil.toString(message)
1666
+ });
1667
+ }
1668
+ positive(message) {
1669
+ return this._addCheck({
1670
+ kind: "min",
1671
+ value: 0,
1672
+ inclusive: false,
1673
+ message: errorUtil_errorUtil.toString(message)
1674
+ });
1675
+ }
1676
+ negative(message) {
1677
+ return this._addCheck({
1678
+ kind: "max",
1679
+ value: 0,
1680
+ inclusive: false,
1681
+ message: errorUtil_errorUtil.toString(message)
1682
+ });
1683
+ }
1684
+ nonpositive(message) {
1685
+ return this._addCheck({
1686
+ kind: "max",
1687
+ value: 0,
1688
+ inclusive: true,
1689
+ message: errorUtil_errorUtil.toString(message)
1690
+ });
1691
+ }
1692
+ nonnegative(message) {
1693
+ return this._addCheck({
1694
+ kind: "min",
1695
+ value: 0,
1696
+ inclusive: true,
1697
+ message: errorUtil_errorUtil.toString(message)
1698
+ });
1699
+ }
1700
+ multipleOf(value, message) {
1701
+ return this._addCheck({
1702
+ kind: "multipleOf",
1703
+ value: value,
1704
+ message: errorUtil_errorUtil.toString(message)
1705
+ });
1706
+ }
1707
+ finite(message) {
1708
+ return this._addCheck({
1709
+ kind: "finite",
1710
+ message: errorUtil_errorUtil.toString(message)
1711
+ });
1712
+ }
1713
+ safe(message) {
1714
+ return this._addCheck({
1715
+ kind: "min",
1716
+ inclusive: true,
1717
+ value: Number.MIN_SAFE_INTEGER,
1718
+ message: errorUtil_errorUtil.toString(message)
1719
+ })._addCheck({
1720
+ kind: "max",
1721
+ inclusive: true,
1722
+ value: Number.MAX_SAFE_INTEGER,
1723
+ message: errorUtil_errorUtil.toString(message)
1724
+ });
1725
+ }
1726
+ get minValue() {
1727
+ let min = null;
1728
+ for (const ch of this._def.checks)if ("min" === ch.kind) {
1729
+ if (null === min || ch.value > min) min = ch.value;
1730
+ }
1731
+ return min;
1732
+ }
1733
+ get maxValue() {
1734
+ let max = null;
1735
+ for (const ch of this._def.checks)if ("max" === ch.kind) {
1736
+ if (null === max || ch.value < max) max = ch.value;
1737
+ }
1738
+ return max;
1739
+ }
1740
+ get isInt() {
1741
+ return !!this._def.checks.find((ch)=>"int" === ch.kind || "multipleOf" === ch.kind && util_util.isInteger(ch.value));
1742
+ }
1743
+ get isFinite() {
1744
+ let max = null;
1745
+ let min = null;
1746
+ for (const ch of this._def.checks)if ("finite" === ch.kind || "int" === ch.kind || "multipleOf" === ch.kind) return true;
1747
+ else if ("min" === ch.kind) {
1748
+ if (null === min || ch.value > min) min = ch.value;
1749
+ } else if ("max" === ch.kind) {
1750
+ if (null === max || ch.value < max) max = ch.value;
1751
+ }
1752
+ return Number.isFinite(min) && Number.isFinite(max);
1753
+ }
1754
+ }
1755
+ ZodNumber.create = (params)=>new ZodNumber({
1756
+ checks: [],
1757
+ typeName: types_ZodFirstPartyTypeKind.ZodNumber,
1758
+ coerce: params?.coerce || false,
1759
+ ...processCreateParams(params)
1760
+ });
1761
+ class ZodBigInt extends ZodType {
1762
+ constructor(){
1763
+ super(...arguments);
1764
+ this.min = this.gte;
1765
+ this.max = this.lte;
1766
+ }
1767
+ _parse(input) {
1768
+ if (this._def.coerce) try {
1769
+ input.data = BigInt(input.data);
1770
+ } catch {
1771
+ return this._getInvalidInput(input);
1772
+ }
1773
+ const parsedType = this._getType(input);
1774
+ if (parsedType !== ZodParsedType.bigint) return this._getInvalidInput(input);
1775
+ let ctx;
1776
+ const status = new ParseStatus();
1777
+ for (const check of this._def.checks)if ("min" === check.kind) {
1778
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1779
+ if (tooSmall) {
1780
+ ctx = this._getOrReturnCtx(input, ctx);
1781
+ addIssueToContext(ctx, {
1782
+ code: ZodIssueCode.too_small,
1783
+ type: "bigint",
1784
+ minimum: check.value,
1785
+ inclusive: check.inclusive,
1786
+ message: check.message
1787
+ });
1788
+ status.dirty();
1789
+ }
1790
+ } else if ("max" === check.kind) {
1791
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1792
+ if (tooBig) {
1793
+ ctx = this._getOrReturnCtx(input, ctx);
1794
+ addIssueToContext(ctx, {
1795
+ code: ZodIssueCode.too_big,
1796
+ type: "bigint",
1797
+ maximum: check.value,
1798
+ inclusive: check.inclusive,
1799
+ message: check.message
1800
+ });
1801
+ status.dirty();
1802
+ }
1803
+ } else if ("multipleOf" === check.kind) {
1804
+ if (input.data % check.value !== BigInt(0)) {
1805
+ ctx = this._getOrReturnCtx(input, ctx);
1806
+ addIssueToContext(ctx, {
1807
+ code: ZodIssueCode.not_multiple_of,
1808
+ multipleOf: check.value,
1809
+ message: check.message
1810
+ });
1811
+ status.dirty();
1812
+ }
1813
+ } else util_util.assertNever(check);
1814
+ return {
1815
+ status: status.value,
1816
+ value: input.data
1817
+ };
1818
+ }
1819
+ _getInvalidInput(input) {
1820
+ const ctx = this._getOrReturnCtx(input);
1821
+ addIssueToContext(ctx, {
1822
+ code: ZodIssueCode.invalid_type,
1823
+ expected: ZodParsedType.bigint,
1824
+ received: ctx.parsedType
1825
+ });
1826
+ return INVALID;
1827
+ }
1828
+ gte(value, message) {
1829
+ return this.setLimit("min", value, true, errorUtil_errorUtil.toString(message));
1830
+ }
1831
+ gt(value, message) {
1832
+ return this.setLimit("min", value, false, errorUtil_errorUtil.toString(message));
1833
+ }
1834
+ lte(value, message) {
1835
+ return this.setLimit("max", value, true, errorUtil_errorUtil.toString(message));
1836
+ }
1837
+ lt(value, message) {
1838
+ return this.setLimit("max", value, false, errorUtil_errorUtil.toString(message));
1839
+ }
1840
+ setLimit(kind, value, inclusive, message) {
1841
+ return new ZodBigInt({
1842
+ ...this._def,
1843
+ checks: [
1844
+ ...this._def.checks,
1845
+ {
1846
+ kind,
1847
+ value,
1848
+ inclusive,
1849
+ message: errorUtil_errorUtil.toString(message)
1850
+ }
1851
+ ]
1852
+ });
1853
+ }
1854
+ _addCheck(check) {
1855
+ return new ZodBigInt({
1856
+ ...this._def,
1857
+ checks: [
1858
+ ...this._def.checks,
1859
+ check
1860
+ ]
1861
+ });
1862
+ }
1863
+ positive(message) {
1864
+ return this._addCheck({
1865
+ kind: "min",
1866
+ value: BigInt(0),
1867
+ inclusive: false,
1868
+ message: errorUtil_errorUtil.toString(message)
1869
+ });
1870
+ }
1871
+ negative(message) {
1872
+ return this._addCheck({
1873
+ kind: "max",
1874
+ value: BigInt(0),
1875
+ inclusive: false,
1876
+ message: errorUtil_errorUtil.toString(message)
1877
+ });
1878
+ }
1879
+ nonpositive(message) {
1880
+ return this._addCheck({
1881
+ kind: "max",
1882
+ value: BigInt(0),
1883
+ inclusive: true,
1884
+ message: errorUtil_errorUtil.toString(message)
1885
+ });
1886
+ }
1887
+ nonnegative(message) {
1888
+ return this._addCheck({
1889
+ kind: "min",
1890
+ value: BigInt(0),
1891
+ inclusive: true,
1892
+ message: errorUtil_errorUtil.toString(message)
1893
+ });
1894
+ }
1895
+ multipleOf(value, message) {
1896
+ return this._addCheck({
1897
+ kind: "multipleOf",
1898
+ value,
1899
+ message: errorUtil_errorUtil.toString(message)
1900
+ });
1901
+ }
1902
+ get minValue() {
1903
+ let min = null;
1904
+ for (const ch of this._def.checks)if ("min" === ch.kind) {
1905
+ if (null === min || ch.value > min) min = ch.value;
1906
+ }
1907
+ return min;
1908
+ }
1909
+ get maxValue() {
1910
+ let max = null;
1911
+ for (const ch of this._def.checks)if ("max" === ch.kind) {
1912
+ if (null === max || ch.value < max) max = ch.value;
1913
+ }
1914
+ return max;
1915
+ }
1916
+ }
1917
+ ZodBigInt.create = (params)=>new ZodBigInt({
1918
+ checks: [],
1919
+ typeName: types_ZodFirstPartyTypeKind.ZodBigInt,
1920
+ coerce: params?.coerce ?? false,
1921
+ ...processCreateParams(params)
1922
+ });
1923
+ class ZodBoolean extends ZodType {
1924
+ _parse(input) {
1925
+ if (this._def.coerce) input.data = Boolean(input.data);
1926
+ const parsedType = this._getType(input);
1927
+ if (parsedType !== ZodParsedType.boolean) {
1928
+ const ctx = this._getOrReturnCtx(input);
1929
+ addIssueToContext(ctx, {
1930
+ code: ZodIssueCode.invalid_type,
1931
+ expected: ZodParsedType.boolean,
1932
+ received: ctx.parsedType
1933
+ });
1934
+ return INVALID;
1935
+ }
1936
+ return OK(input.data);
1937
+ }
1938
+ }
1939
+ ZodBoolean.create = (params)=>new ZodBoolean({
1940
+ typeName: types_ZodFirstPartyTypeKind.ZodBoolean,
1941
+ coerce: params?.coerce || false,
1942
+ ...processCreateParams(params)
1943
+ });
1944
+ class ZodDate extends ZodType {
1945
+ _parse(input) {
1946
+ if (this._def.coerce) input.data = new Date(input.data);
1947
+ const parsedType = this._getType(input);
1948
+ if (parsedType !== ZodParsedType.date) {
1949
+ const ctx = this._getOrReturnCtx(input);
1950
+ addIssueToContext(ctx, {
1951
+ code: ZodIssueCode.invalid_type,
1952
+ expected: ZodParsedType.date,
1953
+ received: ctx.parsedType
1954
+ });
1955
+ return INVALID;
1956
+ }
1957
+ if (Number.isNaN(input.data.getTime())) {
1958
+ const ctx = this._getOrReturnCtx(input);
1959
+ addIssueToContext(ctx, {
1960
+ code: ZodIssueCode.invalid_date
1961
+ });
1962
+ return INVALID;
1963
+ }
1964
+ const status = new ParseStatus();
1965
+ let ctx;
1966
+ for (const check of this._def.checks)if ("min" === check.kind) {
1967
+ if (input.data.getTime() < check.value) {
1968
+ ctx = this._getOrReturnCtx(input, ctx);
1969
+ addIssueToContext(ctx, {
1970
+ code: ZodIssueCode.too_small,
1971
+ message: check.message,
1972
+ inclusive: true,
1973
+ exact: false,
1974
+ minimum: check.value,
1975
+ type: "date"
1976
+ });
1977
+ status.dirty();
1978
+ }
1979
+ } else if ("max" === check.kind) {
1980
+ if (input.data.getTime() > check.value) {
1981
+ ctx = this._getOrReturnCtx(input, ctx);
1982
+ addIssueToContext(ctx, {
1983
+ code: ZodIssueCode.too_big,
1984
+ message: check.message,
1985
+ inclusive: true,
1986
+ exact: false,
1987
+ maximum: check.value,
1988
+ type: "date"
1989
+ });
1990
+ status.dirty();
1991
+ }
1992
+ } else util_util.assertNever(check);
1993
+ return {
1994
+ status: status.value,
1995
+ value: new Date(input.data.getTime())
1996
+ };
1997
+ }
1998
+ _addCheck(check) {
1999
+ return new ZodDate({
2000
+ ...this._def,
2001
+ checks: [
2002
+ ...this._def.checks,
2003
+ check
2004
+ ]
2005
+ });
2006
+ }
2007
+ min(minDate, message) {
2008
+ return this._addCheck({
2009
+ kind: "min",
2010
+ value: minDate.getTime(),
2011
+ message: errorUtil_errorUtil.toString(message)
2012
+ });
2013
+ }
2014
+ max(maxDate, message) {
2015
+ return this._addCheck({
2016
+ kind: "max",
2017
+ value: maxDate.getTime(),
2018
+ message: errorUtil_errorUtil.toString(message)
2019
+ });
2020
+ }
2021
+ get minDate() {
2022
+ let min = null;
2023
+ for (const ch of this._def.checks)if ("min" === ch.kind) {
2024
+ if (null === min || ch.value > min) min = ch.value;
2025
+ }
2026
+ return null != min ? new Date(min) : null;
2027
+ }
2028
+ get maxDate() {
2029
+ let max = null;
2030
+ for (const ch of this._def.checks)if ("max" === ch.kind) {
2031
+ if (null === max || ch.value < max) max = ch.value;
2032
+ }
2033
+ return null != max ? new Date(max) : null;
2034
+ }
2035
+ }
2036
+ ZodDate.create = (params)=>new ZodDate({
2037
+ checks: [],
2038
+ coerce: params?.coerce || false,
2039
+ typeName: types_ZodFirstPartyTypeKind.ZodDate,
2040
+ ...processCreateParams(params)
2041
+ });
2042
+ class ZodSymbol extends ZodType {
2043
+ _parse(input) {
2044
+ const parsedType = this._getType(input);
2045
+ if (parsedType !== ZodParsedType.symbol) {
2046
+ const ctx = this._getOrReturnCtx(input);
2047
+ addIssueToContext(ctx, {
2048
+ code: ZodIssueCode.invalid_type,
2049
+ expected: ZodParsedType.symbol,
2050
+ received: ctx.parsedType
2051
+ });
2052
+ return INVALID;
2053
+ }
2054
+ return OK(input.data);
2055
+ }
2056
+ }
2057
+ ZodSymbol.create = (params)=>new ZodSymbol({
2058
+ typeName: types_ZodFirstPartyTypeKind.ZodSymbol,
2059
+ ...processCreateParams(params)
2060
+ });
2061
+ class ZodUndefined extends ZodType {
2062
+ _parse(input) {
2063
+ const parsedType = this._getType(input);
2064
+ if (parsedType !== ZodParsedType.undefined) {
2065
+ const ctx = this._getOrReturnCtx(input);
2066
+ addIssueToContext(ctx, {
2067
+ code: ZodIssueCode.invalid_type,
2068
+ expected: ZodParsedType.undefined,
2069
+ received: ctx.parsedType
2070
+ });
2071
+ return INVALID;
2072
+ }
2073
+ return OK(input.data);
2074
+ }
2075
+ }
2076
+ ZodUndefined.create = (params)=>new ZodUndefined({
2077
+ typeName: types_ZodFirstPartyTypeKind.ZodUndefined,
2078
+ ...processCreateParams(params)
2079
+ });
2080
+ class ZodNull extends ZodType {
2081
+ _parse(input) {
2082
+ const parsedType = this._getType(input);
2083
+ if (parsedType !== ZodParsedType["null"]) {
2084
+ const ctx = this._getOrReturnCtx(input);
2085
+ addIssueToContext(ctx, {
2086
+ code: ZodIssueCode.invalid_type,
2087
+ expected: ZodParsedType["null"],
2088
+ received: ctx.parsedType
2089
+ });
2090
+ return INVALID;
2091
+ }
2092
+ return OK(input.data);
2093
+ }
2094
+ }
2095
+ ZodNull.create = (params)=>new ZodNull({
2096
+ typeName: types_ZodFirstPartyTypeKind.ZodNull,
2097
+ ...processCreateParams(params)
2098
+ });
2099
+ class ZodAny extends ZodType {
2100
+ constructor(){
2101
+ super(...arguments);
2102
+ this._any = true;
2103
+ }
2104
+ _parse(input) {
2105
+ return OK(input.data);
2106
+ }
2107
+ }
2108
+ ZodAny.create = (params)=>new ZodAny({
2109
+ typeName: types_ZodFirstPartyTypeKind.ZodAny,
2110
+ ...processCreateParams(params)
2111
+ });
2112
+ class ZodUnknown extends ZodType {
2113
+ constructor(){
2114
+ super(...arguments);
2115
+ this._unknown = true;
2116
+ }
2117
+ _parse(input) {
2118
+ return OK(input.data);
2119
+ }
2120
+ }
2121
+ ZodUnknown.create = (params)=>new ZodUnknown({
2122
+ typeName: types_ZodFirstPartyTypeKind.ZodUnknown,
2123
+ ...processCreateParams(params)
2124
+ });
2125
+ class ZodNever extends ZodType {
2126
+ _parse(input) {
2127
+ const ctx = this._getOrReturnCtx(input);
2128
+ addIssueToContext(ctx, {
2129
+ code: ZodIssueCode.invalid_type,
2130
+ expected: ZodParsedType.never,
2131
+ received: ctx.parsedType
2132
+ });
2133
+ return INVALID;
2134
+ }
2135
+ }
2136
+ ZodNever.create = (params)=>new ZodNever({
2137
+ typeName: types_ZodFirstPartyTypeKind.ZodNever,
2138
+ ...processCreateParams(params)
2139
+ });
2140
+ class ZodVoid extends ZodType {
2141
+ _parse(input) {
2142
+ const parsedType = this._getType(input);
2143
+ if (parsedType !== ZodParsedType.undefined) {
2144
+ const ctx = this._getOrReturnCtx(input);
2145
+ addIssueToContext(ctx, {
2146
+ code: ZodIssueCode.invalid_type,
2147
+ expected: ZodParsedType["void"],
2148
+ received: ctx.parsedType
2149
+ });
2150
+ return INVALID;
2151
+ }
2152
+ return OK(input.data);
2153
+ }
2154
+ }
2155
+ ZodVoid.create = (params)=>new ZodVoid({
2156
+ typeName: types_ZodFirstPartyTypeKind.ZodVoid,
2157
+ ...processCreateParams(params)
2158
+ });
2159
+ class ZodArray extends ZodType {
2160
+ _parse(input) {
2161
+ const { ctx, status } = this._processInputParams(input);
2162
+ const def = this._def;
2163
+ if (ctx.parsedType !== ZodParsedType.array) {
2164
+ addIssueToContext(ctx, {
2165
+ code: ZodIssueCode.invalid_type,
2166
+ expected: ZodParsedType.array,
2167
+ received: ctx.parsedType
2168
+ });
2169
+ return INVALID;
2170
+ }
2171
+ if (null !== def.exactLength) {
2172
+ const tooBig = ctx.data.length > def.exactLength.value;
2173
+ const tooSmall = ctx.data.length < def.exactLength.value;
2174
+ if (tooBig || tooSmall) {
2175
+ addIssueToContext(ctx, {
2176
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2177
+ minimum: tooSmall ? def.exactLength.value : void 0,
2178
+ maximum: tooBig ? def.exactLength.value : void 0,
2179
+ type: "array",
2180
+ inclusive: true,
2181
+ exact: true,
2182
+ message: def.exactLength.message
2183
+ });
2184
+ status.dirty();
2185
+ }
2186
+ }
2187
+ if (null !== def.minLength) {
2188
+ if (ctx.data.length < def.minLength.value) {
2189
+ addIssueToContext(ctx, {
2190
+ code: ZodIssueCode.too_small,
2191
+ minimum: def.minLength.value,
2192
+ type: "array",
2193
+ inclusive: true,
2194
+ exact: false,
2195
+ message: def.minLength.message
2196
+ });
2197
+ status.dirty();
2198
+ }
2199
+ }
2200
+ if (null !== def.maxLength) {
2201
+ if (ctx.data.length > def.maxLength.value) {
2202
+ addIssueToContext(ctx, {
2203
+ code: ZodIssueCode.too_big,
2204
+ maximum: def.maxLength.value,
2205
+ type: "array",
2206
+ inclusive: true,
2207
+ exact: false,
2208
+ message: def.maxLength.message
2209
+ });
2210
+ status.dirty();
2211
+ }
2212
+ }
2213
+ if (ctx.common.async) return Promise.all([
2214
+ ...ctx.data
2215
+ ].map((item, i)=>def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i)))).then((result)=>ParseStatus.mergeArray(status, result));
2216
+ const result = [
2217
+ ...ctx.data
2218
+ ].map((item, i)=>def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2219
+ return ParseStatus.mergeArray(status, result);
2220
+ }
2221
+ get element() {
2222
+ return this._def.type;
2223
+ }
2224
+ min(minLength, message) {
2225
+ return new ZodArray({
2226
+ ...this._def,
2227
+ minLength: {
2228
+ value: minLength,
2229
+ message: errorUtil_errorUtil.toString(message)
2230
+ }
2231
+ });
2232
+ }
2233
+ max(maxLength, message) {
2234
+ return new ZodArray({
2235
+ ...this._def,
2236
+ maxLength: {
2237
+ value: maxLength,
2238
+ message: errorUtil_errorUtil.toString(message)
2239
+ }
2240
+ });
2241
+ }
2242
+ length(len, message) {
2243
+ return new ZodArray({
2244
+ ...this._def,
2245
+ exactLength: {
2246
+ value: len,
2247
+ message: errorUtil_errorUtil.toString(message)
2248
+ }
2249
+ });
2250
+ }
2251
+ nonempty(message) {
2252
+ return this.min(1, message);
2253
+ }
2254
+ }
2255
+ ZodArray.create = (schema, params)=>new ZodArray({
2256
+ type: schema,
2257
+ minLength: null,
2258
+ maxLength: null,
2259
+ exactLength: null,
2260
+ typeName: types_ZodFirstPartyTypeKind.ZodArray,
2261
+ ...processCreateParams(params)
2262
+ });
2263
+ function deepPartialify(schema) {
2264
+ if (schema instanceof ZodObject) {
2265
+ const newShape = {};
2266
+ for(const key in schema.shape){
2267
+ const fieldSchema = schema.shape[key];
2268
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2269
+ }
2270
+ return new ZodObject({
2271
+ ...schema._def,
2272
+ shape: ()=>newShape
2273
+ });
2274
+ }
2275
+ if (schema instanceof ZodArray) return new ZodArray({
2276
+ ...schema._def,
2277
+ type: deepPartialify(schema.element)
2278
+ });
2279
+ if (schema instanceof ZodOptional) return ZodOptional.create(deepPartialify(schema.unwrap()));
2280
+ if (schema instanceof ZodNullable) return ZodNullable.create(deepPartialify(schema.unwrap()));
2281
+ if (schema instanceof ZodTuple) return ZodTuple.create(schema.items.map((item)=>deepPartialify(item)));
2282
+ else return schema;
2283
+ }
2284
+ class ZodObject extends ZodType {
2285
+ constructor(){
2286
+ super(...arguments);
2287
+ this._cached = null;
2288
+ this.nonstrict = this.passthrough;
2289
+ this.augment = this.extend;
2290
+ }
2291
+ _getCached() {
2292
+ if (null !== this._cached) return this._cached;
2293
+ const shape = this._def.shape();
2294
+ const keys = util_util.objectKeys(shape);
2295
+ this._cached = {
2296
+ shape,
2297
+ keys
2298
+ };
2299
+ return this._cached;
2300
+ }
2301
+ _parse(input) {
2302
+ const parsedType = this._getType(input);
2303
+ if (parsedType !== ZodParsedType.object) {
2304
+ const ctx = this._getOrReturnCtx(input);
2305
+ addIssueToContext(ctx, {
2306
+ code: ZodIssueCode.invalid_type,
2307
+ expected: ZodParsedType.object,
2308
+ received: ctx.parsedType
2309
+ });
2310
+ return INVALID;
2311
+ }
2312
+ const { status, ctx } = this._processInputParams(input);
2313
+ const { shape, keys: shapeKeys } = this._getCached();
2314
+ const extraKeys = [];
2315
+ if (!(this._def.catchall instanceof ZodNever && "strip" === this._def.unknownKeys)) {
2316
+ for(const key in ctx.data)if (!shapeKeys.includes(key)) extraKeys.push(key);
2317
+ }
2318
+ const pairs = [];
2319
+ for (const key of shapeKeys){
2320
+ const keyValidator = shape[key];
2321
+ const value = ctx.data[key];
2322
+ pairs.push({
2323
+ key: {
2324
+ status: "valid",
2325
+ value: key
2326
+ },
2327
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2328
+ alwaysSet: key in ctx.data
2329
+ });
2330
+ }
2331
+ if (this._def.catchall instanceof ZodNever) {
2332
+ const unknownKeys = this._def.unknownKeys;
2333
+ if ("passthrough" === unknownKeys) for (const key of extraKeys)pairs.push({
2334
+ key: {
2335
+ status: "valid",
2336
+ value: key
2337
+ },
2338
+ value: {
2339
+ status: "valid",
2340
+ value: ctx.data[key]
2341
+ }
2342
+ });
2343
+ else if ("strict" === unknownKeys) {
2344
+ if (extraKeys.length > 0) {
2345
+ addIssueToContext(ctx, {
2346
+ code: ZodIssueCode.unrecognized_keys,
2347
+ keys: extraKeys
2348
+ });
2349
+ status.dirty();
2350
+ }
2351
+ } else if ("strip" === unknownKeys) ;
2352
+ else throw new Error("Internal ZodObject error: invalid unknownKeys value.");
2353
+ } else {
2354
+ const catchall = this._def.catchall;
2355
+ for (const key of extraKeys){
2356
+ const value = ctx.data[key];
2357
+ pairs.push({
2358
+ key: {
2359
+ status: "valid",
2360
+ value: key
2361
+ },
2362
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2363
+ alwaysSet: key in ctx.data
2364
+ });
2365
+ }
2366
+ }
2367
+ if (ctx.common.async) return Promise.resolve().then(async ()=>{
2368
+ const syncPairs = [];
2369
+ for (const pair of pairs){
2370
+ const key = await pair.key;
2371
+ const value = await pair.value;
2372
+ syncPairs.push({
2373
+ key,
2374
+ value,
2375
+ alwaysSet: pair.alwaysSet
2376
+ });
2377
+ }
2378
+ return syncPairs;
2379
+ }).then((syncPairs)=>ParseStatus.mergeObjectSync(status, syncPairs));
2380
+ return ParseStatus.mergeObjectSync(status, pairs);
2381
+ }
2382
+ get shape() {
2383
+ return this._def.shape();
2384
+ }
2385
+ strict(message) {
2386
+ errorUtil_errorUtil.errToObj;
2387
+ return new ZodObject({
2388
+ ...this._def,
2389
+ unknownKeys: "strict",
2390
+ ...void 0 !== message ? {
2391
+ errorMap: (issue, ctx)=>{
2392
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2393
+ if ("unrecognized_keys" === issue.code) return {
2394
+ message: errorUtil_errorUtil.errToObj(message).message ?? defaultError
2395
+ };
2396
+ return {
2397
+ message: defaultError
2398
+ };
2399
+ }
2400
+ } : {}
2401
+ });
2402
+ }
2403
+ strip() {
2404
+ return new ZodObject({
2405
+ ...this._def,
2406
+ unknownKeys: "strip"
2407
+ });
2408
+ }
2409
+ passthrough() {
2410
+ return new ZodObject({
2411
+ ...this._def,
2412
+ unknownKeys: "passthrough"
2413
+ });
2414
+ }
2415
+ extend(augmentation) {
2416
+ return new ZodObject({
2417
+ ...this._def,
2418
+ shape: ()=>({
2419
+ ...this._def.shape(),
2420
+ ...augmentation
2421
+ })
2422
+ });
2423
+ }
2424
+ merge(merging) {
2425
+ const merged = new ZodObject({
2426
+ unknownKeys: merging._def.unknownKeys,
2427
+ catchall: merging._def.catchall,
2428
+ shape: ()=>({
2429
+ ...this._def.shape(),
2430
+ ...merging._def.shape()
2431
+ }),
2432
+ typeName: types_ZodFirstPartyTypeKind.ZodObject
2433
+ });
2434
+ return merged;
2435
+ }
2436
+ setKey(key, schema) {
2437
+ return this.augment({
2438
+ [key]: schema
2439
+ });
2440
+ }
2441
+ catchall(index) {
2442
+ return new ZodObject({
2443
+ ...this._def,
2444
+ catchall: index
2445
+ });
2446
+ }
2447
+ pick(mask) {
2448
+ const shape = {};
2449
+ for (const key of util_util.objectKeys(mask))if (mask[key] && this.shape[key]) shape[key] = this.shape[key];
2450
+ return new ZodObject({
2451
+ ...this._def,
2452
+ shape: ()=>shape
2453
+ });
2454
+ }
2455
+ omit(mask) {
2456
+ const shape = {};
2457
+ for (const key of util_util.objectKeys(this.shape))if (!mask[key]) shape[key] = this.shape[key];
2458
+ return new ZodObject({
2459
+ ...this._def,
2460
+ shape: ()=>shape
2461
+ });
2462
+ }
2463
+ deepPartial() {
2464
+ return deepPartialify(this);
2465
+ }
2466
+ partial(mask) {
2467
+ const newShape = {};
2468
+ for (const key of util_util.objectKeys(this.shape)){
2469
+ const fieldSchema = this.shape[key];
2470
+ if (mask && !mask[key]) newShape[key] = fieldSchema;
2471
+ else newShape[key] = fieldSchema.optional();
2472
+ }
2473
+ return new ZodObject({
2474
+ ...this._def,
2475
+ shape: ()=>newShape
2476
+ });
2477
+ }
2478
+ required(mask) {
2479
+ const newShape = {};
2480
+ for (const key of util_util.objectKeys(this.shape))if (mask && !mask[key]) newShape[key] = this.shape[key];
2481
+ else {
2482
+ const fieldSchema = this.shape[key];
2483
+ let newField = fieldSchema;
2484
+ while(newField instanceof ZodOptional)newField = newField._def.innerType;
2485
+ newShape[key] = newField;
2486
+ }
2487
+ return new ZodObject({
2488
+ ...this._def,
2489
+ shape: ()=>newShape
2490
+ });
2491
+ }
2492
+ keyof() {
2493
+ return createZodEnum(util_util.objectKeys(this.shape));
2494
+ }
2495
+ }
2496
+ ZodObject.create = (shape, params)=>new ZodObject({
2497
+ shape: ()=>shape,
2498
+ unknownKeys: "strip",
2499
+ catchall: ZodNever.create(),
2500
+ typeName: types_ZodFirstPartyTypeKind.ZodObject,
2501
+ ...processCreateParams(params)
2502
+ });
2503
+ ZodObject.strictCreate = (shape, params)=>new ZodObject({
2504
+ shape: ()=>shape,
2505
+ unknownKeys: "strict",
2506
+ catchall: ZodNever.create(),
2507
+ typeName: types_ZodFirstPartyTypeKind.ZodObject,
2508
+ ...processCreateParams(params)
2509
+ });
2510
+ ZodObject.lazycreate = (shape, params)=>new ZodObject({
2511
+ shape,
2512
+ unknownKeys: "strip",
2513
+ catchall: ZodNever.create(),
2514
+ typeName: types_ZodFirstPartyTypeKind.ZodObject,
2515
+ ...processCreateParams(params)
2516
+ });
2517
+ class ZodUnion extends ZodType {
2518
+ _parse(input) {
2519
+ const { ctx } = this._processInputParams(input);
2520
+ const options = this._def.options;
2521
+ function handleResults(results) {
2522
+ for (const result of results)if ("valid" === result.result.status) return result.result;
2523
+ for (const result of results)if ("dirty" === result.result.status) {
2524
+ ctx.common.issues.push(...result.ctx.common.issues);
2525
+ return result.result;
2526
+ }
2527
+ const unionErrors = results.map((result)=>new ZodError(result.ctx.common.issues));
2528
+ addIssueToContext(ctx, {
2529
+ code: ZodIssueCode.invalid_union,
2530
+ unionErrors
2531
+ });
2532
+ return INVALID;
2533
+ }
2534
+ if (ctx.common.async) return Promise.all(options.map(async (option)=>{
2535
+ const childCtx = {
2536
+ ...ctx,
2537
+ common: {
2538
+ ...ctx.common,
2539
+ issues: []
2540
+ },
2541
+ parent: null
2542
+ };
2543
+ return {
2544
+ result: await option._parseAsync({
2545
+ data: ctx.data,
2546
+ path: ctx.path,
2547
+ parent: childCtx
2548
+ }),
2549
+ ctx: childCtx
2550
+ };
2551
+ })).then(handleResults);
2552
+ {
2553
+ let dirty;
2554
+ const issues = [];
2555
+ for (const option of options){
2556
+ const childCtx = {
2557
+ ...ctx,
2558
+ common: {
2559
+ ...ctx.common,
2560
+ issues: []
2561
+ },
2562
+ parent: null
2563
+ };
2564
+ const result = option._parseSync({
2565
+ data: ctx.data,
2566
+ path: ctx.path,
2567
+ parent: childCtx
2568
+ });
2569
+ if ("valid" === result.status) return result;
2570
+ if ("dirty" === result.status && !dirty) dirty = {
2571
+ result,
2572
+ ctx: childCtx
2573
+ };
2574
+ if (childCtx.common.issues.length) issues.push(childCtx.common.issues);
2575
+ }
2576
+ if (dirty) {
2577
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2578
+ return dirty.result;
2579
+ }
2580
+ const unionErrors = issues.map((issues)=>new ZodError(issues));
2581
+ addIssueToContext(ctx, {
2582
+ code: ZodIssueCode.invalid_union,
2583
+ unionErrors
2584
+ });
2585
+ return INVALID;
2586
+ }
2587
+ }
2588
+ get options() {
2589
+ return this._def.options;
2590
+ }
2591
+ }
2592
+ ZodUnion.create = (types, params)=>new ZodUnion({
2593
+ options: types,
2594
+ typeName: types_ZodFirstPartyTypeKind.ZodUnion,
2595
+ ...processCreateParams(params)
2596
+ });
2597
+ const getDiscriminator = (type)=>{
2598
+ if (type instanceof ZodLazy) return getDiscriminator(type.schema);
2599
+ if (type instanceof ZodEffects) return getDiscriminator(type.innerType());
2600
+ if (type instanceof ZodLiteral) return [
2601
+ type.value
2602
+ ];
2603
+ if (type instanceof ZodEnum) return type.options;
2604
+ if (type instanceof ZodNativeEnum) return util_util.objectValues(type.enum);
2605
+ else if (type instanceof ZodDefault) return getDiscriminator(type._def.innerType);
2606
+ else if (type instanceof ZodUndefined) return [
2607
+ void 0
2608
+ ];
2609
+ else if (type instanceof ZodNull) return [
2610
+ null
2611
+ ];
2612
+ else if (type instanceof ZodOptional) return [
2613
+ void 0,
2614
+ ...getDiscriminator(type.unwrap())
2615
+ ];
2616
+ else if (type instanceof ZodNullable) return [
2617
+ null,
2618
+ ...getDiscriminator(type.unwrap())
2619
+ ];
2620
+ else if (type instanceof ZodBranded) return getDiscriminator(type.unwrap());
2621
+ else if (type instanceof ZodReadonly) return getDiscriminator(type.unwrap());
2622
+ else if (type instanceof ZodCatch) return getDiscriminator(type._def.innerType);
2623
+ else return [];
2624
+ };
2625
+ class ZodDiscriminatedUnion extends ZodType {
2626
+ _parse(input) {
2627
+ const { ctx } = this._processInputParams(input);
2628
+ if (ctx.parsedType !== ZodParsedType.object) {
2629
+ addIssueToContext(ctx, {
2630
+ code: ZodIssueCode.invalid_type,
2631
+ expected: ZodParsedType.object,
2632
+ received: ctx.parsedType
2633
+ });
2634
+ return INVALID;
2635
+ }
2636
+ const discriminator = this.discriminator;
2637
+ const discriminatorValue = ctx.data[discriminator];
2638
+ const option = this.optionsMap.get(discriminatorValue);
2639
+ if (!option) {
2640
+ addIssueToContext(ctx, {
2641
+ code: ZodIssueCode.invalid_union_discriminator,
2642
+ options: Array.from(this.optionsMap.keys()),
2643
+ path: [
2644
+ discriminator
2645
+ ]
2646
+ });
2647
+ return INVALID;
2648
+ }
2649
+ if (ctx.common.async) return option._parseAsync({
2650
+ data: ctx.data,
2651
+ path: ctx.path,
2652
+ parent: ctx
2653
+ });
2654
+ return option._parseSync({
2655
+ data: ctx.data,
2656
+ path: ctx.path,
2657
+ parent: ctx
2658
+ });
2659
+ }
2660
+ get discriminator() {
2661
+ return this._def.discriminator;
2662
+ }
2663
+ get options() {
2664
+ return this._def.options;
2665
+ }
2666
+ get optionsMap() {
2667
+ return this._def.optionsMap;
2668
+ }
2669
+ static create(discriminator, options, params) {
2670
+ const optionsMap = new Map();
2671
+ for (const type of options){
2672
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2673
+ if (!discriminatorValues.length) throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2674
+ for (const value of discriminatorValues){
2675
+ if (optionsMap.has(value)) throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2676
+ optionsMap.set(value, type);
2677
+ }
2678
+ }
2679
+ return new ZodDiscriminatedUnion({
2680
+ typeName: types_ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2681
+ discriminator,
2682
+ options,
2683
+ optionsMap,
2684
+ ...processCreateParams(params)
2685
+ });
2686
+ }
2687
+ }
2688
+ function mergeValues(a, b) {
2689
+ const aType = getParsedType(a);
2690
+ const bType = getParsedType(b);
2691
+ if (a === b) return {
2692
+ valid: true,
2693
+ data: a
2694
+ };
2695
+ if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2696
+ const bKeys = util_util.objectKeys(b);
2697
+ const sharedKeys = util_util.objectKeys(a).filter((key)=>-1 !== bKeys.indexOf(key));
2698
+ const newObj = {
2699
+ ...a,
2700
+ ...b
2701
+ };
2702
+ for (const key of sharedKeys){
2703
+ const sharedValue = mergeValues(a[key], b[key]);
2704
+ if (!sharedValue.valid) return {
2705
+ valid: false
2706
+ };
2707
+ newObj[key] = sharedValue.data;
2708
+ }
2709
+ return {
2710
+ valid: true,
2711
+ data: newObj
2712
+ };
2713
+ }
2714
+ if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2715
+ if (a.length !== b.length) return {
2716
+ valid: false
2717
+ };
2718
+ const newArray = [];
2719
+ for(let index = 0; index < a.length; index++){
2720
+ const itemA = a[index];
2721
+ const itemB = b[index];
2722
+ const sharedValue = mergeValues(itemA, itemB);
2723
+ if (!sharedValue.valid) return {
2724
+ valid: false
2725
+ };
2726
+ newArray.push(sharedValue.data);
2727
+ }
2728
+ return {
2729
+ valid: true,
2730
+ data: newArray
2731
+ };
2732
+ }
2733
+ if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) return {
2734
+ valid: true,
2735
+ data: a
2736
+ };
2737
+ return {
2738
+ valid: false
2739
+ };
2740
+ }
2741
+ class ZodIntersection extends ZodType {
2742
+ _parse(input) {
2743
+ const { status, ctx } = this._processInputParams(input);
2744
+ const handleParsed = (parsedLeft, parsedRight)=>{
2745
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) return INVALID;
2746
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2747
+ if (!merged.valid) {
2748
+ addIssueToContext(ctx, {
2749
+ code: ZodIssueCode.invalid_intersection_types
2750
+ });
2751
+ return INVALID;
2752
+ }
2753
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) status.dirty();
2754
+ return {
2755
+ status: status.value,
2756
+ value: merged.data
2757
+ };
2758
+ };
2759
+ if (ctx.common.async) return Promise.all([
2760
+ this._def.left._parseAsync({
2761
+ data: ctx.data,
2762
+ path: ctx.path,
2763
+ parent: ctx
2764
+ }),
2765
+ this._def.right._parseAsync({
2766
+ data: ctx.data,
2767
+ path: ctx.path,
2768
+ parent: ctx
2769
+ })
2770
+ ]).then(([left, right])=>handleParsed(left, right));
2771
+ return handleParsed(this._def.left._parseSync({
2772
+ data: ctx.data,
2773
+ path: ctx.path,
2774
+ parent: ctx
2775
+ }), this._def.right._parseSync({
2776
+ data: ctx.data,
2777
+ path: ctx.path,
2778
+ parent: ctx
2779
+ }));
2780
+ }
2781
+ }
2782
+ ZodIntersection.create = (left, right, params)=>new ZodIntersection({
2783
+ left: left,
2784
+ right: right,
2785
+ typeName: types_ZodFirstPartyTypeKind.ZodIntersection,
2786
+ ...processCreateParams(params)
2787
+ });
2788
+ class ZodTuple extends ZodType {
2789
+ _parse(input) {
2790
+ const { status, ctx } = this._processInputParams(input);
2791
+ if (ctx.parsedType !== ZodParsedType.array) {
2792
+ addIssueToContext(ctx, {
2793
+ code: ZodIssueCode.invalid_type,
2794
+ expected: ZodParsedType.array,
2795
+ received: ctx.parsedType
2796
+ });
2797
+ return INVALID;
2798
+ }
2799
+ if (ctx.data.length < this._def.items.length) {
2800
+ addIssueToContext(ctx, {
2801
+ code: ZodIssueCode.too_small,
2802
+ minimum: this._def.items.length,
2803
+ inclusive: true,
2804
+ exact: false,
2805
+ type: "array"
2806
+ });
2807
+ return INVALID;
2808
+ }
2809
+ const rest = this._def.rest;
2810
+ if (!rest && ctx.data.length > this._def.items.length) {
2811
+ addIssueToContext(ctx, {
2812
+ code: ZodIssueCode.too_big,
2813
+ maximum: this._def.items.length,
2814
+ inclusive: true,
2815
+ exact: false,
2816
+ type: "array"
2817
+ });
2818
+ status.dirty();
2819
+ }
2820
+ const items = [
2821
+ ...ctx.data
2822
+ ].map((item, itemIndex)=>{
2823
+ const schema = this._def.items[itemIndex] || this._def.rest;
2824
+ if (!schema) return null;
2825
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2826
+ }).filter((x)=>!!x);
2827
+ if (ctx.common.async) return Promise.all(items).then((results)=>ParseStatus.mergeArray(status, results));
2828
+ return ParseStatus.mergeArray(status, items);
2829
+ }
2830
+ get items() {
2831
+ return this._def.items;
2832
+ }
2833
+ rest(rest) {
2834
+ return new ZodTuple({
2835
+ ...this._def,
2836
+ rest
2837
+ });
2838
+ }
2839
+ }
2840
+ ZodTuple.create = (schemas, params)=>{
2841
+ if (!Array.isArray(schemas)) throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2842
+ return new ZodTuple({
2843
+ items: schemas,
2844
+ typeName: types_ZodFirstPartyTypeKind.ZodTuple,
2845
+ rest: null,
2846
+ ...processCreateParams(params)
2847
+ });
2848
+ };
2849
+ class ZodRecord extends ZodType {
2850
+ get keySchema() {
2851
+ return this._def.keyType;
2852
+ }
2853
+ get valueSchema() {
2854
+ return this._def.valueType;
2855
+ }
2856
+ _parse(input) {
2857
+ const { status, ctx } = this._processInputParams(input);
2858
+ if (ctx.parsedType !== ZodParsedType.object) {
2859
+ addIssueToContext(ctx, {
2860
+ code: ZodIssueCode.invalid_type,
2861
+ expected: ZodParsedType.object,
2862
+ received: ctx.parsedType
2863
+ });
2864
+ return INVALID;
2865
+ }
2866
+ const pairs = [];
2867
+ const keyType = this._def.keyType;
2868
+ const valueType = this._def.valueType;
2869
+ for(const key in ctx.data)pairs.push({
2870
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2871
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2872
+ alwaysSet: key in ctx.data
2873
+ });
2874
+ if (ctx.common.async) return ParseStatus.mergeObjectAsync(status, pairs);
2875
+ return ParseStatus.mergeObjectSync(status, pairs);
2876
+ }
2877
+ get element() {
2878
+ return this._def.valueType;
2879
+ }
2880
+ static create(first, second, third) {
2881
+ if (second instanceof ZodType) return new ZodRecord({
2882
+ keyType: first,
2883
+ valueType: second,
2884
+ typeName: types_ZodFirstPartyTypeKind.ZodRecord,
2885
+ ...processCreateParams(third)
2886
+ });
2887
+ return new ZodRecord({
2888
+ keyType: ZodString.create(),
2889
+ valueType: first,
2890
+ typeName: types_ZodFirstPartyTypeKind.ZodRecord,
2891
+ ...processCreateParams(second)
2892
+ });
2893
+ }
2894
+ }
2895
+ class ZodMap extends ZodType {
2896
+ get keySchema() {
2897
+ return this._def.keyType;
2898
+ }
2899
+ get valueSchema() {
2900
+ return this._def.valueType;
2901
+ }
2902
+ _parse(input) {
2903
+ const { status, ctx } = this._processInputParams(input);
2904
+ if (ctx.parsedType !== ZodParsedType.map) {
2905
+ addIssueToContext(ctx, {
2906
+ code: ZodIssueCode.invalid_type,
2907
+ expected: ZodParsedType.map,
2908
+ received: ctx.parsedType
2909
+ });
2910
+ return INVALID;
2911
+ }
2912
+ const keyType = this._def.keyType;
2913
+ const valueType = this._def.valueType;
2914
+ const pairs = [
2915
+ ...ctx.data.entries()
2916
+ ].map(([key, value], index)=>({
2917
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [
2918
+ index,
2919
+ "key"
2920
+ ])),
2921
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [
2922
+ index,
2923
+ "value"
2924
+ ]))
2925
+ }));
2926
+ if (ctx.common.async) {
2927
+ const finalMap = new Map();
2928
+ return Promise.resolve().then(async ()=>{
2929
+ for (const pair of pairs){
2930
+ const key = await pair.key;
2931
+ const value = await pair.value;
2932
+ if ("aborted" === key.status || "aborted" === value.status) return INVALID;
2933
+ if ("dirty" === key.status || "dirty" === value.status) status.dirty();
2934
+ finalMap.set(key.value, value.value);
2935
+ }
2936
+ return {
2937
+ status: status.value,
2938
+ value: finalMap
2939
+ };
2940
+ });
2941
+ }
2942
+ {
2943
+ const finalMap = new Map();
2944
+ for (const pair of pairs){
2945
+ const key = pair.key;
2946
+ const value = pair.value;
2947
+ if ("aborted" === key.status || "aborted" === value.status) return INVALID;
2948
+ if ("dirty" === key.status || "dirty" === value.status) status.dirty();
2949
+ finalMap.set(key.value, value.value);
2950
+ }
2951
+ return {
2952
+ status: status.value,
2953
+ value: finalMap
2954
+ };
2955
+ }
2956
+ }
2957
+ }
2958
+ ZodMap.create = (keyType, valueType, params)=>new ZodMap({
2959
+ valueType,
2960
+ keyType,
2961
+ typeName: types_ZodFirstPartyTypeKind.ZodMap,
2962
+ ...processCreateParams(params)
2963
+ });
2964
+ class ZodSet extends ZodType {
2965
+ _parse(input) {
2966
+ const { status, ctx } = this._processInputParams(input);
2967
+ if (ctx.parsedType !== ZodParsedType.set) {
2968
+ addIssueToContext(ctx, {
2969
+ code: ZodIssueCode.invalid_type,
2970
+ expected: ZodParsedType.set,
2971
+ received: ctx.parsedType
2972
+ });
2973
+ return INVALID;
2974
+ }
2975
+ const def = this._def;
2976
+ if (null !== def.minSize) {
2977
+ if (ctx.data.size < def.minSize.value) {
2978
+ addIssueToContext(ctx, {
2979
+ code: ZodIssueCode.too_small,
2980
+ minimum: def.minSize.value,
2981
+ type: "set",
2982
+ inclusive: true,
2983
+ exact: false,
2984
+ message: def.minSize.message
2985
+ });
2986
+ status.dirty();
2987
+ }
2988
+ }
2989
+ if (null !== def.maxSize) {
2990
+ if (ctx.data.size > def.maxSize.value) {
2991
+ addIssueToContext(ctx, {
2992
+ code: ZodIssueCode.too_big,
2993
+ maximum: def.maxSize.value,
2994
+ type: "set",
2995
+ inclusive: true,
2996
+ exact: false,
2997
+ message: def.maxSize.message
2998
+ });
2999
+ status.dirty();
3000
+ }
3001
+ }
3002
+ const valueType = this._def.valueType;
3003
+ function finalizeSet(elements) {
3004
+ const parsedSet = new Set();
3005
+ for (const element of elements){
3006
+ if ("aborted" === element.status) return INVALID;
3007
+ if ("dirty" === element.status) status.dirty();
3008
+ parsedSet.add(element.value);
3009
+ }
3010
+ return {
3011
+ status: status.value,
3012
+ value: parsedSet
3013
+ };
3014
+ }
3015
+ const elements = [
3016
+ ...ctx.data.values()
3017
+ ].map((item, i)=>valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3018
+ if (ctx.common.async) return Promise.all(elements).then((elements)=>finalizeSet(elements));
3019
+ return finalizeSet(elements);
3020
+ }
3021
+ min(minSize, message) {
3022
+ return new ZodSet({
3023
+ ...this._def,
3024
+ minSize: {
3025
+ value: minSize,
3026
+ message: errorUtil_errorUtil.toString(message)
3027
+ }
3028
+ });
3029
+ }
3030
+ max(maxSize, message) {
3031
+ return new ZodSet({
3032
+ ...this._def,
3033
+ maxSize: {
3034
+ value: maxSize,
3035
+ message: errorUtil_errorUtil.toString(message)
3036
+ }
3037
+ });
3038
+ }
3039
+ size(size, message) {
3040
+ return this.min(size, message).max(size, message);
3041
+ }
3042
+ nonempty(message) {
3043
+ return this.min(1, message);
3044
+ }
3045
+ }
3046
+ ZodSet.create = (valueType, params)=>new ZodSet({
3047
+ valueType,
3048
+ minSize: null,
3049
+ maxSize: null,
3050
+ typeName: types_ZodFirstPartyTypeKind.ZodSet,
3051
+ ...processCreateParams(params)
3052
+ });
3053
+ class ZodFunction extends ZodType {
3054
+ constructor(){
3055
+ super(...arguments);
3056
+ this.validate = this.implement;
3057
+ }
3058
+ _parse(input) {
3059
+ const { ctx } = this._processInputParams(input);
3060
+ if (ctx.parsedType !== ZodParsedType["function"]) {
3061
+ addIssueToContext(ctx, {
3062
+ code: ZodIssueCode.invalid_type,
3063
+ expected: ZodParsedType["function"],
3064
+ received: ctx.parsedType
3065
+ });
3066
+ return INVALID;
3067
+ }
3068
+ function makeArgsIssue(args, error) {
3069
+ return makeIssue({
3070
+ data: args,
3071
+ path: ctx.path,
3072
+ errorMaps: [
3073
+ ctx.common.contextualErrorMap,
3074
+ ctx.schemaErrorMap,
3075
+ getErrorMap(),
3076
+ en
3077
+ ].filter((x)=>!!x),
3078
+ issueData: {
3079
+ code: ZodIssueCode.invalid_arguments,
3080
+ argumentsError: error
3081
+ }
3082
+ });
3083
+ }
3084
+ function makeReturnsIssue(returns, error) {
3085
+ return makeIssue({
3086
+ data: returns,
3087
+ path: ctx.path,
3088
+ errorMaps: [
3089
+ ctx.common.contextualErrorMap,
3090
+ ctx.schemaErrorMap,
3091
+ getErrorMap(),
3092
+ en
3093
+ ].filter((x)=>!!x),
3094
+ issueData: {
3095
+ code: ZodIssueCode.invalid_return_type,
3096
+ returnTypeError: error
3097
+ }
3098
+ });
3099
+ }
3100
+ const params = {
3101
+ errorMap: ctx.common.contextualErrorMap
3102
+ };
3103
+ const fn = ctx.data;
3104
+ if (this._def.returns instanceof ZodPromise) {
3105
+ const me = this;
3106
+ return OK(async function(...args) {
3107
+ const error = new ZodError([]);
3108
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e)=>{
3109
+ error.addIssue(makeArgsIssue(args, e));
3110
+ throw error;
3111
+ });
3112
+ const result = await Reflect.apply(fn, this, parsedArgs);
3113
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e)=>{
3114
+ error.addIssue(makeReturnsIssue(result, e));
3115
+ throw error;
3116
+ });
3117
+ return parsedReturns;
3118
+ });
3119
+ }
3120
+ {
3121
+ const me = this;
3122
+ return OK(function(...args) {
3123
+ const parsedArgs = me._def.args.safeParse(args, params);
3124
+ if (!parsedArgs.success) throw new ZodError([
3125
+ makeArgsIssue(args, parsedArgs.error)
3126
+ ]);
3127
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3128
+ const parsedReturns = me._def.returns.safeParse(result, params);
3129
+ if (!parsedReturns.success) throw new ZodError([
3130
+ makeReturnsIssue(result, parsedReturns.error)
3131
+ ]);
3132
+ return parsedReturns.data;
3133
+ });
3134
+ }
3135
+ }
3136
+ parameters() {
3137
+ return this._def.args;
3138
+ }
3139
+ returnType() {
3140
+ return this._def.returns;
3141
+ }
3142
+ args(...items) {
3143
+ return new ZodFunction({
3144
+ ...this._def,
3145
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3146
+ });
3147
+ }
3148
+ returns(returnType) {
3149
+ return new ZodFunction({
3150
+ ...this._def,
3151
+ returns: returnType
3152
+ });
3153
+ }
3154
+ implement(func) {
3155
+ const validatedFunc = this.parse(func);
3156
+ return validatedFunc;
3157
+ }
3158
+ strictImplement(func) {
3159
+ const validatedFunc = this.parse(func);
3160
+ return validatedFunc;
3161
+ }
3162
+ static create(args, returns, params) {
3163
+ return new ZodFunction({
3164
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3165
+ returns: returns || ZodUnknown.create(),
3166
+ typeName: types_ZodFirstPartyTypeKind.ZodFunction,
3167
+ ...processCreateParams(params)
3168
+ });
3169
+ }
3170
+ }
3171
+ class ZodLazy extends ZodType {
3172
+ get schema() {
3173
+ return this._def.getter();
3174
+ }
3175
+ _parse(input) {
3176
+ const { ctx } = this._processInputParams(input);
3177
+ const lazySchema = this._def.getter();
3178
+ return lazySchema._parse({
3179
+ data: ctx.data,
3180
+ path: ctx.path,
3181
+ parent: ctx
3182
+ });
3183
+ }
3184
+ }
3185
+ ZodLazy.create = (getter, params)=>new ZodLazy({
3186
+ getter: getter,
3187
+ typeName: types_ZodFirstPartyTypeKind.ZodLazy,
3188
+ ...processCreateParams(params)
3189
+ });
3190
+ class ZodLiteral extends ZodType {
3191
+ _parse(input) {
3192
+ if (input.data !== this._def.value) {
3193
+ const ctx = this._getOrReturnCtx(input);
3194
+ addIssueToContext(ctx, {
3195
+ received: ctx.data,
3196
+ code: ZodIssueCode.invalid_literal,
3197
+ expected: this._def.value
3198
+ });
3199
+ return INVALID;
3200
+ }
3201
+ return {
3202
+ status: "valid",
3203
+ value: input.data
3204
+ };
3205
+ }
3206
+ get value() {
3207
+ return this._def.value;
3208
+ }
3209
+ }
3210
+ ZodLiteral.create = (value, params)=>new ZodLiteral({
3211
+ value: value,
3212
+ typeName: types_ZodFirstPartyTypeKind.ZodLiteral,
3213
+ ...processCreateParams(params)
3214
+ });
3215
+ function createZodEnum(values, params) {
3216
+ return new ZodEnum({
3217
+ values,
3218
+ typeName: types_ZodFirstPartyTypeKind.ZodEnum,
3219
+ ...processCreateParams(params)
3220
+ });
3221
+ }
3222
+ class ZodEnum extends ZodType {
3223
+ _parse(input) {
3224
+ if ("string" != typeof input.data) {
3225
+ const ctx = this._getOrReturnCtx(input);
3226
+ const expectedValues = this._def.values;
3227
+ addIssueToContext(ctx, {
3228
+ expected: util_util.joinValues(expectedValues),
3229
+ received: ctx.parsedType,
3230
+ code: ZodIssueCode.invalid_type
3231
+ });
3232
+ return INVALID;
3233
+ }
3234
+ if (!this._cache) this._cache = new Set(this._def.values);
3235
+ if (!this._cache.has(input.data)) {
3236
+ const ctx = this._getOrReturnCtx(input);
3237
+ const expectedValues = this._def.values;
3238
+ addIssueToContext(ctx, {
3239
+ received: ctx.data,
3240
+ code: ZodIssueCode.invalid_enum_value,
3241
+ options: expectedValues
3242
+ });
3243
+ return INVALID;
3244
+ }
3245
+ return OK(input.data);
3246
+ }
3247
+ get options() {
3248
+ return this._def.values;
3249
+ }
3250
+ get enum() {
3251
+ const enumValues = {};
3252
+ for (const val of this._def.values)enumValues[val] = val;
3253
+ return enumValues;
3254
+ }
3255
+ get Values() {
3256
+ const enumValues = {};
3257
+ for (const val of this._def.values)enumValues[val] = val;
3258
+ return enumValues;
3259
+ }
3260
+ get Enum() {
3261
+ const enumValues = {};
3262
+ for (const val of this._def.values)enumValues[val] = val;
3263
+ return enumValues;
3264
+ }
3265
+ extract(values, newDef = this._def) {
3266
+ return ZodEnum.create(values, {
3267
+ ...this._def,
3268
+ ...newDef
3269
+ });
3270
+ }
3271
+ exclude(values, newDef = this._def) {
3272
+ return ZodEnum.create(this.options.filter((opt)=>!values.includes(opt)), {
3273
+ ...this._def,
3274
+ ...newDef
3275
+ });
3276
+ }
3277
+ }
3278
+ ZodEnum.create = createZodEnum;
3279
+ class ZodNativeEnum extends ZodType {
3280
+ _parse(input) {
3281
+ const nativeEnumValues = util_util.getValidEnumValues(this._def.values);
3282
+ const ctx = this._getOrReturnCtx(input);
3283
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3284
+ const expectedValues = util_util.objectValues(nativeEnumValues);
3285
+ addIssueToContext(ctx, {
3286
+ expected: util_util.joinValues(expectedValues),
3287
+ received: ctx.parsedType,
3288
+ code: ZodIssueCode.invalid_type
3289
+ });
3290
+ return INVALID;
3291
+ }
3292
+ if (!this._cache) this._cache = new Set(util_util.getValidEnumValues(this._def.values));
3293
+ if (!this._cache.has(input.data)) {
3294
+ const expectedValues = util_util.objectValues(nativeEnumValues);
3295
+ addIssueToContext(ctx, {
3296
+ received: ctx.data,
3297
+ code: ZodIssueCode.invalid_enum_value,
3298
+ options: expectedValues
3299
+ });
3300
+ return INVALID;
3301
+ }
3302
+ return OK(input.data);
3303
+ }
3304
+ get enum() {
3305
+ return this._def.values;
3306
+ }
3307
+ }
3308
+ ZodNativeEnum.create = (values, params)=>new ZodNativeEnum({
3309
+ values: values,
3310
+ typeName: types_ZodFirstPartyTypeKind.ZodNativeEnum,
3311
+ ...processCreateParams(params)
3312
+ });
3313
+ class ZodPromise extends ZodType {
3314
+ unwrap() {
3315
+ return this._def.type;
3316
+ }
3317
+ _parse(input) {
3318
+ const { ctx } = this._processInputParams(input);
3319
+ if (ctx.parsedType !== ZodParsedType.promise && false === ctx.common.async) {
3320
+ addIssueToContext(ctx, {
3321
+ code: ZodIssueCode.invalid_type,
3322
+ expected: ZodParsedType.promise,
3323
+ received: ctx.parsedType
3324
+ });
3325
+ return INVALID;
3326
+ }
3327
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3328
+ return OK(promisified.then((data)=>this._def.type.parseAsync(data, {
3329
+ path: ctx.path,
3330
+ errorMap: ctx.common.contextualErrorMap
3331
+ })));
3332
+ }
3333
+ }
3334
+ ZodPromise.create = (schema, params)=>new ZodPromise({
3335
+ type: schema,
3336
+ typeName: types_ZodFirstPartyTypeKind.ZodPromise,
3337
+ ...processCreateParams(params)
3338
+ });
3339
+ class ZodEffects extends ZodType {
3340
+ innerType() {
3341
+ return this._def.schema;
3342
+ }
3343
+ sourceType() {
3344
+ return this._def.schema._def.typeName === types_ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3345
+ }
3346
+ _parse(input) {
3347
+ const { status, ctx } = this._processInputParams(input);
3348
+ const effect = this._def.effect || null;
3349
+ const checkCtx = {
3350
+ addIssue: (arg)=>{
3351
+ addIssueToContext(ctx, arg);
3352
+ if (arg.fatal) status.abort();
3353
+ else status.dirty();
3354
+ },
3355
+ get path () {
3356
+ return ctx.path;
3357
+ }
3358
+ };
3359
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3360
+ if ("preprocess" === effect.type) {
3361
+ const processed = effect.transform(ctx.data, checkCtx);
3362
+ if (ctx.common.async) return Promise.resolve(processed).then(async (processed)=>{
3363
+ if ("aborted" === status.value) return INVALID;
3364
+ const result = await this._def.schema._parseAsync({
3365
+ data: processed,
3366
+ path: ctx.path,
3367
+ parent: ctx
3368
+ });
3369
+ if ("aborted" === result.status) return INVALID;
3370
+ if ("dirty" === result.status) return DIRTY(result.value);
3371
+ if ("dirty" === status.value) return DIRTY(result.value);
3372
+ return result;
3373
+ });
3374
+ {
3375
+ if ("aborted" === status.value) return INVALID;
3376
+ const result = this._def.schema._parseSync({
3377
+ data: processed,
3378
+ path: ctx.path,
3379
+ parent: ctx
3380
+ });
3381
+ if ("aborted" === result.status) return INVALID;
3382
+ if ("dirty" === result.status) return DIRTY(result.value);
3383
+ if ("dirty" === status.value) return DIRTY(result.value);
3384
+ return result;
3385
+ }
3386
+ }
3387
+ if ("refinement" === effect.type) {
3388
+ const executeRefinement = (acc)=>{
3389
+ const result = effect.refinement(acc, checkCtx);
3390
+ if (ctx.common.async) return Promise.resolve(result);
3391
+ if (result instanceof Promise) throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3392
+ return acc;
3393
+ };
3394
+ if (false !== ctx.common.async) return this._def.schema._parseAsync({
3395
+ data: ctx.data,
3396
+ path: ctx.path,
3397
+ parent: ctx
3398
+ }).then((inner)=>{
3399
+ if ("aborted" === inner.status) return INVALID;
3400
+ if ("dirty" === inner.status) status.dirty();
3401
+ return executeRefinement(inner.value).then(()=>({
3402
+ status: status.value,
3403
+ value: inner.value
3404
+ }));
3405
+ });
3406
+ {
3407
+ const inner = this._def.schema._parseSync({
3408
+ data: ctx.data,
3409
+ path: ctx.path,
3410
+ parent: ctx
3411
+ });
3412
+ if ("aborted" === inner.status) return INVALID;
3413
+ if ("dirty" === inner.status) status.dirty();
3414
+ executeRefinement(inner.value);
3415
+ return {
3416
+ status: status.value,
3417
+ value: inner.value
3418
+ };
3419
+ }
3420
+ }
3421
+ if ("transform" === effect.type) if (false !== ctx.common.async) return this._def.schema._parseAsync({
3422
+ data: ctx.data,
3423
+ path: ctx.path,
3424
+ parent: ctx
3425
+ }).then((base)=>{
3426
+ if (!isValid(base)) return INVALID;
3427
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result)=>({
3428
+ status: status.value,
3429
+ value: result
3430
+ }));
3431
+ });
3432
+ else {
3433
+ const base = this._def.schema._parseSync({
3434
+ data: ctx.data,
3435
+ path: ctx.path,
3436
+ parent: ctx
3437
+ });
3438
+ if (!isValid(base)) return INVALID;
3439
+ const result = effect.transform(base.value, checkCtx);
3440
+ if (result instanceof Promise) throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
3441
+ return {
3442
+ status: status.value,
3443
+ value: result
3444
+ };
3445
+ }
3446
+ util_util.assertNever(effect);
3447
+ }
3448
+ }
3449
+ ZodEffects.create = (schema, effect, params)=>new ZodEffects({
3450
+ schema,
3451
+ typeName: types_ZodFirstPartyTypeKind.ZodEffects,
3452
+ effect,
3453
+ ...processCreateParams(params)
3454
+ });
3455
+ ZodEffects.createWithPreprocess = (preprocess, schema, params)=>new ZodEffects({
3456
+ schema,
3457
+ effect: {
3458
+ type: "preprocess",
3459
+ transform: preprocess
3460
+ },
3461
+ typeName: types_ZodFirstPartyTypeKind.ZodEffects,
3462
+ ...processCreateParams(params)
3463
+ });
3464
+ class ZodOptional extends ZodType {
3465
+ _parse(input) {
3466
+ const parsedType = this._getType(input);
3467
+ if (parsedType === ZodParsedType.undefined) return OK(void 0);
3468
+ return this._def.innerType._parse(input);
3469
+ }
3470
+ unwrap() {
3471
+ return this._def.innerType;
3472
+ }
3473
+ }
3474
+ ZodOptional.create = (type, params)=>new ZodOptional({
3475
+ innerType: type,
3476
+ typeName: types_ZodFirstPartyTypeKind.ZodOptional,
3477
+ ...processCreateParams(params)
3478
+ });
3479
+ class ZodNullable extends ZodType {
3480
+ _parse(input) {
3481
+ const parsedType = this._getType(input);
3482
+ if (parsedType === ZodParsedType["null"]) return OK(null);
3483
+ return this._def.innerType._parse(input);
3484
+ }
3485
+ unwrap() {
3486
+ return this._def.innerType;
3487
+ }
3488
+ }
3489
+ ZodNullable.create = (type, params)=>new ZodNullable({
3490
+ innerType: type,
3491
+ typeName: types_ZodFirstPartyTypeKind.ZodNullable,
3492
+ ...processCreateParams(params)
3493
+ });
3494
+ class ZodDefault extends ZodType {
3495
+ _parse(input) {
3496
+ const { ctx } = this._processInputParams(input);
3497
+ let data = ctx.data;
3498
+ if (ctx.parsedType === ZodParsedType.undefined) data = this._def.defaultValue();
3499
+ return this._def.innerType._parse({
3500
+ data,
3501
+ path: ctx.path,
3502
+ parent: ctx
3503
+ });
3504
+ }
3505
+ removeDefault() {
3506
+ return this._def.innerType;
3507
+ }
3508
+ }
3509
+ ZodDefault.create = (type, params)=>new ZodDefault({
3510
+ innerType: type,
3511
+ typeName: types_ZodFirstPartyTypeKind.ZodDefault,
3512
+ defaultValue: "function" == typeof params.default ? params.default : ()=>params.default,
3513
+ ...processCreateParams(params)
3514
+ });
3515
+ class ZodCatch extends ZodType {
3516
+ _parse(input) {
3517
+ const { ctx } = this._processInputParams(input);
3518
+ const newCtx = {
3519
+ ...ctx,
3520
+ common: {
3521
+ ...ctx.common,
3522
+ issues: []
3523
+ }
3524
+ };
3525
+ const result = this._def.innerType._parse({
3526
+ data: newCtx.data,
3527
+ path: newCtx.path,
3528
+ parent: {
3529
+ ...newCtx
3530
+ }
3531
+ });
3532
+ if (isAsync(result)) return result.then((result)=>({
3533
+ status: "valid",
3534
+ value: "valid" === result.status ? result.value : this._def.catchValue({
3535
+ get error () {
3536
+ return new ZodError(newCtx.common.issues);
3537
+ },
3538
+ input: newCtx.data
3539
+ })
3540
+ }));
3541
+ return {
3542
+ status: "valid",
3543
+ value: "valid" === result.status ? result.value : this._def.catchValue({
3544
+ get error () {
3545
+ return new ZodError(newCtx.common.issues);
3546
+ },
3547
+ input: newCtx.data
3548
+ })
3549
+ };
3550
+ }
3551
+ removeCatch() {
3552
+ return this._def.innerType;
3553
+ }
3554
+ }
3555
+ ZodCatch.create = (type, params)=>new ZodCatch({
3556
+ innerType: type,
3557
+ typeName: types_ZodFirstPartyTypeKind.ZodCatch,
3558
+ catchValue: "function" == typeof params.catch ? params.catch : ()=>params.catch,
3559
+ ...processCreateParams(params)
3560
+ });
3561
+ class ZodNaN extends ZodType {
3562
+ _parse(input) {
3563
+ const parsedType = this._getType(input);
3564
+ if (parsedType !== ZodParsedType.nan) {
3565
+ const ctx = this._getOrReturnCtx(input);
3566
+ addIssueToContext(ctx, {
3567
+ code: ZodIssueCode.invalid_type,
3568
+ expected: ZodParsedType.nan,
3569
+ received: ctx.parsedType
3570
+ });
3571
+ return INVALID;
3572
+ }
3573
+ return {
3574
+ status: "valid",
3575
+ value: input.data
3576
+ };
3577
+ }
3578
+ }
3579
+ ZodNaN.create = (params)=>new ZodNaN({
3580
+ typeName: types_ZodFirstPartyTypeKind.ZodNaN,
3581
+ ...processCreateParams(params)
3582
+ });
3583
+ const BRAND = Symbol("zod_brand");
3584
+ class ZodBranded extends ZodType {
3585
+ _parse(input) {
3586
+ const { ctx } = this._processInputParams(input);
3587
+ const data = ctx.data;
3588
+ return this._def.type._parse({
3589
+ data,
3590
+ path: ctx.path,
3591
+ parent: ctx
3592
+ });
3593
+ }
3594
+ unwrap() {
3595
+ return this._def.type;
3596
+ }
3597
+ }
3598
+ class ZodPipeline extends ZodType {
3599
+ _parse(input) {
3600
+ const { status, ctx } = this._processInputParams(input);
3601
+ if (ctx.common.async) {
3602
+ const handleAsync = async ()=>{
3603
+ const inResult = await this._def.in._parseAsync({
3604
+ data: ctx.data,
3605
+ path: ctx.path,
3606
+ parent: ctx
3607
+ });
3608
+ if ("aborted" === inResult.status) return INVALID;
3609
+ if ("dirty" !== inResult.status) return this._def.out._parseAsync({
3610
+ data: inResult.value,
3611
+ path: ctx.path,
3612
+ parent: ctx
3613
+ });
3614
+ status.dirty();
3615
+ return DIRTY(inResult.value);
3616
+ };
3617
+ return handleAsync();
3618
+ }
3619
+ {
3620
+ const inResult = this._def.in._parseSync({
3621
+ data: ctx.data,
3622
+ path: ctx.path,
3623
+ parent: ctx
3624
+ });
3625
+ if ("aborted" === inResult.status) return INVALID;
3626
+ if ("dirty" !== inResult.status) return this._def.out._parseSync({
3627
+ data: inResult.value,
3628
+ path: ctx.path,
3629
+ parent: ctx
3630
+ });
3631
+ status.dirty();
3632
+ return {
3633
+ status: "dirty",
3634
+ value: inResult.value
3635
+ };
3636
+ }
3637
+ }
3638
+ static create(a, b) {
3639
+ return new ZodPipeline({
3640
+ in: a,
3641
+ out: b,
3642
+ typeName: types_ZodFirstPartyTypeKind.ZodPipeline
3643
+ });
3644
+ }
3645
+ }
3646
+ class ZodReadonly extends ZodType {
3647
+ _parse(input) {
3648
+ const result = this._def.innerType._parse(input);
3649
+ const freeze = (data)=>{
3650
+ if (isValid(data)) data.value = Object.freeze(data.value);
3651
+ return data;
3652
+ };
3653
+ return isAsync(result) ? result.then((data)=>freeze(data)) : freeze(result);
3654
+ }
3655
+ unwrap() {
3656
+ return this._def.innerType;
3657
+ }
3658
+ }
3659
+ ZodReadonly.create = (type, params)=>new ZodReadonly({
3660
+ innerType: type,
3661
+ typeName: types_ZodFirstPartyTypeKind.ZodReadonly,
3662
+ ...processCreateParams(params)
3663
+ });
3664
+ function cleanParams(params, data) {
3665
+ const p = "function" == typeof params ? params(data) : "string" == typeof params ? {
3666
+ message: params
3667
+ } : params;
3668
+ const p2 = "string" == typeof p ? {
3669
+ message: p
3670
+ } : p;
3671
+ return p2;
3672
+ }
3673
+ function custom(check, _params = {}, fatal) {
3674
+ if (check) return ZodAny.create().superRefine((data, ctx)=>{
3675
+ const r = check(data);
3676
+ if (r instanceof Promise) return r.then((r)=>{
3677
+ if (!r) {
3678
+ const params = cleanParams(_params, data);
3679
+ const _fatal = params.fatal ?? fatal ?? true;
3680
+ ctx.addIssue({
3681
+ code: "custom",
3682
+ ...params,
3683
+ fatal: _fatal
3684
+ });
3685
+ }
3686
+ });
3687
+ if (!r) {
3688
+ const params = cleanParams(_params, data);
3689
+ const _fatal = params.fatal ?? fatal ?? true;
3690
+ ctx.addIssue({
3691
+ code: "custom",
3692
+ ...params,
3693
+ fatal: _fatal
3694
+ });
3695
+ }
3696
+ });
3697
+ return ZodAny.create();
3698
+ }
3699
+ const late = {
3700
+ object: ZodObject.lazycreate
3701
+ };
3702
+ var types_ZodFirstPartyTypeKind;
3703
+ (function(ZodFirstPartyTypeKind) {
3704
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
3705
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
3706
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
3707
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
3708
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
3709
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
3710
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
3711
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
3712
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
3713
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
3714
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
3715
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
3716
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
3717
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
3718
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
3719
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
3720
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3721
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
3722
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
3723
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
3724
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
3725
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
3726
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
3727
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
3728
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
3729
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
3730
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
3731
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
3732
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
3733
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
3734
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
3735
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
3736
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
3737
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
3738
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
3739
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
3740
+ })(types_ZodFirstPartyTypeKind || (types_ZodFirstPartyTypeKind = {}));
3741
+ const instanceOfType = (cls, params = {
3742
+ message: `Input not instance of ${cls.name}`
3743
+ })=>custom((data)=>data instanceof cls, params);
3744
+ const stringType = ZodString.create;
3745
+ const numberType = ZodNumber.create;
3746
+ const nanType = ZodNaN.create;
3747
+ const bigIntType = ZodBigInt.create;
3748
+ const booleanType = ZodBoolean.create;
3749
+ const dateType = ZodDate.create;
3750
+ const symbolType = ZodSymbol.create;
3751
+ const undefinedType = ZodUndefined.create;
3752
+ const nullType = ZodNull.create;
3753
+ const anyType = ZodAny.create;
3754
+ const unknownType = ZodUnknown.create;
3755
+ const neverType = ZodNever.create;
3756
+ const voidType = ZodVoid.create;
3757
+ const arrayType = ZodArray.create;
3758
+ const objectType = ZodObject.create;
3759
+ const strictObjectType = ZodObject.strictCreate;
3760
+ const unionType = ZodUnion.create;
3761
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
3762
+ const intersectionType = ZodIntersection.create;
3763
+ const tupleType = ZodTuple.create;
3764
+ const recordType = ZodRecord.create;
3765
+ const mapType = ZodMap.create;
3766
+ const setType = ZodSet.create;
3767
+ const functionType = ZodFunction.create;
3768
+ const lazyType = ZodLazy.create;
3769
+ const literalType = ZodLiteral.create;
3770
+ const enumType = ZodEnum.create;
3771
+ const nativeEnumType = ZodNativeEnum.create;
3772
+ const promiseType = ZodPromise.create;
3773
+ const effectsType = ZodEffects.create;
3774
+ const optionalType = ZodOptional.create;
3775
+ const nullableType = ZodNullable.create;
3776
+ const preprocessType = ZodEffects.createWithPreprocess;
3777
+ const pipelineType = ZodPipeline.create;
3778
+ const ostring = ()=>stringType().optional();
3779
+ const onumber = ()=>numberType().optional();
3780
+ const oboolean = ()=>booleanType().optional();
3781
+ const coerce = {
3782
+ string: (arg)=>ZodString.create({
3783
+ ...arg,
3784
+ coerce: true
3785
+ }),
3786
+ number: (arg)=>ZodNumber.create({
3787
+ ...arg,
3788
+ coerce: true
3789
+ }),
3790
+ boolean: (arg)=>ZodBoolean.create({
3791
+ ...arg,
3792
+ coerce: true
3793
+ }),
3794
+ bigint: (arg)=>ZodBigInt.create({
3795
+ ...arg,
3796
+ coerce: true
3797
+ }),
3798
+ date: (arg)=>ZodDate.create({
3799
+ ...arg,
3800
+ coerce: true
3801
+ })
3802
+ };
3803
+ const NEVER = INVALID;
3804
+ const v3 = external_namespaceObject;
3805
+ const esm = v3;
3806
+ const RequirementClarifierParams = objectType({
3807
+ user_input: stringType().describe("\u7528\u6237\u8F93\u5165\u7684\u9700\u6C42\u63CF\u8FF0"),
3808
+ context: stringType().optional().describe("\u9700\u6C42\u4E0A\u4E0B\u6587\u4FE1\u606F")
3809
+ });
3810
+ const RequirementManagerParams = objectType({
3811
+ clarified_info: stringType().describe("\u6F84\u6E05\u540E\u7684\u9700\u6C42\u4FE1\u606F"),
3812
+ category: enumType([
3813
+ "\u9879\u76EE\u6982\u8FF0",
3814
+ "\u6838\u5FC3\u529F\u80FD\u9700\u6C42",
3815
+ "\u529F\u80FD\u548CUI\u9700\u6C42",
3816
+ "\u529F\u80FD\u9700\u6C42",
3817
+ "\u6280\u672F\u9700\u6C42",
3818
+ "\u6280\u672F\u548C\u8BBE\u8BA1\u7EA6\u675F",
3819
+ "\u8BBE\u8BA1\u9700\u6C42",
3820
+ "\u90E8\u7F72\u9700\u6C42",
3821
+ "AI\u7EA6\u675F"
3822
+ ]).describe("\u9700\u6C42\u5206\u7C7B")
3823
+ });
3824
+ const ArchitectureDesignerParams = objectType({
3825
+ design_focus: stringType().optional().default("full_architecture").describe("\u8BBE\u8BA1\u91CD\u70B9")
3826
+ });
3827
+ function _define_property(obj, key, value) {
3828
+ if (key in obj) Object.defineProperty(obj, key, {
3829
+ value: value,
3830
+ enumerable: true,
3831
+ configurable: true,
3832
+ writable: true
3833
+ });
3834
+ else obj[key] = value;
3835
+ return obj;
3836
+ }
3837
+ const getStorageDir = ()=>{
3838
+ const envDir = process.env.MCP_STORAGE_DIR || "./intention-coding";
3839
+ if (!existsSync(envDir)) mkdirSync(envDir, {
3840
+ recursive: true
3841
+ });
3842
+ return envDir;
3843
+ };
3844
+ class RequirementStorage {
3845
+ get requirementsFile() {
3846
+ return this._requirementsFile;
3847
+ }
3848
+ get historyFile() {
3849
+ return this._historyFile;
3850
+ }
3851
+ get storageDirectory() {
3852
+ return this.storageDir;
3853
+ }
3854
+ loadRequirements() {
3855
+ try {
3856
+ if (existsSync(this.requirementsFile)) {
3857
+ const data = readFileSync(this.requirementsFile, "utf8");
3858
+ const savedData = JSON.parse(data);
3859
+ console.log(`\u{2705} \u{5DF2}\u{52A0}\u{8F7D}\u{9700}\u{6C42}\u{6587}\u{6863}: ${this.requirementsFile}`);
3860
+ return savedData;
3861
+ }
3862
+ } catch (e) {
3863
+ console.warn(`\u{26A0}\u{FE0F} \u{52A0}\u{8F7D}\u{9700}\u{6C42}\u{6587}\u{6863}\u{5931}\u{8D25}: ${e}`);
3864
+ }
3865
+ }
3866
+ saveRequirements(currentRequirements) {
3867
+ try {
3868
+ currentRequirements.last_updated = new Date().toISOString();
3869
+ writeFileSync(this.requirementsFile, JSON.stringify(currentRequirements, null, 2), "utf8");
3870
+ console.log(`\u{2705} \u{9700}\u{6C42}\u{6587}\u{6863}\u{5DF2}\u{4FDD}\u{5B58}: ${this.requirementsFile}`);
3871
+ } catch (e) {
3872
+ console.error(`\u{274C} \u{4FDD}\u{5B58}\u{9700}\u{6C42}\u{6587}\u{6863}\u{5931}\u{8D25}: ${e}`);
3873
+ }
3874
+ }
3875
+ saveHistoryEntry(entryType, content, metadata = {}) {
3876
+ try {
3877
+ const historyEntry = {
3878
+ timestamp: new Date().toISOString(),
3879
+ type: entryType,
3880
+ content,
3881
+ metadata
3882
+ };
3883
+ let history = [];
3884
+ if (existsSync(this.historyFile)) {
3885
+ const data = readFileSync(this.historyFile, "utf8");
3886
+ history = JSON.parse(data);
3887
+ }
3888
+ history.push(historyEntry);
3889
+ writeFileSync(this.historyFile, JSON.stringify(history, null, 2), "utf8");
3890
+ console.log(`\u{2705} \u{5386}\u{53F2}\u{8BB0}\u{5F55}\u{5DF2}\u{4FDD}\u{5B58}: ${entryType}`);
3891
+ } catch (e) {
3892
+ console.error(`\u{274C} \u{4FDD}\u{5B58}\u{5386}\u{53F2}\u{8BB0}\u{5F55}\u{5931}\u{8D25}: ${e}`);
3893
+ }
3894
+ }
3895
+ exportFinalDocument(currentRequirements) {
3896
+ try {
3897
+ const finalDoc = {
3898
+ project_summary: {
3899
+ generated_at: new Date().toISOString(),
3900
+ project_id: currentRequirements.project_id,
3901
+ last_updated: currentRequirements.last_updated
3902
+ },
3903
+ requirements: currentRequirements,
3904
+ export_format: "markdown"
3905
+ };
3906
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "_").slice(0, 19);
3907
+ const exportFile = join(this.storageDir, `final_document_${timestamp}.json`);
3908
+ writeFileSync(exportFile, JSON.stringify(finalDoc, null, 2), "utf8");
3909
+ this.generateMarkdownReport(currentRequirements, timestamp);
3910
+ console.log(`\u{2705} \u{6700}\u{7EC8}\u{6587}\u{6863}\u{5DF2}\u{5BFC}\u{51FA}: ${exportFile}`);
3911
+ return exportFile;
3912
+ } catch (e) {
3913
+ console.error(`\u{274C} \u{5BFC}\u{51FA}\u{6700}\u{7EC8}\u{6587}\u{6863}\u{5931}\u{8D25}: ${e}`);
3914
+ return null;
3915
+ }
3916
+ }
3917
+ generateMarkdownReport(currentRequirements, timestamp) {
3918
+ try {
3919
+ const mdFile = join(this.storageDir, `final_document_${timestamp}.md`);
3920
+ const mdContent = [
3921
+ "# \uD83D\uDE80 AI\u5F00\u53D1\u9879\u76EE\u9700\u6C42\u4E0E\u67B6\u6784\u6587\u6863\n"
3922
+ ];
3923
+ mdContent.push(`**\u{751F}\u{6210}\u{65F6}\u{95F4}**: ${new Date().toISOString().slice(0, 19)}\n`);
3924
+ if (currentRequirements.project_overview.length > 0) {
3925
+ mdContent.push("## \uD83D\uDCCB \u9879\u76EE\u6982\u8FF0\n");
3926
+ currentRequirements.project_overview.forEach((item)=>{
3927
+ mdContent.push(`- ${item.content}`);
3928
+ });
3929
+ mdContent.push("");
3930
+ }
3931
+ if (currentRequirements.functional_requirements.length > 0) {
3932
+ mdContent.push("## \u2699\uFE0F \u529F\u80FD\u9700\u6C42\n");
3933
+ currentRequirements.functional_requirements.forEach((item)=>{
3934
+ mdContent.push(`- ${item.content}`);
3935
+ });
3936
+ mdContent.push("");
3937
+ }
3938
+ if (currentRequirements.technical_requirements.length > 0) {
3939
+ mdContent.push("## \uD83D\uDD27 \u6280\u672F\u9700\u6C42\n");
3940
+ currentRequirements.technical_requirements.forEach((item)=>{
3941
+ mdContent.push(`- ${item.content}`);
3942
+ });
3943
+ mdContent.push("");
3944
+ }
3945
+ if (currentRequirements.architecture_designs.length > 0) {
3946
+ mdContent.push("## \uD83C\uDFD7\uFE0F \u67B6\u6784\u8BBE\u8BA1\n");
3947
+ currentRequirements.architecture_designs.forEach((design)=>{
3948
+ mdContent.push(`${design.content}\n`);
3949
+ });
3950
+ }
3951
+ if (currentRequirements.clarification_history.length > 0) {
3952
+ mdContent.push("## \uD83D\uDCDD \u9700\u6C42\u6F84\u6E05\u5386\u53F2\n");
3953
+ currentRequirements.clarification_history.forEach((item)=>{
3954
+ mdContent.push(`- ${item.content}`);
3955
+ });
3956
+ mdContent.push("");
3957
+ }
3958
+ writeFileSync(mdFile, mdContent.join("\n"), "utf8");
3959
+ console.log(`\u{2705} Markdown\u{62A5}\u{544A}\u{5DF2}\u{751F}\u{6210}: ${mdFile}`);
3960
+ } catch (e) {
3961
+ console.error(`\u{274C} \u{751F}\u{6210}Markdown\u{62A5}\u{544A}\u{5931}\u{8D25}: ${e}`);
3962
+ }
3963
+ }
3964
+ constructor(){
3965
+ _define_property(this, "storageDir", void 0);
3966
+ _define_property(this, "_requirementsFile", void 0);
3967
+ _define_property(this, "_historyFile", void 0);
3968
+ this.storageDir = getStorageDir();
3969
+ this._requirementsFile = join(this.storageDir, "requirements.json");
3970
+ this._historyFile = join(this.storageDir, "history.json");
3971
+ this.loadRequirements();
3972
+ }
3973
+ }
3974
+ const requirements_utils_currentRequirements = {
3975
+ project_overview: [],
3976
+ functional_requirements: [],
3977
+ technical_requirements: [],
3978
+ design_requirements: [],
3979
+ deployment_requirements: [],
3980
+ ai_constraints: [],
3981
+ clarification_history: [],
3982
+ architecture_designs: [],
3983
+ last_updated: null,
3984
+ project_id: null
3985
+ };
3986
+ const categoryMapping = {
3987
+ 项目概述: "project_overview",
3988
+ 核心功能需求: "functional_requirements",
3989
+ 功能和UI需求: "functional_requirements",
3990
+ 功能需求: "functional_requirements",
3991
+ 技术需求: "technical_requirements",
3992
+ 技术和设计约束: "technical_requirements",
3993
+ 设计需求: "design_requirements",
3994
+ 部署需求: "deployment_requirements",
3995
+ AI约束: "ai_constraints"
3996
+ };
3997
+ function countRequirements(requirements) {
3998
+ return [
3999
+ "project_overview",
4000
+ "functional_requirements",
4001
+ "technical_requirements",
4002
+ "design_requirements",
4003
+ "deployment_requirements",
4004
+ "ai_constraints"
4005
+ ].reduce((sum, key)=>sum + requirements[key].length, 0);
4006
+ }
4007
+ function getStorageCategory(category) {
4008
+ return categoryMapping[category] || "functional_requirements";
4009
+ }
4010
+ function addRequirementEntry(requirements, category, content) {
4011
+ const storageCategory = getStorageCategory(category);
4012
+ const requirementEntry = {
4013
+ timestamp: new Date().toISOString(),
4014
+ category,
4015
+ content
4016
+ };
4017
+ if (Array.isArray(requirements[storageCategory])) requirements[storageCategory].push(requirementEntry);
4018
+ else requirements[storageCategory] = [
4019
+ requirementEntry
4020
+ ];
4021
+ return requirements;
4022
+ }
4023
+ function formatRequirementUpdateResponse(category, content, requirements, requirementsFile, historyFile) {
4024
+ const total = countRequirements(requirements);
4025
+ return `# \u{2705} \u{9700}\u{6C42}\u{6587}\u{6863}\u{5DF2}\u{66F4}\u{65B0}
4026
+
4027
+ ## \u{1F4DD} \u{66F4}\u{65B0}\u{4FE1}\u{606F}
4028
+ - **\u{7C7B}\u{522B}**\u{FF1A}${category}
4029
+ - **\u{5185}\u{5BB9}**\u{FF1A}${content}
4030
+ - **\u{65F6}\u{95F4}**\u{FF1A}${new Date().toISOString().slice(0, 19)}
4031
+ - **\u{5B58}\u{50A8}\u{4F4D}\u{7F6E}**\u{FF1A}${requirementsFile}
4032
+
4033
+ ## \u{1F4CB} \u{5F53}\u{524D}\u{9700}\u{6C42}\u{6587}\u{6863}\u{72B6}\u{6001}
4034
+ - **\u{603B}\u{9700}\u{6C42}\u{6761}\u{76EE}**\u{FF1A}${total}
4035
+ - **\u{9879}\u{76EE}\u{6982}\u{8FF0}**\u{FF1A}${requirements.project_overview.length} \u{6761}
4036
+ - **\u{529F}\u{80FD}\u{9700}\u{6C42}**\u{FF1A}${requirements.functional_requirements.length} \u{6761}
4037
+ - **\u{6280}\u{672F}\u{9700}\u{6C42}**\u{FF1A}${requirements.technical_requirements.length} \u{6761}
4038
+ - **\u{8BBE}\u{8BA1}\u{9700}\u{6C42}**\u{FF1A}${requirements.design_requirements.length} \u{6761}
4039
+
4040
+ ## \u{1F4BE} \u{6301}\u{4E45}\u{5316}\u{5B58}\u{50A8}
4041
+ - \u{2705} \u{9700}\u{6C42}\u{5DF2}\u{4FDD}\u{5B58}\u{5230}: \`${requirementsFile}\`
4042
+ - \u{2705} \u{5386}\u{53F2}\u{8BB0}\u{5F55}\u{5DF2}\u{4FDD}\u{5B58}\u{5230}: \`${historyFile}\`
4043
+
4044
+ ## \u{1F3AF} \u{4E0B}\u{4E00}\u{6B65}\u{5EFA}\u{8BAE}
4045
+ \u{7EE7}\u{7EED}\u{4F7F}\u{7528} requirement_clarifier \u{5B8C}\u{5584}\u{5176}\u{4ED6}\u{9700}\u{6C42}\u{4FE1}\u{606F}\u{FF0C}\u{6216}\u{5728}\u{9700}\u{6C42}\u{5B8C}\u{6574}\u{540E}\u{4F7F}\u{7528} architecture_designer \u{751F}\u{6210}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{3002}`;
4046
+ }
4047
+ const requirementClarifierTool = {
4048
+ name: "requirement_clarifier",
4049
+ description: "\u9700\u6C42\u6F84\u6E05\u52A9\u624B - \u5206\u6790\u7528\u6237\u9700\u6C42\u5B8C\u6574\u6027\uFF0C\u4E3B\u52A8\u53D1\u73B0\u4E0D\u660E\u786E\u7684\u5730\u65B9",
4050
+ parameters: RequirementClarifierParams,
4051
+ execute: async (args)=>{
4052
+ const { user_input, context = "" } = args;
4053
+ const storage = new RequirementStorage();
4054
+ if (!requirements_utils_currentRequirements.clarification_history) requirements_utils_currentRequirements.clarification_history = [];
4055
+ requirements_utils_currentRequirements.clarification_history.push({
4056
+ timestamp: new Date().toISOString(),
4057
+ content: `\u{7528}\u{6237}\u{8F93}\u{5165}: ${user_input} | \u{4E0A}\u{4E0B}\u{6587}: ${context}`
4058
+ });
4059
+ storage.saveHistoryEntry("requirement_clarification", user_input, {
4060
+ context
4061
+ });
4062
+ storage.saveRequirements(requirements_utils_currentRequirements);
4063
+ const analysisPrompt = `# \u{1F50D} AI\u{9700}\u{6C42}\u{5206}\u{6790}\u{4EFB}\u{52A1} - \u{5FC5}\u{987B}\u{5B8C}\u{6210}
4064
+
4065
+ ## \u{1F4DD} \u{7528}\u{6237}\u{8F93}\u{5165}
4066
+ ${user_input}
4067
+
4068
+ ## \u{1F4CB} \u{5F53}\u{524D}\u{4E0A}\u{4E0B}\u{6587}
4069
+ ${context}
4070
+
4071
+ ## \u{1F3AF} \u{4F60}\u{7684}\u{5206}\u{6790}\u{4EFB}\u{52A1}\u{FF08}AI\u{52A9}\u{624B}\u{5FC5}\u{987B}\u{6267}\u{884C}\u{FF09}
4072
+
4073
+ ### 1. \u{9879}\u{76EE}\u{7C7B}\u{578B}\u{8BC6}\u{522B}
4074
+ \u{6839}\u{636E}\u{7528}\u{6237}\u{63CF}\u{8FF0}\u{FF0C}\u{5224}\u{65AD}\u{9879}\u{76EE}\u{7C7B}\u{578B}\u{FF1A}
4075
+ - **Web\u{5E94}\u{7528}**\u{FF1A}\u{7F51}\u{7AD9}\u{3001}Web\u{7CFB}\u{7EDF}\u{3001}\u{5728}\u{7EBF}\u{5E73}\u{53F0}
4076
+ - **\u{79FB}\u{52A8}\u{5E94}\u{7528}**\u{FF1A}\u{624B}\u{673A}APP\u{3001}\u{79FB}\u{52A8}\u{7AEF}\u{5E94}\u{7528}
4077
+ - **\u{684C}\u{9762}\u{5E94}\u{7528}**\u{FF1A}PC\u{8F6F}\u{4EF6}\u{3001}\u{684C}\u{9762}\u{5DE5}\u{5177}
4078
+ - **\u{5C0F}\u{7A0B}\u{5E8F}**\u{FF1A}\u{5FAE}\u{4FE1}\u{5C0F}\u{7A0B}\u{5E8F}\u{3001}\u{652F}\u{4ED8}\u{5B9D}\u{5C0F}\u{7A0B}\u{5E8F}
4079
+ - **\u{901A}\u{7528}\u{9879}\u{76EE}**\u{FF1A}\u{5176}\u{4ED6}\u{7C7B}\u{578B}\u{6216}\u{6DF7}\u{5408}\u{9879}\u{76EE}
4080
+
4081
+ ### 2. \u{9700}\u{6C42}\u{5B8C}\u{6574}\u{6027}\u{6DF1}\u{5EA6}\u{5206}\u{6790}
4082
+ \u{68C0}\u{67E5}\u{4EE5}\u{4E0B}\u{5173}\u{952E}\u{7EF4}\u{5EA6}\u{662F}\u{5426}\u{660E}\u{786E}\u{FF1A}
4083
+
4084
+ **\u{1F3AF} \u{9879}\u{76EE}\u{76EE}\u{6807}\u{7EF4}\u{5EA6}**
4085
+ - \u{89E3}\u{51B3}\u{4EC0}\u{4E48}\u{5177}\u{4F53}\u{95EE}\u{9898}\u{FF1F}
4086
+ - \u{76EE}\u{6807}\u{7528}\u{6237}\u{7FA4}\u{4F53}\u{662F}\u{8C01}\u{FF1F}
4087
+ - \u{9884}\u{671F}\u{8FBE}\u{5230}\u{4EC0}\u{4E48}\u{6548}\u{679C}\u{FF1F}
4088
+
4089
+ **\u{2699}\u{FE0F} \u{529F}\u{80FD}\u{9700}\u{6C42}\u{7EF4}\u{5EA6}**
4090
+ - \u{6838}\u{5FC3}\u{529F}\u{80FD}\u{6709}\u{54EA}\u{4E9B}\u{FF1F}\u{FF08}\u{6700}\u{91CD}\u{8981}\u{7684}3-5\u{4E2A}\u{FF09}
4091
+ - \u{6B21}\u{8981}\u{529F}\u{80FD}\u{6709}\u{54EA}\u{4E9B}\u{FF1F}
4092
+ - \u{529F}\u{80FD}\u{7684}\u{4F18}\u{5148}\u{7EA7}\u{5982}\u{4F55}\u{FF1F}
4093
+
4094
+ **\u{1F527} \u{6280}\u{672F}\u{9700}\u{6C42}\u{7EF4}\u{5EA6}**
4095
+ - \u{6709}\u{6280}\u{672F}\u{6808}\u{504F}\u{597D}\u{5417}\u{FF1F}
4096
+ - \u{6027}\u{80FD}\u{8981}\u{6C42}\u{5982}\u{4F55}\u{FF1F}
4097
+ - \u{517C}\u{5BB9}\u{6027}\u{8981}\u{6C42}\u{FF1F}
4098
+
4099
+ **\u{1F3A8} \u{7528}\u{6237}\u{4F53}\u{9A8C}\u{7EF4}\u{5EA6}**
4100
+ - \u{754C}\u{9762}\u{98CE}\u{683C}\u{504F}\u{597D}\u{FF1F}
4101
+ - \u{4EA4}\u{4E92}\u{65B9}\u{5F0F}\u{8981}\u{6C42}\u{FF1F}
4102
+
4103
+ **\u{1F4CA} \u{89C4}\u{6A21}\u{548C}\u{6027}\u{80FD}\u{7EF4}\u{5EA6}**
4104
+ - \u{9884}\u{671F}\u{7528}\u{6237}\u{89C4}\u{6A21}\u{FF1F}
4105
+ - \u{5E76}\u{53D1}\u{91CF}\u{8981}\u{6C42}\u{FF1F}
4106
+
4107
+ **\u{1F680} \u{90E8}\u{7F72}\u{548C}\u{7EF4}\u{62A4}\u{7EF4}\u{5EA6}**
4108
+ - \u{90E8}\u{7F72}\u{73AF}\u{5883}\u{504F}\u{597D}\u{FF1F}
4109
+ - \u{7EF4}\u{62A4}\u{65B9}\u{5F0F}\u{FF1F}
4110
+
4111
+ ### 3. \u{667A}\u{80FD}\u{6F84}\u{6E05}\u{7B56}\u{7565}
4112
+ \u{751F}\u{6210}2-3\u{4E2A}\u{6700}\u{91CD}\u{8981}\u{7684}\u{6F84}\u{6E05}\u{95EE}\u{9898}\u{FF1A}
4113
+ - \u{4F18}\u{5148}\u{6F84}\u{6E05}\u{5BF9}\u{9879}\u{76EE}\u{5F71}\u{54CD}\u{6700}\u{5927}\u{7684}\u{65B9}\u{9762}
4114
+ - \u{63D0}\u{4F9B}\u{5177}\u{4F53}\u{9009}\u{9879}\u{5E2E}\u{52A9}\u{7528}\u{6237}\u{7406}\u{89E3}
4115
+ - \u{4F7F}\u{7528}\u{53CB}\u{597D}\u{8BED}\u{8A00}\u{FF0C}\u{907F}\u{514D}\u{8FC7}\u{4E8E}\u{6280}\u{672F}\u{5316}
4116
+
4117
+ ## \u{1F4E4} \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{8981}\u{6C42}
4118
+
4119
+ **\u{1F50D} \u{9700}\u{6C42}\u{5206}\u{6790}\u{7ED3}\u{679C}\u{FF1A}**
4120
+ - **\u{9879}\u{76EE}\u{7C7B}\u{578B}**\u{FF1A}[\u{660E}\u{786E}\u{8BC6}\u{522B}\u{7684}\u{7C7B}\u{578B}]
4121
+ - **\u{5DF2}\u{660E}\u{786E}\u{4FE1}\u{606F}**\u{FF1A}[\u{7528}\u{6237}\u{5DF2}\u{7ECF}\u{6E05}\u{695A}\u{8868}\u{8FBE}\u{7684}\u{9700}\u{6C42}\u{70B9}]
4122
+ - **\u{9700}\u{8981}\u{6F84}\u{6E05}**\u{FF1A}[\u{4E0D}\u{660E}\u{786E}\u{3001}\u{6709}\u{6B67}\u{4E49}\u{6216}\u{7F3A}\u{5931}\u{7684}\u{5173}\u{952E}\u{4FE1}\u{606F}]
4123
+
4124
+ **\u{2753} \u{5173}\u{952E}\u{6F84}\u{6E05}\u{95EE}\u{9898}\u{FF1A}**
4125
+ 1. [\u{6700}\u{91CD}\u{8981}\u{7684}\u{6F84}\u{6E05}\u{95EE}\u{9898}\u{FF0C}\u{5305}\u{542B}\u{9009}\u{9879}]
4126
+ 2. [\u{7B2C}\u{4E8C}\u{91CD}\u{8981}\u{7684}\u{95EE}\u{9898}\u{FF0C}\u{63D0}\u{4F9B}\u{793A}\u{4F8B}]
4127
+ 3. [\u{7B2C}\u{4E09}\u{4E2A}\u{95EE}\u{9898}\u{FF0C}\u{5982}\u{679C}\u{9700}\u{8981}\u{7684}\u{8BDD}]
4128
+
4129
+ **\u{1F4A1} \u{4E13}\u{4E1A}\u{5EFA}\u{8BAE}\u{FF1A}**
4130
+ [\u{57FA}\u{4E8E}\u{5206}\u{6790}\u{7ED9}\u{51FA}\u{7684}\u{5EFA}\u{8BAE}\u{548C}\u{63D0}\u{793A}]
4131
+
4132
+ **\u{1F3AF} \u{4E0B}\u{4E00}\u{6B65}\u{6307}\u{5BFC}\u{FF1A}**
4133
+ [\u{544A}\u{8BC9}\u{7528}\u{6237}\u{63A5}\u{4E0B}\u{6765}\u{5E94}\u{8BE5}\u{5982}\u{4F55}\u{56DE}\u{7B54}\u{6216}\u{601D}\u{8003}]
4134
+
4135
+ ---
4136
+ *\u{91CD}\u{8981}\u{63D0}\u{9192}\u{FF1A}\u{6BCF}\u{6B21}\u{6F84}\u{6E05}\u{540E}\u{FF0C}\u{8BF7}\u{4F7F}\u{7528} requirement_manager \u{5DE5}\u{5177}\u{4FDD}\u{5B58}\u{660E}\u{786E}\u{7684}\u{9700}\u{6C42}\u{4FE1}\u{606F}\u{FF01}*
4137
+ `;
4138
+ return analysisPrompt;
4139
+ }
4140
+ };
4141
+ const requirementManagerTool = {
4142
+ name: "requirement_manager",
4143
+ description: "\u9700\u6C42\u6587\u6863\u7BA1\u7406\u5668 - \u5B9E\u65F6\u66F4\u65B0\u548C\u7EF4\u62A4\u7ED3\u6784\u5316\u7684\u9700\u6C42\u6587\u6863",
4144
+ parameters: RequirementManagerParams,
4145
+ execute: async (args)=>{
4146
+ const { clarified_info, category } = args;
4147
+ const storage = new RequirementStorage();
4148
+ addRequirementEntry(requirements_utils_currentRequirements, category, clarified_info);
4149
+ storage.saveHistoryEntry("requirement_update", clarified_info, {
4150
+ category
4151
+ });
4152
+ storage.saveRequirements(requirements_utils_currentRequirements);
4153
+ return formatRequirementUpdateResponse(category, clarified_info, requirements_utils_currentRequirements, storage.requirementsFile, storage.historyFile);
4154
+ }
4155
+ };
4156
+ const architectureDesignerTool = {
4157
+ name: "architecture_designer",
4158
+ description: "\u67B6\u6784\u8BBE\u8BA1\u751F\u6210\u5668 - \u57FA\u4E8E\u5B8C\u6574\u9700\u6C42\u751F\u6210\u6700\u4F18\u6280\u672F\u67B6\u6784\u65B9\u6848",
4159
+ parameters: ArchitectureDesignerParams,
4160
+ execute: async (args)=>{
4161
+ const { design_focus = "full_architecture" } = args;
4162
+ const storage = new RequirementStorage();
4163
+ const architecture_design = `# \u{1F3D7}\u{FE0F} \u{9879}\u{76EE}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{65B9}\u{6848}
4164
+
4165
+ ## \u{1F3AF} \u{8BBE}\u{8BA1}\u{76EE}\u{6807}
4166
+ - **\u{8BBE}\u{8BA1}\u{91CD}\u{70B9}**\u{FF1A}${design_focus}
4167
+ - **\u{4F18}\u{5316}\u{76EE}\u{6807}**\u{FF1A}AI\u{53CB}\u{597D}\u{3001}\u{4F4E}\u{8026}\u{5408}\u{3001}\u{53EF}\u{7EF4}\u{62A4}
4168
+
4169
+ ## \u{1F3DB}\u{FE0F} \u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{539F}\u{5219}\u{FF08}\u{9488}\u{5BF9}AI\u{5F00}\u{53D1}\u{4F18}\u{5316}\u{FF09}
4170
+
4171
+ ### 1. \u{4F4E}\u{8026}\u{5408}\u{8BBE}\u{8BA1}\u{539F}\u{5219}
4172
+ - **\u{6A21}\u{5757}\u{72EC}\u{7ACB}\u{6027}**\u{FF1A}\u{6BCF}\u{4E2A}\u{6A21}\u{5757}\u{529F}\u{80FD}\u{5355}\u{4E00}\u{FF0C}\u{8FB9}\u{754C}\u{6E05}\u{6670}
4173
+ - **\u{63A5}\u{53E3}\u{6807}\u{51C6}\u{5316}**\u{FF1A}\u{7EDF}\u{4E00}\u{7684}API\u{63A5}\u{53E3}\u{89C4}\u{8303}
4174
+ - **\u{4F9D}\u{8D56}\u{6700}\u{5C0F}\u{5316}**\u{FF1A}\u{51CF}\u{5C11}\u{6A21}\u{5757}\u{95F4}\u{7684}\u{5F3A}\u{4F9D}\u{8D56}\u{5173}\u{7CFB}
4175
+ - **\u{9519}\u{8BEF}\u{9694}\u{79BB}**\u{FF1A}\u{5355}\u{4E2A}\u{6A21}\u{5757}\u{95EE}\u{9898}\u{4E0D}\u{5F71}\u{54CD}\u{6574}\u{4F53}\u{7CFB}\u{7EDF}
4176
+
4177
+ ### 2. AI\u{53CB}\u{597D}\u{67B6}\u{6784}\u{539F}\u{5219}
4178
+ - **\u{4EE3}\u{7801}\u{53EF}\u{7406}\u{89E3}\u{6027}**\u{FF1A}\u{6E05}\u{6670}\u{7684}\u{547D}\u{540D}\u{548C}\u{6CE8}\u{91CA}\u{89C4}\u{8303}
4179
+ - **\u{6A21}\u{5757}\u{5316}\u{5F00}\u{53D1}**\u{FF1A}\u{907F}\u{514D}\u{5927}\u{6587}\u{4EF6}\u{FF0C}\u{4FBF}\u{4E8E}AI\u{7406}\u{89E3}\u{548C}\u{4FEE}\u{6539}
4180
+ - **\u{6807}\u{51C6}\u{5316}\u{7ED3}\u{6784}**\u{FF1A}\u{7EDF}\u{4E00}\u{7684}\u{9879}\u{76EE}\u{7ED3}\u{6784}\u{548C}\u{4EE3}\u{7801}\u{7EC4}\u{7EC7}
4181
+ - **\u{6E10}\u{8FDB}\u{5F0F}\u{5F00}\u{53D1}**\u{FF1A}\u{652F}\u{6301}\u{5206}\u{9636}\u{6BB5}\u{5B9E}\u{73B0}\u{548C}\u{6D4B}\u{8BD5}
4182
+
4183
+ ## \u{1F527} \u{6280}\u{672F}\u{67B6}\u{6784}\u{5EFA}\u{8BAE}
4184
+
4185
+ ### \u{524D}\u{7AEF}\u{67B6}\u{6784}
4186
+ **\u{63A8}\u{8350}\u{6280}\u{672F}\u{6808}\u{FF1A}**
4187
+ - \u{6846}\u{67B6}\u{FF1A}React 18 / Vue 3 / Next.js 15
4188
+ - \u{72B6}\u{6001}\u{7BA1}\u{7406}\u{FF1A}Redux Toolkit / Zustand / Pinia
4189
+ - UI\u{7EC4}\u{4EF6}\u{FF1A}Ant Design / Material-UI / Tailwind CSS
4190
+
4191
+ ### \u{540E}\u{7AEF}\u{67B6}\u{6784}
4192
+ **\u{63A8}\u{8350}\u{6280}\u{672F}\u{6808}\u{FF1A}**
4193
+ - \u{6846}\u{67B6}\u{FF1A}FastAPI / Express.js / Spring Boot
4194
+ - \u{6570}\u{636E}\u{5E93}\u{FF1A}PostgreSQL / MySQL / MongoDB
4195
+ - \u{7F13}\u{5B58}\u{FF1A}Redis / Memcached
4196
+
4197
+ ## \u{1F4E6} \u{529F}\u{80FD}\u{6A21}\u{5757}\u{5212}\u{5206}
4198
+
4199
+ ### \u{6838}\u{5FC3}\u{4E1A}\u{52A1}\u{6A21}\u{5757}
4200
+ 1. **\u{7528}\u{6237}\u{7BA1}\u{7406}\u{6A21}\u{5757}**
4201
+ - \u{529F}\u{80FD}\u{FF1A}\u{7528}\u{6237}\u{6CE8}\u{518C}\u{3001}\u{767B}\u{5F55}\u{3001}\u{6743}\u{9650}\u{7BA1}\u{7406}
4202
+ - \u{63A5}\u{53E3}\u{FF1A}\u{7528}\u{6237}CRUD\u{3001}\u{8BA4}\u{8BC1}API
4203
+ - AI\u{5F00}\u{53D1}\u{63D0}\u{793A}\u{FF1A}\u{5148}\u{5B9E}\u{73B0}\u{57FA}\u{7840}\u{8BA4}\u{8BC1}\u{FF0C}\u{518D}\u{6DFB}\u{52A0}\u{9AD8}\u{7EA7}\u{529F}\u{80FD}
4204
+
4205
+ 2. **\u{4E1A}\u{52A1}\u{6838}\u{5FC3}\u{6A21}\u{5757}**
4206
+ - \u{529F}\u{80FD}\u{FF1A}[\u{6839}\u{636E}\u{5177}\u{4F53}\u{9700}\u{6C42}\u{5B9A}\u{5236}]
4207
+ - \u{63A5}\u{53E3}\u{FF1A}\u{4E1A}\u{52A1}\u{903B}\u{8F91}API\u{3001}\u{6570}\u{636E}\u{5904}\u{7406}\u{63A5}\u{53E3}
4208
+ - AI\u{5F00}\u{53D1}\u{63D0}\u{793A}\u{FF1A}\u{6309}\u{529F}\u{80FD}\u{4F18}\u{5148}\u{7EA7}\u{9010}\u{6B65}\u{5B9E}\u{73B0}
4209
+
4210
+ ## \u{1F4C5} \u{5F00}\u{53D1}\u{9636}\u{6BB5}\u{89C4}\u{5212}
4211
+
4212
+ ### \u{7B2C}\u{4E00}\u{9636}\u{6BB5}\u{FF1A}\u{57FA}\u{7840}\u{6846}\u{67B6}\u{642D}\u{5EFA}\u{FF08}1-2\u{5468}\u{FF09}
4213
+ - \u{9879}\u{76EE}\u{521D}\u{59CB}\u{5316}\u{548C}\u{73AF}\u{5883}\u{914D}\u{7F6E}
4214
+ - \u{57FA}\u{7840}\u{6846}\u{67B6}\u{4EE3}\u{7801}\u{642D}\u{5EFA}
4215
+ - \u{6570}\u{636E}\u{5E93}\u{8BBE}\u{8BA1}\u{548C}\u{521D}\u{59CB}\u{5316}
4216
+
4217
+ ### \u{7B2C}\u{4E8C}\u{9636}\u{6BB5}\u{FF1A}\u{6838}\u{5FC3}\u{529F}\u{80FD}\u{5F00}\u{53D1}\u{FF08}2-4\u{5468}\u{FF09}
4218
+ - \u{7528}\u{6237}\u{7BA1}\u{7406}\u{529F}\u{80FD}\u{5B9E}\u{73B0}
4219
+ - \u{6838}\u{5FC3}\u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{5F00}\u{53D1}
4220
+ - \u{524D}\u{7AEF}\u{4E3B}\u{8981}\u{9875}\u{9762}\u{5B9E}\u{73B0}
4221
+
4222
+ ### \u{7B2C}\u{4E09}\u{9636}\u{6BB5}\u{FF1A}\u{529F}\u{80FD}\u{5B8C}\u{5584}\u{548C}\u{4F18}\u{5316}\u{FF08}1-3\u{5468}\u{FF09}
4223
+ - \u{6B21}\u{8981}\u{529F}\u{80FD}\u{5B9E}\u{73B0}
4224
+ - \u{6027}\u{80FD}\u{4F18}\u{5316}\u{548C}\u{8C03}\u{8BD5}
4225
+ - \u{7528}\u{6237}\u{4F53}\u{9A8C}\u{4F18}\u{5316}
4226
+
4227
+ ## \u{1F916} AI\u{5F00}\u{53D1}\u{6700}\u{4F73}\u{5B9E}\u{8DF5}
4228
+
4229
+ ### \u{6A21}\u{5757}\u{5F00}\u{53D1}\u{6307}\u{5BFC}
4230
+ 1. **\u{5148}\u{5B9E}\u{73B0}\u{6838}\u{5FC3}\u{903B}\u{8F91}**\u{FF1A}\u{4E13}\u{6CE8}\u{4E3B}\u{8981}\u{529F}\u{80FD}
4231
+ 2. **\u{518D}\u{6DFB}\u{52A0}\u{9519}\u{8BEF}\u{5904}\u{7406}**\u{FF1A}\u{5B8C}\u{5584}\u{5F02}\u{5E38}\u{5904}\u{7406}
4232
+ 3. **\u{6700}\u{540E}\u{8FDB}\u{884C}\u{4F18}\u{5316}**\u{FF1A}\u{6027}\u{80FD}\u{4F18}\u{5316}\u{548C}\u{4EE3}\u{7801}\u{91CD}\u{6784}
4233
+
4234
+ ### \u{63A5}\u{53E3}\u{8BBE}\u{8BA1}\u{89C4}\u{8303}
4235
+ - GET /api/users - \u{83B7}\u{53D6}\u{7528}\u{6237}\u{5217}\u{8868}
4236
+ - POST /api/users - \u{521B}\u{5EFA}\u{7528}\u{6237}
4237
+ - PUT /api/users/:id - \u{66F4}\u{65B0}\u{7528}\u{6237}
4238
+ - DELETE /api/users/:id - \u{5220}\u{9664}\u{7528}\u{6237}
4239
+
4240
+ ## \u{1F3AF} \u{603B}\u{7ED3}\u{548C}\u{5EFA}\u{8BAE}
4241
+
4242
+ ### \u{67B6}\u{6784}\u{4F18}\u{52BF}
4243
+ 1. **\u{4F4E}\u{8026}\u{5408}\u{8BBE}\u{8BA1}**\u{FF1A}\u{6A21}\u{5757}\u{72EC}\u{7ACB}\u{FF0C}\u{4FBF}\u{4E8E}\u{7EF4}\u{62A4}\u{548C}\u{6269}\u{5C55}
4244
+ 2. **AI\u{53CB}\u{597D}**\u{FF1A}\u{6E05}\u{6670}\u{7684}\u{7ED3}\u{6784}\u{FF0C}\u{4FBF}\u{4E8E}AI\u{7406}\u{89E3}\u{548C}\u{5F00}\u{53D1}
4245
+ 3. **\u{53EF}\u{6269}\u{5C55}\u{6027}**\u{FF1A}\u{652F}\u{6301}\u{4E1A}\u{52A1}\u{589E}\u{957F}\u{548C}\u{529F}\u{80FD}\u{6269}\u{5C55}
4246
+
4247
+ ### \u{5B9E}\u{65BD}\u{5EFA}\u{8BAE}
4248
+ 1. **\u{5206}\u{9636}\u{6BB5}\u{5B9E}\u{65BD}**\u{FF1A}\u{6309}\u{8BA1}\u{5212}\u{9010}\u{6B65}\u{5B9E}\u{73B0}
4249
+ 2. **\u{6301}\u{7EED}\u{6D4B}\u{8BD5}**\u{FF1A}\u{6BCF}\u{4E2A}\u{9636}\u{6BB5}\u{90FD}\u{8981}\u{8FDB}\u{884C}\u{5145}\u{5206}\u{6D4B}\u{8BD5}
4250
+ 3. **\u{6587}\u{6863}\u{540C}\u{6B65}**\u{FF1A}\u{53CA}\u{65F6}\u{66F4}\u{65B0}\u{6587}\u{6863}
4251
+
4252
+ ---
4253
+
4254
+ **\u{1F389} \u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{5B8C}\u{6210}\u{FF01}**
4255
+
4256
+ \u{8FD9}\u{4E2A}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{65B9}\u{6848}\u{4E13}\u{95E8}\u{9488}\u{5BF9}AI\u{5F00}\u{53D1}\u{8FDB}\u{884C}\u{4E86}\u{4F18}\u{5316}\u{FF0C}\u{786E}\u{4FDD}\u{4F4E}\u{8026}\u{5408}\u{3001}AI\u{53CB}\u{597D}\u{7684}\u{5F00}\u{53D1}\u{4F53}\u{9A8C}\u{FF01}
4257
+
4258
+ ## \u{1F4BE} \u{6587}\u{6863}\u{5B58}\u{50A8}\u{4FE1}\u{606F}
4259
+ - **\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{5DF2}\u{4FDD}\u{5B58}\u{5230}**: \`${storage.requirementsFile}\`
4260
+ - **\u{5B8C}\u{6574}\u{6587}\u{6863}\u{5BFC}\u{51FA}**: \u{4F7F}\u{7528} \`export_final_document\` \u{5DE5}\u{5177}\u{5BFC}\u{51FA}\u{5B8C}\u{6574}\u{9879}\u{76EE}\u{6587}\u{6863}
4261
+ `;
4262
+ requirements_utils_currentRequirements.architecture_designs = requirements_utils_currentRequirements.architecture_designs || [];
4263
+ requirements_utils_currentRequirements.architecture_designs.push({
4264
+ timestamp: new Date().toISOString(),
4265
+ design_focus,
4266
+ content: architecture_design
4267
+ });
4268
+ storage.saveHistoryEntry("architecture_design", architecture_design, {
4269
+ design_focus
4270
+ });
4271
+ storage.saveRequirements(requirements_utils_currentRequirements);
4272
+ return architecture_design;
4273
+ }
4274
+ };
4275
+ const exportFinalDocumentTool = {
4276
+ name: "export_final_document",
4277
+ description: "\u5BFC\u51FA\u5B8C\u6574\u7684\u9879\u76EE\u9700\u6C42\u548C\u67B6\u6784\u6587\u6863",
4278
+ parameters: esm.object({}),
4279
+ execute: async ()=>{
4280
+ const storage = new RequirementStorage();
4281
+ const exportPath = storage.exportFinalDocument(requirements_utils_currentRequirements);
4282
+ if (!exportPath) return `# \u{274C} \u{6587}\u{6863}\u{5BFC}\u{51FA}\u{5931}\u{8D25}
4283
+
4284
+ \u{8BF7}\u{68C0}\u{67E5}\u{5B58}\u{50A8}\u{76EE}\u{5F55}\u{6743}\u{9650}\u{548C}\u{78C1}\u{76D8}\u{7A7A}\u{95F4}\u{3002}
4285
+
4286
+ **\u{5B58}\u{50A8}\u{76EE}\u{5F55}**: \`${storage.storageDir}\``;
4287
+ {
4288
+ const totalClarifications = requirements_utils_currentRequirements.clarification_history.length;
4289
+ const totalRequirements = [
4290
+ "project_overview",
4291
+ "functional_requirements",
4292
+ "technical_requirements",
4293
+ "design_requirements",
4294
+ "deployment_requirements",
4295
+ "ai_constraints"
4296
+ ].reduce((sum, key)=>sum + requirements_utils_currentRequirements[key].length, 0);
4297
+ const totalArchitectures = requirements_utils_currentRequirements.architecture_designs.length;
4298
+ return `# \u{1F4C4} \u{9879}\u{76EE}\u{6587}\u{6863}\u{5BFC}\u{51FA}\u{5B8C}\u{6210}
4299
+
4300
+ ## \u{2705} \u{5BFC}\u{51FA}\u{4FE1}\u{606F}
4301
+ - **\u{5BFC}\u{51FA}\u{65F6}\u{95F4}**: ${new Date().toISOString().slice(0, 19)}
4302
+ - **\u{6587}\u{4EF6}\u{8DEF}\u{5F84}**: \`${exportPath}\`
4303
+ - **Markdown\u{7248}\u{672C}**: \`${exportPath.replace('.json', '.md')}\`
4304
+
4305
+ ## \u{1F4CA} \u{6587}\u{6863}\u{7EDF}\u{8BA1}
4306
+ - **\u{9700}\u{6C42}\u{6F84}\u{6E05}\u{6B21}\u{6570}**: ${totalClarifications}
4307
+ - **\u{9700}\u{6C42}\u{6761}\u{76EE}\u{603B}\u{6570}**: ${totalRequirements}
4308
+ - **\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{65B9}\u{6848}**: ${totalArchitectures}
4309
+
4310
+ ## \u{1F4C1} \u{5B58}\u{50A8}\u{76EE}\u{5F55}\u{7ED3}\u{6784}
4311
+ \`\`\`
4312
+ ${storage.storageDir}/
4313
+ \u{251C}\u{2500}\u{2500} requirements.json # \u{5B9E}\u{65F6}\u{9700}\u{6C42}\u{6587}\u{6863}
4314
+ \u{251C}\u{2500}\u{2500} history.json # \u{64CD}\u{4F5C}\u{5386}\u{53F2}\u{8BB0}\u{5F55}
4315
+ \u{251C}\u{2500}\u{2500} final_document_*.json # \u{5BFC}\u{51FA}\u{7684}\u{5B8C}\u{6574}\u{6587}\u{6863}
4316
+ \u{2514}\u{2500}\u{2500} final_document_*.md # Markdown\u{683C}\u{5F0F}\u{62A5}\u{544A}
4317
+ \`\`\`
4318
+
4319
+ ## \u{1F3AF} \u{6587}\u{6863}\u{7528}\u{9014}
4320
+ - **requirements.json**: \u{5B9E}\u{65F6}\u{66F4}\u{65B0}\u{7684}\u{7ED3}\u{6784}\u{5316}\u{9700}\u{6C42}\u{6570}\u{636E}
4321
+ - **history.json**: \u{5B8C}\u{6574}\u{7684}\u{64CD}\u{4F5C}\u{5386}\u{53F2}\u{FF0C}\u{4FBF}\u{4E8E}\u{8FFD}\u{6EAF}
4322
+ - **final_document_*.json**: \u{5B8C}\u{6574}\u{9879}\u{76EE}\u{6587}\u{6863}\u{FF0C}\u{5305}\u{542B}\u{6240}\u{6709}\u{4FE1}\u{606F}
4323
+ - **final_document_*.md**: \u{4EBA}\u{7C7B}\u{53EF}\u{8BFB}\u{7684}Markdown\u{62A5}\u{544A}
4324
+
4325
+ ## \u{1F4A1} \u{4F7F}\u{7528}\u{5EFA}\u{8BAE}
4326
+ 1. \u{5C06}\u{5BFC}\u{51FA}\u{7684}\u{6587}\u{6863}\u{4FDD}\u{5B58}\u{5230}\u{9879}\u{76EE}\u{4ED3}\u{5E93}\u{4E2D}
4327
+ 2. \u{4F7F}\u{7528}Markdown\u{6587}\u{4EF6}\u{4F5C}\u{4E3A}\u{9879}\u{76EE}README\u{7684}\u{57FA}\u{7840}
4328
+ 3. JSON\u{6587}\u{4EF6}\u{53EF}\u{7528}\u{4E8E}\u{540E}\u{7EED}\u{7684}\u{81EA}\u{52A8}\u{5316}\u{5904}\u{7406}
4329
+
4330
+ **\u{1F389} \u{9879}\u{76EE}\u{6587}\u{6863}\u{5DF2}\u{5B8C}\u{6574}\u{4FDD}\u{5B58}\u{FF0C}\u{53EF}\u{4EE5}\u{5F00}\u{59CB}\u{5F00}\u{53D1}\u{4E86}\u{FF01}**`;
4331
+ }
4332
+ }
4333
+ };
4334
+ let view_requirements_status_currentRequirements = {
4335
+ project_overview: [],
4336
+ functional_requirements: [],
4337
+ technical_requirements: [],
4338
+ design_requirements: [],
4339
+ deployment_requirements: [],
4340
+ ai_constraints: [],
4341
+ clarification_history: [],
4342
+ architecture_designs: [],
4343
+ last_updated: null,
4344
+ project_id: null
4345
+ };
4346
+ const viewRequirementsStatusTool = {
4347
+ name: "view_requirements_status",
4348
+ description: "\u67E5\u770B\u5F53\u524D\u9700\u6C42\u6587\u6863\u7684\u8BE6\u7EC6\u72B6\u6001\u548C\u5185\u5BB9",
4349
+ parameters: esm.object({}),
4350
+ execute: async ()=>{
4351
+ var _currentRequirements_last_updated;
4352
+ const storage = new RequirementStorage();
4353
+ const totalClarifications = view_requirements_status_currentRequirements.clarification_history.length;
4354
+ const totalRequirements = [
4355
+ "project_overview",
4356
+ "functional_requirements",
4357
+ "technical_requirements",
4358
+ "design_requirements",
4359
+ "deployment_requirements",
4360
+ "ai_constraints"
4361
+ ].reduce((sum, key)=>sum + view_requirements_status_currentRequirements[key].length, 0);
4362
+ const totalArchitectures = view_requirements_status_currentRequirements.architecture_designs.length;
4363
+ let statusReport = `# \u{1F4CB} \u{5F53}\u{524D}\u{9700}\u{6C42}\u{6587}\u{6863}\u{72B6}\u{6001}
4364
+
4365
+ ## \u{1F4CA} \u{603B}\u{4F53}\u{7EDF}\u{8BA1}
4366
+ - **\u{6700}\u{540E}\u{66F4}\u{65B0}**: ${(null == (_currentRequirements_last_updated = view_requirements_status_currentRequirements.last_updated) ? void 0 : _currentRequirements_last_updated.slice(0, 19)) || "\u672A\u66F4\u65B0"}
4367
+ - **\u{9700}\u{6C42}\u{6F84}\u{6E05}\u{6B21}\u{6570}**: ${totalClarifications}
4368
+ - **\u{9700}\u{6C42}\u{6761}\u{76EE}\u{603B}\u{6570}**: ${totalRequirements}
4369
+ - **\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{65B9}\u{6848}**: ${totalArchitectures}
4370
+ - **\u{5B58}\u{50A8}\u{4F4D}\u{7F6E}**: \`${storage.storageDir}\`
4371
+
4372
+ ## \u{1F4DD} \u{9700}\u{6C42}\u{5206}\u{7C7B}\u{8BE6}\u{60C5}
4373
+
4374
+ ### \u{1F3AF} \u{9879}\u{76EE}\u{6982}\u{8FF0} (${view_requirements_status_currentRequirements.project_overview.length} \u{6761})
4375
+ `;
4376
+ view_requirements_status_currentRequirements.project_overview.forEach((item, i)=>{
4377
+ const content = item.content;
4378
+ statusReport += `${i + 1}. ${content.slice(0, 100)}${content.length > 100 ? "..." : ""}\n`;
4379
+ });
4380
+ statusReport += `
4381
+ ### \u{2699}\u{FE0F} \u{529F}\u{80FD}\u{9700}\u{6C42} (${view_requirements_status_currentRequirements.functional_requirements.length} \u{6761})
4382
+ `;
4383
+ view_requirements_status_currentRequirements.functional_requirements.forEach((item, i)=>{
4384
+ const content = item.content;
4385
+ statusReport += `${i + 1}. ${content.slice(0, 100)}${content.length > 100 ? "..." : ""}\n`;
4386
+ });
4387
+ statusReport += `
4388
+ ### \u{1F527} \u{6280}\u{672F}\u{9700}\u{6C42} (${view_requirements_status_currentRequirements.technical_requirements.length} \u{6761})
4389
+ `;
4390
+ view_requirements_status_currentRequirements.technical_requirements.forEach((item, i)=>{
4391
+ const content = item.content;
4392
+ statusReport += `${i + 1}. ${content.slice(0, 100)}${content.length > 100 ? "..." : ""}\n`;
4393
+ });
4394
+ statusReport += `
4395
+ ### \u{1F3D7}\u{FE0F} \u{67B6}\u{6784}\u{8BBE}\u{8BA1} (${view_requirements_status_currentRequirements.architecture_designs.length} \u{4E2A})
4396
+ `;
4397
+ view_requirements_status_currentRequirements.architecture_designs.forEach((design, i)=>{
4398
+ var _design_timestamp;
4399
+ const focus = design.design_focus || "\u672A\u6307\u5B9A";
4400
+ const timestamp = (null == (_design_timestamp = design.timestamp) ? void 0 : _design_timestamp.slice(0, 19)) || "\u672A\u77E5\u65F6\u95F4";
4401
+ statusReport += `${i + 1}. \u{8BBE}\u{8BA1}\u{91CD}\u{70B9}: ${focus} (\u{751F}\u{6210}\u{65F6}\u{95F4}: ${timestamp})\n`;
4402
+ });
4403
+ statusReport += `
4404
+ ## \u{1F4C1} \u{6587}\u{4EF6}\u{4FE1}\u{606F}
4405
+ - **\u{9700}\u{6C42}\u{6587}\u{6863}**: \`${storage.requirementsFile}\`
4406
+ - **\u{5386}\u{53F2}\u{8BB0}\u{5F55}**: \`${storage.historyFile}\`
4407
+ - **\u{6587}\u{4EF6}\u{5927}\u{5C0F}**: \u{9700}\u{6C42}\u{6587}\u{6863} ${fs_0.existsSync(storage.requirementsFile) ? fs_0.statSync(storage.requirementsFile).size : 0} \u{5B57}\u{8282}
4408
+
4409
+ ## \u{1F3AF} \u{4E0B}\u{4E00}\u{6B65}\u{5EFA}\u{8BAE}
4410
+ `;
4411
+ if (totalRequirements < 3) statusReport += "- \uD83D\uDCDD \u9700\u6C42\u4FE1\u606F\u8F83\u5C11\uFF0C\u5EFA\u8BAE\u7EE7\u7EED\u4F7F\u7528 requirement_clarifier \u6F84\u6E05\u66F4\u591A\u9700\u6C42\n";
4412
+ if (0 === totalArchitectures) statusReport += "- \uD83C\uDFD7\uFE0F \u5C1A\u672A\u751F\u6210\u67B6\u6784\u8BBE\u8BA1\uFF0C\u5EFA\u8BAE\u4F7F\u7528 architecture_designer \u751F\u6210\u6280\u672F\u65B9\u6848\n";
4413
+ if (totalRequirements >= 3 && totalArchitectures >= 1) {
4414
+ statusReport += "- \uD83D\uDCC4 \u9700\u6C42\u548C\u67B6\u6784\u5DF2\u57FA\u672C\u5B8C\u5584\uFF0C\u53EF\u4EE5\u4F7F\u7528 export_final_document \u5BFC\u51FA\u5B8C\u6574\u6587\u6863\n";
4415
+ statusReport += "- \uD83D\uDE80 \u53EF\u4EE5\u5F00\u59CB\u9879\u76EE\u5F00\u53D1\u4E86\uFF01\n";
4416
+ }
4417
+ statusReport += `
4418
+ ## \u{1F6E0}\u{FE0F} \u{53EF}\u{7528}\u{5DE5}\u{5177}
4419
+ - \`requirement_clarifier\`: \u{6F84}\u{6E05}\u{548C}\u{5206}\u{6790}\u{9700}\u{6C42}
4420
+ - \`requirement_manager\`: \u{7BA1}\u{7406}\u{548C}\u{4FDD}\u{5B58}\u{9700}\u{6C42}
4421
+ - \`architecture_designer\`: \u{751F}\u{6210}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}
4422
+ - \`export_final_document\`: \u{5BFC}\u{51FA}\u{5B8C}\u{6574}\u{6587}\u{6863}
4423
+ - \`view_requirements_status\`: \u{67E5}\u{770B}\u{5F53}\u{524D}\u{72B6}\u{6001}\u{FF08}\u{5F53}\u{524D}\u{5DE5}\u{5177}\u{FF09}
4424
+ `;
4425
+ return statusReport;
4426
+ }
4427
+ };
4428
+ const mcp = new FastMCP({
4429
+ name: SERVICE_CONFIG.name,
4430
+ version: SERVICE_CONFIG.version,
4431
+ ping: {
4432
+ enabled: true,
4433
+ intervalMs: 10000,
4434
+ logLevel: "info"
4435
+ }
4436
+ });
4437
+ mcp.addTool(requirementClarifierTool);
4438
+ mcp.addTool(requirementManagerTool);
4439
+ mcp.addTool(architectureDesignerTool);
4440
+ mcp.addTool(exportFinalDocumentTool);
4441
+ mcp.addTool(viewRequirementsStatusTool);
4442
+ console.log("\uD83D\uDE80 \u542F\u52A8AI\u9700\u6C42\u5206\u6790\u548C\u8BBE\u8BA1\u52A9\u624B");
4443
+ mcp.start({
4444
+ transportType: "stdio"
4445
+ });