@frontmcp/lazy-zod 1.7.0 → 1.7.1
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/esm/index.mjs +22 -10
- package/esm/package.json +1 -1
- package/index.js +22 -10
- package/lazy-z.d.ts +31 -0
- package/package.json +1 -1
package/esm/index.mjs
CHANGED
|
@@ -227,16 +227,28 @@ function deepMaterialize(value, seen) {
|
|
|
227
227
|
|
|
228
228
|
// libs/lazy-zod/src/lazy-z.ts
|
|
229
229
|
import { z as realZ } from "zod";
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
230
|
+
function createLazyZ(namespace) {
|
|
231
|
+
return new Proxy({}, {
|
|
232
|
+
get(_target, key, receiver) {
|
|
233
|
+
if (typeof key === "string" && HEAVY_FACTORIES.has(key)) {
|
|
234
|
+
const realFactory = namespace[key];
|
|
235
|
+
return (...args) => wrapLazy(
|
|
236
|
+
new LazyZodSchema(() => realFactory.call(namespace, ...args))
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return Reflect.get(namespace, key, receiver);
|
|
240
|
+
},
|
|
241
|
+
set: (_target, key, value) => Reflect.set(namespace, key, value),
|
|
242
|
+
has: (_target, key) => Reflect.has(namespace, key),
|
|
243
|
+
ownKeys: () => Reflect.ownKeys(namespace),
|
|
244
|
+
getOwnPropertyDescriptor(_target, key) {
|
|
245
|
+
const desc = Reflect.getOwnPropertyDescriptor(namespace, key);
|
|
246
|
+
return desc ? { ...desc, configurable: true } : void 0;
|
|
247
|
+
},
|
|
248
|
+
getPrototypeOf: () => Reflect.getPrototypeOf(namespace)
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
var z = createLazyZ(realZ);
|
|
240
252
|
|
|
241
253
|
// libs/lazy-zod/src/eager-z.ts
|
|
242
254
|
import { z as z2 } from "zod";
|
package/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/lazy-zod",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Drop-in zod replacement that lazily constructs compound schemas for dramatic cold-start speedups. Exports `z` (lazy, drop-in), `eagerZ` (real zod, zero overhead), and `lazyZ` (explicit factory wrapper).",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"license": "Apache-2.0",
|
package/index.js
CHANGED
|
@@ -287,16 +287,28 @@ function deepMaterialize(value, seen) {
|
|
|
287
287
|
|
|
288
288
|
// libs/lazy-zod/src/lazy-z.ts
|
|
289
289
|
var import_zod = require("zod");
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
290
|
+
function createLazyZ(namespace) {
|
|
291
|
+
return new Proxy({}, {
|
|
292
|
+
get(_target, key, receiver) {
|
|
293
|
+
if (typeof key === "string" && HEAVY_FACTORIES.has(key)) {
|
|
294
|
+
const realFactory = namespace[key];
|
|
295
|
+
return (...args) => wrapLazy(
|
|
296
|
+
new LazyZodSchema(() => realFactory.call(namespace, ...args))
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
return Reflect.get(namespace, key, receiver);
|
|
300
|
+
},
|
|
301
|
+
set: (_target, key, value) => Reflect.set(namespace, key, value),
|
|
302
|
+
has: (_target, key) => Reflect.has(namespace, key),
|
|
303
|
+
ownKeys: () => Reflect.ownKeys(namespace),
|
|
304
|
+
getOwnPropertyDescriptor(_target, key) {
|
|
305
|
+
const desc = Reflect.getOwnPropertyDescriptor(namespace, key);
|
|
306
|
+
return desc ? { ...desc, configurable: true } : void 0;
|
|
307
|
+
},
|
|
308
|
+
getPrototypeOf: () => Reflect.getPrototypeOf(namespace)
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
var z = createLazyZ(import_zod.z);
|
|
300
312
|
|
|
301
313
|
// libs/lazy-zod/src/eager-z.ts
|
|
302
314
|
var import_zod2 = require("zod");
|
package/lazy-z.d.ts
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import { z as realZ } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Build the lazy `z` Proxy over a zod namespace object.
|
|
4
|
+
*
|
|
5
|
+
* The Proxy target is a fresh empty object, NOT the namespace itself. zod >= 4.6
|
|
6
|
+
* `Object.freeze`s its namespace, so every export became a non-configurable,
|
|
7
|
+
* non-writable DATA property — and a `get` trap that returns anything other than
|
|
8
|
+
* the value the target holds violates a Proxy invariant:
|
|
9
|
+
*
|
|
10
|
+
* TypeError: 'get' on proxy: property 'object' is a read-only and
|
|
11
|
+
* non-configurable data property on the proxy target but the proxy did not
|
|
12
|
+
* return its actual value
|
|
13
|
+
*
|
|
14
|
+
* which is exactly what swapping in a lazy factory does. An empty, extensible
|
|
15
|
+
* target owns nothing, so no invariant applies; every trap forwards to
|
|
16
|
+
* `namespace` instead. Exported for tests — the public entry point is `z`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createLazyZ(namespace: typeof realZ): typeof realZ;
|
|
19
|
+
/**
|
|
20
|
+
* Lazy-by-default `z`. Proxy over real zod's `z`:
|
|
21
|
+
* - Heavy compound factories (`object`, `union`, `discriminatedUnion`,
|
|
22
|
+
* `intersection`, `record`, `tuple`) return a `LazyZodSchema` Proxy —
|
|
23
|
+
* construction deferred until first `.parse()`.
|
|
24
|
+
* - Everything else (`string`, `number`, `boolean`, `enum`, `literal`,
|
|
25
|
+
* `lazy`, `custom`, etc.) passes through unchanged. Primitives are
|
|
26
|
+
* already cheap; the type constructors are phantom at runtime.
|
|
27
|
+
*
|
|
28
|
+
* Typed as `typeof realZ` so every zod value helper works identically,
|
|
29
|
+
* and a declaration-merged `namespace z` below re-exports zod's type
|
|
30
|
+
* namespace so `z.infer<T>`, `z.ZodObject<Shape>`, `z.ZodRawShape`, etc.
|
|
31
|
+
* resolve at the TYPE level (a const alone doesn't expose the namespace).
|
|
32
|
+
*/
|
|
2
33
|
export declare const z: typeof realZ;
|
|
3
34
|
export declare namespace z {
|
|
4
35
|
type infer<T> = realZ.infer<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/lazy-zod",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Drop-in zod replacement that lazily constructs compound schemas for dramatic cold-start speedups. Exports `z` (lazy, drop-in), `eagerZ` (real zod, zero overhead), and `lazyZ` (explicit factory wrapper).",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"license": "Apache-2.0",
|