@frontmcp/lazy-zod 0.0.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @frontmcp/lazy-zod
2
+
3
+ Drop-in Zod replacement that lazily constructs compound schemas. On bundled
4
+ CLI binaries and edge workers, this cuts module-init cold-start by ~50× on
5
+ schema-heavy entries with effectively zero steady-state parse overhead.
6
+
7
+ ## Why
8
+
9
+ In a benchmark of 1,515 realistic schemas (see `apps/poc-lazy-zod/`):
10
+
11
+ | Metric | Eager zod | Lazy zod | Delta |
12
+ | ------------------- | --------- | -------- | -------- |
13
+ | Cold-start (median) | 387 ms | 7.1 ms | **−98%** |
14
+ | First-parse | 0.45 ms | 1.47 ms | +1 ms |
15
+ | Parse-all (steady) | 31 ms | 31 ms | +0.2% |
16
+ | Bundle size | 1.69 MB | 1.70 MB | +0.64% |
17
+
18
+ The win comes from deferring `z.object({…})` / `z.union([…])` construction
19
+ until the first `.parse()` call — and self-patching the schema instance on
20
+ that first call so all subsequent parses bypass the wrapper entirely.
21
+
22
+ ## Install
23
+
24
+ ```sh
25
+ npm install @frontmcp/lazy-zod zod
26
+ ```
27
+
28
+ `zod` is a peer dependency (v4).
29
+
30
+ ## Usage
31
+
32
+ ```ts
33
+ // Preferred — lazy by default, full drop-in for zod's `z`.
34
+ import { z } from '@frontmcp/lazy-zod';
35
+
36
+ const schema = z.object({
37
+ name: z.string(),
38
+ age: z.number().optional(),
39
+ });
40
+
41
+ type User = z.infer<typeof schema>; // { name: string; age?: number }
42
+ schema.parse({ name: 'Ada', age: 36 });
43
+ ```
44
+
45
+ ```ts
46
+ // Escape hatch — real zod, zero proxy overhead.
47
+ // Use when you need a schema to be fully-constructed at module load
48
+ // (e.g. a library will immediately introspect it via toJSONSchema).
49
+ import { eagerZ } from '@frontmcp/lazy-zod';
50
+
51
+ const eager = eagerZ.object({ foo: eagerZ.string() });
52
+ ```
53
+
54
+ ```ts
55
+ // Explicit factory-style wrapper — when you already have a real zod schema
56
+ // and want to defer it.
57
+ import { eagerZ, lazyZ } from '@frontmcp/lazy-zod';
58
+
59
+ const deferred = lazyZ(() => eagerZ.object({ foo: eagerZ.string() }));
60
+ deferred.parse({ foo: 'bar' }); // materializes on first call
61
+ ```
62
+
63
+ When used inside FrontMCP, you don't need to depend on this package
64
+ directly — it's re-exported as `z` from `@frontmcp/sdk`.
65
+
66
+ ## Status
67
+
68
+ Implemented. `z` is lazy by default — heavy compound factories (`z.object`,
69
+ `z.union`, `z.discriminatedUnion`, `z.intersection`, `z.record`, `z.tuple`,
70
+ plus `z.strictObject` / `z.looseObject`) return a `Proxy` over a
71
+ `LazyZodSchema` that materializes the real zod schema on first
72
+ `.parse()` / `.safeParse()` / `.parseAsync()` / `.safeParseAsync()` call
73
+ and self-patches the hot-path methods onto the instance so subsequent
74
+ parses run at native zod speed (measured at +0.2% steady-state overhead
75
+ in the POC). Light factories (`z.string`, `z.number`, `z.enum`,
76
+ `z.literal`, `z.lazy`, etc.) pass straight through to real zod. See
77
+ `src/lazy-z.ts` for the Proxy and `src/lazy-schema.ts` for the wrapper.
78
+ Use `eagerZ` when a consumer needs a fully-constructed schema at
79
+ import time (e.g. immediate introspection).
80
+
81
+ ## License
82
+
83
+ Apache-2.0
package/eager-z.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Escape hatch — straight pass-through to real zod. Zero proxy overhead,
3
+ * eager construction. Use when you need a schema fully built at module
4
+ * load (e.g. a library will immediately introspect it) or for hot paths
5
+ * that don't care about cold-start.
6
+ */
7
+ export { z as eagerZ } from 'zod';
package/esm/index.mjs ADDED
@@ -0,0 +1,311 @@
1
+ // libs/lazy-zod/src/lazy-z.ts
2
+ import { z as realZ } from "zod";
3
+
4
+ // libs/lazy-zod/src/factories.ts
5
+ var HEAVY_FACTORIES = /* @__PURE__ */ new Set([
6
+ "object",
7
+ "strictObject",
8
+ "looseObject",
9
+ "union",
10
+ "discriminatedUnion",
11
+ "intersection",
12
+ "record",
13
+ "tuple"
14
+ ]);
15
+ var CHAIN_METHODS = /* @__PURE__ */ new Set([
16
+ // ZodType generic
17
+ "optional",
18
+ "nullable",
19
+ "nullish",
20
+ "default",
21
+ "prefault",
22
+ "describe",
23
+ "refine",
24
+ "superRefine",
25
+ "transform",
26
+ "pipe",
27
+ "or",
28
+ "and",
29
+ "readonly",
30
+ "brand",
31
+ "catch",
32
+ "array",
33
+ "promise",
34
+ // ZodString
35
+ "email",
36
+ "url",
37
+ "uuid",
38
+ "cuid",
39
+ "cuid2",
40
+ "ulid",
41
+ "regex",
42
+ "startsWith",
43
+ "endsWith",
44
+ "trim",
45
+ "toLowerCase",
46
+ "toUpperCase",
47
+ "datetime",
48
+ "date",
49
+ "time",
50
+ "ip",
51
+ "cidr",
52
+ "base64",
53
+ "base64url",
54
+ "jwt",
55
+ "nanoid",
56
+ "emoji",
57
+ "includes",
58
+ "normalize",
59
+ // ZodString / ZodNumber / ZodArray — shared (`Set` dedupes)
60
+ "min",
61
+ "max",
62
+ "length",
63
+ "gt",
64
+ "gte",
65
+ "lt",
66
+ "lte",
67
+ // ZodNumber
68
+ "int",
69
+ "positive",
70
+ "negative",
71
+ "nonnegative",
72
+ "nonpositive",
73
+ "finite",
74
+ "safe",
75
+ "multipleOf",
76
+ "step",
77
+ // ZodObject
78
+ "extend",
79
+ "merge",
80
+ "pick",
81
+ "omit",
82
+ "partial",
83
+ "deepPartial",
84
+ "required",
85
+ "passthrough",
86
+ "strict",
87
+ "strip",
88
+ "catchall",
89
+ "keyof",
90
+ // ZodArray
91
+ "nonempty",
92
+ "element",
93
+ // ZodEnum
94
+ "extract",
95
+ "exclude"
96
+ ]);
97
+
98
+ // libs/lazy-zod/src/lazy-schema.ts
99
+ var LAZY_BRAND = /* @__PURE__ */ Symbol.for("@frontmcp/lazy-zod.LazyZodSchema");
100
+ var LAZY_TARGET = /* @__PURE__ */ Symbol.for("@frontmcp/lazy-zod.LazyZodSchema.target");
101
+ var HOT_PATH_METHODS = /* @__PURE__ */ new Set(["parse", "safeParse", "parseAsync", "safeParseAsync"]);
102
+ var LazyZodSchema = class {
103
+ constructor(_materialize) {
104
+ this._materialize = _materialize;
105
+ Object.defineProperty(this, LAZY_BRAND, {
106
+ value: true,
107
+ enumerable: false,
108
+ writable: false,
109
+ configurable: false
110
+ });
111
+ }
112
+ _resolved;
113
+ /** Materialize (and memoize) the underlying real zod schema. */
114
+ materialize() {
115
+ return this._resolved ?? (this._resolved = this._materialize());
116
+ }
117
+ /** True once the underlying schema has been constructed. */
118
+ get isMaterialized() {
119
+ return this._resolved !== void 0;
120
+ }
121
+ };
122
+ function wrapLazy(schema) {
123
+ const proxy = new Proxy(schema, {
124
+ get(target, key, _receiver) {
125
+ if (key === LAZY_BRAND) return true;
126
+ if (key === LAZY_TARGET) return target;
127
+ if (typeof key !== "symbol" && Object.prototype.hasOwnProperty.call(target, key)) {
128
+ return target[key];
129
+ }
130
+ if (typeof key === "string" && HOT_PATH_METHODS.has(key)) {
131
+ return (...args) => {
132
+ const real2 = target.materialize();
133
+ const bound = real2[key].bind(real2);
134
+ Object.defineProperty(target, key, {
135
+ value: bound,
136
+ writable: true,
137
+ configurable: true,
138
+ enumerable: false
139
+ });
140
+ return bound(...args);
141
+ };
142
+ }
143
+ if (typeof key === "string" && CHAIN_METHODS.has(key)) {
144
+ return (...args) => wrapLazy(
145
+ new LazyZodSchema(() => {
146
+ const real2 = target.materialize();
147
+ return real2[key](...args);
148
+ })
149
+ );
150
+ }
151
+ const real = target.materialize();
152
+ const val = real[key];
153
+ if (typeof val === "function") {
154
+ if (key === "constructor") return val;
155
+ const maybeCtor = val;
156
+ if (typeof maybeCtor.prototype === "object" && maybeCtor.prototype !== null && Object.getOwnPropertyNames(maybeCtor.prototype).length > 1) {
157
+ return val;
158
+ }
159
+ return val.bind(real);
160
+ }
161
+ return val;
162
+ },
163
+ has(target, key) {
164
+ if (key === LAZY_BRAND) return true;
165
+ if (typeof key === "string" && (HOT_PATH_METHODS.has(key) || CHAIN_METHODS.has(key))) {
166
+ return true;
167
+ }
168
+ return Reflect.has(target.materialize(), key);
169
+ },
170
+ getPrototypeOf(target) {
171
+ return Object.getPrototypeOf(target.materialize());
172
+ }
173
+ });
174
+ return proxy;
175
+ }
176
+ function lazyZ(factory) {
177
+ return wrapLazy(new LazyZodSchema(factory));
178
+ }
179
+
180
+ // libs/lazy-zod/src/lazy-z.ts
181
+ var lazyProxy = new Proxy(realZ, {
182
+ get(target, key, receiver) {
183
+ if (typeof key === "string" && HEAVY_FACTORIES.has(key)) {
184
+ const realFactory = target[key];
185
+ return (...args) => wrapLazy(new LazyZodSchema(() => realFactory.call(target, ...args)));
186
+ }
187
+ return Reflect.get(target, key, receiver);
188
+ }
189
+ });
190
+ var z = lazyProxy;
191
+
192
+ // libs/lazy-zod/src/eager-z.ts
193
+ import { z as z2 } from "zod";
194
+
195
+ // libs/lazy-zod/src/utils.ts
196
+ function isLazy(value) {
197
+ if (value === null || typeof value !== "object" && typeof value !== "function") return false;
198
+ return value[LAZY_BRAND] === true;
199
+ }
200
+ function forceMaterialize(schema) {
201
+ const seen = /* @__PURE__ */ new WeakSet();
202
+ return deepMaterialize(schema, seen);
203
+ }
204
+ function deepMaterialize(value, seen) {
205
+ if (value === null || typeof value !== "object" && typeof value !== "function") return value;
206
+ let resolved = value;
207
+ if (value[LAZY_BRAND] === true) {
208
+ const target = value[LAZY_TARGET];
209
+ resolved = target.materialize();
210
+ }
211
+ if (typeof resolved !== "object" && typeof resolved !== "function") return resolved;
212
+ if (resolved === null) return resolved;
213
+ if (seen.has(resolved)) return resolved;
214
+ seen.add(resolved);
215
+ const def = resolved._def;
216
+ if (def && typeof def === "object") {
217
+ const rawShape = def["shape"];
218
+ const shape = typeof rawShape === "function" ? rawShape.call(def) : rawShape;
219
+ if (shape && typeof shape === "object") {
220
+ for (const k of Object.keys(shape)) {
221
+ shape[k] = deepMaterialize(shape[k], seen);
222
+ }
223
+ }
224
+ const options = def["options"];
225
+ if (Array.isArray(options)) {
226
+ for (let i = 0; i < options.length; i++) options[i] = deepMaterialize(options[i], seen);
227
+ }
228
+ if ("innerType" in def) def["innerType"] = deepMaterialize(def["innerType"], seen);
229
+ if ("element" in def) def["element"] = deepMaterialize(def["element"], seen);
230
+ if ("valueType" in def) def["valueType"] = deepMaterialize(def["valueType"], seen);
231
+ if ("keyType" in def) def["keyType"] = deepMaterialize(def["keyType"], seen);
232
+ if ("left" in def) def["left"] = deepMaterialize(def["left"], seen);
233
+ if ("right" in def) def["right"] = deepMaterialize(def["right"], seen);
234
+ const items = def["items"];
235
+ if (Array.isArray(items)) {
236
+ for (let i = 0; i < items.length; i++) items[i] = deepMaterialize(items[i], seen);
237
+ }
238
+ }
239
+ return resolved;
240
+ }
241
+
242
+ // libs/lazy-zod/src/index.ts
243
+ import { toJSONSchema } from "zod";
244
+ import {
245
+ NEVER,
246
+ ZodAny,
247
+ ZodArray,
248
+ ZodBigInt,
249
+ ZodBoolean,
250
+ ZodDate,
251
+ ZodDefault,
252
+ ZodDiscriminatedUnion,
253
+ ZodEnum,
254
+ ZodError,
255
+ ZodIntersection,
256
+ ZodLiteral,
257
+ ZodNever,
258
+ ZodNull,
259
+ ZodNullable,
260
+ ZodNumber,
261
+ ZodObject,
262
+ ZodOptional,
263
+ ZodRecord,
264
+ ZodString,
265
+ ZodSymbol,
266
+ ZodTuple,
267
+ ZodType,
268
+ ZodUndefined,
269
+ ZodUnion,
270
+ ZodUnknown,
271
+ ZodVoid
272
+ } from "zod";
273
+ export {
274
+ LAZY_BRAND,
275
+ LAZY_TARGET,
276
+ LazyZodSchema,
277
+ NEVER,
278
+ ZodAny,
279
+ ZodArray,
280
+ ZodBigInt,
281
+ ZodBoolean,
282
+ ZodDate,
283
+ ZodDefault,
284
+ ZodDiscriminatedUnion,
285
+ ZodEnum,
286
+ ZodError,
287
+ ZodIntersection,
288
+ ZodLiteral,
289
+ ZodNever,
290
+ ZodNull,
291
+ ZodNullable,
292
+ ZodNumber,
293
+ ZodObject,
294
+ ZodOptional,
295
+ ZodRecord,
296
+ ZodString,
297
+ ZodSymbol,
298
+ ZodTuple,
299
+ ZodType,
300
+ ZodUndefined,
301
+ ZodUnion,
302
+ ZodUnknown,
303
+ ZodVoid,
304
+ z as default,
305
+ z2 as eagerZ,
306
+ forceMaterialize,
307
+ isLazy,
308
+ lazyZ,
309
+ toJSONSchema,
310
+ z
311
+ };
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@frontmcp/lazy-zod",
3
+ "version": "1.0.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
+ "author": "AgentFront <info@agentfront.dev>",
6
+ "license": "Apache-2.0",
7
+ "keywords": [
8
+ "zod",
9
+ "lazy",
10
+ "cold-start",
11
+ "performance",
12
+ "edge",
13
+ "bundler",
14
+ "validation",
15
+ "schema",
16
+ "typescript",
17
+ "frontmcp"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/agentfront/frontmcp.git",
22
+ "directory": "libs/lazy-zod"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/agentfront/frontmcp/issues"
26
+ },
27
+ "homepage": "https://github.com/agentfront/frontmcp/blob/main/libs/lazy-zod/README.md",
28
+ "type": "module",
29
+ "main": "../index.js",
30
+ "module": "./index.mjs",
31
+ "types": "../index.d.ts",
32
+ "sideEffects": false,
33
+ "exports": {
34
+ "./package.json": "../package.json",
35
+ ".": {
36
+ "require": {
37
+ "types": "../index.d.ts",
38
+ "default": "../index.js"
39
+ },
40
+ "import": {
41
+ "types": "../index.d.ts",
42
+ "default": "./index.mjs"
43
+ }
44
+ },
45
+ "./esm": null
46
+ },
47
+ "engines": {
48
+ "node": ">=24.0.0"
49
+ },
50
+ "peerDependencies": {
51
+ "zod": "^4.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^24.0.0",
55
+ "typescript": "^5.0.0",
56
+ "zod": "^4.0.0"
57
+ }
58
+ }
package/factories.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Classification of zod APIs for lazy-zod.
3
+ *
4
+ * HEAVY_FACTORIES: compound-schema factories whose construction dominates
5
+ * cold-start cost. Calls to these on the lazy `z` return a `LazyZodSchema`.
6
+ *
7
+ * CHAIN_METHODS: methods called on a zod schema that return another zod
8
+ * schema. When called on a lazy wrapper they produce a new lazy wrapper
9
+ * whose factory is `() => parent.materialize()[method](...args)`. The
10
+ * list is exhaustive for zod v4 to stay drop-in — any method not on the
11
+ * list forces materialization on first access.
12
+ */
13
+ export declare const HEAVY_FACTORIES: ReadonlySet<string>;
14
+ export declare const CHAIN_METHODS: ReadonlySet<string>;
package/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @frontmcp/lazy-zod — Drop-in zod replacement with lazy compound-schema
3
+ * construction.
4
+ *
5
+ * - `z`: lazy-by-default. Import anywhere you'd import zod's `z`.
6
+ * - `eagerZ`: straight real zod, zero proxy overhead.
7
+ * - `lazyZ(factory)`: explicit factory-style lazy wrapper.
8
+ * - `isLazy`, `forceMaterialize`: runtime escape hatches.
9
+ */
10
+ export { z } from './lazy-z';
11
+ export { z as default } from './lazy-z';
12
+ export { eagerZ } from './eager-z';
13
+ export { lazyZ, LazyZodSchema, LAZY_BRAND, LAZY_TARGET, type InferLazy } from './lazy-schema';
14
+ export { isLazy, forceMaterialize } from './utils';
15
+ export { toJSONSchema } from 'zod';
16
+ export type { JSONSchema } from 'zod/v4/core';
17
+ export { NEVER, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEnum, ZodError, ZodIntersection, ZodLiteral, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodRecord, ZodString, ZodSymbol, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, } from 'zod';
18
+ export type { ZodTypeAny, ZodRawShape, infer, input, output } from 'zod';
package/index.js ADDED
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // libs/lazy-zod/src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ LAZY_BRAND: () => LAZY_BRAND,
24
+ LAZY_TARGET: () => LAZY_TARGET,
25
+ LazyZodSchema: () => LazyZodSchema,
26
+ NEVER: () => import_zod4.NEVER,
27
+ ZodAny: () => import_zod4.ZodAny,
28
+ ZodArray: () => import_zod4.ZodArray,
29
+ ZodBigInt: () => import_zod4.ZodBigInt,
30
+ ZodBoolean: () => import_zod4.ZodBoolean,
31
+ ZodDate: () => import_zod4.ZodDate,
32
+ ZodDefault: () => import_zod4.ZodDefault,
33
+ ZodDiscriminatedUnion: () => import_zod4.ZodDiscriminatedUnion,
34
+ ZodEnum: () => import_zod4.ZodEnum,
35
+ ZodError: () => import_zod4.ZodError,
36
+ ZodIntersection: () => import_zod4.ZodIntersection,
37
+ ZodLiteral: () => import_zod4.ZodLiteral,
38
+ ZodNever: () => import_zod4.ZodNever,
39
+ ZodNull: () => import_zod4.ZodNull,
40
+ ZodNullable: () => import_zod4.ZodNullable,
41
+ ZodNumber: () => import_zod4.ZodNumber,
42
+ ZodObject: () => import_zod4.ZodObject,
43
+ ZodOptional: () => import_zod4.ZodOptional,
44
+ ZodRecord: () => import_zod4.ZodRecord,
45
+ ZodString: () => import_zod4.ZodString,
46
+ ZodSymbol: () => import_zod4.ZodSymbol,
47
+ ZodTuple: () => import_zod4.ZodTuple,
48
+ ZodType: () => import_zod4.ZodType,
49
+ ZodUndefined: () => import_zod4.ZodUndefined,
50
+ ZodUnion: () => import_zod4.ZodUnion,
51
+ ZodUnknown: () => import_zod4.ZodUnknown,
52
+ ZodVoid: () => import_zod4.ZodVoid,
53
+ default: () => z,
54
+ eagerZ: () => import_zod2.z,
55
+ forceMaterialize: () => forceMaterialize,
56
+ isLazy: () => isLazy,
57
+ lazyZ: () => lazyZ,
58
+ toJSONSchema: () => import_zod3.toJSONSchema,
59
+ z: () => z
60
+ });
61
+ module.exports = __toCommonJS(index_exports);
62
+
63
+ // libs/lazy-zod/src/lazy-z.ts
64
+ var import_zod = require("zod");
65
+
66
+ // libs/lazy-zod/src/factories.ts
67
+ var HEAVY_FACTORIES = /* @__PURE__ */ new Set([
68
+ "object",
69
+ "strictObject",
70
+ "looseObject",
71
+ "union",
72
+ "discriminatedUnion",
73
+ "intersection",
74
+ "record",
75
+ "tuple"
76
+ ]);
77
+ var CHAIN_METHODS = /* @__PURE__ */ new Set([
78
+ // ZodType generic
79
+ "optional",
80
+ "nullable",
81
+ "nullish",
82
+ "default",
83
+ "prefault",
84
+ "describe",
85
+ "refine",
86
+ "superRefine",
87
+ "transform",
88
+ "pipe",
89
+ "or",
90
+ "and",
91
+ "readonly",
92
+ "brand",
93
+ "catch",
94
+ "array",
95
+ "promise",
96
+ // ZodString
97
+ "email",
98
+ "url",
99
+ "uuid",
100
+ "cuid",
101
+ "cuid2",
102
+ "ulid",
103
+ "regex",
104
+ "startsWith",
105
+ "endsWith",
106
+ "trim",
107
+ "toLowerCase",
108
+ "toUpperCase",
109
+ "datetime",
110
+ "date",
111
+ "time",
112
+ "ip",
113
+ "cidr",
114
+ "base64",
115
+ "base64url",
116
+ "jwt",
117
+ "nanoid",
118
+ "emoji",
119
+ "includes",
120
+ "normalize",
121
+ // ZodString / ZodNumber / ZodArray — shared (`Set` dedupes)
122
+ "min",
123
+ "max",
124
+ "length",
125
+ "gt",
126
+ "gte",
127
+ "lt",
128
+ "lte",
129
+ // ZodNumber
130
+ "int",
131
+ "positive",
132
+ "negative",
133
+ "nonnegative",
134
+ "nonpositive",
135
+ "finite",
136
+ "safe",
137
+ "multipleOf",
138
+ "step",
139
+ // ZodObject
140
+ "extend",
141
+ "merge",
142
+ "pick",
143
+ "omit",
144
+ "partial",
145
+ "deepPartial",
146
+ "required",
147
+ "passthrough",
148
+ "strict",
149
+ "strip",
150
+ "catchall",
151
+ "keyof",
152
+ // ZodArray
153
+ "nonempty",
154
+ "element",
155
+ // ZodEnum
156
+ "extract",
157
+ "exclude"
158
+ ]);
159
+
160
+ // libs/lazy-zod/src/lazy-schema.ts
161
+ var LAZY_BRAND = /* @__PURE__ */ Symbol.for("@frontmcp/lazy-zod.LazyZodSchema");
162
+ var LAZY_TARGET = /* @__PURE__ */ Symbol.for("@frontmcp/lazy-zod.LazyZodSchema.target");
163
+ var HOT_PATH_METHODS = /* @__PURE__ */ new Set(["parse", "safeParse", "parseAsync", "safeParseAsync"]);
164
+ var LazyZodSchema = class {
165
+ constructor(_materialize) {
166
+ this._materialize = _materialize;
167
+ Object.defineProperty(this, LAZY_BRAND, {
168
+ value: true,
169
+ enumerable: false,
170
+ writable: false,
171
+ configurable: false
172
+ });
173
+ }
174
+ _resolved;
175
+ /** Materialize (and memoize) the underlying real zod schema. */
176
+ materialize() {
177
+ return this._resolved ?? (this._resolved = this._materialize());
178
+ }
179
+ /** True once the underlying schema has been constructed. */
180
+ get isMaterialized() {
181
+ return this._resolved !== void 0;
182
+ }
183
+ };
184
+ function wrapLazy(schema) {
185
+ const proxy = new Proxy(schema, {
186
+ get(target, key, _receiver) {
187
+ if (key === LAZY_BRAND) return true;
188
+ if (key === LAZY_TARGET) return target;
189
+ if (typeof key !== "symbol" && Object.prototype.hasOwnProperty.call(target, key)) {
190
+ return target[key];
191
+ }
192
+ if (typeof key === "string" && HOT_PATH_METHODS.has(key)) {
193
+ return (...args) => {
194
+ const real2 = target.materialize();
195
+ const bound = real2[key].bind(real2);
196
+ Object.defineProperty(target, key, {
197
+ value: bound,
198
+ writable: true,
199
+ configurable: true,
200
+ enumerable: false
201
+ });
202
+ return bound(...args);
203
+ };
204
+ }
205
+ if (typeof key === "string" && CHAIN_METHODS.has(key)) {
206
+ return (...args) => wrapLazy(
207
+ new LazyZodSchema(() => {
208
+ const real2 = target.materialize();
209
+ return real2[key](...args);
210
+ })
211
+ );
212
+ }
213
+ const real = target.materialize();
214
+ const val = real[key];
215
+ if (typeof val === "function") {
216
+ if (key === "constructor") return val;
217
+ const maybeCtor = val;
218
+ if (typeof maybeCtor.prototype === "object" && maybeCtor.prototype !== null && Object.getOwnPropertyNames(maybeCtor.prototype).length > 1) {
219
+ return val;
220
+ }
221
+ return val.bind(real);
222
+ }
223
+ return val;
224
+ },
225
+ has(target, key) {
226
+ if (key === LAZY_BRAND) return true;
227
+ if (typeof key === "string" && (HOT_PATH_METHODS.has(key) || CHAIN_METHODS.has(key))) {
228
+ return true;
229
+ }
230
+ return Reflect.has(target.materialize(), key);
231
+ },
232
+ getPrototypeOf(target) {
233
+ return Object.getPrototypeOf(target.materialize());
234
+ }
235
+ });
236
+ return proxy;
237
+ }
238
+ function lazyZ(factory) {
239
+ return wrapLazy(new LazyZodSchema(factory));
240
+ }
241
+
242
+ // libs/lazy-zod/src/lazy-z.ts
243
+ var lazyProxy = new Proxy(import_zod.z, {
244
+ get(target, key, receiver) {
245
+ if (typeof key === "string" && HEAVY_FACTORIES.has(key)) {
246
+ const realFactory = target[key];
247
+ return (...args) => wrapLazy(new LazyZodSchema(() => realFactory.call(target, ...args)));
248
+ }
249
+ return Reflect.get(target, key, receiver);
250
+ }
251
+ });
252
+ var z = lazyProxy;
253
+
254
+ // libs/lazy-zod/src/eager-z.ts
255
+ var import_zod2 = require("zod");
256
+
257
+ // libs/lazy-zod/src/utils.ts
258
+ function isLazy(value) {
259
+ if (value === null || typeof value !== "object" && typeof value !== "function") return false;
260
+ return value[LAZY_BRAND] === true;
261
+ }
262
+ function forceMaterialize(schema) {
263
+ const seen = /* @__PURE__ */ new WeakSet();
264
+ return deepMaterialize(schema, seen);
265
+ }
266
+ function deepMaterialize(value, seen) {
267
+ if (value === null || typeof value !== "object" && typeof value !== "function") return value;
268
+ let resolved = value;
269
+ if (value[LAZY_BRAND] === true) {
270
+ const target = value[LAZY_TARGET];
271
+ resolved = target.materialize();
272
+ }
273
+ if (typeof resolved !== "object" && typeof resolved !== "function") return resolved;
274
+ if (resolved === null) return resolved;
275
+ if (seen.has(resolved)) return resolved;
276
+ seen.add(resolved);
277
+ const def = resolved._def;
278
+ if (def && typeof def === "object") {
279
+ const rawShape = def["shape"];
280
+ const shape = typeof rawShape === "function" ? rawShape.call(def) : rawShape;
281
+ if (shape && typeof shape === "object") {
282
+ for (const k of Object.keys(shape)) {
283
+ shape[k] = deepMaterialize(shape[k], seen);
284
+ }
285
+ }
286
+ const options = def["options"];
287
+ if (Array.isArray(options)) {
288
+ for (let i = 0; i < options.length; i++) options[i] = deepMaterialize(options[i], seen);
289
+ }
290
+ if ("innerType" in def) def["innerType"] = deepMaterialize(def["innerType"], seen);
291
+ if ("element" in def) def["element"] = deepMaterialize(def["element"], seen);
292
+ if ("valueType" in def) def["valueType"] = deepMaterialize(def["valueType"], seen);
293
+ if ("keyType" in def) def["keyType"] = deepMaterialize(def["keyType"], seen);
294
+ if ("left" in def) def["left"] = deepMaterialize(def["left"], seen);
295
+ if ("right" in def) def["right"] = deepMaterialize(def["right"], seen);
296
+ const items = def["items"];
297
+ if (Array.isArray(items)) {
298
+ for (let i = 0; i < items.length; i++) items[i] = deepMaterialize(items[i], seen);
299
+ }
300
+ }
301
+ return resolved;
302
+ }
303
+
304
+ // libs/lazy-zod/src/index.ts
305
+ var import_zod3 = require("zod");
306
+ var import_zod4 = require("zod");
307
+ // Annotate the CommonJS export names for ESM import in node:
308
+ 0 && (module.exports = {
309
+ LAZY_BRAND,
310
+ LAZY_TARGET,
311
+ LazyZodSchema,
312
+ NEVER,
313
+ ZodAny,
314
+ ZodArray,
315
+ ZodBigInt,
316
+ ZodBoolean,
317
+ ZodDate,
318
+ ZodDefault,
319
+ ZodDiscriminatedUnion,
320
+ ZodEnum,
321
+ ZodError,
322
+ ZodIntersection,
323
+ ZodLiteral,
324
+ ZodNever,
325
+ ZodNull,
326
+ ZodNullable,
327
+ ZodNumber,
328
+ ZodObject,
329
+ ZodOptional,
330
+ ZodRecord,
331
+ ZodString,
332
+ ZodSymbol,
333
+ ZodTuple,
334
+ ZodType,
335
+ ZodUndefined,
336
+ ZodUnion,
337
+ ZodUnknown,
338
+ ZodVoid,
339
+ eagerZ,
340
+ forceMaterialize,
341
+ isLazy,
342
+ lazyZ,
343
+ toJSONSchema,
344
+ z
345
+ });
@@ -0,0 +1,51 @@
1
+ import type { infer as zInfer, ZodTypeAny } from 'zod';
2
+ /**
3
+ * Branded symbol that identifies lazy schemas at runtime.
4
+ * `isLazy(x)` checks for this; the Proxy's `get` trap reports it as `true`.
5
+ */
6
+ export declare const LAZY_BRAND: unique symbol;
7
+ /**
8
+ * Escape-hatch symbol. Accessing `proxy[LAZY_TARGET]` on a lazy schema
9
+ * returns the underlying `LazyZodSchema` instance (bypassing the Proxy).
10
+ * Used by `forceMaterialize` and in tests to assert on the real target.
11
+ */
12
+ export declare const LAZY_TARGET: unique symbol;
13
+ /**
14
+ * Holds a memoized factory that builds a real zod schema on first call.
15
+ * The Proxy in `wrapLazy` is what makes instances of this class behave
16
+ * like the schema they eventually materialize to.
17
+ */
18
+ export declare class LazyZodSchema {
19
+ private readonly _materialize;
20
+ private _resolved;
21
+ constructor(_materialize: () => ZodTypeAny);
22
+ /** Materialize (and memoize) the underlying real zod schema. */
23
+ materialize(): ZodTypeAny;
24
+ /** True once the underlying schema has been constructed. */
25
+ get isMaterialized(): boolean;
26
+ }
27
+ /**
28
+ * Wrap a `LazyZodSchema` in a Proxy that presents the full zod API surface:
29
+ * - `.parse / .safeParse / .parseAsync / .safeParseAsync` materialize,
30
+ * bind, and self-patch the bound method onto the underlying instance
31
+ * so subsequent calls skip all Proxy logic (validated at +0.2% overhead
32
+ * by the POC).
33
+ * - Methods in `CHAIN_METHODS` capture into a new child `LazyZodSchema`
34
+ * whose factory is `() => parent.materialize()[method](...args)`.
35
+ * - Everything else (`.shape`, `._def`, `isOptional()`, etc.) materializes
36
+ * and forwards. Functions are bound to the materialized schema.
37
+ * - `getPrototypeOf` forwards to the materialized schema so `instanceof`
38
+ * works (materializes on first check).
39
+ */
40
+ export declare function wrapLazy(schema: LazyZodSchema): unknown;
41
+ /**
42
+ * Explicit factory-style lazy wrapper. Given a function that returns a
43
+ * real zod schema, returns a drop-in replacement whose construction is
44
+ * deferred until first `.parse()`.
45
+ */
46
+ export declare function lazyZ<T extends ZodTypeAny>(factory: () => T): T;
47
+ /**
48
+ * Type helper mirroring `z.infer` for `lazyZ`-wrapped schemas.
49
+ * Useful when the factory's return type is carried explicitly.
50
+ */
51
+ export type InferLazy<L> = L extends ZodTypeAny ? zInfer<L> : never;
package/lazy-z.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { z as realZ } from 'zod';
2
+ export declare const z: typeof realZ;
3
+ export declare namespace z {
4
+ type infer<T> = realZ.infer<T>;
5
+ type output<T> = realZ.output<T>;
6
+ type input<T> = realZ.input<T>;
7
+ type ZodType<Output = unknown, Input = unknown> = realZ.ZodType<Output, Input>;
8
+ type ZodTypeAny = realZ.ZodTypeAny;
9
+ type ZodRawShape = realZ.ZodRawShape;
10
+ type ZodObject<T extends realZ.ZodRawShape = realZ.ZodRawShape> = realZ.ZodObject<T>;
11
+ type ZodArray<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = realZ.ZodArray<T>;
12
+ type ZodUnion<T extends readonly realZ.ZodTypeAny[] = readonly realZ.ZodTypeAny[]> = realZ.ZodUnion<T>;
13
+ type ZodDiscriminatedUnion<O = any, D = any> = realZ.ZodDiscriminatedUnion<O extends readonly realZ.core.SomeType[] ? O : never, D extends string ? D : never>;
14
+ type ZodIntersection<L extends realZ.ZodTypeAny = realZ.ZodTypeAny, R extends realZ.ZodTypeAny = realZ.ZodTypeAny> = realZ.ZodIntersection<L, R>;
15
+ type ZodTuple<T extends readonly realZ.ZodTypeAny[] = readonly realZ.ZodTypeAny[]> = realZ.ZodTuple<T>;
16
+ type ZodRecord<K = any, V = any> = realZ.ZodRecord<K extends realZ.core.$ZodRecordKey ? K : never, V extends realZ.core.SomeType ? V : never>;
17
+ type ZodString = realZ.ZodString;
18
+ type ZodNumber = realZ.ZodNumber;
19
+ type ZodBoolean = realZ.ZodBoolean;
20
+ type ZodBigInt = realZ.ZodBigInt;
21
+ type ZodDate = realZ.ZodDate;
22
+ type ZodSymbol = realZ.ZodSymbol;
23
+ type ZodEnum<T = any> = realZ.ZodEnum<T extends Readonly<Record<string, realZ.core.util.EnumValue>> ? T : never>;
24
+ type ZodLiteral<T = any> = realZ.ZodLiteral<T extends realZ.core.util.Literal ? T : never>;
25
+ type ZodNull = realZ.ZodNull;
26
+ type ZodUndefined = realZ.ZodUndefined;
27
+ type ZodVoid = realZ.ZodVoid;
28
+ type ZodAny = realZ.ZodAny;
29
+ type ZodUnknown = realZ.ZodUnknown;
30
+ type ZodNever = realZ.ZodNever;
31
+ type ZodOptional<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = realZ.ZodOptional<T>;
32
+ type ZodNullable<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = realZ.ZodNullable<T>;
33
+ type ZodDefault<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = realZ.ZodDefault<T>;
34
+ type ZodError = realZ.ZodError;
35
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@frontmcp/lazy-zod",
3
+ "version": "0.0.1",
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
+ "author": "AgentFront <info@agentfront.dev>",
6
+ "license": "Apache-2.0",
7
+ "keywords": [
8
+ "zod",
9
+ "lazy",
10
+ "cold-start",
11
+ "performance",
12
+ "edge",
13
+ "bundler",
14
+ "validation",
15
+ "schema",
16
+ "typescript",
17
+ "frontmcp"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/agentfront/frontmcp.git",
22
+ "directory": "libs/lazy-zod"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/agentfront/frontmcp/issues"
26
+ },
27
+ "homepage": "https://github.com/agentfront/frontmcp/blob/main/libs/lazy-zod/README.md",
28
+ "type": "commonjs",
29
+ "main": "./index.js",
30
+ "module": "./esm/index.mjs",
31
+ "types": "./index.d.ts",
32
+ "sideEffects": false,
33
+ "exports": {
34
+ "./package.json": "./package.json",
35
+ ".": {
36
+ "require": {
37
+ "types": "./index.d.ts",
38
+ "default": "./index.js"
39
+ },
40
+ "import": {
41
+ "types": "./index.d.ts",
42
+ "default": "./esm/index.mjs"
43
+ }
44
+ },
45
+ "./esm": null
46
+ },
47
+ "engines": {
48
+ "node": ">=24.0.0"
49
+ },
50
+ "peerDependencies": {
51
+ "zod": "^4.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^24.0.0",
55
+ "typescript": "^5.0.0",
56
+ "zod": "^4.0.0"
57
+ }
58
+ }
package/utils.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ /**
3
+ * Runtime check: returns true if the given value is a lazy-zod schema
4
+ * (either from the `z` Proxy or from `lazyZ(...)`).
5
+ */
6
+ export declare function isLazy(value: unknown): boolean;
7
+ /**
8
+ * Materialize a lazy schema and return the underlying real zod schema,
9
+ * recursively materializing any lazy wrappers found in the schema tree
10
+ * (object shapes, array elements, union options, etc.).
11
+ *
12
+ * Required before handing a schema to third-party code that walks zod's
13
+ * internal `_def` properties and mutates them — `toJSONSchema`'s
14
+ * processors write to `_def` nodes during traversal, and a lazy Proxy
15
+ * in any nested position breaks those writes with
16
+ * "TypeError: Cannot set properties of undefined".
17
+ *
18
+ * If `schema` is not lazy at the top level, the tree is still walked in
19
+ * place so that nested lazy wrappers get resolved too.
20
+ */
21
+ export declare function forceMaterialize<T extends ZodTypeAny>(schema: T): T;