diff --git a/.buildkite/scripts/steps/security/third_party_packages.txt b/.buildkite/scripts/steps/security/third_party_packages.txt index 13670d53bb0db..4f975e2b0cbc9 100644 --- a/.buildkite/scripts/steps/security/third_party_packages.txt +++ b/.buildkite/scripts/steps/security/third_party_packages.txt @@ -44,3 +44,4 @@ tar-fs browserslist react-day-picker jszip +patch-package diff --git a/package.json b/package.json index 6681913e4a128..efd5f357c1d23 100644 --- a/package.json +++ b/package.json @@ -2127,6 +2127,7 @@ "oboe": "2.1.7", "openapi-types": "12.1.3", "oxlint": "1.56.0", + "patch-package": "8.0.1", "peggy": "4.2.0", "picomatch": "4.0.4", "pirates": "4.0.7", diff --git a/patches/zod+4.3.6.patch b/patches/zod+4.3.6.patch new file mode 100644 index 0000000000000..8ea51e91d9e35 --- /dev/null +++ b/patches/zod+4.3.6.patch @@ -0,0 +1,2388 @@ +diff --git a/node_modules/zod/v4/classic/schemas.cjs b/node_modules/zod/v4/classic/schemas.cjs +index e928299..3e3489c 100644 +--- a/node_modules/zod/v4/classic/schemas.cjs ++++ b/node_modules/zod/v4/classic/schemas.cjs +@@ -126,6 +126,455 @@ const to_json_schema_js_1 = require("../core/to-json-schema.cjs"); + const checks = __importStar(require("./checks.cjs")); + const iso = __importStar(require("./iso.cjs")); + const parse = __importStar(require("./parse.cjs")); ++// Maps (internalProto, key) pairs already initialized — avoids repeated prototype setup ++const _protoInitMap = new WeakMap(); ++/** ++ * Sets shared methods on the *internal* prototype layer of inst's concrete constructor ++ * (once per concrete type per key). The internal prototype sits one level below the ++ * user-visible `_.prototype`, keeping `Object.keys(_.prototype)` empty by default ++ * and preventing V8 dictionary-mode degradation. ++ * ++ * Falls back to `Object.getPrototypeOf(inst)` for constructors not created with ++ * `$constructor` (e.g., in tests or third-party code). ++ */ ++function _initProto(inst, key, methods, defineProps) { ++ const proto = inst._zod?.constr?.[core.$internalProto] ?? Object.getPrototypeOf(inst); ++ let keys = _protoInitMap.get(proto); ++ if (!keys) { ++ keys = new Set(); ++ _protoInitMap.set(proto, keys); ++ } ++ if (keys.has(key)) ++ return; ++ keys.add(key); ++ Object.assign(proto, methods); ++ if (defineProps) { ++ for (const [k, desc] of defineProps) { ++ Object.defineProperty(proto, k, { ...desc, configurable: true }); ++ } ++ } ++} ++// ───────────────────────────────────────────────────────────────────────────── ++// Shared method references (memory optimization) ++// ++// Zod v4 originally assigned every schema method as a per-instance arrow ++// function closure, capturing `inst`. With many schemas this causes significant ++// heap pressure (~50 extra function objects per schema instance). Instead, we ++// define each method once as a named function that uses `this` for context. ++// All instances then share the same function objects while retaining the same ++// own-property API surface and full runtime correctness. ++// ++// The return-type casts (`as any`) are required because TypeScript cannot ++// statically verify that a shared `this: ZodType` matches the polymorphic ++// `this` in the interface declaration. The declared interface types remain ++// authoritative; these casts are implementation-only. ++// ───────────────────────────────────────────────────────────────────────────── ++// ZodType – base methods ++function _sharedCheck(...chks) { ++ const def = this.def; ++ return this.clone(index_js_1.util.mergeDefs(def, { ++ checks: [ ++ ...(def.checks ?? []), ++ ...chks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), ++ ], ++ }), { parent: true }); ++} ++function _sharedClone(def, params) { ++ return core.clone(this, def, params); ++} ++function _sharedBrand() { ++ return this; ++} ++function _sharedRegister(reg, meta) { ++ reg.add(this, meta); ++ return this; ++} ++// NOTE: parse/safeParse/parseAsync/safeParseAsync/encode/decode (and their variants) ++// are intentionally kept as per-instance closures in the ZodType initializer below. ++// These methods are commonly called in a detached manner (e.g. `arr.map(schema.parse)` ++// or `const p = schema.parse; p(v)`), so they must capture `inst` rather than rely ++// on `this` binding. ++function _sharedRefine(check, params) { ++ return this.check(refine(check, params)); ++} ++function _sharedSuperRefine(refinement) { ++ return this.check(superRefine(refinement)); ++} ++function _sharedOverwrite(fn) { ++ return this.check(checks.overwrite(fn)); ++} ++function _sharedOptional() { ++ return optional(this); ++} ++function _sharedExactOptional() { ++ return exactOptional(this); ++} ++function _sharedNullable() { ++ return nullable(this); ++} ++function _sharedNullish() { ++ return optional(nullable(this)); ++} ++function _sharedNonoptional(params) { ++ return nonoptional(this, params); ++} ++function _sharedArray() { ++ return array(this); ++} ++function _sharedOr(arg) { ++ return union([this, arg]); ++} ++function _sharedAnd(arg) { ++ return intersection(this, arg); ++} ++function _sharedTransform(tx) { ++ return pipe(this, transform(tx)); ++} ++function _sharedDefault(d) { ++ return _default(this, d); ++} ++function _sharedPrefault(d) { ++ return prefault(this, d); ++} ++function _sharedCatch(params) { ++ return _catch(this, params); ++} ++function _sharedPipe(target) { ++ return pipe(this, target); ++} ++function _sharedReadonly() { ++ return readonly(this); ++} ++function _sharedDescribe(description) { ++ const cl = this.clone(); ++ core.globalRegistry.add(cl, { description }); ++ return cl; ++} ++function _sharedMeta(...args) { ++ if (args.length === 0) ++ return core.globalRegistry.get(this); ++ const cl = this.clone(); ++ core.globalRegistry.add(cl, args[0]); ++ return cl; ++} ++function _sharedIsOptional() { ++ return this.safeParse(undefined).success; ++} ++function _sharedIsNullable() { ++ return this.safeParse(null).success; ++} ++function _sharedApply(fn) { ++ return fn(this); ++} ++// _ZodString – string validation methods ++function _sharedRegex(...args) { ++ return this.check(checks.regex(...args)); ++} ++function _sharedIncludes(...args) { ++ return this.check(checks.includes(...args)); ++} ++function _sharedStartsWith(...args) { ++ return this.check(checks.startsWith(...args)); ++} ++function _sharedEndsWith(...args) { ++ return this.check(checks.endsWith(...args)); ++} ++function _sharedStrMin(...args) { ++ return this.check(checks.minLength(...args)); ++} ++function _sharedStrMax(...args) { ++ return this.check(checks.maxLength(...args)); ++} ++function _sharedStrLength(...args) { ++ return this.check(checks.length(...args)); ++} ++function _sharedStrNonempty(...args) { ++ return this.check(checks.minLength(1, ...args)); ++} ++function _sharedLowercase(params) { ++ return this.check(checks.lowercase(params)); ++} ++function _sharedUppercase(params) { ++ return this.check(checks.uppercase(params)); ++} ++function _sharedTrim() { ++ return this.check(checks.trim()); ++} ++function _sharedNormalize(...args) { ++ return this.check(checks.normalize(...args)); ++} ++function _sharedToLowerCase() { ++ return this.check(checks.toLowerCase()); ++} ++function _sharedToUpperCase() { ++ return this.check(checks.toUpperCase()); ++} ++function _sharedSlugify() { ++ return this.check(checks.slugify()); ++} ++// ZodString – format methods ++function _sharedEmail(params) { ++ return this.check(core._email(exports.ZodEmail, params)); ++} ++function _sharedUrl(params) { ++ return this.check(core._url(exports.ZodURL, params)); ++} ++function _sharedJwt(params) { ++ return this.check(core._jwt(exports.ZodJWT, params)); ++} ++function _sharedEmoji(params) { ++ return this.check(core._emoji(exports.ZodEmoji, params)); ++} ++function _sharedGuid(params) { ++ return this.check(core._guid(exports.ZodGUID, params)); ++} ++function _sharedUuid(params) { ++ return this.check(core._uuid(exports.ZodUUID, params)); ++} ++function _sharedUuidv4(params) { ++ return this.check(core._uuidv4(exports.ZodUUID, params)); ++} ++function _sharedUuidv6(params) { ++ return this.check(core._uuidv6(exports.ZodUUID, params)); ++} ++function _sharedUuidv7(params) { ++ return this.check(core._uuidv7(exports.ZodUUID, params)); ++} ++function _sharedNanoid(params) { ++ return this.check(core._nanoid(exports.ZodNanoID, params)); ++} ++function _sharedCuid(params) { ++ return this.check(core._cuid(exports.ZodCUID, params)); ++} ++function _sharedCuid2(params) { ++ return this.check(core._cuid2(exports.ZodCUID2, params)); ++} ++function _sharedUlid(params) { ++ return this.check(core._ulid(exports.ZodULID, params)); ++} ++function _sharedBase64(params) { ++ return this.check(core._base64(exports.ZodBase64, params)); ++} ++function _sharedBase64url(params) { ++ return this.check(core._base64url(exports.ZodBase64URL, params)); ++} ++function _sharedXid(params) { ++ return this.check(core._xid(exports.ZodXID, params)); ++} ++function _sharedKsuid(params) { ++ return this.check(core._ksuid(exports.ZodKSUID, params)); ++} ++function _sharedIpv4(params) { ++ return this.check(core._ipv4(exports.ZodIPv4, params)); ++} ++function _sharedIpv6(params) { ++ return this.check(core._ipv6(exports.ZodIPv6, params)); ++} ++function _sharedCidrv4(params) { ++ return this.check(core._cidrv4(exports.ZodCIDRv4, params)); ++} ++function _sharedCidrv6(params) { ++ return this.check(core._cidrv6(exports.ZodCIDRv6, params)); ++} ++function _sharedE164(params) { ++ return this.check(core._e164(exports.ZodE164, params)); ++} ++function _sharedDatetime(params) { ++ return this.check(iso.datetime(params)); ++} ++function _sharedDate(params) { ++ return this.check(iso.date(params)); ++} ++function _sharedTime(params) { ++ return this.check(iso.time(params)); ++} ++function _sharedDuration(params) { ++ return this.check(iso.duration(params)); ++} ++// ZodNumber – numeric methods ++function _sharedNumGt(value, params) { ++ return this.check(checks.gt(value, params)); ++} ++function _sharedNumGte(value, params) { ++ return this.check(checks.gte(value, params)); ++} ++function _sharedNumLt(value, params) { ++ return this.check(checks.lt(value, params)); ++} ++function _sharedNumLte(value, params) { ++ return this.check(checks.lte(value, params)); ++} ++function _sharedNumInt(params) { ++ return this.check(int(params)); ++} ++function _sharedNumPositive(params) { ++ return this.check(checks.gt(0, params)); ++} ++function _sharedNumNonnegative(params) { ++ return this.check(checks.gte(0, params)); ++} ++function _sharedNumNegative(params) { ++ return this.check(checks.lt(0, params)); ++} ++function _sharedNumNonpositive(params) { ++ return this.check(checks.lte(0, params)); ++} ++function _sharedNumMultipleOf(value, params) { ++ return this.check(checks.multipleOf(value, params)); ++} ++function _sharedNumFinite() { ++ return this; ++} ++// ZodBigInt – bigint methods ++function _sharedBigIntGt(value, params) { ++ return this.check(checks.gt(value, params)); ++} ++function _sharedBigIntGte(value, params) { ++ return this.check(checks.gte(value, params)); ++} ++function _sharedBigIntLt(value, params) { ++ return this.check(checks.lt(value, params)); ++} ++function _sharedBigIntLte(value, params) { ++ return this.check(checks.lte(value, params)); ++} ++function _sharedBigIntPositive(params) { ++ return this.check(checks.gt(BigInt(0), params)); ++} ++function _sharedBigIntNegative(params) { ++ return this.check(checks.lt(BigInt(0), params)); ++} ++function _sharedBigIntNonpositive(params) { ++ return this.check(checks.lte(BigInt(0), params)); ++} ++function _sharedBigIntNonnegative(params) { ++ return this.check(checks.gte(BigInt(0), params)); ++} ++function _sharedBigIntMultipleOf(value, params) { ++ return this.check(checks.multipleOf(value, params)); ++} ++// ZodDate – date validation methods ++function _sharedDateMin(value, params) { ++ return this.check(checks.gte(value, params)); ++} ++function _sharedDateMax(value, params) { ++ return this.check(checks.lte(value, params)); ++} ++// ZodArray – array methods ++function _sharedArrMin(minLength, params) { ++ return this.check(checks.minLength(minLength, params)); ++} ++function _sharedArrNonempty(params) { ++ return this.check(checks.minLength(1, params)); ++} ++function _sharedArrMax(maxLength, params) { ++ return this.check(checks.maxLength(maxLength, params)); ++} ++function _sharedArrLength(len, params) { ++ return this.check(checks.length(len, params)); ++} ++function _sharedArrUnwrap() { ++ return this.element; ++} ++// ZodObject – object methods ++function _sharedObjKeyof() { ++ return _enum(Object.keys(this._zod.def.shape)); ++} ++function _sharedObjCatchall(catchall) { ++ return this.clone({ ...this._zod.def, catchall }); ++} ++function _sharedObjPassthrough() { ++ return this.clone({ ...this._zod.def, catchall: unknown() }); ++} ++function _sharedObjLoose() { ++ return this.clone({ ...this._zod.def, catchall: unknown() }); ++} ++function _sharedObjStrict() { ++ return this.clone({ ...this._zod.def, catchall: never() }); ++} ++function _sharedObjStrip() { ++ return this.clone({ ...this._zod.def, catchall: undefined }); ++} ++function _sharedObjExtend(incoming) { ++ return index_js_1.util.extend(this, incoming); ++} ++function _sharedObjSafeExtend(incoming) { ++ return index_js_1.util.safeExtend(this, incoming); ++} ++function _sharedObjMerge(other) { ++ return index_js_1.util.merge(this, other); ++} ++function _sharedObjPick(mask) { ++ return index_js_1.util.pick(this, mask); ++} ++function _sharedObjOmit(mask) { ++ return index_js_1.util.omit(this, mask); ++} ++function _sharedObjPartial(...args) { ++ return index_js_1.util.partial(exports.ZodOptional, this, args[0]); ++} ++function _sharedObjRequired(...args) { ++ return index_js_1.util.required(exports.ZodNonOptional, this, args[0]); ++} ++// ZodTuple ++function _sharedTupleRest(rest) { ++ return this.clone({ ...this._zod.def, rest }); ++} ++// ZodMap / ZodSet – size methods ++function _sharedSizeMin(...args) { ++ return this.check(core._minSize(...args)); ++} ++function _sharedSizeNonempty(params) { ++ return this.check(core._minSize(1, params)); ++} ++function _sharedSizeMax(...args) { ++ return this.check(core._maxSize(...args)); ++} ++function _sharedSize(...args) { ++ return this.check(core._size(...args)); ++} ++// ZodFile – file methods ++function _sharedFileMin(size, params) { ++ return this.check(core._minSize(size, params)); ++} ++function _sharedFileMax(size, params) { ++ return this.check(core._maxSize(size, params)); ++} ++function _sharedFileMime(types, params) { ++ return this.check(core._mime(Array.isArray(types) ? types : [types], params)); ++} ++// ZodEnum – extract/exclude ++function _sharedEnumExtract(values, params) { ++ const def = this._zod.def; ++ const keys = new Set(Object.keys(def.entries)); ++ const newEntries = {}; ++ for (const value of values) { ++ if (keys.has(value)) ++ newEntries[value] = def.entries[value]; ++ else ++ throw new Error(`Key ${value} not found in enum`); ++ } ++ return new exports.ZodEnum({ ...def, checks: [], ...index_js_1.util.normalizeParams(params), entries: newEntries }); ++} ++function _sharedEnumExclude(values, params) { ++ const def = this._zod.def; ++ const keys = new Set(Object.keys(def.entries)); ++ const newEntries = { ...def.entries }; ++ for (const value of values) { ++ if (keys.has(value)) ++ delete newEntries[value]; ++ else ++ throw new Error(`Key ${value} not found in enum`); ++ } ++ return new exports.ZodEnum({ ...def, checks: [], ...index_js_1.util.normalizeParams(params), entries: newEntries }); ++} ++// Wrapper types – shared unwrap ++function _sharedUnwrap() { ++ return this._zod.def.innerType; ++} ++function _sharedLazyUnwrap() { ++ return this._zod.def.getter(); ++} + exports.ZodType = core.$constructor("ZodType", (inst, def) => { + core.$ZodType.init(inst, def); + Object.assign(inst["~standard"], { +@@ -139,30 +588,15 @@ exports.ZodType = core.$constructor("ZodType", (inst, def) => { + inst.type = def.type; + Object.defineProperty(inst, "_def", { value: def }); + // base methods +- inst.check = (...checks) => { +- return inst.clone(index_js_1.util.mergeDefs(def, { +- checks: [ +- ...(def.checks ?? []), +- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), +- ], +- }), { +- parent: true, +- }); +- }; +- inst.with = inst.check; +- inst.clone = (def, params) => core.clone(inst, def, params); +- inst.brand = () => inst; +- inst.register = ((reg, meta) => { +- reg.add(inst, meta); +- return inst; +- }); + // parsing ++ // parsing — kept as per-instance closures so that detached usage works: ++ // const parse = schema.parse; parse("hello"); // must work + inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse }); + inst.safeParse = (data, params) => parse.safeParse(inst, data, params); + inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync }); + inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params); + inst.spa = inst.safeParseAsync; +- // encoding/decoding ++ // encoding/decoding — same reason + inst.encode = (data, params) => parse.encode(inst, data, params); + inst.decode = (data, params) => parse.decode(inst, data, params); + inst.encodeAsync = async (data, params) => parse.encodeAsync(inst, data, params); +@@ -172,49 +606,49 @@ exports.ZodType = core.$constructor("ZodType", (inst, def) => { + inst.safeEncodeAsync = async (data, params) => parse.safeEncodeAsync(inst, data, params); + inst.safeDecodeAsync = async (data, params) => parse.safeDecodeAsync(inst, data, params); + // refinements +- inst.refine = (check, params) => inst.check(refine(check, params)); +- inst.superRefine = (refinement) => inst.check(superRefine(refinement)); +- inst.overwrite = (fn) => inst.check(checks.overwrite(fn)); + // wrappers +- inst.optional = () => optional(inst); +- inst.exactOptional = () => exactOptional(inst); +- inst.nullable = () => nullable(inst); +- inst.nullish = () => optional(nullable(inst)); +- inst.nonoptional = (params) => nonoptional(inst, params); +- inst.array = () => array(inst); +- inst.or = (arg) => union([inst, arg]); +- inst.and = (arg) => intersection(inst, arg); +- inst.transform = (tx) => pipe(inst, transform(tx)); +- inst.default = (def) => _default(inst, def); +- inst.prefault = (def) => prefault(inst, def); + // inst.coalesce = (def, params) => coalesce(inst, def, params); +- inst.catch = (params) => _catch(inst, params); +- inst.pipe = (target) => pipe(inst, target); +- inst.readonly = () => readonly(inst); + // meta +- inst.describe = (description) => { +- const cl = inst.clone(); +- core.globalRegistry.add(cl, { description }); +- return cl; +- }; +- Object.defineProperty(inst, "description", { +- get() { +- return core.globalRegistry.get(inst)?.description; +- }, +- configurable: true, +- }); +- inst.meta = (...args) => { +- if (args.length === 0) { +- return core.globalRegistry.get(inst); +- } +- const cl = inst.clone(); +- core.globalRegistry.add(cl, args[0]); +- return cl; +- }; + // helpers +- inst.isOptional = () => inst.safeParse(undefined).success; +- inst.isNullable = () => inst.safeParse(null).success; +- inst.apply = (fn) => fn(inst); ++ _initProto(inst, "ZodType", { ++ check: _sharedCheck, ++ with: _sharedCheck, ++ clone: _sharedClone, ++ brand: _sharedBrand, ++ register: _sharedRegister, ++ refine: _sharedRefine, ++ superRefine: _sharedSuperRefine, ++ overwrite: _sharedOverwrite, ++ optional: _sharedOptional, ++ exactOptional: _sharedExactOptional, ++ nullable: _sharedNullable, ++ nullish: _sharedNullish, ++ nonoptional: _sharedNonoptional, ++ array: _sharedArray, ++ or: _sharedOr, ++ and: _sharedAnd, ++ transform: _sharedTransform, ++ default: _sharedDefault, ++ prefault: _sharedPrefault, ++ catch: _sharedCatch, ++ pipe: _sharedPipe, ++ readonly: _sharedReadonly, ++ describe: _sharedDescribe, ++ meta: _sharedMeta, ++ isOptional: _sharedIsOptional, ++ isNullable: _sharedIsNullable, ++ apply: _sharedApply, ++ }, [ ++ [ ++ "description", ++ { ++ get() { ++ return core.globalRegistry.get(this)?.description; ++ }, ++ configurable: true, ++ }, ++ ], ++ ]); + return inst; + }); + /** @internal */ +@@ -227,54 +661,57 @@ exports._ZodString = core.$constructor("_ZodString", (inst, def) => { + inst.minLength = bag.minimum ?? null; + inst.maxLength = bag.maximum ?? null; + // validations +- inst.regex = (...args) => inst.check(checks.regex(...args)); +- inst.includes = (...args) => inst.check(checks.includes(...args)); +- inst.startsWith = (...args) => inst.check(checks.startsWith(...args)); +- inst.endsWith = (...args) => inst.check(checks.endsWith(...args)); +- inst.min = (...args) => inst.check(checks.minLength(...args)); +- inst.max = (...args) => inst.check(checks.maxLength(...args)); +- inst.length = (...args) => inst.check(checks.length(...args)); +- inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args)); +- inst.lowercase = (params) => inst.check(checks.lowercase(params)); +- inst.uppercase = (params) => inst.check(checks.uppercase(params)); + // transforms +- inst.trim = () => inst.check(checks.trim()); +- inst.normalize = (...args) => inst.check(checks.normalize(...args)); +- inst.toLowerCase = () => inst.check(checks.toLowerCase()); +- inst.toUpperCase = () => inst.check(checks.toUpperCase()); +- inst.slugify = () => inst.check(checks.slugify()); ++ _initProto(inst, "_ZodString", { ++ regex: _sharedRegex, ++ includes: _sharedIncludes, ++ startsWith: _sharedStartsWith, ++ endsWith: _sharedEndsWith, ++ min: _sharedStrMin, ++ max: _sharedStrMax, ++ length: _sharedStrLength, ++ nonempty: _sharedStrNonempty, ++ lowercase: _sharedLowercase, ++ uppercase: _sharedUppercase, ++ trim: _sharedTrim, ++ normalize: _sharedNormalize, ++ toLowerCase: _sharedToLowerCase, ++ toUpperCase: _sharedToUpperCase, ++ slugify: _sharedSlugify, ++ }); + }); + exports.ZodString = core.$constructor("ZodString", (inst, def) => { + core.$ZodString.init(inst, def); + exports._ZodString.init(inst, def); +- inst.email = (params) => inst.check(core._email(exports.ZodEmail, params)); +- inst.url = (params) => inst.check(core._url(exports.ZodURL, params)); +- inst.jwt = (params) => inst.check(core._jwt(exports.ZodJWT, params)); +- inst.emoji = (params) => inst.check(core._emoji(exports.ZodEmoji, params)); +- inst.guid = (params) => inst.check(core._guid(exports.ZodGUID, params)); +- inst.uuid = (params) => inst.check(core._uuid(exports.ZodUUID, params)); +- inst.uuidv4 = (params) => inst.check(core._uuidv4(exports.ZodUUID, params)); +- inst.uuidv6 = (params) => inst.check(core._uuidv6(exports.ZodUUID, params)); +- inst.uuidv7 = (params) => inst.check(core._uuidv7(exports.ZodUUID, params)); +- inst.nanoid = (params) => inst.check(core._nanoid(exports.ZodNanoID, params)); +- inst.guid = (params) => inst.check(core._guid(exports.ZodGUID, params)); +- inst.cuid = (params) => inst.check(core._cuid(exports.ZodCUID, params)); +- inst.cuid2 = (params) => inst.check(core._cuid2(exports.ZodCUID2, params)); +- inst.ulid = (params) => inst.check(core._ulid(exports.ZodULID, params)); +- inst.base64 = (params) => inst.check(core._base64(exports.ZodBase64, params)); +- inst.base64url = (params) => inst.check(core._base64url(exports.ZodBase64URL, params)); +- inst.xid = (params) => inst.check(core._xid(exports.ZodXID, params)); +- inst.ksuid = (params) => inst.check(core._ksuid(exports.ZodKSUID, params)); +- inst.ipv4 = (params) => inst.check(core._ipv4(exports.ZodIPv4, params)); +- inst.ipv6 = (params) => inst.check(core._ipv6(exports.ZodIPv6, params)); +- inst.cidrv4 = (params) => inst.check(core._cidrv4(exports.ZodCIDRv4, params)); +- inst.cidrv6 = (params) => inst.check(core._cidrv6(exports.ZodCIDRv6, params)); +- inst.e164 = (params) => inst.check(core._e164(exports.ZodE164, params)); + // iso +- inst.datetime = (params) => inst.check(iso.datetime(params)); +- inst.date = (params) => inst.check(iso.date(params)); +- inst.time = (params) => inst.check(iso.time(params)); +- inst.duration = (params) => inst.check(iso.duration(params)); ++ _initProto(inst, "ZodString", { ++ email: _sharedEmail, ++ url: _sharedUrl, ++ jwt: _sharedJwt, ++ emoji: _sharedEmoji, ++ guid: _sharedGuid, ++ uuid: _sharedUuid, ++ uuidv4: _sharedUuidv4, ++ uuidv6: _sharedUuidv6, ++ uuidv7: _sharedUuidv7, ++ nanoid: _sharedNanoid, ++ cuid: _sharedCuid, ++ cuid2: _sharedCuid2, ++ ulid: _sharedUlid, ++ base64: _sharedBase64, ++ base64url: _sharedBase64url, ++ xid: _sharedXid, ++ ksuid: _sharedKsuid, ++ ipv4: _sharedIpv4, ++ ipv6: _sharedIpv6, ++ cidrv4: _sharedCidrv4, ++ cidrv6: _sharedCidrv6, ++ e164: _sharedE164, ++ datetime: _sharedDatetime, ++ date: _sharedDate, ++ time: _sharedTime, ++ duration: _sharedDuration, ++ }); + }); + function string(params) { + return core._string(exports.ZodString, params); +@@ -485,22 +922,7 @@ exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => { + core.$ZodNumber.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.numberProcessor(inst, ctx, json, params); +- inst.gt = (value, params) => inst.check(checks.gt(value, params)); +- inst.gte = (value, params) => inst.check(checks.gte(value, params)); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.lt = (value, params) => inst.check(checks.lt(value, params)); +- inst.lte = (value, params) => inst.check(checks.lte(value, params)); +- inst.max = (value, params) => inst.check(checks.lte(value, params)); +- inst.int = (params) => inst.check(int(params)); +- inst.safe = (params) => inst.check(int(params)); +- inst.positive = (params) => inst.check(checks.gt(0, params)); +- inst.nonnegative = (params) => inst.check(checks.gte(0, params)); +- inst.negative = (params) => inst.check(checks.lt(0, params)); +- inst.nonpositive = (params) => inst.check(checks.lte(0, params)); +- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params)); +- inst.step = (value, params) => inst.check(checks.multipleOf(value, params)); + // inst.finite = (params) => inst.check(core.finite(params)); +- inst.finite = () => inst; + const bag = inst._zod.bag; + inst.minValue = + Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null; +@@ -509,6 +931,23 @@ exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => { + inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5); + inst.isFinite = true; + inst.format = bag.format ?? null; ++ _initProto(inst, "ZodNumber", { ++ gt: _sharedNumGt, ++ gte: _sharedNumGte, ++ min: _sharedNumGte, ++ lt: _sharedNumLt, ++ lte: _sharedNumLte, ++ max: _sharedNumLte, ++ int: _sharedNumInt, ++ safe: _sharedNumInt, ++ positive: _sharedNumPositive, ++ nonnegative: _sharedNumNonnegative, ++ negative: _sharedNumNegative, ++ nonpositive: _sharedNumNonpositive, ++ multipleOf: _sharedNumMultipleOf, ++ step: _sharedNumMultipleOf, ++ finite: _sharedNumFinite, ++ }); + }); + function number(params) { + return core._number(exports.ZodNumber, params); +@@ -544,23 +983,23 @@ exports.ZodBigInt = core.$constructor("ZodBigInt", (inst, def) => { + core.$ZodBigInt.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.bigintProcessor(inst, ctx, json, params); +- inst.gte = (value, params) => inst.check(checks.gte(value, params)); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.gt = (value, params) => inst.check(checks.gt(value, params)); +- inst.gte = (value, params) => inst.check(checks.gte(value, params)); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.lt = (value, params) => inst.check(checks.lt(value, params)); +- inst.lte = (value, params) => inst.check(checks.lte(value, params)); +- inst.max = (value, params) => inst.check(checks.lte(value, params)); +- inst.positive = (params) => inst.check(checks.gt(BigInt(0), params)); +- inst.negative = (params) => inst.check(checks.lt(BigInt(0), params)); +- inst.nonpositive = (params) => inst.check(checks.lte(BigInt(0), params)); +- inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params)); +- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params)); + const bag = inst._zod.bag; + inst.minValue = bag.minimum ?? null; + inst.maxValue = bag.maximum ?? null; + inst.format = bag.format ?? null; ++ _initProto(inst, "ZodBigInt", { ++ gte: _sharedBigIntGte, ++ min: _sharedBigIntGte, ++ gt: _sharedBigIntGt, ++ lt: _sharedBigIntLt, ++ lte: _sharedBigIntLte, ++ max: _sharedBigIntLte, ++ positive: _sharedBigIntPositive, ++ negative: _sharedBigIntNegative, ++ nonpositive: _sharedBigIntNonpositive, ++ nonnegative: _sharedBigIntNonnegative, ++ multipleOf: _sharedBigIntMultipleOf, ++ }); + }); + function bigint(params) { + return core._bigint(exports.ZodBigInt, params); +@@ -637,8 +1076,8 @@ exports.ZodDate = core.$constructor("ZodDate", (inst, def) => { + core.$ZodDate.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.dateProcessor(inst, ctx, json, params); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.max = (value, params) => inst.check(checks.lte(value, params)); ++ _initProto(inst, "__min__", { min: _sharedDateMin }); ++ _initProto(inst, "__max__", { max: _sharedDateMax }); + const c = inst._zod.bag; + inst.minDate = c.minimum ? new Date(c.minimum) : null; + inst.maxDate = c.maximum ? new Date(c.maximum) : null; +@@ -651,11 +1090,11 @@ exports.ZodArray = core.$constructor("ZodArray", (inst, def) => { + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.arrayProcessor(inst, ctx, json, params); + inst.element = def.element; +- inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params)); +- inst.nonempty = (params) => inst.check(checks.minLength(1, params)); +- inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params)); +- inst.length = (len, params) => inst.check(checks.length(len, params)); +- inst.unwrap = () => inst.element; ++ _initProto(inst, "__min__", { min: _sharedArrMin }); ++ _initProto(inst, "__nonempty__", { nonempty: _sharedArrNonempty }); ++ _initProto(inst, "__max__", { max: _sharedArrMax }); ++ _initProto(inst, "__length__", { length: _sharedArrLength }); ++ _initProto(inst, "__unwrap__", { unwrap: _sharedArrUnwrap }); + }); + function array(element, params) { + return core._array(exports.ZodArray, element, params); +@@ -672,23 +1111,19 @@ exports.ZodObject = core.$constructor("ZodObject", (inst, def) => { + index_js_1.util.defineLazy(inst, "shape", () => { + return def.shape; + }); +- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)); +- inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall }); +- inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() }); +- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() }); +- inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() }); +- inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined }); +- inst.extend = (incoming) => { +- return index_js_1.util.extend(inst, incoming); +- }; +- inst.safeExtend = (incoming) => { +- return index_js_1.util.safeExtend(inst, incoming); +- }; +- inst.merge = (other) => index_js_1.util.merge(inst, other); +- inst.pick = (mask) => index_js_1.util.pick(inst, mask); +- inst.omit = (mask) => index_js_1.util.omit(inst, mask); +- inst.partial = (...args) => index_js_1.util.partial(exports.ZodOptional, inst, args[0]); +- inst.required = (...args) => index_js_1.util.required(exports.ZodNonOptional, inst, args[0]); ++ _initProto(inst, "__keyof__", { keyof: _sharedObjKeyof }); ++ _initProto(inst, "__catchall__", { catchall: _sharedObjCatchall }); ++ _initProto(inst, "__passthrough__", { passthrough: _sharedObjPassthrough }); ++ _initProto(inst, "__loose__", { loose: _sharedObjLoose }); ++ _initProto(inst, "__strict__", { strict: _sharedObjStrict }); ++ _initProto(inst, "__strip__", { strip: _sharedObjStrip }); ++ _initProto(inst, "__extend__", { extend: _sharedObjExtend }); ++ _initProto(inst, "__safeExtend__", { safeExtend: _sharedObjSafeExtend }); ++ _initProto(inst, "__merge__", { merge: _sharedObjMerge }); ++ _initProto(inst, "__pick__", { pick: _sharedObjPick }); ++ _initProto(inst, "__omit__", { omit: _sharedObjOmit }); ++ _initProto(inst, "__partial__", { partial: _sharedObjPartial }); ++ _initProto(inst, "__required__", { required: _sharedObjRequired }); + }); + function object(shape, params) { + const def = { +@@ -775,10 +1210,7 @@ exports.ZodTuple = core.$constructor("ZodTuple", (inst, def) => { + core.$ZodTuple.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.tupleProcessor(inst, ctx, json, params); +- inst.rest = (rest) => inst.clone({ +- ...inst._zod.def, +- rest: rest, +- }); ++ _initProto(inst, "__rest__", { rest: _sharedTupleRest }); + }); + function tuple(items, _paramsOrRest, _params) { + const hasRest = _paramsOrRest instanceof core.$ZodType; +@@ -832,10 +1264,10 @@ exports.ZodMap = core.$constructor("ZodMap", (inst, def) => { + inst._zod.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params); + inst.keyType = def.keyType; + inst.valueType = def.valueType; +- inst.min = (...args) => inst.check(core._minSize(...args)); +- inst.nonempty = (params) => inst.check(core._minSize(1, params)); +- inst.max = (...args) => inst.check(core._maxSize(...args)); +- inst.size = (...args) => inst.check(core._size(...args)); ++ _initProto(inst, "__min__", { min: _sharedSizeMin }); ++ _initProto(inst, "__nonempty__", { nonempty: _sharedSizeNonempty }); ++ _initProto(inst, "__max__", { max: _sharedSizeMax }); ++ _initProto(inst, "__size__", { size: _sharedSize }); + }); + function map(keyType, valueType, params) { + return new exports.ZodMap({ +@@ -849,10 +1281,10 @@ exports.ZodSet = core.$constructor("ZodSet", (inst, def) => { + core.$ZodSet.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.setProcessor(inst, ctx, json, params); +- inst.min = (...args) => inst.check(core._minSize(...args)); +- inst.nonempty = (params) => inst.check(core._minSize(1, params)); +- inst.max = (...args) => inst.check(core._maxSize(...args)); +- inst.size = (...args) => inst.check(core._size(...args)); ++ _initProto(inst, "__min__", { min: _sharedSizeMin }); ++ _initProto(inst, "__nonempty__", { nonempty: _sharedSizeNonempty }); ++ _initProto(inst, "__max__", { max: _sharedSizeMax }); ++ _initProto(inst, "__size__", { size: _sharedSize }); + }); + function set(valueType, params) { + return new exports.ZodSet({ +@@ -867,39 +1299,8 @@ exports.ZodEnum = core.$constructor("ZodEnum", (inst, def) => { + inst._zod.processJSONSchema = (ctx, json, params) => processors.enumProcessor(inst, ctx, json, params); + inst.enum = def.entries; + inst.options = Object.values(def.entries); +- const keys = new Set(Object.keys(def.entries)); +- inst.extract = (values, params) => { +- const newEntries = {}; +- for (const value of values) { +- if (keys.has(value)) { +- newEntries[value] = def.entries[value]; +- } +- else +- throw new Error(`Key ${value} not found in enum`); +- } +- return new exports.ZodEnum({ +- ...def, +- checks: [], +- ...index_js_1.util.normalizeParams(params), +- entries: newEntries, +- }); +- }; +- inst.exclude = (values, params) => { +- const newEntries = { ...def.entries }; +- for (const value of values) { +- if (keys.has(value)) { +- delete newEntries[value]; +- } +- else +- throw new Error(`Key ${value} not found in enum`); +- } +- return new exports.ZodEnum({ +- ...def, +- checks: [], +- ...index_js_1.util.normalizeParams(params), +- entries: newEntries, +- }); +- }; ++ _initProto(inst, "__extract__", { extract: _sharedEnumExtract }); ++ _initProto(inst, "__exclude__", { exclude: _sharedEnumExclude }); + }); + function _enum(values, params) { + const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values; +@@ -948,9 +1349,9 @@ exports.ZodFile = core.$constructor("ZodFile", (inst, def) => { + core.$ZodFile.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.fileProcessor(inst, ctx, json, params); +- inst.min = (size, params) => inst.check(core._minSize(size, params)); +- inst.max = (size, params) => inst.check(core._maxSize(size, params)); +- inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params)); ++ _initProto(inst, "__min__", { min: _sharedFileMin }); ++ _initProto(inst, "__max__", { max: _sharedFileMax }); ++ _initProto(inst, "__mime__", { mime: _sharedFileMime }); + }); + function file(params) { + return core._file(exports.ZodFile, params); +@@ -1000,7 +1401,7 @@ exports.ZodOptional = core.$constructor("ZodOptional", (inst, def) => { + core.$ZodOptional.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function optional(innerType) { + return new exports.ZodOptional({ +@@ -1012,7 +1413,7 @@ exports.ZodExactOptional = core.$constructor("ZodExactOptional", (inst, def) => + core.$ZodExactOptional.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function exactOptional(innerType) { + return new exports.ZodExactOptional({ +@@ -1024,7 +1425,7 @@ exports.ZodNullable = core.$constructor("ZodNullable", (inst, def) => { + core.$ZodNullable.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.nullableProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function nullable(innerType) { + return new exports.ZodNullable({ +@@ -1040,8 +1441,8 @@ exports.ZodDefault = core.$constructor("ZodDefault", (inst, def) => { + core.$ZodDefault.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.defaultProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; +- inst.removeDefault = inst.unwrap; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); ++ _initProto(inst, "__removeDefault__", { removeDefault: _sharedUnwrap }); + }); + function _default(innerType, defaultValue) { + return new exports.ZodDefault({ +@@ -1056,7 +1457,7 @@ exports.ZodPrefault = core.$constructor("ZodPrefault", (inst, def) => { + core.$ZodPrefault.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.prefaultProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function prefault(innerType, defaultValue) { + return new exports.ZodPrefault({ +@@ -1071,7 +1472,7 @@ exports.ZodNonOptional = core.$constructor("ZodNonOptional", (inst, def) => { + core.$ZodNonOptional.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.nonoptionalProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function nonoptional(innerType, params) { + return new exports.ZodNonOptional({ +@@ -1084,7 +1485,7 @@ exports.ZodSuccess = core.$constructor("ZodSuccess", (inst, def) => { + core.$ZodSuccess.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.successProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function success(innerType) { + return new exports.ZodSuccess({ +@@ -1096,8 +1497,8 @@ exports.ZodCatch = core.$constructor("ZodCatch", (inst, def) => { + core.$ZodCatch.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.catchProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; +- inst.removeCatch = inst.unwrap; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); ++ _initProto(inst, "__removeCatch__", { removeCatch: _sharedUnwrap }); + }); + function _catch(innerType, catchValue) { + return new exports.ZodCatch({ +@@ -1146,7 +1547,7 @@ exports.ZodReadonly = core.$constructor("ZodReadonly", (inst, def) => { + core.$ZodReadonly.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.readonlyProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function readonly(innerType) { + return new exports.ZodReadonly({ +@@ -1170,7 +1571,7 @@ exports.ZodLazy = core.$constructor("ZodLazy", (inst, def) => { + core.$ZodLazy.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.lazyProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.getter(); ++ _initProto(inst, "__unwrap__", { unwrap: _sharedLazyUnwrap }); + }); + function lazy(getter) { + return new exports.ZodLazy({ +@@ -1182,7 +1583,7 @@ exports.ZodPromise = core.$constructor("ZodPromise", (inst, def) => { + core.$ZodPromise.init(inst, def); + exports.ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.promiseProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + function promise(innerType) { + return new exports.ZodPromise({ +diff --git a/node_modules/zod/v4/classic/schemas.js b/node_modules/zod/v4/classic/schemas.js +index a95b958..71ba782 100644 +--- a/node_modules/zod/v4/classic/schemas.js ++++ b/node_modules/zod/v4/classic/schemas.js +@@ -5,6 +5,455 @@ import { createStandardJSONSchemaMethod, createToJSONSchemaMethod } from "../cor + import * as checks from "./checks.js"; + import * as iso from "./iso.js"; + import * as parse from "./parse.js"; ++// Maps (internalProto, key) pairs already initialized — avoids repeated prototype setup ++const _protoInitMap = new WeakMap(); ++/** ++ * Sets shared methods on the *internal* prototype layer of inst's concrete constructor ++ * (once per concrete type per key). The internal prototype sits one level below the ++ * user-visible `_.prototype`, keeping `Object.keys(_.prototype)` empty by default ++ * and preventing V8 dictionary-mode degradation. ++ * ++ * Falls back to `Object.getPrototypeOf(inst)` for constructors not created with ++ * `$constructor` (e.g., in tests or third-party code). ++ */ ++function _initProto(inst, key, methods, defineProps) { ++ const proto = inst._zod?.constr?.[core.$internalProto] ?? Object.getPrototypeOf(inst); ++ let keys = _protoInitMap.get(proto); ++ if (!keys) { ++ keys = new Set(); ++ _protoInitMap.set(proto, keys); ++ } ++ if (keys.has(key)) ++ return; ++ keys.add(key); ++ Object.assign(proto, methods); ++ if (defineProps) { ++ for (const [k, desc] of defineProps) { ++ Object.defineProperty(proto, k, { ...desc, configurable: true }); ++ } ++ } ++} ++// ───────────────────────────────────────────────────────────────────────────── ++// Shared method references (memory optimization) ++// ++// Zod v4 originally assigned every schema method as a per-instance arrow ++// function closure, capturing `inst`. With many schemas this causes significant ++// heap pressure (~50 extra function objects per schema instance). Instead, we ++// define each method once as a named function that uses `this` for context. ++// All instances then share the same function objects while retaining the same ++// own-property API surface and full runtime correctness. ++// ++// The return-type casts (`as any`) are required because TypeScript cannot ++// statically verify that a shared `this: ZodType` matches the polymorphic ++// `this` in the interface declaration. The declared interface types remain ++// authoritative; these casts are implementation-only. ++// ───────────────────────────────────────────────────────────────────────────── ++// ZodType – base methods ++function _sharedCheck(...chks) { ++ const def = this.def; ++ return this.clone(util.mergeDefs(def, { ++ checks: [ ++ ...(def.checks ?? []), ++ ...chks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), ++ ], ++ }), { parent: true }); ++} ++function _sharedClone(def, params) { ++ return core.clone(this, def, params); ++} ++function _sharedBrand() { ++ return this; ++} ++function _sharedRegister(reg, meta) { ++ reg.add(this, meta); ++ return this; ++} ++// NOTE: parse/safeParse/parseAsync/safeParseAsync/encode/decode (and their variants) ++// are intentionally kept as per-instance closures in the ZodType initializer below. ++// These methods are commonly called in a detached manner (e.g. `arr.map(schema.parse)` ++// or `const p = schema.parse; p(v)`), so they must capture `inst` rather than rely ++// on `this` binding. ++function _sharedRefine(check, params) { ++ return this.check(refine(check, params)); ++} ++function _sharedSuperRefine(refinement) { ++ return this.check(superRefine(refinement)); ++} ++function _sharedOverwrite(fn) { ++ return this.check(checks.overwrite(fn)); ++} ++function _sharedOptional() { ++ return optional(this); ++} ++function _sharedExactOptional() { ++ return exactOptional(this); ++} ++function _sharedNullable() { ++ return nullable(this); ++} ++function _sharedNullish() { ++ return optional(nullable(this)); ++} ++function _sharedNonoptional(params) { ++ return nonoptional(this, params); ++} ++function _sharedArray() { ++ return array(this); ++} ++function _sharedOr(arg) { ++ return union([this, arg]); ++} ++function _sharedAnd(arg) { ++ return intersection(this, arg); ++} ++function _sharedTransform(tx) { ++ return pipe(this, transform(tx)); ++} ++function _sharedDefault(d) { ++ return _default(this, d); ++} ++function _sharedPrefault(d) { ++ return prefault(this, d); ++} ++function _sharedCatch(params) { ++ return _catch(this, params); ++} ++function _sharedPipe(target) { ++ return pipe(this, target); ++} ++function _sharedReadonly() { ++ return readonly(this); ++} ++function _sharedDescribe(description) { ++ const cl = this.clone(); ++ core.globalRegistry.add(cl, { description }); ++ return cl; ++} ++function _sharedMeta(...args) { ++ if (args.length === 0) ++ return core.globalRegistry.get(this); ++ const cl = this.clone(); ++ core.globalRegistry.add(cl, args[0]); ++ return cl; ++} ++function _sharedIsOptional() { ++ return this.safeParse(undefined).success; ++} ++function _sharedIsNullable() { ++ return this.safeParse(null).success; ++} ++function _sharedApply(fn) { ++ return fn(this); ++} ++// _ZodString – string validation methods ++function _sharedRegex(...args) { ++ return this.check(checks.regex(...args)); ++} ++function _sharedIncludes(...args) { ++ return this.check(checks.includes(...args)); ++} ++function _sharedStartsWith(...args) { ++ return this.check(checks.startsWith(...args)); ++} ++function _sharedEndsWith(...args) { ++ return this.check(checks.endsWith(...args)); ++} ++function _sharedStrMin(...args) { ++ return this.check(checks.minLength(...args)); ++} ++function _sharedStrMax(...args) { ++ return this.check(checks.maxLength(...args)); ++} ++function _sharedStrLength(...args) { ++ return this.check(checks.length(...args)); ++} ++function _sharedStrNonempty(...args) { ++ return this.check(checks.minLength(1, ...args)); ++} ++function _sharedLowercase(params) { ++ return this.check(checks.lowercase(params)); ++} ++function _sharedUppercase(params) { ++ return this.check(checks.uppercase(params)); ++} ++function _sharedTrim() { ++ return this.check(checks.trim()); ++} ++function _sharedNormalize(...args) { ++ return this.check(checks.normalize(...args)); ++} ++function _sharedToLowerCase() { ++ return this.check(checks.toLowerCase()); ++} ++function _sharedToUpperCase() { ++ return this.check(checks.toUpperCase()); ++} ++function _sharedSlugify() { ++ return this.check(checks.slugify()); ++} ++// ZodString – format methods ++function _sharedEmail(params) { ++ return this.check(core._email(ZodEmail, params)); ++} ++function _sharedUrl(params) { ++ return this.check(core._url(ZodURL, params)); ++} ++function _sharedJwt(params) { ++ return this.check(core._jwt(ZodJWT, params)); ++} ++function _sharedEmoji(params) { ++ return this.check(core._emoji(ZodEmoji, params)); ++} ++function _sharedGuid(params) { ++ return this.check(core._guid(ZodGUID, params)); ++} ++function _sharedUuid(params) { ++ return this.check(core._uuid(ZodUUID, params)); ++} ++function _sharedUuidv4(params) { ++ return this.check(core._uuidv4(ZodUUID, params)); ++} ++function _sharedUuidv6(params) { ++ return this.check(core._uuidv6(ZodUUID, params)); ++} ++function _sharedUuidv7(params) { ++ return this.check(core._uuidv7(ZodUUID, params)); ++} ++function _sharedNanoid(params) { ++ return this.check(core._nanoid(ZodNanoID, params)); ++} ++function _sharedCuid(params) { ++ return this.check(core._cuid(ZodCUID, params)); ++} ++function _sharedCuid2(params) { ++ return this.check(core._cuid2(ZodCUID2, params)); ++} ++function _sharedUlid(params) { ++ return this.check(core._ulid(ZodULID, params)); ++} ++function _sharedBase64(params) { ++ return this.check(core._base64(ZodBase64, params)); ++} ++function _sharedBase64url(params) { ++ return this.check(core._base64url(ZodBase64URL, params)); ++} ++function _sharedXid(params) { ++ return this.check(core._xid(ZodXID, params)); ++} ++function _sharedKsuid(params) { ++ return this.check(core._ksuid(ZodKSUID, params)); ++} ++function _sharedIpv4(params) { ++ return this.check(core._ipv4(ZodIPv4, params)); ++} ++function _sharedIpv6(params) { ++ return this.check(core._ipv6(ZodIPv6, params)); ++} ++function _sharedCidrv4(params) { ++ return this.check(core._cidrv4(ZodCIDRv4, params)); ++} ++function _sharedCidrv6(params) { ++ return this.check(core._cidrv6(ZodCIDRv6, params)); ++} ++function _sharedE164(params) { ++ return this.check(core._e164(ZodE164, params)); ++} ++function _sharedDatetime(params) { ++ return this.check(iso.datetime(params)); ++} ++function _sharedDate(params) { ++ return this.check(iso.date(params)); ++} ++function _sharedTime(params) { ++ return this.check(iso.time(params)); ++} ++function _sharedDuration(params) { ++ return this.check(iso.duration(params)); ++} ++// ZodNumber – numeric methods ++function _sharedNumGt(value, params) { ++ return this.check(checks.gt(value, params)); ++} ++function _sharedNumGte(value, params) { ++ return this.check(checks.gte(value, params)); ++} ++function _sharedNumLt(value, params) { ++ return this.check(checks.lt(value, params)); ++} ++function _sharedNumLte(value, params) { ++ return this.check(checks.lte(value, params)); ++} ++function _sharedNumInt(params) { ++ return this.check(int(params)); ++} ++function _sharedNumPositive(params) { ++ return this.check(checks.gt(0, params)); ++} ++function _sharedNumNonnegative(params) { ++ return this.check(checks.gte(0, params)); ++} ++function _sharedNumNegative(params) { ++ return this.check(checks.lt(0, params)); ++} ++function _sharedNumNonpositive(params) { ++ return this.check(checks.lte(0, params)); ++} ++function _sharedNumMultipleOf(value, params) { ++ return this.check(checks.multipleOf(value, params)); ++} ++function _sharedNumFinite() { ++ return this; ++} ++// ZodBigInt – bigint methods ++function _sharedBigIntGt(value, params) { ++ return this.check(checks.gt(value, params)); ++} ++function _sharedBigIntGte(value, params) { ++ return this.check(checks.gte(value, params)); ++} ++function _sharedBigIntLt(value, params) { ++ return this.check(checks.lt(value, params)); ++} ++function _sharedBigIntLte(value, params) { ++ return this.check(checks.lte(value, params)); ++} ++function _sharedBigIntPositive(params) { ++ return this.check(checks.gt(BigInt(0), params)); ++} ++function _sharedBigIntNegative(params) { ++ return this.check(checks.lt(BigInt(0), params)); ++} ++function _sharedBigIntNonpositive(params) { ++ return this.check(checks.lte(BigInt(0), params)); ++} ++function _sharedBigIntNonnegative(params) { ++ return this.check(checks.gte(BigInt(0), params)); ++} ++function _sharedBigIntMultipleOf(value, params) { ++ return this.check(checks.multipleOf(value, params)); ++} ++// ZodDate – date validation methods ++function _sharedDateMin(value, params) { ++ return this.check(checks.gte(value, params)); ++} ++function _sharedDateMax(value, params) { ++ return this.check(checks.lte(value, params)); ++} ++// ZodArray – array methods ++function _sharedArrMin(minLength, params) { ++ return this.check(checks.minLength(minLength, params)); ++} ++function _sharedArrNonempty(params) { ++ return this.check(checks.minLength(1, params)); ++} ++function _sharedArrMax(maxLength, params) { ++ return this.check(checks.maxLength(maxLength, params)); ++} ++function _sharedArrLength(len, params) { ++ return this.check(checks.length(len, params)); ++} ++function _sharedArrUnwrap() { ++ return this.element; ++} ++// ZodObject – object methods ++function _sharedObjKeyof() { ++ return _enum(Object.keys(this._zod.def.shape)); ++} ++function _sharedObjCatchall(catchall) { ++ return this.clone({ ...this._zod.def, catchall }); ++} ++function _sharedObjPassthrough() { ++ return this.clone({ ...this._zod.def, catchall: unknown() }); ++} ++function _sharedObjLoose() { ++ return this.clone({ ...this._zod.def, catchall: unknown() }); ++} ++function _sharedObjStrict() { ++ return this.clone({ ...this._zod.def, catchall: never() }); ++} ++function _sharedObjStrip() { ++ return this.clone({ ...this._zod.def, catchall: undefined }); ++} ++function _sharedObjExtend(incoming) { ++ return util.extend(this, incoming); ++} ++function _sharedObjSafeExtend(incoming) { ++ return util.safeExtend(this, incoming); ++} ++function _sharedObjMerge(other) { ++ return util.merge(this, other); ++} ++function _sharedObjPick(mask) { ++ return util.pick(this, mask); ++} ++function _sharedObjOmit(mask) { ++ return util.omit(this, mask); ++} ++function _sharedObjPartial(...args) { ++ return util.partial(ZodOptional, this, args[0]); ++} ++function _sharedObjRequired(...args) { ++ return util.required(ZodNonOptional, this, args[0]); ++} ++// ZodTuple ++function _sharedTupleRest(rest) { ++ return this.clone({ ...this._zod.def, rest }); ++} ++// ZodMap / ZodSet – size methods ++function _sharedSizeMin(...args) { ++ return this.check(core._minSize(...args)); ++} ++function _sharedSizeNonempty(params) { ++ return this.check(core._minSize(1, params)); ++} ++function _sharedSizeMax(...args) { ++ return this.check(core._maxSize(...args)); ++} ++function _sharedSize(...args) { ++ return this.check(core._size(...args)); ++} ++// ZodFile – file methods ++function _sharedFileMin(size, params) { ++ return this.check(core._minSize(size, params)); ++} ++function _sharedFileMax(size, params) { ++ return this.check(core._maxSize(size, params)); ++} ++function _sharedFileMime(types, params) { ++ return this.check(core._mime(Array.isArray(types) ? types : [types], params)); ++} ++// ZodEnum – extract/exclude ++function _sharedEnumExtract(values, params) { ++ const def = this._zod.def; ++ const keys = new Set(Object.keys(def.entries)); ++ const newEntries = {}; ++ for (const value of values) { ++ if (keys.has(value)) ++ newEntries[value] = def.entries[value]; ++ else ++ throw new Error(`Key ${value} not found in enum`); ++ } ++ return new ZodEnum({ ...def, checks: [], ...util.normalizeParams(params), entries: newEntries }); ++} ++function _sharedEnumExclude(values, params) { ++ const def = this._zod.def; ++ const keys = new Set(Object.keys(def.entries)); ++ const newEntries = { ...def.entries }; ++ for (const value of values) { ++ if (keys.has(value)) ++ delete newEntries[value]; ++ else ++ throw new Error(`Key ${value} not found in enum`); ++ } ++ return new ZodEnum({ ...def, checks: [], ...util.normalizeParams(params), entries: newEntries }); ++} ++// Wrapper types – shared unwrap ++function _sharedUnwrap() { ++ return this._zod.def.innerType; ++} ++function _sharedLazyUnwrap() { ++ return this._zod.def.getter(); ++} + export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => { + core.$ZodType.init(inst, def); + Object.assign(inst["~standard"], { +@@ -18,30 +467,15 @@ export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => + inst.type = def.type; + Object.defineProperty(inst, "_def", { value: def }); + // base methods +- inst.check = (...checks) => { +- return inst.clone(util.mergeDefs(def, { +- checks: [ +- ...(def.checks ?? []), +- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), +- ], +- }), { +- parent: true, +- }); +- }; +- inst.with = inst.check; +- inst.clone = (def, params) => core.clone(inst, def, params); +- inst.brand = () => inst; +- inst.register = ((reg, meta) => { +- reg.add(inst, meta); +- return inst; +- }); + // parsing ++ // parsing — kept as per-instance closures so that detached usage works: ++ // const parse = schema.parse; parse("hello"); // must work + inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse }); + inst.safeParse = (data, params) => parse.safeParse(inst, data, params); + inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync }); + inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params); + inst.spa = inst.safeParseAsync; +- // encoding/decoding ++ // encoding/decoding — same reason + inst.encode = (data, params) => parse.encode(inst, data, params); + inst.decode = (data, params) => parse.decode(inst, data, params); + inst.encodeAsync = async (data, params) => parse.encodeAsync(inst, data, params); +@@ -51,49 +485,49 @@ export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => + inst.safeEncodeAsync = async (data, params) => parse.safeEncodeAsync(inst, data, params); + inst.safeDecodeAsync = async (data, params) => parse.safeDecodeAsync(inst, data, params); + // refinements +- inst.refine = (check, params) => inst.check(refine(check, params)); +- inst.superRefine = (refinement) => inst.check(superRefine(refinement)); +- inst.overwrite = (fn) => inst.check(checks.overwrite(fn)); + // wrappers +- inst.optional = () => optional(inst); +- inst.exactOptional = () => exactOptional(inst); +- inst.nullable = () => nullable(inst); +- inst.nullish = () => optional(nullable(inst)); +- inst.nonoptional = (params) => nonoptional(inst, params); +- inst.array = () => array(inst); +- inst.or = (arg) => union([inst, arg]); +- inst.and = (arg) => intersection(inst, arg); +- inst.transform = (tx) => pipe(inst, transform(tx)); +- inst.default = (def) => _default(inst, def); +- inst.prefault = (def) => prefault(inst, def); + // inst.coalesce = (def, params) => coalesce(inst, def, params); +- inst.catch = (params) => _catch(inst, params); +- inst.pipe = (target) => pipe(inst, target); +- inst.readonly = () => readonly(inst); + // meta +- inst.describe = (description) => { +- const cl = inst.clone(); +- core.globalRegistry.add(cl, { description }); +- return cl; +- }; +- Object.defineProperty(inst, "description", { +- get() { +- return core.globalRegistry.get(inst)?.description; +- }, +- configurable: true, +- }); +- inst.meta = (...args) => { +- if (args.length === 0) { +- return core.globalRegistry.get(inst); +- } +- const cl = inst.clone(); +- core.globalRegistry.add(cl, args[0]); +- return cl; +- }; + // helpers +- inst.isOptional = () => inst.safeParse(undefined).success; +- inst.isNullable = () => inst.safeParse(null).success; +- inst.apply = (fn) => fn(inst); ++ _initProto(inst, "ZodType", { ++ check: _sharedCheck, ++ with: _sharedCheck, ++ clone: _sharedClone, ++ brand: _sharedBrand, ++ register: _sharedRegister, ++ refine: _sharedRefine, ++ superRefine: _sharedSuperRefine, ++ overwrite: _sharedOverwrite, ++ optional: _sharedOptional, ++ exactOptional: _sharedExactOptional, ++ nullable: _sharedNullable, ++ nullish: _sharedNullish, ++ nonoptional: _sharedNonoptional, ++ array: _sharedArray, ++ or: _sharedOr, ++ and: _sharedAnd, ++ transform: _sharedTransform, ++ default: _sharedDefault, ++ prefault: _sharedPrefault, ++ catch: _sharedCatch, ++ pipe: _sharedPipe, ++ readonly: _sharedReadonly, ++ describe: _sharedDescribe, ++ meta: _sharedMeta, ++ isOptional: _sharedIsOptional, ++ isNullable: _sharedIsNullable, ++ apply: _sharedApply, ++ }, [ ++ [ ++ "description", ++ { ++ get() { ++ return core.globalRegistry.get(this)?.description; ++ }, ++ configurable: true, ++ }, ++ ], ++ ]); + return inst; + }); + /** @internal */ +@@ -106,54 +540,57 @@ export const _ZodString = /*@__PURE__*/ core.$constructor("_ZodString", (inst, d + inst.minLength = bag.minimum ?? null; + inst.maxLength = bag.maximum ?? null; + // validations +- inst.regex = (...args) => inst.check(checks.regex(...args)); +- inst.includes = (...args) => inst.check(checks.includes(...args)); +- inst.startsWith = (...args) => inst.check(checks.startsWith(...args)); +- inst.endsWith = (...args) => inst.check(checks.endsWith(...args)); +- inst.min = (...args) => inst.check(checks.minLength(...args)); +- inst.max = (...args) => inst.check(checks.maxLength(...args)); +- inst.length = (...args) => inst.check(checks.length(...args)); +- inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args)); +- inst.lowercase = (params) => inst.check(checks.lowercase(params)); +- inst.uppercase = (params) => inst.check(checks.uppercase(params)); + // transforms +- inst.trim = () => inst.check(checks.trim()); +- inst.normalize = (...args) => inst.check(checks.normalize(...args)); +- inst.toLowerCase = () => inst.check(checks.toLowerCase()); +- inst.toUpperCase = () => inst.check(checks.toUpperCase()); +- inst.slugify = () => inst.check(checks.slugify()); ++ _initProto(inst, "_ZodString", { ++ regex: _sharedRegex, ++ includes: _sharedIncludes, ++ startsWith: _sharedStartsWith, ++ endsWith: _sharedEndsWith, ++ min: _sharedStrMin, ++ max: _sharedStrMax, ++ length: _sharedStrLength, ++ nonempty: _sharedStrNonempty, ++ lowercase: _sharedLowercase, ++ uppercase: _sharedUppercase, ++ trim: _sharedTrim, ++ normalize: _sharedNormalize, ++ toLowerCase: _sharedToLowerCase, ++ toUpperCase: _sharedToUpperCase, ++ slugify: _sharedSlugify, ++ }); + }); + export const ZodString = /*@__PURE__*/ core.$constructor("ZodString", (inst, def) => { + core.$ZodString.init(inst, def); + _ZodString.init(inst, def); +- inst.email = (params) => inst.check(core._email(ZodEmail, params)); +- inst.url = (params) => inst.check(core._url(ZodURL, params)); +- inst.jwt = (params) => inst.check(core._jwt(ZodJWT, params)); +- inst.emoji = (params) => inst.check(core._emoji(ZodEmoji, params)); +- inst.guid = (params) => inst.check(core._guid(ZodGUID, params)); +- inst.uuid = (params) => inst.check(core._uuid(ZodUUID, params)); +- inst.uuidv4 = (params) => inst.check(core._uuidv4(ZodUUID, params)); +- inst.uuidv6 = (params) => inst.check(core._uuidv6(ZodUUID, params)); +- inst.uuidv7 = (params) => inst.check(core._uuidv7(ZodUUID, params)); +- inst.nanoid = (params) => inst.check(core._nanoid(ZodNanoID, params)); +- inst.guid = (params) => inst.check(core._guid(ZodGUID, params)); +- inst.cuid = (params) => inst.check(core._cuid(ZodCUID, params)); +- inst.cuid2 = (params) => inst.check(core._cuid2(ZodCUID2, params)); +- inst.ulid = (params) => inst.check(core._ulid(ZodULID, params)); +- inst.base64 = (params) => inst.check(core._base64(ZodBase64, params)); +- inst.base64url = (params) => inst.check(core._base64url(ZodBase64URL, params)); +- inst.xid = (params) => inst.check(core._xid(ZodXID, params)); +- inst.ksuid = (params) => inst.check(core._ksuid(ZodKSUID, params)); +- inst.ipv4 = (params) => inst.check(core._ipv4(ZodIPv4, params)); +- inst.ipv6 = (params) => inst.check(core._ipv6(ZodIPv6, params)); +- inst.cidrv4 = (params) => inst.check(core._cidrv4(ZodCIDRv4, params)); +- inst.cidrv6 = (params) => inst.check(core._cidrv6(ZodCIDRv6, params)); +- inst.e164 = (params) => inst.check(core._e164(ZodE164, params)); + // iso +- inst.datetime = (params) => inst.check(iso.datetime(params)); +- inst.date = (params) => inst.check(iso.date(params)); +- inst.time = (params) => inst.check(iso.time(params)); +- inst.duration = (params) => inst.check(iso.duration(params)); ++ _initProto(inst, "ZodString", { ++ email: _sharedEmail, ++ url: _sharedUrl, ++ jwt: _sharedJwt, ++ emoji: _sharedEmoji, ++ guid: _sharedGuid, ++ uuid: _sharedUuid, ++ uuidv4: _sharedUuidv4, ++ uuidv6: _sharedUuidv6, ++ uuidv7: _sharedUuidv7, ++ nanoid: _sharedNanoid, ++ cuid: _sharedCuid, ++ cuid2: _sharedCuid2, ++ ulid: _sharedUlid, ++ base64: _sharedBase64, ++ base64url: _sharedBase64url, ++ xid: _sharedXid, ++ ksuid: _sharedKsuid, ++ ipv4: _sharedIpv4, ++ ipv6: _sharedIpv6, ++ cidrv4: _sharedCidrv4, ++ cidrv6: _sharedCidrv6, ++ e164: _sharedE164, ++ datetime: _sharedDatetime, ++ date: _sharedDate, ++ time: _sharedTime, ++ duration: _sharedDuration, ++ }); + }); + export function string(params) { + return core._string(ZodString, params); +@@ -364,22 +801,7 @@ export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def + core.$ZodNumber.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.numberProcessor(inst, ctx, json, params); +- inst.gt = (value, params) => inst.check(checks.gt(value, params)); +- inst.gte = (value, params) => inst.check(checks.gte(value, params)); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.lt = (value, params) => inst.check(checks.lt(value, params)); +- inst.lte = (value, params) => inst.check(checks.lte(value, params)); +- inst.max = (value, params) => inst.check(checks.lte(value, params)); +- inst.int = (params) => inst.check(int(params)); +- inst.safe = (params) => inst.check(int(params)); +- inst.positive = (params) => inst.check(checks.gt(0, params)); +- inst.nonnegative = (params) => inst.check(checks.gte(0, params)); +- inst.negative = (params) => inst.check(checks.lt(0, params)); +- inst.nonpositive = (params) => inst.check(checks.lte(0, params)); +- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params)); +- inst.step = (value, params) => inst.check(checks.multipleOf(value, params)); + // inst.finite = (params) => inst.check(core.finite(params)); +- inst.finite = () => inst; + const bag = inst._zod.bag; + inst.minValue = + Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null; +@@ -388,6 +810,23 @@ export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def + inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5); + inst.isFinite = true; + inst.format = bag.format ?? null; ++ _initProto(inst, "ZodNumber", { ++ gt: _sharedNumGt, ++ gte: _sharedNumGte, ++ min: _sharedNumGte, ++ lt: _sharedNumLt, ++ lte: _sharedNumLte, ++ max: _sharedNumLte, ++ int: _sharedNumInt, ++ safe: _sharedNumInt, ++ positive: _sharedNumPositive, ++ nonnegative: _sharedNumNonnegative, ++ negative: _sharedNumNegative, ++ nonpositive: _sharedNumNonpositive, ++ multipleOf: _sharedNumMultipleOf, ++ step: _sharedNumMultipleOf, ++ finite: _sharedNumFinite, ++ }); + }); + export function number(params) { + return core._number(ZodNumber, params); +@@ -423,23 +862,23 @@ export const ZodBigInt = /*@__PURE__*/ core.$constructor("ZodBigInt", (inst, def + core.$ZodBigInt.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.bigintProcessor(inst, ctx, json, params); +- inst.gte = (value, params) => inst.check(checks.gte(value, params)); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.gt = (value, params) => inst.check(checks.gt(value, params)); +- inst.gte = (value, params) => inst.check(checks.gte(value, params)); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.lt = (value, params) => inst.check(checks.lt(value, params)); +- inst.lte = (value, params) => inst.check(checks.lte(value, params)); +- inst.max = (value, params) => inst.check(checks.lte(value, params)); +- inst.positive = (params) => inst.check(checks.gt(BigInt(0), params)); +- inst.negative = (params) => inst.check(checks.lt(BigInt(0), params)); +- inst.nonpositive = (params) => inst.check(checks.lte(BigInt(0), params)); +- inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params)); +- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params)); + const bag = inst._zod.bag; + inst.minValue = bag.minimum ?? null; + inst.maxValue = bag.maximum ?? null; + inst.format = bag.format ?? null; ++ _initProto(inst, "ZodBigInt", { ++ gte: _sharedBigIntGte, ++ min: _sharedBigIntGte, ++ gt: _sharedBigIntGt, ++ lt: _sharedBigIntLt, ++ lte: _sharedBigIntLte, ++ max: _sharedBigIntLte, ++ positive: _sharedBigIntPositive, ++ negative: _sharedBigIntNegative, ++ nonpositive: _sharedBigIntNonpositive, ++ nonnegative: _sharedBigIntNonnegative, ++ multipleOf: _sharedBigIntMultipleOf, ++ }); + }); + export function bigint(params) { + return core._bigint(ZodBigInt, params); +@@ -519,8 +958,8 @@ export const ZodDate = /*@__PURE__*/ core.$constructor("ZodDate", (inst, def) => + core.$ZodDate.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.dateProcessor(inst, ctx, json, params); +- inst.min = (value, params) => inst.check(checks.gte(value, params)); +- inst.max = (value, params) => inst.check(checks.lte(value, params)); ++ _initProto(inst, "__min__", { min: _sharedDateMin }); ++ _initProto(inst, "__max__", { max: _sharedDateMax }); + const c = inst._zod.bag; + inst.minDate = c.minimum ? new Date(c.minimum) : null; + inst.maxDate = c.maximum ? new Date(c.maximum) : null; +@@ -533,11 +972,11 @@ export const ZodArray = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def) + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.arrayProcessor(inst, ctx, json, params); + inst.element = def.element; +- inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params)); +- inst.nonempty = (params) => inst.check(checks.minLength(1, params)); +- inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params)); +- inst.length = (len, params) => inst.check(checks.length(len, params)); +- inst.unwrap = () => inst.element; ++ _initProto(inst, "__min__", { min: _sharedArrMin }); ++ _initProto(inst, "__nonempty__", { nonempty: _sharedArrNonempty }); ++ _initProto(inst, "__max__", { max: _sharedArrMax }); ++ _initProto(inst, "__length__", { length: _sharedArrLength }); ++ _initProto(inst, "__unwrap__", { unwrap: _sharedArrUnwrap }); + }); + export function array(element, params) { + return core._array(ZodArray, element, params); +@@ -554,23 +993,19 @@ export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def + util.defineLazy(inst, "shape", () => { + return def.shape; + }); +- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)); +- inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall }); +- inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() }); +- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() }); +- inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() }); +- inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined }); +- inst.extend = (incoming) => { +- return util.extend(inst, incoming); +- }; +- inst.safeExtend = (incoming) => { +- return util.safeExtend(inst, incoming); +- }; +- inst.merge = (other) => util.merge(inst, other); +- inst.pick = (mask) => util.pick(inst, mask); +- inst.omit = (mask) => util.omit(inst, mask); +- inst.partial = (...args) => util.partial(ZodOptional, inst, args[0]); +- inst.required = (...args) => util.required(ZodNonOptional, inst, args[0]); ++ _initProto(inst, "__keyof__", { keyof: _sharedObjKeyof }); ++ _initProto(inst, "__catchall__", { catchall: _sharedObjCatchall }); ++ _initProto(inst, "__passthrough__", { passthrough: _sharedObjPassthrough }); ++ _initProto(inst, "__loose__", { loose: _sharedObjLoose }); ++ _initProto(inst, "__strict__", { strict: _sharedObjStrict }); ++ _initProto(inst, "__strip__", { strip: _sharedObjStrip }); ++ _initProto(inst, "__extend__", { extend: _sharedObjExtend }); ++ _initProto(inst, "__safeExtend__", { safeExtend: _sharedObjSafeExtend }); ++ _initProto(inst, "__merge__", { merge: _sharedObjMerge }); ++ _initProto(inst, "__pick__", { pick: _sharedObjPick }); ++ _initProto(inst, "__omit__", { omit: _sharedObjOmit }); ++ _initProto(inst, "__partial__", { partial: _sharedObjPartial }); ++ _initProto(inst, "__required__", { required: _sharedObjRequired }); + }); + export function object(shape, params) { + const def = { +@@ -657,10 +1092,7 @@ export const ZodTuple = /*@__PURE__*/ core.$constructor("ZodTuple", (inst, def) + core.$ZodTuple.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.tupleProcessor(inst, ctx, json, params); +- inst.rest = (rest) => inst.clone({ +- ...inst._zod.def, +- rest: rest, +- }); ++ _initProto(inst, "__rest__", { rest: _sharedTupleRest }); + }); + export function tuple(items, _paramsOrRest, _params) { + const hasRest = _paramsOrRest instanceof core.$ZodType; +@@ -714,10 +1146,10 @@ export const ZodMap = /*@__PURE__*/ core.$constructor("ZodMap", (inst, def) => { + inst._zod.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params); + inst.keyType = def.keyType; + inst.valueType = def.valueType; +- inst.min = (...args) => inst.check(core._minSize(...args)); +- inst.nonempty = (params) => inst.check(core._minSize(1, params)); +- inst.max = (...args) => inst.check(core._maxSize(...args)); +- inst.size = (...args) => inst.check(core._size(...args)); ++ _initProto(inst, "__min__", { min: _sharedSizeMin }); ++ _initProto(inst, "__nonempty__", { nonempty: _sharedSizeNonempty }); ++ _initProto(inst, "__max__", { max: _sharedSizeMax }); ++ _initProto(inst, "__size__", { size: _sharedSize }); + }); + export function map(keyType, valueType, params) { + return new ZodMap({ +@@ -731,10 +1163,10 @@ export const ZodSet = /*@__PURE__*/ core.$constructor("ZodSet", (inst, def) => { + core.$ZodSet.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.setProcessor(inst, ctx, json, params); +- inst.min = (...args) => inst.check(core._minSize(...args)); +- inst.nonempty = (params) => inst.check(core._minSize(1, params)); +- inst.max = (...args) => inst.check(core._maxSize(...args)); +- inst.size = (...args) => inst.check(core._size(...args)); ++ _initProto(inst, "__min__", { min: _sharedSizeMin }); ++ _initProto(inst, "__nonempty__", { nonempty: _sharedSizeNonempty }); ++ _initProto(inst, "__max__", { max: _sharedSizeMax }); ++ _initProto(inst, "__size__", { size: _sharedSize }); + }); + export function set(valueType, params) { + return new ZodSet({ +@@ -749,39 +1181,8 @@ export const ZodEnum = /*@__PURE__*/ core.$constructor("ZodEnum", (inst, def) => + inst._zod.processJSONSchema = (ctx, json, params) => processors.enumProcessor(inst, ctx, json, params); + inst.enum = def.entries; + inst.options = Object.values(def.entries); +- const keys = new Set(Object.keys(def.entries)); +- inst.extract = (values, params) => { +- const newEntries = {}; +- for (const value of values) { +- if (keys.has(value)) { +- newEntries[value] = def.entries[value]; +- } +- else +- throw new Error(`Key ${value} not found in enum`); +- } +- return new ZodEnum({ +- ...def, +- checks: [], +- ...util.normalizeParams(params), +- entries: newEntries, +- }); +- }; +- inst.exclude = (values, params) => { +- const newEntries = { ...def.entries }; +- for (const value of values) { +- if (keys.has(value)) { +- delete newEntries[value]; +- } +- else +- throw new Error(`Key ${value} not found in enum`); +- } +- return new ZodEnum({ +- ...def, +- checks: [], +- ...util.normalizeParams(params), +- entries: newEntries, +- }); +- }; ++ _initProto(inst, "__extract__", { extract: _sharedEnumExtract }); ++ _initProto(inst, "__exclude__", { exclude: _sharedEnumExclude }); + }); + function _enum(values, params) { + const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values; +@@ -831,9 +1232,9 @@ export const ZodFile = /*@__PURE__*/ core.$constructor("ZodFile", (inst, def) => + core.$ZodFile.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.fileProcessor(inst, ctx, json, params); +- inst.min = (size, params) => inst.check(core._minSize(size, params)); +- inst.max = (size, params) => inst.check(core._maxSize(size, params)); +- inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params)); ++ _initProto(inst, "__min__", { min: _sharedFileMin }); ++ _initProto(inst, "__max__", { max: _sharedFileMax }); ++ _initProto(inst, "__mime__", { mime: _sharedFileMime }); + }); + export function file(params) { + return core._file(ZodFile, params); +@@ -883,7 +1284,7 @@ export const ZodOptional = /*@__PURE__*/ core.$constructor("ZodOptional", (inst, + core.$ZodOptional.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function optional(innerType) { + return new ZodOptional({ +@@ -895,7 +1296,7 @@ export const ZodExactOptional = /*@__PURE__*/ core.$constructor("ZodExactOptiona + core.$ZodExactOptional.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function exactOptional(innerType) { + return new ZodExactOptional({ +@@ -907,7 +1308,7 @@ export const ZodNullable = /*@__PURE__*/ core.$constructor("ZodNullable", (inst, + core.$ZodNullable.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.nullableProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function nullable(innerType) { + return new ZodNullable({ +@@ -923,8 +1324,8 @@ export const ZodDefault = /*@__PURE__*/ core.$constructor("ZodDefault", (inst, d + core.$ZodDefault.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.defaultProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; +- inst.removeDefault = inst.unwrap; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); ++ _initProto(inst, "__removeDefault__", { removeDefault: _sharedUnwrap }); + }); + export function _default(innerType, defaultValue) { + return new ZodDefault({ +@@ -939,7 +1340,7 @@ export const ZodPrefault = /*@__PURE__*/ core.$constructor("ZodPrefault", (inst, + core.$ZodPrefault.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.prefaultProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function prefault(innerType, defaultValue) { + return new ZodPrefault({ +@@ -954,7 +1355,7 @@ export const ZodNonOptional = /*@__PURE__*/ core.$constructor("ZodNonOptional", + core.$ZodNonOptional.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.nonoptionalProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function nonoptional(innerType, params) { + return new ZodNonOptional({ +@@ -967,7 +1368,7 @@ export const ZodSuccess = /*@__PURE__*/ core.$constructor("ZodSuccess", (inst, d + core.$ZodSuccess.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.successProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function success(innerType) { + return new ZodSuccess({ +@@ -979,8 +1380,8 @@ export const ZodCatch = /*@__PURE__*/ core.$constructor("ZodCatch", (inst, def) + core.$ZodCatch.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.catchProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; +- inst.removeCatch = inst.unwrap; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); ++ _initProto(inst, "__removeCatch__", { removeCatch: _sharedUnwrap }); + }); + function _catch(innerType, catchValue) { + return new ZodCatch({ +@@ -1030,7 +1431,7 @@ export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, + core.$ZodReadonly.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.readonlyProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function readonly(innerType) { + return new ZodReadonly({ +@@ -1054,7 +1455,7 @@ export const ZodLazy = /*@__PURE__*/ core.$constructor("ZodLazy", (inst, def) => + core.$ZodLazy.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.lazyProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.getter(); ++ _initProto(inst, "__unwrap__", { unwrap: _sharedLazyUnwrap }); + }); + export function lazy(getter) { + return new ZodLazy({ +@@ -1066,7 +1467,7 @@ export const ZodPromise = /*@__PURE__*/ core.$constructor("ZodPromise", (inst, d + core.$ZodPromise.init(inst, def); + ZodType.init(inst, def); + inst._zod.processJSONSchema = (ctx, json, params) => processors.promiseProcessor(inst, ctx, json, params); +- inst.unwrap = () => inst._zod.def.innerType; ++ _initProto(inst, "__unwrap__", { unwrap: _sharedUnwrap }); + }); + export function promise(innerType) { + return new ZodPromise({ +diff --git a/node_modules/zod/v4/core/core.cjs b/node_modules/zod/v4/core/core.cjs +index 937f35e..6a9ee27 100644 +--- a/node_modules/zod/v4/core/core.cjs ++++ b/node_modules/zod/v4/core/core.cjs +@@ -1,12 +1,26 @@ + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +-exports.globalConfig = exports.$ZodEncodeError = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0; ++exports.globalConfig = exports.$ZodEncodeError = exports.$ZodAsyncError = exports.$brand = exports.$internalProto = exports.NEVER = void 0; + exports.$constructor = $constructor; + exports.config = config; + /** A special constant with type `never` */ + exports.NEVER = Object.freeze({ + status: "aborted", + }); ++/** ++ * Symbol used to access the internal prototype of a Zod constructor. ++ * ++ * Each constructor created by `$constructor` maintains two prototype layers: ++ * inst → _.prototype (user-visible; copy-loop targets this) ++ * └── internalProto (library methods set by _initProto go here) ++ * ++ * Keeping library methods one layer below the user-visible prototype means the ++ * copy-loop is a no-op for default schemas (_.prototype is empty), which ++ * prevents V8 dictionary-mode degradation caused by too many own properties. ++ * User prototype extensions still work exactly as before: adding a method to ++ * e.g. `z.ZodType.prototype` triggers the copy-loop for every new instance. ++ */ ++exports.$internalProto = Symbol("zod.internalProto"); + function $constructor(name, initializer, params) { + function init(inst, def) { + if (!inst._zod) { +@@ -25,6 +39,11 @@ function $constructor(name, initializer, params) { + inst._zod.traits.add(name); + initializer(inst, def); + // support prototype modifications ++ // _.prototype is the user-visible layer (empty by default). When users add ++ // methods there (e.g. z.ZodType.prototype.myHelper = fn) those methods are ++ // copied to new instances here, preserving the original extension contract. ++ // Library methods live on internalProto (one level below), so they are ++ // never enumerated by Object.keys(_.prototype) and never copied to instances. + const proto = _.prototype; + const keys = Object.keys(proto); + for (let i = 0; i < keys.length; i++) { +@@ -39,6 +58,11 @@ function $constructor(name, initializer, params) { + class Definition extends Parent { + } + Object.defineProperty(Definition, "name", { value: name }); ++ // Internal prototype layer: library-owned methods (_initProto targets this). ++ // Sits between _.prototype (user space) and the Parent prototype so that ++ // Object.keys(_.prototype) always returns only user-added keys. ++ const internalProto = Object.create(params?.Parent?.prototype ?? Object.prototype); ++ Object.setPrototypeOf(Definition.prototype, internalProto); + function _(def) { + var _a; + const inst = params?.Parent ? new Definition() : this; +@@ -49,6 +73,8 @@ function $constructor(name, initializer, params) { + } + return inst; + } ++ // Expose internalProto so that _initProto (in schemas.ts) can find it. ++ Object.defineProperty(_, exports.$internalProto, { value: internalProto }); + Object.defineProperty(_, "init", { value: init }); + Object.defineProperty(_, Symbol.hasInstance, { + value: (inst) => { +@@ -58,6 +84,9 @@ function $constructor(name, initializer, params) { + }, + }); + Object.defineProperty(_, "name", { value: name }); ++ // Wire _.prototype → internalProto so that instance prototype chain is: ++ // inst → _.prototype (user space) → internalProto (library space) → Parent ++ Object.setPrototypeOf(_.prototype, internalProto); + return _; + } + ////////////////////////////// UTILITIES /////////////////////////////////////// +diff --git a/node_modules/zod/v4/core/core.js b/node_modules/zod/v4/core/core.js +index 2a32024..d7be196 100644 +--- a/node_modules/zod/v4/core/core.js ++++ b/node_modules/zod/v4/core/core.js +@@ -2,6 +2,20 @@ + export const NEVER = Object.freeze({ + status: "aborted", + }); ++/** ++ * Symbol used to access the internal prototype of a Zod constructor. ++ * ++ * Each constructor created by `$constructor` maintains two prototype layers: ++ * inst → _.prototype (user-visible; copy-loop targets this) ++ * └── internalProto (library methods set by _initProto go here) ++ * ++ * Keeping library methods one layer below the user-visible prototype means the ++ * copy-loop is a no-op for default schemas (_.prototype is empty), which ++ * prevents V8 dictionary-mode degradation caused by too many own properties. ++ * User prototype extensions still work exactly as before: adding a method to ++ * e.g. `z.ZodType.prototype` triggers the copy-loop for every new instance. ++ */ ++export const $internalProto = Symbol("zod.internalProto"); + export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) { + function init(inst, def) { + if (!inst._zod) { +@@ -20,6 +34,11 @@ export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) + inst._zod.traits.add(name); + initializer(inst, def); + // support prototype modifications ++ // _.prototype is the user-visible layer (empty by default). When users add ++ // methods there (e.g. z.ZodType.prototype.myHelper = fn) those methods are ++ // copied to new instances here, preserving the original extension contract. ++ // Library methods live on internalProto (one level below), so they are ++ // never enumerated by Object.keys(_.prototype) and never copied to instances. + const proto = _.prototype; + const keys = Object.keys(proto); + for (let i = 0; i < keys.length; i++) { +@@ -34,6 +53,11 @@ export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) + class Definition extends Parent { + } + Object.defineProperty(Definition, "name", { value: name }); ++ // Internal prototype layer: library-owned methods (_initProto targets this). ++ // Sits between _.prototype (user space) and the Parent prototype so that ++ // Object.keys(_.prototype) always returns only user-added keys. ++ const internalProto = Object.create(params?.Parent?.prototype ?? Object.prototype); ++ Object.setPrototypeOf(Definition.prototype, internalProto); + function _(def) { + var _a; + const inst = params?.Parent ? new Definition() : this; +@@ -44,6 +68,8 @@ export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) + } + return inst; + } ++ // Expose internalProto so that _initProto (in schemas.ts) can find it. ++ Object.defineProperty(_, $internalProto, { value: internalProto }); + Object.defineProperty(_, "init", { value: init }); + Object.defineProperty(_, Symbol.hasInstance, { + value: (inst) => { +@@ -53,6 +79,9 @@ export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) + }, + }); + Object.defineProperty(_, "name", { value: name }); ++ // Wire _.prototype → internalProto so that instance prototype chain is: ++ // inst → _.prototype (user space) → internalProto (library space) → Parent ++ Object.setPrototypeOf(_.prototype, internalProto); + return _; + } + ////////////////////////////// UTILITIES /////////////////////////////////////// +diff --git a/node_modules/zod/v4/mini/schemas.cjs b/node_modules/zod/v4/mini/schemas.cjs +index 0fea79d..5c3039e 100644 +--- a/node_modules/zod/v4/mini/schemas.cjs ++++ b/node_modules/zod/v4/mini/schemas.cjs +@@ -129,33 +129,69 @@ exports.function = _function; + const core = __importStar(require("../core/index.cjs")); + const util = __importStar(require("../core/util.cjs")); + const parse = __importStar(require("./parse.cjs")); ++// Maps (internalProto, key) pairs already initialized — avoids repeated setup ++const _protoInitMap = new WeakMap(); ++/** ++ * Sets shared methods on the *internal* prototype layer of inst's concrete constructor ++ * (once per concrete type per key). See core.ts `$internalProto` for design rationale. ++ */ ++function _initProto(inst, key, methods) { ++ const proto = inst._zod?.constr?.[core.$internalProto] ?? Object.getPrototypeOf(inst); ++ let keys = _protoInitMap.get(proto); ++ if (!keys) { ++ keys = new Set(); ++ _protoInitMap.set(proto, keys); ++ } ++ if (keys.has(key)) ++ return; ++ keys.add(key); ++ Object.assign(proto, methods); ++} ++// Shared mini builder methods (use `this` instead of per-instance closure over `inst`) ++function _sharedMiniCheck(...checks) { ++ const def = this._zod.def; ++ return this.clone({ ++ ...def, ++ checks: [ ++ ...(def.checks ?? []), ++ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), ++ ], ++ }, { parent: true }); ++} ++function _sharedMiniClone(_def, params) { ++ return core.clone(this, _def, params); ++} ++function _sharedMiniBrand() { ++ return this; ++} ++function _sharedMiniRegister(reg, meta) { ++ reg.add(this, meta); ++ return this; ++} ++function _sharedMiniApply(fn) { ++ return fn(this); ++} + exports.ZodMiniType = core.$constructor("ZodMiniType", (inst, def) => { + if (!inst._zod) + throw new Error("Uninitialized schema in ZodMiniType."); + core.$ZodType.init(inst, def); + inst.def = def; + inst.type = def.type; ++ // Parse-family: kept as per-instance closures so detached usage works ++ // const parse = schema.parse; parse("hello"); // must work + inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse }); + inst.safeParse = (data, params) => parse.safeParse(inst, data, params); + inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync }); + inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params); +- inst.check = (...checks) => { +- return inst.clone({ +- ...def, +- checks: [ +- ...(def.checks ?? []), +- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), +- ], +- }, { parent: true }); +- }; +- inst.with = inst.check; +- inst.clone = (_def, params) => core.clone(inst, _def, params); +- inst.brand = () => inst; +- inst.register = ((reg, meta) => { +- reg.add(inst, meta); +- return inst; ++ // Builder methods: placed on the internal prototype once per concrete type ++ _initProto(inst, "ZodMiniType", { ++ check: _sharedMiniCheck, ++ with: _sharedMiniCheck, ++ clone: _sharedMiniClone, ++ brand: _sharedMiniBrand, ++ register: _sharedMiniRegister, ++ apply: _sharedMiniApply, + }); +- inst.apply = (fn) => fn(inst); + }); + exports.ZodMiniString = core.$constructor("ZodMiniString", (inst, def) => { + core.$ZodString.init(inst, def); +diff --git a/node_modules/zod/v4/mini/schemas.js b/node_modules/zod/v4/mini/schemas.js +index 0276617..b5e32b2 100644 +--- a/node_modules/zod/v4/mini/schemas.js ++++ b/node_modules/zod/v4/mini/schemas.js +@@ -1,33 +1,69 @@ + import * as core from "../core/index.js"; + import * as util from "../core/util.js"; + import * as parse from "./parse.js"; ++// Maps (internalProto, key) pairs already initialized — avoids repeated setup ++const _protoInitMap = new WeakMap(); ++/** ++ * Sets shared methods on the *internal* prototype layer of inst's concrete constructor ++ * (once per concrete type per key). See core.ts `$internalProto` for design rationale. ++ */ ++function _initProto(inst, key, methods) { ++ const proto = inst._zod?.constr?.[core.$internalProto] ?? Object.getPrototypeOf(inst); ++ let keys = _protoInitMap.get(proto); ++ if (!keys) { ++ keys = new Set(); ++ _protoInitMap.set(proto, keys); ++ } ++ if (keys.has(key)) ++ return; ++ keys.add(key); ++ Object.assign(proto, methods); ++} ++// Shared mini builder methods (use `this` instead of per-instance closure over `inst`) ++function _sharedMiniCheck(...checks) { ++ const def = this._zod.def; ++ return this.clone({ ++ ...def, ++ checks: [ ++ ...(def.checks ?? []), ++ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), ++ ], ++ }, { parent: true }); ++} ++function _sharedMiniClone(_def, params) { ++ return core.clone(this, _def, params); ++} ++function _sharedMiniBrand() { ++ return this; ++} ++function _sharedMiniRegister(reg, meta) { ++ reg.add(this, meta); ++ return this; ++} ++function _sharedMiniApply(fn) { ++ return fn(this); ++} + export const ZodMiniType = /*@__PURE__*/ core.$constructor("ZodMiniType", (inst, def) => { + if (!inst._zod) + throw new Error("Uninitialized schema in ZodMiniType."); + core.$ZodType.init(inst, def); + inst.def = def; + inst.type = def.type; ++ // Parse-family: kept as per-instance closures so detached usage works ++ // const parse = schema.parse; parse("hello"); // must work + inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse }); + inst.safeParse = (data, params) => parse.safeParse(inst, data, params); + inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync }); + inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params); +- inst.check = (...checks) => { +- return inst.clone({ +- ...def, +- checks: [ +- ...(def.checks ?? []), +- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch), +- ], +- }, { parent: true }); +- }; +- inst.with = inst.check; +- inst.clone = (_def, params) => core.clone(inst, _def, params); +- inst.brand = () => inst; +- inst.register = ((reg, meta) => { +- reg.add(inst, meta); +- return inst; +- }); +- inst.apply = (fn) => fn(inst); ++ // Builder methods: placed on the internal prototype once per concrete type ++ _initProto(inst, "ZodMiniType", { ++ check: _sharedMiniCheck, ++ with: _sharedMiniCheck, ++ clone: _sharedMiniClone, ++ brand: _sharedMiniBrand, ++ register: _sharedMiniRegister, ++ apply: _sharedMiniApply, ++ }); + }); + export const ZodMiniString = /*@__PURE__*/ core.$constructor("ZodMiniString", (inst, def) => { + core.$ZodString.init(inst, def); diff --git a/renovate.json b/renovate.json index 0f7f2e27ab277..0ddf86d0b978a 100644 --- a/renovate.json +++ b/renovate.json @@ -2641,6 +2641,15 @@ "addLabels": ["Team:EUI"], "minimumReleaseAge": "14 days", "enabled": true + }, + { + "groupName": "patch-package", + "matchDepNames": ["patch-package"], + "reviewers": ["team:kibana-operations"], + "matchBaseBranches": ["main"], + "addLabels": ["Team:Operations"], + "minimumReleaseAge": "14 days", + "enabled": true } ], "customManagers": [ diff --git a/src/dev/kbn_pm/src/commands/bootstrap/bootstrap_command.mjs b/src/dev/kbn_pm/src/commands/bootstrap/bootstrap_command.mjs index 85a958307f861..48f17845ab9c3 100644 --- a/src/dev/kbn_pm/src/commands/bootstrap/bootstrap_command.mjs +++ b/src/dev/kbn_pm/src/commands/bootstrap/bootstrap_command.mjs @@ -138,6 +138,20 @@ export const command = { await runInstallScripts(log, { quiet }); }) : undefined, + shouldInstall + ? time('apply node_modules patches', async () => { + log.info('applying node_modules patches via patch-package'); + // The patch-package command is used to apply patches to the node_modules directory. + // At the time of writing, the following packages are patched: + // - zod@4.3.6 => memory regression introduced in 4.x (see https://github.com/colinhacks/zod/issues/5760) + // The libraries above should not be updated, as doing so would break the patches. + await run('node', ['node_modules/.bin/patch-package', '--error-on-fail'], { + pipe: !quiet, + description: 'patch-package', + }); + log.success('node_modules patches applied'); + }) + : undefined, ]); await time('sort package json', async () => { diff --git a/yarn.lock b/yarn.lock index 720691c5065f3..444dc9944fb51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18057,7 +18057,7 @@ chromium-bidi@13.1.1: mitt "^3.0.1" zod "^3.24.1" -ci-info@^3.2.0: +ci-info@^3.2.0, ci-info@^3.7.0: version "3.8.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.8.0.tgz#81408265a5380c929f0bc665d62256628ce9ef91" integrity sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw== @@ -22219,6 +22219,13 @@ find-up@^8.0.0: locate-path "^8.0.0" unicorn-magic "^0.3.0" +find-yarn-workspace-root@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd" + integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ== + dependencies: + micromatch "^4.0.2" + fix-esm@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/fix-esm/-/fix-esm-1.0.1.tgz#e0e2199d841e43ff7db9b5f5ba7496bc45130ebb" @@ -23074,7 +23081,7 @@ gpt-tokenizer@2.6.2: resolved "https://registry.yarnpkg.com/gpt-tokenizer/-/gpt-tokenizer-2.6.2.tgz#90e6932c7b5f73df7c13d360802edb43a2776586" integrity sha512-OznIET3z069FiwbLtLFXJ9pVESYAa8EnX0BMogs6YJ4Fn2FIcyeZYEbxsp2grPiK0DVaqP1f+0JR/8t9R7/jlg== -graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.8, graceful-fs@^4.2.9: +graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.8, graceful-fs@^4.2.9: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -24736,7 +24743,7 @@ is-word-character@^1.0.0: resolved "https://registry.yarnpkg.com/is-word-character/-/is-word-character-1.0.1.tgz#5a03fa1ea91ace8a6eb0c7cd770eb86d65c8befb" integrity sha1-WgP6HqkazopusMfNdw64bWXIvvs= -is-wsl@^2.2.0: +is-wsl@^2.1.1, is-wsl@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== @@ -25597,7 +25604,7 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= -json-stable-stringify@^1.0.1: +json-stable-stringify@^1.0.1, json-stable-stringify@^1.0.2: version "1.3.0" resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.3.0.tgz#8903cfac42ea1a0f97f35d63a4ce0518f0cc6a70" integrity sha512-qtYiSSFlwot9XHtF9bD9c7rwKjr+RecWT//ZnPvSmEjpV5mmPOCN4j8UjY5hbjNkOwZ/jQv3J6R1/pL7RwgMsg== @@ -25830,6 +25837,13 @@ kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + kleur@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" @@ -28346,6 +28360,14 @@ open@^10.0.3: is-inside-container "^1.0.0" is-wsl "^3.1.0" +open@^7.4.2: + version "7.4.2" + resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" + integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q== + dependencies: + is-docker "^2.0.0" + is-wsl "^2.1.1" + open@^8.0.4, open@^8.4.0, open@~8.4.0: version "8.4.2" resolved "https://registry.yarnpkg.com/open/-/open-8.4.2.tgz#5b5ffe2a8f793dcd2aad73e550cb87b59cb084f9" @@ -28880,6 +28902,26 @@ patch-console@^2.0.0: resolved "https://registry.yarnpkg.com/patch-console/-/patch-console-2.0.0.tgz#9023f4665840e66f40e9ce774f904a63167433bb" integrity sha512-0YNdUceMdaQwoKce1gatDScmMo5pu/tfABfnzEqeG0gtTmd7mh/WcwgUjtAeOU7N8nFFlbQBnFK2gXW5fGvmMA== +patch-package@8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-8.0.1.tgz#79d02f953f711e06d1f8949c8a13e5d3d7ba1a60" + integrity sha512-VsKRIA8f5uqHQ7NGhwIna6Bx6D9s/1iXlA1hthBVBEbkq+t4kXD0HHt+rJhf/Z+Ci0F/HCB2hvn0qLdLG+Qxlw== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^4.1.2" + ci-info "^3.7.0" + cross-spawn "^7.0.3" + find-yarn-workspace-root "^2.0.0" + fs-extra "^10.0.0" + json-stable-stringify "^1.0.2" + klaw-sync "^6.0.0" + minimist "^1.2.6" + open "^7.4.2" + semver "^7.5.3" + slash "^2.0.0" + tmp "^0.2.4" + yaml "^2.2.2" + path-browserify@^1.0.0, path-browserify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd" @@ -33878,7 +33920,7 @@ tmp@^0.0.33: dependencies: os-tmpdir "~1.0.2" -tmp@^0.2.5, tmp@~0.2.4: +tmp@^0.2.4, tmp@^0.2.5, tmp@~0.2.4: version "0.2.5" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.5.tgz#b06bcd23f0f3c8357b426891726d16015abfd8f8" integrity sha512-voyz6MApa1rQGUxT3E+BK7/ROe8itEx7vD8/HEvt4xwXucvQ5G5oeEiHkmHZJuBO21RpOf+YYm9MOivj709jow== @@ -36130,7 +36172,7 @@ yaml@2.7.1: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.7.1.tgz#44a247d1b88523855679ac7fa7cda6ed7e135cf6" integrity sha512-10ULxpnOCQXxJvBgxsn9ptjq6uviG/htZKk9veJGhlqn3w/DxQ631zFF+nlQXLwmImeS5amR2dl2U8sg6U9jsQ== -yaml@2.8.3: +yaml@2.8.3, yaml@^2.2.2: version "2.8.3" resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.8.3.tgz#a0d6bd2efb3dd03c59370223701834e60409bd7d" integrity sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg==