@es-joy/jsoe 0.26.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +10 -0
- package/.npmignore +9 -0
- package/CHANGES.md +43 -0
- package/README.md +3 -3
- package/badges/coverage-badge.svg +1 -1
- package/dist/formats/schema.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/eslint.config.js +36 -27
- package/package.json +12 -11
- package/pnpm-workspace.yaml +3 -2
- package/src/formats/schema.js +35 -6
- package/src/fundamentalTypes/arrayType.js +30 -6
- package/src/fundamentalTypes/stringType.js +5 -0
- package/src/typeChoices.js +3 -1
- package/src/types.js +7 -0
- package/vendor/typeson-registry/dist/index.js +83 -10
- package/vendor/zod/classic/checks.d.ts +1 -1
- package/vendor/zod/classic/checks.js +1 -1
- package/vendor/zod/classic/external.d.ts +1 -1
- package/vendor/zod/classic/external.js +1 -1
- package/vendor/zod/classic/from-json-schema.js +245 -24
- package/vendor/zod/classic/schemas.d.ts +17 -1
- package/vendor/zod/classic/schemas.js +77 -29
- package/vendor/zod/core/api.d.ts +6 -4
- package/vendor/zod/core/api.js +17 -2
- package/vendor/zod/core/checks.d.ts +1 -1
- package/vendor/zod/core/checks.js +0 -96
- package/vendor/zod/core/compile.d.ts +18 -4
- package/vendor/zod/core/compile.js +146 -67
- package/vendor/zod/core/doc.js +7 -2
- package/vendor/zod/core/errors.js +2 -5
- package/vendor/zod/core/json-schema-generator.js +2 -2
- package/vendor/zod/core/json-schema-processors.d.ts +17 -0
- package/vendor/zod/core/json-schema-processors.js +195 -64
- package/vendor/zod/core/memoizer.js +72 -23
- package/vendor/zod/core/parse.js +37 -16
- package/vendor/zod/core/regexes.d.ts +2 -0
- package/vendor/zod/core/regexes.js +8 -4
- package/vendor/zod/core/schemas.d.ts +42 -7
- package/vendor/zod/core/schemas.js +301 -94
- package/vendor/zod/core/to-json-schema.d.ts +7 -3
- package/vendor/zod/core/to-json-schema.js +8 -7
- package/vendor/zod/core/util.d.ts +25 -4
- package/vendor/zod/core/util.js +160 -143
- package/vendor/zod/core/versions.d.ts +1 -1
- package/vendor/zod/core/versions.js +2 -2
- package/vendor/zod/core/visit.js +12 -0
- package/vendor/zod/locales/ar.js +1 -0
- package/vendor/zod/locales/az.js +1 -0
- package/vendor/zod/locales/be.js +1 -0
- package/vendor/zod/locales/bg.js +1 -0
- package/vendor/zod/locales/bn.js +1 -0
- package/vendor/zod/locales/ca.js +1 -0
- package/vendor/zod/locales/ckb.js +1 -0
- package/vendor/zod/locales/cs.js +1 -0
- package/vendor/zod/locales/da.js +1 -0
- package/vendor/zod/locales/de.js +1 -0
- package/vendor/zod/locales/el.js +1 -0
- package/vendor/zod/locales/en.js +1 -0
- package/vendor/zod/locales/eo.js +1 -0
- package/vendor/zod/locales/es.js +1 -0
- package/vendor/zod/locales/fa.js +1 -0
- package/vendor/zod/locales/fi.js +1 -0
- package/vendor/zod/locales/fr-CA.js +1 -0
- package/vendor/zod/locales/fr.js +1 -0
- package/vendor/zod/locales/gu.js +1 -0
- package/vendor/zod/locales/he.js +1 -0
- package/vendor/zod/locales/hi.js +1 -0
- package/vendor/zod/locales/hr.js +1 -0
- package/vendor/zod/locales/hu.js +1 -0
- package/vendor/zod/locales/hy.js +1 -0
- package/vendor/zod/locales/id.js +1 -0
- package/vendor/zod/locales/index.d.ts +1 -0
- package/vendor/zod/locales/index.js +1 -0
- package/vendor/zod/locales/is.js +1 -0
- package/vendor/zod/locales/it.js +1 -0
- package/vendor/zod/locales/ja.js +1 -0
- package/vendor/zod/locales/ka.js +1 -0
- package/vendor/zod/locales/km.js +1 -0
- package/vendor/zod/locales/kn.js +1 -0
- package/vendor/zod/locales/ko.js +1 -0
- package/vendor/zod/locales/lt.js +1 -0
- package/vendor/zod/locales/mk.js +1 -0
- package/vendor/zod/locales/ms.js +1 -0
- package/vendor/zod/locales/ne.js +1 -0
- package/vendor/zod/locales/nl.js +1 -0
- package/vendor/zod/locales/nn.js +1 -0
- package/vendor/zod/locales/no.js +1 -0
- package/vendor/zod/locales/ota.js +1 -0
- package/vendor/zod/locales/pl.js +1 -0
- package/vendor/zod/locales/ps.js +1 -0
- package/vendor/zod/locales/pt-BR.js +1 -0
- package/vendor/zod/locales/pt.js +1 -0
- package/vendor/zod/locales/ro.js +1 -0
- package/vendor/zod/locales/ru.js +1 -0
- package/vendor/zod/locales/sk.js +1 -0
- package/vendor/zod/locales/sl.js +1 -0
- package/vendor/zod/locales/sv.js +1 -0
- package/vendor/zod/locales/ta.js +1 -0
- package/vendor/zod/locales/tg.d.ts +4 -0
- package/vendor/zod/locales/tg.js +116 -0
- package/vendor/zod/locales/th.js +1 -0
- package/vendor/zod/locales/tk.js +1 -0
- package/vendor/zod/locales/tr.js +1 -0
- package/vendor/zod/locales/uk.js +1 -0
- package/vendor/zod/locales/ur.js +1 -0
- package/vendor/zod/locales/uz.js +1 -0
- package/vendor/zod/locales/vi.js +1 -0
- package/vendor/zod/locales/yo.js +1 -0
- package/vendor/zod/locales/zh-CN.js +1 -0
- package/vendor/zod/locales/zh-TW.js +1 -0
- package/vendor/zod/mini/checks.d.ts +1 -1
- package/vendor/zod/mini/checks.js +1 -1
- package/vendor/zod/mini/external.d.ts +1 -1
- package/vendor/zod/mini/external.js +1 -1
- package/vendor/zod/mini/schemas.d.ts +8 -0
- package/vendor/zod/mini/schemas.js +19 -2
- package/vendor/zodexy/dist/esm/index.js +34 -1
- package/vendor/zodexy/dist/schema.zodexy.json +18 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as util from "./util.js";
|
|
1
2
|
export class $ZodCyclicError extends Error {
|
|
2
3
|
constructor() {
|
|
3
4
|
super(`Cannot parse a reference cycle that closes through a transform`);
|
|
@@ -7,35 +8,68 @@ export class $ZodCyclicError extends Error {
|
|
|
7
8
|
/** Keyed off the context object every schema in one parse call already shares. */
|
|
8
9
|
const STATE = "~memo";
|
|
9
10
|
const NO_ISSUES = [];
|
|
11
|
+
// a value a cycle can close through; callables count, since z.properties asserts on one
|
|
12
|
+
function isRef(value) {
|
|
13
|
+
return value !== null && (typeof value === "object" || typeof value === "function");
|
|
14
|
+
}
|
|
10
15
|
// Receivers prefix paths in place, so the cache and every hand-out need their own copies.
|
|
11
16
|
function cloneIssues(issues) {
|
|
12
17
|
return issues.map((iss) => (iss.path ? { ...iss, path: iss.path.slice() } : { ...iss }));
|
|
13
18
|
}
|
|
14
19
|
const recursive = /*@__PURE__*/ new WeakMap();
|
|
20
|
+
/** What the walk established, in order of certainty: ordered so the strongest answer among children wins. */
|
|
21
|
+
const NONE = 0;
|
|
22
|
+
const ASSUMED = 1;
|
|
23
|
+
const PROVEN = 2;
|
|
15
24
|
/** Whether this schema's subtree contains a cycle, so one parse can re-enter it. */
|
|
16
|
-
function isRecursive(inst, stack) {
|
|
25
|
+
function isRecursive(inst, stack, resolve) {
|
|
17
26
|
const cached = recursive.get(inst);
|
|
18
27
|
if (cached !== undefined)
|
|
19
|
-
return cached;
|
|
28
|
+
return cached ? PROVEN : NONE;
|
|
20
29
|
// Relative to the walk in progress, so not cached.
|
|
21
30
|
if (stack.has(inst))
|
|
22
|
-
return
|
|
31
|
+
return PROVEN;
|
|
23
32
|
stack.add(inst);
|
|
24
|
-
let result =
|
|
33
|
+
let result = NONE;
|
|
25
34
|
const check = (child) => {
|
|
26
|
-
if (
|
|
27
|
-
|
|
35
|
+
if (result !== PROVEN && child?._zod) {
|
|
36
|
+
const answer = isRecursive(child, stack, resolve);
|
|
37
|
+
if (answer > result)
|
|
38
|
+
result = answer;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
// `Reflect.ownKeys` rather than `Object.keys`, so a cycle through a declared symbol key is still seen
|
|
42
|
+
const shape = (sh, spread) => {
|
|
43
|
+
let answer = NONE;
|
|
44
|
+
for (const key of Reflect.ownKeys(sh)) {
|
|
45
|
+
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
46
|
+
// an object resolves its shape by spread, so a key it does not enumerate is never parsed; `z.properties` reads every own key and so keeps them all
|
|
47
|
+
if (spread && !desc.enumerable)
|
|
48
|
+
continue;
|
|
49
|
+
// resolving runs user code, and a factory mints a fresh subtree per read, so an edge the walk can't follow counts as a cycle
|
|
50
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve) : NONE;
|
|
51
|
+
if (child > answer)
|
|
52
|
+
answer = child;
|
|
53
|
+
}
|
|
54
|
+
return answer;
|
|
55
|
+
};
|
|
56
|
+
const merge = (answer) => {
|
|
57
|
+
if (answer > result)
|
|
58
|
+
result = answer;
|
|
28
59
|
};
|
|
29
60
|
const def = inst._zod.def;
|
|
30
61
|
const kind = def.type;
|
|
31
62
|
switch (kind) {
|
|
32
63
|
case "object": {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
64
|
+
const raw = util.rawShape(def);
|
|
65
|
+
// a def with no raw shape answers `shape` from an accessor of its own, and running that can mint a whole fresh subtree
|
|
66
|
+
merge(raw ? shape(raw, true) : ASSUMED);
|
|
36
67
|
check(def.catchall);
|
|
37
68
|
break;
|
|
38
69
|
}
|
|
70
|
+
case "properties":
|
|
71
|
+
merge(shape(def.shape, false));
|
|
72
|
+
break;
|
|
39
73
|
case "array":
|
|
40
74
|
check(def.element);
|
|
41
75
|
break;
|
|
@@ -79,10 +113,13 @@ function isRecursive(inst, stack) {
|
|
|
79
113
|
check(def.input);
|
|
80
114
|
check(def.output);
|
|
81
115
|
break;
|
|
82
|
-
//
|
|
83
|
-
case "lazy":
|
|
84
|
-
|
|
116
|
+
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
117
|
+
case "lazy": {
|
|
118
|
+
const inner = def._cachedInner ?? (resolve ? inst._zod.innerType : undefined);
|
|
119
|
+
// walked with resolution off: one hop sees past the deferral, and a lazy that yields only another unresolved lazy is generative, so it stops there
|
|
120
|
+
merge(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
85
121
|
break;
|
|
122
|
+
}
|
|
86
123
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
87
124
|
case "template_literal":
|
|
88
125
|
// leaves
|
|
@@ -126,8 +163,13 @@ function isRecursive(inst, stack) {
|
|
|
126
163
|
}
|
|
127
164
|
}
|
|
128
165
|
stack.delete(inst);
|
|
129
|
-
|
|
130
|
-
|
|
166
|
+
return settle(inst, result);
|
|
167
|
+
}
|
|
168
|
+
/** An assumed answer must not outlive the resolution that settles it, so only a certain one is cached. */
|
|
169
|
+
function settle(inst, answer) {
|
|
170
|
+
if (answer !== ASSUMED)
|
|
171
|
+
recursive.set(inst, answer === PROVEN);
|
|
172
|
+
return answer;
|
|
131
173
|
}
|
|
132
174
|
/**
|
|
133
175
|
* Whether one parse can re-enter this schema, i.e. its subtree contains a cycle.
|
|
@@ -136,12 +178,13 @@ function isRecursive(inst, stack) {
|
|
|
136
178
|
* generated fast path has no context to key on.
|
|
137
179
|
*/
|
|
138
180
|
export function isRecursiveSchema(inst) {
|
|
139
|
-
|
|
181
|
+
// z.compile never parses, so nothing would ever resolve a lazy for it; it runs once and already treats a throw here as recursive
|
|
182
|
+
return isRecursive(inst, new Set(), true) !== NONE;
|
|
140
183
|
}
|
|
141
184
|
function bucketFor(state, inst) {
|
|
142
185
|
let bucket = state.buckets.get(inst);
|
|
143
186
|
if (!bucket) {
|
|
144
|
-
bucket = new
|
|
187
|
+
bucket = new WeakMap();
|
|
145
188
|
state.buckets.set(inst, bucket);
|
|
146
189
|
}
|
|
147
190
|
return bucket;
|
|
@@ -180,7 +223,8 @@ const memo = {
|
|
|
180
223
|
attach(inst) {
|
|
181
224
|
var _a;
|
|
182
225
|
let isRecursiveInst;
|
|
183
|
-
|
|
226
|
+
let rechecked = false;
|
|
227
|
+
// a recursive schema is re-entered many times per parse and its bucket never changes
|
|
184
228
|
let lastCtx;
|
|
185
229
|
let lastBucket;
|
|
186
230
|
// Wraps `parse` in a deferred so it sees the container's final parse. Core's own deferred copies `parse` into `run` when there are no checks, and it ran first, so `run` is patched to match; with checks, `run` reads `parse` dynamically.
|
|
@@ -189,21 +233,26 @@ const memo = {
|
|
|
189
233
|
const base = inst._zod.parse;
|
|
190
234
|
const wrapped = (payload, ctx) => {
|
|
191
235
|
if (isRecursiveInst === undefined) {
|
|
192
|
-
|
|
193
|
-
if (
|
|
236
|
+
const walked = isRecursive(inst, new Set(), false);
|
|
237
|
+
if (walked === NONE) {
|
|
194
238
|
// Nothing here can ever fire, so take it back out.
|
|
195
239
|
inst._zod.parse = base;
|
|
196
240
|
if (inst._zod.run === wrapped)
|
|
197
241
|
inst._zod.run = base;
|
|
198
242
|
return base(payload, ctx);
|
|
199
243
|
}
|
|
244
|
+
// this parse resolves the deferred edges on its own path, so ask once more before latching
|
|
245
|
+
if (walked === PROVEN || rechecked)
|
|
246
|
+
isRecursiveInst = true;
|
|
247
|
+
else
|
|
248
|
+
rechecked = true;
|
|
200
249
|
}
|
|
201
250
|
const input = payload.value;
|
|
202
|
-
if (input
|
|
251
|
+
if (!isRef(input))
|
|
203
252
|
return base(payload, ctx);
|
|
204
253
|
let state = ctx[STATE];
|
|
205
254
|
if (!state) {
|
|
206
|
-
state = { buckets: new
|
|
255
|
+
state = { buckets: new WeakMap(), backEdges: undefined };
|
|
207
256
|
ctx[STATE] = state;
|
|
208
257
|
}
|
|
209
258
|
let bucket;
|
|
@@ -225,7 +274,7 @@ const memo = {
|
|
|
225
274
|
else {
|
|
226
275
|
// Still being parsed: its own checks cover it, so skip them here.
|
|
227
276
|
payload.memo = true;
|
|
228
|
-
state.backEdges ?? (state.backEdges = new
|
|
277
|
+
state.backEdges ?? (state.backEdges = new WeakSet());
|
|
229
278
|
state.backEdges.add(hit.value);
|
|
230
279
|
}
|
|
231
280
|
return payload;
|
|
@@ -261,5 +310,5 @@ export function memoizer() {
|
|
|
261
310
|
/** Whether this value is a node a back-edge resolved to before it finished. */
|
|
262
311
|
export function isBackEdge(ctx, value) {
|
|
263
312
|
const backEdges = ctx[STATE]?.backEdges;
|
|
264
|
-
return backEdges !== undefined && value
|
|
313
|
+
return backEdges !== undefined && isRef(value) && backEdges.has(value);
|
|
265
314
|
}
|
package/vendor/zod/core/parse.js
CHANGED
|
@@ -44,25 +44,37 @@ export const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
44
44
|
if (result instanceof Promise) {
|
|
45
45
|
throw new core.$ZodAsyncError();
|
|
46
46
|
}
|
|
47
|
-
return result.issues.length
|
|
48
|
-
? {
|
|
49
|
-
success: false,
|
|
50
|
-
error: new (_Err ?? errors.$ZodError)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
51
|
-
}
|
|
52
|
-
: { success: true, data: result.value };
|
|
47
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : { success: true, data: result.value };
|
|
53
48
|
};
|
|
54
49
|
export const safeParse = /* @__PURE__*/ _safeParse(errors.$ZodRealError);
|
|
50
|
+
// the error is built on the first read of `error`: finalizing the issues and constructing the instance is most of a failing parse, and a caller that only branches on `success` never pays it. a getter in the literal keeps this small; the alternative, one shared accessor descriptor plus a hidden state slot, reads ~15% faster but costs ~75 B gzipped in every bundle
|
|
51
|
+
function failure(Err, issues, ctx) {
|
|
52
|
+
let error;
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
get error() {
|
|
56
|
+
if (!error) {
|
|
57
|
+
error = new Err(issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
|
|
58
|
+
// finalizeIssue drops `input`, so the built error holds nothing; keeping the raw issues past this point pins the parsed value for the life of the result
|
|
59
|
+
issues = undefined;
|
|
60
|
+
ctx = undefined;
|
|
61
|
+
}
|
|
62
|
+
return error;
|
|
63
|
+
},
|
|
64
|
+
set error(e) {
|
|
65
|
+
error = e;
|
|
66
|
+
// a replacement makes the getter's branch unreachable, so the captures have to go here too
|
|
67
|
+
issues = undefined;
|
|
68
|
+
ctx = undefined;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
55
72
|
export const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
56
73
|
const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
|
|
57
74
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
58
75
|
if (result instanceof Promise)
|
|
59
76
|
result = await result;
|
|
60
|
-
return result.issues.length
|
|
61
|
-
? {
|
|
62
|
-
success: false,
|
|
63
|
-
error: new _Err(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
64
|
-
}
|
|
65
|
-
: { success: true, data: result.value };
|
|
77
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : { success: true, data: result.value };
|
|
66
78
|
};
|
|
67
79
|
export const safeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$ZodRealError);
|
|
68
80
|
// registry mirrors of the compiler's sentinels, so this module never imports the compiler
|
|
@@ -71,12 +83,19 @@ const COMPILE_FALLBACK = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
|
71
83
|
// Deliberately tiny, because v8 will not inline a body carrying the fallback's object literals and throw. Everything that is not the compiled happy path lives in validateFallback, and that split is worth ~35% on a compiled schema.
|
|
72
84
|
export const validate = ((schema, value, _ctx) => {
|
|
73
85
|
const validator = schema._zod.bag.validator;
|
|
74
|
-
if (validator !== undefined
|
|
75
|
-
|
|
86
|
+
if (validator !== undefined) {
|
|
87
|
+
if (validator(value) !== COMPILE_INVALID)
|
|
88
|
+
return true;
|
|
89
|
+
// a definite sentinel means the runtime would reject, so skip the re-parse; a ctx can still change the answer
|
|
90
|
+
if (validator.definite === true && _ctx === undefined)
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
76
93
|
return validateFallback(schema, value, _ctx);
|
|
77
94
|
});
|
|
78
95
|
function validateFallback(schema, value, _ctx) {
|
|
79
|
-
const ctx = _ctx
|
|
96
|
+
const ctx = _ctx
|
|
97
|
+
? { ..._ctx, async: false, abortEarly: true }
|
|
98
|
+
: { async: false, abortEarly: true };
|
|
80
99
|
const fallbackRun = schema._zod.bag.fallbackRun;
|
|
81
100
|
let result;
|
|
82
101
|
if (fallbackRun) {
|
|
@@ -94,7 +113,9 @@ function validateFallback(schema, value, _ctx) {
|
|
|
94
113
|
}
|
|
95
114
|
// no fast path: the compiler keeps async parses on the runtime, because a promise-returning callback that is not declared async compiles to a throw
|
|
96
115
|
export const validateAsync = async (schema, value, _ctx) => {
|
|
97
|
-
const ctx = _ctx
|
|
116
|
+
const ctx = _ctx
|
|
117
|
+
? { ..._ctx, async: true, abortEarly: true }
|
|
118
|
+
: { async: true, abortEarly: true };
|
|
98
119
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
99
120
|
if (result instanceof Promise)
|
|
100
121
|
result = await result;
|
|
@@ -46,6 +46,7 @@ export declare const domain: RegExp;
|
|
|
46
46
|
export declare const httpProtocol: RegExp;
|
|
47
47
|
export declare const e164: RegExp;
|
|
48
48
|
export declare const creditCard: RegExp;
|
|
49
|
+
export declare const iban: RegExp;
|
|
49
50
|
export declare const date: RegExp;
|
|
50
51
|
export declare function time(args: {
|
|
51
52
|
precision?: number | null;
|
|
@@ -55,6 +56,7 @@ export declare function datetime(args: {
|
|
|
55
56
|
offset?: boolean;
|
|
56
57
|
local?: boolean;
|
|
57
58
|
}): RegExp;
|
|
59
|
+
export declare const anyString: RegExp;
|
|
58
60
|
export declare const string: (params?: {
|
|
59
61
|
minimum?: number | undefined;
|
|
60
62
|
maximum?: number | undefined;
|
|
@@ -31,7 +31,7 @@ export const uuid4 = /*@__PURE__*/ uuid(4);
|
|
|
31
31
|
export const uuid6 = /*@__PURE__*/ uuid(6);
|
|
32
32
|
export const uuid7 = /*@__PURE__*/ uuid(7);
|
|
33
33
|
/** Practical email validation */
|
|
34
|
-
export const email = /^(
|
|
34
|
+
export const email = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
35
35
|
/** Equivalent to the HTML5 input[type=email] validation implemented by browsers. Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email */
|
|
36
36
|
export const html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
37
37
|
/** The classic emailregex.com regex for RFC 5322-compliant emails */
|
|
@@ -41,8 +41,8 @@ export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
|
41
41
|
export const idnEmail = unicodeEmail;
|
|
42
42
|
export const browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
43
43
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
44
|
-
// Single character class, not an alternation: the two properties overlap (U+1F9B0-U+1F9B3), so `(A|B)+` backtracks exponentially on a failed match.
|
|
45
|
-
const _emoji = `^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
44
|
+
// Single character class, not an alternation: the two properties overlap (U+1F9B0-U+1F9B3), so `(A|B)+` backtracks exponentially on a failed match. The leading lookahead then demands one anchor — a pictograph, a regional indicator, or the enclosing keycap — because `\p{Emoji_Component}` on its own covers ASCII digits, `#`, `*`, ZWJ, variation selectors and skin tone modifiers, none of which is an emoji without a base.
|
|
45
|
+
const _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
46
46
|
export function emoji() {
|
|
47
47
|
return new RegExp(_emoji, "u");
|
|
48
48
|
}
|
|
@@ -56,7 +56,7 @@ export const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3
|
|
|
56
56
|
export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
57
57
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
58
58
|
export const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
59
|
-
export const base64url = /^[A-Za-z0-9_-]
|
|
59
|
+
export const base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
60
60
|
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
61
61
|
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
62
62
|
export const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
@@ -66,6 +66,8 @@ export const httpProtocol = /^https?$/;
|
|
|
66
66
|
export const e164 = /^\+[1-9]\d{6,14}$/;
|
|
67
67
|
// Credit card shape: 12–19 digits, optionally separated by single spaces or single hyphens. ISO/IEC 7812 caps the PAN at 19 digits; 12 is the shortest issued length (Maestro).
|
|
68
68
|
export const creditCard = /^\d(?:[ -]?\d){11,18}$/;
|
|
69
|
+
// iban electronic format: 2-letter country, check digits 02-98 (the only values `98 - remainder` can produce), 11-30 bban characters
|
|
70
|
+
export const iban = /^[A-Z]{2}(?!00|01|99)\d{2}[A-Z0-9]{11,30}$/;
|
|
69
71
|
const dateSource = `(?:(?:\\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])))`;
|
|
70
72
|
/** Anchors a pattern source. The interpolation lives here rather than at the call site because
|
|
71
73
|
* esbuild will not drop a `@__PURE__` call whose own argument interpolates a variable, but it
|
|
@@ -101,6 +103,8 @@ export function datetime(args) {
|
|
|
101
103
|
const timeRegex = args.local ? `${qualified}|${timeSource({ precision: args.precision })}` : qualified;
|
|
102
104
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
103
105
|
}
|
|
106
|
+
// the unbounded form of `string()` as a literal, so every plain string shares one instance instead of building its own
|
|
107
|
+
export const anyString = /^[\s\S]{0,}$/;
|
|
104
108
|
export const string = (params) => {
|
|
105
109
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
106
110
|
return new RegExp(`^${regex}$`);
|
|
@@ -21,6 +21,8 @@ export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> ex
|
|
|
21
21
|
readonly async?: boolean | undefined;
|
|
22
22
|
readonly direction?: "forward" | "backward";
|
|
23
23
|
readonly skipChecks?: boolean;
|
|
24
|
+
/** Set only by `validate`/`validateAsync`. A container may stop before its next child, never inside one, so a map entry and a tuple's fixed items parse whole. */
|
|
25
|
+
readonly abortEarly?: boolean;
|
|
24
26
|
}
|
|
25
27
|
/** Gives a container cycle support: `attach` wraps its parse, and `alloc` registers the object it builds into before any child is parsed so a reference back to the same input resolves to it. */
|
|
26
28
|
export interface $ZodMemoizer {
|
|
@@ -39,7 +41,7 @@ export interface ParsePayload<T = unknown> {
|
|
|
39
41
|
}
|
|
40
42
|
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
|
41
43
|
export interface $ZodTypeDef {
|
|
42
|
-
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "function" | "custom";
|
|
44
|
+
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "function" | "custom" | "properties";
|
|
43
45
|
error?: errors.$ZodErrorMap<never> | undefined;
|
|
44
46
|
checks?: checks.$ZodCheck<never>[];
|
|
45
47
|
}
|
|
@@ -371,7 +373,9 @@ export interface $ZodBase64Internals extends $ZodStringFormatInternals<"base64">
|
|
|
371
373
|
export interface $ZodBase64 extends $ZodType {
|
|
372
374
|
_zod: $ZodBase64Internals;
|
|
373
375
|
}
|
|
376
|
+
export declare const base64Charset: RegExp;
|
|
374
377
|
export declare const $ZodBase64: core.$constructor<$ZodBase64>;
|
|
378
|
+
export declare const base64urlCharset: RegExp;
|
|
375
379
|
export declare function isValidBase64URL(data: string): boolean;
|
|
376
380
|
export interface $ZodBase64URLDef extends $ZodStringFormatDef<"base64url"> {
|
|
377
381
|
}
|
|
@@ -399,6 +403,16 @@ export interface $ZodCreditCard extends $ZodType {
|
|
|
399
403
|
_zod: $ZodCreditCardInternals;
|
|
400
404
|
}
|
|
401
405
|
export declare const $ZodCreditCard: core.$constructor<$ZodCreditCard>;
|
|
406
|
+
export declare function isValidIBAN(input: string): boolean;
|
|
407
|
+
export interface $ZodIBANDef extends $ZodStringFormatDef<"iban"> {
|
|
408
|
+
}
|
|
409
|
+
export interface $ZodIBANInternals extends $ZodStringFormatInternals<"iban"> {
|
|
410
|
+
def: $ZodIBANDef;
|
|
411
|
+
}
|
|
412
|
+
export interface $ZodIBAN extends $ZodType {
|
|
413
|
+
_zod: $ZodIBANInternals;
|
|
414
|
+
}
|
|
415
|
+
export declare const $ZodIBAN: core.$constructor<$ZodIBAN>;
|
|
402
416
|
export declare function isValidJWT(token: string, algorithm?: util.JWTAlgorithm | null): boolean;
|
|
403
417
|
export interface $ZodJWTDef extends $ZodStringFormatDef<"jwt"> {
|
|
404
418
|
alg?: util.JWTAlgorithm | undefined;
|
|
@@ -617,12 +631,16 @@ type OptionalInSchema = {
|
|
|
617
631
|
optin: "optional" | "defaulted";
|
|
618
632
|
};
|
|
619
633
|
};
|
|
620
|
-
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> :
|
|
634
|
+
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : {
|
|
635
|
+
[k in string]: core.output<T[keyof T]>;
|
|
636
|
+
} : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
621
637
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
|
|
622
638
|
} & {
|
|
623
639
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
|
|
624
640
|
} & Extra>;
|
|
625
|
-
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> :
|
|
641
|
+
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : {
|
|
642
|
+
[k in string]: core.input<T[keyof T]>;
|
|
643
|
+
} : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
626
644
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
|
|
627
645
|
} & {
|
|
628
646
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
|
|
@@ -715,7 +733,7 @@ export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeTy
|
|
|
715
733
|
def: $ZodDiscriminatedUnionDef<Options, Disc>;
|
|
716
734
|
propValues: util.PropValues;
|
|
717
735
|
bag: util.LoosePartial<{
|
|
718
|
-
optionsMap: Map<util.Primitive, $ZodType>;
|
|
736
|
+
optionsMap: Map<util.Primitive, $ZodType | null>;
|
|
719
737
|
}>;
|
|
720
738
|
}
|
|
721
739
|
/** The discriminator values a member of `Options` can declare. An omittable discriminator contributes `undefined`, matching what `propValues` claims for it. */
|
|
@@ -734,7 +752,7 @@ export type $DiscriminatedOption<Options extends readonly SomeType[], Disc exten
|
|
|
734
752
|
};
|
|
735
753
|
} ? Disc extends keyof Out ? V extends Out[Disc] ? Options[I] : never : never : never;
|
|
736
754
|
}[number];
|
|
737
|
-
/** Returns the option
|
|
755
|
+
/** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
|
|
738
756
|
export declare function getDiscriminatedOption<Options extends readonly SomeType[], Disc extends string, const V extends $DiscriminatorValue<Options, Disc>>(union: $ZodDiscriminatedUnion<Options, Disc>, value: V): $DiscriminatedOption<Options, Disc, V>;
|
|
739
757
|
export interface $ZodDiscriminatedUnion<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodType {
|
|
740
758
|
_zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
|
|
@@ -1249,5 +1267,22 @@ export interface $ZodCustom<O = unknown, I = unknown> extends $ZodType {
|
|
|
1249
1267
|
_zod: $ZodCustomInternals<O, I>;
|
|
1250
1268
|
}
|
|
1251
1269
|
export declare const $ZodCustom: core.$constructor<$ZodCustom>;
|
|
1252
|
-
export
|
|
1253
|
-
|
|
1270
|
+
export interface $ZodPropertiesDef<Shape extends $ZodShape = $ZodShape> extends $ZodTypeDef, checks.$ZodCheckDef {
|
|
1271
|
+
type: "properties";
|
|
1272
|
+
check: "properties";
|
|
1273
|
+
shape: Shape;
|
|
1274
|
+
}
|
|
1275
|
+
export interface $ZodPropertiesInternals<Shape extends $ZodShape = $ZodShape> extends $ZodTypeInternals<$InferObjectInput<Shape, {}>, $InferObjectInput<Shape, {}>>, checks.$ZodCheckInternals<{
|
|
1276
|
+
-readonly [k in keyof Shape]: util.Widen<core.input<Shape[k]>>;
|
|
1277
|
+
}> {
|
|
1278
|
+
def: $ZodPropertiesDef<Shape>;
|
|
1279
|
+
isst: errors.$ZodIssueInvalidType;
|
|
1280
|
+
issc: errors.$ZodIssue;
|
|
1281
|
+
}
|
|
1282
|
+
export interface $ZodProperties<Shape extends $ZodShape = $ZodShape> extends $ZodType {
|
|
1283
|
+
_zod: $ZodPropertiesInternals<Shape>;
|
|
1284
|
+
[Symbol.iterator](): Iterator<this>;
|
|
1285
|
+
}
|
|
1286
|
+
export declare const $ZodProperties: core.$constructor<$ZodProperties>;
|
|
1287
|
+
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodFunction | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodProperties | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
|
1288
|
+
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodMAC | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodCreditCard | $ZodIBAN | $ZodJWT | $ZodCustomStringFormat<"hex"> | $ZodCustomStringFormat<util.HashFormat> | $ZodCustomStringFormat<"hostname">;
|