zod 4.2.0-canary.20251207T223211 → 4.2.0-canary.20251213T203150

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 (39) hide show
  1. package/package.json +1 -1
  2. package/src/v4/classic/schemas.ts +97 -5
  3. package/src/v4/classic/tests/json.test.ts +4 -3
  4. package/src/v4/classic/tests/standard-schema.test.ts +77 -0
  5. package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  6. package/src/v4/classic/tests/to-json-schema.test.ts +66 -30
  7. package/src/v4/core/index.ts +2 -0
  8. package/src/v4/core/json-schema-generator.ts +124 -0
  9. package/src/v4/core/json-schema-processors.ts +630 -0
  10. package/src/v4/core/schemas.ts +8 -13
  11. package/src/v4/core/standard-schema.ts +114 -19
  12. package/src/v4/core/to-json-schema.ts +373 -827
  13. package/src/v4/mini/tests/standard-schema.test.ts +17 -0
  14. package/v4/classic/schemas.cjs +48 -0
  15. package/v4/classic/schemas.d.cts +35 -0
  16. package/v4/classic/schemas.d.ts +35 -0
  17. package/v4/classic/schemas.js +48 -0
  18. package/v4/core/index.cjs +5 -1
  19. package/v4/core/index.d.cts +2 -0
  20. package/v4/core/index.d.ts +2 -0
  21. package/v4/core/index.js +2 -0
  22. package/v4/core/json-schema-generator.cjs +99 -0
  23. package/v4/core/json-schema-generator.d.cts +64 -0
  24. package/v4/core/json-schema-generator.d.ts +64 -0
  25. package/v4/core/json-schema-generator.js +95 -0
  26. package/v4/core/json-schema-processors.cjs +617 -0
  27. package/v4/core/json-schema-processors.d.cts +49 -0
  28. package/v4/core/json-schema-processors.d.ts +49 -0
  29. package/v4/core/json-schema-processors.js +574 -0
  30. package/v4/core/schemas.cjs +0 -10
  31. package/v4/core/schemas.d.cts +4 -1
  32. package/v4/core/schemas.d.ts +4 -1
  33. package/v4/core/schemas.js +0 -10
  34. package/v4/core/standard-schema.d.cts +90 -19
  35. package/v4/core/standard-schema.d.ts +90 -19
  36. package/v4/core/to-json-schema.cjs +302 -793
  37. package/v4/core/to-json-schema.d.cts +56 -33
  38. package/v4/core/to-json-schema.d.ts +56 -33
  39. package/v4/core/to-json-schema.js +296 -791
@@ -72,16 +72,6 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
72
72
  }
73
73
  return payload;
74
74
  };
