@clipform/mcp-server 3.3.2 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/README.template.md +5 -7
- package/dist/api-client.d.ts +78 -0
- package/dist/api-client.js +22 -0
- package/dist/api-client.js.map +1 -0
- package/dist/auth-context.d.ts +10 -1
- package/dist/auth-context.js +5 -1
- package/dist/{chunk-7I765YTD.js → chunk-FC7D3235.js} +4364 -4941
- package/dist/chunk-FC7D3235.js.map +1 -0
- package/dist/{chunk-65MTGAFF.js → chunk-JRASOR5T.js} +102 -103
- package/dist/chunk-JRASOR5T.js.map +1 -0
- package/dist/chunk-KWR2WJQI.js +15361 -0
- package/dist/chunk-KWR2WJQI.js.map +1 -0
- package/dist/chunk-S6RYUVDM.js +102 -0
- package/dist/chunk-S6RYUVDM.js.map +1 -0
- package/dist/{chunk-KHRY3A3M.js → chunk-V5AI2TSQ.js} +21 -9
- package/dist/chunk-V5AI2TSQ.js.map +1 -0
- package/dist/{chunk-A5CFGL27.js → chunk-VPF6MLKM.js} +5 -1
- package/dist/chunk-VPF6MLKM.js.map +1 -0
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/instrument.d.ts +20 -3
- package/dist/instrument.js +45 -39
- package/dist/instrument.js.map +1 -1
- package/dist/prompts.js +4 -3
- package/dist/resources.js +4 -3
- package/dist/server.js +6 -5
- package/package.json +8 -4
- package/dist/chunk-5J5N7KTW.js +0 -4859
- package/dist/chunk-5J5N7KTW.js.map +0 -1
- package/dist/chunk-65MTGAFF.js.map +0 -1
- package/dist/chunk-7I765YTD.js.map +0 -1
- package/dist/chunk-A5CFGL27.js.map +0 -1
- package/dist/chunk-KHRY3A3M.js.map +0 -1
package/dist/chunk-5J5N7KTW.js
DELETED
|
@@ -1,4859 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FULL_CAPS,
|
|
3
|
-
WORKFLOW_TYPES,
|
|
4
|
-
getDiscoveryParams,
|
|
5
|
-
getSessionContextWithAuth
|
|
6
|
-
} from "./chunk-65MTGAFF.js";
|
|
7
|
-
import {
|
|
8
|
-
__export
|
|
9
|
-
} from "./chunk-G3PMV62Z.js";
|
|
10
|
-
|
|
11
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
12
|
-
var external_exports = {};
|
|
13
|
-
__export(external_exports, {
|
|
14
|
-
BRAND: () => BRAND,
|
|
15
|
-
DIRTY: () => DIRTY,
|
|
16
|
-
EMPTY_PATH: () => EMPTY_PATH,
|
|
17
|
-
INVALID: () => INVALID,
|
|
18
|
-
NEVER: () => NEVER,
|
|
19
|
-
OK: () => OK,
|
|
20
|
-
ParseStatus: () => ParseStatus,
|
|
21
|
-
Schema: () => ZodType,
|
|
22
|
-
ZodAny: () => ZodAny,
|
|
23
|
-
ZodArray: () => ZodArray,
|
|
24
|
-
ZodBigInt: () => ZodBigInt,
|
|
25
|
-
ZodBoolean: () => ZodBoolean,
|
|
26
|
-
ZodBranded: () => ZodBranded,
|
|
27
|
-
ZodCatch: () => ZodCatch,
|
|
28
|
-
ZodDate: () => ZodDate,
|
|
29
|
-
ZodDefault: () => ZodDefault,
|
|
30
|
-
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
31
|
-
ZodEffects: () => ZodEffects,
|
|
32
|
-
ZodEnum: () => ZodEnum,
|
|
33
|
-
ZodError: () => ZodError,
|
|
34
|
-
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
35
|
-
ZodFunction: () => ZodFunction,
|
|
36
|
-
ZodIntersection: () => ZodIntersection,
|
|
37
|
-
ZodIssueCode: () => ZodIssueCode,
|
|
38
|
-
ZodLazy: () => ZodLazy,
|
|
39
|
-
ZodLiteral: () => ZodLiteral,
|
|
40
|
-
ZodMap: () => ZodMap,
|
|
41
|
-
ZodNaN: () => ZodNaN,
|
|
42
|
-
ZodNativeEnum: () => ZodNativeEnum,
|
|
43
|
-
ZodNever: () => ZodNever,
|
|
44
|
-
ZodNull: () => ZodNull,
|
|
45
|
-
ZodNullable: () => ZodNullable,
|
|
46
|
-
ZodNumber: () => ZodNumber,
|
|
47
|
-
ZodObject: () => ZodObject,
|
|
48
|
-
ZodOptional: () => ZodOptional,
|
|
49
|
-
ZodParsedType: () => ZodParsedType,
|
|
50
|
-
ZodPipeline: () => ZodPipeline,
|
|
51
|
-
ZodPromise: () => ZodPromise,
|
|
52
|
-
ZodReadonly: () => ZodReadonly,
|
|
53
|
-
ZodRecord: () => ZodRecord,
|
|
54
|
-
ZodSchema: () => ZodType,
|
|
55
|
-
ZodSet: () => ZodSet,
|
|
56
|
-
ZodString: () => ZodString,
|
|
57
|
-
ZodSymbol: () => ZodSymbol,
|
|
58
|
-
ZodTransformer: () => ZodEffects,
|
|
59
|
-
ZodTuple: () => ZodTuple,
|
|
60
|
-
ZodType: () => ZodType,
|
|
61
|
-
ZodUndefined: () => ZodUndefined,
|
|
62
|
-
ZodUnion: () => ZodUnion,
|
|
63
|
-
ZodUnknown: () => ZodUnknown,
|
|
64
|
-
ZodVoid: () => ZodVoid,
|
|
65
|
-
addIssueToContext: () => addIssueToContext,
|
|
66
|
-
any: () => anyType,
|
|
67
|
-
array: () => arrayType,
|
|
68
|
-
bigint: () => bigIntType,
|
|
69
|
-
boolean: () => booleanType,
|
|
70
|
-
coerce: () => coerce,
|
|
71
|
-
custom: () => custom,
|
|
72
|
-
date: () => dateType,
|
|
73
|
-
datetimeRegex: () => datetimeRegex,
|
|
74
|
-
defaultErrorMap: () => en_default,
|
|
75
|
-
discriminatedUnion: () => discriminatedUnionType,
|
|
76
|
-
effect: () => effectsType,
|
|
77
|
-
enum: () => enumType,
|
|
78
|
-
function: () => functionType,
|
|
79
|
-
getErrorMap: () => getErrorMap,
|
|
80
|
-
getParsedType: () => getParsedType,
|
|
81
|
-
instanceof: () => instanceOfType,
|
|
82
|
-
intersection: () => intersectionType,
|
|
83
|
-
isAborted: () => isAborted,
|
|
84
|
-
isAsync: () => isAsync,
|
|
85
|
-
isDirty: () => isDirty,
|
|
86
|
-
isValid: () => isValid,
|
|
87
|
-
late: () => late,
|
|
88
|
-
lazy: () => lazyType,
|
|
89
|
-
literal: () => literalType,
|
|
90
|
-
makeIssue: () => makeIssue,
|
|
91
|
-
map: () => mapType,
|
|
92
|
-
nan: () => nanType,
|
|
93
|
-
nativeEnum: () => nativeEnumType,
|
|
94
|
-
never: () => neverType,
|
|
95
|
-
null: () => nullType,
|
|
96
|
-
nullable: () => nullableType,
|
|
97
|
-
number: () => numberType,
|
|
98
|
-
object: () => objectType,
|
|
99
|
-
objectUtil: () => objectUtil,
|
|
100
|
-
oboolean: () => oboolean,
|
|
101
|
-
onumber: () => onumber,
|
|
102
|
-
optional: () => optionalType,
|
|
103
|
-
ostring: () => ostring,
|
|
104
|
-
pipeline: () => pipelineType,
|
|
105
|
-
preprocess: () => preprocessType,
|
|
106
|
-
promise: () => promiseType,
|
|
107
|
-
quotelessJson: () => quotelessJson,
|
|
108
|
-
record: () => recordType,
|
|
109
|
-
set: () => setType,
|
|
110
|
-
setErrorMap: () => setErrorMap,
|
|
111
|
-
strictObject: () => strictObjectType,
|
|
112
|
-
string: () => stringType,
|
|
113
|
-
symbol: () => symbolType,
|
|
114
|
-
transformer: () => effectsType,
|
|
115
|
-
tuple: () => tupleType,
|
|
116
|
-
undefined: () => undefinedType,
|
|
117
|
-
union: () => unionType,
|
|
118
|
-
unknown: () => unknownType,
|
|
119
|
-
util: () => util,
|
|
120
|
-
void: () => voidType
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
124
|
-
var util;
|
|
125
|
-
(function(util2) {
|
|
126
|
-
util2.assertEqual = (_) => {
|
|
127
|
-
};
|
|
128
|
-
function assertIs(_arg) {
|
|
129
|
-
}
|
|
130
|
-
util2.assertIs = assertIs;
|
|
131
|
-
function assertNever(_x) {
|
|
132
|
-
throw new Error();
|
|
133
|
-
}
|
|
134
|
-
util2.assertNever = assertNever;
|
|
135
|
-
util2.arrayToEnum = (items) => {
|
|
136
|
-
const obj = {};
|
|
137
|
-
for (const item of items) {
|
|
138
|
-
obj[item] = item;
|
|
139
|
-
}
|
|
140
|
-
return obj;
|
|
141
|
-
};
|
|
142
|
-
util2.getValidEnumValues = (obj) => {
|
|
143
|
-
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
144
|
-
const filtered = {};
|
|
145
|
-
for (const k of validKeys) {
|
|
146
|
-
filtered[k] = obj[k];
|
|
147
|
-
}
|
|
148
|
-
return util2.objectValues(filtered);
|
|
149
|
-
};
|
|
150
|
-
util2.objectValues = (obj) => {
|
|
151
|
-
return util2.objectKeys(obj).map(function(e) {
|
|
152
|
-
return obj[e];
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
156
|
-
const keys = [];
|
|
157
|
-
for (const key in object) {
|
|
158
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
159
|
-
keys.push(key);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return keys;
|
|
163
|
-
};
|
|
164
|
-
util2.find = (arr, checker) => {
|
|
165
|
-
for (const item of arr) {
|
|
166
|
-
if (checker(item))
|
|
167
|
-
return item;
|
|
168
|
-
}
|
|
169
|
-
return void 0;
|
|
170
|
-
};
|
|
171
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
172
|
-
function joinValues(array, separator = " | ") {
|
|
173
|
-
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
174
|
-
}
|
|
175
|
-
util2.joinValues = joinValues;
|
|
176
|
-
util2.jsonStringifyReplacer = (_, value) => {
|
|
177
|
-
if (typeof value === "bigint") {
|
|
178
|
-
return value.toString();
|
|
179
|
-
}
|
|
180
|
-
return value;
|
|
181
|
-
};
|
|
182
|
-
})(util || (util = {}));
|
|
183
|
-
var objectUtil;
|
|
184
|
-
(function(objectUtil2) {
|
|
185
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
186
|
-
return {
|
|
187
|
-
...first,
|
|
188
|
-
...second
|
|
189
|
-
// second overwrites first
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
})(objectUtil || (objectUtil = {}));
|
|
193
|
-
var ZodParsedType = util.arrayToEnum([
|
|
194
|
-
"string",
|
|
195
|
-
"nan",
|
|
196
|
-
"number",
|
|
197
|
-
"integer",
|
|
198
|
-
"float",
|
|
199
|
-
"boolean",
|
|
200
|
-
"date",
|
|
201
|
-
"bigint",
|
|
202
|
-
"symbol",
|
|
203
|
-
"function",
|
|
204
|
-
"undefined",
|
|
205
|
-
"null",
|
|
206
|
-
"array",
|
|
207
|
-
"object",
|
|
208
|
-
"unknown",
|
|
209
|
-
"promise",
|
|
210
|
-
"void",
|
|
211
|
-
"never",
|
|
212
|
-
"map",
|
|
213
|
-
"set"
|
|
214
|
-
]);
|
|
215
|
-
var getParsedType = (data) => {
|
|
216
|
-
const t = typeof data;
|
|
217
|
-
switch (t) {
|
|
218
|
-
case "undefined":
|
|
219
|
-
return ZodParsedType.undefined;
|
|
220
|
-
case "string":
|
|
221
|
-
return ZodParsedType.string;
|
|
222
|
-
case "number":
|
|
223
|
-
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
224
|
-
case "boolean":
|
|
225
|
-
return ZodParsedType.boolean;
|
|
226
|
-
case "function":
|
|
227
|
-
return ZodParsedType.function;
|
|
228
|
-
case "bigint":
|
|
229
|
-
return ZodParsedType.bigint;
|
|
230
|
-
case "symbol":
|
|
231
|
-
return ZodParsedType.symbol;
|
|
232
|
-
case "object":
|
|
233
|
-
if (Array.isArray(data)) {
|
|
234
|
-
return ZodParsedType.array;
|
|
235
|
-
}
|
|
236
|
-
if (data === null) {
|
|
237
|
-
return ZodParsedType.null;
|
|
238
|
-
}
|
|
239
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
240
|
-
return ZodParsedType.promise;
|
|
241
|
-
}
|
|
242
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
243
|
-
return ZodParsedType.map;
|
|
244
|
-
}
|
|
245
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
246
|
-
return ZodParsedType.set;
|
|
247
|
-
}
|
|
248
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
249
|
-
return ZodParsedType.date;
|
|
250
|
-
}
|
|
251
|
-
return ZodParsedType.object;
|
|
252
|
-
default:
|
|
253
|
-
return ZodParsedType.unknown;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
258
|
-
var ZodIssueCode = util.arrayToEnum([
|
|
259
|
-
"invalid_type",
|
|
260
|
-
"invalid_literal",
|
|
261
|
-
"custom",
|
|
262
|
-
"invalid_union",
|
|
263
|
-
"invalid_union_discriminator",
|
|
264
|
-
"invalid_enum_value",
|
|
265
|
-
"unrecognized_keys",
|
|
266
|
-
"invalid_arguments",
|
|
267
|
-
"invalid_return_type",
|
|
268
|
-
"invalid_date",
|
|
269
|
-
"invalid_string",
|
|
270
|
-
"too_small",
|
|
271
|
-
"too_big",
|
|
272
|
-
"invalid_intersection_types",
|
|
273
|
-
"not_multiple_of",
|
|
274
|
-
"not_finite"
|
|
275
|
-
]);
|
|
276
|
-
var quotelessJson = (obj) => {
|
|
277
|
-
const json = JSON.stringify(obj, null, 2);
|
|
278
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
279
|
-
};
|
|
280
|
-
var ZodError = class _ZodError extends Error {
|
|
281
|
-
get errors() {
|
|
282
|
-
return this.issues;
|
|
283
|
-
}
|
|
284
|
-
constructor(issues) {
|
|
285
|
-
super();
|
|
286
|
-
this.issues = [];
|
|
287
|
-
this.addIssue = (sub) => {
|
|
288
|
-
this.issues = [...this.issues, sub];
|
|
289
|
-
};
|
|
290
|
-
this.addIssues = (subs = []) => {
|
|
291
|
-
this.issues = [...this.issues, ...subs];
|
|
292
|
-
};
|
|
293
|
-
const actualProto = new.target.prototype;
|
|
294
|
-
if (Object.setPrototypeOf) {
|
|
295
|
-
Object.setPrototypeOf(this, actualProto);
|
|
296
|
-
} else {
|
|
297
|
-
this.__proto__ = actualProto;
|
|
298
|
-
}
|
|
299
|
-
this.name = "ZodError";
|
|
300
|
-
this.issues = issues;
|
|
301
|
-
}
|
|
302
|
-
format(_mapper) {
|
|
303
|
-
const mapper = _mapper || function(issue) {
|
|
304
|
-
return issue.message;
|
|
305
|
-
};
|
|
306
|
-
const fieldErrors = { _errors: [] };
|
|
307
|
-
const processError = (error) => {
|
|
308
|
-
for (const issue of error.issues) {
|
|
309
|
-
if (issue.code === "invalid_union") {
|
|
310
|
-
issue.unionErrors.map(processError);
|
|
311
|
-
} else if (issue.code === "invalid_return_type") {
|
|
312
|
-
processError(issue.returnTypeError);
|
|
313
|
-
} else if (issue.code === "invalid_arguments") {
|
|
314
|
-
processError(issue.argumentsError);
|
|
315
|
-
} else if (issue.path.length === 0) {
|
|
316
|
-
fieldErrors._errors.push(mapper(issue));
|
|
317
|
-
} else {
|
|
318
|
-
let curr = fieldErrors;
|
|
319
|
-
let i = 0;
|
|
320
|
-
while (i < issue.path.length) {
|
|
321
|
-
const el = issue.path[i];
|
|
322
|
-
const terminal = i === issue.path.length - 1;
|
|
323
|
-
if (!terminal) {
|
|
324
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
325
|
-
} else {
|
|
326
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
327
|
-
curr[el]._errors.push(mapper(issue));
|
|
328
|
-
}
|
|
329
|
-
curr = curr[el];
|
|
330
|
-
i++;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
processError(this);
|
|
336
|
-
return fieldErrors;
|
|
337
|
-
}
|
|
338
|
-
static assert(value) {
|
|
339
|
-
if (!(value instanceof _ZodError)) {
|
|
340
|
-
throw new Error(`Not a ZodError: ${value}`);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
toString() {
|
|
344
|
-
return this.message;
|
|
345
|
-
}
|
|
346
|
-
get message() {
|
|
347
|
-
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
348
|
-
}
|
|
349
|
-
get isEmpty() {
|
|
350
|
-
return this.issues.length === 0;
|
|
351
|
-
}
|
|
352
|
-
flatten(mapper = (issue) => issue.message) {
|
|
353
|
-
const fieldErrors = {};
|
|
354
|
-
const formErrors = [];
|
|
355
|
-
for (const sub of this.issues) {
|
|
356
|
-
if (sub.path.length > 0) {
|
|
357
|
-
const firstEl = sub.path[0];
|
|
358
|
-
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
359
|
-
fieldErrors[firstEl].push(mapper(sub));
|
|
360
|
-
} else {
|
|
361
|
-
formErrors.push(mapper(sub));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
return { formErrors, fieldErrors };
|
|
365
|
-
}
|
|
366
|
-
get formErrors() {
|
|
367
|
-
return this.flatten();
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
ZodError.create = (issues) => {
|
|
371
|
-
const error = new ZodError(issues);
|
|
372
|
-
return error;
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
376
|
-
var errorMap = (issue, _ctx) => {
|
|
377
|
-
let message;
|
|
378
|
-
switch (issue.code) {
|
|
379
|
-
case ZodIssueCode.invalid_type:
|
|
380
|
-
if (issue.received === ZodParsedType.undefined) {
|
|
381
|
-
message = "Required";
|
|
382
|
-
} else {
|
|
383
|
-
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
384
|
-
}
|
|
385
|
-
break;
|
|
386
|
-
case ZodIssueCode.invalid_literal:
|
|
387
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
388
|
-
break;
|
|
389
|
-
case ZodIssueCode.unrecognized_keys:
|
|
390
|
-
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
391
|
-
break;
|
|
392
|
-
case ZodIssueCode.invalid_union:
|
|
393
|
-
message = `Invalid input`;
|
|
394
|
-
break;
|
|
395
|
-
case ZodIssueCode.invalid_union_discriminator:
|
|
396
|
-
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
397
|
-
break;
|
|
398
|
-
case ZodIssueCode.invalid_enum_value:
|
|
399
|
-
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
400
|
-
break;
|
|
401
|
-
case ZodIssueCode.invalid_arguments:
|
|
402
|
-
message = `Invalid function arguments`;
|
|
403
|
-
break;
|
|
404
|
-
case ZodIssueCode.invalid_return_type:
|
|
405
|
-
message = `Invalid function return type`;
|
|
406
|
-
break;
|
|
407
|
-
case ZodIssueCode.invalid_date:
|
|
408
|
-
message = `Invalid date`;
|
|
409
|
-
break;
|
|
410
|
-
case ZodIssueCode.invalid_string:
|
|
411
|
-
if (typeof issue.validation === "object") {
|
|
412
|
-
if ("includes" in issue.validation) {
|
|
413
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
414
|
-
if (typeof issue.validation.position === "number") {
|
|
415
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
416
|
-
}
|
|
417
|
-
} else if ("startsWith" in issue.validation) {
|
|
418
|
-
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
419
|
-
} else if ("endsWith" in issue.validation) {
|
|
420
|
-
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
421
|
-
} else {
|
|
422
|
-
util.assertNever(issue.validation);
|
|
423
|
-
}
|
|
424
|
-
} else if (issue.validation !== "regex") {
|
|
425
|
-
message = `Invalid ${issue.validation}`;
|
|
426
|
-
} else {
|
|
427
|
-
message = "Invalid";
|
|
428
|
-
}
|
|
429
|
-
break;
|
|
430
|
-
case ZodIssueCode.too_small:
|
|
431
|
-
if (issue.type === "array")
|
|
432
|
-
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
433
|
-
else if (issue.type === "string")
|
|
434
|
-
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
435
|
-
else if (issue.type === "number")
|
|
436
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
437
|
-
else if (issue.type === "bigint")
|
|
438
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
439
|
-
else if (issue.type === "date")
|
|
440
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
441
|
-
else
|
|
442
|
-
message = "Invalid input";
|
|
443
|
-
break;
|
|
444
|
-
case ZodIssueCode.too_big:
|
|
445
|
-
if (issue.type === "array")
|
|
446
|
-
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
447
|
-
else if (issue.type === "string")
|
|
448
|
-
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
449
|
-
else if (issue.type === "number")
|
|
450
|
-
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
451
|
-
else if (issue.type === "bigint")
|
|
452
|
-
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
453
|
-
else if (issue.type === "date")
|
|
454
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
455
|
-
else
|
|
456
|
-
message = "Invalid input";
|
|
457
|
-
break;
|
|
458
|
-
case ZodIssueCode.custom:
|
|
459
|
-
message = `Invalid input`;
|
|
460
|
-
break;
|
|
461
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
462
|
-
message = `Intersection results could not be merged`;
|
|
463
|
-
break;
|
|
464
|
-
case ZodIssueCode.not_multiple_of:
|
|
465
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
466
|
-
break;
|
|
467
|
-
case ZodIssueCode.not_finite:
|
|
468
|
-
message = "Number must be finite";
|
|
469
|
-
break;
|
|
470
|
-
default:
|
|
471
|
-
message = _ctx.defaultError;
|
|
472
|
-
util.assertNever(issue);
|
|
473
|
-
}
|
|
474
|
-
return { message };
|
|
475
|
-
};
|
|
476
|
-
var en_default = errorMap;
|
|
477
|
-
|
|
478
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
479
|
-
var overrideErrorMap = en_default;
|
|
480
|
-
function setErrorMap(map) {
|
|
481
|
-
overrideErrorMap = map;
|
|
482
|
-
}
|
|
483
|
-
function getErrorMap() {
|
|
484
|
-
return overrideErrorMap;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
488
|
-
var makeIssue = (params) => {
|
|
489
|
-
const { data, path, errorMaps, issueData } = params;
|
|
490
|
-
const fullPath = [...path, ...issueData.path || []];
|
|
491
|
-
const fullIssue = {
|
|
492
|
-
...issueData,
|
|
493
|
-
path: fullPath
|
|
494
|
-
};
|
|
495
|
-
if (issueData.message !== void 0) {
|
|
496
|
-
return {
|
|
497
|
-
...issueData,
|
|
498
|
-
path: fullPath,
|
|
499
|
-
message: issueData.message
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
let errorMessage = "";
|
|
503
|
-
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
504
|
-
for (const map of maps) {
|
|
505
|
-
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
...issueData,
|
|
509
|
-
path: fullPath,
|
|
510
|
-
message: errorMessage
|
|
511
|
-
};
|
|
512
|
-
};
|
|
513
|
-
var EMPTY_PATH = [];
|
|
514
|
-
function addIssueToContext(ctx, issueData) {
|
|
515
|
-
const overrideMap = getErrorMap();
|
|
516
|
-
const issue = makeIssue({
|
|
517
|
-
issueData,
|
|
518
|
-
data: ctx.data,
|
|
519
|
-
path: ctx.path,
|
|
520
|
-
errorMaps: [
|
|
521
|
-
ctx.common.contextualErrorMap,
|
|
522
|
-
// contextual error map is first priority
|
|
523
|
-
ctx.schemaErrorMap,
|
|
524
|
-
// then schema-bound map if available
|
|
525
|
-
overrideMap,
|
|
526
|
-
// then global override map
|
|
527
|
-
overrideMap === en_default ? void 0 : en_default
|
|
528
|
-
// then global default map
|
|
529
|
-
].filter((x) => !!x)
|
|
530
|
-
});
|
|
531
|
-
ctx.common.issues.push(issue);
|
|
532
|
-
}
|
|
533
|
-
var ParseStatus = class _ParseStatus {
|
|
534
|
-
constructor() {
|
|
535
|
-
this.value = "valid";
|
|
536
|
-
}
|
|
537
|
-
dirty() {
|
|
538
|
-
if (this.value === "valid")
|
|
539
|
-
this.value = "dirty";
|
|
540
|
-
}
|
|
541
|
-
abort() {
|
|
542
|
-
if (this.value !== "aborted")
|
|
543
|
-
this.value = "aborted";
|
|
544
|
-
}
|
|
545
|
-
static mergeArray(status, results) {
|
|
546
|
-
const arrayValue = [];
|
|
547
|
-
for (const s of results) {
|
|
548
|
-
if (s.status === "aborted")
|
|
549
|
-
return INVALID;
|
|
550
|
-
if (s.status === "dirty")
|
|
551
|
-
status.dirty();
|
|
552
|
-
arrayValue.push(s.value);
|
|
553
|
-
}
|
|
554
|
-
return { status: status.value, value: arrayValue };
|
|
555
|
-
}
|
|
556
|
-
static async mergeObjectAsync(status, pairs) {
|
|
557
|
-
const syncPairs = [];
|
|
558
|
-
for (const pair of pairs) {
|
|
559
|
-
const key = await pair.key;
|
|
560
|
-
const value = await pair.value;
|
|
561
|
-
syncPairs.push({
|
|
562
|
-
key,
|
|
563
|
-
value
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
567
|
-
}
|
|
568
|
-
static mergeObjectSync(status, pairs) {
|
|
569
|
-
const finalObject = {};
|
|
570
|
-
for (const pair of pairs) {
|
|
571
|
-
const { key, value } = pair;
|
|
572
|
-
if (key.status === "aborted")
|
|
573
|
-
return INVALID;
|
|
574
|
-
if (value.status === "aborted")
|
|
575
|
-
return INVALID;
|
|
576
|
-
if (key.status === "dirty")
|
|
577
|
-
status.dirty();
|
|
578
|
-
if (value.status === "dirty")
|
|
579
|
-
status.dirty();
|
|
580
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
581
|
-
finalObject[key.value] = value.value;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
return { status: status.value, value: finalObject };
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
var INVALID = Object.freeze({
|
|
588
|
-
status: "aborted"
|
|
589
|
-
});
|
|
590
|
-
var DIRTY = (value) => ({ status: "dirty", value });
|
|
591
|
-
var OK = (value) => ({ status: "valid", value });
|
|
592
|
-
var isAborted = (x) => x.status === "aborted";
|
|
593
|
-
var isDirty = (x) => x.status === "dirty";
|
|
594
|
-
var isValid = (x) => x.status === "valid";
|
|
595
|
-
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
596
|
-
|
|
597
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
598
|
-
var errorUtil;
|
|
599
|
-
(function(errorUtil2) {
|
|
600
|
-
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
601
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
602
|
-
})(errorUtil || (errorUtil = {}));
|
|
603
|
-
|
|
604
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
605
|
-
var ParseInputLazyPath = class {
|
|
606
|
-
constructor(parent, value, path, key) {
|
|
607
|
-
this._cachedPath = [];
|
|
608
|
-
this.parent = parent;
|
|
609
|
-
this.data = value;
|
|
610
|
-
this._path = path;
|
|
611
|
-
this._key = key;
|
|
612
|
-
}
|
|
613
|
-
get path() {
|
|
614
|
-
if (!this._cachedPath.length) {
|
|
615
|
-
if (Array.isArray(this._key)) {
|
|
616
|
-
this._cachedPath.push(...this._path, ...this._key);
|
|
617
|
-
} else {
|
|
618
|
-
this._cachedPath.push(...this._path, this._key);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
return this._cachedPath;
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
var handleResult = (ctx, result) => {
|
|
625
|
-
if (isValid(result)) {
|
|
626
|
-
return { success: true, data: result.value };
|
|
627
|
-
} else {
|
|
628
|
-
if (!ctx.common.issues.length) {
|
|
629
|
-
throw new Error("Validation failed but no issues detected.");
|
|
630
|
-
}
|
|
631
|
-
return {
|
|
632
|
-
success: false,
|
|
633
|
-
get error() {
|
|
634
|
-
if (this._error)
|
|
635
|
-
return this._error;
|
|
636
|
-
const error = new ZodError(ctx.common.issues);
|
|
637
|
-
this._error = error;
|
|
638
|
-
return this._error;
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
};
|
|
643
|
-
function processCreateParams(params) {
|
|
644
|
-
if (!params)
|
|
645
|
-
return {};
|
|
646
|
-
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
647
|
-
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
648
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
649
|
-
}
|
|
650
|
-
if (errorMap2)
|
|
651
|
-
return { errorMap: errorMap2, description };
|
|
652
|
-
const customMap = (iss, ctx) => {
|
|
653
|
-
const { message } = params;
|
|
654
|
-
if (iss.code === "invalid_enum_value") {
|
|
655
|
-
return { message: message ?? ctx.defaultError };
|
|
656
|
-
}
|
|
657
|
-
if (typeof ctx.data === "undefined") {
|
|
658
|
-
return { message: message ?? required_error ?? ctx.defaultError };
|
|
659
|
-
}
|
|
660
|
-
if (iss.code !== "invalid_type")
|
|
661
|
-
return { message: ctx.defaultError };
|
|
662
|
-
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
663
|
-
};
|
|
664
|
-
return { errorMap: customMap, description };
|
|
665
|
-
}
|
|
666
|
-
var ZodType = class {
|
|
667
|
-
get description() {
|
|
668
|
-
return this._def.description;
|
|
669
|
-
}
|
|
670
|
-
_getType(input) {
|
|
671
|
-
return getParsedType(input.data);
|
|
672
|
-
}
|
|
673
|
-
_getOrReturnCtx(input, ctx) {
|
|
674
|
-
return ctx || {
|
|
675
|
-
common: input.parent.common,
|
|
676
|
-
data: input.data,
|
|
677
|
-
parsedType: getParsedType(input.data),
|
|
678
|
-
schemaErrorMap: this._def.errorMap,
|
|
679
|
-
path: input.path,
|
|
680
|
-
parent: input.parent
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
_processInputParams(input) {
|
|
684
|
-
return {
|
|
685
|
-
status: new ParseStatus(),
|
|
686
|
-
ctx: {
|
|
687
|
-
common: input.parent.common,
|
|
688
|
-
data: input.data,
|
|
689
|
-
parsedType: getParsedType(input.data),
|
|
690
|
-
schemaErrorMap: this._def.errorMap,
|
|
691
|
-
path: input.path,
|
|
692
|
-
parent: input.parent
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
_parseSync(input) {
|
|
697
|
-
const result = this._parse(input);
|
|
698
|
-
if (isAsync(result)) {
|
|
699
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
700
|
-
}
|
|
701
|
-
return result;
|
|
702
|
-
}
|
|
703
|
-
_parseAsync(input) {
|
|
704
|
-
const result = this._parse(input);
|
|
705
|
-
return Promise.resolve(result);
|
|
706
|
-
}
|
|
707
|
-
parse(data, params) {
|
|
708
|
-
const result = this.safeParse(data, params);
|
|
709
|
-
if (result.success)
|
|
710
|
-
return result.data;
|
|
711
|
-
throw result.error;
|
|
712
|
-
}
|
|
713
|
-
safeParse(data, params) {
|
|
714
|
-
const ctx = {
|
|
715
|
-
common: {
|
|
716
|
-
issues: [],
|
|
717
|
-
async: params?.async ?? false,
|
|
718
|
-
contextualErrorMap: params?.errorMap
|
|
719
|
-
},
|
|
720
|
-
path: params?.path || [],
|
|
721
|
-
schemaErrorMap: this._def.errorMap,
|
|
722
|
-
parent: null,
|
|
723
|
-
data,
|
|
724
|
-
parsedType: getParsedType(data)
|
|
725
|
-
};
|
|
726
|
-
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
727
|
-
return handleResult(ctx, result);
|
|
728
|
-
}
|
|
729
|
-
"~validate"(data) {
|
|
730
|
-
const ctx = {
|
|
731
|
-
common: {
|
|
732
|
-
issues: [],
|
|
733
|
-
async: !!this["~standard"].async
|
|
734
|
-
},
|
|
735
|
-
path: [],
|
|
736
|
-
schemaErrorMap: this._def.errorMap,
|
|
737
|
-
parent: null,
|
|
738
|
-
data,
|
|
739
|
-
parsedType: getParsedType(data)
|
|
740
|
-
};
|
|
741
|
-
if (!this["~standard"].async) {
|
|
742
|
-
try {
|
|
743
|
-
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
744
|
-
return isValid(result) ? {
|
|
745
|
-
value: result.value
|
|
746
|
-
} : {
|
|
747
|
-
issues: ctx.common.issues
|
|
748
|
-
};
|
|
749
|
-
} catch (err) {
|
|
750
|
-
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
751
|
-
this["~standard"].async = true;
|
|
752
|
-
}
|
|
753
|
-
ctx.common = {
|
|
754
|
-
issues: [],
|
|
755
|
-
async: true
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
760
|
-
value: result.value
|
|
761
|
-
} : {
|
|
762
|
-
issues: ctx.common.issues
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
async parseAsync(data, params) {
|
|
766
|
-
const result = await this.safeParseAsync(data, params);
|
|
767
|
-
if (result.success)
|
|
768
|
-
return result.data;
|
|
769
|
-
throw result.error;
|
|
770
|
-
}
|
|
771
|
-
async safeParseAsync(data, params) {
|
|
772
|
-
const ctx = {
|
|
773
|
-
common: {
|
|
774
|
-
issues: [],
|
|
775
|
-
contextualErrorMap: params?.errorMap,
|
|
776
|
-
async: true
|
|
777
|
-
},
|
|
778
|
-
path: params?.path || [],
|
|
779
|
-
schemaErrorMap: this._def.errorMap,
|
|
780
|
-
parent: null,
|
|
781
|
-
data,
|
|
782
|
-
parsedType: getParsedType(data)
|
|
783
|
-
};
|
|
784
|
-
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
785
|
-
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
786
|
-
return handleResult(ctx, result);
|
|
787
|
-
}
|
|
788
|
-
refine(check, message) {
|
|
789
|
-
const getIssueProperties = (val) => {
|
|
790
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
791
|
-
return { message };
|
|
792
|
-
} else if (typeof message === "function") {
|
|
793
|
-
return message(val);
|
|
794
|
-
} else {
|
|
795
|
-
return message;
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
return this._refinement((val, ctx) => {
|
|
799
|
-
const result = check(val);
|
|
800
|
-
const setError = () => ctx.addIssue({
|
|
801
|
-
code: ZodIssueCode.custom,
|
|
802
|
-
...getIssueProperties(val)
|
|
803
|
-
});
|
|
804
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
805
|
-
return result.then((data) => {
|
|
806
|
-
if (!data) {
|
|
807
|
-
setError();
|
|
808
|
-
return false;
|
|
809
|
-
} else {
|
|
810
|
-
return true;
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
if (!result) {
|
|
815
|
-
setError();
|
|
816
|
-
return false;
|
|
817
|
-
} else {
|
|
818
|
-
return true;
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
refinement(check, refinementData) {
|
|
823
|
-
return this._refinement((val, ctx) => {
|
|
824
|
-
if (!check(val)) {
|
|
825
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
826
|
-
return false;
|
|
827
|
-
} else {
|
|
828
|
-
return true;
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
_refinement(refinement) {
|
|
833
|
-
return new ZodEffects({
|
|
834
|
-
schema: this,
|
|
835
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
836
|
-
effect: { type: "refinement", refinement }
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
superRefine(refinement) {
|
|
840
|
-
return this._refinement(refinement);
|
|
841
|
-
}
|
|
842
|
-
constructor(def) {
|
|
843
|
-
this.spa = this.safeParseAsync;
|
|
844
|
-
this._def = def;
|
|
845
|
-
this.parse = this.parse.bind(this);
|
|
846
|
-
this.safeParse = this.safeParse.bind(this);
|
|
847
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
848
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
849
|
-
this.spa = this.spa.bind(this);
|
|
850
|
-
this.refine = this.refine.bind(this);
|
|
851
|
-
this.refinement = this.refinement.bind(this);
|
|
852
|
-
this.superRefine = this.superRefine.bind(this);
|
|
853
|
-
this.optional = this.optional.bind(this);
|
|
854
|
-
this.nullable = this.nullable.bind(this);
|
|
855
|
-
this.nullish = this.nullish.bind(this);
|
|
856
|
-
this.array = this.array.bind(this);
|
|
857
|
-
this.promise = this.promise.bind(this);
|
|
858
|
-
this.or = this.or.bind(this);
|
|
859
|
-
this.and = this.and.bind(this);
|
|
860
|
-
this.transform = this.transform.bind(this);
|
|
861
|
-
this.brand = this.brand.bind(this);
|
|
862
|
-
this.default = this.default.bind(this);
|
|
863
|
-
this.catch = this.catch.bind(this);
|
|
864
|
-
this.describe = this.describe.bind(this);
|
|
865
|
-
this.pipe = this.pipe.bind(this);
|
|
866
|
-
this.readonly = this.readonly.bind(this);
|
|
867
|
-
this.isNullable = this.isNullable.bind(this);
|
|
868
|
-
this.isOptional = this.isOptional.bind(this);
|
|
869
|
-
this["~standard"] = {
|
|
870
|
-
version: 1,
|
|
871
|
-
vendor: "zod",
|
|
872
|
-
validate: (data) => this["~validate"](data)
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
optional() {
|
|
876
|
-
return ZodOptional.create(this, this._def);
|
|
877
|
-
}
|
|
878
|
-
nullable() {
|
|
879
|
-
return ZodNullable.create(this, this._def);
|
|
880
|
-
}
|
|
881
|
-
nullish() {
|
|
882
|
-
return this.nullable().optional();
|
|
883
|
-
}
|
|
884
|
-
array() {
|
|
885
|
-
return ZodArray.create(this);
|
|
886
|
-
}
|
|
887
|
-
promise() {
|
|
888
|
-
return ZodPromise.create(this, this._def);
|
|
889
|
-
}
|
|
890
|
-
or(option) {
|
|
891
|
-
return ZodUnion.create([this, option], this._def);
|
|
892
|
-
}
|
|
893
|
-
and(incoming) {
|
|
894
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
895
|
-
}
|
|
896
|
-
transform(transform) {
|
|
897
|
-
return new ZodEffects({
|
|
898
|
-
...processCreateParams(this._def),
|
|
899
|
-
schema: this,
|
|
900
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
901
|
-
effect: { type: "transform", transform }
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
default(def) {
|
|
905
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
906
|
-
return new ZodDefault({
|
|
907
|
-
...processCreateParams(this._def),
|
|
908
|
-
innerType: this,
|
|
909
|
-
defaultValue: defaultValueFunc,
|
|
910
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
brand() {
|
|
914
|
-
return new ZodBranded({
|
|
915
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
916
|
-
type: this,
|
|
917
|
-
...processCreateParams(this._def)
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
catch(def) {
|
|
921
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
922
|
-
return new ZodCatch({
|
|
923
|
-
...processCreateParams(this._def),
|
|
924
|
-
innerType: this,
|
|
925
|
-
catchValue: catchValueFunc,
|
|
926
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
describe(description) {
|
|
930
|
-
const This = this.constructor;
|
|
931
|
-
return new This({
|
|
932
|
-
...this._def,
|
|
933
|
-
description
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
pipe(target) {
|
|
937
|
-
return ZodPipeline.create(this, target);
|
|
938
|
-
}
|
|
939
|
-
readonly() {
|
|
940
|
-
return ZodReadonly.create(this);
|
|
941
|
-
}
|
|
942
|
-
isOptional() {
|
|
943
|
-
return this.safeParse(void 0).success;
|
|
944
|
-
}
|
|
945
|
-
isNullable() {
|
|
946
|
-
return this.safeParse(null).success;
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
950
|
-
var cuid2Regex = /^[0-9a-z]+$/;
|
|
951
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
952
|
-
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
953
|
-
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
954
|
-
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
955
|
-
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
956
|
-
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
957
|
-
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
958
|
-
var emojiRegex;
|
|
959
|
-
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
960
|
-
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
961
|
-
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
962
|
-
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
963
|
-
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
964
|
-
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
965
|
-
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
966
|
-
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
967
|
-
function timeRegexSource(args) {
|
|
968
|
-
let secondsRegexSource = `[0-5]\\d`;
|
|
969
|
-
if (args.precision) {
|
|
970
|
-
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
971
|
-
} else if (args.precision == null) {
|
|
972
|
-
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
973
|
-
}
|
|
974
|
-
const secondsQuantifier = args.precision ? "+" : "?";
|
|
975
|
-
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
976
|
-
}
|
|
977
|
-
function timeRegex(args) {
|
|
978
|
-
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
979
|
-
}
|
|
980
|
-
function datetimeRegex(args) {
|
|
981
|
-
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
982
|
-
const opts = [];
|
|
983
|
-
opts.push(args.local ? `Z?` : `Z`);
|
|
984
|
-
if (args.offset)
|
|
985
|
-
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
986
|
-
regex = `${regex}(${opts.join("|")})`;
|
|
987
|
-
return new RegExp(`^${regex}$`);
|
|
988
|
-
}
|
|
989
|
-
function isValidIP(ip, version) {
|
|
990
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
991
|
-
return true;
|
|
992
|
-
}
|
|
993
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
994
|
-
return true;
|
|
995
|
-
}
|
|
996
|
-
return false;
|
|
997
|
-
}
|
|
998
|
-
function isValidJWT(jwt, alg) {
|
|
999
|
-
if (!jwtRegex.test(jwt))
|
|
1000
|
-
return false;
|
|
1001
|
-
try {
|
|
1002
|
-
const [header] = jwt.split(".");
|
|
1003
|
-
if (!header)
|
|
1004
|
-
return false;
|
|
1005
|
-
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1006
|
-
const decoded = JSON.parse(atob(base64));
|
|
1007
|
-
if (typeof decoded !== "object" || decoded === null)
|
|
1008
|
-
return false;
|
|
1009
|
-
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1010
|
-
return false;
|
|
1011
|
-
if (!decoded.alg)
|
|
1012
|
-
return false;
|
|
1013
|
-
if (alg && decoded.alg !== alg)
|
|
1014
|
-
return false;
|
|
1015
|
-
return true;
|
|
1016
|
-
} catch {
|
|
1017
|
-
return false;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
function isValidCidr(ip, version) {
|
|
1021
|
-
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1022
|
-
return true;
|
|
1023
|
-
}
|
|
1024
|
-
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1025
|
-
return true;
|
|
1026
|
-
}
|
|
1027
|
-
return false;
|
|
1028
|
-
}
|
|
1029
|
-
var ZodString = class _ZodString extends ZodType {
|
|
1030
|
-
_parse(input) {
|
|
1031
|
-
if (this._def.coerce) {
|
|
1032
|
-
input.data = String(input.data);
|
|
1033
|
-
}
|
|
1034
|
-
const parsedType = this._getType(input);
|
|
1035
|
-
if (parsedType !== ZodParsedType.string) {
|
|
1036
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
1037
|
-
addIssueToContext(ctx2, {
|
|
1038
|
-
code: ZodIssueCode.invalid_type,
|
|
1039
|
-
expected: ZodParsedType.string,
|
|
1040
|
-
received: ctx2.parsedType
|
|
1041
|
-
});
|
|
1042
|
-
return INVALID;
|
|
1043
|
-
}
|
|
1044
|
-
const status = new ParseStatus();
|
|
1045
|
-
let ctx = void 0;
|
|
1046
|
-
for (const check of this._def.checks) {
|
|
1047
|
-
if (check.kind === "min") {
|
|
1048
|
-
if (input.data.length < check.value) {
|
|
1049
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1050
|
-
addIssueToContext(ctx, {
|
|
1051
|
-
code: ZodIssueCode.too_small,
|
|
1052
|
-
minimum: check.value,
|
|
1053
|
-
type: "string",
|
|
1054
|
-
inclusive: true,
|
|
1055
|
-
exact: false,
|
|
1056
|
-
message: check.message
|
|
1057
|
-
});
|
|
1058
|
-
status.dirty();
|
|
1059
|
-
}
|
|
1060
|
-
} else if (check.kind === "max") {
|
|
1061
|
-
if (input.data.length > check.value) {
|
|
1062
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1063
|
-
addIssueToContext(ctx, {
|
|
1064
|
-
code: ZodIssueCode.too_big,
|
|
1065
|
-
maximum: check.value,
|
|
1066
|
-
type: "string",
|
|
1067
|
-
inclusive: true,
|
|
1068
|
-
exact: false,
|
|
1069
|
-
message: check.message
|
|
1070
|
-
});
|
|
1071
|
-
status.dirty();
|
|
1072
|
-
}
|
|
1073
|
-
} else if (check.kind === "length") {
|
|
1074
|
-
const tooBig = input.data.length > check.value;
|
|
1075
|
-
const tooSmall = input.data.length < check.value;
|
|
1076
|
-
if (tooBig || tooSmall) {
|
|
1077
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1078
|
-
if (tooBig) {
|
|
1079
|
-
addIssueToContext(ctx, {
|
|
1080
|
-
code: ZodIssueCode.too_big,
|
|
1081
|
-
maximum: check.value,
|
|
1082
|
-
type: "string",
|
|
1083
|
-
inclusive: true,
|
|
1084
|
-
exact: true,
|
|
1085
|
-
message: check.message
|
|
1086
|
-
});
|
|
1087
|
-
} else if (tooSmall) {
|
|
1088
|
-
addIssueToContext(ctx, {
|
|
1089
|
-
code: ZodIssueCode.too_small,
|
|
1090
|
-
minimum: check.value,
|
|
1091
|
-
type: "string",
|
|
1092
|
-
inclusive: true,
|
|
1093
|
-
exact: true,
|
|
1094
|
-
message: check.message
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
status.dirty();
|
|
1098
|
-
}
|
|
1099
|
-
} else if (check.kind === "email") {
|
|
1100
|
-
if (!emailRegex.test(input.data)) {
|
|
1101
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1102
|
-
addIssueToContext(ctx, {
|
|
1103
|
-
validation: "email",
|
|
1104
|
-
code: ZodIssueCode.invalid_string,
|
|
1105
|
-
message: check.message
|
|
1106
|
-
});
|
|
1107
|
-
status.dirty();
|
|
1108
|
-
}
|
|
1109
|
-
} else if (check.kind === "emoji") {
|
|
1110
|
-
if (!emojiRegex) {
|
|
1111
|
-
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1112
|
-
}
|
|
1113
|
-
if (!emojiRegex.test(input.data)) {
|
|
1114
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1115
|
-
addIssueToContext(ctx, {
|
|
1116
|
-
validation: "emoji",
|
|
1117
|
-
code: ZodIssueCode.invalid_string,
|
|
1118
|
-
message: check.message
|
|
1119
|
-
});
|
|
1120
|
-
status.dirty();
|
|
1121
|
-
}
|
|
1122
|
-
} else if (check.kind === "uuid") {
|
|
1123
|
-
if (!uuidRegex.test(input.data)) {
|
|
1124
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1125
|
-
addIssueToContext(ctx, {
|
|
1126
|
-
validation: "uuid",
|
|
1127
|
-
code: ZodIssueCode.invalid_string,
|
|
1128
|
-
message: check.message
|
|
1129
|
-
});
|
|
1130
|
-
status.dirty();
|
|
1131
|
-
}
|
|
1132
|
-
} else if (check.kind === "nanoid") {
|
|
1133
|
-
if (!nanoidRegex.test(input.data)) {
|
|
1134
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1135
|
-
addIssueToContext(ctx, {
|
|
1136
|
-
validation: "nanoid",
|
|
1137
|
-
code: ZodIssueCode.invalid_string,
|
|
1138
|
-
message: check.message
|
|
1139
|
-
});
|
|
1140
|
-
status.dirty();
|
|
1141
|
-
}
|
|
1142
|
-
} else if (check.kind === "cuid") {
|
|
1143
|
-
if (!cuidRegex.test(input.data)) {
|
|
1144
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1145
|
-
addIssueToContext(ctx, {
|
|
1146
|
-
validation: "cuid",
|
|
1147
|
-
code: ZodIssueCode.invalid_string,
|
|
1148
|
-
message: check.message
|
|
1149
|
-
});
|
|
1150
|
-
status.dirty();
|
|
1151
|
-
}
|
|
1152
|
-
} else if (check.kind === "cuid2") {
|
|
1153
|
-
if (!cuid2Regex.test(input.data)) {
|
|
1154
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1155
|
-
addIssueToContext(ctx, {
|
|
1156
|
-
validation: "cuid2",
|
|
1157
|
-
code: ZodIssueCode.invalid_string,
|
|
1158
|
-
message: check.message
|
|
1159
|
-
});
|
|
1160
|
-
status.dirty();
|
|
1161
|
-
}
|
|
1162
|
-
} else if (check.kind === "ulid") {
|
|
1163
|
-
if (!ulidRegex.test(input.data)) {
|
|
1164
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1165
|
-
addIssueToContext(ctx, {
|
|
1166
|
-
validation: "ulid",
|
|
1167
|
-
code: ZodIssueCode.invalid_string,
|
|
1168
|
-
message: check.message
|
|
1169
|
-
});
|
|
1170
|
-
status.dirty();
|
|
1171
|
-
}
|
|
1172
|
-
} else if (check.kind === "url") {
|
|
1173
|
-
try {
|
|
1174
|
-
new URL(input.data);
|
|
1175
|
-
} catch {
|
|
1176
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1177
|
-
addIssueToContext(ctx, {
|
|
1178
|
-
validation: "url",
|
|
1179
|
-
code: ZodIssueCode.invalid_string,
|
|
1180
|
-
message: check.message
|
|
1181
|
-
});
|
|
1182
|
-
status.dirty();
|
|
1183
|
-
}
|
|
1184
|
-
} else if (check.kind === "regex") {
|
|
1185
|
-
check.regex.lastIndex = 0;
|
|
1186
|
-
const testResult = check.regex.test(input.data);
|
|
1187
|
-
if (!testResult) {
|
|
1188
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1189
|
-
addIssueToContext(ctx, {
|
|
1190
|
-
validation: "regex",
|
|
1191
|
-
code: ZodIssueCode.invalid_string,
|
|
1192
|
-
message: check.message
|
|
1193
|
-
});
|
|
1194
|
-
status.dirty();
|
|
1195
|
-
}
|
|
1196
|
-
} else if (check.kind === "trim") {
|
|
1197
|
-
input.data = input.data.trim();
|
|
1198
|
-
} else if (check.kind === "includes") {
|
|
1199
|
-
if (!input.data.includes(check.value, check.position)) {
|
|
1200
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1201
|
-
addIssueToContext(ctx, {
|
|
1202
|
-
code: ZodIssueCode.invalid_string,
|
|
1203
|
-
validation: { includes: check.value, position: check.position },
|
|
1204
|
-
message: check.message
|
|
1205
|
-
});
|
|
1206
|
-
status.dirty();
|
|
1207
|
-
}
|
|
1208
|
-
} else if (check.kind === "toLowerCase") {
|
|
1209
|
-
input.data = input.data.toLowerCase();
|
|
1210
|
-
} else if (check.kind === "toUpperCase") {
|
|
1211
|
-
input.data = input.data.toUpperCase();
|
|
1212
|
-
} else if (check.kind === "startsWith") {
|
|
1213
|
-
if (!input.data.startsWith(check.value)) {
|
|
1214
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1215
|
-
addIssueToContext(ctx, {
|
|
1216
|
-
code: ZodIssueCode.invalid_string,
|
|
1217
|
-
validation: { startsWith: check.value },
|
|
1218
|
-
message: check.message
|
|
1219
|
-
});
|
|
1220
|
-
status.dirty();
|
|
1221
|
-
}
|
|
1222
|
-
} else if (check.kind === "endsWith") {
|
|
1223
|
-
if (!input.data.endsWith(check.value)) {
|
|
1224
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1225
|
-
addIssueToContext(ctx, {
|
|
1226
|
-
code: ZodIssueCode.invalid_string,
|
|
1227
|
-
validation: { endsWith: check.value },
|
|
1228
|
-
message: check.message
|
|
1229
|
-
});
|
|
1230
|
-
status.dirty();
|
|
1231
|
-
}
|
|
1232
|
-
} else if (check.kind === "datetime") {
|
|
1233
|
-
const regex = datetimeRegex(check);
|
|
1234
|
-
if (!regex.test(input.data)) {
|
|
1235
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1236
|
-
addIssueToContext(ctx, {
|
|
1237
|
-
code: ZodIssueCode.invalid_string,
|
|
1238
|
-
validation: "datetime",
|
|
1239
|
-
message: check.message
|
|
1240
|
-
});
|
|
1241
|
-
status.dirty();
|
|
1242
|
-
}
|
|
1243
|
-
} else if (check.kind === "date") {
|
|
1244
|
-
const regex = dateRegex;
|
|
1245
|
-
if (!regex.test(input.data)) {
|
|
1246
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1247
|
-
addIssueToContext(ctx, {
|
|
1248
|
-
code: ZodIssueCode.invalid_string,
|
|
1249
|
-
validation: "date",
|
|
1250
|
-
message: check.message
|
|
1251
|
-
});
|
|
1252
|
-
status.dirty();
|
|
1253
|
-
}
|
|
1254
|
-
} else if (check.kind === "time") {
|
|
1255
|
-
const regex = timeRegex(check);
|
|
1256
|
-
if (!regex.test(input.data)) {
|
|
1257
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1258
|
-
addIssueToContext(ctx, {
|
|
1259
|
-
code: ZodIssueCode.invalid_string,
|
|
1260
|
-
validation: "time",
|
|
1261
|
-
message: check.message
|
|
1262
|
-
});
|
|
1263
|
-
status.dirty();
|
|
1264
|
-
}
|
|
1265
|
-
} else if (check.kind === "duration") {
|
|
1266
|
-
if (!durationRegex.test(input.data)) {
|
|
1267
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1268
|
-
addIssueToContext(ctx, {
|
|
1269
|
-
validation: "duration",
|
|
1270
|
-
code: ZodIssueCode.invalid_string,
|
|
1271
|
-
message: check.message
|
|
1272
|
-
});
|
|
1273
|
-
status.dirty();
|
|
1274
|
-
}
|
|
1275
|
-
} else if (check.kind === "ip") {
|
|
1276
|
-
if (!isValidIP(input.data, check.version)) {
|
|
1277
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1278
|
-
addIssueToContext(ctx, {
|
|
1279
|
-
validation: "ip",
|
|
1280
|
-
code: ZodIssueCode.invalid_string,
|
|
1281
|
-
message: check.message
|
|
1282
|
-
});
|
|
1283
|
-
status.dirty();
|
|
1284
|
-
}
|
|
1285
|
-
} else if (check.kind === "jwt") {
|
|
1286
|
-
if (!isValidJWT(input.data, check.alg)) {
|
|
1287
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1288
|
-
addIssueToContext(ctx, {
|
|
1289
|
-
validation: "jwt",
|
|
1290
|
-
code: ZodIssueCode.invalid_string,
|
|
1291
|
-
message: check.message
|
|
1292
|
-
});
|
|
1293
|
-
status.dirty();
|
|
1294
|
-
}
|
|
1295
|
-
} else if (check.kind === "cidr") {
|
|
1296
|
-
if (!isValidCidr(input.data, check.version)) {
|
|
1297
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1298
|
-
addIssueToContext(ctx, {
|
|
1299
|
-
validation: "cidr",
|
|
1300
|
-
code: ZodIssueCode.invalid_string,
|
|
1301
|
-
message: check.message
|
|
1302
|
-
});
|
|
1303
|
-
status.dirty();
|
|
1304
|
-
}
|
|
1305
|
-
} else if (check.kind === "base64") {
|
|
1306
|
-
if (!base64Regex.test(input.data)) {
|
|
1307
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1308
|
-
addIssueToContext(ctx, {
|
|
1309
|
-
validation: "base64",
|
|
1310
|
-
code: ZodIssueCode.invalid_string,
|
|
1311
|
-
message: check.message
|
|
1312
|
-
});
|
|
1313
|
-
status.dirty();
|
|
1314
|
-
}
|
|
1315
|
-
} else if (check.kind === "base64url") {
|
|
1316
|
-
if (!base64urlRegex.test(input.data)) {
|
|
1317
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1318
|
-
addIssueToContext(ctx, {
|
|
1319
|
-
validation: "base64url",
|
|
1320
|
-
code: ZodIssueCode.invalid_string,
|
|
1321
|
-
message: check.message
|
|
1322
|
-
});
|
|
1323
|
-
status.dirty();
|
|
1324
|
-
}
|
|
1325
|
-
} else {
|
|
1326
|
-
util.assertNever(check);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
return { status: status.value, value: input.data };
|
|
1330
|
-
}
|
|
1331
|
-
_regex(regex, validation, message) {
|
|
1332
|
-
return this.refinement((data) => regex.test(data), {
|
|
1333
|
-
validation,
|
|
1334
|
-
code: ZodIssueCode.invalid_string,
|
|
1335
|
-
...errorUtil.errToObj(message)
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
_addCheck(check) {
|
|
1339
|
-
return new _ZodString({
|
|
1340
|
-
...this._def,
|
|
1341
|
-
checks: [...this._def.checks, check]
|
|
1342
|
-
});
|
|
1343
|
-
}
|
|
1344
|
-
email(message) {
|
|
1345
|
-
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1346
|
-
}
|
|
1347
|
-
url(message) {
|
|
1348
|
-
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1349
|
-
}
|
|
1350
|
-
emoji(message) {
|
|
1351
|
-
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1352
|
-
}
|
|
1353
|
-
uuid(message) {
|
|
1354
|
-
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1355
|
-
}
|
|
1356
|
-
nanoid(message) {
|
|
1357
|
-
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1358
|
-
}
|
|
1359
|
-
cuid(message) {
|
|
1360
|
-
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1361
|
-
}
|
|
1362
|
-
cuid2(message) {
|
|
1363
|
-
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1364
|
-
}
|
|
1365
|
-
ulid(message) {
|
|
1366
|
-
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1367
|
-
}
|
|
1368
|
-
base64(message) {
|
|
1369
|
-
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1370
|
-
}
|
|
1371
|
-
base64url(message) {
|
|
1372
|
-
return this._addCheck({
|
|
1373
|
-
kind: "base64url",
|
|
1374
|
-
...errorUtil.errToObj(message)
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
jwt(options) {
|
|
1378
|
-
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1379
|
-
}
|
|
1380
|
-
ip(options) {
|
|
1381
|
-
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1382
|
-
}
|
|
1383
|
-
cidr(options) {
|
|
1384
|
-
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1385
|
-
}
|
|
1386
|
-
datetime(options) {
|
|
1387
|
-
if (typeof options === "string") {
|
|
1388
|
-
return this._addCheck({
|
|
1389
|
-
kind: "datetime",
|
|
1390
|
-
precision: null,
|
|
1391
|
-
offset: false,
|
|
1392
|
-
local: false,
|
|
1393
|
-
message: options
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
return this._addCheck({
|
|
1397
|
-
kind: "datetime",
|
|
1398
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1399
|
-
offset: options?.offset ?? false,
|
|
1400
|
-
local: options?.local ?? false,
|
|
1401
|
-
...errorUtil.errToObj(options?.message)
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
date(message) {
|
|
1405
|
-
return this._addCheck({ kind: "date", message });
|
|
1406
|
-
}
|
|
1407
|
-
time(options) {
|
|
1408
|
-
if (typeof options === "string") {
|
|
1409
|
-
return this._addCheck({
|
|
1410
|
-
kind: "time",
|
|
1411
|
-
precision: null,
|
|
1412
|
-
message: options
|
|
1413
|
-
});
|
|
1414
|
-
}
|
|
1415
|
-
return this._addCheck({
|
|
1416
|
-
kind: "time",
|
|
1417
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1418
|
-
...errorUtil.errToObj(options?.message)
|
|
1419
|
-
});
|
|
1420
|
-
}
|
|
1421
|
-
duration(message) {
|
|
1422
|
-
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1423
|
-
}
|
|
1424
|
-
regex(regex, message) {
|
|
1425
|
-
return this._addCheck({
|
|
1426
|
-
kind: "regex",
|
|
1427
|
-
regex,
|
|
1428
|
-
...errorUtil.errToObj(message)
|
|
1429
|
-
});
|
|
1430
|
-
}
|
|
1431
|
-
includes(value, options) {
|
|
1432
|
-
return this._addCheck({
|
|
1433
|
-
kind: "includes",
|
|
1434
|
-
value,
|
|
1435
|
-
position: options?.position,
|
|
1436
|
-
...errorUtil.errToObj(options?.message)
|
|
1437
|
-
});
|
|
1438
|
-
}
|
|
1439
|
-
startsWith(value, message) {
|
|
1440
|
-
return this._addCheck({
|
|
1441
|
-
kind: "startsWith",
|
|
1442
|
-
value,
|
|
1443
|
-
...errorUtil.errToObj(message)
|
|
1444
|
-
});
|
|
1445
|
-
}
|
|
1446
|
-
endsWith(value, message) {
|
|
1447
|
-
return this._addCheck({
|
|
1448
|
-
kind: "endsWith",
|
|
1449
|
-
value,
|
|
1450
|
-
...errorUtil.errToObj(message)
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
min(minLength, message) {
|
|
1454
|
-
return this._addCheck({
|
|
1455
|
-
kind: "min",
|
|
1456
|
-
value: minLength,
|
|
1457
|
-
...errorUtil.errToObj(message)
|
|
1458
|
-
});
|
|
1459
|
-
}
|
|
1460
|
-
max(maxLength, message) {
|
|
1461
|
-
return this._addCheck({
|
|
1462
|
-
kind: "max",
|
|
1463
|
-
value: maxLength,
|
|
1464
|
-
...errorUtil.errToObj(message)
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
length(len, message) {
|
|
1468
|
-
return this._addCheck({
|
|
1469
|
-
kind: "length",
|
|
1470
|
-
value: len,
|
|
1471
|
-
...errorUtil.errToObj(message)
|
|
1472
|
-
});
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* Equivalent to `.min(1)`
|
|
1476
|
-
*/
|
|
1477
|
-
nonempty(message) {
|
|
1478
|
-
return this.min(1, errorUtil.errToObj(message));
|
|
1479
|
-
}
|
|
1480
|
-
trim() {
|
|
1481
|
-
return new _ZodString({
|
|
1482
|
-
...this._def,
|
|
1483
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
toLowerCase() {
|
|
1487
|
-
return new _ZodString({
|
|
1488
|
-
...this._def,
|
|
1489
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
toUpperCase() {
|
|
1493
|
-
return new _ZodString({
|
|
1494
|
-
...this._def,
|
|
1495
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
get isDatetime() {
|
|
1499
|
-
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1500
|
-
}
|
|
1501
|
-
get isDate() {
|
|
1502
|
-
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1503
|
-
}
|
|
1504
|
-
get isTime() {
|
|
1505
|
-
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1506
|
-
}
|
|
1507
|
-
get isDuration() {
|
|
1508
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1509
|
-
}
|
|
1510
|
-
get isEmail() {
|
|
1511
|
-
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1512
|
-
}
|
|
1513
|
-
get isURL() {
|
|
1514
|
-
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1515
|
-
}
|
|
1516
|
-
get isEmoji() {
|
|
1517
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1518
|
-
}
|
|
1519
|
-
get isUUID() {
|
|
1520
|
-
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1521
|
-
}
|
|
1522
|
-
get isNANOID() {
|
|
1523
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1524
|
-
}
|
|
1525
|
-
get isCUID() {
|
|
1526
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1527
|
-
}
|
|
1528
|
-
get isCUID2() {
|
|
1529
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1530
|
-
}
|
|
1531
|
-
get isULID() {
|
|
1532
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1533
|
-
}
|
|
1534
|
-
get isIP() {
|
|
1535
|
-
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1536
|
-
}
|
|
1537
|
-
get isCIDR() {
|
|
1538
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1539
|
-
}
|
|
1540
|
-
get isBase64() {
|
|
1541
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1542
|
-
}
|
|
1543
|
-
get isBase64url() {
|
|
1544
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1545
|
-
}
|
|
1546
|
-
get minLength() {
|
|
1547
|
-
let min = null;
|
|
1548
|
-
for (const ch of this._def.checks) {
|
|
1549
|
-
if (ch.kind === "min") {
|
|
1550
|
-
if (min === null || ch.value > min)
|
|
1551
|
-
min = ch.value;
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
return min;
|
|
1555
|
-
}
|
|
1556
|
-
get maxLength() {
|
|
1557
|
-
let max = null;
|
|
1558
|
-
for (const ch of this._def.checks) {
|
|
1559
|
-
if (ch.kind === "max") {
|
|
1560
|
-
if (max === null || ch.value < max)
|
|
1561
|
-
max = ch.value;
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
return max;
|
|
1565
|
-
}
|
|
1566
|
-
};
|
|
1567
|
-
ZodString.create = (params) => {
|
|
1568
|
-
return new ZodString({
|
|
1569
|
-
checks: [],
|
|
1570
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1571
|
-
coerce: params?.coerce ?? false,
|
|
1572
|
-
...processCreateParams(params)
|
|
1573
|
-
});
|
|
1574
|
-
};
|
|
1575
|
-
function floatSafeRemainder(val, step) {
|
|
1576
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1577
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1578
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1579
|
-
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1580
|
-
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1581
|
-
return valInt % stepInt / 10 ** decCount;
|
|
1582
|
-
}
|
|
1583
|
-
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1584
|
-
constructor() {
|
|
1585
|
-
super(...arguments);
|
|
1586
|
-
this.min = this.gte;
|
|
1587
|
-
this.max = this.lte;
|
|
1588
|
-
this.step = this.multipleOf;
|
|
1589
|
-
}
|
|
1590
|
-
_parse(input) {
|
|
1591
|
-
if (this._def.coerce) {
|
|
1592
|
-
input.data = Number(input.data);
|
|
1593
|
-
}
|
|
1594
|
-
const parsedType = this._getType(input);
|
|
1595
|
-
if (parsedType !== ZodParsedType.number) {
|
|
1596
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
1597
|
-
addIssueToContext(ctx2, {
|
|
1598
|
-
code: ZodIssueCode.invalid_type,
|
|
1599
|
-
expected: ZodParsedType.number,
|
|
1600
|
-
received: ctx2.parsedType
|
|
1601
|
-
});
|
|
1602
|
-
return INVALID;
|
|
1603
|
-
}
|
|
1604
|
-
let ctx = void 0;
|
|
1605
|
-
const status = new ParseStatus();
|
|
1606
|
-
for (const check of this._def.checks) {
|
|
1607
|
-
if (check.kind === "int") {
|
|
1608
|
-
if (!util.isInteger(input.data)) {
|
|
1609
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1610
|
-
addIssueToContext(ctx, {
|
|
1611
|
-
code: ZodIssueCode.invalid_type,
|
|
1612
|
-
expected: "integer",
|
|
1613
|
-
received: "float",
|
|
1614
|
-
message: check.message
|
|
1615
|
-
});
|
|
1616
|
-
status.dirty();
|
|
1617
|
-
}
|
|
1618
|
-
} else if (check.kind === "min") {
|
|
1619
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1620
|
-
if (tooSmall) {
|
|
1621
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1622
|
-
addIssueToContext(ctx, {
|
|
1623
|
-
code: ZodIssueCode.too_small,
|
|
1624
|
-
minimum: check.value,
|
|
1625
|
-
type: "number",
|
|
1626
|
-
inclusive: check.inclusive,
|
|
1627
|
-
exact: false,
|
|
1628
|
-
message: check.message
|
|
1629
|
-
});
|
|
1630
|
-
status.dirty();
|
|
1631
|
-
}
|
|
1632
|
-
} else if (check.kind === "max") {
|
|
1633
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1634
|
-
if (tooBig) {
|
|
1635
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1636
|
-
addIssueToContext(ctx, {
|
|
1637
|
-
code: ZodIssueCode.too_big,
|
|
1638
|
-
maximum: check.value,
|
|
1639
|
-
type: "number",
|
|
1640
|
-
inclusive: check.inclusive,
|
|
1641
|
-
exact: false,
|
|
1642
|
-
message: check.message
|
|
1643
|
-
});
|
|
1644
|
-
status.dirty();
|
|
1645
|
-
}
|
|
1646
|
-
} else if (check.kind === "multipleOf") {
|
|
1647
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1648
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1649
|
-
addIssueToContext(ctx, {
|
|
1650
|
-
code: ZodIssueCode.not_multiple_of,
|
|
1651
|
-
multipleOf: check.value,
|
|
1652
|
-
message: check.message
|
|
1653
|
-
});
|
|
1654
|
-
status.dirty();
|
|
1655
|
-
}
|
|
1656
|
-
} else if (check.kind === "finite") {
|
|
1657
|
-
if (!Number.isFinite(input.data)) {
|
|
1658
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1659
|
-
addIssueToContext(ctx, {
|
|
1660
|
-
code: ZodIssueCode.not_finite,
|
|
1661
|
-
message: check.message
|
|
1662
|
-
});
|
|
1663
|
-
status.dirty();
|
|
1664
|
-
}
|
|
1665
|
-
} else {
|
|
1666
|
-
util.assertNever(check);
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
return { status: status.value, value: input.data };
|
|
1670
|
-
}
|
|
1671
|
-
gte(value, message) {
|
|
1672
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1673
|
-
}
|
|
1674
|
-
gt(value, message) {
|
|
1675
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1676
|
-
}
|
|
1677
|
-
lte(value, message) {
|
|
1678
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1679
|
-
}
|
|
1680
|
-
lt(value, message) {
|
|
1681
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1682
|
-
}
|
|
1683
|
-
setLimit(kind, value, inclusive, message) {
|
|
1684
|
-
return new _ZodNumber({
|
|
1685
|
-
...this._def,
|
|
1686
|
-
checks: [
|
|
1687
|
-
...this._def.checks,
|
|
1688
|
-
{
|
|
1689
|
-
kind,
|
|
1690
|
-
value,
|
|
1691
|
-
inclusive,
|
|
1692
|
-
message: errorUtil.toString(message)
|
|
1693
|
-
}
|
|
1694
|
-
]
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
_addCheck(check) {
|
|
1698
|
-
return new _ZodNumber({
|
|
1699
|
-
...this._def,
|
|
1700
|
-
checks: [...this._def.checks, check]
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
int(message) {
|
|
1704
|
-
return this._addCheck({
|
|
1705
|
-
kind: "int",
|
|
1706
|
-
message: errorUtil.toString(message)
|
|
1707
|
-
});
|
|
1708
|
-
}
|
|
1709
|
-
positive(message) {
|
|
1710
|
-
return this._addCheck({
|
|
1711
|
-
kind: "min",
|
|
1712
|
-
value: 0,
|
|
1713
|
-
inclusive: false,
|
|
1714
|
-
message: errorUtil.toString(message)
|
|
1715
|
-
});
|
|
1716
|
-
}
|
|
1717
|
-
negative(message) {
|
|
1718
|
-
return this._addCheck({
|
|
1719
|
-
kind: "max",
|
|
1720
|
-
value: 0,
|
|
1721
|
-
inclusive: false,
|
|
1722
|
-
message: errorUtil.toString(message)
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
nonpositive(message) {
|
|
1726
|
-
return this._addCheck({
|
|
1727
|
-
kind: "max",
|
|
1728
|
-
value: 0,
|
|
1729
|
-
inclusive: true,
|
|
1730
|
-
message: errorUtil.toString(message)
|
|
1731
|
-
});
|
|
1732
|
-
}
|
|
1733
|
-
nonnegative(message) {
|
|
1734
|
-
return this._addCheck({
|
|
1735
|
-
kind: "min",
|
|
1736
|
-
value: 0,
|
|
1737
|
-
inclusive: true,
|
|
1738
|
-
message: errorUtil.toString(message)
|
|
1739
|
-
});
|
|
1740
|
-
}
|
|
1741
|
-
multipleOf(value, message) {
|
|
1742
|
-
return this._addCheck({
|
|
1743
|
-
kind: "multipleOf",
|
|
1744
|
-
value,
|
|
1745
|
-
message: errorUtil.toString(message)
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
finite(message) {
|
|
1749
|
-
return this._addCheck({
|
|
1750
|
-
kind: "finite",
|
|
1751
|
-
message: errorUtil.toString(message)
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
safe(message) {
|
|
1755
|
-
return this._addCheck({
|
|
1756
|
-
kind: "min",
|
|
1757
|
-
inclusive: true,
|
|
1758
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
1759
|
-
message: errorUtil.toString(message)
|
|
1760
|
-
})._addCheck({
|
|
1761
|
-
kind: "max",
|
|
1762
|
-
inclusive: true,
|
|
1763
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
1764
|
-
message: errorUtil.toString(message)
|
|
1765
|
-
});
|
|
1766
|
-
}
|
|
1767
|
-
get minValue() {
|
|
1768
|
-
let min = null;
|
|
1769
|
-
for (const ch of this._def.checks) {
|
|
1770
|
-
if (ch.kind === "min") {
|
|
1771
|
-
if (min === null || ch.value > min)
|
|
1772
|
-
min = ch.value;
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
return min;
|
|
1776
|
-
}
|
|
1777
|
-
get maxValue() {
|
|
1778
|
-
let max = null;
|
|
1779
|
-
for (const ch of this._def.checks) {
|
|
1780
|
-
if (ch.kind === "max") {
|
|
1781
|
-
if (max === null || ch.value < max)
|
|
1782
|
-
max = ch.value;
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
return max;
|
|
1786
|
-
}
|
|
1787
|
-
get isInt() {
|
|
1788
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1789
|
-
}
|
|
1790
|
-
get isFinite() {
|
|
1791
|
-
let max = null;
|
|
1792
|
-
let min = null;
|
|
1793
|
-
for (const ch of this._def.checks) {
|
|
1794
|
-
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1795
|
-
return true;
|
|
1796
|
-
} else if (ch.kind === "min") {
|
|
1797
|
-
if (min === null || ch.value > min)
|
|
1798
|
-
min = ch.value;
|
|
1799
|
-
} else if (ch.kind === "max") {
|
|
1800
|
-
if (max === null || ch.value < max)
|
|
1801
|
-
max = ch.value;
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
|
1805
|
-
}
|
|
1806
|
-
};
|
|
1807
|
-
ZodNumber.create = (params) => {
|
|
1808
|
-
return new ZodNumber({
|
|
1809
|
-
checks: [],
|
|
1810
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1811
|
-
coerce: params?.coerce || false,
|
|
1812
|
-
...processCreateParams(params)
|
|
1813
|
-
});
|
|
1814
|
-
};
|
|
1815
|
-
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1816
|
-
constructor() {
|
|
1817
|
-
super(...arguments);
|
|
1818
|
-
this.min = this.gte;
|
|
1819
|
-
this.max = this.lte;
|
|
1820
|
-
}
|
|
1821
|
-
_parse(input) {
|
|
1822
|
-
if (this._def.coerce) {
|
|
1823
|
-
try {
|
|
1824
|
-
input.data = BigInt(input.data);
|
|
1825
|
-
} catch {
|
|
1826
|
-
return this._getInvalidInput(input);
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
const parsedType = this._getType(input);
|
|
1830
|
-
if (parsedType !== ZodParsedType.bigint) {
|
|
1831
|
-
return this._getInvalidInput(input);
|
|
1832
|
-
}
|
|
1833
|
-
let ctx = void 0;
|
|
1834
|
-
const status = new ParseStatus();
|
|
1835
|
-
for (const check of this._def.checks) {
|
|
1836
|
-
if (check.kind === "min") {
|
|
1837
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1838
|
-
if (tooSmall) {
|
|
1839
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1840
|
-
addIssueToContext(ctx, {
|
|
1841
|
-
code: ZodIssueCode.too_small,
|
|
1842
|
-
type: "bigint",
|
|
1843
|
-
minimum: check.value,
|
|
1844
|
-
inclusive: check.inclusive,
|
|
1845
|
-
message: check.message
|
|
1846
|
-
});
|
|
1847
|
-
status.dirty();
|
|
1848
|
-
}
|
|
1849
|
-
} else if (check.kind === "max") {
|
|
1850
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1851
|
-
if (tooBig) {
|
|
1852
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1853
|
-
addIssueToContext(ctx, {
|
|
1854
|
-
code: ZodIssueCode.too_big,
|
|
1855
|
-
type: "bigint",
|
|
1856
|
-
maximum: check.value,
|
|
1857
|
-
inclusive: check.inclusive,
|
|
1858
|
-
message: check.message
|
|
1859
|
-
});
|
|
1860
|
-
status.dirty();
|
|
1861
|
-
}
|
|
1862
|
-
} else if (check.kind === "multipleOf") {
|
|
1863
|
-
if (input.data % check.value !== BigInt(0)) {
|
|
1864
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1865
|
-
addIssueToContext(ctx, {
|
|
1866
|
-
code: ZodIssueCode.not_multiple_of,
|
|
1867
|
-
multipleOf: check.value,
|
|
1868
|
-
message: check.message
|
|
1869
|
-
});
|
|
1870
|
-
status.dirty();
|
|
1871
|
-
}
|
|
1872
|
-
} else {
|
|
1873
|
-
util.assertNever(check);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
return { status: status.value, value: input.data };
|
|
1877
|
-
}
|
|
1878
|
-
_getInvalidInput(input) {
|
|
1879
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1880
|
-
addIssueToContext(ctx, {
|
|
1881
|
-
code: ZodIssueCode.invalid_type,
|
|
1882
|
-
expected: ZodParsedType.bigint,
|
|
1883
|
-
received: ctx.parsedType
|
|
1884
|
-
});
|
|
1885
|
-
return INVALID;
|
|
1886
|
-
}
|
|
1887
|
-
gte(value, message) {
|
|
1888
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1889
|
-
}
|
|
1890
|
-
gt(value, message) {
|
|
1891
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1892
|
-
}
|
|
1893
|
-
lte(value, message) {
|
|
1894
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1895
|
-
}
|
|
1896
|
-
lt(value, message) {
|
|
1897
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1898
|
-
}
|
|
1899
|
-
setLimit(kind, value, inclusive, message) {
|
|
1900
|
-
return new _ZodBigInt({
|
|
1901
|
-
...this._def,
|
|
1902
|
-
checks: [
|
|
1903
|
-
...this._def.checks,
|
|
1904
|
-
{
|
|
1905
|
-
kind,
|
|
1906
|
-
value,
|
|
1907
|
-
inclusive,
|
|
1908
|
-
message: errorUtil.toString(message)
|
|
1909
|
-
}
|
|
1910
|
-
]
|
|
1911
|
-
});
|
|
1912
|
-
}
|
|
1913
|
-
_addCheck(check) {
|
|
1914
|
-
return new _ZodBigInt({
|
|
1915
|
-
...this._def,
|
|
1916
|
-
checks: [...this._def.checks, check]
|
|
1917
|
-
});
|
|
1918
|
-
}
|
|
1919
|
-
positive(message) {
|
|
1920
|
-
return this._addCheck({
|
|
1921
|
-
kind: "min",
|
|
1922
|
-
value: BigInt(0),
|
|
1923
|
-
inclusive: false,
|
|
1924
|
-
message: errorUtil.toString(message)
|
|
1925
|
-
});
|
|
1926
|
-
}
|
|
1927
|
-
negative(message) {
|
|
1928
|
-
return this._addCheck({
|
|
1929
|
-
kind: "max",
|
|
1930
|
-
value: BigInt(0),
|
|
1931
|
-
inclusive: false,
|
|
1932
|
-
message: errorUtil.toString(message)
|
|
1933
|
-
});
|
|
1934
|
-
}
|
|
1935
|
-
nonpositive(message) {
|
|
1936
|
-
return this._addCheck({
|
|
1937
|
-
kind: "max",
|
|
1938
|
-
value: BigInt(0),
|
|
1939
|
-
inclusive: true,
|
|
1940
|
-
message: errorUtil.toString(message)
|
|
1941
|
-
});
|
|
1942
|
-
}
|
|
1943
|
-
nonnegative(message) {
|
|
1944
|
-
return this._addCheck({
|
|
1945
|
-
kind: "min",
|
|
1946
|
-
value: BigInt(0),
|
|
1947
|
-
inclusive: true,
|
|
1948
|
-
message: errorUtil.toString(message)
|
|
1949
|
-
});
|
|
1950
|
-
}
|
|
1951
|
-
multipleOf(value, message) {
|
|
1952
|
-
return this._addCheck({
|
|
1953
|
-
kind: "multipleOf",
|
|
1954
|
-
value,
|
|
1955
|
-
message: errorUtil.toString(message)
|
|
1956
|
-
});
|
|
1957
|
-
}
|
|
1958
|
-
get minValue() {
|
|
1959
|
-
let min = null;
|
|
1960
|
-
for (const ch of this._def.checks) {
|
|
1961
|
-
if (ch.kind === "min") {
|
|
1962
|
-
if (min === null || ch.value > min)
|
|
1963
|
-
min = ch.value;
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
return min;
|
|
1967
|
-
}
|
|
1968
|
-
get maxValue() {
|
|
1969
|
-
let max = null;
|
|
1970
|
-
for (const ch of this._def.checks) {
|
|
1971
|
-
if (ch.kind === "max") {
|
|
1972
|
-
if (max === null || ch.value < max)
|
|
1973
|
-
max = ch.value;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
return max;
|
|
1977
|
-
}
|
|
1978
|
-
};
|
|
1979
|
-
ZodBigInt.create = (params) => {
|
|
1980
|
-
return new ZodBigInt({
|
|
1981
|
-
checks: [],
|
|
1982
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1983
|
-
coerce: params?.coerce ?? false,
|
|
1984
|
-
...processCreateParams(params)
|
|
1985
|
-
});
|
|
1986
|
-
};
|
|
1987
|
-
var ZodBoolean = class extends ZodType {
|
|
1988
|
-
_parse(input) {
|
|
1989
|
-
if (this._def.coerce) {
|
|
1990
|
-
input.data = Boolean(input.data);
|
|
1991
|
-
}
|
|
1992
|
-
const parsedType = this._getType(input);
|
|
1993
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
1994
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1995
|
-
addIssueToContext(ctx, {
|
|
1996
|
-
code: ZodIssueCode.invalid_type,
|
|
1997
|
-
expected: ZodParsedType.boolean,
|
|
1998
|
-
received: ctx.parsedType
|
|
1999
|
-
});
|
|
2000
|
-
return INVALID;
|
|
2001
|
-
}
|
|
2002
|
-
return OK(input.data);
|
|
2003
|
-
}
|
|
2004
|
-
};
|
|
2005
|
-
ZodBoolean.create = (params) => {
|
|
2006
|
-
return new ZodBoolean({
|
|
2007
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2008
|
-
coerce: params?.coerce || false,
|
|
2009
|
-
...processCreateParams(params)
|
|
2010
|
-
});
|
|
2011
|
-
};
|
|
2012
|
-
var ZodDate = class _ZodDate extends ZodType {
|
|
2013
|
-
_parse(input) {
|
|
2014
|
-
if (this._def.coerce) {
|
|
2015
|
-
input.data = new Date(input.data);
|
|
2016
|
-
}
|
|
2017
|
-
const parsedType = this._getType(input);
|
|
2018
|
-
if (parsedType !== ZodParsedType.date) {
|
|
2019
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2020
|
-
addIssueToContext(ctx2, {
|
|
2021
|
-
code: ZodIssueCode.invalid_type,
|
|
2022
|
-
expected: ZodParsedType.date,
|
|
2023
|
-
received: ctx2.parsedType
|
|
2024
|
-
});
|
|
2025
|
-
return INVALID;
|
|
2026
|
-
}
|
|
2027
|
-
if (Number.isNaN(input.data.getTime())) {
|
|
2028
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2029
|
-
addIssueToContext(ctx2, {
|
|
2030
|
-
code: ZodIssueCode.invalid_date
|
|
2031
|
-
});
|
|
2032
|
-
return INVALID;
|
|
2033
|
-
}
|
|
2034
|
-
const status = new ParseStatus();
|
|
2035
|
-
let ctx = void 0;
|
|
2036
|
-
for (const check of this._def.checks) {
|
|
2037
|
-
if (check.kind === "min") {
|
|
2038
|
-
if (input.data.getTime() < check.value) {
|
|
2039
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2040
|
-
addIssueToContext(ctx, {
|
|
2041
|
-
code: ZodIssueCode.too_small,
|
|
2042
|
-
message: check.message,
|
|
2043
|
-
inclusive: true,
|
|
2044
|
-
exact: false,
|
|
2045
|
-
minimum: check.value,
|
|
2046
|
-
type: "date"
|
|
2047
|
-
});
|
|
2048
|
-
status.dirty();
|
|
2049
|
-
}
|
|
2050
|
-
} else if (check.kind === "max") {
|
|
2051
|
-
if (input.data.getTime() > check.value) {
|
|
2052
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2053
|
-
addIssueToContext(ctx, {
|
|
2054
|
-
code: ZodIssueCode.too_big,
|
|
2055
|
-
message: check.message,
|
|
2056
|
-
inclusive: true,
|
|
2057
|
-
exact: false,
|
|
2058
|
-
maximum: check.value,
|
|
2059
|
-
type: "date"
|
|
2060
|
-
});
|
|
2061
|
-
status.dirty();
|
|
2062
|
-
}
|
|
2063
|
-
} else {
|
|
2064
|
-
util.assertNever(check);
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
return {
|
|
2068
|
-
status: status.value,
|
|
2069
|
-
value: new Date(input.data.getTime())
|
|
2070
|
-
};
|
|
2071
|
-
}
|
|
2072
|
-
_addCheck(check) {
|
|
2073
|
-
return new _ZodDate({
|
|
2074
|
-
...this._def,
|
|
2075
|
-
checks: [...this._def.checks, check]
|
|
2076
|
-
});
|
|
2077
|
-
}
|
|
2078
|
-
min(minDate, message) {
|
|
2079
|
-
return this._addCheck({
|
|
2080
|
-
kind: "min",
|
|
2081
|
-
value: minDate.getTime(),
|
|
2082
|
-
message: errorUtil.toString(message)
|
|
2083
|
-
});
|
|
2084
|
-
}
|
|
2085
|
-
max(maxDate, message) {
|
|
2086
|
-
return this._addCheck({
|
|
2087
|
-
kind: "max",
|
|
2088
|
-
value: maxDate.getTime(),
|
|
2089
|
-
message: errorUtil.toString(message)
|
|
2090
|
-
});
|
|
2091
|
-
}
|
|
2092
|
-
get minDate() {
|
|
2093
|
-
let min = null;
|
|
2094
|
-
for (const ch of this._def.checks) {
|
|
2095
|
-
if (ch.kind === "min") {
|
|
2096
|
-
if (min === null || ch.value > min)
|
|
2097
|
-
min = ch.value;
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
return min != null ? new Date(min) : null;
|
|
2101
|
-
}
|
|
2102
|
-
get maxDate() {
|
|
2103
|
-
let max = null;
|
|
2104
|
-
for (const ch of this._def.checks) {
|
|
2105
|
-
if (ch.kind === "max") {
|
|
2106
|
-
if (max === null || ch.value < max)
|
|
2107
|
-
max = ch.value;
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
return max != null ? new Date(max) : null;
|
|
2111
|
-
}
|
|
2112
|
-
};
|
|
2113
|
-
ZodDate.create = (params) => {
|
|
2114
|
-
return new ZodDate({
|
|
2115
|
-
checks: [],
|
|
2116
|
-
coerce: params?.coerce || false,
|
|
2117
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2118
|
-
...processCreateParams(params)
|
|
2119
|
-
});
|
|
2120
|
-
};
|
|
2121
|
-
var ZodSymbol = class extends ZodType {
|
|
2122
|
-
_parse(input) {
|
|
2123
|
-
const parsedType = this._getType(input);
|
|
2124
|
-
if (parsedType !== ZodParsedType.symbol) {
|
|
2125
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2126
|
-
addIssueToContext(ctx, {
|
|
2127
|
-
code: ZodIssueCode.invalid_type,
|
|
2128
|
-
expected: ZodParsedType.symbol,
|
|
2129
|
-
received: ctx.parsedType
|
|
2130
|
-
});
|
|
2131
|
-
return INVALID;
|
|
2132
|
-
}
|
|
2133
|
-
return OK(input.data);
|
|
2134
|
-
}
|
|
2135
|
-
};
|
|
2136
|
-
ZodSymbol.create = (params) => {
|
|
2137
|
-
return new ZodSymbol({
|
|
2138
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2139
|
-
...processCreateParams(params)
|
|
2140
|
-
});
|
|
2141
|
-
};
|
|
2142
|
-
var ZodUndefined = class extends ZodType {
|
|
2143
|
-
_parse(input) {
|
|
2144
|
-
const parsedType = this._getType(input);
|
|
2145
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2146
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2147
|
-
addIssueToContext(ctx, {
|
|
2148
|
-
code: ZodIssueCode.invalid_type,
|
|
2149
|
-
expected: ZodParsedType.undefined,
|
|
2150
|
-
received: ctx.parsedType
|
|
2151
|
-
});
|
|
2152
|
-
return INVALID;
|
|
2153
|
-
}
|
|
2154
|
-
return OK(input.data);
|
|
2155
|
-
}
|
|
2156
|
-
};
|
|
2157
|
-
ZodUndefined.create = (params) => {
|
|
2158
|
-
return new ZodUndefined({
|
|
2159
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2160
|
-
...processCreateParams(params)
|
|
2161
|
-
});
|
|
2162
|
-
};
|
|
2163
|
-
var ZodNull = class extends ZodType {
|
|
2164
|
-
_parse(input) {
|
|
2165
|
-
const parsedType = this._getType(input);
|
|
2166
|
-
if (parsedType !== ZodParsedType.null) {
|
|
2167
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2168
|
-
addIssueToContext(ctx, {
|
|
2169
|
-
code: ZodIssueCode.invalid_type,
|
|
2170
|
-
expected: ZodParsedType.null,
|
|
2171
|
-
received: ctx.parsedType
|
|
2172
|
-
});
|
|
2173
|
-
return INVALID;
|
|
2174
|
-
}
|
|
2175
|
-
return OK(input.data);
|
|
2176
|
-
}
|
|
2177
|
-
};
|
|
2178
|
-
ZodNull.create = (params) => {
|
|
2179
|
-
return new ZodNull({
|
|
2180
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2181
|
-
...processCreateParams(params)
|
|
2182
|
-
});
|
|
2183
|
-
};
|
|
2184
|
-
var ZodAny = class extends ZodType {
|
|
2185
|
-
constructor() {
|
|
2186
|
-
super(...arguments);
|
|
2187
|
-
this._any = true;
|
|
2188
|
-
}
|
|
2189
|
-
_parse(input) {
|
|
2190
|
-
return OK(input.data);
|
|
2191
|
-
}
|
|
2192
|
-
};
|
|
2193
|
-
ZodAny.create = (params) => {
|
|
2194
|
-
return new ZodAny({
|
|
2195
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2196
|
-
...processCreateParams(params)
|
|
2197
|
-
});
|
|
2198
|
-
};
|
|
2199
|
-
var ZodUnknown = class extends ZodType {
|
|
2200
|
-
constructor() {
|
|
2201
|
-
super(...arguments);
|
|
2202
|
-
this._unknown = true;
|
|
2203
|
-
}
|
|
2204
|
-
_parse(input) {
|
|
2205
|
-
return OK(input.data);
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2208
|
-
ZodUnknown.create = (params) => {
|
|
2209
|
-
return new ZodUnknown({
|
|
2210
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2211
|
-
...processCreateParams(params)
|
|
2212
|
-
});
|
|
2213
|
-
};
|
|
2214
|
-
var ZodNever = class extends ZodType {
|
|
2215
|
-
_parse(input) {
|
|
2216
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2217
|
-
addIssueToContext(ctx, {
|
|
2218
|
-
code: ZodIssueCode.invalid_type,
|
|
2219
|
-
expected: ZodParsedType.never,
|
|
2220
|
-
received: ctx.parsedType
|
|
2221
|
-
});
|
|
2222
|
-
return INVALID;
|
|
2223
|
-
}
|
|
2224
|
-
};
|
|
2225
|
-
ZodNever.create = (params) => {
|
|
2226
|
-
return new ZodNever({
|
|
2227
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2228
|
-
...processCreateParams(params)
|
|
2229
|
-
});
|
|
2230
|
-
};
|
|
2231
|
-
var ZodVoid = class extends ZodType {
|
|
2232
|
-
_parse(input) {
|
|
2233
|
-
const parsedType = this._getType(input);
|
|
2234
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2235
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2236
|
-
addIssueToContext(ctx, {
|
|
2237
|
-
code: ZodIssueCode.invalid_type,
|
|
2238
|
-
expected: ZodParsedType.void,
|
|
2239
|
-
received: ctx.parsedType
|
|
2240
|
-
});
|
|
2241
|
-
return INVALID;
|
|
2242
|
-
}
|
|
2243
|
-
return OK(input.data);
|
|
2244
|
-
}
|
|
2245
|
-
};
|
|
2246
|
-
ZodVoid.create = (params) => {
|
|
2247
|
-
return new ZodVoid({
|
|
2248
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2249
|
-
...processCreateParams(params)
|
|
2250
|
-
});
|
|
2251
|
-
};
|
|
2252
|
-
var ZodArray = class _ZodArray extends ZodType {
|
|
2253
|
-
_parse(input) {
|
|
2254
|
-
const { ctx, status } = this._processInputParams(input);
|
|
2255
|
-
const def = this._def;
|
|
2256
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2257
|
-
addIssueToContext(ctx, {
|
|
2258
|
-
code: ZodIssueCode.invalid_type,
|
|
2259
|
-
expected: ZodParsedType.array,
|
|
2260
|
-
received: ctx.parsedType
|
|
2261
|
-
});
|
|
2262
|
-
return INVALID;
|
|
2263
|
-
}
|
|
2264
|
-
if (def.exactLength !== null) {
|
|
2265
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2266
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2267
|
-
if (tooBig || tooSmall) {
|
|
2268
|
-
addIssueToContext(ctx, {
|
|
2269
|
-
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2270
|
-
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2271
|
-
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2272
|
-
type: "array",
|
|
2273
|
-
inclusive: true,
|
|
2274
|
-
exact: true,
|
|
2275
|
-
message: def.exactLength.message
|
|
2276
|
-
});
|
|
2277
|
-
status.dirty();
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
if (def.minLength !== null) {
|
|
2281
|
-
if (ctx.data.length < def.minLength.value) {
|
|
2282
|
-
addIssueToContext(ctx, {
|
|
2283
|
-
code: ZodIssueCode.too_small,
|
|
2284
|
-
minimum: def.minLength.value,
|
|
2285
|
-
type: "array",
|
|
2286
|
-
inclusive: true,
|
|
2287
|
-
exact: false,
|
|
2288
|
-
message: def.minLength.message
|
|
2289
|
-
});
|
|
2290
|
-
status.dirty();
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
if (def.maxLength !== null) {
|
|
2294
|
-
if (ctx.data.length > def.maxLength.value) {
|
|
2295
|
-
addIssueToContext(ctx, {
|
|
2296
|
-
code: ZodIssueCode.too_big,
|
|
2297
|
-
maximum: def.maxLength.value,
|
|
2298
|
-
type: "array",
|
|
2299
|
-
inclusive: true,
|
|
2300
|
-
exact: false,
|
|
2301
|
-
message: def.maxLength.message
|
|
2302
|
-
});
|
|
2303
|
-
status.dirty();
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
if (ctx.common.async) {
|
|
2307
|
-
return Promise.all([...ctx.data].map((item, i) => {
|
|
2308
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2309
|
-
})).then((result2) => {
|
|
2310
|
-
return ParseStatus.mergeArray(status, result2);
|
|
2311
|
-
});
|
|
2312
|
-
}
|
|
2313
|
-
const result = [...ctx.data].map((item, i) => {
|
|
2314
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2315
|
-
});
|
|
2316
|
-
return ParseStatus.mergeArray(status, result);
|
|
2317
|
-
}
|
|
2318
|
-
get element() {
|
|
2319
|
-
return this._def.type;
|
|
2320
|
-
}
|
|
2321
|
-
min(minLength, message) {
|
|
2322
|
-
return new _ZodArray({
|
|
2323
|
-
...this._def,
|
|
2324
|
-
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2325
|
-
});
|
|
2326
|
-
}
|
|
2327
|
-
max(maxLength, message) {
|
|
2328
|
-
return new _ZodArray({
|
|
2329
|
-
...this._def,
|
|
2330
|
-
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2331
|
-
});
|
|
2332
|
-
}
|
|
2333
|
-
length(len, message) {
|
|
2334
|
-
return new _ZodArray({
|
|
2335
|
-
...this._def,
|
|
2336
|
-
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2337
|
-
});
|
|
2338
|
-
}
|
|
2339
|
-
nonempty(message) {
|
|
2340
|
-
return this.min(1, message);
|
|
2341
|
-
}
|
|
2342
|
-
};
|
|
2343
|
-
ZodArray.create = (schema, params) => {
|
|
2344
|
-
return new ZodArray({
|
|
2345
|
-
type: schema,
|
|
2346
|
-
minLength: null,
|
|
2347
|
-
maxLength: null,
|
|
2348
|
-
exactLength: null,
|
|
2349
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2350
|
-
...processCreateParams(params)
|
|
2351
|
-
});
|
|
2352
|
-
};
|
|
2353
|
-
function deepPartialify(schema) {
|
|
2354
|
-
if (schema instanceof ZodObject) {
|
|
2355
|
-
const newShape = {};
|
|
2356
|
-
for (const key in schema.shape) {
|
|
2357
|
-
const fieldSchema = schema.shape[key];
|
|
2358
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2359
|
-
}
|
|
2360
|
-
return new ZodObject({
|
|
2361
|
-
...schema._def,
|
|
2362
|
-
shape: () => newShape
|
|
2363
|
-
});
|
|
2364
|
-
} else if (schema instanceof ZodArray) {
|
|
2365
|
-
return new ZodArray({
|
|
2366
|
-
...schema._def,
|
|
2367
|
-
type: deepPartialify(schema.element)
|
|
2368
|
-
});
|
|
2369
|
-
} else if (schema instanceof ZodOptional) {
|
|
2370
|
-
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2371
|
-
} else if (schema instanceof ZodNullable) {
|
|
2372
|
-
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2373
|
-
} else if (schema instanceof ZodTuple) {
|
|
2374
|
-
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2375
|
-
} else {
|
|
2376
|
-
return schema;
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
var ZodObject = class _ZodObject extends ZodType {
|
|
2380
|
-
constructor() {
|
|
2381
|
-
super(...arguments);
|
|
2382
|
-
this._cached = null;
|
|
2383
|
-
this.nonstrict = this.passthrough;
|
|
2384
|
-
this.augment = this.extend;
|
|
2385
|
-
}
|
|
2386
|
-
_getCached() {
|
|
2387
|
-
if (this._cached !== null)
|
|
2388
|
-
return this._cached;
|
|
2389
|
-
const shape = this._def.shape();
|
|
2390
|
-
const keys = util.objectKeys(shape);
|
|
2391
|
-
this._cached = { shape, keys };
|
|
2392
|
-
return this._cached;
|
|
2393
|
-
}
|
|
2394
|
-
_parse(input) {
|
|
2395
|
-
const parsedType = this._getType(input);
|
|
2396
|
-
if (parsedType !== ZodParsedType.object) {
|
|
2397
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2398
|
-
addIssueToContext(ctx2, {
|
|
2399
|
-
code: ZodIssueCode.invalid_type,
|
|
2400
|
-
expected: ZodParsedType.object,
|
|
2401
|
-
received: ctx2.parsedType
|
|
2402
|
-
});
|
|
2403
|
-
return INVALID;
|
|
2404
|
-
}
|
|
2405
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2406
|
-
const { shape, keys: shapeKeys } = this._getCached();
|
|
2407
|
-
const extraKeys = [];
|
|
2408
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2409
|
-
for (const key in ctx.data) {
|
|
2410
|
-
if (!shapeKeys.includes(key)) {
|
|
2411
|
-
extraKeys.push(key);
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
const pairs = [];
|
|
2416
|
-
for (const key of shapeKeys) {
|
|
2417
|
-
const keyValidator = shape[key];
|
|
2418
|
-
const value = ctx.data[key];
|
|
2419
|
-
pairs.push({
|
|
2420
|
-
key: { status: "valid", value: key },
|
|
2421
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2422
|
-
alwaysSet: key in ctx.data
|
|
2423
|
-
});
|
|
2424
|
-
}
|
|
2425
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
2426
|
-
const unknownKeys = this._def.unknownKeys;
|
|
2427
|
-
if (unknownKeys === "passthrough") {
|
|
2428
|
-
for (const key of extraKeys) {
|
|
2429
|
-
pairs.push({
|
|
2430
|
-
key: { status: "valid", value: key },
|
|
2431
|
-
value: { status: "valid", value: ctx.data[key] }
|
|
2432
|
-
});
|
|
2433
|
-
}
|
|
2434
|
-
} else if (unknownKeys === "strict") {
|
|
2435
|
-
if (extraKeys.length > 0) {
|
|
2436
|
-
addIssueToContext(ctx, {
|
|
2437
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
2438
|
-
keys: extraKeys
|
|
2439
|
-
});
|
|
2440
|
-
status.dirty();
|
|
2441
|
-
}
|
|
2442
|
-
} else if (unknownKeys === "strip") {
|
|
2443
|
-
} else {
|
|
2444
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2445
|
-
}
|
|
2446
|
-
} else {
|
|
2447
|
-
const catchall = this._def.catchall;
|
|
2448
|
-
for (const key of extraKeys) {
|
|
2449
|
-
const value = ctx.data[key];
|
|
2450
|
-
pairs.push({
|
|
2451
|
-
key: { status: "valid", value: key },
|
|
2452
|
-
value: catchall._parse(
|
|
2453
|
-
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2454
|
-
//, ctx.child(key), value, getParsedType(value)
|
|
2455
|
-
),
|
|
2456
|
-
alwaysSet: key in ctx.data
|
|
2457
|
-
});
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
if (ctx.common.async) {
|
|
2461
|
-
return Promise.resolve().then(async () => {
|
|
2462
|
-
const syncPairs = [];
|
|
2463
|
-
for (const pair of pairs) {
|
|
2464
|
-
const key = await pair.key;
|
|
2465
|
-
const value = await pair.value;
|
|
2466
|
-
syncPairs.push({
|
|
2467
|
-
key,
|
|
2468
|
-
value,
|
|
2469
|
-
alwaysSet: pair.alwaysSet
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2472
|
-
return syncPairs;
|
|
2473
|
-
}).then((syncPairs) => {
|
|
2474
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2475
|
-
});
|
|
2476
|
-
} else {
|
|
2477
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2478
|
-
}
|
|
2479
|
-
}
|
|
2480
|
-
get shape() {
|
|
2481
|
-
return this._def.shape();
|
|
2482
|
-
}
|
|
2483
|
-
strict(message) {
|
|
2484
|
-
errorUtil.errToObj;
|
|
2485
|
-
return new _ZodObject({
|
|
2486
|
-
...this._def,
|
|
2487
|
-
unknownKeys: "strict",
|
|
2488
|
-
...message !== void 0 ? {
|
|
2489
|
-
errorMap: (issue, ctx) => {
|
|
2490
|
-
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2491
|
-
if (issue.code === "unrecognized_keys")
|
|
2492
|
-
return {
|
|
2493
|
-
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2494
|
-
};
|
|
2495
|
-
return {
|
|
2496
|
-
message: defaultError
|
|
2497
|
-
};
|
|
2498
|
-
}
|
|
2499
|
-
} : {}
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
strip() {
|
|
2503
|
-
return new _ZodObject({
|
|
2504
|
-
...this._def,
|
|
2505
|
-
unknownKeys: "strip"
|
|
2506
|
-
});
|
|
2507
|
-
}
|
|
2508
|
-
passthrough() {
|
|
2509
|
-
return new _ZodObject({
|
|
2510
|
-
...this._def,
|
|
2511
|
-
unknownKeys: "passthrough"
|
|
2512
|
-
});
|
|
2513
|
-
}
|
|
2514
|
-
// const AugmentFactory =
|
|
2515
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2516
|
-
// <Augmentation extends ZodRawShape>(
|
|
2517
|
-
// augmentation: Augmentation
|
|
2518
|
-
// ): ZodObject<
|
|
2519
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2520
|
-
// Def["unknownKeys"],
|
|
2521
|
-
// Def["catchall"]
|
|
2522
|
-
// > => {
|
|
2523
|
-
// return new ZodObject({
|
|
2524
|
-
// ...def,
|
|
2525
|
-
// shape: () => ({
|
|
2526
|
-
// ...def.shape(),
|
|
2527
|
-
// ...augmentation,
|
|
2528
|
-
// }),
|
|
2529
|
-
// }) as any;
|
|
2530
|
-
// };
|
|
2531
|
-
extend(augmentation) {
|
|
2532
|
-
return new _ZodObject({
|
|
2533
|
-
...this._def,
|
|
2534
|
-
shape: () => ({
|
|
2535
|
-
...this._def.shape(),
|
|
2536
|
-
...augmentation
|
|
2537
|
-
})
|
|
2538
|
-
});
|
|
2539
|
-
}
|
|
2540
|
-
/**
|
|
2541
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
2542
|
-
* inferred type of merged objects. Please
|
|
2543
|
-
* upgrade if you are experiencing issues.
|
|
2544
|
-
*/
|
|
2545
|
-
merge(merging) {
|
|
2546
|
-
const merged = new _ZodObject({
|
|
2547
|
-
unknownKeys: merging._def.unknownKeys,
|
|
2548
|
-
catchall: merging._def.catchall,
|
|
2549
|
-
shape: () => ({
|
|
2550
|
-
...this._def.shape(),
|
|
2551
|
-
...merging._def.shape()
|
|
2552
|
-
}),
|
|
2553
|
-
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2554
|
-
});
|
|
2555
|
-
return merged;
|
|
2556
|
-
}
|
|
2557
|
-
// merge<
|
|
2558
|
-
// Incoming extends AnyZodObject,
|
|
2559
|
-
// Augmentation extends Incoming["shape"],
|
|
2560
|
-
// NewOutput extends {
|
|
2561
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2562
|
-
// ? Augmentation[k]["_output"]
|
|
2563
|
-
// : k extends keyof Output
|
|
2564
|
-
// ? Output[k]
|
|
2565
|
-
// : never;
|
|
2566
|
-
// },
|
|
2567
|
-
// NewInput extends {
|
|
2568
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2569
|
-
// ? Augmentation[k]["_input"]
|
|
2570
|
-
// : k extends keyof Input
|
|
2571
|
-
// ? Input[k]
|
|
2572
|
-
// : never;
|
|
2573
|
-
// }
|
|
2574
|
-
// >(
|
|
2575
|
-
// merging: Incoming
|
|
2576
|
-
// ): ZodObject<
|
|
2577
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2578
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2579
|
-
// Incoming["_def"]["catchall"],
|
|
2580
|
-
// NewOutput,
|
|
2581
|
-
// NewInput
|
|
2582
|
-
// > {
|
|
2583
|
-
// const merged: any = new ZodObject({
|
|
2584
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2585
|
-
// catchall: merging._def.catchall,
|
|
2586
|
-
// shape: () =>
|
|
2587
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2588
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2589
|
-
// }) as any;
|
|
2590
|
-
// return merged;
|
|
2591
|
-
// }
|
|
2592
|
-
setKey(key, schema) {
|
|
2593
|
-
return this.augment({ [key]: schema });
|
|
2594
|
-
}
|
|
2595
|
-
// merge<Incoming extends AnyZodObject>(
|
|
2596
|
-
// merging: Incoming
|
|
2597
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2598
|
-
// ZodObject<
|
|
2599
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2600
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2601
|
-
// Incoming["_def"]["catchall"]
|
|
2602
|
-
// > {
|
|
2603
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
2604
|
-
// // this._def.shape(),
|
|
2605
|
-
// // merging._def.shape()
|
|
2606
|
-
// // );
|
|
2607
|
-
// const merged: any = new ZodObject({
|
|
2608
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2609
|
-
// catchall: merging._def.catchall,
|
|
2610
|
-
// shape: () =>
|
|
2611
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2612
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2613
|
-
// }) as any;
|
|
2614
|
-
// return merged;
|
|
2615
|
-
// }
|
|
2616
|
-
catchall(index) {
|
|
2617
|
-
return new _ZodObject({
|
|
2618
|
-
...this._def,
|
|
2619
|
-
catchall: index
|
|
2620
|
-
});
|
|
2621
|
-
}
|
|
2622
|
-
pick(mask) {
|
|
2623
|
-
const shape = {};
|
|
2624
|
-
for (const key of util.objectKeys(mask)) {
|
|
2625
|
-
if (mask[key] && this.shape[key]) {
|
|
2626
|
-
shape[key] = this.shape[key];
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
return new _ZodObject({
|
|
2630
|
-
...this._def,
|
|
2631
|
-
shape: () => shape
|
|
2632
|
-
});
|
|
2633
|
-
}
|
|
2634
|
-
omit(mask) {
|
|
2635
|
-
const shape = {};
|
|
2636
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
2637
|
-
if (!mask[key]) {
|
|
2638
|
-
shape[key] = this.shape[key];
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
return new _ZodObject({
|
|
2642
|
-
...this._def,
|
|
2643
|
-
shape: () => shape
|
|
2644
|
-
});
|
|
2645
|
-
}
|
|
2646
|
-
/**
|
|
2647
|
-
* @deprecated
|
|
2648
|
-
*/
|
|
2649
|
-
deepPartial() {
|
|
2650
|
-
return deepPartialify(this);
|
|
2651
|
-
}
|
|
2652
|
-
partial(mask) {
|
|
2653
|
-
const newShape = {};
|
|
2654
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
2655
|
-
const fieldSchema = this.shape[key];
|
|
2656
|
-
if (mask && !mask[key]) {
|
|
2657
|
-
newShape[key] = fieldSchema;
|
|
2658
|
-
} else {
|
|
2659
|
-
newShape[key] = fieldSchema.optional();
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
return new _ZodObject({
|
|
2663
|
-
...this._def,
|
|
2664
|
-
shape: () => newShape
|
|
2665
|
-
});
|
|
2666
|
-
}
|
|
2667
|
-
required(mask) {
|
|
2668
|
-
const newShape = {};
|
|
2669
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
2670
|
-
if (mask && !mask[key]) {
|
|
2671
|
-
newShape[key] = this.shape[key];
|
|
2672
|
-
} else {
|
|
2673
|
-
const fieldSchema = this.shape[key];
|
|
2674
|
-
let newField = fieldSchema;
|
|
2675
|
-
while (newField instanceof ZodOptional) {
|
|
2676
|
-
newField = newField._def.innerType;
|
|
2677
|
-
}
|
|
2678
|
-
newShape[key] = newField;
|
|
2679
|
-
}
|
|
2680
|
-
}
|
|
2681
|
-
return new _ZodObject({
|
|
2682
|
-
...this._def,
|
|
2683
|
-
shape: () => newShape
|
|
2684
|
-
});
|
|
2685
|
-
}
|
|
2686
|
-
keyof() {
|
|
2687
|
-
return createZodEnum(util.objectKeys(this.shape));
|
|
2688
|
-
}
|
|
2689
|
-
};
|
|
2690
|
-
ZodObject.create = (shape, params) => {
|
|
2691
|
-
return new ZodObject({
|
|
2692
|
-
shape: () => shape,
|
|
2693
|
-
unknownKeys: "strip",
|
|
2694
|
-
catchall: ZodNever.create(),
|
|
2695
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2696
|
-
...processCreateParams(params)
|
|
2697
|
-
});
|
|
2698
|
-
};
|
|
2699
|
-
ZodObject.strictCreate = (shape, params) => {
|
|
2700
|
-
return new ZodObject({
|
|
2701
|
-
shape: () => shape,
|
|
2702
|
-
unknownKeys: "strict",
|
|
2703
|
-
catchall: ZodNever.create(),
|
|
2704
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2705
|
-
...processCreateParams(params)
|
|
2706
|
-
});
|
|
2707
|
-
};
|
|
2708
|
-
ZodObject.lazycreate = (shape, params) => {
|
|
2709
|
-
return new ZodObject({
|
|
2710
|
-
shape,
|
|
2711
|
-
unknownKeys: "strip",
|
|
2712
|
-
catchall: ZodNever.create(),
|
|
2713
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2714
|
-
...processCreateParams(params)
|
|
2715
|
-
});
|
|
2716
|
-
};
|
|
2717
|
-
var ZodUnion = class extends ZodType {
|
|
2718
|
-
_parse(input) {
|
|
2719
|
-
const { ctx } = this._processInputParams(input);
|
|
2720
|
-
const options = this._def.options;
|
|
2721
|
-
function handleResults(results) {
|
|
2722
|
-
for (const result of results) {
|
|
2723
|
-
if (result.result.status === "valid") {
|
|
2724
|
-
return result.result;
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
for (const result of results) {
|
|
2728
|
-
if (result.result.status === "dirty") {
|
|
2729
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2730
|
-
return result.result;
|
|
2731
|
-
}
|
|
2732
|
-
}
|
|
2733
|
-
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2734
|
-
addIssueToContext(ctx, {
|
|
2735
|
-
code: ZodIssueCode.invalid_union,
|
|
2736
|
-
unionErrors
|
|
2737
|
-
});
|
|
2738
|
-
return INVALID;
|
|
2739
|
-
}
|
|
2740
|
-
if (ctx.common.async) {
|
|
2741
|
-
return Promise.all(options.map(async (option) => {
|
|
2742
|
-
const childCtx = {
|
|
2743
|
-
...ctx,
|
|
2744
|
-
common: {
|
|
2745
|
-
...ctx.common,
|
|
2746
|
-
issues: []
|
|
2747
|
-
},
|
|
2748
|
-
parent: null
|
|
2749
|
-
};
|
|
2750
|
-
return {
|
|
2751
|
-
result: await option._parseAsync({
|
|
2752
|
-
data: ctx.data,
|
|
2753
|
-
path: ctx.path,
|
|
2754
|
-
parent: childCtx
|
|
2755
|
-
}),
|
|
2756
|
-
ctx: childCtx
|
|
2757
|
-
};
|
|
2758
|
-
})).then(handleResults);
|
|
2759
|
-
} else {
|
|
2760
|
-
let dirty = void 0;
|
|
2761
|
-
const issues = [];
|
|
2762
|
-
for (const option of options) {
|
|
2763
|
-
const childCtx = {
|
|
2764
|
-
...ctx,
|
|
2765
|
-
common: {
|
|
2766
|
-
...ctx.common,
|
|
2767
|
-
issues: []
|
|
2768
|
-
},
|
|
2769
|
-
parent: null
|
|
2770
|
-
};
|
|
2771
|
-
const result = option._parseSync({
|
|
2772
|
-
data: ctx.data,
|
|
2773
|
-
path: ctx.path,
|
|
2774
|
-
parent: childCtx
|
|
2775
|
-
});
|
|
2776
|
-
if (result.status === "valid") {
|
|
2777
|
-
return result;
|
|
2778
|
-
} else if (result.status === "dirty" && !dirty) {
|
|
2779
|
-
dirty = { result, ctx: childCtx };
|
|
2780
|
-
}
|
|
2781
|
-
if (childCtx.common.issues.length) {
|
|
2782
|
-
issues.push(childCtx.common.issues);
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
if (dirty) {
|
|
2786
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2787
|
-
return dirty.result;
|
|
2788
|
-
}
|
|
2789
|
-
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
2790
|
-
addIssueToContext(ctx, {
|
|
2791
|
-
code: ZodIssueCode.invalid_union,
|
|
2792
|
-
unionErrors
|
|
2793
|
-
});
|
|
2794
|
-
return INVALID;
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
get options() {
|
|
2798
|
-
return this._def.options;
|
|
2799
|
-
}
|
|
2800
|
-
};
|
|
2801
|
-
ZodUnion.create = (types, params) => {
|
|
2802
|
-
return new ZodUnion({
|
|
2803
|
-
options: types,
|
|
2804
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2805
|
-
...processCreateParams(params)
|
|
2806
|
-
});
|
|
2807
|
-
};
|
|
2808
|
-
var getDiscriminator = (type) => {
|
|
2809
|
-
if (type instanceof ZodLazy) {
|
|
2810
|
-
return getDiscriminator(type.schema);
|
|
2811
|
-
} else if (type instanceof ZodEffects) {
|
|
2812
|
-
return getDiscriminator(type.innerType());
|
|
2813
|
-
} else if (type instanceof ZodLiteral) {
|
|
2814
|
-
return [type.value];
|
|
2815
|
-
} else if (type instanceof ZodEnum) {
|
|
2816
|
-
return type.options;
|
|
2817
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
2818
|
-
return util.objectValues(type.enum);
|
|
2819
|
-
} else if (type instanceof ZodDefault) {
|
|
2820
|
-
return getDiscriminator(type._def.innerType);
|
|
2821
|
-
} else if (type instanceof ZodUndefined) {
|
|
2822
|
-
return [void 0];
|
|
2823
|
-
} else if (type instanceof ZodNull) {
|
|
2824
|
-
return [null];
|
|
2825
|
-
} else if (type instanceof ZodOptional) {
|
|
2826
|
-
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2827
|
-
} else if (type instanceof ZodNullable) {
|
|
2828
|
-
return [null, ...getDiscriminator(type.unwrap())];
|
|
2829
|
-
} else if (type instanceof ZodBranded) {
|
|
2830
|
-
return getDiscriminator(type.unwrap());
|
|
2831
|
-
} else if (type instanceof ZodReadonly) {
|
|
2832
|
-
return getDiscriminator(type.unwrap());
|
|
2833
|
-
} else if (type instanceof ZodCatch) {
|
|
2834
|
-
return getDiscriminator(type._def.innerType);
|
|
2835
|
-
} else {
|
|
2836
|
-
return [];
|
|
2837
|
-
}
|
|
2838
|
-
};
|
|
2839
|
-
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
2840
|
-
_parse(input) {
|
|
2841
|
-
const { ctx } = this._processInputParams(input);
|
|
2842
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2843
|
-
addIssueToContext(ctx, {
|
|
2844
|
-
code: ZodIssueCode.invalid_type,
|
|
2845
|
-
expected: ZodParsedType.object,
|
|
2846
|
-
received: ctx.parsedType
|
|
2847
|
-
});
|
|
2848
|
-
return INVALID;
|
|
2849
|
-
}
|
|
2850
|
-
const discriminator = this.discriminator;
|
|
2851
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
2852
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
2853
|
-
if (!option) {
|
|
2854
|
-
addIssueToContext(ctx, {
|
|
2855
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
2856
|
-
options: Array.from(this.optionsMap.keys()),
|
|
2857
|
-
path: [discriminator]
|
|
2858
|
-
});
|
|
2859
|
-
return INVALID;
|
|
2860
|
-
}
|
|
2861
|
-
if (ctx.common.async) {
|
|
2862
|
-
return option._parseAsync({
|
|
2863
|
-
data: ctx.data,
|
|
2864
|
-
path: ctx.path,
|
|
2865
|
-
parent: ctx
|
|
2866
|
-
});
|
|
2867
|
-
} else {
|
|
2868
|
-
return option._parseSync({
|
|
2869
|
-
data: ctx.data,
|
|
2870
|
-
path: ctx.path,
|
|
2871
|
-
parent: ctx
|
|
2872
|
-
});
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
get discriminator() {
|
|
2876
|
-
return this._def.discriminator;
|
|
2877
|
-
}
|
|
2878
|
-
get options() {
|
|
2879
|
-
return this._def.options;
|
|
2880
|
-
}
|
|
2881
|
-
get optionsMap() {
|
|
2882
|
-
return this._def.optionsMap;
|
|
2883
|
-
}
|
|
2884
|
-
/**
|
|
2885
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2886
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2887
|
-
* have a different value for each object in the union.
|
|
2888
|
-
* @param discriminator the name of the discriminator property
|
|
2889
|
-
* @param types an array of object schemas
|
|
2890
|
-
* @param params
|
|
2891
|
-
*/
|
|
2892
|
-
static create(discriminator, options, params) {
|
|
2893
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
2894
|
-
for (const type of options) {
|
|
2895
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2896
|
-
if (!discriminatorValues.length) {
|
|
2897
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2898
|
-
}
|
|
2899
|
-
for (const value of discriminatorValues) {
|
|
2900
|
-
if (optionsMap.has(value)) {
|
|
2901
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2902
|
-
}
|
|
2903
|
-
optionsMap.set(value, type);
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
return new _ZodDiscriminatedUnion({
|
|
2907
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2908
|
-
discriminator,
|
|
2909
|
-
options,
|
|
2910
|
-
optionsMap,
|
|
2911
|
-
...processCreateParams(params)
|
|
2912
|
-
});
|
|
2913
|
-
}
|
|
2914
|
-
};
|
|
2915
|
-
function mergeValues(a, b) {
|
|
2916
|
-
const aType = getParsedType(a);
|
|
2917
|
-
const bType = getParsedType(b);
|
|
2918
|
-
if (a === b) {
|
|
2919
|
-
return { valid: true, data: a };
|
|
2920
|
-
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2921
|
-
const bKeys = util.objectKeys(b);
|
|
2922
|
-
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2923
|
-
const newObj = { ...a, ...b };
|
|
2924
|
-
for (const key of sharedKeys) {
|
|
2925
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
2926
|
-
if (!sharedValue.valid) {
|
|
2927
|
-
return { valid: false };
|
|
2928
|
-
}
|
|
2929
|
-
newObj[key] = sharedValue.data;
|
|
2930
|
-
}
|
|
2931
|
-
return { valid: true, data: newObj };
|
|
2932
|
-
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2933
|
-
if (a.length !== b.length) {
|
|
2934
|
-
return { valid: false };
|
|
2935
|
-
}
|
|
2936
|
-
const newArray = [];
|
|
2937
|
-
for (let index = 0; index < a.length; index++) {
|
|
2938
|
-
const itemA = a[index];
|
|
2939
|
-
const itemB = b[index];
|
|
2940
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
2941
|
-
if (!sharedValue.valid) {
|
|
2942
|
-
return { valid: false };
|
|
2943
|
-
}
|
|
2944
|
-
newArray.push(sharedValue.data);
|
|
2945
|
-
}
|
|
2946
|
-
return { valid: true, data: newArray };
|
|
2947
|
-
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
2948
|
-
return { valid: true, data: a };
|
|
2949
|
-
} else {
|
|
2950
|
-
return { valid: false };
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
var ZodIntersection = class extends ZodType {
|
|
2954
|
-
_parse(input) {
|
|
2955
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2956
|
-
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2957
|
-
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2958
|
-
return INVALID;
|
|
2959
|
-
}
|
|
2960
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2961
|
-
if (!merged.valid) {
|
|
2962
|
-
addIssueToContext(ctx, {
|
|
2963
|
-
code: ZodIssueCode.invalid_intersection_types
|
|
2964
|
-
});
|
|
2965
|
-
return INVALID;
|
|
2966
|
-
}
|
|
2967
|
-
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
2968
|
-
status.dirty();
|
|
2969
|
-
}
|
|
2970
|
-
return { status: status.value, value: merged.data };
|
|
2971
|
-
};
|
|
2972
|
-
if (ctx.common.async) {
|
|
2973
|
-
return Promise.all([
|
|
2974
|
-
this._def.left._parseAsync({
|
|
2975
|
-
data: ctx.data,
|
|
2976
|
-
path: ctx.path,
|
|
2977
|
-
parent: ctx
|
|
2978
|
-
}),
|
|
2979
|
-
this._def.right._parseAsync({
|
|
2980
|
-
data: ctx.data,
|
|
2981
|
-
path: ctx.path,
|
|
2982
|
-
parent: ctx
|
|
2983
|
-
})
|
|
2984
|
-
]).then(([left, right]) => handleParsed(left, right));
|
|
2985
|
-
} else {
|
|
2986
|
-
return handleParsed(this._def.left._parseSync({
|
|
2987
|
-
data: ctx.data,
|
|
2988
|
-
path: ctx.path,
|
|
2989
|
-
parent: ctx
|
|
2990
|
-
}), this._def.right._parseSync({
|
|
2991
|
-
data: ctx.data,
|
|
2992
|
-
path: ctx.path,
|
|
2993
|
-
parent: ctx
|
|
2994
|
-
}));
|
|
2995
|
-
}
|
|
2996
|
-
}
|
|
2997
|
-
};
|
|
2998
|
-
ZodIntersection.create = (left, right, params) => {
|
|
2999
|
-
return new ZodIntersection({
|
|
3000
|
-
left,
|
|
3001
|
-
right,
|
|
3002
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3003
|
-
...processCreateParams(params)
|
|
3004
|
-
});
|
|
3005
|
-
};
|
|
3006
|
-
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3007
|
-
_parse(input) {
|
|
3008
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3009
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3010
|
-
addIssueToContext(ctx, {
|
|
3011
|
-
code: ZodIssueCode.invalid_type,
|
|
3012
|
-
expected: ZodParsedType.array,
|
|
3013
|
-
received: ctx.parsedType
|
|
3014
|
-
});
|
|
3015
|
-
return INVALID;
|
|
3016
|
-
}
|
|
3017
|
-
if (ctx.data.length < this._def.items.length) {
|
|
3018
|
-
addIssueToContext(ctx, {
|
|
3019
|
-
code: ZodIssueCode.too_small,
|
|
3020
|
-
minimum: this._def.items.length,
|
|
3021
|
-
inclusive: true,
|
|
3022
|
-
exact: false,
|
|
3023
|
-
type: "array"
|
|
3024
|
-
});
|
|
3025
|
-
return INVALID;
|
|
3026
|
-
}
|
|
3027
|
-
const rest = this._def.rest;
|
|
3028
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3029
|
-
addIssueToContext(ctx, {
|
|
3030
|
-
code: ZodIssueCode.too_big,
|
|
3031
|
-
maximum: this._def.items.length,
|
|
3032
|
-
inclusive: true,
|
|
3033
|
-
exact: false,
|
|
3034
|
-
type: "array"
|
|
3035
|
-
});
|
|
3036
|
-
status.dirty();
|
|
3037
|
-
}
|
|
3038
|
-
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3039
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3040
|
-
if (!schema)
|
|
3041
|
-
return null;
|
|
3042
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3043
|
-
}).filter((x) => !!x);
|
|
3044
|
-
if (ctx.common.async) {
|
|
3045
|
-
return Promise.all(items).then((results) => {
|
|
3046
|
-
return ParseStatus.mergeArray(status, results);
|
|
3047
|
-
});
|
|
3048
|
-
} else {
|
|
3049
|
-
return ParseStatus.mergeArray(status, items);
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
get items() {
|
|
3053
|
-
return this._def.items;
|
|
3054
|
-
}
|
|
3055
|
-
rest(rest) {
|
|
3056
|
-
return new _ZodTuple({
|
|
3057
|
-
...this._def,
|
|
3058
|
-
rest
|
|
3059
|
-
});
|
|
3060
|
-
}
|
|
3061
|
-
};
|
|
3062
|
-
ZodTuple.create = (schemas, params) => {
|
|
3063
|
-
if (!Array.isArray(schemas)) {
|
|
3064
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3065
|
-
}
|
|
3066
|
-
return new ZodTuple({
|
|
3067
|
-
items: schemas,
|
|
3068
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3069
|
-
rest: null,
|
|
3070
|
-
...processCreateParams(params)
|
|
3071
|
-
});
|
|
3072
|
-
};
|
|
3073
|
-
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3074
|
-
get keySchema() {
|
|
3075
|
-
return this._def.keyType;
|
|
3076
|
-
}
|
|
3077
|
-
get valueSchema() {
|
|
3078
|
-
return this._def.valueType;
|
|
3079
|
-
}
|
|
3080
|
-
_parse(input) {
|
|
3081
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3082
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3083
|
-
addIssueToContext(ctx, {
|
|
3084
|
-
code: ZodIssueCode.invalid_type,
|
|
3085
|
-
expected: ZodParsedType.object,
|
|
3086
|
-
received: ctx.parsedType
|
|
3087
|
-
});
|
|
3088
|
-
return INVALID;
|
|
3089
|
-
}
|
|
3090
|
-
const pairs = [];
|
|
3091
|
-
const keyType = this._def.keyType;
|
|
3092
|
-
const valueType = this._def.valueType;
|
|
3093
|
-
for (const key in ctx.data) {
|
|
3094
|
-
pairs.push({
|
|
3095
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3096
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3097
|
-
alwaysSet: key in ctx.data
|
|
3098
|
-
});
|
|
3099
|
-
}
|
|
3100
|
-
if (ctx.common.async) {
|
|
3101
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3102
|
-
} else {
|
|
3103
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3104
|
-
}
|
|
3105
|
-
}
|
|
3106
|
-
get element() {
|
|
3107
|
-
return this._def.valueType;
|
|
3108
|
-
}
|
|
3109
|
-
static create(first, second, third) {
|
|
3110
|
-
if (second instanceof ZodType) {
|
|
3111
|
-
return new _ZodRecord({
|
|
3112
|
-
keyType: first,
|
|
3113
|
-
valueType: second,
|
|
3114
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3115
|
-
...processCreateParams(third)
|
|
3116
|
-
});
|
|
3117
|
-
}
|
|
3118
|
-
return new _ZodRecord({
|
|
3119
|
-
keyType: ZodString.create(),
|
|
3120
|
-
valueType: first,
|
|
3121
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3122
|
-
...processCreateParams(second)
|
|
3123
|
-
});
|
|
3124
|
-
}
|
|
3125
|
-
};
|
|
3126
|
-
var ZodMap = class extends ZodType {
|
|
3127
|
-
get keySchema() {
|
|
3128
|
-
return this._def.keyType;
|
|
3129
|
-
}
|
|
3130
|
-
get valueSchema() {
|
|
3131
|
-
return this._def.valueType;
|
|
3132
|
-
}
|
|
3133
|
-
_parse(input) {
|
|
3134
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3135
|
-
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3136
|
-
addIssueToContext(ctx, {
|
|
3137
|
-
code: ZodIssueCode.invalid_type,
|
|
3138
|
-
expected: ZodParsedType.map,
|
|
3139
|
-
received: ctx.parsedType
|
|
3140
|
-
});
|
|
3141
|
-
return INVALID;
|
|
3142
|
-
}
|
|
3143
|
-
const keyType = this._def.keyType;
|
|
3144
|
-
const valueType = this._def.valueType;
|
|
3145
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3146
|
-
return {
|
|
3147
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3148
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3149
|
-
};
|
|
3150
|
-
});
|
|
3151
|
-
if (ctx.common.async) {
|
|
3152
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
3153
|
-
return Promise.resolve().then(async () => {
|
|
3154
|
-
for (const pair of pairs) {
|
|
3155
|
-
const key = await pair.key;
|
|
3156
|
-
const value = await pair.value;
|
|
3157
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3158
|
-
return INVALID;
|
|
3159
|
-
}
|
|
3160
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3161
|
-
status.dirty();
|
|
3162
|
-
}
|
|
3163
|
-
finalMap.set(key.value, value.value);
|
|
3164
|
-
}
|
|
3165
|
-
return { status: status.value, value: finalMap };
|
|
3166
|
-
});
|
|
3167
|
-
} else {
|
|
3168
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
3169
|
-
for (const pair of pairs) {
|
|
3170
|
-
const key = pair.key;
|
|
3171
|
-
const value = pair.value;
|
|
3172
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3173
|
-
return INVALID;
|
|
3174
|
-
}
|
|
3175
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3176
|
-
status.dirty();
|
|
3177
|
-
}
|
|
3178
|
-
finalMap.set(key.value, value.value);
|
|
3179
|
-
}
|
|
3180
|
-
return { status: status.value, value: finalMap };
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
};
|
|
3184
|
-
ZodMap.create = (keyType, valueType, params) => {
|
|
3185
|
-
return new ZodMap({
|
|
3186
|
-
valueType,
|
|
3187
|
-
keyType,
|
|
3188
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3189
|
-
...processCreateParams(params)
|
|
3190
|
-
});
|
|
3191
|
-
};
|
|
3192
|
-
var ZodSet = class _ZodSet extends ZodType {
|
|
3193
|
-
_parse(input) {
|
|
3194
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3195
|
-
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3196
|
-
addIssueToContext(ctx, {
|
|
3197
|
-
code: ZodIssueCode.invalid_type,
|
|
3198
|
-
expected: ZodParsedType.set,
|
|
3199
|
-
received: ctx.parsedType
|
|
3200
|
-
});
|
|
3201
|
-
return INVALID;
|
|
3202
|
-
}
|
|
3203
|
-
const def = this._def;
|
|
3204
|
-
if (def.minSize !== null) {
|
|
3205
|
-
if (ctx.data.size < def.minSize.value) {
|
|
3206
|
-
addIssueToContext(ctx, {
|
|
3207
|
-
code: ZodIssueCode.too_small,
|
|
3208
|
-
minimum: def.minSize.value,
|
|
3209
|
-
type: "set",
|
|
3210
|
-
inclusive: true,
|
|
3211
|
-
exact: false,
|
|
3212
|
-
message: def.minSize.message
|
|
3213
|
-
});
|
|
3214
|
-
status.dirty();
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3217
|
-
if (def.maxSize !== null) {
|
|
3218
|
-
if (ctx.data.size > def.maxSize.value) {
|
|
3219
|
-
addIssueToContext(ctx, {
|
|
3220
|
-
code: ZodIssueCode.too_big,
|
|
3221
|
-
maximum: def.maxSize.value,
|
|
3222
|
-
type: "set",
|
|
3223
|
-
inclusive: true,
|
|
3224
|
-
exact: false,
|
|
3225
|
-
message: def.maxSize.message
|
|
3226
|
-
});
|
|
3227
|
-
status.dirty();
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
const valueType = this._def.valueType;
|
|
3231
|
-
function finalizeSet(elements2) {
|
|
3232
|
-
const parsedSet = /* @__PURE__ */ new Set();
|
|
3233
|
-
for (const element of elements2) {
|
|
3234
|
-
if (element.status === "aborted")
|
|
3235
|
-
return INVALID;
|
|
3236
|
-
if (element.status === "dirty")
|
|
3237
|
-
status.dirty();
|
|
3238
|
-
parsedSet.add(element.value);
|
|
3239
|
-
}
|
|
3240
|
-
return { status: status.value, value: parsedSet };
|
|
3241
|
-
}
|
|
3242
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3243
|
-
if (ctx.common.async) {
|
|
3244
|
-
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3245
|
-
} else {
|
|
3246
|
-
return finalizeSet(elements);
|
|
3247
|
-
}
|
|
3248
|
-
}
|
|
3249
|
-
min(minSize, message) {
|
|
3250
|
-
return new _ZodSet({
|
|
3251
|
-
...this._def,
|
|
3252
|
-
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3253
|
-
});
|
|
3254
|
-
}
|
|
3255
|
-
max(maxSize, message) {
|
|
3256
|
-
return new _ZodSet({
|
|
3257
|
-
...this._def,
|
|
3258
|
-
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3259
|
-
});
|
|
3260
|
-
}
|
|
3261
|
-
size(size, message) {
|
|
3262
|
-
return this.min(size, message).max(size, message);
|
|
3263
|
-
}
|
|
3264
|
-
nonempty(message) {
|
|
3265
|
-
return this.min(1, message);
|
|
3266
|
-
}
|
|
3267
|
-
};
|
|
3268
|
-
ZodSet.create = (valueType, params) => {
|
|
3269
|
-
return new ZodSet({
|
|
3270
|
-
valueType,
|
|
3271
|
-
minSize: null,
|
|
3272
|
-
maxSize: null,
|
|
3273
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3274
|
-
...processCreateParams(params)
|
|
3275
|
-
});
|
|
3276
|
-
};
|
|
3277
|
-
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3278
|
-
constructor() {
|
|
3279
|
-
super(...arguments);
|
|
3280
|
-
this.validate = this.implement;
|
|
3281
|
-
}
|
|
3282
|
-
_parse(input) {
|
|
3283
|
-
const { ctx } = this._processInputParams(input);
|
|
3284
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3285
|
-
addIssueToContext(ctx, {
|
|
3286
|
-
code: ZodIssueCode.invalid_type,
|
|
3287
|
-
expected: ZodParsedType.function,
|
|
3288
|
-
received: ctx.parsedType
|
|
3289
|
-
});
|
|
3290
|
-
return INVALID;
|
|
3291
|
-
}
|
|
3292
|
-
function makeArgsIssue(args, error) {
|
|
3293
|
-
return makeIssue({
|
|
3294
|
-
data: args,
|
|
3295
|
-
path: ctx.path,
|
|
3296
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3297
|
-
issueData: {
|
|
3298
|
-
code: ZodIssueCode.invalid_arguments,
|
|
3299
|
-
argumentsError: error
|
|
3300
|
-
}
|
|
3301
|
-
});
|
|
3302
|
-
}
|
|
3303
|
-
function makeReturnsIssue(returns, error) {
|
|
3304
|
-
return makeIssue({
|
|
3305
|
-
data: returns,
|
|
3306
|
-
path: ctx.path,
|
|
3307
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3308
|
-
issueData: {
|
|
3309
|
-
code: ZodIssueCode.invalid_return_type,
|
|
3310
|
-
returnTypeError: error
|
|
3311
|
-
}
|
|
3312
|
-
});
|
|
3313
|
-
}
|
|
3314
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3315
|
-
const fn = ctx.data;
|
|
3316
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
3317
|
-
const me = this;
|
|
3318
|
-
return OK(async function(...args) {
|
|
3319
|
-
const error = new ZodError([]);
|
|
3320
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3321
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
3322
|
-
throw error;
|
|
3323
|
-
});
|
|
3324
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3325
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3326
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
3327
|
-
throw error;
|
|
3328
|
-
});
|
|
3329
|
-
return parsedReturns;
|
|
3330
|
-
});
|
|
3331
|
-
} else {
|
|
3332
|
-
const me = this;
|
|
3333
|
-
return OK(function(...args) {
|
|
3334
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3335
|
-
if (!parsedArgs.success) {
|
|
3336
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3337
|
-
}
|
|
3338
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3339
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3340
|
-
if (!parsedReturns.success) {
|
|
3341
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3342
|
-
}
|
|
3343
|
-
return parsedReturns.data;
|
|
3344
|
-
});
|
|
3345
|
-
}
|
|
3346
|
-
}
|
|
3347
|
-
parameters() {
|
|
3348
|
-
return this._def.args;
|
|
3349
|
-
}
|
|
3350
|
-
returnType() {
|
|
3351
|
-
return this._def.returns;
|
|
3352
|
-
}
|
|
3353
|
-
args(...items) {
|
|
3354
|
-
return new _ZodFunction({
|
|
3355
|
-
...this._def,
|
|
3356
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3357
|
-
});
|
|
3358
|
-
}
|
|
3359
|
-
returns(returnType) {
|
|
3360
|
-
return new _ZodFunction({
|
|
3361
|
-
...this._def,
|
|
3362
|
-
returns: returnType
|
|
3363
|
-
});
|
|
3364
|
-
}
|
|
3365
|
-
implement(func) {
|
|
3366
|
-
const validatedFunc = this.parse(func);
|
|
3367
|
-
return validatedFunc;
|
|
3368
|
-
}
|
|
3369
|
-
strictImplement(func) {
|
|
3370
|
-
const validatedFunc = this.parse(func);
|
|
3371
|
-
return validatedFunc;
|
|
3372
|
-
}
|
|
3373
|
-
static create(args, returns, params) {
|
|
3374
|
-
return new _ZodFunction({
|
|
3375
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3376
|
-
returns: returns || ZodUnknown.create(),
|
|
3377
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3378
|
-
...processCreateParams(params)
|
|
3379
|
-
});
|
|
3380
|
-
}
|
|
3381
|
-
};
|
|
3382
|
-
var ZodLazy = class extends ZodType {
|
|
3383
|
-
get schema() {
|
|
3384
|
-
return this._def.getter();
|
|
3385
|
-
}
|
|
3386
|
-
_parse(input) {
|
|
3387
|
-
const { ctx } = this._processInputParams(input);
|
|
3388
|
-
const lazySchema = this._def.getter();
|
|
3389
|
-
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3390
|
-
}
|
|
3391
|
-
};
|
|
3392
|
-
ZodLazy.create = (getter, params) => {
|
|
3393
|
-
return new ZodLazy({
|
|
3394
|
-
getter,
|
|
3395
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3396
|
-
...processCreateParams(params)
|
|
3397
|
-
});
|
|
3398
|
-
};
|
|
3399
|
-
var ZodLiteral = class extends ZodType {
|
|
3400
|
-
_parse(input) {
|
|
3401
|
-
if (input.data !== this._def.value) {
|
|
3402
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3403
|
-
addIssueToContext(ctx, {
|
|
3404
|
-
received: ctx.data,
|
|
3405
|
-
code: ZodIssueCode.invalid_literal,
|
|
3406
|
-
expected: this._def.value
|
|
3407
|
-
});
|
|
3408
|
-
return INVALID;
|
|
3409
|
-
}
|
|
3410
|
-
return { status: "valid", value: input.data };
|
|
3411
|
-
}
|
|
3412
|
-
get value() {
|
|
3413
|
-
return this._def.value;
|
|
3414
|
-
}
|
|
3415
|
-
};
|
|
3416
|
-
ZodLiteral.create = (value, params) => {
|
|
3417
|
-
return new ZodLiteral({
|
|
3418
|
-
value,
|
|
3419
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3420
|
-
...processCreateParams(params)
|
|
3421
|
-
});
|
|
3422
|
-
};
|
|
3423
|
-
function createZodEnum(values, params) {
|
|
3424
|
-
return new ZodEnum({
|
|
3425
|
-
values,
|
|
3426
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3427
|
-
...processCreateParams(params)
|
|
3428
|
-
});
|
|
3429
|
-
}
|
|
3430
|
-
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3431
|
-
_parse(input) {
|
|
3432
|
-
if (typeof input.data !== "string") {
|
|
3433
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3434
|
-
const expectedValues = this._def.values;
|
|
3435
|
-
addIssueToContext(ctx, {
|
|
3436
|
-
expected: util.joinValues(expectedValues),
|
|
3437
|
-
received: ctx.parsedType,
|
|
3438
|
-
code: ZodIssueCode.invalid_type
|
|
3439
|
-
});
|
|
3440
|
-
return INVALID;
|
|
3441
|
-
}
|
|
3442
|
-
if (!this._cache) {
|
|
3443
|
-
this._cache = new Set(this._def.values);
|
|
3444
|
-
}
|
|
3445
|
-
if (!this._cache.has(input.data)) {
|
|
3446
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3447
|
-
const expectedValues = this._def.values;
|
|
3448
|
-
addIssueToContext(ctx, {
|
|
3449
|
-
received: ctx.data,
|
|
3450
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
3451
|
-
options: expectedValues
|
|
3452
|
-
});
|
|
3453
|
-
return INVALID;
|
|
3454
|
-
}
|
|
3455
|
-
return OK(input.data);
|
|
3456
|
-
}
|
|
3457
|
-
get options() {
|
|
3458
|
-
return this._def.values;
|
|
3459
|
-
}
|
|
3460
|
-
get enum() {
|
|
3461
|
-
const enumValues = {};
|
|
3462
|
-
for (const val of this._def.values) {
|
|
3463
|
-
enumValues[val] = val;
|
|
3464
|
-
}
|
|
3465
|
-
return enumValues;
|
|
3466
|
-
}
|
|
3467
|
-
get Values() {
|
|
3468
|
-
const enumValues = {};
|
|
3469
|
-
for (const val of this._def.values) {
|
|
3470
|
-
enumValues[val] = val;
|
|
3471
|
-
}
|
|
3472
|
-
return enumValues;
|
|
3473
|
-
}
|
|
3474
|
-
get Enum() {
|
|
3475
|
-
const enumValues = {};
|
|
3476
|
-
for (const val of this._def.values) {
|
|
3477
|
-
enumValues[val] = val;
|
|
3478
|
-
}
|
|
3479
|
-
return enumValues;
|
|
3480
|
-
}
|
|
3481
|
-
extract(values, newDef = this._def) {
|
|
3482
|
-
return _ZodEnum.create(values, {
|
|
3483
|
-
...this._def,
|
|
3484
|
-
...newDef
|
|
3485
|
-
});
|
|
3486
|
-
}
|
|
3487
|
-
exclude(values, newDef = this._def) {
|
|
3488
|
-
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3489
|
-
...this._def,
|
|
3490
|
-
...newDef
|
|
3491
|
-
});
|
|
3492
|
-
}
|
|
3493
|
-
};
|
|
3494
|
-
ZodEnum.create = createZodEnum;
|
|
3495
|
-
var ZodNativeEnum = class extends ZodType {
|
|
3496
|
-
_parse(input) {
|
|
3497
|
-
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3498
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3499
|
-
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3500
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3501
|
-
addIssueToContext(ctx, {
|
|
3502
|
-
expected: util.joinValues(expectedValues),
|
|
3503
|
-
received: ctx.parsedType,
|
|
3504
|
-
code: ZodIssueCode.invalid_type
|
|
3505
|
-
});
|
|
3506
|
-
return INVALID;
|
|
3507
|
-
}
|
|
3508
|
-
if (!this._cache) {
|
|
3509
|
-
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3510
|
-
}
|
|
3511
|
-
if (!this._cache.has(input.data)) {
|
|
3512
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3513
|
-
addIssueToContext(ctx, {
|
|
3514
|
-
received: ctx.data,
|
|
3515
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
3516
|
-
options: expectedValues
|
|
3517
|
-
});
|
|
3518
|
-
return INVALID;
|
|
3519
|
-
}
|
|
3520
|
-
return OK(input.data);
|
|
3521
|
-
}
|
|
3522
|
-
get enum() {
|
|
3523
|
-
return this._def.values;
|
|
3524
|
-
}
|
|
3525
|
-
};
|
|
3526
|
-
ZodNativeEnum.create = (values, params) => {
|
|
3527
|
-
return new ZodNativeEnum({
|
|
3528
|
-
values,
|
|
3529
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3530
|
-
...processCreateParams(params)
|
|
3531
|
-
});
|
|
3532
|
-
};
|
|
3533
|
-
var ZodPromise = class extends ZodType {
|
|
3534
|
-
unwrap() {
|
|
3535
|
-
return this._def.type;
|
|
3536
|
-
}
|
|
3537
|
-
_parse(input) {
|
|
3538
|
-
const { ctx } = this._processInputParams(input);
|
|
3539
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3540
|
-
addIssueToContext(ctx, {
|
|
3541
|
-
code: ZodIssueCode.invalid_type,
|
|
3542
|
-
expected: ZodParsedType.promise,
|
|
3543
|
-
received: ctx.parsedType
|
|
3544
|
-
});
|
|
3545
|
-
return INVALID;
|
|
3546
|
-
}
|
|
3547
|
-
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3548
|
-
return OK(promisified.then((data) => {
|
|
3549
|
-
return this._def.type.parseAsync(data, {
|
|
3550
|
-
path: ctx.path,
|
|
3551
|
-
errorMap: ctx.common.contextualErrorMap
|
|
3552
|
-
});
|
|
3553
|
-
}));
|
|
3554
|
-
}
|
|
3555
|
-
};
|
|
3556
|
-
ZodPromise.create = (schema, params) => {
|
|
3557
|
-
return new ZodPromise({
|
|
3558
|
-
type: schema,
|
|
3559
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3560
|
-
...processCreateParams(params)
|
|
3561
|
-
});
|
|
3562
|
-
};
|
|
3563
|
-
var ZodEffects = class extends ZodType {
|
|
3564
|
-
innerType() {
|
|
3565
|
-
return this._def.schema;
|
|
3566
|
-
}
|
|
3567
|
-
sourceType() {
|
|
3568
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3569
|
-
}
|
|
3570
|
-
_parse(input) {
|
|
3571
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3572
|
-
const effect = this._def.effect || null;
|
|
3573
|
-
const checkCtx = {
|
|
3574
|
-
addIssue: (arg) => {
|
|
3575
|
-
addIssueToContext(ctx, arg);
|
|
3576
|
-
if (arg.fatal) {
|
|
3577
|
-
status.abort();
|
|
3578
|
-
} else {
|
|
3579
|
-
status.dirty();
|
|
3580
|
-
}
|
|
3581
|
-
},
|
|
3582
|
-
get path() {
|
|
3583
|
-
return ctx.path;
|
|
3584
|
-
}
|
|
3585
|
-
};
|
|
3586
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3587
|
-
if (effect.type === "preprocess") {
|
|
3588
|
-
const processed = effect.transform(ctx.data, checkCtx);
|
|
3589
|
-
if (ctx.common.async) {
|
|
3590
|
-
return Promise.resolve(processed).then(async (processed2) => {
|
|
3591
|
-
if (status.value === "aborted")
|
|
3592
|
-
return INVALID;
|
|
3593
|
-
const result = await this._def.schema._parseAsync({
|
|
3594
|
-
data: processed2,
|
|
3595
|
-
path: ctx.path,
|
|
3596
|
-
parent: ctx
|
|
3597
|
-
});
|
|
3598
|
-
if (result.status === "aborted")
|
|
3599
|
-
return INVALID;
|
|
3600
|
-
if (result.status === "dirty")
|
|
3601
|
-
return DIRTY(result.value);
|
|
3602
|
-
if (status.value === "dirty")
|
|
3603
|
-
return DIRTY(result.value);
|
|
3604
|
-
return result;
|
|
3605
|
-
});
|
|
3606
|
-
} else {
|
|
3607
|
-
if (status.value === "aborted")
|
|
3608
|
-
return INVALID;
|
|
3609
|
-
const result = this._def.schema._parseSync({
|
|
3610
|
-
data: processed,
|
|
3611
|
-
path: ctx.path,
|
|
3612
|
-
parent: ctx
|
|
3613
|
-
});
|
|
3614
|
-
if (result.status === "aborted")
|
|
3615
|
-
return INVALID;
|
|
3616
|
-
if (result.status === "dirty")
|
|
3617
|
-
return DIRTY(result.value);
|
|
3618
|
-
if (status.value === "dirty")
|
|
3619
|
-
return DIRTY(result.value);
|
|
3620
|
-
return result;
|
|
3621
|
-
}
|
|
3622
|
-
}
|
|
3623
|
-
if (effect.type === "refinement") {
|
|
3624
|
-
const executeRefinement = (acc) => {
|
|
3625
|
-
const result = effect.refinement(acc, checkCtx);
|
|
3626
|
-
if (ctx.common.async) {
|
|
3627
|
-
return Promise.resolve(result);
|
|
3628
|
-
}
|
|
3629
|
-
if (result instanceof Promise) {
|
|
3630
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3631
|
-
}
|
|
3632
|
-
return acc;
|
|
3633
|
-
};
|
|
3634
|
-
if (ctx.common.async === false) {
|
|
3635
|
-
const inner = this._def.schema._parseSync({
|
|
3636
|
-
data: ctx.data,
|
|
3637
|
-
path: ctx.path,
|
|
3638
|
-
parent: ctx
|
|
3639
|
-
});
|
|
3640
|
-
if (inner.status === "aborted")
|
|
3641
|
-
return INVALID;
|
|
3642
|
-
if (inner.status === "dirty")
|
|
3643
|
-
status.dirty();
|
|
3644
|
-
executeRefinement(inner.value);
|
|
3645
|
-
return { status: status.value, value: inner.value };
|
|
3646
|
-
} else {
|
|
3647
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3648
|
-
if (inner.status === "aborted")
|
|
3649
|
-
return INVALID;
|
|
3650
|
-
if (inner.status === "dirty")
|
|
3651
|
-
status.dirty();
|
|
3652
|
-
return executeRefinement(inner.value).then(() => {
|
|
3653
|
-
return { status: status.value, value: inner.value };
|
|
3654
|
-
});
|
|
3655
|
-
});
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
if (effect.type === "transform") {
|
|
3659
|
-
if (ctx.common.async === false) {
|
|
3660
|
-
const base = this._def.schema._parseSync({
|
|
3661
|
-
data: ctx.data,
|
|
3662
|
-
path: ctx.path,
|
|
3663
|
-
parent: ctx
|
|
3664
|
-
});
|
|
3665
|
-
if (!isValid(base))
|
|
3666
|
-
return INVALID;
|
|
3667
|
-
const result = effect.transform(base.value, checkCtx);
|
|
3668
|
-
if (result instanceof Promise) {
|
|
3669
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3670
|
-
}
|
|
3671
|
-
return { status: status.value, value: result };
|
|
3672
|
-
} else {
|
|
3673
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
3674
|
-
if (!isValid(base))
|
|
3675
|
-
return INVALID;
|
|
3676
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3677
|
-
status: status.value,
|
|
3678
|
-
value: result
|
|
3679
|
-
}));
|
|
3680
|
-
});
|
|
3681
|
-
}
|
|
3682
|
-
}
|
|
3683
|
-
util.assertNever(effect);
|
|
3684
|
-
}
|
|
3685
|
-
};
|
|
3686
|
-
ZodEffects.create = (schema, effect, params) => {
|
|
3687
|
-
return new ZodEffects({
|
|
3688
|
-
schema,
|
|
3689
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3690
|
-
effect,
|
|
3691
|
-
...processCreateParams(params)
|
|
3692
|
-
});
|
|
3693
|
-
};
|
|
3694
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3695
|
-
return new ZodEffects({
|
|
3696
|
-
schema,
|
|
3697
|
-
effect: { type: "preprocess", transform: preprocess },
|
|
3698
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3699
|
-
...processCreateParams(params)
|
|
3700
|
-
});
|
|
3701
|
-
};
|
|
3702
|
-
var ZodOptional = class extends ZodType {
|
|
3703
|
-
_parse(input) {
|
|
3704
|
-
const parsedType = this._getType(input);
|
|
3705
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
3706
|
-
return OK(void 0);
|
|
3707
|
-
}
|
|
3708
|
-
return this._def.innerType._parse(input);
|
|
3709
|
-
}
|
|
3710
|
-
unwrap() {
|
|
3711
|
-
return this._def.innerType;
|
|
3712
|
-
}
|
|
3713
|
-
};
|
|
3714
|
-
ZodOptional.create = (type, params) => {
|
|
3715
|
-
return new ZodOptional({
|
|
3716
|
-
innerType: type,
|
|
3717
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3718
|
-
...processCreateParams(params)
|
|
3719
|
-
});
|
|
3720
|
-
};
|
|
3721
|
-
var ZodNullable = class extends ZodType {
|
|
3722
|
-
_parse(input) {
|
|
3723
|
-
const parsedType = this._getType(input);
|
|
3724
|
-
if (parsedType === ZodParsedType.null) {
|
|
3725
|
-
return OK(null);
|
|
3726
|
-
}
|
|
3727
|
-
return this._def.innerType._parse(input);
|
|
3728
|
-
}
|
|
3729
|
-
unwrap() {
|
|
3730
|
-
return this._def.innerType;
|
|
3731
|
-
}
|
|
3732
|
-
};
|
|
3733
|
-
ZodNullable.create = (type, params) => {
|
|
3734
|
-
return new ZodNullable({
|
|
3735
|
-
innerType: type,
|
|
3736
|
-
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3737
|
-
...processCreateParams(params)
|
|
3738
|
-
});
|
|
3739
|
-
};
|
|
3740
|
-
var ZodDefault = class extends ZodType {
|
|
3741
|
-
_parse(input) {
|
|
3742
|
-
const { ctx } = this._processInputParams(input);
|
|
3743
|
-
let data = ctx.data;
|
|
3744
|
-
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3745
|
-
data = this._def.defaultValue();
|
|
3746
|
-
}
|
|
3747
|
-
return this._def.innerType._parse({
|
|
3748
|
-
data,
|
|
3749
|
-
path: ctx.path,
|
|
3750
|
-
parent: ctx
|
|
3751
|
-
});
|
|
3752
|
-
}
|
|
3753
|
-
removeDefault() {
|
|
3754
|
-
return this._def.innerType;
|
|
3755
|
-
}
|
|
3756
|
-
};
|
|
3757
|
-
ZodDefault.create = (type, params) => {
|
|
3758
|
-
return new ZodDefault({
|
|
3759
|
-
innerType: type,
|
|
3760
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3761
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3762
|
-
...processCreateParams(params)
|
|
3763
|
-
});
|
|
3764
|
-
};
|
|
3765
|
-
var ZodCatch = class extends ZodType {
|
|
3766
|
-
_parse(input) {
|
|
3767
|
-
const { ctx } = this._processInputParams(input);
|
|
3768
|
-
const newCtx = {
|
|
3769
|
-
...ctx,
|
|
3770
|
-
common: {
|
|
3771
|
-
...ctx.common,
|
|
3772
|
-
issues: []
|
|
3773
|
-
}
|
|
3774
|
-
};
|
|
3775
|
-
const result = this._def.innerType._parse({
|
|
3776
|
-
data: newCtx.data,
|
|
3777
|
-
path: newCtx.path,
|
|
3778
|
-
parent: {
|
|
3779
|
-
...newCtx
|
|
3780
|
-
}
|
|
3781
|
-
});
|
|
3782
|
-
if (isAsync(result)) {
|
|
3783
|
-
return result.then((result2) => {
|
|
3784
|
-
return {
|
|
3785
|
-
status: "valid",
|
|
3786
|
-
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
3787
|
-
get error() {
|
|
3788
|
-
return new ZodError(newCtx.common.issues);
|
|
3789
|
-
},
|
|
3790
|
-
input: newCtx.data
|
|
3791
|
-
})
|
|
3792
|
-
};
|
|
3793
|
-
});
|
|
3794
|
-
} else {
|
|
3795
|
-
return {
|
|
3796
|
-
status: "valid",
|
|
3797
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3798
|
-
get error() {
|
|
3799
|
-
return new ZodError(newCtx.common.issues);
|
|
3800
|
-
},
|
|
3801
|
-
input: newCtx.data
|
|
3802
|
-
})
|
|
3803
|
-
};
|
|
3804
|
-
}
|
|
3805
|
-
}
|
|
3806
|
-
removeCatch() {
|
|
3807
|
-
return this._def.innerType;
|
|
3808
|
-
}
|
|
3809
|
-
};
|
|
3810
|
-
ZodCatch.create = (type, params) => {
|
|
3811
|
-
return new ZodCatch({
|
|
3812
|
-
innerType: type,
|
|
3813
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3814
|
-
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3815
|
-
...processCreateParams(params)
|
|
3816
|
-
});
|
|
3817
|
-
};
|
|
3818
|
-
var ZodNaN = class extends ZodType {
|
|
3819
|
-
_parse(input) {
|
|
3820
|
-
const parsedType = this._getType(input);
|
|
3821
|
-
if (parsedType !== ZodParsedType.nan) {
|
|
3822
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3823
|
-
addIssueToContext(ctx, {
|
|
3824
|
-
code: ZodIssueCode.invalid_type,
|
|
3825
|
-
expected: ZodParsedType.nan,
|
|
3826
|
-
received: ctx.parsedType
|
|
3827
|
-
});
|
|
3828
|
-
return INVALID;
|
|
3829
|
-
}
|
|
3830
|
-
return { status: "valid", value: input.data };
|
|
3831
|
-
}
|
|
3832
|
-
};
|
|
3833
|
-
ZodNaN.create = (params) => {
|
|
3834
|
-
return new ZodNaN({
|
|
3835
|
-
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3836
|
-
...processCreateParams(params)
|
|
3837
|
-
});
|
|
3838
|
-
};
|
|
3839
|
-
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
3840
|
-
var ZodBranded = class extends ZodType {
|
|
3841
|
-
_parse(input) {
|
|
3842
|
-
const { ctx } = this._processInputParams(input);
|
|
3843
|
-
const data = ctx.data;
|
|
3844
|
-
return this._def.type._parse({
|
|
3845
|
-
data,
|
|
3846
|
-
path: ctx.path,
|
|
3847
|
-
parent: ctx
|
|
3848
|
-
});
|
|
3849
|
-
}
|
|
3850
|
-
unwrap() {
|
|
3851
|
-
return this._def.type;
|
|
3852
|
-
}
|
|
3853
|
-
};
|
|
3854
|
-
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
3855
|
-
_parse(input) {
|
|
3856
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3857
|
-
if (ctx.common.async) {
|
|
3858
|
-
const handleAsync = async () => {
|
|
3859
|
-
const inResult = await this._def.in._parseAsync({
|
|
3860
|
-
data: ctx.data,
|
|
3861
|
-
path: ctx.path,
|
|
3862
|
-
parent: ctx
|
|
3863
|
-
});
|
|
3864
|
-
if (inResult.status === "aborted")
|
|
3865
|
-
return INVALID;
|
|
3866
|
-
if (inResult.status === "dirty") {
|
|
3867
|
-
status.dirty();
|
|
3868
|
-
return DIRTY(inResult.value);
|
|
3869
|
-
} else {
|
|
3870
|
-
return this._def.out._parseAsync({
|
|
3871
|
-
data: inResult.value,
|
|
3872
|
-
path: ctx.path,
|
|
3873
|
-
parent: ctx
|
|
3874
|
-
});
|
|
3875
|
-
}
|
|
3876
|
-
};
|
|
3877
|
-
return handleAsync();
|
|
3878
|
-
} else {
|
|
3879
|
-
const inResult = this._def.in._parseSync({
|
|
3880
|
-
data: ctx.data,
|
|
3881
|
-
path: ctx.path,
|
|
3882
|
-
parent: ctx
|
|
3883
|
-
});
|
|
3884
|
-
if (inResult.status === "aborted")
|
|
3885
|
-
return INVALID;
|
|
3886
|
-
if (inResult.status === "dirty") {
|
|
3887
|
-
status.dirty();
|
|
3888
|
-
return {
|
|
3889
|
-
status: "dirty",
|
|
3890
|
-
value: inResult.value
|
|
3891
|
-
};
|
|
3892
|
-
} else {
|
|
3893
|
-
return this._def.out._parseSync({
|
|
3894
|
-
data: inResult.value,
|
|
3895
|
-
path: ctx.path,
|
|
3896
|
-
parent: ctx
|
|
3897
|
-
});
|
|
3898
|
-
}
|
|
3899
|
-
}
|
|
3900
|
-
}
|
|
3901
|
-
static create(a, b) {
|
|
3902
|
-
return new _ZodPipeline({
|
|
3903
|
-
in: a,
|
|
3904
|
-
out: b,
|
|
3905
|
-
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3906
|
-
});
|
|
3907
|
-
}
|
|
3908
|
-
};
|
|
3909
|
-
var ZodReadonly = class extends ZodType {
|
|
3910
|
-
_parse(input) {
|
|
3911
|
-
const result = this._def.innerType._parse(input);
|
|
3912
|
-
const freeze = (data) => {
|
|
3913
|
-
if (isValid(data)) {
|
|
3914
|
-
data.value = Object.freeze(data.value);
|
|
3915
|
-
}
|
|
3916
|
-
return data;
|
|
3917
|
-
};
|
|
3918
|
-
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3919
|
-
}
|
|
3920
|
-
unwrap() {
|
|
3921
|
-
return this._def.innerType;
|
|
3922
|
-
}
|
|
3923
|
-
};
|
|
3924
|
-
ZodReadonly.create = (type, params) => {
|
|
3925
|
-
return new ZodReadonly({
|
|
3926
|
-
innerType: type,
|
|
3927
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3928
|
-
...processCreateParams(params)
|
|
3929
|
-
});
|
|
3930
|
-
};
|
|
3931
|
-
function cleanParams(params, data) {
|
|
3932
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3933
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3934
|
-
return p2;
|
|
3935
|
-
}
|
|
3936
|
-
function custom(check, _params = {}, fatal) {
|
|
3937
|
-
if (check)
|
|
3938
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
3939
|
-
const r = check(data);
|
|
3940
|
-
if (r instanceof Promise) {
|
|
3941
|
-
return r.then((r2) => {
|
|
3942
|
-
if (!r2) {
|
|
3943
|
-
const params = cleanParams(_params, data);
|
|
3944
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
3945
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3946
|
-
}
|
|
3947
|
-
});
|
|
3948
|
-
}
|
|
3949
|
-
if (!r) {
|
|
3950
|
-
const params = cleanParams(_params, data);
|
|
3951
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
3952
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3953
|
-
}
|
|
3954
|
-
return;
|
|
3955
|
-
});
|
|
3956
|
-
return ZodAny.create();
|
|
3957
|
-
}
|
|
3958
|
-
var late = {
|
|
3959
|
-
object: ZodObject.lazycreate
|
|
3960
|
-
};
|
|
3961
|
-
var ZodFirstPartyTypeKind;
|
|
3962
|
-
(function(ZodFirstPartyTypeKind2) {
|
|
3963
|
-
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
3964
|
-
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
3965
|
-
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
3966
|
-
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
3967
|
-
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
3968
|
-
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
3969
|
-
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
3970
|
-
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
3971
|
-
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
3972
|
-
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
3973
|
-
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
3974
|
-
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
3975
|
-
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
3976
|
-
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
3977
|
-
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
3978
|
-
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
3979
|
-
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3980
|
-
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
3981
|
-
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
3982
|
-
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
3983
|
-
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
3984
|
-
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
3985
|
-
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
3986
|
-
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
3987
|
-
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
3988
|
-
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
3989
|
-
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
3990
|
-
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3991
|
-
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
3992
|
-
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
3993
|
-
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
3994
|
-
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
3995
|
-
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
3996
|
-
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
3997
|
-
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
3998
|
-
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
3999
|
-
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4000
|
-
var instanceOfType = (cls, params = {
|
|
4001
|
-
message: `Input not instance of ${cls.name}`
|
|
4002
|
-
}) => custom((data) => data instanceof cls, params);
|
|
4003
|
-
var stringType = ZodString.create;
|
|
4004
|
-
var numberType = ZodNumber.create;
|
|
4005
|
-
var nanType = ZodNaN.create;
|
|
4006
|
-
var bigIntType = ZodBigInt.create;
|
|
4007
|
-
var booleanType = ZodBoolean.create;
|
|
4008
|
-
var dateType = ZodDate.create;
|
|
4009
|
-
var symbolType = ZodSymbol.create;
|
|
4010
|
-
var undefinedType = ZodUndefined.create;
|
|
4011
|
-
var nullType = ZodNull.create;
|
|
4012
|
-
var anyType = ZodAny.create;
|
|
4013
|
-
var unknownType = ZodUnknown.create;
|
|
4014
|
-
var neverType = ZodNever.create;
|
|
4015
|
-
var voidType = ZodVoid.create;
|
|
4016
|
-
var arrayType = ZodArray.create;
|
|
4017
|
-
var objectType = ZodObject.create;
|
|
4018
|
-
var strictObjectType = ZodObject.strictCreate;
|
|
4019
|
-
var unionType = ZodUnion.create;
|
|
4020
|
-
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4021
|
-
var intersectionType = ZodIntersection.create;
|
|
4022
|
-
var tupleType = ZodTuple.create;
|
|
4023
|
-
var recordType = ZodRecord.create;
|
|
4024
|
-
var mapType = ZodMap.create;
|
|
4025
|
-
var setType = ZodSet.create;
|
|
4026
|
-
var functionType = ZodFunction.create;
|
|
4027
|
-
var lazyType = ZodLazy.create;
|
|
4028
|
-
var literalType = ZodLiteral.create;
|
|
4029
|
-
var enumType = ZodEnum.create;
|
|
4030
|
-
var nativeEnumType = ZodNativeEnum.create;
|
|
4031
|
-
var promiseType = ZodPromise.create;
|
|
4032
|
-
var effectsType = ZodEffects.create;
|
|
4033
|
-
var optionalType = ZodOptional.create;
|
|
4034
|
-
var nullableType = ZodNullable.create;
|
|
4035
|
-
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4036
|
-
var pipelineType = ZodPipeline.create;
|
|
4037
|
-
var ostring = () => stringType().optional();
|
|
4038
|
-
var onumber = () => numberType().optional();
|
|
4039
|
-
var oboolean = () => booleanType().optional();
|
|
4040
|
-
var coerce = {
|
|
4041
|
-
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4042
|
-
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4043
|
-
boolean: ((arg) => ZodBoolean.create({
|
|
4044
|
-
...arg,
|
|
4045
|
-
coerce: true
|
|
4046
|
-
})),
|
|
4047
|
-
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4048
|
-
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4049
|
-
};
|
|
4050
|
-
var NEVER = INVALID;
|
|
4051
|
-
|
|
4052
|
-
// src/prompts.ts
|
|
4053
|
-
var WORKFLOW_TYPES2 = WORKFLOW_TYPES;
|
|
4054
|
-
var MEDIA_STYLE_ENUM = ["text", "images", "video"];
|
|
4055
|
-
function coercePromptArgs(args) {
|
|
4056
|
-
return {
|
|
4057
|
-
...args,
|
|
4058
|
-
question_count: args.question_count ? parseInt(args.question_count, 10) : void 0,
|
|
4059
|
-
needs_consent: args.needs_consent != null ? args.needs_consent === "true" : void 0,
|
|
4060
|
-
anonymous: args.anonymous != null ? args.anonymous === "true" : void 0,
|
|
4061
|
-
needs_contact: args.needs_contact != null ? args.needs_contact === "true" : void 0
|
|
4062
|
-
};
|
|
4063
|
-
}
|
|
4064
|
-
function buildDiscovery(params, args, authMode = "authenticated") {
|
|
4065
|
-
const effectiveParams = authMode === "anonymous" ? params.filter((p) => p.mode === "all") : [...params];
|
|
4066
|
-
const missing = effectiveParams.filter((p) => args[p.key] == null);
|
|
4067
|
-
if (missing.length === 0) return "";
|
|
4068
|
-
if (authMode === "anonymous") {
|
|
4069
|
-
const defaults = missing.map((p) => `- **${p.key}**: ${p.fallback}`).join("\n");
|
|
4070
|
-
return `## Quick Build Mode
|
|
4071
|
-
|
|
4072
|
-
Using smart defaults (sign in for full customisation):
|
|
4073
|
-
|
|
4074
|
-
${defaults}
|
|
4075
|
-
|
|
4076
|
-
`;
|
|
4077
|
-
}
|
|
4078
|
-
const rows = missing.map((p) => `| ${p.question} | ${p.fallback} |`).join("\n");
|
|
4079
|
-
return `## Before You Build
|
|
4080
|
-
|
|
4081
|
-
On interactive channels, ask about anything the user hasn't specified. On non-interactive channels (email, social reply), use the defaults and build directly.
|
|
4082
|
-
|
|
4083
|
-
| Ask | Default |
|
|
4084
|
-
|---|---|
|
|
4085
|
-
${rows}
|
|
4086
|
-
|
|
4087
|
-
`;
|
|
4088
|
-
}
|
|
4089
|
-
function resourceLink(name, uri, title) {
|
|
4090
|
-
return {
|
|
4091
|
-
role: "assistant",
|
|
4092
|
-
content: {
|
|
4093
|
-
type: "resource_link",
|
|
4094
|
-
uri,
|
|
4095
|
-
name,
|
|
4096
|
-
title,
|
|
4097
|
-
mimeType: "text/markdown"
|
|
4098
|
-
}
|
|
4099
|
-
};
|
|
4100
|
-
}
|
|
4101
|
-
var BUILD_ONCE_STEP = "**Build the whole form in ONE clipform_create_form call** - pass nodes, settings, and tags together; do NOT create an empty form and add nodes one by one:";
|
|
4102
|
-
var TAGS_LINE = "- tags: one format (quiz/survey/interview/feedback/lead-gen), one genre (trivia/personality/nps/poll/testimonial), and 2-3 topic words";
|
|
4103
|
-
var ATTACH_MEDIA_STEP = "**Attach media**: pass node_id (and form_id) on each render call (clipform_render_video_template / clipform_render_composition) so it attaches to the node automatically once the render finishes - do not poll clipform_check_render to completion, just fire the renders and move on. Fall back to the manual two-step only for a render that didn't take a node_id: first clipform_upload_media_asset (batch all uploads in one call, include captions), then clipform_attach_node_media (batch all attachments in one call), setting show_captions: true and fit_media: true (generated renders must not be cropped).";
|
|
4104
|
-
var REPUBLISH_STEP = "**Republish** with clipform_update_form (is_live: true) - forms are live from creation, but media and edits added since are only visible in the live form after republishing. Never skip this when you attached anything.";
|
|
4105
|
-
var LOG_STEP = "**Log** with clipform_log_generation";
|
|
4106
|
-
var TEXT_ONLY_OVERRIDE = "\n\n> **Text-only override:** If the user explicitly asked for text-only (no video), skip the video production and media attachment steps. Still generate narration.";
|
|
4107
|
-
function numbered(steps) {
|
|
4108
|
-
return steps.filter((s) => typeof s === "string").map((s, i) => `${i + 1}. ${s}`).join("\n");
|
|
4109
|
-
}
|
|
4110
|
-
function intro(sessionContext, discovery) {
|
|
4111
|
-
return `${sessionContext ? sessionContext + "\n\n" : ""}${discovery}`;
|
|
4112
|
-
}
|
|
4113
|
-
var quizWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4114
|
-
const topic = args.topic ? ` about "${args.topic}"` : "";
|
|
4115
|
-
const count = args.question_count ?? 8;
|
|
4116
|
-
const discovery = buildDiscovery(getDiscoveryParams("quiz", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4117
|
-
const craft = caps.media ? "question design, difficulty curves, and narration style" : "question design and difficulty curves";
|
|
4118
|
-
const steps = numbered([
|
|
4119
|
-
"**Research** the topic - find surprising facts, common misconceptions, myth-busters",
|
|
4120
|
-
`**Write questions** - follow the difficulty curve (easy start, hard middle, satisfying end). Target ${count} questions.`,
|
|
4121
|
-
`${BUILD_ONCE_STEP}
|
|
4122
|
-
- Settings: show_step_counter: true, disable_back_navigation: true
|
|
4123
|
-
- One choice node per question: config { choice: { show_answer_feedback: true }, randomise_options: true }, options with score: 1 on the correct answer and score: 0 on 3-4 plausible wrong ones. The viewer shuffles options at render time, so list them in any order. Scored options enable correct-answer marking automatically.
|
|
4124
|
-
- Final end_screen node - EVERY quiz must have:
|
|
4125
|
-
- show_score: true, icon: "trophy"
|
|
4126
|
-
- show_share_button: true (drives virality)
|
|
4127
|
-
- cta_type: "restart", cta_text: a short challenge like "Beat your score?" or "Try again?"
|
|
4128
|
-
- title and message that fit the quiz's voice - short, punchy, and specific to the topic (not generic "Good job!"). Example: title: "Well played!", message: "Share your score and challenge a friend."
|
|
4129
|
-
- NOTE: Personalised messages per score tier (score_ranges) are coming soon. For now, write one great end screen message that works for all scores.
|
|
4130
|
-
${TAGS_LINE}`,
|
|
4131
|
-
caps.media && "**Generate narration** with clipform_generate_tts - batch ALL questions in a single call (pass an array of items). Tease the question - do NOT reveal the answer or read options aloud. Keep each narration 5-15 seconds.",
|
|
4132
|
-
caps.media && `**Build video** for each question - pass each question's node_id (and form_id) on the render call so it attaches automatically once done. Pick per question; mixing treatments across one quiz is fine:
|
|
4133
|
-
- Default - narrated slideshow: clipform_search_media (kind: "image", 3 images per question, batch all queries in one call), then clipform_render_video_template (template: "slideshow", controls.items + controls.audio_url) with wait: false per question - fires all renders in parallel - then collect URLs with clipform_check_render.
|
|
4134
|
-
- Designed visual - when a recipe or composition fits the question or the user asks for one (e.g. a versus, a grid reveal, guess-the-city): recipe book first - clipform_list_video_templates and match the mechanic to a recipe, then clipform_render_video_template with its curated controls (wait: false, one call per question). Only if no recipe fits, drop to the raw primitives - clipform_list_compositions, then ONE clipform_render_composition call with items (all clips render in parallel). Collect job_ids with clipform_check_render. Both take narration via sound.narration.`,
|
|
4135
|
-
caps.media && ATTACH_MEDIA_STEP,
|
|
4136
|
-
REPUBLISH_STEP,
|
|
4137
|
-
caps.research && `${LOG_STEP} (sources, images, attributions)`
|
|
4138
|
-
]);
|
|
4139
|
-
return `${intro(sessionContext, discovery)}Here's how to build a great ${count}-question ${caps.media ? "video " : ""}quiz${topic} with Clipform. Read the attached quiz guide for craft knowledge on ${craft}.
|
|
4140
|
-
|
|
4141
|
-
## Workflow
|
|
4142
|
-
|
|
4143
|
-
${steps}${caps.media ? TEXT_ONLY_OVERRIDE : ""}`;
|
|
4144
|
-
};
|
|
4145
|
-
var personalityQuizWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4146
|
-
const topic = args.topic ? ` - "${args.topic}"` : "";
|
|
4147
|
-
const count = args.question_count ?? 8;
|
|
4148
|
-
const discovery = buildDiscovery(getDiscoveryParams("quiz", "personality", authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4149
|
-
const steps = numbered([
|
|
4150
|
-
"**Define 3-5 outcome categories** conceptually - these guide your question design even though automated scoring is not yet available.",
|
|
4151
|
-
`**Write questions** - each question should feel revealing but fun. Target ${count} questions.`,
|
|
4152
|
-
`${BUILD_ONCE_STEP}
|
|
4153
|
-
- Settings: show_step_counter: true, disable_back_navigation: true
|
|
4154
|
-
- One choice node per question: config { choice: { show_answer_feedback: false } } (no right/wrong!)
|
|
4155
|
-
- Do NOT set randomise_options (option order matters for personality quizzes - lead with the most appealing)
|
|
4156
|
-
- Do NOT set score or scores on options (category-based scoring is not yet available)
|
|
4157
|
-
- Final end_screen node - EVERY personality quiz must have:
|
|
4158
|
-
- show_score: false, icon: "star"
|
|
4159
|
-
- show_share_button: true (personality results are inherently shareable)
|
|
4160
|
-
- cta_type: "restart", cta_text: "Find out again?" or "Take it again?"
|
|
4161
|
-
- Write a title and message that feel personal and shareable. Example: title: "Thanks for playing!", message: "Share this quiz with friends and compare your answers."
|
|
4162
|
-
- NOTE: Automated result screens per category (scoring_results) are coming soon. For now, write one engaging end screen.
|
|
4163
|
-
${TAGS_LINE}`,
|
|
4164
|
-
caps.media && '**Generate narration** with clipform_generate_tts - batch ALL questions in a single call. Conversational, reflective tone. "What does this say about you?" not "Do you know the answer?"',
|
|
4165
|
-
caps.media && "**Build video** + **attach media** (same as knowledge quiz workflow)",
|
|
4166
|
-
REPUBLISH_STEP,
|
|
4167
|
-
caps.research && LOG_STEP
|
|
4168
|
-
]);
|
|
4169
|
-
return `${intro(sessionContext, discovery)}Here's how to build a ${count}-question personality quiz${topic} with Clipform. Read the attached personality quiz guide for craft knowledge on category design, option weighting, and outcome writing.
|
|
4170
|
-
|
|
4171
|
-
## How it differs from a knowledge quiz
|
|
4172
|
-
|
|
4173
|
-
There are NO correct answers. Each option should feel equally valid - the quiz is about self-expression, not testing knowledge. show_answer_feedback must be false.
|
|
4174
|
-
|
|
4175
|
-
**NOTE:** Full category-based personality scoring (where each option maps to outcome categories and the winning category determines the result) is coming soon. For now, build personality quizzes as engaging choice-based forms with a single end screen. The experience is still great - respondents enjoy the questions themselves.
|
|
4176
|
-
|
|
4177
|
-
## Workflow
|
|
4178
|
-
|
|
4179
|
-
${steps}`;
|
|
4180
|
-
};
|
|
4181
|
-
var comprehensionQuizWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4182
|
-
const count = args.question_count ?? 8;
|
|
4183
|
-
const audienceLabel = args.audience ? ` (${args.audience})` : "";
|
|
4184
|
-
const discovery = buildDiscovery(getDiscoveryParams("quiz", "comprehension", authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4185
|
-
const steps = numbered([
|
|
4186
|
-
`**Get the video content** - ask the user to paste the video's transcript, closed captions, or a detailed summary of its key points (this workflow does not extract YouTube captions itself). Use the YouTube URL, if given, only as a reference/source link${caps.research ? " for the audit log" : ""}, not as something to fetch.`,
|
|
4187
|
-
`**Analyse the content** - identify:
|
|
4188
|
-
- Key claims, facts, or arguments made in the video
|
|
4189
|
-
- Specific details a casual viewer might miss
|
|
4190
|
-
- The video's main thesis or conclusion
|
|
4191
|
-
- Any surprising or counterintuitive points`,
|
|
4192
|
-
`**Write comprehension questions** - these test whether someone WATCHED the video, not general knowledge:
|
|
4193
|
-
- "According to the video, what is the main reason...?"
|
|
4194
|
-
- "What example does the video use to illustrate...?"
|
|
4195
|
-
- Include 1-2 inference questions: "Based on the video, why does the presenter believe...?"
|
|
4196
|
-
- Avoid questions answerable without watching (e.g., common knowledge about the topic)`,
|
|
4197
|
-
`**Adapt to the audience**${audienceLabel} - simplify language for younger audiences, focus on concrete/visual details rather than abstract arguments`,
|
|
4198
|
-
`${BUILD_ONCE_STEP}
|
|
4199
|
-
- Settings: show_step_counter: true, disable_back_navigation: true
|
|
4200
|
-
- One choice node per question: config { choice: { show_answer_feedback: true }, randomise_options: true }, options with score: 1 on the correct answer and score: 0 on 3-4 plausible wrong ones - make distractors things someone might guess without watching. The viewer shuffles options at render time, so list them in any order. Scored options enable correct-answer marking automatically.
|
|
4201
|
-
- Final end_screen node:
|
|
4202
|
-
- show_score: true, icon: "trophy"
|
|
4203
|
-
- show_share_button: true
|
|
4204
|
-
- cta_type: "restart", cta_text: "Rewatch and try again?"
|
|
4205
|
-
- title and message that reference the video. Example: title: "How well do you know this video?", message: "Share your score and see if your friends were really paying attention."
|
|
4206
|
-
- NOTE: Personalised messages per score tier (score_ranges) are coming soon. For now, write one great end screen message.
|
|
4207
|
-
- tags: ["quiz", "comprehension", "youtube"] + 2-3 topic words from the video`,
|
|
4208
|
-
caps.media && `**Generate narration** with clipform_generate_tts - batch ALL questions in a single call. Reference the video naturally: "If you watched closely, you'll know this one..." Keep each narration 5-10 seconds.`,
|
|
4209
|
-
caps.media && `**Build video** for each question:
|
|
4210
|
-
- clipform_search_media (kind: "image") - 3 images per question, batch all queries in one call
|
|
4211
|
-
- clipform_render_video_template (template: "slideshow", controls.items + controls.audio_url) with wait: false per question - fires all renders in parallel - then collect URLs with clipform_check_render`,
|
|
4212
|
-
caps.media && ATTACH_MEDIA_STEP,
|
|
4213
|
-
REPUBLISH_STEP,
|
|
4214
|
-
caps.research && `${LOG_STEP} - include the YouTube URL and video title/channel as sources, using whatever of those the user provided`
|
|
4215
|
-
]);
|
|
4216
|
-
return `${intro(sessionContext, discovery)}Here's how to build a ${count}-question comprehension quiz from a YouTube video. Read the attached quiz and comprehension guides for craft knowledge on question design and distractor techniques.
|
|
4217
|
-
|
|
4218
|
-
## Comprehension Quiz Workflow
|
|
4219
|
-
|
|
4220
|
-
${steps}
|
|
4221
|
-
|
|
4222
|
-
## Question Types for Comprehension
|
|
4223
|
-
|
|
4224
|
-
| Type | Example | Tests |
|
|
4225
|
-
|------|---------|-------|
|
|
4226
|
-
| Detail recall | "What specific number did the presenter mention?" | Active listening |
|
|
4227
|
-
| Sequence | "What was discussed BEFORE the section about...?" | Following the structure |
|
|
4228
|
-
| Inference | "Based on the video, why does the presenter believe...?" | Understanding arguments |
|
|
4229
|
-
| Contrast | "The video compares X and Y. What was the key difference?" | Comprehension depth |
|
|
4230
|
-
| Conclusion | "What was the presenter's final point?" | Watched to the end |
|
|
4231
|
-
|
|
4232
|
-
Wrong answers should sound right to someone who didn't watch but googled the topic. The quiz should be unfair to non-watchers and fair to watchers.${caps.media ? TEXT_ONLY_OVERRIDE : ""}`;
|
|
4233
|
-
};
|
|
4234
|
-
var compositionQuizWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4235
|
-
const topic = args.topic ? ` about "${args.topic}"` : "";
|
|
4236
|
-
const count = args.question_count ?? 5;
|
|
4237
|
-
const discovery = buildDiscovery(getDiscoveryParams("quiz", "composition", authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4238
|
-
if (!caps.media) {
|
|
4239
|
-
return `${intro(sessionContext, discovery)}A composition quiz is a guess-and-reveal quiz built from rendered video clips (flag sweeps, blurred photos resolving, and similar), which needs the media tools - this connection exposes form-building tools only, so those renders are not available here.
|
|
4240
|
-
|
|
4241
|
-
Build a standard scored quiz${topic} instead: call clipform_get_workflow with type "quiz" and follow that recipe. ${count} questions is a good target.`;
|
|
4242
|
-
}
|
|
4243
|
-
const steps = numbered([
|
|
4244
|
-
"**Discover what's renderable - recipe book first.** Call clipform_list_video_templates and match each question's mechanic against a recipe's description/keywords (e.g. guess-the-city for a where-in-the-world/geography mechanic, mystery-reveal for guess-the-image/flag, colour-grid for palette-matching). Render a matched recipe with clipform_render_video_template and its curated controls. Only when no recipe fits a question, drop to the raw primitives - clipform_list_compositions, matched via the composition guide's matrix - and render with clipform_render_composition. Availability varies by session; choose ONLY from what these tools return. Mix 2-3 mechanics across the quiz; for questions with no fitting recipe or composition, use the base quiz's Ken Burns pipeline instead.",
|
|
4245
|
-
`**Write questions** - difficulty curve as in the base guide. Difficulty = subject obscurity (Japan's flag vs Kiribati's), never clue degradation. ${count} questions \u2248 ${count + 1} nodes total (one scored choice node per question + the end screen); an optional reveal beat adds one node per question it's used on - check the plan's node limit.`,
|
|
4246
|
-
"**Render all clips** - raw-composition clips batch in ONE clipform_render_composition call with items (parallel); recipe clips render one clipform_render_video_template call each (wait: false). Collect all job_ids with clipform_check_render. Chain-state compositions: clue clip animate: true; when a question uses an optional reveal clip, animate: false + answer props.",
|
|
4247
|
-
`${BUILD_ONCE_STEP}
|
|
4248
|
-
- Settings: show_step_counter: true, disable_back_navigation: true
|
|
4249
|
-
- Per question, ONE scored choice node (type: "choice"): question as prompt, config { choice: { show_answer_feedback: true }, randomise_options: true }, options with score: 1 on the correct answer and score: 0 on 2-3 wrong ones. Scored options enable correct-answer marking automatically - the viewer's answer feedback delivers the correct answer.
|
|
4250
|
-
- Optional reveal beat (type: "button"): add one only when the quiz wants extra context or celebration - the answer in the prompt ("It was Japan!"), config { button_text: "Next one" }
|
|
4251
|
-
- Final end_screen node: show_score: true, icon: "trophy", show_share_button: true, cta_type: "restart", cta_text: a short challenge. NOTE: per-tier messages (score_ranges) are coming soon - write one great message.
|
|
4252
|
-
- tags: format "quiz", genre "trivia", and 2-3 topic words`,
|
|
4253
|
-
"**Generate narration** with clipform_generate_tts - batch ALL items in one call. The visual does the teasing: set stakes, never describe what's on screen or read the clue aloud. If a question uses the optional reveal node, its narration can celebrate.",
|
|
4254
|
-
`${ATTACH_MEDIA_STEP} Attach the clue clip to each choice node; attach reveal clips to their button nodes only on questions that use one.`,
|
|
4255
|
-
REPUBLISH_STEP,
|
|
4256
|
-
caps.research && `${LOG_STEP} - record the composition IDs used per question alongside sources and attributions`
|
|
4257
|
-
]);
|
|
4258
|
-
return `${intro(sessionContext, discovery)}Here's how to build a ${count}-question composition quiz${topic} with Clipform - a guess-and-reveal quiz where each question is a rendered composition (flag sweep, Rebus, blurred photo resolving) instead of a stock-image slideshow. Read the attached quiz and composition guides for the mechanic matrix, the Composition Question Node pattern, and difficulty design.
|
|
4259
|
-
|
|
4260
|
-
## Composition Quiz Workflow
|
|
4261
|
-
|
|
4262
|
-
${steps}`;
|
|
4263
|
-
};
|
|
4264
|
-
var interviewWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4265
|
-
const purpose = args.purpose ?? "responses";
|
|
4266
|
-
const format = args.response_format ?? "all";
|
|
4267
|
-
const consent = args.needs_consent ?? true;
|
|
4268
|
-
const discovery = buildDiscovery(getDiscoveryParams("interview", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4269
|
-
const steps = numbered([
|
|
4270
|
-
`**Identify the ask** - what do you need from respondents? ${purpose}.`,
|
|
4271
|
-
`${BUILD_ONCE_STEP}
|
|
4272
|
-
- Settings: show_step_counter: true, disable_back_navigation: false
|
|
4273
|
-
- Warm-up question first (type: "open") - something easy: "Tell us your name and role"
|
|
4274
|
-
- 2-3 core questions (type: "open") - one topic per question.${format === "all" ? " Enable text + audio + video responses." : ` Enable ${format} responses.`}
|
|
4275
|
-
- Contact collection (type: "details") - first name + email minimum${consent ? `
|
|
4276
|
-
- Consent node - "I agree that my response may be used in [context]"` : ""}
|
|
4277
|
-
- End screen that sets expectations: "Thanks! We'll be in touch."
|
|
4278
|
-
${TAGS_LINE}`,
|
|
4279
|
-
caps.media && `**Optional - Rich Media:** Add TTS narration (clipform_generate_tts, batch all questions in one call) with a warm, inviting tone - "We'd love to hear your story..." Video backgrounds (clipform_search_media \u2192 clipform_render_video_template slideshow) on the intro question can set a professional tone.`,
|
|
4280
|
-
REPUBLISH_STEP,
|
|
4281
|
-
caps.research && LOG_STEP
|
|
4282
|
-
]);
|
|
4283
|
-
return `${intro(sessionContext, discovery)}Here's how to build an interview form for collecting ${purpose} with Clipform. Read the attached interview guide for craft knowledge on question design and pacing.
|
|
4284
|
-
|
|
4285
|
-
## Workflow
|
|
4286
|
-
|
|
4287
|
-
${steps}`;
|
|
4288
|
-
};
|
|
4289
|
-
var surveyWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4290
|
-
const topic = args.topic ? ` for ${args.topic}` : "";
|
|
4291
|
-
const anonymous = args.anonymous ?? true;
|
|
4292
|
-
const discovery = buildDiscovery(getDiscoveryParams("survey", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4293
|
-
const steps = numbered([
|
|
4294
|
-
"**Define the key metric** - what's the one number you care about? (NPS, satisfaction, likelihood to recommend)",
|
|
4295
|
-
`${BUILD_ONCE_STEP}
|
|
4296
|
-
- Settings: show_step_counter: true, disable_back_navigation: false
|
|
4297
|
-
- Key metric question FIRST (type: "choice" or "rating") - while attention is highest
|
|
4298
|
-
- One "why?" follow-up (type: "open") - "What's the main reason for your score?"
|
|
4299
|
-
- 2-3 specific questions (type: "choice") - only ask what you'll act on${!anonymous ? `
|
|
4300
|
-
- Contact collection (type: "details") - name + email for follow-up` : ""}
|
|
4301
|
-
- End screen: "Thanks for your feedback!"
|
|
4302
|
-
${TAGS_LINE}`,
|
|
4303
|
-
caps.media && "**Optional - Rich Media:** For a more engaging experience, add TTS narration (clipform_generate_tts) for the intro or key questions, video backgrounds (clipform_search_media \u2192 clipform_render_video_template slideshow), or background music (clipform_search_music).",
|
|
4304
|
-
REPUBLISH_STEP,
|
|
4305
|
-
caps.research && LOG_STEP
|
|
4306
|
-
]);
|
|
4307
|
-
return `${intro(sessionContext, discovery)}Here's how to build a survey${topic} with Clipform. Read the attached survey guide for craft knowledge on question design and reducing respondent fatigue.
|
|
4308
|
-
|
|
4309
|
-
## Workflow
|
|
4310
|
-
|
|
4311
|
-
${steps}
|
|
4312
|
-
|
|
4313
|
-
## Key rule: 5 questions max. Every extra question costs completions.`;
|
|
4314
|
-
};
|
|
4315
|
-
var funnelWorkflow = (_args, sessionContext) => {
|
|
4316
|
-
return `${sessionContext ? sessionContext + "\n\n" : ""}Funnel capabilities with conditional routing and branching logic are planned but not yet available.
|
|
4317
|
-
|
|
4318
|
-
Proceed now: build a linear qualification survey or quiz directly with clipform_create_form instead of branching - do not defer to another prompt or stop to ask the user. Order the questions to gather the qualification criteria, then finish with a single end screen.`;
|
|
4319
|
-
};
|
|
4320
|
-
var testimonialWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4321
|
-
const useCase = args.use_case ?? "customer stories";
|
|
4322
|
-
const discovery = buildDiscovery(getDiscoveryParams("testimonial", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4323
|
-
const steps = numbered([
|
|
4324
|
-
"**Define the story arc** - what transformation or experience do you want to capture?",
|
|
4325
|
-
`${BUILD_ONCE_STEP}
|
|
4326
|
-
- Settings: show_step_counter: true, disable_back_navigation: false
|
|
4327
|
-
- Warm-up question (type: "open") - "Tell us your name and [role/relationship/context]". Enable video + audio + text responses.
|
|
4328
|
-
- 2-3 storytelling prompts (type: "open") - follow the before \u2192 during \u2192 after arc. Enable video responses. Example prompts:
|
|
4329
|
-
- "What was your biggest challenge before?"
|
|
4330
|
-
- "What was the experience like working with us?"
|
|
4331
|
-
- "What's different now? What would you tell someone considering it?"
|
|
4332
|
-
- Consent node - "I agree that my response may be used in marketing materials, on the website, and in sales presentations."
|
|
4333
|
-
- End screen: "Thank you for sharing your story! Your experience will help others." icon: "party", no score, no restart CTA
|
|
4334
|
-
- tags: format "testimonial", genre "story", and 2-3 topic words`,
|
|
4335
|
-
caps.media && `**Generate narration** with clipform_generate_tts - batch all prompts in a single call. Warm, appreciative tone - "We'd love to hear your story..." Keep each narration 5-8 seconds.`,
|
|
4336
|
-
caps.media && "**Optional: build video** for the intro/warm-up question to set the tone.",
|
|
4337
|
-
REPUBLISH_STEP,
|
|
4338
|
-
caps.research && LOG_STEP
|
|
4339
|
-
]);
|
|
4340
|
-
return `${intro(sessionContext, discovery)}Here's how to build a testimonial collection form for ${useCase} with Clipform. Read the attached testimonial guide for craft knowledge on storytelling prompts and making respondents comfortable.
|
|
4341
|
-
|
|
4342
|
-
## Workflow
|
|
4343
|
-
|
|
4344
|
-
${steps}${caps.media ? "\n\n> **Text-only override:** If the user explicitly asked for text-only (no video), skip the narration and video production steps." : ""}`;
|
|
4345
|
-
};
|
|
4346
|
-
var applicationWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4347
|
-
const role = args.role ?? "an application";
|
|
4348
|
-
const discovery = buildDiscovery(getDiscoveryParams("application", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4349
|
-
const steps = numbered([
|
|
4350
|
-
"**Define what you're screening for** - what qualifications matter, and what questions reveal fit?",
|
|
4351
|
-
`${BUILD_ONCE_STEP}
|
|
4352
|
-
- Settings: show_step_counter: true, disable_back_navigation: false
|
|
4353
|
-
- Contact collection first (type: "details") - name, email, phone - while motivation is high
|
|
4354
|
-
- 2-3 structured screening questions (type: "choice") - experience level, availability, relevant qualifications. These help you filter quickly.
|
|
4355
|
-
- 1-2 open response questions (type: "open") - "Tell us why you're interested" or "Walk us through a relevant experience." Enable video + audio + text responses.
|
|
4356
|
-
- Optional "Anything else?" (type: "open") - catches things you didn't think to ask.
|
|
4357
|
-
- End screen: "Your application has been submitted. We'll review it and get back to you." icon: "tick", no score, no restart
|
|
4358
|
-
- tags: format "application", genre "screening", and 2-3 topic words`,
|
|
4359
|
-
caps.media && `**Optional - Rich Media:** Add TTS narration (clipform_generate_tts) - professional and welcoming: "Thanks for your interest - let's get to know you." Video backgrounds (clipform_search_media \u2192 clipform_render_video_template slideshow) on the intro can make the application feel more personal.`,
|
|
4360
|
-
REPUBLISH_STEP,
|
|
4361
|
-
caps.research && LOG_STEP
|
|
4362
|
-
]);
|
|
4363
|
-
return `${intro(sessionContext, discovery)}Here's how to build ${role} form with Clipform. Read the attached application guide for craft knowledge on structuring multi-section applications.
|
|
4364
|
-
|
|
4365
|
-
## Workflow
|
|
4366
|
-
|
|
4367
|
-
${steps}`;
|
|
4368
|
-
};
|
|
4369
|
-
var bookingWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4370
|
-
const eventName = args.event_name ?? "an event";
|
|
4371
|
-
const eventType = args.event_type ?? "event";
|
|
4372
|
-
const discovery = buildDiscovery(getDiscoveryParams("booking", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4373
|
-
const steps = numbered([
|
|
4374
|
-
"**Define the essentials** - what info do you actually need from attendees? Keep the list short.",
|
|
4375
|
-
`${BUILD_ONCE_STEP}
|
|
4376
|
-
- Settings: show_step_counter: false (it's so short, a counter adds unnecessary UI), disable_back_navigation: false
|
|
4377
|
-
- Contact collection (type: "details") - name + email minimum. Add phone only if needed.
|
|
4378
|
-
- 1-3 event-specific questions (type: "choice") - session preferences, dietary requirements, experience level. Only ask what you'll use.
|
|
4379
|
-
- End screen: "You're registered! Here's what to expect." Include event details (date, time, location/link) in the message. icon: "tick", no score, no restart, cta_type: "external_link" with a URL to calendar invite or event page (if available)
|
|
4380
|
-
- tags: format "registration", genre "${eventType}", and 2-3 topic words`,
|
|
4381
|
-
caps.media && "**Optional: add welcome video** - a short intro from the host. Generate narration with clipform_generate_tts, then build a video with clipform_search_media + clipform_render_video_template (slideshow).",
|
|
4382
|
-
REPUBLISH_STEP,
|
|
4383
|
-
caps.research && LOG_STEP
|
|
4384
|
-
]);
|
|
4385
|
-
return `${intro(sessionContext, discovery)}Here's how to build a ${eventType} registration form for ${eventName} with Clipform. Read the attached booking guide for craft knowledge on keeping registrations fast.
|
|
4386
|
-
|
|
4387
|
-
## Workflow
|
|
4388
|
-
|
|
4389
|
-
${steps}
|
|
4390
|
-
|
|
4391
|
-
## Key rule: 3-5 fields max. Every extra field costs registrations.`;
|
|
4392
|
-
};
|
|
4393
|
-
var intakeWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4394
|
-
const useCase = args.use_case ?? "new clients";
|
|
4395
|
-
const discovery = buildDiscovery(getDiscoveryParams("intake", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4396
|
-
const steps = numbered([
|
|
4397
|
-
"**Decide what you actually need** - contact details plus one open question about what the client is looking for. Capture, don't qualify.",
|
|
4398
|
-
`${BUILD_ONCE_STEP}
|
|
4399
|
-
- Settings: show_step_counter: true, disable_back_navigation: false
|
|
4400
|
-
- Welcome (type: "button") - warm intro: "Thanks for reaching out - a couple of quick questions so we can help you properly." button_text: "Let's begin"
|
|
4401
|
-
- Contact collection (type: "details") - first name + email; phone optional
|
|
4402
|
-
- What they need (type: "open") - "Tell us a bit about what you're looking for." Enable video + audio + text responses (video-first)
|
|
4403
|
-
- Optional one qualifier (type: "choice") - only if it changes what you do next ("What are you most interested in?"). Don't stack these.
|
|
4404
|
-
- Optional "Anything else?" (type: "open") - catches what you didn't think to ask
|
|
4405
|
-
- End screen: "Thanks! We've got your details and we'll be in touch shortly." icon: "tick", no score, no restart
|
|
4406
|
-
- tags: format "intake", genre "onboarding", and 2-3 topic words`,
|
|
4407
|
-
caps.media && "**Optional: add a welcome video** - a short personal intro from you. Generate narration with clipform_generate_tts, then build a video with clipform_search_media + clipform_render_video_template (slideshow).",
|
|
4408
|
-
REPUBLISH_STEP,
|
|
4409
|
-
caps.research && LOG_STEP
|
|
4410
|
-
]);
|
|
4411
|
-
return `${intro(sessionContext, discovery)}Here's how to build a client intake form for ${useCase} with Clipform. Read the attached intake guide for craft knowledge on a warm welcome and low-friction capture.
|
|
4412
|
-
|
|
4413
|
-
## Workflow
|
|
4414
|
-
|
|
4415
|
-
${steps}
|
|
4416
|
-
|
|
4417
|
-
## Key rule: 3-5 steps max. An intake that feels like paperwork loses the client you just won.`;
|
|
4418
|
-
};
|
|
4419
|
-
var leadCaptureWorkflow = (args, sessionContext, authMode, caps) => {
|
|
4420
|
-
const useCase = args.use_case ?? "enquiries";
|
|
4421
|
-
const discovery = buildDiscovery(getDiscoveryParams("lead-capture", void 0, authMode === "anonymous" ? "demo" : "full"), args, authMode);
|
|
4422
|
-
const steps = numbered([
|
|
4423
|
-
"**Decide the one thing you need** - a contact. Everything else is optional and costs conversions.",
|
|
4424
|
-
`${BUILD_ONCE_STEP}
|
|
4425
|
-
- Settings: show_step_counter: false, disable_back_navigation: false
|
|
4426
|
-
- Optional hook (type: "button") - one line restating the value, e.g. "Want in? Drop your details and we'll be in touch." button_text: "Count me in"
|
|
4427
|
-
- Contact collection (type: "details") - first name + email; phone only if you'll call
|
|
4428
|
-
- Optional ONE qualifier (type: "choice") - only if the answer routes your follow-up ("What are you most interested in?"). If it doesn't, cut it.
|
|
4429
|
-
- End screen: "Thanks! We'll be in touch soon." Set the expectation (when/how). icon: "tick", no score, no restart
|
|
4430
|
-
- tags: format "lead-capture", genre "enquiry", and 2-3 topic words`,
|
|
4431
|
-
REPUBLISH_STEP,
|
|
4432
|
-
caps.research && LOG_STEP
|
|
4433
|
-
]);
|
|
4434
|
-
return `${intro(sessionContext, discovery)}Here's how to build a lead capture form for ${useCase} with Clipform. Read the attached lead-capture guide - the whole game is minimal friction. This is a LINEAR form: no branching, no scoring.
|
|
4435
|
-
|
|
4436
|
-
## Workflow
|
|
4437
|
-
|
|
4438
|
-
${steps}
|
|
4439
|
-
|
|
4440
|
-
## Key rule: 3-4 steps max. Get the contact early, qualify lightly or not at all.`;
|
|
4441
|
-
};
|
|
4442
|
-
var WORKFLOW_BUILDERS = {
|
|
4443
|
-
"quiz": quizWorkflow,
|
|
4444
|
-
"interview": interviewWorkflow,
|
|
4445
|
-
"survey": surveyWorkflow,
|
|
4446
|
-
"funnel": funnelWorkflow,
|
|
4447
|
-
"testimonial": testimonialWorkflow,
|
|
4448
|
-
"application": applicationWorkflow,
|
|
4449
|
-
"booking": bookingWorkflow,
|
|
4450
|
-
"intake": intakeWorkflow,
|
|
4451
|
-
"lead-capture": leadCaptureWorkflow
|
|
4452
|
-
};
|
|
4453
|
-
var QUIZ_VARIANT_BUILDERS = {
|
|
4454
|
-
"personality": personalityQuizWorkflow,
|
|
4455
|
-
"comprehension": comprehensionQuizWorkflow,
|
|
4456
|
-
"composition": compositionQuizWorkflow
|
|
4457
|
-
};
|
|
4458
|
-
async function getWorkflowText(type, args = {}, variant, caps = FULL_CAPS) {
|
|
4459
|
-
const { text: sessionContext, authMode } = await getSessionContextWithAuth();
|
|
4460
|
-
if (type === "quiz" && variant) {
|
|
4461
|
-
return QUIZ_VARIANT_BUILDERS[variant](args, sessionContext, authMode, caps);
|
|
4462
|
-
}
|
|
4463
|
-
return WORKFLOW_BUILDERS[type](args, sessionContext, authMode, caps);
|
|
4464
|
-
}
|
|
4465
|
-
function registerPrompts(server, caps = FULL_CAPS) {
|
|
4466
|
-
const mediaStyleArg = caps.media ? { media_style: external_exports.enum(MEDIA_STYLE_ENUM).optional().default("video").describe("Media style: text only, still images, or slideshow video with narration (default: video)") } : {};
|
|
4467
|
-
const styleNote = (args) => caps.media ? `, ${args.media_style ?? "video"} style` : "";
|
|
4468
|
-
server.registerPrompt(
|
|
4469
|
-
"create-quiz",
|
|
4470
|
-
{
|
|
4471
|
-
title: "Create a Quiz",
|
|
4472
|
-
description: "Build a scored knowledge quiz with narrated video questions",
|
|
4473
|
-
argsSchema: {
|
|
4474
|
-
topic: external_exports.string().optional().describe("Quiz topic (e.g. 'Space exploration', 'Premier League')"),
|
|
4475
|
-
question_count: external_exports.string().optional().default("8").describe("Number of questions (default: 8)"),
|
|
4476
|
-
...mediaStyleArg
|
|
4477
|
-
}
|
|
4478
|
-
},
|
|
4479
|
-
async (rawArgs) => {
|
|
4480
|
-
const args = coercePromptArgs(rawArgs);
|
|
4481
|
-
return {
|
|
4482
|
-
messages: [
|
|
4483
|
-
{
|
|
4484
|
-
role: "user",
|
|
4485
|
-
content: {
|
|
4486
|
-
type: "text",
|
|
4487
|
-
text: `I want to create a quiz${args.topic ? ` about "${args.topic}"` : ""}. ${args.question_count ?? 8} questions${styleNote(args)}.`
|
|
4488
|
-
}
|
|
4489
|
-
},
|
|
4490
|
-
resourceLink("guide-quiz", "clipform://guides/quiz", "Quiz Writing Guide"),
|
|
4491
|
-
{
|
|
4492
|
-
role: "assistant",
|
|
4493
|
-
content: {
|
|
4494
|
-
type: "text",
|
|
4495
|
-
text: await getWorkflowText("quiz", args, void 0, caps)
|
|
4496
|
-
}
|
|
4497
|
-
}
|
|
4498
|
-
]
|
|
4499
|
-
};
|
|
4500
|
-
}
|
|
4501
|
-
);
|
|
4502
|
-
server.registerPrompt(
|
|
4503
|
-
"create-personality-quiz",
|
|
4504
|
-
{
|
|
4505
|
-
title: "Create a Personality Quiz",
|
|
4506
|
-
description: "Build a 'Which X are you?' personality quiz with category-based scoring and outcome screens",
|
|
4507
|
-
argsSchema: {
|
|
4508
|
-
topic: external_exports.string().optional().describe("Quiz theme (e.g. 'Which city are you?', 'What's your work style?')"),
|
|
4509
|
-
categories: external_exports.string().optional().describe("Comma-separated outcome categories (e.g. 'Creative, Analytical, Leader, Collaborator')"),
|
|
4510
|
-
question_count: external_exports.string().optional().default("8").describe("Number of questions (default: 8)"),
|
|
4511
|
-
...mediaStyleArg
|
|
4512
|
-
}
|
|
4513
|
-
},
|
|
4514
|
-
async (rawArgs) => {
|
|
4515
|
-
const args = coercePromptArgs(rawArgs);
|
|
4516
|
-
const categoriesNote = args.categories ? `
|
|
4517
|
-
|
|
4518
|
-
Outcome categories: ${args.categories}` : "";
|
|
4519
|
-
return {
|
|
4520
|
-
messages: [
|
|
4521
|
-
{
|
|
4522
|
-
role: "user",
|
|
4523
|
-
content: {
|
|
4524
|
-
type: "text",
|
|
4525
|
-
text: `I want to create a personality quiz${args.topic ? ` - "${args.topic}"` : ""}. ${args.question_count ?? 8} questions${styleNote(args)}.${categoriesNote}`
|
|
4526
|
-
}
|
|
4527
|
-
},
|
|
4528
|
-
resourceLink("guide-quiz", "clipform://guides/quiz", "Quiz Writing Guide"),
|
|
4529
|
-
resourceLink("guide-quiz-personality", "clipform://guides/quiz/personality", "Personality Quiz Addendum"),
|
|
4530
|
-
{
|
|
4531
|
-
role: "assistant",
|
|
4532
|
-
content: {
|
|
4533
|
-
type: "text",
|
|
4534
|
-
text: await getWorkflowText("quiz", args, "personality", caps)
|
|
4535
|
-
}
|
|
4536
|
-
}
|
|
4537
|
-
]
|
|
4538
|
-
};
|
|
4539
|
-
}
|
|
4540
|
-
);
|
|
4541
|
-
server.registerPrompt(
|
|
4542
|
-
"create-interview",
|
|
4543
|
-
{
|
|
4544
|
-
title: "Create an Interview",
|
|
4545
|
-
description: "Build a form to collect case studies, async video interviews, expert input, or journalist responses",
|
|
4546
|
-
argsSchema: {
|
|
4547
|
-
purpose: external_exports.string().optional().describe("What you're collecting (e.g. 'case study', 'expert input', 'journalist responses')"),
|
|
4548
|
-
response_format: external_exports.enum(["video", "audio", "text", "all"]).optional().default("all").describe("How respondents reply (default: all - video, audio, and text)"),
|
|
4549
|
-
needs_consent: external_exports.string().optional().default("true").describe("Include a consent statement (default: true)")
|
|
4550
|
-
}
|
|
4551
|
-
},
|
|
4552
|
-
async (rawArgs) => {
|
|
4553
|
-
const args = coercePromptArgs(rawArgs);
|
|
4554
|
-
return {
|
|
4555
|
-
messages: [
|
|
4556
|
-
{
|
|
4557
|
-
role: "user",
|
|
4558
|
-
content: {
|
|
4559
|
-
type: "text",
|
|
4560
|
-
text: `I want to collect ${args.purpose ?? "responses"} from people. Responses via ${args.response_format ?? "all"}.${args.needs_consent ?? true ? " Include consent." : ""}`
|
|
4561
|
-
}
|
|
4562
|
-
},
|
|
4563
|
-
resourceLink("guide-interview", "clipform://guides/interview", "Interview Guide"),
|
|
4564
|
-
{
|
|
4565
|
-
role: "assistant",
|
|
4566
|
-
content: {
|
|
4567
|
-
type: "text",
|
|
4568
|
-
text: await getWorkflowText("interview", args, void 0, caps)
|
|
4569
|
-
}
|
|
4570
|
-
}
|
|
4571
|
-
]
|
|
4572
|
-
};
|
|
4573
|
-
}
|
|
4574
|
-
);
|
|
4575
|
-
server.registerPrompt(
|
|
4576
|
-
"create-survey",
|
|
4577
|
-
{
|
|
4578
|
-
title: "Create a Survey",
|
|
4579
|
-
description: "Build a feedback survey, NPS form, or research questionnaire",
|
|
4580
|
-
argsSchema: {
|
|
4581
|
-
topic: external_exports.string().optional().describe("What feedback you're collecting (e.g. 'NPS', 'event feedback', 'product satisfaction')"),
|
|
4582
|
-
anonymous: external_exports.string().optional().default("true").describe("Whether the survey is anonymous (default: true)")
|
|
4583
|
-
}
|
|
4584
|
-
},
|
|
4585
|
-
async (rawArgs) => {
|
|
4586
|
-
const args = coercePromptArgs(rawArgs);
|
|
4587
|
-
return {
|
|
4588
|
-
messages: [
|
|
4589
|
-
{
|
|
4590
|
-
role: "user",
|
|
4591
|
-
content: {
|
|
4592
|
-
type: "text",
|
|
4593
|
-
text: `I want to create a survey${args.topic ? ` for ${args.topic}` : ""}. ${args.anonymous ?? true ? "Anonymous" : "Identified"} respondents.`
|
|
4594
|
-
}
|
|
4595
|
-
},
|
|
4596
|
-
resourceLink("guide-survey", "clipform://guides/survey", "Survey & Feedback Guide"),
|
|
4597
|
-
{
|
|
4598
|
-
role: "assistant",
|
|
4599
|
-
content: {
|
|
4600
|
-
type: "text",
|
|
4601
|
-
text: await getWorkflowText("survey", args, void 0, caps)
|
|
4602
|
-
}
|
|
4603
|
-
}
|
|
4604
|
-
]
|
|
4605
|
-
};
|
|
4606
|
-
}
|
|
4607
|
-
);
|
|
4608
|
-
server.registerPrompt(
|
|
4609
|
-
"create-comprehension-quiz",
|
|
4610
|
-
{
|
|
4611
|
-
title: "Create a YouTube Comprehension Quiz",
|
|
4612
|
-
description: "Build a comprehension quiz from a YouTube video - tests whether the viewer actually watched and understood the content",
|
|
4613
|
-
argsSchema: {
|
|
4614
|
-
youtube_url: external_exports.string().optional().describe("YouTube video URL to create the quiz from"),
|
|
4615
|
-
question_count: external_exports.string().optional().default("8").describe("Number of questions (default: 8)"),
|
|
4616
|
-
audience: external_exports.string().optional().describe("Target audience (e.g. 'children aged 5-8', 'university students', 'general')"),
|
|
4617
|
-
...mediaStyleArg
|
|
4618
|
-
}
|
|
4619
|
-
},
|
|
4620
|
-
async (rawArgs) => {
|
|
4621
|
-
const args = coercePromptArgs(rawArgs);
|
|
4622
|
-
const urlNote = args.youtube_url ? ` The video is: ${args.youtube_url}` : "";
|
|
4623
|
-
const audienceNote = args.audience ? ` Target audience: ${args.audience}.` : "";
|
|
4624
|
-
return {
|
|
4625
|
-
messages: [
|
|
4626
|
-
{
|
|
4627
|
-
role: "user",
|
|
4628
|
-
content: {
|
|
4629
|
-
type: "text",
|
|
4630
|
-
text: `I want to create a comprehension quiz based on a YouTube video. ${args.question_count ?? 8} questions${styleNote(args)}.${urlNote}${audienceNote}`
|
|
4631
|
-
}
|
|
4632
|
-
},
|
|
4633
|
-
resourceLink("guide-quiz", "clipform://guides/quiz", "Quiz Writing Guide"),
|
|
4634
|
-
resourceLink("guide-quiz-comprehension", "clipform://guides/quiz/comprehension", "Comprehension Quiz Addendum"),
|
|
4635
|
-
{
|
|
4636
|
-
role: "assistant",
|
|
4637
|
-
content: {
|
|
4638
|
-
type: "text",
|
|
4639
|
-
text: await getWorkflowText("quiz", args, "comprehension", caps)
|
|
4640
|
-
}
|
|
4641
|
-
}
|
|
4642
|
-
]
|
|
4643
|
-
};
|
|
4644
|
-
}
|
|
4645
|
-
);
|
|
4646
|
-
if (caps.media) server.registerPrompt(
|
|
4647
|
-
"create-composition-quiz",
|
|
4648
|
-
{
|
|
4649
|
-
title: "Create a Composition Quiz",
|
|
4650
|
-
description: "Build a guess-and-reveal quiz from rendered compositions - flag sweeps, Rebus puzzles, blur reveals, odd-one-out grids - instead of stock-image slideshows",
|
|
4651
|
-
argsSchema: {
|
|
4652
|
-
topic: external_exports.string().optional().describe("Quiz topic (e.g. 'world flags', 'movie emoji', '90s music')"),
|
|
4653
|
-
question_count: external_exports.string().optional().default("5").describe("Number of questions (default: 5 - one scored choice node per question)")
|
|
4654
|
-
}
|
|
4655
|
-
},
|
|
4656
|
-
async (rawArgs) => {
|
|
4657
|
-
const args = coercePromptArgs(rawArgs);
|
|
4658
|
-
return {
|
|
4659
|
-
messages: [
|
|
4660
|
-
{
|
|
4661
|
-
role: "user",
|
|
4662
|
-
content: {
|
|
4663
|
-
type: "text",
|
|
4664
|
-
text: `I want to create a composition quiz${args.topic ? ` about "${args.topic}"` : ""}. ${args.question_count ?? 5} questions, guess-and-reveal style.`
|
|
4665
|
-
}
|
|
4666
|
-
},
|
|
4667
|
-
resourceLink("guide-quiz", "clipform://guides/quiz", "Quiz Writing Guide"),
|
|
4668
|
-
resourceLink("guide-quiz-composition", "clipform://guides/quiz/composition", "Composition Quiz Addendum"),
|
|
4669
|
-
{
|
|
4670
|
-
role: "assistant",
|
|
4671
|
-
content: {
|
|
4672
|
-
type: "text",
|
|
4673
|
-
text: await getWorkflowText("quiz", args, "composition", caps)
|
|
4674
|
-
}
|
|
4675
|
-
}
|
|
4676
|
-
]
|
|
4677
|
-
};
|
|
4678
|
-
}
|
|
4679
|
-
);
|
|
4680
|
-
server.registerPrompt(
|
|
4681
|
-
"create-funnel",
|
|
4682
|
-
{
|
|
4683
|
-
title: "Create a Funnel",
|
|
4684
|
-
description: "Lead qualification funnels with branching logic are planned but not yet available. Build a linear qualification survey or quiz directly with clipform_create_form now instead of branching.",
|
|
4685
|
-
argsSchema: {}
|
|
4686
|
-
},
|
|
4687
|
-
async () => ({
|
|
4688
|
-
messages: [
|
|
4689
|
-
{
|
|
4690
|
-
role: "assistant",
|
|
4691
|
-
content: {
|
|
4692
|
-
type: "text",
|
|
4693
|
-
text: await getWorkflowText("funnel")
|
|
4694
|
-
}
|
|
4695
|
-
}
|
|
4696
|
-
]
|
|
4697
|
-
})
|
|
4698
|
-
);
|
|
4699
|
-
server.registerPrompt(
|
|
4700
|
-
"create-testimonial",
|
|
4701
|
-
{
|
|
4702
|
-
title: "Collect Testimonials",
|
|
4703
|
-
description: "Build a video testimonial collection form - capture authentic customer stories on camera",
|
|
4704
|
-
argsSchema: {
|
|
4705
|
-
use_case: external_exports.string().optional().describe("What stories you're collecting (e.g. 'customer success', 'product review', 'case study')"),
|
|
4706
|
-
...mediaStyleArg
|
|
4707
|
-
}
|
|
4708
|
-
},
|
|
4709
|
-
async (args) => ({
|
|
4710
|
-
messages: [
|
|
4711
|
-
{
|
|
4712
|
-
role: "user",
|
|
4713
|
-
content: {
|
|
4714
|
-
type: "text",
|
|
4715
|
-
text: `I want to collect ${args.use_case ?? "testimonials"} from people on video.`
|
|
4716
|
-
}
|
|
4717
|
-
},
|
|
4718
|
-
resourceLink("guide-testimonial", "clipform://guides/testimonial", "Testimonial & Story Collection Guide"),
|
|
4719
|
-
{
|
|
4720
|
-
role: "assistant",
|
|
4721
|
-
content: {
|
|
4722
|
-
type: "text",
|
|
4723
|
-
text: await getWorkflowText("testimonial", args, void 0, caps)
|
|
4724
|
-
}
|
|
4725
|
-
}
|
|
4726
|
-
]
|
|
4727
|
-
})
|
|
4728
|
-
);
|
|
4729
|
-
server.registerPrompt(
|
|
4730
|
-
"create-application",
|
|
4731
|
-
{
|
|
4732
|
-
title: "Create an Application Form",
|
|
4733
|
-
description: "Build a structured application form - job applications, programme admissions, grant proposals with video responses",
|
|
4734
|
-
argsSchema: {
|
|
4735
|
-
role: external_exports.string().optional().describe("What the application is for (e.g. 'Software Engineer', 'Scholarship', 'Membership')")
|
|
4736
|
-
}
|
|
4737
|
-
},
|
|
4738
|
-
async (args) => ({
|
|
4739
|
-
messages: [
|
|
4740
|
-
{
|
|
4741
|
-
role: "user",
|
|
4742
|
-
content: {
|
|
4743
|
-
type: "text",
|
|
4744
|
-
text: `I want to create an application form${args.role ? ` for ${args.role}` : ""}.`
|
|
4745
|
-
}
|
|
4746
|
-
},
|
|
4747
|
-
resourceLink("guide-application", "clipform://guides/application", "Application & Evaluation Guide"),
|
|
4748
|
-
{
|
|
4749
|
-
role: "assistant",
|
|
4750
|
-
content: {
|
|
4751
|
-
type: "text",
|
|
4752
|
-
text: await getWorkflowText("application", args, void 0, caps)
|
|
4753
|
-
}
|
|
4754
|
-
}
|
|
4755
|
-
]
|
|
4756
|
-
})
|
|
4757
|
-
);
|
|
4758
|
-
server.registerPrompt(
|
|
4759
|
-
"create-booking",
|
|
4760
|
-
{
|
|
4761
|
-
title: "Create a Booking Form",
|
|
4762
|
-
description: "Build an event registration, course signup, or booking form with a personal video welcome",
|
|
4763
|
-
argsSchema: {
|
|
4764
|
-
event_name: external_exports.string().optional().describe("Name of the event or offering (e.g. 'Design Workshop', 'Intro Call')"),
|
|
4765
|
-
event_type: external_exports.string().optional().describe("Type of event (e.g. 'workshop', 'webinar', 'consultation', 'course')")
|
|
4766
|
-
}
|
|
4767
|
-
},
|
|
4768
|
-
async (args) => ({
|
|
4769
|
-
messages: [
|
|
4770
|
-
{
|
|
4771
|
-
role: "user",
|
|
4772
|
-
content: {
|
|
4773
|
-
type: "text",
|
|
4774
|
-
text: `I want to create a registration form for ${args.event_name ?? "an event"}.${args.event_type ? ` Type: ${args.event_type}.` : ""}`
|
|
4775
|
-
}
|
|
4776
|
-
},
|
|
4777
|
-
resourceLink("guide-booking", "clipform://guides/booking", "Booking & Registration Guide"),
|
|
4778
|
-
{
|
|
4779
|
-
role: "assistant",
|
|
4780
|
-
content: {
|
|
4781
|
-
type: "text",
|
|
4782
|
-
text: await getWorkflowText("booking", args, void 0, caps)
|
|
4783
|
-
}
|
|
4784
|
-
}
|
|
4785
|
-
]
|
|
4786
|
-
})
|
|
4787
|
-
);
|
|
4788
|
-
server.registerPrompt(
|
|
4789
|
-
"create-intake",
|
|
4790
|
-
{
|
|
4791
|
-
title: "Create a Client Intake Form",
|
|
4792
|
-
description: "Build a warm client intake or onboarding form - capture contact details and what the client needs",
|
|
4793
|
-
argsSchema: {
|
|
4794
|
-
use_case: external_exports.string().optional().describe("What kind of business or service (e.g. 'massage', 'coaching', 'personal training', 'agency')"),
|
|
4795
|
-
response_format: external_exports.enum(["video", "audio", "text", "all"]).optional().describe("How people answer the open question (default: all)")
|
|
4796
|
-
}
|
|
4797
|
-
},
|
|
4798
|
-
async (args) => ({
|
|
4799
|
-
messages: [
|
|
4800
|
-
{
|
|
4801
|
-
role: "user",
|
|
4802
|
-
content: {
|
|
4803
|
-
type: "text",
|
|
4804
|
-
text: `I want to create a client intake form${args.use_case ? ` for a ${args.use_case} business` : ""}.`
|
|
4805
|
-
}
|
|
4806
|
-
},
|
|
4807
|
-
resourceLink("guide-intake", "clipform://guides/intake", "Client Intake & Onboarding Guide"),
|
|
4808
|
-
{
|
|
4809
|
-
role: "assistant",
|
|
4810
|
-
content: {
|
|
4811
|
-
type: "text",
|
|
4812
|
-
text: await getWorkflowText("intake", args, void 0, caps)
|
|
4813
|
-
}
|
|
4814
|
-
}
|
|
4815
|
-
]
|
|
4816
|
-
})
|
|
4817
|
-
);
|
|
4818
|
-
server.registerPrompt(
|
|
4819
|
-
"create-lead-capture",
|
|
4820
|
-
{
|
|
4821
|
-
title: "Create a Lead Capture Form",
|
|
4822
|
-
description: "Build a short lead capture or enquiry form - turn interest into a contact with minimal friction",
|
|
4823
|
-
argsSchema: {
|
|
4824
|
-
use_case: external_exports.string().optional().describe("What you're capturing leads for (e.g. 'a service', 'a product', 'a waitlist', 'a quote')")
|
|
4825
|
-
}
|
|
4826
|
-
},
|
|
4827
|
-
async (args) => ({
|
|
4828
|
-
messages: [
|
|
4829
|
-
{
|
|
4830
|
-
role: "user",
|
|
4831
|
-
content: {
|
|
4832
|
-
type: "text",
|
|
4833
|
-
text: `I want to create a lead capture form${args.use_case ? ` for ${args.use_case}` : ""}.`
|
|
4834
|
-
}
|
|
4835
|
-
},
|
|
4836
|
-
resourceLink("guide-lead-capture", "clipform://guides/lead-capture", "Lead Capture Guide"),
|
|
4837
|
-
{
|
|
4838
|
-
role: "assistant",
|
|
4839
|
-
content: {
|
|
4840
|
-
type: "text",
|
|
4841
|
-
text: await getWorkflowText("lead-capture", args, void 0, caps)
|
|
4842
|
-
}
|
|
4843
|
-
}
|
|
4844
|
-
]
|
|
4845
|
-
})
|
|
4846
|
-
);
|
|
4847
|
-
}
|
|
4848
|
-
|
|
4849
|
-
export {
|
|
4850
|
-
ZodOptional,
|
|
4851
|
-
ZodFirstPartyTypeKind,
|
|
4852
|
-
objectType,
|
|
4853
|
-
external_exports,
|
|
4854
|
-
WORKFLOW_TYPES2 as WORKFLOW_TYPES,
|
|
4855
|
-
buildDiscovery,
|
|
4856
|
-
getWorkflowText,
|
|
4857
|
-
registerPrompts
|
|
4858
|
-
};
|
|
4859
|
-
//# sourceMappingURL=chunk-5J5N7KTW.js.map
|