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