75
- // const handleChecksResult = (
76
- // checkResult: ParsePayload,
77
- // originalResult: ParsePayload,
78
- // ctx: ParseContextInternal
79
- // ): util.MaybeAsync<ParsePayload> => {
80
- // // if the checks mutated the value && there are no issues, re-parse the result
81
- // if (checkResult.value !== originalResult.value && !checkResult.issues.length)
82
- // return inst._zod.parse(checkResult, ctx);
83
- // return originalResult;
84
- // };
85
75
  const handleCanaryResult = (canary, payload, ctx) => {
86
76
  // abort if the canary is aborted
87
77
  if (util.aborted(canary)) {
@@ -1,29 +1,54 @@
1
- /** The Standard Schema interface. */
2
- export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
- /** The Standard Schema properties. */
4
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
1
+ /** The Standard interface. */
2
+ export interface StandardTypedV1<Input = unknown, Output = Input> {
3
+ /** The Standard properties. */
4
+ readonly "~standard": StandardTypedV1.Props<Input, Output>;
5
5
  }
6
- export declare namespace StandardSchemaV1 {
7
- /** The Standard Schema properties interface. */
6
+ export declare namespace StandardTypedV1 {
7
+ /** The Standard properties interface. */
8
8
  interface Props<Input = unknown, Output = Input> {
9
9
  /** The version number of the standard. */
10
10
  readonly version: 1;
11
11
  /** The vendor name of the schema library. */
12
12
  readonly vendor: string;
13
- /** Validates unknown input values. */
14
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
13
  /** Inferred types associated with the schema. */
16
14
  readonly types?: Types<Input, Output> | undefined;
17
15
  }
16
+ /** The Standard types interface. */
17
+ interface Types<Input = unknown, Output = Input> {
18
+ /** The input type of the schema. */
19
+ readonly input: Input;
20
+ /** The output type of the schema. */
21
+ readonly output: Output;
22
+ }
23
+ /** Infers the input type of a Standard. */
24
+ type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
25
+ /** Infers the output type of a Standard. */
26
+ type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
27
+ }
28
+ /** The Standard Schema interface. */
29
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
30
+ /** The Standard Schema properties. */
31
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
32
+ }
33
+ export declare namespace StandardSchemaV1 {
34
+ /** The Standard Schema properties interface. */
35
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
36
+ /** Validates unknown input values. */
37
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
38
+ }
18
39
  /** The result interface of the validate function. */
19
40
  type Result<Output> = SuccessResult<Output> | FailureResult;
20
41
  /** The result interface if validation succeeds. */
21
42
  interface SuccessResult<Output> {
22
43
  /** The typed output value. */
23
44
  readonly value: Output;
24
- /** The non-existent issues. */
45
+ /** The absence of issues indicates success. */
25
46
  readonly issues?: undefined;
26
47
  }
48
+ interface Options {
49
+ /** Implicit support for additional vendor-specific parameters, if needed. */
50
+ readonly libraryOptions?: Record<string, unknown> | undefined;
51
+ }
27
52
  /** The result interface if validation fails. */
28
53
  interface FailureResult {
29
54
  /** The issues of failed validation. */
@@ -41,15 +66,61 @@ export declare namespace StandardSchemaV1 {
41
66
  /** The key representing a path segment. */
42
67
  readonly key: PropertyKey;
43
68
  }
44
- /** The Standard Schema types interface. */
45
- interface Types<Input = unknown, Output = Input> {
46
- /** The input type of the schema. */
47
- readonly input: Input;
48
- /** The output type of the schema. */
49
- readonly output: Output;
69
+ /** The Standard types interface. */
70
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
71
+ }
72
+ /** Infers the input type of a Standard. */
73
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
74
+ /** Infers the output type of a Standard. */
75
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
76
+ }
77
+ /** The Standard JSON Schema interface. */
78
+ export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
79
+ /** The Standard JSON Schema properties. */
80
+ readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
81
+ }
82
+ export declare namespace StandardJSONSchemaV1 {
83
+ /** The Standard JSON Schema properties interface. */
84
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
85
+ /** Methods for generating the input/output JSON Schema. */
86
+ readonly jsonSchema: Converter;
87
+ }
88
+ /** The Standard JSON Schema converter interface. */
89
+ interface Converter {
90
+ /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
91
+ readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
92
+ /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
93
+ readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
50
94
  }
51
- /** Infers the input type of a Standard Schema. */
52
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
53
- /** Infers the output type of a Standard Schema. */
54
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
95
+ /** The target version of the generated JSON Schema.
96
+ *
97
+ * It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use.
98
+ *
99
+ * The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
100
+ *
101
+ * All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
102
+ */
103
+ type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
104
+ /** The options for the input/output methods. */
105
+ interface Options {
106
+ /** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
107
+ readonly target: Target;
108
+ /** Implicit support for additional vendor-specific parameters, if needed. */
109
+ readonly libraryOptions?: Record<string, unknown> | undefined;
110
+ }
111
+ /** The Standard types interface. */
112
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
113
+ }
114
+ /** Infers the input type of a Standard. */
115
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
116
+ /** Infers the output type of a Standard. */
117
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
118
+ }
119
+ export interface StandardSchemaWithJSONProps<Input = unknown, Output = Input> extends StandardSchemaV1.Props<Input, Output>, StandardJSONSchemaV1.Props<Input, Output> {
120
+ }
121
+ /**
122
+ * An interface that combines StandardJSONSchema and StandardSchema.
123
+ */
124
+ export interface StandardSchemaWithJSON<Input = unknown, Output = Input> {
125
+ "~standard": StandardSchemaWithJSONProps<Input, Output>;
55
126
  }
@@ -1,29 +1,54 @@
1
- /** The Standard Schema interface. */
2
- export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
- /** The Standard Schema properties. */
4
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
1
+ /** The Standard interface. */
2
+ export interface StandardTypedV1<Input = unknown, Output = Input> {
3
+ /** The Standard properties. */
4
+ readonly "~standard": StandardTypedV1.Props<Input, Output>;
5
5
  }
