zod 4.5.4 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compile.cjs +19 -0
- package/index.cjs +19 -0
- package/locales/index.cjs +19 -0
- package/mini/index.cjs +19 -0
- package/package.json +8 -7
- package/src/v3/helpers/errorUtil.ts +1 -1
- package/src/v4/classic/checks.ts +0 -1
- package/src/v4/classic/external.ts +2 -0
- package/src/v4/classic/from-json-schema.ts +248 -25
- package/src/v4/classic/schemas.ts +255 -164
- package/src/v4/classic/tests/assignability.test.ts +59 -9
- package/src/v4/classic/tests/bigint.test.ts +6 -0
- package/src/v4/classic/tests/continuability.test.ts +2 -2
- package/src/v4/classic/tests/cyclic-data.test.ts +274 -0
- package/src/v4/classic/tests/enum.test.ts +9 -0
- package/src/v4/classic/tests/error.test.ts +130 -1
- package/src/v4/classic/tests/firstparty.test.ts +4 -0
- package/src/v4/classic/tests/from-json-schema.test.ts +157 -0
- package/src/v4/classic/tests/iban.test.ts +81 -0
- package/src/v4/classic/tests/instance-footprint.test.ts +18 -2
- package/src/v4/classic/tests/instanceof.test.ts +27 -7
- package/src/v4/classic/tests/issue-schema.test.ts +88 -56
- package/src/v4/classic/tests/object.test.ts +56 -0
- package/src/v4/classic/tests/optin-ladder.test.ts +3 -2
- package/src/v4/classic/tests/properties.test.ts +225 -0
- package/src/v4/classic/tests/recursive-types.test.ts +1 -1
- package/src/v4/classic/tests/standard-schema.test.ts +19 -0
- package/src/v4/classic/tests/string.test.ts +25 -0
- package/src/v4/classic/tests/template-literal.test.ts +33 -1
- package/src/v4/classic/tests/to-json-schema.test.ts +147 -3
- package/src/v4/classic/tests/validate.test.ts +569 -0
- package/src/v4/core/api.ts +30 -6
- package/src/v4/core/checks.ts +1 -101
- package/src/v4/core/compile.ts +193 -81
- package/src/v4/core/doc.ts +6 -2
- package/src/v4/core/errors.ts +3 -6
- package/src/v4/core/json-schema-generator.ts +2 -2
- package/src/v4/core/json-schema-processors.ts +226 -68
- package/src/v4/core/memoizer.ts +78 -28
- package/src/v4/core/parse.ts +37 -16
- package/src/v4/core/regexes.ts +10 -4
- package/src/v4/core/schemas.ts +314 -83
- package/src/v4/core/tests/cached.test.ts +54 -0
- package/src/v4/core/tests/compile-generative.test.ts +445 -0
- package/src/v4/core/tests/compile.test.ts +222 -2
- package/src/v4/core/tests/email-regex.test.ts +140 -0
- package/src/v4/core/tests/polyfill-collision.test.ts +46 -0
- package/src/v4/core/to-json-schema.ts +10 -8
- package/src/v4/core/util.ts +222 -147
- package/src/v4/core/versions.ts +2 -2
- package/src/v4/core/visit.ts +11 -0
- package/src/v4/locales/ar.ts +1 -0
- package/src/v4/locales/az.ts +1 -0
- package/src/v4/locales/be.ts +1 -0
- package/src/v4/locales/bg.ts +1 -0
- package/src/v4/locales/bn.ts +1 -0
- package/src/v4/locales/ca.ts +1 -0
- package/src/v4/locales/ckb.ts +1 -0
- package/src/v4/locales/cs.ts +1 -0
- package/src/v4/locales/da.ts +1 -0
- package/src/v4/locales/de.ts +1 -0
- package/src/v4/locales/el.ts +1 -0
- package/src/v4/locales/en.ts +1 -0
- package/src/v4/locales/eo.ts +1 -0
- package/src/v4/locales/es.ts +1 -0
- package/src/v4/locales/fa.ts +1 -0
- package/src/v4/locales/fi.ts +1 -0
- package/src/v4/locales/fr-CA.ts +1 -0
- package/src/v4/locales/fr.ts +1 -0
- package/src/v4/locales/gu.ts +1 -0
- package/src/v4/locales/he.ts +1 -0
- package/src/v4/locales/hi.ts +1 -0
- package/src/v4/locales/hr.ts +1 -0
- package/src/v4/locales/hu.ts +1 -0
- package/src/v4/locales/hy.ts +1 -0
- package/src/v4/locales/id.ts +1 -0
- package/src/v4/locales/is.ts +1 -0
- package/src/v4/locales/it.ts +1 -0
- package/src/v4/locales/ja.ts +1 -0
- package/src/v4/locales/ka.ts +1 -0
- package/src/v4/locales/km.ts +1 -0
- package/src/v4/locales/kn.ts +1 -0
- package/src/v4/locales/ko.ts +1 -0
- package/src/v4/locales/lt.ts +1 -0
- package/src/v4/locales/mk.ts +1 -0
- package/src/v4/locales/ms.ts +1 -0
- package/src/v4/locales/ne.ts +1 -0
- package/src/v4/locales/nl.ts +1 -0
- package/src/v4/locales/nn.ts +1 -0
- package/src/v4/locales/no.ts +1 -0
- package/src/v4/locales/ota.ts +1 -0
- package/src/v4/locales/pl.ts +1 -0
- package/src/v4/locales/ps.ts +1 -0
- package/src/v4/locales/pt-BR.ts +1 -0
- package/src/v4/locales/pt.ts +1 -0
- package/src/v4/locales/ro.ts +1 -0
- package/src/v4/locales/ru.ts +1 -0
- package/src/v4/locales/sk.ts +1 -0
- package/src/v4/locales/sl.ts +1 -0
- package/src/v4/locales/sv.ts +1 -0
- package/src/v4/locales/ta.ts +1 -0
- package/src/v4/locales/th.ts +1 -0
- package/src/v4/locales/tk.ts +1 -0
- package/src/v4/locales/tr.ts +1 -0
- package/src/v4/locales/uk.ts +1 -0
- package/src/v4/locales/ur.ts +1 -0
- package/src/v4/locales/uz.ts +1 -0
- package/src/v4/locales/vi.ts +1 -0
- package/src/v4/locales/yo.ts +1 -0
- package/src/v4/locales/zh-CN.ts +1 -0
- package/src/v4/locales/zh-TW.ts +1 -0
- package/src/v4/mini/checks.ts +0 -1
- package/src/v4/mini/external.ts +2 -0
- package/src/v4/mini/schemas.ts +38 -2
- package/src/v4/mini/tests/checks.test.ts +1 -1
- package/src/v4/mini/tests/computed.test.ts +11 -17
- package/src/v4/mini/tests/index.test.ts +8 -0
- package/src/v4/mini/tests/string.test.ts +16 -0
- package/v3/ZodError.cjs +19 -0
- package/v3/errors.cjs +19 -0
- package/v3/external.cjs +19 -0
- package/v3/helpers/enumUtil.cjs +19 -0
- package/v3/helpers/errorUtil.cjs +20 -1
- package/v3/helpers/errorUtil.js +1 -1
- package/v3/helpers/parseUtil.cjs +19 -0
- package/v3/helpers/partialUtil.cjs +19 -0
- package/v3/helpers/typeAliases.cjs +19 -0
- package/v3/helpers/util.cjs +19 -0
- package/v3/index.cjs +19 -0
- package/v3/standard-schema.cjs +19 -0
- package/v3/types.cjs +19 -0
- package/v4/classic/checks.cjs +20 -2
- package/v4/classic/checks.d.cts +1 -1
- package/v4/classic/checks.d.ts +1 -1
- package/v4/classic/checks.js +1 -1
- package/v4/classic/coerce.cjs +19 -0
- package/v4/classic/compat.cjs +19 -0
- package/v4/classic/deep-partial.cjs +19 -0
- package/v4/classic/errors.cjs +19 -0
- package/v4/classic/external.cjs +22 -1
- package/v4/classic/external.d.cts +1 -1
- package/v4/classic/external.d.ts +1 -1
- package/v4/classic/external.js +1 -1
- package/v4/classic/from-json-schema.cjs +264 -24
- package/v4/classic/from-json-schema.js +245 -24
- package/v4/classic/in-out.cjs +19 -0
- package/v4/classic/index.cjs +19 -0
- package/v4/classic/iso.cjs +19 -0
- package/v4/classic/parse.cjs +19 -0
- package/v4/classic/schemas.cjs +100 -31
- package/v4/classic/schemas.d.cts +17 -1
- package/v4/classic/schemas.d.ts +17 -1
- package/v4/classic/schemas.js +77 -29
- package/v4/core/api.cjs +37 -2
- package/v4/core/api.d.cts +6 -4
- package/v4/core/api.d.ts +6 -4
- package/v4/core/api.js +17 -2
- package/v4/core/checks.cjs +19 -96
- package/v4/core/checks.d.cts +1 -1
- package/v4/core/checks.d.ts +1 -1
- package/v4/core/checks.js +0 -96
- package/v4/core/compile.cjs +164 -65
- package/v4/core/compile.d.cts +18 -4
- package/v4/core/compile.d.ts +18 -4
- package/v4/core/compile.js +145 -66
- package/v4/core/core.cjs +19 -0
- package/v4/core/doc.cjs +26 -2
- package/v4/core/doc.js +7 -2
- package/v4/core/errors.cjs +21 -5
- package/v4/core/errors.js +2 -5
- package/v4/core/index.cjs +19 -0
- package/v4/core/json-schema-generator.cjs +20 -1
- package/v4/core/json-schema-generator.js +2 -2
- package/v4/core/json-schema-processors.cjs +215 -63
- package/v4/core/json-schema-processors.d.cts +17 -0
- package/v4/core/json-schema-processors.d.ts +17 -0
- package/v4/core/json-schema-processors.js +195 -64
- package/v4/core/json-schema.cjs +19 -0
- package/v4/core/memoizer.cjs +114 -23
- package/v4/core/memoizer.js +72 -23
- package/v4/core/parse.cjs +56 -16
- package/v4/core/parse.js +37 -16
- package/v4/core/regexes.cjs +29 -6
- package/v4/core/regexes.d.cts +2 -0
- package/v4/core/regexes.d.ts +2 -0
- package/v4/core/regexes.js +8 -4
- package/v4/core/registries.cjs +19 -0
- package/v4/core/schemas.cjs +285 -66
- package/v4/core/schemas.d.cts +34 -3
- package/v4/core/schemas.d.ts +34 -3
- package/v4/core/schemas.js +264 -65
- package/v4/core/standard-schema.cjs +19 -0
- package/v4/core/to-json-schema.cjs +29 -7
- package/v4/core/to-json-schema.d.cts +7 -3
- package/v4/core/to-json-schema.d.ts +7 -3
- package/v4/core/to-json-schema.js +8 -7
- package/v4/core/util.cjs +181 -143
- package/v4/core/util.d.cts +25 -4
- package/v4/core/util.d.ts +25 -4
- package/v4/core/util.js +160 -143
- package/v4/core/versions.cjs +21 -2
- package/v4/core/versions.d.cts +1 -1
- package/v4/core/versions.d.ts +1 -1
- package/v4/core/versions.js +2 -2
- package/v4/core/visit.cjs +31 -0
- package/v4/core/visit.js +12 -0
- package/v4/index.cjs +19 -0
- package/v4/locales/ar.cjs +1 -0
- package/v4/locales/ar.js +1 -0
- package/v4/locales/az.cjs +1 -0
- package/v4/locales/az.js +1 -0
- package/v4/locales/be.cjs +1 -0
- package/v4/locales/be.js +1 -0
- package/v4/locales/bg.cjs +1 -0
- package/v4/locales/bg.js +1 -0
- package/v4/locales/bn.cjs +1 -0
- package/v4/locales/bn.js +1 -0
- package/v4/locales/ca.cjs +1 -0
- package/v4/locales/ca.js +1 -0
- package/v4/locales/ckb.cjs +1 -0
- package/v4/locales/ckb.js +1 -0
- package/v4/locales/cs.cjs +1 -0
- package/v4/locales/cs.js +1 -0
- package/v4/locales/da.cjs +1 -0
- package/v4/locales/da.js +1 -0
- package/v4/locales/de.cjs +1 -0
- package/v4/locales/de.js +1 -0
- package/v4/locales/el.cjs +1 -0
- package/v4/locales/el.js +1 -0
- package/v4/locales/en.cjs +1 -0
- package/v4/locales/en.js +1 -0
- package/v4/locales/eo.cjs +1 -0
- package/v4/locales/eo.js +1 -0
- package/v4/locales/es.cjs +1 -0
- package/v4/locales/es.js +1 -0
- package/v4/locales/fa.cjs +1 -0
- package/v4/locales/fa.js +1 -0
- package/v4/locales/fi.cjs +1 -0
- package/v4/locales/fi.js +1 -0
- package/v4/locales/fr-CA.cjs +1 -0
- package/v4/locales/fr-CA.js +1 -0
- package/v4/locales/fr.cjs +1 -0
- package/v4/locales/fr.js +1 -0
- package/v4/locales/gu.cjs +1 -0
- package/v4/locales/gu.js +1 -0
- package/v4/locales/he.cjs +1 -0
- package/v4/locales/he.js +1 -0
- package/v4/locales/hi.cjs +1 -0
- package/v4/locales/hi.js +1 -0
- package/v4/locales/hr.cjs +1 -0
- package/v4/locales/hr.js +1 -0
- package/v4/locales/hu.cjs +1 -0
- package/v4/locales/hu.js +1 -0
- package/v4/locales/hy.cjs +1 -0
- package/v4/locales/hy.js +1 -0
- package/v4/locales/id.cjs +1 -0
- package/v4/locales/id.js +1 -0
- package/v4/locales/index.cjs +19 -0
- package/v4/locales/is.cjs +1 -0
- package/v4/locales/is.js +1 -0
- package/v4/locales/it.cjs +1 -0
- package/v4/locales/it.js +1 -0
- package/v4/locales/ja.cjs +1 -0
- package/v4/locales/ja.js +1 -0
- package/v4/locales/ka.cjs +1 -0
- package/v4/locales/ka.js +1 -0
- package/v4/locales/km.cjs +1 -0
- package/v4/locales/km.js +1 -0
- package/v4/locales/kn.cjs +1 -0
- package/v4/locales/kn.js +1 -0
- package/v4/locales/ko.cjs +1 -0
- package/v4/locales/ko.js +1 -0
- package/v4/locales/lt.cjs +1 -0
- package/v4/locales/lt.js +1 -0
- package/v4/locales/mk.cjs +1 -0
- package/v4/locales/mk.js +1 -0
- package/v4/locales/ms.cjs +1 -0
- package/v4/locales/ms.js +1 -0
- package/v4/locales/ne.cjs +1 -0
- package/v4/locales/ne.js +1 -0
- package/v4/locales/nl.cjs +1 -0
- package/v4/locales/nl.js +1 -0
- package/v4/locales/nn.cjs +1 -0
- package/v4/locales/nn.js +1 -0
- package/v4/locales/no.cjs +1 -0
- package/v4/locales/no.js +1 -0
- package/v4/locales/ota.cjs +1 -0
- package/v4/locales/ota.js +1 -0
- package/v4/locales/pl.cjs +1 -0
- package/v4/locales/pl.js +1 -0
- package/v4/locales/ps.cjs +1 -0
- package/v4/locales/ps.js +1 -0
- package/v4/locales/pt-BR.cjs +1 -0
- package/v4/locales/pt-BR.js +1 -0
- package/v4/locales/pt.cjs +1 -0
- package/v4/locales/pt.js +1 -0
- package/v4/locales/ro.cjs +1 -0
- package/v4/locales/ro.js +1 -0
- package/v4/locales/ru.cjs +1 -0
- package/v4/locales/ru.js +1 -0
- package/v4/locales/sk.cjs +1 -0
- package/v4/locales/sk.js +1 -0
- package/v4/locales/sl.cjs +1 -0
- package/v4/locales/sl.js +1 -0
- package/v4/locales/sv.cjs +1 -0
- package/v4/locales/sv.js +1 -0
- package/v4/locales/ta.cjs +1 -0
- package/v4/locales/ta.js +1 -0
- package/v4/locales/th.cjs +1 -0
- package/v4/locales/th.js +1 -0
- package/v4/locales/tk.cjs +1 -0
- package/v4/locales/tk.js +1 -0
- package/v4/locales/tr.cjs +1 -0
- package/v4/locales/tr.js +1 -0
- package/v4/locales/uk.cjs +1 -0
- package/v4/locales/uk.js +1 -0
- package/v4/locales/ur.cjs +1 -0
- package/v4/locales/ur.js +1 -0
- package/v4/locales/uz.cjs +1 -0
- package/v4/locales/uz.js +1 -0
- package/v4/locales/vi.cjs +1 -0
- package/v4/locales/vi.js +1 -0
- package/v4/locales/yo.cjs +1 -0
- package/v4/locales/yo.js +1 -0
- package/v4/locales/zh-CN.cjs +1 -0
- package/v4/locales/zh-CN.js +1 -0
- package/v4/locales/zh-TW.cjs +1 -0
- package/v4/locales/zh-TW.js +1 -0
- package/v4/mini/checks.cjs +20 -2
- package/v4/mini/checks.d.cts +1 -1
- package/v4/mini/checks.d.ts +1 -1
- package/v4/mini/checks.js +1 -1
- package/v4/mini/coerce.cjs +19 -0
- package/v4/mini/deep-partial.cjs +19 -0
- package/v4/mini/external.cjs +22 -1
- package/v4/mini/external.d.cts +1 -1
- package/v4/mini/external.d.ts +1 -1
- package/v4/mini/external.js +1 -1
- package/v4/mini/in-out.cjs +19 -0
- package/v4/mini/index.cjs +19 -0
- package/v4/mini/iso.cjs +19 -0
- package/v4/mini/parse.cjs +19 -0
- package/v4/mini/schemas.cjs +42 -4
- package/v4/mini/schemas.d.cts +8 -0
- package/v4/mini/schemas.d.ts +8 -0
- package/v4/mini/schemas.js +19 -2
- package/v4-mini/index.cjs +19 -0
package/v4/core/util.d.cts
CHANGED
|
@@ -27,8 +27,13 @@ type ToZodKeyMismatch<Expected, Received> = schemas.$ZodType & {
|
|
|
27
27
|
received: Received;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
+
declare const toZodDummy: unique symbol;
|
|
31
|
+
type ToZodNormalize<T> = [T] extends [(...args: any[]) => any] ? T : [T] extends [object] ? {
|
|
32
|
+
[K in keyof T]: ToZodNormalize<T[K]>;
|
|
33
|
+
} : T | typeof toZodDummy;
|
|
34
|
+
type ToZodEqual<Output, T> = AssertEqual<Output, T> extends true ? true : IsAny<Output> extends true ? false : IsAny<T> extends true ? false : AssertEqual<ToZodNormalize<Output>, ToZodNormalize<T>>;
|
|
30
35
|
type ToZodShape<Shape, T> = {
|
|
31
|
-
[K in keyof Shape]: Shape[K] extends schemas.$ZodType ? K extends keyof T ?
|
|
36
|
+
[K in keyof Shape]: Shape[K] extends schemas.$ZodType ? K extends keyof T ? ToZodEqual<Shape[K]["_zod"]["output"], T[K]> extends true ? Shape[K] : ToZodKeyMismatch<T[K], Shape[K]["_zod"]["output"]> : ToZodKeyMismatch<never, Shape[K]["_zod"]["output"]> : Shape[K];
|
|
32
37
|
} & {
|
|
33
38
|
[K in Exclude<keyof T, keyof Shape>]: ToZodKeyMismatch<T[K], never>;
|
|
34
39
|
};
|
|
@@ -44,6 +49,7 @@ export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K
|
|
|
44
49
|
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
|
|
45
50
|
export type NoUndefined<T> = T extends undefined ? never : T;
|
|
46
51
|
export type Whatever = {} | undefined | null;
|
|
52
|
+
export type Widen<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T;
|
|
47
53
|
export type LoosePartial<T extends object> = InexactPartial<T> & {
|
|
48
54
|
[k: string]: unknown;
|
|
49
55
|
};
|
|
@@ -131,7 +137,7 @@ export type PropValues = Record<string, Set<Primitive>>;
|
|
|
131
137
|
export type PrimitiveSet = Set<Primitive>;
|
|
132
138
|
export declare function assertEqual<A, B>(val: AssertEqual<A, B>): AssertEqual<A, B>;
|
|
133
139
|
export declare function assertNotEqual<A, B>(val: AssertNotEqual<A, B>): AssertNotEqual<A, B>;
|
|
134
|
-
export declare function toZod<T>(): <S extends schemas.$ZodType>(schema:
|
|
140
|
+
export declare function toZod<T>(): <S extends schemas.$ZodType>(schema: ToZodEqual<S["_zod"]["output"], T> extends true ? S : ToZodTarget<S, T>) => S;
|
|
135
141
|
export declare function assertIs<T>(_arg: T): void;
|
|
136
142
|
export declare function assertNever(_x: never): never;
|
|
137
143
|
export declare function assert<T>(_: any): asserts _ is T;
|
|
@@ -147,6 +153,17 @@ export declare function floatSafeRemainder(val: number, step: number): number;
|
|
|
147
153
|
export declare function defineLazy<T, K extends keyof T>(object: T, key: K, getter: () => T[K]): void;
|
|
148
154
|
export declare function objectClone(obj: object): any;
|
|
149
155
|
export declare function assignProp<T extends object, K extends PropertyKey>(target: T, prop: K, value: K extends keyof T ? T[K] : any): void;
|
|
156
|
+
/** A def's `shape` accessor, carrying whichever object it currently answers from. */
|
|
157
|
+
export interface ShapeGetter {
|
|
158
|
+
(): Record<PropertyKey, any>;
|
|
159
|
+
raw: Record<PropertyKey, any>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Whichever object a def's `shape` currently answers from: the one the caller passed until the first read, the frozen copy after it.
|
|
163
|
+
*
|
|
164
|
+
* Its keys and descriptors read without invoking anything, which is what lets a discriminated union check its discriminator, and the cycle walk read a shape, without resolving a getter that references the schema being constructed. A def that answers `shape` from an accessor of its own has none.
|
|
165
|
+
*/
|
|
166
|
+
export declare function rawShape(def: any): Record<PropertyKey, any> | undefined;
|
|
150
167
|
export declare function mergeDefs(...defs: Record<string, any>[]): any;
|
|
151
168
|
export declare function cloneDef(schema: schemas.$ZodType): any;
|
|
152
169
|
export declare function getElementAtPath(obj: any, path: (string | number)[] | null | undefined): any;
|
|
@@ -229,9 +246,13 @@ export declare abstract class Class {
|
|
|
229
246
|
*/
|
|
230
247
|
export declare function members(proto: object, table: object): void;
|
|
231
248
|
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
|
232
|
-
export declare function own<T>(inst: object, key:
|
|
249
|
+
export declare function own<T>(inst: object, key: PropertyKey, value: T, enumerable?: boolean): T;
|
|
233
250
|
/** Like {@link own}, for a member that was never an own data property and has to stay out of `Object.keys`. */
|
|
234
|
-
export declare function hide<T>(inst: object, key:
|
|
251
|
+
export declare function hide<T>(inst: object, key: PropertyKey, value: T): T;
|
|
252
|
+
/** Adds members a table derives from the instance: each builds on first read and shadows as own data, and assignment shadows the same way, as when these were own properties. */
|
|
253
|
+
export declare function derived<T>(computes: {
|
|
254
|
+
[K in keyof T]?: (inst: T) => T[K];
|
|
255
|
+
}, table: ProtoOf<T>): ProtoOf<T>;
|
|
235
256
|
/** A trait's prototype members: a partial view of its own interface, with `this` typed as the instance. */
|
|
236
257
|
export type ProtoOf<T> = {
|
|
237
258
|
[K in keyof T]?: (T[K] extends (...args: infer A) => infer R ? (...args: A) => R : T[K]) | undefined;
|
package/v4/core/util.d.ts
CHANGED
|
@@ -27,8 +27,13 @@ type ToZodKeyMismatch<Expected, Received> = schemas.$ZodType & {
|
|
|
27
27
|
received: Received;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
+
declare const toZodDummy: unique symbol;
|
|
31
|
+
type ToZodNormalize<T> = [T] extends [(...args: any[]) => any] ? T : [T] extends [object] ? {
|
|
32
|
+
[K in keyof T]: ToZodNormalize<T[K]>;
|
|
33
|
+
} : T | typeof toZodDummy;
|
|
34
|
+
type ToZodEqual<Output, T> = AssertEqual<Output, T> extends true ? true : IsAny<Output> extends true ? false : IsAny<T> extends true ? false : AssertEqual<ToZodNormalize<Output>, ToZodNormalize<T>>;
|
|
30
35
|
type ToZodShape<Shape, T> = {
|
|
31
|
-
[K in keyof Shape]: Shape[K] extends schemas.$ZodType ? K extends keyof T ?
|
|
36
|
+
[K in keyof Shape]: Shape[K] extends schemas.$ZodType ? K extends keyof T ? ToZodEqual<Shape[K]["_zod"]["output"], T[K]> extends true ? Shape[K] : ToZodKeyMismatch<T[K], Shape[K]["_zod"]["output"]> : ToZodKeyMismatch<never, Shape[K]["_zod"]["output"]> : Shape[K];
|
|
32
37
|
} & {
|
|
33
38
|
[K in Exclude<keyof T, keyof Shape>]: ToZodKeyMismatch<T[K], never>;
|
|
34
39
|
};
|
|
@@ -44,6 +49,7 @@ export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K
|
|
|
44
49
|
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
|
|
45
50
|
export type NoUndefined<T> = T extends undefined ? never : T;
|
|
46
51
|
export type Whatever = {} | undefined | null;
|
|
52
|
+
export type Widen<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T;
|
|
47
53
|
export type LoosePartial<T extends object> = InexactPartial<T> & {
|
|
48
54
|
[k: string]: unknown;
|
|
49
55
|
};
|
|
@@ -131,7 +137,7 @@ export type PropValues = Record<string, Set<Primitive>>;
|
|
|
131
137
|
export type PrimitiveSet = Set<Primitive>;
|
|
132
138
|
export declare function assertEqual<A, B>(val: AssertEqual<A, B>): AssertEqual<A, B>;
|
|
133
139
|
export declare function assertNotEqual<A, B>(val: AssertNotEqual<A, B>): AssertNotEqual<A, B>;
|
|
134
|
-
export declare function toZod<T>(): <S extends schemas.$ZodType>(schema:
|
|
140
|
+
export declare function toZod<T>(): <S extends schemas.$ZodType>(schema: ToZodEqual<S["_zod"]["output"], T> extends true ? S : ToZodTarget<S, T>) => S;
|
|
135
141
|
export declare function assertIs<T>(_arg: T): void;
|
|
136
142
|
export declare function assertNever(_x: never): never;
|
|
137
143
|
export declare function assert<T>(_: any): asserts _ is T;
|
|
@@ -147,6 +153,17 @@ export declare function floatSafeRemainder(val: number, step: number): number;
|
|
|
147
153
|
export declare function defineLazy<T, K extends keyof T>(object: T, key: K, getter: () => T[K]): void;
|
|
148
154
|
export declare function objectClone(obj: object): any;
|
|
149
155
|
export declare function assignProp<T extends object, K extends PropertyKey>(target: T, prop: K, value: K extends keyof T ? T[K] : any): void;
|
|
156
|
+
/** A def's `shape` accessor, carrying whichever object it currently answers from. */
|
|
157
|
+
export interface ShapeGetter {
|
|
158
|
+
(): Record<PropertyKey, any>;
|
|
159
|
+
raw: Record<PropertyKey, any>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Whichever object a def's `shape` currently answers from: the one the caller passed until the first read, the frozen copy after it.
|
|
163
|
+
*
|
|
164
|
+
* Its keys and descriptors read without invoking anything, which is what lets a discriminated union check its discriminator, and the cycle walk read a shape, without resolving a getter that references the schema being constructed. A def that answers `shape` from an accessor of its own has none.
|
|
165
|
+
*/
|
|
166
|
+
export declare function rawShape(def: any): Record<PropertyKey, any> | undefined;
|
|
150
167
|
export declare function mergeDefs(...defs: Record<string, any>[]): any;
|
|
151
168
|
export declare function cloneDef(schema: schemas.$ZodType): any;
|
|
152
169
|
export declare function getElementAtPath(obj: any, path: (string | number)[] | null | undefined): any;
|
|
@@ -229,9 +246,13 @@ export declare abstract class Class {
|
|
|
229
246
|
*/
|
|
230
247
|
export declare function members(proto: object, table: object): void;
|
|
231
248
|
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
|
232
|
-
export declare function own<T>(inst: object, key:
|
|
249
|
+
export declare function own<T>(inst: object, key: PropertyKey, value: T, enumerable?: boolean): T;
|
|
233
250
|
/** Like {@link own}, for a member that was never an own data property and has to stay out of `Object.keys`. */
|
|
234
|
-
export declare function hide<T>(inst: object, key:
|
|
251
|
+
export declare function hide<T>(inst: object, key: PropertyKey, value: T): T;
|
|
252
|
+
/** Adds members a table derives from the instance: each builds on first read and shadows as own data, and assignment shadows the same way, as when these were own properties. */
|
|
253
|
+
export declare function derived<T>(computes: {
|
|
254
|
+
[K in keyof T]?: (inst: T) => T[K];
|
|
255
|
+
}, table: ProtoOf<T>): ProtoOf<T>;
|
|
235
256
|
/** A trait's prototype members: a partial view of its own interface, with `this` typed as the instance. */
|
|
236
257
|
export type ProtoOf<T> = {
|
|
237
258
|
[K in keyof T]?: (T[K] extends (...args: infer A) => infer R ? (...args: A) => R : T[K]) | undefined;
|
package/v4/core/util.js
CHANGED
|
@@ -29,18 +29,23 @@ export function jsonStringifyReplacer(_, value) {
|
|
|
29
29
|
return value.toString();
|
|
30
30
|
return value;
|
|
31
31
|
}
|
|
32
|
+
// the accessor lives on a shared prototype: an own accessor makes every box a dictionary-mode object (~360 B and a slow load per read against ~100 B and an inlined getter here)
|
|
33
|
+
class Cached {
|
|
34
|
+
constructor(getter) {
|
|
35
|
+
this._getter = getter;
|
|
36
|
+
this._value = undefined;
|
|
37
|
+
}
|
|
38
|
+
get value() {
|
|
39
|
+
const getter = this._getter;
|
|
40
|
+
if (getter !== undefined) {
|
|
41
|
+
this._value = getter();
|
|
42
|
+
this._getter = undefined;
|
|
43
|
+
}
|
|
44
|
+
return this._value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
32
47
|
export function cached(getter) {
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
get value() {
|
|
36
|
-
if (!set) {
|
|
37
|
-
const value = getter();
|
|
38
|
-
Object.defineProperty(this, "value", { value });
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
throw new Error("cached value already set");
|
|
42
|
-
},
|
|
43
|
-
};
|
|
48
|
+
return new Cached(getter);
|
|
44
49
|
}
|
|
45
50
|
export function nullish(input) {
|
|
46
51
|
return input === null || input === undefined;
|
|
@@ -95,6 +100,71 @@ export function assignProp(target, prop, value) {
|
|
|
95
100
|
configurable: true,
|
|
96
101
|
});
|
|
97
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Whichever object a def's `shape` currently answers from: the one the caller passed until the first read, the frozen copy after it.
|
|
105
|
+
*
|
|
106
|
+
* Its keys and descriptors read without invoking anything, which is what lets a discriminated union check its discriminator, and the cycle walk read a shape, without resolving a getter that references the schema being constructed. A def that answers `shape` from an accessor of its own has none.
|
|
107
|
+
*/
|
|
108
|
+
export function rawShape(def) {
|
|
109
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
110
|
+
return desc?.get ? desc.get.raw : desc?.value;
|
|
111
|
+
}
|
|
112
|
+
// where a builder reads its source's keys and descriptors, resolving only a shape a def answers for itself. A shape resolves by object spread, so only its enumerable keys are ever part of it.
|
|
113
|
+
function sourceShape(schema) {
|
|
114
|
+
return rawShape(schema._zod.def) ?? schema._zod.def.shape;
|
|
115
|
+
}
|
|
116
|
+
// a key whose value is not settled yet, self-caching so every read after the first gets the same one
|
|
117
|
+
function deferProp(target, key, getter) {
|
|
118
|
+
Object.defineProperty(target, key, {
|
|
119
|
+
get() {
|
|
120
|
+
const value = getter();
|
|
121
|
+
assignProp(this, key, value);
|
|
122
|
+
return value;
|
|
123
|
+
},
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: true,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Writes a settled key. A plain assignment is much cheaper than `defineProperty` and produces the same descriptor, but it runs whatever setter already answers to the key — an accessor this shape deferred, or an inherited one, which `__proto__` has on every object and prototype pollution can add for any name.
|
|
129
|
+
function putProp(target, key, value) {
|
|
130
|
+
if (key in target)
|
|
131
|
+
assignProp(target, key, value);
|
|
132
|
+
else
|
|
133
|
+
target[key] = value;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Copies `keys` of `source`'s shape onto `target`, each value passed through `wrap`.
|
|
137
|
+
*
|
|
138
|
+
* A key the source has resolved is copied through now, so the derived shape states it outright and nothing has to resolve it to learn what it holds. A key the source still defers stays deferred, and reads back through the source's own `shape`, so it resolves once and both shapes get that one schema.
|
|
139
|
+
*/
|
|
140
|
+
function mirrorShape(target, source, keys, wrap) {
|
|
141
|
+
const raw = sourceShape(source);
|
|
142
|
+
for (const key of keys) {
|
|
143
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
144
|
+
if (!desc.enumerable)
|
|
145
|
+
continue;
|
|
146
|
+
if (desc.get) {
|
|
147
|
+
deferProp(target, key, () => {
|
|
148
|
+
const value = source._zod.def.shape[key];
|
|
149
|
+
return wrap ? wrap(value, key) : value;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
putProp(target, key, wrap ? wrap(desc.value, key) : desc.value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// same, for a plain shape a caller passed rather than a schema's
|
|
157
|
+
function mirrorProps(target, source) {
|
|
158
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
159
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
160
|
+
if (!desc.enumerable)
|
|
161
|
+
continue;
|
|
162
|
+
if (desc.get)
|
|
163
|
+
deferProp(target, key, () => source[key]);
|
|
164
|
+
else
|
|
165
|
+
putProp(target, key, desc.value);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
98
168
|
export function mergeDefs(...defs) {
|
|
99
169
|
const mergedDescriptors = {};
|
|
100
170
|
for (const def of defs) {
|
|
@@ -346,24 +416,23 @@ export function pick(schema, mask) {
|
|
|
346
416
|
if (hasChecks) {
|
|
347
417
|
throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
348
418
|
}
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return clone(schema, def);
|
|
419
|
+
const newShape = {};
|
|
420
|
+
mirrorShape(newShape, schema, maskedKeys(schema, mask));
|
|
421
|
+
return clone(schema, mergeDefs(currDef, { shape: newShape, checks: [] }));
|
|
422
|
+
}
|
|
423
|
+
// the mask keys that select something, checked against the source's shape without resolving it
|
|
424
|
+
function maskedKeys(schema, mask) {
|
|
425
|
+
const raw = sourceShape(schema);
|
|
426
|
+
const keys = [];
|
|
427
|
+
// `for...in` skips symbols, so a symbol in the mask would select nothing
|
|
428
|
+
for (const key of Reflect.ownKeys(mask)) {
|
|
429
|
+
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable) {
|
|
430
|
+
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
431
|
+
}
|
|
432
|
+
if (mask[key])
|
|
433
|
+
keys.push(key);
|
|
434
|
+
}
|
|
435
|
+
return keys;
|
|
367
436
|
}
|
|
368
437
|
export function omit(schema, mask) {
|
|
369
438
|
const currDef = schema._zod.def;
|
|
@@ -372,23 +441,10 @@ export function omit(schema, mask) {
|
|
|
372
441
|
if (hasChecks) {
|
|
373
442
|
throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
374
443
|
}
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (!Object.prototype.hasOwnProperty.call(currDef.shape, key)) {
|
|
380
|
-
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
381
|
-
}
|
|
382
|
-
if (!mask[key])
|
|
383
|
-
continue;
|
|
384
|
-
delete newShape[key];
|
|
385
|
-
}
|
|
386
|
-
assignProp(this, "shape", newShape); // self-caching
|
|
387
|
-
return newShape;
|
|
388
|
-
},
|
|
389
|
-
checks: [],
|
|
390
|
-
});
|
|
391
|
-
return clone(schema, def);
|
|
444
|
+
const omitted = new Set(maskedKeys(schema, mask));
|
|
445
|
+
const newShape = {};
|
|
446
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)).filter((key) => !omitted.has(key)));
|
|
447
|
+
return clone(schema, mergeDefs(currDef, { shape: newShape, checks: [] }));
|
|
392
448
|
}
|
|
393
449
|
export function extend(schema, shape) {
|
|
394
450
|
if (!isPlainObject(shape)) {
|
|
@@ -398,34 +454,27 @@ export function extend(schema, shape) {
|
|
|
398
454
|
const hasChecks = checks && checks.length > 0;
|
|
399
455
|
if (hasChecks) {
|
|
400
456
|
// Only throw if new shape overlaps with existing shape. Use getOwnPropertyDescriptor to check key existence without accessing values
|
|
401
|
-
const existingShape = schema
|
|
457
|
+
const existingShape = sourceShape(schema);
|
|
402
458
|
for (const key of Reflect.ownKeys(shape)) {
|
|
403
459
|
if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
|
|
404
460
|
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
405
461
|
}
|
|
406
462
|
}
|
|
407
463
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return
|
|
464
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
|
|
465
|
+
}
|
|
466
|
+
// the source's keys, then the caller's overlaid on top
|
|
467
|
+
function extended(schema, shape) {
|
|
468
|
+
const newShape = {};
|
|
469
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
|
|
470
|
+
mirrorProps(newShape, shape);
|
|
471
|
+
return newShape;
|
|
416
472
|
}
|
|
417
473
|
export function safeExtend(schema, shape) {
|
|
418
474
|
if (!isPlainObject(shape)) {
|
|
419
475
|
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
420
476
|
}
|
|
421
|
-
|
|
422
|
-
get shape() {
|
|
423
|
-
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
424
|
-
assignProp(this, "shape", _shape); // self-caching
|
|
425
|
-
return _shape;
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
return clone(schema, def);
|
|
477
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
|
|
429
478
|
}
|
|
430
479
|
export function merge(a, b) {
|
|
431
480
|
if (!b?._zod?.def) {
|
|
@@ -434,12 +483,11 @@ export function merge(a, b) {
|
|
|
434
483
|
if (a._zod.def.checks?.length) {
|
|
435
484
|
throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
|
|
436
485
|
}
|
|
486
|
+
const newShape = {};
|
|
487
|
+
mirrorShape(newShape, a, Reflect.ownKeys(sourceShape(a)));
|
|
488
|
+
mirrorShape(newShape, b, Reflect.ownKeys(sourceShape(b)));
|
|
437
489
|
const def = mergeDefs(a._zod.def, {
|
|
438
|
-
|
|
439
|
-
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
440
|
-
assignProp(this, "shape", _shape); // self-caching
|
|
441
|
-
return _shape;
|
|
442
|
-
},
|
|
490
|
+
shape: newShape,
|
|
443
491
|
get catchall() {
|
|
444
492
|
return b._zod.def.catchall;
|
|
445
493
|
},
|
|
@@ -454,78 +502,19 @@ export function partial(Class, schema, mask, name = "partial") {
|
|
|
454
502
|
if (hasChecks) {
|
|
455
503
|
throw new Error(`.${name}() cannot be used on object schemas containing refinements`);
|
|
456
504
|
}
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
for (const key of Reflect.ownKeys(mask)) {
|
|
463
|
-
if (!Object.prototype.hasOwnProperty.call(oldShape, key)) {
|
|
464
|
-
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
465
|
-
}
|
|
466
|
-
if (!mask[key])
|
|
467
|
-
continue;
|
|
468
|
-
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
469
|
-
shape[key] = Class
|
|
470
|
-
? new Class({
|
|
471
|
-
type: "optional",
|
|
472
|
-
innerType: oldShape[key],
|
|
473
|
-
})
|
|
474
|
-
: oldShape[key];
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
// the spread copies symbol keys; `for...in` would not reach them
|
|
479
|
-
for (const key of Reflect.ownKeys(oldShape)) {
|
|
480
|
-
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
481
|
-
shape[key] = Class
|
|
482
|
-
? new Class({
|
|
483
|
-
type: "optional",
|
|
484
|
-
innerType: oldShape[key],
|
|
485
|
-
})
|
|
486
|
-
: oldShape[key];
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
assignProp(this, "shape", shape); // self-caching
|
|
490
|
-
return shape;
|
|
491
|
-
},
|
|
492
|
-
checks: [],
|
|
493
|
-
});
|
|
494
|
-
return clone(schema, def);
|
|
505
|
+
const selected = mask ? new Set(maskedKeys(schema, mask)) : undefined;
|
|
506
|
+
const newShape = {};
|
|
507
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), Class &&
|
|
508
|
+
((value, key) => (selected && !selected.has(key) ? value : new Class({ type: "optional", innerType: value }))));
|
|
509
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: newShape, checks: [] }));
|
|
495
510
|
}
|
|
496
511
|
export function required(Class, schema, mask) {
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (!Object.prototype.hasOwnProperty.call(shape, key)) {
|
|
504
|
-
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
505
|
-
}
|
|
506
|
-
if (!mask[key])
|
|
507
|
-
continue;
|
|
508
|
-
// overwrite with non-optional
|
|
509
|
-
shape[key] = new Class({
|
|
510
|
-
type: "nonoptional",
|
|
511
|
-
innerType: oldShape[key],
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
for (const key of Reflect.ownKeys(oldShape)) {
|
|
517
|
-
// overwrite with non-optional
|
|
518
|
-
shape[key] = new Class({
|
|
519
|
-
type: "nonoptional",
|
|
520
|
-
innerType: oldShape[key],
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
assignProp(this, "shape", shape); // self-caching
|
|
525
|
-
return shape;
|
|
526
|
-
},
|
|
527
|
-
});
|
|
528
|
-
return clone(schema, def);
|
|
512
|
+
const selected = mask ? new Set(maskedKeys(schema, mask)) : undefined;
|
|
513
|
+
const newShape = {};
|
|
514
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), (value, key) =>
|
|
515
|
+
// overwrite with non-optional
|
|
516
|
+
selected && !selected.has(key) ? value : new Class({ type: "nonoptional", innerType: value }));
|
|
517
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: newShape }));
|
|
529
518
|
}
|
|
530
519
|
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
|
531
520
|
export function aborted(x, startIndex = 0) {
|
|
@@ -587,13 +576,19 @@ export function finalizeIssue(iss, ctx, config) {
|
|
|
587
576
|
unwrapMessage(config.customError?.(iss)) ??
|
|
588
577
|
unwrapMessage(config.localeError?.(iss)) ??
|
|
589
578
|
"Invalid input");
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
579
|
+
// an explicit own-key copy beats object rest with excluded keys, which v8 routes through a generic runtime call; Object.keys rather than for-in so an issue pushed with a prototype does not leak inherited keys, and an own __proto__ key is dropped rather than assigned through the setter
|
|
580
|
+
const full = {};
|
|
581
|
+
for (const k of Object.keys(iss)) {
|
|
582
|
+
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
|
|
583
|
+
continue;
|
|
584
|
+
full[k] = iss[k];
|
|
585
|
+
}
|
|
586
|
+
full.path ?? (full.path = []);
|
|
587
|
+
full.message = message;
|
|
593
588
|
if (ctx?.reportInput) {
|
|
594
|
-
|
|
589
|
+
full.input = iss.input;
|
|
595
590
|
}
|
|
596
|
-
return
|
|
591
|
+
return full;
|
|
597
592
|
}
|
|
598
593
|
export function getSizableOrigin(input) {
|
|
599
594
|
if (input instanceof Set)
|
|
@@ -730,6 +725,10 @@ export function members(proto, table) {
|
|
|
730
725
|
else
|
|
731
726
|
defineBound(proto, key, desc.value);
|
|
732
727
|
}
|
|
728
|
+
// for..in sees no symbol keys, so well-known members like Symbol.iterator install here
|
|
729
|
+
for (const sym of Object.getOwnPropertySymbols(table)) {
|
|
730
|
+
defineBound(proto, sym, table[sym]);
|
|
731
|
+
}
|
|
733
732
|
}
|
|
734
733
|
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
|
735
734
|
export function own(inst, key, value, enumerable = true) {
|
|
@@ -740,6 +739,24 @@ export function own(inst, key, value, enumerable = true) {
|
|
|
740
739
|
export function hide(inst, key, value) {
|
|
741
740
|
return own(inst, key, value, false);
|
|
742
741
|
}
|
|
742
|
+
/** Adds members a table derives from the instance: each builds on first read and shadows as own data, and assignment shadows the same way, as when these were own properties. */
|
|
743
|
+
export /*@__NO_SIDE_EFFECTS__*/ function derived(computes, table) {
|
|
744
|
+
for (const key in computes) {
|
|
745
|
+
const compute = computes[key];
|
|
746
|
+
// an object literal's accessor is configurable and enumerable, and `members` copies the descriptor as written
|
|
747
|
+
Object.defineProperty(table, key, {
|
|
748
|
+
configurable: true,
|
|
749
|
+
enumerable: true,
|
|
750
|
+
get() {
|
|
751
|
+
return own(this, key, compute(this));
|
|
752
|
+
},
|
|
753
|
+
set(value) {
|
|
754
|
+
own(this, key, value);
|
|
755
|
+
},
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
return table;
|
|
759
|
+
}
|
|
743
760
|
function defineBound(proto, key, fn) {
|
|
744
761
|
Object.defineProperty(proto, key, {
|
|
745
762
|
configurable: true,
|
package/v4/core/versions.cjs
CHANGED
|
@@ -3,6 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.version = void 0;
|
|
4
4
|
exports.version = {
|
|
5
5
|
major: 4,
|
|
6
|
-
minor:
|
|
7
|
-
patch:
|
|
6
|
+
minor: 6,
|
|
7
|
+
patch: 0,
|
|
8
8
|
};
|
|
9
|
+
|
|
10
|
+
// seal-cjs-exports
|
|
11
|
+
(function () {
|
|
12
|
+
var keys = Object.getOwnPropertyNames(exports);
|
|
13
|
+
for (var i = 0; i < keys.length; i++) {
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
|
|
15
|
+
if (!desc || !desc.get || !desc.configurable) continue;
|
|
16
|
+
var value;
|
|
17
|
+
try {
|
|
18
|
+
value = desc.get();
|
|
19
|
+
} catch (e) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
// a circular require may not have settled this one yet, so leave it live
|
|
23
|
+
if (value === undefined) continue;
|
|
24
|
+
Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
|
|
25
|
+
}
|
|
26
|
+
Object.freeze(exports);
|
|
27
|
+
})();
|
package/v4/core/versions.d.cts
CHANGED
package/v4/core/versions.d.ts
CHANGED
package/v4/core/versions.js
CHANGED
package/v4/core/visit.cjs
CHANGED
|
@@ -161,6 +161,18 @@ function visit(schema, fnOrHandlers) {
|
|
|
161
161
|
const { _cachedInner, ...rest } = def;
|
|
162
162
|
return (0, util_js_1.clone)(s, { ...rest, getter: () => run(original()) });
|
|
163
163
|
}
|
|
164
|
+
case "properties": {
|
|
165
|
+
const oldShape = def.shape;
|
|
166
|
+
let changed = false;
|
|
167
|
+
const newShape = {};
|
|
168
|
+
for (const k of Reflect.ownKeys(oldShape)) {
|
|
169
|
+
const mapped = run(oldShape[k]);
|
|
170
|
+
if (mapped !== oldShape[k])
|
|
171
|
+
changed = true;
|
|
172
|
+
newShape[k] = mapped;
|
|
173
|
+
}
|
|
174
|
+
return changed ? (0, util_js_1.clone)(s, { ...def, shape: newShape }) : s;
|
|
175
|
+
}
|
|
164
176
|
// A leaf by choice: `parts` are regex fragments, not data positions.
|
|
165
177
|
case "template_literal":
|
|
166
178
|
// Leaves.
|
|
@@ -193,3 +205,22 @@ function visit(schema, fnOrHandlers) {
|
|
|
193
205
|
}
|
|
194
206
|
return run(schema);
|
|
195
207
|
}
|
|
208
|
+
|
|
209
|
+
// seal-cjs-exports
|
|
210
|
+
(function () {
|
|
211
|
+
var keys = Object.getOwnPropertyNames(exports);
|
|
212
|
+
for (var i = 0; i < keys.length; i++) {
|
|
213
|
+
var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
|
|
214
|
+
if (!desc || !desc.get || !desc.configurable) continue;
|
|
215
|
+
var value;
|
|
216
|
+
try {
|
|
217
|
+
value = desc.get();
|
|
218
|
+
} catch (e) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
// a circular require may not have settled this one yet, so leave it live
|
|
222
|
+
if (value === undefined) continue;
|
|
223
|
+
Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
|
|
224
|
+
}
|
|
225
|
+
Object.freeze(exports);
|
|
226
|
+
})();
|
package/v4/core/visit.js
CHANGED
|
@@ -135,6 +135,18 @@ export function visit(schema, fnOrHandlers) {
|
|
|
135
135
|
const { _cachedInner, ...rest } = def;
|
|
136
136
|
return clone(s, { ...rest, getter: () => run(original()) });
|
|
137
137
|
}
|
|
138
|
+
case "properties": {
|
|
139
|
+
const oldShape = def.shape;
|
|
140
|
+
let changed = false;
|
|
141
|
+
const newShape = {};
|
|
142
|
+
for (const k of Reflect.ownKeys(oldShape)) {
|
|
143
|
+
const mapped = run(oldShape[k]);
|
|
144
|
+
if (mapped !== oldShape[k])
|
|
145
|
+
changed = true;
|
|
146
|
+
newShape[k] = mapped;
|
|
147
|
+
}
|
|
148
|
+
return changed ? clone(s, { ...def, shape: newShape }) : s;
|
|
149
|
+
}
|
|
138
150
|
// A leaf by choice: `parts` are regex fragments, not data positions.
|
|
139
151
|
case "template_literal":
|
|
140
152
|
// Leaves.
|
package/v4/index.cjs
CHANGED
|
@@ -30,3 +30,22 @@ exports.default = void 0;
|
|
|
30
30
|
const z4 = __importStar(require("./classic/external.cjs"));
|
|
31
31
|
exports.default = z4;
|
|
32
32
|
__exportStar(require("./classic/index.cjs"), exports);
|
|
33
|
+
|
|
34
|
+
// seal-cjs-exports
|
|
35
|
+
(function () {
|
|
36
|
+
var keys = Object.getOwnPropertyNames(exports);
|
|
37
|
+
for (var i = 0; i < keys.length; i++) {
|
|
38
|
+
var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
|
|
39
|
+
if (!desc || !desc.get || !desc.configurable) continue;
|
|
40
|
+
var value;
|
|
41
|
+
try {
|
|
42
|
+
value = desc.get();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// a circular require may not have settled this one yet, so leave it live
|
|
47
|
+
if (value === undefined) continue;
|
|
48
|
+
Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
|
|
49
|
+
}
|
|
50
|
+
Object.freeze(exports);
|
|
51
|
+
})();
|