Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 16)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4-mini/index.ts +1 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/assignability.test.ts +129 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/brand.test.ts +51 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/checks.test.ts +144 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/computed.test.ts +36 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/error.test.ts +22 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/functions.test.ts +43 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/index.test.ts +871 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/number.test.ts +95 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/object.test.ts +185 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +275 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/string.test.ts +299 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.cjs +138 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.d.cts +164 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.d.ts +164 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.js +133 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.cjs +17 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.d.cts +5 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.d.ts +5 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.js +9 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.cjs +22 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.d.cts +6 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.d.ts +6 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.js +6 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.cjs +2 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.js +1 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.cjs +9 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.js +6 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.cjs +124 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.js +109 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.cjs +2 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.js +1 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.cjs +2 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.js +1 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.cjs +137 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.d.cts +85 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.d.ts +85 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.js +133 -0
- node_modules/@jimp/plugin-quantize/node_modules/zod/v3/index.cjs +33 -0
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4-mini/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from "../v4/mini/index.js";
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/assignability.test.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { test } from "vitest";
|
| 2 |
+
|
| 3 |
+
import * as z from "zod/v4-mini";
|
| 4 |
+
|
| 5 |
+
test("assignability", () => {
|
| 6 |
+
// $ZodString
|
| 7 |
+
z.string() satisfies z.core.$ZodString;
|
| 8 |
+
|
| 9 |
+
// $ZodNumber
|
| 10 |
+
z.number() satisfies z.core.$ZodNumber;
|
| 11 |
+
|
| 12 |
+
// $ZodBigInt
|
| 13 |
+
z.bigint() satisfies z.core.$ZodBigInt;
|
| 14 |
+
|
| 15 |
+
// $ZodBoolean
|
| 16 |
+
z.boolean() satisfies z.core.$ZodBoolean;
|
| 17 |
+
|
| 18 |
+
// $ZodDate
|
| 19 |
+
z.date() satisfies z.core.$ZodDate;
|
| 20 |
+
|
| 21 |
+
// $ZodSymbol
|
| 22 |
+
z.symbol() satisfies z.core.$ZodSymbol;
|
| 23 |
+
|
| 24 |
+
// $ZodUndefined
|
| 25 |
+
z.undefined() satisfies z.core.$ZodUndefined;
|
| 26 |
+
|
| 27 |
+
// $ZodNullable
|
| 28 |
+
z.nullable(z.string()) satisfies z.core.$ZodNullable;
|
| 29 |
+
|
| 30 |
+
// $ZodNull
|
| 31 |
+
z.null() satisfies z.core.$ZodNull;
|
| 32 |
+
|
| 33 |
+
// $ZodAny
|
| 34 |
+
z.any() satisfies z.core.$ZodAny;
|
| 35 |
+
|
| 36 |
+
// $ZodUnknown
|
| 37 |
+
z.unknown() satisfies z.core.$ZodUnknown;
|
| 38 |
+
|
| 39 |
+
// $ZodNever
|
| 40 |
+
z.never() satisfies z.core.$ZodNever;
|
| 41 |
+
|
| 42 |
+
// $ZodVoid
|
| 43 |
+
z.void() satisfies z.core.$ZodVoid;
|
| 44 |
+
|
| 45 |
+
// $ZodArray
|
| 46 |
+
z.array(z.string()) satisfies z.core.$ZodArray;
|
| 47 |
+
|
| 48 |
+
// $ZodObject
|
| 49 |
+
z.object({ key: z.string() }) satisfies z.core.$ZodObject;
|
| 50 |
+
|
| 51 |
+
// $ZodUnion
|
| 52 |
+
z.union([z.string(), z.number()]) satisfies z.core.$ZodUnion;
|
| 53 |
+
|
| 54 |
+
// $ZodIntersection
|
| 55 |
+
z.intersection(z.string(), z.number()) satisfies z.core.$ZodIntersection;
|
| 56 |
+
|
| 57 |
+
// $ZodTuple
|
| 58 |
+
z.tuple([z.string(), z.number()]) satisfies z.core.$ZodTuple;
|
| 59 |
+
|
| 60 |
+
// $ZodRecord
|
| 61 |
+
z.record(z.string(), z.number()) satisfies z.core.$ZodRecord;
|
| 62 |
+
|
| 63 |
+
// $ZodMap
|
| 64 |
+
z.map(z.string(), z.number()) satisfies z.core.$ZodMap;
|
| 65 |
+
|
| 66 |
+
// $ZodSet
|
| 67 |
+
z.set(z.string()) satisfies z.core.$ZodSet;
|
| 68 |
+
|
| 69 |
+
// $ZodLiteral
|
| 70 |
+
z.literal("example") satisfies z.core.$ZodLiteral;
|
| 71 |
+
|
| 72 |
+
// $ZodEnum
|
| 73 |
+
z.enum(["a", "b", "c"]) satisfies z.core.$ZodEnum;
|
| 74 |
+
|
| 75 |
+
// $ZodPromise
|
| 76 |
+
z.promise(z.string()) satisfies z.core.$ZodPromise;
|
| 77 |
+
|
| 78 |
+
// $ZodLazy
|
| 79 |
+
const lazySchema = z.lazy(() => z.string());
|
| 80 |
+
lazySchema satisfies z.core.$ZodLazy;
|
| 81 |
+
|
| 82 |
+
// $ZodOptional
|
| 83 |
+
z.optional(z.string()) satisfies z.core.$ZodOptional;
|
| 84 |
+
|
| 85 |
+
// $ZodDefault
|
| 86 |
+
z._default(z.string(), "default") satisfies z.core.$ZodDefault;
|
| 87 |
+
|
| 88 |
+
// $ZodTemplateLiteral
|
| 89 |
+
z.templateLiteral([z.literal("a"), z.literal("b")]) satisfies z.core.$ZodTemplateLiteral;
|
| 90 |
+
|
| 91 |
+
// $ZodCustom
|
| 92 |
+
z.custom<string>((val) => typeof val === "string") satisfies z.core.$ZodCustom;
|
| 93 |
+
|
| 94 |
+
// $ZodTransform
|
| 95 |
+
z.transform((val) => val as string) satisfies z.core.$ZodTransform;
|
| 96 |
+
|
| 97 |
+
// $ZodNonOptional
|
| 98 |
+
z.nonoptional(z.optional(z.string())) satisfies z.core.$ZodNonOptional;
|
| 99 |
+
|
| 100 |
+
// $ZodReadonly
|
| 101 |
+
z.readonly(z.object({ key: z.string() })) satisfies z.core.$ZodReadonly;
|
| 102 |
+
|
| 103 |
+
// $ZodNaN
|
| 104 |
+
z.nan() satisfies z.core.$ZodNaN;
|
| 105 |
+
|
| 106 |
+
// $ZodPipe
|
| 107 |
+
z.pipe(z.unknown(), z.number()) satisfies z.core.$ZodPipe;
|
| 108 |
+
|
| 109 |
+
// $ZodSuccess
|
| 110 |
+
z.success(z.string()) satisfies z.core.$ZodSuccess;
|
| 111 |
+
|
| 112 |
+
// $ZodCatch
|
| 113 |
+
z.catch(z.string(), "fallback") satisfies z.core.$ZodCatch;
|
| 114 |
+
|
| 115 |
+
// $ZodFile
|
| 116 |
+
z.file() satisfies z.core.$ZodFile;
|
| 117 |
+
});
|
| 118 |
+
|
| 119 |
+
test("assignability with type narrowing", () => {
|
| 120 |
+
type _RefinedSchema<T extends z.ZodMiniType<object> | z.ZodMiniUnion> = T extends z.ZodMiniUnion
|
| 121 |
+
? RefinedUnionSchema<T> // <-- Type instantiation is excessively deep and possibly infinite.
|
| 122 |
+
: T extends z.ZodMiniType<object>
|
| 123 |
+
? RefinedTypeSchema<z.output<T>> // <-- Type instantiation is excessively deep and possibly infinite.
|
| 124 |
+
: never;
|
| 125 |
+
|
| 126 |
+
type RefinedTypeSchema<T extends object> = T;
|
| 127 |
+
|
| 128 |
+
type RefinedUnionSchema<T extends z.ZodMiniUnion> = T;
|
| 129 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/brand.test.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expectTypeOf, test } from "vitest";
|
| 2 |
+
import * as z from "../index.js";
|
| 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 |
+
// Using true for type equality assertion
|
| 14 |
+
expectTypeOf<MySchema>().toEqualTypeOf<{ name: string } & z.$brand<"superschema">>();
|
| 15 |
+
|
| 16 |
+
const doStuff = (arg: MySchema) => arg;
|
| 17 |
+
doStuff(z.parse(mySchema, { 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(z.parse(extendedSchema, { 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 |
+
type Age1 = z.infer<typeof age>;
|
| 42 |
+
type AgeInput1 = z.input<typeof age>;
|
| 43 |
+
|
| 44 |
+
// Using not for type inequality assertion
|
| 45 |
+
expectTypeOf<AgeInput1>().not.toEqualTypeOf<Age1>();
|
| 46 |
+
expectTypeOf<number>().toEqualTypeOf<AgeInput1>();
|
| 47 |
+
expectTypeOf<number & z.$brand<"age">>().toEqualTypeOf<Age1>();
|
| 48 |
+
|
| 49 |
+
// @ts-expect-error
|
| 50 |
+
doStuff({ name: "hello there!" });
|
| 51 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/checks.test.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, test } from "vitest";
|
| 2 |
+
import * as z from "../index.js";
|
| 3 |
+
|
| 4 |
+
// lt;
|
| 5 |
+
test("z.lt", () => {
|
| 6 |
+
const a = z.number().check(z.lt(10));
|
| 7 |
+
expect(z.safeParse(a, 9).success).toEqual(true);
|
| 8 |
+
expect(z.safeParse(a, 9).data).toEqual(9);
|
| 9 |
+
expect(z.safeParse(a, 10).success).toEqual(false);
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
// lte;
|
| 13 |
+
test("z.lte", () => {
|
| 14 |
+
const a = z.number().check(z.lte(10));
|
| 15 |
+
expect(z.safeParse(a, 10).success).toEqual(true);
|
| 16 |
+
expect(z.safeParse(a, 10).data).toEqual(10);
|
| 17 |
+
expect(z.safeParse(a, 11).success).toEqual(false);
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
// min;
|
| 21 |
+
test("z.max", () => {
|
| 22 |
+
const a = z.number().check(z.maximum(10));
|
| 23 |
+
expect(z.safeParse(a, 10).success).toEqual(true);
|
| 24 |
+
expect(z.safeParse(a, 10).data).toEqual(10);
|
| 25 |
+
expect(z.safeParse(a, 11).success).toEqual(false);
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
// gt;
|
| 29 |
+
test("z.gt", () => {
|
| 30 |
+
const a = z.number().check(z.gt(10));
|
| 31 |
+
expect(z.safeParse(a, 11).success).toEqual(true);
|
| 32 |
+
expect(z.safeParse(a, 11).data).toEqual(11);
|
| 33 |
+
expect(z.safeParse(a, 10).success).toEqual(false);
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
// gte;
|
| 37 |
+
test("z.gte", () => {
|
| 38 |
+
const a = z.number().check(z.gte(10));
|
| 39 |
+
expect(z.safeParse(a, 10).success).toEqual(true);
|
| 40 |
+
expect(z.safeParse(a, 10).data).toEqual(10);
|
| 41 |
+
expect(z.safeParse(a, 9).success).toEqual(false);
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
// min;
|
| 45 |
+
test("z.min", () => {
|
| 46 |
+
const a = z.number().check(z.minimum(10));
|
| 47 |
+
expect(z.safeParse(a, 10).success).toEqual(true);
|
| 48 |
+
expect(z.safeParse(a, 10).data).toEqual(10);
|
| 49 |
+
expect(z.safeParse(a, 9).success).toEqual(false);
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
// maxSize;
|
| 53 |
+
test("z.maxLength", () => {
|
| 54 |
+
const a = z.array(z.string()).check(z.maxLength(3));
|
| 55 |
+
expect(z.safeParse(a, ["a", "b", "c"]).success).toEqual(true);
|
| 56 |
+
expect(z.safeParse(a, ["a", "b", "c", "d"]).success).toEqual(false);
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
// minSize;
|
| 60 |
+
test("z.minLength", () => {
|
| 61 |
+
const a = z.array(z.string()).check(z.minLength(3));
|
| 62 |
+
expect(z.safeParse(a, ["a", "b"]).success).toEqual(false);
|
| 63 |
+
expect(z.safeParse(a, ["a", "b", "c"]).success).toEqual(true);
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
// size;
|
| 67 |
+
test("z.length", () => {
|
| 68 |
+
const a = z.array(z.string()).check(z.length(3));
|
| 69 |
+
expect(z.safeParse(a, ["a", "b"]).success).toEqual(false);
|
| 70 |
+
expect(z.safeParse(a, ["a", "b", "c"]).success).toEqual(true);
|
| 71 |
+
expect(z.safeParse(a, ["a", "b", "c", "d"]).success).toEqual(false);
|
| 72 |
+
});
|
| 73 |
+
|
| 74 |
+
// regex;
|
| 75 |
+
test("z.regex", () => {
|
| 76 |
+
const a = z.string().check(z.regex(/^aaa$/));
|
| 77 |
+
expect(z.safeParse(a, "aaa")).toMatchObject({ success: true, data: "aaa" });
|
| 78 |
+
expect(z.safeParse(a, "aa")).toMatchObject({ success: false });
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
+
// includes;
|
| 82 |
+
test("z.includes", () => {
|
| 83 |
+
const a = z.string().check(z.includes("asdf"));
|
| 84 |
+
z.parse(a, "qqqasdfqqq");
|
| 85 |
+
z.parse(a, "asdf");
|
| 86 |
+
z.parse(a, "qqqasdf");
|
| 87 |
+
z.parse(a, "asdfqqq");
|
| 88 |
+
expect(z.safeParse(a, "qqq")).toMatchObject({ success: false });
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
// startsWith;
|
| 92 |
+
test("z.startsWith", () => {
|
| 93 |
+
const a = z.string().check(z.startsWith("asdf"));
|
| 94 |
+
z.parse(a, "asdf");
|
| 95 |
+
z.parse(a, "asdfqqq");
|
| 96 |
+
expect(z.safeParse(a, "qqq")).toMatchObject({ success: false });
|
| 97 |
+
});
|
| 98 |
+
|
| 99 |
+
// endsWith;
|
| 100 |
+
test("z.endsWith", () => {
|
| 101 |
+
const a = z.string().check(z.endsWith("asdf"));
|
| 102 |
+
z.parse(a, "asdf");
|
| 103 |
+
z.parse(a, "qqqasdf");
|
| 104 |
+
expect(z.safeParse(a, "asdfqqq")).toMatchObject({ success: false });
|
| 105 |
+
});
|
| 106 |
+
|
| 107 |
+
// lowercase;
|
| 108 |
+
test("z.lowercase", () => {
|
| 109 |
+
const a = z.string().check(z.lowercase());
|
| 110 |
+
z.parse(a, "asdf");
|
| 111 |
+
expect(z.safeParse(a, "ASDF")).toMatchObject({ success: false });
|
| 112 |
+
});
|
| 113 |
+
|
| 114 |
+
// uppercase;
|
| 115 |
+
test("z.uppercase", () => {
|
| 116 |
+
const a = z.string().check(z.uppercase());
|
| 117 |
+
z.parse(a, "ASDF");
|
| 118 |
+
expect(z.safeParse(a, "asdf")).toMatchObject({ success: false });
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
// filename;
|
| 122 |
+
// fileType;
|
| 123 |
+
// overwrite;
|
| 124 |
+
test("z.overwrite", () => {
|
| 125 |
+
const a = z.string().check(z.overwrite((val) => val.toUpperCase()));
|
| 126 |
+
expect(z.safeParse(a, "asdf")).toMatchObject({ data: "ASDF" });
|
| 127 |
+
});
|
| 128 |
+
|
| 129 |
+
// normalize;
|
| 130 |
+
// trim;
|
| 131 |
+
// toLowerCase;
|
| 132 |
+
// toUpperCase;
|
| 133 |
+
// property
|
| 134 |
+
|
| 135 |
+
test("abort early", () => {
|
| 136 |
+
const schema = z.string().check(
|
| 137 |
+
z.refine((val) => val.length > 1),
|
| 138 |
+
z.refine((val) => val.length > 2, { abort: true }),
|
| 139 |
+
z.refine((val) => val.length > 3)
|
| 140 |
+
);
|
| 141 |
+
const data = "";
|
| 142 |
+
const result = z.safeParse(schema, data);
|
| 143 |
+
expect(result.error!.issues.length).toEqual(2);
|
| 144 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/computed.test.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 3 |
+
import { util as zc } from "zod/v4/core";
|
| 4 |
+
|
| 5 |
+
test("min/max", () => {
|
| 6 |
+
const a = z.number().check(z.minimum(5), z.minimum(6), z.minimum(7), z.maximum(10), z.maximum(11), z.maximum(12));
|
| 7 |
+
|
| 8 |
+
expect(a._zod.bag.minimum).toEqual(7);
|
| 9 |
+
expect(a._zod.bag.maximum).toEqual(10);
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
test("multipleOf", () => {
|
| 13 |
+
const b = z.number().check(z.multipleOf(5));
|
| 14 |
+
expect(b._zod.bag.multipleOf).toEqual(5);
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
test("int64 format", () => {
|
| 18 |
+
const c = z.int64();
|
| 19 |
+
expect(c._zod.bag.format).toEqual("int64");
|
| 20 |
+
expect(c._zod.bag.minimum).toEqual(zc.BIGINT_FORMAT_RANGES.int64[0]);
|
| 21 |
+
expect(c._zod.bag.maximum).toEqual(zc.BIGINT_FORMAT_RANGES.int64[1]);
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
test("int32 format", () => {
|
| 25 |
+
const d = z.int32();
|
| 26 |
+
expect(d._zod.bag.format).toEqual("int32");
|
| 27 |
+
expect(d._zod.bag.minimum).toEqual(zc.NUMBER_FORMAT_RANGES.int32[0]);
|
| 28 |
+
expect(d._zod.bag.maximum).toEqual(zc.NUMBER_FORMAT_RANGES.int32[1]);
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
test("array size", () => {
|
| 32 |
+
const e = z.array(z.string()).check(z.length(5));
|
| 33 |
+
expect(e._zod.bag.length).toEqual(5);
|
| 34 |
+
expect(e._zod.bag.minimum).toEqual(5);
|
| 35 |
+
expect(e._zod.bag.maximum).toEqual(5);
|
| 36 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/error.test.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 3 |
+
|
| 4 |
+
test("no locale by default", () => {
|
| 5 |
+
const result = z.safeParse(z.string(), 12);
|
| 6 |
+
expect(result.success).toEqual(false);
|
| 7 |
+
expect(result.error!.issues.length).toEqual(1);
|
| 8 |
+
expect(result.error!.issues[0].message).toEqual("Invalid input");
|
| 9 |
+
});
|
| 10 |
+
|
| 11 |
+
test("error inheritance", () => {
|
| 12 |
+
const e1 = z.string().safeParse(123).error!;
|
| 13 |
+
expect(e1).toBeInstanceOf(z.core.$ZodError);
|
| 14 |
+
// expect(e1).not.toBeInstanceOf(Error);
|
| 15 |
+
|
| 16 |
+
try {
|
| 17 |
+
z.string().parse(123);
|
| 18 |
+
} catch (e2) {
|
| 19 |
+
expect(e2).toBeInstanceOf(z.core.$ZodRealError);
|
| 20 |
+
expect(e2).toBeInstanceOf(Error);
|
| 21 |
+
}
|
| 22 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/functions.test.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, test } from "vitest";
|
| 2 |
+
// import * as z from "zod/v4/core";
|
| 3 |
+
|
| 4 |
+
test("z.function", () => {
|
| 5 |
+
expect(true).toEqual(true);
|
| 6 |
+
});
|
| 7 |
+
|
| 8 |
+
// test("z.function", () => {
|
| 9 |
+
// const a = z.function({
|
| 10 |
+
// args: z.tuple([z.string()]),
|
| 11 |
+
// returns: z.string(),
|
| 12 |
+
// });
|
| 13 |
+
|
| 14 |
+
// const myFunc = a.implement((name: string | number) => `Hello, ${name}!`);
|
| 15 |
+
|
| 16 |
+
// expect(myFunc("world")).toEqual("Hello, world!");
|
| 17 |
+
// expect(() => myFunc(123 as any)).toThrow();
|
| 18 |
+
|
| 19 |
+
// // this won't run
|
| 20 |
+
// () => {
|
| 21 |
+
// // @ts-expect-error
|
| 22 |
+
// const r = myFunc(123);
|
| 23 |
+
// expectTypeOf(r).toEqualTypeOf<string>();
|
| 24 |
+
// };
|
| 25 |
+
// });
|
| 26 |
+
|
| 27 |
+
// test("z.function async", async () => {
|
| 28 |
+
// const b = z.function({
|
| 29 |
+
// args: z.tuple([z.string()]).$check(async (_) => {}),
|
| 30 |
+
// returns: z.string().$check(async (_) => {}),
|
| 31 |
+
// });
|
| 32 |
+
// const myFuncAsync = b.implementAsync(async (name) => `Hello, ${name}!`);
|
| 33 |
+
|
| 34 |
+
// expect(await myFuncAsync("world")).toEqual("Hello, world!");
|
| 35 |
+
// expect(myFuncAsync(123 as any)).rejects.toThrow();
|
| 36 |
+
|
| 37 |
+
// // this won't run
|
| 38 |
+
// () => {
|
| 39 |
+
// // @ts-expect-error
|
| 40 |
+
// const r = myFuncAsync(123);
|
| 41 |
+
// expectTypeOf(r).toEqualTypeOf<Promise<string>>();
|
| 42 |
+
// };
|
| 43 |
+
// });
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/index.test.ts
ADDED
|
@@ -0,0 +1,871 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, expectTypeOf, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 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 |
+
});
|
| 270 |
+
|
| 271 |
+
test("z.record", () => {
|
| 272 |
+
// record schema with enum keys
|
| 273 |
+
const a = z.record(z.string(), z.string());
|
| 274 |
+
type a = z.output<typeof a>;
|
| 275 |
+
expectTypeOf<a>().toEqualTypeOf<Record<string, string>>();
|
| 276 |
+
|
| 277 |
+
const b = z.record(z.union([z.string(), z.number(), z.symbol()]), z.string());
|
| 278 |
+
type b = z.output<typeof b>;
|
| 279 |
+
expectTypeOf<b>().toEqualTypeOf<Record<string | number | symbol, string>>();
|
| 280 |
+
expect(z.parse(b, { a: "hello", 1: "world", [Symbol.for("asdf")]: "symbol" })).toEqual({
|
| 281 |
+
a: "hello",
|
| 282 |
+
1: "world",
|
| 283 |
+
[Symbol.for("asdf")]: "symbol",
|
| 284 |
+
});
|
| 285 |
+
|
| 286 |
+
// enum keys
|
| 287 |
+
const c = z.record(z.enum(["a", "b", "c"]), z.string());
|
| 288 |
+
type c = z.output<typeof c>;
|
| 289 |
+
expectTypeOf<c>().toEqualTypeOf<Record<"a" | "b" | "c", string>>();
|
| 290 |
+
expect(z.parse(c, { a: "hello", b: "world", c: "world" })).toEqual({
|
| 291 |
+
a: "hello",
|
| 292 |
+
b: "world",
|
| 293 |
+
c: "world",
|
| 294 |
+
});
|
| 295 |
+
// missing keys
|
| 296 |
+
expect(() => z.parse(c, { a: "hello", b: "world" })).toThrow();
|
| 297 |
+
// extra keys
|
| 298 |
+
expect(() => z.parse(c, { a: "hello", b: "world", c: "world", d: "world" })).toThrow();
|
| 299 |
+
});
|
| 300 |
+
|
| 301 |
+
test("z.map", () => {
|
| 302 |
+
const a = z.map(z.string(), z.number());
|
| 303 |
+
type a = z.output<typeof a>;
|
| 304 |
+
expectTypeOf<a>().toEqualTypeOf<Map<string, number>>();
|
| 305 |
+
expect(z.parse(a, new Map([["hello", 123]]))).toEqual(new Map([["hello", 123]]));
|
| 306 |
+
expect(() => z.parse(a, new Map([["hello", "world"]]))).toThrow();
|
| 307 |
+
expect(() => z.parse(a, new Map([[1243, "world"]]))).toThrow();
|
| 308 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 309 |
+
|
| 310 |
+
const r1 = z.safeParse(a, new Map([[123, 123]]));
|
| 311 |
+
expect(r1.error?.issues[0].code).toEqual("invalid_type");
|
| 312 |
+
expect(r1.error?.issues[0].path).toEqual([123]);
|
| 313 |
+
|
| 314 |
+
const r2: any = z.safeParse(a, new Map([[BigInt(123), 123]]));
|
| 315 |
+
expect(r2.error!.issues[0].code).toEqual("invalid_key");
|
| 316 |
+
expect(r2.error!.issues[0].path).toEqual([]);
|
| 317 |
+
|
| 318 |
+
const r3: any = z.safeParse(a, new Map([["hello", "world"]]));
|
| 319 |
+
expect(r3.error!.issues[0].code).toEqual("invalid_type");
|
| 320 |
+
expect(r3.error!.issues[0].path).toEqual(["hello"]);
|
| 321 |
+
});
|
| 322 |
+
|
| 323 |
+
test("z.map invalid_element", () => {
|
| 324 |
+
const a = z.map(z.bigint(), z.number());
|
| 325 |
+
const r1 = z.safeParse(a, new Map([[BigInt(123), BigInt(123)]]));
|
| 326 |
+
|
| 327 |
+
expect(r1.error!.issues[0].code).toEqual("invalid_element");
|
| 328 |
+
expect(r1.error!.issues[0].path).toEqual([]);
|
| 329 |
+
});
|
| 330 |
+
|
| 331 |
+
test("z.map async", async () => {
|
| 332 |
+
const a = z.map(z.string().check(z.refine(async () => true)), z.number().check(z.refine(async () => true)));
|
| 333 |
+
const d1 = new Map([["hello", 123]]);
|
| 334 |
+
expect(await z.parseAsync(a, d1)).toEqual(d1);
|
| 335 |
+
|
| 336 |
+
await expect(z.parseAsync(a, new Map([[123, 123]]))).rejects.toThrow();
|
| 337 |
+
await expect(z.parseAsync(a, new Map([["hi", "world"]]))).rejects.toThrow();
|
| 338 |
+
await expect(z.parseAsync(a, new Map([[1243, "world"]]))).rejects.toThrow();
|
| 339 |
+
await expect(z.parseAsync(a, "hello")).rejects.toThrow();
|
| 340 |
+
|
| 341 |
+
const r = await z.safeParseAsync(a, new Map([[123, 123]]));
|
| 342 |
+
expect(r.success).toEqual(false);
|
| 343 |
+
expect(r.error!.issues[0].code).toEqual("invalid_type");
|
| 344 |
+
expect(r.error!.issues[0].path).toEqual([123]);
|
| 345 |
+
});
|
| 346 |
+
|
| 347 |
+
test("z.set", () => {
|
| 348 |
+
const a = z.set(z.string());
|
| 349 |
+
type a = z.output<typeof a>;
|
| 350 |
+
expectTypeOf<a>().toEqualTypeOf<Set<string>>();
|
| 351 |
+
expect(z.parse(a, new Set(["hello", "world"]))).toEqual(new Set(["hello", "world"]));
|
| 352 |
+
expect(() => z.parse(a, new Set([123]))).toThrow();
|
| 353 |
+
expect(() => z.parse(a, ["hello", "world"])).toThrow();
|
| 354 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 355 |
+
|
| 356 |
+
const b = z.set(z.number());
|
| 357 |
+
expect(z.parse(b, new Set([1, 2, 3]))).toEqual(new Set([1, 2, 3]));
|
| 358 |
+
expect(() => z.parse(b, new Set(["hello"]))).toThrow();
|
| 359 |
+
expect(() => z.parse(b, [1, 2, 3])).toThrow();
|
| 360 |
+
expect(() => z.parse(b, 123)).toThrow();
|
| 361 |
+
});
|
| 362 |
+
|
| 363 |
+
test("z.enum", () => {
|
| 364 |
+
const a = z.enum(["A", "B", "C"]);
|
| 365 |
+
type a = z.output<typeof a>;
|
| 366 |
+
expectTypeOf<a>().toEqualTypeOf<"A" | "B" | "C">();
|
| 367 |
+
expect(z.parse(a, "A")).toEqual("A");
|
| 368 |
+
expect(z.parse(a, "B")).toEqual("B");
|
| 369 |
+
expect(z.parse(a, "C")).toEqual("C");
|
| 370 |
+
expect(() => z.parse(a, "D")).toThrow();
|
| 371 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 372 |
+
|
| 373 |
+
// expect(a.enum.A).toEqual("A");
|
| 374 |
+
// expect(a.enum.B).toEqual("B");
|
| 375 |
+
// expect(a.enum.C).toEqual("C");
|
| 376 |
+
// expect((a.enum as any).D).toEqual(undefined);
|
| 377 |
+
});
|
| 378 |
+
|
| 379 |
+
test("z.enum - native", () => {
|
| 380 |
+
enum NativeEnum {
|
| 381 |
+
A = "A",
|
| 382 |
+
B = "B",
|
| 383 |
+
C = "C",
|
| 384 |
+
}
|
| 385 |
+
const a = z.enum(NativeEnum);
|
| 386 |
+
type a = z.output<typeof a>;
|
| 387 |
+
expectTypeOf<a>().toEqualTypeOf<NativeEnum>();
|
| 388 |
+
expect(z.parse(a, NativeEnum.A)).toEqual(NativeEnum.A);
|
| 389 |
+
expect(z.parse(a, NativeEnum.B)).toEqual(NativeEnum.B);
|
| 390 |
+
expect(z.parse(a, NativeEnum.C)).toEqual(NativeEnum.C);
|
| 391 |
+
expect(() => z.parse(a, "D")).toThrow();
|
| 392 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 393 |
+
|
| 394 |
+
// test a.enum
|
| 395 |
+
a;
|
| 396 |
+
// expect(a.enum.A).toEqual(NativeEnum.A);
|
| 397 |
+
// expect(a.enum.B).toEqual(NativeEnum.B);
|
| 398 |
+
// expect(a.enum.C).toEqual(NativeEnum.C);
|
| 399 |
+
});
|
| 400 |
+
|
| 401 |
+
test("z.nativeEnum", () => {
|
| 402 |
+
enum NativeEnum {
|
| 403 |
+
A = "A",
|
| 404 |
+
B = "B",
|
| 405 |
+
C = "C",
|
| 406 |
+
}
|
| 407 |
+
const a = z.nativeEnum(NativeEnum);
|
| 408 |
+
type a = z.output<typeof a>;
|
| 409 |
+
expectTypeOf<a>().toEqualTypeOf<NativeEnum>();
|
| 410 |
+
expect(z.parse(a, NativeEnum.A)).toEqual(NativeEnum.A);
|
| 411 |
+
expect(z.parse(a, NativeEnum.B)).toEqual(NativeEnum.B);
|
| 412 |
+
expect(z.parse(a, NativeEnum.C)).toEqual(NativeEnum.C);
|
| 413 |
+
expect(() => z.parse(a, "D")).toThrow();
|
| 414 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 415 |
+
|
| 416 |
+
// test a.enum
|
| 417 |
+
a;
|
| 418 |
+
// expect(a.enum.A).toEqual(NativeEnum.A);
|
| 419 |
+
// expect(a.enum.B).toEqual(NativeEnum.B);
|
| 420 |
+
// expect(a.enum.C).toEqual(NativeEnum.C);
|
| 421 |
+
});
|
| 422 |
+
|
| 423 |
+
test("z.literal", () => {
|
| 424 |
+
const a = z.literal("hello");
|
| 425 |
+
type a = z.output<typeof a>;
|
| 426 |
+
expectTypeOf<a>().toEqualTypeOf<"hello">();
|
| 427 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 428 |
+
expect(() => z.parse(a, "world")).toThrow();
|
| 429 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 430 |
+
|
| 431 |
+
z.literal(["adf"] as const);
|
| 432 |
+
});
|
| 433 |
+
|
| 434 |
+
test("z.file", () => {
|
| 435 |
+
const a = z.file();
|
| 436 |
+
const file = new File(["content"], "filename.txt", { type: "text/plain" });
|
| 437 |
+
expect(z.parse(a, file)).toEqual(file);
|
| 438 |
+
expect(() => z.parse(a, "file")).toThrow();
|
| 439 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 440 |
+
});
|
| 441 |
+
|
| 442 |
+
test("z.transform", () => {
|
| 443 |
+
const a = z.pipe(
|
| 444 |
+
z.string(),
|
| 445 |
+
z.transform((val) => val.toUpperCase())
|
| 446 |
+
);
|
| 447 |
+
type a = z.output<typeof a>;
|
| 448 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 449 |
+
expect(z.parse(a, "hello")).toEqual("HELLO");
|
| 450 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 451 |
+
});
|
| 452 |
+
|
| 453 |
+
test("z.transform async", async () => {
|
| 454 |
+
const a = z.pipe(
|
| 455 |
+
z.string(),
|
| 456 |
+
z.transform(async (val) => val.toUpperCase())
|
| 457 |
+
);
|
| 458 |
+
type a = z.output<typeof a>;
|
| 459 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 460 |
+
expect(await z.parseAsync(a, "hello")).toEqual("HELLO");
|
| 461 |
+
await expect(() => z.parseAsync(a, 123)).rejects.toThrow();
|
| 462 |
+
});
|
| 463 |
+
|
| 464 |
+
test("z.preprocess", () => {
|
| 465 |
+
const a = z.pipe(
|
| 466 |
+
z.transform((val) => String(val).toUpperCase()),
|
| 467 |
+
z.string()
|
| 468 |
+
);
|
| 469 |
+
type a = z.output<typeof a>;
|
| 470 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 471 |
+
expect(z.parse(a, 123)).toEqual("123");
|
| 472 |
+
expect(z.parse(a, true)).toEqual("TRUE");
|
| 473 |
+
expect(z.parse(a, BigInt(1234))).toEqual("1234");
|
| 474 |
+
// expect(() => z.parse(a, Symbol("asdf"))).toThrow();
|
| 475 |
+
});
|
| 476 |
+
|
| 477 |
+
// test("z.preprocess async", () => {
|
| 478 |
+
// const a = z.preprocess(async (val) => String(val), z.string());
|
| 479 |
+
// type a = z.output<typeof a>;
|
| 480 |
+
// expectTypeOf<a>().toEqualTypeOf<string>();
|
| 481 |
+
// expect(z.parse(a, 123)).toEqual("123");
|
| 482 |
+
// expect(z.parse(a, true)).toEqual("true");
|
| 483 |
+
// expect(() => z.parse(a, {})).toThrow();
|
| 484 |
+
// });
|
| 485 |
+
|
| 486 |
+
test("z.optional", () => {
|
| 487 |
+
const a = z.optional(z.string());
|
| 488 |
+
type a = z.output<typeof a>;
|
| 489 |
+
expectTypeOf<a>().toEqualTypeOf<string | undefined>();
|
| 490 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 491 |
+
expect(z.parse(a, undefined)).toEqual(undefined);
|
| 492 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 493 |
+
});
|
| 494 |
+
|
| 495 |
+
test("z.nullable", () => {
|
| 496 |
+
const a = z.nullable(z.string());
|
| 497 |
+
type a = z.output<typeof a>;
|
| 498 |
+
expectTypeOf<a>().toEqualTypeOf<string | null>();
|
| 499 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 500 |
+
expect(z.parse(a, null)).toEqual(null);
|
| 501 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 502 |
+
});
|
| 503 |
+
|
| 504 |
+
test("z.default", () => {
|
| 505 |
+
const a = z._default(z.string(), "default");
|
| 506 |
+
type a = z.output<typeof a>;
|
| 507 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 508 |
+
expect(z.parse(a, undefined)).toEqual("default");
|
| 509 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 510 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 511 |
+
|
| 512 |
+
const b = z._default(z.string(), () => "default");
|
| 513 |
+
expect(z.parse(b, undefined)).toEqual("default");
|
| 514 |
+
expect(z.parse(b, "hello")).toEqual("hello");
|
| 515 |
+
expect(() => z.parse(b, 123)).toThrow();
|
| 516 |
+
});
|
| 517 |
+
|
| 518 |
+
test("z.catch", () => {
|
| 519 |
+
const a = z.catch(z.string(), "default");
|
| 520 |
+
type a = z.output<typeof a>;
|
| 521 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 522 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 523 |
+
expect(z.parse(a, 123)).toEqual("default");
|
| 524 |
+
|
| 525 |
+
const b = z.catch(z.string(), () => "default");
|
| 526 |
+
expect(z.parse(b, "hello")).toEqual("hello");
|
| 527 |
+
expect(z.parse(b, 123)).toEqual("default");
|
| 528 |
+
|
| 529 |
+
const c = z.catch(z.string(), (ctx) => {
|
| 530 |
+
return `${ctx.error.issues.length}issues`;
|
| 531 |
+
});
|
| 532 |
+
expect(z.parse(c, 1234)).toEqual("1issues");
|
| 533 |
+
});
|
| 534 |
+
|
| 535 |
+
test("z.nan", () => {
|
| 536 |
+
const a = z.nan();
|
| 537 |
+
type a = z.output<typeof a>;
|
| 538 |
+
expectTypeOf<a>().toEqualTypeOf<number>();
|
| 539 |
+
expect(z.parse(a, Number.NaN)).toEqual(Number.NaN);
|
| 540 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 541 |
+
expect(() => z.parse(a, "NaN")).toThrow();
|
| 542 |
+
});
|
| 543 |
+
|
| 544 |
+
test("z.pipe", () => {
|
| 545 |
+
const a = z.pipe(
|
| 546 |
+
z.pipe(
|
| 547 |
+
z.string(),
|
| 548 |
+
z.transform((val) => val.length)
|
| 549 |
+
),
|
| 550 |
+
z.number()
|
| 551 |
+
);
|
| 552 |
+
type a_in = z.input<typeof a>;
|
| 553 |
+
expectTypeOf<a_in>().toEqualTypeOf<string>();
|
| 554 |
+
type a_out = z.output<typeof a>;
|
| 555 |
+
expectTypeOf<a_out>().toEqualTypeOf<number>();
|
| 556 |
+
|
| 557 |
+
expect(z.parse(a, "123")).toEqual(3);
|
| 558 |
+
expect(z.parse(a, "hello")).toEqual(5);
|
| 559 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 560 |
+
});
|
| 561 |
+
|
| 562 |
+
test("z.readonly", () => {
|
| 563 |
+
const a = z.readonly(z.string());
|
| 564 |
+
type a = z.output<typeof a>;
|
| 565 |
+
expectTypeOf<a>().toEqualTypeOf<Readonly<string>>();
|
| 566 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 567 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 568 |
+
});
|
| 569 |
+
|
| 570 |
+
test("z.templateLiteral", () => {
|
| 571 |
+
const a = z.templateLiteral([z.string(), z.number()]);
|
| 572 |
+
type a = z.output<typeof a>;
|
| 573 |
+
expectTypeOf<a>().toEqualTypeOf<`${string}${number}`>();
|
| 574 |
+
expect(z.parse(a, "hello123")).toEqual("hello123");
|
| 575 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 576 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 577 |
+
|
| 578 |
+
// multipart
|
| 579 |
+
const b = z.templateLiteral([z.string(), z.number(), z.string()]);
|
| 580 |
+
type b = z.output<typeof b>;
|
| 581 |
+
expectTypeOf<b>().toEqualTypeOf<`${string}${number}${string}`>();
|
| 582 |
+
expect(z.parse(b, "hello123world")).toEqual("hello123world");
|
| 583 |
+
expect(z.parse(b, "123")).toEqual("123");
|
| 584 |
+
expect(() => z.parse(b, "hello")).toThrow();
|
| 585 |
+
expect(() => z.parse(b, 123)).toThrow();
|
| 586 |
+
|
| 587 |
+
// include boolean
|
| 588 |
+
const c = z.templateLiteral([z.string(), z.boolean()]);
|
| 589 |
+
type c = z.output<typeof c>;
|
| 590 |
+
expectTypeOf<c>().toEqualTypeOf<`${string}${boolean}`>();
|
| 591 |
+
expect(z.parse(c, "hellotrue")).toEqual("hellotrue");
|
| 592 |
+
expect(z.parse(c, "hellofalse")).toEqual("hellofalse");
|
| 593 |
+
expect(() => z.parse(c, "hello")).toThrow();
|
| 594 |
+
expect(() => z.parse(c, 123)).toThrow();
|
| 595 |
+
|
| 596 |
+
// include literal prefix
|
| 597 |
+
const d = z.templateLiteral([z.literal("hello"), z.number()]);
|
| 598 |
+
type d = z.output<typeof d>;
|
| 599 |
+
expectTypeOf<d>().toEqualTypeOf<`hello${number}`>();
|
| 600 |
+
expect(z.parse(d, "hello123")).toEqual("hello123");
|
| 601 |
+
expect(() => z.parse(d, 123)).toThrow();
|
| 602 |
+
expect(() => z.parse(d, "world123")).toThrow();
|
| 603 |
+
|
| 604 |
+
// include literal union
|
| 605 |
+
const e = z.templateLiteral([z.literal(["aa", "bb"]), z.number()]);
|
| 606 |
+
type e = z.output<typeof e>;
|
| 607 |
+
expectTypeOf<e>().toEqualTypeOf<`aa${number}` | `bb${number}`>();
|
| 608 |
+
expect(z.parse(e, "aa123")).toEqual("aa123");
|
| 609 |
+
expect(z.parse(e, "bb123")).toEqual("bb123");
|
| 610 |
+
expect(() => z.parse(e, "cc123")).toThrow();
|
| 611 |
+
expect(() => z.parse(e, 123)).toThrow();
|
| 612 |
+
});
|
| 613 |
+
|
| 614 |
+
// this returns both a schema and a check
|
| 615 |
+
test("z.custom", () => {
|
| 616 |
+
const a = z.custom((val) => {
|
| 617 |
+
return typeof val === "string";
|
| 618 |
+
});
|
| 619 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 620 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 621 |
+
|
| 622 |
+
const b = z.string().check(z.custom((val) => val.length > 3));
|
| 623 |
+
|
| 624 |
+
expect(z.parse(b, "hello")).toEqual("hello");
|
| 625 |
+
expect(() => z.parse(b, "hi")).toThrow();
|
| 626 |
+
});
|
| 627 |
+
|
| 628 |
+
test("z.check", () => {
|
| 629 |
+
// this is a more flexible version of z.custom that accepts an arbitrary _parse logic
|
| 630 |
+
// the function should return core.$ZodResult
|
| 631 |
+
const a = z.any().check(
|
| 632 |
+
z.check<string>((ctx) => {
|
| 633 |
+
if (typeof ctx.value === "string") return;
|
| 634 |
+
ctx.issues.push({
|
| 635 |
+
code: "custom",
|
| 636 |
+
origin: "custom",
|
| 637 |
+
message: "Expected a string",
|
| 638 |
+
input: ctx.value,
|
| 639 |
+
});
|
| 640 |
+
})
|
| 641 |
+
);
|
| 642 |
+
expect(z.safeParse(a, "hello")).toMatchObject({
|
| 643 |
+
success: true,
|
| 644 |
+
data: "hello",
|
| 645 |
+
});
|
| 646 |
+
expect(z.safeParse(a, 123)).toMatchObject({
|
| 647 |
+
success: false,
|
| 648 |
+
error: { issues: [{ code: "custom", message: "Expected a string" }] },
|
| 649 |
+
});
|
| 650 |
+
});
|
| 651 |
+
|
| 652 |
+
test("z.instanceof", () => {
|
| 653 |
+
class A {}
|
| 654 |
+
|
| 655 |
+
const a = z.instanceof(A);
|
| 656 |
+
expect(z.parse(a, new A())).toBeInstanceOf(A);
|
| 657 |
+
expect(() => z.parse(a, {})).toThrow();
|
| 658 |
+
});
|
| 659 |
+
|
| 660 |
+
test("z.refine", () => {
|
| 661 |
+
const a = z.number().check(
|
| 662 |
+
z.refine((val) => val > 3),
|
| 663 |
+
z.refine((val) => val < 10)
|
| 664 |
+
);
|
| 665 |
+
expect(z.parse(a, 5)).toEqual(5);
|
| 666 |
+
expect(() => z.parse(a, 2)).toThrow();
|
| 667 |
+
expect(() => z.parse(a, 11)).toThrow();
|
| 668 |
+
expect(() => z.parse(a, "hi")).toThrow();
|
| 669 |
+
});
|
| 670 |
+
|
| 671 |
+
// test("z.superRefine", () => {
|
| 672 |
+
// const a = z.number([
|
| 673 |
+
// z.superRefine((val, ctx) => {
|
| 674 |
+
// if (val < 3) {
|
| 675 |
+
// return ctx.addIssue({
|
| 676 |
+
// code: "custom",
|
| 677 |
+
// origin: "custom",
|
| 678 |
+
// message: "Too small",
|
| 679 |
+
// input: val,
|
| 680 |
+
// });
|
| 681 |
+
// }
|
| 682 |
+
// if (val > 10) {
|
| 683 |
+
// return ctx.addIssue("Too big");
|
| 684 |
+
// }
|
| 685 |
+
// }),
|
| 686 |
+
// ]);
|
| 687 |
+
|
| 688 |
+
// expect(z.parse(a, 5)).toEqual(5);
|
| 689 |
+
// expect(() => z.parse(a, 2)).toThrow();
|
| 690 |
+
// expect(() => z.parse(a, 11)).toThrow();
|
| 691 |
+
// expect(() => z.parse(a, "hi")).toThrow();
|
| 692 |
+
// });
|
| 693 |
+
|
| 694 |
+
test("z.transform", () => {
|
| 695 |
+
const a = z.transform((val: number) => {
|
| 696 |
+
return `${val}`;
|
| 697 |
+
});
|
| 698 |
+
type a_in = z.input<typeof a>;
|
| 699 |
+
expectTypeOf<a_in>().toEqualTypeOf<number>();
|
| 700 |
+
type a_out = z.output<typeof a>;
|
| 701 |
+
expectTypeOf<a_out>().toEqualTypeOf<string>();
|
| 702 |
+
expect(z.parse(a, 123)).toEqual("123");
|
| 703 |
+
});
|
| 704 |
+
|
| 705 |
+
test("z.$brand()", () => {
|
| 706 |
+
const a = z.string().brand<"my-brand">();
|
| 707 |
+
type a = z.output<typeof a>;
|
| 708 |
+
const branded = (_: a) => {};
|
| 709 |
+
// @ts-expect-error
|
| 710 |
+
branded("asdf");
|
| 711 |
+
});
|
| 712 |
+
|
| 713 |
+
test("z.lazy", () => {
|
| 714 |
+
const a = z.lazy(() => z.string());
|
| 715 |
+
type a = z.output<typeof a>;
|
| 716 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 717 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 718 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 719 |
+
});
|
| 720 |
+
|
| 721 |
+
// schema that validates JSON-like data
|
| 722 |
+
test("z.json", () => {
|
| 723 |
+
const a = z.json();
|
| 724 |
+
type a = z.output<typeof a>;
|
| 725 |
+
a._zod.output;
|
| 726 |
+
|
| 727 |
+
expectTypeOf<a>().toEqualTypeOf<util.JSONType>();
|
| 728 |
+
|
| 729 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 730 |
+
expect(z.parse(a, 123)).toEqual(123);
|
| 731 |
+
expect(z.parse(a, true)).toEqual(true);
|
| 732 |
+
expect(z.parse(a, null)).toEqual(null);
|
| 733 |
+
expect(z.parse(a, {})).toEqual({});
|
| 734 |
+
expect(z.parse(a, { a: "hello" })).toEqual({ a: "hello" });
|
| 735 |
+
expect(z.parse(a, [1, 2, 3])).toEqual([1, 2, 3]);
|
| 736 |
+
expect(z.parse(a, [{ a: "hello" }])).toEqual([{ a: "hello" }]);
|
| 737 |
+
|
| 738 |
+
// fail cases
|
| 739 |
+
expect(() => z.parse(a, new Date())).toThrow();
|
| 740 |
+
expect(() => z.parse(a, Symbol())).toThrow();
|
| 741 |
+
expect(() => z.parse(a, { a: new Date() })).toThrow();
|
| 742 |
+
expect(() => z.parse(a, undefined)).toThrow();
|
| 743 |
+
expect(() => z.parse(a, { a: undefined })).toThrow();
|
| 744 |
+
});
|
| 745 |
+
|
| 746 |
+
test("z.stringbool", () => {
|
| 747 |
+
const a = z.stringbool();
|
| 748 |
+
|
| 749 |
+
expect(z.parse(a, "true")).toEqual(true);
|
| 750 |
+
expect(z.parse(a, "yes")).toEqual(true);
|
| 751 |
+
expect(z.parse(a, "1")).toEqual(true);
|
| 752 |
+
expect(z.parse(a, "on")).toEqual(true);
|
| 753 |
+
expect(z.parse(a, "y")).toEqual(true);
|
| 754 |
+
expect(z.parse(a, "enabled")).toEqual(true);
|
| 755 |
+
expect(z.parse(a, "TRUE")).toEqual(true);
|
| 756 |
+
|
| 757 |
+
expect(z.parse(a, "false")).toEqual(false);
|
| 758 |
+
expect(z.parse(a, "no")).toEqual(false);
|
| 759 |
+
expect(z.parse(a, "0")).toEqual(false);
|
| 760 |
+
expect(z.parse(a, "off")).toEqual(false);
|
| 761 |
+
expect(z.parse(a, "n")).toEqual(false);
|
| 762 |
+
expect(z.parse(a, "disabled")).toEqual(false);
|
| 763 |
+
expect(z.parse(a, "FALSE")).toEqual(false);
|
| 764 |
+
|
| 765 |
+
expect(z.safeParse(a, "other")).toMatchObject({ success: false });
|
| 766 |
+
expect(z.safeParse(a, "")).toMatchObject({ success: false });
|
| 767 |
+
expect(z.safeParse(a, undefined)).toMatchObject({ success: false });
|
| 768 |
+
expect(z.safeParse(a, {})).toMatchObject({ success: false });
|
| 769 |
+
expect(z.safeParse(a, true)).toMatchObject({ success: false });
|
| 770 |
+
expect(z.safeParse(a, false)).toMatchObject({ success: false });
|
| 771 |
+
|
| 772 |
+
const b = z.stringbool({
|
| 773 |
+
truthy: ["y"],
|
| 774 |
+
falsy: ["n"],
|
| 775 |
+
});
|
| 776 |
+
expect(z.parse(b, "y")).toEqual(true);
|
| 777 |
+
expect(z.parse(b, "n")).toEqual(false);
|
| 778 |
+
expect(z.safeParse(b, "true")).toMatchObject({ success: false });
|
| 779 |
+
expect(z.safeParse(b, "false")).toMatchObject({ success: false });
|
| 780 |
+
|
| 781 |
+
const c = z.stringbool({
|
| 782 |
+
case: "sensitive",
|
| 783 |
+
});
|
| 784 |
+
expect(z.parse(c, "true")).toEqual(true);
|
| 785 |
+
expect(z.safeParse(c, "TRUE")).toMatchObject({ success: false });
|
| 786 |
+
});
|
| 787 |
+
|
| 788 |
+
// promise
|
| 789 |
+
test("z.promise", async () => {
|
| 790 |
+
const a = z.promise(z.string());
|
| 791 |
+
type a = z.output<typeof a>;
|
| 792 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 793 |
+
|
| 794 |
+
expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
|
| 795 |
+
success: true,
|
| 796 |
+
data: "hello",
|
| 797 |
+
});
|
| 798 |
+
expect(await z.safeParseAsync(a, Promise.resolve(123))).toMatchObject({
|
| 799 |
+
success: false,
|
| 800 |
+
});
|
| 801 |
+
|
| 802 |
+
const b = z.string();
|
| 803 |
+
expect(() => z.parse(b, Promise.resolve("hello"))).toThrow();
|
| 804 |
+
});
|
| 805 |
+
|
| 806 |
+
// test("type assertions", () => {
|
| 807 |
+
// const schema = z.pipe(
|
| 808 |
+
// z.string(),
|
| 809 |
+
// z.transform((val) => val.length)
|
| 810 |
+
// );
|
| 811 |
+
// schema.assertInput<string>();
|
| 812 |
+
// // @ts-expect-error
|
| 813 |
+
// schema.assertInput<number>();
|
| 814 |
+
|
| 815 |
+
// schema.assertOutput<number>();
|
| 816 |
+
// // @ts-expect-error
|
| 817 |
+
// schema.assertOutput<string>();
|
| 818 |
+
// });
|
| 819 |
+
|
| 820 |
+
test("z.pipe type enforcement", () => {
|
| 821 |
+
z.pipe(
|
| 822 |
+
z.pipe(
|
| 823 |
+
z.string().check(z.regex(/asdf/)),
|
| 824 |
+
z.transform((v) => new Date(v))
|
| 825 |
+
),
|
| 826 |
+
z.date().check(z.maximum(new Date()))
|
| 827 |
+
);
|
| 828 |
+
});
|
| 829 |
+
|
| 830 |
+
test("def typing", () => {
|
| 831 |
+
z.string().def.type satisfies "string";
|
| 832 |
+
z.email().def.format satisfies "email";
|
| 833 |
+
z.number().def.type satisfies "number";
|
| 834 |
+
z.float64().def.format satisfies z.core.$ZodNumberFormats;
|
| 835 |
+
z.bigint().def.type satisfies "bigint";
|
| 836 |
+
z.boolean().def.type satisfies "boolean";
|
| 837 |
+
z.date().def.type satisfies "date";
|
| 838 |
+
z.symbol().def.type satisfies "symbol";
|
| 839 |
+
z.undefined().def.type satisfies "undefined";
|
| 840 |
+
z.nullable(z.string()).def.type satisfies "nullable";
|
| 841 |
+
z.null().def.type satisfies "null";
|
| 842 |
+
z.any().def.type satisfies "any";
|
| 843 |
+
z.unknown().def.type satisfies "unknown";
|
| 844 |
+
z.never().def.type satisfies "never";
|
| 845 |
+
z.void().def.type satisfies "void";
|
| 846 |
+
z.array(z.string()).def.type satisfies "array";
|
| 847 |
+
z.object({ key: z.string() }).def.type satisfies "object";
|
| 848 |
+
z.union([z.string(), z.number()]).def.type satisfies "union";
|
| 849 |
+
z.intersection(z.string(), z.number()).def.type satisfies "intersection";
|
| 850 |
+
z.tuple([z.string(), z.number()]).def.type satisfies "tuple";
|
| 851 |
+
z.record(z.string(), z.number()).def.type satisfies "record";
|
| 852 |
+
z.map(z.string(), z.number()).def.type satisfies "map";
|
| 853 |
+
z.set(z.string()).def.type satisfies "set";
|
| 854 |
+
z.literal("example").def.type satisfies "literal";
|
| 855 |
+
expectTypeOf(z.literal("example").def.values).toEqualTypeOf<"example"[]>();
|
| 856 |
+
z.enum(["a", "b", "c"]).def.type satisfies "enum";
|
| 857 |
+
z.promise(z.string()).def.type satisfies "promise";
|
| 858 |
+
z.lazy(() => z.string()).def.type satisfies "lazy";
|
| 859 |
+
z.optional(z.string()).def.type satisfies "optional";
|
| 860 |
+
z._default(z.string(), "default").def.type satisfies "default";
|
| 861 |
+
z.templateLiteral([z.literal("a"), z.literal("b")]).def.type satisfies "template_literal";
|
| 862 |
+
z.custom<string>((val) => typeof val === "string").def.type satisfies "custom";
|
| 863 |
+
z.transform((val) => val as string).def.type satisfies "transform";
|
| 864 |
+
z.nonoptional(z.string()).def.type satisfies "nonoptional";
|
| 865 |
+
z.readonly(z.unknown()).def.type satisfies "readonly";
|
| 866 |
+
z.nan().def.type satisfies "nan";
|
| 867 |
+
z.pipe(z.unknown(), z.number()).def.type satisfies "pipe";
|
| 868 |
+
z.success(z.string()).def.type satisfies "success";
|
| 869 |
+
z.catch(z.string(), "fallback").def.type satisfies "catch";
|
| 870 |
+
z.file().def.type satisfies "file";
|
| 871 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/number.test.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, expectTypeOf, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 3 |
+
|
| 4 |
+
test("z.number", () => {
|
| 5 |
+
const a = z.number();
|
| 6 |
+
expect(z.parse(a, 123)).toEqual(123);
|
| 7 |
+
expect(z.parse(a, 123.45)).toEqual(123.45);
|
| 8 |
+
expect(() => z.parse(a, "123")).toThrow();
|
| 9 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 10 |
+
|
| 11 |
+
type a = z.infer<typeof a>;
|
| 12 |
+
expectTypeOf<a>().toEqualTypeOf<number>();
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
test("z.number async", async () => {
|
| 16 |
+
const a = z.number().check(z.refine(async (_) => _ > 0));
|
| 17 |
+
await expect(z.parseAsync(a, 123)).resolves.toEqual(123);
|
| 18 |
+
await expect(() => z.parseAsync(a, -123)).rejects.toThrow();
|
| 19 |
+
await expect(() => z.parseAsync(a, "123")).rejects.toThrow();
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
test("z.int", () => {
|
| 23 |
+
const a = z.int();
|
| 24 |
+
expect(z.parse(a, 123)).toEqual(123);
|
| 25 |
+
expect(() => z.parse(a, 123.45)).toThrow();
|
| 26 |
+
expect(() => z.parse(a, "123")).toThrow();
|
| 27 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
test("z.float32", () => {
|
| 31 |
+
const a = z.float32();
|
| 32 |
+
expect(z.parse(a, 123.45)).toEqual(123.45);
|
| 33 |
+
expect(() => z.parse(a, "123.45")).toThrow();
|
| 34 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 35 |
+
// -3.4028234663852886e38, 3.4028234663852886e38;
|
| 36 |
+
expect(() => z.parse(a, 3.4028234663852886e38 * 2)).toThrow(); // Exceeds max
|
| 37 |
+
expect(() => z.parse(a, -3.4028234663852886e38 * 2)).toThrow(); // Exceeds min
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
test("z.float64", () => {
|
| 41 |
+
const a = z.float64();
|
| 42 |
+
expect(z.parse(a, 123.45)).toEqual(123.45);
|
| 43 |
+
expect(() => z.parse(a, "123.45")).toThrow();
|
| 44 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 45 |
+
expect(() => z.parse(a, 1.7976931348623157e308 * 2)).toThrow(); // Exceeds max
|
| 46 |
+
expect(() => z.parse(a, -1.7976931348623157e308 * 2)).toThrow(); // Exceeds min
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
test("z.int32", () => {
|
| 50 |
+
const a = z.int32();
|
| 51 |
+
expect(z.parse(a, 123)).toEqual(123);
|
| 52 |
+
expect(() => z.parse(a, 123.45)).toThrow();
|
| 53 |
+
expect(() => z.parse(a, "123")).toThrow();
|
| 54 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 55 |
+
expect(() => z.parse(a, 2147483648)).toThrow(); // Exceeds max
|
| 56 |
+
expect(() => z.parse(a, -2147483649)).toThrow(); // Exceeds min
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
test("z.uint32", () => {
|
| 60 |
+
const a = z.uint32();
|
| 61 |
+
expect(z.parse(a, 123)).toEqual(123);
|
| 62 |
+
expect(() => z.parse(a, -123)).toThrow();
|
| 63 |
+
expect(() => z.parse(a, 123.45)).toThrow();
|
| 64 |
+
expect(() => z.parse(a, "123")).toThrow();
|
| 65 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 66 |
+
expect(() => z.parse(a, 4294967296)).toThrow(); // Exceeds max
|
| 67 |
+
expect(() => z.parse(a, -1)).toThrow(); // Below min
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
test("z.int64", () => {
|
| 71 |
+
const a = z.int64();
|
| 72 |
+
expect(z.parse(a, BigInt(123))).toEqual(BigInt(123));
|
| 73 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 74 |
+
expect(() => z.parse(a, 123.45)).toThrow();
|
| 75 |
+
expect(() => z.parse(a, "123")).toThrow();
|
| 76 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 77 |
+
expect(() => z.parse(a, BigInt("9223372036854775808"))).toThrow();
|
| 78 |
+
expect(() => z.parse(a, BigInt("-9223372036854775809"))).toThrow();
|
| 79 |
+
// expect(() => z.parse(a, BigInt("9223372036854775808"))).toThrow(); // Exceeds max
|
| 80 |
+
// expect(() => z.parse(a, BigInt("-9223372036854775809"))).toThrow(); // Exceeds min
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
test("z.uint64", () => {
|
| 84 |
+
const a = z.uint64();
|
| 85 |
+
expect(z.parse(a, BigInt(123))).toEqual(BigInt(123));
|
| 86 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 87 |
+
expect(() => z.parse(a, -123)).toThrow();
|
| 88 |
+
expect(() => z.parse(a, 123.45)).toThrow();
|
| 89 |
+
expect(() => z.parse(a, "123")).toThrow();
|
| 90 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 91 |
+
expect(() => z.parse(a, BigInt("18446744073709551616"))).toThrow(); // Exceeds max
|
| 92 |
+
expect(() => z.parse(a, BigInt("-1"))).toThrow(); // Below min
|
| 93 |
+
// expect(() => z.parse(a, BigInt("18446744073709551616"))).toThrow(); // Exceeds max
|
| 94 |
+
// expect(() => z.parse(a, BigInt("-1"))).toThrow(); // Below min
|
| 95 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/object.test.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, expectTypeOf, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 3 |
+
|
| 4 |
+
test("z.object", () => {
|
| 5 |
+
const a = z.object({
|
| 6 |
+
name: z.string(),
|
| 7 |
+
age: z.number(),
|
| 8 |
+
points: z.optional(z.number()),
|
| 9 |
+
"test?": z.boolean(),
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
a._zod.def.shape["test?"];
|
| 13 |
+
a._zod.def.shape.points._zod.optin;
|
| 14 |
+
|
| 15 |
+
type a = z.output<typeof a>;
|
| 16 |
+
|
| 17 |
+
expectTypeOf<a>().toEqualTypeOf<{
|
| 18 |
+
name: string;
|
| 19 |
+
age: number;
|
| 20 |
+
points?: number;
|
| 21 |
+
"test?": boolean;
|
| 22 |
+
}>();
|
| 23 |
+
expect(z.parse(a, { name: "john", age: 30, "test?": true })).toEqual({
|
| 24 |
+
name: "john",
|
| 25 |
+
age: 30,
|
| 26 |
+
"test?": true,
|
| 27 |
+
});
|
| 28 |
+
// "test?" is required in ZodObject
|
| 29 |
+
expect(() => z.parse(a, { name: "john", age: "30" })).toThrow();
|
| 30 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 31 |
+
|
| 32 |
+
// null prototype
|
| 33 |
+
const schema = z.object({ a: z.string() });
|
| 34 |
+
const obj = Object.create(null);
|
| 35 |
+
obj.a = "foo";
|
| 36 |
+
expect(schema.parse(obj)).toEqual({ a: "foo" });
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
test("z.object().check()", () => {
|
| 40 |
+
const a = z.object({
|
| 41 |
+
name: z.string(),
|
| 42 |
+
age: z.number(),
|
| 43 |
+
points: z.optional(z.number()),
|
| 44 |
+
"test?": z.boolean(),
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
type a = z.output<typeof a>;
|
| 48 |
+
|
| 49 |
+
a.check(({ value }) => {
|
| 50 |
+
expectTypeOf(value).toEqualTypeOf<a>();
|
| 51 |
+
});
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
test("z.strictObject", () => {
|
| 55 |
+
const a = z.strictObject({
|
| 56 |
+
name: z.string(),
|
| 57 |
+
});
|
| 58 |
+
expect(z.parse(a, { name: "john" })).toEqual({ name: "john" });
|
| 59 |
+
expect(() => z.parse(a, { name: "john", age: 30 })).toThrow();
|
| 60 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
test("z.looseObject", () => {
|
| 64 |
+
const a = z.looseObject({
|
| 65 |
+
name: z.string(),
|
| 66 |
+
age: z.number(),
|
| 67 |
+
});
|
| 68 |
+
expect(z.parse(a, { name: "john", age: 30 })).toEqual({
|
| 69 |
+
name: "john",
|
| 70 |
+
age: 30,
|
| 71 |
+
});
|
| 72 |
+
expect(z.parse(a, { name: "john", age: 30, extra: true })).toEqual({
|
| 73 |
+
name: "john",
|
| 74 |
+
age: 30,
|
| 75 |
+
extra: true,
|
| 76 |
+
});
|
| 77 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
const userSchema = z.object({
|
| 81 |
+
name: z.string(),
|
| 82 |
+
age: z.number(),
|
| 83 |
+
email: z.optional(z.string()),
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
test("z.keyof", () => {
|
| 87 |
+
// z.keyof returns an enum schema of the keys of an object schema
|
| 88 |
+
const userKeysSchema = z.keyof(userSchema);
|
| 89 |
+
type UserKeys = z.infer<typeof userKeysSchema>;
|
| 90 |
+
expectTypeOf<UserKeys>().toEqualTypeOf<"name" | "age" | "email">();
|
| 91 |
+
expect(userKeysSchema).toBeDefined();
|
| 92 |
+
expect(z.safeParse(userKeysSchema, "name").success).toBe(true);
|
| 93 |
+
expect(z.safeParse(userKeysSchema, "age").success).toBe(true);
|
| 94 |
+
expect(z.safeParse(userKeysSchema, "email").success).toBe(true);
|
| 95 |
+
expect(z.safeParse(userKeysSchema, "isAdmin").success).toBe(false);
|
| 96 |
+
});
|
| 97 |
+
|
| 98 |
+
test("z.extend", () => {
|
| 99 |
+
const extendedSchema = z.extend(userSchema, {
|
| 100 |
+
isAdmin: z.boolean(),
|
| 101 |
+
});
|
| 102 |
+
type ExtendedUser = z.infer<typeof extendedSchema>;
|
| 103 |
+
expectTypeOf<ExtendedUser>().toEqualTypeOf<{
|
| 104 |
+
name: string;
|
| 105 |
+
age: number;
|
| 106 |
+
email?: string;
|
| 107 |
+
isAdmin: boolean;
|
| 108 |
+
}>();
|
| 109 |
+
expect(extendedSchema).toBeDefined();
|
| 110 |
+
expect(z.safeParse(extendedSchema, { name: "John", age: 30, isAdmin: true }).success).toBe(true);
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
test("z.pick", () => {
|
| 114 |
+
const pickedSchema = z.pick(userSchema, { name: true, email: true });
|
| 115 |
+
type PickedUser = z.infer<typeof pickedSchema>;
|
| 116 |
+
expectTypeOf<PickedUser>().toEqualTypeOf<{ name: string; email?: string }>();
|
| 117 |
+
expect(pickedSchema).toBeDefined();
|
| 118 |
+
expect(z.safeParse(pickedSchema, { name: "John", email: "john@example.com" }).success).toBe(true);
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
test("z.omit", () => {
|
| 122 |
+
const omittedSchema = z.omit(userSchema, { age: true });
|
| 123 |
+
type OmittedUser = z.infer<typeof omittedSchema>;
|
| 124 |
+
expectTypeOf<OmittedUser>().toEqualTypeOf<{
|
| 125 |
+
name: string;
|
| 126 |
+
email?: string | undefined;
|
| 127 |
+
}>();
|
| 128 |
+
expect(omittedSchema).toBeDefined();
|
| 129 |
+
expect(Reflect.ownKeys(omittedSchema._zod.def.shape)).toEqual(["name", "email"]);
|
| 130 |
+
expect(z.safeParse(omittedSchema, { name: "John", email: "john@example.com" }).success).toBe(true);
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
+
test("z.partial", () => {
|
| 134 |
+
const partialSchema = z.partial(userSchema);
|
| 135 |
+
type PartialUser = z.infer<typeof partialSchema>;
|
| 136 |
+
expectTypeOf<PartialUser>().toEqualTypeOf<{
|
| 137 |
+
name?: string;
|
| 138 |
+
age?: number;
|
| 139 |
+
email?: string;
|
| 140 |
+
}>();
|
| 141 |
+
expect(z.safeParse(partialSchema, { name: "John" }).success).toBe(true);
|
| 142 |
+
});
|
| 143 |
+
|
| 144 |
+
test("z.partial with mask", () => {
|
| 145 |
+
const partialSchemaWithMask = z.partial(userSchema, { name: true });
|
| 146 |
+
type PartialUserWithMask = z.infer<typeof partialSchemaWithMask>;
|
| 147 |
+
expectTypeOf<PartialUserWithMask>().toEqualTypeOf<{
|
| 148 |
+
name?: string;
|
| 149 |
+
age: number;
|
| 150 |
+
email?: string;
|
| 151 |
+
}>();
|
| 152 |
+
expect(z.safeParse(partialSchemaWithMask, { age: 30 }).success).toBe(true);
|
| 153 |
+
expect(z.safeParse(partialSchemaWithMask, { name: "John" }).success).toBe(false);
|
| 154 |
+
});
|
| 155 |
+
|
| 156 |
+
test("z.catchall", () => {
|
| 157 |
+
// z.catchall()
|
| 158 |
+
const schema = z.catchall(
|
| 159 |
+
z.object({
|
| 160 |
+
name: z.string(),
|
| 161 |
+
// age: z.number(),
|
| 162 |
+
}),
|
| 163 |
+
z.string()
|
| 164 |
+
);
|
| 165 |
+
|
| 166 |
+
type schemaIn = z.input<typeof schema>;
|
| 167 |
+
type schemaOut = z.output<typeof schema>;
|
| 168 |
+
expectTypeOf<schemaIn>().toEqualTypeOf<{
|
| 169 |
+
name: string;
|
| 170 |
+
[key: string]: string;
|
| 171 |
+
}>();
|
| 172 |
+
|
| 173 |
+
expectTypeOf<schemaOut>().toEqualTypeOf<{
|
| 174 |
+
name: string;
|
| 175 |
+
[key: string]: string;
|
| 176 |
+
}>();
|
| 177 |
+
|
| 178 |
+
schema.parse({
|
| 179 |
+
name: "john",
|
| 180 |
+
age: "30",
|
| 181 |
+
extra: "extra value",
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
expect(() => schema.parse({ name: "john", age: 30 })).toThrow();
|
| 185 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/prototypes.test.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 3 |
+
|
| 4 |
+
declare module "zod/v4/core" {
|
| 5 |
+
interface $ZodType {
|
| 6 |
+
/** @deprecated */
|
| 7 |
+
_core(): string;
|
| 8 |
+
}
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
test("prototype extension", () => {
|
| 12 |
+
z.core.$ZodType.prototype._core = function () {
|
| 13 |
+
return "_core";
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
// should pass
|
| 17 |
+
const result = z.string()._core();
|
| 18 |
+
expect(result).toBe("_core");
|
| 19 |
+
// expectTypeOf<typeof result>().toEqualTypeOf<string>();
|
| 20 |
+
|
| 21 |
+
// clean up
|
| 22 |
+
z.ZodMiniType.prototype._core = undefined;
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
declare module "zod/v4/mini" {
|
| 26 |
+
interface ZodMiniType {
|
| 27 |
+
/** @deprecated */
|
| 28 |
+
_mini(): string;
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("prototype extension", () => {
|
| 33 |
+
z.ZodMiniType.prototype._mini = function () {
|
| 34 |
+
return "_mini";
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
// should pass
|
| 38 |
+
const result = z.string()._mini();
|
| 39 |
+
expect(result).toBe("_mini");
|
| 40 |
+
|
| 41 |
+
// clean up
|
| 42 |
+
z.ZodMiniType.prototype._mini = undefined;
|
| 43 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, expectTypeOf, test } from "vitest";
|
| 2 |
+
import { z } from "zod/v4-mini";
|
| 3 |
+
|
| 4 |
+
test("recursion with z.lazy", () => {
|
| 5 |
+
const data = {
|
| 6 |
+
name: "I",
|
| 7 |
+
subcategories: [
|
| 8 |
+
{
|
| 9 |
+
name: "A",
|
| 10 |
+
subcategories: [
|
| 11 |
+
{
|
| 12 |
+
name: "1",
|
| 13 |
+
subcategories: [
|
| 14 |
+
{
|
| 15 |
+
name: "a",
|
| 16 |
+
subcategories: [],
|
| 17 |
+
},
|
| 18 |
+
],
|
| 19 |
+
},
|
| 20 |
+
],
|
| 21 |
+
},
|
| 22 |
+
],
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
const Category = z.object({
|
| 26 |
+
name: z.string(),
|
| 27 |
+
get subcategories(): z.ZodMiniOptional<z.ZodMiniArray<typeof Category>> {
|
| 28 |
+
return z.optional(z.array(Category));
|
| 29 |
+
},
|
| 30 |
+
});
|
| 31 |
+
Category.parse(data);
|
| 32 |
+
|
| 33 |
+
type Category = z.infer<typeof Category>;
|
| 34 |
+
interface _Category {
|
| 35 |
+
name: string;
|
| 36 |
+
subcategories?: _Category[];
|
| 37 |
+
}
|
| 38 |
+
expectTypeOf<Category>().toEqualTypeOf<_Category>();
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
test("recursion involving union type", () => {
|
| 42 |
+
const data = {
|
| 43 |
+
value: 1,
|
| 44 |
+
next: {
|
| 45 |
+
value: 2,
|
| 46 |
+
next: {
|
| 47 |
+
value: 3,
|
| 48 |
+
next: {
|
| 49 |
+
value: 4,
|
| 50 |
+
next: null,
|
| 51 |
+
},
|
| 52 |
+
},
|
| 53 |
+
},
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
const LL = z.object({
|
| 57 |
+
value: z.number(),
|
| 58 |
+
get next(): z.ZodMiniNullable<typeof LL> {
|
| 59 |
+
return z.nullable(LL);
|
| 60 |
+
},
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
LL.parse(data);
|
| 64 |
+
type LL = z.infer<typeof LL>;
|
| 65 |
+
type _LL = {
|
| 66 |
+
value: number;
|
| 67 |
+
next: _LL | null;
|
| 68 |
+
};
|
| 69 |
+
expectTypeOf<LL>().toEqualTypeOf<_LL>();
|
| 70 |
+
});
|
| 71 |
+
|
| 72 |
+
test("mutual recursion - native", () => {
|
| 73 |
+
const Alazy = z.object({
|
| 74 |
+
val: z.number(),
|
| 75 |
+
get b() {
|
| 76 |
+
return z.optional(Blazy);
|
| 77 |
+
},
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
const Blazy = z.object({
|
| 81 |
+
val: z.number(),
|
| 82 |
+
get a() {
|
| 83 |
+
return z.optional(Alazy);
|
| 84 |
+
},
|
| 85 |
+
});
|
| 86 |
+
const testData = {
|
| 87 |
+
val: 1,
|
| 88 |
+
b: {
|
| 89 |
+
val: 5,
|
| 90 |
+
a: {
|
| 91 |
+
val: 3,
|
| 92 |
+
b: {
|
| 93 |
+
val: 4,
|
| 94 |
+
a: {
|
| 95 |
+
val: 2,
|
| 96 |
+
b: {
|
| 97 |
+
val: 1,
|
| 98 |
+
},
|
| 99 |
+
},
|
| 100 |
+
},
|
| 101 |
+
},
|
| 102 |
+
},
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
Alazy.parse(testData);
|
| 106 |
+
Blazy.parse(testData.b);
|
| 107 |
+
|
| 108 |
+
type Alazy = z.infer<typeof Alazy>;
|
| 109 |
+
type Blazy = z.infer<typeof Blazy>;
|
| 110 |
+
interface _Alazy {
|
| 111 |
+
val: number;
|
| 112 |
+
b?: _Blazy | undefined;
|
| 113 |
+
}
|
| 114 |
+
interface _Blazy {
|
| 115 |
+
val: number;
|
| 116 |
+
a?: _Alazy | undefined;
|
| 117 |
+
}
|
| 118 |
+
expectTypeOf<Alazy>().toEqualTypeOf<_Alazy>();
|
| 119 |
+
expectTypeOf<Blazy>().toEqualTypeOf<_Blazy>();
|
| 120 |
+
|
| 121 |
+
expect(() => Alazy.parse({ val: "asdf" })).toThrow();
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
test("pick and omit with getter", () => {
|
| 125 |
+
const Category = z.strictObject({
|
| 126 |
+
name: z.string(),
|
| 127 |
+
get subcategories() {
|
| 128 |
+
return z.array(Category);
|
| 129 |
+
},
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
type Category = z.infer<typeof Category>;
|
| 133 |
+
interface _Category {
|
| 134 |
+
name: string;
|
| 135 |
+
subcategories: _Category[];
|
| 136 |
+
}
|
| 137 |
+
expectTypeOf<Category>().toEqualTypeOf<_Category>();
|
| 138 |
+
|
| 139 |
+
const PickedCategory = z.pick(Category, { name: true });
|
| 140 |
+
const OmittedCategory = z.omit(Category, { subcategories: true });
|
| 141 |
+
type PickedCategory = z.infer<typeof PickedCategory>;
|
| 142 |
+
type OmittedCategory = z.infer<typeof OmittedCategory>;
|
| 143 |
+
interface _PickedCategory {
|
| 144 |
+
name: string;
|
| 145 |
+
}
|
| 146 |
+
interface _OmittedCategory {
|
| 147 |
+
name: string;
|
| 148 |
+
}
|
| 149 |
+
expectTypeOf<PickedCategory>().toEqualTypeOf<_PickedCategory>();
|
| 150 |
+
expectTypeOf<OmittedCategory>().toEqualTypeOf<_OmittedCategory>();
|
| 151 |
+
|
| 152 |
+
const picked = { name: "test" };
|
| 153 |
+
const omitted = { name: "test" };
|
| 154 |
+
|
| 155 |
+
PickedCategory.parse(picked);
|
| 156 |
+
OmittedCategory.parse(omitted);
|
| 157 |
+
|
| 158 |
+
expect(() => PickedCategory.parse({ name: "test", subcategories: [] })).toThrow();
|
| 159 |
+
expect(() => OmittedCategory.parse({ name: "test", subcategories: [] })).toThrow();
|
| 160 |
+
});
|
| 161 |
+
|
| 162 |
+
test("deferred self-recursion", () => {
|
| 163 |
+
const Feature = z.object({
|
| 164 |
+
title: z.string(),
|
| 165 |
+
get features(): z.ZodMiniOptional<z.ZodMiniArray<typeof Feature>> {
|
| 166 |
+
return z.optional(z.array(Feature)); //.optional();
|
| 167 |
+
},
|
| 168 |
+
});
|
| 169 |
+
type Feature = z.infer<typeof Feature>;
|
| 170 |
+
|
| 171 |
+
const Output = z.object({
|
| 172 |
+
id: z.int(), //.nonnegative(),
|
| 173 |
+
name: z.string(),
|
| 174 |
+
features: z.array(Feature), //.array(), // <—
|
| 175 |
+
});
|
| 176 |
+
|
| 177 |
+
type Output = z.output<typeof Output>;
|
| 178 |
+
|
| 179 |
+
type _Feature = {
|
| 180 |
+
title: string;
|
| 181 |
+
features?: _Feature[] | undefined;
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
type _Output = {
|
| 185 |
+
id: number;
|
| 186 |
+
name: string;
|
| 187 |
+
features: _Feature[];
|
| 188 |
+
};
|
| 189 |
+
|
| 190 |
+
expectTypeOf<Feature>().toEqualTypeOf<_Feature>();
|
| 191 |
+
expectTypeOf<Output>().toEqualTypeOf<_Output>();
|
| 192 |
+
});
|
| 193 |
+
|
| 194 |
+
test("recursion compatibility", () => {
|
| 195 |
+
// array
|
| 196 |
+
const A = z.object({
|
| 197 |
+
get subcategories() {
|
| 198 |
+
return z.array(A);
|
| 199 |
+
},
|
| 200 |
+
});
|
| 201 |
+
// tuple
|
| 202 |
+
const B = z.object({
|
| 203 |
+
get subcategories() {
|
| 204 |
+
return z.tuple([B, B]);
|
| 205 |
+
},
|
| 206 |
+
});
|
| 207 |
+
// object
|
| 208 |
+
const C = z.object({
|
| 209 |
+
get subcategories() {
|
| 210 |
+
return z.object({
|
| 211 |
+
subcategories: C,
|
| 212 |
+
});
|
| 213 |
+
},
|
| 214 |
+
});
|
| 215 |
+
// union
|
| 216 |
+
const D = z.object({
|
| 217 |
+
get subcategories() {
|
| 218 |
+
return z.union([D, z.string()]);
|
| 219 |
+
},
|
| 220 |
+
});
|
| 221 |
+
// intersection
|
| 222 |
+
const E = z.object({
|
| 223 |
+
get subcategories() {
|
| 224 |
+
return z.intersection(E, E);
|
| 225 |
+
},
|
| 226 |
+
});
|
| 227 |
+
// record
|
| 228 |
+
const F = z.object({
|
| 229 |
+
get subcategories() {
|
| 230 |
+
return z.record(z.string(), F);
|
| 231 |
+
},
|
| 232 |
+
});
|
| 233 |
+
// map
|
| 234 |
+
const G = z.object({
|
| 235 |
+
get subcategories() {
|
| 236 |
+
return z.map(z.string(), G);
|
| 237 |
+
},
|
| 238 |
+
});
|
| 239 |
+
// set
|
| 240 |
+
const H = z.object({
|
| 241 |
+
get subcategories() {
|
| 242 |
+
return z.set(H);
|
| 243 |
+
},
|
| 244 |
+
});
|
| 245 |
+
// optional
|
| 246 |
+
const I = z.object({
|
| 247 |
+
get subcategories() {
|
| 248 |
+
return z.optional(I);
|
| 249 |
+
},
|
| 250 |
+
});
|
| 251 |
+
// nullable
|
| 252 |
+
const J = z.object({
|
| 253 |
+
get subcategories() {
|
| 254 |
+
return z.nullable(J);
|
| 255 |
+
},
|
| 256 |
+
});
|
| 257 |
+
// optional
|
| 258 |
+
const L = z.object({
|
| 259 |
+
get subcategories() {
|
| 260 |
+
return z.optional(L);
|
| 261 |
+
},
|
| 262 |
+
});
|
| 263 |
+
// nullable
|
| 264 |
+
const M = z.object({
|
| 265 |
+
get subcategories() {
|
| 266 |
+
return z.nullable(M);
|
| 267 |
+
},
|
| 268 |
+
});
|
| 269 |
+
// nonoptional
|
| 270 |
+
const N = z.object({
|
| 271 |
+
get subcategories() {
|
| 272 |
+
return z.nonoptional(N);
|
| 273 |
+
},
|
| 274 |
+
});
|
| 275 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/src/v4/mini/tests/string.test.ts
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, expectTypeOf, test } from "vitest";
|
| 2 |
+
import * as z from "zod/v4-mini";
|
| 3 |
+
|
| 4 |
+
const FAIL = { success: false };
|
| 5 |
+
|
| 6 |
+
test("z.string", async () => {
|
| 7 |
+
const a = z.string();
|
| 8 |
+
expect(z.parse(a, "hello")).toEqual("hello");
|
| 9 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 10 |
+
expect(() => z.parse(a, false)).toThrow();
|
| 11 |
+
type a = z.infer<typeof a>;
|
| 12 |
+
expectTypeOf<a>().toEqualTypeOf<string>();
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
// test("z.string with description", () => {
|
| 16 |
+
// const a = z.string({ description: "string description" });
|
| 17 |
+
// a._def;
|
| 18 |
+
// expect(a._def.description).toEqual("string description");
|
| 19 |
+
// });
|
| 20 |
+
|
| 21 |
+
test("z.string with custom error", () => {
|
| 22 |
+
const a = z.string({ error: () => "BAD" });
|
| 23 |
+
expect(z.safeParse(a, 123).error!.issues[0].message).toEqual("BAD");
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
test("inference in checks", () => {
|
| 27 |
+
const a = z.string().check(z.refine((val) => val.length));
|
| 28 |
+
z.parse(a, "___");
|
| 29 |
+
expect(() => z.parse(a, "")).toThrow();
|
| 30 |
+
const b = z.string().check(z.refine((val) => val.length));
|
| 31 |
+
z.parse(b, "___");
|
| 32 |
+
expect(() => z.parse(b, "")).toThrow();
|
| 33 |
+
const c = z.string().check(z.refine((val) => val.length));
|
| 34 |
+
z.parse(c, "___");
|
| 35 |
+
expect(() => z.parse(c, "")).toThrow();
|
| 36 |
+
const d = z.string().check(z.refine((val) => val.length));
|
| 37 |
+
z.parse(d, "___");
|
| 38 |
+
expect(() => z.parse(d, "")).toThrow();
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
test("z.string async", async () => {
|
| 42 |
+
// async
|
| 43 |
+
const a = z.string().check(z.refine(async (val) => val.length));
|
| 44 |
+
expect(await z.parseAsync(a, "___")).toEqual("___");
|
| 45 |
+
await expect(() => z.parseAsync(a, "")).rejects.toThrowError();
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
test("z.uuid", () => {
|
| 49 |
+
const a = z.uuid();
|
| 50 |
+
// parse uuid
|
| 51 |
+
z.parse(a, "550e8400-e29b-41d4-a716-446655440000");
|
| 52 |
+
z.parse(a, "550e8400-e29b-61d4-a716-446655440000");
|
| 53 |
+
|
| 54 |
+
// bad uuid
|
| 55 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 56 |
+
// wrong type
|
| 57 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 58 |
+
|
| 59 |
+
const b = z.uuidv4();
|
| 60 |
+
z.parse(b, "550e8400-e29b-41d4-a716-446655440000");
|
| 61 |
+
expect(z.safeParse(b, "550e8400-e29b-61d4-a716-446655440000")).toMatchObject(FAIL);
|
| 62 |
+
|
| 63 |
+
const c = z.uuidv6();
|
| 64 |
+
z.parse(c, "550e8400-e29b-61d4-a716-446655440000");
|
| 65 |
+
expect(z.safeParse(c, "550e8400-e29b-41d4-a716-446655440000")).toMatchObject(FAIL);
|
| 66 |
+
|
| 67 |
+
const d = z.uuidv7();
|
| 68 |
+
z.parse(d, "550e8400-e29b-71d4-a716-446655440000");
|
| 69 |
+
expect(z.safeParse(d, "550e8400-e29b-41d4-a716-446655440000")).toMatchObject(FAIL);
|
| 70 |
+
expect(z.safeParse(d, "550e8400-e29b-61d4-a716-446655440000")).toMatchObject(FAIL);
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
test("z.email", () => {
|
| 74 |
+
const a = z.email();
|
| 75 |
+
expect(z.parse(a, "test@test.com")).toEqual("test@test.com");
|
| 76 |
+
expect(() => z.parse(a, "test")).toThrow();
|
| 77 |
+
expect(z.safeParse(a, "bad email", { error: () => "bad email" }).error!.issues[0].message).toEqual("bad email");
|
| 78 |
+
|
| 79 |
+
const b = z.email("bad email");
|
| 80 |
+
expect(z.safeParse(b, "bad email").error!.issues[0].message).toEqual("bad email");
|
| 81 |
+
|
| 82 |
+
const c = z.email({ error: "bad email" });
|
| 83 |
+
expect(z.safeParse(c, "bad email").error!.issues[0].message).toEqual("bad email");
|
| 84 |
+
|
| 85 |
+
const d = z.email({ error: () => "bad email" });
|
| 86 |
+
expect(z.safeParse(d, "bad email").error!.issues[0].message).toEqual("bad email");
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
test("z.url", () => {
|
| 90 |
+
const a = z.url();
|
| 91 |
+
// valid URLs
|
| 92 |
+
expect(a.parse("http://example.com")).toEqual("http://example.com");
|
| 93 |
+
expect(a.parse("https://example.com")).toEqual("https://example.com");
|
| 94 |
+
expect(a.parse("ftp://example.com")).toEqual("ftp://example.com");
|
| 95 |
+
expect(a.parse("http://sub.example.com")).toEqual("http://sub.example.com");
|
| 96 |
+
expect(a.parse("https://example.com/path?query=123#fragment")).toEqual("https://example.com/path?query=123#fragment");
|
| 97 |
+
expect(a.parse("http://localhost")).toEqual("http://localhost");
|
| 98 |
+
expect(a.parse("https://localhost")).toEqual("https://localhost");
|
| 99 |
+
expect(a.parse("http://localhost:3000")).toEqual("http://localhost:3000");
|
| 100 |
+
expect(a.parse("https://localhost:3000")).toEqual("https://localhost:3000");
|
| 101 |
+
|
| 102 |
+
// test trimming
|
| 103 |
+
expect(a.parse(" http://example.com ")).toEqual("http://example.com");
|
| 104 |
+
expect(a.parse(" http://example.com/")).toEqual("http://example.com/");
|
| 105 |
+
expect(a.parse(" http://example.com")).toEqual("http://example.com");
|
| 106 |
+
expect(a.parse(" http://example.com//")).toEqual("http://example.com//");
|
| 107 |
+
|
| 108 |
+
// invalid URLs
|
| 109 |
+
expect(() => a.parse("not-a-url")).toThrow();
|
| 110 |
+
// expect(() => a.parse("http:/example.com")).toThrow();
|
| 111 |
+
expect(() => a.parse("://example.com")).toThrow();
|
| 112 |
+
expect(() => a.parse("http://")).toThrow();
|
| 113 |
+
expect(() => a.parse("example.com")).toThrow();
|
| 114 |
+
|
| 115 |
+
// wrong type
|
| 116 |
+
expect(() => a.parse(123)).toThrow();
|
| 117 |
+
expect(() => a.parse(null)).toThrow();
|
| 118 |
+
expect(() => a.parse(undefined)).toThrow();
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
test("z.url with optional hostname regex", () => {
|
| 122 |
+
const a = z.url({ hostname: /example\.com$/ });
|
| 123 |
+
expect(a.parse("http://example.com")).toEqual("http://example.com");
|
| 124 |
+
expect(a.parse("https://sub.example.com")).toEqual("https://sub.example.com");
|
| 125 |
+
expect(() => a.parse("http://examples.com")).toThrow();
|
| 126 |
+
expect(() => a.parse("http://example.org")).toThrow();
|
| 127 |
+
expect(() => a.parse("asdf")).toThrow();
|
| 128 |
+
});
|
| 129 |
+
|
| 130 |
+
test("z.url - file urls", () => {
|
| 131 |
+
// file URLs
|
| 132 |
+
const a = z.url({ hostname: /.*/ }); // allow any hostname
|
| 133 |
+
expect(a.parse("file:///path/to/file.txt")).toEqual("file:///path/to/file.txt");
|
| 134 |
+
expect(a.parse("file:///C:/path/to/file.txt")).toEqual("file:///C:/path/to/file.txt");
|
| 135 |
+
expect(a.parse("file:///C:/path/to/file.txt?query=123#fragment")).toEqual(
|
| 136 |
+
"file:///C:/path/to/file.txt?query=123#fragment"
|
| 137 |
+
);
|
| 138 |
+
});
|
| 139 |
+
test("z.url with optional protocol regex", () => {
|
| 140 |
+
const a = z.url({ protocol: /^https?$/ });
|
| 141 |
+
expect(a.parse("http://example.com")).toEqual("http://example.com");
|
| 142 |
+
expect(a.parse("https://example.com")).toEqual("https://example.com");
|
| 143 |
+
expect(() => a.parse("ftp://example.com")).toThrow();
|
| 144 |
+
expect(() => a.parse("mailto:example@example.com")).toThrow();
|
| 145 |
+
expect(() => a.parse("asdf")).toThrow();
|
| 146 |
+
});
|
| 147 |
+
|
| 148 |
+
test("z.url with both hostname and protocol regexes", () => {
|
| 149 |
+
const a = z.url({ hostname: /example\.com$/, protocol: /^https$/ });
|
| 150 |
+
expect(a.parse("https://example.com")).toEqual("https://example.com");
|
| 151 |
+
expect(a.parse("https://sub.example.com")).toEqual("https://sub.example.com");
|
| 152 |
+
expect(() => a.parse("http://example.com")).toThrow();
|
| 153 |
+
expect(() => a.parse("https://example.org")).toThrow();
|
| 154 |
+
expect(() => a.parse("ftp://example.com")).toThrow();
|
| 155 |
+
expect(() => a.parse("asdf")).toThrow();
|
| 156 |
+
});
|
| 157 |
+
|
| 158 |
+
test("z.url with invalid regex patterns", () => {
|
| 159 |
+
const a = z.url({ hostname: /a+$/, protocol: /^ftp$/ });
|
| 160 |
+
a.parse("ftp://a");
|
| 161 |
+
a.parse("ftp://aaaaaaaa");
|
| 162 |
+
expect(() => a.parse("http://aaa")).toThrow();
|
| 163 |
+
expect(() => a.parse("https://example.com")).toThrow();
|
| 164 |
+
expect(() => a.parse("ftp://asdfasdf")).toThrow();
|
| 165 |
+
expect(() => a.parse("ftp://invalid")).toThrow();
|
| 166 |
+
});
|
| 167 |
+
|
| 168 |
+
test("z.emoji", () => {
|
| 169 |
+
const a = z.emoji();
|
| 170 |
+
expect(z.parse(a, "😀")).toEqual("😀");
|
| 171 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 172 |
+
});
|
| 173 |
+
|
| 174 |
+
test("z.nanoid", () => {
|
| 175 |
+
const a = z.nanoid();
|
| 176 |
+
expect(z.parse(a, "8FHZpIxleEK3axQRBNNjN")).toEqual("8FHZpIxleEK3axQRBNNjN");
|
| 177 |
+
expect(() => z.parse(a, "abc")).toThrow();
|
| 178 |
+
});
|
| 179 |
+
|
| 180 |
+
test("z.cuid", () => {
|
| 181 |
+
const a = z.cuid();
|
| 182 |
+
expect(z.parse(a, "cixs7y0c0000f7x3b1z6m3w6r")).toEqual("cixs7y0c0000f7x3b1z6m3w6r");
|
| 183 |
+
expect(() => z.parse(a, "abc")).toThrow();
|
| 184 |
+
});
|
| 185 |
+
|
| 186 |
+
test("z.cuid2", () => {
|
| 187 |
+
const a = z.cuid2();
|
| 188 |
+
expect(z.parse(a, "cixs7y0c0000f7x3b1z6m3w6r")).toEqual("cixs7y0c0000f7x3b1z6m3w6r");
|
| 189 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 190 |
+
});
|
| 191 |
+
|
| 192 |
+
test("z.ulid", () => {
|
| 193 |
+
const a = z.ulid();
|
| 194 |
+
expect(z.parse(a, "01ETGRM9QYVX6S9V2F3B6JXG4N")).toEqual("01ETGRM9QYVX6S9V2F3B6JXG4N");
|
| 195 |
+
expect(() => z.parse(a, "abc")).toThrow();
|
| 196 |
+
});
|
| 197 |
+
|
| 198 |
+
test("z.xid", () => {
|
| 199 |
+
const a = z.xid();
|
| 200 |
+
expect(z.parse(a, "9m4e2mr0ui3e8a215n4g")).toEqual("9m4e2mr0ui3e8a215n4g");
|
| 201 |
+
expect(() => z.parse(a, "abc")).toThrow();
|
| 202 |
+
});
|
| 203 |
+
|
| 204 |
+
test("z.ksuid", () => {
|
| 205 |
+
const a = z.ksuid();
|
| 206 |
+
expect(z.parse(a, "2naeRjTrrHJAkfd3tOuEjw90WCA")).toEqual("2naeRjTrrHJAkfd3tOuEjw90WCA");
|
| 207 |
+
expect(() => z.parse(a, "abc")).toThrow();
|
| 208 |
+
});
|
| 209 |
+
|
| 210 |
+
// test("z.ip", () => {
|
| 211 |
+
// const a = z.ip();
|
| 212 |
+
// expect(z.parse(a, "127.0.0.1")).toEqual("127.0.0.1");
|
| 213 |
+
// expect(z.parse(a, "2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toEqual("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
| 214 |
+
// expect(() => z.parse(a, "abc")).toThrow();
|
| 215 |
+
// });
|
| 216 |
+
|
| 217 |
+
test("z.ipv4", () => {
|
| 218 |
+
const a = z.ipv4();
|
| 219 |
+
// valid ipv4
|
| 220 |
+
expect(z.parse(a, "192.168.1.1")).toEqual("192.168.1.1");
|
| 221 |
+
expect(z.parse(a, "255.255.255.255")).toEqual("255.255.255.255");
|
| 222 |
+
// invalid ipv4
|
| 223 |
+
expect(() => z.parse(a, "999.999.999.999")).toThrow();
|
| 224 |
+
expect(() => z.parse(a, "256.256.256.256")).toThrow();
|
| 225 |
+
expect(() => z.parse(a, "192.168.1")).toThrow();
|
| 226 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 227 |
+
// wrong type
|
| 228 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
test("z.ipv6", () => {
|
| 232 |
+
const a = z.ipv6();
|
| 233 |
+
// valid ipv6
|
| 234 |
+
expect(z.parse(a, "2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toEqual("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
| 235 |
+
expect(z.parse(a, "::1")).toEqual("::1");
|
| 236 |
+
// invalid ipv6
|
| 237 |
+
expect(() => z.parse(a, "2001:db8::85a3::8a2e:370:7334")).toThrow();
|
| 238 |
+
expect(() => z.parse(a, "2001:db8:85a3:0:0:8a2e:370g:7334")).toThrow();
|
| 239 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 240 |
+
// wrong type
|
| 241 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 242 |
+
});
|
| 243 |
+
|
| 244 |
+
test("z.base64", () => {
|
| 245 |
+
const a = z.base64();
|
| 246 |
+
// valid base64
|
| 247 |
+
expect(z.parse(a, "SGVsbG8gd29ybGQ=")).toEqual("SGVsbG8gd29ybGQ=");
|
| 248 |
+
expect(z.parse(a, "U29tZSBvdGhlciBzdHJpbmc=")).toEqual("U29tZSBvdGhlciBzdHJpbmc=");
|
| 249 |
+
// invalid base64
|
| 250 |
+
expect(() => z.parse(a, "SGVsbG8gd29ybGQ")).toThrow();
|
| 251 |
+
expect(() => z.parse(a, "U29tZSBvdGhlciBzdHJpbmc")).toThrow();
|
| 252 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 253 |
+
// wrong type
|
| 254 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 255 |
+
});
|
| 256 |
+
|
| 257 |
+
// test("z.jsonString", () => {
|
| 258 |
+
// const a = z.jsonString();
|
| 259 |
+
// // valid JSON string
|
| 260 |
+
// expect(z.parse(a, '{"key":"value"}')).toEqual('{"key":"value"}');
|
| 261 |
+
// expect(z.parse(a, '["item1", "item2"]')).toEqual('["item1", "item2"]');
|
| 262 |
+
// // invalid JSON string
|
| 263 |
+
// expect(() => z.parse(a, '{"key":value}')).toThrow();
|
| 264 |
+
// expect(() => z.parse(a, '["item1", "item2"')).toThrow();
|
| 265 |
+
// expect(() => z.parse(a, "hello")).toThrow();
|
| 266 |
+
// // wrong type
|
| 267 |
+
// expect(() => z.parse(a, 123)).toThrow();
|
| 268 |
+
// });
|
| 269 |
+
|
| 270 |
+
test("z.e164", () => {
|
| 271 |
+
const a = z.e164();
|
| 272 |
+
// valid e164
|
| 273 |
+
expect(z.parse(a, "+1234567890")).toEqual("+1234567890");
|
| 274 |
+
expect(z.parse(a, "+19876543210")).toEqual("+19876543210");
|
| 275 |
+
// invalid e164
|
| 276 |
+
expect(() => z.parse(a, "1234567890")).toThrow();
|
| 277 |
+
expect(() => z.parse(a, "+12345")).toThrow();
|
| 278 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 279 |
+
// wrong type
|
| 280 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 281 |
+
});
|
| 282 |
+
|
| 283 |
+
test("z.jwt", () => {
|
| 284 |
+
const a = z.jwt();
|
| 285 |
+
// valid jwt
|
| 286 |
+
expect(
|
| 287 |
+
z.parse(
|
| 288 |
+
a,
|
| 289 |
+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
| 290 |
+
)
|
| 291 |
+
).toEqual(
|
| 292 |
+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
| 293 |
+
);
|
| 294 |
+
// invalid jwt
|
| 295 |
+
expect(() => z.parse(a, "invalid.jwt.token")).toThrow();
|
| 296 |
+
expect(() => z.parse(a, "hello")).toThrow();
|
| 297 |
+
// wrong type
|
| 298 |
+
expect(() => z.parse(a, 123)).toThrow();
|
| 299 |
+
});
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.cjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
|
| 4 |
+
const util_js_1 = require("./helpers/util.cjs");
|
| 5 |
+
exports.ZodIssueCode = util_js_1.util.arrayToEnum([
|
| 6 |
+
"invalid_type",
|
| 7 |
+
"invalid_literal",
|
| 8 |
+
"custom",
|
| 9 |
+
"invalid_union",
|
| 10 |
+
"invalid_union_discriminator",
|
| 11 |
+
"invalid_enum_value",
|
| 12 |
+
"unrecognized_keys",
|
| 13 |
+
"invalid_arguments",
|
| 14 |
+
"invalid_return_type",
|
| 15 |
+
"invalid_date",
|
| 16 |
+
"invalid_string",
|
| 17 |
+
"too_small",
|
| 18 |
+
"too_big",
|
| 19 |
+
"invalid_intersection_types",
|
| 20 |
+
"not_multiple_of",
|
| 21 |
+
"not_finite",
|
| 22 |
+
]);
|
| 23 |
+
const quotelessJson = (obj) => {
|
| 24 |
+
const json = JSON.stringify(obj, null, 2);
|
| 25 |
+
return json.replace(/"([^"]+)":/g, "$1:");
|
| 26 |
+
};
|
| 27 |
+
exports.quotelessJson = quotelessJson;
|
| 28 |
+
class ZodError extends Error {
|
| 29 |
+
get errors() {
|
| 30 |
+
return this.issues;
|
| 31 |
+
}
|
| 32 |
+
constructor(issues) {
|
| 33 |
+
super();
|
| 34 |
+
this.issues = [];
|
| 35 |
+
this.addIssue = (sub) => {
|
| 36 |
+
this.issues = [...this.issues, sub];
|
| 37 |
+
};
|
| 38 |
+
this.addIssues = (subs = []) => {
|
| 39 |
+
this.issues = [...this.issues, ...subs];
|
| 40 |
+
};
|
| 41 |
+
const actualProto = new.target.prototype;
|
| 42 |
+
if (Object.setPrototypeOf) {
|
| 43 |
+
// eslint-disable-next-line ban/ban
|
| 44 |
+
Object.setPrototypeOf(this, actualProto);
|
| 45 |
+
}
|
| 46 |
+
else {
|
| 47 |
+
this.__proto__ = actualProto;
|
| 48 |
+
}
|
| 49 |
+
this.name = "ZodError";
|
| 50 |
+
this.issues = issues;
|
| 51 |
+
}
|
| 52 |
+
format(_mapper) {
|
| 53 |
+
const mapper = _mapper ||
|
| 54 |
+
function (issue) {
|
| 55 |
+
return issue.message;
|
| 56 |
+
};
|
| 57 |
+
const fieldErrors = { _errors: [] };
|
| 58 |
+
const processError = (error) => {
|
| 59 |
+
for (const issue of error.issues) {
|
| 60 |
+
if (issue.code === "invalid_union") {
|
| 61 |
+
issue.unionErrors.map(processError);
|
| 62 |
+
}
|
| 63 |
+
else if (issue.code === "invalid_return_type") {
|
| 64 |
+
processError(issue.returnTypeError);
|
| 65 |
+
}
|
| 66 |
+
else if (issue.code === "invalid_arguments") {
|
| 67 |
+
processError(issue.argumentsError);
|
| 68 |
+
}
|
| 69 |
+
else if (issue.path.length === 0) {
|
| 70 |
+
fieldErrors._errors.push(mapper(issue));
|
| 71 |
+
}
|
| 72 |
+
else {
|
| 73 |
+
let curr = fieldErrors;
|
| 74 |
+
let i = 0;
|
| 75 |
+
while (i < issue.path.length) {
|
| 76 |
+
const el = issue.path[i];
|
| 77 |
+
const terminal = i === issue.path.length - 1;
|
| 78 |
+
if (!terminal) {
|
| 79 |
+
curr[el] = curr[el] || { _errors: [] };
|
| 80 |
+
// if (typeof el === "string") {
|
| 81 |
+
// curr[el] = curr[el] || { _errors: [] };
|
| 82 |
+
// } else if (typeof el === "number") {
|
| 83 |
+
// const errorArray: any = [];
|
| 84 |
+
// errorArray._errors = [];
|
| 85 |
+
// curr[el] = curr[el] || errorArray;
|
| 86 |
+
// }
|
| 87 |
+
}
|
| 88 |
+
else {
|
| 89 |
+
curr[el] = curr[el] || { _errors: [] };
|
| 90 |
+
curr[el]._errors.push(mapper(issue));
|
| 91 |
+
}
|
| 92 |
+
curr = curr[el];
|
| 93 |
+
i++;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
};
|
| 98 |
+
processError(this);
|
| 99 |
+
return fieldErrors;
|
| 100 |
+
}
|
| 101 |
+
static assert(value) {
|
| 102 |
+
if (!(value instanceof ZodError)) {
|
| 103 |
+
throw new Error(`Not a ZodError: ${value}`);
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
toString() {
|
| 107 |
+
return this.message;
|
| 108 |
+
}
|
| 109 |
+
get message() {
|
| 110 |
+
return JSON.stringify(this.issues, util_js_1.util.jsonStringifyReplacer, 2);
|
| 111 |
+
}
|
| 112 |
+
get isEmpty() {
|
| 113 |
+
return this.issues.length === 0;
|
| 114 |
+
}
|
| 115 |
+
flatten(mapper = (issue) => issue.message) {
|
| 116 |
+
const fieldErrors = {};
|
| 117 |
+
const formErrors = [];
|
| 118 |
+
for (const sub of this.issues) {
|
| 119 |
+
if (sub.path.length > 0) {
|
| 120 |
+
const firstEl = sub.path[0];
|
| 121 |
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
| 122 |
+
fieldErrors[firstEl].push(mapper(sub));
|
| 123 |
+
}
|
| 124 |
+
else {
|
| 125 |
+
formErrors.push(mapper(sub));
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return { formErrors, fieldErrors };
|
| 129 |
+
}
|
| 130 |
+
get formErrors() {
|
| 131 |
+
return this.flatten();
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
exports.ZodError = ZodError;
|
| 135 |
+
ZodError.create = (issues) => {
|
| 136 |
+
const error = new ZodError(issues);
|
| 137 |
+
return error;
|
| 138 |
+
};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.d.cts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Primitive } from "./helpers/typeAliases.cjs";
|
| 2 |
+
import { util, type ZodParsedType } from "./helpers/util.cjs";
|
| 3 |
+
import type { TypeOf, ZodType } from "./index.cjs";
|
| 4 |
+
type allKeys<T> = T extends any ? keyof T : never;
|
| 5 |
+
export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
| 6 |
+
export type typeToFlattenedError<T, U = string> = {
|
| 7 |
+
formErrors: U[];
|
| 8 |
+
fieldErrors: {
|
| 9 |
+
[P in allKeys<T>]?: U[];
|
| 10 |
+
};
|
| 11 |
+
};
|
| 12 |
+
export declare const ZodIssueCode: {
|
| 13 |
+
invalid_type: "invalid_type";
|
| 14 |
+
invalid_literal: "invalid_literal";
|
| 15 |
+
custom: "custom";
|
| 16 |
+
invalid_union: "invalid_union";
|
| 17 |
+
invalid_union_discriminator: "invalid_union_discriminator";
|
| 18 |
+
invalid_enum_value: "invalid_enum_value";
|
| 19 |
+
unrecognized_keys: "unrecognized_keys";
|
| 20 |
+
invalid_arguments: "invalid_arguments";
|
| 21 |
+
invalid_return_type: "invalid_return_type";
|
| 22 |
+
invalid_date: "invalid_date";
|
| 23 |
+
invalid_string: "invalid_string";
|
| 24 |
+
too_small: "too_small";
|
| 25 |
+
too_big: "too_big";
|
| 26 |
+
invalid_intersection_types: "invalid_intersection_types";
|
| 27 |
+
not_multiple_of: "not_multiple_of";
|
| 28 |
+
not_finite: "not_finite";
|
| 29 |
+
};
|
| 30 |
+
export type ZodIssueCode = keyof typeof ZodIssueCode;
|
| 31 |
+
export type ZodIssueBase = {
|
| 32 |
+
path: (string | number)[];
|
| 33 |
+
message?: string | undefined;
|
| 34 |
+
};
|
| 35 |
+
export interface ZodInvalidTypeIssue extends ZodIssueBase {
|
| 36 |
+
code: typeof ZodIssueCode.invalid_type;
|
| 37 |
+
expected: ZodParsedType;
|
| 38 |
+
received: ZodParsedType;
|
| 39 |
+
}
|
| 40 |
+
export interface ZodInvalidLiteralIssue extends ZodIssueBase {
|
| 41 |
+
code: typeof ZodIssueCode.invalid_literal;
|
| 42 |
+
expected: unknown;
|
| 43 |
+
received: unknown;
|
| 44 |
+
}
|
| 45 |
+
export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
|
| 46 |
+
code: typeof ZodIssueCode.unrecognized_keys;
|
| 47 |
+
keys: string[];
|
| 48 |
+
}
|
| 49 |
+
export interface ZodInvalidUnionIssue extends ZodIssueBase {
|
| 50 |
+
code: typeof ZodIssueCode.invalid_union;
|
| 51 |
+
unionErrors: ZodError[];
|
| 52 |
+
}
|
| 53 |
+
export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase {
|
| 54 |
+
code: typeof ZodIssueCode.invalid_union_discriminator;
|
| 55 |
+
options: Primitive[];
|
| 56 |
+
}
|
| 57 |
+
export interface ZodInvalidEnumValueIssue extends ZodIssueBase {
|
| 58 |
+
received: string | number;
|
| 59 |
+
code: typeof ZodIssueCode.invalid_enum_value;
|
| 60 |
+
options: (string | number)[];
|
| 61 |
+
}
|
| 62 |
+
export interface ZodInvalidArgumentsIssue extends ZodIssueBase {
|
| 63 |
+
code: typeof ZodIssueCode.invalid_arguments;
|
| 64 |
+
argumentsError: ZodError;
|
| 65 |
+
}
|
| 66 |
+
export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
|
| 67 |
+
code: typeof ZodIssueCode.invalid_return_type;
|
| 68 |
+
returnTypeError: ZodError;
|
| 69 |
+
}
|
| 70 |
+
export interface ZodInvalidDateIssue extends ZodIssueBase {
|
| 71 |
+
code: typeof ZodIssueCode.invalid_date;
|
| 72 |
+
}
|
| 73 |
+
export type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "cidr" | "base64" | "jwt" | "base64url" | {
|
| 74 |
+
includes: string;
|
| 75 |
+
position?: number | undefined;
|
| 76 |
+
} | {
|
| 77 |
+
startsWith: string;
|
| 78 |
+
} | {
|
| 79 |
+
endsWith: string;
|
| 80 |
+
};
|
| 81 |
+
export interface ZodInvalidStringIssue extends ZodIssueBase {
|
| 82 |
+
code: typeof ZodIssueCode.invalid_string;
|
| 83 |
+
validation: StringValidation;
|
| 84 |
+
}
|
| 85 |
+
export interface ZodTooSmallIssue extends ZodIssueBase {
|
| 86 |
+
code: typeof ZodIssueCode.too_small;
|
| 87 |
+
minimum: number | bigint;
|
| 88 |
+
inclusive: boolean;
|
| 89 |
+
exact?: boolean;
|
| 90 |
+
type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
| 91 |
+
}
|
| 92 |
+
export interface ZodTooBigIssue extends ZodIssueBase {
|
| 93 |
+
code: typeof ZodIssueCode.too_big;
|
| 94 |
+
maximum: number | bigint;
|
| 95 |
+
inclusive: boolean;
|
| 96 |
+
exact?: boolean;
|
| 97 |
+
type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
| 98 |
+
}
|
| 99 |
+
export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase {
|
| 100 |
+
code: typeof ZodIssueCode.invalid_intersection_types;
|
| 101 |
+
}
|
| 102 |
+
export interface ZodNotMultipleOfIssue extends ZodIssueBase {
|
| 103 |
+
code: typeof ZodIssueCode.not_multiple_of;
|
| 104 |
+
multipleOf: number | bigint;
|
| 105 |
+
}
|
| 106 |
+
export interface ZodNotFiniteIssue extends ZodIssueBase {
|
| 107 |
+
code: typeof ZodIssueCode.not_finite;
|
| 108 |
+
}
|
| 109 |
+
export interface ZodCustomIssue extends ZodIssueBase {
|
| 110 |
+
code: typeof ZodIssueCode.custom;
|
| 111 |
+
params?: {
|
| 112 |
+
[k: string]: any;
|
| 113 |
+
};
|
| 114 |
+
}
|
| 115 |
+
export type DenormalizedError = {
|
| 116 |
+
[k: string]: DenormalizedError | string[];
|
| 117 |
+
};
|
| 118 |
+
export type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
|
| 119 |
+
export type ZodIssue = ZodIssueOptionalMessage & {
|
| 120 |
+
fatal?: boolean | undefined;
|
| 121 |
+
message: string;
|
| 122 |
+
};
|
| 123 |
+
export declare const quotelessJson: (obj: any) => string;
|
| 124 |
+
type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? {
|
| 125 |
+
[K in keyof T]?: ZodFormattedError<T[K]>;
|
| 126 |
+
} : T extends any[] ? {
|
| 127 |
+
[k: number]: ZodFormattedError<T[number]>;
|
| 128 |
+
} : T extends object ? {
|
| 129 |
+
[K in keyof T]?: ZodFormattedError<T[K]>;
|
| 130 |
+
} : unknown;
|
| 131 |
+
export type ZodFormattedError<T, U = string> = {
|
| 132 |
+
_errors: U[];
|
| 133 |
+
} & recursiveZodFormattedError<NonNullable<T>>;
|
| 134 |
+
export type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
|
| 135 |
+
export declare class ZodError<T = any> extends Error {
|
| 136 |
+
issues: ZodIssue[];
|
| 137 |
+
get errors(): ZodIssue[];
|
| 138 |
+
constructor(issues: ZodIssue[]);
|
| 139 |
+
format(): ZodFormattedError<T>;
|
| 140 |
+
format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
|
| 141 |
+
static create: (issues: ZodIssue[]) => ZodError<any>;
|
| 142 |
+
static assert(value: unknown): asserts value is ZodError;
|
| 143 |
+
toString(): string;
|
| 144 |
+
get message(): string;
|
| 145 |
+
get isEmpty(): boolean;
|
| 146 |
+
addIssue: (sub: ZodIssue) => void;
|
| 147 |
+
addIssues: (subs?: ZodIssue[]) => void;
|
| 148 |
+
flatten(): typeToFlattenedError<T>;
|
| 149 |
+
flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
|
| 150 |
+
get formErrors(): typeToFlattenedError<T, string>;
|
| 151 |
+
}
|
| 152 |
+
type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
|
| 153 |
+
export type IssueData = stripPath<ZodIssueOptionalMessage> & {
|
| 154 |
+
path?: (string | number)[];
|
| 155 |
+
fatal?: boolean | undefined;
|
| 156 |
+
};
|
| 157 |
+
export type ErrorMapCtx = {
|
| 158 |
+
defaultError: string;
|
| 159 |
+
data: any;
|
| 160 |
+
};
|
| 161 |
+
export type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
|
| 162 |
+
message: string;
|
| 163 |
+
};
|
| 164 |
+
export {};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Primitive } from "./helpers/typeAliases.js";
|
| 2 |
+
import { util, type ZodParsedType } from "./helpers/util.js";
|
| 3 |
+
import type { TypeOf, ZodType } from "./index.js";
|
| 4 |
+
type allKeys<T> = T extends any ? keyof T : never;
|
| 5 |
+
export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
| 6 |
+
export type typeToFlattenedError<T, U = string> = {
|
| 7 |
+
formErrors: U[];
|
| 8 |
+
fieldErrors: {
|
| 9 |
+
[P in allKeys<T>]?: U[];
|
| 10 |
+
};
|
| 11 |
+
};
|
| 12 |
+
export declare const ZodIssueCode: {
|
| 13 |
+
invalid_type: "invalid_type";
|
| 14 |
+
invalid_literal: "invalid_literal";
|
| 15 |
+
custom: "custom";
|
| 16 |
+
invalid_union: "invalid_union";
|
| 17 |
+
invalid_union_discriminator: "invalid_union_discriminator";
|
| 18 |
+
invalid_enum_value: "invalid_enum_value";
|
| 19 |
+
unrecognized_keys: "unrecognized_keys";
|
| 20 |
+
invalid_arguments: "invalid_arguments";
|
| 21 |
+
invalid_return_type: "invalid_return_type";
|
| 22 |
+
invalid_date: "invalid_date";
|
| 23 |
+
invalid_string: "invalid_string";
|
| 24 |
+
too_small: "too_small";
|
| 25 |
+
too_big: "too_big";
|
| 26 |
+
invalid_intersection_types: "invalid_intersection_types";
|
| 27 |
+
not_multiple_of: "not_multiple_of";
|
| 28 |
+
not_finite: "not_finite";
|
| 29 |
+
};
|
| 30 |
+
export type ZodIssueCode = keyof typeof ZodIssueCode;
|
| 31 |
+
export type ZodIssueBase = {
|
| 32 |
+
path: (string | number)[];
|
| 33 |
+
message?: string | undefined;
|
| 34 |
+
};
|
| 35 |
+
export interface ZodInvalidTypeIssue extends ZodIssueBase {
|
| 36 |
+
code: typeof ZodIssueCode.invalid_type;
|
| 37 |
+
expected: ZodParsedType;
|
| 38 |
+
received: ZodParsedType;
|
| 39 |
+
}
|
| 40 |
+
export interface ZodInvalidLiteralIssue extends ZodIssueBase {
|
| 41 |
+
code: typeof ZodIssueCode.invalid_literal;
|
| 42 |
+
expected: unknown;
|
| 43 |
+
received: unknown;
|
| 44 |
+
}
|
| 45 |
+
export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
|
| 46 |
+
code: typeof ZodIssueCode.unrecognized_keys;
|
| 47 |
+
keys: string[];
|
| 48 |
+
}
|
| 49 |
+
export interface ZodInvalidUnionIssue extends ZodIssueBase {
|
| 50 |
+
code: typeof ZodIssueCode.invalid_union;
|
| 51 |
+
unionErrors: ZodError[];
|
| 52 |
+
}
|
| 53 |
+
export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase {
|
| 54 |
+
code: typeof ZodIssueCode.invalid_union_discriminator;
|
| 55 |
+
options: Primitive[];
|
| 56 |
+
}
|
| 57 |
+
export interface ZodInvalidEnumValueIssue extends ZodIssueBase {
|
| 58 |
+
received: string | number;
|
| 59 |
+
code: typeof ZodIssueCode.invalid_enum_value;
|
| 60 |
+
options: (string | number)[];
|
| 61 |
+
}
|
| 62 |
+
export interface ZodInvalidArgumentsIssue extends ZodIssueBase {
|
| 63 |
+
code: typeof ZodIssueCode.invalid_arguments;
|
| 64 |
+
argumentsError: ZodError;
|
| 65 |
+
}
|
| 66 |
+
export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
|
| 67 |
+
code: typeof ZodIssueCode.invalid_return_type;
|
| 68 |
+
returnTypeError: ZodError;
|
| 69 |
+
}
|
| 70 |
+
export interface ZodInvalidDateIssue extends ZodIssueBase {
|
| 71 |
+
code: typeof ZodIssueCode.invalid_date;
|
| 72 |
+
}
|
| 73 |
+
export type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "cidr" | "base64" | "jwt" | "base64url" | {
|
| 74 |
+
includes: string;
|
| 75 |
+
position?: number | undefined;
|
| 76 |
+
} | {
|
| 77 |
+
startsWith: string;
|
| 78 |
+
} | {
|
| 79 |
+
endsWith: string;
|
| 80 |
+
};
|
| 81 |
+
export interface ZodInvalidStringIssue extends ZodIssueBase {
|
| 82 |
+
code: typeof ZodIssueCode.invalid_string;
|
| 83 |
+
validation: StringValidation;
|
| 84 |
+
}
|
| 85 |
+
export interface ZodTooSmallIssue extends ZodIssueBase {
|
| 86 |
+
code: typeof ZodIssueCode.too_small;
|
| 87 |
+
minimum: number | bigint;
|
| 88 |
+
inclusive: boolean;
|
| 89 |
+
exact?: boolean;
|
| 90 |
+
type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
| 91 |
+
}
|
| 92 |
+
export interface ZodTooBigIssue extends ZodIssueBase {
|
| 93 |
+
code: typeof ZodIssueCode.too_big;
|
| 94 |
+
maximum: number | bigint;
|
| 95 |
+
inclusive: boolean;
|
| 96 |
+
exact?: boolean;
|
| 97 |
+
type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
| 98 |
+
}
|
| 99 |
+
export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase {
|
| 100 |
+
code: typeof ZodIssueCode.invalid_intersection_types;
|
| 101 |
+
}
|
| 102 |
+
export interface ZodNotMultipleOfIssue extends ZodIssueBase {
|
| 103 |
+
code: typeof ZodIssueCode.not_multiple_of;
|
| 104 |
+
multipleOf: number | bigint;
|
| 105 |
+
}
|
| 106 |
+
export interface ZodNotFiniteIssue extends ZodIssueBase {
|
| 107 |
+
code: typeof ZodIssueCode.not_finite;
|
| 108 |
+
}
|
| 109 |
+
export interface ZodCustomIssue extends ZodIssueBase {
|
| 110 |
+
code: typeof ZodIssueCode.custom;
|
| 111 |
+
params?: {
|
| 112 |
+
[k: string]: any;
|
| 113 |
+
};
|
| 114 |
+
}
|
| 115 |
+
export type DenormalizedError = {
|
| 116 |
+
[k: string]: DenormalizedError | string[];
|
| 117 |
+
};
|
| 118 |
+
export type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
|
| 119 |
+
export type ZodIssue = ZodIssueOptionalMessage & {
|
| 120 |
+
fatal?: boolean | undefined;
|
| 121 |
+
message: string;
|
| 122 |
+
};
|
| 123 |
+
export declare const quotelessJson: (obj: any) => string;
|
| 124 |
+
type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? {
|
| 125 |
+
[K in keyof T]?: ZodFormattedError<T[K]>;
|
| 126 |
+
} : T extends any[] ? {
|
| 127 |
+
[k: number]: ZodFormattedError<T[number]>;
|
| 128 |
+
} : T extends object ? {
|
| 129 |
+
[K in keyof T]?: ZodFormattedError<T[K]>;
|
| 130 |
+
} : unknown;
|
| 131 |
+
export type ZodFormattedError<T, U = string> = {
|
| 132 |
+
_errors: U[];
|
| 133 |
+
} & recursiveZodFormattedError<NonNullable<T>>;
|
| 134 |
+
export type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
|
| 135 |
+
export declare class ZodError<T = any> extends Error {
|
| 136 |
+
issues: ZodIssue[];
|
| 137 |
+
get errors(): ZodIssue[];
|
| 138 |
+
constructor(issues: ZodIssue[]);
|
| 139 |
+
format(): ZodFormattedError<T>;
|
| 140 |
+
format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
|
| 141 |
+
static create: (issues: ZodIssue[]) => ZodError<any>;
|
| 142 |
+
static assert(value: unknown): asserts value is ZodError;
|
| 143 |
+
toString(): string;
|
| 144 |
+
get message(): string;
|
| 145 |
+
get isEmpty(): boolean;
|
| 146 |
+
addIssue: (sub: ZodIssue) => void;
|
| 147 |
+
addIssues: (subs?: ZodIssue[]) => void;
|
| 148 |
+
flatten(): typeToFlattenedError<T>;
|
| 149 |
+
flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
|
| 150 |
+
get formErrors(): typeToFlattenedError<T, string>;
|
| 151 |
+
}
|
| 152 |
+
type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
|
| 153 |
+
export type IssueData = stripPath<ZodIssueOptionalMessage> & {
|
| 154 |
+
path?: (string | number)[];
|
| 155 |
+
fatal?: boolean | undefined;
|
| 156 |
+
};
|
| 157 |
+
export type ErrorMapCtx = {
|
| 158 |
+
defaultError: string;
|
| 159 |
+
data: any;
|
| 160 |
+
};
|
| 161 |
+
export type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
|
| 162 |
+
message: string;
|
| 163 |
+
};
|
| 164 |
+
export {};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/ZodError.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { util } from "./helpers/util.js";
|
| 2 |
+
export const ZodIssueCode = util.arrayToEnum([
|
| 3 |
+
"invalid_type",
|
| 4 |
+
"invalid_literal",
|
| 5 |
+
"custom",
|
| 6 |
+
"invalid_union",
|
| 7 |
+
"invalid_union_discriminator",
|
| 8 |
+
"invalid_enum_value",
|
| 9 |
+
"unrecognized_keys",
|
| 10 |
+
"invalid_arguments",
|
| 11 |
+
"invalid_return_type",
|
| 12 |
+
"invalid_date",
|
| 13 |
+
"invalid_string",
|
| 14 |
+
"too_small",
|
| 15 |
+
"too_big",
|
| 16 |
+
"invalid_intersection_types",
|
| 17 |
+
"not_multiple_of",
|
| 18 |
+
"not_finite",
|
| 19 |
+
]);
|
| 20 |
+
export const quotelessJson = (obj) => {
|
| 21 |
+
const json = JSON.stringify(obj, null, 2);
|
| 22 |
+
return json.replace(/"([^"]+)":/g, "$1:");
|
| 23 |
+
};
|
| 24 |
+
export class ZodError extends Error {
|
| 25 |
+
get errors() {
|
| 26 |
+
return this.issues;
|
| 27 |
+
}
|
| 28 |
+
constructor(issues) {
|
| 29 |
+
super();
|
| 30 |
+
this.issues = [];
|
| 31 |
+
this.addIssue = (sub) => {
|
| 32 |
+
this.issues = [...this.issues, sub];
|
| 33 |
+
};
|
| 34 |
+
this.addIssues = (subs = []) => {
|
| 35 |
+
this.issues = [...this.issues, ...subs];
|
| 36 |
+
};
|
| 37 |
+
const actualProto = new.target.prototype;
|
| 38 |
+
if (Object.setPrototypeOf) {
|
| 39 |
+
// eslint-disable-next-line ban/ban
|
| 40 |
+
Object.setPrototypeOf(this, actualProto);
|
| 41 |
+
}
|
| 42 |
+
else {
|
| 43 |
+
this.__proto__ = actualProto;
|
| 44 |
+
}
|
| 45 |
+
this.name = "ZodError";
|
| 46 |
+
this.issues = issues;
|
| 47 |
+
}
|
| 48 |
+
format(_mapper) {
|
| 49 |
+
const mapper = _mapper ||
|
| 50 |
+
function (issue) {
|
| 51 |
+
return issue.message;
|
| 52 |
+
};
|
| 53 |
+
const fieldErrors = { _errors: [] };
|
| 54 |
+
const processError = (error) => {
|
| 55 |
+
for (const issue of error.issues) {
|
| 56 |
+
if (issue.code === "invalid_union") {
|
| 57 |
+
issue.unionErrors.map(processError);
|
| 58 |
+
}
|
| 59 |
+
else if (issue.code === "invalid_return_type") {
|
| 60 |
+
processError(issue.returnTypeError);
|
| 61 |
+
}
|
| 62 |
+
else if (issue.code === "invalid_arguments") {
|
| 63 |
+
processError(issue.argumentsError);
|
| 64 |
+
}
|
| 65 |
+
else if (issue.path.length === 0) {
|
| 66 |
+
fieldErrors._errors.push(mapper(issue));
|
| 67 |
+
}
|
| 68 |
+
else {
|
| 69 |
+
let curr = fieldErrors;
|
| 70 |
+
let i = 0;
|
| 71 |
+
while (i < issue.path.length) {
|
| 72 |
+
const el = issue.path[i];
|
| 73 |
+
const terminal = i === issue.path.length - 1;
|
| 74 |
+
if (!terminal) {
|
| 75 |
+
curr[el] = curr[el] || { _errors: [] };
|
| 76 |
+
// if (typeof el === "string") {
|
| 77 |
+
// curr[el] = curr[el] || { _errors: [] };
|
| 78 |
+
// } else if (typeof el === "number") {
|
| 79 |
+
// const errorArray: any = [];
|
| 80 |
+
// errorArray._errors = [];
|
| 81 |
+
// curr[el] = curr[el] || errorArray;
|
| 82 |
+
// }
|
| 83 |
+
}
|
| 84 |
+
else {
|
| 85 |
+
curr[el] = curr[el] || { _errors: [] };
|
| 86 |
+
curr[el]._errors.push(mapper(issue));
|
| 87 |
+
}
|
| 88 |
+
curr = curr[el];
|
| 89 |
+
i++;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
};
|
| 94 |
+
processError(this);
|
| 95 |
+
return fieldErrors;
|
| 96 |
+
}
|
| 97 |
+
static assert(value) {
|
| 98 |
+
if (!(value instanceof ZodError)) {
|
| 99 |
+
throw new Error(`Not a ZodError: ${value}`);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
toString() {
|
| 103 |
+
return this.message;
|
| 104 |
+
}
|
| 105 |
+
get message() {
|
| 106 |
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
| 107 |
+
}
|
| 108 |
+
get isEmpty() {
|
| 109 |
+
return this.issues.length === 0;
|
| 110 |
+
}
|
| 111 |
+
flatten(mapper = (issue) => issue.message) {
|
| 112 |
+
const fieldErrors = {};
|
| 113 |
+
const formErrors = [];
|
| 114 |
+
for (const sub of this.issues) {
|
| 115 |
+
if (sub.path.length > 0) {
|
| 116 |
+
const firstEl = sub.path[0];
|
| 117 |
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
| 118 |
+
fieldErrors[firstEl].push(mapper(sub));
|
| 119 |
+
}
|
| 120 |
+
else {
|
| 121 |
+
formErrors.push(mapper(sub));
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
return { formErrors, fieldErrors };
|
| 125 |
+
}
|
| 126 |
+
get formErrors() {
|
| 127 |
+
return this.flatten();
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
ZodError.create = (issues) => {
|
| 131 |
+
const error = new ZodError(issues);
|
| 132 |
+
return error;
|
| 133 |
+
};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
| 3 |
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
| 4 |
+
};
|
| 5 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 6 |
+
exports.defaultErrorMap = void 0;
|
| 7 |
+
exports.setErrorMap = setErrorMap;
|
| 8 |
+
exports.getErrorMap = getErrorMap;
|
| 9 |
+
const en_js_1 = __importDefault(require("./locales/en.cjs"));
|
| 10 |
+
exports.defaultErrorMap = en_js_1.default;
|
| 11 |
+
let overrideErrorMap = en_js_1.default;
|
| 12 |
+
function setErrorMap(map) {
|
| 13 |
+
overrideErrorMap = map;
|
| 14 |
+
}
|
| 15 |
+
function getErrorMap() {
|
| 16 |
+
return overrideErrorMap;
|
| 17 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ZodErrorMap } from "./ZodError.cjs";
|
| 2 |
+
import defaultErrorMap from "./locales/en.cjs";
|
| 3 |
+
export { defaultErrorMap };
|
| 4 |
+
export declare function setErrorMap(map: ZodErrorMap): void;
|
| 5 |
+
export declare function getErrorMap(): ZodErrorMap;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ZodErrorMap } from "./ZodError.js";
|
| 2 |
+
import defaultErrorMap from "./locales/en.js";
|
| 3 |
+
export { defaultErrorMap };
|
| 4 |
+
export declare function setErrorMap(map: ZodErrorMap): void;
|
| 5 |
+
export declare function getErrorMap(): ZodErrorMap;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/errors.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import defaultErrorMap from "./locales/en.js";
|
| 2 |
+
let overrideErrorMap = defaultErrorMap;
|
| 3 |
+
export { defaultErrorMap };
|
| 4 |
+
export function setErrorMap(map) {
|
| 5 |
+
overrideErrorMap = map;
|
| 6 |
+
}
|
| 7 |
+
export function getErrorMap() {
|
| 8 |
+
return overrideErrorMap;
|
| 9 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 3 |
+
if (k2 === undefined) k2 = k;
|
| 4 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 5 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 6 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 7 |
+
}
|
| 8 |
+
Object.defineProperty(o, k2, desc);
|
| 9 |
+
}) : (function(o, m, k, k2) {
|
| 10 |
+
if (k2 === undefined) k2 = k;
|
| 11 |
+
o[k2] = m[k];
|
| 12 |
+
}));
|
| 13 |
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
| 14 |
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
| 15 |
+
};
|
| 16 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 17 |
+
__exportStar(require("./errors.cjs"), exports);
|
| 18 |
+
__exportStar(require("./helpers/parseUtil.cjs"), exports);
|
| 19 |
+
__exportStar(require("./helpers/typeAliases.cjs"), exports);
|
| 20 |
+
__exportStar(require("./helpers/util.cjs"), exports);
|
| 21 |
+
__exportStar(require("./types.cjs"), exports);
|
| 22 |
+
__exportStar(require("./ZodError.cjs"), exports);
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from "./errors.cjs";
|
| 2 |
+
export * from "./helpers/parseUtil.cjs";
|
| 3 |
+
export * from "./helpers/typeAliases.cjs";
|
| 4 |
+
export * from "./helpers/util.cjs";
|
| 5 |
+
export * from "./types.cjs";
|
| 6 |
+
export * from "./ZodError.cjs";
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from "./errors.js";
|
| 2 |
+
export * from "./helpers/parseUtil.js";
|
| 3 |
+
export * from "./helpers/typeAliases.js";
|
| 4 |
+
export * from "./helpers/util.js";
|
| 5 |
+
export * from "./types.js";
|
| 6 |
+
export * from "./ZodError.js";
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/external.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from "./errors.js";
|
| 2 |
+
export * from "./helpers/parseUtil.js";
|
| 3 |
+
export * from "./helpers/typeAliases.js";
|
| 4 |
+
export * from "./helpers/util.js";
|
| 5 |
+
export * from "./types.js";
|
| 6 |
+
export * from "./ZodError.js";
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare namespace enumUtil {
|
| 2 |
+
type UnionToIntersectionFn<T> = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never;
|
| 3 |
+
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last ? Last : never;
|
| 4 |
+
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] ? Tuple : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>;
|
| 5 |
+
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never;
|
| 6 |
+
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>;
|
| 7 |
+
export {};
|
| 8 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare namespace enumUtil {
|
| 2 |
+
type UnionToIntersectionFn<T> = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never;
|
| 3 |
+
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last ? Last : never;
|
| 4 |
+
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] ? Tuple : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>;
|
| 5 |
+
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never;
|
| 6 |
+
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>;
|
| 7 |
+
export {};
|
| 8 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/enumUtil.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export {};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.errorUtil = void 0;
|
| 4 |
+
var errorUtil;
|
| 5 |
+
(function (errorUtil) {
|
| 6 |
+
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
| 7 |
+
// biome-ignore lint:
|
| 8 |
+
errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
|
| 9 |
+
})(errorUtil || (exports.errorUtil = errorUtil = {}));
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare namespace errorUtil {
|
| 2 |
+
type ErrMessage = string | {
|
| 3 |
+
message?: string | undefined;
|
| 4 |
+
};
|
| 5 |
+
const errToObj: (message?: ErrMessage) => {
|
| 6 |
+
message?: string | undefined;
|
| 7 |
+
};
|
| 8 |
+
const toString: (message?: ErrMessage) => string | undefined;
|
| 9 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare namespace errorUtil {
|
| 2 |
+
type ErrMessage = string | {
|
| 3 |
+
message?: string | undefined;
|
| 4 |
+
};
|
| 5 |
+
const errToObj: (message?: ErrMessage) => {
|
| 6 |
+
message?: string | undefined;
|
| 7 |
+
};
|
| 8 |
+
const toString: (message?: ErrMessage) => string | undefined;
|
| 9 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/errorUtil.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export var errorUtil;
|
| 2 |
+
(function (errorUtil) {
|
| 3 |
+
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
| 4 |
+
// biome-ignore lint:
|
| 5 |
+
errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
|
| 6 |
+
})(errorUtil || (errorUtil = {}));
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.cjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
| 3 |
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
| 4 |
+
};
|
| 5 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 6 |
+
exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.EMPTY_PATH = exports.makeIssue = void 0;
|
| 7 |
+
exports.addIssueToContext = addIssueToContext;
|
| 8 |
+
const errors_js_1 = require("../errors.cjs");
|
| 9 |
+
const en_js_1 = __importDefault(require("../locales/en.cjs"));
|
| 10 |
+
const makeIssue = (params) => {
|
| 11 |
+
const { data, path, errorMaps, issueData } = params;
|
| 12 |
+
const fullPath = [...path, ...(issueData.path || [])];
|
| 13 |
+
const fullIssue = {
|
| 14 |
+
...issueData,
|
| 15 |
+
path: fullPath,
|
| 16 |
+
};
|
| 17 |
+
if (issueData.message !== undefined) {
|
| 18 |
+
return {
|
| 19 |
+
...issueData,
|
| 20 |
+
path: fullPath,
|
| 21 |
+
message: issueData.message,
|
| 22 |
+
};
|
| 23 |
+
}
|
| 24 |
+
let errorMessage = "";
|
| 25 |
+
const maps = errorMaps
|
| 26 |
+
.filter((m) => !!m)
|
| 27 |
+
.slice()
|
| 28 |
+
.reverse();
|
| 29 |
+
for (const map of maps) {
|
| 30 |
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
| 31 |
+
}
|
| 32 |
+
return {
|
| 33 |
+
...issueData,
|
| 34 |
+
path: fullPath,
|
| 35 |
+
message: errorMessage,
|
| 36 |
+
};
|
| 37 |
+
};
|
| 38 |
+
exports.makeIssue = makeIssue;
|
| 39 |
+
exports.EMPTY_PATH = [];
|
| 40 |
+
function addIssueToContext(ctx, issueData) {
|
| 41 |
+
const overrideMap = (0, errors_js_1.getErrorMap)();
|
| 42 |
+
const issue = (0, exports.makeIssue)({
|
| 43 |
+
issueData: issueData,
|
| 44 |
+
data: ctx.data,
|
| 45 |
+
path: ctx.path,
|
| 46 |
+
errorMaps: [
|
| 47 |
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
| 48 |
+
ctx.schemaErrorMap, // then schema-bound map if available
|
| 49 |
+
overrideMap, // then global override map
|
| 50 |
+
overrideMap === en_js_1.default ? undefined : en_js_1.default, // then global default map
|
| 51 |
+
].filter((x) => !!x),
|
| 52 |
+
});
|
| 53 |
+
ctx.common.issues.push(issue);
|
| 54 |
+
}
|
| 55 |
+
class ParseStatus {
|
| 56 |
+
constructor() {
|
| 57 |
+
this.value = "valid";
|
| 58 |
+
}
|
| 59 |
+
dirty() {
|
| 60 |
+
if (this.value === "valid")
|
| 61 |
+
this.value = "dirty";
|
| 62 |
+
}
|
| 63 |
+
abort() {
|
| 64 |
+
if (this.value !== "aborted")
|
| 65 |
+
this.value = "aborted";
|
| 66 |
+
}
|
| 67 |
+
static mergeArray(status, results) {
|
| 68 |
+
const arrayValue = [];
|
| 69 |
+
for (const s of results) {
|
| 70 |
+
if (s.status === "aborted")
|
| 71 |
+
return exports.INVALID;
|
| 72 |
+
if (s.status === "dirty")
|
| 73 |
+
status.dirty();
|
| 74 |
+
arrayValue.push(s.value);
|
| 75 |
+
}
|
| 76 |
+
return { status: status.value, value: arrayValue };
|
| 77 |
+
}
|
| 78 |
+
static async mergeObjectAsync(status, pairs) {
|
| 79 |
+
const syncPairs = [];
|
| 80 |
+
for (const pair of pairs) {
|
| 81 |
+
const key = await pair.key;
|
| 82 |
+
const value = await pair.value;
|
| 83 |
+
syncPairs.push({
|
| 84 |
+
key,
|
| 85 |
+
value,
|
| 86 |
+
});
|
| 87 |
+
}
|
| 88 |
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
| 89 |
+
}
|
| 90 |
+
static mergeObjectSync(status, pairs) {
|
| 91 |
+
const finalObject = {};
|
| 92 |
+
for (const pair of pairs) {
|
| 93 |
+
const { key, value } = pair;
|
| 94 |
+
if (key.status === "aborted")
|
| 95 |
+
return exports.INVALID;
|
| 96 |
+
if (value.status === "aborted")
|
| 97 |
+
return exports.INVALID;
|
| 98 |
+
if (key.status === "dirty")
|
| 99 |
+
status.dirty();
|
| 100 |
+
if (value.status === "dirty")
|
| 101 |
+
status.dirty();
|
| 102 |
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
| 103 |
+
finalObject[key.value] = value.value;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
return { status: status.value, value: finalObject };
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
exports.ParseStatus = ParseStatus;
|
| 110 |
+
exports.INVALID = Object.freeze({
|
| 111 |
+
status: "aborted",
|
| 112 |
+
});
|
| 113 |
+
const DIRTY = (value) => ({ status: "dirty", value });
|
| 114 |
+
exports.DIRTY = DIRTY;
|
| 115 |
+
const OK = (value) => ({ status: "valid", value });
|
| 116 |
+
exports.OK = OK;
|
| 117 |
+
const isAborted = (x) => x.status === "aborted";
|
| 118 |
+
exports.isAborted = isAborted;
|
| 119 |
+
const isDirty = (x) => x.status === "dirty";
|
| 120 |
+
exports.isDirty = isDirty;
|
| 121 |
+
const isValid = (x) => x.status === "valid";
|
| 122 |
+
exports.isValid = isValid;
|
| 123 |
+
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
| 124 |
+
exports.isAsync = isAsync;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.d.cts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.cjs";
|
| 2 |
+
import type { ZodParsedType } from "./util.cjs";
|
| 3 |
+
export declare const makeIssue: (params: {
|
| 4 |
+
data: any;
|
| 5 |
+
path: (string | number)[];
|
| 6 |
+
errorMaps: ZodErrorMap[];
|
| 7 |
+
issueData: IssueData;
|
| 8 |
+
}) => ZodIssue;
|
| 9 |
+
export type ParseParams = {
|
| 10 |
+
path: (string | number)[];
|
| 11 |
+
errorMap: ZodErrorMap;
|
| 12 |
+
async: boolean;
|
| 13 |
+
};
|
| 14 |
+
export type ParsePathComponent = string | number;
|
| 15 |
+
export type ParsePath = ParsePathComponent[];
|
| 16 |
+
export declare const EMPTY_PATH: ParsePath;
|
| 17 |
+
export interface ParseContext {
|
| 18 |
+
readonly common: {
|
| 19 |
+
readonly issues: ZodIssue[];
|
| 20 |
+
readonly contextualErrorMap?: ZodErrorMap | undefined;
|
| 21 |
+
readonly async: boolean;
|
| 22 |
+
};
|
| 23 |
+
readonly path: ParsePath;
|
| 24 |
+
readonly schemaErrorMap?: ZodErrorMap | undefined;
|
| 25 |
+
readonly parent: ParseContext | null;
|
| 26 |
+
readonly data: any;
|
| 27 |
+
readonly parsedType: ZodParsedType;
|
| 28 |
+
}
|
| 29 |
+
export type ParseInput = {
|
| 30 |
+
data: any;
|
| 31 |
+
path: (string | number)[];
|
| 32 |
+
parent: ParseContext;
|
| 33 |
+
};
|
| 34 |
+
export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
|
| 35 |
+
export type ObjectPair = {
|
| 36 |
+
key: SyncParseReturnType<any>;
|
| 37 |
+
value: SyncParseReturnType<any>;
|
| 38 |
+
};
|
| 39 |
+
export declare class ParseStatus {
|
| 40 |
+
value: "aborted" | "dirty" | "valid";
|
| 41 |
+
dirty(): void;
|
| 42 |
+
abort(): void;
|
| 43 |
+
static mergeArray(status: ParseStatus, results: SyncParseReturnType<any>[]): SyncParseReturnType;
|
| 44 |
+
static mergeObjectAsync(status: ParseStatus, pairs: {
|
| 45 |
+
key: ParseReturnType<any>;
|
| 46 |
+
value: ParseReturnType<any>;
|
| 47 |
+
}[]): Promise<SyncParseReturnType<any>>;
|
| 48 |
+
static mergeObjectSync(status: ParseStatus, pairs: {
|
| 49 |
+
key: SyncParseReturnType<any>;
|
| 50 |
+
value: SyncParseReturnType<any>;
|
| 51 |
+
alwaysSet?: boolean;
|
| 52 |
+
}[]): SyncParseReturnType;
|
| 53 |
+
}
|
| 54 |
+
export interface ParseResult {
|
| 55 |
+
status: "aborted" | "dirty" | "valid";
|
| 56 |
+
data: any;
|
| 57 |
+
}
|
| 58 |
+
export type INVALID = {
|
| 59 |
+
status: "aborted";
|
| 60 |
+
};
|
| 61 |
+
export declare const INVALID: INVALID;
|
| 62 |
+
export type DIRTY<T> = {
|
| 63 |
+
status: "dirty";
|
| 64 |
+
value: T;
|
| 65 |
+
};
|
| 66 |
+
export declare const DIRTY: <T>(value: T) => DIRTY<T>;
|
| 67 |
+
export type OK<T> = {
|
| 68 |
+
status: "valid";
|
| 69 |
+
value: T;
|
| 70 |
+
};
|
| 71 |
+
export declare const OK: <T>(value: T) => OK<T>;
|
| 72 |
+
export type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
|
| 73 |
+
export type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
|
| 74 |
+
export type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
|
| 75 |
+
export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
|
| 76 |
+
export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
|
| 77 |
+
export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T>;
|
| 78 |
+
export declare const isAsync: <T>(x: ParseReturnType<T>) => x is AsyncParseReturnType<T>;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.js";
|
| 2 |
+
import type { ZodParsedType } from "./util.js";
|
| 3 |
+
export declare const makeIssue: (params: {
|
| 4 |
+
data: any;
|
| 5 |
+
path: (string | number)[];
|
| 6 |
+
errorMaps: ZodErrorMap[];
|
| 7 |
+
issueData: IssueData;
|
| 8 |
+
}) => ZodIssue;
|
| 9 |
+
export type ParseParams = {
|
| 10 |
+
path: (string | number)[];
|
| 11 |
+
errorMap: ZodErrorMap;
|
| 12 |
+
async: boolean;
|
| 13 |
+
};
|
| 14 |
+
export type ParsePathComponent = string | number;
|
| 15 |
+
export type ParsePath = ParsePathComponent[];
|
| 16 |
+
export declare const EMPTY_PATH: ParsePath;
|
| 17 |
+
export interface ParseContext {
|
| 18 |
+
readonly common: {
|
| 19 |
+
readonly issues: ZodIssue[];
|
| 20 |
+
readonly contextualErrorMap?: ZodErrorMap | undefined;
|
| 21 |
+
readonly async: boolean;
|
| 22 |
+
};
|
| 23 |
+
readonly path: ParsePath;
|
| 24 |
+
readonly schemaErrorMap?: ZodErrorMap | undefined;
|
| 25 |
+
readonly parent: ParseContext | null;
|
| 26 |
+
readonly data: any;
|
| 27 |
+
readonly parsedType: ZodParsedType;
|
| 28 |
+
}
|
| 29 |
+
export type ParseInput = {
|
| 30 |
+
data: any;
|
| 31 |
+
path: (string | number)[];
|
| 32 |
+
parent: ParseContext;
|
| 33 |
+
};
|
| 34 |
+
export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
|
| 35 |
+
export type ObjectPair = {
|
| 36 |
+
key: SyncParseReturnType<any>;
|
| 37 |
+
value: SyncParseReturnType<any>;
|
| 38 |
+
};
|
| 39 |
+
export declare class ParseStatus {
|
| 40 |
+
value: "aborted" | "dirty" | "valid";
|
| 41 |
+
dirty(): void;
|
| 42 |
+
abort(): void;
|
| 43 |
+
static mergeArray(status: ParseStatus, results: SyncParseReturnType<any>[]): SyncParseReturnType;
|
| 44 |
+
static mergeObjectAsync(status: ParseStatus, pairs: {
|
| 45 |
+
key: ParseReturnType<any>;
|
| 46 |
+
value: ParseReturnType<any>;
|
| 47 |
+
}[]): Promise<SyncParseReturnType<any>>;
|
| 48 |
+
static mergeObjectSync(status: ParseStatus, pairs: {
|
| 49 |
+
key: SyncParseReturnType<any>;
|
| 50 |
+
value: SyncParseReturnType<any>;
|
| 51 |
+
alwaysSet?: boolean;
|
| 52 |
+
}[]): SyncParseReturnType;
|
| 53 |
+
}
|
| 54 |
+
export interface ParseResult {
|
| 55 |
+
status: "aborted" | "dirty" | "valid";
|
| 56 |
+
data: any;
|
| 57 |
+
}
|
| 58 |
+
export type INVALID = {
|
| 59 |
+
status: "aborted";
|
| 60 |
+
};
|
| 61 |
+
export declare const INVALID: INVALID;
|
| 62 |
+
export type DIRTY<T> = {
|
| 63 |
+
status: "dirty";
|
| 64 |
+
value: T;
|
| 65 |
+
};
|
| 66 |
+
export declare const DIRTY: <T>(value: T) => DIRTY<T>;
|
| 67 |
+
export type OK<T> = {
|
| 68 |
+
status: "valid";
|
| 69 |
+
value: T;
|
| 70 |
+
};
|
| 71 |
+
export declare const OK: <T>(value: T) => OK<T>;
|
| 72 |
+
export type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
|
| 73 |
+
export type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
|
| 74 |
+
export type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
|
| 75 |
+
export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
|
| 76 |
+
export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
|
| 77 |
+
export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T>;
|
| 78 |
+
export declare const isAsync: <T>(x: ParseReturnType<T>) => x is AsyncParseReturnType<T>;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/parseUtil.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getErrorMap } from "../errors.js";
|
| 2 |
+
import defaultErrorMap from "../locales/en.js";
|
| 3 |
+
export const makeIssue = (params) => {
|
| 4 |
+
const { data, path, errorMaps, issueData } = params;
|
| 5 |
+
const fullPath = [...path, ...(issueData.path || [])];
|
| 6 |
+
const fullIssue = {
|
| 7 |
+
...issueData,
|
| 8 |
+
path: fullPath,
|
| 9 |
+
};
|
| 10 |
+
if (issueData.message !== undefined) {
|
| 11 |
+
return {
|
| 12 |
+
...issueData,
|
| 13 |
+
path: fullPath,
|
| 14 |
+
message: issueData.message,
|
| 15 |
+
};
|
| 16 |
+
}
|
| 17 |
+
let errorMessage = "";
|
| 18 |
+
const maps = errorMaps
|
| 19 |
+
.filter((m) => !!m)
|
| 20 |
+
.slice()
|
| 21 |
+
.reverse();
|
| 22 |
+
for (const map of maps) {
|
| 23 |
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
| 24 |
+
}
|
| 25 |
+
return {
|
| 26 |
+
...issueData,
|
| 27 |
+
path: fullPath,
|
| 28 |
+
message: errorMessage,
|
| 29 |
+
};
|
| 30 |
+
};
|
| 31 |
+
export const EMPTY_PATH = [];
|
| 32 |
+
export function addIssueToContext(ctx, issueData) {
|
| 33 |
+
const overrideMap = getErrorMap();
|
| 34 |
+
const issue = makeIssue({
|
| 35 |
+
issueData: issueData,
|
| 36 |
+
data: ctx.data,
|
| 37 |
+
path: ctx.path,
|
| 38 |
+
errorMaps: [
|
| 39 |
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
| 40 |
+
ctx.schemaErrorMap, // then schema-bound map if available
|
| 41 |
+
overrideMap, // then global override map
|
| 42 |
+
overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map
|
| 43 |
+
].filter((x) => !!x),
|
| 44 |
+
});
|
| 45 |
+
ctx.common.issues.push(issue);
|
| 46 |
+
}
|
| 47 |
+
export class ParseStatus {
|
| 48 |
+
constructor() {
|
| 49 |
+
this.value = "valid";
|
| 50 |
+
}
|
| 51 |
+
dirty() {
|
| 52 |
+
if (this.value === "valid")
|
| 53 |
+
this.value = "dirty";
|
| 54 |
+
}
|
| 55 |
+
abort() {
|
| 56 |
+
if (this.value !== "aborted")
|
| 57 |
+
this.value = "aborted";
|
| 58 |
+
}
|
| 59 |
+
static mergeArray(status, results) {
|
| 60 |
+
const arrayValue = [];
|
| 61 |
+
for (const s of results) {
|
| 62 |
+
if (s.status === "aborted")
|
| 63 |
+
return INVALID;
|
| 64 |
+
if (s.status === "dirty")
|
| 65 |
+
status.dirty();
|
| 66 |
+
arrayValue.push(s.value);
|
| 67 |
+
}
|
| 68 |
+
return { status: status.value, value: arrayValue };
|
| 69 |
+
}
|
| 70 |
+
static async mergeObjectAsync(status, pairs) {
|
| 71 |
+
const syncPairs = [];
|
| 72 |
+
for (const pair of pairs) {
|
| 73 |
+
const key = await pair.key;
|
| 74 |
+
const value = await pair.value;
|
| 75 |
+
syncPairs.push({
|
| 76 |
+
key,
|
| 77 |
+
value,
|
| 78 |
+
});
|
| 79 |
+
}
|
| 80 |
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
| 81 |
+
}
|
| 82 |
+
static mergeObjectSync(status, pairs) {
|
| 83 |
+
const finalObject = {};
|
| 84 |
+
for (const pair of pairs) {
|
| 85 |
+
const { key, value } = pair;
|
| 86 |
+
if (key.status === "aborted")
|
| 87 |
+
return INVALID;
|
| 88 |
+
if (value.status === "aborted")
|
| 89 |
+
return INVALID;
|
| 90 |
+
if (key.status === "dirty")
|
| 91 |
+
status.dirty();
|
| 92 |
+
if (value.status === "dirty")
|
| 93 |
+
status.dirty();
|
| 94 |
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
| 95 |
+
finalObject[key.value] = value.value;
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
return { status: status.value, value: finalObject };
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
export const INVALID = Object.freeze({
|
| 102 |
+
status: "aborted",
|
| 103 |
+
});
|
| 104 |
+
export const DIRTY = (value) => ({ status: "dirty", value });
|
| 105 |
+
export const OK = (value) => ({ status: "valid", value });
|
| 106 |
+
export const isAborted = (x) => x.status === "aborted";
|
| 107 |
+
export const isDirty = (x) => x.status === "dirty";
|
| 108 |
+
export const isValid = (x) => x.status === "valid";
|
| 109 |
+
export const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../types.cjs";
|
| 2 |
+
export declare namespace partialUtil {
|
| 3 |
+
type DeepPartial<T extends ZodTypeAny> = T extends ZodObject<ZodRawShape> ? ZodObject<{
|
| 4 |
+
[k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>>;
|
| 5 |
+
}, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray<infer Type, infer Card> ? ZodArray<DeepPartial<Type>, Card> : T extends ZodOptional<infer Type> ? ZodOptional<DeepPartial<Type>> : T extends ZodNullable<infer Type> ? ZodNullable<DeepPartial<Type>> : T extends ZodTuple<infer Items> ? {
|
| 6 |
+
[k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial<Items[k]> : never;
|
| 7 |
+
} extends infer PI ? PI extends ZodTupleItems ? ZodTuple<PI> : never : never : T;
|
| 8 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../types.js";
|
| 2 |
+
export declare namespace partialUtil {
|
| 3 |
+
type DeepPartial<T extends ZodTypeAny> = T extends ZodObject<ZodRawShape> ? ZodObject<{
|
| 4 |
+
[k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>>;
|
| 5 |
+
}, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray<infer Type, infer Card> ? ZodArray<DeepPartial<Type>, Card> : T extends ZodOptional<infer Type> ? ZodOptional<DeepPartial<Type>> : T extends ZodNullable<infer Type> ? ZodNullable<DeepPartial<Type>> : T extends ZodTuple<infer Items> ? {
|
| 6 |
+
[k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial<Items[k]> : never;
|
| 7 |
+
} extends infer PI ? PI extends ZodTupleItems ? ZodTuple<PI> : never : never : T;
|
| 8 |
+
}
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/partialUtil.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export {};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
| 2 |
+
export type Scalars = Primitive | Primitive[];
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
| 2 |
+
export type Scalars = Primitive | Primitive[];
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/typeAliases.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export {};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.cjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
|
| 4 |
+
var util;
|
| 5 |
+
(function (util) {
|
| 6 |
+
util.assertEqual = (_) => { };
|
| 7 |
+
function assertIs(_arg) { }
|
| 8 |
+
util.assertIs = assertIs;
|
| 9 |
+
function assertNever(_x) {
|
| 10 |
+
throw new Error();
|
| 11 |
+
}
|
| 12 |
+
util.assertNever = assertNever;
|
| 13 |
+
util.arrayToEnum = (items) => {
|
| 14 |
+
const obj = {};
|
| 15 |
+
for (const item of items) {
|
| 16 |
+
obj[item] = item;
|
| 17 |
+
}
|
| 18 |
+
return obj;
|
| 19 |
+
};
|
| 20 |
+
util.getValidEnumValues = (obj) => {
|
| 21 |
+
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
| 22 |
+
const filtered = {};
|
| 23 |
+
for (const k of validKeys) {
|
| 24 |
+
filtered[k] = obj[k];
|
| 25 |
+
}
|
| 26 |
+
return util.objectValues(filtered);
|
| 27 |
+
};
|
| 28 |
+
util.objectValues = (obj) => {
|
| 29 |
+
return util.objectKeys(obj).map(function (e) {
|
| 30 |
+
return obj[e];
|
| 31 |
+
});
|
| 32 |
+
};
|
| 33 |
+
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
| 34 |
+
? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
|
| 35 |
+
: (object) => {
|
| 36 |
+
const keys = [];
|
| 37 |
+
for (const key in object) {
|
| 38 |
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
| 39 |
+
keys.push(key);
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
return keys;
|
| 43 |
+
};
|
| 44 |
+
util.find = (arr, checker) => {
|
| 45 |
+
for (const item of arr) {
|
| 46 |
+
if (checker(item))
|
| 47 |
+
return item;
|
| 48 |
+
}
|
| 49 |
+
return undefined;
|
| 50 |
+
};
|
| 51 |
+
util.isInteger = typeof Number.isInteger === "function"
|
| 52 |
+
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
| 53 |
+
: (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
| 54 |
+
function joinValues(array, separator = " | ") {
|
| 55 |
+
return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
|
| 56 |
+
}
|
| 57 |
+
util.joinValues = joinValues;
|
| 58 |
+
util.jsonStringifyReplacer = (_, value) => {
|
| 59 |
+
if (typeof value === "bigint") {
|
| 60 |
+
return value.toString();
|
| 61 |
+
}
|
| 62 |
+
return value;
|
| 63 |
+
};
|
| 64 |
+
})(util || (exports.util = util = {}));
|
| 65 |
+
var objectUtil;
|
| 66 |
+
(function (objectUtil) {
|
| 67 |
+
objectUtil.mergeShapes = (first, second) => {
|
| 68 |
+
return {
|
| 69 |
+
...first,
|
| 70 |
+
...second, // second overwrites first
|
| 71 |
+
};
|
| 72 |
+
};
|
| 73 |
+
})(objectUtil || (exports.objectUtil = objectUtil = {}));
|
| 74 |
+
exports.ZodParsedType = util.arrayToEnum([
|
| 75 |
+
"string",
|
| 76 |
+
"nan",
|
| 77 |
+
"number",
|
| 78 |
+
"integer",
|
| 79 |
+
"float",
|
| 80 |
+
"boolean",
|
| 81 |
+
"date",
|
| 82 |
+
"bigint",
|
| 83 |
+
"symbol",
|
| 84 |
+
"function",
|
| 85 |
+
"undefined",
|
| 86 |
+
"null",
|
| 87 |
+
"array",
|
| 88 |
+
"object",
|
| 89 |
+
"unknown",
|
| 90 |
+
"promise",
|
| 91 |
+
"void",
|
| 92 |
+
"never",
|
| 93 |
+
"map",
|
| 94 |
+
"set",
|
| 95 |
+
]);
|
| 96 |
+
const getParsedType = (data) => {
|
| 97 |
+
const t = typeof data;
|
| 98 |
+
switch (t) {
|
| 99 |
+
case "undefined":
|
| 100 |
+
return exports.ZodParsedType.undefined;
|
| 101 |
+
case "string":
|
| 102 |
+
return exports.ZodParsedType.string;
|
| 103 |
+
case "number":
|
| 104 |
+
return Number.isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
|
| 105 |
+
case "boolean":
|
| 106 |
+
return exports.ZodParsedType.boolean;
|
| 107 |
+
case "function":
|
| 108 |
+
return exports.ZodParsedType.function;
|
| 109 |
+
case "bigint":
|
| 110 |
+
return exports.ZodParsedType.bigint;
|
| 111 |
+
case "symbol":
|
| 112 |
+
return exports.ZodParsedType.symbol;
|
| 113 |
+
case "object":
|
| 114 |
+
if (Array.isArray(data)) {
|
| 115 |
+
return exports.ZodParsedType.array;
|
| 116 |
+
}
|
| 117 |
+
if (data === null) {
|
| 118 |
+
return exports.ZodParsedType.null;
|
| 119 |
+
}
|
| 120 |
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
| 121 |
+
return exports.ZodParsedType.promise;
|
| 122 |
+
}
|
| 123 |
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
| 124 |
+
return exports.ZodParsedType.map;
|
| 125 |
+
}
|
| 126 |
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
| 127 |
+
return exports.ZodParsedType.set;
|
| 128 |
+
}
|
| 129 |
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
| 130 |
+
return exports.ZodParsedType.date;
|
| 131 |
+
}
|
| 132 |
+
return exports.ZodParsedType.object;
|
| 133 |
+
default:
|
| 134 |
+
return exports.ZodParsedType.unknown;
|
| 135 |
+
}
|
| 136 |
+
};
|
| 137 |
+
exports.getParsedType = getParsedType;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.d.cts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare namespace util {
|
| 2 |
+
type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : false;
|
| 3 |
+
export type isAny<T> = 0 extends 1 & T ? true : false;
|
| 4 |
+
export const assertEqual: <A, B>(_: AssertEqual<A, B>) => void;
|
| 5 |
+
export function assertIs<T>(_arg: T): void;
|
| 6 |
+
export function assertNever(_x: never): never;
|
| 7 |
+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
| 8 |
+
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
|
| 9 |
+
export type MakePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
| 10 |
+
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
|
| 11 |
+
export type InexactPartial<T> = {
|
| 12 |
+
[k in keyof T]?: T[k] | undefined;
|
| 13 |
+
};
|
| 14 |
+
export const arrayToEnum: <T extends string, U extends [T, ...T[]]>(items: U) => { [k in U[number]]: k; };
|
| 15 |
+
export const getValidEnumValues: (obj: any) => any[];
|
| 16 |
+
export const objectValues: (obj: any) => any[];
|
| 17 |
+
export const objectKeys: ObjectConstructor["keys"];
|
| 18 |
+
export const find: <T>(arr: T[], checker: (arg: T) => any) => T | undefined;
|
| 19 |
+
export type identity<T> = objectUtil.identity<T>;
|
| 20 |
+
export type flatten<T> = objectUtil.flatten<T>;
|
| 21 |
+
export type noUndefined<T> = T extends undefined ? never : T;
|
| 22 |
+
export const isInteger: NumberConstructor["isInteger"];
|
| 23 |
+
export function joinValues<T extends any[]>(array: T, separator?: string): string;
|
| 24 |
+
export const jsonStringifyReplacer: (_: string, value: any) => any;
|
| 25 |
+
export {};
|
| 26 |
+
}
|
| 27 |
+
export declare namespace objectUtil {
|
| 28 |
+
export type MergeShapes<U, V> = keyof U & keyof V extends never ? U & V : {
|
| 29 |
+
[k in Exclude<keyof U, keyof V>]: U[k];
|
| 30 |
+
} & V;
|
| 31 |
+
type optionalKeys<T extends object> = {
|
| 32 |
+
[k in keyof T]: undefined extends T[k] ? k : never;
|
| 33 |
+
}[keyof T];
|
| 34 |
+
type requiredKeys<T extends object> = {
|
| 35 |
+
[k in keyof T]: undefined extends T[k] ? never : k;
|
| 36 |
+
}[keyof T];
|
| 37 |
+
export type addQuestionMarks<T extends object, _O = any> = {
|
| 38 |
+
[K in requiredKeys<T>]: T[K];
|
| 39 |
+
} & {
|
| 40 |
+
[K in optionalKeys<T>]?: T[K];
|
| 41 |
+
} & {
|
| 42 |
+
[k in keyof T]?: unknown;
|
| 43 |
+
};
|
| 44 |
+
export type identity<T> = T;
|
| 45 |
+
export type flatten<T> = identity<{
|
| 46 |
+
[k in keyof T]: T[k];
|
| 47 |
+
}>;
|
| 48 |
+
export type noNeverKeys<T> = {
|
| 49 |
+
[k in keyof T]: [T[k]] extends [never] ? never : k;
|
| 50 |
+
}[keyof T];
|
| 51 |
+
export type noNever<T> = identity<{
|
| 52 |
+
[k in noNeverKeys<T>]: k extends keyof T ? T[k] : never;
|
| 53 |
+
}>;
|
| 54 |
+
export const mergeShapes: <U, T>(first: U, second: T) => T & U;
|
| 55 |
+
export type extendShape<A extends object, B extends object> = keyof A & keyof B extends never ? A & B : {
|
| 56 |
+
[K in keyof A as K extends keyof B ? never : K]: A[K];
|
| 57 |
+
} & {
|
| 58 |
+
[K in keyof B]: B[K];
|
| 59 |
+
};
|
| 60 |
+
export {};
|
| 61 |
+
}
|
| 62 |
+
export declare const ZodParsedType: {
|
| 63 |
+
string: "string";
|
| 64 |
+
nan: "nan";
|
| 65 |
+
number: "number";
|
| 66 |
+
integer: "integer";
|
| 67 |
+
float: "float";
|
| 68 |
+
boolean: "boolean";
|
| 69 |
+
date: "date";
|
| 70 |
+
bigint: "bigint";
|
| 71 |
+
symbol: "symbol";
|
| 72 |
+
function: "function";
|
| 73 |
+
undefined: "undefined";
|
| 74 |
+
null: "null";
|
| 75 |
+
array: "array";
|
| 76 |
+
object: "object";
|
| 77 |
+
unknown: "unknown";
|
| 78 |
+
promise: "promise";
|
| 79 |
+
void: "void";
|
| 80 |
+
never: "never";
|
| 81 |
+
map: "map";
|
| 82 |
+
set: "set";
|
| 83 |
+
};
|
| 84 |
+
export type ZodParsedType = keyof typeof ZodParsedType;
|
| 85 |
+
export declare const getParsedType: (data: any) => ZodParsedType;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare namespace util {
|
| 2 |
+
type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : false;
|
| 3 |
+
export type isAny<T> = 0 extends 1 & T ? true : false;
|
| 4 |
+
export const assertEqual: <A, B>(_: AssertEqual<A, B>) => void;
|
| 5 |
+
export function assertIs<T>(_arg: T): void;
|
| 6 |
+
export function assertNever(_x: never): never;
|
| 7 |
+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
| 8 |
+
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
|
| 9 |
+
export type MakePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
| 10 |
+
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
|
| 11 |
+
export type InexactPartial<T> = {
|
| 12 |
+
[k in keyof T]?: T[k] | undefined;
|
| 13 |
+
};
|
| 14 |
+
export const arrayToEnum: <T extends string, U extends [T, ...T[]]>(items: U) => { [k in U[number]]: k; };
|
| 15 |
+
export const getValidEnumValues: (obj: any) => any[];
|
| 16 |
+
export const objectValues: (obj: any) => any[];
|
| 17 |
+
export const objectKeys: ObjectConstructor["keys"];
|
| 18 |
+
export const find: <T>(arr: T[], checker: (arg: T) => any) => T | undefined;
|
| 19 |
+
export type identity<T> = objectUtil.identity<T>;
|
| 20 |
+
export type flatten<T> = objectUtil.flatten<T>;
|
| 21 |
+
export type noUndefined<T> = T extends undefined ? never : T;
|
| 22 |
+
export const isInteger: NumberConstructor["isInteger"];
|
| 23 |
+
export function joinValues<T extends any[]>(array: T, separator?: string): string;
|
| 24 |
+
export const jsonStringifyReplacer: (_: string, value: any) => any;
|
| 25 |
+
export {};
|
| 26 |
+
}
|
| 27 |
+
export declare namespace objectUtil {
|
| 28 |
+
export type MergeShapes<U, V> = keyof U & keyof V extends never ? U & V : {
|
| 29 |
+
[k in Exclude<keyof U, keyof V>]: U[k];
|
| 30 |
+
} & V;
|
| 31 |
+
type optionalKeys<T extends object> = {
|
| 32 |
+
[k in keyof T]: undefined extends T[k] ? k : never;
|
| 33 |
+
}[keyof T];
|
| 34 |
+
type requiredKeys<T extends object> = {
|
| 35 |
+
[k in keyof T]: undefined extends T[k] ? never : k;
|
| 36 |
+
}[keyof T];
|
| 37 |
+
export type addQuestionMarks<T extends object, _O = any> = {
|
| 38 |
+
[K in requiredKeys<T>]: T[K];
|
| 39 |
+
} & {
|
| 40 |
+
[K in optionalKeys<T>]?: T[K];
|
| 41 |
+
} & {
|
| 42 |
+
[k in keyof T]?: unknown;
|
| 43 |
+
};
|
| 44 |
+
export type identity<T> = T;
|
| 45 |
+
export type flatten<T> = identity<{
|
| 46 |
+
[k in keyof T]: T[k];
|
| 47 |
+
}>;
|
| 48 |
+
export type noNeverKeys<T> = {
|
| 49 |
+
[k in keyof T]: [T[k]] extends [never] ? never : k;
|
| 50 |
+
}[keyof T];
|
| 51 |
+
export type noNever<T> = identity<{
|
| 52 |
+
[k in noNeverKeys<T>]: k extends keyof T ? T[k] : never;
|
| 53 |
+
}>;
|
| 54 |
+
export const mergeShapes: <U, T>(first: U, second: T) => T & U;
|
| 55 |
+
export type extendShape<A extends object, B extends object> = keyof A & keyof B extends never ? A & B : {
|
| 56 |
+
[K in keyof A as K extends keyof B ? never : K]: A[K];
|
| 57 |
+
} & {
|
| 58 |
+
[K in keyof B]: B[K];
|
| 59 |
+
};
|
| 60 |
+
export {};
|
| 61 |
+
}
|
| 62 |
+
export declare const ZodParsedType: {
|
| 63 |
+
string: "string";
|
| 64 |
+
nan: "nan";
|
| 65 |
+
number: "number";
|
| 66 |
+
integer: "integer";
|
| 67 |
+
float: "float";
|
| 68 |
+
boolean: "boolean";
|
| 69 |
+
date: "date";
|
| 70 |
+
bigint: "bigint";
|
| 71 |
+
symbol: "symbol";
|
| 72 |
+
function: "function";
|
| 73 |
+
undefined: "undefined";
|
| 74 |
+
null: "null";
|
| 75 |
+
array: "array";
|
| 76 |
+
object: "object";
|
| 77 |
+
unknown: "unknown";
|
| 78 |
+
promise: "promise";
|
| 79 |
+
void: "void";
|
| 80 |
+
never: "never";
|
| 81 |
+
map: "map";
|
| 82 |
+
set: "set";
|
| 83 |
+
};
|
| 84 |
+
export type ZodParsedType = keyof typeof ZodParsedType;
|
| 85 |
+
export declare const getParsedType: (data: any) => ZodParsedType;
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/helpers/util.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export var util;
|
| 2 |
+
(function (util) {
|
| 3 |
+
util.assertEqual = (_) => { };
|
| 4 |
+
function assertIs(_arg) { }
|
| 5 |
+
util.assertIs = assertIs;
|
| 6 |
+
function assertNever(_x) {
|
| 7 |
+
throw new Error();
|
| 8 |
+
}
|
| 9 |
+
util.assertNever = assertNever;
|
| 10 |
+
util.arrayToEnum = (items) => {
|
| 11 |
+
const obj = {};
|
| 12 |
+
for (const item of items) {
|
| 13 |
+
obj[item] = item;
|
| 14 |
+
}
|
| 15 |
+
return obj;
|
| 16 |
+
};
|
| 17 |
+
util.getValidEnumValues = (obj) => {
|
| 18 |
+
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
| 19 |
+
const filtered = {};
|
| 20 |
+
for (const k of validKeys) {
|
| 21 |
+
filtered[k] = obj[k];
|
| 22 |
+
}
|
| 23 |
+
return util.objectValues(filtered);
|
| 24 |
+
};
|
| 25 |
+
util.objectValues = (obj) => {
|
| 26 |
+
return util.objectKeys(obj).map(function (e) {
|
| 27 |
+
return obj[e];
|
| 28 |
+
});
|
| 29 |
+
};
|
| 30 |
+
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
| 31 |
+
? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
|
| 32 |
+
: (object) => {
|
| 33 |
+
const keys = [];
|
| 34 |
+
for (const key in object) {
|
| 35 |
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
| 36 |
+
keys.push(key);
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
return keys;
|
| 40 |
+
};
|
| 41 |
+
util.find = (arr, checker) => {
|
| 42 |
+
for (const item of arr) {
|
| 43 |
+
if (checker(item))
|
| 44 |
+
return item;
|
| 45 |
+
}
|
| 46 |
+
return undefined;
|
| 47 |
+
};
|
| 48 |
+
util.isInteger = typeof Number.isInteger === "function"
|
| 49 |
+
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
| 50 |
+
: (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
| 51 |
+
function joinValues(array, separator = " | ") {
|
| 52 |
+
return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
|
| 53 |
+
}
|
| 54 |
+
util.joinValues = joinValues;
|
| 55 |
+
util.jsonStringifyReplacer = (_, value) => {
|
| 56 |
+
if (typeof value === "bigint") {
|
| 57 |
+
return value.toString();
|
| 58 |
+
}
|
| 59 |
+
return value;
|
| 60 |
+
};
|
| 61 |
+
})(util || (util = {}));
|
| 62 |
+
export var objectUtil;
|
| 63 |
+
(function (objectUtil) {
|
| 64 |
+
objectUtil.mergeShapes = (first, second) => {
|
| 65 |
+
return {
|
| 66 |
+
...first,
|
| 67 |
+
...second, // second overwrites first
|
| 68 |
+
};
|
| 69 |
+
};
|
| 70 |
+
})(objectUtil || (objectUtil = {}));
|
| 71 |
+
export const ZodParsedType = util.arrayToEnum([
|
| 72 |
+
"string",
|
| 73 |
+
"nan",
|
| 74 |
+
"number",
|
| 75 |
+
"integer",
|
| 76 |
+
"float",
|
| 77 |
+
"boolean",
|
| 78 |
+
"date",
|
| 79 |
+
"bigint",
|
| 80 |
+
"symbol",
|
| 81 |
+
"function",
|
| 82 |
+
"undefined",
|
| 83 |
+
"null",
|
| 84 |
+
"array",
|
| 85 |
+
"object",
|
| 86 |
+
"unknown",
|
| 87 |
+
"promise",
|
| 88 |
+
"void",
|
| 89 |
+
"never",
|
| 90 |
+
"map",
|
| 91 |
+
"set",
|
| 92 |
+
]);
|
| 93 |
+
export const getParsedType = (data) => {
|
| 94 |
+
const t = typeof data;
|
| 95 |
+
switch (t) {
|
| 96 |
+
case "undefined":
|
| 97 |
+
return ZodParsedType.undefined;
|
| 98 |
+
case "string":
|
| 99 |
+
return ZodParsedType.string;
|
| 100 |
+
case "number":
|
| 101 |
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
| 102 |
+
case "boolean":
|
| 103 |
+
return ZodParsedType.boolean;
|
| 104 |
+
case "function":
|
| 105 |
+
return ZodParsedType.function;
|
| 106 |
+
case "bigint":
|
| 107 |
+
return ZodParsedType.bigint;
|
| 108 |
+
case "symbol":
|
| 109 |
+
return ZodParsedType.symbol;
|
| 110 |
+
case "object":
|
| 111 |
+
if (Array.isArray(data)) {
|
| 112 |
+
return ZodParsedType.array;
|
| 113 |
+
}
|
| 114 |
+
if (data === null) {
|
| 115 |
+
return ZodParsedType.null;
|
| 116 |
+
}
|
| 117 |
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
| 118 |
+
return ZodParsedType.promise;
|
| 119 |
+
}
|
| 120 |
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
| 121 |
+
return ZodParsedType.map;
|
| 122 |
+
}
|
| 123 |
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
| 124 |
+
return ZodParsedType.set;
|
| 125 |
+
}
|
| 126 |
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
| 127 |
+
return ZodParsedType.date;
|
| 128 |
+
}
|
| 129 |
+
return ZodParsedType.object;
|
| 130 |
+
default:
|
| 131 |
+
return ZodParsedType.unknown;
|
| 132 |
+
}
|
| 133 |
+
};
|
node_modules/@jimp/plugin-quantize/node_modules/zod/v3/index.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 3 |
+
if (k2 === undefined) k2 = k;
|
| 4 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 5 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 6 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 7 |
+
}
|
| 8 |
+
Object.defineProperty(o, k2, desc);
|
| 9 |
+
}) : (function(o, m, k, k2) {
|
| 10 |
+
if (k2 === undefined) k2 = k;
|
| 11 |
+
o[k2] = m[k];
|
| 12 |
+
}));
|
| 13 |
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
| 14 |
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
| 15 |
+
}) : function(o, v) {
|
| 16 |
+
o["default"] = v;
|
| 17 |
+
});
|
| 18 |
+
var __importStar = (this && this.__importStar) || function (mod) {
|
| 19 |
+
if (mod && mod.__esModule) return mod;
|
| 20 |
+
var result = {};
|
| 21 |
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
| 22 |
+
__setModuleDefault(result, mod);
|
| 23 |
+
return result;
|
| 24 |
+
};
|
| 25 |
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
| 26 |
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
| 27 |
+
};
|
| 28 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 29 |
+
exports.z = void 0;
|
| 30 |
+
const z = __importStar(require("./external.cjs"));
|
| 31 |
+
exports.z = z;
|
| 32 |
+
__exportStar(require("./external.cjs"), exports);
|
| 33 |
+
exports.default = z;
|