Leon4gr45 commited on
Commit
28334c8
·
verified ·
1 Parent(s): c9fa884

Upload folder using huggingface_hub (part 19)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4-mini/index.ts +1 -0
  3. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/array.test.ts +264 -0
  4. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/assignability.test.ts +210 -0
  5. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  6. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  7. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
  8. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/bigint.test.ts +54 -0
  9. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/brand.test.ts +63 -0
  10. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/catch.test.ts +252 -0
  11. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  12. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  13. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/continuability.test.ts +352 -0
  14. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
  15. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/date.test.ts +31 -0
  16. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/datetime.test.ts +296 -0
  17. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/default.test.ts +313 -0
  18. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
  19. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +619 -0
  20. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/enum.test.ts +285 -0
  21. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +527 -0
  22. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/error.test.ts +711 -0
  23. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/file.test.ts +91 -0
  24. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +175 -0
  25. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/function.test.ts +268 -0
  26. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
  27. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/index.test.ts +829 -0
  28. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +34 -0
  29. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/intersection.test.ts +171 -0
  30. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/json.test.ts +108 -0
  31. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/lazy.test.ts +227 -0
  32. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/literal.test.ts +92 -0
  33. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/map.test.ts +196 -0
  34. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
  35. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  36. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +86 -0
  37. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  38. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/number.test.ts +247 -0
  39. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/object.test.ts +563 -0
  40. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/optional.test.ts +123 -0
  41. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/partial.test.ts +147 -0
  42. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +127 -0
  43. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/pipe.test.ts +81 -0
  44. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/prefault.test.ts +37 -0
  45. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +298 -0
  46. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  47. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
  48. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  49. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/readonly.test.ts +252 -0
  50. node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/record.test.ts +342 -0
.gitattributes CHANGED
@@ -36,3 +36,4 @@ node_modules/@jimp/plugin-print/dist/fonts/open-sans/open-sans-128-black/open-sa
36
  node_modules/@jimp/plugin-print/dist/fonts/open-sans/open-sans-128-white/open-sans-128-white.png filter=lfs diff=lfs merge=lfs -text
37
  node_modules/@jimp/plugin-print/fonts/open-sans/open-sans-128-black/open-sans-128-black.png filter=lfs diff=lfs merge=lfs -text
38
  node_modules/@jimp/plugin-print/fonts/open-sans/open-sans-128-white/open-sans-128-white.png filter=lfs diff=lfs merge=lfs -text
 
 
36
  node_modules/@jimp/plugin-print/dist/fonts/open-sans/open-sans-128-white/open-sans-128-white.png filter=lfs diff=lfs merge=lfs -text
37
  node_modules/@jimp/plugin-print/fonts/open-sans/open-sans-128-black/open-sans-128-black.png filter=lfs diff=lfs merge=lfs -text
38
  node_modules/@jimp/plugin-print/fonts/open-sans/open-sans-128-white/open-sans-128-white.png filter=lfs diff=lfs merge=lfs -text
39
+ node_modules/@jimp/plugin-threshold/src/__image_snapshots__/index-test-ts-src-index-test-ts-threshold-defines-default-threshold-for-lighter-backgrounds-1-snap.png filter=lfs diff=lfs merge=lfs -text
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4-mini/index.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export * from "../v4/mini/index.js";
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/array.test.ts ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("type inference", () => {
5
+ const schema = z.string().array();
6
+ expectTypeOf<z.infer<typeof schema>>().toEqualTypeOf<string[]>();
7
+ });
8
+
9
+ test("array min/max", async () => {
10
+ const schema = z.array(z.string()).min(2).max(2);
11
+ const r1 = await schema.safeParse(["asdf"]);
12
+ expect(r1.success).toEqual(false);
13
+ expect(r1.error!.issues).toMatchInlineSnapshot(`
14
+ [
15
+ {
16
+ "code": "too_small",
17
+ "inclusive": true,
18
+ "message": "Too small: expected array to have >=2 items",
19
+ "minimum": 2,
20
+ "origin": "array",
21
+ "path": [],
22
+ },
23
+ ]
24
+ `);
25
+
26
+ const r2 = await schema.safeParse(["asdf", "asdf", "asdf"]);
27
+ expect(r2.success).toEqual(false);
28
+ expect(r2.error!.issues).toMatchInlineSnapshot(`
29
+ [
30
+ {
31
+ "code": "too_big",
32
+ "inclusive": true,
33
+ "maximum": 2,
34
+ "message": "Too big: expected array to have <=2 items",
35
+ "origin": "array",
36
+ "path": [],
37
+ },
38
+ ]
39
+ `);
40
+ });
41
+
42
+ test("array length", async () => {
43
+ const schema = z.array(z.string()).length(2);
44
+ schema.parse(["asdf", "asdf"]);
45
+
46
+ const r1 = await schema.safeParse(["asdf"]);
47
+ expect(r1.success).toEqual(false);
48
+ expect(r1.error!.issues).toMatchInlineSnapshot(`
49
+ [
50
+ {
51
+ "code": "too_small",
52
+ "exact": true,
53
+ "inclusive": true,
54
+ "message": "Too small: expected array to have >=2 items",
55
+ "minimum": 2,
56
+ "origin": "array",
57
+ "path": [],
58
+ },
59
+ ]
60
+ `);
61
+
62
+ const r2 = await schema.safeParse(["asdf", "asdf", "asdf"]);
63
+ expect(r2.success).toEqual(false);
64
+ expect(r2.error!.issues).toMatchInlineSnapshot(`
65
+ [
66
+ {
67
+ "code": "too_big",
68
+ "exact": true,
69
+ "inclusive": true,
70
+ "maximum": 2,
71
+ "message": "Too big: expected array to have <=2 items",
72
+ "origin": "array",
73
+ "path": [],
74
+ },
75
+ ]
76
+ `);
77
+ });
78
+
79
+ test("array.nonempty()", () => {
80
+ const schema = z.string().array().nonempty();
81
+ schema.parse(["a"]);
82
+ expect(() => schema.parse([])).toThrow();
83
+ });
84
+
85
+ test("array.nonempty().max()", () => {
86
+ const schema = z.string().array().nonempty().max(2);
87
+ schema.parse(["a"]);
88
+ expect(() => schema.parse([])).toThrow();
89
+ expect(() => schema.parse(["a", "a", "a"])).toThrow();
90
+ });
91
+
92
+ test("parse empty array in nonempty", () => {
93
+ expect(() =>
94
+ z
95
+ .array(z.string())
96
+ .nonempty()
97
+ .parse([] as any)
98
+ ).toThrow();
99
+ });
100
+
101
+ test("get element", () => {
102
+ const schema = z.string().array();
103
+ schema.element.parse("asdf");
104
+ expect(() => schema.element.parse(12)).toThrow();
105
+ });
106
+
107
+ test("continue parsing despite array size error", () => {
108
+ const schema = z.object({
109
+ people: z.string().array().min(2),
110
+ });
111
+
112
+ const result = schema.safeParse({
113
+ people: [123],
114
+ });
115
+ expect(result).toMatchInlineSnapshot(`
116
+ {
117
+ "error": [ZodError: [
118
+ {
119
+ "expected": "string",
120
+ "code": "invalid_type",
121
+ "path": [
122
+ "people",
123
+ 0
124
+ ],
125
+ "message": "Invalid input: expected string, received number"
126
+ },
127
+ {
128
+ "origin": "array",
129
+ "code": "too_small",
130
+ "minimum": 2,
131
+ "inclusive": true,
132
+ "path": [
133
+ "people"
134
+ ],
135
+ "message": "Too small: expected array to have >=2 items"
136
+ }
137
+ ]],
138
+ "success": false,
139
+ }
140
+ `);
141
+ });
142
+
143
+ test("parse should fail given sparse array", () => {
144
+ const schema = z.array(z.string()).nonempty().min(1).max(3);
145
+ const result = schema.safeParse(new Array(3));
146
+ expect(result.success).toEqual(false);
147
+ expect(result).toMatchInlineSnapshot(`
148
+ {
149
+ "error": [ZodError: [
150
+ {
151
+ "expected": "string",
152
+ "code": "invalid_type",
153
+ "path": [
154
+ 0
155
+ ],
156
+ "message": "Invalid input: expected string, received undefined"
157
+ },
158
+ {
159
+ "expected": "string",
160
+ "code": "invalid_type",
161
+ "path": [
162
+ 1
163
+ ],
164
+ "message": "Invalid input: expected string, received undefined"
165
+ },
166
+ {
167
+ "expected": "string",
168
+ "code": "invalid_type",
169
+ "path": [
170
+ 2
171
+ ],
172
+ "message": "Invalid input: expected string, received undefined"
173
+ }
174
+ ]],
175
+ "success": false,
176
+ }
177
+ `);
178
+ });
179
+
180
+ // const unique = z.string().array().unique();
181
+ // const uniqueArrayOfObjects = z.array(z.object({ name: z.string() })).unique({ identifier: (item) => item.name });
182
+
183
+ // test("passing unique validation", () => {
184
+ // unique.parse(["a", "b", "c"]);
185
+ // uniqueArrayOfObjects.parse([{ name: "Leo" }, { name: "Joe" }]);
186
+ // });
187
+
188
+ // test("failing unique validation", () => {
189
+ // expect(() => unique.parse(["a", "a", "b"])).toThrow();
190
+ // expect(() => uniqueArrayOfObjects.parse([{ name: "Leo" }, { name: "Leo" }])).toThrow();
191
+ // });
192
+
193
+ // test("continue parsing despite array of primitives uniqueness error", () => {
194
+ // const schema = z.number().array().unique();
195
+
196
+ // const result = schema.safeParse([1, 1, 2, 2, 3]);
197
+
198
+ // expect(result.success).toEqual(false);
199
+ // if (!result.success) {
200
+ // const issue = result.error.issues.find(({ code }) => code === "not_unique");
201
+ // expect(issue?.message).toEqual("Values must be unique");
202
+ // }
203
+ // });
204
+
205
+ // test("continue parsing despite array of objects not_unique error", () => {
206
+ // const schema = z.array(z.object({ name: z.string() })).unique({
207
+ // identifier: (item) => item.name,
208
+ // showDuplicates: true,
209
+ // });
210
+
211
+ // const result = schema.safeParse([
212
+ // { name: "Leo" },
213
+ // { name: "Joe" },
214
+ // { name: "Leo" },
215
+ // ]);
216
+
217
+ // expect(result.success).toEqual(false);
218
+ // if (!result.success) {
219
+ // const issue = result.error.issues.find(({ code }) => code === "not_unique");
220
+ // expect(issue?.message).toEqual("Element(s): 'Leo' not unique");
221
+ // }
222
+ // });
223
+
224
+ // test("returns custom error message without duplicate elements", () => {
225
+ // const schema = z.number().array().unique({ message: "Custom message" });
226
+
227
+ // const result = schema.safeParse([1, 1, 2, 2, 3]);
228
+
229
+ // expect(result.success).toEqual(false);
230
+ // if (!result.success) {
231
+ // const issue = result.error.issues.find(({ code }) => code === "not_unique");
232
+ // expect(issue?.message).toEqual("Custom message");
233
+ // }
234
+ // });
235
+
236
+ // test("returns error message with duplicate elements", () => {
237
+ // const schema = z.number().array().unique({ showDuplicates: true });
238
+
239
+ // const result = schema.safeParse([1, 1, 2, 2, 3]);
240
+
241
+ // expect(result.success).toEqual(false);
242
+ // if (!result.success) {
243
+ // const issue = result.error.issues.find(({ code }) => code === "not_unique");
244
+ // expect(issue?.message).toEqual("Element(s): '1,2' not unique");
245
+ // }
246
+ // });
247
+
248
+ // test("returns custom error message with duplicate elements", () => {
249
+ // const schema = z
250
+ // .number()
251
+ // .array()
252
+ // .unique({
253
+ // message: (item) => `Custom message: '${item}' are not unique`,
254
+ // showDuplicates: true,
255
+ // });
256
+
257
+ // const result = schema.safeParse([1, 1, 2, 2, 3]);
258
+
259
+ // expect(result.success).toEqual(false);
260
+ // if (!result.success) {
261
+ // const issue = result.error.issues.find(({ code }) => code === "not_unique");
262
+ // expect(issue?.message).toEqual("Custom message: '1,2' are not unique");
263
+ // }
264
+ // });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/assignability.test.ts ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expectTypeOf, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("assignability", () => {
6
+ // $ZodString
7
+ z.string() satisfies z.core.$ZodString;
8
+ z.string() satisfies z.ZodString;
9
+
10
+ // $ZodNumber
11
+ z.number() satisfies z.core.$ZodNumber;
12
+ z.number() satisfies z.ZodNumber;
13
+
14
+ // $ZodBigInt
15
+ z.bigint() satisfies z.core.$ZodBigInt;
16
+ z.bigint() satisfies z.ZodBigInt;
17
+
18
+ // $ZodBoolean
19
+ z.boolean() satisfies z.core.$ZodBoolean;
20
+ z.boolean() satisfies z.ZodBoolean;
21
+
22
+ // $ZodDate
23
+ z.date() satisfies z.core.$ZodDate;
24
+ z.date() satisfies z.ZodDate;
25
+
26
+ // $ZodSymbol
27
+ z.symbol() satisfies z.core.$ZodSymbol;
28
+ z.symbol() satisfies z.ZodSymbol;
29
+
30
+ // $ZodUndefined
31
+ z.undefined() satisfies z.core.$ZodUndefined;
32
+ z.undefined() satisfies z.ZodUndefined;
33
+
34
+ // $ZodNullable
35
+ z.string().nullable() satisfies z.core.$ZodNullable;
36
+ z.string().nullable() satisfies z.ZodNullable;
37
+
38
+ // $ZodNull
39
+ z.null() satisfies z.core.$ZodNull;
40
+ z.null() satisfies z.ZodNull;
41
+
42
+ // $ZodAny
43
+ z.any() satisfies z.core.$ZodAny;
44
+ z.any() satisfies z.ZodAny;
45
+
46
+ // $ZodUnknown
47
+ z.unknown() satisfies z.core.$ZodUnknown;
48
+ z.unknown() satisfies z.ZodUnknown;
49
+
50
+ // $ZodNever
51
+ z.never() satisfies z.core.$ZodNever;
52
+ z.never() satisfies z.ZodNever;
53
+
54
+ // $ZodVoid
55
+ z.void() satisfies z.core.$ZodVoid;
56
+ z.void() satisfies z.ZodVoid;
57
+
58
+ // $ZodArray
59
+ z.array(z.string()) satisfies z.core.$ZodArray;
60
+ z.array(z.string()) satisfies z.ZodArray;
61
+ z.array(z.string()) satisfies z.ZodType<Array<unknown>>;
62
+
63
+ // $ZodObject
64
+ z.object({ key: z.string() }) satisfies z.core.$ZodObject;
65
+ z.object({ key: z.string() }) satisfies z.ZodObject<{ key: z.ZodType }>;
66
+ z.object({ key: z.string() }) satisfies z.ZodType<{ key: string }>;
67
+
68
+ // $ZodUnion
69
+ z.union([z.string(), z.number()]) satisfies z.core.$ZodUnion;
70
+ z.union([z.string(), z.number()]) satisfies z.ZodUnion;
71
+ z.union([z.string(), z.number()]) satisfies z.ZodType<string | number>;
72
+
73
+ // $ZodIntersection
74
+ z.intersection(z.string(), z.number()) satisfies z.core.$ZodIntersection;
75
+ z.intersection(z.string(), z.number()) satisfies z.ZodIntersection;
76
+
77
+ // $ZodTuple
78
+ z.tuple([z.string(), z.number()]) satisfies z.core.$ZodTuple;
79
+ z.tuple([z.string(), z.number()]) satisfies z.ZodTuple;
80
+
81
+ // $ZodRecord
82
+ z.record(z.string(), z.number()) satisfies z.core.$ZodRecord;
83
+ z.record(z.string(), z.number()) satisfies z.ZodRecord;
84
+
85
+ // $ZodMap
86
+ z.map(z.string(), z.number()) satisfies z.core.$ZodMap;
87
+ z.map(z.string(), z.number()) satisfies z.ZodMap;
88
+
89
+ // $ZodSet
90
+ z.set(z.string()) satisfies z.core.$ZodSet;
91
+ z.set(z.string()) satisfies z.ZodSet;
92
+
93
+ // $ZodLiteral
94
+ z.literal("example") satisfies z.core.$ZodLiteral;
95
+ z.literal("example") satisfies z.ZodLiteral;
96
+
97
+ // $ZodEnum
98
+ z.enum(["a", "b", "c"]) satisfies z.core.$ZodEnum;
99
+ z.enum(["a", "b", "c"]) satisfies z.ZodEnum;
100
+
101
+ // $ZodPromise
102
+ z.promise(z.string()) satisfies z.core.$ZodPromise;
103
+ z.promise(z.string()) satisfies z.ZodPromise;
104
+
105
+ // $ZodLazy
106
+ const lazySchema = z.lazy(() => z.string());
107
+ lazySchema satisfies z.core.$ZodLazy;
108
+ lazySchema satisfies z.ZodLazy;
109
+
110
+ // $ZodOptional
111
+ z.string().optional() satisfies z.core.$ZodOptional;
112
+ z.string().optional() satisfies z.ZodOptional;
113
+
114
+ // $ZodDefault
115
+ z.string().default("default") satisfies z.core.$ZodDefault;
116
+ z.string().default("default") satisfies z.ZodDefault;
117
+
118
+ // $ZodTemplateLiteral
119
+ z.templateLiteral([z.literal("a"), z.literal("b")]) satisfies z.core.$ZodTemplateLiteral;
120
+ z.templateLiteral([z.literal("a"), z.literal("b")]) satisfies z.ZodTemplateLiteral;
121
+
122
+ // $ZodCustom
123
+ z.custom<string>((val) => typeof val === "string") satisfies z.core.$ZodCustom;
124
+ z.custom<string>((val) => typeof val === "string") satisfies z.ZodCustom;
125
+
126
+ // $ZodTransform
127
+ z.transform((val) => val as string) satisfies z.core.$ZodTransform;
128
+ z.transform((val) => val as string) satisfies z.ZodTransform;
129
+
130
+ // $ZodNonOptional
131
+ z.string().optional().nonoptional() satisfies z.core.$ZodNonOptional;
132
+ z.string().optional().nonoptional() satisfies z.ZodNonOptional;
133
+
134
+ // $ZodReadonly
135
+ z.object({ key: z.string() }).readonly() satisfies z.core.$ZodReadonly;
136
+ z.object({ key: z.string() }).readonly() satisfies z.ZodReadonly;
137
+
138
+ // $ZodNaN
139
+ z.nan() satisfies z.core.$ZodNaN;
140
+ z.nan() satisfies z.ZodNaN;
141
+
142
+ // $ZodPipe
143
+ z.unknown().pipe(z.number()) satisfies z.core.$ZodPipe;
144
+ z.unknown().pipe(z.number()) satisfies z.ZodPipe;
145
+
146
+ // $ZodSuccess
147
+ z.success(z.string()) satisfies z.core.$ZodSuccess;
148
+ z.success(z.string()) satisfies z.ZodSuccess;
149
+
150
+ // $ZodCatch
151
+ z.string().catch("fallback") satisfies z.core.$ZodCatch;
152
+ z.string().catch("fallback") satisfies z.ZodCatch;
153
+
154
+ // $ZodFile
155
+ z.file() satisfies z.core.$ZodFile;
156
+ z.file() satisfies z.ZodFile;
157
+ });
158
+
159
+ test("checks", () => {
160
+ const _a: z.core.$ZodCheck = {} as any as z.core.$ZodChecks;
161
+ const _b: z.core.$ZodCheck = {} as any as z.core.$ZodStringFormatChecks;
162
+ const _c: z.core.$ZodType = {} as any as z.core.$ZodTypes;
163
+ const _d: z.core.$ZodType = {} as any as z.core.$ZodStringFormatTypes;
164
+ });
165
+
166
+ test("assignability to $ZodType", () => {
167
+ z.string() satisfies z.ZodType;
168
+ z.number() satisfies z.ZodType;
169
+ z.boolean() satisfies z.ZodType;
170
+ z.object({ key: z.string() }) satisfies z.ZodType;
171
+ z.object({ key: z.string() }) satisfies z.ZodType<{ key: string }>;
172
+ z.array(z.string()) satisfies z.ZodType;
173
+ z.union([z.string(), z.number()]) satisfies z.ZodType;
174
+ z.intersection(z.string(), z.number()) satisfies z.ZodType;
175
+ z.tuple([z.string(), z.number()]) satisfies z.ZodType;
176
+ z.record(z.string(), z.number()) satisfies z.ZodType;
177
+ z.map(z.string(), z.number()) satisfies z.ZodType;
178
+ z.set(z.string()) satisfies z.ZodType;
179
+ z.literal("example") satisfies z.ZodType;
180
+
181
+ expectTypeOf<z.ZodType extends z.core.$ZodType ? true : false>().toEqualTypeOf<true>();
182
+ });
183
+
184
+ test("assignability with narrowing", () => {
185
+ type _RefinedSchema<T extends z.ZodType<object> | z.ZodUnion> = T extends z.ZodUnion
186
+ ? RefinedUnionSchema<T> // <-- Type instantiation is excessively deep and possibly infinite.
187
+ : T extends z.ZodType<object>
188
+ ? RefinedTypeSchema<z.output<T>> // <-- Type instantiation is excessively deep and possibly infinite.
189
+ : never;
190
+
191
+ type RefinedTypeSchema<T extends object> = T;
192
+
193
+ type RefinedUnionSchema<T extends z.ZodUnion> = T;
194
+ });
195
+
196
+ test("generic assignability in objects", () => {
197
+ interface SortItem<T extends string> {
198
+ key: T;
199
+ order: string;
200
+ }
201
+
202
+ const createSortItemSchema = <T extends z.ZodType<string>>(sortKeySchema: T) =>
203
+ z.object({
204
+ key: sortKeySchema,
205
+ order: z.string(),
206
+ });
207
+
208
+ <T extends z.ZodType<string>>(sortKeySchema: T, defaultSortBy: SortItem<z.output<T>>[] = []) =>
209
+ createSortItemSchema(sortKeySchema).array().default(defaultSortBy);
210
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ /// string
6
+ const stringSchema = z.string();
7
+
8
+ test("string async parse", async () => {
9
+ const goodData = "XXX";
10
+ const badData = 12;
11
+
12
+ const goodResult = await stringSchema.safeParseAsync(goodData);
13
+ expect(goodResult.success).toBe(true);
14
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
15
+
16
+ const badResult = await stringSchema.safeParseAsync(badData);
17
+ expect(badResult.success).toBe(false);
18
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
19
+ });
20
+
21
+ /// number
22
+ const numberSchema = z.number();
23
+ test("number async parse", async () => {
24
+ const goodData = 1234.2353;
25
+ const badData = "1234";
26
+
27
+ const goodResult = await numberSchema.safeParseAsync(goodData);
28
+ expect(goodResult.success).toBe(true);
29
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
30
+
31
+ const badResult = await numberSchema.safeParseAsync(badData);
32
+ expect(badResult.success).toBe(false);
33
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
34
+ });
35
+
36
+ /// bigInt
37
+ const bigIntSchema = z.bigint();
38
+ test("bigInt async parse", async () => {
39
+ const goodData = BigInt(145);
40
+ const badData = 134;
41
+
42
+ const goodResult = await bigIntSchema.safeParseAsync(goodData);
43
+ expect(goodResult.success).toBe(true);
44
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
45
+
46
+ const badResult = await bigIntSchema.safeParseAsync(badData);
47
+ expect(badResult.success).toBe(false);
48
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
49
+ });
50
+
51
+ /// boolean
52
+ const booleanSchema = z.boolean();
53
+ test("boolean async parse", async () => {
54
+ const goodData = true;
55
+ const badData = 1;
56
+
57
+ const goodResult = await booleanSchema.safeParseAsync(goodData);
58
+ expect(goodResult.success).toBe(true);
59
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
60
+
61
+ const badResult = await booleanSchema.safeParseAsync(badData);
62
+ expect(badResult.success).toBe(false);
63
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
64
+ });
65
+
66
+ /// date
67
+ const dateSchema = z.date();
68
+ test("date async parse", async () => {
69
+ const goodData = new Date();
70
+ const badData = new Date().toISOString();
71
+
72
+ const goodResult = await dateSchema.safeParseAsync(goodData);
73
+ expect(goodResult.success).toBe(true);
74
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
75
+
76
+ const badResult = await dateSchema.safeParseAsync(badData);
77
+ expect(badResult.success).toBe(false);
78
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
79
+ });
80
+
81
+ /// undefined
82
+ const undefinedSchema = z.undefined();
83
+ test("undefined async parse", async () => {
84
+ const goodData = undefined;
85
+ const badData = "XXX";
86
+
87
+ const goodResult = await undefinedSchema.safeParseAsync(goodData);
88
+ expect(goodResult.success).toBe(true);
89
+ if (goodResult.success) expect(goodResult.data).toEqual(undefined);
90
+
91
+ const badResult = await undefinedSchema.safeParseAsync(badData);
92
+ expect(badResult.success).toBe(false);
93
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
94
+ });
95
+
96
+ /// null
97
+ const nullSchema = z.null();
98
+ test("null async parse", async () => {
99
+ const goodData = null;
100
+ const badData = undefined;
101
+
102
+ const goodResult = await nullSchema.safeParseAsync(goodData);
103
+ expect(goodResult.success).toBe(true);
104
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
105
+
106
+ const badResult = await nullSchema.safeParseAsync(badData);
107
+ expect(badResult.success).toBe(false);
108
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
109
+ });
110
+
111
+ /// any
112
+ const anySchema = z.any();
113
+ test("any async parse", async () => {
114
+ const goodData = [{}];
115
+ // const badData = 'XXX';
116
+
117
+ const goodResult = await anySchema.safeParseAsync(goodData);
118
+ expect(goodResult.success).toBe(true);
119
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
120
+
121
+ // const badResult = await anySchema.safeParseAsync(badData);
122
+ // expect(badResult.success).toBe(false);
123
+ // if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
124
+ });
125
+
126
+ /// unknown
127
+ const unknownSchema = z.unknown();
128
+ test("unknown async parse", async () => {
129
+ const goodData = ["asdf", 124, () => {}];
130
+ // const badData = 'XXX';
131
+
132
+ const goodResult = await unknownSchema.safeParseAsync(goodData);
133
+ expect(goodResult.success).toBe(true);
134
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
135
+
136
+ // const badResult = await unknownSchema.safeParseAsync(badData);
137
+ // expect(badResult.success).toBe(false);
138
+ // if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
139
+ });
140
+
141
+ /// void
142
+ const voidSchema = z.void();
143
+ test("void async parse", async () => {
144
+ const goodData = undefined;
145
+ const badData = 0;
146
+
147
+ const goodResult = await voidSchema.safeParseAsync(goodData);
148
+ expect(goodResult.success).toBe(true);
149
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
150
+
151
+ const badResult = await voidSchema.safeParseAsync(badData);
152
+ expect(badResult.success).toBe(false);
153
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
154
+ });
155
+
156
+ /// array
157
+ const arraySchema = z.array(z.string());
158
+ test("array async parse", async () => {
159
+ const goodData = ["XXX"];
160
+ const badData = "XXX";
161
+
162
+ const goodResult = await arraySchema.safeParseAsync(goodData);
163
+ expect(goodResult.success).toBe(true);
164
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
165
+
166
+ const badResult = await arraySchema.safeParseAsync(badData);
167
+ expect(badResult.success).toBe(false);
168
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
169
+ });
170
+
171
+ /// object
172
+ const objectSchema = z.object({ string: z.string() });
173
+ test("object async parse", async () => {
174
+ const goodData = { string: "XXX" };
175
+ const badData = { string: 12 };
176
+
177
+ const goodResult = await objectSchema.safeParseAsync(goodData);
178
+ expect(goodResult.success).toBe(true);
179
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
180
+
181
+ const badResult = await objectSchema.safeParseAsync(badData);
182
+ expect(badResult.success).toBe(false);
183
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
184
+ });
185
+
186
+ /// union
187
+ const unionSchema = z.union([z.string(), z.undefined()]);
188
+ test("union async parse", async () => {
189
+ const goodData = undefined;
190
+ const badData = null;
191
+
192
+ const goodResult = await unionSchema.safeParseAsync(goodData);
193
+ expect(goodResult.success).toBe(true);
194
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
195
+
196
+ const badResult = await unionSchema.safeParseAsync(badData);
197
+ expect(badResult.success).toBe(false);
198
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
199
+ });
200
+
201
+ /// record
202
+ const recordSchema = z.record(z.string(), z.object({}));
203
+ test("record async parse", async () => {
204
+ const goodData = { adsf: {}, asdf: {} };
205
+ const badData = [{}];
206
+
207
+ const goodResult = await recordSchema.safeParseAsync(goodData);
208
+ expect(goodResult.success).toBe(true);
209
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
210
+
211
+ const badResult = await recordSchema.safeParseAsync(badData);
212
+ expect(badResult.success).toBe(false);
213
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
214
+ });
215
+
216
+ /// function
217
+ // const functionSchema = z.function();
218
+ // test("function async parse", async () => {
219
+ // const goodData = () => {};
220
+ // const badData = "XXX";
221
+
222
+ // const goodResult = await functionSchema.safeParseAsync(goodData);
223
+ // expect(goodResult.success).toBe(true);
224
+ // if (goodResult.success) expect(typeof goodResult.data).toEqual("function");
225
+
226
+ // const badResult = await functionSchema.safeParseAsync(badData);
227
+ // expect(badResult.success).toBe(false);
228
+ // if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
229
+ // });
230
+
231
+ /// literal
232
+ const literalSchema = z.literal("asdf");
233
+ test("literal async parse", async () => {
234
+ const goodData = "asdf";
235
+ const badData = "asdff";
236
+
237
+ const goodResult = await literalSchema.safeParseAsync(goodData);
238
+ expect(goodResult.success).toBe(true);
239
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
240
+
241
+ const badResult = await literalSchema.safeParseAsync(badData);
242
+ expect(badResult.success).toBe(false);
243
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
244
+ });
245
+
246
+ /// enum
247
+ const enumSchema = z.enum(["fish", "whale"]);
248
+ test("enum async parse", async () => {
249
+ const goodData = "whale";
250
+ const badData = "leopard";
251
+
252
+ const goodResult = await enumSchema.safeParseAsync(goodData);
253
+ expect(goodResult.success).toBe(true);
254
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
255
+
256
+ const badResult = await enumSchema.safeParseAsync(badData);
257
+ expect(badResult.success).toBe(false);
258
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
259
+ });
260
+
261
+ /// nativeEnum
262
+ enum nativeEnumTest {
263
+ asdf = "qwer",
264
+ }
265
+ // @ts-ignore
266
+ const nativeEnumSchema = z.nativeEnum(nativeEnumTest);
267
+ test("nativeEnum async parse", async () => {
268
+ const goodData = nativeEnumTest.asdf;
269
+ const badData = "asdf";
270
+
271
+ const goodResult = await nativeEnumSchema.safeParseAsync(goodData);
272
+ expect(goodResult.success).toBe(true);
273
+ if (goodResult.success) expect(goodResult.data).toEqual(goodData);
274
+
275
+ const badResult = await nativeEnumSchema.safeParseAsync(badData);
276
+ expect(badResult.success).toBe(false);
277
+ if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
278
+ });
279
+
280
+ /// promise
281
+ const promiseSchema = z.promise(z.number());
282
+ test("promise async parse good", async () => {
283
+ const goodData = Promise.resolve(123);
284
+
285
+ const goodResult = await promiseSchema.safeParseAsync(goodData);
286
+ expect(goodResult.success).toBe(true);
287
+ expect(typeof goodResult.data).toEqual("number");
288
+ expect(goodResult.data).toEqual(123);
289
+ });
290
+
291
+ test("promise async parse bad", async () => {
292
+ const badData = Promise.resolve("XXX");
293
+ const badResult = await promiseSchema.safeParseAsync(badData);
294
+ expect(badResult.success).toBe(false);
295
+ expect(badResult.error).toBeInstanceOf(z.ZodError);
296
+ });
297
+
298
+ test("async validation non-empty strings", async () => {
299
+ const base = z.object({
300
+ hello: z.string().refine((x) => x && x.length > 0),
301
+ foo: z.string().refine((x) => x && x.length > 0),
302
+ });
303
+
304
+ const testval = { hello: "", foo: "" };
305
+ const result1 = base.safeParse(testval);
306
+ const result2 = base.safeParseAsync(testval);
307
+
308
+ const r1 = result1;
309
+ await result2.then((r2) => {
310
+ expect(r1.error!.issues.length).toBe(r2.error!.issues.length);
311
+ });
312
+ });
313
+
314
+ test("async validation multiple errors 1", async () => {
315
+ const base = z.object({
316
+ hello: z.string(),
317
+ foo: z.number(),
318
+ });
319
+
320
+ const testval = { hello: 3, foo: "hello" };
321
+ const result1 = base.safeParse(testval);
322
+ const result2 = base.safeParseAsync(testval);
323
+
324
+ await result2.then((result2) => {
325
+ expect(result2.error!.issues.length).toBe(result1.error!.issues.length);
326
+ });
327
+ });
328
+
329
+ test("async validation multiple errors 2", async () => {
330
+ const base = (is_async?: boolean) =>
331
+ z.object({
332
+ hello: z.string(),
333
+ foo: z.object({
334
+ bar: z.number().refine(
335
+ is_async
336
+ ? async () =>
337
+ new Promise((resolve) => {
338
+ setTimeout(() => resolve(false), 500);
339
+ })
340
+ : () => false
341
+ ),
342
+ }),
343
+ });
344
+
345
+ const testval = { hello: 3, foo: { bar: 4 } };
346
+ const result1 = base().safeParse(testval);
347
+ const result2 = base(true).safeParseAsync(testval);
348
+
349
+ await result2.then((result2) => {
350
+ expect(result1.error!.issues.length).toBe(result2.error!.issues.length);
351
+ });
352
+ });
353
+
354
+ test("ensure early async failure prevents follow-up refinement checks", async () => {
355
+ let count = 0;
356
+ const base = z.object({
357
+ hello: z.string(),
358
+ foo: z
359
+ .number()
360
+ .refine(async () => {
361
+ count++;
362
+ return true;
363
+ })
364
+ .refine(async () => {
365
+ count++;
366
+ return true;
367
+ }, "Good"),
368
+ });
369
+
370
+ const testval = { hello: "bye", foo: 3 };
371
+ const result = await base.safeParseAsync(testval);
372
+ if (result.success === false) {
373
+ expect(result.error.issues.length).toBe(1);
374
+ expect(count).toBe(1);
375
+ }
376
+
377
+ // await result.then((r) => {
378
+ // if (r.success === false) expect(r.error.issues.length).toBe(1);
379
+ // expect(count).toBe(2);
380
+ // });
381
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("async refine .parse()", async () => {
6
+ // throws ZodAsyncError
7
+ const s1 = z.string().refine(async (_val) => true);
8
+ expect(() => s1.safeParse("asdf")).toThrow();
9
+ });
10
+
11
+ test("async refine", async () => {
12
+ const s1 = z.string().refine(async (_val) => true);
13
+ const r1 = await s1.parseAsync("asdf");
14
+ expect(r1).toEqual("asdf");
15
+
16
+ const s2 = z.string().refine(async (_val) => false);
17
+ const r2 = await s2.safeParseAsync("asdf");
18
+ expect(r2.success).toBe(false);
19
+ expect(r2).toMatchInlineSnapshot(`
20
+ {
21
+ "error": [ZodError: [
22
+ {
23
+ "code": "custom",
24
+ "path": [],
25
+ "message": "Invalid input"
26
+ }
27
+ ]],
28
+ "success": false,
29
+ }
30
+ `);
31
+ });
32
+
33
+ test("async refine with Promises", async () => {
34
+ // expect.assertions(2);
35
+
36
+ const schema1 = z.string().refine((_val) => Promise.resolve(true));
37
+ const v1 = await schema1.parseAsync("asdf");
38
+ expect(v1).toEqual("asdf");
39
+
40
+ const schema2 = z.string().refine((_val) => Promise.resolve(false));
41
+ await expect(schema2.parseAsync("asdf")).rejects.toBeDefined();
42
+
43
+ const schema3 = z.string().refine((_val) => Promise.resolve(true));
44
+ await expect(schema3.parseAsync("asdf")).resolves.toEqual("asdf");
45
+ return await expect(schema3.parseAsync("qwer")).resolves.toEqual("qwer");
46
+ });
47
+
48
+ test("async refine that uses value", async () => {
49
+ const schema1 = z.string().refine(async (val) => {
50
+ return val.length > 5;
51
+ });
52
+
53
+ const r1 = await schema1.safeParseAsync("asdf");
54
+ expect(r1.success).toBe(false);
55
+ expect(r1.error).toMatchInlineSnapshot(`
56
+ [ZodError: [
57
+ {
58
+ "code": "custom",
59
+ "path": [],
60
+ "message": "Invalid input"
61
+ }
62
+ ]]
63
+ `);
64
+
65
+ const r2 = await schema1.safeParseAsync("asdf123");
66
+ expect(r2.success).toBe(true);
67
+ expect(r2.data).toEqual("asdf123");
68
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/base.test.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("test this binding", () => {
5
+ const parse = z.string().parse;
6
+ expect(parse("asdf")).toBe("asdf");
7
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/bigint.test.ts ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ const gtFive = z.bigint().gt(BigInt(5));
6
+ const gteFive = z.bigint().gte(BigInt(5));
7
+ const ltFive = z.bigint().lt(BigInt(5));
8
+ const lteFive = z.bigint().lte(BigInt(5));
9
+ const positive = z.bigint().positive();
10
+ const negative = z.bigint().negative();
11
+ const nonnegative = z.bigint().nonnegative();
12
+ const nonpositive = z.bigint().nonpositive();
13
+ const multipleOfFive = z.bigint().multipleOf(BigInt(5));
14
+
15
+ test("passing validations", () => {
16
+ z.bigint().parse(BigInt(1));
17
+ z.bigint().parse(BigInt(0));
18
+ z.bigint().parse(BigInt(-1));
19
+ gtFive.parse(BigInt(6));
20
+ gteFive.parse(BigInt(5));
21
+ gteFive.parse(BigInt(6));
22
+ ltFive.parse(BigInt(4));
23
+ lteFive.parse(BigInt(5));
24
+ lteFive.parse(BigInt(4));
25
+ positive.parse(BigInt(3));
26
+ negative.parse(BigInt(-2));
27
+ nonnegative.parse(BigInt(0));
28
+ nonnegative.parse(BigInt(7));
29
+ nonpositive.parse(BigInt(0));
30
+ nonpositive.parse(BigInt(-12));
31
+ multipleOfFive.parse(BigInt(15));
32
+ });
33
+
34
+ test("failing validations", () => {
35
+ expect(() => gtFive.parse(BigInt(5))).toThrow();
36
+ expect(() => gteFive.parse(BigInt(4))).toThrow();
37
+ expect(() => ltFive.parse(BigInt(5))).toThrow();
38
+ expect(() => lteFive.parse(BigInt(6))).toThrow();
39
+ expect(() => positive.parse(BigInt(0))).toThrow();
40
+ expect(() => positive.parse(BigInt(-2))).toThrow();
41
+ expect(() => negative.parse(BigInt(0))).toThrow();
42
+ expect(() => negative.parse(BigInt(3))).toThrow();
43
+ expect(() => nonnegative.parse(BigInt(-1))).toThrow();
44
+ expect(() => nonpositive.parse(BigInt(1))).toThrow();
45
+ expect(() => multipleOfFive.parse(BigInt(13))).toThrow();
46
+ });
47
+
48
+ test("min max getters", () => {
49
+ expect(z.bigint().min(BigInt(5)).minValue).toEqual(BigInt(5));
50
+ expect(z.bigint().min(BigInt(5)).min(BigInt(10)).minValue).toEqual(BigInt(10));
51
+
52
+ expect(z.bigint().max(BigInt(5)).maxValue).toEqual(BigInt(5));
53
+ expect(z.bigint().max(BigInt(5)).max(BigInt(1)).maxValue).toEqual(BigInt(1));
54
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/brand.test.ts ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("branded types", () => {
5
+ const mySchema = z
6
+ .object({
7
+ name: z.string(),
8
+ })
9
+ .brand<"superschema">();
10
+
11
+ // simple branding
12
+ type MySchema = z.infer<typeof mySchema>;
13
+
14
+ expectTypeOf<MySchema>().toEqualTypeOf<{ name: string } & z.$brand<"superschema">>();
15
+
16
+ const doStuff = (arg: MySchema) => arg;
17
+ doStuff(mySchema.parse({ name: "hello there" }));
18
+
19
+ // inheritance
20
+ const extendedSchema = mySchema.brand<"subschema">();
21
+ type ExtendedSchema = z.infer<typeof extendedSchema>;
22
+ expectTypeOf<ExtendedSchema>().toEqualTypeOf<{ name: string } & z.BRAND<"superschema"> & z.BRAND<"subschema">>();
23
+
24
+ doStuff(extendedSchema.parse({ name: "hello again" }));
25
+
26
+ // number branding
27
+ const numberSchema = z.number().brand<42>();
28
+ type NumberSchema = z.infer<typeof numberSchema>;
29
+ expectTypeOf<NumberSchema>().toEqualTypeOf<number & { [z.$brand]: { 42: true } }>();
30
+
31
+ // symbol branding
32
+ const MyBrand: unique symbol = Symbol("hello");
33
+ type MyBrand = typeof MyBrand;
34
+ const symbolBrand = z.number().brand<"sup">().brand<typeof MyBrand>();
35
+ type SymbolBrand = z.infer<typeof symbolBrand>;
36
+ // number & { [z.BRAND]: { sup: true, [MyBrand]: true } }
37
+ expectTypeOf<SymbolBrand>().toEqualTypeOf<number & z.BRAND<"sup"> & z.BRAND<MyBrand>>();
38
+
39
+ // keeping brands out of input types
40
+ const age = z.number().brand<"age">();
41
+
42
+ type Age = z.infer<typeof age>;
43
+ type AgeInput = z.input<typeof age>;
44
+
45
+ expectTypeOf<AgeInput>().not.toEqualTypeOf<Age>();
46
+ expectTypeOf<number>().toEqualTypeOf<AgeInput>();
47
+ expectTypeOf<number & z.BRAND<"age">>().toEqualTypeOf<Age>();
48
+
49
+ // @ts-expect-error
50
+ doStuff({ name: "hello there!" });
51
+ });
52
+
53
+ test("$branded", () => {
54
+ const a = z.string().brand<"a">();
55
+
56
+ expectTypeOf<typeof a>().toEqualTypeOf<z.core.$ZodBranded<z.ZodString, "a">>();
57
+ });
58
+
59
+ test("branded record", () => {
60
+ const recordWithBrandedNumberKeys = z.record(z.string().brand("SomeBrand"), z.number());
61
+ type recordWithBrandedNumberKeys = z.infer<typeof recordWithBrandedNumberKeys>;
62
+ expectTypeOf<recordWithBrandedNumberKeys>().toEqualTypeOf<Record<string & z.core.$brand<"SomeBrand">, number>>();
63
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/catch.test.ts ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import { z } from "zod/v4";
3
+ import type { util } from "zod/v4/core";
4
+
5
+ test("basic catch", () => {
6
+ expect(z.string().catch("default").parse(undefined)).toBe("default");
7
+ });
8
+
9
+ test("catch fn does not run when parsing succeeds", () => {
10
+ let isCalled = false;
11
+ const cb = () => {
12
+ isCalled = true;
13
+ return "asdf";
14
+ };
15
+ expect(z.string().catch(cb).parse("test")).toBe("test");
16
+ expect(isCalled).toEqual(false);
17
+ });
18
+
19
+ test("basic catch async", async () => {
20
+ const result = await z.string().catch("default").parseAsync(1243);
21
+ expect(result).toBe("default");
22
+ });
23
+
24
+ test("catch replace wrong types", () => {
25
+ expect(z.string().catch("default").parse(true)).toBe("default");
26
+ expect(z.string().catch("default").parse(true)).toBe("default");
27
+ expect(z.string().catch("default").parse(15)).toBe("default");
28
+ expect(z.string().catch("default").parse([])).toBe("default");
29
+ expect(z.string().catch("default").parse(new Map())).toBe("default");
30
+ expect(z.string().catch("default").parse(new Set())).toBe("default");
31
+ expect(z.string().catch("default").parse({})).toBe("default");
32
+ });
33
+
34
+ test("catch with transform", () => {
35
+ const stringWithDefault = z
36
+ .string()
37
+ .transform((val) => val.toUpperCase())
38
+ .catch("default");
39
+
40
+ expect(stringWithDefault.parse(undefined)).toBe("default");
41
+ expect(stringWithDefault.parse(15)).toBe("default");
42
+ expect(stringWithDefault).toBeInstanceOf(z.ZodCatch);
43
+ expect(stringWithDefault.unwrap()).toBeInstanceOf(z.ZodPipe);
44
+ expect(stringWithDefault.unwrap().in).toBeInstanceOf(z.ZodString);
45
+ expect(stringWithDefault.unwrap().out).toBeInstanceOf(z.ZodTransform);
46
+
47
+ type inp = z.input<typeof stringWithDefault>;
48
+ expectTypeOf<inp>().toEqualTypeOf<string | util.Whatever>();
49
+ type out = z.output<typeof stringWithDefault>;
50
+ expectTypeOf<out>().toEqualTypeOf<string>();
51
+ });
52
+
53
+ test("catch on existing optional", () => {
54
+ const stringWithDefault = z.string().optional().catch("asdf");
55
+ expect(stringWithDefault.parse(undefined)).toBe(undefined);
56
+ expect(stringWithDefault.parse(15)).toBe("asdf");
57
+ expect(stringWithDefault).toBeInstanceOf(z.ZodCatch);
58
+ expect(stringWithDefault.unwrap()).toBeInstanceOf(z.ZodOptional);
59
+ expect(stringWithDefault.unwrap().unwrap()).toBeInstanceOf(z.ZodString);
60
+
61
+ type inp = z.input<typeof stringWithDefault>;
62
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined | util.Whatever>();
63
+ type out = z.output<typeof stringWithDefault>;
64
+ expectTypeOf<out>().toEqualTypeOf<string | undefined>();
65
+ });
66
+
67
+ test("optional on catch", () => {
68
+ const stringWithDefault = z.string().catch("asdf").optional();
69
+
70
+ type inp = z.input<typeof stringWithDefault>;
71
+ expectTypeOf<inp>().toEqualTypeOf<string | util.Whatever>();
72
+ type out = z.output<typeof stringWithDefault>;
73
+ expectTypeOf<out>().toEqualTypeOf<string | undefined>();
74
+ });
75
+
76
+ test("complex chain example", () => {
77
+ const complex = z
78
+ .string()
79
+ .catch("asdf")
80
+ .transform((val) => `${val}!`)
81
+ .transform((val) => val.toUpperCase())
82
+ .catch("qwer")
83
+ .unwrap()
84
+ .optional()
85
+ .catch("asdfasdf");
86
+
87
+ expect(complex.parse("qwer")).toBe("QWER!");
88
+ expect(complex.parse(15)).toBe("ASDF!");
89
+ expect(complex.parse(true)).toBe("ASDF!");
90
+ });
91
+
92
+ test("removeCatch", () => {
93
+ const stringWithRemovedDefault = z.string().catch("asdf").unwrap();
94
+
95
+ type out = z.output<typeof stringWithRemovedDefault>;
96
+ expectTypeOf<out>().toEqualTypeOf<string>();
97
+ });
98
+
99
+ test("nested", () => {
100
+ const inner = z.string().catch("asdf");
101
+ const outer = z.object({ inner }).catch({
102
+ inner: "asdf",
103
+ });
104
+ type input = z.input<typeof outer>;
105
+ expectTypeOf<input>().toEqualTypeOf<{ inner: string | util.Whatever } | util.Whatever>();
106
+ type out = z.output<typeof outer>;
107
+
108
+ expectTypeOf<out>().toEqualTypeOf<{ inner: string }>();
109
+ expect(outer.parse(undefined)).toEqual({ inner: "asdf" });
110
+ expect(outer.parse({})).toEqual({ inner: "asdf" });
111
+ expect(outer.parse({ inner: undefined })).toEqual({ inner: "asdf" });
112
+ });
113
+
114
+ test("chained catch", () => {
115
+ const stringWithDefault = z.string().catch("inner").catch("outer");
116
+ const result = stringWithDefault.parse(undefined);
117
+ expect(result).toEqual("inner");
118
+ const resultDiff = stringWithDefault.parse(5);
119
+ expect(resultDiff).toEqual("inner");
120
+ });
121
+
122
+ test("native enum", () => {
123
+ enum Fruits {
124
+ apple = "apple",
125
+ orange = "orange",
126
+ }
127
+
128
+ const schema = z.object({
129
+ fruit: z.nativeEnum(Fruits).catch(Fruits.apple),
130
+ });
131
+
132
+ expect(schema.parse({})).toEqual({ fruit: Fruits.apple });
133
+ expect(schema.parse({ fruit: 15 })).toEqual({ fruit: Fruits.apple });
134
+ });
135
+
136
+ test("enum", () => {
137
+ const schema = z.object({
138
+ fruit: z.enum(["apple", "orange"]).catch("apple"),
139
+ });
140
+
141
+ expect(schema.parse({})).toEqual({ fruit: "apple" });
142
+ expect(schema.parse({ fruit: true })).toEqual({ fruit: "apple" });
143
+ expect(schema.parse({ fruit: 15 })).toEqual({ fruit: "apple" });
144
+ });
145
+
146
+ test("reported issues with nested usage", () => {
147
+ const schema = z.object({
148
+ string: z.string(),
149
+ obj: z.object({
150
+ sub: z.object({
151
+ lit: z.literal("a"),
152
+ subCatch: z.number().catch(23),
153
+ }),
154
+ midCatch: z.number().catch(42),
155
+ }),
156
+ number: z.number().catch(0),
157
+ bool: z.boolean(),
158
+ });
159
+
160
+ try {
161
+ schema.parse({
162
+ string: {},
163
+ obj: {
164
+ sub: {
165
+ lit: "b",
166
+ subCatch: "24",
167
+ },
168
+ midCatch: 444,
169
+ },
170
+ number: "",
171
+ bool: "yes",
172
+ });
173
+ } catch (error) {
174
+ const issues = (error as z.ZodError).issues;
175
+
176
+ expect(issues.length).toEqual(3);
177
+ expect(issues).toMatchInlineSnapshot(`
178
+ [
179
+ {
180
+ "code": "invalid_type",
181
+ "expected": "string",
182
+ "message": "Invalid input: expected string, received object",
183
+ "path": [
184
+ "string",
185
+ ],
186
+ },
187
+ {
188
+ "code": "invalid_value",
189
+ "message": "Invalid input: expected "a"",
190
+ "path": [
191
+ "obj",
192
+ "sub",
193
+ "lit",
194
+ ],
195
+ "values": [
196
+ "a",
197
+ ],
198
+ },
199
+ {
200
+ "code": "invalid_type",
201
+ "expected": "boolean",
202
+ "message": "Invalid input: expected boolean, received string",
203
+ "path": [
204
+ "bool",
205
+ ],
206
+ },
207
+ ]
208
+ `);
209
+ // expect(issues[0].message).toMatch("string");
210
+ // expect(issues[1].message).toMatch("literal");
211
+ // expect(issues[2].message).toMatch("boolean");
212
+ }
213
+ });
214
+
215
+ test("catch error", () => {
216
+ const schema = z.object({
217
+ age: z.number(),
218
+ name: z.string().catch((ctx) => {
219
+ ctx.issues;
220
+ // issues = ctx.issues;
221
+
222
+ return "John Doe";
223
+ }),
224
+ });
225
+
226
+ const result = schema.safeParse({
227
+ age: null,
228
+ name: null,
229
+ });
230
+
231
+ expect(result.success).toEqual(false);
232
+ expect(result.error!).toMatchInlineSnapshot(`
233
+ [ZodError: [
234
+ {
235
+ "expected": "number",
236
+ "code": "invalid_type",
237
+ "path": [
238
+ "age"
239
+ ],
240
+ "message": "Invalid input: expected number, received null"
241
+ }
242
+ ]]
243
+ `);
244
+ });
245
+
246
+ test("ctx.input", () => {
247
+ const schema = z.string().catch((ctx) => {
248
+ return String(ctx.input);
249
+ });
250
+
251
+ expect(schema.parse(123)).toEqual("123");
252
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/coalesce.test.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ test("coalesce", () => {
4
+ expect(true).toBe(true);
5
+ });
6
+
7
+ // test("nonoptional with default", () => {
8
+ // const schema = z.string().optional().coalesce("hi");
9
+ // expectTypeOf<typeof schema._input>().toEqualTypeOf<string | undefined>();
10
+ // expectTypeOf<typeof schema._output>().toEqualTypeOf<string>();
11
+ // expect(schema.parse(undefined)).toBe("hi");
12
+ // });
13
+
14
+ // test("nonoptional in object", () => {
15
+ // const schema = z.object({ hi: z.string().optional().nonoptional("hi") });
16
+
17
+ // expectTypeOf<typeof schema._input>().toEqualTypeOf<{ hi: string | undefined }>();
18
+ // expectTypeOf<typeof schema._output>().toEqualTypeOf<{ hi: string }>();
19
+ // expect(schema.parse(undefined)).toBe("hi");
20
+ // });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/coerce.test.ts ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("string coercion", () => {
6
+ const schema = z.coerce.string();
7
+ expect(schema.parse("sup")).toEqual("sup");
8
+ expect(schema.parse("")).toEqual("");
9
+ expect(schema.parse(12)).toEqual("12");
10
+ expect(schema.parse(0)).toEqual("0");
11
+ expect(schema.parse(-12)).toEqual("-12");
12
+ expect(schema.parse(3.14)).toEqual("3.14");
13
+ expect(schema.parse(BigInt(15))).toEqual("15");
14
+ expect(schema.parse(Number.NaN)).toEqual("NaN");
15
+ expect(schema.parse(Number.POSITIVE_INFINITY)).toEqual("Infinity");
16
+ expect(schema.parse(Number.NEGATIVE_INFINITY)).toEqual("-Infinity");
17
+ expect(schema.parse(true)).toEqual("true");
18
+ expect(schema.parse(false)).toEqual("false");
19
+ expect(schema.parse(null)).toEqual("null");
20
+ expect(schema.parse(undefined)).toEqual("undefined");
21
+ expect(schema.parse({ hello: "world!" })).toEqual("[object Object]");
22
+ expect(schema.parse(["item", "another_item"])).toEqual("item,another_item");
23
+ expect(schema.parse([])).toEqual("");
24
+ expect(schema.parse(new Date("2022-01-01T00:00:00.000Z"))).toEqual(new Date("2022-01-01T00:00:00.000Z").toString());
25
+ });
26
+
27
+ test("number coercion", () => {
28
+ const schema = z.coerce.number();
29
+ expect(schema.parse("12")).toEqual(12);
30
+ expect(schema.parse("0")).toEqual(0);
31
+ expect(schema.parse("-12")).toEqual(-12);
32
+ expect(schema.parse("3.14")).toEqual(3.14);
33
+ expect(schema.parse("")).toEqual(0);
34
+ expect(() => schema.parse("NOT_A_NUMBER")).toThrow(); // z.ZodError
35
+ expect(schema.parse(12)).toEqual(12);
36
+ expect(schema.parse(0)).toEqual(0);
37
+ expect(schema.parse(-12)).toEqual(-12);
38
+ expect(schema.parse(3.14)).toEqual(3.14);
39
+ expect(schema.parse(BigInt(15))).toEqual(15);
40
+ expect(() => schema.parse(Number.NaN)).toThrow(); // z.ZodError
41
+ // expect(schema.parse(Number.POSITIVE_INFINITY)).toEqual(Number.POSITIVE_INFINITY);
42
+ // expect(schema.parse(Number.NEGATIVE_INFINITY)).toEqual(Number.NEGATIVE_INFINITY);
43
+ expect(schema.parse(true)).toEqual(1);
44
+ expect(schema.parse(false)).toEqual(0);
45
+ expect(schema.parse(null)).toEqual(0);
46
+ expect(() => schema.parse(undefined)).toThrow(); // z.ZodError
47
+ expect(() => schema.parse({ hello: "world!" })).toThrow(); // z.ZodError
48
+ expect(() => schema.parse(["item", "another_item"])).toThrow(); // z.ZodError
49
+ expect(schema.parse([])).toEqual(0);
50
+ expect(schema.parse(new Date(1670139203496))).toEqual(1670139203496);
51
+ });
52
+
53
+ test("boolean coercion", () => {
54
+ const schema = z.coerce.boolean();
55
+ expect(schema.parse("true")).toEqual(true);
56
+ expect(schema.parse("false")).toEqual(true);
57
+ expect(schema.parse("0")).toEqual(true);
58
+ expect(schema.parse("1")).toEqual(true);
59
+ expect(schema.parse("")).toEqual(false);
60
+ expect(schema.parse(1)).toEqual(true);
61
+ expect(schema.parse(0)).toEqual(false);
62
+ expect(schema.parse(-1)).toEqual(true);
63
+ expect(schema.parse(3.14)).toEqual(true);
64
+ expect(schema.parse(BigInt(15))).toEqual(true);
65
+ expect(schema.parse(Number.NaN)).toEqual(false);
66
+ expect(schema.parse(Number.POSITIVE_INFINITY)).toEqual(true);
67
+ expect(schema.parse(Number.NEGATIVE_INFINITY)).toEqual(true);
68
+ expect(schema.parse(true)).toEqual(true);
69
+ expect(schema.parse(false)).toEqual(false);
70
+ expect(schema.parse(null)).toEqual(false);
71
+ expect(schema.parse(undefined)).toEqual(false);
72
+ expect(schema.parse({ hello: "world!" })).toEqual(true);
73
+ expect(schema.parse(["item", "another_item"])).toEqual(true);
74
+ expect(schema.parse([])).toEqual(true);
75
+ expect(schema.parse(new Date(1670139203496))).toEqual(true);
76
+ });
77
+
78
+ test("bigint coercion", () => {
79
+ const schema = z.coerce.bigint();
80
+ expect(schema.parse("5")).toEqual(BigInt(5));
81
+ expect(schema.parse("0")).toEqual(BigInt(0));
82
+ expect(schema.parse("-5")).toEqual(BigInt(-5));
83
+ expect(() => schema.parse("3.14")).toThrow(); // not a z.ZodError!
84
+ expect(schema.parse("")).toEqual(BigInt(0));
85
+ expect(() => schema.parse("NOT_A_NUMBER")).toThrow(); // not a z.ZodError!
86
+ expect(schema.parse(5)).toEqual(BigInt(5));
87
+ expect(schema.parse(0)).toEqual(BigInt(0));
88
+ expect(schema.parse(-5)).toEqual(BigInt(-5));
89
+ expect(() => schema.parse(3.14)).toThrow(); // not a z.ZodError!
90
+ expect(schema.parse(BigInt(5))).toEqual(BigInt(5));
91
+ expect(() => schema.parse(Number.NaN)).toThrow(); // not a z.ZodError!
92
+ expect(() => schema.parse(Number.POSITIVE_INFINITY)).toThrow(); // not a z.ZodError!
93
+ expect(() => schema.parse(Number.NEGATIVE_INFINITY)).toThrow(); // not a z.ZodError!
94
+ expect(schema.parse(true)).toEqual(BigInt(1));
95
+ expect(schema.parse(false)).toEqual(BigInt(0));
96
+ expect(() => schema.parse(null)).toThrow(); // not a z.ZodError!
97
+ expect(() => schema.parse(undefined)).toThrow(); // not a z.ZodError!
98
+ expect(() => schema.parse({ hello: "world!" })).toThrow(); // not a z.ZodError!
99
+ expect(() => schema.parse(["item", "another_item"])).toThrow(); // not a z.ZodError!
100
+ expect(schema.parse([])).toEqual(BigInt(0));
101
+ expect(schema.parse(new Date(1670139203496))).toEqual(BigInt(1670139203496));
102
+ });
103
+
104
+ test("date coercion", () => {
105
+ const schema = z.coerce.date();
106
+ expect(schema.parse(new Date().toDateString())).toBeInstanceOf(Date);
107
+ expect(schema.parse(new Date().toISOString())).toBeInstanceOf(Date);
108
+ expect(schema.parse(new Date().toUTCString())).toBeInstanceOf(Date);
109
+ expect(schema.parse("5")).toBeInstanceOf(Date);
110
+ expect(schema.parse("2000-01-01")).toBeInstanceOf(Date);
111
+ // expect(schema.parse("0")).toBeInstanceOf(Date);
112
+ // expect(schema.parse("-5")).toBeInstanceOf(Date);
113
+ // expect(schema.parse("3.14")).toBeInstanceOf(Date);
114
+ expect(() => schema.parse("")).toThrow(); // z.ZodError
115
+ expect(() => schema.parse("NOT_A_DATE")).toThrow(); // z.ZodError
116
+ expect(schema.parse(5)).toBeInstanceOf(Date);
117
+ expect(schema.parse(0)).toBeInstanceOf(Date);
118
+ expect(schema.parse(-5)).toBeInstanceOf(Date);
119
+ expect(schema.parse(3.14)).toBeInstanceOf(Date);
120
+ expect(() => schema.parse(BigInt(5))).toThrow(); // not a z.ZodError!
121
+ expect(() => schema.parse(Number.NaN)).toThrow(); // z.ZodError
122
+ expect(() => schema.parse(Number.POSITIVE_INFINITY)).toThrow(); // z.ZodError
123
+ expect(() => schema.parse(Number.NEGATIVE_INFINITY)).toThrow(); // z.ZodError
124
+ expect(schema.parse(true)).toBeInstanceOf(Date);
125
+ expect(schema.parse(false)).toBeInstanceOf(Date);
126
+ expect(schema.parse(null)).toBeInstanceOf(Date);
127
+ expect(() => schema.parse(undefined)).toThrow(); // z.ZodError
128
+ expect(() => schema.parse({ hello: "world!" })).toThrow(); // z.ZodError
129
+ expect(() => schema.parse(["item", "another_item"])).toThrow(); // z.ZodError
130
+ expect(() => schema.parse([])).toThrow(); // z.ZodError
131
+ expect(schema.parse(new Date())).toBeInstanceOf(Date);
132
+ });
133
+
134
+ // test("template literal coercion", () => {
135
+ // const schema = z.coerce
136
+ // .templateLiteral()
137
+ // .interpolated(z.number().finite())
138
+ // .interpolated(
139
+ // z.enum(["px", "em", "rem", "vh", "vw", "vmin", "vmax"]).optional()
140
+ // );
141
+ // expect(schema.parse(300)).toEqual("300");
142
+ // expect(schema.parse(BigInt(300))).toEqual("300");
143
+ // expect(schema.parse("300")).toEqual("300");
144
+ // expect(schema.parse("300px")).toEqual("300px");
145
+ // expect(schema.parse("300em")).toEqual("300em");
146
+ // expect(schema.parse("300rem")).toEqual("300rem");
147
+ // expect(schema.parse("300vh")).toEqual("300vh");
148
+ // expect(schema.parse("300vw")).toEqual("300vw");
149
+ // expect(schema.parse("300vmin")).toEqual("300vmin");
150
+ // expect(schema.parse("300vmax")).toEqual("300vmax");
151
+ // expect(schema.parse(["300px"])).toEqual("300px");
152
+ // });
153
+
154
+ test("override input type", () => {
155
+ const a = z.coerce.string<any>();
156
+ type input = z.input<typeof a>;
157
+ expectTypeOf<input>().toEqualTypeOf<any>();
158
+ type output = z.infer<typeof a>;
159
+ expectTypeOf<output>().toEqualTypeOf<string>();
160
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/continuability.test.ts ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("continuability", () => {
5
+ /**
6
+ * | $ZodGUID
7
+ | $ZodUUID
8
+ | $ZodEmail
9
+ | $ZodURL
10
+ | $ZodEmoji
11
+ | $ZodNanoID
12
+ | $ZodCUID
13
+ | $ZodCUID2
14
+ | $ZodULID
15
+ | $ZodXID
16
+ | $ZodKSUID
17
+ | $ZodISODateTime
18
+ | $ZodISODate
19
+ | $ZodISOTime
20
+ | $ZodISODuration
21
+ | $ZodIPv4
22
+ | $ZodIPv6
23
+ | $ZodCIDRv4
24
+ | $ZodCIDRv6
25
+ | $ZodBase64
26
+ | $ZodBase64URL
27
+ | $ZodE164
28
+ | $ZodJWT;
29
+ */
30
+ expect(
31
+ z
32
+ .email()
33
+ .refine(() => false)
34
+ .safeParse("invalid_value").error!.issues
35
+ ).toMatchInlineSnapshot(`
36
+ [
37
+ {
38
+ "code": "invalid_format",
39
+ "format": "email",
40
+ "message": "Invalid email address",
41
+ "origin": "string",
42
+ "path": [],
43
+ "pattern": "/^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$/",
44
+ },
45
+ {
46
+ "code": "custom",
47
+ "message": "Invalid input",
48
+ "path": [],
49
+ },
50
+ ]
51
+ `);
52
+ expect(
53
+ z
54
+ .uuid()
55
+ .refine(() => false)
56
+ .safeParse("invalid_value").error!.issues
57
+ ).toMatchInlineSnapshot(`
58
+ [
59
+ {
60
+ "code": "invalid_format",
61
+ "format": "uuid",
62
+ "message": "Invalid UUID",
63
+ "origin": "string",
64
+ "path": [],
65
+ "pattern": "/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/",
66
+ },
67
+ {
68
+ "code": "custom",
69
+ "message": "Invalid input",
70
+ "path": [],
71
+ },
72
+ ]
73
+ `);
74
+ expect(
75
+ z
76
+ .url()
77
+ .refine(() => false)
78
+ .safeParse("invalid_value").error!.issues
79
+ ).toMatchInlineSnapshot(`
80
+ [
81
+ {
82
+ "code": "invalid_format",
83
+ "format": "url",
84
+ "message": "Invalid URL",
85
+ "path": [],
86
+ },
87
+ {
88
+ "code": "custom",
89
+ "message": "Invalid input",
90
+ "path": [],
91
+ },
92
+ ]
93
+ `);
94
+ expect(
95
+ z
96
+ .jwt()
97
+ .refine(() => false)
98
+ .safeParse("invalid_value").error!.issues
99
+ ).toMatchInlineSnapshot(`
100
+ [
101
+ {
102
+ "code": "invalid_format",
103
+ "format": "jwt",
104
+ "message": "Invalid JWT",
105
+ "path": [],
106
+ },
107
+ {
108
+ "code": "custom",
109
+ "message": "Invalid input",
110
+ "path": [],
111
+ },
112
+ ]
113
+ `);
114
+ expect(
115
+ z
116
+ .cidrv4()
117
+ .refine(() => false)
118
+ .safeParse("invalid_value").error!.issues
119
+ ).toMatchInlineSnapshot(`
120
+ [
121
+ {
122
+ "code": "invalid_format",
123
+ "format": "cidrv4",
124
+ "message": "Invalid IPv4 range",
125
+ "origin": "string",
126
+ "path": [],
127
+ "pattern": "/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\/([0-9]|[1-2][0-9]|3[0-2])$/",
128
+ },
129
+ {
130
+ "code": "custom",
131
+ "message": "Invalid input",
132
+ "path": [],
133
+ },
134
+ ]
135
+ `);
136
+ expect(
137
+ z
138
+ .cidrv6()
139
+ .refine(() => false)
140
+ .safeParse("invalid_value").error!.issues
141
+ ).toMatchInlineSnapshot(`
142
+ [
143
+ {
144
+ "code": "invalid_format",
145
+ "format": "cidrv6",
146
+ "message": "Invalid IPv6 range",
147
+ "path": [],
148
+ },
149
+ {
150
+ "code": "custom",
151
+ "message": "Invalid input",
152
+ "path": [],
153
+ },
154
+ ]
155
+ `);
156
+ expect(
157
+ z
158
+ .ipv4()
159
+ .refine(() => false)
160
+ .safeParse("invalid_value").error!.issues
161
+ ).toMatchInlineSnapshot(`
162
+ [
163
+ {
164
+ "code": "invalid_format",
165
+ "format": "ipv4",
166
+ "message": "Invalid IPv4 address",
167
+ "origin": "string",
168
+ "path": [],
169
+ "pattern": "/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/",
170
+ },
171
+ {
172
+ "code": "custom",
173
+ "message": "Invalid input",
174
+ "path": [],
175
+ },
176
+ ]
177
+ `);
178
+ expect(
179
+ z
180
+ .ipv6()
181
+ .refine(() => false)
182
+ .safeParse("invalid_value").error!.issues
183
+ ).toMatchInlineSnapshot(`
184
+ [
185
+ {
186
+ "code": "invalid_format",
187
+ "format": "ipv6",
188
+ "message": "Invalid IPv6 address",
189
+ "path": [],
190
+ },
191
+ {
192
+ "code": "custom",
193
+ "message": "Invalid input",
194
+ "path": [],
195
+ },
196
+ ]
197
+ `);
198
+ expect(
199
+ z
200
+ .emoji()
201
+ .refine(() => false)
202
+ .safeParse("invalid_value").error!.issues
203
+ ).toMatchInlineSnapshot(`
204
+ [
205
+ {
206
+ "code": "invalid_format",
207
+ "format": "emoji",
208
+ "message": "Invalid emoji",
209
+ "origin": "string",
210
+ "path": [],
211
+ "pattern": "/^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$/u",
212
+ },
213
+ {
214
+ "code": "custom",
215
+ "message": "Invalid input",
216
+ "path": [],
217
+ },
218
+ ]
219
+ `);
220
+ expect(
221
+ z
222
+ .nanoid()
223
+ .refine(() => false)
224
+ .safeParse("invalid_value").error!.issues
225
+ ).toMatchInlineSnapshot(`
226
+ [
227
+ {
228
+ "code": "invalid_format",
229
+ "format": "nanoid",
230
+ "message": "Invalid nanoid",
231
+ "origin": "string",
232
+ "path": [],
233
+ "pattern": "/^[a-zA-Z0-9_-]{21}$/",
234
+ },
235
+ {
236
+ "code": "custom",
237
+ "message": "Invalid input",
238
+ "path": [],
239
+ },
240
+ ]
241
+ `);
242
+ expect(
243
+ z
244
+ .cuid()
245
+ .refine(() => false)
246
+ .safeParse("invalid_value").error!.issues
247
+ ).toMatchInlineSnapshot(`
248
+ [
249
+ {
250
+ "code": "invalid_format",
251
+ "format": "cuid",
252
+ "message": "Invalid cuid",
253
+ "origin": "string",
254
+ "path": [],
255
+ "pattern": "/^[cC][^\\s-]{8,}$/",
256
+ },
257
+ {
258
+ "code": "custom",
259
+ "message": "Invalid input",
260
+ "path": [],
261
+ },
262
+ ]
263
+ `);
264
+ expect(
265
+ z
266
+ .cuid2()
267
+ .refine(() => false)
268
+ .safeParse("invalid_value").error!.issues
269
+ ).toMatchInlineSnapshot(`
270
+ [
271
+ {
272
+ "code": "invalid_format",
273
+ "format": "cuid2",
274
+ "message": "Invalid cuid2",
275
+ "origin": "string",
276
+ "path": [],
277
+ "pattern": "/^[0-9a-z]+$/",
278
+ },
279
+ {
280
+ "code": "custom",
281
+ "message": "Invalid input",
282
+ "path": [],
283
+ },
284
+ ]
285
+ `);
286
+ expect(
287
+ z
288
+ .ulid()
289
+ .refine(() => false)
290
+ .safeParse("invalid_value").error!.issues
291
+ ).toMatchInlineSnapshot(`
292
+ [
293
+ {
294
+ "code": "invalid_format",
295
+ "format": "ulid",
296
+ "message": "Invalid ULID",
297
+ "origin": "string",
298
+ "path": [],
299
+ "pattern": "/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/",
300
+ },
301
+ {
302
+ "code": "custom",
303
+ "message": "Invalid input",
304
+ "path": [],
305
+ },
306
+ ]
307
+ `);
308
+ expect(
309
+ z
310
+ .xid()
311
+ .refine(() => false)
312
+ .safeParse("invalid_value").error!.issues
313
+ ).toMatchInlineSnapshot(`
314
+ [
315
+ {
316
+ "code": "invalid_format",
317
+ "format": "xid",
318
+ "message": "Invalid XID",
319
+ "origin": "string",
320
+ "path": [],
321
+ "pattern": "/^[0-9a-vA-V]{20}$/",
322
+ },
323
+ {
324
+ "code": "custom",
325
+ "message": "Invalid input",
326
+ "path": [],
327
+ },
328
+ ]
329
+ `);
330
+ expect(
331
+ z
332
+ .ksuid()
333
+ .refine(() => false)
334
+ .safeParse("invalid_value").error!.issues
335
+ ).toMatchInlineSnapshot(`
336
+ [
337
+ {
338
+ "code": "invalid_format",
339
+ "format": "ksuid",
340
+ "message": "Invalid KSUID",
341
+ "origin": "string",
342
+ "path": [],
343
+ "pattern": "/^[A-Za-z0-9]{27}$/",
344
+ },
345
+ {
346
+ "code": "custom",
347
+ "message": "Invalid input",
348
+ "path": [],
349
+ },
350
+ ]
351
+ `);
352
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/custom.test.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("passing validations", () => {
6
+ const example1 = z.custom<number>((x) => typeof x === "number");
7
+ example1.parse(1234);
8
+ expect(() => example1.parse({})).toThrow();
9
+ });
10
+
11
+ test("string params", () => {
12
+ const example1 = z.custom<number>((x) => typeof x !== "number", "customerr");
13
+ const result = example1.safeParse(1234);
14
+ expect(result.success).toEqual(false);
15
+ expect(JSON.stringify(result.error).includes("customerr")).toEqual(true);
16
+ });
17
+
18
+ test("instanceof", () => {
19
+ const fn = (value: string) => Uint8Array.from(Buffer.from(value, "base64"));
20
+
21
+ // Argument of type 'ZodCustom<Uint8Array<ArrayBuffer>, unknown>' is not assignable to parameter of type '$ZodType<any, Uint8Array<ArrayBuffer>>'.
22
+ z.string().transform(fn).pipe(z.instanceof(Uint8Array));
23
+ });
24
+
25
+ test("non-continuable by default", () => {
26
+ const A = z
27
+ .custom<string>((val) => typeof val === "string")
28
+ .transform((_) => {
29
+ throw new Error("Invalid input");
30
+ });
31
+ expect(A.safeParse(123).error!).toMatchInlineSnapshot(`
32
+ [ZodError: [
33
+ {
34
+ "code": "custom",
35
+ "path": [],
36
+ "message": "Invalid input"
37
+ }
38
+ ]]
39
+ `);
40
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/date.test.ts ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ const beforeBenchmarkDate = new Date(2022, 10, 4);
6
+ const benchmarkDate = new Date(2022, 10, 5);
7
+ const afterBenchmarkDate = new Date(2022, 10, 6);
8
+
9
+ const minCheck = z.date().min(benchmarkDate);
10
+ const maxCheck = z.date().max(benchmarkDate);
11
+
12
+ test("passing validations", () => {
13
+ minCheck.parse(benchmarkDate);
14
+ minCheck.parse(afterBenchmarkDate);
15
+
16
+ maxCheck.parse(benchmarkDate);
17
+ maxCheck.parse(beforeBenchmarkDate);
18
+ });
19
+
20
+ test("failing validations", () => {
21
+ expect(() => minCheck.parse(beforeBenchmarkDate)).toThrow();
22
+ expect(() => maxCheck.parse(afterBenchmarkDate)).toThrow();
23
+ });
24
+
25
+ test("min max getters", () => {
26
+ expect(minCheck.minDate).toEqual(benchmarkDate);
27
+ expect(minCheck.min(afterBenchmarkDate).minDate).toEqual(afterBenchmarkDate);
28
+
29
+ expect(maxCheck.maxDate).toEqual(benchmarkDate);
30
+ expect(maxCheck.max(beforeBenchmarkDate).maxDate).toEqual(beforeBenchmarkDate);
31
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/datetime.test.ts ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { checkSync } from "recheck";
2
+ import { expect, test } from "vitest";
3
+ import * as z from "zod/v4";
4
+
5
+ test("basic datetime parsing", () => {
6
+ const datetime = z.string().datetime();
7
+ datetime.parse("1970-01-01T00:00:00.000Z");
8
+ datetime.parse("2022-10-13T09:52:31.816Z");
9
+ datetime.parse("2022-10-13T09:52:31.8162314Z");
10
+ datetime.parse("1970-01-01T00:00:00Z");
11
+ datetime.parse("2022-10-13T09:52:31Z");
12
+ expect(() => datetime.parse("")).toThrow();
13
+ expect(() => datetime.parse("foo")).toThrow();
14
+ expect(() => datetime.parse("2020-10-14")).toThrow();
15
+ expect(() => datetime.parse("T18:45:12.123")).toThrow();
16
+ expect(() => datetime.parse("2020-10-14T17:42:29+00:00")).toThrow();
17
+ });
18
+
19
+ test("datetime parsing with precision -1", () => {
20
+ const datetimeNoMs = z.string().datetime({ precision: -1, offset: true, local: true });
21
+ datetimeNoMs.parse("1970-01-01T00:00Z");
22
+ datetimeNoMs.parse("2022-10-13T09:52Z");
23
+ datetimeNoMs.parse("2022-10-13T09:52+02:00");
24
+
25
+ datetimeNoMs.parse("2022-10-13T09:52");
26
+ expect(() => datetimeNoMs.parse("tuna")).toThrow();
27
+ expect(() => datetimeNoMs.parse("2022-10-13T09:52+02")).toThrow();
28
+ expect(() => datetimeNoMs.parse("1970-01-01T00:00:00.000Z")).toThrow();
29
+ expect(() => datetimeNoMs.parse("1970-01-01T00:00:00.Z")).toThrow();
30
+ expect(() => datetimeNoMs.parse("2022-10-13T09:52:31.816Z")).toThrow();
31
+ });
32
+
33
+ test("datetime parsing with precision 0", () => {
34
+ const datetimeNoMs = z.string().datetime({ precision: 0 });
35
+ datetimeNoMs.parse("1970-01-01T00:00:00Z");
36
+ datetimeNoMs.parse("2022-10-13T09:52:31Z");
37
+ expect(() => datetimeNoMs.parse("tuna")).toThrow();
38
+ expect(() => datetimeNoMs.parse("1970-01-01T00:00:00.000Z")).toThrow();
39
+ expect(() => datetimeNoMs.parse("1970-01-01T00:00:00.Z")).toThrow();
40
+ expect(() => datetimeNoMs.parse("2022-10-13T09:52:31.816Z")).toThrow();
41
+ });
42
+
43
+ test("datetime parsing with precision 3", () => {
44
+ const datetime3Ms = z.string().datetime({ precision: 3 });
45
+ datetime3Ms.parse("1970-01-01T00:00:00.000Z");
46
+ datetime3Ms.parse("2022-10-13T09:52:31.123Z");
47
+ expect(() => datetime3Ms.parse("tuna")).toThrow();
48
+ expect(() => datetime3Ms.parse("1970-01-01T00:00:00.1Z")).toThrow();
49
+ expect(() => datetime3Ms.parse("1970-01-01T00:00:00.12Z")).toThrow();
50
+ expect(() => datetime3Ms.parse("2022-10-13T09:52:31Z")).toThrow();
51
+ });
52
+
53
+ test("datetime parsing with offset", () => {
54
+ const datetimeOffset = z.string().datetime({ offset: true });
55
+ datetimeOffset.parse("1970-01-01T00:00:00.000Z");
56
+ datetimeOffset.parse("2022-10-13T09:52:31.816234134Z");
57
+ datetimeOffset.parse("1970-01-01T00:00:00Z");
58
+ datetimeOffset.parse("2022-10-13T09:52:31.4Z");
59
+ datetimeOffset.parse("2020-10-14T17:42:29+00:00");
60
+ datetimeOffset.parse("2020-10-14T17:42:29+03:15");
61
+ expect(() => datetimeOffset.parse("2020-10-14T17:42:29+0315")).toThrow();
62
+ expect(() => datetimeOffset.parse("2020-10-14T17:42:29+03")).toThrow();
63
+ expect(() => datetimeOffset.parse("tuna")).toThrow();
64
+ expect(() => datetimeOffset.parse("2022-10-13T09:52:31.Z")).toThrow();
65
+ });
66
+
67
+ test("datetime parsing with offset and precision 0", () => {
68
+ const datetimeOffsetNoMs = z.string().datetime({ offset: true, precision: 0 });
69
+ datetimeOffsetNoMs.parse("1970-01-01T00:00:00Z");
70
+ datetimeOffsetNoMs.parse("2022-10-13T09:52:31Z");
71
+ datetimeOffsetNoMs.parse("2020-10-14T17:42:29+00:00");
72
+ expect(() => datetimeOffsetNoMs.parse("2020-10-14T17:42:29+0000")).toThrow();
73
+ expect(() => datetimeOffsetNoMs.parse("2020-10-14T17:42:29+00")).toThrow();
74
+ expect(() => datetimeOffsetNoMs.parse("tuna")).toThrow();
75
+ expect(() => datetimeOffsetNoMs.parse("1970-01-01T00:00:00.000Z")).toThrow();
76
+ expect(() => datetimeOffsetNoMs.parse("1970-01-01T00:00:00.Z")).toThrow();
77
+ expect(() => datetimeOffsetNoMs.parse("2022-10-13T09:52:31.816Z")).toThrow();
78
+ expect(() => datetimeOffsetNoMs.parse("2020-10-14T17:42:29.124+00:00")).toThrow();
79
+ });
80
+
81
+ test("datetime parsing with offset and precision 4", () => {
82
+ const datetimeOffset4Ms = z.string().datetime({ offset: true, precision: 4 });
83
+ datetimeOffset4Ms.parse("1970-01-01T00:00:00.1234Z");
84
+ datetimeOffset4Ms.parse("2020-10-14T17:42:29.1234+00:00");
85
+ expect(() => datetimeOffset4Ms.parse("2020-10-14T17:42:29.1234+0000")).toThrow();
86
+ expect(() => datetimeOffset4Ms.parse("2020-10-14T17:42:29.1234+00")).toThrow();
87
+ expect(() => datetimeOffset4Ms.parse("tuna")).toThrow();
88
+ expect(() => datetimeOffset4Ms.parse("1970-01-01T00:00:00.123Z")).toThrow();
89
+ expect(() => datetimeOffset4Ms.parse("2020-10-14T17:42:29.124+00:00")).toThrow();
90
+ });
91
+
92
+ test("datetime offset normalization", () => {
93
+ const a = z.iso.datetime({ offset: true });
94
+
95
+ expect(a.safeParse("2020-10-14T17:42:29+02")).toMatchObject({ success: false });
96
+ expect(a.safeParse("2020-10-14T17:42:29+0200")).toMatchObject({ success: false });
97
+ a.safeParse("2020-10-14T17:42:29+02:00");
98
+ });
99
+
100
+ test("datetime parsing with local option", () => {
101
+ const a = z.string().datetime({ local: true });
102
+
103
+ expect(a.safeParse("1970-01-01T00:00")).toMatchObject({ success: true });
104
+ expect(a.safeParse("1970-01-01T00:00:00")).toMatchObject({ success: true });
105
+ expect(a.safeParse("2022-10-13T09:52:31.816")).toMatchObject({ success: true });
106
+ expect(a.safeParse("1970-01-01T00:00:00.000")).toMatchObject({ success: true });
107
+ expect(a.safeParse("1970-01-01T00")).toMatchObject({ success: false });
108
+
109
+ // Should reject timezone indicators and invalid formats
110
+
111
+ expect(() => a.parse("2022-10-13T09:52:31+00:00")).toThrow();
112
+ expect(() => a.parse("2022-10-13 09:52:31")).toThrow();
113
+ expect(() => a.parse("2022-10-13T24:52:31")).toThrow();
114
+ expect(() => a.parse("2022-10-13T24:52")).toThrow();
115
+ expect(() => a.parse("2022-10-13T24:52Z")).toThrow();
116
+ });
117
+
118
+ test("datetime parsing with local and offset", () => {
119
+ const a = z.string().datetime({ local: true, offset: true });
120
+
121
+ // expect(a.parse("2022-10-13T12:52")).toEqual("2022-10-13T12:52:00");
122
+ a.parse("2022-10-13T12:52:00");
123
+ a.parse("2022-10-13T12:52:00Z");
124
+ a.parse("2022-10-13T12:52Z");
125
+ a.parse("2022-10-13T12:52");
126
+ a.parse("2022-10-13T12:52+02:00");
127
+ expect(() => a.parse("2022-10-13T12:52:00+02")).toThrow();
128
+ // expect(() => a.parse("2022-10-13T12:52Z")).toThrow();
129
+ // expect(() => a.parse("2022-10-13T12:52+02:00")).toThrow();
130
+ });
131
+
132
+ test("date parsing", () => {
133
+ const date = z.string().date();
134
+ date.parse("1970-01-01");
135
+ date.parse("2022-01-31");
136
+ date.parse("2022-03-31");
137
+ date.parse("2022-04-30");
138
+ date.parse("2022-05-31");
139
+ date.parse("2022-06-30");
140
+ date.parse("2022-07-31");
141
+ date.parse("2022-08-31");
142
+ date.parse("2022-09-30");
143
+ date.parse("2022-10-31");
144
+ date.parse("2022-11-30");
145
+ date.parse("2022-12-31");
146
+
147
+ date.parse("2000-02-29");
148
+ date.parse("2400-02-29");
149
+ expect(() => date.parse("2022-02-29")).toThrow();
150
+ expect(() => date.parse("2100-02-29")).toThrow();
151
+ expect(() => date.parse("2200-02-29")).toThrow();
152
+ expect(() => date.parse("2300-02-29")).toThrow();
153
+ expect(() => date.parse("2500-02-29")).toThrow();
154
+
155
+ expect(() => date.parse("")).toThrow();
156
+ expect(() => date.parse("foo")).toThrow();
157
+ expect(() => date.parse("200-01-01")).toThrow();
158
+ expect(() => date.parse("20000-01-01")).toThrow();
159
+ expect(() => date.parse("2000-0-01")).toThrow();
160
+ expect(() => date.parse("2000-011-01")).toThrow();
161
+ expect(() => date.parse("2000-01-0")).toThrow();
162
+ expect(() => date.parse("2000-01-011")).toThrow();
163
+ expect(() => date.parse("2000/01/01")).toThrow();
164
+ expect(() => date.parse("01-01-2022")).toThrow();
165
+ expect(() => date.parse("01/01/2022")).toThrow();
166
+ expect(() => date.parse("2000-01-01 00:00:00Z")).toThrow();
167
+ expect(() => date.parse("2020-10-14T17:42:29+00:00")).toThrow();
168
+ expect(() => date.parse("2020-10-14T17:42:29Z")).toThrow();
169
+ expect(() => date.parse("2020-10-14T17:42:29")).toThrow();
170
+ expect(() => date.parse("2020-10-14T17:42:29.123Z")).toThrow();
171
+
172
+ expect(() => date.parse("2000-00-12")).toThrow();
173
+ expect(() => date.parse("2000-12-00")).toThrow();
174
+ expect(() => date.parse("2000-01-32")).toThrow();
175
+ expect(() => date.parse("2000-13-01")).toThrow();
176
+ expect(() => date.parse("2000-21-01")).toThrow();
177
+
178
+ expect(() => date.parse("2000-02-30")).toThrow();
179
+ expect(() => date.parse("2000-02-31")).toThrow();
180
+ expect(() => date.parse("2000-04-31")).toThrow();
181
+ expect(() => date.parse("2000-06-31")).toThrow();
182
+ expect(() => date.parse("2000-09-31")).toThrow();
183
+ expect(() => date.parse("2000-11-31")).toThrow();
184
+ });
185
+
186
+ test("time parsing", () => {
187
+ const time = z.string().time();
188
+ time.parse("00:00:00");
189
+ time.parse("23:00:00");
190
+ time.parse("00:59:00");
191
+ time.parse("00:00:59");
192
+ time.parse("23:59:59");
193
+ time.parse("09:52:31");
194
+ time.parse("23:59:59.9999999");
195
+ time.parse("00:00");
196
+ expect(() => time.parse("")).toThrow();
197
+ expect(() => time.parse("foo")).toThrow();
198
+ expect(() => time.parse("00:00:00Z")).toThrow();
199
+ expect(() => time.parse("0:00:00")).toThrow();
200
+ expect(() => time.parse("00:0:00")).toThrow();
201
+ expect(() => time.parse("00:00:0")).toThrow();
202
+ expect(() => time.parse("00:00:00.000+00:00")).toThrow();
203
+ expect(() => time.parse("24:00:00")).toThrow();
204
+ expect(() => time.parse("00:60:00")).toThrow();
205
+ expect(() => time.parse("00:00:60")).toThrow();
206
+ expect(() => time.parse("24:60:60")).toThrow();
207
+
208
+ const time2 = z.string().time({ precision: 2 });
209
+ time2.parse("00:00:00.00");
210
+ time2.parse("09:52:31.12");
211
+ time2.parse("23:59:59.99");
212
+ expect(() => time2.parse("")).toThrow();
213
+ expect(() => time2.parse("foo")).toThrow();
214
+ expect(() => time2.parse("00:00:00")).toThrow();
215
+ expect(() => time2.parse("00:00:00.00Z")).toThrow();
216
+ expect(() => time2.parse("00:00:00.0")).toThrow();
217
+ expect(() => time2.parse("00:00:00.000")).toThrow();
218
+ expect(() => time2.parse("00:00:00.00+00:00")).toThrow();
219
+
220
+ const time3 = z.string().time({ precision: z.TimePrecision.Minute });
221
+ time3.parse("00:00");
222
+ expect(() => time3.parse("00:00:00")).toThrow();
223
+ });
224
+
225
+ test("duration", () => {
226
+ const duration = z.string().duration();
227
+
228
+ const validDurations = [
229
+ "P3Y6M4DT12H30M5S",
230
+ "P2Y9M3DT12H31M8.001S",
231
+ // "+P3Y6M4DT12H30M5S",
232
+ // "-PT0.001S",
233
+ // "+PT0.001S",
234
+ "PT0,001S",
235
+ "PT12H30M5S",
236
+ // "-P2M1D",
237
+ // "P-2M-1D",
238
+ // "-P5DT10H",
239
+ // "P-5DT-10H",
240
+ "P1Y",
241
+ "P2MT30M",
242
+ "PT6H",
243
+ "P5W",
244
+ // "P0.5Y",
245
+ // "P0,5Y",
246
+ // "P42YT7.004M",
247
+ ];
248
+
249
+ const invalidDurations = [
250
+ "foo bar",
251
+ "",
252
+ " ",
253
+ "P",
254
+ "PT",
255
+ "P1Y2MT",
256
+ "T1H",
257
+ "P0.5Y1D",
258
+ "P0,5Y6M",
259
+ "P1YT",
260
+ "P-2M-1D",
261
+ "P-5DT-10H",
262
+ "P1W2D",
263
+ "-P1D",
264
+ ];
265
+
266
+ for (const val of validDurations) {
267
+ const result = duration.safeParse(val);
268
+ if (!result.success) {
269
+ throw Error(`Valid duration could not be parsed: ${val}`);
270
+ }
271
+ }
272
+
273
+ for (const val of invalidDurations) {
274
+ const result = duration.safeParse(val);
275
+
276
+ if (result.success) {
277
+ throw Error(`Invalid duration was successful parsed: ${val}`);
278
+ }
279
+
280
+ expect(result.error.issues[0].message).toEqual("Invalid ISO duration");
281
+ }
282
+ });
283
+
284
+ test("redos checker", () => {
285
+ const a = z.iso.datetime();
286
+ const b = z.string().datetime({ offset: true });
287
+ const c = z.string().datetime({ local: true });
288
+ const d = z.string().datetime({ local: true, offset: true, precision: 3 });
289
+ const e = z.string().date();
290
+ const f = z.string().time();
291
+ const g = z.string().duration();
292
+ for (const schema of [a, b, c, d, e, f, g]) {
293
+ const result = checkSync(schema._zod.pattern.source, "");
294
+ if (result.status !== "safe") throw Error("ReDoS issue");
295
+ }
296
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/default.test.ts ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import { z } from "zod/v4";
3
+
4
+ test("basic defaults", () => {
5
+ expect(z.string().default("default").parse(undefined)).toBe("default");
6
+ });
7
+
8
+ test("default with optional", () => {
9
+ const schema = z.string().optional().default("default");
10
+ expect(schema.parse(undefined)).toBe("default");
11
+ expect(schema.unwrap().parse(undefined)).toBe(undefined);
12
+ });
13
+
14
+ test("default with transform", () => {
15
+ const stringWithDefault = z
16
+ .string()
17
+ .transform((val) => val.toUpperCase())
18
+ .default("default");
19
+ expect(stringWithDefault.parse(undefined)).toBe("default");
20
+ expect(stringWithDefault).toBeInstanceOf(z.ZodDefault);
21
+ expect(stringWithDefault.unwrap()).toBeInstanceOf(z.ZodPipe);
22
+ expect(stringWithDefault.unwrap().in).toBeInstanceOf(z.ZodString);
23
+ expect(stringWithDefault.unwrap().out).toBeInstanceOf(z.ZodTransform);
24
+
25
+ type inp = z.input<typeof stringWithDefault>;
26
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
27
+ type out = z.output<typeof stringWithDefault>;
28
+ expectTypeOf<out>().toEqualTypeOf<string>();
29
+ });
30
+
31
+ test("default on existing optional", () => {
32
+ const stringWithDefault = z.string().optional().default("asdf");
33
+ expect(stringWithDefault.parse(undefined)).toBe("asdf");
34
+ expect(stringWithDefault).toBeInstanceOf(z.ZodDefault);
35
+ expect(stringWithDefault.unwrap()).toBeInstanceOf(z.ZodOptional);
36
+ expect(stringWithDefault.unwrap().unwrap()).toBeInstanceOf(z.ZodString);
37
+
38
+ type inp = z.input<typeof stringWithDefault>;
39
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
40
+ type out = z.output<typeof stringWithDefault>;
41
+ expectTypeOf<out>().toEqualTypeOf<string>();
42
+ });
43
+
44
+ test("optional on default", () => {
45
+ const stringWithDefault = z.string().default("asdf").optional();
46
+
47
+ type inp = z.input<typeof stringWithDefault>;
48
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
49
+ type out = z.output<typeof stringWithDefault>;
50
+ expectTypeOf<out>().toEqualTypeOf<string | undefined>();
51
+
52
+ expect(stringWithDefault.parse(undefined)).toBe("asdf");
53
+ });
54
+
55
+ // test("complex chain example", () => {
56
+ // const complex = z
57
+ // .string()
58
+ // .default("asdf")
59
+ // .transform((val) => val.toUpperCase())
60
+ // .default("qwer")
61
+ // .unwrap()
62
+ // .optional()
63
+ // .default("asdfasdf");
64
+
65
+ // expect(complex.parse(undefined)).toBe("asdfasdf");
66
+ // });
67
+
68
+ test("removeDefault", () => {
69
+ const stringWithRemovedDefault = z.string().default("asdf").removeDefault();
70
+
71
+ type out = z.output<typeof stringWithRemovedDefault>;
72
+ expectTypeOf<out>().toEqualTypeOf<string>();
73
+ });
74
+
75
+ test("apply default at output", () => {
76
+ const schema = z
77
+ .string()
78
+ .transform((_) => (Math.random() > 0 ? undefined : _))
79
+ .default("asdf");
80
+ expect(schema.parse("")).toEqual("asdf");
81
+ });
82
+
83
+ test("nested", () => {
84
+ const inner = z.string().default("asdf");
85
+ const outer = z.object({ inner }).default({
86
+ inner: "qwer",
87
+ });
88
+ type input = z.input<typeof outer>;
89
+ expectTypeOf<input>().toEqualTypeOf<{ inner?: string | undefined } | undefined>();
90
+ type out = z.output<typeof outer>;
91
+ expectTypeOf<out>().toEqualTypeOf<{ inner: string }>();
92
+ expect(outer.parse(undefined)).toEqual({ inner: "qwer" });
93
+ expect(outer.parse({})).toEqual({ inner: "asdf" });
94
+ expect(outer.parse({ inner: undefined })).toEqual({ inner: "asdf" });
95
+ });
96
+
97
+ test("chained defaults", () => {
98
+ const stringWithDefault = z.string().default("inner").default("outer");
99
+ const result = stringWithDefault.parse(undefined);
100
+ expect(result).toEqual("outer");
101
+ });
102
+
103
+ test("object optionality", () => {
104
+ const schema = z.object({
105
+ hi: z.string().default("hi"),
106
+ });
107
+ type schemaInput = z.input<typeof schema>;
108
+ type schemaOutput = z.output<typeof schema>;
109
+ expectTypeOf<schemaInput>().toEqualTypeOf<{ hi?: string | undefined }>();
110
+ expectTypeOf<schemaOutput>().toEqualTypeOf<{ hi: string }>();
111
+ expect(schema.parse({})).toEqual({
112
+ hi: "hi",
113
+ });
114
+ });
115
+
116
+ test("nested prefault/default", () => {
117
+ const a = z
118
+ .string()
119
+ .default("a")
120
+ .refine((val) => val.startsWith("a"));
121
+ const b = z
122
+ .string()
123
+ .refine((val) => val.startsWith("b"))
124
+ .default("b");
125
+ const c = z
126
+ .string()
127
+ .prefault("c")
128
+ .refine((val) => val.startsWith("c"));
129
+ const d = z
130
+ .string()
131
+ .refine((val) => val.startsWith("d"))
132
+ .prefault("d");
133
+
134
+ const obj = z.object({
135
+ a,
136
+ b,
137
+ c,
138
+ d,
139
+ });
140
+
141
+ expect(obj.safeParse({ a: "a1", b: "b1", c: "c1", d: "d1" })).toMatchInlineSnapshot(`
142
+ {
143
+ "data": {
144
+ "a": "a1",
145
+ "b": "b1",
146
+ "c": "c1",
147
+ "d": "d1",
148
+ },
149
+ "success": true,
150
+ }
151
+ `);
152
+
153
+ expect(obj.safeParse({ a: "f", b: "f", c: "f", d: "f" })).toMatchInlineSnapshot(`
154
+ {
155
+ "error": [ZodError: [
156
+ {
157
+ "code": "custom",
158
+ "path": [
159
+ "a"
160
+ ],
161
+ "message": "Invalid input"
162
+ },
163
+ {
164
+ "code": "custom",
165
+ "path": [
166
+ "b"
167
+ ],
168
+ "message": "Invalid input"
169
+ },
170
+ {
171
+ "code": "custom",
172
+ "path": [
173
+ "c"
174
+ ],
175
+ "message": "Invalid input"
176
+ },
177
+ {
178
+ "code": "custom",
179
+ "path": [
180
+ "d"
181
+ ],
182
+ "message": "Invalid input"
183
+ }
184
+ ]],
185
+ "success": false,
186
+ }
187
+ `);
188
+
189
+ expect(obj.safeParse({})).toMatchInlineSnapshot(`
190
+ {
191
+ "data": {
192
+ "a": "a",
193
+ "b": "b",
194
+ "c": "c",
195
+ "d": "d",
196
+ },
197
+ "success": true,
198
+ }
199
+ `);
200
+
201
+ expect(obj.safeParse({ a: undefined, b: undefined, c: undefined, d: undefined })).toMatchInlineSnapshot(`
202
+ {
203
+ "data": {
204
+ "a": "a",
205
+ "b": "b",
206
+ "c": "c",
207
+ "d": "d",
208
+ },
209
+ "success": true,
210
+ }
211
+ `);
212
+
213
+ const obj2 = z.object({
214
+ a: a.optional(),
215
+ b: b.optional(),
216
+ c: c.optional(),
217
+ d: d.optional(),
218
+ });
219
+ expect(obj2.safeParse({ a: undefined, b: undefined, c: undefined, d: undefined })).toMatchInlineSnapshot(`
220
+ {
221
+ "data": {
222
+ "a": "a",
223
+ "b": "b",
224
+ "c": "c",
225
+ "d": "d",
226
+ },
227
+ "success": true,
228
+ }
229
+ `);
230
+
231
+ expect(a.parse(undefined)).toBe("a");
232
+ expect(b.parse(undefined)).toBe("b");
233
+ expect(c.parse(undefined)).toBe("c");
234
+ expect(d.parse(undefined)).toBe("d");
235
+ });
236
+
237
+ test("failing default", () => {
238
+ const a = z
239
+ .string()
240
+ .default("z")
241
+ .refine((val) => val.startsWith("a"));
242
+ const b = z
243
+ .string()
244
+ .refine((val) => val.startsWith("b"))
245
+ .default("z");
246
+ const c = z
247
+ .string()
248
+ .prefault("z")
249
+ .refine((val) => val.startsWith("c"));
250
+ const d = z
251
+ .string()
252
+ .refine((val) => val.startsWith("d"))
253
+ .prefault("z");
254
+
255
+ const obj = z.object({
256
+ a,
257
+ b,
258
+ c,
259
+ d,
260
+ });
261
+
262
+ expect(
263
+ obj.safeParse({
264
+ a: undefined,
265
+ b: undefined,
266
+ c: undefined,
267
+ d: undefined,
268
+ }).error!.issues
269
+ ).toMatchInlineSnapshot(`
270
+ [
271
+ {
272
+ "code": "custom",
273
+ "message": "Invalid input",
274
+ "path": [
275
+ "a",
276
+ ],
277
+ },
278
+ {
279
+ "code": "custom",
280
+ "message": "Invalid input",
281
+ "path": [
282
+ "c",
283
+ ],
284
+ },
285
+ {
286
+ "code": "custom",
287
+ "message": "Invalid input",
288
+ "path": [
289
+ "d",
290
+ ],
291
+ },
292
+ ]
293
+ `);
294
+ });
295
+
296
+ test("partial should not clobber defaults", () => {
297
+ const objWithDefaults = z.object({
298
+ a: z.string().default("defaultA"),
299
+ b: z.string().default("defaultB"),
300
+ c: z.string().default("defaultC"),
301
+ });
302
+
303
+ const objPartialWithOneRequired = objWithDefaults.partial(); //.required({ a: true });
304
+
305
+ const test = objPartialWithOneRequired.parse({});
306
+ expect(test).toMatchInlineSnapshot(`
307
+ {
308
+ "a": "defaultA",
309
+ "b": "defaultB",
310
+ "c": "defaultC",
311
+ }
312
+ `);
313
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/description.test.ts ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ const description = "a description";
6
+
7
+ // test("passing `description` to schema should add a description", () => {
8
+ // expect(z.string({ description }).description).toEqual(description);
9
+ // expect(z.number({ description }).description).toEqual(description);
10
+ // expect(z.boolean({ description }).description).toEqual(description);
11
+ // });
12
+
13
+ test(".describe", () => {
14
+ expect(z.string().describe(description).description).toEqual(description);
15
+ expect(z.number().describe(description).description).toEqual(description);
16
+ expect(z.boolean().describe(description).description).toEqual(description);
17
+ });
18
+
19
+ test("adding description with z.globalRegistry", () => {
20
+ const schema = z.string();
21
+ z.core.globalRegistry.add(schema, { description });
22
+ z.core.globalRegistry.get(schema);
23
+ expect(schema.description).toEqual(description);
24
+ });
25
+
26
+ // in Zod 4 descriptions are not inherited
27
+ // test("description should carry over to chained schemas", () => {
28
+ // const schema = z.string().describe(description);
29
+ // expect(schema.description).toEqual(description);
30
+ // expect(schema.optional().description).toEqual(description);
31
+ // expect(schema.optional().nullable().default("default").description).toEqual(description);
32
+ // });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts ADDED
@@ -0,0 +1,619 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("_values", () => {
6
+ expect(z.string()._zod.values).toEqual(undefined);
7
+ expect(z.enum(["a", "b"])._zod.values).toEqual(new Set(["a", "b"]));
8
+ expect(z.nativeEnum({ a: "A", b: "B" })._zod.values).toEqual(new Set(["A", "B"]));
9
+ expect(z.literal("test")._zod.values).toEqual(new Set(["test"]));
10
+ expect(z.literal(123)._zod.values).toEqual(new Set([123]));
11
+ expect(z.literal(true)._zod.values).toEqual(new Set([true]));
12
+ expect(z.literal(BigInt(123))._zod.values).toEqual(new Set([BigInt(123)]));
13
+ expect(z.undefined()._zod.values).toEqual(new Set([undefined]));
14
+ expect(z.null()._zod.values).toEqual(new Set([null]));
15
+
16
+ const t = z.literal("test");
17
+ expect(t.optional()._zod.values).toEqual(new Set(["test", undefined]));
18
+ expect(t.nullable()._zod.values).toEqual(new Set(["test", null]));
19
+ expect(t.default("test")._zod.values).toEqual(new Set(["test"]));
20
+ expect(t.catch("test")._zod.values).toEqual(new Set(["test"]));
21
+
22
+ const pre = z.preprocess((val) => String(val), z.string()).pipe(z.literal("test"));
23
+ expect(pre._zod.values).toEqual(undefined);
24
+
25
+ const post = z.literal("test").transform((_) => Math.random());
26
+ expect(post._zod.values).toEqual(new Set(["test"]));
27
+
28
+ // Test that readonly literals pass through their values property
29
+ expect(z.literal("test").readonly()._zod.values).toEqual(new Set(["test"]));
30
+ });
31
+
32
+ test("valid parse - object", () => {
33
+ expect(
34
+ z
35
+ .discriminatedUnion("type", [
36
+ z.object({ type: z.literal("a"), a: z.string() }),
37
+ z.object({ type: z.literal("b"), b: z.string() }),
38
+ ])
39
+ .parse({ type: "a", a: "abc" })
40
+ ).toEqual({ type: "a", a: "abc" });
41
+ });
42
+
43
+ test("valid - include discriminator key (deprecated)", () => {
44
+ expect(
45
+ z
46
+ .discriminatedUnion("type", [
47
+ z.object({ type: z.literal("a"), a: z.string() }),
48
+ z.object({ type: z.literal("b"), b: z.string() }),
49
+ ])
50
+ .parse({ type: "a", a: "abc" })
51
+ ).toEqual({ type: "a", a: "abc" });
52
+ });
53
+
54
+ test("valid - optional discriminator (object)", () => {
55
+ const schema = z.discriminatedUnion("type", [
56
+ z.object({ type: z.literal("a").optional(), a: z.string() }),
57
+ z.object({ type: z.literal("b"), b: z.string() }),
58
+ ]);
59
+ expect(schema.parse({ type: "a", a: "abc" })).toEqual({ type: "a", a: "abc" });
60
+ expect(schema.parse({ a: "abc" })).toEqual({ a: "abc" });
61
+ });
62
+
63
+ test("valid - discriminator value of various primitive types", () => {
64
+ const schema = z.discriminatedUnion("type", [
65
+ z.object({ type: z.literal("1"), val: z.string() }),
66
+ z.object({ type: z.literal(1), val: z.string() }),
67
+ z.object({ type: z.literal(BigInt(1)), val: z.string() }),
68
+ z.object({ type: z.literal("true"), val: z.string() }),
69
+ z.object({ type: z.literal(true), val: z.string() }),
70
+ z.object({ type: z.literal("null"), val: z.string() }),
71
+ z.object({ type: z.null(), val: z.string() }),
72
+ z.object({ type: z.literal("undefined"), val: z.string() }),
73
+ z.object({ type: z.undefined(), val: z.string() }),
74
+ ]);
75
+
76
+ expect(schema.parse({ type: "1", val: "val" })).toEqual({ type: "1", val: "val" });
77
+ expect(schema.parse({ type: 1, val: "val" })).toEqual({ type: 1, val: "val" });
78
+ expect(schema.parse({ type: BigInt(1), val: "val" })).toEqual({
79
+ type: BigInt(1),
80
+ val: "val",
81
+ });
82
+ expect(schema.parse({ type: "true", val: "val" })).toEqual({
83
+ type: "true",
84
+ val: "val",
85
+ });
86
+ expect(schema.parse({ type: true, val: "val" })).toEqual({
87
+ type: true,
88
+ val: "val",
89
+ });
90
+ expect(schema.parse({ type: "null", val: "val" })).toEqual({
91
+ type: "null",
92
+ val: "val",
93
+ });
94
+ expect(schema.parse({ type: null, val: "val" })).toEqual({
95
+ type: null,
96
+ val: "val",
97
+ });
98
+ expect(schema.parse({ type: "undefined", val: "val" })).toEqual({
99
+ type: "undefined",
100
+ val: "val",
101
+ });
102
+ expect(schema.parse({ type: undefined, val: "val" })).toEqual({
103
+ type: undefined,
104
+ val: "val",
105
+ });
106
+
107
+ const fail = schema.safeParse({
108
+ type: "not_a_key",
109
+ val: "val",
110
+ });
111
+ expect(fail.error).toBeInstanceOf(z.ZodError);
112
+ });
113
+
114
+ test("invalid - null", () => {
115
+ try {
116
+ z.discriminatedUnion("type", [
117
+ z.object({ type: z.literal("a"), a: z.string() }),
118
+ z.object({ type: z.literal("b"), b: z.string() }),
119
+ ]).parse(null);
120
+ throw new Error();
121
+ } catch (e: any) {
122
+ // [
123
+ // {
124
+ // code: z.ZodIssueCode.invalid_type,
125
+ // expected: z.ZodParsedType.object,
126
+ // input: null,
127
+ // message: "Expected object, received null",
128
+ // received: z.ZodParsedType.null,
129
+ // path: [],
130
+ // },
131
+ // ];
132
+ expect(e.issues).toMatchInlineSnapshot(`
133
+ [
134
+ {
135
+ "code": "invalid_type",
136
+ "expected": "object",
137
+ "message": "Invalid input: expected object, received null",
138
+ "path": [],
139
+ },
140
+ ]
141
+ `);
142
+ }
143
+ });
144
+
145
+ test("invalid discriminator value", () => {
146
+ const result = z
147
+ .discriminatedUnion("type", [
148
+ z.object({ type: z.literal("a"), a: z.string() }),
149
+ z.object({ type: z.literal("b"), b: z.string() }),
150
+ ])
151
+ .safeParse({ type: "x", a: "abc" });
152
+
153
+ expect(result).toMatchInlineSnapshot(`
154
+ {
155
+ "error": [ZodError: [
156
+ {
157
+ "code": "invalid_union",
158
+ "errors": [],
159
+ "note": "No matching discriminator",
160
+ "path": [
161
+ "type"
162
+ ],
163
+ "message": "Invalid input"
164
+ }
165
+ ]],
166
+ "success": false,
167
+ }
168
+ `);
169
+ });
170
+
171
+ test("invalid discriminator value - unionFallback", () => {
172
+ const result = z
173
+ .discriminatedUnion(
174
+ "type",
175
+ [z.object({ type: z.literal("a"), a: z.string() }), z.object({ type: z.literal("b"), b: z.string() })],
176
+ { unionFallback: true }
177
+ )
178
+ .safeParse({ type: "x", a: "abc" });
179
+ expect(result).toMatchInlineSnapshot(`
180
+ {
181
+ "error": [ZodError: [
182
+ {
183
+ "code": "invalid_union",
184
+ "errors": [
185
+ [
186
+ {
187
+ "code": "invalid_value",
188
+ "values": [
189
+ "a"
190
+ ],
191
+ "path": [
192
+ "type"
193
+ ],
194
+ "message": "Invalid input: expected \\"a\\""
195
+ }
196
+ ],
197
+ [
198
+ {
199
+ "code": "invalid_value",
200
+ "values": [
201
+ "b"
202
+ ],
203
+ "path": [
204
+ "type"
205
+ ],
206
+ "message": "Invalid input: expected \\"b\\""
207
+ },
208
+ {
209
+ "expected": "string",
210
+ "code": "invalid_type",
211
+ "path": [
212
+ "b"
213
+ ],
214
+ "message": "Invalid input: expected string, received undefined"
215
+ }
216
+ ]
217
+ ],
218
+ "path": [],
219
+ "message": "Invalid input"
220
+ }
221
+ ]],
222
+ "success": false,
223
+ }
224
+ `);
225
+ });
226
+
227
+ test("valid discriminator value, invalid data", () => {
228
+ const result = z
229
+ .discriminatedUnion("type", [
230
+ z.object({ type: z.literal("a"), a: z.string() }),
231
+ z.object({ type: z.literal("b"), b: z.string() }),
232
+ ])
233
+ .safeParse({ type: "a", b: "abc" });
234
+
235
+ // [
236
+ // {
237
+ // code: z.ZodIssueCode.invalid_type,
238
+ // expected: z.ZodParsedType.string,
239
+ // message: "Required",
240
+ // path: ["a"],
241
+ // received: z.ZodParsedType.undefined,
242
+ // },
243
+ // ];
244
+ expect(result).toMatchInlineSnapshot(`
245
+ {
246
+ "error": [ZodError: [
247
+ {
248
+ "expected": "string",
249
+ "code": "invalid_type",
250
+ "path": [
251
+ "a"
252
+ ],
253
+ "message": "Invalid input: expected string, received undefined"
254
+ }
255
+ ]],
256
+ "success": false,
257
+ }
258
+ `);
259
+ });
260
+
261
+ test("wrong schema - missing discriminator", () => {
262
+ try {
263
+ z.discriminatedUnion("type", [
264
+ z.object({ type: z.literal("a"), a: z.string() }),
265
+ z.object({ b: z.string() }) as any,
266
+ ])._zod.propValues;
267
+ throw new Error();
268
+ } catch (e: any) {
269
+ expect(e.message.includes("Invalid discriminated union option")).toBe(true);
270
+ }
271
+ });
272
+
273
+ // removed to account for unions of unions
274
+ // test("wrong schema - duplicate discriminator values", () => {
275
+ // try {
276
+ // z.discriminatedUnion("type",[
277
+ // z.object({ type: z.literal("a"), a: z.string() }),
278
+ // z.object({ type: z.literal("a"), b: z.string() }),
279
+ // ]);
280
+ // throw new Error();
281
+ // } catch (e: any) {
282
+ // expect(e.message.includes("Duplicate discriminator value")).toEqual(true);
283
+ // }
284
+ // });
285
+
286
+ test("async - valid", async () => {
287
+ const schema = await z.discriminatedUnion("type", [
288
+ z.object({
289
+ type: z.literal("a"),
290
+ a: z
291
+ .string()
292
+ .refine(async () => true)
293
+ .transform(async (val) => Number(val)),
294
+ }),
295
+ z.object({
296
+ type: z.literal("b"),
297
+ b: z.string(),
298
+ }),
299
+ ]);
300
+ const data = { type: "a", a: "1" };
301
+ const result = await schema.safeParseAsync(data);
302
+ expect(result.data).toEqual({ type: "a", a: 1 });
303
+ });
304
+
305
+ test("async - invalid", async () => {
306
+ // try {
307
+ const a = z.discriminatedUnion("type", [
308
+ z.object({
309
+ type: z.literal("a"),
310
+ a: z
311
+ .string()
312
+ .refine(async () => true)
313
+ .transform(async (val) => val),
314
+ }),
315
+ z.object({
316
+ type: z.literal("b"),
317
+ b: z.string(),
318
+ }),
319
+ ]);
320
+ const result = await a.safeParseAsync({ type: "a", a: 1 });
321
+
322
+ // expect(JSON.parse(e.message)).toEqual([
323
+ // {
324
+ // code: "invalid_type",
325
+ // expected: "string",
326
+ // input: 1,
327
+ // received: "number",
328
+ // path: ["a"],
329
+ // message: "Expected string, received number",
330
+ // },
331
+ // ]);
332
+ expect(result.error).toMatchInlineSnapshot(`
333
+ [ZodError: [
334
+ {
335
+ "expected": "string",
336
+ "code": "invalid_type",
337
+ "path": [
338
+ "a"
339
+ ],
340
+ "message": "Invalid input: expected string, received number"
341
+ }
342
+ ]]
343
+ `);
344
+ });
345
+
346
+ test("valid - literals with .default or .pipe", () => {
347
+ const schema = z.discriminatedUnion("type", [
348
+ z.object({
349
+ type: z.literal("foo").default("foo"),
350
+ a: z.string(),
351
+ }),
352
+ z.object({
353
+ type: z.literal("custom"),
354
+ method: z.string(),
355
+ }),
356
+ z.object({
357
+ type: z.literal("bar").transform((val) => val),
358
+ c: z.string(),
359
+ }),
360
+ ]);
361
+ expect(schema.parse({ type: "foo", a: "foo" })).toEqual({
362
+ type: "foo",
363
+ a: "foo",
364
+ });
365
+ });
366
+
367
+ test("enum and nativeEnum", () => {
368
+ enum MyEnum {
369
+ d = 0,
370
+ e = "e",
371
+ }
372
+
373
+ const schema = z.discriminatedUnion("key", [
374
+ z.object({
375
+ key: z.literal("a"),
376
+ // Add other properties specific to this option
377
+ }),
378
+ z.object({
379
+ key: z.enum(["b", "c"]),
380
+ // Add other properties specific to this option
381
+ }),
382
+ z.object({
383
+ key: z.nativeEnum(MyEnum),
384
+ // Add other properties specific to this option
385
+ }),
386
+ ]);
387
+
388
+ type schema = z.infer<typeof schema>;
389
+ expectTypeOf<schema>().toEqualTypeOf<{ key: "a" } | { key: "b" | "c" } | { key: MyEnum.d | MyEnum.e }>();
390
+
391
+ schema.parse({ key: "a" });
392
+ schema.parse({ key: "b" });
393
+ schema.parse({ key: "c" });
394
+ schema.parse({ key: MyEnum.d });
395
+ schema.parse({ key: MyEnum.e });
396
+ schema.parse({ key: "e" });
397
+ });
398
+
399
+ test("branded", () => {
400
+ const schema = z.discriminatedUnion("key", [
401
+ z.object({
402
+ key: z.literal("a"),
403
+ // Add other properties specific to this option
404
+ }),
405
+ z.object({
406
+ key: z.literal("b").brand<"asdfasdf">(),
407
+ // Add other properties specific to this option
408
+ }),
409
+ ]);
410
+
411
+ type schema = z.infer<typeof schema>;
412
+ expectTypeOf<schema>().toEqualTypeOf<{ key: "a" } | { key: "b" & z.core.$brand<"asdfasdf"> }>();
413
+
414
+ schema.parse({ key: "a" });
415
+ schema.parse({ key: "b" });
416
+ expect(() => {
417
+ schema.parse({ key: "c" });
418
+ }).toThrow();
419
+ });
420
+
421
+ test("optional and nullable", () => {
422
+ const schema = z.discriminatedUnion("key", [
423
+ z.object({
424
+ key: z.literal("a").optional(),
425
+ a: z.literal(true),
426
+ }),
427
+ z.object({
428
+ key: z.literal("b").nullable(),
429
+ b: z.literal(true),
430
+ // Add other properties specific to this option
431
+ }),
432
+ ]);
433
+
434
+ type schema = z.infer<typeof schema>;
435
+ expectTypeOf<schema>().toEqualTypeOf<{ key?: "a" | undefined; a: true } | { key: "b" | null; b: true }>();
436
+
437
+ schema.parse({ key: "a", a: true });
438
+ schema.parse({ key: undefined, a: true });
439
+ schema.parse({ key: "b", b: true });
440
+ schema.parse({ key: null, b: true });
441
+ expect(() => {
442
+ schema.parse({ key: null, a: true });
443
+ }).toThrow();
444
+ expect(() => {
445
+ schema.parse({ key: "b", a: true });
446
+ }).toThrow();
447
+
448
+ const value = schema.parse({ key: null, b: true });
449
+
450
+ if (!("key" in value)) value.a;
451
+ if (value.key === undefined) value.a;
452
+ if (value.key === "a") value.a;
453
+ if (value.key === "b") value.b;
454
+ if (value.key === null) value.b;
455
+ });
456
+
457
+ test("multiple discriminators", () => {
458
+ const FreeConfig = z.object({
459
+ type: z.literal("free"),
460
+ min_cents: z.null(),
461
+ });
462
+
463
+ // console.log(FreeConfig.shape.type);
464
+ const PricedConfig = z.object({
465
+ type: z.literal("fiat-price"),
466
+ // min_cents: z.int().nullable(),
467
+ min_cents: z.null(),
468
+ });
469
+
470
+ const Config = z.discriminatedUnion("type", [FreeConfig, PricedConfig]);
471
+
472
+ Config.parse({
473
+ min_cents: null,
474
+ type: "fiat-price",
475
+ name: "Standard",
476
+ });
477
+
478
+ expect(() => {
479
+ Config.parse({
480
+ min_cents: null,
481
+ type: "not real",
482
+ name: "Standard",
483
+ });
484
+ }).toThrow();
485
+ });
486
+
487
+ test("single element union", () => {
488
+ const schema = z.object({
489
+ a: z.literal("discKey"),
490
+ b: z.enum(["apple", "banana"]),
491
+ c: z.object({ id: z.string() }),
492
+ });
493
+
494
+ const input = {
495
+ a: "discKey",
496
+ b: "apple",
497
+ c: {}, // Invalid, as schema requires `id` property
498
+ };
499
+
500
+ // Validation must fail here, but it doesn't
501
+
502
+ const u = z.discriminatedUnion("a", [schema]);
503
+ const result = u.safeParse(input);
504
+ expect(result).toMatchObject({ success: false });
505
+ expect(result).toMatchInlineSnapshot(`
506
+ {
507
+ "error": [ZodError: [
508
+ {
509
+ "expected": "string",
510
+ "code": "invalid_type",
511
+ "path": [
512
+ "c",
513
+ "id"
514
+ ],
515
+ "message": "Invalid input: expected string, received undefined"
516
+ }
517
+ ]],
518
+ "success": false,
519
+ }
520
+ `);
521
+
522
+ expect(u.options.length).toEqual(1);
523
+ });
524
+
525
+ test("nested discriminated unions", () => {
526
+ const BaseError = z.object({ status: z.literal("failed"), message: z.string() });
527
+ const MyErrors = z.discriminatedUnion("code", [
528
+ BaseError.extend({ code: z.literal(400) }),
529
+ BaseError.extend({ code: z.literal(401) }),
530
+ BaseError.extend({ code: z.literal(500) }),
531
+ ]);
532
+
533
+ const MyResult = z.discriminatedUnion("status", [
534
+ z.object({ status: z.literal("success"), data: z.string() }),
535
+ MyErrors,
536
+ ]);
537
+
538
+ expect(MyErrors._zod.propValues).toMatchInlineSnapshot(`
539
+ {
540
+ "code": Set {
541
+ 400,
542
+ 401,
543
+ 500,
544
+ },
545
+ "status": Set {
546
+ "failed",
547
+ },
548
+ }
549
+ `);
550
+ expect(MyResult._zod.propValues).toMatchInlineSnapshot(`
551
+ {
552
+ "code": Set {
553
+ 400,
554
+ 401,
555
+ 500,
556
+ },
557
+ "status": Set {
558
+ "success",
559
+ "failed",
560
+ },
561
+ }
562
+ `);
563
+
564
+ const result = MyResult.parse({ status: "success", data: "hello" });
565
+ expect(result).toMatchInlineSnapshot(`
566
+ {
567
+ "data": "hello",
568
+ "status": "success",
569
+ }
570
+ `);
571
+ const result2 = MyResult.parse({ status: "failed", code: 400, message: "bad request" });
572
+ expect(result2).toMatchInlineSnapshot(`
573
+ {
574
+ "code": 400,
575
+ "message": "bad request",
576
+ "status": "failed",
577
+ }
578
+ `);
579
+ const result3 = MyResult.parse({ status: "failed", code: 401, message: "unauthorized" });
580
+ expect(result3).toMatchInlineSnapshot(`
581
+ {
582
+ "code": 401,
583
+ "message": "unauthorized",
584
+ "status": "failed",
585
+ }
586
+ `);
587
+ const result4 = MyResult.parse({ status: "failed", code: 500, message: "internal server error" });
588
+ expect(result4).toMatchInlineSnapshot(`
589
+ {
590
+ "code": 500,
591
+ "message": "internal server error",
592
+ "status": "failed",
593
+ }
594
+ `);
595
+ });
596
+
597
+ test("readonly literal discriminator", () => {
598
+ const discUnion = z.discriminatedUnion("type", [
599
+ z.object({ type: z.literal("a").readonly(), a: z.string() }),
600
+ z.object({ type: z.literal("b"), b: z.number() }),
601
+ ]);
602
+
603
+ // Test that both discriminator values are correctly included in propValues
604
+ const propValues = discUnion._zod.propValues;
605
+ expect(propValues?.type?.has("a")).toBe(true);
606
+ expect(propValues?.type?.has("b")).toBe(true);
607
+
608
+ // Test that the discriminated union works correctly
609
+ const result1 = discUnion.parse({ type: "a", a: "hello" });
610
+ expect(result1).toEqual({ type: "a", a: "hello" });
611
+
612
+ const result2 = discUnion.parse({ type: "b", b: 42 });
613
+ expect(result2).toEqual({ type: "b", b: 42 });
614
+
615
+ // Test that invalid discriminator values are rejected
616
+ expect(() => {
617
+ discUnion.parse({ type: "c", a: "hello" });
618
+ }).toThrow();
619
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/enum.test.ts ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("enum from string array", () => {
5
+ const MyEnum = z.enum(["Red", "Green", "Blue"]);
6
+ expect(MyEnum.enum.Red).toEqual("Red");
7
+
8
+ type MyEnum = z.infer<typeof MyEnum>;
9
+ expectTypeOf<MyEnum>().toEqualTypeOf<"Red" | "Green" | "Blue">();
10
+ });
11
+
12
+ test("enum from const object", () => {
13
+ const Fruits: { Apple: "apple"; Banana: "banana" } = {
14
+ Apple: "apple",
15
+ Banana: "banana",
16
+ };
17
+ const fruitEnum = z.nativeEnum(Fruits);
18
+ type fruitEnum = z.infer<typeof fruitEnum>;
19
+ fruitEnum.parse("apple");
20
+ fruitEnum.parse("banana");
21
+ fruitEnum.parse(Fruits.Apple);
22
+ fruitEnum.parse(Fruits.Banana);
23
+ expectTypeOf<fruitEnum>().toEqualTypeOf<"apple" | "banana">();
24
+ });
25
+
26
+ test("enum from native enum", () => {
27
+ enum Fruits {
28
+ Apple = "apple",
29
+ Banana = "banana",
30
+ Orange = 3,
31
+ }
32
+ // @ts-ignore
33
+ const fruitEnum = z.nativeEnum(Fruits);
34
+ type fruitEnum = z.infer<typeof fruitEnum>;
35
+ fruitEnum.parse("apple");
36
+ fruitEnum.parse("banana");
37
+ fruitEnum.parse(Fruits.Apple);
38
+ fruitEnum.parse(Fruits.Banana);
39
+
40
+ expect(fruitEnum.safeParse("Apple").success).toEqual(false);
41
+ expect(fruitEnum.safeParse("Cantaloupe").success).toEqual(false);
42
+
43
+ expectTypeOf<fruitEnum>().toMatchTypeOf<Fruits>();
44
+ expectTypeOf<Fruits>().toMatchTypeOf<fruitEnum>();
45
+ });
46
+
47
+ test("enum from native enum with numeric keys", () => {
48
+ const FruitValues = {
49
+ Apple: 10,
50
+ Banana: 20,
51
+ // @ts-ignore
52
+ } as const;
53
+ const fruitEnum = z.nativeEnum(FruitValues);
54
+ type fruitEnum = z.infer<typeof fruitEnum>;
55
+ fruitEnum.parse(10);
56
+ fruitEnum.parse(20);
57
+ fruitEnum.parse(FruitValues.Apple);
58
+ fruitEnum.parse(FruitValues.Banana);
59
+ expectTypeOf<fruitEnum>().toEqualTypeOf<10 | 20>();
60
+ });
61
+
62
+ test("issue metadata", () => {
63
+ const schema = z.enum(["Red", "Green", "Blue"]);
64
+ const result = schema.safeParse("Yellow");
65
+ expect(result.error!.issues[0]).toMatchInlineSnapshot(`
66
+ {
67
+ "code": "invalid_value",
68
+ "message": "Invalid option: expected one of "Red"|"Green"|"Blue"",
69
+ "path": [],
70
+ "values": [
71
+ "Red",
72
+ "Green",
73
+ "Blue",
74
+ ],
75
+ }
76
+ `);
77
+ });
78
+
79
+ test("enum from non-const inputs", () => {
80
+ const foods = ["Pasta", "Pizza", "Tacos", "Burgers", "Salad"];
81
+ const FoodEnum = z.enum(foods);
82
+
83
+ expectTypeOf<z.infer<typeof FoodEnum>>().toEqualTypeOf<string>();
84
+ expect(FoodEnum.safeParse("Pasta").success).toEqual(true);
85
+ expect(FoodEnum.safeParse("Cucumbers").success).toEqual(false);
86
+ });
87
+
88
+ test("get options", () => {
89
+ expect(z.enum(["tuna", "trout"]).options).toEqual(["tuna", "trout"]);
90
+ });
91
+
92
+ test("readonly enum", () => {
93
+ const HTTP_SUCCESS = ["200", "201"] as const;
94
+ const arg = z.enum(HTTP_SUCCESS);
95
+ type arg = z.infer<typeof arg>;
96
+ expectTypeOf<arg>().toEqualTypeOf<"200" | "201">();
97
+
98
+ arg.parse("201");
99
+ expect(() => arg.parse("202")).toThrow();
100
+ });
101
+
102
+ test("error map", () => {
103
+ const result = z
104
+ .enum(["test"], { error: (iss) => (iss.input === undefined ? "REQUIRED" : undefined) })
105
+ .safeParse(undefined);
106
+ expect(result.success).toEqual(false);
107
+ if (!result.success) {
108
+ expect(result.error.issues[0].message).toEqual("REQUIRED");
109
+ }
110
+ });
111
+
112
+ test("type signatures", () => {
113
+ const a = z.enum(["a", "b", "c"]);
114
+ const b = z.enum(a.options);
115
+ expectTypeOf(a).toEqualTypeOf(b);
116
+
117
+ const c = z.enum({ a: 1, b: 2 } as const);
118
+ expectTypeOf(c.enum).toEqualTypeOf<{
119
+ readonly a: 1;
120
+ readonly b: 2;
121
+ }>();
122
+
123
+ enum Fruit {
124
+ Apple = "apple",
125
+ Banana = "banana",
126
+ Orange = "orange",
127
+ }
128
+ const d = z.enum(Fruit);
129
+ expectTypeOf(d.enum).toEqualTypeOf(Fruit);
130
+
131
+ const e = z.enum({ a: 1, b: 2 });
132
+ expectTypeOf(e.enum).toEqualTypeOf<{
133
+ readonly a: 1;
134
+ readonly b: 2;
135
+ }>();
136
+ });
137
+
138
+ test("extract", () => {
139
+ const foods = ["Pasta", "Pizza", "Tacos", "Burgers", "Salad"] as const;
140
+ const FoodEnum = z.enum(foods);
141
+ const ItalianEnum = FoodEnum.extract(["Pasta", "Pizza"]);
142
+
143
+ expect(ItalianEnum.safeParse("Pasta").success).toEqual(true);
144
+ expect(ItalianEnum.safeParse("Tacos").success).toEqual(false);
145
+
146
+ expectTypeOf<z.infer<typeof ItalianEnum>>().toEqualTypeOf<"Pasta" | "Pizza">();
147
+ });
148
+
149
+ test("exclude", () => {
150
+ const foods = ["Pasta", "Pizza", "Tacos", "Burgers", "Salad"] as const;
151
+ const FoodEnum = z.enum(foods);
152
+ const UnhealthyEnum = FoodEnum.exclude(["Salad"]);
153
+
154
+ expect(UnhealthyEnum.safeParse("Pasta").success).toEqual(true);
155
+ expect(UnhealthyEnum.safeParse("Salad").success).toEqual(false);
156
+ expectTypeOf<z.infer<typeof UnhealthyEnum>>().toEqualTypeOf<"Pasta" | "Pizza" | "Tacos" | "Burgers">();
157
+
158
+ const EmptyFoodEnum = FoodEnum.exclude(foods);
159
+ expectTypeOf<typeof EmptyFoodEnum>().toEqualTypeOf<z.ZodEnum<{}>>();
160
+ expectTypeOf<z.infer<typeof EmptyFoodEnum>>().toEqualTypeOf<never>();
161
+ });
162
+
163
+ test("error map inheritance", () => {
164
+ const foods = ["Pasta", "Pizza", "Tacos", "Burgers", "Salad"] as const;
165
+ const FoodEnum = z.enum(foods, { error: () => "This is not food!" });
166
+ const ItalianEnum = FoodEnum.extract(["Pasta", "Pizza"]);
167
+
168
+ const foodsError = FoodEnum.safeParse("Cucumbers");
169
+ const italianError = ItalianEnum.safeParse("Tacos");
170
+
171
+ expect(foodsError.error!.issues[0].message).toEqual(italianError.error!.issues[0].message);
172
+
173
+ const UnhealthyEnum = FoodEnum.exclude(["Salad"], {
174
+ error: () => ({ message: "This is not healthy food!" }),
175
+ });
176
+ const unhealthyError = UnhealthyEnum.safeParse("Salad");
177
+ if (!unhealthyError.success) {
178
+ expect(unhealthyError.error.issues[0].message).toEqual("This is not healthy food!");
179
+ }
180
+ });
181
+
182
+ test("readonly in ZodEnumDef", () => {
183
+ type _a = z.ZodEnum<{ readonly a: "a"; readonly b: "b" }>;
184
+ type _b = z.ZodEnum<{ a: "a"; b: "b" }>;
185
+ });
186
+
187
+ test("enum error message, invalid enum elementstring", () => {
188
+ const result = z.enum(["Tuna", "Trout"]).safeParse("Salmon");
189
+ expect(result.success).toEqual(false);
190
+ expect(result.error!.issues.length).toEqual(1);
191
+
192
+ expect(result.error).toMatchInlineSnapshot(`
193
+ [ZodError: [
194
+ {
195
+ "code": "invalid_value",
196
+ "values": [
197
+ "Tuna",
198
+ "Trout"
199
+ ],
200
+ "path": [],
201
+ "message": "Invalid option: expected one of \\"Tuna\\"|\\"Trout\\""
202
+ }
203
+ ]]
204
+ `);
205
+ });
206
+
207
+ test("enum error message, invalid type", () => {
208
+ const result = z.enum(["Tuna", "Trout"]).safeParse(12);
209
+ expect(result.success).toEqual(false);
210
+ expect(result.error!.issues.length).toEqual(1);
211
+ // expect(result.error!.issues[0].message).toEqual('Invalid input: expected one of "Tuna"|"Trout"');
212
+ expect(result.error).toMatchInlineSnapshot(`
213
+ [ZodError: [
214
+ {
215
+ "code": "invalid_value",
216
+ "values": [
217
+ "Tuna",
218
+ "Trout"
219
+ ],
220
+ "path": [],
221
+ "message": "Invalid option: expected one of \\"Tuna\\"|\\"Trout\\""
222
+ }
223
+ ]]
224
+ `);
225
+ });
226
+
227
+ test("nativeEnum default error message", () => {
228
+ enum Fish {
229
+ Tuna = "Tuna",
230
+ Trout = "Trout",
231
+ }
232
+ const result = z.nativeEnum(Fish).safeParse("Salmon");
233
+ expect(result.success).toEqual(false);
234
+ expect(result.error!.issues.length).toEqual(1);
235
+ // expect(result.error!.issues[0].message).toEqual('Invalid input: expected one of "Tuna"|"Trout"');
236
+ expect(result.error).toMatchInlineSnapshot(`
237
+ [ZodError: [
238
+ {
239
+ "code": "invalid_value",
240
+ "values": [
241
+ "Tuna",
242
+ "Trout"
243
+ ],
244
+ "path": [],
245
+ "message": "Invalid option: expected one of \\"Tuna\\"|\\"Trout\\""
246
+ }
247
+ ]]
248
+ `);
249
+ });
250
+
251
+ test("enum with message returns the custom error message", () => {
252
+ const schema = z.enum(["apple", "banana"], {
253
+ message: "the value provided is invalid",
254
+ });
255
+
256
+ const result1 = schema.safeParse("berries");
257
+ expect(result1.success).toEqual(false);
258
+ if (!result1.success) {
259
+ expect(result1.error.issues[0].message).toEqual("the value provided is invalid");
260
+ }
261
+
262
+ const result2 = schema.safeParse(undefined);
263
+ expect(result2.success).toEqual(false);
264
+ if (!result2.success) {
265
+ expect(result2.error.issues[0].message).toEqual("the value provided is invalid");
266
+ }
267
+
268
+ const result3 = schema.safeParse("banana");
269
+ expect(result3.success).toEqual(true);
270
+
271
+ const result4 = schema.safeParse(null);
272
+ expect(result4.success).toEqual(false);
273
+ if (!result4.success) {
274
+ expect(result4.error.issues[0].message).toEqual("the value provided is invalid");
275
+ }
276
+ });
277
+
278
+ test("enum with diagonal keys", () => {
279
+ const schema_02 = z.enum({
280
+ A: 1,
281
+ B: "A",
282
+ });
283
+
284
+ expect(schema_02.safeParse("A")).toMatchObject({ success: true });
285
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/error-utils.test.ts ADDED
@@ -0,0 +1,527 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ declare const iss: z.core.$ZodIssueCode;
5
+
6
+ const Test = z.object({
7
+ f1: z.number(),
8
+ f2: z.string().optional(),
9
+ f3: z.string().nullable(),
10
+ f4: z.array(z.object({ t: z.union([z.string(), z.boolean()]) })),
11
+ });
12
+ // type TestFlattenedErrors = core.inferFlattenedErrors<typeof Test, { message: string; code: number }>;
13
+ // type TestFormErrors = core.inferFlattenedErrors<typeof Test>;
14
+ const parsed = Test.safeParse({});
15
+
16
+ test("regular error", () => {
17
+ expect(parsed).toMatchInlineSnapshot(`
18
+ {
19
+ "error": [ZodError: [
20
+ {
21
+ "expected": "number",
22
+ "code": "invalid_type",
23
+ "path": [
24
+ "f1"
25
+ ],
26
+ "message": "Invalid input: expected number, received undefined"
27
+ },
28
+ {
29
+ "expected": "string",
30
+ "code": "invalid_type",
31
+ "path": [
32
+ "f3"
33
+ ],
34
+ "message": "Invalid input: expected string, received undefined"
35
+ },
36
+ {
37
+ "expected": "array",
38
+ "code": "invalid_type",
39
+ "path": [
40
+ "f4"
41
+ ],
42
+ "message": "Invalid input: expected array, received undefined"
43
+ }
44
+ ]],
45
+ "success": false,
46
+ }
47
+ `);
48
+ });
49
+
50
+ test(".flatten()", () => {
51
+ const flattened = parsed.error!.flatten();
52
+ // flattened.
53
+ expectTypeOf(flattened).toMatchTypeOf<{
54
+ formErrors: string[];
55
+ fieldErrors: {
56
+ f2?: string[];
57
+ f1?: string[];
58
+ f3?: string[];
59
+ f4?: string[];
60
+ };
61
+ }>();
62
+
63
+ expect(flattened).toMatchInlineSnapshot(`
64
+ {
65
+ "fieldErrors": {
66
+ "f1": [
67
+ "Invalid input: expected number, received undefined",
68
+ ],
69
+ "f3": [
70
+ "Invalid input: expected string, received undefined",
71
+ ],
72
+ "f4": [
73
+ "Invalid input: expected array, received undefined",
74
+ ],
75
+ },
76
+ "formErrors": [],
77
+ }
78
+ `);
79
+ });
80
+
81
+ test("custom .flatten()", () => {
82
+ type ErrorType = { message: string; code: number };
83
+ const flattened = parsed.error!.flatten((iss) => ({ message: iss.message, code: 1234 }));
84
+ expectTypeOf(flattened).toMatchTypeOf<{
85
+ formErrors: ErrorType[];
86
+ fieldErrors: {
87
+ f2?: ErrorType[];
88
+ f1?: ErrorType[];
89
+ f3?: ErrorType[];
90
+ f4?: ErrorType[];
91
+ };
92
+ }>();
93
+
94
+ expect(flattened).toMatchInlineSnapshot(`
95
+ {
96
+ "fieldErrors": {
97
+ "f1": [
98
+ {
99
+ "code": 1234,
100
+ "message": "Invalid input: expected number, received undefined",
101
+ },
102
+ ],
103
+ "f3": [
104
+ {
105
+ "code": 1234,
106
+ "message": "Invalid input: expected string, received undefined",
107
+ },
108
+ ],
109
+ "f4": [
110
+ {
111
+ "code": 1234,
112
+ "message": "Invalid input: expected array, received undefined",
113
+ },
114
+ ],
115
+ },
116
+ "formErrors": [],
117
+ }
118
+ `);
119
+ });
120
+
121
+ test(".format()", () => {
122
+ const formatted = parsed.error!.format();
123
+ expectTypeOf(formatted).toMatchTypeOf<{
124
+ _errors: string[];
125
+ f2?: { _errors: string[] };
126
+ f1?: { _errors: string[] };
127
+ f3?: { _errors: string[] };
128
+ f4?: {
129
+ [x: number]: {
130
+ _errors: string[];
131
+ t?: {
132
+ _errors: string[];
133
+ };
134
+ };
135
+ _errors: string[];
136
+ };
137
+ }>();
138
+
139
+ expect(formatted).toMatchInlineSnapshot(`
140
+ {
141
+ "_errors": [],
142
+ "f1": {
143
+ "_errors": [
144
+ "Invalid input: expected number, received undefined",
145
+ ],
146
+ },
147
+ "f3": {
148
+ "_errors": [
149
+ "Invalid input: expected string, received undefined",
150
+ ],
151
+ },
152
+ "f4": {
153
+ "_errors": [
154
+ "Invalid input: expected array, received undefined",
155
+ ],
156
+ },
157
+ }
158
+ `);
159
+ });
160
+
161
+ test("custom .format()", () => {
162
+ type ErrorType = { message: string; code: number };
163
+ const formatted = parsed.error!.format((iss) => ({ message: iss.message, code: 1234 }));
164
+ expectTypeOf(formatted).toMatchTypeOf<{
165
+ _errors: ErrorType[];
166
+ f2?: { _errors: ErrorType[] };
167
+ f1?: { _errors: ErrorType[] };
168
+ f3?: { _errors: ErrorType[] };
169
+ f4?: {
170
+ [x: number]: {
171
+ _errors: ErrorType[];
172
+ t?: {
173
+ _errors: ErrorType[];
174
+ };
175
+ };
176
+ _errors: ErrorType[];
177
+ };
178
+ }>();
179
+
180
+ expect(formatted).toMatchInlineSnapshot(`
181
+ {
182
+ "_errors": [],
183
+ "f1": {
184
+ "_errors": [
185
+ {
186
+ "code": 1234,
187
+ "message": "Invalid input: expected number, received undefined",
188
+ },
189
+ ],
190
+ },
191
+ "f3": {
192
+ "_errors": [
193
+ {
194
+ "code": 1234,
195
+ "message": "Invalid input: expected string, received undefined",
196
+ },
197
+ ],
198
+ },
199
+ "f4": {
200
+ "_errors": [
201
+ {
202
+ "code": 1234,
203
+ "message": "Invalid input: expected array, received undefined",
204
+ },
205
+ ],
206
+ },
207
+ }
208
+ `);
209
+ });
210
+
211
+ test("all errors", () => {
212
+ const propertySchema = z.string();
213
+ const schema = z
214
+ .object({
215
+ a: propertySchema,
216
+ b: propertySchema,
217
+ })
218
+ .refine(
219
+ (val) => {
220
+ return val.a === val.b;
221
+ },
222
+ { message: "Must be equal" }
223
+ );
224
+
225
+ const r1 = schema.safeParse({
226
+ a: "asdf",
227
+ b: "qwer",
228
+ });
229
+
230
+ expect(z.core.flattenError(r1.error!)).toEqual({
231
+ formErrors: ["Must be equal"],
232
+ fieldErrors: {},
233
+ });
234
+
235
+ const r2 = schema.safeParse({
236
+ a: null,
237
+ b: null,
238
+ });
239
+
240
+ // const error = _error as z.ZodError;
241
+ expect(z.core.flattenError(r2.error!)).toMatchInlineSnapshot(`
242
+ {
243
+ "fieldErrors": {
244
+ "a": [
245
+ "Invalid input: expected string, received null",
246
+ ],
247
+ "b": [
248
+ "Invalid input: expected string, received null",
249
+ ],
250
+ },
251
+ "formErrors": [],
252
+ }
253
+ `);
254
+
255
+ expect(z.core.flattenError(r2.error!, (iss) => iss.message.toUpperCase())).toMatchInlineSnapshot(`
256
+ {
257
+ "fieldErrors": {
258
+ "a": [
259
+ "INVALID INPUT: EXPECTED STRING, RECEIVED NULL",
260
+ ],
261
+ "b": [
262
+ "INVALID INPUT: EXPECTED STRING, RECEIVED NULL",
263
+ ],
264
+ },
265
+ "formErrors": [],
266
+ }
267
+ `);
268
+ // Test identity
269
+
270
+ expect(z.core.flattenError(r2.error!, (i: z.ZodIssue) => i)).toMatchInlineSnapshot(`
271
+ {
272
+ "fieldErrors": {
273
+ "a": [
274
+ {
275
+ "code": "invalid_type",
276
+ "expected": "string",
277
+ "message": "Invalid input: expected string, received null",
278
+ "path": [
279
+ "a",
280
+ ],
281
+ },
282
+ ],
283
+ "b": [
284
+ {
285
+ "code": "invalid_type",
286
+ "expected": "string",
287
+ "message": "Invalid input: expected string, received null",
288
+ "path": [
289
+ "b",
290
+ ],
291
+ },
292
+ ],
293
+ },
294
+ "formErrors": [],
295
+ }
296
+ `);
297
+
298
+ // Test mapping
299
+ const f1 = z.core.flattenError(r2.error!, (i: z.ZodIssue) => i.message.length);
300
+ expect(f1).toMatchInlineSnapshot(`
301
+ {
302
+ "fieldErrors": {
303
+ "a": [
304
+ 45,
305
+ ],
306
+ "b": [
307
+ 45,
308
+ ],
309
+ },
310
+ "formErrors": [],
311
+ }
312
+ `);
313
+ // expect(f1.fieldErrors.a![0]).toEqual("Invalid input: expected string".length);
314
+ // expect(f1).toMatchObject({
315
+ // formErrors: [],
316
+ // fieldErrors: {
317
+ // a: ["Invalid input: expected string".length],
318
+ // b: ["Invalid input: expected string".length],
319
+ // },
320
+ // });
321
+ });
322
+
323
+ const schema = z.strictObject({
324
+ username: z.string(),
325
+ favoriteNumbers: z.array(z.number()),
326
+ nesting: z.object({
327
+ a: z.string(),
328
+ }),
329
+ });
330
+ const result = schema.safeParse({
331
+ username: 1234,
332
+ favoriteNumbers: [1234, "4567"],
333
+ nesting: {
334
+ a: 123,
335
+ },
336
+ extra: 1234,
337
+ });
338
+
339
+ test("z.treeifyError", () => {
340
+ expect(z.treeifyError(result.error!)).toMatchInlineSnapshot(`
341
+ {
342
+ "errors": [
343
+ "Unrecognized key: "extra"",
344
+ ],
345
+ "properties": {
346
+ "favoriteNumbers": {
347
+ "errors": [],
348
+ "items": [
349
+ ,
350
+ {
351
+ "errors": [
352
+ "Invalid input: expected number, received string",
353
+ ],
354
+ },
355
+ ],
356
+ },
357
+ "nesting": {
358
+ "errors": [],
359
+ "properties": {
360
+ "a": {
361
+ "errors": [
362
+ "Invalid input: expected string, received number",
363
+ ],
364
+ },
365
+ },
366
+ },
367
+ "username": {
368
+ "errors": [
369
+ "Invalid input: expected string, received number",
370
+ ],
371
+ },
372
+ },
373
+ }
374
+ `);
375
+ });
376
+
377
+ test("z.treeifyError 2", () => {
378
+ const schema = z.strictObject({
379
+ name: z.string(),
380
+ logLevel: z.union([z.string(), z.number()]),
381
+ env: z.literal(["production", "development"]),
382
+ });
383
+
384
+ const data = {
385
+ name: 1000,
386
+ logLevel: false,
387
+ extra: 1000,
388
+ };
389
+
390
+ const result = schema.safeParse(data);
391
+ const err = z.treeifyError(result.error!);
392
+ expect(err).toMatchInlineSnapshot(`
393
+ {
394
+ "errors": [
395
+ "Unrecognized key: "extra"",
396
+ ],
397
+ "properties": {
398
+ "env": {
399
+ "errors": [
400
+ "Invalid option: expected one of "production"|"development"",
401
+ ],
402
+ },
403
+ "logLevel": {
404
+ "errors": [
405
+ "Invalid input: expected string, received boolean",
406
+ "Invalid input: expected number, received boolean",
407
+ ],
408
+ },
409
+ "name": {
410
+ "errors": [
411
+ "Invalid input: expected string, received number",
412
+ ],
413
+ },
414
+ },
415
+ }
416
+ `);
417
+ });
418
+
419
+ test("z.prettifyError", () => {
420
+ expect(z.prettifyError(result.error!)).toMatchInlineSnapshot(`
421
+ "✖ Unrecognized key: "extra"
422
+ ✖ Invalid input: expected string, received number
423
+ → at username
424
+ ✖ Invalid input: expected number, received string
425
+ → at favoriteNumbers[1]
426
+ ✖ Invalid input: expected string, received number
427
+ → at nesting.a"
428
+ `);
429
+ });
430
+
431
+ test("z.toDotPath", () => {
432
+ expect(z.core.toDotPath(["a", "b", 0, "c"])).toMatchInlineSnapshot(`"a.b[0].c"`);
433
+
434
+ expect(z.core.toDotPath(["a", Symbol("b"), 0, "c"])).toMatchInlineSnapshot(`"a["Symbol(b)"][0].c"`);
435
+
436
+ // Test with periods in keys
437
+ expect(z.core.toDotPath(["user.name", "first.last"])).toMatchInlineSnapshot(`"["user.name"]["first.last"]"`);
438
+
439
+ // Test with special characters
440
+ expect(z.core.toDotPath(["user", "$special", Symbol("#symbol")])).toMatchInlineSnapshot(
441
+ `"user.$special["Symbol(#symbol)"]"`
442
+ );
443
+
444
+ // Test with dots and quotes
445
+ expect(z.core.toDotPath(["search", `query("foo.bar"="abc")`])).toMatchInlineSnapshot(
446
+ `"search["query(\\"foo.bar\\"=\\"abc\\")"]"`
447
+ );
448
+
449
+ // Test with newlines
450
+ expect(z.core.toDotPath(["search", `foo\nbar`])).toMatchInlineSnapshot(`"search["foo\\nbar"]"`);
451
+
452
+ // Test with empty strings
453
+ expect(z.core.toDotPath(["", "empty"])).toMatchInlineSnapshot(`".empty"`);
454
+
455
+ // Test with array indices
456
+ expect(z.core.toDotPath(["items", 0, 1, 2])).toMatchInlineSnapshot(`"items[0][1][2]"`);
457
+
458
+ // Test with mixed path elements
459
+ expect(z.core.toDotPath(["users", "user.config", 0, "settings.theme"])).toMatchInlineSnapshot(
460
+ `"users["user.config"][0]["settings.theme"]"`
461
+ );
462
+
463
+ // Test with square brackets in keys
464
+ expect(z.core.toDotPath(["data[0]", "value"])).toMatchInlineSnapshot(`"["data[0]"].value"`);
465
+
466
+ // Test with empty path
467
+ expect(z.core.toDotPath([])).toMatchInlineSnapshot(`""`);
468
+ });
469
+
470
+ test("inheritance", () => {
471
+ const e1 = new z.ZodError([]);
472
+ expect(e1).toBeInstanceOf(z.core.$ZodError);
473
+ expect(e1).toBeInstanceOf(z.ZodError);
474
+ // expect(e1).not.toBeInstanceOf(Error);
475
+
476
+ const e2 = new z.ZodRealError([]);
477
+ expect(e2).toBeInstanceOf(z.ZodError);
478
+ expect(e2).toBeInstanceOf(z.ZodRealError);
479
+ expect(e2).toBeInstanceOf(Error);
480
+ });
481
+
482
+ test("disc union treeify/format", () => {
483
+ const schema = z.discriminatedUnion(
484
+ "foo",
485
+ [
486
+ z.object({
487
+ foo: z.literal("x"),
488
+ x: z.string(),
489
+ }),
490
+ z.object({
491
+ foo: z.literal("y"),
492
+ y: z.string(),
493
+ }),
494
+ ],
495
+ {
496
+ error: "Invalid discriminator",
497
+ }
498
+ );
499
+
500
+ const error = schema.safeParse({ foo: "invalid" }).error;
501
+ expect(z.treeifyError(error!)).toMatchInlineSnapshot(`
502
+ {
503
+ "errors": [],
504
+ "properties": {
505
+ "foo": {
506
+ "errors": [
507
+ "Invalid discriminator",
508
+ ],
509
+ },
510
+ },
511
+ }
512
+ `);
513
+ expect(z.prettifyError(error!)).toMatchInlineSnapshot(`
514
+ "✖ Invalid discriminator
515
+ → at foo"
516
+ `);
517
+ expect(z.formatError(error!)).toMatchInlineSnapshot(`
518
+ {
519
+ "_errors": [],
520
+ "foo": {
521
+ "_errors": [
522
+ "Invalid discriminator",
523
+ ],
524
+ },
525
+ }
526
+ `);
527
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/error.test.ts ADDED
@@ -0,0 +1,711 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { inspect } from "node:util";
2
+ import { expect, test } from "vitest";
3
+ import * as z from "zod/v4";
4
+
5
+ test("error creation", () => {
6
+ const err1 = new z.ZodError([]);
7
+
8
+ err1.issues.push({
9
+ code: "invalid_type",
10
+ expected: "object",
11
+ path: [],
12
+ message: "",
13
+ input: "adf",
14
+ });
15
+ err1.isEmpty;
16
+
17
+ const err2 = new z.ZodError(err1.issues);
18
+ const err3 = new z.ZodError([]);
19
+ err3.addIssues(err1.issues);
20
+ err3.addIssue(err1.issues[0]);
21
+ err1.message;
22
+ err2.message;
23
+ err3.message;
24
+ });
25
+
26
+ test("do not allow error and message together", () => {
27
+ expect(() =>
28
+ z.string().refine((_) => true, {
29
+ message: "override",
30
+ error: (iss) => (iss.input === undefined ? "asdf" : null),
31
+ })
32
+ ).toThrow();
33
+ });
34
+
35
+ const errorMap: z.ZodErrorMap = (issue) => {
36
+ if (issue.code === "invalid_type") {
37
+ if (issue.expected === "string") {
38
+ return { message: "bad type!" };
39
+ }
40
+ }
41
+ if (issue.code === "custom") {
42
+ return { message: `less-than-${issue.params?.minimum}` };
43
+ }
44
+ return undefined;
45
+ };
46
+
47
+ test("type error with custom error map", () => {
48
+ const result = z.string().safeParse(234, { error: errorMap });
49
+ expect(result.success).toBe(false);
50
+ expect(result.error).toMatchInlineSnapshot(`
51
+ [ZodError: [
52
+ {
53
+ "expected": "string",
54
+ "code": "invalid_type",
55
+ "path": [],
56
+ "message": "bad type!"
57
+ }
58
+ ]]
59
+ `);
60
+ });
61
+
62
+ test("refinement fail with params", () => {
63
+ const result = z
64
+ .number()
65
+ .refine((val) => val >= 3, {
66
+ params: { minimum: 3 },
67
+ })
68
+ .safeParse(2, { error: errorMap });
69
+ expect(result.success).toBe(false);
70
+ expect(result.error).toMatchInlineSnapshot(`
71
+ [ZodError: [
72
+ {
73
+ "code": "custom",
74
+ "path": [],
75
+ "params": {
76
+ "minimum": 3
77
+ },
78
+ "message": "less-than-3"
79
+ }
80
+ ]]
81
+ `);
82
+ });
83
+
84
+ test("hard coded error with custom errormap", () => {
85
+ const result = z
86
+ .string()
87
+ .refine((val) => val.length > 12, {
88
+ params: { minimum: 13 },
89
+ message: "override",
90
+ })
91
+ .safeParse("asdf", { error: () => "contextual" });
92
+
93
+ expect(result.success).toBe(false);
94
+ expect(result.error).toMatchInlineSnapshot(`
95
+ [ZodError: [
96
+ {
97
+ "code": "custom",
98
+ "path": [],
99
+ "params": {
100
+ "minimum": 13
101
+ },
102
+ "message": "override"
103
+ }
104
+ ]]
105
+ `);
106
+ });
107
+
108
+ test("default error message", () => {
109
+ const result = z
110
+ .number()
111
+ .refine((x) => x > 3)
112
+ .safeParse(2);
113
+
114
+ expect(result.success).toBe(false);
115
+ expect(result.error).toMatchInlineSnapshot(`
116
+ [ZodError: [
117
+ {
118
+ "code": "custom",
119
+ "path": [],
120
+ "message": "Invalid input"
121
+ }
122
+ ]]
123
+ `);
124
+ });
125
+
126
+ test("override error in refine", () => {
127
+ const result = z
128
+ .number()
129
+ .refine((x) => x > 3, "override")
130
+ .safeParse(2);
131
+ expect(result.success).toBe(false);
132
+ expect(result.error!.issues.length).toEqual(1);
133
+ expect(result.error).toMatchInlineSnapshot(`
134
+ [ZodError: [
135
+ {
136
+ "code": "custom",
137
+ "path": [],
138
+ "message": "override"
139
+ }
140
+ ]]
141
+ `);
142
+ });
143
+
144
+ test("override error in refinement", () => {
145
+ const result = z
146
+ .number()
147
+ .refine((x) => x > 3, {
148
+ message: "override",
149
+ })
150
+ .safeParse(2);
151
+ expect(result.success).toBe(false);
152
+ expect(result.error!.issues.length).toEqual(1);
153
+ expect(result.error).toMatchInlineSnapshot(`
154
+ [ZodError: [
155
+ {
156
+ "code": "custom",
157
+ "path": [],
158
+ "message": "override"
159
+ }
160
+ ]]
161
+ `);
162
+ });
163
+
164
+ test("array minimum", () => {
165
+ let result = z.array(z.string()).min(3, "tooshort").safeParse(["asdf", "qwer"]);
166
+ expect(result.success).toBe(false);
167
+ expect(result.error!.issues[0].code).toEqual("too_small");
168
+ expect(result.error!.issues[0].message).toEqual("tooshort");
169
+
170
+ result = z.array(z.string()).min(3).safeParse(["asdf", "qwer"]);
171
+ expect(result.success).toBe(false);
172
+ expect(result.error!.issues[0].code).toEqual("too_small");
173
+ expect(result.error).toMatchInlineSnapshot(`
174
+ [ZodError: [
175
+ {
176
+ "origin": "array",
177
+ "code": "too_small",
178
+ "minimum": 3,
179
+ "inclusive": true,
180
+ "path": [],
181
+ "message": "Too small: expected array to have >=3 items"
182
+ }
183
+ ]]
184
+ `);
185
+ });
186
+
187
+ test("literal bigint default error message", () => {
188
+ const result = z.literal(BigInt(12)).safeParse(BigInt(13));
189
+ expect(result.success).toBe(false);
190
+ expect(result.error!.issues.length).toEqual(1);
191
+ expect(result.error).toMatchInlineSnapshot(`
192
+ [ZodError: [
193
+ {
194
+ "code": "invalid_value",
195
+ "values": [
196
+ "12"
197
+ ],
198
+ "path": [],
199
+ "message": "Invalid input: expected 12n"
200
+ }
201
+ ]]
202
+ `);
203
+ });
204
+
205
+ test("custom path in custom error map", () => {
206
+ const schema = z.object({
207
+ items: z.array(z.string()).refine((data) => data.length > 3, {
208
+ path: ["items-too-few"],
209
+ }),
210
+ });
211
+
212
+ const errorMap: z.ZodErrorMap = (issue) => {
213
+ expect((issue.path ?? []).length).toBe(2);
214
+ return { message: "doesnt matter" };
215
+ };
216
+ const result = schema.safeParse({ items: ["first"] }, { error: errorMap });
217
+ expect(result.success).toBe(false);
218
+ expect(result.error).toMatchInlineSnapshot(`
219
+ [ZodError: [
220
+ {
221
+ "code": "custom",
222
+ "path": [
223
+ "items",
224
+ "items-too-few"
225
+ ],
226
+ "message": "doesnt matter"
227
+ }
228
+ ]]
229
+ `);
230
+ });
231
+
232
+ // test("error metadata from value", () => {
233
+ // const dynamicRefine = z.string().refine(
234
+ // (val) => val === val.toUpperCase(),
235
+ // (val) => ({ params: { val } })
236
+ // );
237
+
238
+ // const result = dynamicRefine.safeParse("asdf");
239
+ // expect(result.success).toEqual(false);
240
+ // if (!result.success) {
241
+ // const sub = result.error.issues[0];
242
+ // expect(result.error.issues[0].code).toEqual("custom");
243
+ // if (sub.code === "custom") {
244
+ // expect(sub.params?.val).toEqual("asdf");
245
+ // }
246
+ // }
247
+ // });
248
+
249
+ // test("don't call refine after validation failed", () => {
250
+ // const asdf = z
251
+ // .union([
252
+ // z.number(),
253
+ // z.string().transform(z.number(), (val) => {
254
+ // return parseFloat(val);
255
+ // }),
256
+ // ])
257
+ // .refine((v) => v >= 1);
258
+
259
+ // expect(() => asdf.safeParse("foo")).not.toThrow();
260
+ // });
261
+
262
+ test("root level formatting", () => {
263
+ const schema = z.string().email();
264
+ const result = schema.safeParse("asdfsdf");
265
+ expect(result.success).toBe(false);
266
+
267
+ expect(result.error!.format()).toMatchInlineSnapshot(`
268
+ {
269
+ "_errors": [
270
+ "Invalid email address",
271
+ ],
272
+ }
273
+ `);
274
+ });
275
+
276
+ test("custom path", () => {
277
+ const schema = z
278
+ .object({
279
+ password: z.string(),
280
+ confirm: z.string(),
281
+ })
282
+ .refine((val) => val.confirm === val.password, { path: ["confirm"] });
283
+
284
+ const result = schema.safeParse({
285
+ password: "peanuts",
286
+ confirm: "qeanuts",
287
+ });
288
+
289
+ expect(result.success).toBe(false);
290
+ const error = result.error!.format();
291
+ expect(error._errors).toEqual([]);
292
+ expect(error.password?._errors).toEqual(undefined);
293
+ expect(error.confirm?._errors).toEqual(["Invalid input"]);
294
+ });
295
+
296
+ test("custom path", () => {
297
+ const schema = z
298
+ .object({
299
+ password: z.string().min(6),
300
+ confirm: z.string().min(6),
301
+ })
302
+ .refine((val) => val.confirm === val.password);
303
+
304
+ const result = schema.safeParse({
305
+ password: "qwer",
306
+ confirm: "asdf",
307
+ });
308
+
309
+ expect(result.success).toBe(false);
310
+ expect(result.error!.issues.length).toEqual(3);
311
+ });
312
+
313
+ const schema = z.object({
314
+ inner: z.object({
315
+ name: z
316
+ .string()
317
+ .refine((val) => val.length > 5)
318
+ .array()
319
+ .refine((val) => val.length <= 1),
320
+ }),
321
+ });
322
+
323
+ test("no abort early on refinements", () => {
324
+ const invalidItem = {
325
+ inner: { name: ["aasd", "asdfasdfasfd"] },
326
+ };
327
+
328
+ const result1 = schema.safeParse(invalidItem);
329
+ expect(result1.success).toBe(false);
330
+ expect(result1.error!.issues.length).toEqual(2);
331
+ });
332
+
333
+ test("detect issue with input fallback", () => {
334
+ const schema = z
335
+ .string()
336
+ .transform((val) => val.length)
337
+ .refine(() => false, { message: "always fails" })
338
+ .refine(
339
+ (val) => {
340
+ if (typeof val !== "number") throw new Error();
341
+ return (val ^ 2) > 10;
342
+ } // should be number but it's a string
343
+ );
344
+ expect(() => schema.parse("hello")).toThrow(z.ZodError);
345
+ });
346
+
347
+ test("formatting", () => {
348
+ const invalidItem = {
349
+ inner: { name: ["aasd", "asdfasdfasfd"] },
350
+ };
351
+ const invalidArray = {
352
+ inner: { name: ["asdfasdf", "asdfasdfasfd"] },
353
+ };
354
+ const result1 = schema.safeParse(invalidItem);
355
+ const result2 = schema.safeParse(invalidArray);
356
+
357
+ expect(result1.success).toBe(false);
358
+ expect(result2.success).toBe(false);
359
+ const error1 = result1.error!.format();
360
+ expect(error1._errors).toEqual([]);
361
+ expect(error1.inner?._errors).toEqual([]);
362
+ expect(error1.inner?.name?.[1]).toEqual(undefined);
363
+
364
+ type FormattedError = z.inferFormattedError<typeof schema>;
365
+ const error2: FormattedError = result2.error!.format();
366
+ expect(error2._errors).toEqual([]);
367
+ expect(error2.inner?._errors).toEqual([]);
368
+ expect(error2.inner?.name?._errors).toEqual(["Invalid input"]);
369
+ expect(error2.inner?.name?.[0]).toEqual(undefined);
370
+ expect(error2.inner?.name?.[1]).toEqual(undefined);
371
+ expect(error2.inner?.name?.[2]).toEqual(undefined);
372
+
373
+ // test custom mapper
374
+ type FormattedErrorWithNumber = z.inferFormattedError<typeof schema, number>;
375
+ const errorWithNumber: FormattedErrorWithNumber = result2.error!.format(() => 5);
376
+ expect(errorWithNumber._errors).toEqual([]);
377
+ expect(errorWithNumber.inner?._errors).toEqual([]);
378
+ expect(errorWithNumber.inner?.name?._errors).toEqual([5]);
379
+ });
380
+
381
+ test("formatting with nullable and optional fields", () => {
382
+ const nameSchema = z.string().refine((val) => val.length > 5);
383
+ const schema = z.object({
384
+ nullableObject: z.object({ name: nameSchema }).nullable(),
385
+ nullableArray: z.array(nameSchema).nullable(),
386
+ nullableTuple: z.tuple([nameSchema, nameSchema, z.number()]).nullable(),
387
+ optionalObject: z.object({ name: nameSchema }).optional(),
388
+ optionalArray: z.array(nameSchema).optional(),
389
+ optionalTuple: z.tuple([nameSchema, nameSchema, z.number()]).optional(),
390
+ });
391
+ const invalidItem = {
392
+ nullableObject: { name: "abcd" },
393
+ nullableArray: ["abcd"],
394
+ nullableTuple: ["abcd", "abcd", 1],
395
+ optionalObject: { name: "abcd" },
396
+ optionalArray: ["abcd"],
397
+ optionalTuple: ["abcd", "abcd", 1],
398
+ };
399
+ const result = schema.safeParse(invalidItem);
400
+ expect(result.success).toBe(false);
401
+ const error: z.inferFormattedError<typeof schema> = result.error!.format();
402
+ expect(error._errors).toEqual([]);
403
+ expect(error.nullableObject?._errors).toEqual([]);
404
+ expect(error.nullableObject?.name?._errors).toEqual(["Invalid input"]);
405
+ expect(error.nullableArray?._errors).toEqual([]);
406
+ expect(error.nullableArray?.[0]?._errors).toEqual(["Invalid input"]);
407
+ expect(error.nullableTuple?._errors).toEqual([]);
408
+ expect(error.nullableTuple?.[0]?._errors).toEqual(["Invalid input"]);
409
+ expect(error.nullableTuple?.[1]?._errors).toEqual(["Invalid input"]);
410
+ expect(error.optionalObject?._errors).toEqual([]);
411
+ expect(error.optionalObject?.name?._errors).toEqual(["Invalid input"]);
412
+ expect(error.optionalArray?._errors).toEqual([]);
413
+ expect(error.optionalArray?.[0]?._errors).toEqual(["Invalid input"]);
414
+ expect(error.optionalTuple?._errors).toEqual([]);
415
+ expect(error.optionalTuple?.[0]?._errors).toEqual(["Invalid input"]);
416
+ expect(error.optionalTuple?.[1]?._errors).toEqual(["Invalid input"]);
417
+
418
+ expect(error).toMatchInlineSnapshot(`
419
+ {
420
+ "_errors": [],
421
+ "nullableArray": {
422
+ "0": {
423
+ "_errors": [
424
+ "Invalid input",
425
+ ],
426
+ },
427
+ "_errors": [],
428
+ },
429
+ "nullableObject": {
430
+ "_errors": [],
431
+ "name": {
432
+ "_errors": [
433
+ "Invalid input",
434
+ ],
435
+ },
436
+ },
437
+ "nullableTuple": {
438
+ "0": {
439
+ "_errors": [
440
+ "Invalid input",
441
+ ],
442
+ },
443
+ "1": {
444
+ "_errors": [
445
+ "Invalid input",
446
+ ],
447
+ },
448
+ "_errors": [],
449
+ },
450
+ "optionalArray": {
451
+ "0": {
452
+ "_errors": [
453
+ "Invalid input",
454
+ ],
455
+ },
456
+ "_errors": [],
457
+ },
458
+ "optionalObject": {
459
+ "_errors": [],
460
+ "name": {
461
+ "_errors": [
462
+ "Invalid input",
463
+ ],
464
+ },
465
+ },
466
+ "optionalTuple": {
467
+ "0": {
468
+ "_errors": [
469
+ "Invalid input",
470
+ ],
471
+ },
472
+ "1": {
473
+ "_errors": [
474
+ "Invalid input",
475
+ ],
476
+ },
477
+ "_errors": [],
478
+ },
479
+ }
480
+ `);
481
+ });
482
+
483
+ test("inferFlattenedErrors", () => {
484
+ const schemaWithTransform = z.object({ foo: z.string() }).transform((o) => ({ bar: o.foo }));
485
+
486
+ const result = schemaWithTransform.safeParse({});
487
+
488
+ expect(result.success).toBe(false);
489
+ type ValidationErrors = z.inferFlattenedErrors<typeof schemaWithTransform>;
490
+ const error: ValidationErrors = result.error!.flatten();
491
+ expect(error).toMatchInlineSnapshot(`
492
+ {
493
+ "fieldErrors": {
494
+ "foo": [
495
+ "Invalid input: expected string, received undefined",
496
+ ],
497
+ },
498
+ "formErrors": [],
499
+ }
500
+ `);
501
+ });
502
+
503
+ const stringWithCustomError = z.string({
504
+ error: () => "bound",
505
+ });
506
+
507
+ test("schema-bound error map", () => {
508
+ const result = stringWithCustomError.safeParse(1234);
509
+ expect(result.success).toBe(false);
510
+ expect(result.error!.issues[0].message).toEqual("bound");
511
+ });
512
+
513
+ test("bound error map overrides contextual", () => {
514
+ // support contextual override
515
+ const result = stringWithCustomError.safeParse(undefined, {
516
+ error: () => ({ message: "override" }),
517
+ });
518
+ expect(result.success).toBe(false);
519
+ expect(result.error!.issues[0].message).toEqual("bound");
520
+ });
521
+
522
+ test("z.config customError ", () => {
523
+ // support overrideErrorMap
524
+
525
+ z.config({ customError: () => ({ message: "override" }) });
526
+ const result = stringWithCustomError.min(10).safeParse("tooshort");
527
+ expect(result.success).toBe(false);
528
+ expect(result.error).toMatchInlineSnapshot(`
529
+ [ZodError: [
530
+ {
531
+ "origin": "string",
532
+ "code": "too_small",
533
+ "minimum": 10,
534
+ "inclusive": true,
535
+ "path": [],
536
+ "message": "override"
537
+ }
538
+ ]]
539
+ `);
540
+ expect(result.error!.issues[0].message).toEqual("override");
541
+ z.config({ customError: undefined });
542
+ });
543
+
544
+ // test("invalid and required", () => {
545
+ // const str = z.string({
546
+ // invalid_type_error: "Invalid name",
547
+ // required_error: "Name is required",
548
+ // });
549
+ // const result1 = str.safeParse(1234);
550
+ // expect(result1.success).toBe(false);
551
+ // if (!result1.success) {
552
+ // expect(result1.error.issues[0].message).toEqual("Invalid name");
553
+ // }
554
+ // const result2 = str.safeParse(undefined);
555
+ // expect(result2.success).toBe(false);
556
+ // if (!result2.success) {
557
+ // expect(result2.error.issues[0].message).toEqual("Name is required");
558
+ // }
559
+ // });
560
+
561
+ // test("Fallback to default required error", () => {
562
+ // const str = z.string({
563
+ // invalid_type_error: "Invalid name",
564
+ // // required_error: "Name is required",
565
+ // });
566
+
567
+ // const result2 = str.safeParse(undefined);
568
+ // expect(result2.success).toBe(false);
569
+ // if (!result2.success) {
570
+ // expect(result2.error.issues[0].message).toEqual("Required");
571
+ // }
572
+ // });
573
+
574
+ // test("invalid and required and errorMap", () => {
575
+ // expect(() => {
576
+ // return z.string({
577
+ // invalid_type_error: "Invalid name",
578
+ // required_error: "Name is required",
579
+ // errorMap: () => ({ message: "override" }),
580
+ // });
581
+ // }).toThrow();
582
+ // });
583
+
584
+ // test("strict error message", () => {
585
+ // const errorMsg = "Invalid object";
586
+ // const obj = z.object({ x: z.string() }).strict(errorMsg);
587
+ // const result = obj.safeParse({ x: "a", y: "b" });
588
+ // expect(result.success).toBe(false);
589
+ // if (!result.success) {
590
+ // expect(result.error.issues[0].message).toEqual(errorMsg);
591
+ // }
592
+ // });
593
+
594
+ test("empty string error message", () => {
595
+ const schema = z.string().max(1, { message: "" });
596
+ const result = schema.safeParse("asdf");
597
+ expect(result.success).toBe(false);
598
+ expect(result.error!.issues[0].message).toEqual("");
599
+ });
600
+
601
+ test("dont short circuit on continuable errors", () => {
602
+ const user = z
603
+ .object({
604
+ password: z.string().min(6),
605
+ confirm: z.string(),
606
+ })
607
+ .refine((data) => data.password === data.confirm, {
608
+ message: "Passwords don't match",
609
+ path: ["confirm"],
610
+ });
611
+ const result = user.safeParse({ password: "asdf", confirm: "qwer" });
612
+ expect(result.success).toBe(false);
613
+ expect(result.error).toMatchInlineSnapshot(`
614
+ [ZodError: [
615
+ {
616
+ "origin": "string",
617
+ "code": "too_small",
618
+ "minimum": 6,
619
+ "inclusive": true,
620
+ "path": [
621
+ "password"
622
+ ],
623
+ "message": "Too small: expected string to have >=6 characters"
624
+ },
625
+ {
626
+ "code": "custom",
627
+ "path": [
628
+ "confirm"
629
+ ],
630
+ "message": "Passwords don't match"
631
+ }
632
+ ]]
633
+ `);
634
+ // expect(result.error!.issues.length).toEqual(2);
635
+ });
636
+
637
+ test("string error params", () => {
638
+ const a = z.string("Bad!");
639
+ expect(a.safeParse(123).error!.issues[0].message).toBe("Bad!");
640
+
641
+ const b = z.string().min(5, "Too short!");
642
+ expect(b.safeParse("abc").error!.issues[0].message).toBe("Too short!");
643
+
644
+ const c = z.uuid("Bad UUID!");
645
+ expect(c.safeParse("not-a-uuid").error!.issues[0].message).toBe("Bad UUID!");
646
+
647
+ const d = z.string().datetime({ message: "Bad date!" });
648
+ expect(d.safeParse("not-a-date").error!.issues[0].message).toBe("Bad date!");
649
+
650
+ const e = z.array(z.string(), "Bad array!");
651
+ expect(e.safeParse("not-an-array").error!.issues[0].message).toBe("Bad array!");
652
+
653
+ const f = z.array(z.string()).min(5, "Too few items!");
654
+ expect(f.safeParse(["a", "b"]).error!.issues[0].message).toBe("Too few items!");
655
+
656
+ const g = z.set(z.string(), "Bad set!");
657
+ expect(g.safeParse("not-a-set").error!.issues[0].message).toBe("Bad set!");
658
+
659
+ const h = z.array(z.string(), "Bad array!");
660
+ expect(h.safeParse(123).error!.issues[0].message).toBe("Bad array!");
661
+
662
+ const i = z.set(z.string(), "Bad set!");
663
+ expect(i.safeParse(123).error!.issues[0].message).toBe("Bad set!");
664
+
665
+ const j = z.array(z.string(), "Bad array!");
666
+ expect(j.safeParse(null).error!.issues[0].message).toBe("Bad array!");
667
+ });
668
+
669
+ test("error inheritance", () => {
670
+ const e1 = z.string().safeParse(123).error!;
671
+ expect(e1).toBeInstanceOf(z.core.$ZodError);
672
+ expect(e1).toBeInstanceOf(z.ZodError);
673
+ expect(e1).toBeInstanceOf(z.ZodRealError);
674
+ // expect(e1).not.toBeInstanceOf(Error);
675
+
676
+ try {
677
+ z.string().parse(123);
678
+ } catch (e2) {
679
+ expect(e1).toBeInstanceOf(z.core.$ZodError);
680
+ expect(e2).toBeInstanceOf(z.ZodError);
681
+ expect(e2).toBeInstanceOf(z.ZodRealError);
682
+ // expect(e2).toBeInstanceOf(Error);
683
+ }
684
+ });
685
+
686
+ test("error serialization", () => {
687
+ try {
688
+ z.string().parse(123);
689
+ } catch (e) {
690
+ expect(e).toMatchInlineSnapshot(`
691
+ [ZodError: [
692
+ {
693
+ "expected": "string",
694
+ "code": "invalid_type",
695
+ "path": [],
696
+ "message": "Invalid input: expected string, received number"
697
+ }
698
+ ]]
699
+ `);
700
+ expect(inspect(e).split("\n").slice(0, 8).join("\n")).toMatchInlineSnapshot(`
701
+ "ZodError: [
702
+ {
703
+ "expected": "string",
704
+ "code": "invalid_type",
705
+ "path": [],
706
+ "message": "Invalid input: expected string, received number"
707
+ }
708
+ ]"
709
+ `);
710
+ }
711
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/file.test.ts ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @ts-ignore
2
+ import { File as WebFile } from "@web-std/file";
3
+
4
+ import { afterEach, beforeEach, expect, test } from "vitest";
5
+
6
+ import * as z from "zod/v4";
7
+
8
+ const minCheck = z.file().min(5);
9
+ const maxCheck = z.file().max(8);
10
+ const mimeCheck = z.file().mime(["text/plain", "application/json"]);
11
+
12
+ const originalFile = global.File;
13
+ beforeEach(async () => {
14
+ if (!globalThis.File) globalThis.File = WebFile;
15
+ });
16
+ afterEach(() => {
17
+ if (globalThis.File !== originalFile) {
18
+ globalThis.File = originalFile;
19
+ }
20
+ });
21
+
22
+ test("passing validations", () => {
23
+ minCheck.safeParse(new File(["12345"], "test.txt"));
24
+ maxCheck.safeParse(new File(["12345678"], "test.txt"));
25
+ mimeCheck.safeParse(new File([""], "test.csv", { type: "text/plain" }));
26
+ expect(() => mimeCheck.parse(new File([""], "test.txt"))).toThrow();
27
+ expect(() => mimeCheck.parse(new File([""], "test.txt", { type: "text/csv" }))).toThrow();
28
+ });
29
+
30
+ test("failing validations", () => {
31
+ expect(minCheck.safeParse(new File(["1234"], "test.txt"))).toMatchInlineSnapshot(`
32
+ {
33
+ "error": [ZodError: [
34
+ {
35
+ "origin": "file",
36
+ "code": "too_small",
37
+ "minimum": 5,
38
+ "path": [],
39
+ "message": "Too small: expected file to have >5 bytes"
40
+ }
41
+ ]],
42
+ "success": false,
43
+ }
44
+ `);
45
+ expect(maxCheck.safeParse(new File(["123456789"], "test.txt"))).toMatchInlineSnapshot(`
46
+ {
47
+ "error": [ZodError: [
48
+ {
49
+ "origin": "file",
50
+ "code": "too_big",
51
+ "maximum": 8,
52
+ "path": [],
53
+ "message": "Too big: expected file to have <8 bytes"
54
+ }
55
+ ]],
56
+ "success": false,
57
+ }
58
+ `);
59
+ expect(mimeCheck.safeParse(new File([""], "test.csv"))).toMatchInlineSnapshot(`
60
+ {
61
+ "error": [ZodError: [
62
+ {
63
+ "code": "invalid_value",
64
+ "values": [
65
+ "text/plain",
66
+ "application/json"
67
+ ],
68
+ "path": [],
69
+ "message": "Invalid option: expected one of \\"text/plain\\"|\\"application/json\\""
70
+ }
71
+ ]],
72
+ "success": false,
73
+ }
74
+ `);
75
+ expect(mimeCheck.safeParse(new File([""], "test.csv", { type: "text/csv" }))).toMatchInlineSnapshot(`
76
+ {
77
+ "error": [ZodError: [
78
+ {
79
+ "code": "invalid_value",
80
+ "values": [
81
+ "text/plain",
82
+ "application/json"
83
+ ],
84
+ "path": [],
85
+ "message": "Invalid option: expected one of \\"text/plain\\"|\\"application/json\\""
86
+ }
87
+ ]],
88
+ "success": false,
89
+ }
90
+ `);
91
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/firstparty.test.ts ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+ import type * as core from "zod/v4/core";
4
+
5
+ test("first party switch", () => {
6
+ const myType = z.string() as core.$ZodTypes;
7
+ const def = myType._zod.def;
8
+ switch (def.type) {
9
+ case "string":
10
+ break;
11
+ case "number":
12
+ break;
13
+ case "bigint":
14
+ break;
15
+ case "boolean":
16
+ break;
17
+ case "date":
18
+ break;
19
+ case "symbol":
20
+ break;
21
+ case "undefined":
22
+ break;
23
+ case "null":
24
+ break;
25
+ case "any":
26
+ break;
27
+ case "unknown":
28
+ break;
29
+ case "never":
30
+ break;
31
+ case "void":
32
+ break;
33
+ case "array":
34
+ break;
35
+ case "object":
36
+ break;
37
+ case "union":
38
+ break;
39
+ case "intersection":
40
+ break;
41
+ case "tuple":
42
+ break;
43
+ case "record":
44
+ break;
45
+ case "map":
46
+ break;
47
+ case "set":
48
+ break;
49
+ case "literal":
50
+ break;
51
+ case "enum":
52
+ break;
53
+ case "promise":
54
+ break;
55
+ case "optional":
56
+ break;
57
+ case "nonoptional":
58
+ break;
59
+ case "nullable":
60
+ break;
61
+ case "default":
62
+ break;
63
+ case "prefault":
64
+ break;
65
+ case "template_literal":
66
+ break;
67
+ case "custom":
68
+ break;
69
+ case "transform":
70
+ break;
71
+ case "readonly":
72
+ break;
73
+ case "nan":
74
+ break;
75
+ case "pipe":
76
+ break;
77
+ case "success":
78
+ break;
79
+ case "catch":
80
+ break;
81
+ case "file":
82
+ break;
83
+ case "lazy":
84
+ break;
85
+ default:
86
+ expectTypeOf(def).toEqualTypeOf<never>();
87
+ }
88
+ });
89
+
90
+ test("$ZodSchemaTypes", () => {
91
+ const type = "string" as core.$ZodTypeDef["type"];
92
+ switch (type) {
93
+ case "string":
94
+ break;
95
+ case "number":
96
+ break;
97
+ case "int":
98
+ break;
99
+ case "bigint":
100
+ break;
101
+ case "boolean":
102
+ break;
103
+ case "date":
104
+ break;
105
+ case "symbol":
106
+ break;
107
+ case "undefined":
108
+ break;
109
+ case "null":
110
+ break;
111
+ case "any":
112
+ break;
113
+ case "unknown":
114
+ break;
115
+ case "never":
116
+ break;
117
+ case "void":
118
+ break;
119
+ case "array":
120
+ break;
121
+ case "object":
122
+ break;
123
+ case "union":
124
+ break;
125
+ case "intersection":
126
+ break;
127
+ case "tuple":
128
+ break;
129
+ case "record":
130
+ break;
131
+ case "map":
132
+ break;
133
+ case "set":
134
+ break;
135
+ case "literal":
136
+ break;
137
+ case "enum":
138
+ break;
139
+ case "promise":
140
+ break;
141
+ case "optional":
142
+ break;
143
+ case "nonoptional":
144
+ break;
145
+ case "nullable":
146
+ break;
147
+ case "default":
148
+ break;
149
+ case "prefault":
150
+ break;
151
+ case "template_literal":
152
+ break;
153
+ case "custom":
154
+ break;
155
+ case "transform":
156
+ break;
157
+ case "readonly":
158
+ break;
159
+ case "nan":
160
+ break;
161
+ case "pipe":
162
+ break;
163
+ case "success":
164
+ break;
165
+ case "catch":
166
+ break;
167
+ case "file":
168
+ break;
169
+ case "lazy":
170
+ break;
171
+
172
+ default:
173
+ expectTypeOf(type).toEqualTypeOf<never>();
174
+ }
175
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/function.test.ts ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ const args1 = z.tuple([z.string()]);
5
+ const returns1 = z.number();
6
+ const func1 = z.function({
7
+ input: args1,
8
+
9
+ output: returns1,
10
+ });
11
+
12
+ test("function parsing", () => {
13
+ const parsed = func1.implement((arg: any) => arg.length);
14
+ const result = parsed("asdf");
15
+ expect(result).toBe(4);
16
+ });
17
+
18
+ test("parsed function fail 1", () => {
19
+ // @ts-expect-error
20
+ const parsed = func1.implement((x: string) => x);
21
+ expect(() => parsed("asdf")).toThrow();
22
+ });
23
+
24
+ test("parsed function fail 2", () => {
25
+ // @ts-expect-error
26
+ const parsed = func1.implement((x: string) => x);
27
+ expect(() => parsed(13 as any)).toThrow();
28
+ });
29
+
30
+ test("function inference 1", () => {
31
+ type func1 = (typeof func1)["_input"];
32
+ expectTypeOf<func1>().toEqualTypeOf<(k: string) => number>();
33
+ });
34
+
35
+ // test("method parsing", () => {
36
+ // const methodObject = z.object({
37
+ // property: z.number(),
38
+ // method: z
39
+ // .function()
40
+ // .input(z.tuple([z.string()]))
41
+ // .output(z.number()),
42
+ // });
43
+ // const methodInstance = {
44
+ // property: 3,
45
+ // method: function (s: string) {
46
+ // return s.length + this.property;
47
+ // },
48
+ // };
49
+ // const parsed = methodObject.parse(methodInstance);
50
+ // expect(parsed.method("length=8")).toBe(11); // 8 length + 3 property
51
+ // });
52
+
53
+ // test("async method parsing", async () => {
54
+ // const methodObject = z.object({
55
+ // property: z.number(),
56
+ // method: z.function().input(z.string()).output(z.promise(z.number())),
57
+ // });
58
+ // const methodInstance = {
59
+ // property: 3,
60
+ // method: async function (s: string) {
61
+ // return s.length + this.property;
62
+ // },
63
+ // };
64
+ // const parsed = methodObject.parse(methodInstance);
65
+ // expect(await parsed.method("length=8")).toBe(11); // 8 length + 3 property
66
+ // });
67
+
68
+ test("args method", () => {
69
+ const t1 = z.function();
70
+ type t1 = (typeof t1)["_input"];
71
+ expectTypeOf<t1>().toEqualTypeOf<(...args_1: never[]) => unknown>();
72
+ t1._input;
73
+
74
+ const t2args = z.tuple([z.string()], z.unknown());
75
+
76
+ const t2 = t1.input(t2args);
77
+ type t2 = (typeof t2)["_input"];
78
+ expectTypeOf<t2>().toEqualTypeOf<(arg: string, ...args_1: unknown[]) => unknown>();
79
+
80
+ const t3 = t2.output(z.boolean());
81
+ type t3 = (typeof t3)["_input"];
82
+ expectTypeOf<t3>().toEqualTypeOf<(arg: string, ...args_1: unknown[]) => boolean>();
83
+ });
84
+
85
+ // test("custom args", () => {
86
+ // const fn = z.function().implement((_a: string, _b: number) => {
87
+ // return new Date();
88
+ // });
89
+
90
+ // expectTypeOf(fn).toEqualTypeOf<(a: string, b: number) => Date>();
91
+ // });
92
+
93
+ const args2 = z.tuple([
94
+ z.object({
95
+ f1: z.number(),
96
+ f2: z.string().nullable(),
97
+ f3: z.array(z.boolean().optional()).optional(),
98
+ }),
99
+ ]);
100
+ const returns2 = z.union([z.string(), z.number()]);
101
+
102
+ const func2 = z.function({
103
+ input: args2,
104
+ output: returns2,
105
+ });
106
+
107
+ test("function inference 2", () => {
108
+ type func2 = (typeof func2)["_input"];
109
+
110
+ expectTypeOf<func2>().toEqualTypeOf<
111
+ (arg: {
112
+ f3?: (boolean | undefined)[] | undefined;
113
+ f1: number;
114
+ f2: string | null;
115
+ }) => string | number
116
+ >();
117
+ });
118
+
119
+ test("valid function run", () => {
120
+ const validFunc2Instance = func2.implement((_x) => {
121
+ _x.f2;
122
+ _x.f3![0];
123
+ return "adf" as any;
124
+ });
125
+
126
+ validFunc2Instance({
127
+ f1: 21,
128
+ f2: "asdf",
129
+ f3: [true, false],
130
+ });
131
+ });
132
+
133
+ test("input validation error", () => {
134
+ const schema = z.function({
135
+ input: z.tuple([z.string()]),
136
+ output: z.void(),
137
+ });
138
+ const fn = schema.implement(() => 1234 as any);
139
+
140
+ // @ts-expect-error
141
+ const checker = () => fn();
142
+
143
+ try {
144
+ checker();
145
+ } catch (e: any) {
146
+ expect(e.issues).toMatchInlineSnapshot(`
147
+ [
148
+ {
149
+ "code": "invalid_type",
150
+ "expected": "string",
151
+ "message": "Invalid input: expected string, received undefined",
152
+ "path": [
153
+ 0,
154
+ ],
155
+ },
156
+ ]
157
+ `);
158
+ }
159
+ });
160
+
161
+ test("array inputs", () => {
162
+ const a = z.function({
163
+ input: [
164
+ z.object({
165
+ name: z.string(),
166
+ age: z.number().int(),
167
+ }),
168
+ ],
169
+ output: z.string(),
170
+ });
171
+
172
+ a.implement((args) => {
173
+ return `${args.age}`;
174
+ });
175
+
176
+ const b = z.function({
177
+ input: [
178
+ z.object({
179
+ name: z.string(),
180
+ age: z.number().int(),
181
+ }),
182
+ ],
183
+ });
184
+ b.implement((args) => {
185
+ return `${args.age}`;
186
+ });
187
+ });
188
+
189
+ test("output validation error", () => {
190
+ const schema = z.function({
191
+ input: z.tuple([]),
192
+ output: z.string(),
193
+ });
194
+ const fn = schema.implement(() => 1234 as any);
195
+ try {
196
+ fn();
197
+ } catch (e: any) {
198
+ expect(e.issues).toMatchInlineSnapshot(`
199
+ [
200
+ {
201
+ "code": "invalid_type",
202
+ "expected": "string",
203
+ "message": "Invalid input: expected string, received number",
204
+ "path": [],
205
+ },
206
+ ]
207
+ `);
208
+ }
209
+ });
210
+
211
+ test("function with async refinements", async () => {
212
+ const schema = z
213
+ .function()
214
+ .input([z.string().refine(async (val) => val.length > 10)])
215
+ .output(z.promise(z.number().refine(async (val) => val > 10)));
216
+
217
+ const func = schema.implementAsync(async (val) => {
218
+ return val.length;
219
+ });
220
+ const results = [];
221
+ try {
222
+ await func("asdfasdf");
223
+ results.push("success");
224
+ } catch (_) {
225
+ results.push("fail");
226
+ }
227
+ try {
228
+ await func("asdflkjasdflkjsf");
229
+ results.push("success");
230
+ } catch (_) {
231
+ results.push("fail");
232
+ }
233
+
234
+ expect(results).toEqual(["fail", "success"]);
235
+ });
236
+
237
+ test("non async function with async refinements should fail", async () => {
238
+ const func = z
239
+ .function()
240
+ .input([z.string().refine(async (val) => val.length > 10)])
241
+ .output(z.number().refine(async (val) => val > 10))
242
+ .implement((val) => {
243
+ return val.length;
244
+ });
245
+
246
+ const results = [];
247
+ try {
248
+ await func("asdasdfasdffasdf");
249
+ results.push("success");
250
+ } catch (_) {
251
+ results.push("fail");
252
+ }
253
+
254
+ expect(results).toEqual(["fail"]);
255
+ });
256
+
257
+ test("extra parameters with rest", () => {
258
+ const maxLength5 = z
259
+ .function()
260
+ .input([z.string()], z.unknown())
261
+ .output(z.boolean())
262
+ .implement((str, _arg, _qewr) => {
263
+ return str.length <= 5;
264
+ });
265
+
266
+ const filteredList = ["apple", "orange", "pear", "banana", "strawberry"].filter(maxLength5);
267
+ expect(filteredList.length).toEqual(2);
268
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/generics.test.ts ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ function nest<TData extends z.ZodType>(schema: TData) {
5
+ return z.object({
6
+ nested: schema,
7
+ });
8
+ }
9
+
10
+ test("generics", () => {
11
+ const a = nest(z.object({ a: z.string() }));
12
+ type a = z.infer<typeof a>;
13
+ expectTypeOf<a>().toEqualTypeOf<{ nested: { a: string } }>();
14
+
15
+ const b = nest(z.object({ a: z.string().optional() }));
16
+ type b = z.infer<typeof b>;
17
+ expectTypeOf<b>().toEqualTypeOf<{ nested: { a?: string | undefined } }>();
18
+ });
19
+
20
+ test("generics with optional", () => {
21
+ async function stripOuter<TData extends z.ZodType>(schema: TData, data: unknown) {
22
+ return z
23
+ .object({
24
+ nested: schema.optional(),
25
+ })
26
+ .transform((data) => {
27
+ return data.nested;
28
+ })
29
+ .parse({ nested: data });
30
+ }
31
+
32
+ const result = stripOuter(z.object({ a: z.string() }), { a: "asdf" });
33
+ expectTypeOf<typeof result>().toEqualTypeOf<Promise<{ a: string } | undefined>>();
34
+ });
35
+
36
+ // test("assignability", () => {
37
+ // const createSchemaAndParse = <K extends string, VS extends z.ZodString>(key: K, valueSchema: VS, data: unknown) => {
38
+ // const schema = z.object({
39
+ // [key]: valueSchema,
40
+ // });
41
+ // // return { [key]: valueSchema };
42
+ // const parsed = schema.parse(data);
43
+ // return parsed;
44
+ // // const inferred: z.infer<z.ZodObject<{ [k in K]: VS }>> = parsed;
45
+ // // return inferred;
46
+ // };
47
+ // const parsed = createSchemaAndParse("foo", z.string(), { foo: "" });
48
+ // expectTypeOf<typeof parsed>().toEqualTypeOf<{ foo: string }>();
49
+ // });
50
+
51
+ test("nested no undefined", () => {
52
+ const inner = z.string().or(z.array(z.string()));
53
+ const outer = z.object({ inner });
54
+ type outerSchema = z.infer<typeof outer>;
55
+ expectTypeOf<outerSchema>().toEqualTypeOf<{ inner: string | string[] }>();
56
+
57
+ expect(outer.safeParse({ inner: undefined }).success).toEqual(false);
58
+ });
59
+
60
+ test("generic on output type", () => {
61
+ const createV4Schema = <Output>(opts: {
62
+ schema: z.ZodType<Output>;
63
+ }) => {
64
+ return opts.schema;
65
+ };
66
+
67
+ createV4Schema({
68
+ schema: z.object({
69
+ name: z.string(),
70
+ }),
71
+ })?._zod?.output?.name;
72
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/index.test.ts ADDED
@@ -0,0 +1,829 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+ import type { util } from "zod/v4/core";
4
+
5
+ test("z.boolean", () => {
6
+ const a = z.boolean();
7
+ expect(z.parse(a, true)).toEqual(true);
8
+ expect(z.parse(a, false)).toEqual(false);
9
+ expect(() => z.parse(a, 123)).toThrow();
10
+ expect(() => z.parse(a, "true")).toThrow();
11
+ type a = z.output<typeof a>;
12
+ expectTypeOf<a>().toEqualTypeOf<boolean>();
13
+ });
14
+
15
+ test("z.bigint", () => {
16
+ const a = z.bigint();
17
+ expect(z.parse(a, BigInt(123))).toEqual(BigInt(123));
18
+ expect(() => z.parse(a, 123)).toThrow();
19
+ expect(() => z.parse(a, "123")).toThrow();
20
+ });
21
+
22
+ test("z.symbol", () => {
23
+ const a = z.symbol();
24
+ const sym = Symbol();
25
+ expect(z.parse(a, sym)).toEqual(sym);
26
+ expect(() => z.parse(a, "symbol")).toThrow();
27
+ });
28
+
29
+ test("z.date", () => {
30
+ const a = z.date();
31
+ const date = new Date();
32
+ expect(z.parse(a, date)).toEqual(date);
33
+ expect(() => z.parse(a, "date")).toThrow();
34
+ });
35
+
36
+ test("z.coerce.string", () => {
37
+ const a = z.coerce.string();
38
+ expect(z.parse(a, 123)).toEqual("123");
39
+ expect(z.parse(a, true)).toEqual("true");
40
+ expect(z.parse(a, null)).toEqual("null");
41
+ expect(z.parse(a, undefined)).toEqual("undefined");
42
+ });
43
+
44
+ test("z.coerce.number", () => {
45
+ const a = z.coerce.number();
46
+ expect(z.parse(a, "123")).toEqual(123);
47
+ expect(z.parse(a, "123.45")).toEqual(123.45);
48
+ expect(z.parse(a, true)).toEqual(1);
49
+ expect(z.parse(a, false)).toEqual(0);
50
+ expect(() => z.parse(a, "abc")).toThrow();
51
+ });
52
+
53
+ test("z.coerce.boolean", () => {
54
+ const a = z.coerce.boolean();
55
+ // test booleans
56
+ expect(z.parse(a, true)).toEqual(true);
57
+ expect(z.parse(a, false)).toEqual(false);
58
+ expect(z.parse(a, "true")).toEqual(true);
59
+ expect(z.parse(a, "false")).toEqual(true);
60
+ expect(z.parse(a, 1)).toEqual(true);
61
+ expect(z.parse(a, 0)).toEqual(false);
62
+ expect(z.parse(a, {})).toEqual(true);
63
+ expect(z.parse(a, [])).toEqual(true);
64
+ expect(z.parse(a, undefined)).toEqual(false);
65
+ expect(z.parse(a, null)).toEqual(false);
66
+ expect(z.parse(a, "")).toEqual(false);
67
+ });
68
+
69
+ test("z.coerce.bigint", () => {
70
+ const a = z.coerce.bigint();
71
+ expect(z.parse(a, "123")).toEqual(BigInt(123));
72
+ expect(z.parse(a, 123)).toEqual(BigInt(123));
73
+ expect(() => z.parse(a, "abc")).toThrow();
74
+ });
75
+
76
+ test("z.coerce.date", () => {
77
+ const a = z.coerce.date();
78
+ const date = new Date();
79
+ expect(z.parse(a, date.toISOString())).toEqual(date);
80
+ expect(z.parse(a, date.getTime())).toEqual(date);
81
+ expect(() => z.parse(a, "invalid date")).toThrow();
82
+ });
83
+
84
+ test("z.iso.datetime", () => {
85
+ const d1 = "2021-01-01T00:00:00Z";
86
+ const d2 = "2021-01-01T00:00:00.123Z";
87
+ const d3 = "2021-01-01T00:00:00";
88
+ const d4 = "2021-01-01T00:00:00+07:00";
89
+ const d5 = "bad data";
90
+
91
+ // local: false, offset: false, precision: null
92
+ const a = z.iso.datetime();
93
+ expect(z.safeParse(a, d1).success).toEqual(true);
94
+ expect(z.safeParse(a, d2).success).toEqual(true);
95
+ expect(z.safeParse(a, d3).success).toEqual(false);
96
+ expect(z.safeParse(a, d4).success).toEqual(false);
97
+ expect(z.safeParse(a, d5).success).toEqual(false);
98
+
99
+ const b = z.iso.datetime({ local: true });
100
+ expect(z.safeParse(b, d1).success).toEqual(true);
101
+ expect(z.safeParse(b, d2).success).toEqual(true);
102
+ expect(z.safeParse(b, d3).success).toEqual(true);
103
+ expect(z.safeParse(b, d4).success).toEqual(false);
104
+ expect(z.safeParse(b, d5).success).toEqual(false);
105
+
106
+ const c = z.iso.datetime({ offset: true });
107
+ expect(z.safeParse(c, d1).success).toEqual(true);
108
+ expect(z.safeParse(c, d2).success).toEqual(true);
109
+ expect(z.safeParse(c, d3).success).toEqual(false);
110
+ expect(z.safeParse(c, d4).success).toEqual(true);
111
+ expect(z.safeParse(c, d5).success).toEqual(false);
112
+
113
+ const d = z.iso.datetime({ precision: 3 });
114
+ expect(z.safeParse(d, d1).success).toEqual(false);
115
+ expect(z.safeParse(d, d2).success).toEqual(true);
116
+ expect(z.safeParse(d, d3).success).toEqual(false);
117
+ expect(z.safeParse(d, d4).success).toEqual(false);
118
+ expect(z.safeParse(d, d5).success).toEqual(false);
119
+ });
120
+
121
+ test("z.iso.date", () => {
122
+ const d1 = "2021-01-01";
123
+ const d2 = "bad data";
124
+
125
+ const a = z.iso.date();
126
+ expect(z.safeParse(a, d1).success).toEqual(true);
127
+ expect(z.safeParse(a, d2).success).toEqual(false);
128
+
129
+ const b = z.string().check(z.iso.date());
130
+ expect(z.safeParse(b, d1).success).toEqual(true);
131
+ expect(z.safeParse(b, d2).success).toEqual(false);
132
+ });
133
+
134
+ test("z.iso.time", () => {
135
+ const d1 = "00:00:00";
136
+ const d2 = "00:00:00.123";
137
+ const d3 = "bad data";
138
+
139
+ const a = z.iso.time();
140
+ expect(z.safeParse(a, d1).success).toEqual(true);
141
+ expect(z.safeParse(a, d2).success).toEqual(true);
142
+ expect(z.safeParse(a, d3).success).toEqual(false);
143
+
144
+ const b = z.iso.time({ precision: 3 });
145
+ expect(z.safeParse(b, d1).success).toEqual(false);
146
+ expect(z.safeParse(b, d2).success).toEqual(true);
147
+ expect(z.safeParse(b, d3).success).toEqual(false);
148
+
149
+ const c = z.string().check(z.iso.time());
150
+ expect(z.safeParse(c, d1).success).toEqual(true);
151
+ expect(z.safeParse(c, d2).success).toEqual(true);
152
+ expect(z.safeParse(c, d3).success).toEqual(false);
153
+ });
154
+
155
+ test("z.iso.duration", () => {
156
+ const d1 = "P3Y6M4DT12H30M5S";
157
+ const d2 = "bad data";
158
+
159
+ const a = z.iso.duration();
160
+ expect(z.safeParse(a, d1).success).toEqual(true);
161
+ expect(z.safeParse(a, d2).success).toEqual(false);
162
+
163
+ const b = z.string().check(z.iso.duration());
164
+ expect(z.safeParse(b, d1).success).toEqual(true);
165
+ expect(z.safeParse(b, d2).success).toEqual(false);
166
+ });
167
+
168
+ test("z.undefined", () => {
169
+ const a = z.undefined();
170
+ expect(z.parse(a, undefined)).toEqual(undefined);
171
+ expect(() => z.parse(a, "undefined")).toThrow();
172
+ });
173
+
174
+ test("z.null", () => {
175
+ const a = z.null();
176
+ expect(z.parse(a, null)).toEqual(null);
177
+ expect(() => z.parse(a, "null")).toThrow();
178
+ });
179
+
180
+ test("z.any", () => {
181
+ const a = z.any();
182
+ expect(z.parse(a, "hello")).toEqual("hello");
183
+ expect(z.parse(a, 123)).toEqual(123);
184
+ expect(z.parse(a, true)).toEqual(true);
185
+ expect(z.parse(a, null)).toEqual(null);
186
+ expect(z.parse(a, undefined)).toEqual(undefined);
187
+ z.parse(a, {});
188
+ z.parse(a, []);
189
+ z.parse(a, Symbol());
190
+ z.parse(a, new Date());
191
+ });
192
+
193
+ test("z.unknown", () => {
194
+ const a = z.unknown();
195
+ expect(z.parse(a, "hello")).toEqual("hello");
196
+ expect(z.parse(a, 123)).toEqual(123);
197
+ expect(z.parse(a, true)).toEqual(true);
198
+ expect(z.parse(a, null)).toEqual(null);
199
+ expect(z.parse(a, undefined)).toEqual(undefined);
200
+ z.parse(a, {});
201
+ z.parse(a, []);
202
+ z.parse(a, Symbol());
203
+ z.parse(a, new Date());
204
+ });
205
+
206
+ test("z.never", () => {
207
+ const a = z.never();
208
+ expect(() => z.parse(a, "hello")).toThrow();
209
+ });
210
+
211
+ test("z.void", () => {
212
+ const a = z.void();
213
+ expect(z.parse(a, undefined)).toEqual(undefined);
214
+ expect(() => z.parse(a, null)).toThrow();
215
+ });
216
+
217
+ test("z.array", () => {
218
+ const a = z.array(z.string());
219
+ expect(z.parse(a, ["hello", "world"])).toEqual(["hello", "world"]);
220
+ expect(() => z.parse(a, [123])).toThrow();
221
+ expect(() => z.parse(a, "hello")).toThrow();
222
+ });
223
+
224
+ test("z.union", () => {
225
+ const a = z.union([z.string(), z.number()]);
226
+ expect(z.parse(a, "hello")).toEqual("hello");
227
+ expect(z.parse(a, 123)).toEqual(123);
228
+ expect(() => z.parse(a, true)).toThrow();
229
+ });
230
+
231
+ test("z.intersection", () => {
232
+ const a = z.intersection(z.object({ a: z.string() }), z.object({ b: z.number() }));
233
+ expect(z.parse(a, { a: "hello", b: 123 })).toEqual({ a: "hello", b: 123 });
234
+ expect(() => z.parse(a, { a: "hello" })).toThrow();
235
+ expect(() => z.parse(a, { b: 123 })).toThrow();
236
+ expect(() => z.parse(a, "hello")).toThrow();
237
+ });
238
+
239
+ test("z.tuple", () => {
240
+ const a = z.tuple([z.string(), z.number()]);
241
+ expect(z.parse(a, ["hello", 123])).toEqual(["hello", 123]);
242
+ expect(() => z.parse(a, ["hello", "world"])).toThrow();
243
+ expect(() => z.parse(a, [123, 456])).toThrow();
244
+ expect(() => z.parse(a, "hello")).toThrow();
245
+
246
+ // tuple with rest
247
+ const b = z.tuple([z.string(), z.number(), z.optional(z.string())], z.boolean());
248
+ type b = z.output<typeof b>;
249
+
250
+ expectTypeOf<b>().toEqualTypeOf<[string, number, string?, ...boolean[]]>();
251
+ const datas = [
252
+ ["hello", 123],
253
+ ["hello", 123, "world"],
254
+ ["hello", 123, "world", true],
255
+ ["hello", 123, "world", true, false, true],
256
+ ];
257
+ for (const data of datas) {
258
+ expect(z.parse(b, data)).toEqual(data);
259
+ }
260
+
261
+ expect(() => z.parse(b, ["hello", 123, 123])).toThrow();
262
+ expect(() => z.parse(b, ["hello", 123, "world", 123])).toThrow();
263
+
264
+ // tuple with readonly args
265
+ const cArgs = [z.string(), z.number(), z.optional(z.string())] as const;
266
+ const c = z.tuple(cArgs, z.boolean());
267
+ type c = z.output<typeof c>;
268
+ expectTypeOf<c>().toEqualTypeOf<[string, number, string?, ...boolean[]]>();
269
+ // type c = z.output<typeof c>;
270
+ });
271
+
272
+ test("z.record", () => {
273
+ // record schema with enum keys
274
+ const a = z.record(z.string(), z.string());
275
+ type a = z.output<typeof a>;
276
+ expectTypeOf<a>().toEqualTypeOf<Record<string, string>>();
277
+
278
+ const b = z.record(z.union([z.string(), z.number(), z.symbol()]), z.string());
279
+ type b = z.output<typeof b>;
280
+ expectTypeOf<b>().toEqualTypeOf<Record<string | number | symbol, string>>();
281
+ expect(z.parse(b, { a: "hello", 1: "world", [Symbol.for("asdf")]: "symbol" })).toEqual({
282
+ a: "hello",
283
+ 1: "world",
284
+ [Symbol.for("asdf")]: "symbol",
285
+ });
286
+
287
+ // enum keys
288
+ const c = z.record(z.enum(["a", "b", "c"]), z.string());
289
+ type c = z.output<typeof c>;
290
+ expectTypeOf<c>().toEqualTypeOf<Record<"a" | "b" | "c", string>>();
291
+ expect(z.parse(c, { a: "hello", b: "world", c: "world" })).toEqual({
292
+ a: "hello",
293
+ b: "world",
294
+ c: "world",
295
+ });
296
+ // missing keys
297
+ expect(() => z.parse(c, { a: "hello", b: "world" })).toThrow();
298
+ // extra keys
299
+ expect(() => z.parse(c, { a: "hello", b: "world", c: "world", d: "world" })).toThrow();
300
+
301
+ // partial enum
302
+ const d = z.record(z.enum(["a", "b"]).or(z.never()), z.string());
303
+ type d = z.output<typeof d>;
304
+ expectTypeOf<d>().toEqualTypeOf<Record<"a" | "b", string>>();
305
+ });
306
+
307
+ test("z.map", () => {
308
+ const a = z.map(z.string(), z.number());
309
+ type a = z.output<typeof a>;
310
+ expectTypeOf<a>().toEqualTypeOf<Map<string, number>>();
311
+ expect(z.parse(a, new Map([["hello", 123]]))).toEqual(new Map([["hello", 123]]));
312
+ expect(() => z.parse(a, new Map([["hello", "world"]]))).toThrow();
313
+ expect(() => z.parse(a, new Map([[1243, "world"]]))).toThrow();
314
+ expect(() => z.parse(a, "hello")).toThrow();
315
+
316
+ const r1 = z.safeParse(a, new Map([[123, 123]]));
317
+ expect(r1.error?.issues[0].code).toEqual("invalid_type");
318
+ expect(r1.error?.issues[0].path).toEqual([123]);
319
+
320
+ const r2: any = z.safeParse(a, new Map([[BigInt(123), 123]]));
321
+ expect(r2.error!.issues[0].code).toEqual("invalid_key");
322
+ expect(r2.error!.issues[0].path).toEqual([]);
323
+
324
+ const r3: any = z.safeParse(a, new Map([["hello", "world"]]));
325
+ expect(r3.error!.issues[0].code).toEqual("invalid_type");
326
+ expect(r3.error!.issues[0].path).toEqual(["hello"]);
327
+ });
328
+
329
+ test("z.map invalid_element", () => {
330
+ const a = z.map(z.bigint(), z.number());
331
+ const r1 = z.safeParse(a, new Map([[BigInt(123), BigInt(123)]]));
332
+
333
+ expect(r1.error!.issues[0].code).toEqual("invalid_element");
334
+ expect(r1.error!.issues[0].path).toEqual([]);
335
+ });
336
+
337
+ test("z.map async", async () => {
338
+ const a = z.map(z.string().check(z.refine(async () => true)), z.number().check(z.refine(async () => true)));
339
+ const d1 = new Map([["hello", 123]]);
340
+ expect(await z.parseAsync(a, d1)).toEqual(d1);
341
+
342
+ await expect(z.parseAsync(a, new Map([[123, 123]]))).rejects.toThrow();
343
+ await expect(z.parseAsync(a, new Map([["hi", "world"]]))).rejects.toThrow();
344
+ await expect(z.parseAsync(a, new Map([[1243, "world"]]))).rejects.toThrow();
345
+ await expect(z.parseAsync(a, "hello")).rejects.toThrow();
346
+
347
+ const r = await z.safeParseAsync(a, new Map([[123, 123]]));
348
+ expect(r.success).toEqual(false);
349
+ expect(r.error!.issues[0].code).toEqual("invalid_type");
350
+ expect(r.error!.issues[0].path).toEqual([123]);
351
+ });
352
+
353
+ test("z.set", () => {
354
+ const a = z.set(z.string());
355
+ type a = z.output<typeof a>;
356
+ expectTypeOf<a>().toEqualTypeOf<Set<string>>();
357
+ expect(z.parse(a, new Set(["hello", "world"]))).toEqual(new Set(["hello", "world"]));
358
+ expect(() => z.parse(a, new Set([123]))).toThrow();
359
+ expect(() => z.parse(a, ["hello", "world"])).toThrow();
360
+ expect(() => z.parse(a, "hello")).toThrow();
361
+
362
+ const b = z.set(z.number());
363
+ expect(z.parse(b, new Set([1, 2, 3]))).toEqual(new Set([1, 2, 3]));
364
+ expect(() => z.parse(b, new Set(["hello"]))).toThrow();
365
+ expect(() => z.parse(b, [1, 2, 3])).toThrow();
366
+ expect(() => z.parse(b, 123)).toThrow();
367
+ });
368
+
369
+ test("z.enum", () => {
370
+ const a = z.enum(["A", "B", "C"]);
371
+ type a = z.output<typeof a>;
372
+ expectTypeOf<a>().toEqualTypeOf<"A" | "B" | "C">();
373
+ expect(z.parse(a, "A")).toEqual("A");
374
+ expect(z.parse(a, "B")).toEqual("B");
375
+ expect(z.parse(a, "C")).toEqual("C");
376
+ expect(() => z.parse(a, "D")).toThrow();
377
+ expect(() => z.parse(a, 123)).toThrow();
378
+
379
+ expect(a.enum.A).toEqual("A");
380
+ expect(a.enum.B).toEqual("B");
381
+ expect(a.enum.C).toEqual("C");
382
+ expect((a.enum as any).D).toEqual(undefined);
383
+ });
384
+
385
+ test("z.enum - native", () => {
386
+ enum NativeEnum {
387
+ A = "A",
388
+ B = "B",
389
+ C = "C",
390
+ }
391
+ const a = z.enum(NativeEnum);
392
+ type a = z.output<typeof a>;
393
+ expectTypeOf<a>().toEqualTypeOf<NativeEnum>();
394
+ expect(z.parse(a, NativeEnum.A)).toEqual(NativeEnum.A);
395
+ expect(z.parse(a, NativeEnum.B)).toEqual(NativeEnum.B);
396
+ expect(z.parse(a, NativeEnum.C)).toEqual(NativeEnum.C);
397
+ expect(() => z.parse(a, "D")).toThrow();
398
+ expect(() => z.parse(a, 123)).toThrow();
399
+
400
+ // test a.enum
401
+ a;
402
+ expect(a.enum.A).toEqual(NativeEnum.A);
403
+ expect(a.enum.B).toEqual(NativeEnum.B);
404
+ expect(a.enum.C).toEqual(NativeEnum.C);
405
+ });
406
+
407
+ test("z.nativeEnum", () => {
408
+ enum NativeEnum {
409
+ A = "A",
410
+ B = "B",
411
+ C = "C",
412
+ }
413
+ const a = z.nativeEnum(NativeEnum);
414
+ type a = z.output<typeof a>;
415
+ expectTypeOf<a>().toEqualTypeOf<NativeEnum>();
416
+ expect(z.parse(a, NativeEnum.A)).toEqual(NativeEnum.A);
417
+ expect(z.parse(a, NativeEnum.B)).toEqual(NativeEnum.B);
418
+ expect(z.parse(a, NativeEnum.C)).toEqual(NativeEnum.C);
419
+ expect(() => z.parse(a, "D")).toThrow();
420
+ expect(() => z.parse(a, 123)).toThrow();
421
+
422
+ // test a.enum
423
+ a;
424
+ expect(a.enum.A).toEqual(NativeEnum.A);
425
+ expect(a.enum.B).toEqual(NativeEnum.B);
426
+ expect(a.enum.C).toEqual(NativeEnum.C);
427
+ });
428
+
429
+ test("z.literal", () => {
430
+ const a = z.literal("hello");
431
+ type a = z.output<typeof a>;
432
+ expectTypeOf<a>().toEqualTypeOf<"hello">();
433
+ expect(z.parse(a, "hello")).toEqual("hello");
434
+ expect(() => z.parse(a, "world")).toThrow();
435
+ expect(() => z.parse(a, 123)).toThrow();
436
+ });
437
+
438
+ test("z.file", () => {
439
+ const a = z.file();
440
+ const file = new File(["content"], "filename.txt", { type: "text/plain" });
441
+ expect(z.parse(a, file)).toEqual(file);
442
+ expect(() => z.parse(a, "file")).toThrow();
443
+ expect(() => z.parse(a, 123)).toThrow();
444
+ });
445
+
446
+ test("z.transform", () => {
447
+ const a = z.pipe(
448
+ z.string(),
449
+ z.transform((val) => val.toUpperCase())
450
+ );
451
+ type a = z.output<typeof a>;
452
+ expectTypeOf<a>().toEqualTypeOf<string>();
453
+ expect(z.parse(a, "hello")).toEqual("HELLO");
454
+ expect(() => z.parse(a, 123)).toThrow();
455
+ });
456
+
457
+ test("z.transform async", async () => {
458
+ const a = z.pipe(
459
+ z.string(),
460
+ z.transform(async (val) => val.toUpperCase())
461
+ );
462
+ type a = z.output<typeof a>;
463
+ expectTypeOf<a>().toEqualTypeOf<string>();
464
+ expect(await z.parseAsync(a, "hello")).toEqual("HELLO");
465
+ await expect(() => z.parseAsync(a, 123)).rejects.toThrow();
466
+ });
467
+
468
+ test("z.preprocess", () => {
469
+ const a = z.pipe(
470
+ z.transform((val) => String(val).toUpperCase()),
471
+ z.string()
472
+ );
473
+ type a = z.output<typeof a>;
474
+ expectTypeOf<a>().toEqualTypeOf<string>();
475
+ expect(z.parse(a, 123)).toEqual("123");
476
+ expect(z.parse(a, true)).toEqual("TRUE");
477
+ expect(z.parse(a, BigInt(1234))).toEqual("1234");
478
+ // expect(() => z.parse(a, Symbol("asdf"))).toThrow();
479
+ });
480
+
481
+ // test("z.preprocess async", () => {
482
+ // const a = z.preprocess(async (val) => String(val), z.string());
483
+ // type a = z.output<typeof a>;
484
+ // expectTypeOf<a>().toEqualTypeOf<string>();
485
+ // expect(z.parse(a, 123)).toEqual("123");
486
+ // expect(z.parse(a, true)).toEqual("true");
487
+ // expect(() => z.parse(a, {})).toThrow();
488
+ // });
489
+
490
+ test("z.optional", () => {
491
+ const a = z.optional(z.string());
492
+ type a = z.output<typeof a>;
493
+ expectTypeOf<a>().toEqualTypeOf<string | undefined>();
494
+ expect(z.parse(a, "hello")).toEqual("hello");
495
+ expect(z.parse(a, undefined)).toEqual(undefined);
496
+ expect(() => z.parse(a, 123)).toThrow();
497
+ });
498
+
499
+ test("z.nullable", () => {
500
+ const a = z.nullable(z.string());
501
+ type a = z.output<typeof a>;
502
+ expectTypeOf<a>().toEqualTypeOf<string | null>();
503
+ expect(z.parse(a, "hello")).toEqual("hello");
504
+ expect(z.parse(a, null)).toEqual(null);
505
+ expect(() => z.parse(a, 123)).toThrow();
506
+ });
507
+
508
+ test("z.default", () => {
509
+ const a = z._default(z.string(), "default");
510
+ type a = z.output<typeof a>;
511
+ expectTypeOf<a>().toEqualTypeOf<string>();
512
+ expect(z.parse(a, undefined)).toEqual("default");
513
+ expect(z.parse(a, "hello")).toEqual("hello");
514
+ expect(() => z.parse(a, 123)).toThrow();
515
+
516
+ const b = z._default(z.string(), () => "default");
517
+ expect(z.parse(b, undefined)).toEqual("default");
518
+ expect(z.parse(b, "hello")).toEqual("hello");
519
+ expect(() => z.parse(b, 123)).toThrow();
520
+ });
521
+
522
+ test("z.catch", () => {
523
+ const a = z.catch(z.string(), "default");
524
+ type a = z.output<typeof a>;
525
+ expectTypeOf<a>().toEqualTypeOf<string>();
526
+ expect(z.parse(a, "hello")).toEqual("hello");
527
+ expect(z.parse(a, 123)).toEqual("default");
528
+
529
+ const b = z.catch(z.string(), () => "default");
530
+ expect(z.parse(b, "hello")).toEqual("hello");
531
+ expect(z.parse(b, 123)).toEqual("default");
532
+
533
+ const c = z.catch(z.string(), (ctx) => {
534
+ return `${ctx.error.issues.length}issues`;
535
+ });
536
+ expect(z.parse(c, 1234)).toEqual("1issues");
537
+ });
538
+
539
+ test("z.nan", () => {
540
+ const a = z.nan();
541
+ type a = z.output<typeof a>;
542
+ expectTypeOf<a>().toEqualTypeOf<number>();
543
+ expect(z.parse(a, Number.NaN)).toEqual(Number.NaN);
544
+ expect(() => z.parse(a, 123)).toThrow();
545
+ expect(() => z.parse(a, "NaN")).toThrow();
546
+ });
547
+
548
+ test("z.pipe", () => {
549
+ const a = z.pipe(
550
+ z.pipe(
551
+ z.string(),
552
+ z.transform((val) => val.length)
553
+ ),
554
+ z.number()
555
+ );
556
+ type a_in = z.input<typeof a>;
557
+ expectTypeOf<a_in>().toEqualTypeOf<string>();
558
+ type a_out = z.output<typeof a>;
559
+ expectTypeOf<a_out>().toEqualTypeOf<number>();
560
+
561
+ expect(z.parse(a, "123")).toEqual(3);
562
+ expect(z.parse(a, "hello")).toEqual(5);
563
+ expect(() => z.parse(a, 123)).toThrow();
564
+ });
565
+
566
+ test("z.readonly", () => {
567
+ const a = z.readonly(z.string());
568
+ type a = z.output<typeof a>;
569
+ expectTypeOf<a>().toEqualTypeOf<Readonly<string>>();
570
+ expect(z.parse(a, "hello")).toEqual("hello");
571
+ expect(() => z.parse(a, 123)).toThrow();
572
+ });
573
+
574
+ test("z.templateLiteral", () => {
575
+ const a = z.templateLiteral([z.string(), z.number()]);
576
+ type a = z.output<typeof a>;
577
+ expectTypeOf<a>().toEqualTypeOf<`${string}${number}`>();
578
+ expect(z.parse(a, "hello123")).toEqual("hello123");
579
+ expect(() => z.parse(a, "hello")).toThrow();
580
+ expect(() => z.parse(a, 123)).toThrow();
581
+
582
+ // multipart
583
+ const b = z.templateLiteral([z.string(), z.number(), z.string()]);
584
+ type b = z.output<typeof b>;
585
+ expectTypeOf<b>().toEqualTypeOf<`${string}${number}${string}`>();
586
+ expect(z.parse(b, "hello123world")).toEqual("hello123world");
587
+ expect(z.parse(b, "123")).toEqual("123");
588
+ expect(() => z.parse(b, "hello")).toThrow();
589
+ expect(() => z.parse(b, 123)).toThrow();
590
+
591
+ // include boolean
592
+ const c = z.templateLiteral([z.string(), z.boolean()]);
593
+ type c = z.output<typeof c>;
594
+ expectTypeOf<c>().toEqualTypeOf<`${string}${boolean}`>();
595
+ expect(z.parse(c, "hellotrue")).toEqual("hellotrue");
596
+ expect(z.parse(c, "hellofalse")).toEqual("hellofalse");
597
+ expect(() => z.parse(c, "hello")).toThrow();
598
+ expect(() => z.parse(c, 123)).toThrow();
599
+
600
+ // include literal prefix
601
+ const d = z.templateLiteral([z.literal("hello"), z.number()]);
602
+ type d = z.output<typeof d>;
603
+ expectTypeOf<d>().toEqualTypeOf<`hello${number}`>();
604
+ expect(z.parse(d, "hello123")).toEqual("hello123");
605
+ expect(() => z.parse(d, 123)).toThrow();
606
+ expect(() => z.parse(d, "world123")).toThrow();
607
+
608
+ // include literal union
609
+ const e = z.templateLiteral([z.literal(["aa", "bb"]), z.number()]);
610
+ type e = z.output<typeof e>;
611
+ expectTypeOf<e>().toEqualTypeOf<`aa${number}` | `bb${number}`>();
612
+ expect(z.parse(e, "aa123")).toEqual("aa123");
613
+ expect(z.parse(e, "bb123")).toEqual("bb123");
614
+ expect(() => z.parse(e, "cc123")).toThrow();
615
+ expect(() => z.parse(e, 123)).toThrow();
616
+ });
617
+
618
+ // this returns both a schema and a check
619
+ test("z.custom schema", () => {
620
+ const a = z.custom((val) => {
621
+ return typeof val === "string";
622
+ });
623
+ expect(z.parse(a, "hello")).toEqual("hello");
624
+ expect(() => z.parse(a, 123)).toThrow();
625
+ });
626
+
627
+ test("z.custom check", () => {
628
+ // @ts-expect-error Inference not possible, use z.refine()
629
+ z.date().check(z.custom((val) => val.getTime() > 0));
630
+ });
631
+
632
+ test("z.check", () => {
633
+ // this is a more flexible version of z.custom that accepts an arbitrary _parse logic
634
+ // the function should return base.$ZodResult
635
+ const a = z.any().check(
636
+ z.check<string>((ctx) => {
637
+ if (typeof ctx.value === "string") return;
638
+ ctx.issues.push({
639
+ code: "custom",
640
+ origin: "custom",
641
+ message: "Expected a string",
642
+ input: ctx.value,
643
+ });
644
+ })
645
+ );
646
+ expect(z.safeParse(a, "hello")).toMatchObject({
647
+ success: true,
648
+ data: "hello",
649
+ });
650
+ expect(z.safeParse(a, 123)).toMatchObject({
651
+ success: false,
652
+ error: { issues: [{ code: "custom", message: "Expected a string" }] },
653
+ });
654
+ });
655
+
656
+ test("z.instanceof", () => {
657
+ class A {}
658
+
659
+ const a = z.instanceof(A);
660
+ expect(z.parse(a, new A())).toBeInstanceOf(A);
661
+ expect(() => z.parse(a, {})).toThrow();
662
+ });
663
+
664
+ test("z.refine", () => {
665
+ const a = z.number().check(
666
+ z.refine((val) => val > 3),
667
+ z.refine((val) => val < 10)
668
+ );
669
+ expect(z.parse(a, 5)).toEqual(5);
670
+ expect(() => z.parse(a, 2)).toThrow();
671
+ expect(() => z.parse(a, 11)).toThrow();
672
+ expect(() => z.parse(a, "hi")).toThrow();
673
+ });
674
+
675
+ // test("z.superRefine", () => {
676
+ // const a = z.number([
677
+ // z.superRefine((val, ctx) => {
678
+ // if (val < 3) {
679
+ // return ctx.addIssue({
680
+ // code: "custom",
681
+ // origin: "custom",
682
+ // message: "Too small",
683
+ // input: val,
684
+ // });
685
+ // }
686
+ // if (val > 10) {
687
+ // return ctx.addIssue("Too big");
688
+ // }
689
+ // }),
690
+ // ]);
691
+
692
+ // expect(z.parse(a, 5)).toEqual(5);
693
+ // expect(() => z.parse(a, 2)).toThrow();
694
+ // expect(() => z.parse(a, 11)).toThrow();
695
+ // expect(() => z.parse(a, "hi")).toThrow();
696
+ // });
697
+
698
+ test("z.transform", () => {
699
+ const a = z.transform((val: number) => {
700
+ return `${val}`;
701
+ });
702
+ type a_in = z.input<typeof a>;
703
+ expectTypeOf<a_in>().toEqualTypeOf<number>();
704
+ type a_out = z.output<typeof a>;
705
+ expectTypeOf<a_out>().toEqualTypeOf<string>();
706
+ expect(z.parse(a, 123)).toEqual("123");
707
+ });
708
+
709
+ test("z.$brand()", () => {
710
+ const a = z.string().brand<"my-brand">();
711
+ type a = z.output<typeof a>;
712
+ const branded = (_: a) => {};
713
+ // @ts-expect-error
714
+ branded("asdf");
715
+ });
716
+
717
+ test("z.lazy", () => {
718
+ const a = z.lazy(() => z.string());
719
+ type a = z.output<typeof a>;
720
+ expectTypeOf<a>().toEqualTypeOf<string>();
721
+ expect(z.parse(a, "hello")).toEqual("hello");
722
+ expect(() => z.parse(a, 123)).toThrow();
723
+ });
724
+
725
+ // schema that validates JSON-like data
726
+ test("z.json", () => {
727
+ const a = z.json();
728
+ type a = z.output<typeof a>;
729
+ expectTypeOf<a>().toEqualTypeOf<util.JSONType>();
730
+
731
+ expect(z.parse(a, "hello")).toEqual("hello");
732
+ expect(z.parse(a, 123)).toEqual(123);
733
+ expect(z.parse(a, true)).toEqual(true);
734
+ expect(z.parse(a, null)).toEqual(null);
735
+ expect(z.parse(a, {})).toEqual({});
736
+ expect(z.parse(a, { a: "hello" })).toEqual({ a: "hello" });
737
+ expect(z.parse(a, [1, 2, 3])).toEqual([1, 2, 3]);
738
+ expect(z.parse(a, [{ a: "hello" }])).toEqual([{ a: "hello" }]);
739
+
740
+ // fail cases
741
+ expect(() => z.parse(a, new Date())).toThrow();
742
+ expect(() => z.parse(a, Symbol())).toThrow();
743
+ expect(() => z.parse(a, { a: new Date() })).toThrow();
744
+ expect(() => z.parse(a, undefined)).toThrow();
745
+ expect(() => z.parse(a, { a: undefined })).toThrow();
746
+ });
747
+
748
+ // promise
749
+ test("z.promise", async () => {
750
+ const a = z.promise(z.string());
751
+ type a = z.output<typeof a>;
752
+ expectTypeOf<a>().toEqualTypeOf<string>();
753
+
754
+ expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
755
+ success: true,
756
+ data: "hello",
757
+ });
758
+ expect(await z.safeParseAsync(a, Promise.resolve(123))).toMatchObject({
759
+ success: false,
760
+ });
761
+
762
+ const b = z.string();
763
+ expect(() => z.parse(b, Promise.resolve("hello"))).toThrow();
764
+ });
765
+ // test("type assertions", () => {
766
+ // const schema = z.pipe(
767
+ // z.string(),
768
+ // z.transform((val) => val.length)
769
+ // );
770
+ // schema.assertInput<string>();
771
+ // // @ts-expect-error
772
+ // schema.assertInput<number>();
773
+
774
+ // schema.assertOutput<number>();
775
+ // // @ts-expect-error
776
+ // schema.assertOutput<string>();
777
+ // });
778
+
779
+ test("isPlainObject", () => {
780
+ expect(z.core.util.isPlainObject({})).toEqual(true);
781
+ expect(z.core.util.isPlainObject(Object.create(null))).toEqual(true);
782
+ expect(z.core.util.isPlainObject([])).toEqual(false);
783
+ expect(z.core.util.isPlainObject(new Date())).toEqual(false);
784
+ expect(z.core.util.isPlainObject(null)).toEqual(false);
785
+ expect(z.core.util.isPlainObject(undefined)).toEqual(false);
786
+ expect(z.core.util.isPlainObject("string")).toEqual(false);
787
+ expect(z.core.util.isPlainObject(123)).toEqual(false);
788
+ expect(z.core.util.isPlainObject(Symbol())).toEqual(false);
789
+ });
790
+
791
+ test("def typing", () => {
792
+ z.string().def.type satisfies "string";
793
+ z.number().def.type satisfies "number";
794
+ z.bigint().def.type satisfies "bigint";
795
+ z.boolean().def.type satisfies "boolean";
796
+ z.date().def.type satisfies "date";
797
+ z.symbol().def.type satisfies "symbol";
798
+ z.undefined().def.type satisfies "undefined";
799
+ z.string().nullable().def.type satisfies "nullable";
800
+ z.null().def.type satisfies "null";
801
+ z.any().def.type satisfies "any";
802
+ z.unknown().def.type satisfies "unknown";
803
+ z.never().def.type satisfies "never";
804
+ z.void().def.type satisfies "void";
805
+ z.array(z.string()).def.type satisfies "array";
806
+ z.object({ key: z.string() }).def.type satisfies "object";
807
+ z.union([z.string(), z.number()]).def.type satisfies "union";
808
+ z.intersection(z.string(), z.number()).def.type satisfies "intersection";
809
+ z.tuple([z.string(), z.number()]).def.type satisfies "tuple";
810
+ z.record(z.string(), z.number()).def.type satisfies "record";
811
+ z.map(z.string(), z.number()).def.type satisfies "map";
812
+ z.set(z.string()).def.type satisfies "set";
813
+ z.literal("example").def.type satisfies "literal";
814
+ z.enum(["a", "b", "c"]).def.type satisfies "enum";
815
+ z.promise(z.string()).def.type satisfies "promise";
816
+ z.lazy(() => z.string()).def.type satisfies "lazy";
817
+ z.string().optional().def.type satisfies "optional";
818
+ z.string().default("default").def.type satisfies "default";
819
+ z.templateLiteral([z.literal("a"), z.literal("b")]).def.type satisfies "template_literal";
820
+ z.custom<string>((val) => typeof val === "string").def.type satisfies "custom";
821
+ z.transform((val) => val as string).def.type satisfies "transform";
822
+ z.string().optional().nonoptional().def.type satisfies "nonoptional";
823
+ z.object({ key: z.string() }).readonly().def.type satisfies "readonly";
824
+ z.nan().def.type satisfies "nan";
825
+ z.unknown().pipe(z.number()).def.type satisfies "pipe";
826
+ z.success(z.string()).def.type satisfies "success";
827
+ z.string().catch("fallback").def.type satisfies "catch";
828
+ z.file().def.type satisfies "file";
829
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/instanceof.test.ts ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("instanceof", async () => {
5
+ class Test {}
6
+ class Subtest extends Test {}
7
+ abstract class AbstractBar {
8
+ constructor(public val: string) {}
9
+ }
10
+ class Bar extends AbstractBar {}
11
+
12
+ const TestSchema = z.instanceof(Test);
13
+ const SubtestSchema = z.instanceof(Subtest);
14
+ const AbstractSchema = z.instanceof(AbstractBar);
15
+ const BarSchema = z.instanceof(Bar);
16
+
17
+ TestSchema.parse(new Test());
18
+ TestSchema.parse(new Subtest());
19
+ SubtestSchema.parse(new Subtest());
20
+ AbstractSchema.parse(new Bar("asdf"));
21
+ const bar = BarSchema.parse(new Bar("asdf"));
22
+ expect(bar.val).toEqual("asdf");
23
+
24
+ await expect(() => SubtestSchema.parse(new Test())).toThrow();
25
+ await expect(() => TestSchema.parse(12)).toThrow();
26
+
27
+ expectTypeOf<Test>().toEqualTypeOf<z.infer<typeof TestSchema>>();
28
+ });
29
+
30
+ test("instanceof fatal", () => {
31
+ const schema = z.instanceof(Date).refine((d) => d.toString());
32
+ const res = schema.safeParse(null);
33
+ expect(res.success).toBe(false);
34
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/intersection.test.ts ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import type { util } from "zod/v4/core";
3
+
4
+ import * as z from "zod/v4";
5
+
6
+ test("object intersection", () => {
7
+ const A = z.object({ a: z.string() });
8
+ const B = z.object({ b: z.string() });
9
+
10
+ const C = z.intersection(A, B); // BaseC.merge(HasID);
11
+ type C = z.infer<typeof C>;
12
+ expectTypeOf<C>().toEqualTypeOf<{ a: string } & { b: string }>();
13
+ const data = { a: "foo", b: "foo" };
14
+ expect(C.parse(data)).toEqual(data);
15
+ expect(() => C.parse({ a: "foo" })).toThrow();
16
+ });
17
+
18
+ test("object intersection: loose", () => {
19
+ const A = z.looseObject({ a: z.string() });
20
+ const B = z.object({ b: z.string() });
21
+
22
+ const C = z.intersection(A, B); // BaseC.merge(HasID);
23
+ type C = z.infer<typeof C>;
24
+ expectTypeOf<C>().toEqualTypeOf<{ a: string; [x: string]: unknown } & { b: string }>();
25
+ const data = { a: "foo", b: "foo", c: "extra" };
26
+ expect(C.parse(data)).toEqual(data);
27
+ expect(() => C.parse({ a: "foo" })).toThrow();
28
+ });
29
+
30
+ test("object intersection: strict", () => {
31
+ const A = z.strictObject({ a: z.string() });
32
+ const B = z.object({ b: z.string() });
33
+
34
+ const C = z.intersection(A, B); // BaseC.merge(HasID);
35
+ type C = z.infer<typeof C>;
36
+ expectTypeOf<C>().toEqualTypeOf<{ a: string } & { b: string }>();
37
+ const data = { a: "foo", b: "foo", c: "extra" };
38
+
39
+ const result = C.safeParse(data);
40
+ expect(result.success).toEqual(false);
41
+ });
42
+
43
+ test("deep intersection", () => {
44
+ const Animal = z.object({
45
+ properties: z.object({
46
+ is_animal: z.boolean(),
47
+ }),
48
+ });
49
+ const Cat = z.intersection(
50
+ z.object({
51
+ properties: z.object({
52
+ jumped: z.boolean(),
53
+ }),
54
+ }),
55
+ Animal
56
+ );
57
+
58
+ type Cat = util.Flatten<z.infer<typeof Cat>>;
59
+ expectTypeOf<Cat>().toEqualTypeOf<{ properties: { is_animal: boolean } & { jumped: boolean } }>();
60
+ const a = Cat.safeParse({ properties: { is_animal: true, jumped: true } });
61
+ expect(a.data!.properties).toEqual({ is_animal: true, jumped: true });
62
+ });
63
+
64
+ test("deep intersection of arrays", async () => {
65
+ const Author = z.object({
66
+ posts: z.array(
67
+ z.object({
68
+ post_id: z.number(),
69
+ })
70
+ ),
71
+ });
72
+ const Registry = z.intersection(
73
+ Author,
74
+ z.object({
75
+ posts: z.array(
76
+ z.object({
77
+ title: z.string(),
78
+ })
79
+ ),
80
+ })
81
+ );
82
+
83
+ const posts = [
84
+ { post_id: 1, title: "Novels" },
85
+ { post_id: 2, title: "Fairy tales" },
86
+ ];
87
+ const cat = Registry.parse({ posts });
88
+ expect(cat.posts).toEqual(posts);
89
+ const asyncCat = await Registry.parseAsync({ posts });
90
+ expect(asyncCat.posts).toEqual(posts);
91
+ });
92
+
93
+ test("invalid intersection types", async () => {
94
+ const numberIntersection = z.intersection(
95
+ z.number(),
96
+ z.number().transform((x) => x + 1)
97
+ );
98
+
99
+ expect(() => {
100
+ numberIntersection.parse(1234);
101
+ }).toThrowErrorMatchingInlineSnapshot(`[Error: Unmergable intersection. Error path: []]`);
102
+ });
103
+
104
+ test("invalid array merge (incompatible lengths)", async () => {
105
+ const stringArrInt = z.intersection(
106
+ z.string().array(),
107
+ z
108
+ .string()
109
+ .array()
110
+ .transform((val) => [...val, "asdf"])
111
+ );
112
+
113
+ expect(() => stringArrInt.safeParse(["asdf", "qwer"])).toThrowErrorMatchingInlineSnapshot(
114
+ `[Error: Unmergable intersection. Error path: []]`
115
+ );
116
+ });
117
+
118
+ test("invalid array merge (incompatible elements)", async () => {
119
+ const stringArrInt = z.intersection(
120
+ z.string().array(),
121
+ z
122
+ .string()
123
+ .array()
124
+ .transform((val) => [...val.slice(0, -1), "asdf"])
125
+ );
126
+
127
+ expect(() => stringArrInt.safeParse(["asdf", "qwer"])).toThrowErrorMatchingInlineSnapshot(
128
+ `[Error: Unmergable intersection. Error path: [1]]`
129
+ );
130
+ });
131
+
132
+ test("invalid object merge", async () => {
133
+ const Cat = z.object({
134
+ phrase: z.string().transform((val) => `${val} Meow`),
135
+ });
136
+ const Dog = z.object({
137
+ phrase: z.string().transform((val) => `${val} Woof`),
138
+ });
139
+ const CatDog = z.intersection(Cat, Dog);
140
+
141
+ expect(() => CatDog.parse({ phrase: "Hello, my name is CatDog." })).toThrowErrorMatchingInlineSnapshot(
142
+ `[Error: Unmergable intersection. Error path: ["phrase"]]`
143
+ );
144
+ });
145
+
146
+ test("invalid deep merge of object and array combination", async () => {
147
+ const University = z.object({
148
+ students: z.array(
149
+ z.object({
150
+ name: z.string().transform((val) => `Student name: ${val}`),
151
+ })
152
+ ),
153
+ });
154
+ const Registry = z.intersection(
155
+ University,
156
+ z.object({
157
+ students: z.array(
158
+ z.object({
159
+ name: z.string(),
160
+ surname: z.string(),
161
+ })
162
+ ),
163
+ })
164
+ );
165
+
166
+ const students = [{ name: "John", surname: "Doe" }];
167
+
168
+ expect(() => Registry.parse({ students })).toThrowErrorMatchingInlineSnapshot(
169
+ `[Error: Unmergable intersection. Error path: ["students",0,"name"]]`
170
+ );
171
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/json.test.ts ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { test } from "vitest";
2
+ // import * as z from "zod/v4";
3
+
4
+ test(() => {});
5
+ // test("overload types", () => {
6
+ // const schema = z.string().json();
7
+ // util.assertEqual<typeof schema, z.ZodString>(true);
8
+ // const schema2 = z.string().json(z.number());
9
+ // util.assertEqual<typeof schema2, z.ZodPipe<z.ZodTransform<any, string>, z.ZodNumber>>(true);
10
+ // const r2 = schema2.parse("12");
11
+ // util.assertEqual<number, typeof r2>(true);
12
+ // });
13
+ // test("parse string to json", async () => {
14
+ // const Env = z.object({
15
+ // myJsonConfig: z.string().jsonString(z.object({ foo: z.number() })),
16
+ // someOtherValue: z.string(),
17
+ // });
18
+
19
+ // expect(
20
+ // Env.parse({
21
+ // myJsonConfig: '{ "foo": 123 }',
22
+ // someOtherValue: "abc",
23
+ // })
24
+ // ).toEqual({
25
+ // myJsonConfig: { foo: 123 },
26
+ // someOtherValue: "abc",
27
+ // });
28
+
29
+ // const invalidValues = Env.safeParse({
30
+ // myJsonConfig: '{"foo": "not a number!"}',
31
+ // someOtherValue: null,
32
+ // });
33
+ // expect(JSON.parse(JSON.stringify(invalidValues))).toEqual({
34
+ // success: false,
35
+ // error: {
36
+ // name: "ZodError",
37
+ // issues: [
38
+ // {
39
+ // code: "invalid_type",
40
+ // expected: "number",
41
+ // input: "not a number!",
42
+ // received: "string",
43
+ // path: ["myJsonConfig", "foo"],
44
+ // message: "Expected number, received string",
45
+ // },
46
+ // {
47
+ // code: "invalid_type",
48
+ // expected: "string",
49
+ // input: null,
50
+ // received: "null",
51
+ // path: ["someOtherValue"],
52
+ // message: "Expected string, received null",
53
+ // },
54
+ // ],
55
+ // },
56
+ // });
57
+
58
+ // const invalidJsonSyntax = Env.safeParse({
59
+ // myJsonConfig: "This is not valid json",
60
+ // someOtherValue: null,
61
+ // });
62
+ // expect(JSON.parse(JSON.stringify(invalidJsonSyntax))).toMatchObject({
63
+ // success: false,
64
+ // error: {
65
+ // name: "ZodError",
66
+ // issues: [
67
+ // {
68
+ // code: "invalid_string",
69
+ // input: {
70
+ // _def: {
71
+ // catchall: {
72
+ // _def: {
73
+ // typeName: "ZodNever",
74
+ // },
75
+ // },
76
+ // typeName: "ZodObject",
77
+ // unknownKeys: "strip",
78
+ // },
79
+ // },
80
+ // validation: "json",
81
+ // message: "Invalid json",
82
+ // path: ["myJsonConfig"],
83
+ // },
84
+ // {
85
+ // code: "invalid_type",
86
+ // expected: "string",
87
+ // input: null,
88
+ // received: "null",
89
+ // path: ["someOtherValue"],
90
+ // message: "Expected string, received null",
91
+ // },
92
+ // ],
93
+ // },
94
+ // });
95
+ // });
96
+
97
+ // test("no argument", () => {
98
+ // const schema = z.string().json();
99
+ // util.assertEqual<typeof schema, z.ZodString>(true);
100
+ // z.string().json().parse(`{}`);
101
+ // z.string().json().parse(`null`);
102
+ // z.string().json().parse(`12`);
103
+ // z.string().json().parse(`{ "test": "test"}`);
104
+ // expect(() => z.string().json().parse(`asdf`)).toThrow();
105
+ // expect(() => z.string().json().parse(`{ "test": undefined }`)).toThrow();
106
+ // expect(() => z.string().json().parse(`{ "test": 12n }`)).toThrow();
107
+ // expect(() => z.string().json().parse(`{ test: "test" }`)).toThrow();
108
+ // });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/lazy.test.ts ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("opt passthrough", () => {
6
+ const object = z.object({
7
+ a: z.lazy(() => z.string()),
8
+ b: z.lazy(() => z.string().optional()),
9
+ c: z.lazy(() => z.string().default("default")),
10
+ });
11
+
12
+ type ObjectTypeIn = z.input<typeof object>;
13
+ expectTypeOf<ObjectTypeIn>().toEqualTypeOf<{
14
+ a: string;
15
+ b?: string | undefined;
16
+ c?: string | undefined;
17
+ }>();
18
+
19
+ type ObjectTypeOut = z.output<typeof object>;
20
+ expectTypeOf<ObjectTypeOut>().toEqualTypeOf<{
21
+ a: string;
22
+ b?: string | undefined;
23
+ c: string;
24
+ }>();
25
+
26
+ const result = object.parse(
27
+ {
28
+ a: "hello",
29
+ b: undefined,
30
+ },
31
+ { jitless: true }
32
+ );
33
+ expect(result).toEqual({
34
+ a: "hello",
35
+ // b: undefined,
36
+ c: "default",
37
+ });
38
+
39
+ expect(z.lazy(() => z.string())._zod.optin).toEqual(undefined);
40
+ expect(z.lazy(() => z.string())._zod.optout).toEqual(undefined);
41
+
42
+ expect(z.lazy(() => z.string().optional())._zod.optin).toEqual("optional");
43
+ expect(z.lazy(() => z.string().optional())._zod.optout).toEqual("optional");
44
+
45
+ expect(z.lazy(() => z.string().default("asdf"))._zod.optin).toEqual("optional");
46
+ expect(z.lazy(() => z.string().default("asdf"))._zod.optout).toEqual(undefined);
47
+ });
48
+
49
+ ////////////// LAZY //////////////
50
+
51
+ test("schema getter", () => {
52
+ z.lazy(() => z.string()).parse("asdf");
53
+ });
54
+
55
+ test("lazy proxy", () => {
56
+ const schema = z.lazy(() => z.string())._zod.innerType.min(6);
57
+ schema.parse("123456");
58
+ expect(schema.safeParse("12345").success).toBe(false);
59
+ });
60
+
61
+ interface Category {
62
+ name: string;
63
+ subcategories: Category[];
64
+ }
65
+
66
+ const testCategory: Category = {
67
+ name: "I",
68
+ subcategories: [
69
+ {
70
+ name: "A",
71
+ subcategories: [
72
+ {
73
+ name: "1",
74
+ subcategories: [
75
+ {
76
+ name: "a",
77
+ subcategories: [],
78
+ },
79
+ ],
80
+ },
81
+ ],
82
+ },
83
+ ],
84
+ };
85
+
86
+ test("recursion with z.lazy", () => {
87
+ const Category: z.ZodType<Category> = z.lazy(() =>
88
+ z.object({
89
+ name: z.string(),
90
+ subcategories: z.array(Category),
91
+ })
92
+ );
93
+ Category.parse(testCategory);
94
+ });
95
+
96
+ type LinkedList = null | { value: number; next: LinkedList };
97
+
98
+ const linkedListExample = {
99
+ value: 1,
100
+ next: {
101
+ value: 2,
102
+ next: {
103
+ value: 3,
104
+ next: {
105
+ value: 4,
106
+ next: null,
107
+ },
108
+ },
109
+ },
110
+ };
111
+
112
+ test("recursive union wit z.lazy", () => {
113
+ const LinkedListSchema: z.ZodType<LinkedList> = z.lazy(() =>
114
+ z.union([
115
+ z.null(),
116
+ z.object({
117
+ value: z.number(),
118
+ next: LinkedListSchema,
119
+ }),
120
+ ])
121
+ );
122
+ LinkedListSchema.parse(linkedListExample);
123
+ });
124
+
125
+ interface A {
126
+ val: number;
127
+ b: B;
128
+ }
129
+
130
+ interface B {
131
+ val: number;
132
+ a?: A | undefined;
133
+ }
134
+
135
+ test("mutual recursion with lazy", () => {
136
+ const Alazy: z.ZodType<A> = z.lazy(() =>
137
+ z.object({
138
+ val: z.number(),
139
+ b: Blazy,
140
+ })
141
+ );
142
+
143
+ const Blazy: z.ZodType<B> = z.lazy(() =>
144
+ z.object({
145
+ val: z.number(),
146
+ a: Alazy.optional(),
147
+ })
148
+ );
149
+
150
+ const testData = {
151
+ val: 1,
152
+ b: {
153
+ val: 5,
154
+ a: {
155
+ val: 3,
156
+ b: {
157
+ val: 4,
158
+ a: {
159
+ val: 2,
160
+ b: {
161
+ val: 1,
162
+ },
163
+ },
164
+ },
165
+ },
166
+ },
167
+ };
168
+
169
+ Alazy.parse(testData);
170
+ Blazy.parse(testData.b);
171
+
172
+ expect(() => Alazy.parse({ val: "asdf" })).toThrow();
173
+ });
174
+
175
+ // TODO
176
+ test("mutual recursion with cyclical data", () => {
177
+ const a: any = { val: 1 };
178
+ const b: any = { val: 2 };
179
+ a.b = b;
180
+ b.a = a;
181
+ });
182
+
183
+ test("complicated self-recursion", () => {
184
+ const Category = z.object({
185
+ name: z.string(),
186
+ age: z.optional(z.number()),
187
+ get nullself() {
188
+ return Category.nullable();
189
+ },
190
+ get optself() {
191
+ return Category.optional();
192
+ },
193
+ get self() {
194
+ return Category;
195
+ },
196
+ get subcategories() {
197
+ return z.array(Category);
198
+ },
199
+ nested: z.object({
200
+ get sub() {
201
+ return Category;
202
+ },
203
+ }),
204
+ });
205
+
206
+ type _Category = z.output<typeof Category>;
207
+ });
208
+
209
+ test("lazy initialization", () => {
210
+ const a: any = z.lazy(() => a).optional();
211
+ const b: any = z.lazy(() => b).nullable();
212
+ const c: any = z.lazy(() => c).default({} as any);
213
+ const d: any = z.lazy(() => d).prefault({} as any);
214
+ const e: any = z.lazy(() => e).nonoptional();
215
+ const f: any = z.lazy(() => f).catch({} as any);
216
+ const g: any = z.lazy(() => z.object({ g })).readonly();
217
+
218
+ const baseCategorySchema = z.object({
219
+ name: z.string(),
220
+ });
221
+ type Category = z.infer<typeof baseCategorySchema> & {
222
+ subcategories: Category[];
223
+ };
224
+ const categorySchema: z.ZodType<Category> = baseCategorySchema.extend({
225
+ subcategories: z.lazy(() => categorySchema.array()),
226
+ });
227
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/literal.test.ts ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ const literalTuna = z.literal("tuna");
6
+ const literalTunaCustomMessage = z.literal("tuna", {
7
+ message: "That's not a tuna",
8
+ });
9
+ const literalFortyTwo = z.literal(42);
10
+ const literalTrue = z.literal(true);
11
+
12
+ test("passing validations", () => {
13
+ literalTuna.parse("tuna");
14
+ literalFortyTwo.parse(42);
15
+ literalTrue.parse(true);
16
+ });
17
+
18
+ test("failing validations", () => {
19
+ expect(() => literalTuna.parse("shark")).toThrow();
20
+ expect(() => literalFortyTwo.parse(43)).toThrow();
21
+ expect(() => literalTrue.parse(false)).toThrow();
22
+ });
23
+
24
+ test("invalid_literal should have `input` field with data", () => {
25
+ const data = "shark";
26
+ const result = literalTuna.safeParse(data);
27
+
28
+ const issue = result.error!.issues[0];
29
+ expect(issue.code).toBe("invalid_value");
30
+ expect(issue).toMatchInlineSnapshot(`
31
+ {
32
+ "code": "invalid_value",
33
+ "message": "Invalid input: expected "tuna"",
34
+ "path": [],
35
+ "values": [
36
+ "tuna",
37
+ ],
38
+ }
39
+ `);
40
+ });
41
+
42
+ test("invalid_literal should return default message", () => {
43
+ const data = "shark";
44
+ const result = literalTuna.safeParse(data);
45
+
46
+ const issue = result.error!.issues[0];
47
+ expect(issue.message).toEqual(`Invalid input: expected \"tuna\"`);
48
+ });
49
+
50
+ test("invalid_literal should return custom message", () => {
51
+ const data = "shark";
52
+ const result = literalTunaCustomMessage.safeParse(data);
53
+
54
+ const issue = result.error!.issues[0];
55
+ expect(issue.message).toEqual(`That's not a tuna`);
56
+ });
57
+
58
+ test("literal default error message", () => {
59
+ const result = z.literal("Tuna").safeParse("Trout");
60
+ expect(result.success).toEqual(false);
61
+ expect(result.error!.issues.length).toEqual(1);
62
+ expect(result.error).toMatchInlineSnapshot(`
63
+ [ZodError: [
64
+ {
65
+ "code": "invalid_value",
66
+ "values": [
67
+ "Tuna"
68
+ ],
69
+ "path": [],
70
+ "message": "Invalid input: expected \\"Tuna\\""
71
+ }
72
+ ]]
73
+ `);
74
+ });
75
+
76
+ test("literal bigint default error message", () => {
77
+ const result = z.literal(BigInt(12)).safeParse(BigInt(13));
78
+ expect(result.success).toBe(false);
79
+
80
+ expect(result.error!.issues.length).toEqual(1);
81
+ expect(result.error!.issues[0].message).toEqual(`Invalid input: expected 12n`);
82
+ });
83
+
84
+ test(".value getter", () => {
85
+ expect(z.literal("tuna").value).toEqual("tuna");
86
+ expect(() => z.literal([1, 2, 3]).value).toThrow();
87
+ });
88
+
89
+ test("readonly", () => {
90
+ const a = ["asdf"] as const;
91
+ z.literal(a);
92
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/map.test.ts ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ const stringMap = z.map(z.string(), z.string());
5
+ type stringMap = z.infer<typeof stringMap>;
6
+
7
+ test("type inference", () => {
8
+ expectTypeOf<stringMap>().toEqualTypeOf<Map<string, string>>();
9
+ });
10
+
11
+ test("valid parse", () => {
12
+ const result = stringMap.safeParse(
13
+ new Map([
14
+ ["first", "foo"],
15
+ ["second", "bar"],
16
+ ])
17
+ );
18
+ expect(result.success).toEqual(true);
19
+ expect(result.data).toMatchInlineSnapshot(`
20
+ Map {
21
+ "first" => "foo",
22
+ "second" => "bar",
23
+ }
24
+ `);
25
+ });
26
+
27
+ test("valid parse async", async () => {
28
+ const asyncMap = z.map(
29
+ z.string().refine(async () => false, "bad key"),
30
+ z.string().refine(async () => false, "bad value")
31
+ );
32
+ const result = await asyncMap.safeParseAsync(new Map([["first", "foo"]]));
33
+ expect(result.success).toEqual(false);
34
+ expect(result.error).toMatchInlineSnapshot(`
35
+ [ZodError: [
36
+ {
37
+ "code": "custom",
38
+ "path": [
39
+ "first"
40
+ ],
41
+ "message": "bad key"
42
+ },
43
+ {
44
+ "code": "custom",
45
+ "path": [
46
+ "first"
47
+ ],
48
+ "message": "bad value"
49
+ }
50
+ ]]
51
+ `);
52
+ });
53
+
54
+ test("throws when a Set is given", () => {
55
+ const result = stringMap.safeParse(new Set([]));
56
+ expect(result.success).toEqual(false);
57
+ if (result.success === false) {
58
+ expect(result.error.issues.length).toEqual(1);
59
+ expect(result.error.issues[0].code).toEqual("invalid_type");
60
+ }
61
+ });
62
+
63
+ test("throws when the given map has invalid key and invalid input", () => {
64
+ const result = stringMap.safeParse(new Map([[42, Symbol()]]));
65
+ expect(result.success).toEqual(false);
66
+ if (result.success === false) {
67
+ expect(result.error.issues.length).toEqual(2);
68
+ expect(result.error).toMatchInlineSnapshot(`
69
+ [ZodError: [
70
+ {
71
+ "expected": "string",
72
+ "code": "invalid_type",
73
+ "path": [
74
+ 42
75
+ ],
76
+ "message": "Invalid input: expected string, received number"
77
+ },
78
+ {
79
+ "expected": "string",
80
+ "code": "invalid_type",
81
+ "path": [
82
+ 42
83
+ ],
84
+ "message": "Invalid input: expected string, received symbol"
85
+ }
86
+ ]]
87
+ `);
88
+ }
89
+ });
90
+
91
+ test("throws when the given map has multiple invalid entries", () => {
92
+ // const result = stringMap.safeParse(new Map([[42, Symbol()]]));
93
+
94
+ const result = stringMap.safeParse(
95
+ new Map([
96
+ [1, "foo"],
97
+ ["bar", 2],
98
+ ] as [any, any][]) as Map<any, any>
99
+ );
100
+
101
+ // const result = stringMap.safeParse(new Map([[42, Symbol()]]));
102
+ expect(result.success).toEqual(false);
103
+ if (result.success === false) {
104
+ expect(result.error.issues.length).toEqual(2);
105
+ expect(result.error.issues).toMatchInlineSnapshot(`
106
+ [
107
+ {
108
+ "code": "invalid_type",
109
+ "expected": "string",
110
+ "message": "Invalid input: expected string, received number",
111
+ "path": [
112
+ 1,
113
+ ],
114
+ },
115
+ {
116
+ "code": "invalid_type",
117
+ "expected": "string",
118
+ "message": "Invalid input: expected string, received number",
119
+ "path": [
120
+ "bar",
121
+ ],
122
+ },
123
+ ]
124
+ `);
125
+ }
126
+ });
127
+
128
+ test("dirty", async () => {
129
+ const map = z.map(
130
+ z.string().refine((val) => val === val.toUpperCase(), {
131
+ message: "Keys must be uppercase",
132
+ }),
133
+ z.string()
134
+ );
135
+ const result = await map.spa(
136
+ new Map([
137
+ ["first", "foo"],
138
+ ["second", "bar"],
139
+ ])
140
+ );
141
+ expect(result.success).toEqual(false);
142
+ if (!result.success) {
143
+ expect(result.error.issues.length).toEqual(2);
144
+ expect(result.error).toMatchInlineSnapshot(`
145
+ [ZodError: [
146
+ {
147
+ "code": "custom",
148
+ "path": [
149
+ "first"
150
+ ],
151
+ "message": "Keys must be uppercase"
152
+ },
153
+ {
154
+ "code": "custom",
155
+ "path": [
156
+ "second"
157
+ ],
158
+ "message": "Keys must be uppercase"
159
+ }
160
+ ]]
161
+ `);
162
+ }
163
+ });
164
+
165
+ test("map with object keys", () => {
166
+ const map = z.map(
167
+ z.object({
168
+ name: z.string(),
169
+ age: z.number(),
170
+ }),
171
+ z.string()
172
+ );
173
+ const data = new Map([
174
+ [{ name: "John", age: 30 }, "foo"],
175
+ [{ name: "Jane", age: 25 }, "bar"],
176
+ ]);
177
+ const result = map.safeParse(data);
178
+ expect(result.success).toEqual(true);
179
+ expect(result.data!).toEqual(data);
180
+
181
+ const badData = new Map([["bad", "foo"]]);
182
+ const badResult = map.safeParse(badData);
183
+ expect(badResult.success).toEqual(false);
184
+ expect(badResult.error).toMatchInlineSnapshot(`
185
+ [ZodError: [
186
+ {
187
+ "expected": "object",
188
+ "code": "invalid_type",
189
+ "path": [
190
+ "bad"
191
+ ],
192
+ "message": "Invalid input: expected object, received string"
193
+ }
194
+ ]]
195
+ `);
196
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nan.test.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ const schema = z.nan();
6
+
7
+ test("passing validations", () => {
8
+ schema.parse(Number.NaN);
9
+ schema.parse(Number("Not a number"));
10
+ expectTypeOf<typeof schema._output>().toEqualTypeOf<number>();
11
+ });
12
+
13
+ test("failing validations", () => {
14
+ expect(() => schema.parse(5)).toThrow();
15
+ expect(() => schema.parse("John")).toThrow();
16
+ expect(() => schema.parse(true)).toThrow();
17
+ expect(() => schema.parse(null)).toThrow();
18
+ expect(() => schema.parse(undefined)).toThrow();
19
+ expect(() => schema.parse({})).toThrow();
20
+ expect(() => schema.parse([])).toThrow();
21
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("nested refinements", () => {
5
+ const zodSchema = z
6
+ .object({
7
+ password: z.string().min(1),
8
+ nested: z
9
+ .object({
10
+ confirm: z
11
+ .string()
12
+ .min(1)
13
+ .refine((value) => value.length > 2, {
14
+ message: "Confirm length should be > 2",
15
+ }),
16
+ })
17
+ .refine(
18
+ (data) => {
19
+ return data.confirm === "bar";
20
+ },
21
+ {
22
+ path: ["confirm"],
23
+ error: 'Value must be "bar"',
24
+ }
25
+ ),
26
+ })
27
+ .refine(
28
+ (data) => {
29
+ return data.nested.confirm === data.password;
30
+ },
31
+ {
32
+ path: ["nested", "confirm"],
33
+ error: "Password and confirm must match",
34
+ }
35
+ );
36
+
37
+ const DATA = {
38
+ password: "bar",
39
+ nested: { confirm: "" },
40
+ };
41
+ expect(zodSchema.safeParse(DATA)).toMatchInlineSnapshot(`
42
+ {
43
+ "error": [ZodError: [
44
+ {
45
+ "origin": "string",
46
+ "code": "too_small",
47
+ "minimum": 1,
48
+ "inclusive": true,
49
+ "path": [
50
+ "nested",
51
+ "confirm"
52
+ ],
53
+ "message": "Too small: expected string to have >=1 characters"
54
+ },
55
+ {
56
+ "code": "custom",
57
+ "path": [
58
+ "nested",
59
+ "confirm"
60
+ ],
61
+ "message": "Confirm length should be > 2"
62
+ },
63
+ {
64
+ "code": "custom",
65
+ "path": [
66
+ "nested",
67
+ "confirm"
68
+ ],
69
+ "message": "Value must be \\"bar\\""
70
+ },
71
+ {
72
+ "code": "custom",
73
+ "path": [
74
+ "nested",
75
+ "confirm"
76
+ ],
77
+ "message": "Password and confirm must match"
78
+ }
79
+ ]],
80
+ "success": false,
81
+ }
82
+ `);
83
+
84
+ expect(zodSchema.safeParse(DATA, { jitless: true })).toMatchInlineSnapshot(`
85
+ {
86
+ "error": [ZodError: [
87
+ {
88
+ "origin": "string",
89
+ "code": "too_small",
90
+ "minimum": 1,
91
+ "inclusive": true,
92
+ "path": [
93
+ "nested",
94
+ "confirm"
95
+ ],
96
+ "message": "Too small: expected string to have >=1 characters"
97
+ },
98
+ {
99
+ "code": "custom",
100
+ "path": [
101
+ "nested",
102
+ "confirm"
103
+ ],
104
+ "message": "Confirm length should be > 2"
105
+ },
106
+ {
107
+ "code": "custom",
108
+ "path": [
109
+ "nested",
110
+ "confirm"
111
+ ],
112
+ "message": "Value must be \\"bar\\""
113
+ },
114
+ {
115
+ "code": "custom",
116
+ "path": [
117
+ "nested",
118
+ "confirm"
119
+ ],
120
+ "message": "Password and confirm must match"
121
+ }
122
+ ]],
123
+ "success": false,
124
+ }
125
+ `);
126
+
127
+ expect(zodSchema["~standard"].validate(DATA)).toMatchInlineSnapshot(`
128
+ {
129
+ "issues": [
130
+ {
131
+ "code": "too_small",
132
+ "inclusive": true,
133
+ "message": "Too small: expected string to have >=1 characters",
134
+ "minimum": 1,
135
+ "origin": "string",
136
+ "path": [
137
+ "nested",
138
+ "confirm",
139
+ ],
140
+ },
141
+ {
142
+ "code": "custom",
143
+ "message": "Confirm length should be > 2",
144
+ "path": [
145
+ "nested",
146
+ "confirm",
147
+ ],
148
+ },
149
+ {
150
+ "code": "custom",
151
+ "message": "Value must be "bar"",
152
+ "path": [
153
+ "nested",
154
+ "confirm",
155
+ ],
156
+ },
157
+ {
158
+ "code": "custom",
159
+ "message": "Password and confirm must match",
160
+ "path": [
161
+ "nested",
162
+ "confirm",
163
+ ],
164
+ },
165
+ ],
166
+ }
167
+ `);
168
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import { z } from "zod/v4";
3
+
4
+ test("nonoptional", () => {
5
+ const schema = z.string().nonoptional();
6
+ expectTypeOf<typeof schema._input>().toEqualTypeOf<string>();
7
+ expectTypeOf<typeof schema._output>().toEqualTypeOf<string>();
8
+
9
+ const result = schema.safeParse(undefined);
10
+ expect(result.success).toBe(false);
11
+ expect(result).toMatchInlineSnapshot(`
12
+ {
13
+ "error": [ZodError: [
14
+ {
15
+ "expected": "string",
16
+ "code": "invalid_type",
17
+ "path": [],
18
+ "message": "Invalid input: expected string, received undefined"
19
+ }
20
+ ]],
21
+ "success": false,
22
+ }
23
+ `);
24
+ });
25
+
26
+ test("nonoptional with default", () => {
27
+ const schema = z.string().optional().nonoptional();
28
+ expectTypeOf<typeof schema._input>().toEqualTypeOf<string>();
29
+ expectTypeOf<typeof schema._output>().toEqualTypeOf<string>();
30
+
31
+ const result = schema.safeParse(undefined);
32
+ expect(result.success).toBe(false);
33
+ expect(result).toMatchInlineSnapshot(`
34
+ {
35
+ "error": [ZodError: [
36
+ {
37
+ "code": "invalid_type",
38
+ "expected": "nonoptional",
39
+ "path": [],
40
+ "message": "Invalid input: expected nonoptional, received undefined"
41
+ }
42
+ ]],
43
+ "success": false,
44
+ }
45
+ `);
46
+ });
47
+
48
+ test("nonoptional in object", () => {
49
+ const schema = z.object({ hi: z.string().optional().nonoptional() });
50
+
51
+ expectTypeOf<typeof schema._input>().toEqualTypeOf<{ hi: string }>();
52
+ expectTypeOf<typeof schema._output>().toEqualTypeOf<{ hi: string }>();
53
+ const r1 = schema.safeParse({ hi: "asdf" });
54
+ expect(r1.success).toEqual(true);
55
+
56
+ const r2 = schema.safeParse({ hi: undefined });
57
+ // expect(schema.safeParse({ hi: undefined }).success).toEqual(false);
58
+ expect(r2.success).toEqual(false);
59
+ expect(r2.error).toMatchInlineSnapshot(`
60
+ [ZodError: [
61
+ {
62
+ "code": "invalid_type",
63
+ "expected": "nonoptional",
64
+ "path": [
65
+ "hi"
66
+ ],
67
+ "message": "Invalid input: expected nonoptional, received undefined"
68
+ }
69
+ ]]
70
+ `);
71
+
72
+ const r3 = schema.safeParse({});
73
+ expect(r3.success).toEqual(false);
74
+ expect(r3.error).toMatchInlineSnapshot(`
75
+ [ZodError: [
76
+ {
77
+ "code": "invalid_type",
78
+ "expected": "nonoptional",
79
+ "path": [
80
+ "hi"
81
+ ],
82
+ "message": "Invalid input: expected nonoptional, received undefined"
83
+ }
84
+ ]]
85
+ `);
86
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/nullable.test.ts ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test(".nullable()", () => {
6
+ const nullable = z.string().nullable();
7
+ expect(nullable.parse(null)).toBe(null);
8
+ expect(nullable.parse("asdf")).toBe("asdf");
9
+ expect(() => nullable.parse(123)).toThrow();
10
+ });
11
+
12
+ test(".nullable unwrap", () => {
13
+ const schema = z.string().nullable();
14
+ expect(schema).toBeInstanceOf(z.ZodNullable);
15
+ expect(schema.unwrap()).toBeInstanceOf(z.ZodString);
16
+ });
17
+
18
+ test("z.null", () => {
19
+ const n = z.null();
20
+ expect(n.parse(null)).toBe(null);
21
+ expect(() => n.parse("asdf")).toThrow();
22
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/number.test.ts ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("z.number() basic validation", () => {
6
+ const schema = z.number();
7
+ expect(schema.parse(1234)).toEqual(1234);
8
+ });
9
+
10
+ test("NaN validation", () => {
11
+ const schema = z.number();
12
+ expect(() => schema.parse(Number.NaN)).toThrow();
13
+ });
14
+
15
+ test("Infinity validation", () => {
16
+ const schema = z.number();
17
+ expect(schema.safeParse(Number.POSITIVE_INFINITY)).toMatchInlineSnapshot(`
18
+ {
19
+ "error": [ZodError: [
20
+ {
21
+ "expected": "number",
22
+ "code": "invalid_type",
23
+ "received": "Infinity",
24
+ "path": [],
25
+ "message": "Invalid input: expected number, received number"
26
+ }
27
+ ]],
28
+ "success": false,
29
+ }
30
+ `);
31
+ expect(schema.safeParse(Number.NEGATIVE_INFINITY)).toMatchInlineSnapshot(`
32
+ {
33
+ "error": [ZodError: [
34
+ {
35
+ "expected": "number",
36
+ "code": "invalid_type",
37
+ "received": "Infinity",
38
+ "path": [],
39
+ "message": "Invalid input: expected number, received number"
40
+ }
41
+ ]],
42
+ "success": false,
43
+ }
44
+ `);
45
+ });
46
+
47
+ test(".gt() validation", () => {
48
+ const schema = z.number().gt(0).gt(5);
49
+ expect(schema.parse(6)).toEqual(6);
50
+ expect(() => schema.parse(5)).toThrow();
51
+ });
52
+
53
+ test(".gte() validation", () => {
54
+ const schema = z.number().gt(0).gte(1).gte(5);
55
+ expect(schema.parse(5)).toEqual(5);
56
+ expect(() => schema.parse(4)).toThrow();
57
+ });
58
+
59
+ test(".min() validation", () => {
60
+ const schema = z.number().min(0).min(5);
61
+ expect(schema.parse(5)).toEqual(5);
62
+ expect(() => schema.parse(4)).toThrow();
63
+ });
64
+
65
+ test(".lt() validation", () => {
66
+ const schema = z.number().lte(10).lt(5);
67
+ expect(schema.parse(4)).toEqual(4);
68
+ expect(() => schema.parse(5)).toThrow();
69
+ });
70
+
71
+ test(".lte() validation", () => {
72
+ const schema = z.number().lte(10).lte(5);
73
+ expect(schema.parse(5)).toEqual(5);
74
+ expect(() => schema.parse(6)).toThrow();
75
+ });
76
+
77
+ test(".max() validation", () => {
78
+ const schema = z.number().max(10).max(5);
79
+ expect(schema.parse(5)).toEqual(5);
80
+ expect(() => schema.parse(6)).toThrow();
81
+ });
82
+
83
+ test(".int() validation", () => {
84
+ const schema = z.number().int();
85
+ expect(schema.parse(4)).toEqual(4);
86
+ expect(() => schema.parse(3.14)).toThrow();
87
+ });
88
+
89
+ test(".positive() validation", () => {
90
+ const schema = z.number().positive();
91
+ expect(schema.parse(1)).toEqual(1);
92
+ expect(() => schema.parse(0)).toThrow();
93
+ expect(() => schema.parse(-1)).toThrow();
94
+ });
95
+
96
+ test(".negative() validation", () => {
97
+ const schema = z.number().negative();
98
+ expect(schema.parse(-1)).toEqual(-1);
99
+ expect(() => schema.parse(0)).toThrow();
100
+ expect(() => schema.parse(1)).toThrow();
101
+ });
102
+
103
+ test(".nonpositive() validation", () => {
104
+ const schema = z.number().nonpositive();
105
+ expect(schema.parse(0)).toEqual(0);
106
+ expect(schema.parse(-1)).toEqual(-1);
107
+ expect(() => schema.parse(1)).toThrow();
108
+ });
109
+
110
+ test(".nonnegative() validation", () => {
111
+ const schema = z.number().nonnegative();
112
+ expect(schema.parse(0)).toEqual(0);
113
+ expect(schema.parse(1)).toEqual(1);
114
+ expect(() => schema.parse(-1)).toThrow();
115
+ });
116
+
117
+ test(".multipleOf() with positive divisor", () => {
118
+ const schema = z.number().multipleOf(5);
119
+ expect(schema.parse(15)).toEqual(15);
120
+ expect(schema.parse(-15)).toEqual(-15);
121
+ expect(() => schema.parse(7.5)).toThrow();
122
+ expect(() => schema.parse(-7.5)).toThrow();
123
+ });
124
+
125
+ test(".multipleOf() with negative divisor", () => {
126
+ const schema = z.number().multipleOf(-5);
127
+ expect(schema.parse(-15)).toEqual(-15);
128
+ expect(schema.parse(15)).toEqual(15);
129
+ expect(() => schema.parse(-7.5)).toThrow();
130
+ expect(() => schema.parse(7.5)).toThrow();
131
+ });
132
+
133
+ test(".step() validation", () => {
134
+ const schemaPointOne = z.number().step(0.1);
135
+ const schemaPointZeroZeroZeroOne = z.number().step(0.0001);
136
+ const schemaSixPointFour = z.number().step(6.4);
137
+
138
+ expect(schemaPointOne.parse(6)).toEqual(6);
139
+ expect(schemaPointOne.parse(6.1)).toEqual(6.1);
140
+ expect(schemaSixPointFour.parse(12.8)).toEqual(12.8);
141
+ expect(schemaPointZeroZeroZeroOne.parse(3.01)).toEqual(3.01);
142
+ expect(() => schemaPointOne.parse(6.11)).toThrow();
143
+ expect(() => schemaPointOne.parse(6.1000000001)).toThrow();
144
+ expect(() => schemaSixPointFour.parse(6.41)).toThrow();
145
+ });
146
+
147
+ test(".finite() validation", () => {
148
+ const schema = z.number().finite();
149
+ expect(schema.parse(123)).toEqual(123);
150
+ expect(schema.safeParse(Number.POSITIVE_INFINITY)).toMatchInlineSnapshot(`
151
+ {
152
+ "error": [ZodError: [
153
+ {
154
+ "expected": "number",
155
+ "code": "invalid_type",
156
+ "received": "Infinity",
157
+ "path": [],
158
+ "message": "Invalid input: expected number, received number"
159
+ }
160
+ ]],
161
+ "success": false,
162
+ }
163
+ `);
164
+ expect(schema.safeParse(Number.NEGATIVE_INFINITY)).toMatchInlineSnapshot(`
165
+ {
166
+ "error": [ZodError: [
167
+ {
168
+ "expected": "number",
169
+ "code": "invalid_type",
170
+ "received": "Infinity",
171
+ "path": [],
172
+ "message": "Invalid input: expected number, received number"
173
+ }
174
+ ]],
175
+ "success": false,
176
+ }
177
+ `);
178
+ });
179
+
180
+ test(".safe() validation", () => {
181
+ const schema = z.number().safe();
182
+ expect(schema.parse(Number.MIN_SAFE_INTEGER)).toEqual(Number.MIN_SAFE_INTEGER);
183
+ expect(schema.parse(Number.MAX_SAFE_INTEGER)).toEqual(Number.MAX_SAFE_INTEGER);
184
+ expect(() => schema.parse(Number.MIN_SAFE_INTEGER - 1)).toThrow();
185
+ expect(() => schema.parse(Number.MAX_SAFE_INTEGER + 1)).toThrow();
186
+ });
187
+
188
+ test("min value getters", () => {
189
+ expect(z.number().minValue).toBeNull;
190
+ expect(z.number().lt(5).minValue).toBeNull;
191
+ expect(z.number().lte(5).minValue).toBeNull;
192
+ expect(z.number().max(5).minValue).toBeNull;
193
+ expect(z.number().negative().minValue).toBeNull;
194
+ expect(z.number().nonpositive().minValue).toBeNull;
195
+ expect(z.number().int().minValue).toBeNull;
196
+ expect(z.number().multipleOf(5).minValue).toBeNull;
197
+ expect(z.number().finite().minValue).toBeNull;
198
+ expect(z.number().gt(5).minValue).toEqual(5);
199
+ expect(z.number().gte(5).minValue).toEqual(5);
200
+ expect(z.number().min(5).minValue).toEqual(5);
201
+ expect(z.number().min(5).min(10).minValue).toEqual(10);
202
+ expect(z.number().positive().minValue).toEqual(0);
203
+ expect(z.number().nonnegative().minValue).toEqual(0);
204
+ expect(z.number().safe().minValue).toEqual(Number.MIN_SAFE_INTEGER);
205
+ });
206
+
207
+ test("max value getters", () => {
208
+ expect(z.number().maxValue).toBeNull;
209
+ expect(z.number().gt(5).maxValue).toBeNull;
210
+ expect(z.number().gte(5).maxValue).toBeNull;
211
+ expect(z.number().min(5).maxValue).toBeNull;
212
+ expect(z.number().positive().maxValue).toBeNull;
213
+ expect(z.number().nonnegative().maxValue).toBeNull;
214
+ expect(z.number().int().minValue).toBeNull;
215
+ expect(z.number().multipleOf(5).minValue).toBeNull;
216
+ expect(z.number().finite().minValue).toBeNull;
217
+ expect(z.number().lt(5).maxValue).toEqual(5);
218
+ expect(z.number().lte(5).maxValue).toEqual(5);
219
+ expect(z.number().max(5).maxValue).toEqual(5);
220
+ expect(z.number().max(5).max(1).maxValue).toEqual(1);
221
+ expect(z.number().negative().maxValue).toEqual(0);
222
+ expect(z.number().nonpositive().maxValue).toEqual(0);
223
+ expect(z.number().safe().maxValue).toEqual(Number.MAX_SAFE_INTEGER);
224
+ });
225
+
226
+ test("int getter", () => {
227
+ expect(z.number().isInt).toEqual(false);
228
+ expect(z.number().int().isInt).toEqual(true);
229
+ expect(z.number().safe().isInt).toEqual(true);
230
+ expect(z.number().multipleOf(5).isInt).toEqual(true);
231
+ });
232
+
233
+ /** In Zod 4, number schemas don't accept infinite values. */
234
+ test("finite getter", () => {
235
+ expect(z.number().isFinite).toEqual(true);
236
+ });
237
+
238
+ test("string format methods", () => {
239
+ const a = z.int32().min(5);
240
+ expect(a.parse(6)).toEqual(6);
241
+ expect(() => a.parse(1)).toThrow();
242
+ });
243
+
244
+ test("error customization", () => {
245
+ z.number().gte(5, { error: (iss) => "Min: " + iss.minimum.valueOf() });
246
+ z.number().lte(5, { error: (iss) => "Max: " + iss.maximum.valueOf() });
247
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/object.test.ts ADDED
@@ -0,0 +1,563 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+ import * as core from "zod/v4/core";
4
+
5
+ const Test = z.object({
6
+ f1: z.number(),
7
+ f2: z.string().optional(),
8
+ f3: z.string().nullable(),
9
+ f4: z.array(z.object({ t: z.union([z.string(), z.boolean()]) })),
10
+ });
11
+
12
+ test("object type inference", () => {
13
+ type TestType = {
14
+ f1: number;
15
+ f2?: string | undefined;
16
+ f3: string | null;
17
+ f4: { t: string | boolean }[];
18
+ };
19
+
20
+ expectTypeOf<z.TypeOf<typeof Test>>().toEqualTypeOf<TestType>();
21
+ });
22
+
23
+ test("unknown throw", () => {
24
+ const asdf: unknown = 35;
25
+ expect(() => Test.parse(asdf)).toThrow();
26
+ });
27
+
28
+ test("shape() should return schema of particular key", () => {
29
+ const f1Schema = Test.shape.f1;
30
+ const f2Schema = Test.shape.f2;
31
+ const f3Schema = Test.shape.f3;
32
+ const f4Schema = Test.shape.f4;
33
+
34
+ expect(f1Schema).toBeInstanceOf(z.ZodNumber);
35
+ expect(f2Schema).toBeInstanceOf(z.ZodOptional);
36
+ expect(f3Schema).toBeInstanceOf(z.ZodNullable);
37
+ expect(f4Schema).toBeInstanceOf(z.ZodArray);
38
+ });
39
+
40
+ test("correct parsing", () => {
41
+ Test.parse({
42
+ f1: 12,
43
+ f2: "string",
44
+ f3: "string",
45
+ f4: [
46
+ {
47
+ t: "string",
48
+ },
49
+ ],
50
+ });
51
+
52
+ Test.parse({
53
+ f1: 12,
54
+ f3: null,
55
+ f4: [
56
+ {
57
+ t: false,
58
+ },
59
+ ],
60
+ });
61
+ });
62
+
63
+ test("nonstrict by default", () => {
64
+ z.object({ points: z.number() }).parse({
65
+ points: 2314,
66
+ unknown: "asdf",
67
+ });
68
+ });
69
+
70
+ test("parse optional keys ", () => {
71
+ const schema = z.object({
72
+ a: z.string().optional(),
73
+ });
74
+ expect(schema.parse({ a: "asdf" })).toEqual({ a: "asdf" });
75
+ });
76
+
77
+ test("empty object", () => {
78
+ const schema = z.object({});
79
+ expect(schema.parse({})).toEqual({});
80
+ expect(schema.parse({ name: "asdf" })).toEqual({});
81
+ expect(schema.safeParse(null).success).toEqual(false);
82
+ expect(schema.safeParse("asdf").success).toEqual(false);
83
+ expectTypeOf<z.output<typeof schema>>().toEqualTypeOf<Record<string, never>>();
84
+ });
85
+
86
+ const data = {
87
+ points: 2314,
88
+ unknown: "asdf",
89
+ };
90
+
91
+ test("strip by default", () => {
92
+ const val = z.object({ points: z.number() }).parse(data);
93
+ expect(val).toEqual({ points: 2314 });
94
+ });
95
+
96
+ test("unknownkeys override", () => {
97
+ const val = z.object({ points: z.number() }).strict().passthrough().strip().passthrough().parse(data);
98
+
99
+ expect(val).toEqual(data);
100
+ });
101
+
102
+ test("passthrough unknown", () => {
103
+ const val = z.object({ points: z.number() }).passthrough().parse(data);
104
+
105
+ expect(val).toEqual(data);
106
+ });
107
+
108
+ test("strip unknown", () => {
109
+ const val = z.object({ points: z.number() }).strip().parse(data);
110
+
111
+ expect(val).toEqual({ points: 2314 });
112
+ });
113
+
114
+ test("strict", () => {
115
+ const val = z.object({ points: z.number() }).strict().safeParse(data);
116
+
117
+ expect(val.success).toEqual(false);
118
+ });
119
+
120
+ test("catchall inference", () => {
121
+ const o1 = z
122
+ .object({
123
+ first: z.string(),
124
+ })
125
+ .catchall(z.number());
126
+
127
+ const d1 = o1.parse({ first: "asdf", num: 1243 });
128
+ // expectTypeOf<(typeof d1)["asdf"]>().toEqualTypeOf<number>();
129
+ expectTypeOf<(typeof d1)["first"]>().toEqualTypeOf<string>();
130
+ });
131
+
132
+ test("catchall overrides strict", () => {
133
+ const o1 = z.object({ first: z.string().optional() }).strict().catchall(z.number());
134
+
135
+ // should run fine
136
+ // setting a catchall overrides the unknownKeys behavior
137
+ o1.parse({
138
+ asdf: 1234,
139
+ });
140
+
141
+ // should only run catchall validation
142
+ // against unknown keys
143
+ o1.parse({
144
+ first: "asdf",
145
+ asdf: 1234,
146
+ });
147
+ });
148
+
149
+ test("catchall overrides strict", () => {
150
+ const o1 = z
151
+ .object({
152
+ first: z.string(),
153
+ })
154
+ .strict()
155
+ .catchall(z.number());
156
+
157
+ // should run fine
158
+ // setting a catchall overrides the unknownKeys behavior
159
+ o1.parse({
160
+ first: "asdf",
161
+ asdf: 1234,
162
+ });
163
+ });
164
+
165
+ test("optional keys are unset", async () => {
166
+ const SNamedEntity = z.object({
167
+ id: z.string(),
168
+ set: z.string().optional(),
169
+ unset: z.string().optional(),
170
+ });
171
+ const result = await SNamedEntity.parse({
172
+ id: "asdf",
173
+ set: undefined,
174
+ });
175
+ expect(Object.keys(result)).toEqual(["id", "set"]);
176
+ });
177
+
178
+ test("catchall parsing", async () => {
179
+ const result = z.object({ name: z.string() }).catchall(z.number()).parse({ name: "Foo", validExtraKey: 61 });
180
+
181
+ expect(result).toEqual({ name: "Foo", validExtraKey: 61 });
182
+
183
+ const result2 = z
184
+ .object({ name: z.string() })
185
+ .catchall(z.number())
186
+ .safeParse({ name: "Foo", validExtraKey: 61, invalid: "asdf" });
187
+
188
+ expect(result2.success).toEqual(false);
189
+ });
190
+
191
+ test("nonexistent keys", async () => {
192
+ const Schema = z.union([z.object({ a: z.string() }), z.object({ b: z.number() })]);
193
+ const obj = { a: "A" };
194
+ const result = await Schema.spa(obj); // Works with 1.11.10, breaks with 2.0.0-beta.21
195
+ expect(result.success).toBe(true);
196
+ });
197
+
198
+ test("test async union", async () => {
199
+ const Schema2 = z.union([
200
+ z.object({
201
+ ty: z.string(),
202
+ }),
203
+ z.object({
204
+ ty: z.number(),
205
+ }),
206
+ ]);
207
+
208
+ const obj = { ty: "A" };
209
+ const result = await Schema2.spa(obj); // Works with 1.11.10, breaks with 2.0.0-beta.21
210
+ expect(result.success).toEqual(true);
211
+ });
212
+
213
+ test("test inferred merged type", async () => {
214
+ const asdf = z.object({ a: z.string() }).merge(z.object({ a: z.number() }));
215
+ type asdf = z.infer<typeof asdf>;
216
+
217
+ expectTypeOf<asdf>().toEqualTypeOf<{ a: number }>();
218
+ });
219
+
220
+ test("inferred type with Record shape", () => {
221
+ type A = z.ZodObject<Record<string, z.ZodType<string, number>>>;
222
+ expectTypeOf<z.infer<A>>().toEqualTypeOf<Record<string, string>>();
223
+ expectTypeOf<z.input<A>>().toEqualTypeOf<Record<string, number>>();
224
+
225
+ type B = z.ZodObject;
226
+ expectTypeOf<z.infer<B>>().toEqualTypeOf<Record<string, unknown>>();
227
+ expectTypeOf<z.input<B>>().toEqualTypeOf<Record<string, unknown>>();
228
+ });
229
+
230
+ test("inferred merged object type with optional properties", async () => {
231
+ const Merged = z
232
+ .object({ a: z.string(), b: z.string().optional() })
233
+ .merge(z.object({ a: z.string().optional(), b: z.string() }));
234
+ type Merged = z.infer<typeof Merged>;
235
+ expectTypeOf<Merged>().toEqualTypeOf<{ a?: string; b: string }>();
236
+ expectTypeOf<Merged>().toEqualTypeOf<{ a?: string; b: string }>();
237
+ });
238
+
239
+ test("inferred unioned object type with optional properties", async () => {
240
+ const Unioned = z.union([
241
+ z.object({ a: z.string(), b: z.string().optional() }),
242
+ z.object({ a: z.string().optional(), b: z.string() }),
243
+ ]);
244
+ type Unioned = z.infer<typeof Unioned>;
245
+ expectTypeOf<Unioned>().toEqualTypeOf<{ a: string; b?: string } | { a?: string; b: string }>();
246
+ });
247
+
248
+ test("inferred enum type", async () => {
249
+ const Enum = z.object({ a: z.string(), b: z.string().optional() }).keyof();
250
+
251
+ expect(Enum.enum).toEqual({
252
+ a: "a",
253
+ b: "b",
254
+ });
255
+
256
+ expect(Enum._zod.def.entries).toEqual({
257
+ a: "a",
258
+ b: "b",
259
+ });
260
+ type Enum = z.infer<typeof Enum>;
261
+ expectTypeOf<Enum>().toEqualTypeOf<"a" | "b">();
262
+ });
263
+
264
+ test("inferred partial object type with optional properties", async () => {
265
+ const Partial = z.object({ a: z.string(), b: z.string().optional() }).partial();
266
+ type Partial = z.infer<typeof Partial>;
267
+ expectTypeOf<Partial>().toEqualTypeOf<{ a?: string; b?: string }>();
268
+ });
269
+
270
+ test("inferred picked object type with optional properties", async () => {
271
+ const Picked = z.object({ a: z.string(), b: z.string().optional() }).pick({ b: true });
272
+ type Picked = z.infer<typeof Picked>;
273
+ expectTypeOf<Picked>().toEqualTypeOf<{ b?: string }>();
274
+ });
275
+
276
+ test("inferred type for unknown/any keys", () => {
277
+ const myType = z.object({
278
+ anyOptional: z.any().optional(),
279
+ anyRequired: z.any(),
280
+ unknownOptional: z.unknown().optional(),
281
+ unknownRequired: z.unknown(),
282
+ });
283
+ type myType = z.infer<typeof myType>;
284
+ expectTypeOf<myType>().toEqualTypeOf<{
285
+ anyOptional?: any;
286
+ anyRequired: any;
287
+ unknownOptional?: unknown;
288
+ unknownRequired: unknown;
289
+ }>();
290
+ });
291
+
292
+ test("strictObject", async () => {
293
+ const strictObj = z.strictObject({
294
+ name: z.string(),
295
+ });
296
+
297
+ const syncResult = strictObj.safeParse({ name: "asdf", unexpected: 13 });
298
+ expect(syncResult.success).toEqual(false);
299
+
300
+ const asyncResult = await strictObj.spa({ name: "asdf", unexpected: 13 });
301
+ expect(asyncResult.success).toEqual(false);
302
+ });
303
+
304
+ test("object with refine", async () => {
305
+ const schema = z
306
+ .object({
307
+ a: z.string().default("foo"),
308
+ b: z.number(),
309
+ })
310
+ .refine(() => true);
311
+ expect(schema.parse({ b: 5 })).toEqual({ b: 5, a: "foo" });
312
+ const result = await schema.parseAsync({ b: 5 });
313
+ expect(result).toEqual({ b: 5, a: "foo" });
314
+ });
315
+
316
+ test("intersection of object with date", async () => {
317
+ const schema = z.object({
318
+ a: z.date(),
319
+ });
320
+ expect(z.intersection(schema, schema).parse({ a: new Date(1637353595983) })).toEqual({
321
+ a: new Date(1637353595983),
322
+ });
323
+ const result = await schema.parseAsync({ a: new Date(1637353595983) });
324
+ expect(result).toEqual({ a: new Date(1637353595983) });
325
+ });
326
+
327
+ test("intersection of object with refine with date", async () => {
328
+ const schema = z
329
+ .object({
330
+ a: z.date(),
331
+ })
332
+ .refine(() => true);
333
+ expect(z.intersection(schema, schema).parse({ a: new Date(1637353595983) })).toEqual({
334
+ a: new Date(1637353595983),
335
+ });
336
+ const result = await schema.parseAsync({ a: new Date(1637353595983) });
337
+ expect(result).toEqual({ a: new Date(1637353595983) });
338
+ });
339
+
340
+ test("constructor key", () => {
341
+ const person = z
342
+ .object({
343
+ name: z.string(),
344
+ })
345
+ .strict();
346
+
347
+ expect(() =>
348
+ person.parse({
349
+ name: "bob dylan",
350
+ constructor: 61,
351
+ })
352
+ ).toThrow();
353
+ });
354
+
355
+ test("constructor key", () => {
356
+ const Example = z.object({
357
+ prop: z.string(),
358
+ opt: z.number().optional(),
359
+ arr: z.string().array(),
360
+ });
361
+
362
+ type Example = z.infer<typeof Example>;
363
+ expectTypeOf<keyof Example>().toEqualTypeOf<"prop" | "opt" | "arr">();
364
+ });
365
+
366
+ test("catchall", () => {
367
+ const a = z.object({});
368
+ expect(a._zod.def.catchall).toBeUndefined();
369
+
370
+ const b = z.strictObject({});
371
+ expect(b._zod.def.catchall).toBeInstanceOf(core.$ZodNever);
372
+
373
+ const c = z.looseObject({});
374
+ expect(c._zod.def.catchall).toBeInstanceOf(core.$ZodUnknown);
375
+
376
+ const d = z.object({}).catchall(z.number());
377
+ expect(d._zod.def.catchall).toBeInstanceOf(core.$ZodNumber);
378
+ });
379
+
380
+ test("unknownkeys merging", () => {
381
+ // This one is "strict"
382
+ const a = z.looseObject({
383
+ a: z.string(),
384
+ });
385
+
386
+ const b = z.strictObject({ b: z.string() });
387
+
388
+ // incoming object overrides
389
+ const c = a.merge(b);
390
+ expect(c._zod.def.catchall).toBeInstanceOf(core.$ZodNever);
391
+ });
392
+
393
+ const personToExtend = z.object({
394
+ firstName: z.string(),
395
+ lastName: z.string(),
396
+ });
397
+
398
+ test("extend() should return schema with new key", () => {
399
+ const PersonWithNickname = personToExtend.extend({ nickName: z.string() });
400
+ type PersonWithNickname = z.infer<typeof PersonWithNickname>;
401
+
402
+ const expected = { firstName: "f", nickName: "n", lastName: "l" };
403
+ const actual = PersonWithNickname.parse(expected);
404
+
405
+ expect(actual).toEqual(expected);
406
+ expectTypeOf<keyof PersonWithNickname>().toEqualTypeOf<"firstName" | "lastName" | "nickName">();
407
+ expectTypeOf<PersonWithNickname>().toEqualTypeOf<{ firstName: string; lastName: string; nickName: string }>();
408
+ });
409
+
410
+ test("extend() should have power to override existing key", () => {
411
+ const PersonWithNumberAsLastName = personToExtend.extend({
412
+ lastName: z.number(),
413
+ });
414
+ type PersonWithNumberAsLastName = z.infer<typeof PersonWithNumberAsLastName>;
415
+
416
+ const expected = { firstName: "f", lastName: 42 };
417
+ const actual = PersonWithNumberAsLastName.parse(expected);
418
+
419
+ expect(actual).toEqual(expected);
420
+ expectTypeOf<PersonWithNumberAsLastName>().toEqualTypeOf<{ firstName: string; lastName: number }>();
421
+ });
422
+
423
+ test("passthrough index signature", () => {
424
+ const a = z.object({ a: z.string() });
425
+ type a = z.infer<typeof a>;
426
+ expectTypeOf<a>().toEqualTypeOf<{ a: string }>();
427
+ const b = a.passthrough();
428
+ type b = z.infer<typeof b>;
429
+ expectTypeOf<b>().toEqualTypeOf<{ a: string; [k: string]: unknown }>();
430
+ });
431
+
432
+ // test("xor", () => {
433
+ // type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
434
+ // type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;
435
+
436
+ // type A = { name: string; a: number };
437
+ // type B = { name: string; b: number };
438
+ // type C = XOR<A, B>;
439
+ // type Outer = { data: C };
440
+ // const Outer = z.object({
441
+ // data: z.union([z.object({ name: z.string(), a: z.number() }), z.object({ name: z.string(), b: z.number() })]),
442
+ // }) satisfies z.ZodType<Outer, any>;
443
+ // });
444
+
445
+ test("assignability", () => {
446
+ z.object({ a: z.string() }) satisfies z.ZodObject<{ a: z.ZodString }>;
447
+ z.object({ a: z.string() }).catchall(z.number()) satisfies z.ZodObject<{ a: z.ZodString }>;
448
+ z.object({ a: z.string() }).strict() satisfies z.ZodObject;
449
+ z.object({}) satisfies z.ZodObject;
450
+
451
+ z.looseObject({ name: z.string() }) satisfies z.ZodObject<
452
+ {
453
+ name: z.ZodString;
454
+ },
455
+ z.core.$loose
456
+ >;
457
+ z.looseObject({ name: z.string() }) satisfies z.ZodObject<{
458
+ name: z.ZodString;
459
+ }>;
460
+ z.strictObject({ name: z.string() }) satisfies z.ZodObject<
461
+ {
462
+ name: z.ZodString;
463
+ },
464
+ z.core.$loose
465
+ >;
466
+ z.strictObject({ name: z.string() }) satisfies z.ZodObject<
467
+ {
468
+ name: z.ZodString;
469
+ },
470
+ z.core.$strict
471
+ >;
472
+ z.object({ name: z.string() }) satisfies z.ZodObject<{
473
+ name: z.ZodString;
474
+ }>;
475
+ z.object({
476
+ a: z.string(),
477
+ b: z.number(),
478
+ c: z.boolean(),
479
+ }) satisfies z.core.$ZodObject;
480
+ });
481
+
482
+ test("null prototype", () => {
483
+ const schema = z.object({ a: z.string() });
484
+ const obj = Object.create(null);
485
+ obj.a = "foo";
486
+ expect(schema.parse(obj)).toEqual({ a: "foo" });
487
+ });
488
+
489
+ test("empty objects", () => {
490
+ const A = z.looseObject({});
491
+ type Ain = z.input<typeof A>;
492
+ expectTypeOf<Ain>().toEqualTypeOf<Record<string, unknown>>();
493
+ type Aout = z.output<typeof A>;
494
+ expectTypeOf<Aout>().toEqualTypeOf<Record<string, unknown>>();
495
+
496
+ const B = z.object({});
497
+ type Bout = z.output<typeof B>;
498
+ expectTypeOf<Bout>().toEqualTypeOf<Record<string, never>>();
499
+ type Bin = z.input<typeof B>;
500
+ expectTypeOf<Bin>().toEqualTypeOf<Record<string, never>>();
501
+
502
+ const C = z.strictObject({});
503
+ type Cout = z.output<typeof C>;
504
+ expectTypeOf<Cout>().toEqualTypeOf<Record<string, never>>();
505
+ type Cin = z.input<typeof C>;
506
+ expectTypeOf<Cin>().toEqualTypeOf<Record<string, never>>();
507
+ });
508
+
509
+ test("preserve key order", () => {
510
+ const schema = z.object({
511
+ a: z.string().optional(),
512
+ b: z.string(),
513
+ });
514
+ const r1 = schema.safeParse({ a: "asdf", b: "qwer" });
515
+ const r2 = schema.safeParse({ a: "asdf", b: "qwer" }, { jitless: true });
516
+
517
+ expect(Object.keys(r1.data!)).toMatchInlineSnapshot(`
518
+ [
519
+ "a",
520
+ "b",
521
+ ]
522
+ `);
523
+ expect(Object.keys(r1.data!)).toEqual(Object.keys(r2.data!));
524
+ });
525
+
526
+ test("empty shape", () => {
527
+ const a = z.object({});
528
+
529
+ a.parse({});
530
+ a.parse({}, { jitless: true });
531
+ a.parse(Object.create(null));
532
+ a.parse(Object.create(null), { jitless: true });
533
+
534
+ expect(() => a.parse([])).toThrow();
535
+ expect(() => a.parse([], { jitless: true })).toThrow();
536
+ });
537
+
538
+ test("zodtype assignability", () => {
539
+ // Does not error
540
+ z.object({ hello: z.string().optional() }) satisfies z.ZodType<{ hello?: string | undefined }>;
541
+ z.object({ hello: z.string() }) satisfies z.ZodType<{ hello?: string | undefined }>;
542
+ // @ts-expect-error
543
+ z.object({}) satisfies z.ZodType<{ hello: string | undefined }>;
544
+ // @ts-expect-error
545
+ z.object({ hello: z.string().optional() }) satisfies z.ZodType<{ hello: string | undefined }>;
546
+ // @ts-expect-error
547
+ z.object({ hello: z.string().optional() }) satisfies z.ZodType<{ hello: string }>;
548
+ // @ts-expect-error
549
+ z.object({ hello: z.number() }) satisfies z.ZodType<{ hello?: string | undefined }>;
550
+ });
551
+
552
+ test("index signature in shape", () => {
553
+ function makeZodObj<const T extends string>(key: T) {
554
+ return z.looseObject({
555
+ [key]: z.string(),
556
+ });
557
+ }
558
+
559
+ const schema = makeZodObj("foo");
560
+ type schema = z.infer<typeof schema>;
561
+
562
+ expectTypeOf<schema>().toEqualTypeOf<Record<string, string>>();
563
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/optional.test.ts ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @ts-ignore TS6133
2
+ import { expect, expectTypeOf, test } from "vitest";
3
+
4
+ import * as z from "zod/v4";
5
+
6
+ test(".optional()", () => {
7
+ const schema = z.string().optional();
8
+ expect(schema.parse("adsf")).toEqual("adsf");
9
+ expect(schema.parse(undefined)).toEqual(undefined);
10
+ expect(schema.safeParse(null).success).toEqual(false);
11
+
12
+ expectTypeOf<typeof schema._output>().toEqualTypeOf<string | undefined>();
13
+ });
14
+
15
+ test("unwrap", () => {
16
+ const unwrapped = z.string().optional().unwrap();
17
+ expect(unwrapped).toBeInstanceOf(z.ZodString);
18
+ });
19
+
20
+ test("optionality", () => {
21
+ const a = z.string();
22
+ expect(a._zod.optin).toEqual(undefined);
23
+ expect(a._zod.optout).toEqual(undefined);
24
+
25
+ const b = z.string().optional();
26
+ expect(b._zod.optin).toEqual("optional");
27
+ expect(b._zod.optout).toEqual("optional");
28
+
29
+ const c = z.string().default("asdf");
30
+ expect(c._zod.optin).toEqual("optional");
31
+ expect(c._zod.optout).toEqual(undefined);
32
+
33
+ const d = z.string().optional().nullable();
34
+ expect(d._zod.optin).toEqual("optional");
35
+ expect(d._zod.optout).toEqual("optional");
36
+
37
+ const e = z.string().default("asdf").nullable();
38
+ expect(e._zod.optin).toEqual("optional");
39
+ expect(e._zod.optout).toEqual(undefined);
40
+
41
+ // z.undefined should NOT be optional
42
+ const f = z.undefined();
43
+ expect(f._zod.optin).toEqual("optional");
44
+ expect(f._zod.optout).toEqual("optional");
45
+ expectTypeOf<typeof f._zod.optin>().toEqualTypeOf<"optional" | undefined>();
46
+ expectTypeOf<typeof f._zod.optout>().toEqualTypeOf<"optional" | undefined>();
47
+
48
+ // z.union should be optional if any of the types are optional
49
+ const g = z.union([z.string(), z.undefined()]);
50
+ expect(g._zod.optin).toEqual("optional");
51
+ expect(g._zod.optout).toEqual("optional");
52
+ expectTypeOf<typeof g._zod.optin>().toEqualTypeOf<"optional" | undefined>();
53
+ expectTypeOf<typeof g._zod.optout>().toEqualTypeOf<"optional" | undefined>();
54
+
55
+ const h = z.union([z.string(), z.optional(z.string())]);
56
+ expect(h._zod.optin).toEqual("optional");
57
+ expect(h._zod.optout).toEqual("optional");
58
+ expectTypeOf<typeof h._zod.optin>().toEqualTypeOf<"optional">();
59
+ expectTypeOf<typeof h._zod.optout>().toEqualTypeOf<"optional">();
60
+ });
61
+
62
+ test("pipe optionality", () => {
63
+ z.string().optional()._zod.optin;
64
+ const a = z.string().optional().pipe(z.string());
65
+ expect(a._zod.optin).toEqual("optional");
66
+ expect(a._zod.optout).toEqual(undefined);
67
+ expectTypeOf<typeof a._zod.optin>().toEqualTypeOf<"optional">();
68
+ expectTypeOf<typeof a._zod.optout>().toEqualTypeOf<"optional" | undefined>();
69
+
70
+ const b = z
71
+ .string()
72
+ .transform((val) => (Math.random() ? val : undefined))
73
+ .pipe(z.string().optional());
74
+ expect(b._zod.optin).toEqual(undefined);
75
+ expect(b._zod.optout).toEqual("optional");
76
+ expectTypeOf<typeof b._zod.optin>().toEqualTypeOf<"optional" | undefined>();
77
+ expectTypeOf<typeof b._zod.optout>().toEqualTypeOf<"optional">();
78
+
79
+ const c = z.string().default("asdf").pipe(z.string());
80
+ expect(c._zod.optin).toEqual("optional");
81
+ expect(c._zod.optout).toEqual(undefined);
82
+
83
+ const d = z
84
+ .string()
85
+ .transform((val) => (Math.random() ? val : undefined))
86
+ .pipe(z.string().default("asdf"));
87
+ expect(d._zod.optin).toEqual(undefined);
88
+ expect(d._zod.optout).toEqual(undefined);
89
+ });
90
+
91
+ test("pipe optionality inside objects", () => {
92
+ const schema = z.object({
93
+ a: z.string().optional(),
94
+ b: z.string().optional().pipe(z.string()),
95
+ c: z.string().default("asdf").pipe(z.string()),
96
+ d: z
97
+ .string()
98
+ .transform((val) => (Math.random() ? val : undefined))
99
+ .pipe(z.string().optional()),
100
+ e: z
101
+ .string()
102
+ .transform((val) => (Math.random() ? val : undefined))
103
+ .pipe(z.string().default("asdf")),
104
+ });
105
+
106
+ type SchemaIn = z.input<typeof schema>;
107
+ expectTypeOf<SchemaIn>().toEqualTypeOf<{
108
+ a?: string | undefined;
109
+ b?: string | undefined;
110
+ c?: string | undefined;
111
+ d: string;
112
+ e: string;
113
+ }>();
114
+
115
+ type SchemaOut = z.output<typeof schema>;
116
+ expectTypeOf<SchemaOut>().toEqualTypeOf<{
117
+ a?: string | undefined;
118
+ b: string;
119
+ c: string;
120
+ d?: string | undefined;
121
+ e: string;
122
+ }>();
123
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/partial.test.ts ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ const nested = z.object({
5
+ name: z.string(),
6
+ age: z.number(),
7
+ outer: z.object({
8
+ inner: z.string(),
9
+ }),
10
+ array: z.array(z.object({ asdf: z.string() })),
11
+ });
12
+
13
+ test("shallow inference", () => {
14
+ const shallow = nested.partial();
15
+ type shallow = z.infer<typeof shallow>;
16
+
17
+ expectTypeOf<shallow>().toEqualTypeOf<{
18
+ name?: string | undefined;
19
+ age?: number | undefined;
20
+ outer?: { inner: string } | undefined;
21
+ array?: { asdf: string }[] | undefined;
22
+ }>();
23
+ });
24
+
25
+ test("shallow partial parse", () => {
26
+ const shallow = nested.partial();
27
+ shallow.parse({});
28
+ shallow.parse({
29
+ name: "asdf",
30
+ age: 23143,
31
+ });
32
+ });
33
+
34
+ test("required", () => {
35
+ const object = z.object({
36
+ name: z.string(),
37
+ age: z.number().optional(),
38
+ field: z.string().optional().default("asdf"),
39
+ nullableField: z.number().nullable(),
40
+ nullishField: z.string().nullish(),
41
+ });
42
+
43
+ const requiredObject = object.required();
44
+ expect(requiredObject.shape.name).toBeInstanceOf(z.ZodNonOptional);
45
+ expect(requiredObject.shape.name.unwrap()).toBeInstanceOf(z.ZodString);
46
+ expect(requiredObject.shape.age).toBeInstanceOf(z.ZodNonOptional);
47
+ expect(requiredObject.shape.age.unwrap()).toBeInstanceOf(z.ZodOptional);
48
+ expect(requiredObject.shape.field).toBeInstanceOf(z.ZodNonOptional);
49
+ expect(requiredObject.shape.field.unwrap()).toBeInstanceOf(z.ZodDefault);
50
+ expect(requiredObject.shape.nullableField).toBeInstanceOf(z.ZodNonOptional);
51
+ expect(requiredObject.shape.nullableField.unwrap()).toBeInstanceOf(z.ZodNullable);
52
+ expect(requiredObject.shape.nullishField).toBeInstanceOf(z.ZodNonOptional);
53
+ expect(requiredObject.shape.nullishField.unwrap()).toBeInstanceOf(z.ZodOptional);
54
+ expect(requiredObject.shape.nullishField.unwrap().unwrap()).toBeInstanceOf(z.ZodNullable);
55
+ });
56
+
57
+ test("required inference", () => {
58
+ const object = z.object({
59
+ name: z.string(),
60
+ age: z.number().optional(),
61
+ field: z.string().optional().default("asdf"),
62
+ nullableField: z.number().nullable(),
63
+ nullishField: z.string().nullish(),
64
+ });
65
+
66
+ const requiredObject = object.required();
67
+
68
+ type required = z.infer<typeof requiredObject>;
69
+ type expected = {
70
+ name: string;
71
+ age: number;
72
+ field: string;
73
+ nullableField: number | null;
74
+ nullishField: string | null;
75
+ };
76
+ expectTypeOf<expected>().toEqualTypeOf<required>();
77
+ });
78
+
79
+ test("required with mask", () => {
80
+ const object = z.object({
81
+ name: z.string(),
82
+ age: z.number().optional(),
83
+ field: z.string().optional().default("asdf"),
84
+ country: z.string().optional(),
85
+ });
86
+
87
+ const requiredObject = object.required({ age: true });
88
+ expect(requiredObject.shape.name).toBeInstanceOf(z.ZodString);
89
+ expect(requiredObject.shape.age).toBeInstanceOf(z.ZodNonOptional);
90
+ expect(requiredObject.shape.field).toBeInstanceOf(z.ZodDefault);
91
+ expect(requiredObject.shape.country).toBeInstanceOf(z.ZodOptional);
92
+ });
93
+
94
+ test("required with mask -- ignore falsy values", () => {
95
+ const object = z.object({
96
+ name: z.string(),
97
+ age: z.number().optional(),
98
+ field: z.string().optional().default("asdf"),
99
+ country: z.string().optional(),
100
+ });
101
+
102
+ // @ts-expect-error
103
+ const requiredObject = object.required({ age: true, country: false });
104
+ expect(requiredObject.shape.name).toBeInstanceOf(z.ZodString);
105
+ expect(requiredObject.shape.age).toBeInstanceOf(z.ZodNonOptional);
106
+ expect(requiredObject.shape.field).toBeInstanceOf(z.ZodDefault);
107
+ expect(requiredObject.shape.country).toBeInstanceOf(z.ZodOptional);
108
+ });
109
+
110
+ test("partial with mask", async () => {
111
+ const object = z.object({
112
+ name: z.string(),
113
+ age: z.number().optional(),
114
+ field: z.string().optional().default("asdf"),
115
+ country: z.string(),
116
+ });
117
+
118
+ const masked = object.partial({ age: true, field: true, name: true }).strict();
119
+
120
+ expect(masked.shape.name).toBeInstanceOf(z.ZodOptional);
121
+ expect(masked.shape.age).toBeInstanceOf(z.ZodOptional);
122
+ expect(masked.shape.field).toBeInstanceOf(z.ZodOptional);
123
+ expect(masked.shape.country).toBeInstanceOf(z.ZodString);
124
+
125
+ masked.parse({ country: "US" });
126
+ await masked.parseAsync({ country: "US" });
127
+ });
128
+
129
+ test("partial with mask -- ignore falsy values", async () => {
130
+ const object = z.object({
131
+ name: z.string(),
132
+ age: z.number().optional(),
133
+ field: z.string().optional().default("asdf"),
134
+ country: z.string(),
135
+ });
136
+
137
+ // @ts-expect-error
138
+ const masked = object.partial({ name: true, country: false }).strict();
139
+
140
+ expect(masked.shape.name).toBeInstanceOf(z.ZodOptional);
141
+ expect(masked.shape.age).toBeInstanceOf(z.ZodOptional);
142
+ expect(masked.shape.field).toBeInstanceOf(z.ZodDefault);
143
+ expect(masked.shape.country).toBeInstanceOf(z.ZodString);
144
+
145
+ masked.parse({ country: "US" });
146
+ await masked.parseAsync({ country: "US" });
147
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/pickomit.test.ts ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ const fish = z.object({
5
+ name: z.string(),
6
+ age: z.number(),
7
+ nested: z.object({}),
8
+ });
9
+
10
+ test("pick type inference", () => {
11
+ const nameonlyFish = fish.pick({ name: true });
12
+ type nameonlyFish = z.infer<typeof nameonlyFish>;
13
+ expectTypeOf<nameonlyFish>().toEqualTypeOf<{ name: string }>();
14
+ });
15
+
16
+ test("pick parse - success", () => {
17
+ const nameonlyFish = fish.pick({ name: true });
18
+ nameonlyFish.parse({ name: "bob" });
19
+
20
+ // @ts-expect-error checking runtime picks `name` only.
21
+ const anotherNameonlyFish = fish.pick({ name: true, age: false });
22
+ anotherNameonlyFish.parse({ name: "bob" });
23
+ });
24
+
25
+ test("pick parse - fail", () => {
26
+ fish.pick({ name: true }).parse({ name: "12" } as any);
27
+ fish.pick({ name: true }).parse({ name: "bob", age: 12 } as any);
28
+ fish.pick({ age: true }).parse({ age: 12 } as any);
29
+
30
+ const nameonlyFish = fish.pick({ name: true }).strict();
31
+ const bad1 = () => nameonlyFish.parse({ name: 12 } as any);
32
+ const bad2 = () => nameonlyFish.parse({ name: "bob", age: 12 } as any);
33
+ const bad3 = () => nameonlyFish.parse({ age: 12 } as any);
34
+
35
+ // @ts-expect-error checking runtime picks `name` only.
36
+ const anotherNameonlyFish = fish.pick({ name: true, age: false }).strict();
37
+ const bad4 = () => anotherNameonlyFish.parse({ name: "bob", age: 12 } as any);
38
+
39
+ expect(bad1).toThrow();
40
+ expect(bad2).toThrow();
41
+ expect(bad3).toThrow();
42
+ expect(bad4).toThrow();
43
+ });
44
+
45
+ test("pick - remove optional", () => {
46
+ const schema = z.object({ a: z.string(), b: z.string().optional() });
47
+ expect("a" in schema._zod.def.shape).toEqual(true);
48
+ expect("b" in schema._zod.def.shape!).toEqual(true);
49
+ const picked = schema.pick({ a: true });
50
+ expect("a" in picked._zod.def.shape).toEqual(true);
51
+ expect("b" in picked._zod.def.shape!).toEqual(false);
52
+ });
53
+
54
+ test("omit type inference", () => {
55
+ const nonameFish = fish.omit({ name: true });
56
+ type nonameFish = z.infer<typeof nonameFish>;
57
+
58
+ expectTypeOf<nonameFish>().toEqualTypeOf<{ age: number; nested: Record<string, never> }>();
59
+ });
60
+
61
+ test("omit parse - success", () => {
62
+ const nonameFish = fish.omit({ name: true });
63
+ nonameFish.parse({ age: 12, nested: {} });
64
+
65
+ // @ts-expect-error checking runtime omits `name` only.
66
+ const anotherNonameFish = fish.omit({ name: true, age: false });
67
+ anotherNonameFish.parse({ age: 12, nested: {} });
68
+ });
69
+
70
+ test("omit parse - fail", () => {
71
+ const nonameFish = fish.omit({ name: true });
72
+ const bad1 = () => nonameFish.parse({ name: 12 } as any);
73
+ const bad2 = () => nonameFish.parse({ age: 12 } as any);
74
+ const bad3 = () => nonameFish.parse({} as any);
75
+
76
+ // @ts-expect-error checking runtime omits `name` only.
77
+ const anotherNonameFish = fish.omit({ name: true, age: false });
78
+ const bad4 = () => anotherNonameFish.parse({ nested: {} } as any);
79
+
80
+ expect(bad1).toThrow();
81
+ expect(bad2).toThrow();
82
+ expect(bad3).toThrow();
83
+ expect(bad4).toThrow();
84
+ });
85
+
86
+ test("omit - remove optional", () => {
87
+ const schema = z.object({ a: z.string(), b: z.string().optional() });
88
+ expect("a" in schema._zod.def.shape).toEqual(true);
89
+ const omitted = schema.omit({ a: true });
90
+ expect("a" in omitted._zod.def.shape).toEqual(false);
91
+ });
92
+
93
+ test("nonstrict inference", () => {
94
+ const laxfish = fish.pick({ name: true }).catchall(z.any());
95
+ type laxfish = z.infer<typeof laxfish>;
96
+ expectTypeOf<laxfish>().toEqualTypeOf<{ name: string; [k: string]: any }>();
97
+ });
98
+
99
+ test("nonstrict parsing - pass", () => {
100
+ const laxfish = fish.passthrough().pick({ name: true });
101
+ laxfish.parse({ name: "asdf", whatever: "asdf" });
102
+ laxfish.parse({ name: "asdf", age: 12, nested: {} });
103
+ });
104
+
105
+ test("nonstrict parsing - fail", () => {
106
+ const laxfish = fish.passthrough().pick({ name: true });
107
+ const bad = () => laxfish.parse({ whatever: "asdf" } as any);
108
+ expect(bad).toThrow();
109
+ });
110
+
111
+ test("pick/omit/required/partial - do not allow unknown keys", () => {
112
+ const schema = z.object({
113
+ name: z.string(),
114
+ age: z.number(),
115
+ });
116
+
117
+ expect(() => schema.pick({ name: true, asdf: true })).toThrow();
118
+
119
+ // @ts-expect-error
120
+ expect(() => schema.pick({ $unknown: true })).toThrow();
121
+ // @ts-expect-error
122
+ expect(() => schema.omit({ $unknown: true })).toThrow();
123
+ // @ts-expect-error
124
+ expect(() => schema.required({ $unknown: true })).toThrow();
125
+ // @ts-expect-error
126
+ expect(() => schema.partial({ $unknown: true })).toThrow();
127
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/pipe.test.ts ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+
3
+ import * as z from "zod/v4";
4
+
5
+ test("string to number pipe", () => {
6
+ const schema = z.string().transform(Number).pipe(z.number());
7
+ expect(schema.parse("1234")).toEqual(1234);
8
+ });
9
+
10
+ test("string to number pipe async", async () => {
11
+ const schema = z
12
+ .string()
13
+ .transform(async (val) => Number(val))
14
+ .pipe(z.number());
15
+ expect(await schema.parseAsync("1234")).toEqual(1234);
16
+ });
17
+
18
+ test("string with default fallback", () => {
19
+ const stringWithDefault = z
20
+ .pipe(
21
+ z.transform((v) => (v === "none" ? undefined : v)),
22
+ z.string()
23
+ )
24
+ .catch("default");
25
+
26
+ expect(stringWithDefault.parse("ok")).toBe("ok");
27
+ expect(stringWithDefault.parse(undefined)).toBe("default");
28
+ expect(stringWithDefault.parse("none")).toBe("default");
29
+ expect(stringWithDefault.parse(15)).toBe("default");
30
+ });
31
+
32
+ test("continue on non-fatal errors", () => {
33
+ const schema = z
34
+ .string()
35
+ .refine((c) => c === "1234", "A")
36
+ .transform((val) => Number(val))
37
+ .refine((c) => c === 1234, "B");
38
+
39
+ schema.parse("1234");
40
+
41
+ expect(schema.safeParse("4321")).toMatchInlineSnapshot(`
42
+ {
43
+ "error": [ZodError: [
44
+ {
45
+ "code": "custom",
46
+ "path": [],
47
+ "message": "A"
48
+ },
49
+ {
50
+ "code": "custom",
51
+ "path": [],
52
+ "message": "B"
53
+ }
54
+ ]],
55
+ "success": false,
56
+ }
57
+ `);
58
+ });
59
+
60
+ test("break on fatal errors", () => {
61
+ const schema = z
62
+ .string()
63
+ .refine((c) => c === "1234", { message: "A", abort: true })
64
+ .transform((val) => Number(val))
65
+ .refine((c) => c === 1234, "B");
66
+
67
+ schema.parse("1234");
68
+
69
+ expect(schema.safeParse("4321")).toMatchInlineSnapshot(`
70
+ {
71
+ "error": [ZodError: [
72
+ {
73
+ "code": "custom",
74
+ "path": [],
75
+ "message": "A"
76
+ }
77
+ ]],
78
+ "success": false,
79
+ }
80
+ `);
81
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/prefault.test.ts ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import { z } from "zod/v4";
3
+
4
+ test("basic prefault", () => {
5
+ const a = z.prefault(z.string().trim(), " default ");
6
+ expect(a).toBeInstanceOf(z.ZodPrefault);
7
+ expect(a.parse(" asdf ")).toEqual("asdf");
8
+ expect(a.parse(undefined)).toEqual("default");
9
+
10
+ type inp = z.input<typeof a>;
11
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
12
+ type out = z.output<typeof a>;
13
+ expectTypeOf<out>().toEqualTypeOf<string>();
14
+ });
15
+
16
+ test("prefault inside object", () => {
17
+ // test optinality
18
+ const a = z.object({
19
+ name: z.string().optional(),
20
+ age: z.number().default(1234),
21
+ email: z.string().prefault("1234"),
22
+ });
23
+
24
+ type inp = z.input<typeof a>;
25
+ expectTypeOf<inp>().toEqualTypeOf<{
26
+ name?: string | undefined;
27
+ age?: number | undefined;
28
+ email?: string | undefined;
29
+ }>();
30
+
31
+ type out = z.output<typeof a>;
32
+ expectTypeOf<out>().toEqualTypeOf<{
33
+ name?: string | undefined;
34
+ age: number;
35
+ email: string;
36
+ }>();
37
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/preprocess.test.ts ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("preprocess", () => {
5
+ const schema = z.preprocess((data) => [data], z.string().array());
6
+ const value = schema.parse("asdf");
7
+ expect(value).toEqual(["asdf"]);
8
+ expectTypeOf<(typeof schema)["_input"]>().toEqualTypeOf<unknown>();
9
+ });
10
+
11
+ test("async preprocess", async () => {
12
+ const schema = z.preprocess(async (data) => {
13
+ return [data];
14
+ }, z.string().array());
15
+ const value = await schema.safeParseAsync("asdf");
16
+ expect(value.data).toEqual(["asdf"]);
17
+ expect(value).toMatchInlineSnapshot(`
18
+ {
19
+ "data": [
20
+ "asdf",
21
+ ],
22
+ "success": true,
23
+ }
24
+ `);
25
+ });
26
+
27
+ test("ctx.addIssue accepts string", () => {
28
+ const schema = z.preprocess((_, ctx) => {
29
+ ctx.addIssue("bad stuff");
30
+ }, z.string());
31
+ const result = schema.safeParse("asdf");
32
+ expect(result.error!.issues).toHaveLength(1);
33
+ expect(result).toMatchInlineSnapshot(`
34
+ {
35
+ "error": [ZodError: [
36
+ {
37
+ "message": "bad stuff",
38
+ "code": "custom",
39
+ "path": []
40
+ }
41
+ ]],
42
+ "success": false,
43
+ }
44
+ `);
45
+ });
46
+
47
+ test("preprocess ctx.addIssue with parse", () => {
48
+ const a = z.preprocess((data, ctx) => {
49
+ ctx.addIssue({
50
+ input: data,
51
+ code: "custom",
52
+ message: `${data} is not one of our allowed strings`,
53
+ });
54
+ return data;
55
+ }, z.string());
56
+
57
+ const result = a.safeParse("asdf");
58
+
59
+ // expect(result.error!.toJSON()).toContain("not one of our allowed strings");
60
+
61
+ expect(result.error!.issues).toHaveLength(1);
62
+ expect(result).toMatchInlineSnapshot(`
63
+ {
64
+ "error": [ZodError: [
65
+ {
66
+ "code": "custom",
67
+ "message": "asdf is not one of our allowed strings",
68
+ "path": []
69
+ }
70
+ ]],
71
+ "success": false,
72
+ }
73
+ `);
74
+ });
75
+
76
+ test("preprocess ctx.addIssue non-fatal by default", () => {
77
+ const schema = z.preprocess((data, ctx) => {
78
+ ctx.addIssue({
79
+ code: "custom",
80
+ message: `custom error`,
81
+ });
82
+ return data;
83
+ }, z.string());
84
+ const result = schema.safeParse(1234);
85
+
86
+ expect(result.error!.issues).toHaveLength(2);
87
+ expect(result).toMatchInlineSnapshot(`
88
+ {
89
+ "error": [ZodError: [
90
+ {
91
+ "code": "custom",
92
+ "message": "custom error",
93
+ "path": []
94
+ },
95
+ {
96
+ "expected": "string",
97
+ "code": "invalid_type",
98
+ "path": [],
99
+ "message": "Invalid input: expected string, received number"
100
+ }
101
+ ]],
102
+ "success": false,
103
+ }
104
+ `);
105
+ });
106
+
107
+ test("preprocess ctx.addIssue fatal true", () => {
108
+ const schema = z.preprocess((data, ctx) => {
109
+ ctx.addIssue({
110
+ input: data,
111
+ code: "custom",
112
+ origin: "custom",
113
+ message: `custom error`,
114
+ fatal: true,
115
+ });
116
+ return data;
117
+ }, z.string());
118
+
119
+ const result = schema.safeParse(1234);
120
+
121
+ expect(result.error!.issues).toHaveLength(1);
122
+ expect(result).toMatchInlineSnapshot(`
123
+ {
124
+ "error": [ZodError: [
125
+ {
126
+ "code": "custom",
127
+ "origin": "custom",
128
+ "message": "custom error",
129
+ "fatal": true,
130
+ "path": []
131
+ }
132
+ ]],
133
+ "success": false,
134
+ }
135
+ `);
136
+ });
137
+
138
+ test("async preprocess ctx.addIssue with parseAsync", async () => {
139
+ const schema = z.preprocess(async (data, ctx) => {
140
+ ctx.addIssue({
141
+ input: data,
142
+ code: "custom",
143
+ message: `${data} is not one of our allowed strings`,
144
+ });
145
+ return data;
146
+ }, z.string());
147
+
148
+ const result = await schema.safeParseAsync("asdf");
149
+
150
+ expect(result.error!.issues).toHaveLength(1);
151
+ expect(result).toMatchInlineSnapshot(`
152
+ {
153
+ "error": [ZodError: [
154
+ {
155
+ "code": "custom",
156
+ "message": "asdf is not one of our allowed strings",
157
+ "path": []
158
+ }
159
+ ]],
160
+ "success": false,
161
+ }
162
+ `);
163
+ });
164
+
165
+ test("z.NEVER in preprocess", () => {
166
+ const foo = z.preprocess((val, ctx) => {
167
+ if (!val) {
168
+ ctx.addIssue({ input: val, code: "custom", message: "bad" });
169
+ return z.NEVER;
170
+ }
171
+ return val;
172
+ }, z.number());
173
+
174
+ type foo = z.infer<typeof foo>;
175
+ expectTypeOf<foo>().toEqualTypeOf<number>();
176
+ const result = foo.safeParse(undefined);
177
+
178
+ expect(result.error!.issues).toHaveLength(2);
179
+ expect(result).toMatchInlineSnapshot(`
180
+ {
181
+ "error": [ZodError: [
182
+ {
183
+ "code": "custom",
184
+ "message": "bad",
185
+ "path": []
186
+ },
187
+ {
188
+ "expected": "number",
189
+ "code": "invalid_type",
190
+ "path": [],
191
+ "message": "Invalid input: expected number, received object"
192
+ }
193
+ ]],
194
+ "success": false,
195
+ }
196
+ `);
197
+ });
198
+
199
+ test("preprocess as the second property of object", () => {
200
+ const schema = z.object({
201
+ nonEmptyStr: z.string().min(1),
202
+ positiveNum: z.preprocess((v) => Number(v), z.number().positive()),
203
+ });
204
+ const result = schema.safeParse({
205
+ nonEmptyStr: "",
206
+ positiveNum: "",
207
+ });
208
+
209
+ expect(result.error!.issues).toHaveLength(2);
210
+ expect(result).toMatchInlineSnapshot(`
211
+ {
212
+ "error": [ZodError: [
213
+ {
214
+ "origin": "string",
215
+ "code": "too_small",
216
+ "minimum": 1,
217
+ "inclusive": true,
218
+ "path": [
219
+ "nonEmptyStr"
220
+ ],
221
+ "message": "Too small: expected string to have >=1 characters"
222
+ },
223
+ {
224
+ "origin": "number",
225
+ "code": "too_small",
226
+ "minimum": 0,
227
+ "inclusive": false,
228
+ "path": [
229
+ "positiveNum"
230
+ ],
231
+ "message": "Too small: expected number to be >0"
232
+ }
233
+ ]],
234
+ "success": false,
235
+ }
236
+ `);
237
+ });
238
+
239
+ test("preprocess validates with sibling errors", () => {
240
+ const schema = z.object({
241
+ missing: z.string().refine(() => false),
242
+ preprocess: z.preprocess((data: any) => data?.trim(), z.string().regex(/ asdf/)),
243
+ });
244
+
245
+ const result = schema.safeParse({ preprocess: " asdf" });
246
+
247
+ expect(result.error!.issues).toHaveLength(2);
248
+ expect(result).toMatchInlineSnapshot(`
249
+ {
250
+ "error": [ZodError: [
251
+ {
252
+ "expected": "string",
253
+ "code": "invalid_type",
254
+ "path": [
255
+ "missing"
256
+ ],
257
+ "message": "Invalid input: expected string, received undefined"
258
+ },
259
+ {
260
+ "origin": "string",
261
+ "code": "invalid_format",
262
+ "format": "regex",
263
+ "pattern": "/ asdf/",
264
+ "path": [
265
+ "preprocess"
266
+ ],
267
+ "message": "Invalid string: must match pattern / asdf/"
268
+ }
269
+ ]],
270
+ "success": false,
271
+ }
272
+ `);
273
+ });
274
+
275
+ test("perform transform with non-fatal issues", () => {
276
+ const A = z
277
+ .string()
278
+ .refine((_) => false)
279
+ .min(4)
280
+ .transform((val) => val.length)
281
+ .pipe(z.number())
282
+ .refine((_) => false);
283
+ expect(A.safeParse("asdfasdf").error!.issues).toHaveLength(2);
284
+ expect(A.safeParse("asdfasdf").error).toMatchInlineSnapshot(`
285
+ [ZodError: [
286
+ {
287
+ "code": "custom",
288
+ "path": [],
289
+ "message": "Invalid input"
290
+ },
291
+ {
292
+ "code": "custom",
293
+ "path": [],
294
+ "message": "Invalid input"
295
+ }
296
+ ]]
297
+ `);
298
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/primitive.test.ts ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ const literalStringSchema = z.literal("asdf");
5
+ const literalNumberSchema = z.literal(12);
6
+ const literalBooleanSchema = z.literal(true);
7
+ const literalBigIntSchema = z.literal(BigInt(42));
8
+
9
+ const stringSchema = z.string();
10
+ const numberSchema = z.number();
11
+ const bigintSchema = z.bigint();
12
+ const booleanSchema = z.boolean();
13
+ const dateSchema = z.date();
14
+ const symbolSchema = z.symbol();
15
+ const nullSchema = z.null();
16
+ const undefinedSchema = z.undefined();
17
+ const stringSchemaOptional = z.string().optional();
18
+ const stringSchemaNullable = z.string().nullable();
19
+ const numberSchemaOptional = z.number().optional();
20
+ const numberSchemaNullable = z.number().nullable();
21
+ const bigintSchemaOptional = z.bigint().optional();
22
+ const bigintSchemaNullable = z.bigint().nullable();
23
+ const booleanSchemaOptional = z.boolean().optional();
24
+ const booleanSchemaNullable = z.boolean().nullable();
25
+ const dateSchemaOptional = z.date().optional();
26
+ const dateSchemaNullable = z.date().nullable();
27
+ const symbolSchemaOptional = z.symbol().optional();
28
+ const symbolSchemaNullable = z.symbol().nullable();
29
+
30
+ test("literal string schema", () => {
31
+ expect(literalStringSchema.parse("asdf")).toBe("asdf");
32
+ expect(() => literalStringSchema.parse("not_asdf")).toThrow();
33
+ expect(() => literalStringSchema.parse(123)).toThrow();
34
+ expect(() => literalStringSchema.parse(true)).toThrow();
35
+ expect(() => literalStringSchema.parse({})).toThrow();
36
+ });
37
+
38
+ test("literal number schema", () => {
39
+ expect(literalNumberSchema.parse(12)).toBe(12);
40
+ expect(() => literalNumberSchema.parse(13)).toThrow();
41
+ expect(() => literalNumberSchema.parse("foo")).toThrow();
42
+ expect(() => literalNumberSchema.parse(true)).toThrow();
43
+ expect(() => literalNumberSchema.parse({})).toThrow();
44
+ });
45
+
46
+ test("literal boolean schema", () => {
47
+ expect(literalBooleanSchema.parse(true)).toBe(true);
48
+ expect(() => literalBooleanSchema.parse(false)).toThrow();
49
+ expect(() => literalBooleanSchema.parse("asdf")).toThrow();
50
+ expect(() => literalBooleanSchema.parse(123)).toThrow();
51
+ expect(() => literalBooleanSchema.parse({})).toThrow();
52
+ });
53
+
54
+ test("literal bigint schema", () => {
55
+ expect(literalBigIntSchema.parse(BigInt(42))).toBe(BigInt(42));
56
+ expect(() => literalBigIntSchema.parse(BigInt(43))).toThrow();
57
+ expect(() => literalBigIntSchema.parse("asdf")).toThrow();
58
+ expect(() => literalBigIntSchema.parse(123)).toThrow();
59
+ expect(() => literalBigIntSchema.parse({})).toThrow();
60
+ });
61
+
62
+ test("string schema", () => {
63
+ stringSchema.parse("foo");
64
+ expect(() => stringSchema.parse(Math.random())).toThrow();
65
+ expect(() => stringSchema.parse(true)).toThrow();
66
+ expect(() => stringSchema.parse(undefined)).toThrow();
67
+ expect(() => stringSchema.parse(null)).toThrow();
68
+ });
69
+
70
+ test("number schema", () => {
71
+ numberSchema.parse(Math.random());
72
+ expect(() => numberSchema.parse("foo")).toThrow();
73
+ expect(() => numberSchema.parse(BigInt(17))).toThrow();
74
+ expect(() => numberSchema.parse(true)).toThrow();
75
+ expect(() => numberSchema.parse(undefined)).toThrow();
76
+ expect(() => numberSchema.parse(null)).toThrow();
77
+ });
78
+
79
+ test("bigint schema", () => {
80
+ bigintSchema.parse(BigInt(17));
81
+ expect(() => bigintSchema.parse("foo")).toThrow();
82
+ expect(() => bigintSchema.parse(Math.random())).toThrow();
83
+ expect(() => bigintSchema.parse(true)).toThrow();
84
+ expect(() => bigintSchema.parse(undefined)).toThrow();
85
+ expect(() => bigintSchema.parse(null)).toThrow();
86
+ });
87
+
88
+ test("boolean schema", () => {
89
+ booleanSchema.parse(true);
90
+ expect(() => booleanSchema.parse("foo")).toThrow();
91
+ expect(() => booleanSchema.parse(Math.random())).toThrow();
92
+ expect(() => booleanSchema.parse(undefined)).toThrow();
93
+ expect(() => booleanSchema.parse(null)).toThrow();
94
+ });
95
+
96
+ test("date schema", async () => {
97
+ dateSchema.parse(new Date());
98
+ expect(() => dateSchema.parse("foo")).toThrow();
99
+ expect(() => dateSchema.parse(Math.random())).toThrow();
100
+ expect(() => dateSchema.parse(true)).toThrow();
101
+ expect(() => dateSchema.parse(undefined)).toThrow();
102
+ expect(() => dateSchema.parse(null)).toThrow();
103
+ expect(await dateSchema.safeParseAsync(new Date("invalid"))).toMatchInlineSnapshot(`
104
+ {
105
+ "error": [ZodError: [
106
+ {
107
+ "expected": "date",
108
+ "code": "invalid_type",
109
+ "received": "Invalid Date",
110
+ "path": [],
111
+ "message": "Invalid input: expected date, received Date"
112
+ }
113
+ ]],
114
+ "success": false,
115
+ }
116
+ `);
117
+ });
118
+
119
+ test("symbol schema", () => {
120
+ symbolSchema.parse(Symbol("foo"));
121
+ expect(() => symbolSchema.parse("foo")).toThrow();
122
+ expect(() => symbolSchema.parse(Math.random())).toThrow();
123
+ expect(() => symbolSchema.parse(true)).toThrow();
124
+ expect(() => symbolSchema.parse(new Date())).toThrow();
125
+ expect(() => symbolSchema.parse(undefined)).toThrow();
126
+ expect(() => symbolSchema.parse(null)).toThrow();
127
+ });
128
+
129
+ test("undefined schema", () => {
130
+ undefinedSchema.parse(undefined);
131
+ expect(() => undefinedSchema.parse("foo")).toThrow();
132
+ expect(() => undefinedSchema.parse(Math.random())).toThrow();
133
+ expect(() => undefinedSchema.parse(true)).toThrow();
134
+ expect(() => undefinedSchema.parse(null)).toThrow();
135
+ });
136
+
137
+ test("null schema", () => {
138
+ nullSchema.parse(null);
139
+ expect(() => nullSchema.parse("foo")).toThrow();
140
+ expect(() => nullSchema.parse(Math.random())).toThrow();
141
+ expect(() => nullSchema.parse(true)).toThrow();
142
+ expect(() => nullSchema.parse(undefined)).toThrow();
143
+ });
144
+
145
+ test("primitive inference", () => {
146
+ expectTypeOf<z.TypeOf<typeof literalStringSchema>>().toEqualTypeOf<"asdf">();
147
+ expectTypeOf<z.TypeOf<typeof literalNumberSchema>>().toEqualTypeOf<12>();
148
+ expectTypeOf<z.TypeOf<typeof literalBooleanSchema>>().toEqualTypeOf<true>();
149
+ expectTypeOf<z.TypeOf<typeof literalBigIntSchema>>().toEqualTypeOf<bigint>();
150
+ expectTypeOf<z.TypeOf<typeof stringSchema>>().toEqualTypeOf<string>();
151
+ expectTypeOf<z.TypeOf<typeof numberSchema>>().toEqualTypeOf<number>();
152
+ expectTypeOf<z.TypeOf<typeof bigintSchema>>().toEqualTypeOf<bigint>();
153
+ expectTypeOf<z.TypeOf<typeof booleanSchema>>().toEqualTypeOf<boolean>();
154
+ expectTypeOf<z.TypeOf<typeof dateSchema>>().toEqualTypeOf<Date>();
155
+ expectTypeOf<z.TypeOf<typeof symbolSchema>>().toEqualTypeOf<symbol>();
156
+ expectTypeOf<z.TypeOf<typeof nullSchema>>().toEqualTypeOf<null>();
157
+ expectTypeOf<z.TypeOf<typeof undefinedSchema>>().toEqualTypeOf<undefined>();
158
+ expectTypeOf<z.TypeOf<typeof stringSchemaOptional>>().toEqualTypeOf<string | undefined>();
159
+ expectTypeOf<z.TypeOf<typeof stringSchemaNullable>>().toEqualTypeOf<string | null>();
160
+ expectTypeOf<z.TypeOf<typeof numberSchemaOptional>>().toEqualTypeOf<number | undefined>();
161
+ expectTypeOf<z.TypeOf<typeof numberSchemaNullable>>().toEqualTypeOf<number | null>();
162
+ expectTypeOf<z.TypeOf<typeof bigintSchemaOptional>>().toEqualTypeOf<bigint | undefined>();
163
+ expectTypeOf<z.TypeOf<typeof bigintSchemaNullable>>().toEqualTypeOf<bigint | null>();
164
+ expectTypeOf<z.TypeOf<typeof booleanSchemaOptional>>().toEqualTypeOf<boolean | undefined>();
165
+ expectTypeOf<z.TypeOf<typeof booleanSchemaNullable>>().toEqualTypeOf<boolean | null>();
166
+ expectTypeOf<z.TypeOf<typeof dateSchemaOptional>>().toEqualTypeOf<Date | undefined>();
167
+ expectTypeOf<z.TypeOf<typeof dateSchemaNullable>>().toEqualTypeOf<Date | null>();
168
+ expectTypeOf<z.TypeOf<typeof symbolSchemaOptional>>().toEqualTypeOf<symbol | undefined>();
169
+ expectTypeOf<z.TypeOf<typeof symbolSchemaNullable>>().toEqualTypeOf<symbol | null>();
170
+ });
171
+
172
+ test("get literal values", () => {
173
+ expect(literalStringSchema.values).toEqual(new Set(["asdf"]));
174
+ expect(literalStringSchema._zod.def.values).toEqual(["asdf"]);
175
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/promise.test.ts ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ const promSchema = z.promise(
5
+ z.object({
6
+ name: z.string(),
7
+ age: z.number(),
8
+ })
9
+ );
10
+
11
+ test("promise inference", () => {
12
+ type promSchemaType = z.infer<typeof promSchema>;
13
+ expectTypeOf<promSchemaType>().toEqualTypeOf<{ name: string; age: number }>();
14
+ });
15
+
16
+ test("promise parsing success", async () => {
17
+ // expect(() => promSchema.parse(Promise.resolve({ name: "Bobby", age: 10 }))).toThrow();
18
+ const pr = promSchema.parseAsync(Promise.resolve({ name: "Bobby", age: 10 }));
19
+ expect(pr).toBeInstanceOf(Promise);
20
+ const result = await pr;
21
+ expect(result).toMatchInlineSnapshot(`
22
+ {
23
+ "age": 10,
24
+ "name": "Bobby",
25
+ }
26
+ `);
27
+ });
28
+
29
+ test("promise parsing fail", async () => {
30
+ const bad = await promSchema.safeParseAsync(Promise.resolve({ name: "Bobby", age: "10" }));
31
+ expect(bad.success).toBe(false);
32
+ expect(bad.error).toBeInstanceOf(z.ZodError);
33
+ });
34
+
35
+ test("promise parsing fail 2", async () => {
36
+ const result = await promSchema.safeParseAsync(Promise.resolve({ name: "Bobby", age: "10" }));
37
+ expect(result.success).toBe(false);
38
+ expect(result.error).toBeInstanceOf(z.ZodError);
39
+ });
40
+
41
+ test("promise parsing fail", () => {
42
+ const bad = () => promSchema.parse({ then: () => {}, catch: {} });
43
+ expect(bad).toThrow();
44
+ });
45
+
46
+ test("sync promise parsing", () => {
47
+ expect(() => z.promise(z.string()).parse(Promise.resolve("asfd"))).toThrow();
48
+ });
49
+
50
+ const asyncFunction = z.function({
51
+ input: z.tuple([]),
52
+ output: promSchema,
53
+ });
54
+
55
+ test("async function pass", async () => {
56
+ const validatedFunction = asyncFunction.implementAsync(async () => {
57
+ return { name: "jimmy", age: 14 };
58
+ });
59
+ await expect(validatedFunction()).resolves.toEqual({
60
+ name: "jimmy",
61
+ age: 14,
62
+ });
63
+ });
64
+
65
+ test("async function fail", async () => {
66
+ const validatedFunction = asyncFunction.implementAsync(() => {
67
+ return Promise.resolve("asdf" as any);
68
+ });
69
+ await expect(validatedFunction()).rejects.toBeInstanceOf(z.core.$ZodError);
70
+ });
71
+
72
+ test("async promise parsing", () => {
73
+ const res = z.promise(z.number()).parseAsync(Promise.resolve(12));
74
+ expect(res).toBeInstanceOf(Promise);
75
+ });
76
+
77
+ test("resolves", () => {
78
+ const foo = z.literal("foo");
79
+ const res = z.promise(foo);
80
+ expect(res.unwrap()).toEqual(foo);
81
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/prototypes.test.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ declare module "zod/v4" {
5
+ interface ZodType {
6
+ /** @deprecated */
7
+ _classic(): string;
8
+ }
9
+ }
10
+
11
+ test("prototype extension", () => {
12
+ z.ZodType.prototype._classic = function () {
13
+ return "_classic";
14
+ };
15
+
16
+ // should pass
17
+ const result = z.string()._classic();
18
+ expect(result).toBe("_classic");
19
+ // expectTypeOf<typeof result>().toEqualTypeOf<string>();
20
+
21
+ // clean up
22
+ z.ZodType.prototype._classic = undefined;
23
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/readonly.test.ts ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ enum testEnum {
5
+ A = 0,
6
+ B = 1,
7
+ }
8
+
9
+ test("flat inference", () => {
10
+ const readonlyString = z.string().readonly();
11
+ const readonlyNumber = z.number().readonly();
12
+ const readonlyNaN = z.nan().readonly();
13
+ const readonlyBigInt = z.bigint().readonly();
14
+ const readonlyBoolean = z.boolean().readonly();
15
+ const readonlyDate = z.date().readonly();
16
+ const readonlyUndefined = z.undefined().readonly();
17
+ const readonlyNull = z.null().readonly();
18
+ const readonlyAny = z.any().readonly();
19
+ const readonlyUnknown = z.unknown().readonly();
20
+ const readonlyVoid = z.void().readonly();
21
+ const readonlyStringArray = z.array(z.string()).readonly();
22
+ const readonlyTuple = z.tuple([z.string(), z.number()]).readonly();
23
+ const readonlyMap = z.map(z.string(), z.date()).readonly();
24
+ const readonlySet = z.set(z.string()).readonly();
25
+ const readonlyStringRecord = z.record(z.string(), z.string()).readonly();
26
+ const readonlyNumberRecord = z.record(z.string(), z.number()).readonly();
27
+ const readonlyObject = z.object({ a: z.string(), 1: z.number() }).readonly();
28
+ const readonlyEnum = z.nativeEnum(testEnum).readonly();
29
+ const readonlyPromise = z.promise(z.string()).readonly();
30
+
31
+ expectTypeOf<typeof readonlyString._output>().toEqualTypeOf<string>();
32
+ expectTypeOf<typeof readonlyNumber._output>().toEqualTypeOf<number>();
33
+ expectTypeOf<typeof readonlyNaN._output>().toEqualTypeOf<number>();
34
+ expectTypeOf<typeof readonlyBigInt._output>().toEqualTypeOf<bigint>();
35
+ expectTypeOf<typeof readonlyBoolean._output>().toEqualTypeOf<boolean>();
36
+ expectTypeOf<typeof readonlyDate._output>().toEqualTypeOf<Date>();
37
+ expectTypeOf<typeof readonlyUndefined._output>().toEqualTypeOf<undefined>();
38
+ expectTypeOf<typeof readonlyNull._output>().toEqualTypeOf<null>();
39
+ expectTypeOf<typeof readonlyAny._output>().toEqualTypeOf<any>();
40
+ expectTypeOf<typeof readonlyUnknown._output>().toEqualTypeOf<Readonly<unknown>>();
41
+ expectTypeOf<typeof readonlyVoid._output>().toEqualTypeOf<void>();
42
+ expectTypeOf<typeof readonlyStringArray._output>().toEqualTypeOf<readonly string[]>();
43
+ expectTypeOf<typeof readonlyTuple._output>().toEqualTypeOf<readonly [string, number]>();
44
+ expectTypeOf<typeof readonlyMap._output>().toEqualTypeOf<ReadonlyMap<string, Date>>();
45
+ expectTypeOf<typeof readonlySet._output>().toEqualTypeOf<ReadonlySet<string>>();
46
+ expectTypeOf<typeof readonlyStringRecord._output>().toEqualTypeOf<Readonly<Record<string, string>>>();
47
+ expectTypeOf<typeof readonlyNumberRecord._output>().toEqualTypeOf<Readonly<Record<string, number>>>();
48
+ expectTypeOf<typeof readonlyObject._output>().toEqualTypeOf<{ readonly a: string; readonly 1: number }>();
49
+ expectTypeOf<typeof readonlyEnum._output>().toEqualTypeOf<Readonly<testEnum>>();
50
+ expectTypeOf<typeof readonlyPromise._output>().toEqualTypeOf<string>();
51
+ });
52
+
53
+ // test("deep inference", () => {
54
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[0]>>().toEqualTypeOf<string>();
55
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[1]>>().toEqualTypeOf<number>();
56
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[2]>>().toEqualTypeOf<number>();
57
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[3]>>().toEqualTypeOf<bigint>();
58
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[4]>>().toEqualTypeOf<boolean>();
59
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[5]>>().toEqualTypeOf<Date>();
60
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[6]>>().toEqualTypeOf<undefined>();
61
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[7]>>().toEqualTypeOf<null>();
62
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[8]>>().toEqualTypeOf<any>();
63
+ // expectTypeOf<
64
+ // z.infer<(typeof deepReadonlySchemas_0)[9]>
65
+ // >().toEqualTypeOf<Readonly<unknown>>();
66
+ // expectTypeOf<z.infer<(typeof deepReadonlySchemas_0)[10]>>().toEqualTypeOf<void>();
67
+ // expectTypeOf<
68
+ // z.infer<(typeof deepReadonlySchemas_0)[11]>
69
+ // >().toEqualTypeOf<(args_0: string, args_1: number, ...args_2: unknown[]) => unknown>();
70
+ // expectTypeOf<
71
+ // z.infer<(typeof deepReadonlySchemas_0)[12]>
72
+ // >().toEqualTypeOf<readonly string[]>();
73
+ // expectTypeOf<
74
+ // z.infer<(typeof deepReadonlySchemas_0)[13]>
75
+ // >().toEqualTypeOf<readonly [string, number]>();
76
+ // expectTypeOf<
77
+ // z.infer<(typeof deepReadonlySchemas_0)[14]>
78
+ // >().toEqualTypeOf<ReadonlyMap<string, Date>>();
79
+ // expectTypeOf<
80
+ // z.infer<(typeof deepReadonlySchemas_0)[15]>
81
+ // >().toEqualTypeOf<ReadonlySet<Promise<string>>>();
82
+ // expectTypeOf<
83
+ // z.infer<(typeof deepReadonlySchemas_0)[16]>
84
+ // >().toEqualTypeOf<Readonly<Record<string, string>>>();
85
+ // expectTypeOf<
86
+ // z.infer<(typeof deepReadonlySchemas_0)[17]>
87
+ // >().toEqualTypeOf<Readonly<Record<string, number>>>();
88
+ // expectTypeOf<
89
+ // z.infer<(typeof deepReadonlySchemas_0)[18]>
90
+ // >().toEqualTypeOf<{ readonly a: string; readonly 1: number }>();
91
+ // expectTypeOf<
92
+ // z.infer<(typeof deepReadonlySchemas_0)[19]>
93
+ // >().toEqualTypeOf<Readonly<testEnum>>();
94
+ // expectTypeOf<
95
+ // z.infer<(typeof deepReadonlySchemas_0)[20]>
96
+ // >().toEqualTypeOf<Promise<string>>();
97
+
98
+ // expectTypeOf<
99
+ // z.infer<typeof crazyDeepReadonlySchema>
100
+ // >().toEqualTypeOf<ReadonlyMap<
101
+ // ReadonlySet<readonly [string, number]>,
102
+ // {
103
+ // readonly a: {
104
+ // readonly [x: string]: readonly any[];
105
+ // };
106
+ // readonly b: {
107
+ // readonly c: {
108
+ // readonly d: {
109
+ // readonly e: {
110
+ // readonly f: {
111
+ // readonly g?: {};
112
+ // };
113
+ // };
114
+ // };
115
+ // };
116
+ // };
117
+ // }
118
+ // >>();
119
+ // });
120
+
121
+ test("object freezing", async () => {
122
+ expect(Object.isFrozen(z.array(z.string()).readonly().parse(["a"]))).toBe(true);
123
+ expect(Object.isFrozen(z.tuple([z.string(), z.number()]).readonly().parse(["a", 1]))).toBe(true);
124
+ expect(
125
+ Object.isFrozen(
126
+ z
127
+ .map(z.string(), z.date())
128
+ .readonly()
129
+ .parse(new Map([["a", new Date()]]))
130
+ )
131
+ ).toBe(true);
132
+
133
+ expect(Object.isFrozen(z.record(z.string(), z.string()).readonly().parse({ a: "b" }))).toBe(true);
134
+ expect(Object.isFrozen(z.record(z.string(), z.number()).readonly().parse({ a: 1 }))).toBe(true);
135
+ expect(Object.isFrozen(z.object({ a: z.string(), 1: z.number() }).readonly().parse({ a: "b", 1: 2 }))).toBe(true);
136
+ expect(
137
+ Object.isFrozen(
138
+ await z
139
+ .set(z.promise(z.string()))
140
+ .readonly()
141
+ .parseAsync(new Set([Promise.resolve("a")]))
142
+ )
143
+ ).toBe(true);
144
+ expect(Object.isFrozen(await z.promise(z.string()).readonly().parseAsync(Promise.resolve("a")))).toBe(true);
145
+ });
146
+
147
+ test("async object freezing", async () => {
148
+ expect(Object.isFrozen(await z.array(z.string()).readonly().parseAsync(["a"]))).toBe(true);
149
+ expect(Object.isFrozen(await z.tuple([z.string(), z.number()]).readonly().parseAsync(["a", 1]))).toBe(true);
150
+ expect(
151
+ Object.isFrozen(
152
+ await z
153
+ .map(z.string(), z.date())
154
+ .readonly()
155
+ .parseAsync(new Map([["a", new Date()]]))
156
+ )
157
+ ).toBe(true);
158
+ expect(
159
+ Object.isFrozen(
160
+ await z
161
+ .set(z.promise(z.string()))
162
+ .readonly()
163
+ .parseAsync(new Set([Promise.resolve("a")]))
164
+ )
165
+ ).toBe(true);
166
+ expect(Object.isFrozen(await z.record(z.string(), z.string()).readonly().parseAsync({ a: "b" }))).toBe(true);
167
+ expect(Object.isFrozen(await z.record(z.string(), z.number()).readonly().parseAsync({ a: 1 }))).toBe(true);
168
+ expect(
169
+ Object.isFrozen(await z.object({ a: z.string(), 1: z.number() }).readonly().parseAsync({ a: "b", 1: 2 }))
170
+ ).toBe(true);
171
+ expect(Object.isFrozen(await z.promise(z.string()).readonly().parseAsync(Promise.resolve("a")))).toBe(true);
172
+ });
173
+
174
+ test("readonly inference", () => {
175
+ const readonlyStringArray = z.string().array().readonly();
176
+ const readonlyStringTuple = z.tuple([z.string()]).readonly();
177
+ const deepReadonly = z.object({ a: z.string() }).readonly();
178
+
179
+ type readonlyStringArray = z.infer<typeof readonlyStringArray>;
180
+ type readonlyStringTuple = z.infer<typeof readonlyStringTuple>;
181
+ type deepReadonly = z.infer<typeof deepReadonly>;
182
+
183
+ expectTypeOf<readonlyStringArray>().toEqualTypeOf<readonly string[]>();
184
+ expectTypeOf<readonlyStringTuple>().toEqualTypeOf<readonly [string]>();
185
+ expectTypeOf<deepReadonly>().toEqualTypeOf<{ readonly a: string }>();
186
+ });
187
+
188
+ test("readonly parse", () => {
189
+ const schema = z.array(z.string()).readonly();
190
+ const readonlyArray = ["a", "b", "c"] as const;
191
+ const mutableArray = ["a", "b", "c"];
192
+ const result1 = schema.parse(readonlyArray);
193
+ const result2 = schema.parse(mutableArray);
194
+ expect(result1).toEqual(readonlyArray);
195
+ expect(result2).toEqual(mutableArray);
196
+ });
197
+
198
+ test("readonly parse with tuples", () => {
199
+ const schema = z.tuple([z.string(), z.number()]).readonly();
200
+ schema.parse(["a", 1]);
201
+ });
202
+
203
+ test("readonly and the get method", () => {
204
+ const readonlyString = z.string().readonly();
205
+ const readonlyNumber1 = z.number().readonly();
206
+ const readonlyNumber2 = z.number().readonly();
207
+ const readonlyBigInt = z.bigint().readonly();
208
+ const readonlyBoolean = z.boolean().readonly();
209
+ const readonlyDate = z.date().readonly();
210
+ const readonlyUndefined = z.undefined().readonly();
211
+ const readonlyNull = z.null().readonly();
212
+ const readonlyAny = z.any().readonly();
213
+ const readonlyUnknown = z.unknown().readonly();
214
+ const readonlyVoid = z.void().readonly();
215
+ // const readonlyFunction = z.function(z.tuple([z.string(), z.number()]), z.unknown()).readonly();
216
+ const readonlyStringArray = z.string().array().readonly();
217
+ const readonlyTuple = z.tuple([z.string(), z.number()]).readonly();
218
+
219
+ expectTypeOf<z.infer<typeof readonlyString>>().toEqualTypeOf<string>();
220
+ expectTypeOf<z.infer<typeof readonlyNumber1>>().toEqualTypeOf<number>();
221
+ expectTypeOf<z.infer<typeof readonlyNumber2>>().toEqualTypeOf<number>();
222
+ expectTypeOf<z.infer<typeof readonlyBigInt>>().toEqualTypeOf<bigint>();
223
+ expectTypeOf<z.infer<typeof readonlyBoolean>>().toEqualTypeOf<boolean>();
224
+ expectTypeOf<z.infer<typeof readonlyDate>>().toEqualTypeOf<Date>();
225
+ expectTypeOf<z.infer<typeof readonlyUndefined>>().toEqualTypeOf<undefined>();
226
+ expectTypeOf<z.infer<typeof readonlyNull>>().toEqualTypeOf<null>();
227
+ expectTypeOf<z.infer<typeof readonlyAny>>().toEqualTypeOf<any>();
228
+ expectTypeOf<z.infer<typeof readonlyUnknown>>().toEqualTypeOf<Readonly<unknown>>();
229
+ expectTypeOf<z.infer<typeof readonlyVoid>>().toEqualTypeOf<void>();
230
+ // expectTypeOf<z.infer<typeof readonlyFunction>>().toEqualTypeOf<
231
+ // (args_0: string, args_1: number, ...args_2: unknown[]) => unknown
232
+ // >();
233
+ expectTypeOf<z.infer<typeof readonlyStringArray>>().toEqualTypeOf<readonly string[]>();
234
+ expectTypeOf<z.infer<typeof readonlyTuple>>().toEqualTypeOf<readonly [string, number]>();
235
+
236
+ expect(readonlyString.parse("asdf")).toEqual("asdf");
237
+ expect(readonlyNumber1.parse(1234)).toEqual(1234);
238
+ expect(readonlyNumber2.parse(1234)).toEqual(1234);
239
+ const bigIntVal = BigInt(1);
240
+ expect(readonlyBigInt.parse(bigIntVal)).toEqual(bigIntVal);
241
+ expect(readonlyBoolean.parse(true)).toEqual(true);
242
+ const dateVal = new Date();
243
+ expect(readonlyDate.parse(dateVal)).toEqual(dateVal);
244
+ expect(readonlyUndefined.parse(undefined)).toEqual(undefined);
245
+ expect(readonlyNull.parse(null)).toEqual(null);
246
+ expect(readonlyAny.parse("whatever")).toEqual("whatever");
247
+ expect(readonlyUnknown.parse("whatever")).toEqual("whatever");
248
+ expect(readonlyVoid.parse(undefined)).toEqual(undefined);
249
+ // expect(readonlyFunction.parse(() => void 0)).toEqual(() => void 0);
250
+ expect(readonlyStringArray.parse(["asdf"])).toEqual(["asdf"]);
251
+ expect(readonlyTuple.parse(["asdf", 1234])).toEqual(["asdf", 1234]);
252
+ });
node_modules/@jimp/plugin-threshold/node_modules/zod/src/v4/classic/tests/record.test.ts ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ test("type inference", () => {
5
+ const booleanRecord = z.record(z.string(), z.boolean());
6
+ type booleanRecord = typeof booleanRecord._output;
7
+
8
+ const recordWithEnumKeys = z.record(z.enum(["Tuna", "Salmon"]), z.string());
9
+ type recordWithEnumKeys = z.infer<typeof recordWithEnumKeys>;
10
+
11
+ const recordWithLiteralKey = z.record(z.literal(["Tuna", "Salmon"]), z.string());
12
+ type recordWithLiteralKey = z.infer<typeof recordWithLiteralKey>;
13
+
14
+ const recordWithLiteralUnionKeys = z.record(z.union([z.literal("Tuna"), z.literal("Salmon")]), z.string());
15
+ type recordWithLiteralUnionKeys = z.infer<typeof recordWithLiteralUnionKeys>;
16
+
17
+ expectTypeOf<booleanRecord>().toEqualTypeOf<Record<string, boolean>>();
18
+ expectTypeOf<recordWithEnumKeys>().toEqualTypeOf<Record<"Tuna" | "Salmon", string>>();
19
+ expectTypeOf<recordWithLiteralKey>().toEqualTypeOf<Record<"Tuna" | "Salmon", string>>();
20
+ expectTypeOf<recordWithLiteralUnionKeys>().toEqualTypeOf<Record<"Tuna" | "Salmon", string>>();
21
+ });
22
+
23
+ test("enum exhaustiveness", () => {
24
+ const schema = z.record(z.enum(["Tuna", "Salmon"]), z.string());
25
+ expect(
26
+ schema.parse({
27
+ Tuna: "asdf",
28
+ Salmon: "asdf",
29
+ })
30
+ ).toEqual({
31
+ Tuna: "asdf",
32
+ Salmon: "asdf",
33
+ });
34
+
35
+ expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(`
36
+ {
37
+ "error": [ZodError: [
38
+ {
39
+ "code": "unrecognized_keys",
40
+ "keys": [
41
+ "Trout"
42
+ ],
43
+ "path": [],
44
+ "message": "Unrecognized key: \\"Trout\\""
45
+ }
46
+ ]],
47
+ "success": false,
48
+ }
49
+ `);
50
+ expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(`
51
+ {
52
+ "error": [ZodError: [
53
+ {
54
+ "expected": "string",
55
+ "code": "invalid_type",
56
+ "path": [
57
+ "Salmon"
58
+ ],
59
+ "message": "Invalid input: expected string, received undefined"
60
+ }
61
+ ]],
62
+ "success": false,
63
+ }
64
+ `);
65
+ });
66
+
67
+ test("literal exhaustiveness", () => {
68
+ const schema = z.record(z.literal(["Tuna", "Salmon"]), z.string());
69
+ schema.parse({
70
+ Tuna: "asdf",
71
+ Salmon: "asdf",
72
+ });
73
+
74
+ expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(`
75
+ {
76
+ "error": [ZodError: [
77
+ {
78
+ "code": "unrecognized_keys",
79
+ "keys": [
80
+ "Trout"
81
+ ],
82
+ "path": [],
83
+ "message": "Unrecognized key: \\"Trout\\""
84
+ }
85
+ ]],
86
+ "success": false,
87
+ }
88
+ `);
89
+ expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(`
90
+ {
91
+ "error": [ZodError: [
92
+ {
93
+ "expected": "string",
94
+ "code": "invalid_type",
95
+ "path": [
96
+ "Salmon"
97
+ ],
98
+ "message": "Invalid input: expected string, received undefined"
99
+ }
100
+ ]],
101
+ "success": false,
102
+ }
103
+ `);
104
+ });
105
+
106
+ test("pipe exhaustiveness", () => {
107
+ const schema = z.record(z.enum(["Tuna", "Salmon"]).pipe(z.any()), z.string());
108
+ expect(schema.parse({ Tuna: "asdf", Salmon: "asdf" })).toEqual({
109
+ Tuna: "asdf",
110
+ Salmon: "asdf",
111
+ });
112
+
113
+ expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(`
114
+ {
115
+ "error": [ZodError: [
116
+ {
117
+ "code": "unrecognized_keys",
118
+ "keys": [
119
+ "Trout"
120
+ ],
121
+ "path": [],
122
+ "message": "Unrecognized key: \\"Trout\\""
123
+ }
124
+ ]],
125
+ "success": false,
126
+ }
127
+ `);
128
+ expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(`
129
+ {
130
+ "error": [ZodError: [
131
+ {
132
+ "expected": "string",
133
+ "code": "invalid_type",
134
+ "path": [
135
+ "Salmon"
136
+ ],
137
+ "message": "Invalid input: expected string, received undefined"
138
+ }
139
+ ]],
140
+ "success": false,
141
+ }
142
+ `);
143
+ });
144
+
145
+ test("union exhaustiveness", () => {
146
+ const schema = z.record(z.union([z.literal("Tuna"), z.literal("Salmon")]), z.string());
147
+ expect(schema.parse({ Tuna: "asdf", Salmon: "asdf" })).toEqual({
148
+ Tuna: "asdf",
149
+ Salmon: "asdf",
150
+ });
151
+
152
+ expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(`
153
+ {
154
+ "error": [ZodError: [
155
+ {
156
+ "code": "unrecognized_keys",
157
+ "keys": [
158
+ "Trout"
159
+ ],
160
+ "path": [],
161
+ "message": "Unrecognized key: \\"Trout\\""
162
+ }
163
+ ]],
164
+ "success": false,
165
+ }
166
+ `);
167
+ expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(`
168
+ {
169
+ "error": [ZodError: [
170
+ {
171
+ "expected": "string",
172
+ "code": "invalid_type",
173
+ "path": [
174
+ "Salmon"
175
+ ],
176
+ "message": "Invalid input: expected string, received undefined"
177
+ }
178
+ ]],
179
+ "success": false,
180
+ }
181
+ `);
182
+ });
183
+
184
+ test("string record parse - pass", () => {
185
+ const schema = z.record(z.string(), z.boolean());
186
+ schema.parse({
187
+ k1: true,
188
+ k2: false,
189
+ 1234: false,
190
+ });
191
+
192
+ expect(schema.safeParse({ asdf: 1234 }).success).toEqual(false);
193
+ expect(schema.safeParse("asdf")).toMatchInlineSnapshot(`
194
+ {
195
+ "error": [ZodError: [
196
+ {
197
+ "expected": "record",
198
+ "code": "invalid_type",
199
+ "path": [],
200
+ "message": "Invalid input: expected record, received string"
201
+ }
202
+ ]],
203
+ "success": false,
204
+ }
205
+ `);
206
+ });
207
+
208
+ test("key and value getters", () => {
209
+ const rec = z.record(z.string(), z.number());
210
+
211
+ rec.keyType.parse("asdf");
212
+ rec.valueType.parse(1234);
213
+ });
214
+
215
+ test("is not vulnerable to prototype pollution", async () => {
216
+ const rec = z.record(
217
+ z.string(),
218
+ z.object({
219
+ a: z.string(),
220
+ })
221
+ );
222
+
223
+ const data = JSON.parse(`
224
+ {
225
+ "__proto__": {
226
+ "a": "evil"
227
+ },
228
+ "b": {
229
+ "a": "good"
230
+ }
231
+ }
232
+ `);
233
+
234
+ const obj1 = rec.parse(data);
235
+ expect(obj1.a).toBeUndefined();
236
+
237
+ const obj2 = rec.safeParse(data);
238
+ expect(obj2.success).toBe(true);
239
+ if (obj2.success) {
240
+ expect(obj2.data.a).toBeUndefined();
241
+ }
242
+
243
+ const obj3 = await rec.parseAsync(data);
244
+ expect(obj3.a).toBeUndefined();
245
+
246
+ const obj4 = await rec.safeParseAsync(data);
247
+ expect(obj4.success).toBe(true);
248
+ if (obj4.success) {
249
+ expect(obj4.data.a).toBeUndefined();
250
+ }
251
+ });
252
+
253
+ test("dont remove undefined values", () => {
254
+ const result1 = z.record(z.string(), z.any()).parse({ foo: undefined });
255
+
256
+ expect(result1).toEqual({
257
+ foo: undefined,
258
+ });
259
+ });
260
+
261
+ test("allow undefined values", () => {
262
+ const schema = z.record(z.string(), z.undefined());
263
+
264
+ expect(
265
+ Object.keys(
266
+ schema.parse({
267
+ _test: undefined,
268
+ })
269
+ )
270
+ ).toEqual(["_test"]);
271
+ });
272
+
273
+ test("async parsing", async () => {
274
+ const schema = z
275
+ .record(
276
+ z.string(),
277
+ z
278
+ .string()
279
+ .optional()
280
+ .refine(async () => true)
281
+ )
282
+ .refine(async () => true);
283
+
284
+ const data = {
285
+ foo: "bar",
286
+ baz: "qux",
287
+ };
288
+ const result = await schema.safeParseAsync(data);
289
+ expect(result.data).toEqual(data);
290
+ });
291
+
292
+ test("async parsing", async () => {
293
+ const schema = z
294
+ .record(
295
+ z.string(),
296
+ z
297
+ .string()
298
+ .optional()
299
+ .refine(async () => false)
300
+ )
301
+ .refine(async () => false);
302
+
303
+ const data = {
304
+ foo: "bar",
305
+ baz: "qux",
306
+ };
307
+ const result = await schema.safeParseAsync(data);
308
+ expect(result.success).toEqual(false);
309
+ expect(result.error).toMatchInlineSnapshot(`
310
+ [ZodError: [
311
+ {
312
+ "code": "custom",
313
+ "path": [
314
+ "foo"
315
+ ],
316
+ "message": "Invalid input"
317
+ },
318
+ {
319
+ "code": "custom",
320
+ "path": [
321
+ "baz"
322
+ ],
323
+ "message": "Invalid input"
324
+ },
325
+ {
326
+ "code": "custom",
327
+ "path": [],
328
+ "message": "Invalid input"
329
+ }
330
+ ]]
331
+ `);
332
+ });
333
+
334
+ test("partial record", () => {
335
+ const schema = z.partialRecord(z.string(), z.string());
336
+ type schema = z.infer<typeof schema>;
337
+ expectTypeOf<schema>().toEqualTypeOf<Partial<Record<string, string>>>();
338
+
339
+ const Keys = z.enum(["id", "name", "email"]).or(z.never());
340
+ const Person = z.partialRecord(Keys, z.string());
341
+ expectTypeOf<z.infer<typeof Person>>().toEqualTypeOf<Partial<Record<"id" | "name" | "email", string>>>();
342
+ });