zod 4.2.0-canary.20251202T062120 → 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 (43) hide show
  1. package/package.json +1 -1
  2. package/src/v4/classic/schemas.ts +97 -5
  3. package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  4. package/src/v4/classic/tests/json.test.ts +4 -3
  5. package/src/v4/classic/tests/standard-schema.test.ts +77 -0
  6. package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  7. package/src/v4/classic/tests/to-json-schema.test.ts +66 -30
  8. package/src/v4/core/index.ts +2 -0
  9. package/src/v4/core/json-schema-generator.ts +124 -0
  10. package/src/v4/core/json-schema-processors.ts +630 -0
  11. package/src/v4/core/schemas.ts +8 -13
  12. package/src/v4/core/standard-schema.ts +114 -19
  13. package/src/v4/core/to-json-schema.ts +373 -827
  14. package/src/v4/mini/schemas.ts +2 -2
  15. package/src/v4/mini/tests/standard-schema.test.ts +17 -0
  16. package/v4/classic/schemas.cjs +48 -0
  17. package/v4/classic/schemas.d.cts +35 -0
  18. package/v4/classic/schemas.d.ts +35 -0
  19. package/v4/classic/schemas.js +48 -0
  20. package/v4/core/index.cjs +5 -1
  21. package/v4/core/index.d.cts +2 -0
  22. package/v4/core/index.d.ts +2 -0
  23. package/v4/core/index.js +2 -0
  24. package/v4/core/json-schema-generator.cjs +99 -0
  25. package/v4/core/json-schema-generator.d.cts +64 -0
  26. package/v4/core/json-schema-generator.d.ts +64 -0
  27. package/v4/core/json-schema-generator.js +95 -0
  28. package/v4/core/json-schema-processors.cjs +617 -0
  29. package/v4/core/json-schema-processors.d.cts +49 -0
  30. package/v4/core/json-schema-processors.d.ts +49 -0
  31. package/v4/core/json-schema-processors.js +574 -0
  32. package/v4/core/schemas.cjs +0 -10
  33. package/v4/core/schemas.d.cts +4 -1
  34. package/v4/core/schemas.d.ts +4 -1
  35. package/v4/core/schemas.js +0 -10
  36. package/v4/core/standard-schema.d.cts +90 -19
  37. package/v4/core/standard-schema.d.ts +90 -19
  38. package/v4/core/to-json-schema.cjs +302 -793
  39. package/v4/core/to-json-schema.d.cts +56 -33
  40. package/v4/core/to-json-schema.d.ts +56 -33
  41. package/v4/core/to-json-schema.js +296 -791
  42. package/v4/mini/schemas.d.cts +2 -2
  43. package/v4/mini/schemas.d.ts +2 -2
@@ -1,22 +1,51 @@
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
6
 
7
- export declare namespace StandardSchemaV1 {
8
- /** The Standard Schema properties interface. */
7
+ export declare namespace StandardTypedV1 {
8
+ /** The Standard properties interface. */
9
9
  export interface Props<Input = unknown, Output = Input> {
10
10
  /** The version number of the standard. */
11
11
  readonly version: 1;
12
12
  /** The vendor name of the schema library. */
13
13
  readonly vendor: string;
14
- /** Validates unknown input values. */
15
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
16
14
  /** Inferred types associated with the schema. */
17
15
  readonly types?: Types<Input, Output> | undefined;
18
16
  }
19
17
 
18
+ /** The Standard types interface. */
19
+ export interface Types<Input = unknown, Output = Input> {
20
+ /** The input type of the schema. */
21
+ readonly input: Input;
22
+ /** The output type of the schema. */
23
+ readonly output: Output;
24
+ }
25
+
26
+ /** Infers the input type of a Standard. */
27
+ export type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
28
+
29
+ /** Infers the output type of a Standard. */
30
+ export type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
31
+ }
32
+
33
+ /** The Standard Schema interface. */
34
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
35
+ /** The Standard Schema properties. */
36
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
37
+ }
38
+
39
+ export declare namespace StandardSchemaV1 {
40
+ /** The Standard Schema properties interface. */
41
+ export interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
42
+ /** Validates unknown input values. */
43
+ readonly validate: (
44
+ value: unknown,
45
+ options?: StandardSchemaV1.Options | undefined
46
+ ) => Result<Output> | Promise<Result<Output>>;
47
+ }
48
+
20
49
  /** The result interface of the validate function. */
