zod 4.2.0-canary.20251118T054932 → 4.2.0-canary.20251118T055019
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/package.json
CHANGED
|
@@ -19,6 +19,10 @@ test("globalRegistry", () => {
|
|
|
19
19
|
expect(z.globalRegistry.has(a)).toEqual(false);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
test("globalRegistry is singleton and attached to globalThis", () => {
|
|
23
|
+
expect(z.globalRegistry).toBe((globalThis as any).__zod_globalRegistry);
|
|
24
|
+
});
|
|
25
|
+
|
|
22
26
|
test("z.registry", () => {
|
|
23
27
|
const fieldRegistry = z.registry<{ name: string; description: string }>();
|
|
24
28
|
|
|
@@ -94,4 +94,15 @@ export function registry<T extends MetadataType = MetadataType, S extends $ZodTy
|
|
|
94
94
|
return new $ZodRegistry<T, S>();
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
interface GlobalThisWithRegistry {
|
|
98
|
+
/**
|
|
99
|
+
* The globalRegistry instance shared across both CommonJS and ESM builds.
|
|
100
|
+
* By attaching the registry to `globalThis`, this property ensures a single, deduplicated instance
|
|
101
|
+
* is used regardless of whether the package is loaded via `require` (CJS) or `import` (ESM).
|
|
102
|
+
* This prevents dual package hazards and keeps registry state consistent.
|
|
103
|
+
*/
|
|
104
|
+
__zod_globalRegistry?: $ZodRegistry<GlobalMeta>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
(globalThis as GlobalThisWithRegistry).__zod_globalRegistry ??= registry<GlobalMeta>();
|
|
108
|
+
export const globalRegistry: $ZodRegistry<GlobalMeta> = (globalThis as GlobalThisWithRegistry).__zod_globalRegistry!;
|
package/v4/core/registries.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.globalRegistry = exports.$ZodRegistry = exports.$input = exports.$output = void 0;
|
|
4
5
|
exports.registry = registry;
|
|
@@ -54,4 +55,5 @@ exports.$ZodRegistry = $ZodRegistry;
|
|
|
54
55
|
function registry() {
|
|
55
56
|
return new $ZodRegistry();
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
59
|
+
exports.globalRegistry = globalThis.__zod_globalRegistry;
|
package/v4/core/registries.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
export const $output = Symbol("ZodOutput");
|
|
2
3
|
export const $input = Symbol("ZodInput");
|
|
3
4
|
export class $ZodRegistry {
|
|
@@ -49,4 +50,5 @@ export class $ZodRegistry {
|
|
|
49
50
|
export function registry() {
|
|
50
51
|
return new $ZodRegistry();
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
54
|
+
export const globalRegistry = globalThis.__zod_globalRegistry;
|