6
- export declare namespace StandardSchemaV1 {
7
- /** The Standard Schema properties interface. */
6
+ export declare namespace StandardTypedV1 {
7
+ /** The Standard properties interface. */
8
8
  interface Props<Input = unknown, Output = Input> {
9
9
  /** The version number of the standard. */
10
10
  readonly version: 1;
11
11
  /** The vendor name of the schema library. */
12
12
  readonly vendor: string;
13
- /** Validates unknown input values. */
14
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
13
  /** Inferred types associated with the schema. */
16
14
  readonly types?: Types<Input, Output> | undefined;
17
15
  }
16
+ /** The Standard types interface. */
17
+ interface Types<Input = unknown, Output = Input> {
18
+ /** The input type of the schema. */
19
+ readonly input: Input;
20
+ /** The output type of the schema. */
21
+ readonly output: Output;
22
+ }
23
+ /** Infers the input type of a Standard. */
24
+ type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
25
+ /** Infers the output type of a Standard. */
26
+ type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
27
+ }
28
+ /** The Standard Schema interface. */
29
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
30
+ /** The Standard Schema properties. */
31
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
32
+ }
33
+ export declare namespace StandardSchemaV1 {
34
+ /** The Standard Schema properties interface. */
35
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
36
+ /** Validates unknown input values. */
37
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
38
+ }
18
39
  /** The result interface of the validate function. */
19
40
  type Result<Output> = SuccessResult<Output> | FailureResult;
20
41
  /** The result interface if validation succeeds. */
21
42
  interface SuccessResult<Output> {
22
43
  /** The typed output value. */
23
44
  readonly value: Output;
24
- /** The non-existent issues. */
45
+ /** The absence of issues indicates success. */
25
46
  readonly issues?: undefined;
26
47
  }
48
+ interface Options {
49
+ /** Implicit support for additional vendor-specific parameters, if needed. */
50
+ readonly libraryOptions?: Record<string, unknown> | undefined;
51
+ }
27
52
  /** The result interface if validation fails. */
28
53
  interface FailureResult {
29
54
  /** The issues of failed validation. */
@@ -41,15 +66,61 @@ export declare namespace StandardSchemaV1 {
41
66
  /** The key representing a path segment. */
42
67
  readonly key: PropertyKey;
43
68
  }
44
- /** The Standard Schema types interface. */
45
- interface Types<Input = unknown, Output = Input> {
46
- /** The input type of the schema. */
47
- readonly input: Input;
48
- /** The output type of the schema. */
49
- readonly output: Output;
69
+ /** The Standard types interface. */
70
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
71
+ }
72
+ /** Infers the input type of a Standard. */
73
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
74
+ /** Infers the output type of a Standard. */
75
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
76
+ }
77
+ /** The Standard JSON Schema interface. */
78
+ export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
79
+ /** The Standard JSON Schema properties. */
80
+ readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
81
+ }
82
+ export declare namespace StandardJSONSchemaV1 {
83
+ /** The Standard JSON Schema properties interface. */
84
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
85
+ /** Methods for generating the input/output JSON Schema. */
86
+ readonly jsonSchema: Converter;
87
+ }
88
+ /** The Standard JSON Schema converter interface. */
89
+ interface Converter {
90
+ /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
91
+ readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
92
+ /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
93
+ readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
50
94
  }
51
- /** Infers the input type of a Standard Schema. */
52
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
53
- /** Infers the output type of a Standard Schema. */
54
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
95
+ /** The target version of the generated JSON Schema.
96
+ *
97
+ * It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use.
98
+ *
99
+ * The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
100
+ *
101
+ * All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
102
+ */
103
+ type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
104
+ /** The options for the input/output methods. */
105
+ interface Options {
106
+ /** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
107
+ readonly target: Target;
108
+ /** Implicit support for additional vendor-specific parameters, if needed. */
109
+ readonly libraryOptions?: Record<string, unknown> | undefined;
110
+ }
111
+ /** The Standard types interface. */
112
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
113
+ }
114
+ /** Infers the input type of a Standard. */
115
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
116
+ /** Infers the output type of a Standard. */
117
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
118
+ }
119
+ export interface StandardSchemaWithJSONProps<Input = unknown, Output = Input> extends StandardSchemaV1.Props<Input, Output>, StandardJSONSchemaV1.Props<Input, Output> {
120
+ }
121
+ /**
122
+ * An interface that combines StandardJSONSchema and StandardSchema.
123
+ */
124
+ export interface StandardSchemaWithJSON<Input = unknown, Output = Input> {
125
+ "~standard": StandardSchemaWithJSONProps<Input, Output>;
55
126
  }