zod 4.1.0-canary.20250821T014930 → 4.1.0-canary.20250823T064644

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.
Files changed (103) hide show
  1. package/package.json +1 -1
  2. package/src/v4/classic/external.ts +0 -1
  3. package/src/v4/classic/parse.ts +49 -0
  4. package/src/v4/classic/schemas.ts +145 -7
  5. package/src/v4/classic/tests/catch.test.ts +25 -0
  6. package/src/v4/classic/tests/codec-examples.test.ts +538 -0
  7. package/src/v4/classic/tests/codec.test.ts +532 -0
  8. package/src/v4/classic/tests/continuability.test.ts +1 -1
  9. package/src/v4/classic/tests/default.test.ts +32 -0
  10. package/src/v4/classic/tests/firstparty.test.ts +4 -0
  11. package/src/v4/classic/tests/function.test.ts +31 -31
  12. package/src/v4/classic/tests/hash.test.ts +68 -0
  13. package/src/v4/classic/tests/nonoptional.test.ts +15 -0
  14. package/src/v4/classic/tests/object.test.ts +31 -0
  15. package/src/v4/classic/tests/pipe.test.ts +25 -5
  16. package/src/v4/classic/tests/prefault.test.ts +25 -0
  17. package/src/v4/classic/tests/preprocess.test.ts +1 -6
  18. package/src/v4/classic/tests/refine.test.ts +76 -3
  19. package/src/v4/classic/tests/string-formats.test.ts +16 -0
  20. package/src/v4/classic/tests/string.test.ts +82 -1
  21. package/src/v4/classic/tests/stringbool.test.ts +40 -0
  22. package/src/v4/classic/tests/template-literal.test.ts +1 -1
  23. package/src/v4/classic/tests/to-json-schema.test.ts +21 -2
  24. package/src/v4/classic/tests/transform.test.ts +7 -0
  25. package/src/v4/classic/tests/union.test.ts +1 -1
  26. package/src/v4/core/api.ts +25 -35
  27. package/src/v4/core/core.ts +7 -26
  28. package/src/v4/core/index.ts +0 -1
  29. package/src/v4/core/json-schema.ts +1 -0
  30. package/src/v4/core/parse.ts +101 -0
  31. package/src/v4/core/regexes.ts +40 -1
  32. package/src/v4/core/schemas.ts +521 -129
  33. package/src/v4/core/to-json-schema.ts +43 -8
  34. package/src/v4/core/util.ts +73 -0
  35. package/src/v4/mini/external.ts +0 -1
  36. package/src/v4/mini/parse.ts +14 -1
  37. package/src/v4/mini/schemas.ts +153 -12
  38. package/src/v4/mini/tests/codec.test.ts +499 -0
  39. package/src/v4/mini/tests/object.test.ts +9 -0
  40. package/src/v4/mini/tests/string.test.ts +16 -0
  41. package/v4/classic/external.cjs +1 -2
  42. package/v4/classic/external.d.cts +1 -1
  43. package/v4/classic/external.d.ts +1 -1
  44. package/v4/classic/external.js +1 -1
  45. package/v4/classic/parse.cjs +10 -1
  46. package/v4/classic/parse.d.cts +8 -0
  47. package/v4/classic/parse.d.ts +8 -0
  48. package/v4/classic/parse.js +9 -0
  49. package/v4/classic/schemas.cjs +59 -4
  50. package/v4/classic/schemas.d.cts +48 -2
  51. package/v4/classic/schemas.d.ts +48 -2
  52. package/v4/classic/schemas.js +51 -3
  53. package/v4/core/api.cjs +19 -24
  54. package/v4/core/api.d.cts +3 -4
  55. package/v4/core/api.d.ts +3 -4
  56. package/v4/core/api.js +19 -24
  57. package/v4/core/core.cjs +8 -1
  58. package/v4/core/core.d.cts +3 -0
  59. package/v4/core/core.d.ts +3 -0
  60. package/v4/core/core.js +6 -0
  61. package/v4/core/index.cjs +0 -1
  62. package/v4/core/index.d.cts +0 -1
  63. package/v4/core/index.d.ts +0 -1
  64. package/v4/core/index.js +0 -1
  65. package/v4/core/json-schema.d.cts +1 -0
  66. package/v4/core/json-schema.d.ts +1 -0
  67. package/v4/core/parse.cjs +45 -1
  68. package/v4/core/parse.d.cts +24 -0
  69. package/v4/core/parse.d.ts +24 -0
  70. package/v4/core/parse.js +36 -0
  71. package/v4/core/regexes.cjs +34 -2
  72. package/v4/core/regexes.d.cts +16 -0
  73. package/v4/core/regexes.d.ts +16 -0
  74. package/v4/core/regexes.js +32 -1
  75. package/v4/core/schemas.cjs +309 -77
  76. package/v4/core/schemas.d.cts +61 -3
  77. package/v4/core/schemas.d.ts +61 -3
  78. package/v4/core/schemas.js +308 -76
  79. package/v4/core/to-json-schema.cjs +42 -5
  80. package/v4/core/to-json-schema.d.cts +4 -3
  81. package/v4/core/to-json-schema.d.ts +4 -3
  82. package/v4/core/to-json-schema.js +42 -5
  83. package/v4/core/util.cjs +69 -0
  84. package/v4/core/util.d.cts +10 -0
  85. package/v4/core/util.d.ts +10 -0
  86. package/v4/core/util.js +62 -0
  87. package/v4/mini/external.cjs +1 -2
  88. package/v4/mini/external.d.cts +1 -1
  89. package/v4/mini/external.d.ts +1 -1
  90. package/v4/mini/external.js +1 -1
  91. package/v4/mini/parse.cjs +9 -1
  92. package/v4/mini/parse.d.cts +1 -1
  93. package/v4/mini/parse.d.ts +1 -1
  94. package/v4/mini/parse.js +1 -1
  95. package/v4/mini/schemas.cjs +58 -3
  96. package/v4/mini/schemas.d.cts +49 -1
  97. package/v4/mini/schemas.d.ts +49 -1
  98. package/v4/mini/schemas.js +49 -2
  99. package/src/v4/core/function.ts +0 -176
  100. package/v4/core/function.cjs +0 -102
  101. package/v4/core/function.d.cts +0 -52
  102. package/v4/core/function.d.ts +0 -52
  103. package/v4/core/function.js +0 -75
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.$ZodFunction = void 0;
27
- exports.function = _function;
28
- const api_js_1 = require("./api.cjs");
29
- const parse_js_1 = require("./parse.cjs");
30
- const schemas = __importStar(require("./schemas.cjs"));
31
- const schemas_js_1 = require("./schemas.cjs");
32
- class $ZodFunction {
33
- constructor(def) {
34
- this._def = def;
35
- this.def = def;
36
- }
37
- implement(func) {
38
- if (typeof func !== "function") {
39
- throw new Error("implement() must be called with a function");
40
- }
41
- const impl = ((...args) => {
42
- const parsedArgs = this._def.input ? (0, parse_js_1.parse)(this._def.input, args, undefined, { callee: impl }) : args;
43
- if (!Array.isArray(parsedArgs)) {
44
- throw new Error("Invalid arguments schema: not an array or tuple schema.");
45
- }
46
- const output = func(...parsedArgs);
47
- return this._def.output ? (0, parse_js_1.parse)(this._def.output, output, undefined, { callee: impl }) : output;
48
- });
49
- return impl;
50
- }
51
- implementAsync(func) {
52
- if (typeof func !== "function") {
53
- throw new Error("implement() must be called with a function");
54
- }
55
- const impl = (async (...args) => {
56
- const parsedArgs = this._def.input ? await (0, parse_js_1.parseAsync)(this._def.input, args, undefined, { callee: impl }) : args;
57
- if (!Array.isArray(parsedArgs)) {
58
- throw new Error("Invalid arguments schema: not an array or tuple schema.");
59
- }
60
- const output = await func(...parsedArgs);
61
- return this._def.output ? (0, parse_js_1.parseAsync)(this._def.output, output, undefined, { callee: impl }) : output;
62
- });
63
- return impl;
64
- }
65
- input(...args) {
66
- const F = this.constructor;
67
- if (Array.isArray(args[0])) {
68
- return new F({
69
- type: "function",
70
- input: new schemas_js_1.$ZodTuple({
71
- type: "tuple",
72
- items: args[0],
73
- rest: args[1],
74
- }),
75
- output: this._def.output,
76
- });
77
- }
78
- return new F({
79
- type: "function",
80
- input: args[0],
81
- output: this._def.output,
82
- });
83
- }
84
- output(output) {
85
- const F = this.constructor;
86
- return new F({
87
- type: "function",
88
- input: this._def.input,
89
- output,
90
- });
91
- }
92
- }
93
- exports.$ZodFunction = $ZodFunction;
94
- function _function(params) {
95
- return new $ZodFunction({
96
- type: "function",
97
- input: Array.isArray(params?.input)
98
- ? (0, api_js_1._tuple)(schemas.$ZodTuple, params?.input)
99
- : (params?.input ?? (0, api_js_1._array)(schemas.$ZodArray, (0, api_js_1._unknown)(schemas.$ZodUnknown))),
100
- output: params?.output ?? (0, api_js_1._unknown)(schemas.$ZodUnknown),
101
- });
102
- }
@@ -1,52 +0,0 @@
1
- import type * as core from "./core.cjs";
2
- import * as schemas from "./schemas.cjs";
3
- import { $ZodTuple } from "./schemas.cjs";
4
- import type * as util from "./util.cjs";
5
- export interface $ZodFunctionDef<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends $ZodFunctionOut = $ZodFunctionOut> {
6
- type: "function";
7
- input: In;
8
- output: Out;
9
- }
10
- export type $ZodFunctionArgs = schemas.$ZodType<unknown[], unknown[]>;
11
- export type $ZodFunctionIn = $ZodFunctionArgs;
12
- export type $ZodFunctionOut = schemas.$ZodType;
13
- export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => core.input<Returns>;
14
- export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => util.MaybeAsync<core.input<Returns>>;
15
- export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => core.output<Returns>;
16
- export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => util.MaybeAsync<core.output<Returns>>;
17
- export declare class $ZodFunction<Args extends $ZodFunctionIn = $ZodFunctionIn, Returns extends $ZodFunctionOut = $ZodFunctionOut> {
18
- def: $ZodFunctionDef<Args, Returns>;
19
- /** @deprecated */
20
- _def: $ZodFunctionDef<Args, Returns>;
21
- _input: $InferInnerFunctionType<Args, Returns>;
22
- _output: $InferOuterFunctionType<Args, Returns>;
23
- constructor(def: $ZodFunctionDef<Args, Returns>);
24
- implement<F extends $InferInnerFunctionType<Args, Returns>>(func: F): (...args: Parameters<this["_output"]>) => ReturnType<F> extends ReturnType<this["_output"]> ? ReturnType<F> : ReturnType<this["_output"]>;
25
- implementAsync<F extends $InferInnerFunctionTypeAsync<Args, Returns>>(func: F): F extends $InferOuterFunctionTypeAsync<Args, Returns> ? F : $InferOuterFunctionTypeAsync<Args, Returns>;
26
- input<const Items extends util.TupleItems, const Rest extends $ZodFunctionOut = $ZodFunctionOut>(args: Items, rest?: Rest): $ZodFunction<schemas.$ZodTuple<Items, Rest>, Returns>;
27
- input<NewArgs extends $ZodFunctionIn>(args: NewArgs): $ZodFunction<NewArgs, Returns>;
28
- output<NewReturns extends schemas.$ZodType>(output: NewReturns): $ZodFunction<Args, NewReturns>;
29
- }
30
- export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends schemas.$ZodType> {
31
- input?: I;
32
- output?: O;
33
- }
34
- declare function _function(): $ZodFunction;
35
- declare function _function<const In extends Array<schemas.$ZodType> = Array<schemas.$ZodType>>(params: {
36
- input: In;
37
- }): $ZodFunction<$ZodTuple<In, null>, $ZodFunctionOut>;
38
- declare function _function<const In extends Array<schemas.$ZodType> = Array<schemas.$ZodType>, const Out extends $ZodFunctionOut = $ZodFunctionOut>(params: {
39
- input: In;
40
- output: Out;
41
- }): $ZodFunction<$ZodTuple<In, null>, Out>;
42
- declare function _function<const In extends $ZodFunctionIn = $ZodFunctionIn>(params: {
43
- input: In;
44
- }): $ZodFunction<In, $ZodFunctionOut>;
45
- declare function _function<const Out extends $ZodFunctionOut = $ZodFunctionOut>(params: {
46
- output: Out;
47
- }): $ZodFunction<$ZodFunctionIn, Out>;
48
- declare function _function<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends schemas.$ZodType = schemas.$ZodType>(params?: {
49
- input: In;
50
- output: Out;
51
- }): $ZodFunction<In, Out>;
52
- export { _function as function };
@@ -1,52 +0,0 @@
1
- import type * as core from "./core.js";
2
- import * as schemas from "./schemas.js";
3
- import { $ZodTuple } from "./schemas.js";
4
- import type * as util from "./util.js";
5
- export interface $ZodFunctionDef<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends $ZodFunctionOut = $ZodFunctionOut> {
6
- type: "function";
7
- input: In;
8
- output: Out;
9
- }
10
- export type $ZodFunctionArgs = schemas.$ZodType<unknown[], unknown[]>;
11
- export type $ZodFunctionIn = $ZodFunctionArgs;
12
- export type $ZodFunctionOut = schemas.$ZodType;
13
- export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => core.input<Returns>;
14
- export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => util.MaybeAsync<core.input<Returns>>;
15
- export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => core.output<Returns>;
16
- export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => util.MaybeAsync<core.output<Returns>>;
17
- export declare class $ZodFunction<Args extends $ZodFunctionIn = $ZodFunctionIn, Returns extends $ZodFunctionOut = $ZodFunctionOut> {
18
- def: $ZodFunctionDef<Args, Returns>;
19
- /** @deprecated */
20
- _def: $ZodFunctionDef<Args, Returns>;
21
- _input: $InferInnerFunctionType<Args, Returns>;
22
- _output: $InferOuterFunctionType<Args, Returns>;
23
- constructor(def: $ZodFunctionDef<Args, Returns>);
24
- implement<F extends $InferInnerFunctionType<Args, Returns>>(func: F): (...args: Parameters<this["_output"]>) => ReturnType<F> extends ReturnType<this["_output"]> ? ReturnType<F> : ReturnType<this["_output"]>;
25
- implementAsync<F extends $InferInnerFunctionTypeAsync<Args, Returns>>(func: F): F extends $InferOuterFunctionTypeAsync<Args, Returns> ? F : $InferOuterFunctionTypeAsync<Args, Returns>;
26
- input<const Items extends util.TupleItems, const Rest extends $ZodFunctionOut = $ZodFunctionOut>(args: Items, rest?: Rest): $ZodFunction<schemas.$ZodTuple<Items, Rest>, Returns>;
27
- input<NewArgs extends $ZodFunctionIn>(args: NewArgs): $ZodFunction<NewArgs, Returns>;
28
- output<NewReturns extends schemas.$ZodType>(output: NewReturns): $ZodFunction<Args, NewReturns>;
29
- }
30
- export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends schemas.$ZodType> {
31
- input?: I;
32
- output?: O;
33
- }
34
- declare function _function(): $ZodFunction;
35
- declare function _function<const In extends Array<schemas.$ZodType> = Array<schemas.$ZodType>>(params: {
36
- input: In;
37
- }): $ZodFunction<$ZodTuple<In, null>, $ZodFunctionOut>;
38
- declare function _function<const In extends Array<schemas.$ZodType> = Array<schemas.$ZodType>, const Out extends $ZodFunctionOut = $ZodFunctionOut>(params: {
39
- input: In;
40
- output: Out;
41
- }): $ZodFunction<$ZodTuple<In, null>, Out>;
42
- declare function _function<const In extends $ZodFunctionIn = $ZodFunctionIn>(params: {
43
- input: In;
44
- }): $ZodFunction<In, $ZodFunctionOut>;
45
- declare function _function<const Out extends $ZodFunctionOut = $ZodFunctionOut>(params: {
46
- output: Out;
47
- }): $ZodFunction<$ZodFunctionIn, Out>;
48
- declare function _function<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends schemas.$ZodType = schemas.$ZodType>(params?: {
49
- input: In;
50
- output: Out;
51
- }): $ZodFunction<In, Out>;
52
- export { _function as function };
@@ -1,75 +0,0 @@
1
- import { _array, _tuple, _unknown } from "./api.js";
2
- import { parse, parseAsync } from "./parse.js";
3
- import * as schemas from "./schemas.js";
4
- import { $ZodTuple } from "./schemas.js";
5
- export class $ZodFunction {
6
- constructor(def) {
7
- this._def = def;
8
- this.def = def;
9
- }
10
- implement(func) {
11
- if (typeof func !== "function") {
12
- throw new Error("implement() must be called with a function");
13
- }
14
- const impl = ((...args) => {
15
- const parsedArgs = this._def.input ? parse(this._def.input, args, undefined, { callee: impl }) : args;
16
- if (!Array.isArray(parsedArgs)) {
17
- throw new Error("Invalid arguments schema: not an array or tuple schema.");
18
- }
19
- const output = func(...parsedArgs);
20
- return this._def.output ? parse(this._def.output, output, undefined, { callee: impl }) : output;
21
- });
22
- return impl;
23
- }
24
- implementAsync(func) {
25
- if (typeof func !== "function") {
26
- throw new Error("implement() must be called with a function");
27
- }
28
- const impl = (async (...args) => {
29
- const parsedArgs = this._def.input ? await parseAsync(this._def.input, args, undefined, { callee: impl }) : args;
30
- if (!Array.isArray(parsedArgs)) {
31
- throw new Error("Invalid arguments schema: not an array or tuple schema.");
32
- }
33
- const output = await func(...parsedArgs);
34
- return this._def.output ? parseAsync(this._def.output, output, undefined, { callee: impl }) : output;
35
- });
36
- return impl;
37
- }
38
- input(...args) {
39
- const F = this.constructor;
40
- if (Array.isArray(args[0])) {
41
- return new F({
42
- type: "function",
43
- input: new $ZodTuple({
44
- type: "tuple",
45
- items: args[0],
46
- rest: args[1],
47
- }),
48
- output: this._def.output,
49
- });
50
- }
51
- return new F({
52
- type: "function",
53
- input: args[0],
54
- output: this._def.output,
55
- });
56
- }
57
- output(output) {
58
- const F = this.constructor;
59
- return new F({
60
- type: "function",
61
- input: this._def.input,
62
- output,
63
- });
64
- }
65
- }
66
- function _function(params) {
67
- return new $ZodFunction({
68
- type: "function",
69
- input: Array.isArray(params?.input)
70
- ? _tuple(schemas.$ZodTuple, params?.input)
71
- : (params?.input ?? _array(schemas.$ZodArray, _unknown(schemas.$ZodUnknown))),
72
- output: params?.output ?? _unknown(schemas.$ZodUnknown),
73
- });
74
- }
75
- export { _function as function };