@frontmcp/lazy-zod 1.10.16 → 1.11.0-rc.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/README.md +11 -10
- package/esm/index.mjs +1 -1
- package/esm/package.json +1 -1
- package/factories.d.ts +2 -0
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/internal-z.d.ts +37 -0
- package/lazy-schema.d.ts +6 -16
- package/lazy-z.d.ts +4 -2
- package/memoizer.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,16 +39,17 @@ const Deferred = lazyZ(() => eagerZ.object({ id: eagerZ.string() }));
|
|
|
39
39
|
|
|
40
40
|
A stand-in behaves like the schema it stands for: it parses the same, `instanceof ZodObject` is `true`, and `z.infer` gives the same type.
|
|
41
41
|
|
|
42
|
-
| Export | What it is
|
|
43
|
-
| ----------------------------- |
|
|
44
|
-
| `z` (also the default export) | Zod 4's `z`, with the factories above deferred.
|
|
45
|
-
| `eagerZ` | Zod's own `z`. Use it for a schema that something reads as soon as it's defined.
|
|
46
|
-
| `lazyZ(build)` | A schema that calls `build()` the first time it's used, and only then.
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
42
|
+
| Export | What it is |
|
|
43
|
+
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `z` (also the default export) | Zod 4's `z`, with the factories above deferred. |
|
|
45
|
+
| `eagerZ` | Zod's own `z`. Use it for a schema that something reads as soon as it's defined. |
|
|
46
|
+
| `lazyZ(build)` | A schema that calls `build()` the first time it's used, and only then. |
|
|
47
|
+
| `internalZ` | What FrontMCP's own packages build their schemas with. Every factory, leaves included, returns a stand-in, and a stand-in builds its leaf children with it. Zod's cycle check isn't attached to them, so a recursive schema is built with `z`. It isn't part of the public API and can change in any release: use `z`. |
|
|
48
|
+
| `isLazy(schema)` | `true` for a stand-in, from `z` or from `lazyZ()`. |
|
|
49
|
+
| `forceMaterialize(schema)` | The real Zod schema, with every stand-in inside it built. |
|
|
50
|
+
| `hasTransform(schema)` | `true` when the schema runs a transform anywhere in its tree (`.transform()`, `z.preprocess()`, `.pipe()`, a codec), so what it parses to can differ in shape from its input. |
|
|
51
|
+
| `toJSONSchema(schema)` | Zod's JSON Schema converter, run on `forceMaterialize(schema)`. Use it instead of Zod's own `z.toJSONSchema()`, which throws `TypeError: Cannot set properties of undefined (setting 'ref')` when an object or union in the schema is `.optional()` or has a `.default()`. |
|
|
52
|
+
| `ZodObject`, `ZodError`, … | Zod's classes and types (`ZodTypeAny`, `infer`, `input`, `output`), so your code needs no import from `zod`. |
|
|
52
53
|
|
|
53
54
|
## Performance
|
|
54
55
|
|
package/esm/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toJSONSchema as zodToJSONSchema}from"zod";var HEAVY_FACTORIES=new Set(["object","strictObject","looseObject","union","discriminatedUnion","intersection","record","tuple"]);var CHAIN_METHODS=new Set(["optional","nullable","nullish","default","prefault","describe","refine","superRefine","transform","pipe","or","and","readonly","brand","catch","array","promise","email","url","uuid","cuid","cuid2","ulid","regex","startsWith","endsWith","trim","toLowerCase","toUpperCase","datetime","date","time","ip","cidr","base64","base64url","jwt","nanoid","emoji","includes","normalize","min","max","length","gt","gte","lt","lte","int","positive","negative","nonnegative","nonpositive","finite","safe","multipleOf","step","extend","merge","pick","omit","partial","deepPartial","required","passthrough","strict","strip","catchall","keyof","nonempty","element","extract","exclude"]);var LAZY_BRAND=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema");var LAZY_TARGET=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema.target");var HOT_PATH_METHODS=new Set(["parse","safeParse","parseAsync","safeParseAsync"]);var LazyZodSchema=class{constructor(_materialize){this._materialize=_materialize;Object.defineProperty(this,LAZY_BRAND,{value:true,enumerable:false,writable:false,configurable:false})}_materialize;_resolved;materialize(){return this._resolved??(this._resolved=this._materialize())}get isMaterialized(){return this._resolved!==void 0}};function wrapLazy(schema){const proxy=new Proxy(schema,{get(target,key,_receiver){if(key===LAZY_BRAND)return true;if(key===LAZY_TARGET)return target;if(typeof key!=="symbol"&&Object.prototype.hasOwnProperty.call(target,key)){return target[key]}if(typeof key==="string"&&HOT_PATH_METHODS.has(key)){return(...args)=>{const real2=target.materialize();const bound=real2[key].bind(real2);Object.defineProperty(target,key,{value:bound,writable:true,configurable:true,enumerable:false});return bound(...args)}}if(typeof key==="string"&&CHAIN_METHODS.has(key)){return(...args)=>wrapLazy(new LazyZodSchema(()=>{const real2=target.materialize();return real2[key](...args)}))}const real=target.materialize();const val=real[key];if(typeof val==="function"){if(key==="constructor")return val;const maybeCtor=val;if(typeof maybeCtor.prototype==="object"&&maybeCtor.prototype!==null&&Object.getOwnPropertyNames(maybeCtor.prototype).length>1){return val}return val.bind(real)}return val},has(target,key){if(key===LAZY_BRAND)return true;if(typeof key==="string"&&(HOT_PATH_METHODS.has(key)||CHAIN_METHODS.has(key))){return true}return Reflect.has(target.materialize(),key)},getPrototypeOf(target){return Object.getPrototypeOf(target.materialize())}});return proxy}function lazyZ(factory){return wrapLazy(new LazyZodSchema(factory))}function isLazy(value){if(value===null||typeof value!=="object"&&typeof value!=="function")return false;return value[LAZY_BRAND]===true}function hasTransform(schema){return containsPipe(schema,new WeakSet)}function containsPipe(value,seen){const def=value?._zod?.def;if(!def||seen.has(def))return false;seen.add(def);if(def["type"]==="pipe")return true;if(def["type"]==="lazy")return containsPipe(def["getter"](),seen);return Object.values(def).some(child=>nestedSchemas(child).some(nested=>containsPipe(nested,seen)))}function nestedSchemas(field){if(Array.isArray(field))return field;const isShape=field!==null&&typeof field==="object"&&field._zod===void 0;if(isShape)return Object.values(field);return[field]}function forceMaterialize(schema){const seen=new WeakSet;return deepMaterialize(schema,seen)}function deepMaterialize(value,seen){if(value===null||typeof value!=="object"&&typeof value!=="function")return value;let resolved=value;if(value[LAZY_BRAND]===true){const target=value[LAZY_TARGET];resolved=target.materialize()}if(typeof resolved!=="object"&&typeof resolved!=="function")return resolved;if(resolved===null)return resolved;if(seen.has(resolved))return resolved;seen.add(resolved);const def=resolved._def;if(def&&typeof def==="object"){const rawShape=def["shape"];const shape=typeof rawShape==="function"?rawShape.call(def):rawShape;if(shape&&typeof shape==="object"){for(const k of Object.keys(shape)){shape[k]=deepMaterialize(shape[k],seen)}}const options=def["options"];if(Array.isArray(options)){for(let i=0;i<options.length;i++)options[i]=deepMaterialize(options[i],seen)}if("innerType"in def)def["innerType"]=deepMaterialize(def["innerType"],seen);if("element"in def)def["element"]=deepMaterialize(def["element"],seen);if("valueType"in def)def["valueType"]=deepMaterialize(def["valueType"],seen);if("keyType"in def)def["keyType"]=deepMaterialize(def["keyType"],seen);if("left"in def)def["left"]=deepMaterialize(def["left"],seen);if("right"in def)def["right"]=deepMaterialize(def["right"],seen);const items=def["items"];if(Array.isArray(items)){for(let i=0;i<items.length;i++)items[i]=deepMaterialize(items[i],seen)}}return resolved}import{z as realZ}from"zod";function createLazyZ(namespace){return new Proxy({},{get(_target,key,receiver){if(typeof key==="string"&&HEAVY_FACTORIES.has(key)){const realFactory=namespace[key];return(...args)=>wrapLazy(new LazyZodSchema(()=>realFactory.call(namespace,...args)))}return Reflect.get(namespace,key,receiver)},set:(_target,key,value)=>Reflect.set(namespace,key,value),has:(_target,key)=>Reflect.has(namespace,key),ownKeys:()=>Reflect.ownKeys(namespace),getOwnPropertyDescriptor(_target,key){const desc=Reflect.getOwnPropertyDescriptor(namespace,key);return desc?{...desc,configurable:true}:void 0},getPrototypeOf:()=>Reflect.getPrototypeOf(namespace)})}var z=createLazyZ(realZ);import{z as z2}from"zod";import{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";var toJSONSchema=((schema,params)=>zodToJSONSchema(forceMaterialize(schema),params));export{LAZY_BRAND,LAZY_TARGET,LazyZodSchema,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,z as default,z2 as eagerZ,forceMaterialize,hasTransform,isLazy,lazyZ,toJSONSchema,z};
|
|
1
|
+
import{toJSONSchema as zodToJSONSchema}from"zod";var HEAVY_FACTORIES=new Set(["object","strictObject","looseObject","union","discriminatedUnion","intersection","record","tuple"]);var LEAF_FACTORIES=new Set(["string","number","int","boolean","bigint","symbol","date","undefined","null","void","any","unknown","never","nan","literal","enum","nativeEnum","url","email","uuid","array","set","map","partialRecord","optional","nullable","lazy","function","custom","instanceof","preprocess"]);var CHAIN_METHODS=new Set(["optional","nullable","nullish","default","prefault","describe","refine","superRefine","transform","pipe","or","and","readonly","brand","catch","array","promise","email","url","uuid","cuid","cuid2","ulid","regex","startsWith","endsWith","trim","toLowerCase","toUpperCase","datetime","date","time","ip","cidr","base64","base64url","jwt","nanoid","emoji","includes","normalize","min","max","length","gt","gte","lt","lte","int","positive","negative","nonnegative","nonpositive","finite","safe","multipleOf","step","extend","merge","pick","omit","partial","deepPartial","required","passthrough","strict","strip","catchall","keyof","nonempty","element","extract","exclude"]);import{z as realZ}from"zod";var WALKLESS=Symbol.for("@frontmcp/lazy-zod.walklessMemoizer");var zodConfig=realZ.config();var defaultMemoizer=realZ.memoizer;var walklessMemoizers=new WeakMap;function isWalkless(memoizer){return memoizer?.[WALKLESS]===true}function buildWith(memoizer,build){const saved=zodConfig.memoizer;zodConfig.memoizer=memoizer;try{return build()}finally{zodConfig.memoizer=saved}}function withoutRecursionWalk(build){const memoizer=zodConfig.memoizer??defaultMemoizer?.();if(!memoizer||isWalkless(memoizer))return build();let walkless=walklessMemoizers.get(memoizer);if(!walkless){walkless=Object.create(memoizer,{attach:{value:()=>void 0},[WALKLESS]:{value:true}});walklessMemoizers.set(memoizer,walkless)}return buildWith(walkless,build)}function withRecursionWalk(build){const memoizer=zodConfig.memoizer;return isWalkless(memoizer)?buildWith(Object.getPrototypeOf(memoizer),build):build()}var LAZY_BRAND=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema");var LAZY_TARGET=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema.target");var HOT_PATH_METHODS=new Set(["parse","safeParse","parseAsync","safeParseAsync"]);var LazyZodSchema=class _LazyZodSchema{_resolved;_materialize;constructor(materialize){this._materialize=materialize;Object.defineProperty(this,LAZY_BRAND,{value:true,enumerable:false,writable:false,configurable:false})}materialize(){const factory=this._materialize;if(factory){this._resolved=this.build(factory);this._materialize=void 0}return this._resolved}build(factory){return withRecursionWalk(factory)}get isMaterialized(){return this._resolved!==void 0}chain(method,args){return wrapLazy(new _LazyZodSchema(()=>{const real=this.materialize();return real[method](...args)}))}};var lazyHandler={get(target,key,_receiver){if(key===LAZY_BRAND)return true;if(key===LAZY_TARGET)return target;if(typeof key!=="symbol"&&Object.prototype.hasOwnProperty.call(target,key)){return target[key]}if(typeof key==="string"&&HOT_PATH_METHODS.has(key)){return(...args)=>{const real2=target.materialize();const bound=real2[key].bind(real2);Object.defineProperty(target,key,{value:bound,writable:true,configurable:true,enumerable:false});return bound(...args)}}if(typeof key==="string"&&CHAIN_METHODS.has(key)){return(...args)=>target.chain(key,args)}const real=target.materialize();const val=real[key];if(typeof val==="function"){if(key==="constructor")return val;const maybeCtor=val;if(typeof maybeCtor.prototype==="object"&&maybeCtor.prototype!==null&&Object.getOwnPropertyNames(maybeCtor.prototype).length>1){return val}return val.bind(real)}return val},has(target,key){if(key===LAZY_BRAND)return true;if(typeof key==="string"&&(HOT_PATH_METHODS.has(key)||CHAIN_METHODS.has(key))){return true}return Reflect.has(target.materialize(),key)},getPrototypeOf(target){return Object.getPrototypeOf(target.materialize())}};function wrapLazy(schema){return new Proxy(schema,lazyHandler)}function lazyZ(factory){return wrapLazy(new LazyZodSchema(factory))}function isLazy(value){if(value===null||typeof value!=="object"&&typeof value!=="function")return false;return value[LAZY_BRAND]===true}function hasTransform(schema){return containsPipe(schema,new WeakSet)}function containsPipe(value,seen){const def=value?._zod?.def;if(!def||seen.has(def))return false;seen.add(def);if(def["type"]==="pipe")return true;if(def["type"]==="lazy")return containsPipe(def["getter"](),seen);return Object.values(def).some(child=>nestedSchemas(child).some(nested=>containsPipe(nested,seen)))}function nestedSchemas(field){if(Array.isArray(field))return field;const isShape2=field!==null&&typeof field==="object"&&field._zod===void 0;if(isShape2)return Object.values(field);return[field]}var CHILD_KEYS=["innerType","element","valueType","keyType","left","right","catchall","rest","in","out"];function forceMaterialize(schema){const seen=new WeakSet;return deepMaterialize(schema,seen)}function deepMaterialize(value,seen){if(value===null||typeof value!=="object"&&typeof value!=="function")return value;let resolved=value;if(value[LAZY_BRAND]===true){const target=value[LAZY_TARGET];resolved=target.materialize()}if(typeof resolved!=="object"&&typeof resolved!=="function")return resolved;if(resolved===null)return resolved;if(seen.has(resolved))return resolved;seen.add(resolved);const def=resolved._def;if(def&&typeof def==="object"){const rawShape=def["shape"];const shape=typeof rawShape==="function"?rawShape.call(def):rawShape;if(shape&&typeof shape==="object"){for(const k of Object.keys(shape)){shape[k]=deepMaterialize(shape[k],seen)}}const options=def["options"];if(Array.isArray(options)){for(let i=0;i<options.length;i++)options[i]=deepMaterialize(options[i],seen)}for(const key of CHILD_KEYS){if(key in def)Reflect.set(def,key,deepMaterialize(def[key],seen))}const items=def["items"];if(Array.isArray(items)){for(let i=0;i<items.length;i++)items[i]=deepMaterialize(items[i],seen)}}return resolved}import{z as realZ2}from"zod";var compoundStandIn=(_name,args,factory,namespace)=>wrapLazy(new LazyZodSchema(()=>factory.apply(namespace,args)));function createLazyZ(namespace,factories=HEAVY_FACTORIES,standIn=compoundStandIn){return new Proxy({},{get(_target,key,receiver){if(typeof key==="string"&&factories.has(key)){const realFactory=namespace[key];return(...args)=>standIn(key,args,realFactory,namespace)}return Reflect.get(namespace,key,receiver)},set:(_target,key,value)=>Reflect.set(namespace,key,value),has:(_target,key)=>Reflect.has(namespace,key),ownKeys:()=>Reflect.ownKeys(namespace),getOwnPropertyDescriptor(_target,key){const desc=Reflect.getOwnPropertyDescriptor(namespace,key);return desc?{...desc,configurable:true}:void 0},getPrototypeOf:()=>Reflect.getPrototypeOf(namespace)})}var z=createLazyZ(realZ2);import{z as z2}from"zod";import{z as realZ3}from"zod";var BUILT_WITH_PARENT=Symbol("builtWithParent");var NO_ARGS=Object.freeze([]);var InternalLazySchema=class _InternalLazySchema extends LazyZodSchema{[BUILT_WITH_PARENT];args;constructor(args,builtWithParent){super(_InternalLazySchema.buildOnce);this.args=args;this[BUILT_WITH_PARENT]=builtWithParent}static buildOnce(){const built=this.buildWith(this.args);this.args=NO_ARGS;return built}build(factory){return withoutRecursionWalk(()=>factory.call(this))}chain(method,args){return wrapLazy(new ChainedStandIn(this,method,args,this[BUILT_WITH_PARENT]&&args.every(holdsOnlyLeaves)))}};var FactoryStandIn=class extends InternalLazySchema{constructor(factory,namespace,args,builtWithParent){super(args,builtWithParent);this.factory=factory;this.namespace=namespace}factory;namespace;buildWith(args){return this.factory.apply(this.namespace,args.map(withBuiltChildren))}};var ChainedStandIn=class extends InternalLazySchema{constructor(parent,method,args,builtWithParent){super(args,builtWithParent);this.method=method;this.parent=parent}method;parent;buildWith(args){const real=this.parent.materialize();const built=real[this.method](...args.map(withBuiltChildren));this.parent=void 0;return built}};function targetOf(value){return isLazy(value)?value[LAZY_TARGET]:void 0}function isLeaf(value){const target=targetOf(value);return target===void 0||target instanceof InternalLazySchema&&target[BUILT_WITH_PARENT]}function builtChild(value){const target=targetOf(value);return target&&(target.isMaterialized||isLeaf(value))?target.materialize():value}function isShape(value){if(value===null||typeof value!=="object"||isLazy(value)||Array.isArray(value))return false;const prototype=Object.getPrototypeOf(value);if(prototype!==Object.prototype&&prototype!==null)return false;return Object.values(Object.getOwnPropertyDescriptors(value)).every(descriptor=>"value"in descriptor)}function childrenOf(arg){if(Array.isArray(arg))return arg;if(isShape(arg))return Reflect.ownKeys(arg).map(key=>arg[key]);return[arg]}function holdsOnlyLeaves(arg){return childrenOf(arg).every(isLeaf)}function withBuiltChildren(arg){if(Array.isArray(arg)){const built=arg.map(builtChild);return built.some((child,index)=>child!==arg[index])?built:arg}if(!isShape(arg))return builtChild(arg);const descriptors=Object.getOwnPropertyDescriptors(arg);let changed=false;for(const key of Reflect.ownKeys(descriptors)){const built=builtChild(descriptors[key].value);if(built!==descriptors[key].value){descriptors[key]={...descriptors[key],value:built};changed=true}}return changed?Object.create(Object.getPrototypeOf(arg),descriptors):arg}var deferEveryFactory=(name,args,factory,namespace)=>wrapLazy(new FactoryStandIn(factory,namespace,args,LEAF_FACTORIES.has(name)&&args.every(holdsOnlyLeaves)));var internalZ=createLazyZ(realZ3,new Set([...HEAVY_FACTORIES,...LEAF_FACTORIES]),deferEveryFactory);import{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";var toJSONSchema=((schema,params)=>zodToJSONSchema(forceMaterialize(schema),params));export{LAZY_BRAND,LAZY_TARGET,LazyZodSchema,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,z as default,z2 as eagerZ,forceMaterialize,hasTransform,internalZ,isLazy,lazyZ,toJSONSchema,z};
|
package/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/lazy-zod",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0-rc.1",
|
|
4
4
|
"description": "Zod 4's z with compound schemas built on first use, for faster start-up. Exports z (lazy), eagerZ (Zod's own) and lazyZ",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"license": "Apache-2.0",
|
package/factories.d.ts
CHANGED
|
@@ -11,4 +11,6 @@
|
|
|
11
11
|
* list forces materialization on first access.
|
|
12
12
|
*/
|
|
13
13
|
export declare const HEAVY_FACTORIES: ReadonlySet<string>;
|
|
14
|
+
/** The other schema factories, which `internalZ` defers too. The public `z` leaves them as Zod's own. */
|
|
15
|
+
export declare const LEAF_FACTORIES: ReadonlySet<string>;
|
|
14
16
|
export declare const CHAIN_METHODS: ReadonlySet<string>;
|
package/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { toJSONSchema as zodToJSONSchema } from 'zod';
|
|
|
11
11
|
export { z } from './lazy-z';
|
|
12
12
|
export { z as default } from './lazy-z';
|
|
13
13
|
export { eagerZ } from './eager-z';
|
|
14
|
+
export { internalZ } from './internal-z';
|
|
14
15
|
export { lazyZ, LazyZodSchema, LAZY_BRAND, LAZY_TARGET, type InferLazy } from './lazy-schema';
|
|
15
16
|
export { isLazy, forceMaterialize, hasTransform } from './utils';
|
|
16
17
|
export declare const toJSONSchema: typeof zodToJSONSchema;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var index_exports={};__export(index_exports,{LAZY_BRAND:()=>LAZY_BRAND,LAZY_TARGET:()=>LAZY_TARGET,LazyZodSchema:()=>LazyZodSchema,NEVER:()=>import_zod4.NEVER,ZodAny:()=>import_zod4.ZodAny,ZodArray:()=>import_zod4.ZodArray,ZodBigInt:()=>import_zod4.ZodBigInt,ZodBoolean:()=>import_zod4.ZodBoolean,ZodDate:()=>import_zod4.ZodDate,ZodDefault:()=>import_zod4.ZodDefault,ZodDiscriminatedUnion:()=>import_zod4.ZodDiscriminatedUnion,ZodEnum:()=>import_zod4.ZodEnum,ZodError:()=>import_zod4.ZodError,ZodIntersection:()=>import_zod4.ZodIntersection,ZodLiteral:()=>import_zod4.ZodLiteral,ZodNever:()=>import_zod4.ZodNever,ZodNull:()=>import_zod4.ZodNull,ZodNullable:()=>import_zod4.ZodNullable,ZodNumber:()=>import_zod4.ZodNumber,ZodObject:()=>import_zod4.ZodObject,ZodOptional:()=>import_zod4.ZodOptional,ZodRecord:()=>import_zod4.ZodRecord,ZodString:()=>import_zod4.ZodString,ZodSymbol:()=>import_zod4.ZodSymbol,ZodTuple:()=>import_zod4.ZodTuple,ZodType:()=>import_zod4.ZodType,ZodUndefined:()=>import_zod4.ZodUndefined,ZodUnion:()=>import_zod4.ZodUnion,ZodUnknown:()=>import_zod4.ZodUnknown,ZodVoid:()=>import_zod4.ZodVoid,default:()=>z,eagerZ:()=>import_zod2.z,forceMaterialize:()=>forceMaterialize,hasTransform:()=>hasTransform,isLazy:()=>isLazy,lazyZ:()=>lazyZ,toJSONSchema:()=>toJSONSchema,z:()=>z});module.exports=__toCommonJS(index_exports);var import_zod3=require("zod");var HEAVY_FACTORIES=new Set(["object","strictObject","looseObject","union","discriminatedUnion","intersection","record","tuple"]);var CHAIN_METHODS=new Set(["optional","nullable","nullish","default","prefault","describe","refine","superRefine","transform","pipe","or","and","readonly","brand","catch","array","promise","email","url","uuid","cuid","cuid2","ulid","regex","startsWith","endsWith","trim","toLowerCase","toUpperCase","datetime","date","time","ip","cidr","base64","base64url","jwt","nanoid","emoji","includes","normalize","min","max","length","gt","gte","lt","lte","int","positive","negative","nonnegative","nonpositive","finite","safe","multipleOf","step","extend","merge","pick","omit","partial","deepPartial","required","passthrough","strict","strip","catchall","keyof","nonempty","element","extract","exclude"]);var LAZY_BRAND=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema");var LAZY_TARGET=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema.target");var HOT_PATH_METHODS=new Set(["parse","safeParse","parseAsync","safeParseAsync"]);var LazyZodSchema=class{constructor(_materialize){this._materialize=_materialize;Object.defineProperty(this,LAZY_BRAND,{value:true,enumerable:false,writable:false,configurable:false})}_materialize;_resolved;materialize(){return this._resolved??(this._resolved=this._materialize())}get isMaterialized(){return this._resolved!==void 0}};function wrapLazy(schema){const proxy=new Proxy(schema,{get(target,key,_receiver){if(key===LAZY_BRAND)return true;if(key===LAZY_TARGET)return target;if(typeof key!=="symbol"&&Object.prototype.hasOwnProperty.call(target,key)){return target[key]}if(typeof key==="string"&&HOT_PATH_METHODS.has(key)){return(...args)=>{const real2=target.materialize();const bound=real2[key].bind(real2);Object.defineProperty(target,key,{value:bound,writable:true,configurable:true,enumerable:false});return bound(...args)}}if(typeof key==="string"&&CHAIN_METHODS.has(key)){return(...args)=>wrapLazy(new LazyZodSchema(()=>{const real2=target.materialize();return real2[key](...args)}))}const real=target.materialize();const val=real[key];if(typeof val==="function"){if(key==="constructor")return val;const maybeCtor=val;if(typeof maybeCtor.prototype==="object"&&maybeCtor.prototype!==null&&Object.getOwnPropertyNames(maybeCtor.prototype).length>1){return val}return val.bind(real)}return val},has(target,key){if(key===LAZY_BRAND)return true;if(typeof key==="string"&&(HOT_PATH_METHODS.has(key)||CHAIN_METHODS.has(key))){return true}return Reflect.has(target.materialize(),key)},getPrototypeOf(target){return Object.getPrototypeOf(target.materialize())}});return proxy}function lazyZ(factory){return wrapLazy(new LazyZodSchema(factory))}function isLazy(value){if(value===null||typeof value!=="object"&&typeof value!=="function")return false;return value[LAZY_BRAND]===true}function hasTransform(schema){return containsPipe(schema,new WeakSet)}function containsPipe(value,seen){const def=value?._zod?.def;if(!def||seen.has(def))return false;seen.add(def);if(def["type"]==="pipe")return true;if(def["type"]==="lazy")return containsPipe(def["getter"](),seen);return Object.values(def).some(child=>nestedSchemas(child).some(nested=>containsPipe(nested,seen)))}function nestedSchemas(field){if(Array.isArray(field))return field;const isShape=field!==null&&typeof field==="object"&&field._zod===void 0;if(isShape)return Object.values(field);return[field]}function forceMaterialize(schema){const seen=new WeakSet;return deepMaterialize(schema,seen)}function deepMaterialize(value,seen){if(value===null||typeof value!=="object"&&typeof value!=="function")return value;let resolved=value;if(value[LAZY_BRAND]===true){const target=value[LAZY_TARGET];resolved=target.materialize()}if(typeof resolved!=="object"&&typeof resolved!=="function")return resolved;if(resolved===null)return resolved;if(seen.has(resolved))return resolved;seen.add(resolved);const def=resolved._def;if(def&&typeof def==="object"){const rawShape=def["shape"];const shape=typeof rawShape==="function"?rawShape.call(def):rawShape;if(shape&&typeof shape==="object"){for(const k of Object.keys(shape)){shape[k]=deepMaterialize(shape[k],seen)}}const options=def["options"];if(Array.isArray(options)){for(let i=0;i<options.length;i++)options[i]=deepMaterialize(options[i],seen)}if("innerType"in def)def["innerType"]=deepMaterialize(def["innerType"],seen);if("element"in def)def["element"]=deepMaterialize(def["element"],seen);if("valueType"in def)def["valueType"]=deepMaterialize(def["valueType"],seen);if("keyType"in def)def["keyType"]=deepMaterialize(def["keyType"],seen);if("left"in def)def["left"]=deepMaterialize(def["left"],seen);if("right"in def)def["right"]=deepMaterialize(def["right"],seen);const items=def["items"];if(Array.isArray(items)){for(let i=0;i<items.length;i++)items[i]=deepMaterialize(items[i],seen)}}return resolved}var import_zod=require("zod");function createLazyZ(namespace){return new Proxy({},{get(_target,key,receiver){if(typeof key==="string"&&HEAVY_FACTORIES.has(key)){const realFactory=namespace[key];return(...args)=>wrapLazy(new LazyZodSchema(()=>realFactory.call(namespace,...args)))}return Reflect.get(namespace,key,receiver)},set:(_target,key,value)=>Reflect.set(namespace,key,value),has:(_target,key)=>Reflect.has(namespace,key),ownKeys:()=>Reflect.ownKeys(namespace),getOwnPropertyDescriptor(_target,key){const desc=Reflect.getOwnPropertyDescriptor(namespace,key);return desc?{...desc,configurable:true}:void 0},getPrototypeOf:()=>Reflect.getPrototypeOf(namespace)})}var z=createLazyZ(import_zod.z);var import_zod2=require("zod");var import_zod4=require("zod");var toJSONSchema=((schema,params)=>(0,import_zod3.toJSONSchema)(forceMaterialize(schema),params));0&&(module.exports={LAZY_BRAND,LAZY_TARGET,LazyZodSchema,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,eagerZ,forceMaterialize,hasTransform,isLazy,lazyZ,toJSONSchema,z});
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var index_exports={};__export(index_exports,{LAZY_BRAND:()=>LAZY_BRAND,LAZY_TARGET:()=>LAZY_TARGET,LazyZodSchema:()=>LazyZodSchema,NEVER:()=>import_zod6.NEVER,ZodAny:()=>import_zod6.ZodAny,ZodArray:()=>import_zod6.ZodArray,ZodBigInt:()=>import_zod6.ZodBigInt,ZodBoolean:()=>import_zod6.ZodBoolean,ZodDate:()=>import_zod6.ZodDate,ZodDefault:()=>import_zod6.ZodDefault,ZodDiscriminatedUnion:()=>import_zod6.ZodDiscriminatedUnion,ZodEnum:()=>import_zod6.ZodEnum,ZodError:()=>import_zod6.ZodError,ZodIntersection:()=>import_zod6.ZodIntersection,ZodLiteral:()=>import_zod6.ZodLiteral,ZodNever:()=>import_zod6.ZodNever,ZodNull:()=>import_zod6.ZodNull,ZodNullable:()=>import_zod6.ZodNullable,ZodNumber:()=>import_zod6.ZodNumber,ZodObject:()=>import_zod6.ZodObject,ZodOptional:()=>import_zod6.ZodOptional,ZodRecord:()=>import_zod6.ZodRecord,ZodString:()=>import_zod6.ZodString,ZodSymbol:()=>import_zod6.ZodSymbol,ZodTuple:()=>import_zod6.ZodTuple,ZodType:()=>import_zod6.ZodType,ZodUndefined:()=>import_zod6.ZodUndefined,ZodUnion:()=>import_zod6.ZodUnion,ZodUnknown:()=>import_zod6.ZodUnknown,ZodVoid:()=>import_zod6.ZodVoid,default:()=>z,eagerZ:()=>import_zod3.z,forceMaterialize:()=>forceMaterialize,hasTransform:()=>hasTransform,internalZ:()=>internalZ,isLazy:()=>isLazy,lazyZ:()=>lazyZ,toJSONSchema:()=>toJSONSchema,z:()=>z});module.exports=__toCommonJS(index_exports);var import_zod5=require("zod");var HEAVY_FACTORIES=new Set(["object","strictObject","looseObject","union","discriminatedUnion","intersection","record","tuple"]);var LEAF_FACTORIES=new Set(["string","number","int","boolean","bigint","symbol","date","undefined","null","void","any","unknown","never","nan","literal","enum","nativeEnum","url","email","uuid","array","set","map","partialRecord","optional","nullable","lazy","function","custom","instanceof","preprocess"]);var CHAIN_METHODS=new Set(["optional","nullable","nullish","default","prefault","describe","refine","superRefine","transform","pipe","or","and","readonly","brand","catch","array","promise","email","url","uuid","cuid","cuid2","ulid","regex","startsWith","endsWith","trim","toLowerCase","toUpperCase","datetime","date","time","ip","cidr","base64","base64url","jwt","nanoid","emoji","includes","normalize","min","max","length","gt","gte","lt","lte","int","positive","negative","nonnegative","nonpositive","finite","safe","multipleOf","step","extend","merge","pick","omit","partial","deepPartial","required","passthrough","strict","strip","catchall","keyof","nonempty","element","extract","exclude"]);var import_zod=require("zod");var WALKLESS=Symbol.for("@frontmcp/lazy-zod.walklessMemoizer");var zodConfig=import_zod.z.config();var defaultMemoizer=import_zod.z.memoizer;var walklessMemoizers=new WeakMap;function isWalkless(memoizer){return memoizer?.[WALKLESS]===true}function buildWith(memoizer,build){const saved=zodConfig.memoizer;zodConfig.memoizer=memoizer;try{return build()}finally{zodConfig.memoizer=saved}}function withoutRecursionWalk(build){const memoizer=zodConfig.memoizer??defaultMemoizer?.();if(!memoizer||isWalkless(memoizer))return build();let walkless=walklessMemoizers.get(memoizer);if(!walkless){walkless=Object.create(memoizer,{attach:{value:()=>void 0},[WALKLESS]:{value:true}});walklessMemoizers.set(memoizer,walkless)}return buildWith(walkless,build)}function withRecursionWalk(build){const memoizer=zodConfig.memoizer;return isWalkless(memoizer)?buildWith(Object.getPrototypeOf(memoizer),build):build()}var LAZY_BRAND=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema");var LAZY_TARGET=Symbol.for("@frontmcp/lazy-zod.LazyZodSchema.target");var HOT_PATH_METHODS=new Set(["parse","safeParse","parseAsync","safeParseAsync"]);var LazyZodSchema=class _LazyZodSchema{_resolved;_materialize;constructor(materialize){this._materialize=materialize;Object.defineProperty(this,LAZY_BRAND,{value:true,enumerable:false,writable:false,configurable:false})}materialize(){const factory=this._materialize;if(factory){this._resolved=this.build(factory);this._materialize=void 0}return this._resolved}build(factory){return withRecursionWalk(factory)}get isMaterialized(){return this._resolved!==void 0}chain(method,args){return wrapLazy(new _LazyZodSchema(()=>{const real=this.materialize();return real[method](...args)}))}};var lazyHandler={get(target,key,_receiver){if(key===LAZY_BRAND)return true;if(key===LAZY_TARGET)return target;if(typeof key!=="symbol"&&Object.prototype.hasOwnProperty.call(target,key)){return target[key]}if(typeof key==="string"&&HOT_PATH_METHODS.has(key)){return(...args)=>{const real2=target.materialize();const bound=real2[key].bind(real2);Object.defineProperty(target,key,{value:bound,writable:true,configurable:true,enumerable:false});return bound(...args)}}if(typeof key==="string"&&CHAIN_METHODS.has(key)){return(...args)=>target.chain(key,args)}const real=target.materialize();const val=real[key];if(typeof val==="function"){if(key==="constructor")return val;const maybeCtor=val;if(typeof maybeCtor.prototype==="object"&&maybeCtor.prototype!==null&&Object.getOwnPropertyNames(maybeCtor.prototype).length>1){return val}return val.bind(real)}return val},has(target,key){if(key===LAZY_BRAND)return true;if(typeof key==="string"&&(HOT_PATH_METHODS.has(key)||CHAIN_METHODS.has(key))){return true}return Reflect.has(target.materialize(),key)},getPrototypeOf(target){return Object.getPrototypeOf(target.materialize())}};function wrapLazy(schema){return new Proxy(schema,lazyHandler)}function lazyZ(factory){return wrapLazy(new LazyZodSchema(factory))}function isLazy(value){if(value===null||typeof value!=="object"&&typeof value!=="function")return false;return value[LAZY_BRAND]===true}function hasTransform(schema){return containsPipe(schema,new WeakSet)}function containsPipe(value,seen){const def=value?._zod?.def;if(!def||seen.has(def))return false;seen.add(def);if(def["type"]==="pipe")return true;if(def["type"]==="lazy")return containsPipe(def["getter"](),seen);return Object.values(def).some(child=>nestedSchemas(child).some(nested=>containsPipe(nested,seen)))}function nestedSchemas(field){if(Array.isArray(field))return field;const isShape2=field!==null&&typeof field==="object"&&field._zod===void 0;if(isShape2)return Object.values(field);return[field]}var CHILD_KEYS=["innerType","element","valueType","keyType","left","right","catchall","rest","in","out"];function forceMaterialize(schema){const seen=new WeakSet;return deepMaterialize(schema,seen)}function deepMaterialize(value,seen){if(value===null||typeof value!=="object"&&typeof value!=="function")return value;let resolved=value;if(value[LAZY_BRAND]===true){const target=value[LAZY_TARGET];resolved=target.materialize()}if(typeof resolved!=="object"&&typeof resolved!=="function")return resolved;if(resolved===null)return resolved;if(seen.has(resolved))return resolved;seen.add(resolved);const def=resolved._def;if(def&&typeof def==="object"){const rawShape=def["shape"];const shape=typeof rawShape==="function"?rawShape.call(def):rawShape;if(shape&&typeof shape==="object"){for(const k of Object.keys(shape)){shape[k]=deepMaterialize(shape[k],seen)}}const options=def["options"];if(Array.isArray(options)){for(let i=0;i<options.length;i++)options[i]=deepMaterialize(options[i],seen)}for(const key of CHILD_KEYS){if(key in def)Reflect.set(def,key,deepMaterialize(def[key],seen))}const items=def["items"];if(Array.isArray(items)){for(let i=0;i<items.length;i++)items[i]=deepMaterialize(items[i],seen)}}return resolved}var import_zod2=require("zod");var compoundStandIn=(_name,args,factory,namespace)=>wrapLazy(new LazyZodSchema(()=>factory.apply(namespace,args)));function createLazyZ(namespace,factories=HEAVY_FACTORIES,standIn=compoundStandIn){return new Proxy({},{get(_target,key,receiver){if(typeof key==="string"&&factories.has(key)){const realFactory=namespace[key];return(...args)=>standIn(key,args,realFactory,namespace)}return Reflect.get(namespace,key,receiver)},set:(_target,key,value)=>Reflect.set(namespace,key,value),has:(_target,key)=>Reflect.has(namespace,key),ownKeys:()=>Reflect.ownKeys(namespace),getOwnPropertyDescriptor(_target,key){const desc=Reflect.getOwnPropertyDescriptor(namespace,key);return desc?{...desc,configurable:true}:void 0},getPrototypeOf:()=>Reflect.getPrototypeOf(namespace)})}var z=createLazyZ(import_zod2.z);var import_zod3=require("zod");var import_zod4=require("zod");var BUILT_WITH_PARENT=Symbol("builtWithParent");var NO_ARGS=Object.freeze([]);var InternalLazySchema=class _InternalLazySchema extends LazyZodSchema{[BUILT_WITH_PARENT];args;constructor(args,builtWithParent){super(_InternalLazySchema.buildOnce);this.args=args;this[BUILT_WITH_PARENT]=builtWithParent}static buildOnce(){const built=this.buildWith(this.args);this.args=NO_ARGS;return built}build(factory){return withoutRecursionWalk(()=>factory.call(this))}chain(method,args){return wrapLazy(new ChainedStandIn(this,method,args,this[BUILT_WITH_PARENT]&&args.every(holdsOnlyLeaves)))}};var FactoryStandIn=class extends InternalLazySchema{constructor(factory,namespace,args,builtWithParent){super(args,builtWithParent);this.factory=factory;this.namespace=namespace}factory;namespace;buildWith(args){return this.factory.apply(this.namespace,args.map(withBuiltChildren))}};var ChainedStandIn=class extends InternalLazySchema{constructor(parent,method,args,builtWithParent){super(args,builtWithParent);this.method=method;this.parent=parent}method;parent;buildWith(args){const real=this.parent.materialize();const built=real[this.method](...args.map(withBuiltChildren));this.parent=void 0;return built}};function targetOf(value){return isLazy(value)?value[LAZY_TARGET]:void 0}function isLeaf(value){const target=targetOf(value);return target===void 0||target instanceof InternalLazySchema&&target[BUILT_WITH_PARENT]}function builtChild(value){const target=targetOf(value);return target&&(target.isMaterialized||isLeaf(value))?target.materialize():value}function isShape(value){if(value===null||typeof value!=="object"||isLazy(value)||Array.isArray(value))return false;const prototype=Object.getPrototypeOf(value);if(prototype!==Object.prototype&&prototype!==null)return false;return Object.values(Object.getOwnPropertyDescriptors(value)).every(descriptor=>"value"in descriptor)}function childrenOf(arg){if(Array.isArray(arg))return arg;if(isShape(arg))return Reflect.ownKeys(arg).map(key=>arg[key]);return[arg]}function holdsOnlyLeaves(arg){return childrenOf(arg).every(isLeaf)}function withBuiltChildren(arg){if(Array.isArray(arg)){const built=arg.map(builtChild);return built.some((child,index)=>child!==arg[index])?built:arg}if(!isShape(arg))return builtChild(arg);const descriptors=Object.getOwnPropertyDescriptors(arg);let changed=false;for(const key of Reflect.ownKeys(descriptors)){const built=builtChild(descriptors[key].value);if(built!==descriptors[key].value){descriptors[key]={...descriptors[key],value:built};changed=true}}return changed?Object.create(Object.getPrototypeOf(arg),descriptors):arg}var deferEveryFactory=(name,args,factory,namespace)=>wrapLazy(new FactoryStandIn(factory,namespace,args,LEAF_FACTORIES.has(name)&&args.every(holdsOnlyLeaves)));var internalZ=createLazyZ(import_zod4.z,new Set([...HEAVY_FACTORIES,...LEAF_FACTORIES]),deferEveryFactory);var import_zod6=require("zod");var toJSONSchema=((schema,params)=>(0,import_zod5.toJSONSchema)(forceMaterialize(schema),params));0&&(module.exports={LAZY_BRAND,LAZY_TARGET,LazyZodSchema,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,eagerZ,forceMaterialize,hasTransform,internalZ,isLazy,lazyZ,toJSONSchema,z});
|
package/internal-z.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z as realZ } from 'zod';
|
|
2
|
+
import { type z } from './lazy-z';
|
|
3
|
+
/** FrontMCP's own `z`: every factory returns a stand-in that builds its leaf children with it. Not public API. */
|
|
4
|
+
export declare const internalZ: typeof realZ;
|
|
5
|
+
export declare namespace internalZ {
|
|
6
|
+
type infer<T> = z.infer<T>;
|
|
7
|
+
type output<T> = z.output<T>;
|
|
8
|
+
type input<T> = z.input<T>;
|
|
9
|
+
type ZodType<Output = unknown, Input = unknown> = z.ZodType<Output, Input>;
|
|
10
|
+
type ZodTypeAny = z.ZodTypeAny;
|
|
11
|
+
type ZodRawShape = z.ZodRawShape;
|
|
12
|
+
type ZodObject<T extends realZ.ZodRawShape = realZ.ZodRawShape> = z.ZodObject<T>;
|
|
13
|
+
type ZodArray<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = z.ZodArray<T>;
|
|
14
|
+
type ZodUnion<T extends readonly realZ.ZodTypeAny[] = readonly realZ.ZodTypeAny[]> = z.ZodUnion<T>;
|
|
15
|
+
type ZodDiscriminatedUnion<O = any, D = any> = z.ZodDiscriminatedUnion<O, D>;
|
|
16
|
+
type ZodIntersection<L extends realZ.ZodTypeAny = realZ.ZodTypeAny, R extends realZ.ZodTypeAny = realZ.ZodTypeAny> = z.ZodIntersection<L, R>;
|
|
17
|
+
type ZodTuple<T extends readonly realZ.ZodTypeAny[] = readonly realZ.ZodTypeAny[]> = z.ZodTuple<T>;
|
|
18
|
+
type ZodRecord<K = any, V = any> = z.ZodRecord<K, V>;
|
|
19
|
+
type ZodString = z.ZodString;
|
|
20
|
+
type ZodNumber = z.ZodNumber;
|
|
21
|
+
type ZodBoolean = z.ZodBoolean;
|
|
22
|
+
type ZodBigInt = z.ZodBigInt;
|
|
23
|
+
type ZodDate = z.ZodDate;
|
|
24
|
+
type ZodSymbol = z.ZodSymbol;
|
|
25
|
+
type ZodEnum<T = any> = z.ZodEnum<T>;
|
|
26
|
+
type ZodLiteral<T = any> = z.ZodLiteral<T>;
|
|
27
|
+
type ZodNull = z.ZodNull;
|
|
28
|
+
type ZodUndefined = z.ZodUndefined;
|
|
29
|
+
type ZodVoid = z.ZodVoid;
|
|
30
|
+
type ZodAny = z.ZodAny;
|
|
31
|
+
type ZodUnknown = z.ZodUnknown;
|
|
32
|
+
type ZodNever = z.ZodNever;
|
|
33
|
+
type ZodOptional<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = z.ZodOptional<T>;
|
|
34
|
+
type ZodNullable<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = z.ZodNullable<T>;
|
|
35
|
+
type ZodDefault<T extends realZ.ZodTypeAny = realZ.ZodTypeAny> = z.ZodDefault<T>;
|
|
36
|
+
type ZodError = z.ZodError;
|
|
37
|
+
}
|
package/lazy-schema.d.ts
CHANGED
|
@@ -16,27 +16,17 @@ export declare const LAZY_TARGET: unique symbol;
|
|
|
16
16
|
* like the schema they eventually materialize to.
|
|
17
17
|
*/
|
|
18
18
|
export declare class LazyZodSchema {
|
|
19
|
-
private readonly _materialize;
|
|
20
19
|
private _resolved;
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
private _materialize;
|
|
21
|
+
constructor(materialize: () => ZodTypeAny);
|
|
22
|
+
/** Materialize (and memoize) the underlying real zod schema, then drop the factory and what it captured. */
|
|
23
23
|
materialize(): ZodTypeAny;
|
|
24
|
+
protected build(factory: () => ZodTypeAny): ZodTypeAny;
|
|
24
25
|
/** True once the underlying schema has been constructed. */
|
|
25
26
|
get isMaterialized(): boolean;
|
|
27
|
+
/** The stand-in for `materialize()[method](...args)`. */
|
|
28
|
+
chain(method: string, args: unknown[]): unknown;
|
|
26
29
|
}
|
|
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
30
|
export declare function wrapLazy(schema: LazyZodSchema): unknown;
|
|
41
31
|
/**
|
|
42
32
|
* Explicit factory-style lazy wrapper. Given a function that returns a
|
package/lazy-z.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z as realZ } from 'zod';
|
|
1
|
+
import { z as realZ, type ZodTypeAny } from 'zod';
|
|
2
2
|
/**
|
|
3
3
|
* Build the lazy `z` Proxy over a zod namespace object.
|
|
4
4
|
*
|
|
@@ -15,7 +15,9 @@ import { z as realZ } from 'zod';
|
|
|
15
15
|
* target owns nothing, so no invariant applies; every trap forwards to
|
|
16
16
|
* `namespace` instead. Exported for tests — the public entry point is `z`.
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export type SchemaFactory = (...args: unknown[]) => ZodTypeAny;
|
|
19
|
+
export type StandInFactory = (name: string, args: unknown[], factory: SchemaFactory, namespace: object) => unknown;
|
|
20
|
+
export declare function createLazyZ(namespace: typeof realZ, factories?: ReadonlySet<string>, standIn?: StandInFactory): typeof realZ;
|
|
19
21
|
/**
|
|
20
22
|
* Lazy-by-default `z`. Proxy over real zod's `z`:
|
|
21
23
|
* - Heavy compound factories (`object`, `union`, `discriminatedUnion`,
|
package/memoizer.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Zod's memoizer walks a container's whole subtree on its first parse, which would build every stand-in in it. */
|
|
2
|
+
export declare function withoutRecursionWalk<T>(build: () => T): T;
|
|
3
|
+
/** Builds a schema that isn't FrontMCP's own, even inside a FrontMCP build, with Zod's memoizer and its cycle check. */
|
|
4
|
+
export declare function withRecursionWalk<T>(build: () => T): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/lazy-zod",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0-rc.1",
|
|
4
4
|
"description": "Zod 4's z with compound schemas built on first use, for faster start-up. Exports z (lazy), eagerZ (Zod's own) and lazyZ",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"license": "Apache-2.0",
|