zod 3.26.0-canary.20250703T215303 → 3.26.0-canary.20250708T090717
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/index.cjs +2 -2
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/v4/classic/schemas.ts +8 -9
- package/src/v4/classic/tests/brand.test.ts +1 -3
- package/src/v4/classic/tests/discriminated-unions.test.ts +27 -0
- package/src/v4/classic/tests/index.test.ts +1 -1
- package/src/v4/classic/tests/object.test.ts +11 -1
- package/src/v4/classic/tests/record.test.ts +11 -1
- package/src/v4/classic/tests/recursive-types.test.ts +33 -2
- package/src/v4/classic/tests/refine.test.ts +109 -0
- package/src/v4/classic/tests/registries.test.ts +9 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +78 -17
- package/src/v4/core/api.ts +2 -0
- package/src/v4/core/checks.ts +8 -10
- package/src/v4/core/errors.ts +4 -0
- package/src/v4/core/registries.ts +11 -1
- package/src/v4/core/schemas.ts +80 -34
- package/src/v4/core/to-json-schema.ts +67 -30
- package/src/v4/mini/schemas.ts +2 -2
- package/src/v4/mini/tests/string.test.ts +6 -0
- package/v4/classic/schemas.cjs +4 -4
- package/v4/classic/schemas.d.cts +4 -3
- package/v4/classic/schemas.d.ts +4 -3
- package/v4/classic/schemas.js +4 -4
- package/v4/core/checks.cjs +18 -12
- package/v4/core/checks.d.cts +2 -1
- package/v4/core/checks.d.ts +2 -1
- package/v4/core/checks.js +18 -12
- package/v4/core/errors.cjs +4 -0
- package/v4/core/errors.js +4 -0
- package/v4/core/registries.cjs +10 -1
- package/v4/core/registries.d.cts +2 -1
- package/v4/core/registries.d.ts +2 -1
- package/v4/core/registries.js +10 -1
- package/v4/core/schemas.cjs +15 -6
- package/v4/core/schemas.d.cts +31 -9
- package/v4/core/schemas.d.ts +31 -9
- package/v4/core/schemas.js +15 -6
- package/v4/core/to-json-schema.cjs +51 -26
- package/v4/core/to-json-schema.d.cts +6 -2
- package/v4/core/to-json-schema.d.ts +6 -2
- package/v4/core/to-json-schema.js +51 -26
- package/v4/mini/schemas.d.cts +1 -1
- package/v4/mini/schemas.d.ts +1 -1
package/v4/classic/schemas.js
CHANGED
|
@@ -935,10 +935,10 @@ export const ZodCustom = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def
|
|
|
935
935
|
ZodType.init(inst, def);
|
|
936
936
|
});
|
|
937
937
|
// custom checks
|
|
938
|
-
export function check(fn
|
|
938
|
+
export function check(fn) {
|
|
939
939
|
const ch = new core.$ZodCheck({
|
|
940
940
|
check: "custom",
|
|
941
|
-
...util.normalizeParams(params),
|
|
941
|
+
// ...util.normalizeParams(params),
|
|
942
942
|
});
|
|
943
943
|
ch._zod.check = fn;
|
|
944
944
|
return ch;
|
|
@@ -950,7 +950,7 @@ export function refine(fn, _params = {}) {
|
|
|
950
950
|
return core._refine(ZodCustom, fn, _params);
|
|
951
951
|
}
|
|
952
952
|
// superRefine
|
|
953
|
-
export function superRefine(fn
|
|
953
|
+
export function superRefine(fn) {
|
|
954
954
|
const ch = check((payload) => {
|
|
955
955
|
payload.addIssue = (issue) => {
|
|
956
956
|
if (typeof issue === "string") {
|
|
@@ -969,7 +969,7 @@ export function superRefine(fn, params) {
|
|
|
969
969
|
}
|
|
970
970
|
};
|
|
971
971
|
return fn(payload.value, payload);
|
|
972
|
-
}
|
|
972
|
+
});
|
|
973
973
|
return ch;
|
|
974
974
|
}
|
|
975
975
|
function _instanceof(cls, params = {
|
package/v4/core/checks.cjs
CHANGED
|
@@ -248,11 +248,12 @@ exports.$ZodCheckBigIntFormat = core.$constructor("$ZodCheckBigIntFormat", (inst
|
|
|
248
248
|
};
|
|
249
249
|
});
|
|
250
250
|
exports.$ZodCheckMaxSize = core.$constructor("$ZodCheckMaxSize", (inst, def) => {
|
|
251
|
+
var _a;
|
|
251
252
|
exports.$ZodCheck.init(inst, def);
|
|
252
|
-
inst._zod.when = (payload) => {
|
|
253
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
253
254
|
const val = payload.value;
|
|
254
255
|
return !util.nullish(val) && val.size !== undefined;
|
|
255
|
-
};
|
|
256
|
+
});
|
|
256
257
|
inst._zod.onattach.push((inst) => {
|
|
257
258
|
const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
|
|
258
259
|
if (def.maximum < curr)
|
|
@@ -274,11 +275,12 @@ exports.$ZodCheckMaxSize = core.$constructor("$ZodCheckMaxSize", (inst, def) =>
|
|
|
274
275
|
};
|
|
275
276
|
});
|
|
276
277
|
exports.$ZodCheckMinSize = core.$constructor("$ZodCheckMinSize", (inst, def) => {
|
|
278
|
+
var _a;
|
|
277
279
|
exports.$ZodCheck.init(inst, def);
|
|
278
|
-
inst._zod.when = (payload) => {
|
|
280
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
279
281
|
const val = payload.value;
|
|
280
282
|
return !util.nullish(val) && val.size !== undefined;
|
|
281
|
-
};
|
|
283
|
+
});
|
|
282
284
|
inst._zod.onattach.push((inst) => {
|
|
283
285
|
const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
|
|
284
286
|
if (def.minimum > curr)
|
|
@@ -300,11 +302,12 @@ exports.$ZodCheckMinSize = core.$constructor("$ZodCheckMinSize", (inst, def) =>
|
|
|
300
302
|
};
|
|
301
303
|
});
|
|
302
304
|
exports.$ZodCheckSizeEquals = core.$constructor("$ZodCheckSizeEquals", (inst, def) => {
|
|
305
|
+
var _a;
|
|
303
306
|
exports.$ZodCheck.init(inst, def);
|
|
304
|
-
inst._zod.when = (payload) => {
|
|
307
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
305
308
|
const val = payload.value;
|
|
306
309
|
return !util.nullish(val) && val.size !== undefined;
|
|
307
|
-
};
|
|
310
|
+
});
|
|
308
311
|
inst._zod.onattach.push((inst) => {
|
|
309
312
|
const bag = inst._zod.bag;
|
|
310
313
|
bag.minimum = def.size;
|
|
@@ -329,11 +332,12 @@ exports.$ZodCheckSizeEquals = core.$constructor("$ZodCheckSizeEquals", (inst, de
|
|
|
329
332
|
};
|
|
330
333
|
});
|
|
331
334
|
exports.$ZodCheckMaxLength = core.$constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
335
|
+
var _a;
|
|
332
336
|
exports.$ZodCheck.init(inst, def);
|
|
333
|
-
inst._zod.when = (payload) => {
|
|
337
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
334
338
|
const val = payload.value;
|
|
335
339
|
return !util.nullish(val) && val.length !== undefined;
|
|
336
|
-
};
|
|
340
|
+
});
|
|
337
341
|
inst._zod.onattach.push((inst) => {
|
|
338
342
|
const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
|
|
339
343
|
if (def.maximum < curr)
|
|
@@ -357,11 +361,12 @@ exports.$ZodCheckMaxLength = core.$constructor("$ZodCheckMaxLength", (inst, def)
|
|
|
357
361
|
};
|
|
358
362
|
});
|
|
359
363
|
exports.$ZodCheckMinLength = core.$constructor("$ZodCheckMinLength", (inst, def) => {
|
|
364
|
+
var _a;
|
|
360
365
|
exports.$ZodCheck.init(inst, def);
|
|
361
|
-
inst._zod.when = (payload) => {
|
|
366
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
362
367
|
const val = payload.value;
|
|
363
368
|
return !util.nullish(val) && val.length !== undefined;
|
|
364
|
-
};
|
|
369
|
+
});
|
|
365
370
|
inst._zod.onattach.push((inst) => {
|
|
366
371
|
const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
|
|
367
372
|
if (def.minimum > curr)
|
|
@@ -385,11 +390,12 @@ exports.$ZodCheckMinLength = core.$constructor("$ZodCheckMinLength", (inst, def)
|
|
|
385
390
|
};
|
|
386
391
|
});
|
|
387
392
|
exports.$ZodCheckLengthEquals = core.$constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
393
|
+
var _a;
|
|
388
394
|
exports.$ZodCheck.init(inst, def);
|
|
389
|
-
inst._zod.when = (payload) => {
|
|
395
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
390
396
|
const val = payload.value;
|
|
391
397
|
return !util.nullish(val) && val.length !== undefined;
|
|
392
|
-
};
|
|
398
|
+
});
|
|
393
399
|
inst._zod.onattach.push((inst) => {
|
|
394
400
|
const bag = inst._zod.bag;
|
|
395
401
|
bag.minimum = def.length;
|
package/v4/core/checks.d.cts
CHANGED
|
@@ -7,6 +7,8 @@ export interface $ZodCheckDef {
|
|
|
7
7
|
error?: errors.$ZodErrorMap<never> | undefined;
|
|
8
8
|
/** If true, no later checks will be executed if this check fails. Default `false`. */
|
|
9
9
|
abort?: boolean | undefined;
|
|
10
|
+
/** If provided, this check will only be executed if the function returns `true`. Defaults to `payload => z.util.isAborted(payload)`. */
|
|
11
|
+
when?: ((payload: schemas.ParsePayload) => boolean) | undefined;
|
|
10
12
|
}
|
|
11
13
|
export interface $ZodCheckInternals<T> {
|
|
12
14
|
def: $ZodCheckDef;
|
|
@@ -14,7 +16,6 @@ export interface $ZodCheckInternals<T> {
|
|
|
14
16
|
issc?: errors.$ZodIssueBase;
|
|
15
17
|
check(payload: schemas.ParsePayload<T>): util.MaybeAsync<void>;
|
|
16
18
|
onattach: ((schema: schemas.$ZodType) => void)[];
|
|
17
|
-
when?: ((payload: schemas.ParsePayload) => boolean) | undefined;
|
|
18
19
|
}
|
|
19
20
|
export interface $ZodCheck<in T = never> {
|
|
20
21
|
_zod: $ZodCheckInternals<T>;
|
package/v4/core/checks.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface $ZodCheckDef {
|
|
|
7
7
|
error?: errors.$ZodErrorMap<never> | undefined;
|
|
8
8
|
/** If true, no later checks will be executed if this check fails. Default `false`. */
|
|
9
9
|
abort?: boolean | undefined;
|
|
10
|
+
/** If provided, this check will only be executed if the function returns `true`. Defaults to `payload => z.util.isAborted(payload)`. */
|
|
11
|
+
when?: ((payload: schemas.ParsePayload) => boolean) | undefined;
|
|
10
12
|
}
|
|
11
13
|
export interface $ZodCheckInternals<T> {
|
|
12
14
|
def: $ZodCheckDef;
|
|
@@ -14,7 +16,6 @@ export interface $ZodCheckInternals<T> {
|
|
|
14
16
|
issc?: errors.$ZodIssueBase;
|
|
15
17
|
check(payload: schemas.ParsePayload<T>): util.MaybeAsync<void>;
|
|
16
18
|
onattach: ((schema: schemas.$ZodType) => void)[];
|
|
17
|
-
when?: ((payload: schemas.ParsePayload) => boolean) | undefined;
|
|
18
19
|
}
|
|
19
20
|
export interface $ZodCheck<in T = never> {
|
|
20
21
|
_zod: $ZodCheckInternals<T>;
|
package/v4/core/checks.js
CHANGED
|
@@ -222,11 +222,12 @@ export const $ZodCheckBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodCheckB
|
|
|
222
222
|
};
|
|
223
223
|
});
|
|
224
224
|
export const $ZodCheckMaxSize = /*@__PURE__*/ core.$constructor("$ZodCheckMaxSize", (inst, def) => {
|
|
225
|
+
var _a;
|
|
225
226
|
$ZodCheck.init(inst, def);
|
|
226
|
-
inst._zod.when = (payload) => {
|
|
227
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
227
228
|
const val = payload.value;
|
|
228
229
|
return !util.nullish(val) && val.size !== undefined;
|
|
229
|
-
};
|
|
230
|
+
});
|
|
230
231
|
inst._zod.onattach.push((inst) => {
|
|
231
232
|
const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
|
|
232
233
|
if (def.maximum < curr)
|
|
@@ -248,11 +249,12 @@ export const $ZodCheckMaxSize = /*@__PURE__*/ core.$constructor("$ZodCheckMaxSiz
|
|
|
248
249
|
};
|
|
249
250
|
});
|
|
250
251
|
export const $ZodCheckMinSize = /*@__PURE__*/ core.$constructor("$ZodCheckMinSize", (inst, def) => {
|
|
252
|
+
var _a;
|
|
251
253
|
$ZodCheck.init(inst, def);
|
|
252
|
-
inst._zod.when = (payload) => {
|
|
254
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
253
255
|
const val = payload.value;
|
|
254
256
|
return !util.nullish(val) && val.size !== undefined;
|
|
255
|
-
};
|
|
257
|
+
});
|
|
256
258
|
inst._zod.onattach.push((inst) => {
|
|
257
259
|
const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
|
|
258
260
|
if (def.minimum > curr)
|
|
@@ -274,11 +276,12 @@ export const $ZodCheckMinSize = /*@__PURE__*/ core.$constructor("$ZodCheckMinSiz
|
|
|
274
276
|
};
|
|
275
277
|
});
|
|
276
278
|
export const $ZodCheckSizeEquals = /*@__PURE__*/ core.$constructor("$ZodCheckSizeEquals", (inst, def) => {
|
|
279
|
+
var _a;
|
|
277
280
|
$ZodCheck.init(inst, def);
|
|
278
|
-
inst._zod.when = (payload) => {
|
|
281
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
279
282
|
const val = payload.value;
|
|
280
283
|
return !util.nullish(val) && val.size !== undefined;
|
|
281
|
-
};
|
|
284
|
+
});
|
|
282
285
|
inst._zod.onattach.push((inst) => {
|
|
283
286
|
const bag = inst._zod.bag;
|
|
284
287
|
bag.minimum = def.size;
|
|
@@ -303,11 +306,12 @@ export const $ZodCheckSizeEquals = /*@__PURE__*/ core.$constructor("$ZodCheckSiz
|
|
|
303
306
|
};
|
|
304
307
|
});
|
|
305
308
|
export const $ZodCheckMaxLength = /*@__PURE__*/ core.$constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
309
|
+
var _a;
|
|
306
310
|
$ZodCheck.init(inst, def);
|
|
307
|
-
inst._zod.when = (payload) => {
|
|
311
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
308
312
|
const val = payload.value;
|
|
309
313
|
return !util.nullish(val) && val.length !== undefined;
|
|
310
|
-
};
|
|
314
|
+
});
|
|
311
315
|
inst._zod.onattach.push((inst) => {
|
|
312
316
|
const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
|
|
313
317
|
if (def.maximum < curr)
|
|
@@ -331,11 +335,12 @@ export const $ZodCheckMaxLength = /*@__PURE__*/ core.$constructor("$ZodCheckMaxL
|
|
|
331
335
|
};
|
|
332
336
|
});
|
|
333
337
|
export const $ZodCheckMinLength = /*@__PURE__*/ core.$constructor("$ZodCheckMinLength", (inst, def) => {
|
|
338
|
+
var _a;
|
|
334
339
|
$ZodCheck.init(inst, def);
|
|
335
|
-
inst._zod.when = (payload) => {
|
|
340
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
336
341
|
const val = payload.value;
|
|
337
342
|
return !util.nullish(val) && val.length !== undefined;
|
|
338
|
-
};
|
|
343
|
+
});
|
|
339
344
|
inst._zod.onattach.push((inst) => {
|
|
340
345
|
const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
|
|
341
346
|
if (def.minimum > curr)
|
|
@@ -359,11 +364,12 @@ export const $ZodCheckMinLength = /*@__PURE__*/ core.$constructor("$ZodCheckMinL
|
|
|
359
364
|
};
|
|
360
365
|
});
|
|
361
366
|
export const $ZodCheckLengthEquals = /*@__PURE__*/ core.$constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
367
|
+
var _a;
|
|
362
368
|
$ZodCheck.init(inst, def);
|
|
363
|
-
inst._zod.when = (payload) => {
|
|
369
|
+
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
364
370
|
const val = payload.value;
|
|
365
371
|
return !util.nullish(val) && val.length !== undefined;
|
|
366
|
-
};
|
|
372
|
+
});
|
|
367
373
|
inst._zod.onattach.push((inst) => {
|
|
368
374
|
const bag = inst._zod.bag;
|
|
369
375
|
bag.minimum = def.length;
|
package/v4/core/errors.cjs
CHANGED
|
@@ -48,6 +48,10 @@ const initializer = (inst, def) => {
|
|
|
48
48
|
enumerable: true,
|
|
49
49
|
// configurable: false,
|
|
50
50
|
});
|
|
51
|
+
Object.defineProperty(inst, "toString", {
|
|
52
|
+
value: () => inst.message,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
});
|
|
51
55
|
};
|
|
52
56
|
exports.$ZodError = (0, core_js_1.$constructor)("$ZodError", initializer);
|
|
53
57
|
exports.$ZodRealError = (0, core_js_1.$constructor)("$ZodError", initializer, { Parent: Error });
|
package/v4/core/errors.js
CHANGED
|
@@ -17,6 +17,10 @@ const initializer = (inst, def) => {
|
|
|
17
17
|
enumerable: true,
|
|
18
18
|
// configurable: false,
|
|
19
19
|
});
|
|
20
|
+
Object.defineProperty(inst, "toString", {
|
|
21
|
+
value: () => inst.message,
|
|
22
|
+
enumerable: false,
|
|
23
|
+
});
|
|
20
24
|
};
|
|
21
25
|
export const $ZodError = $constructor("$ZodError", initializer);
|
|
22
26
|
export const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
package/v4/core/registries.cjs
CHANGED
|
@@ -6,7 +6,7 @@ exports.$output = Symbol("ZodOutput");
|
|
|
6
6
|
exports.$input = Symbol("ZodInput");
|
|
7
7
|
class $ZodRegistry {
|
|
8
8
|
constructor() {
|
|
9
|
-
this._map = new
|
|
9
|
+
this._map = new Map();
|
|
10
10
|
this._idmap = new Map();
|
|
11
11
|
}
|
|
12
12
|
add(schema, ..._meta) {
|
|
@@ -20,7 +20,16 @@ class $ZodRegistry {
|
|
|
20
20
|
}
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
|
+
clear() {
|
|
24
|
+
this._map = new Map();
|
|
25
|
+
this._idmap = new Map();
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
23
28
|
remove(schema) {
|
|
29
|
+
const meta = this._map.get(schema);
|
|
30
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
31
|
+
this._idmap.delete(meta.id);
|
|
32
|
+
}
|
|
24
33
|
this._map.delete(schema);
|
|
25
34
|
return this;
|
|
26
35
|
}
|
package/v4/core/registries.d.cts
CHANGED
|
@@ -13,9 +13,10 @@ type MetadataType = Record<string, unknown> | undefined;
|
|
|
13
13
|
export declare class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
|
|
14
14
|
_meta: Meta;
|
|
15
15
|
_schema: Schema;
|
|
16
|
-
_map:
|
|
16
|
+
_map: Map<Schema, $replace<Meta, Schema>>;
|
|
17
17
|
_idmap: Map<string, Schema>;
|
|
18
18
|
add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
|
|
19
|
+
clear(): this;
|
|
19
20
|
remove(schema: Schema): this;
|
|
20
21
|
get<S extends Schema>(schema: S): $replace<Meta, S> | undefined;
|
|
21
22
|
has(schema: Schema): boolean;
|
package/v4/core/registries.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ type MetadataType = Record<string, unknown> | undefined;
|
|
|
13
13
|
export declare class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
|
|
14
14
|
_meta: Meta;
|
|
15
15
|
_schema: Schema;
|
|
16
|
-
_map:
|
|
16
|
+
_map: Map<Schema, $replace<Meta, Schema>>;
|
|
17
17
|
_idmap: Map<string, Schema>;
|
|
18
18
|
add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
|
|
19
|
+
clear(): this;
|
|
19
20
|
remove(schema: Schema): this;
|
|
20
21
|
get<S extends Schema>(schema: S): $replace<Meta, S> | undefined;
|
|
21
22
|
has(schema: Schema): boolean;
|
package/v4/core/registries.js
CHANGED
|
@@ -2,7 +2,7 @@ export const $output = Symbol("ZodOutput");
|
|
|
2
2
|
export const $input = Symbol("ZodInput");
|
|
3
3
|
export class $ZodRegistry {
|
|
4
4
|
constructor() {
|
|
5
|
-
this._map = new
|
|
5
|
+
this._map = new Map();
|
|
6
6
|
this._idmap = new Map();
|
|
7
7
|
}
|
|
8
8
|
add(schema, ..._meta) {
|
|
@@ -16,7 +16,16 @@ export class $ZodRegistry {
|
|
|
16
16
|
}
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
|
+
clear() {
|
|
20
|
+
this._map = new Map();
|
|
21
|
+
this._idmap = new Map();
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
19
24
|
remove(schema) {
|
|
25
|
+
const meta = this._map.get(schema);
|
|
26
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
27
|
+
this._idmap.delete(meta.id);
|
|
28
|
+
}
|
|
20
29
|
this._map.delete(schema);
|
|
21
30
|
return this;
|
|
22
31
|
}
|
package/v4/core/schemas.cjs
CHANGED
|
@@ -38,8 +38,6 @@ const versions_js_1 = require("./versions.cjs");
|
|
|
38
38
|
exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
|
|
39
39
|
var _a;
|
|
40
40
|
inst ?? (inst = {});
|
|
41
|
-
// avoids issues with using Math.random() in Next.js caching
|
|
42
|
-
util.defineLazy(inst._zod, "id", () => def.type + "_" + util.randomString(10));
|
|
43
41
|
inst._zod.def = def; // set _def property
|
|
44
42
|
inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
|
|
45
43
|
inst._zod.version = versions_js_1.version;
|
|
@@ -67,8 +65,8 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
|
|
|
67
65
|
let isAborted = util.aborted(payload);
|
|
68
66
|
let asyncResult;
|
|
69
67
|
for (const ch of checks) {
|
|
70
|
-
if (ch._zod.when) {
|
|
71
|
-
const shouldRun = ch._zod.when(payload);
|
|
68
|
+
if (ch._zod.def.when) {
|
|
69
|
+
const shouldRun = ch._zod.def.when(payload);
|
|
72
70
|
if (!shouldRun)
|
|
73
71
|
continue;
|
|
74
72
|
}
|
|
@@ -189,7 +187,9 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
|
|
|
189
187
|
exports.$ZodStringFormat.init(inst, def);
|
|
190
188
|
inst._zod.check = (payload) => {
|
|
191
189
|
try {
|
|
192
|
-
const
|
|
190
|
+
const orig = payload.value;
|
|
191
|
+
const url = new URL(orig);
|
|
192
|
+
const href = url.href;
|
|
193
193
|
if (def.hostname) {
|
|
194
194
|
def.hostname.lastIndex = 0;
|
|
195
195
|
if (!def.hostname.test(url.hostname)) {
|
|
@@ -218,6 +218,13 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
|
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
+
// payload.value = url.href;
|
|
222
|
+
if (!orig.endsWith("/") && href.endsWith("/")) {
|
|
223
|
+
payload.value = href.slice(0, -1);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
payload.value = href;
|
|
227
|
+
}
|
|
221
228
|
return;
|
|
222
229
|
}
|
|
223
230
|
catch (_) {
|
|
@@ -751,8 +758,9 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
|
|
|
751
758
|
};
|
|
752
759
|
doc.write(`const input = payload.value;`);
|
|
753
760
|
const ids = Object.create(null);
|
|
761
|
+
let counter = 0;
|
|
754
762
|
for (const key of normalized.keys) {
|
|
755
|
-
ids[key] =
|
|
763
|
+
ids[key] = `key_${counter++}`;
|
|
756
764
|
}
|
|
757
765
|
// A: preserve key order {
|
|
758
766
|
doc.write(`const newResult = {}`);
|
|
@@ -1626,6 +1634,7 @@ function handlePipeResult(left, def, ctx) {
|
|
|
1626
1634
|
exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
|
|
1627
1635
|
exports.$ZodType.init(inst, def);
|
|
1628
1636
|
util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
1637
|
+
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
1629
1638
|
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
1630
1639
|
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
1631
1640
|
inst._zod.parse = (payload, ctx) => {
|
package/v4/core/schemas.d.cts
CHANGED
|
@@ -32,7 +32,6 @@ export interface _$ZodTypeInternals {
|
|
|
32
32
|
/** Schema definition. */
|
|
33
33
|
def: $ZodTypeDef;
|
|
34
34
|
/** @internal Randomly generated ID for this schema. */
|
|
35
|
-
id: string;
|
|
36
35
|
/** @internal List of deferred initializers. */
|
|
37
36
|
deferred: util.AnyFunc[] | undefined;
|
|
38
37
|
/** @internal Parses input and runs all checks (refinements). */
|
|
@@ -516,11 +515,13 @@ export interface $ZodArrayDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
516
515
|
type: "array";
|
|
517
516
|
element: T;
|
|
518
517
|
}
|
|
519
|
-
export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals
|
|
518
|
+
export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$ZodTypeInternals {
|
|
520
519
|
def: $ZodArrayDef<T>;
|
|
521
520
|
isst: errors.$ZodIssueInvalidType;
|
|
521
|
+
output: core.output<T>[];
|
|
522
|
+
input: core.input<T>[];
|
|
522
523
|
}
|
|
523
|
-
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<
|
|
524
|
+
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {
|
|
524
525
|
}
|
|
525
526
|
export declare const $ZodArray: core.$constructor<$ZodArray>;
|
|
526
527
|
type OptionalOutSchema = {
|
|
@@ -533,12 +534,12 @@ type OptionalInSchema = {
|
|
|
533
534
|
optin: "optional";
|
|
534
535
|
};
|
|
535
536
|
};
|
|
536
|
-
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? Record<string, unknown> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
537
|
+
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> : Record<string, core.output<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
537
538
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
|
|
538
539
|
} & {
|
|
539
540
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
|
|
540
541
|
} & Extra>;
|
|
541
|
-
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? Record<string, unknown> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
542
|
+
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> : Record<string, core.input<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
542
543
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
|
|
543
544
|
} & {
|
|
544
545
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
|
|
@@ -600,14 +601,17 @@ export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $Zo
|
|
|
600
601
|
}
|
|
601
602
|
type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
|
|
602
603
|
type IsOptionalOut<T extends SomeType> = T extends OptionalOutSchema ? true : false;
|
|
603
|
-
export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeInternals
|
|
604
|
+
export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends _$ZodTypeInternals {
|
|
604
605
|
def: $ZodUnionDef<T>;
|
|
605
606
|
isst: errors.$ZodIssueInvalidUnion;
|
|
606
607
|
pattern: T[number]["_zod"]["pattern"];
|
|
608
|
+
values: T[number]["_zod"]["values"];
|
|
609
|
+
output: $InferUnionOutput<T[number]>;
|
|
610
|
+
input: $InferUnionInput<T[number]>;
|
|
607
611
|
optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
|
|
608
612
|
optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
|
|
609
613
|
}
|
|
610
|
-
export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType {
|
|
614
|
+
export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType<any, any, $ZodUnionInternals<T>> {
|
|
611
615
|
_zod: $ZodUnionInternals<T>;
|
|
612
616
|
}
|
|
613
617
|
export declare const $ZodUnion: core.$constructor<$ZodUnion>;
|
|
@@ -631,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
|
|
631
635
|
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
|
|
632
636
|
def: $ZodIntersectionDef<A, B>;
|
|
633
637
|
isst: never;
|
|
638
|
+
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
|
639
|
+
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
|
634
640
|
}
|
|
635
641
|
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
636
642
|
_zod: $ZodIntersectionInternals<A, B>;
|
|
@@ -677,12 +683,17 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
|
|
|
677
683
|
keyType: Key;
|
|
678
684
|
valueType: Value;
|
|
679
685
|
}
|
|
680
|
-
export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> =
|
|
681
|
-
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> =
|
|
686
|
+
export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.output<Key>, core.output<Value>>> : Record<core.output<Key>, core.output<Value>>;
|
|
687
|
+
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.input<Key>, core.input<Value>>> : Record<core.input<Key>, core.input<Value>>;
|
|
682
688
|
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
|
|
683
689
|
def: $ZodRecordDef<Key, Value>;
|
|
684
690
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
|
|
691
|
+
optin?: "optional" | undefined;
|
|
692
|
+
optout?: "optional" | undefined;
|
|
685
693
|
}
|
|
694
|
+
export type $partial = {
|
|
695
|
+
"~~partial": true;
|
|
696
|
+
};
|
|
686
697
|
export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodType {
|
|
687
698
|
_zod: $ZodRecordInternals<Key, Value>;
|
|
688
699
|
}
|
|
@@ -695,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
|
|
|
695
706
|
export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
|
|
696
707
|
def: $ZodMapDef<Key, Value>;
|
|
697
708
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
|
|
709
|
+
optin?: "optional" | undefined;
|
|
710
|
+
optout?: "optional" | undefined;
|
|
698
711
|
}
|
|
699
712
|
export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
|
|
700
713
|
_zod: $ZodMapInternals<Key, Value>;
|
|
@@ -707,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
|
|
707
720
|
export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
|
|
708
721
|
def: $ZodSetDef<T>;
|
|
709
722
|
isst: errors.$ZodIssueInvalidType;
|
|
723
|
+
optin?: "optional" | undefined;
|
|
724
|
+
optout?: "optional" | undefined;
|
|
710
725
|
}
|
|
711
726
|
export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
|
|
712
727
|
_zod: $ZodSetInternals<T>;
|
|
@@ -819,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
819
834
|
export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
820
835
|
def: $ZodDefaultDef<T>;
|
|
821
836
|
optin: "optional";
|
|
837
|
+
optout?: "optional" | undefined;
|
|
822
838
|
isst: never;
|
|
823
839
|
values: T["_zod"]["values"];
|
|
824
840
|
}
|
|
@@ -835,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
835
851
|
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
836
852
|
def: $ZodPrefaultDef<T>;
|
|
837
853
|
optin: "optional";
|
|
854
|
+
optout?: "optional" | undefined;
|
|
838
855
|
isst: never;
|
|
839
856
|
values: T["_zod"]["values"];
|
|
840
857
|
}
|
|
@@ -850,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
|
|
|
850
867
|
def: $ZodNonOptionalDef<T>;
|
|
851
868
|
isst: errors.$ZodIssueInvalidType;
|
|
852
869
|
values: T["_zod"]["values"];
|
|
870
|
+
optin: "optional" | undefined;
|
|
871
|
+
optout: "optional" | undefined;
|
|
853
872
|
}
|
|
854
873
|
export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
855
874
|
_zod: $ZodNonOptionalInternals<T>;
|
|
@@ -862,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
862
881
|
export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
|
|
863
882
|
def: $ZodSuccessDef<T>;
|
|
864
883
|
isst: never;
|
|
884
|
+
optin: T["_zod"]["optin"];
|
|
885
|
+
optout: "optional" | undefined;
|
|
865
886
|
}
|
|
866
887
|
export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
|
|
867
888
|
_zod: $ZodSuccessInternals<T>;
|
|
@@ -928,6 +949,7 @@ export interface $ZodReadonlyInternals<T extends SomeType = $ZodType> extends $Z
|
|
|
928
949
|
optout: T["_zod"]["optout"];
|
|
929
950
|
isst: never;
|
|
930
951
|
propValues: T["_zod"]["propValues"];
|
|
952
|
+
values: T["_zod"]["values"];
|
|
931
953
|
}
|
|
932
954
|
export interface $ZodReadonly<T extends SomeType = $ZodType> extends $ZodType {
|
|
933
955
|
_zod: $ZodReadonlyInternals<T>;
|