@envsync-cloud/deploy-cli 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4530 -125
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,14 +1,4332 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { createHash, randomBytes } from "crypto";
|
|
10
|
+
import { spawnSync } from "child_process";
|
|
11
|
+
import fs3 from "fs";
|
|
12
|
+
import path3 from "path";
|
|
13
|
+
import readline from "readline";
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import YAML2 from "yaml";
|
|
16
|
+
|
|
17
|
+
// ../deploy-core/src/index.ts
|
|
18
|
+
import fs from "fs";
|
|
19
|
+
import path from "path";
|
|
20
|
+
import YAML from "yaml";
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/zod/v3/external.js
|
|
23
|
+
var external_exports = {};
|
|
24
|
+
__export(external_exports, {
|
|
25
|
+
BRAND: () => BRAND,
|
|
26
|
+
DIRTY: () => DIRTY,
|
|
27
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
28
|
+
INVALID: () => INVALID,
|
|
29
|
+
NEVER: () => NEVER,
|
|
30
|
+
OK: () => OK,
|
|
31
|
+
ParseStatus: () => ParseStatus,
|
|
32
|
+
Schema: () => ZodType,
|
|
33
|
+
ZodAny: () => ZodAny,
|
|
34
|
+
ZodArray: () => ZodArray,
|
|
35
|
+
ZodBigInt: () => ZodBigInt,
|
|
36
|
+
ZodBoolean: () => ZodBoolean,
|
|
37
|
+
ZodBranded: () => ZodBranded,
|
|
38
|
+
ZodCatch: () => ZodCatch,
|
|
39
|
+
ZodDate: () => ZodDate,
|
|
40
|
+
ZodDefault: () => ZodDefault,
|
|
41
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
42
|
+
ZodEffects: () => ZodEffects,
|
|
43
|
+
ZodEnum: () => ZodEnum,
|
|
44
|
+
ZodError: () => ZodError,
|
|
45
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
46
|
+
ZodFunction: () => ZodFunction,
|
|
47
|
+
ZodIntersection: () => ZodIntersection,
|
|
48
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
49
|
+
ZodLazy: () => ZodLazy,
|
|
50
|
+
ZodLiteral: () => ZodLiteral,
|
|
51
|
+
ZodMap: () => ZodMap,
|
|
52
|
+
ZodNaN: () => ZodNaN,
|
|
53
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
54
|
+
ZodNever: () => ZodNever,
|
|
55
|
+
ZodNull: () => ZodNull,
|
|
56
|
+
ZodNullable: () => ZodNullable,
|
|
57
|
+
ZodNumber: () => ZodNumber,
|
|
58
|
+
ZodObject: () => ZodObject,
|
|
59
|
+
ZodOptional: () => ZodOptional,
|
|
60
|
+
ZodParsedType: () => ZodParsedType,
|
|
61
|
+
ZodPipeline: () => ZodPipeline,
|
|
62
|
+
ZodPromise: () => ZodPromise,
|
|
63
|
+
ZodReadonly: () => ZodReadonly,
|
|
64
|
+
ZodRecord: () => ZodRecord,
|
|
65
|
+
ZodSchema: () => ZodType,
|
|
66
|
+
ZodSet: () => ZodSet,
|
|
67
|
+
ZodString: () => ZodString,
|
|
68
|
+
ZodSymbol: () => ZodSymbol,
|
|
69
|
+
ZodTransformer: () => ZodEffects,
|
|
70
|
+
ZodTuple: () => ZodTuple,
|
|
71
|
+
ZodType: () => ZodType,
|
|
72
|
+
ZodUndefined: () => ZodUndefined,
|
|
73
|
+
ZodUnion: () => ZodUnion,
|
|
74
|
+
ZodUnknown: () => ZodUnknown,
|
|
75
|
+
ZodVoid: () => ZodVoid,
|
|
76
|
+
addIssueToContext: () => addIssueToContext,
|
|
77
|
+
any: () => anyType,
|
|
78
|
+
array: () => arrayType,
|
|
79
|
+
bigint: () => bigIntType,
|
|
80
|
+
boolean: () => booleanType,
|
|
81
|
+
coerce: () => coerce,
|
|
82
|
+
custom: () => custom,
|
|
83
|
+
date: () => dateType,
|
|
84
|
+
datetimeRegex: () => datetimeRegex,
|
|
85
|
+
defaultErrorMap: () => en_default,
|
|
86
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
87
|
+
effect: () => effectsType,
|
|
88
|
+
enum: () => enumType,
|
|
89
|
+
function: () => functionType,
|
|
90
|
+
getErrorMap: () => getErrorMap,
|
|
91
|
+
getParsedType: () => getParsedType,
|
|
92
|
+
instanceof: () => instanceOfType,
|
|
93
|
+
intersection: () => intersectionType,
|
|
94
|
+
isAborted: () => isAborted,
|
|
95
|
+
isAsync: () => isAsync,
|
|
96
|
+
isDirty: () => isDirty,
|
|
97
|
+
isValid: () => isValid,
|
|
98
|
+
late: () => late,
|
|
99
|
+
lazy: () => lazyType,
|
|
100
|
+
literal: () => literalType,
|
|
101
|
+
makeIssue: () => makeIssue,
|
|
102
|
+
map: () => mapType,
|
|
103
|
+
nan: () => nanType,
|
|
104
|
+
nativeEnum: () => nativeEnumType,
|
|
105
|
+
never: () => neverType,
|
|
106
|
+
null: () => nullType,
|
|
107
|
+
nullable: () => nullableType,
|
|
108
|
+
number: () => numberType,
|
|
109
|
+
object: () => objectType,
|
|
110
|
+
objectUtil: () => objectUtil,
|
|
111
|
+
oboolean: () => oboolean,
|
|
112
|
+
onumber: () => onumber,
|
|
113
|
+
optional: () => optionalType,
|
|
114
|
+
ostring: () => ostring,
|
|
115
|
+
pipeline: () => pipelineType,
|
|
116
|
+
preprocess: () => preprocessType,
|
|
117
|
+
promise: () => promiseType,
|
|
118
|
+
quotelessJson: () => quotelessJson,
|
|
119
|
+
record: () => recordType,
|
|
120
|
+
set: () => setType,
|
|
121
|
+
setErrorMap: () => setErrorMap,
|
|
122
|
+
strictObject: () => strictObjectType,
|
|
123
|
+
string: () => stringType,
|
|
124
|
+
symbol: () => symbolType,
|
|
125
|
+
transformer: () => effectsType,
|
|
126
|
+
tuple: () => tupleType,
|
|
127
|
+
undefined: () => undefinedType,
|
|
128
|
+
union: () => unionType,
|
|
129
|
+
unknown: () => unknownType,
|
|
130
|
+
util: () => util,
|
|
131
|
+
void: () => voidType
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ../../node_modules/zod/v3/helpers/util.js
|
|
135
|
+
var util;
|
|
136
|
+
(function(util2) {
|
|
137
|
+
util2.assertEqual = (_) => {
|
|
138
|
+
};
|
|
139
|
+
function assertIs(_arg) {
|
|
140
|
+
}
|
|
141
|
+
util2.assertIs = assertIs;
|
|
142
|
+
function assertNever(_x) {
|
|
143
|
+
throw new Error();
|
|
144
|
+
}
|
|
145
|
+
util2.assertNever = assertNever;
|
|
146
|
+
util2.arrayToEnum = (items) => {
|
|
147
|
+
const obj = {};
|
|
148
|
+
for (const item of items) {
|
|
149
|
+
obj[item] = item;
|
|
150
|
+
}
|
|
151
|
+
return obj;
|
|
152
|
+
};
|
|
153
|
+
util2.getValidEnumValues = (obj) => {
|
|
154
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
155
|
+
const filtered = {};
|
|
156
|
+
for (const k of validKeys) {
|
|
157
|
+
filtered[k] = obj[k];
|
|
158
|
+
}
|
|
159
|
+
return util2.objectValues(filtered);
|
|
160
|
+
};
|
|
161
|
+
util2.objectValues = (obj) => {
|
|
162
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
163
|
+
return obj[e];
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
167
|
+
const keys = [];
|
|
168
|
+
for (const key in object) {
|
|
169
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
170
|
+
keys.push(key);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return keys;
|
|
174
|
+
};
|
|
175
|
+
util2.find = (arr, checker) => {
|
|
176
|
+
for (const item of arr) {
|
|
177
|
+
if (checker(item))
|
|
178
|
+
return item;
|
|
179
|
+
}
|
|
180
|
+
return void 0;
|
|
181
|
+
};
|
|
182
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
183
|
+
function joinValues(array, separator = " | ") {
|
|
184
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
185
|
+
}
|
|
186
|
+
util2.joinValues = joinValues;
|
|
187
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
188
|
+
if (typeof value === "bigint") {
|
|
189
|
+
return value.toString();
|
|
190
|
+
}
|
|
191
|
+
return value;
|
|
192
|
+
};
|
|
193
|
+
})(util || (util = {}));
|
|
194
|
+
var objectUtil;
|
|
195
|
+
(function(objectUtil2) {
|
|
196
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
197
|
+
return {
|
|
198
|
+
...first,
|
|
199
|
+
...second
|
|
200
|
+
// second overwrites first
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
})(objectUtil || (objectUtil = {}));
|
|
204
|
+
var ZodParsedType = util.arrayToEnum([
|
|
205
|
+
"string",
|
|
206
|
+
"nan",
|
|
207
|
+
"number",
|
|
208
|
+
"integer",
|
|
209
|
+
"float",
|
|
210
|
+
"boolean",
|
|
211
|
+
"date",
|
|
212
|
+
"bigint",
|
|
213
|
+
"symbol",
|
|
214
|
+
"function",
|
|
215
|
+
"undefined",
|
|
216
|
+
"null",
|
|
217
|
+
"array",
|
|
218
|
+
"object",
|
|
219
|
+
"unknown",
|
|
220
|
+
"promise",
|
|
221
|
+
"void",
|
|
222
|
+
"never",
|
|
223
|
+
"map",
|
|
224
|
+
"set"
|
|
225
|
+
]);
|
|
226
|
+
var getParsedType = (data) => {
|
|
227
|
+
const t = typeof data;
|
|
228
|
+
switch (t) {
|
|
229
|
+
case "undefined":
|
|
230
|
+
return ZodParsedType.undefined;
|
|
231
|
+
case "string":
|
|
232
|
+
return ZodParsedType.string;
|
|
233
|
+
case "number":
|
|
234
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
235
|
+
case "boolean":
|
|
236
|
+
return ZodParsedType.boolean;
|
|
237
|
+
case "function":
|
|
238
|
+
return ZodParsedType.function;
|
|
239
|
+
case "bigint":
|
|
240
|
+
return ZodParsedType.bigint;
|
|
241
|
+
case "symbol":
|
|
242
|
+
return ZodParsedType.symbol;
|
|
243
|
+
case "object":
|
|
244
|
+
if (Array.isArray(data)) {
|
|
245
|
+
return ZodParsedType.array;
|
|
246
|
+
}
|
|
247
|
+
if (data === null) {
|
|
248
|
+
return ZodParsedType.null;
|
|
249
|
+
}
|
|
250
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
251
|
+
return ZodParsedType.promise;
|
|
252
|
+
}
|
|
253
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
254
|
+
return ZodParsedType.map;
|
|
255
|
+
}
|
|
256
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
257
|
+
return ZodParsedType.set;
|
|
258
|
+
}
|
|
259
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
260
|
+
return ZodParsedType.date;
|
|
261
|
+
}
|
|
262
|
+
return ZodParsedType.object;
|
|
263
|
+
default:
|
|
264
|
+
return ZodParsedType.unknown;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// ../../node_modules/zod/v3/ZodError.js
|
|
269
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
270
|
+
"invalid_type",
|
|
271
|
+
"invalid_literal",
|
|
272
|
+
"custom",
|
|
273
|
+
"invalid_union",
|
|
274
|
+
"invalid_union_discriminator",
|
|
275
|
+
"invalid_enum_value",
|
|
276
|
+
"unrecognized_keys",
|
|
277
|
+
"invalid_arguments",
|
|
278
|
+
"invalid_return_type",
|
|
279
|
+
"invalid_date",
|
|
280
|
+
"invalid_string",
|
|
281
|
+
"too_small",
|
|
282
|
+
"too_big",
|
|
283
|
+
"invalid_intersection_types",
|
|
284
|
+
"not_multiple_of",
|
|
285
|
+
"not_finite"
|
|
286
|
+
]);
|
|
287
|
+
var quotelessJson = (obj) => {
|
|
288
|
+
const json = JSON.stringify(obj, null, 2);
|
|
289
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
290
|
+
};
|
|
291
|
+
var ZodError = class _ZodError extends Error {
|
|
292
|
+
get errors() {
|
|
293
|
+
return this.issues;
|
|
294
|
+
}
|
|
295
|
+
constructor(issues) {
|
|
296
|
+
super();
|
|
297
|
+
this.issues = [];
|
|
298
|
+
this.addIssue = (sub) => {
|
|
299
|
+
this.issues = [...this.issues, sub];
|
|
300
|
+
};
|
|
301
|
+
this.addIssues = (subs = []) => {
|
|
302
|
+
this.issues = [...this.issues, ...subs];
|
|
303
|
+
};
|
|
304
|
+
const actualProto = new.target.prototype;
|
|
305
|
+
if (Object.setPrototypeOf) {
|
|
306
|
+
Object.setPrototypeOf(this, actualProto);
|
|
307
|
+
} else {
|
|
308
|
+
this.__proto__ = actualProto;
|
|
309
|
+
}
|
|
310
|
+
this.name = "ZodError";
|
|
311
|
+
this.issues = issues;
|
|
312
|
+
}
|
|
313
|
+
format(_mapper) {
|
|
314
|
+
const mapper = _mapper || function(issue) {
|
|
315
|
+
return issue.message;
|
|
316
|
+
};
|
|
317
|
+
const fieldErrors = { _errors: [] };
|
|
318
|
+
const processError = (error) => {
|
|
319
|
+
for (const issue of error.issues) {
|
|
320
|
+
if (issue.code === "invalid_union") {
|
|
321
|
+
issue.unionErrors.map(processError);
|
|
322
|
+
} else if (issue.code === "invalid_return_type") {
|
|
323
|
+
processError(issue.returnTypeError);
|
|
324
|
+
} else if (issue.code === "invalid_arguments") {
|
|
325
|
+
processError(issue.argumentsError);
|
|
326
|
+
} else if (issue.path.length === 0) {
|
|
327
|
+
fieldErrors._errors.push(mapper(issue));
|
|
328
|
+
} else {
|
|
329
|
+
let curr = fieldErrors;
|
|
330
|
+
let i = 0;
|
|
331
|
+
while (i < issue.path.length) {
|
|
332
|
+
const el = issue.path[i];
|
|
333
|
+
const terminal = i === issue.path.length - 1;
|
|
334
|
+
if (!terminal) {
|
|
335
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
336
|
+
} else {
|
|
337
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
338
|
+
curr[el]._errors.push(mapper(issue));
|
|
339
|
+
}
|
|
340
|
+
curr = curr[el];
|
|
341
|
+
i++;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
processError(this);
|
|
347
|
+
return fieldErrors;
|
|
348
|
+
}
|
|
349
|
+
static assert(value) {
|
|
350
|
+
if (!(value instanceof _ZodError)) {
|
|
351
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
toString() {
|
|
355
|
+
return this.message;
|
|
356
|
+
}
|
|
357
|
+
get message() {
|
|
358
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
359
|
+
}
|
|
360
|
+
get isEmpty() {
|
|
361
|
+
return this.issues.length === 0;
|
|
362
|
+
}
|
|
363
|
+
flatten(mapper = (issue) => issue.message) {
|
|
364
|
+
const fieldErrors = {};
|
|
365
|
+
const formErrors = [];
|
|
366
|
+
for (const sub of this.issues) {
|
|
367
|
+
if (sub.path.length > 0) {
|
|
368
|
+
const firstEl = sub.path[0];
|
|
369
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
370
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
371
|
+
} else {
|
|
372
|
+
formErrors.push(mapper(sub));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return { formErrors, fieldErrors };
|
|
376
|
+
}
|
|
377
|
+
get formErrors() {
|
|
378
|
+
return this.flatten();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
ZodError.create = (issues) => {
|
|
382
|
+
const error = new ZodError(issues);
|
|
383
|
+
return error;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// ../../node_modules/zod/v3/locales/en.js
|
|
387
|
+
var errorMap = (issue, _ctx) => {
|
|
388
|
+
let message;
|
|
389
|
+
switch (issue.code) {
|
|
390
|
+
case ZodIssueCode.invalid_type:
|
|
391
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
392
|
+
message = "Required";
|
|
393
|
+
} else {
|
|
394
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
case ZodIssueCode.invalid_literal:
|
|
398
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
399
|
+
break;
|
|
400
|
+
case ZodIssueCode.unrecognized_keys:
|
|
401
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
402
|
+
break;
|
|
403
|
+
case ZodIssueCode.invalid_union:
|
|
404
|
+
message = `Invalid input`;
|
|
405
|
+
break;
|
|
406
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
407
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
408
|
+
break;
|
|
409
|
+
case ZodIssueCode.invalid_enum_value:
|
|
410
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
411
|
+
break;
|
|
412
|
+
case ZodIssueCode.invalid_arguments:
|
|
413
|
+
message = `Invalid function arguments`;
|
|
414
|
+
break;
|
|
415
|
+
case ZodIssueCode.invalid_return_type:
|
|
416
|
+
message = `Invalid function return type`;
|
|
417
|
+
break;
|
|
418
|
+
case ZodIssueCode.invalid_date:
|
|
419
|
+
message = `Invalid date`;
|
|
420
|
+
break;
|
|
421
|
+
case ZodIssueCode.invalid_string:
|
|
422
|
+
if (typeof issue.validation === "object") {
|
|
423
|
+
if ("includes" in issue.validation) {
|
|
424
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
425
|
+
if (typeof issue.validation.position === "number") {
|
|
426
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
427
|
+
}
|
|
428
|
+
} else if ("startsWith" in issue.validation) {
|
|
429
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
430
|
+
} else if ("endsWith" in issue.validation) {
|
|
431
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
432
|
+
} else {
|
|
433
|
+
util.assertNever(issue.validation);
|
|
434
|
+
}
|
|
435
|
+
} else if (issue.validation !== "regex") {
|
|
436
|
+
message = `Invalid ${issue.validation}`;
|
|
437
|
+
} else {
|
|
438
|
+
message = "Invalid";
|
|
439
|
+
}
|
|
440
|
+
break;
|
|
441
|
+
case ZodIssueCode.too_small:
|
|
442
|
+
if (issue.type === "array")
|
|
443
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
444
|
+
else if (issue.type === "string")
|
|
445
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
446
|
+
else if (issue.type === "number")
|
|
447
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
448
|
+
else if (issue.type === "bigint")
|
|
449
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
450
|
+
else if (issue.type === "date")
|
|
451
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
452
|
+
else
|
|
453
|
+
message = "Invalid input";
|
|
454
|
+
break;
|
|
455
|
+
case ZodIssueCode.too_big:
|
|
456
|
+
if (issue.type === "array")
|
|
457
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
458
|
+
else if (issue.type === "string")
|
|
459
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
460
|
+
else if (issue.type === "number")
|
|
461
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
462
|
+
else if (issue.type === "bigint")
|
|
463
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
464
|
+
else if (issue.type === "date")
|
|
465
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
466
|
+
else
|
|
467
|
+
message = "Invalid input";
|
|
468
|
+
break;
|
|
469
|
+
case ZodIssueCode.custom:
|
|
470
|
+
message = `Invalid input`;
|
|
471
|
+
break;
|
|
472
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
473
|
+
message = `Intersection results could not be merged`;
|
|
474
|
+
break;
|
|
475
|
+
case ZodIssueCode.not_multiple_of:
|
|
476
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
477
|
+
break;
|
|
478
|
+
case ZodIssueCode.not_finite:
|
|
479
|
+
message = "Number must be finite";
|
|
480
|
+
break;
|
|
481
|
+
default:
|
|
482
|
+
message = _ctx.defaultError;
|
|
483
|
+
util.assertNever(issue);
|
|
484
|
+
}
|
|
485
|
+
return { message };
|
|
486
|
+
};
|
|
487
|
+
var en_default = errorMap;
|
|
488
|
+
|
|
489
|
+
// ../../node_modules/zod/v3/errors.js
|
|
490
|
+
var overrideErrorMap = en_default;
|
|
491
|
+
function setErrorMap(map) {
|
|
492
|
+
overrideErrorMap = map;
|
|
493
|
+
}
|
|
494
|
+
function getErrorMap() {
|
|
495
|
+
return overrideErrorMap;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
499
|
+
var makeIssue = (params) => {
|
|
500
|
+
const { data, path: path4, errorMaps, issueData } = params;
|
|
501
|
+
const fullPath = [...path4, ...issueData.path || []];
|
|
502
|
+
const fullIssue = {
|
|
503
|
+
...issueData,
|
|
504
|
+
path: fullPath
|
|
505
|
+
};
|
|
506
|
+
if (issueData.message !== void 0) {
|
|
507
|
+
return {
|
|
508
|
+
...issueData,
|
|
509
|
+
path: fullPath,
|
|
510
|
+
message: issueData.message
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
let errorMessage = "";
|
|
514
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
515
|
+
for (const map of maps) {
|
|
516
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
...issueData,
|
|
520
|
+
path: fullPath,
|
|
521
|
+
message: errorMessage
|
|
522
|
+
};
|
|
523
|
+
};
|
|
524
|
+
var EMPTY_PATH = [];
|
|
525
|
+
function addIssueToContext(ctx, issueData) {
|
|
526
|
+
const overrideMap = getErrorMap();
|
|
527
|
+
const issue = makeIssue({
|
|
528
|
+
issueData,
|
|
529
|
+
data: ctx.data,
|
|
530
|
+
path: ctx.path,
|
|
531
|
+
errorMaps: [
|
|
532
|
+
ctx.common.contextualErrorMap,
|
|
533
|
+
// contextual error map is first priority
|
|
534
|
+
ctx.schemaErrorMap,
|
|
535
|
+
// then schema-bound map if available
|
|
536
|
+
overrideMap,
|
|
537
|
+
// then global override map
|
|
538
|
+
overrideMap === en_default ? void 0 : en_default
|
|
539
|
+
// then global default map
|
|
540
|
+
].filter((x) => !!x)
|
|
541
|
+
});
|
|
542
|
+
ctx.common.issues.push(issue);
|
|
543
|
+
}
|
|
544
|
+
var ParseStatus = class _ParseStatus {
|
|
545
|
+
constructor() {
|
|
546
|
+
this.value = "valid";
|
|
547
|
+
}
|
|
548
|
+
dirty() {
|
|
549
|
+
if (this.value === "valid")
|
|
550
|
+
this.value = "dirty";
|
|
551
|
+
}
|
|
552
|
+
abort() {
|
|
553
|
+
if (this.value !== "aborted")
|
|
554
|
+
this.value = "aborted";
|
|
555
|
+
}
|
|
556
|
+
static mergeArray(status, results) {
|
|
557
|
+
const arrayValue = [];
|
|
558
|
+
for (const s of results) {
|
|
559
|
+
if (s.status === "aborted")
|
|
560
|
+
return INVALID;
|
|
561
|
+
if (s.status === "dirty")
|
|
562
|
+
status.dirty();
|
|
563
|
+
arrayValue.push(s.value);
|
|
564
|
+
}
|
|
565
|
+
return { status: status.value, value: arrayValue };
|
|
566
|
+
}
|
|
567
|
+
static async mergeObjectAsync(status, pairs) {
|
|
568
|
+
const syncPairs = [];
|
|
569
|
+
for (const pair of pairs) {
|
|
570
|
+
const key = await pair.key;
|
|
571
|
+
const value = await pair.value;
|
|
572
|
+
syncPairs.push({
|
|
573
|
+
key,
|
|
574
|
+
value
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
578
|
+
}
|
|
579
|
+
static mergeObjectSync(status, pairs) {
|
|
580
|
+
const finalObject = {};
|
|
581
|
+
for (const pair of pairs) {
|
|
582
|
+
const { key, value } = pair;
|
|
583
|
+
if (key.status === "aborted")
|
|
584
|
+
return INVALID;
|
|
585
|
+
if (value.status === "aborted")
|
|
586
|
+
return INVALID;
|
|
587
|
+
if (key.status === "dirty")
|
|
588
|
+
status.dirty();
|
|
589
|
+
if (value.status === "dirty")
|
|
590
|
+
status.dirty();
|
|
591
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
592
|
+
finalObject[key.value] = value.value;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return { status: status.value, value: finalObject };
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
var INVALID = Object.freeze({
|
|
599
|
+
status: "aborted"
|
|
600
|
+
});
|
|
601
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
602
|
+
var OK = (value) => ({ status: "valid", value });
|
|
603
|
+
var isAborted = (x) => x.status === "aborted";
|
|
604
|
+
var isDirty = (x) => x.status === "dirty";
|
|
605
|
+
var isValid = (x) => x.status === "valid";
|
|
606
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
607
|
+
|
|
608
|
+
// ../../node_modules/zod/v3/helpers/errorUtil.js
|
|
609
|
+
var errorUtil;
|
|
610
|
+
(function(errorUtil2) {
|
|
611
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
612
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
613
|
+
})(errorUtil || (errorUtil = {}));
|
|
614
|
+
|
|
615
|
+
// ../../node_modules/zod/v3/types.js
|
|
616
|
+
var ParseInputLazyPath = class {
|
|
617
|
+
constructor(parent, value, path4, key) {
|
|
618
|
+
this._cachedPath = [];
|
|
619
|
+
this.parent = parent;
|
|
620
|
+
this.data = value;
|
|
621
|
+
this._path = path4;
|
|
622
|
+
this._key = key;
|
|
623
|
+
}
|
|
624
|
+
get path() {
|
|
625
|
+
if (!this._cachedPath.length) {
|
|
626
|
+
if (Array.isArray(this._key)) {
|
|
627
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
628
|
+
} else {
|
|
629
|
+
this._cachedPath.push(...this._path, this._key);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return this._cachedPath;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
var handleResult = (ctx, result) => {
|
|
636
|
+
if (isValid(result)) {
|
|
637
|
+
return { success: true, data: result.value };
|
|
638
|
+
} else {
|
|
639
|
+
if (!ctx.common.issues.length) {
|
|
640
|
+
throw new Error("Validation failed but no issues detected.");
|
|
641
|
+
}
|
|
642
|
+
return {
|
|
643
|
+
success: false,
|
|
644
|
+
get error() {
|
|
645
|
+
if (this._error)
|
|
646
|
+
return this._error;
|
|
647
|
+
const error = new ZodError(ctx.common.issues);
|
|
648
|
+
this._error = error;
|
|
649
|
+
return this._error;
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
function processCreateParams(params) {
|
|
655
|
+
if (!params)
|
|
656
|
+
return {};
|
|
657
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
658
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
659
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
660
|
+
}
|
|
661
|
+
if (errorMap2)
|
|
662
|
+
return { errorMap: errorMap2, description };
|
|
663
|
+
const customMap = (iss, ctx) => {
|
|
664
|
+
const { message } = params;
|
|
665
|
+
if (iss.code === "invalid_enum_value") {
|
|
666
|
+
return { message: message ?? ctx.defaultError };
|
|
667
|
+
}
|
|
668
|
+
if (typeof ctx.data === "undefined") {
|
|
669
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
670
|
+
}
|
|
671
|
+
if (iss.code !== "invalid_type")
|
|
672
|
+
return { message: ctx.defaultError };
|
|
673
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
674
|
+
};
|
|
675
|
+
return { errorMap: customMap, description };
|
|
676
|
+
}
|
|
677
|
+
var ZodType = class {
|
|
678
|
+
get description() {
|
|
679
|
+
return this._def.description;
|
|
680
|
+
}
|
|
681
|
+
_getType(input) {
|
|
682
|
+
return getParsedType(input.data);
|
|
683
|
+
}
|
|
684
|
+
_getOrReturnCtx(input, ctx) {
|
|
685
|
+
return ctx || {
|
|
686
|
+
common: input.parent.common,
|
|
687
|
+
data: input.data,
|
|
688
|
+
parsedType: getParsedType(input.data),
|
|
689
|
+
schemaErrorMap: this._def.errorMap,
|
|
690
|
+
path: input.path,
|
|
691
|
+
parent: input.parent
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
_processInputParams(input) {
|
|
695
|
+
return {
|
|
696
|
+
status: new ParseStatus(),
|
|
697
|
+
ctx: {
|
|
698
|
+
common: input.parent.common,
|
|
699
|
+
data: input.data,
|
|
700
|
+
parsedType: getParsedType(input.data),
|
|
701
|
+
schemaErrorMap: this._def.errorMap,
|
|
702
|
+
path: input.path,
|
|
703
|
+
parent: input.parent
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
_parseSync(input) {
|
|
708
|
+
const result = this._parse(input);
|
|
709
|
+
if (isAsync(result)) {
|
|
710
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
711
|
+
}
|
|
712
|
+
return result;
|
|
713
|
+
}
|
|
714
|
+
_parseAsync(input) {
|
|
715
|
+
const result = this._parse(input);
|
|
716
|
+
return Promise.resolve(result);
|
|
717
|
+
}
|
|
718
|
+
parse(data, params) {
|
|
719
|
+
const result = this.safeParse(data, params);
|
|
720
|
+
if (result.success)
|
|
721
|
+
return result.data;
|
|
722
|
+
throw result.error;
|
|
723
|
+
}
|
|
724
|
+
safeParse(data, params) {
|
|
725
|
+
const ctx = {
|
|
726
|
+
common: {
|
|
727
|
+
issues: [],
|
|
728
|
+
async: params?.async ?? false,
|
|
729
|
+
contextualErrorMap: params?.errorMap
|
|
730
|
+
},
|
|
731
|
+
path: params?.path || [],
|
|
732
|
+
schemaErrorMap: this._def.errorMap,
|
|
733
|
+
parent: null,
|
|
734
|
+
data,
|
|
735
|
+
parsedType: getParsedType(data)
|
|
736
|
+
};
|
|
737
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
738
|
+
return handleResult(ctx, result);
|
|
739
|
+
}
|
|
740
|
+
"~validate"(data) {
|
|
741
|
+
const ctx = {
|
|
742
|
+
common: {
|
|
743
|
+
issues: [],
|
|
744
|
+
async: !!this["~standard"].async
|
|
745
|
+
},
|
|
746
|
+
path: [],
|
|
747
|
+
schemaErrorMap: this._def.errorMap,
|
|
748
|
+
parent: null,
|
|
749
|
+
data,
|
|
750
|
+
parsedType: getParsedType(data)
|
|
751
|
+
};
|
|
752
|
+
if (!this["~standard"].async) {
|
|
753
|
+
try {
|
|
754
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
755
|
+
return isValid(result) ? {
|
|
756
|
+
value: result.value
|
|
757
|
+
} : {
|
|
758
|
+
issues: ctx.common.issues
|
|
759
|
+
};
|
|
760
|
+
} catch (err) {
|
|
761
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
762
|
+
this["~standard"].async = true;
|
|
763
|
+
}
|
|
764
|
+
ctx.common = {
|
|
765
|
+
issues: [],
|
|
766
|
+
async: true
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
771
|
+
value: result.value
|
|
772
|
+
} : {
|
|
773
|
+
issues: ctx.common.issues
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
async parseAsync(data, params) {
|
|
777
|
+
const result = await this.safeParseAsync(data, params);
|
|
778
|
+
if (result.success)
|
|
779
|
+
return result.data;
|
|
780
|
+
throw result.error;
|
|
781
|
+
}
|
|
782
|
+
async safeParseAsync(data, params) {
|
|
783
|
+
const ctx = {
|
|
784
|
+
common: {
|
|
785
|
+
issues: [],
|
|
786
|
+
contextualErrorMap: params?.errorMap,
|
|
787
|
+
async: true
|
|
788
|
+
},
|
|
789
|
+
path: params?.path || [],
|
|
790
|
+
schemaErrorMap: this._def.errorMap,
|
|
791
|
+
parent: null,
|
|
792
|
+
data,
|
|
793
|
+
parsedType: getParsedType(data)
|
|
794
|
+
};
|
|
795
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
796
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
797
|
+
return handleResult(ctx, result);
|
|
798
|
+
}
|
|
799
|
+
refine(check, message) {
|
|
800
|
+
const getIssueProperties = (val) => {
|
|
801
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
802
|
+
return { message };
|
|
803
|
+
} else if (typeof message === "function") {
|
|
804
|
+
return message(val);
|
|
805
|
+
} else {
|
|
806
|
+
return message;
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
return this._refinement((val, ctx) => {
|
|
810
|
+
const result = check(val);
|
|
811
|
+
const setError = () => ctx.addIssue({
|
|
812
|
+
code: ZodIssueCode.custom,
|
|
813
|
+
...getIssueProperties(val)
|
|
814
|
+
});
|
|
815
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
816
|
+
return result.then((data) => {
|
|
817
|
+
if (!data) {
|
|
818
|
+
setError();
|
|
819
|
+
return false;
|
|
820
|
+
} else {
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (!result) {
|
|
826
|
+
setError();
|
|
827
|
+
return false;
|
|
828
|
+
} else {
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
refinement(check, refinementData) {
|
|
834
|
+
return this._refinement((val, ctx) => {
|
|
835
|
+
if (!check(val)) {
|
|
836
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
837
|
+
return false;
|
|
838
|
+
} else {
|
|
839
|
+
return true;
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
_refinement(refinement) {
|
|
844
|
+
return new ZodEffects({
|
|
845
|
+
schema: this,
|
|
846
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
847
|
+
effect: { type: "refinement", refinement }
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
superRefine(refinement) {
|
|
851
|
+
return this._refinement(refinement);
|
|
852
|
+
}
|
|
853
|
+
constructor(def) {
|
|
854
|
+
this.spa = this.safeParseAsync;
|
|
855
|
+
this._def = def;
|
|
856
|
+
this.parse = this.parse.bind(this);
|
|
857
|
+
this.safeParse = this.safeParse.bind(this);
|
|
858
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
859
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
860
|
+
this.spa = this.spa.bind(this);
|
|
861
|
+
this.refine = this.refine.bind(this);
|
|
862
|
+
this.refinement = this.refinement.bind(this);
|
|
863
|
+
this.superRefine = this.superRefine.bind(this);
|
|
864
|
+
this.optional = this.optional.bind(this);
|
|
865
|
+
this.nullable = this.nullable.bind(this);
|
|
866
|
+
this.nullish = this.nullish.bind(this);
|
|
867
|
+
this.array = this.array.bind(this);
|
|
868
|
+
this.promise = this.promise.bind(this);
|
|
869
|
+
this.or = this.or.bind(this);
|
|
870
|
+
this.and = this.and.bind(this);
|
|
871
|
+
this.transform = this.transform.bind(this);
|
|
872
|
+
this.brand = this.brand.bind(this);
|
|
873
|
+
this.default = this.default.bind(this);
|
|
874
|
+
this.catch = this.catch.bind(this);
|
|
875
|
+
this.describe = this.describe.bind(this);
|
|
876
|
+
this.pipe = this.pipe.bind(this);
|
|
877
|
+
this.readonly = this.readonly.bind(this);
|
|
878
|
+
this.isNullable = this.isNullable.bind(this);
|
|
879
|
+
this.isOptional = this.isOptional.bind(this);
|
|
880
|
+
this["~standard"] = {
|
|
881
|
+
version: 1,
|
|
882
|
+
vendor: "zod",
|
|
883
|
+
validate: (data) => this["~validate"](data)
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
optional() {
|
|
887
|
+
return ZodOptional.create(this, this._def);
|
|
888
|
+
}
|
|
889
|
+
nullable() {
|
|
890
|
+
return ZodNullable.create(this, this._def);
|
|
891
|
+
}
|
|
892
|
+
nullish() {
|
|
893
|
+
return this.nullable().optional();
|
|
894
|
+
}
|
|
895
|
+
array() {
|
|
896
|
+
return ZodArray.create(this);
|
|
897
|
+
}
|
|
898
|
+
promise() {
|
|
899
|
+
return ZodPromise.create(this, this._def);
|
|
900
|
+
}
|
|
901
|
+
or(option) {
|
|
902
|
+
return ZodUnion.create([this, option], this._def);
|
|
903
|
+
}
|
|
904
|
+
and(incoming) {
|
|
905
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
906
|
+
}
|
|
907
|
+
transform(transform) {
|
|
908
|
+
return new ZodEffects({
|
|
909
|
+
...processCreateParams(this._def),
|
|
910
|
+
schema: this,
|
|
911
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
912
|
+
effect: { type: "transform", transform }
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
default(def) {
|
|
916
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
917
|
+
return new ZodDefault({
|
|
918
|
+
...processCreateParams(this._def),
|
|
919
|
+
innerType: this,
|
|
920
|
+
defaultValue: defaultValueFunc,
|
|
921
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
brand() {
|
|
925
|
+
return new ZodBranded({
|
|
926
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
927
|
+
type: this,
|
|
928
|
+
...processCreateParams(this._def)
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
catch(def) {
|
|
932
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
933
|
+
return new ZodCatch({
|
|
934
|
+
...processCreateParams(this._def),
|
|
935
|
+
innerType: this,
|
|
936
|
+
catchValue: catchValueFunc,
|
|
937
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
describe(description) {
|
|
941
|
+
const This = this.constructor;
|
|
942
|
+
return new This({
|
|
943
|
+
...this._def,
|
|
944
|
+
description
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
pipe(target) {
|
|
948
|
+
return ZodPipeline.create(this, target);
|
|
949
|
+
}
|
|
950
|
+
readonly() {
|
|
951
|
+
return ZodReadonly.create(this);
|
|
952
|
+
}
|
|
953
|
+
isOptional() {
|
|
954
|
+
return this.safeParse(void 0).success;
|
|
955
|
+
}
|
|
956
|
+
isNullable() {
|
|
957
|
+
return this.safeParse(null).success;
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
961
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
962
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
963
|
+
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;
|
|
964
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
965
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
966
|
+
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)?)??$/;
|
|
967
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
968
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
969
|
+
var emojiRegex;
|
|
970
|
+
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])$/;
|
|
971
|
+
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])$/;
|
|
972
|
+
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]))$/;
|
|
973
|
+
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])$/;
|
|
974
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
975
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
976
|
+
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])))`;
|
|
977
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
978
|
+
function timeRegexSource(args) {
|
|
979
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
980
|
+
if (args.precision) {
|
|
981
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
982
|
+
} else if (args.precision == null) {
|
|
983
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
984
|
+
}
|
|
985
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
986
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
987
|
+
}
|
|
988
|
+
function timeRegex(args) {
|
|
989
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
990
|
+
}
|
|
991
|
+
function datetimeRegex(args) {
|
|
992
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
993
|
+
const opts = [];
|
|
994
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
995
|
+
if (args.offset)
|
|
996
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
997
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
998
|
+
return new RegExp(`^${regex}$`);
|
|
999
|
+
}
|
|
1000
|
+
function isValidIP(ip, version) {
|
|
1001
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
function isValidJWT(jwt, alg) {
|
|
1010
|
+
if (!jwtRegex.test(jwt))
|
|
1011
|
+
return false;
|
|
1012
|
+
try {
|
|
1013
|
+
const [header] = jwt.split(".");
|
|
1014
|
+
if (!header)
|
|
1015
|
+
return false;
|
|
1016
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1017
|
+
const decoded = JSON.parse(atob(base64));
|
|
1018
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1019
|
+
return false;
|
|
1020
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1021
|
+
return false;
|
|
1022
|
+
if (!decoded.alg)
|
|
1023
|
+
return false;
|
|
1024
|
+
if (alg && decoded.alg !== alg)
|
|
1025
|
+
return false;
|
|
1026
|
+
return true;
|
|
1027
|
+
} catch {
|
|
1028
|
+
return false;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
function isValidCidr(ip, version) {
|
|
1032
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1033
|
+
return true;
|
|
1034
|
+
}
|
|
1035
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1036
|
+
return true;
|
|
1037
|
+
}
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
var ZodString = class _ZodString extends ZodType {
|
|
1041
|
+
_parse(input) {
|
|
1042
|
+
if (this._def.coerce) {
|
|
1043
|
+
input.data = String(input.data);
|
|
1044
|
+
}
|
|
1045
|
+
const parsedType = this._getType(input);
|
|
1046
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1047
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1048
|
+
addIssueToContext(ctx2, {
|
|
1049
|
+
code: ZodIssueCode.invalid_type,
|
|
1050
|
+
expected: ZodParsedType.string,
|
|
1051
|
+
received: ctx2.parsedType
|
|
1052
|
+
});
|
|
1053
|
+
return INVALID;
|
|
1054
|
+
}
|
|
1055
|
+
const status = new ParseStatus();
|
|
1056
|
+
let ctx = void 0;
|
|
1057
|
+
for (const check of this._def.checks) {
|
|
1058
|
+
if (check.kind === "min") {
|
|
1059
|
+
if (input.data.length < check.value) {
|
|
1060
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1061
|
+
addIssueToContext(ctx, {
|
|
1062
|
+
code: ZodIssueCode.too_small,
|
|
1063
|
+
minimum: check.value,
|
|
1064
|
+
type: "string",
|
|
1065
|
+
inclusive: true,
|
|
1066
|
+
exact: false,
|
|
1067
|
+
message: check.message
|
|
1068
|
+
});
|
|
1069
|
+
status.dirty();
|
|
1070
|
+
}
|
|
1071
|
+
} else if (check.kind === "max") {
|
|
1072
|
+
if (input.data.length > check.value) {
|
|
1073
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1074
|
+
addIssueToContext(ctx, {
|
|
1075
|
+
code: ZodIssueCode.too_big,
|
|
1076
|
+
maximum: check.value,
|
|
1077
|
+
type: "string",
|
|
1078
|
+
inclusive: true,
|
|
1079
|
+
exact: false,
|
|
1080
|
+
message: check.message
|
|
1081
|
+
});
|
|
1082
|
+
status.dirty();
|
|
1083
|
+
}
|
|
1084
|
+
} else if (check.kind === "length") {
|
|
1085
|
+
const tooBig = input.data.length > check.value;
|
|
1086
|
+
const tooSmall = input.data.length < check.value;
|
|
1087
|
+
if (tooBig || tooSmall) {
|
|
1088
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1089
|
+
if (tooBig) {
|
|
1090
|
+
addIssueToContext(ctx, {
|
|
1091
|
+
code: ZodIssueCode.too_big,
|
|
1092
|
+
maximum: check.value,
|
|
1093
|
+
type: "string",
|
|
1094
|
+
inclusive: true,
|
|
1095
|
+
exact: true,
|
|
1096
|
+
message: check.message
|
|
1097
|
+
});
|
|
1098
|
+
} else if (tooSmall) {
|
|
1099
|
+
addIssueToContext(ctx, {
|
|
1100
|
+
code: ZodIssueCode.too_small,
|
|
1101
|
+
minimum: check.value,
|
|
1102
|
+
type: "string",
|
|
1103
|
+
inclusive: true,
|
|
1104
|
+
exact: true,
|
|
1105
|
+
message: check.message
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
status.dirty();
|
|
1109
|
+
}
|
|
1110
|
+
} else if (check.kind === "email") {
|
|
1111
|
+
if (!emailRegex.test(input.data)) {
|
|
1112
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1113
|
+
addIssueToContext(ctx, {
|
|
1114
|
+
validation: "email",
|
|
1115
|
+
code: ZodIssueCode.invalid_string,
|
|
1116
|
+
message: check.message
|
|
1117
|
+
});
|
|
1118
|
+
status.dirty();
|
|
1119
|
+
}
|
|
1120
|
+
} else if (check.kind === "emoji") {
|
|
1121
|
+
if (!emojiRegex) {
|
|
1122
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1123
|
+
}
|
|
1124
|
+
if (!emojiRegex.test(input.data)) {
|
|
1125
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1126
|
+
addIssueToContext(ctx, {
|
|
1127
|
+
validation: "emoji",
|
|
1128
|
+
code: ZodIssueCode.invalid_string,
|
|
1129
|
+
message: check.message
|
|
1130
|
+
});
|
|
1131
|
+
status.dirty();
|
|
1132
|
+
}
|
|
1133
|
+
} else if (check.kind === "uuid") {
|
|
1134
|
+
if (!uuidRegex.test(input.data)) {
|
|
1135
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1136
|
+
addIssueToContext(ctx, {
|
|
1137
|
+
validation: "uuid",
|
|
1138
|
+
code: ZodIssueCode.invalid_string,
|
|
1139
|
+
message: check.message
|
|
1140
|
+
});
|
|
1141
|
+
status.dirty();
|
|
1142
|
+
}
|
|
1143
|
+
} else if (check.kind === "nanoid") {
|
|
1144
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1145
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1146
|
+
addIssueToContext(ctx, {
|
|
1147
|
+
validation: "nanoid",
|
|
1148
|
+
code: ZodIssueCode.invalid_string,
|
|
1149
|
+
message: check.message
|
|
1150
|
+
});
|
|
1151
|
+
status.dirty();
|
|
1152
|
+
}
|
|
1153
|
+
} else if (check.kind === "cuid") {
|
|
1154
|
+
if (!cuidRegex.test(input.data)) {
|
|
1155
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1156
|
+
addIssueToContext(ctx, {
|
|
1157
|
+
validation: "cuid",
|
|
1158
|
+
code: ZodIssueCode.invalid_string,
|
|
1159
|
+
message: check.message
|
|
1160
|
+
});
|
|
1161
|
+
status.dirty();
|
|
1162
|
+
}
|
|
1163
|
+
} else if (check.kind === "cuid2") {
|
|
1164
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1165
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1166
|
+
addIssueToContext(ctx, {
|
|
1167
|
+
validation: "cuid2",
|
|
1168
|
+
code: ZodIssueCode.invalid_string,
|
|
1169
|
+
message: check.message
|
|
1170
|
+
});
|
|
1171
|
+
status.dirty();
|
|
1172
|
+
}
|
|
1173
|
+
} else if (check.kind === "ulid") {
|
|
1174
|
+
if (!ulidRegex.test(input.data)) {
|
|
1175
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1176
|
+
addIssueToContext(ctx, {
|
|
1177
|
+
validation: "ulid",
|
|
1178
|
+
code: ZodIssueCode.invalid_string,
|
|
1179
|
+
message: check.message
|
|
1180
|
+
});
|
|
1181
|
+
status.dirty();
|
|
1182
|
+
}
|
|
1183
|
+
} else if (check.kind === "url") {
|
|
1184
|
+
try {
|
|
1185
|
+
new URL(input.data);
|
|
1186
|
+
} catch {
|
|
1187
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1188
|
+
addIssueToContext(ctx, {
|
|
1189
|
+
validation: "url",
|
|
1190
|
+
code: ZodIssueCode.invalid_string,
|
|
1191
|
+
message: check.message
|
|
1192
|
+
});
|
|
1193
|
+
status.dirty();
|
|
1194
|
+
}
|
|
1195
|
+
} else if (check.kind === "regex") {
|
|
1196
|
+
check.regex.lastIndex = 0;
|
|
1197
|
+
const testResult = check.regex.test(input.data);
|
|
1198
|
+
if (!testResult) {
|
|
1199
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1200
|
+
addIssueToContext(ctx, {
|
|
1201
|
+
validation: "regex",
|
|
1202
|
+
code: ZodIssueCode.invalid_string,
|
|
1203
|
+
message: check.message
|
|
1204
|
+
});
|
|
1205
|
+
status.dirty();
|
|
1206
|
+
}
|
|
1207
|
+
} else if (check.kind === "trim") {
|
|
1208
|
+
input.data = input.data.trim();
|
|
1209
|
+
} else if (check.kind === "includes") {
|
|
1210
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1211
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1212
|
+
addIssueToContext(ctx, {
|
|
1213
|
+
code: ZodIssueCode.invalid_string,
|
|
1214
|
+
validation: { includes: check.value, position: check.position },
|
|
1215
|
+
message: check.message
|
|
1216
|
+
});
|
|
1217
|
+
status.dirty();
|
|
1218
|
+
}
|
|
1219
|
+
} else if (check.kind === "toLowerCase") {
|
|
1220
|
+
input.data = input.data.toLowerCase();
|
|
1221
|
+
} else if (check.kind === "toUpperCase") {
|
|
1222
|
+
input.data = input.data.toUpperCase();
|
|
1223
|
+
} else if (check.kind === "startsWith") {
|
|
1224
|
+
if (!input.data.startsWith(check.value)) {
|
|
1225
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1226
|
+
addIssueToContext(ctx, {
|
|
1227
|
+
code: ZodIssueCode.invalid_string,
|
|
1228
|
+
validation: { startsWith: check.value },
|
|
1229
|
+
message: check.message
|
|
1230
|
+
});
|
|
1231
|
+
status.dirty();
|
|
1232
|
+
}
|
|
1233
|
+
} else if (check.kind === "endsWith") {
|
|
1234
|
+
if (!input.data.endsWith(check.value)) {
|
|
1235
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1236
|
+
addIssueToContext(ctx, {
|
|
1237
|
+
code: ZodIssueCode.invalid_string,
|
|
1238
|
+
validation: { endsWith: check.value },
|
|
1239
|
+
message: check.message
|
|
1240
|
+
});
|
|
1241
|
+
status.dirty();
|
|
1242
|
+
}
|
|
1243
|
+
} else if (check.kind === "datetime") {
|
|
1244
|
+
const regex = datetimeRegex(check);
|
|
1245
|
+
if (!regex.test(input.data)) {
|
|
1246
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1247
|
+
addIssueToContext(ctx, {
|
|
1248
|
+
code: ZodIssueCode.invalid_string,
|
|
1249
|
+
validation: "datetime",
|
|
1250
|
+
message: check.message
|
|
1251
|
+
});
|
|
1252
|
+
status.dirty();
|
|
1253
|
+
}
|
|
1254
|
+
} else if (check.kind === "date") {
|
|
1255
|
+
const regex = dateRegex;
|
|
1256
|
+
if (!regex.test(input.data)) {
|
|
1257
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1258
|
+
addIssueToContext(ctx, {
|
|
1259
|
+
code: ZodIssueCode.invalid_string,
|
|
1260
|
+
validation: "date",
|
|
1261
|
+
message: check.message
|
|
1262
|
+
});
|
|
1263
|
+
status.dirty();
|
|
1264
|
+
}
|
|
1265
|
+
} else if (check.kind === "time") {
|
|
1266
|
+
const regex = timeRegex(check);
|
|
1267
|
+
if (!regex.test(input.data)) {
|
|
1268
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1269
|
+
addIssueToContext(ctx, {
|
|
1270
|
+
code: ZodIssueCode.invalid_string,
|
|
1271
|
+
validation: "time",
|
|
1272
|
+
message: check.message
|
|
1273
|
+
});
|
|
1274
|
+
status.dirty();
|
|
1275
|
+
}
|
|
1276
|
+
} else if (check.kind === "duration") {
|
|
1277
|
+
if (!durationRegex.test(input.data)) {
|
|
1278
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1279
|
+
addIssueToContext(ctx, {
|
|
1280
|
+
validation: "duration",
|
|
1281
|
+
code: ZodIssueCode.invalid_string,
|
|
1282
|
+
message: check.message
|
|
1283
|
+
});
|
|
1284
|
+
status.dirty();
|
|
1285
|
+
}
|
|
1286
|
+
} else if (check.kind === "ip") {
|
|
1287
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1288
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1289
|
+
addIssueToContext(ctx, {
|
|
1290
|
+
validation: "ip",
|
|
1291
|
+
code: ZodIssueCode.invalid_string,
|
|
1292
|
+
message: check.message
|
|
1293
|
+
});
|
|
1294
|
+
status.dirty();
|
|
1295
|
+
}
|
|
1296
|
+
} else if (check.kind === "jwt") {
|
|
1297
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1298
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1299
|
+
addIssueToContext(ctx, {
|
|
1300
|
+
validation: "jwt",
|
|
1301
|
+
code: ZodIssueCode.invalid_string,
|
|
1302
|
+
message: check.message
|
|
1303
|
+
});
|
|
1304
|
+
status.dirty();
|
|
1305
|
+
}
|
|
1306
|
+
} else if (check.kind === "cidr") {
|
|
1307
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1308
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1309
|
+
addIssueToContext(ctx, {
|
|
1310
|
+
validation: "cidr",
|
|
1311
|
+
code: ZodIssueCode.invalid_string,
|
|
1312
|
+
message: check.message
|
|
1313
|
+
});
|
|
1314
|
+
status.dirty();
|
|
1315
|
+
}
|
|
1316
|
+
} else if (check.kind === "base64") {
|
|
1317
|
+
if (!base64Regex.test(input.data)) {
|
|
1318
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1319
|
+
addIssueToContext(ctx, {
|
|
1320
|
+
validation: "base64",
|
|
1321
|
+
code: ZodIssueCode.invalid_string,
|
|
1322
|
+
message: check.message
|
|
1323
|
+
});
|
|
1324
|
+
status.dirty();
|
|
1325
|
+
}
|
|
1326
|
+
} else if (check.kind === "base64url") {
|
|
1327
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1328
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1329
|
+
addIssueToContext(ctx, {
|
|
1330
|
+
validation: "base64url",
|
|
1331
|
+
code: ZodIssueCode.invalid_string,
|
|
1332
|
+
message: check.message
|
|
1333
|
+
});
|
|
1334
|
+
status.dirty();
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
util.assertNever(check);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return { status: status.value, value: input.data };
|
|
1341
|
+
}
|
|
1342
|
+
_regex(regex, validation, message) {
|
|
1343
|
+
return this.refinement((data) => regex.test(data), {
|
|
1344
|
+
validation,
|
|
1345
|
+
code: ZodIssueCode.invalid_string,
|
|
1346
|
+
...errorUtil.errToObj(message)
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
_addCheck(check) {
|
|
1350
|
+
return new _ZodString({
|
|
1351
|
+
...this._def,
|
|
1352
|
+
checks: [...this._def.checks, check]
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
email(message) {
|
|
1356
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1357
|
+
}
|
|
1358
|
+
url(message) {
|
|
1359
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1360
|
+
}
|
|
1361
|
+
emoji(message) {
|
|
1362
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1363
|
+
}
|
|
1364
|
+
uuid(message) {
|
|
1365
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1366
|
+
}
|
|
1367
|
+
nanoid(message) {
|
|
1368
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1369
|
+
}
|
|
1370
|
+
cuid(message) {
|
|
1371
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1372
|
+
}
|
|
1373
|
+
cuid2(message) {
|
|
1374
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1375
|
+
}
|
|
1376
|
+
ulid(message) {
|
|
1377
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1378
|
+
}
|
|
1379
|
+
base64(message) {
|
|
1380
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1381
|
+
}
|
|
1382
|
+
base64url(message) {
|
|
1383
|
+
return this._addCheck({
|
|
1384
|
+
kind: "base64url",
|
|
1385
|
+
...errorUtil.errToObj(message)
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
jwt(options) {
|
|
1389
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1390
|
+
}
|
|
1391
|
+
ip(options) {
|
|
1392
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1393
|
+
}
|
|
1394
|
+
cidr(options) {
|
|
1395
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1396
|
+
}
|
|
1397
|
+
datetime(options) {
|
|
1398
|
+
if (typeof options === "string") {
|
|
1399
|
+
return this._addCheck({
|
|
1400
|
+
kind: "datetime",
|
|
1401
|
+
precision: null,
|
|
1402
|
+
offset: false,
|
|
1403
|
+
local: false,
|
|
1404
|
+
message: options
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
return this._addCheck({
|
|
1408
|
+
kind: "datetime",
|
|
1409
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1410
|
+
offset: options?.offset ?? false,
|
|
1411
|
+
local: options?.local ?? false,
|
|
1412
|
+
...errorUtil.errToObj(options?.message)
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
date(message) {
|
|
1416
|
+
return this._addCheck({ kind: "date", message });
|
|
1417
|
+
}
|
|
1418
|
+
time(options) {
|
|
1419
|
+
if (typeof options === "string") {
|
|
1420
|
+
return this._addCheck({
|
|
1421
|
+
kind: "time",
|
|
1422
|
+
precision: null,
|
|
1423
|
+
message: options
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
return this._addCheck({
|
|
1427
|
+
kind: "time",
|
|
1428
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1429
|
+
...errorUtil.errToObj(options?.message)
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
duration(message) {
|
|
1433
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1434
|
+
}
|
|
1435
|
+
regex(regex, message) {
|
|
1436
|
+
return this._addCheck({
|
|
1437
|
+
kind: "regex",
|
|
1438
|
+
regex,
|
|
1439
|
+
...errorUtil.errToObj(message)
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
includes(value, options) {
|
|
1443
|
+
return this._addCheck({
|
|
1444
|
+
kind: "includes",
|
|
1445
|
+
value,
|
|
1446
|
+
position: options?.position,
|
|
1447
|
+
...errorUtil.errToObj(options?.message)
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
startsWith(value, message) {
|
|
1451
|
+
return this._addCheck({
|
|
1452
|
+
kind: "startsWith",
|
|
1453
|
+
value,
|
|
1454
|
+
...errorUtil.errToObj(message)
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
endsWith(value, message) {
|
|
1458
|
+
return this._addCheck({
|
|
1459
|
+
kind: "endsWith",
|
|
1460
|
+
value,
|
|
1461
|
+
...errorUtil.errToObj(message)
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
min(minLength, message) {
|
|
1465
|
+
return this._addCheck({
|
|
1466
|
+
kind: "min",
|
|
1467
|
+
value: minLength,
|
|
1468
|
+
...errorUtil.errToObj(message)
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
max(maxLength, message) {
|
|
1472
|
+
return this._addCheck({
|
|
1473
|
+
kind: "max",
|
|
1474
|
+
value: maxLength,
|
|
1475
|
+
...errorUtil.errToObj(message)
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
length(len, message) {
|
|
1479
|
+
return this._addCheck({
|
|
1480
|
+
kind: "length",
|
|
1481
|
+
value: len,
|
|
1482
|
+
...errorUtil.errToObj(message)
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Equivalent to `.min(1)`
|
|
1487
|
+
*/
|
|
1488
|
+
nonempty(message) {
|
|
1489
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1490
|
+
}
|
|
1491
|
+
trim() {
|
|
1492
|
+
return new _ZodString({
|
|
1493
|
+
...this._def,
|
|
1494
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
toLowerCase() {
|
|
1498
|
+
return new _ZodString({
|
|
1499
|
+
...this._def,
|
|
1500
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
toUpperCase() {
|
|
1504
|
+
return new _ZodString({
|
|
1505
|
+
...this._def,
|
|
1506
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
get isDatetime() {
|
|
1510
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1511
|
+
}
|
|
1512
|
+
get isDate() {
|
|
1513
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1514
|
+
}
|
|
1515
|
+
get isTime() {
|
|
1516
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1517
|
+
}
|
|
1518
|
+
get isDuration() {
|
|
1519
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1520
|
+
}
|
|
1521
|
+
get isEmail() {
|
|
1522
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1523
|
+
}
|
|
1524
|
+
get isURL() {
|
|
1525
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1526
|
+
}
|
|
1527
|
+
get isEmoji() {
|
|
1528
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1529
|
+
}
|
|
1530
|
+
get isUUID() {
|
|
1531
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1532
|
+
}
|
|
1533
|
+
get isNANOID() {
|
|
1534
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1535
|
+
}
|
|
1536
|
+
get isCUID() {
|
|
1537
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1538
|
+
}
|
|
1539
|
+
get isCUID2() {
|
|
1540
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1541
|
+
}
|
|
1542
|
+
get isULID() {
|
|
1543
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1544
|
+
}
|
|
1545
|
+
get isIP() {
|
|
1546
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1547
|
+
}
|
|
1548
|
+
get isCIDR() {
|
|
1549
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1550
|
+
}
|
|
1551
|
+
get isBase64() {
|
|
1552
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1553
|
+
}
|
|
1554
|
+
get isBase64url() {
|
|
1555
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1556
|
+
}
|
|
1557
|
+
get minLength() {
|
|
1558
|
+
let min = null;
|
|
1559
|
+
for (const ch of this._def.checks) {
|
|
1560
|
+
if (ch.kind === "min") {
|
|
1561
|
+
if (min === null || ch.value > min)
|
|
1562
|
+
min = ch.value;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return min;
|
|
1566
|
+
}
|
|
1567
|
+
get maxLength() {
|
|
1568
|
+
let max = null;
|
|
1569
|
+
for (const ch of this._def.checks) {
|
|
1570
|
+
if (ch.kind === "max") {
|
|
1571
|
+
if (max === null || ch.value < max)
|
|
1572
|
+
max = ch.value;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return max;
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
ZodString.create = (params) => {
|
|
1579
|
+
return new ZodString({
|
|
1580
|
+
checks: [],
|
|
1581
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1582
|
+
coerce: params?.coerce ?? false,
|
|
1583
|
+
...processCreateParams(params)
|
|
1584
|
+
});
|
|
1585
|
+
};
|
|
1586
|
+
function floatSafeRemainder(val, step) {
|
|
1587
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1588
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1589
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1590
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1591
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1592
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1593
|
+
}
|
|
1594
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1595
|
+
constructor() {
|
|
1596
|
+
super(...arguments);
|
|
1597
|
+
this.min = this.gte;
|
|
1598
|
+
this.max = this.lte;
|
|
1599
|
+
this.step = this.multipleOf;
|
|
1600
|
+
}
|
|
1601
|
+
_parse(input) {
|
|
1602
|
+
if (this._def.coerce) {
|
|
1603
|
+
input.data = Number(input.data);
|
|
1604
|
+
}
|
|
1605
|
+
const parsedType = this._getType(input);
|
|
1606
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1607
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1608
|
+
addIssueToContext(ctx2, {
|
|
1609
|
+
code: ZodIssueCode.invalid_type,
|
|
1610
|
+
expected: ZodParsedType.number,
|
|
1611
|
+
received: ctx2.parsedType
|
|
1612
|
+
});
|
|
1613
|
+
return INVALID;
|
|
1614
|
+
}
|
|
1615
|
+
let ctx = void 0;
|
|
1616
|
+
const status = new ParseStatus();
|
|
1617
|
+
for (const check of this._def.checks) {
|
|
1618
|
+
if (check.kind === "int") {
|
|
1619
|
+
if (!util.isInteger(input.data)) {
|
|
1620
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1621
|
+
addIssueToContext(ctx, {
|
|
1622
|
+
code: ZodIssueCode.invalid_type,
|
|
1623
|
+
expected: "integer",
|
|
1624
|
+
received: "float",
|
|
1625
|
+
message: check.message
|
|
1626
|
+
});
|
|
1627
|
+
status.dirty();
|
|
1628
|
+
}
|
|
1629
|
+
} else if (check.kind === "min") {
|
|
1630
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1631
|
+
if (tooSmall) {
|
|
1632
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1633
|
+
addIssueToContext(ctx, {
|
|
1634
|
+
code: ZodIssueCode.too_small,
|
|
1635
|
+
minimum: check.value,
|
|
1636
|
+
type: "number",
|
|
1637
|
+
inclusive: check.inclusive,
|
|
1638
|
+
exact: false,
|
|
1639
|
+
message: check.message
|
|
1640
|
+
});
|
|
1641
|
+
status.dirty();
|
|
1642
|
+
}
|
|
1643
|
+
} else if (check.kind === "max") {
|
|
1644
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1645
|
+
if (tooBig) {
|
|
1646
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1647
|
+
addIssueToContext(ctx, {
|
|
1648
|
+
code: ZodIssueCode.too_big,
|
|
1649
|
+
maximum: check.value,
|
|
1650
|
+
type: "number",
|
|
1651
|
+
inclusive: check.inclusive,
|
|
1652
|
+
exact: false,
|
|
1653
|
+
message: check.message
|
|
1654
|
+
});
|
|
1655
|
+
status.dirty();
|
|
1656
|
+
}
|
|
1657
|
+
} else if (check.kind === "multipleOf") {
|
|
1658
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1659
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1660
|
+
addIssueToContext(ctx, {
|
|
1661
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1662
|
+
multipleOf: check.value,
|
|
1663
|
+
message: check.message
|
|
1664
|
+
});
|
|
1665
|
+
status.dirty();
|
|
1666
|
+
}
|
|
1667
|
+
} else if (check.kind === "finite") {
|
|
1668
|
+
if (!Number.isFinite(input.data)) {
|
|
1669
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1670
|
+
addIssueToContext(ctx, {
|
|
1671
|
+
code: ZodIssueCode.not_finite,
|
|
1672
|
+
message: check.message
|
|
1673
|
+
});
|
|
1674
|
+
status.dirty();
|
|
1675
|
+
}
|
|
1676
|
+
} else {
|
|
1677
|
+
util.assertNever(check);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
return { status: status.value, value: input.data };
|
|
1681
|
+
}
|
|
1682
|
+
gte(value, message) {
|
|
1683
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1684
|
+
}
|
|
1685
|
+
gt(value, message) {
|
|
1686
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1687
|
+
}
|
|
1688
|
+
lte(value, message) {
|
|
1689
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1690
|
+
}
|
|
1691
|
+
lt(value, message) {
|
|
1692
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1693
|
+
}
|
|
1694
|
+
setLimit(kind, value, inclusive, message) {
|
|
1695
|
+
return new _ZodNumber({
|
|
1696
|
+
...this._def,
|
|
1697
|
+
checks: [
|
|
1698
|
+
...this._def.checks,
|
|
1699
|
+
{
|
|
1700
|
+
kind,
|
|
1701
|
+
value,
|
|
1702
|
+
inclusive,
|
|
1703
|
+
message: errorUtil.toString(message)
|
|
1704
|
+
}
|
|
1705
|
+
]
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
_addCheck(check) {
|
|
1709
|
+
return new _ZodNumber({
|
|
1710
|
+
...this._def,
|
|
1711
|
+
checks: [...this._def.checks, check]
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
int(message) {
|
|
1715
|
+
return this._addCheck({
|
|
1716
|
+
kind: "int",
|
|
1717
|
+
message: errorUtil.toString(message)
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
positive(message) {
|
|
1721
|
+
return this._addCheck({
|
|
1722
|
+
kind: "min",
|
|
1723
|
+
value: 0,
|
|
1724
|
+
inclusive: false,
|
|
1725
|
+
message: errorUtil.toString(message)
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
negative(message) {
|
|
1729
|
+
return this._addCheck({
|
|
1730
|
+
kind: "max",
|
|
1731
|
+
value: 0,
|
|
1732
|
+
inclusive: false,
|
|
1733
|
+
message: errorUtil.toString(message)
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
nonpositive(message) {
|
|
1737
|
+
return this._addCheck({
|
|
1738
|
+
kind: "max",
|
|
1739
|
+
value: 0,
|
|
1740
|
+
inclusive: true,
|
|
1741
|
+
message: errorUtil.toString(message)
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
nonnegative(message) {
|
|
1745
|
+
return this._addCheck({
|
|
1746
|
+
kind: "min",
|
|
1747
|
+
value: 0,
|
|
1748
|
+
inclusive: true,
|
|
1749
|
+
message: errorUtil.toString(message)
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
multipleOf(value, message) {
|
|
1753
|
+
return this._addCheck({
|
|
1754
|
+
kind: "multipleOf",
|
|
1755
|
+
value,
|
|
1756
|
+
message: errorUtil.toString(message)
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
finite(message) {
|
|
1760
|
+
return this._addCheck({
|
|
1761
|
+
kind: "finite",
|
|
1762
|
+
message: errorUtil.toString(message)
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
safe(message) {
|
|
1766
|
+
return this._addCheck({
|
|
1767
|
+
kind: "min",
|
|
1768
|
+
inclusive: true,
|
|
1769
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1770
|
+
message: errorUtil.toString(message)
|
|
1771
|
+
})._addCheck({
|
|
1772
|
+
kind: "max",
|
|
1773
|
+
inclusive: true,
|
|
1774
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1775
|
+
message: errorUtil.toString(message)
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
get minValue() {
|
|
1779
|
+
let min = null;
|
|
1780
|
+
for (const ch of this._def.checks) {
|
|
1781
|
+
if (ch.kind === "min") {
|
|
1782
|
+
if (min === null || ch.value > min)
|
|
1783
|
+
min = ch.value;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
return min;
|
|
1787
|
+
}
|
|
1788
|
+
get maxValue() {
|
|
1789
|
+
let max = null;
|
|
1790
|
+
for (const ch of this._def.checks) {
|
|
1791
|
+
if (ch.kind === "max") {
|
|
1792
|
+
if (max === null || ch.value < max)
|
|
1793
|
+
max = ch.value;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
return max;
|
|
1797
|
+
}
|
|
1798
|
+
get isInt() {
|
|
1799
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1800
|
+
}
|
|
1801
|
+
get isFinite() {
|
|
1802
|
+
let max = null;
|
|
1803
|
+
let min = null;
|
|
1804
|
+
for (const ch of this._def.checks) {
|
|
1805
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1806
|
+
return true;
|
|
1807
|
+
} else if (ch.kind === "min") {
|
|
1808
|
+
if (min === null || ch.value > min)
|
|
1809
|
+
min = ch.value;
|
|
1810
|
+
} else if (ch.kind === "max") {
|
|
1811
|
+
if (max === null || ch.value < max)
|
|
1812
|
+
max = ch.value;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
ZodNumber.create = (params) => {
|
|
1819
|
+
return new ZodNumber({
|
|
1820
|
+
checks: [],
|
|
1821
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1822
|
+
coerce: params?.coerce || false,
|
|
1823
|
+
...processCreateParams(params)
|
|
1824
|
+
});
|
|
1825
|
+
};
|
|
1826
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1827
|
+
constructor() {
|
|
1828
|
+
super(...arguments);
|
|
1829
|
+
this.min = this.gte;
|
|
1830
|
+
this.max = this.lte;
|
|
1831
|
+
}
|
|
1832
|
+
_parse(input) {
|
|
1833
|
+
if (this._def.coerce) {
|
|
1834
|
+
try {
|
|
1835
|
+
input.data = BigInt(input.data);
|
|
1836
|
+
} catch {
|
|
1837
|
+
return this._getInvalidInput(input);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
const parsedType = this._getType(input);
|
|
1841
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
1842
|
+
return this._getInvalidInput(input);
|
|
1843
|
+
}
|
|
1844
|
+
let ctx = void 0;
|
|
1845
|
+
const status = new ParseStatus();
|
|
1846
|
+
for (const check of this._def.checks) {
|
|
1847
|
+
if (check.kind === "min") {
|
|
1848
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1849
|
+
if (tooSmall) {
|
|
1850
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1851
|
+
addIssueToContext(ctx, {
|
|
1852
|
+
code: ZodIssueCode.too_small,
|
|
1853
|
+
type: "bigint",
|
|
1854
|
+
minimum: check.value,
|
|
1855
|
+
inclusive: check.inclusive,
|
|
1856
|
+
message: check.message
|
|
1857
|
+
});
|
|
1858
|
+
status.dirty();
|
|
1859
|
+
}
|
|
1860
|
+
} else if (check.kind === "max") {
|
|
1861
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1862
|
+
if (tooBig) {
|
|
1863
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1864
|
+
addIssueToContext(ctx, {
|
|
1865
|
+
code: ZodIssueCode.too_big,
|
|
1866
|
+
type: "bigint",
|
|
1867
|
+
maximum: check.value,
|
|
1868
|
+
inclusive: check.inclusive,
|
|
1869
|
+
message: check.message
|
|
1870
|
+
});
|
|
1871
|
+
status.dirty();
|
|
1872
|
+
}
|
|
1873
|
+
} else if (check.kind === "multipleOf") {
|
|
1874
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1875
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1876
|
+
addIssueToContext(ctx, {
|
|
1877
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1878
|
+
multipleOf: check.value,
|
|
1879
|
+
message: check.message
|
|
1880
|
+
});
|
|
1881
|
+
status.dirty();
|
|
1882
|
+
}
|
|
1883
|
+
} else {
|
|
1884
|
+
util.assertNever(check);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return { status: status.value, value: input.data };
|
|
1888
|
+
}
|
|
1889
|
+
_getInvalidInput(input) {
|
|
1890
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1891
|
+
addIssueToContext(ctx, {
|
|
1892
|
+
code: ZodIssueCode.invalid_type,
|
|
1893
|
+
expected: ZodParsedType.bigint,
|
|
1894
|
+
received: ctx.parsedType
|
|
1895
|
+
});
|
|
1896
|
+
return INVALID;
|
|
1897
|
+
}
|
|
1898
|
+
gte(value, message) {
|
|
1899
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1900
|
+
}
|
|
1901
|
+
gt(value, message) {
|
|
1902
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1903
|
+
}
|
|
1904
|
+
lte(value, message) {
|
|
1905
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1906
|
+
}
|
|
1907
|
+
lt(value, message) {
|
|
1908
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1909
|
+
}
|
|
1910
|
+
setLimit(kind, value, inclusive, message) {
|
|
1911
|
+
return new _ZodBigInt({
|
|
1912
|
+
...this._def,
|
|
1913
|
+
checks: [
|
|
1914
|
+
...this._def.checks,
|
|
1915
|
+
{
|
|
1916
|
+
kind,
|
|
1917
|
+
value,
|
|
1918
|
+
inclusive,
|
|
1919
|
+
message: errorUtil.toString(message)
|
|
1920
|
+
}
|
|
1921
|
+
]
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
_addCheck(check) {
|
|
1925
|
+
return new _ZodBigInt({
|
|
1926
|
+
...this._def,
|
|
1927
|
+
checks: [...this._def.checks, check]
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
positive(message) {
|
|
1931
|
+
return this._addCheck({
|
|
1932
|
+
kind: "min",
|
|
1933
|
+
value: BigInt(0),
|
|
1934
|
+
inclusive: false,
|
|
1935
|
+
message: errorUtil.toString(message)
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
negative(message) {
|
|
1939
|
+
return this._addCheck({
|
|
1940
|
+
kind: "max",
|
|
1941
|
+
value: BigInt(0),
|
|
1942
|
+
inclusive: false,
|
|
1943
|
+
message: errorUtil.toString(message)
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
nonpositive(message) {
|
|
1947
|
+
return this._addCheck({
|
|
1948
|
+
kind: "max",
|
|
1949
|
+
value: BigInt(0),
|
|
1950
|
+
inclusive: true,
|
|
1951
|
+
message: errorUtil.toString(message)
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
nonnegative(message) {
|
|
1955
|
+
return this._addCheck({
|
|
1956
|
+
kind: "min",
|
|
1957
|
+
value: BigInt(0),
|
|
1958
|
+
inclusive: true,
|
|
1959
|
+
message: errorUtil.toString(message)
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
multipleOf(value, message) {
|
|
1963
|
+
return this._addCheck({
|
|
1964
|
+
kind: "multipleOf",
|
|
1965
|
+
value,
|
|
1966
|
+
message: errorUtil.toString(message)
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
get minValue() {
|
|
1970
|
+
let min = null;
|
|
1971
|
+
for (const ch of this._def.checks) {
|
|
1972
|
+
if (ch.kind === "min") {
|
|
1973
|
+
if (min === null || ch.value > min)
|
|
1974
|
+
min = ch.value;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
return min;
|
|
1978
|
+
}
|
|
1979
|
+
get maxValue() {
|
|
1980
|
+
let max = null;
|
|
1981
|
+
for (const ch of this._def.checks) {
|
|
1982
|
+
if (ch.kind === "max") {
|
|
1983
|
+
if (max === null || ch.value < max)
|
|
1984
|
+
max = ch.value;
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
return max;
|
|
1988
|
+
}
|
|
1989
|
+
};
|
|
1990
|
+
ZodBigInt.create = (params) => {
|
|
1991
|
+
return new ZodBigInt({
|
|
1992
|
+
checks: [],
|
|
1993
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1994
|
+
coerce: params?.coerce ?? false,
|
|
1995
|
+
...processCreateParams(params)
|
|
1996
|
+
});
|
|
1997
|
+
};
|
|
1998
|
+
var ZodBoolean = class extends ZodType {
|
|
1999
|
+
_parse(input) {
|
|
2000
|
+
if (this._def.coerce) {
|
|
2001
|
+
input.data = Boolean(input.data);
|
|
2002
|
+
}
|
|
2003
|
+
const parsedType = this._getType(input);
|
|
2004
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
2005
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2006
|
+
addIssueToContext(ctx, {
|
|
2007
|
+
code: ZodIssueCode.invalid_type,
|
|
2008
|
+
expected: ZodParsedType.boolean,
|
|
2009
|
+
received: ctx.parsedType
|
|
2010
|
+
});
|
|
2011
|
+
return INVALID;
|
|
2012
|
+
}
|
|
2013
|
+
return OK(input.data);
|
|
2014
|
+
}
|
|
2015
|
+
};
|
|
2016
|
+
ZodBoolean.create = (params) => {
|
|
2017
|
+
return new ZodBoolean({
|
|
2018
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2019
|
+
coerce: params?.coerce || false,
|
|
2020
|
+
...processCreateParams(params)
|
|
2021
|
+
});
|
|
2022
|
+
};
|
|
2023
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
2024
|
+
_parse(input) {
|
|
2025
|
+
if (this._def.coerce) {
|
|
2026
|
+
input.data = new Date(input.data);
|
|
2027
|
+
}
|
|
2028
|
+
const parsedType = this._getType(input);
|
|
2029
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2030
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2031
|
+
addIssueToContext(ctx2, {
|
|
2032
|
+
code: ZodIssueCode.invalid_type,
|
|
2033
|
+
expected: ZodParsedType.date,
|
|
2034
|
+
received: ctx2.parsedType
|
|
2035
|
+
});
|
|
2036
|
+
return INVALID;
|
|
2037
|
+
}
|
|
2038
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2039
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2040
|
+
addIssueToContext(ctx2, {
|
|
2041
|
+
code: ZodIssueCode.invalid_date
|
|
2042
|
+
});
|
|
2043
|
+
return INVALID;
|
|
2044
|
+
}
|
|
2045
|
+
const status = new ParseStatus();
|
|
2046
|
+
let ctx = void 0;
|
|
2047
|
+
for (const check of this._def.checks) {
|
|
2048
|
+
if (check.kind === "min") {
|
|
2049
|
+
if (input.data.getTime() < check.value) {
|
|
2050
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2051
|
+
addIssueToContext(ctx, {
|
|
2052
|
+
code: ZodIssueCode.too_small,
|
|
2053
|
+
message: check.message,
|
|
2054
|
+
inclusive: true,
|
|
2055
|
+
exact: false,
|
|
2056
|
+
minimum: check.value,
|
|
2057
|
+
type: "date"
|
|
2058
|
+
});
|
|
2059
|
+
status.dirty();
|
|
2060
|
+
}
|
|
2061
|
+
} else if (check.kind === "max") {
|
|
2062
|
+
if (input.data.getTime() > check.value) {
|
|
2063
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2064
|
+
addIssueToContext(ctx, {
|
|
2065
|
+
code: ZodIssueCode.too_big,
|
|
2066
|
+
message: check.message,
|
|
2067
|
+
inclusive: true,
|
|
2068
|
+
exact: false,
|
|
2069
|
+
maximum: check.value,
|
|
2070
|
+
type: "date"
|
|
2071
|
+
});
|
|
2072
|
+
status.dirty();
|
|
2073
|
+
}
|
|
2074
|
+
} else {
|
|
2075
|
+
util.assertNever(check);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return {
|
|
2079
|
+
status: status.value,
|
|
2080
|
+
value: new Date(input.data.getTime())
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
_addCheck(check) {
|
|
2084
|
+
return new _ZodDate({
|
|
2085
|
+
...this._def,
|
|
2086
|
+
checks: [...this._def.checks, check]
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
min(minDate, message) {
|
|
2090
|
+
return this._addCheck({
|
|
2091
|
+
kind: "min",
|
|
2092
|
+
value: minDate.getTime(),
|
|
2093
|
+
message: errorUtil.toString(message)
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
max(maxDate, message) {
|
|
2097
|
+
return this._addCheck({
|
|
2098
|
+
kind: "max",
|
|
2099
|
+
value: maxDate.getTime(),
|
|
2100
|
+
message: errorUtil.toString(message)
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
get minDate() {
|
|
2104
|
+
let min = null;
|
|
2105
|
+
for (const ch of this._def.checks) {
|
|
2106
|
+
if (ch.kind === "min") {
|
|
2107
|
+
if (min === null || ch.value > min)
|
|
2108
|
+
min = ch.value;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
return min != null ? new Date(min) : null;
|
|
2112
|
+
}
|
|
2113
|
+
get maxDate() {
|
|
2114
|
+
let max = null;
|
|
2115
|
+
for (const ch of this._def.checks) {
|
|
2116
|
+
if (ch.kind === "max") {
|
|
2117
|
+
if (max === null || ch.value < max)
|
|
2118
|
+
max = ch.value;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
return max != null ? new Date(max) : null;
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
ZodDate.create = (params) => {
|
|
2125
|
+
return new ZodDate({
|
|
2126
|
+
checks: [],
|
|
2127
|
+
coerce: params?.coerce || false,
|
|
2128
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2129
|
+
...processCreateParams(params)
|
|
2130
|
+
});
|
|
2131
|
+
};
|
|
2132
|
+
var ZodSymbol = class extends ZodType {
|
|
2133
|
+
_parse(input) {
|
|
2134
|
+
const parsedType = this._getType(input);
|
|
2135
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2136
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2137
|
+
addIssueToContext(ctx, {
|
|
2138
|
+
code: ZodIssueCode.invalid_type,
|
|
2139
|
+
expected: ZodParsedType.symbol,
|
|
2140
|
+
received: ctx.parsedType
|
|
2141
|
+
});
|
|
2142
|
+
return INVALID;
|
|
2143
|
+
}
|
|
2144
|
+
return OK(input.data);
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
ZodSymbol.create = (params) => {
|
|
2148
|
+
return new ZodSymbol({
|
|
2149
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2150
|
+
...processCreateParams(params)
|
|
2151
|
+
});
|
|
2152
|
+
};
|
|
2153
|
+
var ZodUndefined = class extends ZodType {
|
|
2154
|
+
_parse(input) {
|
|
2155
|
+
const parsedType = this._getType(input);
|
|
2156
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2157
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2158
|
+
addIssueToContext(ctx, {
|
|
2159
|
+
code: ZodIssueCode.invalid_type,
|
|
2160
|
+
expected: ZodParsedType.undefined,
|
|
2161
|
+
received: ctx.parsedType
|
|
2162
|
+
});
|
|
2163
|
+
return INVALID;
|
|
2164
|
+
}
|
|
2165
|
+
return OK(input.data);
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
ZodUndefined.create = (params) => {
|
|
2169
|
+
return new ZodUndefined({
|
|
2170
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2171
|
+
...processCreateParams(params)
|
|
2172
|
+
});
|
|
2173
|
+
};
|
|
2174
|
+
var ZodNull = class extends ZodType {
|
|
2175
|
+
_parse(input) {
|
|
2176
|
+
const parsedType = this._getType(input);
|
|
2177
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2178
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2179
|
+
addIssueToContext(ctx, {
|
|
2180
|
+
code: ZodIssueCode.invalid_type,
|
|
2181
|
+
expected: ZodParsedType.null,
|
|
2182
|
+
received: ctx.parsedType
|
|
2183
|
+
});
|
|
2184
|
+
return INVALID;
|
|
2185
|
+
}
|
|
2186
|
+
return OK(input.data);
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
ZodNull.create = (params) => {
|
|
2190
|
+
return new ZodNull({
|
|
2191
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2192
|
+
...processCreateParams(params)
|
|
2193
|
+
});
|
|
2194
|
+
};
|
|
2195
|
+
var ZodAny = class extends ZodType {
|
|
2196
|
+
constructor() {
|
|
2197
|
+
super(...arguments);
|
|
2198
|
+
this._any = true;
|
|
2199
|
+
}
|
|
2200
|
+
_parse(input) {
|
|
2201
|
+
return OK(input.data);
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
ZodAny.create = (params) => {
|
|
2205
|
+
return new ZodAny({
|
|
2206
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2207
|
+
...processCreateParams(params)
|
|
2208
|
+
});
|
|
2209
|
+
};
|
|
2210
|
+
var ZodUnknown = class extends ZodType {
|
|
2211
|
+
constructor() {
|
|
2212
|
+
super(...arguments);
|
|
2213
|
+
this._unknown = true;
|
|
2214
|
+
}
|
|
2215
|
+
_parse(input) {
|
|
2216
|
+
return OK(input.data);
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
ZodUnknown.create = (params) => {
|
|
2220
|
+
return new ZodUnknown({
|
|
2221
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2222
|
+
...processCreateParams(params)
|
|
2223
|
+
});
|
|
2224
|
+
};
|
|
2225
|
+
var ZodNever = class extends ZodType {
|
|
2226
|
+
_parse(input) {
|
|
2227
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2228
|
+
addIssueToContext(ctx, {
|
|
2229
|
+
code: ZodIssueCode.invalid_type,
|
|
2230
|
+
expected: ZodParsedType.never,
|
|
2231
|
+
received: ctx.parsedType
|
|
2232
|
+
});
|
|
2233
|
+
return INVALID;
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
ZodNever.create = (params) => {
|
|
2237
|
+
return new ZodNever({
|
|
2238
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2239
|
+
...processCreateParams(params)
|
|
2240
|
+
});
|
|
2241
|
+
};
|
|
2242
|
+
var ZodVoid = class extends ZodType {
|
|
2243
|
+
_parse(input) {
|
|
2244
|
+
const parsedType = this._getType(input);
|
|
2245
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2246
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2247
|
+
addIssueToContext(ctx, {
|
|
2248
|
+
code: ZodIssueCode.invalid_type,
|
|
2249
|
+
expected: ZodParsedType.void,
|
|
2250
|
+
received: ctx.parsedType
|
|
2251
|
+
});
|
|
2252
|
+
return INVALID;
|
|
2253
|
+
}
|
|
2254
|
+
return OK(input.data);
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
ZodVoid.create = (params) => {
|
|
2258
|
+
return new ZodVoid({
|
|
2259
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2260
|
+
...processCreateParams(params)
|
|
2261
|
+
});
|
|
2262
|
+
};
|
|
2263
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
2264
|
+
_parse(input) {
|
|
2265
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2266
|
+
const def = this._def;
|
|
2267
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2268
|
+
addIssueToContext(ctx, {
|
|
2269
|
+
code: ZodIssueCode.invalid_type,
|
|
2270
|
+
expected: ZodParsedType.array,
|
|
2271
|
+
received: ctx.parsedType
|
|
2272
|
+
});
|
|
2273
|
+
return INVALID;
|
|
2274
|
+
}
|
|
2275
|
+
if (def.exactLength !== null) {
|
|
2276
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2277
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2278
|
+
if (tooBig || tooSmall) {
|
|
2279
|
+
addIssueToContext(ctx, {
|
|
2280
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2281
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2282
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2283
|
+
type: "array",
|
|
2284
|
+
inclusive: true,
|
|
2285
|
+
exact: true,
|
|
2286
|
+
message: def.exactLength.message
|
|
2287
|
+
});
|
|
2288
|
+
status.dirty();
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
if (def.minLength !== null) {
|
|
2292
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2293
|
+
addIssueToContext(ctx, {
|
|
2294
|
+
code: ZodIssueCode.too_small,
|
|
2295
|
+
minimum: def.minLength.value,
|
|
2296
|
+
type: "array",
|
|
2297
|
+
inclusive: true,
|
|
2298
|
+
exact: false,
|
|
2299
|
+
message: def.minLength.message
|
|
2300
|
+
});
|
|
2301
|
+
status.dirty();
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
if (def.maxLength !== null) {
|
|
2305
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2306
|
+
addIssueToContext(ctx, {
|
|
2307
|
+
code: ZodIssueCode.too_big,
|
|
2308
|
+
maximum: def.maxLength.value,
|
|
2309
|
+
type: "array",
|
|
2310
|
+
inclusive: true,
|
|
2311
|
+
exact: false,
|
|
2312
|
+
message: def.maxLength.message
|
|
2313
|
+
});
|
|
2314
|
+
status.dirty();
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
if (ctx.common.async) {
|
|
2318
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
2319
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2320
|
+
})).then((result2) => {
|
|
2321
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
const result = [...ctx.data].map((item, i) => {
|
|
2325
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2326
|
+
});
|
|
2327
|
+
return ParseStatus.mergeArray(status, result);
|
|
2328
|
+
}
|
|
2329
|
+
get element() {
|
|
2330
|
+
return this._def.type;
|
|
2331
|
+
}
|
|
2332
|
+
min(minLength, message) {
|
|
2333
|
+
return new _ZodArray({
|
|
2334
|
+
...this._def,
|
|
2335
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
max(maxLength, message) {
|
|
2339
|
+
return new _ZodArray({
|
|
2340
|
+
...this._def,
|
|
2341
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
length(len, message) {
|
|
2345
|
+
return new _ZodArray({
|
|
2346
|
+
...this._def,
|
|
2347
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
nonempty(message) {
|
|
2351
|
+
return this.min(1, message);
|
|
2352
|
+
}
|
|
2353
|
+
};
|
|
2354
|
+
ZodArray.create = (schema, params) => {
|
|
2355
|
+
return new ZodArray({
|
|
2356
|
+
type: schema,
|
|
2357
|
+
minLength: null,
|
|
2358
|
+
maxLength: null,
|
|
2359
|
+
exactLength: null,
|
|
2360
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2361
|
+
...processCreateParams(params)
|
|
2362
|
+
});
|
|
2363
|
+
};
|
|
2364
|
+
function deepPartialify(schema) {
|
|
2365
|
+
if (schema instanceof ZodObject) {
|
|
2366
|
+
const newShape = {};
|
|
2367
|
+
for (const key in schema.shape) {
|
|
2368
|
+
const fieldSchema = schema.shape[key];
|
|
2369
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2370
|
+
}
|
|
2371
|
+
return new ZodObject({
|
|
2372
|
+
...schema._def,
|
|
2373
|
+
shape: () => newShape
|
|
2374
|
+
});
|
|
2375
|
+
} else if (schema instanceof ZodArray) {
|
|
2376
|
+
return new ZodArray({
|
|
2377
|
+
...schema._def,
|
|
2378
|
+
type: deepPartialify(schema.element)
|
|
2379
|
+
});
|
|
2380
|
+
} else if (schema instanceof ZodOptional) {
|
|
2381
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2382
|
+
} else if (schema instanceof ZodNullable) {
|
|
2383
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2384
|
+
} else if (schema instanceof ZodTuple) {
|
|
2385
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2386
|
+
} else {
|
|
2387
|
+
return schema;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
2391
|
+
constructor() {
|
|
2392
|
+
super(...arguments);
|
|
2393
|
+
this._cached = null;
|
|
2394
|
+
this.nonstrict = this.passthrough;
|
|
2395
|
+
this.augment = this.extend;
|
|
2396
|
+
}
|
|
2397
|
+
_getCached() {
|
|
2398
|
+
if (this._cached !== null)
|
|
2399
|
+
return this._cached;
|
|
2400
|
+
const shape = this._def.shape();
|
|
2401
|
+
const keys = util.objectKeys(shape);
|
|
2402
|
+
this._cached = { shape, keys };
|
|
2403
|
+
return this._cached;
|
|
2404
|
+
}
|
|
2405
|
+
_parse(input) {
|
|
2406
|
+
const parsedType = this._getType(input);
|
|
2407
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2408
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2409
|
+
addIssueToContext(ctx2, {
|
|
2410
|
+
code: ZodIssueCode.invalid_type,
|
|
2411
|
+
expected: ZodParsedType.object,
|
|
2412
|
+
received: ctx2.parsedType
|
|
2413
|
+
});
|
|
2414
|
+
return INVALID;
|
|
2415
|
+
}
|
|
2416
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2417
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2418
|
+
const extraKeys = [];
|
|
2419
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2420
|
+
for (const key in ctx.data) {
|
|
2421
|
+
if (!shapeKeys.includes(key)) {
|
|
2422
|
+
extraKeys.push(key);
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
const pairs = [];
|
|
2427
|
+
for (const key of shapeKeys) {
|
|
2428
|
+
const keyValidator = shape[key];
|
|
2429
|
+
const value = ctx.data[key];
|
|
2430
|
+
pairs.push({
|
|
2431
|
+
key: { status: "valid", value: key },
|
|
2432
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2433
|
+
alwaysSet: key in ctx.data
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2437
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2438
|
+
if (unknownKeys === "passthrough") {
|
|
2439
|
+
for (const key of extraKeys) {
|
|
2440
|
+
pairs.push({
|
|
2441
|
+
key: { status: "valid", value: key },
|
|
2442
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
} else if (unknownKeys === "strict") {
|
|
2446
|
+
if (extraKeys.length > 0) {
|
|
2447
|
+
addIssueToContext(ctx, {
|
|
2448
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2449
|
+
keys: extraKeys
|
|
2450
|
+
});
|
|
2451
|
+
status.dirty();
|
|
2452
|
+
}
|
|
2453
|
+
} else if (unknownKeys === "strip") {
|
|
2454
|
+
} else {
|
|
2455
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2456
|
+
}
|
|
2457
|
+
} else {
|
|
2458
|
+
const catchall = this._def.catchall;
|
|
2459
|
+
for (const key of extraKeys) {
|
|
2460
|
+
const value = ctx.data[key];
|
|
2461
|
+
pairs.push({
|
|
2462
|
+
key: { status: "valid", value: key },
|
|
2463
|
+
value: catchall._parse(
|
|
2464
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2465
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
2466
|
+
),
|
|
2467
|
+
alwaysSet: key in ctx.data
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
if (ctx.common.async) {
|
|
2472
|
+
return Promise.resolve().then(async () => {
|
|
2473
|
+
const syncPairs = [];
|
|
2474
|
+
for (const pair of pairs) {
|
|
2475
|
+
const key = await pair.key;
|
|
2476
|
+
const value = await pair.value;
|
|
2477
|
+
syncPairs.push({
|
|
2478
|
+
key,
|
|
2479
|
+
value,
|
|
2480
|
+
alwaysSet: pair.alwaysSet
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
return syncPairs;
|
|
2484
|
+
}).then((syncPairs) => {
|
|
2485
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2486
|
+
});
|
|
2487
|
+
} else {
|
|
2488
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
get shape() {
|
|
2492
|
+
return this._def.shape();
|
|
2493
|
+
}
|
|
2494
|
+
strict(message) {
|
|
2495
|
+
errorUtil.errToObj;
|
|
2496
|
+
return new _ZodObject({
|
|
2497
|
+
...this._def,
|
|
2498
|
+
unknownKeys: "strict",
|
|
2499
|
+
...message !== void 0 ? {
|
|
2500
|
+
errorMap: (issue, ctx) => {
|
|
2501
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2502
|
+
if (issue.code === "unrecognized_keys")
|
|
2503
|
+
return {
|
|
2504
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2505
|
+
};
|
|
2506
|
+
return {
|
|
2507
|
+
message: defaultError
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
} : {}
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2513
|
+
strip() {
|
|
2514
|
+
return new _ZodObject({
|
|
2515
|
+
...this._def,
|
|
2516
|
+
unknownKeys: "strip"
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
passthrough() {
|
|
2520
|
+
return new _ZodObject({
|
|
2521
|
+
...this._def,
|
|
2522
|
+
unknownKeys: "passthrough"
|
|
2523
|
+
});
|
|
2524
|
+
}
|
|
2525
|
+
// const AugmentFactory =
|
|
2526
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2527
|
+
// <Augmentation extends ZodRawShape>(
|
|
2528
|
+
// augmentation: Augmentation
|
|
2529
|
+
// ): ZodObject<
|
|
2530
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2531
|
+
// Def["unknownKeys"],
|
|
2532
|
+
// Def["catchall"]
|
|
2533
|
+
// > => {
|
|
2534
|
+
// return new ZodObject({
|
|
2535
|
+
// ...def,
|
|
2536
|
+
// shape: () => ({
|
|
2537
|
+
// ...def.shape(),
|
|
2538
|
+
// ...augmentation,
|
|
2539
|
+
// }),
|
|
2540
|
+
// }) as any;
|
|
2541
|
+
// };
|
|
2542
|
+
extend(augmentation) {
|
|
2543
|
+
return new _ZodObject({
|
|
2544
|
+
...this._def,
|
|
2545
|
+
shape: () => ({
|
|
2546
|
+
...this._def.shape(),
|
|
2547
|
+
...augmentation
|
|
2548
|
+
})
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2553
|
+
* inferred type of merged objects. Please
|
|
2554
|
+
* upgrade if you are experiencing issues.
|
|
2555
|
+
*/
|
|
2556
|
+
merge(merging) {
|
|
2557
|
+
const merged = new _ZodObject({
|
|
2558
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2559
|
+
catchall: merging._def.catchall,
|
|
2560
|
+
shape: () => ({
|
|
2561
|
+
...this._def.shape(),
|
|
2562
|
+
...merging._def.shape()
|
|
2563
|
+
}),
|
|
2564
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2565
|
+
});
|
|
2566
|
+
return merged;
|
|
2567
|
+
}
|
|
2568
|
+
// merge<
|
|
2569
|
+
// Incoming extends AnyZodObject,
|
|
2570
|
+
// Augmentation extends Incoming["shape"],
|
|
2571
|
+
// NewOutput extends {
|
|
2572
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2573
|
+
// ? Augmentation[k]["_output"]
|
|
2574
|
+
// : k extends keyof Output
|
|
2575
|
+
// ? Output[k]
|
|
2576
|
+
// : never;
|
|
2577
|
+
// },
|
|
2578
|
+
// NewInput extends {
|
|
2579
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2580
|
+
// ? Augmentation[k]["_input"]
|
|
2581
|
+
// : k extends keyof Input
|
|
2582
|
+
// ? Input[k]
|
|
2583
|
+
// : never;
|
|
2584
|
+
// }
|
|
2585
|
+
// >(
|
|
2586
|
+
// merging: Incoming
|
|
2587
|
+
// ): ZodObject<
|
|
2588
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2589
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2590
|
+
// Incoming["_def"]["catchall"],
|
|
2591
|
+
// NewOutput,
|
|
2592
|
+
// NewInput
|
|
2593
|
+
// > {
|
|
2594
|
+
// const merged: any = new ZodObject({
|
|
2595
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2596
|
+
// catchall: merging._def.catchall,
|
|
2597
|
+
// shape: () =>
|
|
2598
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2599
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2600
|
+
// }) as any;
|
|
2601
|
+
// return merged;
|
|
2602
|
+
// }
|
|
2603
|
+
setKey(key, schema) {
|
|
2604
|
+
return this.augment({ [key]: schema });
|
|
2605
|
+
}
|
|
2606
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2607
|
+
// merging: Incoming
|
|
2608
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2609
|
+
// ZodObject<
|
|
2610
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2611
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2612
|
+
// Incoming["_def"]["catchall"]
|
|
2613
|
+
// > {
|
|
2614
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2615
|
+
// // this._def.shape(),
|
|
2616
|
+
// // merging._def.shape()
|
|
2617
|
+
// // );
|
|
2618
|
+
// const merged: any = new ZodObject({
|
|
2619
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2620
|
+
// catchall: merging._def.catchall,
|
|
2621
|
+
// shape: () =>
|
|
2622
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2623
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2624
|
+
// }) as any;
|
|
2625
|
+
// return merged;
|
|
2626
|
+
// }
|
|
2627
|
+
catchall(index) {
|
|
2628
|
+
return new _ZodObject({
|
|
2629
|
+
...this._def,
|
|
2630
|
+
catchall: index
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2633
|
+
pick(mask) {
|
|
2634
|
+
const shape = {};
|
|
2635
|
+
for (const key of util.objectKeys(mask)) {
|
|
2636
|
+
if (mask[key] && this.shape[key]) {
|
|
2637
|
+
shape[key] = this.shape[key];
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
return new _ZodObject({
|
|
2641
|
+
...this._def,
|
|
2642
|
+
shape: () => shape
|
|
2643
|
+
});
|
|
2644
|
+
}
|
|
2645
|
+
omit(mask) {
|
|
2646
|
+
const shape = {};
|
|
2647
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2648
|
+
if (!mask[key]) {
|
|
2649
|
+
shape[key] = this.shape[key];
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
return new _ZodObject({
|
|
2653
|
+
...this._def,
|
|
2654
|
+
shape: () => shape
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* @deprecated
|
|
2659
|
+
*/
|
|
2660
|
+
deepPartial() {
|
|
2661
|
+
return deepPartialify(this);
|
|
2662
|
+
}
|
|
2663
|
+
partial(mask) {
|
|
2664
|
+
const newShape = {};
|
|
2665
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2666
|
+
const fieldSchema = this.shape[key];
|
|
2667
|
+
if (mask && !mask[key]) {
|
|
2668
|
+
newShape[key] = fieldSchema;
|
|
2669
|
+
} else {
|
|
2670
|
+
newShape[key] = fieldSchema.optional();
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
return new _ZodObject({
|
|
2674
|
+
...this._def,
|
|
2675
|
+
shape: () => newShape
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
required(mask) {
|
|
2679
|
+
const newShape = {};
|
|
2680
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2681
|
+
if (mask && !mask[key]) {
|
|
2682
|
+
newShape[key] = this.shape[key];
|
|
2683
|
+
} else {
|
|
2684
|
+
const fieldSchema = this.shape[key];
|
|
2685
|
+
let newField = fieldSchema;
|
|
2686
|
+
while (newField instanceof ZodOptional) {
|
|
2687
|
+
newField = newField._def.innerType;
|
|
2688
|
+
}
|
|
2689
|
+
newShape[key] = newField;
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
return new _ZodObject({
|
|
2693
|
+
...this._def,
|
|
2694
|
+
shape: () => newShape
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
keyof() {
|
|
2698
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
2699
|
+
}
|
|
2700
|
+
};
|
|
2701
|
+
ZodObject.create = (shape, params) => {
|
|
2702
|
+
return new ZodObject({
|
|
2703
|
+
shape: () => shape,
|
|
2704
|
+
unknownKeys: "strip",
|
|
2705
|
+
catchall: ZodNever.create(),
|
|
2706
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2707
|
+
...processCreateParams(params)
|
|
2708
|
+
});
|
|
2709
|
+
};
|
|
2710
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2711
|
+
return new ZodObject({
|
|
2712
|
+
shape: () => shape,
|
|
2713
|
+
unknownKeys: "strict",
|
|
2714
|
+
catchall: ZodNever.create(),
|
|
2715
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2716
|
+
...processCreateParams(params)
|
|
2717
|
+
});
|
|
2718
|
+
};
|
|
2719
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2720
|
+
return new ZodObject({
|
|
2721
|
+
shape,
|
|
2722
|
+
unknownKeys: "strip",
|
|
2723
|
+
catchall: ZodNever.create(),
|
|
2724
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2725
|
+
...processCreateParams(params)
|
|
2726
|
+
});
|
|
2727
|
+
};
|
|
2728
|
+
var ZodUnion = class extends ZodType {
|
|
2729
|
+
_parse(input) {
|
|
2730
|
+
const { ctx } = this._processInputParams(input);
|
|
2731
|
+
const options = this._def.options;
|
|
2732
|
+
function handleResults(results) {
|
|
2733
|
+
for (const result of results) {
|
|
2734
|
+
if (result.result.status === "valid") {
|
|
2735
|
+
return result.result;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
for (const result of results) {
|
|
2739
|
+
if (result.result.status === "dirty") {
|
|
2740
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2741
|
+
return result.result;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2745
|
+
addIssueToContext(ctx, {
|
|
2746
|
+
code: ZodIssueCode.invalid_union,
|
|
2747
|
+
unionErrors
|
|
2748
|
+
});
|
|
2749
|
+
return INVALID;
|
|
2750
|
+
}
|
|
2751
|
+
if (ctx.common.async) {
|
|
2752
|
+
return Promise.all(options.map(async (option) => {
|
|
2753
|
+
const childCtx = {
|
|
2754
|
+
...ctx,
|
|
2755
|
+
common: {
|
|
2756
|
+
...ctx.common,
|
|
2757
|
+
issues: []
|
|
2758
|
+
},
|
|
2759
|
+
parent: null
|
|
2760
|
+
};
|
|
2761
|
+
return {
|
|
2762
|
+
result: await option._parseAsync({
|
|
2763
|
+
data: ctx.data,
|
|
2764
|
+
path: ctx.path,
|
|
2765
|
+
parent: childCtx
|
|
2766
|
+
}),
|
|
2767
|
+
ctx: childCtx
|
|
2768
|
+
};
|
|
2769
|
+
})).then(handleResults);
|
|
2770
|
+
} else {
|
|
2771
|
+
let dirty = void 0;
|
|
2772
|
+
const issues = [];
|
|
2773
|
+
for (const option of options) {
|
|
2774
|
+
const childCtx = {
|
|
2775
|
+
...ctx,
|
|
2776
|
+
common: {
|
|
2777
|
+
...ctx.common,
|
|
2778
|
+
issues: []
|
|
2779
|
+
},
|
|
2780
|
+
parent: null
|
|
2781
|
+
};
|
|
2782
|
+
const result = option._parseSync({
|
|
2783
|
+
data: ctx.data,
|
|
2784
|
+
path: ctx.path,
|
|
2785
|
+
parent: childCtx
|
|
2786
|
+
});
|
|
2787
|
+
if (result.status === "valid") {
|
|
2788
|
+
return result;
|
|
2789
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
2790
|
+
dirty = { result, ctx: childCtx };
|
|
2791
|
+
}
|
|
2792
|
+
if (childCtx.common.issues.length) {
|
|
2793
|
+
issues.push(childCtx.common.issues);
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
if (dirty) {
|
|
2797
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2798
|
+
return dirty.result;
|
|
2799
|
+
}
|
|
2800
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
2801
|
+
addIssueToContext(ctx, {
|
|
2802
|
+
code: ZodIssueCode.invalid_union,
|
|
2803
|
+
unionErrors
|
|
2804
|
+
});
|
|
2805
|
+
return INVALID;
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
get options() {
|
|
2809
|
+
return this._def.options;
|
|
2810
|
+
}
|
|
2811
|
+
};
|
|
2812
|
+
ZodUnion.create = (types, params) => {
|
|
2813
|
+
return new ZodUnion({
|
|
2814
|
+
options: types,
|
|
2815
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2816
|
+
...processCreateParams(params)
|
|
2817
|
+
});
|
|
2818
|
+
};
|
|
2819
|
+
var getDiscriminator = (type) => {
|
|
2820
|
+
if (type instanceof ZodLazy) {
|
|
2821
|
+
return getDiscriminator(type.schema);
|
|
2822
|
+
} else if (type instanceof ZodEffects) {
|
|
2823
|
+
return getDiscriminator(type.innerType());
|
|
2824
|
+
} else if (type instanceof ZodLiteral) {
|
|
2825
|
+
return [type.value];
|
|
2826
|
+
} else if (type instanceof ZodEnum) {
|
|
2827
|
+
return type.options;
|
|
2828
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
2829
|
+
return util.objectValues(type.enum);
|
|
2830
|
+
} else if (type instanceof ZodDefault) {
|
|
2831
|
+
return getDiscriminator(type._def.innerType);
|
|
2832
|
+
} else if (type instanceof ZodUndefined) {
|
|
2833
|
+
return [void 0];
|
|
2834
|
+
} else if (type instanceof ZodNull) {
|
|
2835
|
+
return [null];
|
|
2836
|
+
} else if (type instanceof ZodOptional) {
|
|
2837
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2838
|
+
} else if (type instanceof ZodNullable) {
|
|
2839
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
2840
|
+
} else if (type instanceof ZodBranded) {
|
|
2841
|
+
return getDiscriminator(type.unwrap());
|
|
2842
|
+
} else if (type instanceof ZodReadonly) {
|
|
2843
|
+
return getDiscriminator(type.unwrap());
|
|
2844
|
+
} else if (type instanceof ZodCatch) {
|
|
2845
|
+
return getDiscriminator(type._def.innerType);
|
|
2846
|
+
} else {
|
|
2847
|
+
return [];
|
|
2848
|
+
}
|
|
2849
|
+
};
|
|
2850
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
2851
|
+
_parse(input) {
|
|
2852
|
+
const { ctx } = this._processInputParams(input);
|
|
2853
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2854
|
+
addIssueToContext(ctx, {
|
|
2855
|
+
code: ZodIssueCode.invalid_type,
|
|
2856
|
+
expected: ZodParsedType.object,
|
|
2857
|
+
received: ctx.parsedType
|
|
2858
|
+
});
|
|
2859
|
+
return INVALID;
|
|
2860
|
+
}
|
|
2861
|
+
const discriminator = this.discriminator;
|
|
2862
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
2863
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
2864
|
+
if (!option) {
|
|
2865
|
+
addIssueToContext(ctx, {
|
|
2866
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2867
|
+
options: Array.from(this.optionsMap.keys()),
|
|
2868
|
+
path: [discriminator]
|
|
2869
|
+
});
|
|
2870
|
+
return INVALID;
|
|
2871
|
+
}
|
|
2872
|
+
if (ctx.common.async) {
|
|
2873
|
+
return option._parseAsync({
|
|
2874
|
+
data: ctx.data,
|
|
2875
|
+
path: ctx.path,
|
|
2876
|
+
parent: ctx
|
|
2877
|
+
});
|
|
2878
|
+
} else {
|
|
2879
|
+
return option._parseSync({
|
|
2880
|
+
data: ctx.data,
|
|
2881
|
+
path: ctx.path,
|
|
2882
|
+
parent: ctx
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
get discriminator() {
|
|
2887
|
+
return this._def.discriminator;
|
|
2888
|
+
}
|
|
2889
|
+
get options() {
|
|
2890
|
+
return this._def.options;
|
|
2891
|
+
}
|
|
2892
|
+
get optionsMap() {
|
|
2893
|
+
return this._def.optionsMap;
|
|
2894
|
+
}
|
|
2895
|
+
/**
|
|
2896
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2897
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2898
|
+
* have a different value for each object in the union.
|
|
2899
|
+
* @param discriminator the name of the discriminator property
|
|
2900
|
+
* @param types an array of object schemas
|
|
2901
|
+
* @param params
|
|
2902
|
+
*/
|
|
2903
|
+
static create(discriminator, options, params) {
|
|
2904
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
2905
|
+
for (const type of options) {
|
|
2906
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2907
|
+
if (!discriminatorValues.length) {
|
|
2908
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2909
|
+
}
|
|
2910
|
+
for (const value of discriminatorValues) {
|
|
2911
|
+
if (optionsMap.has(value)) {
|
|
2912
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2913
|
+
}
|
|
2914
|
+
optionsMap.set(value, type);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
return new _ZodDiscriminatedUnion({
|
|
2918
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2919
|
+
discriminator,
|
|
2920
|
+
options,
|
|
2921
|
+
optionsMap,
|
|
2922
|
+
...processCreateParams(params)
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2925
|
+
};
|
|
2926
|
+
function mergeValues(a, b) {
|
|
2927
|
+
const aType = getParsedType(a);
|
|
2928
|
+
const bType = getParsedType(b);
|
|
2929
|
+
if (a === b) {
|
|
2930
|
+
return { valid: true, data: a };
|
|
2931
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2932
|
+
const bKeys = util.objectKeys(b);
|
|
2933
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2934
|
+
const newObj = { ...a, ...b };
|
|
2935
|
+
for (const key of sharedKeys) {
|
|
2936
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
2937
|
+
if (!sharedValue.valid) {
|
|
2938
|
+
return { valid: false };
|
|
2939
|
+
}
|
|
2940
|
+
newObj[key] = sharedValue.data;
|
|
2941
|
+
}
|
|
2942
|
+
return { valid: true, data: newObj };
|
|
2943
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2944
|
+
if (a.length !== b.length) {
|
|
2945
|
+
return { valid: false };
|
|
2946
|
+
}
|
|
2947
|
+
const newArray = [];
|
|
2948
|
+
for (let index = 0; index < a.length; index++) {
|
|
2949
|
+
const itemA = a[index];
|
|
2950
|
+
const itemB = b[index];
|
|
2951
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
2952
|
+
if (!sharedValue.valid) {
|
|
2953
|
+
return { valid: false };
|
|
2954
|
+
}
|
|
2955
|
+
newArray.push(sharedValue.data);
|
|
2956
|
+
}
|
|
2957
|
+
return { valid: true, data: newArray };
|
|
2958
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
2959
|
+
return { valid: true, data: a };
|
|
2960
|
+
} else {
|
|
2961
|
+
return { valid: false };
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
var ZodIntersection = class extends ZodType {
|
|
2965
|
+
_parse(input) {
|
|
2966
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2967
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2968
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2969
|
+
return INVALID;
|
|
2970
|
+
}
|
|
2971
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2972
|
+
if (!merged.valid) {
|
|
2973
|
+
addIssueToContext(ctx, {
|
|
2974
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
2975
|
+
});
|
|
2976
|
+
return INVALID;
|
|
2977
|
+
}
|
|
2978
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
2979
|
+
status.dirty();
|
|
2980
|
+
}
|
|
2981
|
+
return { status: status.value, value: merged.data };
|
|
2982
|
+
};
|
|
2983
|
+
if (ctx.common.async) {
|
|
2984
|
+
return Promise.all([
|
|
2985
|
+
this._def.left._parseAsync({
|
|
2986
|
+
data: ctx.data,
|
|
2987
|
+
path: ctx.path,
|
|
2988
|
+
parent: ctx
|
|
2989
|
+
}),
|
|
2990
|
+
this._def.right._parseAsync({
|
|
2991
|
+
data: ctx.data,
|
|
2992
|
+
path: ctx.path,
|
|
2993
|
+
parent: ctx
|
|
2994
|
+
})
|
|
2995
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
2996
|
+
} else {
|
|
2997
|
+
return handleParsed(this._def.left._parseSync({
|
|
2998
|
+
data: ctx.data,
|
|
2999
|
+
path: ctx.path,
|
|
3000
|
+
parent: ctx
|
|
3001
|
+
}), this._def.right._parseSync({
|
|
3002
|
+
data: ctx.data,
|
|
3003
|
+
path: ctx.path,
|
|
3004
|
+
parent: ctx
|
|
3005
|
+
}));
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
};
|
|
3009
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3010
|
+
return new ZodIntersection({
|
|
3011
|
+
left,
|
|
3012
|
+
right,
|
|
3013
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3014
|
+
...processCreateParams(params)
|
|
3015
|
+
});
|
|
3016
|
+
};
|
|
3017
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3018
|
+
_parse(input) {
|
|
3019
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3020
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3021
|
+
addIssueToContext(ctx, {
|
|
3022
|
+
code: ZodIssueCode.invalid_type,
|
|
3023
|
+
expected: ZodParsedType.array,
|
|
3024
|
+
received: ctx.parsedType
|
|
3025
|
+
});
|
|
3026
|
+
return INVALID;
|
|
3027
|
+
}
|
|
3028
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3029
|
+
addIssueToContext(ctx, {
|
|
3030
|
+
code: ZodIssueCode.too_small,
|
|
3031
|
+
minimum: this._def.items.length,
|
|
3032
|
+
inclusive: true,
|
|
3033
|
+
exact: false,
|
|
3034
|
+
type: "array"
|
|
3035
|
+
});
|
|
3036
|
+
return INVALID;
|
|
3037
|
+
}
|
|
3038
|
+
const rest = this._def.rest;
|
|
3039
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3040
|
+
addIssueToContext(ctx, {
|
|
3041
|
+
code: ZodIssueCode.too_big,
|
|
3042
|
+
maximum: this._def.items.length,
|
|
3043
|
+
inclusive: true,
|
|
3044
|
+
exact: false,
|
|
3045
|
+
type: "array"
|
|
3046
|
+
});
|
|
3047
|
+
status.dirty();
|
|
3048
|
+
}
|
|
3049
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3050
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3051
|
+
if (!schema)
|
|
3052
|
+
return null;
|
|
3053
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3054
|
+
}).filter((x) => !!x);
|
|
3055
|
+
if (ctx.common.async) {
|
|
3056
|
+
return Promise.all(items).then((results) => {
|
|
3057
|
+
return ParseStatus.mergeArray(status, results);
|
|
3058
|
+
});
|
|
3059
|
+
} else {
|
|
3060
|
+
return ParseStatus.mergeArray(status, items);
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
get items() {
|
|
3064
|
+
return this._def.items;
|
|
3065
|
+
}
|
|
3066
|
+
rest(rest) {
|
|
3067
|
+
return new _ZodTuple({
|
|
3068
|
+
...this._def,
|
|
3069
|
+
rest
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
};
|
|
3073
|
+
ZodTuple.create = (schemas, params) => {
|
|
3074
|
+
if (!Array.isArray(schemas)) {
|
|
3075
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3076
|
+
}
|
|
3077
|
+
return new ZodTuple({
|
|
3078
|
+
items: schemas,
|
|
3079
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3080
|
+
rest: null,
|
|
3081
|
+
...processCreateParams(params)
|
|
3082
|
+
});
|
|
3083
|
+
};
|
|
3084
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3085
|
+
get keySchema() {
|
|
3086
|
+
return this._def.keyType;
|
|
3087
|
+
}
|
|
3088
|
+
get valueSchema() {
|
|
3089
|
+
return this._def.valueType;
|
|
3090
|
+
}
|
|
3091
|
+
_parse(input) {
|
|
3092
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3093
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3094
|
+
addIssueToContext(ctx, {
|
|
3095
|
+
code: ZodIssueCode.invalid_type,
|
|
3096
|
+
expected: ZodParsedType.object,
|
|
3097
|
+
received: ctx.parsedType
|
|
3098
|
+
});
|
|
3099
|
+
return INVALID;
|
|
3100
|
+
}
|
|
3101
|
+
const pairs = [];
|
|
3102
|
+
const keyType = this._def.keyType;
|
|
3103
|
+
const valueType = this._def.valueType;
|
|
3104
|
+
for (const key in ctx.data) {
|
|
3105
|
+
pairs.push({
|
|
3106
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3107
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3108
|
+
alwaysSet: key in ctx.data
|
|
3109
|
+
});
|
|
3110
|
+
}
|
|
3111
|
+
if (ctx.common.async) {
|
|
3112
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3113
|
+
} else {
|
|
3114
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
get element() {
|
|
3118
|
+
return this._def.valueType;
|
|
3119
|
+
}
|
|
3120
|
+
static create(first, second, third) {
|
|
3121
|
+
if (second instanceof ZodType) {
|
|
3122
|
+
return new _ZodRecord({
|
|
3123
|
+
keyType: first,
|
|
3124
|
+
valueType: second,
|
|
3125
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3126
|
+
...processCreateParams(third)
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3129
|
+
return new _ZodRecord({
|
|
3130
|
+
keyType: ZodString.create(),
|
|
3131
|
+
valueType: first,
|
|
3132
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3133
|
+
...processCreateParams(second)
|
|
3134
|
+
});
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
var ZodMap = class extends ZodType {
|
|
3138
|
+
get keySchema() {
|
|
3139
|
+
return this._def.keyType;
|
|
3140
|
+
}
|
|
3141
|
+
get valueSchema() {
|
|
3142
|
+
return this._def.valueType;
|
|
3143
|
+
}
|
|
3144
|
+
_parse(input) {
|
|
3145
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3146
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3147
|
+
addIssueToContext(ctx, {
|
|
3148
|
+
code: ZodIssueCode.invalid_type,
|
|
3149
|
+
expected: ZodParsedType.map,
|
|
3150
|
+
received: ctx.parsedType
|
|
3151
|
+
});
|
|
3152
|
+
return INVALID;
|
|
3153
|
+
}
|
|
3154
|
+
const keyType = this._def.keyType;
|
|
3155
|
+
const valueType = this._def.valueType;
|
|
3156
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3157
|
+
return {
|
|
3158
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3159
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3160
|
+
};
|
|
3161
|
+
});
|
|
3162
|
+
if (ctx.common.async) {
|
|
3163
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3164
|
+
return Promise.resolve().then(async () => {
|
|
3165
|
+
for (const pair of pairs) {
|
|
3166
|
+
const key = await pair.key;
|
|
3167
|
+
const value = await pair.value;
|
|
3168
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3169
|
+
return INVALID;
|
|
3170
|
+
}
|
|
3171
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3172
|
+
status.dirty();
|
|
3173
|
+
}
|
|
3174
|
+
finalMap.set(key.value, value.value);
|
|
3175
|
+
}
|
|
3176
|
+
return { status: status.value, value: finalMap };
|
|
3177
|
+
});
|
|
3178
|
+
} else {
|
|
3179
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3180
|
+
for (const pair of pairs) {
|
|
3181
|
+
const key = pair.key;
|
|
3182
|
+
const value = pair.value;
|
|
3183
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3184
|
+
return INVALID;
|
|
3185
|
+
}
|
|
3186
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3187
|
+
status.dirty();
|
|
3188
|
+
}
|
|
3189
|
+
finalMap.set(key.value, value.value);
|
|
3190
|
+
}
|
|
3191
|
+
return { status: status.value, value: finalMap };
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
};
|
|
3195
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3196
|
+
return new ZodMap({
|
|
3197
|
+
valueType,
|
|
3198
|
+
keyType,
|
|
3199
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3200
|
+
...processCreateParams(params)
|
|
3201
|
+
});
|
|
3202
|
+
};
|
|
3203
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
3204
|
+
_parse(input) {
|
|
3205
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3206
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3207
|
+
addIssueToContext(ctx, {
|
|
3208
|
+
code: ZodIssueCode.invalid_type,
|
|
3209
|
+
expected: ZodParsedType.set,
|
|
3210
|
+
received: ctx.parsedType
|
|
3211
|
+
});
|
|
3212
|
+
return INVALID;
|
|
3213
|
+
}
|
|
3214
|
+
const def = this._def;
|
|
3215
|
+
if (def.minSize !== null) {
|
|
3216
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3217
|
+
addIssueToContext(ctx, {
|
|
3218
|
+
code: ZodIssueCode.too_small,
|
|
3219
|
+
minimum: def.minSize.value,
|
|
3220
|
+
type: "set",
|
|
3221
|
+
inclusive: true,
|
|
3222
|
+
exact: false,
|
|
3223
|
+
message: def.minSize.message
|
|
3224
|
+
});
|
|
3225
|
+
status.dirty();
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
if (def.maxSize !== null) {
|
|
3229
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3230
|
+
addIssueToContext(ctx, {
|
|
3231
|
+
code: ZodIssueCode.too_big,
|
|
3232
|
+
maximum: def.maxSize.value,
|
|
3233
|
+
type: "set",
|
|
3234
|
+
inclusive: true,
|
|
3235
|
+
exact: false,
|
|
3236
|
+
message: def.maxSize.message
|
|
3237
|
+
});
|
|
3238
|
+
status.dirty();
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
const valueType = this._def.valueType;
|
|
3242
|
+
function finalizeSet(elements2) {
|
|
3243
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
3244
|
+
for (const element of elements2) {
|
|
3245
|
+
if (element.status === "aborted")
|
|
3246
|
+
return INVALID;
|
|
3247
|
+
if (element.status === "dirty")
|
|
3248
|
+
status.dirty();
|
|
3249
|
+
parsedSet.add(element.value);
|
|
3250
|
+
}
|
|
3251
|
+
return { status: status.value, value: parsedSet };
|
|
3252
|
+
}
|
|
3253
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3254
|
+
if (ctx.common.async) {
|
|
3255
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3256
|
+
} else {
|
|
3257
|
+
return finalizeSet(elements);
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
min(minSize, message) {
|
|
3261
|
+
return new _ZodSet({
|
|
3262
|
+
...this._def,
|
|
3263
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3266
|
+
max(maxSize, message) {
|
|
3267
|
+
return new _ZodSet({
|
|
3268
|
+
...this._def,
|
|
3269
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
size(size, message) {
|
|
3273
|
+
return this.min(size, message).max(size, message);
|
|
3274
|
+
}
|
|
3275
|
+
nonempty(message) {
|
|
3276
|
+
return this.min(1, message);
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
ZodSet.create = (valueType, params) => {
|
|
3280
|
+
return new ZodSet({
|
|
3281
|
+
valueType,
|
|
3282
|
+
minSize: null,
|
|
3283
|
+
maxSize: null,
|
|
3284
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3285
|
+
...processCreateParams(params)
|
|
3286
|
+
});
|
|
3287
|
+
};
|
|
3288
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3289
|
+
constructor() {
|
|
3290
|
+
super(...arguments);
|
|
3291
|
+
this.validate = this.implement;
|
|
3292
|
+
}
|
|
3293
|
+
_parse(input) {
|
|
3294
|
+
const { ctx } = this._processInputParams(input);
|
|
3295
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3296
|
+
addIssueToContext(ctx, {
|
|
3297
|
+
code: ZodIssueCode.invalid_type,
|
|
3298
|
+
expected: ZodParsedType.function,
|
|
3299
|
+
received: ctx.parsedType
|
|
3300
|
+
});
|
|
3301
|
+
return INVALID;
|
|
3302
|
+
}
|
|
3303
|
+
function makeArgsIssue(args, error) {
|
|
3304
|
+
return makeIssue({
|
|
3305
|
+
data: args,
|
|
3306
|
+
path: ctx.path,
|
|
3307
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3308
|
+
issueData: {
|
|
3309
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3310
|
+
argumentsError: error
|
|
3311
|
+
}
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
function makeReturnsIssue(returns, error) {
|
|
3315
|
+
return makeIssue({
|
|
3316
|
+
data: returns,
|
|
3317
|
+
path: ctx.path,
|
|
3318
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3319
|
+
issueData: {
|
|
3320
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3321
|
+
returnTypeError: error
|
|
3322
|
+
}
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3326
|
+
const fn = ctx.data;
|
|
3327
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3328
|
+
const me = this;
|
|
3329
|
+
return OK(async function(...args) {
|
|
3330
|
+
const error = new ZodError([]);
|
|
3331
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3332
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
3333
|
+
throw error;
|
|
3334
|
+
});
|
|
3335
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3336
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3337
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
3338
|
+
throw error;
|
|
3339
|
+
});
|
|
3340
|
+
return parsedReturns;
|
|
3341
|
+
});
|
|
3342
|
+
} else {
|
|
3343
|
+
const me = this;
|
|
3344
|
+
return OK(function(...args) {
|
|
3345
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3346
|
+
if (!parsedArgs.success) {
|
|
3347
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3348
|
+
}
|
|
3349
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3350
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3351
|
+
if (!parsedReturns.success) {
|
|
3352
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3353
|
+
}
|
|
3354
|
+
return parsedReturns.data;
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
parameters() {
|
|
3359
|
+
return this._def.args;
|
|
3360
|
+
}
|
|
3361
|
+
returnType() {
|
|
3362
|
+
return this._def.returns;
|
|
3363
|
+
}
|
|
3364
|
+
args(...items) {
|
|
3365
|
+
return new _ZodFunction({
|
|
3366
|
+
...this._def,
|
|
3367
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3368
|
+
});
|
|
3369
|
+
}
|
|
3370
|
+
returns(returnType) {
|
|
3371
|
+
return new _ZodFunction({
|
|
3372
|
+
...this._def,
|
|
3373
|
+
returns: returnType
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3376
|
+
implement(func) {
|
|
3377
|
+
const validatedFunc = this.parse(func);
|
|
3378
|
+
return validatedFunc;
|
|
3379
|
+
}
|
|
3380
|
+
strictImplement(func) {
|
|
3381
|
+
const validatedFunc = this.parse(func);
|
|
3382
|
+
return validatedFunc;
|
|
3383
|
+
}
|
|
3384
|
+
static create(args, returns, params) {
|
|
3385
|
+
return new _ZodFunction({
|
|
3386
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3387
|
+
returns: returns || ZodUnknown.create(),
|
|
3388
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3389
|
+
...processCreateParams(params)
|
|
3390
|
+
});
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
var ZodLazy = class extends ZodType {
|
|
3394
|
+
get schema() {
|
|
3395
|
+
return this._def.getter();
|
|
3396
|
+
}
|
|
3397
|
+
_parse(input) {
|
|
3398
|
+
const { ctx } = this._processInputParams(input);
|
|
3399
|
+
const lazySchema = this._def.getter();
|
|
3400
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
ZodLazy.create = (getter, params) => {
|
|
3404
|
+
return new ZodLazy({
|
|
3405
|
+
getter,
|
|
3406
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3407
|
+
...processCreateParams(params)
|
|
3408
|
+
});
|
|
3409
|
+
};
|
|
3410
|
+
var ZodLiteral = class extends ZodType {
|
|
3411
|
+
_parse(input) {
|
|
3412
|
+
if (input.data !== this._def.value) {
|
|
3413
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3414
|
+
addIssueToContext(ctx, {
|
|
3415
|
+
received: ctx.data,
|
|
3416
|
+
code: ZodIssueCode.invalid_literal,
|
|
3417
|
+
expected: this._def.value
|
|
3418
|
+
});
|
|
3419
|
+
return INVALID;
|
|
3420
|
+
}
|
|
3421
|
+
return { status: "valid", value: input.data };
|
|
3422
|
+
}
|
|
3423
|
+
get value() {
|
|
3424
|
+
return this._def.value;
|
|
3425
|
+
}
|
|
3426
|
+
};
|
|
3427
|
+
ZodLiteral.create = (value, params) => {
|
|
3428
|
+
return new ZodLiteral({
|
|
3429
|
+
value,
|
|
3430
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3431
|
+
...processCreateParams(params)
|
|
3432
|
+
});
|
|
3433
|
+
};
|
|
3434
|
+
function createZodEnum(values, params) {
|
|
3435
|
+
return new ZodEnum({
|
|
3436
|
+
values,
|
|
3437
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3438
|
+
...processCreateParams(params)
|
|
3439
|
+
});
|
|
3440
|
+
}
|
|
3441
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3442
|
+
_parse(input) {
|
|
3443
|
+
if (typeof input.data !== "string") {
|
|
3444
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3445
|
+
const expectedValues = this._def.values;
|
|
3446
|
+
addIssueToContext(ctx, {
|
|
3447
|
+
expected: util.joinValues(expectedValues),
|
|
3448
|
+
received: ctx.parsedType,
|
|
3449
|
+
code: ZodIssueCode.invalid_type
|
|
3450
|
+
});
|
|
3451
|
+
return INVALID;
|
|
3452
|
+
}
|
|
3453
|
+
if (!this._cache) {
|
|
3454
|
+
this._cache = new Set(this._def.values);
|
|
3455
|
+
}
|
|
3456
|
+
if (!this._cache.has(input.data)) {
|
|
3457
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3458
|
+
const expectedValues = this._def.values;
|
|
3459
|
+
addIssueToContext(ctx, {
|
|
3460
|
+
received: ctx.data,
|
|
3461
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3462
|
+
options: expectedValues
|
|
3463
|
+
});
|
|
3464
|
+
return INVALID;
|
|
3465
|
+
}
|
|
3466
|
+
return OK(input.data);
|
|
3467
|
+
}
|
|
3468
|
+
get options() {
|
|
3469
|
+
return this._def.values;
|
|
3470
|
+
}
|
|
3471
|
+
get enum() {
|
|
3472
|
+
const enumValues = {};
|
|
3473
|
+
for (const val of this._def.values) {
|
|
3474
|
+
enumValues[val] = val;
|
|
3475
|
+
}
|
|
3476
|
+
return enumValues;
|
|
3477
|
+
}
|
|
3478
|
+
get Values() {
|
|
3479
|
+
const enumValues = {};
|
|
3480
|
+
for (const val of this._def.values) {
|
|
3481
|
+
enumValues[val] = val;
|
|
3482
|
+
}
|
|
3483
|
+
return enumValues;
|
|
3484
|
+
}
|
|
3485
|
+
get Enum() {
|
|
3486
|
+
const enumValues = {};
|
|
3487
|
+
for (const val of this._def.values) {
|
|
3488
|
+
enumValues[val] = val;
|
|
3489
|
+
}
|
|
3490
|
+
return enumValues;
|
|
3491
|
+
}
|
|
3492
|
+
extract(values, newDef = this._def) {
|
|
3493
|
+
return _ZodEnum.create(values, {
|
|
3494
|
+
...this._def,
|
|
3495
|
+
...newDef
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
exclude(values, newDef = this._def) {
|
|
3499
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3500
|
+
...this._def,
|
|
3501
|
+
...newDef
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
};
|
|
3505
|
+
ZodEnum.create = createZodEnum;
|
|
3506
|
+
var ZodNativeEnum = class extends ZodType {
|
|
3507
|
+
_parse(input) {
|
|
3508
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3509
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3510
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3511
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3512
|
+
addIssueToContext(ctx, {
|
|
3513
|
+
expected: util.joinValues(expectedValues),
|
|
3514
|
+
received: ctx.parsedType,
|
|
3515
|
+
code: ZodIssueCode.invalid_type
|
|
3516
|
+
});
|
|
3517
|
+
return INVALID;
|
|
3518
|
+
}
|
|
3519
|
+
if (!this._cache) {
|
|
3520
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3521
|
+
}
|
|
3522
|
+
if (!this._cache.has(input.data)) {
|
|
3523
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3524
|
+
addIssueToContext(ctx, {
|
|
3525
|
+
received: ctx.data,
|
|
3526
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3527
|
+
options: expectedValues
|
|
3528
|
+
});
|
|
3529
|
+
return INVALID;
|
|
3530
|
+
}
|
|
3531
|
+
return OK(input.data);
|
|
3532
|
+
}
|
|
3533
|
+
get enum() {
|
|
3534
|
+
return this._def.values;
|
|
3535
|
+
}
|
|
3536
|
+
};
|
|
3537
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3538
|
+
return new ZodNativeEnum({
|
|
3539
|
+
values,
|
|
3540
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3541
|
+
...processCreateParams(params)
|
|
3542
|
+
});
|
|
3543
|
+
};
|
|
3544
|
+
var ZodPromise = class extends ZodType {
|
|
3545
|
+
unwrap() {
|
|
3546
|
+
return this._def.type;
|
|
3547
|
+
}
|
|
3548
|
+
_parse(input) {
|
|
3549
|
+
const { ctx } = this._processInputParams(input);
|
|
3550
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3551
|
+
addIssueToContext(ctx, {
|
|
3552
|
+
code: ZodIssueCode.invalid_type,
|
|
3553
|
+
expected: ZodParsedType.promise,
|
|
3554
|
+
received: ctx.parsedType
|
|
3555
|
+
});
|
|
3556
|
+
return INVALID;
|
|
3557
|
+
}
|
|
3558
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3559
|
+
return OK(promisified.then((data) => {
|
|
3560
|
+
return this._def.type.parseAsync(data, {
|
|
3561
|
+
path: ctx.path,
|
|
3562
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3563
|
+
});
|
|
3564
|
+
}));
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
ZodPromise.create = (schema, params) => {
|
|
3568
|
+
return new ZodPromise({
|
|
3569
|
+
type: schema,
|
|
3570
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3571
|
+
...processCreateParams(params)
|
|
3572
|
+
});
|
|
3573
|
+
};
|
|
3574
|
+
var ZodEffects = class extends ZodType {
|
|
3575
|
+
innerType() {
|
|
3576
|
+
return this._def.schema;
|
|
3577
|
+
}
|
|
3578
|
+
sourceType() {
|
|
3579
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3580
|
+
}
|
|
3581
|
+
_parse(input) {
|
|
3582
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3583
|
+
const effect = this._def.effect || null;
|
|
3584
|
+
const checkCtx = {
|
|
3585
|
+
addIssue: (arg) => {
|
|
3586
|
+
addIssueToContext(ctx, arg);
|
|
3587
|
+
if (arg.fatal) {
|
|
3588
|
+
status.abort();
|
|
3589
|
+
} else {
|
|
3590
|
+
status.dirty();
|
|
3591
|
+
}
|
|
3592
|
+
},
|
|
3593
|
+
get path() {
|
|
3594
|
+
return ctx.path;
|
|
3595
|
+
}
|
|
3596
|
+
};
|
|
3597
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3598
|
+
if (effect.type === "preprocess") {
|
|
3599
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3600
|
+
if (ctx.common.async) {
|
|
3601
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3602
|
+
if (status.value === "aborted")
|
|
3603
|
+
return INVALID;
|
|
3604
|
+
const result = await this._def.schema._parseAsync({
|
|
3605
|
+
data: processed2,
|
|
3606
|
+
path: ctx.path,
|
|
3607
|
+
parent: ctx
|
|
3608
|
+
});
|
|
3609
|
+
if (result.status === "aborted")
|
|
3610
|
+
return INVALID;
|
|
3611
|
+
if (result.status === "dirty")
|
|
3612
|
+
return DIRTY(result.value);
|
|
3613
|
+
if (status.value === "dirty")
|
|
3614
|
+
return DIRTY(result.value);
|
|
3615
|
+
return result;
|
|
3616
|
+
});
|
|
3617
|
+
} else {
|
|
3618
|
+
if (status.value === "aborted")
|
|
3619
|
+
return INVALID;
|
|
3620
|
+
const result = this._def.schema._parseSync({
|
|
3621
|
+
data: processed,
|
|
3622
|
+
path: ctx.path,
|
|
3623
|
+
parent: ctx
|
|
3624
|
+
});
|
|
3625
|
+
if (result.status === "aborted")
|
|
3626
|
+
return INVALID;
|
|
3627
|
+
if (result.status === "dirty")
|
|
3628
|
+
return DIRTY(result.value);
|
|
3629
|
+
if (status.value === "dirty")
|
|
3630
|
+
return DIRTY(result.value);
|
|
3631
|
+
return result;
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
if (effect.type === "refinement") {
|
|
3635
|
+
const executeRefinement = (acc) => {
|
|
3636
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3637
|
+
if (ctx.common.async) {
|
|
3638
|
+
return Promise.resolve(result);
|
|
3639
|
+
}
|
|
3640
|
+
if (result instanceof Promise) {
|
|
3641
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3642
|
+
}
|
|
3643
|
+
return acc;
|
|
3644
|
+
};
|
|
3645
|
+
if (ctx.common.async === false) {
|
|
3646
|
+
const inner = this._def.schema._parseSync({
|
|
3647
|
+
data: ctx.data,
|
|
3648
|
+
path: ctx.path,
|
|
3649
|
+
parent: ctx
|
|
3650
|
+
});
|
|
3651
|
+
if (inner.status === "aborted")
|
|
3652
|
+
return INVALID;
|
|
3653
|
+
if (inner.status === "dirty")
|
|
3654
|
+
status.dirty();
|
|
3655
|
+
executeRefinement(inner.value);
|
|
3656
|
+
return { status: status.value, value: inner.value };
|
|
3657
|
+
} else {
|
|
3658
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3659
|
+
if (inner.status === "aborted")
|
|
3660
|
+
return INVALID;
|
|
3661
|
+
if (inner.status === "dirty")
|
|
3662
|
+
status.dirty();
|
|
3663
|
+
return executeRefinement(inner.value).then(() => {
|
|
3664
|
+
return { status: status.value, value: inner.value };
|
|
3665
|
+
});
|
|
3666
|
+
});
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
if (effect.type === "transform") {
|
|
3670
|
+
if (ctx.common.async === false) {
|
|
3671
|
+
const base = this._def.schema._parseSync({
|
|
3672
|
+
data: ctx.data,
|
|
3673
|
+
path: ctx.path,
|
|
3674
|
+
parent: ctx
|
|
3675
|
+
});
|
|
3676
|
+
if (!isValid(base))
|
|
3677
|
+
return INVALID;
|
|
3678
|
+
const result = effect.transform(base.value, checkCtx);
|
|
3679
|
+
if (result instanceof Promise) {
|
|
3680
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3681
|
+
}
|
|
3682
|
+
return { status: status.value, value: result };
|
|
3683
|
+
} else {
|
|
3684
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
3685
|
+
if (!isValid(base))
|
|
3686
|
+
return INVALID;
|
|
3687
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3688
|
+
status: status.value,
|
|
3689
|
+
value: result
|
|
3690
|
+
}));
|
|
3691
|
+
});
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
util.assertNever(effect);
|
|
3695
|
+
}
|
|
3696
|
+
};
|
|
3697
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
3698
|
+
return new ZodEffects({
|
|
3699
|
+
schema,
|
|
3700
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3701
|
+
effect,
|
|
3702
|
+
...processCreateParams(params)
|
|
3703
|
+
});
|
|
3704
|
+
};
|
|
3705
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3706
|
+
return new ZodEffects({
|
|
3707
|
+
schema,
|
|
3708
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
3709
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3710
|
+
...processCreateParams(params)
|
|
3711
|
+
});
|
|
3712
|
+
};
|
|
3713
|
+
var ZodOptional = class extends ZodType {
|
|
3714
|
+
_parse(input) {
|
|
3715
|
+
const parsedType = this._getType(input);
|
|
3716
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
3717
|
+
return OK(void 0);
|
|
3718
|
+
}
|
|
3719
|
+
return this._def.innerType._parse(input);
|
|
3720
|
+
}
|
|
3721
|
+
unwrap() {
|
|
3722
|
+
return this._def.innerType;
|
|
3723
|
+
}
|
|
3724
|
+
};
|
|
3725
|
+
ZodOptional.create = (type, params) => {
|
|
3726
|
+
return new ZodOptional({
|
|
3727
|
+
innerType: type,
|
|
3728
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3729
|
+
...processCreateParams(params)
|
|
3730
|
+
});
|
|
3731
|
+
};
|
|
3732
|
+
var ZodNullable = class extends ZodType {
|
|
3733
|
+
_parse(input) {
|
|
3734
|
+
const parsedType = this._getType(input);
|
|
3735
|
+
if (parsedType === ZodParsedType.null) {
|
|
3736
|
+
return OK(null);
|
|
3737
|
+
}
|
|
3738
|
+
return this._def.innerType._parse(input);
|
|
3739
|
+
}
|
|
3740
|
+
unwrap() {
|
|
3741
|
+
return this._def.innerType;
|
|
3742
|
+
}
|
|
3743
|
+
};
|
|
3744
|
+
ZodNullable.create = (type, params) => {
|
|
3745
|
+
return new ZodNullable({
|
|
3746
|
+
innerType: type,
|
|
3747
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3748
|
+
...processCreateParams(params)
|
|
3749
|
+
});
|
|
3750
|
+
};
|
|
3751
|
+
var ZodDefault = class extends ZodType {
|
|
3752
|
+
_parse(input) {
|
|
3753
|
+
const { ctx } = this._processInputParams(input);
|
|
3754
|
+
let data = ctx.data;
|
|
3755
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3756
|
+
data = this._def.defaultValue();
|
|
3757
|
+
}
|
|
3758
|
+
return this._def.innerType._parse({
|
|
3759
|
+
data,
|
|
3760
|
+
path: ctx.path,
|
|
3761
|
+
parent: ctx
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
removeDefault() {
|
|
3765
|
+
return this._def.innerType;
|
|
3766
|
+
}
|
|
3767
|
+
};
|
|
3768
|
+
ZodDefault.create = (type, params) => {
|
|
3769
|
+
return new ZodDefault({
|
|
3770
|
+
innerType: type,
|
|
3771
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3772
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3773
|
+
...processCreateParams(params)
|
|
3774
|
+
});
|
|
3775
|
+
};
|
|
3776
|
+
var ZodCatch = class extends ZodType {
|
|
3777
|
+
_parse(input) {
|
|
3778
|
+
const { ctx } = this._processInputParams(input);
|
|
3779
|
+
const newCtx = {
|
|
3780
|
+
...ctx,
|
|
3781
|
+
common: {
|
|
3782
|
+
...ctx.common,
|
|
3783
|
+
issues: []
|
|
3784
|
+
}
|
|
3785
|
+
};
|
|
3786
|
+
const result = this._def.innerType._parse({
|
|
3787
|
+
data: newCtx.data,
|
|
3788
|
+
path: newCtx.path,
|
|
3789
|
+
parent: {
|
|
3790
|
+
...newCtx
|
|
3791
|
+
}
|
|
3792
|
+
});
|
|
3793
|
+
if (isAsync(result)) {
|
|
3794
|
+
return result.then((result2) => {
|
|
3795
|
+
return {
|
|
3796
|
+
status: "valid",
|
|
3797
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
3798
|
+
get error() {
|
|
3799
|
+
return new ZodError(newCtx.common.issues);
|
|
3800
|
+
},
|
|
3801
|
+
input: newCtx.data
|
|
3802
|
+
})
|
|
3803
|
+
};
|
|
3804
|
+
});
|
|
3805
|
+
} else {
|
|
3806
|
+
return {
|
|
3807
|
+
status: "valid",
|
|
3808
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3809
|
+
get error() {
|
|
3810
|
+
return new ZodError(newCtx.common.issues);
|
|
3811
|
+
},
|
|
3812
|
+
input: newCtx.data
|
|
3813
|
+
})
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
removeCatch() {
|
|
3818
|
+
return this._def.innerType;
|
|
3819
|
+
}
|
|
3820
|
+
};
|
|
3821
|
+
ZodCatch.create = (type, params) => {
|
|
3822
|
+
return new ZodCatch({
|
|
3823
|
+
innerType: type,
|
|
3824
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3825
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3826
|
+
...processCreateParams(params)
|
|
3827
|
+
});
|
|
3828
|
+
};
|
|
3829
|
+
var ZodNaN = class extends ZodType {
|
|
3830
|
+
_parse(input) {
|
|
3831
|
+
const parsedType = this._getType(input);
|
|
3832
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
3833
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3834
|
+
addIssueToContext(ctx, {
|
|
3835
|
+
code: ZodIssueCode.invalid_type,
|
|
3836
|
+
expected: ZodParsedType.nan,
|
|
3837
|
+
received: ctx.parsedType
|
|
3838
|
+
});
|
|
3839
|
+
return INVALID;
|
|
3840
|
+
}
|
|
3841
|
+
return { status: "valid", value: input.data };
|
|
3842
|
+
}
|
|
3843
|
+
};
|
|
3844
|
+
ZodNaN.create = (params) => {
|
|
3845
|
+
return new ZodNaN({
|
|
3846
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3847
|
+
...processCreateParams(params)
|
|
3848
|
+
});
|
|
3849
|
+
};
|
|
3850
|
+
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
3851
|
+
var ZodBranded = class extends ZodType {
|
|
3852
|
+
_parse(input) {
|
|
3853
|
+
const { ctx } = this._processInputParams(input);
|
|
3854
|
+
const data = ctx.data;
|
|
3855
|
+
return this._def.type._parse({
|
|
3856
|
+
data,
|
|
3857
|
+
path: ctx.path,
|
|
3858
|
+
parent: ctx
|
|
3859
|
+
});
|
|
3860
|
+
}
|
|
3861
|
+
unwrap() {
|
|
3862
|
+
return this._def.type;
|
|
3863
|
+
}
|
|
3864
|
+
};
|
|
3865
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
3866
|
+
_parse(input) {
|
|
3867
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3868
|
+
if (ctx.common.async) {
|
|
3869
|
+
const handleAsync = async () => {
|
|
3870
|
+
const inResult = await this._def.in._parseAsync({
|
|
3871
|
+
data: ctx.data,
|
|
3872
|
+
path: ctx.path,
|
|
3873
|
+
parent: ctx
|
|
3874
|
+
});
|
|
3875
|
+
if (inResult.status === "aborted")
|
|
3876
|
+
return INVALID;
|
|
3877
|
+
if (inResult.status === "dirty") {
|
|
3878
|
+
status.dirty();
|
|
3879
|
+
return DIRTY(inResult.value);
|
|
3880
|
+
} else {
|
|
3881
|
+
return this._def.out._parseAsync({
|
|
3882
|
+
data: inResult.value,
|
|
3883
|
+
path: ctx.path,
|
|
3884
|
+
parent: ctx
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3888
|
+
return handleAsync();
|
|
3889
|
+
} else {
|
|
3890
|
+
const inResult = this._def.in._parseSync({
|
|
3891
|
+
data: ctx.data,
|
|
3892
|
+
path: ctx.path,
|
|
3893
|
+
parent: ctx
|
|
3894
|
+
});
|
|
3895
|
+
if (inResult.status === "aborted")
|
|
3896
|
+
return INVALID;
|
|
3897
|
+
if (inResult.status === "dirty") {
|
|
3898
|
+
status.dirty();
|
|
3899
|
+
return {
|
|
3900
|
+
status: "dirty",
|
|
3901
|
+
value: inResult.value
|
|
3902
|
+
};
|
|
3903
|
+
} else {
|
|
3904
|
+
return this._def.out._parseSync({
|
|
3905
|
+
data: inResult.value,
|
|
3906
|
+
path: ctx.path,
|
|
3907
|
+
parent: ctx
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
static create(a, b) {
|
|
3913
|
+
return new _ZodPipeline({
|
|
3914
|
+
in: a,
|
|
3915
|
+
out: b,
|
|
3916
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
};
|
|
3920
|
+
var ZodReadonly = class extends ZodType {
|
|
3921
|
+
_parse(input) {
|
|
3922
|
+
const result = this._def.innerType._parse(input);
|
|
3923
|
+
const freeze = (data) => {
|
|
3924
|
+
if (isValid(data)) {
|
|
3925
|
+
data.value = Object.freeze(data.value);
|
|
3926
|
+
}
|
|
3927
|
+
return data;
|
|
3928
|
+
};
|
|
3929
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3930
|
+
}
|
|
3931
|
+
unwrap() {
|
|
3932
|
+
return this._def.innerType;
|
|
3933
|
+
}
|
|
3934
|
+
};
|
|
3935
|
+
ZodReadonly.create = (type, params) => {
|
|
3936
|
+
return new ZodReadonly({
|
|
3937
|
+
innerType: type,
|
|
3938
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3939
|
+
...processCreateParams(params)
|
|
3940
|
+
});
|
|
3941
|
+
};
|
|
3942
|
+
function cleanParams(params, data) {
|
|
3943
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3944
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3945
|
+
return p2;
|
|
3946
|
+
}
|
|
3947
|
+
function custom(check, _params = {}, fatal) {
|
|
3948
|
+
if (check)
|
|
3949
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
3950
|
+
const r = check(data);
|
|
3951
|
+
if (r instanceof Promise) {
|
|
3952
|
+
return r.then((r2) => {
|
|
3953
|
+
if (!r2) {
|
|
3954
|
+
const params = cleanParams(_params, data);
|
|
3955
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
3956
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3957
|
+
}
|
|
3958
|
+
});
|
|
3959
|
+
}
|
|
3960
|
+
if (!r) {
|
|
3961
|
+
const params = cleanParams(_params, data);
|
|
3962
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
3963
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3964
|
+
}
|
|
3965
|
+
return;
|
|
3966
|
+
});
|
|
3967
|
+
return ZodAny.create();
|
|
3968
|
+
}
|
|
3969
|
+
var late = {
|
|
3970
|
+
object: ZodObject.lazycreate
|
|
3971
|
+
};
|
|
3972
|
+
var ZodFirstPartyTypeKind;
|
|
3973
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
3974
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
3975
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
3976
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
3977
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
3978
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
3979
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
3980
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
3981
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
3982
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
3983
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
3984
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
3985
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
3986
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
3987
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
3988
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
3989
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
3990
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3991
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
3992
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
3993
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
3994
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
3995
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
3996
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
3997
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
3998
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
3999
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4000
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4001
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4002
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4003
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4004
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4005
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4006
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4007
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4008
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4009
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4010
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4011
|
+
var instanceOfType = (cls, params = {
|
|
4012
|
+
message: `Input not instance of ${cls.name}`
|
|
4013
|
+
}) => custom((data) => data instanceof cls, params);
|
|
4014
|
+
var stringType = ZodString.create;
|
|
4015
|
+
var numberType = ZodNumber.create;
|
|
4016
|
+
var nanType = ZodNaN.create;
|
|
4017
|
+
var bigIntType = ZodBigInt.create;
|
|
4018
|
+
var booleanType = ZodBoolean.create;
|
|
4019
|
+
var dateType = ZodDate.create;
|
|
4020
|
+
var symbolType = ZodSymbol.create;
|
|
4021
|
+
var undefinedType = ZodUndefined.create;
|
|
4022
|
+
var nullType = ZodNull.create;
|
|
4023
|
+
var anyType = ZodAny.create;
|
|
4024
|
+
var unknownType = ZodUnknown.create;
|
|
4025
|
+
var neverType = ZodNever.create;
|
|
4026
|
+
var voidType = ZodVoid.create;
|
|
4027
|
+
var arrayType = ZodArray.create;
|
|
4028
|
+
var objectType = ZodObject.create;
|
|
4029
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
4030
|
+
var unionType = ZodUnion.create;
|
|
4031
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4032
|
+
var intersectionType = ZodIntersection.create;
|
|
4033
|
+
var tupleType = ZodTuple.create;
|
|
4034
|
+
var recordType = ZodRecord.create;
|
|
4035
|
+
var mapType = ZodMap.create;
|
|
4036
|
+
var setType = ZodSet.create;
|
|
4037
|
+
var functionType = ZodFunction.create;
|
|
4038
|
+
var lazyType = ZodLazy.create;
|
|
4039
|
+
var literalType = ZodLiteral.create;
|
|
4040
|
+
var enumType = ZodEnum.create;
|
|
4041
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
4042
|
+
var promiseType = ZodPromise.create;
|
|
4043
|
+
var effectsType = ZodEffects.create;
|
|
4044
|
+
var optionalType = ZodOptional.create;
|
|
4045
|
+
var nullableType = ZodNullable.create;
|
|
4046
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4047
|
+
var pipelineType = ZodPipeline.create;
|
|
4048
|
+
var ostring = () => stringType().optional();
|
|
4049
|
+
var onumber = () => numberType().optional();
|
|
4050
|
+
var oboolean = () => booleanType().optional();
|
|
4051
|
+
var coerce = {
|
|
4052
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4053
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4054
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
4055
|
+
...arg,
|
|
4056
|
+
coerce: true
|
|
4057
|
+
})),
|
|
4058
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4059
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4060
|
+
};
|
|
4061
|
+
var NEVER = INVALID;
|
|
2
4062
|
|
|
3
|
-
// src/index.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4063
|
+
// ../deploy-core/src/index.ts
|
|
4064
|
+
var DeployPlanError = class extends Error {
|
|
4065
|
+
constructor(message) {
|
|
4066
|
+
super(message);
|
|
4067
|
+
this.name = "DeployPlanError";
|
|
4068
|
+
}
|
|
4069
|
+
};
|
|
4070
|
+
var deployConfigSchema = external_exports.object({
|
|
4071
|
+
edition: external_exports.enum(["oss", "enterprise"]).optional(),
|
|
4072
|
+
source: external_exports.object({
|
|
4073
|
+
repo_url: external_exports.string().default("https://github.com/EnvSync-Cloud/envsync.git"),
|
|
4074
|
+
ref: external_exports.string().default("main")
|
|
4075
|
+
}).default({}),
|
|
4076
|
+
release: external_exports.object({
|
|
4077
|
+
version: external_exports.string().default("0.8.7"),
|
|
4078
|
+
channel: external_exports.string().default("stable")
|
|
4079
|
+
}).default({}),
|
|
4080
|
+
domain: external_exports.object({
|
|
4081
|
+
root_domain: external_exports.string().default("example.com"),
|
|
4082
|
+
acme_email: external_exports.string().default("ops@example.com")
|
|
4083
|
+
}).default({}),
|
|
4084
|
+
services: external_exports.object({
|
|
4085
|
+
stack_name: external_exports.string().default("envsync"),
|
|
4086
|
+
api_port: external_exports.number().int().positive().default(4e3),
|
|
4087
|
+
management_api_port: external_exports.number().int().positive().default(4001),
|
|
4088
|
+
public_http_port: external_exports.number().int().positive().default(80),
|
|
4089
|
+
public_https_port: external_exports.number().int().positive().default(443)
|
|
4090
|
+
}).default({}),
|
|
4091
|
+
images: external_exports.object({
|
|
4092
|
+
api: external_exports.string().default("ghcr.io/envsync-cloud/envsync-api:stable"),
|
|
4093
|
+
management_api: external_exports.string().default("ghcr.io/envsync-cloud/envsync-management-api:stable"),
|
|
4094
|
+
web: external_exports.string().default("ghcr.io/envsync-cloud/envsync-web-oss-static:stable"),
|
|
4095
|
+
enterprise_web: external_exports.string().default("ghcr.io/envsync-cloud/envsync-web-static:stable"),
|
|
4096
|
+
landing: external_exports.string().default("ghcr.io/envsync-cloud/envsync-landing-static:stable"),
|
|
4097
|
+
keycloak: external_exports.string().default("envsync-keycloak:stable"),
|
|
4098
|
+
clickstack: external_exports.string().default("ghcr.io/envsync-cloud/clickstack:stable"),
|
|
4099
|
+
otel_agent: external_exports.string().default("otel/opentelemetry-collector-contrib:latest")
|
|
4100
|
+
}).default({}),
|
|
4101
|
+
features: external_exports.object({
|
|
4102
|
+
management_api: external_exports.boolean().optional(),
|
|
4103
|
+
management_web: external_exports.boolean().optional(),
|
|
4104
|
+
landing: external_exports.boolean().optional()
|
|
4105
|
+
}).default({}),
|
|
4106
|
+
observability: external_exports.object({
|
|
4107
|
+
enabled: external_exports.boolean().optional(),
|
|
4108
|
+
public_obs: external_exports.boolean().optional()
|
|
4109
|
+
}).default({}),
|
|
4110
|
+
license: external_exports.object({
|
|
4111
|
+
required: external_exports.boolean().optional(),
|
|
4112
|
+
server_url: external_exports.string().optional(),
|
|
4113
|
+
key: external_exports.string().optional(),
|
|
4114
|
+
install_fingerprint: external_exports.string().optional(),
|
|
4115
|
+
lease_ttl_seconds: external_exports.number().int().positive().default(300)
|
|
4116
|
+
}).default({}),
|
|
4117
|
+
frontend: external_exports.object({
|
|
4118
|
+
dashboard_variant: external_exports.enum(["oss", "enterprise"]).optional(),
|
|
4119
|
+
include_manage_subtree: external_exports.boolean().optional()
|
|
4120
|
+
}).default({})
|
|
4121
|
+
});
|
|
4122
|
+
function readDeployConfigFile(filePath) {
|
|
4123
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
4124
|
+
if (!fs.existsSync(absolutePath)) {
|
|
4125
|
+
throw new DeployPlanError(`Deploy config file not found: ${absolutePath}`);
|
|
4126
|
+
}
|
|
4127
|
+
const raw = fs.readFileSync(absolutePath, "utf8");
|
|
4128
|
+
if (absolutePath.endsWith(".json")) {
|
|
4129
|
+
return JSON.parse(raw);
|
|
4130
|
+
}
|
|
4131
|
+
return YAML.parse(raw);
|
|
4132
|
+
}
|
|
4133
|
+
function validateEditionRules(config, edition) {
|
|
4134
|
+
const errors = [];
|
|
4135
|
+
if (edition === "oss") {
|
|
4136
|
+
if (config.edition === "enterprise") {
|
|
4137
|
+
errors.push("OSS deploy tooling cannot consume a config explicitly marked as enterprise.");
|
|
4138
|
+
}
|
|
4139
|
+
if (config.features.management_api === true) {
|
|
4140
|
+
errors.push("OSS edition cannot enable management_api.");
|
|
4141
|
+
}
|
|
4142
|
+
if (config.features.landing === true) {
|
|
4143
|
+
errors.push("OSS edition cannot enable landing.");
|
|
4144
|
+
}
|
|
4145
|
+
if (config.license.required === true) {
|
|
4146
|
+
errors.push("OSS edition cannot require enterprise licensing.");
|
|
4147
|
+
}
|
|
4148
|
+
if (config.license.server_url || config.license.key || config.license.install_fingerprint) {
|
|
4149
|
+
errors.push("OSS edition cannot include enterprise license server settings.");
|
|
4150
|
+
}
|
|
4151
|
+
if (config.frontend.dashboard_variant === "enterprise") {
|
|
4152
|
+
errors.push("OSS edition cannot use the enterprise dashboard variant.");
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
if (edition === "enterprise") {
|
|
4156
|
+
if (config.edition === "oss") {
|
|
4157
|
+
errors.push("Enterprise deploy tooling cannot consume a config explicitly marked as oss.");
|
|
4158
|
+
}
|
|
4159
|
+
if (config.features.management_api === false) {
|
|
4160
|
+
errors.push("Enterprise edition must enable management_api.");
|
|
4161
|
+
}
|
|
4162
|
+
if (config.features.landing === false) {
|
|
4163
|
+
errors.push("Enterprise edition must enable landing.");
|
|
4164
|
+
}
|
|
4165
|
+
if (config.license.required === false) {
|
|
4166
|
+
errors.push("Enterprise edition must require licensing.");
|
|
4167
|
+
}
|
|
4168
|
+
if (!config.license.server_url) {
|
|
4169
|
+
errors.push("Enterprise edition requires license.server_url.");
|
|
4170
|
+
}
|
|
4171
|
+
if (config.frontend.dashboard_variant === "oss") {
|
|
4172
|
+
errors.push("Enterprise edition cannot use the OSS dashboard variant.");
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4175
|
+
if (errors.length > 0) {
|
|
4176
|
+
throw new DeployPlanError(errors.join(" "));
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
function buildServicePlans(config, edition) {
|
|
4180
|
+
const observabilityEnabled = config.observability.enabled ?? edition === "enterprise";
|
|
4181
|
+
const managementEnabled = edition === "enterprise";
|
|
4182
|
+
const landingEnabled = edition === "enterprise";
|
|
4183
|
+
return [
|
|
4184
|
+
{ id: "api", enabled: true, tier: "core", reason: "Required in all editions.", image: config.images.api },
|
|
4185
|
+
{ id: "web", enabled: true, tier: "core", reason: "Primary dashboard artifact.", image: edition === "enterprise" ? config.images.enterprise_web : config.images.web },
|
|
4186
|
+
{ id: "postgres", enabled: true, tier: "core", reason: "Core persistence.", image: null },
|
|
4187
|
+
{ id: "redis", enabled: true, tier: "core", reason: "Core cache and sessions.", image: null },
|
|
4188
|
+
{ id: "rustfs", enabled: true, tier: "core", reason: "Object storage for artifacts.", image: null },
|
|
4189
|
+
{ id: "openfga", enabled: true, tier: "core", reason: "Authorization service.", image: null },
|
|
4190
|
+
{ id: "minikms", enabled: true, tier: "core", reason: "Secret encryption service.", image: null },
|
|
4191
|
+
{ id: "keycloak", enabled: true, tier: "core", reason: "Authentication provider.", image: config.images.keycloak },
|
|
4192
|
+
{ id: "management-api", enabled: managementEnabled, tier: "enterprise", reason: managementEnabled ? "Enterprise control plane API." : "Not deployed in OSS.", image: managementEnabled ? config.images.management_api : null },
|
|
4193
|
+
{ id: "landing", enabled: landingEnabled, tier: "enterprise", reason: landingEnabled ? "Enterprise/public onboarding surface." : "Omitted in OSS.", image: landingEnabled ? config.images.landing : null },
|
|
4194
|
+
{ id: "clickstack", enabled: observabilityEnabled, tier: observabilityEnabled ? "optional" : "optional", reason: observabilityEnabled ? "Observability enabled for this topology." : "Observability disabled.", image: observabilityEnabled ? config.images.clickstack : null },
|
|
4195
|
+
{ id: "otel-agent", enabled: observabilityEnabled, tier: "optional", reason: observabilityEnabled ? "OTEL pipeline enabled for this topology." : "OTEL disabled.", image: observabilityEnabled ? config.images.otel_agent : null }
|
|
4196
|
+
];
|
|
4197
|
+
}
|
|
4198
|
+
function buildFrontendArtifacts(config, edition) {
|
|
4199
|
+
const enterprise = edition === "enterprise";
|
|
4200
|
+
return [
|
|
4201
|
+
{
|
|
4202
|
+
id: "dashboard",
|
|
4203
|
+
package_name: "envsync-web",
|
|
4204
|
+
build_command: enterprise ? "bun run --filter envsync-web build:enterprise" : "bun run --filter envsync-web build:oss",
|
|
4205
|
+
mount_path: "/",
|
|
4206
|
+
included: true,
|
|
4207
|
+
image: enterprise ? config.images.enterprise_web : config.images.web
|
|
4208
|
+
},
|
|
4209
|
+
{
|
|
4210
|
+
id: "landing",
|
|
4211
|
+
package_name: "envsync-landing",
|
|
4212
|
+
build_command: "bun run --filter envsync-landing build",
|
|
4213
|
+
mount_path: "/",
|
|
4214
|
+
included: enterprise,
|
|
4215
|
+
image: enterprise ? config.images.landing : null
|
|
4216
|
+
}
|
|
4217
|
+
];
|
|
4218
|
+
}
|
|
4219
|
+
function buildRuntimeEnv(config, edition) {
|
|
4220
|
+
const enterprise = edition === "enterprise";
|
|
4221
|
+
const observabilityEnabled = config.observability.enabled ?? enterprise;
|
|
4222
|
+
return {
|
|
4223
|
+
ENVSYNC_EDITION: edition,
|
|
4224
|
+
ENVSYNC_OBSERVABILITY_ENABLED: String(observabilityEnabled),
|
|
4225
|
+
ENVSYNC_MANAGEMENT_ENABLED: String(enterprise),
|
|
4226
|
+
ENVSYNC_LANDING_ENABLED: String(enterprise),
|
|
4227
|
+
ENVSYNC_SINGLE_ORG_MODE: String(edition === "oss"),
|
|
4228
|
+
ENVSYNC_LICENSE_ENFORCEMENT: String(enterprise),
|
|
4229
|
+
ENVSYNC_LICENSE_MODE: enterprise ? "certificate" : "none",
|
|
4230
|
+
ENVSYNC_LICENSE_BUNDLE_PATH: enterprise ? "/etc/envsync/license/enterprise-license-bundle.json" : "",
|
|
4231
|
+
ENVSYNC_LICENSE_CERT_PATH: enterprise ? "/etc/envsync/license/enterprise-cert.pem" : "",
|
|
4232
|
+
ENVSYNC_LICENSE_KEY_PATH: enterprise ? "/etc/envsync/license/enterprise-key.pem" : "",
|
|
4233
|
+
ENVSYNC_LICENSE_ROOT_CA_CERT_PATH: enterprise ? "/etc/envsync/license/root-ca.pem" : "",
|
|
4234
|
+
MANAGEMENT_API_URL: enterprise ? `https://manage-api.${config.domain.root_domain}` : "",
|
|
4235
|
+
ENVSYNC_LICENSE_SERVER_URL: enterprise ? config.license.server_url ?? "" : "",
|
|
4236
|
+
ENVSYNC_LICENSE_KEY: enterprise ? config.license.key ?? "" : "",
|
|
4237
|
+
ENVSYNC_INSTALL_FINGERPRINT: enterprise ? config.license.install_fingerprint ?? "" : "",
|
|
4238
|
+
ENVSYNC_LICENSE_LEASE_TTL_SECONDS: String(config.license.lease_ttl_seconds),
|
|
4239
|
+
ENVSYNC_STACK_NAME: config.services.stack_name,
|
|
4240
|
+
ENVSYNC_RELEASE_VERSION: config.release.version
|
|
4241
|
+
};
|
|
4242
|
+
}
|
|
4243
|
+
function buildReleaseArtifacts(config, edition) {
|
|
4244
|
+
const npmPackages = [
|
|
4245
|
+
{
|
|
4246
|
+
name: "@envsync-cloud/deploy",
|
|
4247
|
+
registry: "npm",
|
|
4248
|
+
edition: "oss",
|
|
4249
|
+
publish: edition === "oss"
|
|
4250
|
+
},
|
|
4251
|
+
{
|
|
4252
|
+
name: "@envsync-cloud/deploy-cli",
|
|
4253
|
+
registry: "github-packages",
|
|
4254
|
+
edition: "enterprise",
|
|
4255
|
+
publish: edition === "enterprise"
|
|
4256
|
+
}
|
|
4257
|
+
];
|
|
4258
|
+
const container_images = [
|
|
4259
|
+
{
|
|
4260
|
+
name: "envsync-api",
|
|
4261
|
+
image: config.images.api,
|
|
4262
|
+
build_target: "packages/envsync-api",
|
|
4263
|
+
edition: "shared"
|
|
4264
|
+
}
|
|
4265
|
+
];
|
|
4266
|
+
if (edition === "enterprise") {
|
|
4267
|
+
container_images.push(
|
|
4268
|
+
{
|
|
4269
|
+
name: "envsync-management-api",
|
|
4270
|
+
image: config.images.management_api,
|
|
4271
|
+
build_target: "packages/envsync-management-api",
|
|
4272
|
+
edition: "enterprise"
|
|
4273
|
+
},
|
|
4274
|
+
{
|
|
4275
|
+
name: "envsync-web-static",
|
|
4276
|
+
image: config.images.enterprise_web,
|
|
4277
|
+
build_target: "apps/envsync-web#build:enterprise",
|
|
4278
|
+
edition: "enterprise"
|
|
4279
|
+
},
|
|
4280
|
+
{
|
|
4281
|
+
name: "envsync-landing-static",
|
|
4282
|
+
image: config.images.landing,
|
|
4283
|
+
build_target: "apps/envsync-landing#build",
|
|
4284
|
+
edition: "enterprise"
|
|
4285
|
+
}
|
|
4286
|
+
);
|
|
4287
|
+
} else {
|
|
4288
|
+
container_images.push({
|
|
4289
|
+
name: "envsync-web-oss-static",
|
|
4290
|
+
image: config.images.web,
|
|
4291
|
+
build_target: "apps/envsync-web#build:oss",
|
|
4292
|
+
edition: "oss"
|
|
4293
|
+
});
|
|
4294
|
+
}
|
|
4295
|
+
return {
|
|
4296
|
+
npm_packages: npmPackages,
|
|
4297
|
+
container_images
|
|
4298
|
+
};
|
|
4299
|
+
}
|
|
4300
|
+
function createDeploymentPlan(rawConfig, forcedEdition) {
|
|
4301
|
+
const config = deployConfigSchema.parse(rawConfig);
|
|
4302
|
+
const edition = forcedEdition ?? config.edition ?? "oss";
|
|
4303
|
+
validateEditionRules(config, edition);
|
|
4304
|
+
const warnings = [];
|
|
4305
|
+
if (edition === "oss" && (config.observability.enabled ?? false) === false) {
|
|
4306
|
+
warnings.push("Observability is disabled for OSS. ClickStack and OTEL services will be omitted.");
|
|
4307
|
+
}
|
|
4308
|
+
if (edition === "enterprise" && !config.license.key) {
|
|
4309
|
+
warnings.push("Enterprise topology is valid, but license.key is empty. Activation will fail until a real key is supplied.");
|
|
4310
|
+
}
|
|
4311
|
+
return {
|
|
4312
|
+
edition,
|
|
4313
|
+
config,
|
|
4314
|
+
services: buildServicePlans(config, edition),
|
|
4315
|
+
frontend: buildFrontendArtifacts(config, edition),
|
|
4316
|
+
runtime_env: buildRuntimeEnv(config, edition),
|
|
4317
|
+
release_artifacts: buildReleaseArtifacts(config, edition),
|
|
4318
|
+
warnings
|
|
4319
|
+
};
|
|
4320
|
+
}
|
|
4321
|
+
function loadDeploymentPlanFromFile(filePath, forcedEdition) {
|
|
4322
|
+
return createDeploymentPlan(readDeployConfigFile(filePath), forcedEdition);
|
|
4323
|
+
}
|
|
4324
|
+
function formatDeploymentPlan(plan, format = "yaml") {
|
|
4325
|
+
if (format === "json") {
|
|
4326
|
+
return JSON.stringify(plan, null, 2);
|
|
4327
|
+
}
|
|
4328
|
+
return YAML.stringify(plan);
|
|
4329
|
+
}
|
|
12
4330
|
|
|
13
4331
|
// src/render.ts
|
|
14
4332
|
function domainMap(rootDomain) {
|
|
@@ -75,7 +4393,7 @@ function createSteadyApiDeploymentState(config, generated) {
|
|
|
75
4393
|
}
|
|
76
4394
|
};
|
|
77
4395
|
}
|
|
78
|
-
function
|
|
4396
|
+
function buildRuntimeEnv2(config, generated) {
|
|
79
4397
|
const hosts = domainMap(config.domain.root_domain);
|
|
80
4398
|
const bucketName = "envsync-bucket";
|
|
81
4399
|
const oss = isOssConfig(config);
|
|
@@ -753,32 +5071,32 @@ ${landingEnabled ? ` nginx_landing_conf:
|
|
|
753
5071
|
}
|
|
754
5072
|
|
|
755
5073
|
// src/static-bundle.ts
|
|
756
|
-
import
|
|
757
|
-
import
|
|
5074
|
+
import fs2 from "fs";
|
|
5075
|
+
import path2 from "path";
|
|
758
5076
|
function exists(target) {
|
|
759
|
-
return
|
|
5077
|
+
return fs2.existsSync(target);
|
|
760
5078
|
}
|
|
761
5079
|
function normalizeExtractedStaticBundle(kind, targetDir) {
|
|
762
|
-
const directIndex =
|
|
5080
|
+
const directIndex = path2.join(targetDir, "index.html");
|
|
763
5081
|
if (exists(directIndex)) {
|
|
764
5082
|
return;
|
|
765
5083
|
}
|
|
766
|
-
const childDirs =
|
|
767
|
-
const candidateRoots = childDirs.filter((dir) => exists(
|
|
5084
|
+
const childDirs = fs2.readdirSync(targetDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => path2.join(targetDir, entry.name));
|
|
5085
|
+
const candidateRoots = childDirs.filter((dir) => exists(path2.join(dir, "index.html")));
|
|
768
5086
|
if (candidateRoots.length !== 1) {
|
|
769
5087
|
return;
|
|
770
5088
|
}
|
|
771
5089
|
const nestedRoot = candidateRoots[0];
|
|
772
|
-
for (const entry of
|
|
773
|
-
|
|
5090
|
+
for (const entry of fs2.readdirSync(nestedRoot)) {
|
|
5091
|
+
fs2.cpSync(path2.join(nestedRoot, entry), path2.join(targetDir, entry), { recursive: true });
|
|
774
5092
|
}
|
|
775
|
-
|
|
5093
|
+
fs2.rmSync(nestedRoot, { recursive: true, force: true });
|
|
776
5094
|
}
|
|
777
5095
|
function validateStaticBundle(kind, targetDir) {
|
|
778
|
-
if (exists(
|
|
5096
|
+
if (exists(path2.join(targetDir, "index.html"))) {
|
|
779
5097
|
return;
|
|
780
5098
|
}
|
|
781
|
-
const entries = exists(targetDir) ?
|
|
5099
|
+
const entries = exists(targetDir) ? fs2.readdirSync(targetDir).slice(0, 20).join(", ") : "";
|
|
782
5100
|
throw new Error(
|
|
783
5101
|
`Invalid ${kind} static bundle at ${targetDir}: missing index.html${entries ? `. Found: ${entries}` : ""}`
|
|
784
5102
|
);
|
|
@@ -788,30 +5106,30 @@ function validateStaticBundle(kind, targetDir) {
|
|
|
788
5106
|
var HOST_ROOT = process.env.ENVSYNC_HOST_ROOT ?? "/opt/envsync";
|
|
789
5107
|
var ETC_ROOT = process.env.ENVSYNC_ETC_ROOT ?? "/etc/envsync";
|
|
790
5108
|
var TRAEFIK_STATE_ROOT = process.env.ENVSYNC_TRAEFIK_STATE_ROOT ?? "/var/lib/envsync/traefik";
|
|
791
|
-
var DEPLOY_ROOT =
|
|
792
|
-
var RELEASES_ROOT =
|
|
793
|
-
var BACKUPS_ROOT =
|
|
794
|
-
var REPO_ROOT = process.env.ENVSYNC_REPO_ROOT ??
|
|
795
|
-
var DEPLOY_ENV =
|
|
796
|
-
var DEPLOY_YAML =
|
|
797
|
-
var LICENSE_ROOT =
|
|
798
|
-
var LICENSE_BUNDLE_FILE =
|
|
799
|
-
var LICENSE_CERT_FILE =
|
|
800
|
-
var LICENSE_KEY_FILE =
|
|
801
|
-
var LICENSE_ROOT_CA_FILE =
|
|
802
|
-
var VERSIONS_LOCK =
|
|
803
|
-
var STACK_FILE =
|
|
804
|
-
var BOOTSTRAP_BASE_STACK_FILE =
|
|
805
|
-
var BOOTSTRAP_STACK_FILE =
|
|
806
|
-
var TRAEFIK_DYNAMIC_FILE =
|
|
807
|
-
var KEYCLOAK_REALM_FILE =
|
|
808
|
-
var NGINX_WEB_CONF =
|
|
809
|
-
var NGINX_LANDING_CONF =
|
|
810
|
-
var NGINX_API_MAINTENANCE_CONF =
|
|
811
|
-
var OTEL_AGENT_CONF =
|
|
812
|
-
var CLICKSTACK_CLICKHOUSE_CONF =
|
|
813
|
-
var INTERNAL_CONFIG_JSON =
|
|
814
|
-
var UPGRADE_BACKUPS_ROOT =
|
|
5109
|
+
var DEPLOY_ROOT = path3.join(HOST_ROOT, "deploy");
|
|
5110
|
+
var RELEASES_ROOT = path3.join(HOST_ROOT, "releases");
|
|
5111
|
+
var BACKUPS_ROOT = path3.join(HOST_ROOT, "backups");
|
|
5112
|
+
var REPO_ROOT = process.env.ENVSYNC_REPO_ROOT ?? path3.join(HOST_ROOT, "repo");
|
|
5113
|
+
var DEPLOY_ENV = path3.join(ETC_ROOT, "deploy.env");
|
|
5114
|
+
var DEPLOY_YAML = path3.join(ETC_ROOT, "deploy.yaml");
|
|
5115
|
+
var LICENSE_ROOT = path3.join(ETC_ROOT, "license");
|
|
5116
|
+
var LICENSE_BUNDLE_FILE = path3.join(LICENSE_ROOT, "enterprise-license-bundle.json");
|
|
5117
|
+
var LICENSE_CERT_FILE = path3.join(LICENSE_ROOT, "enterprise-cert.pem");
|
|
5118
|
+
var LICENSE_KEY_FILE = path3.join(LICENSE_ROOT, "enterprise-key.pem");
|
|
5119
|
+
var LICENSE_ROOT_CA_FILE = path3.join(LICENSE_ROOT, "root-ca.pem");
|
|
5120
|
+
var VERSIONS_LOCK = path3.join(DEPLOY_ROOT, "versions.lock.json");
|
|
5121
|
+
var STACK_FILE = path3.join(DEPLOY_ROOT, "docker-stack.yaml");
|
|
5122
|
+
var BOOTSTRAP_BASE_STACK_FILE = path3.join(DEPLOY_ROOT, "docker-stack.bootstrap.base.yaml");
|
|
5123
|
+
var BOOTSTRAP_STACK_FILE = path3.join(DEPLOY_ROOT, "docker-stack.bootstrap.yaml");
|
|
5124
|
+
var TRAEFIK_DYNAMIC_FILE = path3.join(DEPLOY_ROOT, "traefik-dynamic.yaml");
|
|
5125
|
+
var KEYCLOAK_REALM_FILE = path3.join(DEPLOY_ROOT, "keycloak-realm.envsync.json");
|
|
5126
|
+
var NGINX_WEB_CONF = path3.join(DEPLOY_ROOT, "nginx-web.conf");
|
|
5127
|
+
var NGINX_LANDING_CONF = path3.join(DEPLOY_ROOT, "nginx-landing.conf");
|
|
5128
|
+
var NGINX_API_MAINTENANCE_CONF = path3.join(DEPLOY_ROOT, "nginx-api-maintenance.conf");
|
|
5129
|
+
var OTEL_AGENT_CONF = path3.join(DEPLOY_ROOT, "otel-agent.yaml");
|
|
5130
|
+
var CLICKSTACK_CLICKHOUSE_CONF = path3.join(DEPLOY_ROOT, "clickhouse-listen.xml");
|
|
5131
|
+
var INTERNAL_CONFIG_JSON = path3.join(DEPLOY_ROOT, "config.json");
|
|
5132
|
+
var UPGRADE_BACKUPS_ROOT = path3.join(BACKUPS_ROOT, "upgrade");
|
|
815
5133
|
var DEPLOY_RENDER_PATHS = {
|
|
816
5134
|
traefikStateRoot: TRAEFIK_STATE_ROOT,
|
|
817
5135
|
deployRoot: DEPLOY_ROOT,
|
|
@@ -823,6 +5141,33 @@ var DEPLOY_RENDER_PATHS = {
|
|
|
823
5141
|
nginxWebConf: NGINX_WEB_CONF,
|
|
824
5142
|
nginxApiMaintenanceConf: NGINX_API_MAINTENANCE_CONF
|
|
825
5143
|
};
|
|
5144
|
+
var REMOVE_TARGETS = [
|
|
5145
|
+
DEPLOY_ROOT,
|
|
5146
|
+
RELEASES_ROOT,
|
|
5147
|
+
BACKUPS_ROOT,
|
|
5148
|
+
TRAEFIK_STATE_ROOT,
|
|
5149
|
+
REPO_ROOT,
|
|
5150
|
+
DEPLOY_ENV,
|
|
5151
|
+
DEPLOY_YAML,
|
|
5152
|
+
LICENSE_ROOT,
|
|
5153
|
+
LICENSE_BUNDLE_FILE,
|
|
5154
|
+
LICENSE_CERT_FILE,
|
|
5155
|
+
LICENSE_KEY_FILE,
|
|
5156
|
+
LICENSE_ROOT_CA_FILE,
|
|
5157
|
+
INTERNAL_CONFIG_JSON,
|
|
5158
|
+
VERSIONS_LOCK,
|
|
5159
|
+
STACK_FILE,
|
|
5160
|
+
BOOTSTRAP_BASE_STACK_FILE,
|
|
5161
|
+
BOOTSTRAP_STACK_FILE,
|
|
5162
|
+
TRAEFIK_DYNAMIC_FILE,
|
|
5163
|
+
KEYCLOAK_REALM_FILE,
|
|
5164
|
+
NGINX_WEB_CONF,
|
|
5165
|
+
NGINX_LANDING_CONF,
|
|
5166
|
+
NGINX_API_MAINTENANCE_CONF,
|
|
5167
|
+
OTEL_AGENT_CONF,
|
|
5168
|
+
CLICKSTACK_CLICKHOUSE_CONF
|
|
5169
|
+
];
|
|
5170
|
+
var REMOVE_CONFIRMATION_TOKEN = "YES, DO IT";
|
|
826
5171
|
var STACK_VOLUMES = [
|
|
827
5172
|
"postgres_data",
|
|
828
5173
|
"redis_data",
|
|
@@ -974,12 +5319,12 @@ ${typeof result.stderr === "string" ? result.stderr : ""}`.toLowerCase();
|
|
|
974
5319
|
${stderr}` : ""}`);
|
|
975
5320
|
}
|
|
976
5321
|
function ensureDir(dir) {
|
|
977
|
-
|
|
5322
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
978
5323
|
}
|
|
979
5324
|
function writeFile(target, content, mode) {
|
|
980
|
-
ensureDir(
|
|
981
|
-
|
|
982
|
-
if (mode != null)
|
|
5325
|
+
ensureDir(path3.dirname(target));
|
|
5326
|
+
fs3.writeFileSync(target, content, "utf8");
|
|
5327
|
+
if (mode != null) fs3.chmodSync(target, mode);
|
|
983
5328
|
}
|
|
984
5329
|
function writeFileMaybe(target, content, mode) {
|
|
985
5330
|
if (currentOptions.dryRun) {
|
|
@@ -989,7 +5334,7 @@ function writeFileMaybe(target, content, mode) {
|
|
|
989
5334
|
writeFile(target, content, mode);
|
|
990
5335
|
}
|
|
991
5336
|
function exists2(target) {
|
|
992
|
-
return
|
|
5337
|
+
return fs3.existsSync(target);
|
|
993
5338
|
}
|
|
994
5339
|
function randomSecret(bytes = 24) {
|
|
995
5340
|
return randomBytes(bytes).toString("hex");
|
|
@@ -1022,12 +5367,12 @@ function otherApiSlot(slot) {
|
|
|
1022
5367
|
return slot === "blue" ? "green" : "blue";
|
|
1023
5368
|
}
|
|
1024
5369
|
function toYaml(value, indent = 0) {
|
|
1025
|
-
return
|
|
5370
|
+
return YAML2.stringify(value, {
|
|
1026
5371
|
indent: Math.max(2, indent || 2)
|
|
1027
5372
|
});
|
|
1028
5373
|
}
|
|
1029
5374
|
function parseSimpleYamlObject(input) {
|
|
1030
|
-
const parsed =
|
|
5375
|
+
const parsed = YAML2.parse(input);
|
|
1031
5376
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1032
5377
|
throw new Error(`Invalid deploy config in ${DEPLOY_YAML}. Expected a YAML object at the document root.`);
|
|
1033
5378
|
}
|
|
@@ -1059,9 +5404,9 @@ async function ask(question, fallback = "") {
|
|
|
1059
5404
|
});
|
|
1060
5405
|
});
|
|
1061
5406
|
}
|
|
1062
|
-
async function askRequired(question) {
|
|
5407
|
+
async function askRequired(question, context = "Operation") {
|
|
1063
5408
|
if (!process.stdin.isTTY) {
|
|
1064
|
-
throw new Error(
|
|
5409
|
+
throw new Error(`${context} confirmation requires an interactive terminal. Re-run with --force to bypass the prompt.`);
|
|
1065
5410
|
}
|
|
1066
5411
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1067
5412
|
return await new Promise((resolve) => {
|
|
@@ -1089,13 +5434,13 @@ function domainMap2(rootDomain) {
|
|
|
1089
5434
|
function publicHttpsOrigin2(config, host) {
|
|
1090
5435
|
return `https://${host}${config.services.public_https_port === 443 ? "" : `:${config.services.public_https_port}`}`;
|
|
1091
5436
|
}
|
|
1092
|
-
function publicHttpsUrl2(config, host,
|
|
1093
|
-
return `${publicHttpsOrigin2(config, host)}${
|
|
5437
|
+
function publicHttpsUrl2(config, host, path4 = "") {
|
|
5438
|
+
return `${publicHttpsOrigin2(config, host)}${path4}`;
|
|
1094
5439
|
}
|
|
1095
5440
|
function getDeployCliVersion() {
|
|
1096
5441
|
try {
|
|
1097
5442
|
const packageJsonPath = new URL("../package.json", import.meta.url);
|
|
1098
|
-
const raw =
|
|
5443
|
+
const raw = fs3.readFileSync(packageJsonPath, "utf8");
|
|
1099
5444
|
return JSON.parse(raw).version ?? "0.0.0";
|
|
1100
5445
|
} catch {
|
|
1101
5446
|
return process.env.npm_package_version ?? "0.0.0";
|
|
@@ -1125,6 +5470,7 @@ function renderHelpBlock() {
|
|
|
1125
5470
|
" preinstall Prepare the host with Docker, Swarm, and required packages",
|
|
1126
5471
|
" setup Write /etc/envsync/deploy.yaml for a new self-hosted install",
|
|
1127
5472
|
" bootstrap Destructively rebuild managed infra and bootstrap runtime state",
|
|
5473
|
+
" remove Remove local self-hosted deployment files and runtime resources",
|
|
1128
5474
|
" deploy Deploy the configured release",
|
|
1129
5475
|
" promote [blue|green] Promote the requested or inactive API slot",
|
|
1130
5476
|
" rollback Switch traffic back to the previous API slot",
|
|
@@ -1208,6 +5554,7 @@ function printOperatorOverview() {
|
|
|
1208
5554
|
const overview = buildOperatorOverview();
|
|
1209
5555
|
const commonCommands = [
|
|
1210
5556
|
"`envsync-deploy setup`",
|
|
5557
|
+
"`envsync-deploy remove --force`",
|
|
1211
5558
|
"`envsync-deploy bootstrap --force`",
|
|
1212
5559
|
"`envsync-deploy deploy`",
|
|
1213
5560
|
"`envsync-deploy upgrade`",
|
|
@@ -1459,7 +5806,7 @@ function normalizeGeneratedState(raw) {
|
|
|
1459
5806
|
}
|
|
1460
5807
|
function readInternalState() {
|
|
1461
5808
|
if (!exists2(INTERNAL_CONFIG_JSON)) return null;
|
|
1462
|
-
const raw = JSON.parse(
|
|
5809
|
+
const raw = JSON.parse(fs3.readFileSync(INTERNAL_CONFIG_JSON, "utf8"));
|
|
1463
5810
|
return {
|
|
1464
5811
|
config: raw.config ? normalizeConfig(raw.config) : void 0,
|
|
1465
5812
|
generated: normalizeGeneratedState(raw.generated)
|
|
@@ -1469,7 +5816,7 @@ function loadConfig() {
|
|
|
1469
5816
|
if (!exists2(DEPLOY_YAML)) {
|
|
1470
5817
|
throw new Error(`Missing deploy config at ${DEPLOY_YAML}. Run setup first.`);
|
|
1471
5818
|
}
|
|
1472
|
-
const raw =
|
|
5819
|
+
const raw = fs3.readFileSync(DEPLOY_YAML, "utf8");
|
|
1473
5820
|
if (raw.trimStart().startsWith("{")) {
|
|
1474
5821
|
return normalizeConfig(JSON.parse(raw));
|
|
1475
5822
|
}
|
|
@@ -1477,7 +5824,7 @@ function loadConfig() {
|
|
|
1477
5824
|
}
|
|
1478
5825
|
function loadGeneratedEnv() {
|
|
1479
5826
|
if (!exists2(DEPLOY_ENV)) return {};
|
|
1480
|
-
return parseEnvFile(
|
|
5827
|
+
return parseEnvFile(fs3.readFileSync(DEPLOY_ENV, "utf8"));
|
|
1481
5828
|
}
|
|
1482
5829
|
function mergeGeneratedState(env, generated) {
|
|
1483
5830
|
const normalized = normalizeGeneratedState(generated);
|
|
@@ -1686,7 +6033,7 @@ function touchApiSlotDeployment(deployment, slot) {
|
|
|
1686
6033
|
};
|
|
1687
6034
|
}
|
|
1688
6035
|
function writeDeployArtifacts(config, generated) {
|
|
1689
|
-
const runtimeEnv =
|
|
6036
|
+
const runtimeEnv = buildRuntimeEnv2(config, generated);
|
|
1690
6037
|
logStep("Rendering deploy artifacts");
|
|
1691
6038
|
writeFileMaybe(DEPLOY_ENV, renderEnvFile(runtimeEnv), 384);
|
|
1692
6039
|
writeFileMaybe(
|
|
@@ -1726,7 +6073,7 @@ function ensureRepoCheckout(config) {
|
|
|
1726
6073
|
return;
|
|
1727
6074
|
}
|
|
1728
6075
|
if (hasExplicitRepoOverride()) {
|
|
1729
|
-
if (!exists2(
|
|
6076
|
+
if (!exists2(path3.join(REPO_ROOT, ".git"))) {
|
|
1730
6077
|
throw new Error(`ENVSYNC_REPO_ROOT is set but no git repo was found at ${REPO_ROOT}`);
|
|
1731
6078
|
}
|
|
1732
6079
|
logInfo(`Using local repo override at ${REPO_ROOT}`);
|
|
@@ -1734,7 +6081,7 @@ function ensureRepoCheckout(config) {
|
|
|
1734
6081
|
return;
|
|
1735
6082
|
}
|
|
1736
6083
|
ensureDir(REPO_ROOT);
|
|
1737
|
-
if (!exists2(
|
|
6084
|
+
if (!exists2(path3.join(REPO_ROOT, ".git"))) {
|
|
1738
6085
|
logCommand("git", ["clone", config.source.repo_url, REPO_ROOT]);
|
|
1739
6086
|
run("git", ["clone", config.source.repo_url, REPO_ROOT]);
|
|
1740
6087
|
}
|
|
@@ -1752,7 +6099,7 @@ function extractStaticBundle(kind, image, targetDir) {
|
|
|
1752
6099
|
logDryRun(`Would extract ${kind} bundle from ${image} into ${targetDir}`);
|
|
1753
6100
|
return;
|
|
1754
6101
|
}
|
|
1755
|
-
|
|
6102
|
+
fs3.rmSync(targetDir, { recursive: true, force: true });
|
|
1756
6103
|
ensureDir(targetDir);
|
|
1757
6104
|
const containerId = run("docker", ["create", image], { quiet: true }).trim();
|
|
1758
6105
|
try {
|
|
@@ -1765,38 +6112,38 @@ function extractStaticBundle(kind, image, targetDir) {
|
|
|
1765
6112
|
logSuccess(`${kind} static bundle extracted to ${targetDir}`);
|
|
1766
6113
|
}
|
|
1767
6114
|
function releaseAssetDir(kind, version) {
|
|
1768
|
-
return
|
|
6115
|
+
return path3.join(RELEASES_ROOT, kind, version);
|
|
1769
6116
|
}
|
|
1770
6117
|
function currentReleaseDir(kind) {
|
|
1771
|
-
return
|
|
6118
|
+
return path3.join(RELEASES_ROOT, kind, "current");
|
|
1772
6119
|
}
|
|
1773
6120
|
function stageFrontendRelease(kind, image, version) {
|
|
1774
6121
|
const targetDir = releaseAssetDir(kind, version);
|
|
1775
6122
|
extractStaticBundle(kind, image, targetDir);
|
|
1776
6123
|
}
|
|
1777
6124
|
function writeFrontendRuntimeConfig(targetDir, runtimeConfig) {
|
|
1778
|
-
writeFile(
|
|
6125
|
+
writeFile(path3.join(targetDir, "runtime-config.js"), runtimeConfig);
|
|
1779
6126
|
}
|
|
1780
6127
|
function syncFrontendReleaseContents(sourceDir, targetDir) {
|
|
1781
6128
|
ensureDir(targetDir);
|
|
1782
6129
|
const deferredEntries = /* @__PURE__ */ new Set(["index.html", "runtime-config.js"]);
|
|
1783
|
-
const entries =
|
|
6130
|
+
const entries = fs3.readdirSync(sourceDir, { withFileTypes: true });
|
|
1784
6131
|
for (const entry of entries) {
|
|
1785
6132
|
if (deferredEntries.has(entry.name)) {
|
|
1786
6133
|
continue;
|
|
1787
6134
|
}
|
|
1788
|
-
|
|
6135
|
+
fs3.cpSync(path3.join(sourceDir, entry.name), path3.join(targetDir, entry.name), {
|
|
1789
6136
|
recursive: true,
|
|
1790
6137
|
force: true
|
|
1791
6138
|
});
|
|
1792
6139
|
}
|
|
1793
|
-
const stagedRuntimeConfig =
|
|
6140
|
+
const stagedRuntimeConfig = path3.join(sourceDir, "runtime-config.js");
|
|
1794
6141
|
if (exists2(stagedRuntimeConfig)) {
|
|
1795
|
-
|
|
6142
|
+
fs3.cpSync(stagedRuntimeConfig, path3.join(targetDir, "runtime-config.js"), { force: true });
|
|
1796
6143
|
}
|
|
1797
|
-
const stagedIndex =
|
|
6144
|
+
const stagedIndex = path3.join(sourceDir, "index.html");
|
|
1798
6145
|
if (exists2(stagedIndex)) {
|
|
1799
|
-
|
|
6146
|
+
fs3.cpSync(stagedIndex, path3.join(targetDir, "index.html"), { force: true });
|
|
1800
6147
|
}
|
|
1801
6148
|
}
|
|
1802
6149
|
function activateFrontendRelease(kind, version, runtimeConfig) {
|
|
@@ -1819,7 +6166,7 @@ function activateFrontendRelease(kind, version, runtimeConfig) {
|
|
|
1819
6166
|
function createApiDbUpgradeBackup(config, fromVersion, toVersion) {
|
|
1820
6167
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:]/g, "-");
|
|
1821
6168
|
const fileName = `envsync-db-preupgrade-${fromVersion || "unknown"}-to-${toVersion}-${timestamp}.dump`;
|
|
1822
|
-
const hostPath =
|
|
6169
|
+
const hostPath = path3.join(UPGRADE_BACKUPS_ROOT, fileName);
|
|
1823
6170
|
logStep(`Creating API DB upgrade snapshot ${fileName}`);
|
|
1824
6171
|
if (currentOptions.dryRun) {
|
|
1825
6172
|
logDryRun(`Would create upgrade DB snapshot at ${hostPath}`);
|
|
@@ -1844,7 +6191,7 @@ function createApiDbUpgradeBackup(config, fromVersion, toVersion) {
|
|
|
1844
6191
|
return hostPath;
|
|
1845
6192
|
}
|
|
1846
6193
|
function restoreApiDbUpgradeBackup(config, backupPath) {
|
|
1847
|
-
const fileName =
|
|
6194
|
+
const fileName = path3.basename(backupPath);
|
|
1848
6195
|
logWarn(`Restoring API DB upgrade snapshot ${fileName}`);
|
|
1849
6196
|
if (currentOptions.dryRun) {
|
|
1850
6197
|
logDryRun(`Would restore upgrade DB snapshot from ${backupPath}`);
|
|
@@ -1874,8 +6221,8 @@ function activateFrontendReleaseForState(config, state, fallbackVersion = config
|
|
|
1874
6221
|
}
|
|
1875
6222
|
}
|
|
1876
6223
|
function buildKeycloakImage(imageTag, repoRoot = REPO_ROOT) {
|
|
1877
|
-
const buildContext =
|
|
1878
|
-
if (!exists2(
|
|
6224
|
+
const buildContext = path3.join(repoRoot, "packages/envsync-keycloak-theme");
|
|
6225
|
+
if (!exists2(path3.join(buildContext, "Dockerfile"))) {
|
|
1879
6226
|
throw new Error(`Missing Keycloak Docker build context at ${buildContext}`);
|
|
1880
6227
|
}
|
|
1881
6228
|
logStep(`Building Keycloak image ${imageTag}`);
|
|
@@ -2016,7 +6363,7 @@ function runMiniKmsMigrate(config, runtimeEnv) {
|
|
|
2016
6363
|
"-e",
|
|
2017
6364
|
`PGPASSWORD=${runtimeEnv.MINIKMS_DB_PASSWORD}`,
|
|
2018
6365
|
"-v",
|
|
2019
|
-
`${
|
|
6366
|
+
`${path3.join(REPO_ROOT, "docker/minikms/migrations")}:/migrations:ro`,
|
|
2020
6367
|
"postgres:17",
|
|
2021
6368
|
"sh",
|
|
2022
6369
|
"-lc",
|
|
@@ -2032,7 +6379,7 @@ function runMiniKmsMigrate(config, runtimeEnv) {
|
|
|
2032
6379
|
"-e",
|
|
2033
6380
|
`PGPASSWORD=${runtimeEnv.MINIKMS_DB_PASSWORD}`,
|
|
2034
6381
|
"-v",
|
|
2035
|
-
`${
|
|
6382
|
+
`${path3.join(REPO_ROOT, "docker/minikms/migrations")}:/migrations:ro`,
|
|
2036
6383
|
"postgres:17",
|
|
2037
6384
|
"sh",
|
|
2038
6385
|
"-lc",
|
|
@@ -2125,7 +6472,7 @@ function runClickstackBootstrap(config) {
|
|
|
2125
6472
|
const { generated } = loadState();
|
|
2126
6473
|
if (currentOptions.dryRun) {
|
|
2127
6474
|
logDryRun("Would bootstrap ClickStack sources and dashboards");
|
|
2128
|
-
logCommand("node", [
|
|
6475
|
+
logCommand("node", [path3.join(REPO_ROOT, "scripts/bootstrap-clickstack-selfhost.mjs")]);
|
|
2129
6476
|
return {
|
|
2130
6477
|
browserApiKey: generated.clickstack.browser_api_key
|
|
2131
6478
|
};
|
|
@@ -2134,7 +6481,7 @@ function runClickstackBootstrap(config) {
|
|
|
2134
6481
|
let lastError = "unknown error";
|
|
2135
6482
|
while (Date.now() < deadline) {
|
|
2136
6483
|
try {
|
|
2137
|
-
const output = run("node", [
|
|
6484
|
+
const output = run("node", [path3.join(REPO_ROOT, "scripts/bootstrap-clickstack-selfhost.mjs")], {
|
|
2138
6485
|
env: {
|
|
2139
6486
|
ENVSYNC_STACK_NAME: config.services.stack_name,
|
|
2140
6487
|
ENVSYNC_ROOT_DOMAIN: config.domain.root_domain,
|
|
@@ -2192,7 +6539,7 @@ ${trimmed}`
|
|
|
2192
6539
|
}
|
|
2193
6540
|
function readRenderedRuntimeConfig(filePath) {
|
|
2194
6541
|
if (!exists2(filePath)) return null;
|
|
2195
|
-
const raw =
|
|
6542
|
+
const raw = fs3.readFileSync(filePath, "utf8").trim();
|
|
2196
6543
|
const prefix = "window.__ENVSYNC_RUNTIME_CONFIG__ = ";
|
|
2197
6544
|
if (!raw.startsWith(prefix) || !raw.endsWith(";")) return null;
|
|
2198
6545
|
try {
|
|
@@ -2439,12 +6786,67 @@ async function confirmBootstrapReset(config) {
|
|
|
2439
6786
|
logSuccess("Destructive bootstrap reset confirmed");
|
|
2440
6787
|
return;
|
|
2441
6788
|
}
|
|
2442
|
-
const response = await askRequired(chalk.bold.red('Type "yes" to continue:'));
|
|
6789
|
+
const response = await askRequired(chalk.bold.red('Type "yes" to continue:'), "Bootstrap");
|
|
2443
6790
|
if (response !== "yes") {
|
|
2444
6791
|
throw new Error("Bootstrap aborted. Confirmation did not match 'yes'.");
|
|
2445
6792
|
}
|
|
2446
6793
|
logSuccess("Destructive bootstrap reset confirmed");
|
|
2447
6794
|
}
|
|
6795
|
+
function loadConfigForCleanup() {
|
|
6796
|
+
if (!exists2(DEPLOY_YAML)) {
|
|
6797
|
+
logWarn(`No deploy config found at ${DEPLOY_YAML}; managed runtime cleanup will be skipped.`);
|
|
6798
|
+
return null;
|
|
6799
|
+
}
|
|
6800
|
+
try {
|
|
6801
|
+
return loadConfig();
|
|
6802
|
+
} catch (error) {
|
|
6803
|
+
logWarn(`Deploy config at ${DEPLOY_YAML} is unreadable and managed runtime cleanup will be skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
6804
|
+
return null;
|
|
6805
|
+
}
|
|
6806
|
+
}
|
|
6807
|
+
async function confirmRemove(config) {
|
|
6808
|
+
logWarn("Remove will delete local EnvSync deployment artifacts and managed Docker resources.");
|
|
6809
|
+
logWarn(`Targets: ${REMOVE_TARGETS.join(", ")}`);
|
|
6810
|
+
if (config) {
|
|
6811
|
+
const stackName = config.services.stack_name;
|
|
6812
|
+
const networkName = stackNetworkName(config);
|
|
6813
|
+
const volumeNames = STACK_VOLUMES.map((volume) => stackVolumeName(config, volume));
|
|
6814
|
+
logWarn(`Stack: ${stackName}`);
|
|
6815
|
+
logWarn(`Network: ${networkName}`);
|
|
6816
|
+
logWarn(`Volumes: ${volumeNames.join(", ")}`);
|
|
6817
|
+
}
|
|
6818
|
+
if (currentOptions.force) {
|
|
6819
|
+
logWarn("Skipping confirmation because --force was provided.");
|
|
6820
|
+
logSuccess("Destructive remove confirmed");
|
|
6821
|
+
return;
|
|
6822
|
+
}
|
|
6823
|
+
const response = await askRequired(chalk.bold.red(`Type "${REMOVE_CONFIRMATION_TOKEN}" to continue:`), "Remove");
|
|
6824
|
+
if (response !== REMOVE_CONFIRMATION_TOKEN) {
|
|
6825
|
+
throw new Error(`Remove aborted. Confirmation did not match '${REMOVE_CONFIRMATION_TOKEN}'.`);
|
|
6826
|
+
}
|
|
6827
|
+
logSuccess("Destructive remove confirmed");
|
|
6828
|
+
}
|
|
6829
|
+
function removeTarget(target) {
|
|
6830
|
+
if (!exists2(target)) return;
|
|
6831
|
+
if (currentOptions.dryRun) {
|
|
6832
|
+
logDryRun(`Would remove ${target}`);
|
|
6833
|
+
return;
|
|
6834
|
+
}
|
|
6835
|
+
fs3.rmSync(target, { recursive: true, force: true });
|
|
6836
|
+
logInfo(`Removed ${target}`);
|
|
6837
|
+
}
|
|
6838
|
+
async function cmdRemove() {
|
|
6839
|
+
logSection("Remove");
|
|
6840
|
+
const config = loadConfigForCleanup();
|
|
6841
|
+
await confirmRemove(config);
|
|
6842
|
+
if (config) {
|
|
6843
|
+
cleanupBootstrapState(config);
|
|
6844
|
+
}
|
|
6845
|
+
for (const target of REMOVE_TARGETS) {
|
|
6846
|
+
removeTarget(target);
|
|
6847
|
+
}
|
|
6848
|
+
logSuccess("Remove completed");
|
|
6849
|
+
}
|
|
2448
6850
|
function cleanupBootstrapState(config) {
|
|
2449
6851
|
const volumeNames = STACK_VOLUMES.map((volume) => stackVolumeName(config, volume));
|
|
2450
6852
|
const containerIds = listManagedContainers(config);
|
|
@@ -2819,7 +7221,7 @@ async function cmdBootstrap() {
|
|
|
2819
7221
|
logSection("Bootstrap");
|
|
2820
7222
|
const { config, generated } = loadState();
|
|
2821
7223
|
const nextGenerated = ensureGeneratedRuntimeState(config, resetBootstrapGeneratedState(generated));
|
|
2822
|
-
const runtimeEnv =
|
|
7224
|
+
const runtimeEnv = buildRuntimeEnv2(config, nextGenerated);
|
|
2823
7225
|
logReleaseContext(config);
|
|
2824
7226
|
assertSwarmManager();
|
|
2825
7227
|
await ensureEnterpriseCertificateBundle(config);
|
|
@@ -2970,7 +7372,7 @@ async function cmdDeploy() {
|
|
|
2970
7372
|
sleepSeconds(3);
|
|
2971
7373
|
promoted = true;
|
|
2972
7374
|
if (snapshotPath && !currentOptions.dryRun) {
|
|
2973
|
-
|
|
7375
|
+
fs3.rmSync(snapshotPath, { force: true });
|
|
2974
7376
|
}
|
|
2975
7377
|
} catch (error) {
|
|
2976
7378
|
const rollbackTarget = preUpgradeHead ?? "zero";
|
|
@@ -2999,7 +7401,7 @@ ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)
|
|
|
2999
7401
|
deployRenderedStack(config, "rollback recovery");
|
|
3000
7402
|
waitForApiSlotHealthy(config, recoveredState.deployment.active_slot);
|
|
3001
7403
|
if (snapshotPath && !config.upgrade.keep_failed_upgrade_db_snapshot && !currentOptions.dryRun) {
|
|
3002
|
-
|
|
7404
|
+
fs3.rmSync(snapshotPath, { force: true });
|
|
3003
7405
|
}
|
|
3004
7406
|
throw new Error(
|
|
3005
7407
|
usedSnapshotRestore ? `Deploy failed after DB migration. Previous release was restored using DB snapshot recovery. ${error instanceof Error ? error.message : String(error)}` : `Deploy failed after DB migration. Previous release was restored. ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -3119,9 +7521,9 @@ async function cmdHealth(asJson) {
|
|
|
3119
7521
|
const hosts = domainMap2(config.domain.root_domain);
|
|
3120
7522
|
const services = listStackServices(config);
|
|
3121
7523
|
const stackName = config.services.stack_name;
|
|
3122
|
-
const traefikDynamic = exists2(TRAEFIK_DYNAMIC_FILE) ?
|
|
3123
|
-
const webRuntimeConfig = readRenderedRuntimeConfig(
|
|
3124
|
-
const landingRuntimeConfig = readRenderedRuntimeConfig(
|
|
7524
|
+
const traefikDynamic = exists2(TRAEFIK_DYNAMIC_FILE) ? fs3.readFileSync(TRAEFIK_DYNAMIC_FILE, "utf8") : "";
|
|
7525
|
+
const webRuntimeConfig = readRenderedRuntimeConfig(path3.join(RELEASES_ROOT, "web", "current", "runtime-config.js"));
|
|
7526
|
+
const landingRuntimeConfig = readRenderedRuntimeConfig(path3.join(RELEASES_ROOT, "landing", "current", "runtime-config.js"));
|
|
3125
7527
|
const clickstackSearchState = getClickstackSearchState(config);
|
|
3126
7528
|
const sourceNames = new Set(clickstackSearchState?.sourceNames ?? []);
|
|
3127
7529
|
const savedSearchNames = new Set((clickstackSearchState?.savedSearches ?? []).map((search) => search.name).filter(Boolean));
|
|
@@ -3281,7 +7683,7 @@ async function cmdUpgradeDeps() {
|
|
|
3281
7683
|
}
|
|
3282
7684
|
function sha256File(filePath) {
|
|
3283
7685
|
const hash = createHash("sha256");
|
|
3284
|
-
hash.update(
|
|
7686
|
+
hash.update(fs3.readFileSync(filePath));
|
|
3285
7687
|
return hash.digest("hex");
|
|
3286
7688
|
}
|
|
3287
7689
|
function parseEnterpriseLicenseBundle(raw) {
|
|
@@ -3310,7 +7712,7 @@ function parseEnterpriseLicenseBundle(raw) {
|
|
|
3310
7712
|
return candidate;
|
|
3311
7713
|
}
|
|
3312
7714
|
function readEnterpriseLicenseBundle(bundlePath) {
|
|
3313
|
-
return parseEnterpriseLicenseBundle(JSON.parse(
|
|
7715
|
+
return parseEnterpriseLicenseBundle(JSON.parse(fs3.readFileSync(bundlePath, "utf8")));
|
|
3314
7716
|
}
|
|
3315
7717
|
function normalizeLicenseServerUrl(serverUrl, route) {
|
|
3316
7718
|
const trimmed = serverUrl.replace(/\/+$/, "");
|
|
@@ -3528,10 +7930,10 @@ async function cmdBackup() {
|
|
|
3528
7930
|
logSection("Backup");
|
|
3529
7931
|
const { config } = loadState();
|
|
3530
7932
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:]/g, "-");
|
|
3531
|
-
const archiveBase =
|
|
7933
|
+
const archiveBase = path3.join(config.backup.output_dir, `envsync-backup-${timestamp}`);
|
|
3532
7934
|
const manifestPath = `${archiveBase}.manifest.json`;
|
|
3533
7935
|
const tarPath = `${archiveBase}.tar.gz`;
|
|
3534
|
-
const staged =
|
|
7936
|
+
const staged = path3.join(BACKUPS_ROOT, `staging-${timestamp}`);
|
|
3535
7937
|
logInfo(`Backup archive target: ${tarPath}`);
|
|
3536
7938
|
if (currentOptions.dryRun) {
|
|
3537
7939
|
logDryRun(`Would stage backup files in ${staged}`);
|
|
@@ -3541,7 +7943,7 @@ async function cmdBackup() {
|
|
|
3541
7943
|
logDryRun("Would redeploy the EnvSync stack after the backup archive is created");
|
|
3542
7944
|
}
|
|
3543
7945
|
for (const volume of STACK_VOLUMES) {
|
|
3544
|
-
backupDockerVolume(stackVolumeName(config, volume),
|
|
7946
|
+
backupDockerVolume(stackVolumeName(config, volume), path3.join(staged, "volumes", volume));
|
|
3545
7947
|
}
|
|
3546
7948
|
if (!isOssConfig2(config)) {
|
|
3547
7949
|
logDryRun(`Would include Enterprise license material from ${LICENSE_ROOT}`);
|
|
@@ -3562,27 +7964,27 @@ async function cmdBackup() {
|
|
|
3562
7964
|
logWarn("Backup will temporarily stop the EnvSync stack to capture consistent volume data.");
|
|
3563
7965
|
stopManagedRuntime(config, "Stopping existing EnvSync services for consistent backup");
|
|
3564
7966
|
}
|
|
3565
|
-
writeFile(
|
|
3566
|
-
writeFile(
|
|
3567
|
-
writeFile(
|
|
3568
|
-
writeFile(
|
|
3569
|
-
writeFile(
|
|
3570
|
-
writeFile(
|
|
3571
|
-
writeFile(
|
|
3572
|
-
writeFile(
|
|
3573
|
-
writeFile(
|
|
3574
|
-
writeFile(
|
|
3575
|
-
writeFile(
|
|
7967
|
+
writeFile(path3.join(staged, "deploy.env"), fs3.readFileSync(DEPLOY_ENV, "utf8"));
|
|
7968
|
+
writeFile(path3.join(staged, "deploy.yaml"), fs3.readFileSync(DEPLOY_YAML, "utf8"));
|
|
7969
|
+
writeFile(path3.join(staged, "config.json"), fs3.readFileSync(INTERNAL_CONFIG_JSON, "utf8"));
|
|
7970
|
+
writeFile(path3.join(staged, "versions.lock.json"), fs3.readFileSync(VERSIONS_LOCK, "utf8"));
|
|
7971
|
+
writeFile(path3.join(staged, "docker-stack.bootstrap.base.yaml"), fs3.readFileSync(BOOTSTRAP_BASE_STACK_FILE, "utf8"));
|
|
7972
|
+
writeFile(path3.join(staged, "docker-stack.bootstrap.yaml"), fs3.readFileSync(BOOTSTRAP_STACK_FILE, "utf8"));
|
|
7973
|
+
writeFile(path3.join(staged, "docker-stack.yaml"), fs3.readFileSync(STACK_FILE, "utf8"));
|
|
7974
|
+
writeFile(path3.join(staged, "traefik-dynamic.yaml"), fs3.readFileSync(TRAEFIK_DYNAMIC_FILE, "utf8"));
|
|
7975
|
+
writeFile(path3.join(staged, "keycloak-realm.envsync.json"), fs3.readFileSync(KEYCLOAK_REALM_FILE, "utf8"));
|
|
7976
|
+
writeFile(path3.join(staged, "otel-agent.yaml"), fs3.readFileSync(OTEL_AGENT_CONF, "utf8"));
|
|
7977
|
+
writeFile(path3.join(staged, "clickhouse-listen.xml"), fs3.readFileSync(CLICKSTACK_CLICKHOUSE_CONF, "utf8"));
|
|
3576
7978
|
if (!isOssConfig2(config) && exists2(LICENSE_ROOT)) {
|
|
3577
|
-
|
|
7979
|
+
fs3.cpSync(LICENSE_ROOT, path3.join(staged, "license"), { recursive: true });
|
|
3578
7980
|
}
|
|
3579
|
-
const volumesDir =
|
|
7981
|
+
const volumesDir = path3.join(staged, "volumes");
|
|
3580
7982
|
for (const volume of STACK_VOLUMES) {
|
|
3581
|
-
backupDockerVolume(stackVolumeName(config, volume),
|
|
7983
|
+
backupDockerVolume(stackVolumeName(config, volume), path3.join(volumesDir, volume));
|
|
3582
7984
|
}
|
|
3583
7985
|
run("bash", ["-lc", `tar -czf ${JSON.stringify(tarPath)} -C ${JSON.stringify(staged)} .`]);
|
|
3584
7986
|
const manifest = {
|
|
3585
|
-
archive:
|
|
7987
|
+
archive: path3.basename(tarPath),
|
|
3586
7988
|
sha256: sha256File(tarPath),
|
|
3587
7989
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3588
7990
|
stack_name: config.services.stack_name,
|
|
@@ -3622,7 +8024,7 @@ ${restartError instanceof Error ? restartError.message : String(restartError)}`
|
|
|
3622
8024
|
async function cmdRestore(archivePath, autoDeploy = false) {
|
|
3623
8025
|
if (!archivePath) throw new Error("restore requires a .tar.gz path");
|
|
3624
8026
|
logSection("Restore");
|
|
3625
|
-
const restoreRoot =
|
|
8027
|
+
const restoreRoot = path3.join(BACKUPS_ROOT, `restore-${Date.now()}`);
|
|
3626
8028
|
logInfo(`Restore archive: ${archivePath}`);
|
|
3627
8029
|
if (currentOptions.dryRun) {
|
|
3628
8030
|
logDryRun(`Would extract ${archivePath} into ${restoreRoot}`);
|
|
@@ -3641,25 +8043,25 @@ async function cmdRestore(archivePath, autoDeploy = false) {
|
|
|
3641
8043
|
}
|
|
3642
8044
|
ensureDir(restoreRoot);
|
|
3643
8045
|
run("bash", ["-lc", `tar -xzf ${JSON.stringify(archivePath)} -C ${JSON.stringify(restoreRoot)}`]);
|
|
3644
|
-
writeFile(DEPLOY_ENV,
|
|
3645
|
-
writeFile(DEPLOY_YAML,
|
|
3646
|
-
writeFile(INTERNAL_CONFIG_JSON,
|
|
3647
|
-
writeFile(VERSIONS_LOCK,
|
|
3648
|
-
writeFile(BOOTSTRAP_BASE_STACK_FILE,
|
|
3649
|
-
writeFile(BOOTSTRAP_STACK_FILE,
|
|
3650
|
-
writeFile(STACK_FILE,
|
|
3651
|
-
writeFile(TRAEFIK_DYNAMIC_FILE,
|
|
3652
|
-
writeFile(KEYCLOAK_REALM_FILE,
|
|
3653
|
-
writeFile(OTEL_AGENT_CONF,
|
|
3654
|
-
writeFile(CLICKSTACK_CLICKHOUSE_CONF,
|
|
3655
|
-
const restoredLicenseRoot =
|
|
8046
|
+
writeFile(DEPLOY_ENV, fs3.readFileSync(path3.join(restoreRoot, "deploy.env"), "utf8"), 384);
|
|
8047
|
+
writeFile(DEPLOY_YAML, fs3.readFileSync(path3.join(restoreRoot, "deploy.yaml"), "utf8"));
|
|
8048
|
+
writeFile(INTERNAL_CONFIG_JSON, fs3.readFileSync(path3.join(restoreRoot, "config.json"), "utf8"));
|
|
8049
|
+
writeFile(VERSIONS_LOCK, fs3.readFileSync(path3.join(restoreRoot, "versions.lock.json"), "utf8"));
|
|
8050
|
+
writeFile(BOOTSTRAP_BASE_STACK_FILE, fs3.readFileSync(path3.join(restoreRoot, "docker-stack.bootstrap.base.yaml"), "utf8"));
|
|
8051
|
+
writeFile(BOOTSTRAP_STACK_FILE, fs3.readFileSync(path3.join(restoreRoot, "docker-stack.bootstrap.yaml"), "utf8"));
|
|
8052
|
+
writeFile(STACK_FILE, fs3.readFileSync(path3.join(restoreRoot, "docker-stack.yaml"), "utf8"));
|
|
8053
|
+
writeFile(TRAEFIK_DYNAMIC_FILE, fs3.readFileSync(path3.join(restoreRoot, "traefik-dynamic.yaml"), "utf8"));
|
|
8054
|
+
writeFile(KEYCLOAK_REALM_FILE, fs3.readFileSync(path3.join(restoreRoot, "keycloak-realm.envsync.json"), "utf8"));
|
|
8055
|
+
writeFile(OTEL_AGENT_CONF, fs3.readFileSync(path3.join(restoreRoot, "otel-agent.yaml"), "utf8"));
|
|
8056
|
+
writeFile(CLICKSTACK_CLICKHOUSE_CONF, fs3.readFileSync(path3.join(restoreRoot, "clickhouse-listen.xml"), "utf8"));
|
|
8057
|
+
const restoredLicenseRoot = path3.join(restoreRoot, "license");
|
|
3656
8058
|
if (exists2(restoredLicenseRoot)) {
|
|
3657
|
-
|
|
3658
|
-
|
|
8059
|
+
fs3.rmSync(LICENSE_ROOT, { recursive: true, force: true });
|
|
8060
|
+
fs3.cpSync(restoredLicenseRoot, LICENSE_ROOT, { recursive: true });
|
|
3659
8061
|
}
|
|
3660
8062
|
const config = loadConfig();
|
|
3661
8063
|
for (const volume of STACK_VOLUMES) {
|
|
3662
|
-
restoreDockerVolume(stackVolumeName(config, volume),
|
|
8064
|
+
restoreDockerVolume(stackVolumeName(config, volume), path3.join(restoreRoot, "volumes", volume));
|
|
3663
8065
|
}
|
|
3664
8066
|
logSuccess("Restore completed");
|
|
3665
8067
|
logInfo(`Restored archive: ${archivePath}`);
|
|
@@ -3724,6 +8126,9 @@ async function main() {
|
|
|
3724
8126
|
case "backup":
|
|
3725
8127
|
await cmdBackup();
|
|
3726
8128
|
break;
|
|
8129
|
+
case "remove":
|
|
8130
|
+
await cmdRemove();
|
|
8131
|
+
break;
|
|
3727
8132
|
case "restore":
|
|
3728
8133
|
await cmdRestore(positionals[0] ?? "", args.includes("--deploy"));
|
|
3729
8134
|
break;
|