21
50
  export type Result<Output> = SuccessResult<Output> | FailureResult;
22
51
 
@@ -24,10 +53,15 @@ export declare namespace StandardSchemaV1 {
24
53
  export interface SuccessResult<Output> {
25
54
  /** The typed output value. */
26
55
  readonly value: Output;
27
- /** The non-existent issues. */
56
+ /** The absence of issues indicates success. */
28
57
  readonly issues?: undefined;
29
58
  }
30
59
 
60
+ export interface Options {
61
+ /** Implicit support for additional vendor-specific parameters, if needed. */
62
+ readonly libraryOptions?: Record<string, unknown> | undefined;
63
+ }
64
+
31
65
  /** The result interface if validation fails. */
32
66
  export interface FailureResult {
33
67
  /** The issues of failed validation. */
@@ -48,17 +82,78 @@ export declare namespace StandardSchemaV1 {
48
82
  readonly key: PropertyKey;
49
83
  }
50
84
 
51
- /** The Standard Schema types interface. */
52
- export interface Types<Input = unknown, Output = Input> {
53
- /** The input type of the schema. */
54
- readonly input: Input;
55
- /** The output type of the schema. */
56
- readonly output: Output;
85
+ /** The Standard types interface. */
86
+ export interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
87
+
88
+ /** Infers the input type of a Standard. */
89
+ export type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
90
+
91
+ /** Infers the output type of a Standard. */
92
+ export type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
93
+ }
94
+
95
+ /** The Standard JSON Schema interface. */
96
+ export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
97
+ /** The Standard JSON Schema properties. */
98
+ readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
99
+ }
100
+
101
+ export declare namespace StandardJSONSchemaV1 {
102
+ /** The Standard JSON Schema properties interface. */
103
+ export interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
104
+ /** Methods for generating the input/output JSON Schema. */
105
+ readonly jsonSchema: Converter;
106
+ }
107
+
108
+ /** The Standard JSON Schema converter interface. */
109
+ export interface Converter {
110
+ /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
111
+ readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
112
+ /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
113
+ readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
114
+ }
115
+
116
+ /** The target version of the generated JSON Schema.
117
+ *
118
+ * It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use.
119
+ *
120
+ * The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
121
+ *
122
+ * All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
123
+ */
124
+ export type Target =
125
+ | "draft-2020-12"
126
+ | "draft-07"
127
+ | "openapi-3.0"
128
+ // Accepts any string for future targets while preserving autocomplete
129
+ | ({} & string);
130
+
131
+ /** The options for the input/output methods. */
132
+ export interface Options {
133
+ /** 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. */
134
+ readonly target: Target;
135
+
136
+ /** Implicit support for additional vendor-specific parameters, if needed. */
137
+ readonly libraryOptions?: Record<string, unknown> | undefined;
57
138
  }
58
139
 
59
- /** Infers the input type of a Standard Schema. */
60
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
140
+ /** The Standard types interface. */
141
+ export interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
142
+
143
+ /** Infers the input type of a Standard. */
144
+ export type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
145
+
146
+ /** Infers the output type of a Standard. */
147
+ export type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
148
+ }
149
+
150
+ export interface StandardSchemaWithJSONProps<Input = unknown, Output = Input>
151
+ extends StandardSchemaV1.Props<Input, Output>,
152
+ StandardJSONSchemaV1.Props<Input, Output> {}
61
153
 
62
- /** Infers the output type of a Standard Schema. */
63
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
154
+ /**
155
+ * An interface that combines StandardJSONSchema and StandardSchema.
156
+ */
157
+ export interface StandardSchemaWithJSON<Input = unknown, Output = Input> {
158
+ "~standard": StandardSchemaWithJSONProps<Input, Output>;
64
159
  }