cvx-kit 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,5 +43,7 @@ interface NativeRecipe {
43
43
  }
44
44
  /** Nonthrowing eligibility only; native factories run at the original conversion stage. */
45
45
  export declare function classifyDto(recipe: DtoRecipe): NativeRecipe | undefined;
46
+ /** Eligibility only; hostile configuration readers keep the reconstruction path. */
47
+ export declare function ordinaryDtoConstruction(): boolean;
46
48
  //#endregion
47
49
  //# sourceMappingURL=schema-snapshot.d.mts.map
@@ -1,2 +1,2 @@
1
- import{zodToConvex as e}from"../zod-convex.mjs";import{zid as t}from"convex-helpers/server/zod4";import{z as n}from"zod";import{v as r}from"convex/values";import{vRequired as i}from"convex-helpers/validators";const a=/* @__PURE__ */ new Map,o=[];w(`object`,n.ZodObject,`ZodObject`),w(`array`,n.ZodArray,`ZodArray`),w(`optional`,n.ZodOptional,`ZodOptional`),w(`exactOptional`,n.ZodExactOptional,`ZodExactOptional`),w(`nullable`,n.ZodNullable,`ZodNullable`),w(`nonoptional`,n.ZodNonOptional,`ZodNonOptional`),w(`union`,n.ZodUnion,`ZodUnion`),w(`discriminatedUnion`,n.ZodDiscriminatedUnion,`ZodDiscriminatedUnion`),w(`tuple`,n.ZodTuple,`ZodTuple`),w(`record`,n.ZodRecord,`ZodRecord`),w(`string`,n.ZodString,`ZodString`),w(`number`,n.ZodNumber,`ZodNumber`),w(`boolean`,n.ZodBoolean,`ZodBoolean`),w(`bigint`,n.ZodBigInt,`ZodBigInt`),w(`null`,n.ZodNull,`ZodNull`),w(`never`,n.ZodNever,`ZodNever`),w(`literal`,n.ZodLiteral,`ZodLiteral`),w(`enum`,n.ZodEnum,`ZodEnum`),w(`custom`,n.ZodCustom,`ZodCustom`),w(`minLength`,n.core.$ZodCheckMinLength,`$ZodCheckMinLength`),w(`maxLength`,n.core.$ZodCheckMaxLength,`$ZodCheckMaxLength`),w(`length`,n.core.$ZodCheckLengthEquals,`$ZodCheckLengthEquals`),w(`lessThan`,n.core.$ZodCheckLessThan,`$ZodCheckLessThan`),w(`greaterThan`,n.core.$ZodCheckGreaterThan,`$ZodCheckGreaterThan`),w(`multipleOf`,n.core.$ZodCheckMultipleOf,`$ZodCheckMultipleOf`),w(`checkNumberFormat`,n.core.$ZodCheckNumberFormat,`$ZodCheckNumberFormat`),w(`checkBigintFormat`,n.core.$ZodCheckBigIntFormat,`$ZodCheckBigIntFormat`),w(`stringFormat`,n.core.$ZodCheckStringFormat,`$ZodCheckStringFormat`),w(`regex`,n.core.$ZodCheckRegex,`$ZodCheckRegex`),w(`lowercase`,n.core.$ZodCheckLowerCase,`$ZodCheckLowerCase`),w(`uppercase`,n.core.$ZodCheckUpperCase,`$ZodCheckUpperCase`),w(`includes`,n.core.$ZodCheckIncludes,`$ZodCheckIncludes`),w(`startsWith`,n.core.$ZodCheckStartsWith,`$ZodCheckStartsWith`),w(`endsWith`,n.core.$ZodCheckEndsWith,`$ZodCheckEndsWith`),w(`property`,n.core.$ZodCheckProperty,`$ZodCheckProperty`),w(`properties`,n.core.$ZodCheckProperties,`$ZodCheckProperties`),w(`numberFormat`,n.ZodNumberFormat,`ZodNumberFormat`),w(`bigintFormat`,n.ZodBigIntFormat,`ZodBigIntFormat`),w(`coreEmail`,n.core.$ZodEmail,`$ZodEmail`),w(`coreGUID`,n.core.$ZodGUID,`$ZodGUID`),w(`coreUUID`,n.core.$ZodUUID,`$ZodUUID`),w(`coreURL`,n.core.$ZodURL,`$ZodURL`),w(`coreEmoji`,n.core.$ZodEmoji,`$ZodEmoji`),w(`coreNanoID`,n.core.$ZodNanoID,`$ZodNanoID`),w(`coreCUID`,n.core.$ZodCUID,`$ZodCUID`),w(`coreCUID2`,n.core.$ZodCUID2,`$ZodCUID2`),w(`coreULID`,n.core.$ZodULID,`$ZodULID`),w(`coreXID`,n.core.$ZodXID,`$ZodXID`),w(`coreKSUID`,n.core.$ZodKSUID,`$ZodKSUID`),w(`coreIPv4`,n.core.$ZodIPv4,`$ZodIPv4`),w(`coreIPv6`,n.core.$ZodIPv6,`$ZodIPv6`),w(`coreMAC`,n.core.$ZodMAC,`$ZodMAC`),w(`coreCIDRv4`,n.core.$ZodCIDRv4,`$ZodCIDRv4`),w(`coreCIDRv6`,n.core.$ZodCIDRv6,`$ZodCIDRv6`),w(`coreBase64`,n.core.$ZodBase64,`$ZodBase64`),w(`coreBase64URL`,n.core.$ZodBase64URL,`$ZodBase64URL`),w(`coreE164`,n.core.$ZodE164,`$ZodE164`),w(`coreJWT`,n.core.$ZodJWT,`$ZodJWT`),w(`coreISODateTime`,n.core.$ZodISODateTime,`$ZodISODateTime`),w(`coreISODate`,n.core.$ZodISODate,`$ZodISODate`),w(`coreISOTime`,n.core.$ZodISOTime,`$ZodISOTime`),w(`coreISODuration`,n.core.$ZodISODuration,`$ZodISODuration`),w(`coreCreditCard`,n.core.$ZodCreditCard,`$ZodCreditCard`),w(`coreIBAN`,n.core.$ZodIBAN,`$ZodIBAN`),w(`coreCustomStringFormat`,n.core.$ZodCustomStringFormat,`$ZodCustomStringFormat`),w(`email`,n.ZodEmail,`ZodEmail`),w(`guid`,n.ZodGUID,`ZodGUID`),w(`uuid`,n.ZodUUID,`ZodUUID`),w(`url`,n.ZodURL,`ZodURL`),w(`emoji`,n.ZodEmoji,`ZodEmoji`),w(`nanoid`,n.ZodNanoID,`ZodNanoID`),w(`cuid`,n.ZodCUID,`ZodCUID`),w(`cuid2`,n.ZodCUID2,`ZodCUID2`),w(`ulid`,n.ZodULID,`ZodULID`),w(`xid`,n.ZodXID,`ZodXID`),w(`ksuid`,n.ZodKSUID,`ZodKSUID`),w(`ipv4`,n.ZodIPv4,`ZodIPv4`),w(`ipv6`,n.ZodIPv6,`ZodIPv6`),w(`mac`,n.ZodMAC,`ZodMAC`),w(`cidrv4`,n.ZodCIDRv4,`ZodCIDRv4`),w(`cidrv6`,n.ZodCIDRv6,`ZodCIDRv6`),w(`base64`,n.ZodBase64,`ZodBase64`),w(`base64url`,n.ZodBase64URL,`ZodBase64URL`),w(`e164`,n.ZodE164,`ZodE164`),w(`jwt`,n.ZodJWT,`ZodJWT`),w(`isoDateTime`,n.ZodISODateTime,`ZodISODateTime`),w(`isoDate`,n.ZodISODate,`ZodISODate`),w(`isoTime`,n.ZodISOTime,`ZodISOTime`),w(`isoDuration`,n.ZodISODuration,`ZodISODuration`),w(`creditCard`,n.ZodCreditCard,`ZodCreditCard`),w(`iban`,n.ZodIBAN,`ZodIBAN`),w(`customStringFormat`,n.ZodCustomStringFormat,`ZodCustomStringFormat`);const s=[...a.entries()].reverse(),c=new Map(o.map(({trait:e,rank:t,name:n})=>[e,Object.freeze({rank:t,entry:Object.freeze([n,a.get(n)])})])),l=[`4.5.4`,`4.6.5`].includes(`${n.core.version.major}.${n.core.version.minor}.${n.core.version.patch}`),u=Set.prototype.has,d=Set.prototype.forEach;function f(e){let t=/* @__PURE__ */ new WeakMap,r=/* @__PURE__ */ new WeakSet,i=0;function a(e,o){if(e===null||Object(e)!==e||e instanceof Function)return Object.freeze({kind:`value`,value:e});let c=e;if(r.has(c))throw Error(`Unsupported cyclic DTO schema`);let l=t.get(c);if(l)return l;if(o>64||++i>8192)throw Error(`DTO schema graph budget exceeded`);r.add(c);let u;if(e instanceof RegExp)u={kind:`regexp`,source:e.source,flags:e.flags};else if(e instanceof n.core.$ZodType||e instanceof n.core.$ZodCheck){if(e instanceof n.core.$ZodCheck&&e._zod.def.check===`custom`&&!(e instanceof n.ZodCustom))throw Error(`Unsupported opaque DTO check/superRefine; use .refine() instead`);let t=x(e)??s.find(([,t])=>t.matches(e));if(!t)throw Error(`Unsupported DTO schema or check`);let r;if(e instanceof n.ZodCustom){let t=C(e);t.kind===`id`&&(r=t.tableName)}let i=e instanceof n.ZodObject?{...e._zod.def,shape:e.shape}:e._zod.def;u={kind:`node`,constructor:t[0],definition:a(i,o+1),id:r}}else if(Array.isArray(e))u={kind:`array`,items:Object.freeze(e.map(e=>a(e,o+1)))};else{if(Object.hasOwn(c,`_zod`))throw Error(`Unsupported opaque DTO check/superRefine; use .refine() instead`);if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw Error(`Unsupported DTO definition object`);let t=[];for(let e of Reflect.ownKeys(c)){if(String(e)!==e)throw Error(`Unsupported DTO definition symbol`);let n=Object.getOwnPropertyDescriptor(c,e);if(!(`value`in n))throw Error(`Unsupported DTO schema accessor`);t.push(Object.freeze([e,a(n.value,o+1)]))}u={kind:`record`,entries:Object.freeze(t)}}return r.delete(c),Object.freeze(u),t.set(c,u),u}return Object.freeze({root:a(e,0)})}const p=/* @__PURE__ */ new WeakMap;function m(e){let t=S(e.root)();if(!(t instanceof n.ZodType))throw Error(`Expected classic DTO schema`);return t}n.object({});const h=n.core.globalConfig,g=Object.getOwnPropertyDescriptors(h),_=n.core.memoizer(),v=Object.getOwnPropertyDescriptors(_),y={string:[`coerce`],number:[`coerce`],boolean:[`coerce`],bigint:[`coerce`],null:[],never:[],literal:[`values`],object:[`shape`,`catchall`],array:[`element`],optional:[`innerType`],nullable:[`innerType`],union:[`options`],discriminatedUnion:[`options`,`discriminator`,`inclusive`],custom:[`check`,`fn`,`abort`]};function b(e){try{if(!E())return}catch{return}let t=/* @__PURE__ */ new Map;function n(e){if(!e||e.kind!==`node`)return;if(t.has(e))return t.get(e);let a=Object.hasOwn(y,e.constructor)?y[e.constructor]:void 0;if(!a||e.definition.kind!==`record`)return;let o=new Map(e.definition.entries);if([...o.keys()].some(e=>![`type`,`checks`,...a].includes(e))||D(o.get(`type`))!==(e.constructor===`discriminatedUnion`?`union`:e.constructor)||o.has(`checks`)&&O(o.get(`checks`))?.length!==0||o.has(`coerce`)&&typeof D(o.get(`coerce`))!=`boolean`)return;let s;switch(e.constructor){case`string`:s={emit:()=>r.string()};break;case`number`:s={emit:()=>r.number()};break;case`boolean`:s={emit:()=>r.boolean()};break;case`bigint`:s={emit:()=>r.int64()};break;case`null`:s={emit:()=>r.null()};break;case`never`:s={emit:()=>r.union()};break;case`custom`:{let t=e.id;if(typeof t!=`string`||D(o.get(`check`))!==`custom`||typeof D(o.get(`fn`))!=`function`||o.has(`abort`)&&typeof D(o.get(`abort`))!=`boolean`)return;s={emit:()=>r.id(t)};break}case`literal`:{let e=O(o.get(`values`));if(!e)return;let t=[];for(let n of e){if(n.kind!==`value`)return;let e=n.value;if(e!==null&&typeof e!=`string`&&typeof e!=`boolean`&&typeof e!=`bigint`&&!(typeof e==`number`&&Number.isFinite(e)))return;t.push(e)}s={literal:t,emit:()=>{let e=t.map(e=>e===null?r.null():r.literal(e));return e.length===1?e[0]:r.union(...e)}};break}case`object`:{let e=o.get(`shape`);if(e?.kind!==`record`)return;let t=/* @__PURE__ */ new Map;for(let[r,i]of e.entries){let e=n(i);if(!e)return;t.set(r,e)}let i=o.get(`catchall`);if(i&&(i.kind!==`value`||i.value!==void 0)&&!n(i))return;s={fields:t,boundary:{kind:`object`,keys:[...t.keys()]},emit:()=>r.object(Object.fromEntries([...t].map(([e,t])=>[e,t.emit()])))};break}case`array`:case`optional`:case`nullable`:{let t=n(o.get(e.constructor===`array`?`element`:`innerType`));if(!t)return;let a=e.constructor;s={emit:()=>{let e=t.emit();if(a===`optional`)return r.optional(e);if(a===`nullable`)return e.isOptional===`optional`?r.optional(r.union(i(e),r.null())):r.union(e,r.null());if(e.isOptional===`optional`)throw Error(`Arrays of optional values are not supported`);return r.array(e)}};break}case`union`:case`discriminatedUnion`:{let t=O(o.get(`options`));if(!t)return;let i=[];for(let e of t){let t=n(e);if(!t)return;i.push(t)}let a;if(e.constructor===`discriminatedUnion`){let e=D(o.get(`discriminator`));if(typeof e!=`string`||!i.length||o.has(`inclusive`)&&D(o.get(`inclusive`))!==!1)return;let t=Object.create(null);for(let n of i){let r=n.fields?.get(e)?.literal;if(n.boundary?.kind!==`object`||r?.length!==1||typeof r[0]!=`string`||Object.hasOwn(t,r[0]))return;t[r[0]]=n.boundary.keys}a={kind:`variant`,discriminator:e,branches:t}}s={boundary:a,emit:()=>r.union(...i.map(e=>e.emit()))};break}}return t.set(e,s),s}return n(e.root)}function x(e){if(l)try{let t=Object.getOwnPropertyDescriptor(e,`_zod`);if(!t||!(`value`in t)||t.value===null||typeof t.value!=`object`)return;let n=Object.getOwnPropertyDescriptor(t.value,`traits`);if(!n||!(`value`in n))return;let r=n.value;if(typeof r!=`object`||!r||Object.getPrototypeOf(r)!==Set.prototype||Object.getOwnPropertyDescriptor(r,`has`))return;let i=Object.getOwnPropertyDescriptor(Set.prototype,`has`);if(!i||!(`value`in i)||i.value!==u)return;u.call(r,``);let a,o=-1;return d.call(r,e=>{if(typeof e!=`string`)return;let t=c.get(e);t&&t.rank>o&&(o=t.rank,a=t.entry)}),a}catch{return}}function S(e){let n=p.get(e);if(n)return n;let r;switch(e.kind){case`value`:r=()=>e.value;break;case`regexp`:r=()=>new RegExp(e.source,e.flags);break;case`array`:{let t=e.items.map(S);r=()=>t.map(e=>e());break}case`record`:{let t=e.entries.map(([e,t])=>[e,S(t)]);r=()=>Object.fromEntries(t.map(([e,t])=>[e,t()]));break}case`node`:{let n=S(e.definition);if(e.id!==void 0){let i=e.id;r=()=>{let e=n(),r=t(i);if(e instanceof Object&&`checks`in e){let t=e.checks;if(Array.isArray(t))return r.check(...t)}return r}}else{let t=a.get(e.constructor);r=()=>t.create(n())}break}}return p.set(e,r),r}function C(t){return e(t)}function w(e,t,n){t!==void 0&&(o.push(Object.freeze({trait:n,rank:a.size,name:e})),a.set(e,{matches:e=>e instanceof t,create:e=>new t(e)}))}function T(e,t,n=[]){let r=Object.getOwnPropertyDescriptors(e),i=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(r)]);for(let e of i){if(n.includes(e))continue;let i=t[e],a=r[e];if(!i||!a){let e=i??a;if(e&&`value`in e&&e.value===void 0)continue;return!1}if(!(`value`in i)||!(`value`in a)||!Object.is(i.value,a.value)||i.writable!==a.writable||i.configurable!==a.configurable||i.enumerable!==a.enumerable)return!1}return!0}function E(){let e=n.core.version;if(e.major!==4||!(e.minor===6&&e.patch===5||e.minor===5&&e.patch===4))return!1;let t=Object.getOwnPropertyDescriptor(globalThis,`__zod_globalConfig`);if(!t||!(`value`in t)||t.value!==h)return!1;let r=Object.getOwnPropertyDescriptor(h,`postProcessor`);if(r&&(!(`value`in r)||r.value!==void 0))return!1;let i=Object.getOwnPropertyDescriptor(h,`memoizer`);return!!i&&`value`in i&&i.value===_&&T(h,g,[`postProcessor`])&&T(_,v)}function D(e){return e?.kind===`value`?e.value:void 0}function O(e){if(e?.kind===`array`){for(let t=0;t<e.items.length;t++)if(!Object.hasOwn(e.items,t))return;return e.items}}export{f as captureDto,b as classifyDto,m as materializeDto};
1
+ import{zodToConvex as e}from"../zod-convex.mjs";import{zid as t}from"convex-helpers/server/zod4";import{z as n}from"zod";import{v as r}from"convex/values";import{vRequired as i}from"convex-helpers/validators";const a=/* @__PURE__ */ new Map,o=[];T(`object`,n.ZodObject,`ZodObject`),T(`array`,n.ZodArray,`ZodArray`),T(`optional`,n.ZodOptional,`ZodOptional`),T(`exactOptional`,n.ZodExactOptional,`ZodExactOptional`),T(`nullable`,n.ZodNullable,`ZodNullable`),T(`nonoptional`,n.ZodNonOptional,`ZodNonOptional`),T(`union`,n.ZodUnion,`ZodUnion`),T(`discriminatedUnion`,n.ZodDiscriminatedUnion,`ZodDiscriminatedUnion`),T(`tuple`,n.ZodTuple,`ZodTuple`),T(`record`,n.ZodRecord,`ZodRecord`),T(`string`,n.ZodString,`ZodString`),T(`number`,n.ZodNumber,`ZodNumber`),T(`boolean`,n.ZodBoolean,`ZodBoolean`),T(`bigint`,n.ZodBigInt,`ZodBigInt`),T(`null`,n.ZodNull,`ZodNull`),T(`never`,n.ZodNever,`ZodNever`),T(`literal`,n.ZodLiteral,`ZodLiteral`),T(`enum`,n.ZodEnum,`ZodEnum`),T(`custom`,n.ZodCustom,`ZodCustom`),T(`minLength`,n.core.$ZodCheckMinLength,`$ZodCheckMinLength`),T(`maxLength`,n.core.$ZodCheckMaxLength,`$ZodCheckMaxLength`),T(`length`,n.core.$ZodCheckLengthEquals,`$ZodCheckLengthEquals`),T(`lessThan`,n.core.$ZodCheckLessThan,`$ZodCheckLessThan`),T(`greaterThan`,n.core.$ZodCheckGreaterThan,`$ZodCheckGreaterThan`),T(`multipleOf`,n.core.$ZodCheckMultipleOf,`$ZodCheckMultipleOf`),T(`checkNumberFormat`,n.core.$ZodCheckNumberFormat,`$ZodCheckNumberFormat`),T(`checkBigintFormat`,n.core.$ZodCheckBigIntFormat,`$ZodCheckBigIntFormat`),T(`stringFormat`,n.core.$ZodCheckStringFormat,`$ZodCheckStringFormat`),T(`regex`,n.core.$ZodCheckRegex,`$ZodCheckRegex`),T(`lowercase`,n.core.$ZodCheckLowerCase,`$ZodCheckLowerCase`),T(`uppercase`,n.core.$ZodCheckUpperCase,`$ZodCheckUpperCase`),T(`includes`,n.core.$ZodCheckIncludes,`$ZodCheckIncludes`),T(`startsWith`,n.core.$ZodCheckStartsWith,`$ZodCheckStartsWith`),T(`endsWith`,n.core.$ZodCheckEndsWith,`$ZodCheckEndsWith`),T(`property`,n.core.$ZodCheckProperty,`$ZodCheckProperty`),T(`properties`,n.core.$ZodCheckProperties,`$ZodCheckProperties`),T(`numberFormat`,n.ZodNumberFormat,`ZodNumberFormat`),T(`bigintFormat`,n.ZodBigIntFormat,`ZodBigIntFormat`),T(`coreEmail`,n.core.$ZodEmail,`$ZodEmail`),T(`coreGUID`,n.core.$ZodGUID,`$ZodGUID`),T(`coreUUID`,n.core.$ZodUUID,`$ZodUUID`),T(`coreURL`,n.core.$ZodURL,`$ZodURL`),T(`coreEmoji`,n.core.$ZodEmoji,`$ZodEmoji`),T(`coreNanoID`,n.core.$ZodNanoID,`$ZodNanoID`),T(`coreCUID`,n.core.$ZodCUID,`$ZodCUID`),T(`coreCUID2`,n.core.$ZodCUID2,`$ZodCUID2`),T(`coreULID`,n.core.$ZodULID,`$ZodULID`),T(`coreXID`,n.core.$ZodXID,`$ZodXID`),T(`coreKSUID`,n.core.$ZodKSUID,`$ZodKSUID`),T(`coreIPv4`,n.core.$ZodIPv4,`$ZodIPv4`),T(`coreIPv6`,n.core.$ZodIPv6,`$ZodIPv6`),T(`coreMAC`,n.core.$ZodMAC,`$ZodMAC`),T(`coreCIDRv4`,n.core.$ZodCIDRv4,`$ZodCIDRv4`),T(`coreCIDRv6`,n.core.$ZodCIDRv6,`$ZodCIDRv6`),T(`coreBase64`,n.core.$ZodBase64,`$ZodBase64`),T(`coreBase64URL`,n.core.$ZodBase64URL,`$ZodBase64URL`),T(`coreE164`,n.core.$ZodE164,`$ZodE164`),T(`coreJWT`,n.core.$ZodJWT,`$ZodJWT`),T(`coreISODateTime`,n.core.$ZodISODateTime,`$ZodISODateTime`),T(`coreISODate`,n.core.$ZodISODate,`$ZodISODate`),T(`coreISOTime`,n.core.$ZodISOTime,`$ZodISOTime`),T(`coreISODuration`,n.core.$ZodISODuration,`$ZodISODuration`),T(`coreCreditCard`,n.core.$ZodCreditCard,`$ZodCreditCard`),T(`coreIBAN`,n.core.$ZodIBAN,`$ZodIBAN`),T(`coreCustomStringFormat`,n.core.$ZodCustomStringFormat,`$ZodCustomStringFormat`),T(`email`,n.ZodEmail,`ZodEmail`),T(`guid`,n.ZodGUID,`ZodGUID`),T(`uuid`,n.ZodUUID,`ZodUUID`),T(`url`,n.ZodURL,`ZodURL`),T(`emoji`,n.ZodEmoji,`ZodEmoji`),T(`nanoid`,n.ZodNanoID,`ZodNanoID`),T(`cuid`,n.ZodCUID,`ZodCUID`),T(`cuid2`,n.ZodCUID2,`ZodCUID2`),T(`ulid`,n.ZodULID,`ZodULID`),T(`xid`,n.ZodXID,`ZodXID`),T(`ksuid`,n.ZodKSUID,`ZodKSUID`),T(`ipv4`,n.ZodIPv4,`ZodIPv4`),T(`ipv6`,n.ZodIPv6,`ZodIPv6`),T(`mac`,n.ZodMAC,`ZodMAC`),T(`cidrv4`,n.ZodCIDRv4,`ZodCIDRv4`),T(`cidrv6`,n.ZodCIDRv6,`ZodCIDRv6`),T(`base64`,n.ZodBase64,`ZodBase64`),T(`base64url`,n.ZodBase64URL,`ZodBase64URL`),T(`e164`,n.ZodE164,`ZodE164`),T(`jwt`,n.ZodJWT,`ZodJWT`),T(`isoDateTime`,n.ZodISODateTime,`ZodISODateTime`),T(`isoDate`,n.ZodISODate,`ZodISODate`),T(`isoTime`,n.ZodISOTime,`ZodISOTime`),T(`isoDuration`,n.ZodISODuration,`ZodISODuration`),T(`creditCard`,n.ZodCreditCard,`ZodCreditCard`),T(`iban`,n.ZodIBAN,`ZodIBAN`),T(`customStringFormat`,n.ZodCustomStringFormat,`ZodCustomStringFormat`);const s=[...a.entries()].reverse(),c=new Map(o.map(({trait:e,rank:t,name:n})=>[e,Object.freeze({rank:t,entry:Object.freeze([n,a.get(n)])})])),l=[`4.5.4`,`4.6.5`].includes(`${n.core.version.major}.${n.core.version.minor}.${n.core.version.patch}`),u=Set.prototype.has,d=Set.prototype.forEach;function f(e){let t=/* @__PURE__ */ new WeakMap,r=/* @__PURE__ */ new WeakSet,i=0;function a(e,o){if(e===null||Object(e)!==e||e instanceof Function)return Object.freeze({kind:`value`,value:e});let c=e;if(r.has(c))throw Error(`Unsupported cyclic DTO schema`);let l=t.get(c);if(l)return l;if(o>64||++i>8192)throw Error(`DTO schema graph budget exceeded`);r.add(c);let u;if(e instanceof RegExp)u={kind:`regexp`,source:e.source,flags:e.flags};else if(e instanceof n.core.$ZodType||e instanceof n.core.$ZodCheck){if(e instanceof n.core.$ZodCheck&&e._zod.def.check===`custom`&&!(e instanceof n.ZodCustom))throw Error(`Unsupported opaque DTO check/superRefine; use .refine() instead`);let t=S(e)??s.find(([,t])=>t.matches(e));if(!t)throw Error(`Unsupported DTO schema or check`);let r;if(e instanceof n.ZodCustom){let t=w(e);t.kind===`id`&&(r=t.tableName)}let i=e instanceof n.ZodObject?{...e._zod.def,shape:e.shape}:e._zod.def;u={kind:`node`,constructor:t[0],definition:a(i,o+1),id:r}}else if(Array.isArray(e))u={kind:`array`,items:Object.freeze(e.map(e=>a(e,o+1)))};else{if(Object.hasOwn(c,`_zod`))throw Error(`Unsupported opaque DTO check/superRefine; use .refine() instead`);if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw Error(`Unsupported DTO definition object`);let t=[];for(let e of Reflect.ownKeys(c)){if(String(e)!==e)throw Error(`Unsupported DTO definition symbol`);let n=Object.getOwnPropertyDescriptor(c,e);if(!(`value`in n))throw Error(`Unsupported DTO schema accessor`);t.push(Object.freeze([e,a(n.value,o+1)]))}u={kind:`record`,entries:Object.freeze(t)}}return r.delete(c),Object.freeze(u),t.set(c,u),u}return Object.freeze({root:a(e,0)})}const p=/* @__PURE__ */ new WeakMap;function m(e){let t=C(e.root)();if(!(t instanceof n.ZodType))throw Error(`Expected classic DTO schema`);return t}n.object({});const h=n.core.globalConfig,g=Object.getOwnPropertyDescriptors(h),_=n.core.memoizer(),v=Object.getOwnPropertyDescriptors(_),y={string:[`coerce`],number:[`coerce`],boolean:[`coerce`],bigint:[`coerce`],null:[],never:[],literal:[`values`],object:[`shape`,`catchall`],array:[`element`],optional:[`innerType`],nullable:[`innerType`],union:[`options`],discriminatedUnion:[`options`,`discriminator`,`inclusive`],custom:[`check`,`fn`,`abort`]};function b(e){try{if(!D())return}catch{return}let t=/* @__PURE__ */ new Map;function n(e){if(!e||e.kind!==`node`)return;if(t.has(e))return t.get(e);let a=Object.hasOwn(y,e.constructor)?y[e.constructor]:void 0;if(!a||e.definition.kind!==`record`)return;let o=new Map(e.definition.entries);if([...o.keys()].some(e=>![`type`,`checks`,...a].includes(e))||O(o.get(`type`))!==(e.constructor===`discriminatedUnion`?`union`:e.constructor)||o.has(`checks`)&&k(o.get(`checks`))?.length!==0||o.has(`coerce`)&&typeof O(o.get(`coerce`))!=`boolean`)return;let s;switch(e.constructor){case`string`:s={emit:()=>r.string()};break;case`number`:s={emit:()=>r.number()};break;case`boolean`:s={emit:()=>r.boolean()};break;case`bigint`:s={emit:()=>r.int64()};break;case`null`:s={emit:()=>r.null()};break;case`never`:s={emit:()=>r.union()};break;case`custom`:{let t=e.id;if(typeof t!=`string`||O(o.get(`check`))!==`custom`||typeof O(o.get(`fn`))!=`function`||o.has(`abort`)&&typeof O(o.get(`abort`))!=`boolean`)return;s={emit:()=>r.id(t)};break}case`literal`:{let e=k(o.get(`values`));if(!e)return;let t=[];for(let n of e){if(n.kind!==`value`)return;let e=n.value;if(e!==null&&typeof e!=`string`&&typeof e!=`boolean`&&typeof e!=`bigint`&&!(typeof e==`number`&&Number.isFinite(e)))return;t.push(e)}s={literal:t,emit:()=>{let e=t.map(e=>e===null?r.null():r.literal(e));return e.length===1?e[0]:r.union(...e)}};break}case`object`:{let e=o.get(`shape`);if(e?.kind!==`record`)return;let t=/* @__PURE__ */ new Map;for(let[r,i]of e.entries){let e=n(i);if(!e)return;t.set(r,e)}let i=o.get(`catchall`);if(i&&(i.kind!==`value`||i.value!==void 0)&&!n(i))return;s={fields:t,boundary:{kind:`object`,keys:[...t.keys()]},emit:()=>r.object(Object.fromEntries([...t].map(([e,t])=>[e,t.emit()])))};break}case`array`:case`optional`:case`nullable`:{let t=n(o.get(e.constructor===`array`?`element`:`innerType`));if(!t)return;let a=e.constructor;s={emit:()=>{let e=t.emit();if(a===`optional`)return r.optional(e);if(a===`nullable`)return e.isOptional===`optional`?r.optional(r.union(i(e),r.null())):r.union(e,r.null());if(e.isOptional===`optional`)throw Error(`Arrays of optional values are not supported`);return r.array(e)}};break}case`union`:case`discriminatedUnion`:{let t=k(o.get(`options`));if(!t)return;let i=[];for(let e of t){let t=n(e);if(!t)return;i.push(t)}let a;if(e.constructor===`discriminatedUnion`){let e=O(o.get(`discriminator`));if(typeof e!=`string`||!i.length||o.has(`inclusive`)&&O(o.get(`inclusive`))!==!1)return;let t=Object.create(null);for(let n of i){let r=n.fields?.get(e)?.literal;if(n.boundary?.kind!==`object`||r?.length!==1||typeof r[0]!=`string`||Object.hasOwn(t,r[0]))return;t[r[0]]=n.boundary.keys}a={kind:`variant`,discriminator:e,branches:t}}s={boundary:a,emit:()=>r.union(...i.map(e=>e.emit()))};break}}return t.set(e,s),s}return n(e.root)}function x(){try{return D()}catch{return!1}}function S(e){if(l)try{let t=Object.getOwnPropertyDescriptor(e,`_zod`);if(!t||!(`value`in t)||t.value===null||typeof t.value!=`object`)return;let n=Object.getOwnPropertyDescriptor(t.value,`traits`);if(!n||!(`value`in n))return;let r=n.value;if(typeof r!=`object`||!r||Object.getPrototypeOf(r)!==Set.prototype||Object.getOwnPropertyDescriptor(r,`has`))return;let i=Object.getOwnPropertyDescriptor(Set.prototype,`has`);if(!i||!(`value`in i)||i.value!==u)return;u.call(r,``);let a,o=-1;return d.call(r,e=>{if(typeof e!=`string`)return;let t=c.get(e);t&&t.rank>o&&(o=t.rank,a=t.entry)}),a}catch{return}}function C(e){let n=p.get(e);if(n)return n;let r;switch(e.kind){case`value`:r=()=>e.value;break;case`regexp`:r=()=>new RegExp(e.source,e.flags);break;case`array`:{let t=e.items.map(C);r=()=>t.map(e=>e());break}case`record`:{let t=e.entries.map(([e,t])=>[e,C(t)]);r=()=>Object.fromEntries(t.map(([e,t])=>[e,t()]));break}case`node`:{let n=C(e.definition);if(e.id!==void 0){let i=e.id;r=()=>{let e=n(),r=t(i);if(e instanceof Object&&`checks`in e){let t=e.checks;if(Array.isArray(t))return r.check(...t)}return r}}else{let t=a.get(e.constructor);r=()=>t.create(n())}break}}return p.set(e,r),r}function w(t){return e(t)}function T(e,t,n){t!==void 0&&(o.push(Object.freeze({trait:n,rank:a.size,name:e})),a.set(e,{matches:e=>e instanceof t,create:e=>new t(e)}))}function E(e,t,n=[]){let r=Object.getOwnPropertyDescriptors(e),i=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(r)]);for(let e of i){if(n.includes(e))continue;let i=t[e],a=r[e];if(!i||!a){let e=i??a;if(e&&`value`in e&&e.value===void 0)continue;return!1}if(!(`value`in i)||!(`value`in a)||!Object.is(i.value,a.value)||i.writable!==a.writable||i.configurable!==a.configurable||i.enumerable!==a.enumerable)return!1}return!0}function D(){let e=n.core.version;if(e.major!==4||!(e.minor===6&&e.patch===5||e.minor===5&&e.patch===4))return!1;let t=Object.getOwnPropertyDescriptor(globalThis,`__zod_globalConfig`);if(!t||!(`value`in t)||t.value!==h)return!1;let r=Object.getOwnPropertyDescriptor(h,`postProcessor`);if(r&&(!(`value`in r)||r.value!==void 0))return!1;let i=Object.getOwnPropertyDescriptor(h,`memoizer`);return!!i&&`value`in i&&i.value===_&&E(h,g,[`postProcessor`])&&E(_,v)}function O(e){return e?.kind===`value`?e.value:void 0}function k(e){if(e?.kind===`array`){for(let t=0;t<e.items.length;t++)if(!Object.hasOwn(e.items,t))return;return e.items}}export{f as captureDto,b as classifyDto,m as materializeDto,x as ordinaryDtoConstruction};
2
2
  //# sourceMappingURL=schema-snapshot.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-snapshot.mjs","names":["zodToConvex","zodToConvex$1","constructors","traitEntries","register","z","dispatch","traitDispatch","trait","name","ordinaryTraitDispatch","intrinsicSetHas","intrinsicSetForEach","captureDto","seen","active","nodes","capture","value","object","cached","depth","recipe","entry","ordinaryDispatch","constructor","id","native","nativeValidator","definition","child","entries","key","descriptor","schema","factories","materializeDto","result","compile","admissionConfig","admissionDescriptors","installedMemoizer","memoizerDescriptors","nativeDefinitionKeys","classifyDto","ordinaryConstructorEnvironment","completed","classify","node","allowed","def","recipeValue","denseItems","v","items","values","item","validators","fieldDefinitions","fields","catchall","tag","vRequired","children","boundary","discriminator","branches","internal","traits","has","selected","rank","factory","restored","zid","checks","Constructor","sameDescriptors","after","keys","before","ignored","a","b","present","version","global","hook","memo","i"],"sources":["../../src/querying/schema-snapshot.ts"],"sourcesContent":["import { z } from 'zod'\nimport { v, type GenericValidator } from 'convex/values'\nimport { vRequired } from 'convex-helpers/validators'\nimport { zid } from 'convex-helpers/server/zod4'\nimport { zodToConvex } from '../zod-convex'\n\n// Recipes contain semantic definitions only. No source parser, constructor,\n// parent, hooks or lazy caches survive registration.\ntype Recipe =\n\t| { readonly kind: 'value'; readonly value: unknown }\n\t| { readonly kind: 'array'; readonly items: readonly Recipe[] }\n\t| { readonly kind: 'record'; readonly entries: readonly (readonly [string, Recipe])[] }\n\t| { readonly kind: 'regexp'; readonly source: string; readonly flags: string }\n\t| {\n\t\t\treadonly kind: 'node'\n\t\t\treadonly constructor: string\n\t\t\treadonly definition: Recipe\n\t\t\treadonly id?: string\n\t }\n\nexport interface DtoRecipe<Schema extends z.ZodType = z.ZodType> {\n\treadonly schemaType?: Schema\n\treadonly root: Recipe\n}\n\ntype Node = z.core.$ZodType | z.core.$ZodCheck\nconst constructors = new Map<\n\tstring,\n\t{\n\t\tmatches(node: Node): boolean\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Only recipe-restored semantic definitions enter the selected installed constructor.\n\t\tcreate(definition: unknown): Node\n\t}\n>()\nconst traitEntries: { readonly trait: string; readonly rank: number; readonly name: string }[] = []\n// Base classes precede specialized classes so the most specific installed\n// constructor wins. Never consult a caller's _zod.constr or constructor property.\nregister('object', z.ZodObject, 'ZodObject')\nregister('array', z.ZodArray, 'ZodArray')\nregister('optional', z.ZodOptional, 'ZodOptional')\nregister('exactOptional', z.ZodExactOptional, 'ZodExactOptional')\nregister('nullable', z.ZodNullable, 'ZodNullable')\nregister('nonoptional', z.ZodNonOptional, 'ZodNonOptional')\nregister('union', z.ZodUnion, 'ZodUnion')\nregister('discriminatedUnion', z.ZodDiscriminatedUnion, 'ZodDiscriminatedUnion')\nregister('tuple', z.ZodTuple, 'ZodTuple')\nregister('record', z.ZodRecord, 'ZodRecord')\nregister('string', z.ZodString, 'ZodString')\nregister('number', z.ZodNumber, 'ZodNumber')\nregister('boolean', z.ZodBoolean, 'ZodBoolean')\nregister('bigint', z.ZodBigInt, 'ZodBigInt')\nregister('null', z.ZodNull, 'ZodNull')\nregister('never', z.ZodNever, 'ZodNever')\nregister('literal', z.ZodLiteral, 'ZodLiteral')\nregister('enum', z.ZodEnum, 'ZodEnum')\nregister('custom', z.ZodCustom, 'ZodCustom')\nregister('minLength', z.core.$ZodCheckMinLength, '$ZodCheckMinLength')\nregister('maxLength', z.core.$ZodCheckMaxLength, '$ZodCheckMaxLength')\nregister('length', z.core.$ZodCheckLengthEquals, '$ZodCheckLengthEquals')\nregister('lessThan', z.core.$ZodCheckLessThan, '$ZodCheckLessThan')\nregister('greaterThan', z.core.$ZodCheckGreaterThan, '$ZodCheckGreaterThan')\nregister('multipleOf', z.core.$ZodCheckMultipleOf, '$ZodCheckMultipleOf')\nregister('checkNumberFormat', z.core.$ZodCheckNumberFormat, '$ZodCheckNumberFormat')\nregister('checkBigintFormat', z.core.$ZodCheckBigIntFormat, '$ZodCheckBigIntFormat')\nregister('stringFormat', z.core.$ZodCheckStringFormat, '$ZodCheckStringFormat')\nregister('regex', z.core.$ZodCheckRegex, '$ZodCheckRegex')\nregister('lowercase', z.core.$ZodCheckLowerCase, '$ZodCheckLowerCase')\nregister('uppercase', z.core.$ZodCheckUpperCase, '$ZodCheckUpperCase')\nregister('includes', z.core.$ZodCheckIncludes, '$ZodCheckIncludes')\nregister('startsWith', z.core.$ZodCheckStartsWith, '$ZodCheckStartsWith')\nregister('endsWith', z.core.$ZodCheckEndsWith, '$ZodCheckEndsWith')\nregister('property', z.core.$ZodCheckProperty, '$ZodCheckProperty')\nregister('properties', z.core.$ZodCheckProperties, '$ZodCheckProperties')\nregister('numberFormat', z.ZodNumberFormat, 'ZodNumberFormat')\nregister('bigintFormat', z.ZodBigIntFormat, 'ZodBigIntFormat')\n// Format schemas are also checks; preserve their implicit checks, including\n// URL/JWT validation which cannot be represented by a regex alone.\nregister('coreEmail', z.core.$ZodEmail, '$ZodEmail')\nregister('coreGUID', z.core.$ZodGUID, '$ZodGUID')\nregister('coreUUID', z.core.$ZodUUID, '$ZodUUID')\nregister('coreURL', z.core.$ZodURL, '$ZodURL')\nregister('coreEmoji', z.core.$ZodEmoji, '$ZodEmoji')\nregister('coreNanoID', z.core.$ZodNanoID, '$ZodNanoID')\nregister('coreCUID', z.core.$ZodCUID, '$ZodCUID')\nregister('coreCUID2', z.core.$ZodCUID2, '$ZodCUID2')\nregister('coreULID', z.core.$ZodULID, '$ZodULID')\nregister('coreXID', z.core.$ZodXID, '$ZodXID')\nregister('coreKSUID', z.core.$ZodKSUID, '$ZodKSUID')\nregister('coreIPv4', z.core.$ZodIPv4, '$ZodIPv4')\nregister('coreIPv6', z.core.$ZodIPv6, '$ZodIPv6')\nregister('coreMAC', z.core.$ZodMAC, '$ZodMAC')\nregister('coreCIDRv4', z.core.$ZodCIDRv4, '$ZodCIDRv4')\nregister('coreCIDRv6', z.core.$ZodCIDRv6, '$ZodCIDRv6')\nregister('coreBase64', z.core.$ZodBase64, '$ZodBase64')\nregister('coreBase64URL', z.core.$ZodBase64URL, '$ZodBase64URL')\nregister('coreE164', z.core.$ZodE164, '$ZodE164')\nregister('coreJWT', z.core.$ZodJWT, '$ZodJWT')\nregister('coreISODateTime', z.core.$ZodISODateTime, '$ZodISODateTime')\nregister('coreISODate', z.core.$ZodISODate, '$ZodISODate')\nregister('coreISOTime', z.core.$ZodISOTime, '$ZodISOTime')\nregister('coreISODuration', z.core.$ZodISODuration, '$ZodISODuration')\nregister('coreCreditCard', z.core.$ZodCreditCard, '$ZodCreditCard')\nregister('coreIBAN', z.core.$ZodIBAN, '$ZodIBAN')\nregister('coreCustomStringFormat', z.core.$ZodCustomStringFormat, '$ZodCustomStringFormat')\nregister('email', z.ZodEmail, 'ZodEmail')\nregister('guid', z.ZodGUID, 'ZodGUID')\nregister('uuid', z.ZodUUID, 'ZodUUID')\nregister('url', z.ZodURL, 'ZodURL')\nregister('emoji', z.ZodEmoji, 'ZodEmoji')\nregister('nanoid', z.ZodNanoID, 'ZodNanoID')\nregister('cuid', z.ZodCUID, 'ZodCUID')\nregister('cuid2', z.ZodCUID2, 'ZodCUID2')\nregister('ulid', z.ZodULID, 'ZodULID')\nregister('xid', z.ZodXID, 'ZodXID')\nregister('ksuid', z.ZodKSUID, 'ZodKSUID')\nregister('ipv4', z.ZodIPv4, 'ZodIPv4')\nregister('ipv6', z.ZodIPv6, 'ZodIPv6')\nregister('mac', z.ZodMAC, 'ZodMAC')\nregister('cidrv4', z.ZodCIDRv4, 'ZodCIDRv4')\nregister('cidrv6', z.ZodCIDRv6, 'ZodCIDRv6')\nregister('base64', z.ZodBase64, 'ZodBase64')\nregister('base64url', z.ZodBase64URL, 'ZodBase64URL')\nregister('e164', z.ZodE164, 'ZodE164')\nregister('jwt', z.ZodJWT, 'ZodJWT')\nregister('isoDateTime', z.ZodISODateTime, 'ZodISODateTime')\nregister('isoDate', z.ZodISODate, 'ZodISODate')\nregister('isoTime', z.ZodISOTime, 'ZodISOTime')\nregister('isoDuration', z.ZodISODuration, 'ZodISODuration')\nregister('creditCard', z.ZodCreditCard, 'ZodCreditCard')\nregister('iban', z.ZodIBAN, 'ZodIBAN')\nregister('customStringFormat', z.ZodCustomStringFormat, 'ZodCustomStringFormat')\nconst dispatch = [...constructors.entries()].reverse()\nconst traitDispatch = new Map(\n\ttraitEntries.map(\n\t\t({ trait, rank, name }) =>\n\t\t\t[\n\t\t\t\ttrait,\n\t\t\t\tObject.freeze({ rank, entry: Object.freeze([name, constructors.get(name)!] as const) }),\n\t\t\t] as const,\n\t),\n)\n// The audited installed 4.5.4/4.6.5 constructors use literal trait membership,\n// with no Parent specialization. Unknown peer versions retain the original scan.\nconst ordinaryTraitDispatch = ['4.5.4', '4.6.5'].includes(\n\t`${z.core.version.major}.${z.core.version.minor}.${z.core.version.patch}`,\n)\nconst intrinsicSetHas = Set.prototype.has\nconst intrinsicSetForEach = Set.prototype.forEach\n\nexport function captureDto<Schema extends z.ZodType>(schema: Schema): DtoRecipe<Schema> {\n\tconst seen = new WeakMap<object, Recipe>()\n\tconst active = new WeakSet<object>()\n\tlet nodes = 0\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Recursively decode preflighted Zod definitions into owned recipes.\n\tfunction capture(value: unknown, depth: number): Recipe {\n\t\tif (value === null || Object(value) !== value || value instanceof Function)\n\t\t\treturn Object.freeze({ kind: 'value', value })\n\t\t// SAFETY: the boxing equality above excludes primitives.\n\t\tconst object = value as object\n\t\tif (active.has(object)) throw new Error('Unsupported cyclic DTO schema')\n\t\tconst cached = seen.get(object)\n\t\tif (cached) return cached\n\t\tif (depth > 64 || ++nodes > 8192) throw new Error('DTO schema graph budget exceeded')\n\t\tactive.add(object)\n\t\tlet recipe: Recipe\n\t\tif (value instanceof RegExp) {\n\t\t\trecipe = { kind: 'regexp', source: value.source, flags: value.flags }\n\t\t} else if (value instanceof z.core.$ZodType || value instanceof z.core.$ZodCheck) {\n\t\t\tif (\n\t\t\t\tvalue instanceof z.core.$ZodCheck &&\n\t\t\t\tvalue._zod.def.check === 'custom' &&\n\t\t\t\t!(value instanceof z.ZodCustom)\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported opaque DTO check/superRefine; use .refine() instead')\n\t\t\tconst entry =\n\t\t\t\tordinaryDispatch(value) ?? dispatch.find(([, constructor]) => constructor.matches(value))\n\t\t\tif (!entry) throw new Error('Unsupported DTO schema or check')\n\t\t\tlet id: string | undefined\n\t\t\tif (value instanceof z.ZodCustom) {\n\t\t\t\tconst native = nativeValidator(value)\n\t\t\t\tif (native.kind === 'id') id = native.tableName\n\t\t\t}\n\t\t\tconst definition =\n\t\t\t\tvalue instanceof z.ZodObject\n\t\t\t\t\t? // oxlint-disable-next-line anti-slop/no-shape-in-symbol-names -- The installed Zod object definition requires this exact property.\n\t\t\t\t\t\t{ ...value._zod.def, shape: value.shape }\n\t\t\t\t\t: value._zod.def\n\t\t\trecipe = {\n\t\t\t\tkind: 'node',\n\t\t\t\tconstructor: entry[0],\n\t\t\t\tdefinition: capture(definition, depth + 1),\n\t\t\t\tid,\n\t\t\t}\n\t\t} else if (Array.isArray(value)) {\n\t\t\trecipe = {\n\t\t\t\tkind: 'array',\n\t\t\t\titems: Object.freeze(value.map((child) => capture(child, depth + 1))),\n\t\t\t}\n\t\t} else {\n\t\t\tif (Object.hasOwn(object, '_zod'))\n\t\t\t\tthrow new Error('Unsupported opaque DTO check/superRefine; use .refine() instead')\n\t\t\tif (\n\t\t\t\tObject.getPrototypeOf(value) !== Object.prototype &&\n\t\t\t\tObject.getPrototypeOf(value) !== null\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported DTO definition object')\n\t\t\tconst entries: (readonly [string, Recipe])[] = []\n\t\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\t\tif (String(key) !== key) throw new Error('Unsupported DTO definition symbol')\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(object, key)!\n\t\t\t\tif (!('value' in descriptor)) throw new Error('Unsupported DTO schema accessor')\n\t\t\t\tentries.push(Object.freeze([key, capture(descriptor.value, depth + 1)]))\n\t\t\t}\n\t\t\trecipe = { kind: 'record', entries: Object.freeze(entries) }\n\t\t}\n\t\tactive.delete(object)\n\t\tObject.freeze(recipe)\n\t\tseen.set(object, recipe)\n\t\treturn recipe\n\t}\n\treturn Object.freeze({ root: capture(schema, 0) })\n}\n\n// Factories share immutable instructions only. Every occurrence invokes its factory\n// again, so shared recipe nodes never share mutable materialized definitions.\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Schema recipes and runtime fixture adapters intentionally erase constructor-specific results; their callers validate or assert the result.\ntype Factory = () => unknown\nconst factories = new WeakMap<Recipe, Factory>()\n\nexport function materializeDto<Schema extends z.ZodType>(recipe: DtoRecipe<Schema>): Schema {\n\tconst result = compile(recipe.root)()\n\tif (!(result instanceof z.ZodType)) throw new Error('Expected classic DTO schema')\n\t// SAFETY: the recipe preserves the captured schema constructor and definition.\n\treturn result as Schema\n}\n\n/** Captured public boundary facts; these never require projection construction. */\nexport type DtoBoundary =\n\t| { readonly kind: 'object'; readonly keys: readonly string[] }\n\t| {\n\t\t\treadonly kind: 'variant'\n\t\t\treadonly discriminator: string\n\t\t\treadonly branches: Readonly<Record<string, readonly string[]>>\n\t }\n\ninterface NativeRecipe {\n\temit(): GenericValidator\n\tboundary?: DtoBoundary\n\tliteral?: readonly (string | number | boolean | bigint | null)[]\n\tfields?: ReadonlyMap<string, NativeRecipe>\n}\n\n// Initialize the ordinary classic container configuration before recording change\n// detectors. These descriptors do not attest pristine installed code (D1).\nz.object({})\nconst admissionConfig = z.core.globalConfig\nconst admissionDescriptors = Object.getOwnPropertyDescriptors(admissionConfig)\nconst installedMemoizer = z.core.memoizer()\nconst memoizerDescriptors = Object.getOwnPropertyDescriptors(installedMemoizer)\ninterface NativeDefinitionKeyDictionary {\n\treadonly [constructor: string]: readonly string[]\n}\nconst nativeDefinitionKeys: NativeDefinitionKeyDictionary = {\n\tstring: ['coerce'],\n\tnumber: ['coerce'],\n\tboolean: ['coerce'],\n\tbigint: ['coerce'],\n\tnull: [],\n\tnever: [],\n\tliteral: ['values'],\n\tobject: ['shape', 'catchall'],\n\tarray: ['element'],\n\toptional: ['innerType'],\n\tnullable: ['innerType'],\n\tunion: ['options'],\n\tdiscriminatedUnion: ['options', 'discriminator', 'inclusive'],\n\tcustom: ['check', 'fn', 'abort'],\n}\n\n/** Nonthrowing eligibility only; native factories run at the original conversion stage. */\nexport function classifyDto(recipe: DtoRecipe): NativeRecipe | undefined {\n\ttry {\n\t\tif (!ordinaryConstructorEnvironment()) return undefined\n\t} catch {\n\t\treturn undefined\n\t}\n\tconst completed = new Map<Recipe, NativeRecipe | undefined>()\n\tfunction classify(node: Recipe | undefined): NativeRecipe | undefined {\n\t\tif (!node || node.kind !== 'node') return undefined\n\t\tif (completed.has(node)) return completed.get(node)\n\t\tconst allowed = Object.hasOwn(nativeDefinitionKeys, node.constructor)\n\t\t\t? nativeDefinitionKeys[node.constructor]\n\t\t\t: undefined\n\t\tif (!allowed || node.definition.kind !== 'record') return undefined\n\t\tconst def = new Map(node.definition.entries)\n\t\tif ([...def.keys()].some((key) => !['type', 'checks', ...allowed].includes(key)))\n\t\t\treturn undefined\n\t\tif (\n\t\t\trecipeValue(def.get('type')) !==\n\t\t\t(node.constructor === 'discriminatedUnion' ? 'union' : node.constructor)\n\t\t)\n\t\t\treturn undefined\n\t\tif (def.has('checks') && denseItems(def.get('checks'))?.length !== 0) return undefined\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\tif (def.has('coerce') && typeof recipeValue(def.get('coerce')) !== 'boolean') return undefined\n\t\tlet result: NativeRecipe | undefined\n\t\tswitch (node.constructor) {\n\t\t\tcase 'string':\n\t\t\t\tresult = { emit: () => v.string() }\n\t\t\t\tbreak\n\t\t\tcase 'number':\n\t\t\t\tresult = { emit: () => v.number() }\n\t\t\t\tbreak\n\t\t\tcase 'boolean':\n\t\t\t\tresult = { emit: () => v.boolean() }\n\t\t\t\tbreak\n\t\t\tcase 'bigint':\n\t\t\t\tresult = { emit: () => v.int64() }\n\t\t\t\tbreak\n\t\t\tcase 'null':\n\t\t\t\tresult = { emit: () => v.null() }\n\t\t\t\tbreak\n\t\t\tcase 'never':\n\t\t\t\tresult = { emit: () => v.union() }\n\t\t\t\tbreak\n\t\t\tcase 'custom': {\n\t\t\t\tconst id = node.id\n\t\t\t\tif (\n\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\ttypeof id !== 'string' ||\n\t\t\t\t\trecipeValue(def.get('check')) !== 'custom' ||\n\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\ttypeof recipeValue(def.get('fn')) !== 'function' ||\n\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t(def.has('abort') && typeof recipeValue(def.get('abort')) !== 'boolean')\n\t\t\t\t)\n\t\t\t\t\treturn undefined\n\t\t\t\tresult = { emit: () => v.id(id) }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'literal': {\n\t\t\t\tconst items = denseItems(def.get('values'))\n\t\t\t\tif (!items) return undefined\n\t\t\t\tconst values: (string | number | boolean | bigint | null)[] = []\n\t\t\t\tfor (const item of items) {\n\t\t\t\t\tif (item.kind !== 'value') return undefined\n\t\t\t\t\tconst value = item.value\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalue !== null &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof value !== 'string' &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof value !== 'boolean' &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof value !== 'bigint' &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\t!(typeof value === 'number' && Number.isFinite(value))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\tvalues.push(value)\n\t\t\t\t}\n\t\t\t\tresult = {\n\t\t\t\t\tliteral: values,\n\t\t\t\t\temit: () => {\n\t\t\t\t\t\tconst validators = values.map((value) => (value === null ? v.null() : v.literal(value)))\n\t\t\t\t\t\treturn validators.length === 1 ? validators[0] : v.union(...validators)\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'object': {\n\t\t\t\tconst fieldDefinitions = def.get('shape')\n\t\t\t\tif (fieldDefinitions?.kind !== 'record') return undefined\n\t\t\t\tconst fields = new Map<string, NativeRecipe>()\n\t\t\t\tfor (const [key, value] of fieldDefinitions.entries) {\n\t\t\t\t\tconst child = classify(value)\n\t\t\t\t\tif (!child) return undefined\n\t\t\t\t\tfields.set(key, child)\n\t\t\t\t}\n\t\t\t\tconst catchall = def.get('catchall')\n\t\t\t\tif (\n\t\t\t\t\tcatchall &&\n\t\t\t\t\t!(catchall.kind === 'value' && catchall.value === undefined) &&\n\t\t\t\t\t!classify(catchall)\n\t\t\t\t)\n\t\t\t\t\treturn undefined\n\t\t\t\tresult = {\n\t\t\t\t\tfields,\n\t\t\t\t\tboundary: { kind: 'object', keys: [...fields.keys()] },\n\t\t\t\t\temit: () =>\n\t\t\t\t\t\tv.object(Object.fromEntries([...fields].map(([key, child]) => [key, child.emit()]))),\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'array':\n\t\t\tcase 'optional':\n\t\t\tcase 'nullable': {\n\t\t\t\tconst child = classify(def.get(node.constructor === 'array' ? 'element' : 'innerType'))\n\t\t\t\tif (!child) return undefined\n\t\t\t\tconst tag = node.constructor\n\t\t\t\tresult = {\n\t\t\t\t\temit: () => {\n\t\t\t\t\t\tconst native = child.emit()\n\t\t\t\t\t\tif (tag === 'optional') return v.optional(native)\n\t\t\t\t\t\tif (tag === 'nullable')\n\t\t\t\t\t\t\treturn native.isOptional === 'optional'\n\t\t\t\t\t\t\t\t? v.optional(v.union(vRequired(native), v.null()))\n\t\t\t\t\t\t\t\t: v.union(native, v.null())\n\t\t\t\t\t\tif (native.isOptional === 'optional')\n\t\t\t\t\t\t\tthrow new Error('Arrays of optional values are not supported')\n\t\t\t\t\t\treturn v.array(native)\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'union':\n\t\t\tcase 'discriminatedUnion': {\n\t\t\t\tconst items = denseItems(def.get('options'))\n\t\t\t\tif (!items) return undefined\n\t\t\t\tconst children: NativeRecipe[] = []\n\t\t\t\tfor (const item of items) {\n\t\t\t\t\tconst child = classify(item)\n\t\t\t\t\tif (!child) return undefined\n\t\t\t\t\tchildren.push(child)\n\t\t\t\t}\n\t\t\t\tlet boundary: DtoBoundary | undefined\n\t\t\t\tif (node.constructor === 'discriminatedUnion') {\n\t\t\t\t\tconst discriminator = recipeValue(def.get('discriminator'))\n\t\t\t\t\tif (\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof discriminator !== 'string' ||\n\t\t\t\t\t\t!children.length ||\n\t\t\t\t\t\t(def.has('inclusive') && recipeValue(def.get('inclusive')) !== false)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\tconst branches: Record<string, readonly string[]> = Object.create(null)\n\t\t\t\t\tfor (const child of children) {\n\t\t\t\t\t\tconst tag = child.fields?.get(discriminator)?.literal\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tchild.boundary?.kind !== 'object' ||\n\t\t\t\t\t\t\ttag?.length !== 1 ||\n\t\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\t\ttypeof tag[0] !== 'string' ||\n\t\t\t\t\t\t\tObject.hasOwn(branches, tag[0])\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\tbranches[tag[0]] = child.boundary.keys\n\t\t\t\t\t}\n\t\t\t\t\tboundary = { kind: 'variant', discriminator, branches }\n\t\t\t\t}\n\t\t\t\tresult = { boundary, emit: () => v.union(...children.map((child) => child.emit())) }\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tcompleted.set(node, result)\n\t\treturn result\n\t}\n\treturn classify(recipe.root)\n}\n\nfunction ordinaryDispatch(value: Node): Readonly<(typeof dispatch)[number]> | undefined {\n\tif (!ordinaryTraitDispatch) return\n\ttry {\n\t\tconst internal = Object.getOwnPropertyDescriptor(value, '_zod')\n\t\tif (\n\t\t\t!internal ||\n\t\t\t!('value' in internal) ||\n\t\t\tinternal.value === null ||\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The low-level trait guard inspects descriptor values without invoking caller getters or parsers; ineligible values retain the installed membership scan.\n\t\t\ttypeof internal.value !== 'object'\n\t\t)\n\t\t\treturn\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(internal.value, 'traits')\n\t\tif (!descriptor || !('value' in descriptor)) return\n\t\tconst traits: unknown = descriptor.value\n\t\tif (\n\t\t\ttraits === null ||\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The low-level trait guard inspects descriptor values without invoking caller getters or parsers; ineligible values retain the installed membership scan.\n\t\t\ttypeof traits !== 'object' ||\n\t\t\tObject.getPrototypeOf(traits) !== Set.prototype ||\n\t\t\tObject.getOwnPropertyDescriptor(traits, 'has')\n\t\t)\n\t\t\treturn\n\t\tconst has = Object.getOwnPropertyDescriptor(Set.prototype, 'has')\n\t\tif (!has || !('value' in has) || has.value !== intrinsicSetHas) return\n\t\t// Intrinsic brand check rejects lookalikes/Proxy-wrapped Sets without readers.\n\t\tintrinsicSetHas.call(traits, '')\n\t\tlet selected: Readonly<(typeof dispatch)[number]> | undefined\n\t\tlet rank = -1\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Intrinsic Set iteration supplies arbitrary members; the adjacent primitive guard admits only literal trait names without invoking caller code.\n\t\tintrinsicSetForEach.call(traits, (trait: unknown) => {\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The low-level trait guard inspects descriptor values without invoking caller getters or parsers; ineligible values retain the installed membership scan.\n\t\t\tif (typeof trait !== 'string') return\n\t\t\tconst entry = traitDispatch.get(trait)\n\t\t\tif (entry && entry.rank > rank) {\n\t\t\t\trank = entry.rank\n\t\t\t\tselected = entry.entry\n\t\t\t}\n\t\t})\n\t\treturn selected\n\t} catch {\n\t\t// Unsafe eligibility retains the original installed membership scan.\n\t\treturn\n\t}\n}\n\nfunction compile(recipe: Recipe): Factory {\n\tconst cached = factories.get(recipe)\n\tif (cached) return cached\n\tlet factory: Factory\n\tswitch (recipe.kind) {\n\t\tcase 'value':\n\t\t\tfactory = () => recipe.value\n\t\t\tbreak\n\t\tcase 'regexp':\n\t\t\tfactory = () => new RegExp(recipe.source, recipe.flags)\n\t\t\tbreak\n\t\tcase 'array': {\n\t\t\tconst items = recipe.items.map(compile)\n\t\t\tfactory = () => items.map((item) => item())\n\t\t\tbreak\n\t\t}\n\t\tcase 'record': {\n\t\t\tconst entries = recipe.entries.map(([key, child]) => [key, compile(child)] as const)\n\t\t\tfactory = () => Object.fromEntries(entries.map(([key, child]) => [key, child()]))\n\t\t\tbreak\n\t\t}\n\t\tcase 'node': {\n\t\t\tconst definition = compile(recipe.definition)\n\t\t\tif (recipe.id !== undefined) {\n\t\t\t\tconst id = recipe.id\n\t\t\t\tfactory = () => {\n\t\t\t\t\tconst restored = definition()\n\t\t\t\t\tconst result = zid(id)\n\t\t\t\t\t// The new zid is registered with convex-helpers. Added refinements are\n\t\t\t\t\t// reconstructed independently, never inherited via _zod.parent.\n\t\t\t\t\tif (restored instanceof Object && 'checks' in restored) {\n\t\t\t\t\t\tconst checks = restored.checks\n\t\t\t\t\t\tif (Array.isArray(checks)) return result.check(...checks)\n\t\t\t\t\t}\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst constructor = constructors.get(recipe.constructor)!\n\t\t\t\tfactory = () => constructor.create(definition())\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\tfactories.set(recipe, factory)\n\treturn factory\n}\n\nfunction nativeValidator(schema: z.ZodType): GenericValidator {\n\treturn zodToConvex(schema)\n}\n\nfunction register<T extends Node>(\n\tname: string,\n\tConstructor: z.core.$constructor<T> | undefined,\n\ttrait: string,\n): void {\n\tif (Constructor === undefined) return\n\ttraitEntries.push(Object.freeze({ trait, rank: constructors.size, name }))\n\tconstructors.set(name, {\n\t\tmatches: (node) => node instanceof Constructor,\n\t\tcreate: (definition) => {\n\t\t\t// SAFETY: capture selected this installed constructor and recursively copied\n\t\t\t// its own semantic definition; materialization restores every child first.\n\t\t\treturn new Constructor(definition as T['_zod']['def'])\n\t\t},\n\t})\n}\n\nfunction sameDescriptors(\n\t// oxlint-disable-next-line anti-slop/no-object-parameters -- Descriptor comparison accepts the installed config or memoizer object itself; parsing would change the observed identity and descriptors.\n\tobject: object,\n\tbefore: PropertyDescriptorMap,\n\tignored: readonly string[] = [],\n): boolean {\n\tconst after = Object.getOwnPropertyDescriptors(object)\n\tconst keys = new Set([...Object.keys(before), ...Object.keys(after)])\n\tfor (const key of keys) {\n\t\tif (ignored.includes(key)) continue\n\t\tconst a = before[key],\n\t\t\tb = after[key]\n\t\tif (!a || !b) {\n\t\t\tconst present = a ?? b\n\t\t\tif (present && 'value' in present && present.value === undefined) continue\n\t\t\treturn false\n\t\t}\n\t\tif (\n\t\t\t!('value' in a) ||\n\t\t\t!('value' in b) ||\n\t\t\t!Object.is(a.value, b.value) ||\n\t\t\ta.writable !== b.writable ||\n\t\t\ta.configurable !== b.configurable ||\n\t\t\ta.enumerable !== b.enumerable\n\t\t)\n\t\t\treturn false\n\t}\n\treturn true\n}\nfunction ordinaryConstructorEnvironment(): boolean {\n\tconst version: { major: number; minor: number; patch: number } = z.core.version\n\tif (\n\t\tversion.major !== 4 ||\n\t\t!((version.minor === 6 && version.patch === 5) || (version.minor === 5 && version.patch === 4))\n\t)\n\t\treturn false\n\tconst global = Object.getOwnPropertyDescriptor(globalThis, '__zod_globalConfig')\n\tif (!global || !('value' in global) || global.value !== admissionConfig) return false\n\tconst hook = Object.getOwnPropertyDescriptor(admissionConfig, 'postProcessor')\n\tif (hook && (!('value' in hook) || hook.value !== undefined)) return false\n\tconst memo = Object.getOwnPropertyDescriptor(admissionConfig, 'memoizer')\n\treturn (\n\t\t!!memo &&\n\t\t'value' in memo &&\n\t\tmemo.value === installedMemoizer &&\n\t\tsameDescriptors(admissionConfig, admissionDescriptors, ['postProcessor']) &&\n\t\tsameDescriptors(installedMemoizer, memoizerDescriptors)\n\t)\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- This recipe-parser accessor intentionally returns an unparsed semantic leaf; each classifier branch checks its required primitive contract before use.\nfunction recipeValue(recipe: Recipe | undefined): unknown {\n\treturn recipe?.kind === 'value' ? recipe.value : undefined\n}\nfunction denseItems(recipe: Recipe | undefined): readonly Recipe[] | undefined {\n\tif (recipe?.kind !== 'array') return undefined\n\tfor (let i = 0; i < recipe.items.length; i++)\n\t\tif (!Object.hasOwn(recipe.items, i)) return undefined\n\treturn recipe.items\n}\n"],"mappings":"iNA0BA,MAAME,kBAAe,IAAI,IAQnBC,EAA2F,CAAC,EAGlGC,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,WAAYC,EAAE,YAAa,aAAa,EACjDD,EAAS,gBAAiBC,EAAE,iBAAkB,kBAAkB,EAChED,EAAS,WAAYC,EAAE,YAAa,aAAa,EACjDD,EAAS,cAAeC,EAAE,eAAgB,gBAAgB,EAC1DD,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,qBAAsBC,EAAE,sBAAuB,uBAAuB,EAC/ED,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,UAAWC,EAAE,WAAY,YAAY,EAC9CD,EAAS,SAAUC,EA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AmBC,CAAmB,CAExD,CAGA,SAASS,EAAY,EAAqC,CACzD,OAAO7B,GAAQ,OAAS,QAAUA,EAAO,MAAQ,IAAA,EAClD,CACA,SAAS8B,EAAW,EAA2D,CAC9E,GAAI9B,GAAQ,OAAS,QACrB,KAAK,IAAImE,EAAI,EAAGA,EAAInE,EAAO,MAAM,OAAQ,IACxC,GAAI,CAAC,OAAO,OAAOA,EAAO,MAAOmE,CAAC,EAAG,OACtC,OAAOnE,EAAO,KAD+B,CAE9C"}
1
+ {"version":3,"file":"schema-snapshot.mjs","names":["zodToConvex","zodToConvex$1","constructors","traitEntries","register","z","dispatch","traitDispatch","trait","name","ordinaryTraitDispatch","intrinsicSetHas","intrinsicSetForEach","captureDto","seen","active","nodes","capture","value","object","cached","depth","recipe","entry","ordinaryDispatch","constructor","id","native","nativeValidator","definition","child","entries","key","descriptor","schema","factories","materializeDto","result","compile","admissionConfig","admissionDescriptors","installedMemoizer","memoizerDescriptors","nativeDefinitionKeys","classifyDto","ordinaryConstructorEnvironment","completed","classify","node","allowed","def","recipeValue","denseItems","v","items","values","item","validators","fieldDefinitions","fields","catchall","tag","vRequired","children","boundary","discriminator","branches","ordinaryDtoConstruction","internal","traits","has","selected","rank","factory","restored","zid","checks","Constructor","sameDescriptors","after","keys","before","ignored","a","b","present","version","global","hook","memo","i"],"sources":["../../src/querying/schema-snapshot.ts"],"sourcesContent":["import { z } from 'zod'\nimport { v, type GenericValidator } from 'convex/values'\nimport { vRequired } from 'convex-helpers/validators'\nimport { zid } from 'convex-helpers/server/zod4'\nimport { zodToConvex } from '../zod-convex'\n\n// Recipes contain semantic definitions only. No source parser, constructor,\n// parent, hooks or lazy caches survive registration.\ntype Recipe =\n\t| { readonly kind: 'value'; readonly value: unknown }\n\t| { readonly kind: 'array'; readonly items: readonly Recipe[] }\n\t| { readonly kind: 'record'; readonly entries: readonly (readonly [string, Recipe])[] }\n\t| { readonly kind: 'regexp'; readonly source: string; readonly flags: string }\n\t| {\n\t\t\treadonly kind: 'node'\n\t\t\treadonly constructor: string\n\t\t\treadonly definition: Recipe\n\t\t\treadonly id?: string\n\t }\n\nexport interface DtoRecipe<Schema extends z.ZodType = z.ZodType> {\n\treadonly schemaType?: Schema\n\treadonly root: Recipe\n}\n\ntype Node = z.core.$ZodType | z.core.$ZodCheck\nconst constructors = new Map<\n\tstring,\n\t{\n\t\tmatches(node: Node): boolean\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Only recipe-restored semantic definitions enter the selected installed constructor.\n\t\tcreate(definition: unknown): Node\n\t}\n>()\nconst traitEntries: { readonly trait: string; readonly rank: number; readonly name: string }[] = []\n// Base classes precede specialized classes so the most specific installed\n// constructor wins. Never consult a caller's _zod.constr or constructor property.\nregister('object', z.ZodObject, 'ZodObject')\nregister('array', z.ZodArray, 'ZodArray')\nregister('optional', z.ZodOptional, 'ZodOptional')\nregister('exactOptional', z.ZodExactOptional, 'ZodExactOptional')\nregister('nullable', z.ZodNullable, 'ZodNullable')\nregister('nonoptional', z.ZodNonOptional, 'ZodNonOptional')\nregister('union', z.ZodUnion, 'ZodUnion')\nregister('discriminatedUnion', z.ZodDiscriminatedUnion, 'ZodDiscriminatedUnion')\nregister('tuple', z.ZodTuple, 'ZodTuple')\nregister('record', z.ZodRecord, 'ZodRecord')\nregister('string', z.ZodString, 'ZodString')\nregister('number', z.ZodNumber, 'ZodNumber')\nregister('boolean', z.ZodBoolean, 'ZodBoolean')\nregister('bigint', z.ZodBigInt, 'ZodBigInt')\nregister('null', z.ZodNull, 'ZodNull')\nregister('never', z.ZodNever, 'ZodNever')\nregister('literal', z.ZodLiteral, 'ZodLiteral')\nregister('enum', z.ZodEnum, 'ZodEnum')\nregister('custom', z.ZodCustom, 'ZodCustom')\nregister('minLength', z.core.$ZodCheckMinLength, '$ZodCheckMinLength')\nregister('maxLength', z.core.$ZodCheckMaxLength, '$ZodCheckMaxLength')\nregister('length', z.core.$ZodCheckLengthEquals, '$ZodCheckLengthEquals')\nregister('lessThan', z.core.$ZodCheckLessThan, '$ZodCheckLessThan')\nregister('greaterThan', z.core.$ZodCheckGreaterThan, '$ZodCheckGreaterThan')\nregister('multipleOf', z.core.$ZodCheckMultipleOf, '$ZodCheckMultipleOf')\nregister('checkNumberFormat', z.core.$ZodCheckNumberFormat, '$ZodCheckNumberFormat')\nregister('checkBigintFormat', z.core.$ZodCheckBigIntFormat, '$ZodCheckBigIntFormat')\nregister('stringFormat', z.core.$ZodCheckStringFormat, '$ZodCheckStringFormat')\nregister('regex', z.core.$ZodCheckRegex, '$ZodCheckRegex')\nregister('lowercase', z.core.$ZodCheckLowerCase, '$ZodCheckLowerCase')\nregister('uppercase', z.core.$ZodCheckUpperCase, '$ZodCheckUpperCase')\nregister('includes', z.core.$ZodCheckIncludes, '$ZodCheckIncludes')\nregister('startsWith', z.core.$ZodCheckStartsWith, '$ZodCheckStartsWith')\nregister('endsWith', z.core.$ZodCheckEndsWith, '$ZodCheckEndsWith')\nregister('property', z.core.$ZodCheckProperty, '$ZodCheckProperty')\nregister('properties', z.core.$ZodCheckProperties, '$ZodCheckProperties')\nregister('numberFormat', z.ZodNumberFormat, 'ZodNumberFormat')\nregister('bigintFormat', z.ZodBigIntFormat, 'ZodBigIntFormat')\n// Format schemas are also checks; preserve their implicit checks, including\n// URL/JWT validation which cannot be represented by a regex alone.\nregister('coreEmail', z.core.$ZodEmail, '$ZodEmail')\nregister('coreGUID', z.core.$ZodGUID, '$ZodGUID')\nregister('coreUUID', z.core.$ZodUUID, '$ZodUUID')\nregister('coreURL', z.core.$ZodURL, '$ZodURL')\nregister('coreEmoji', z.core.$ZodEmoji, '$ZodEmoji')\nregister('coreNanoID', z.core.$ZodNanoID, '$ZodNanoID')\nregister('coreCUID', z.core.$ZodCUID, '$ZodCUID')\nregister('coreCUID2', z.core.$ZodCUID2, '$ZodCUID2')\nregister('coreULID', z.core.$ZodULID, '$ZodULID')\nregister('coreXID', z.core.$ZodXID, '$ZodXID')\nregister('coreKSUID', z.core.$ZodKSUID, '$ZodKSUID')\nregister('coreIPv4', z.core.$ZodIPv4, '$ZodIPv4')\nregister('coreIPv6', z.core.$ZodIPv6, '$ZodIPv6')\nregister('coreMAC', z.core.$ZodMAC, '$ZodMAC')\nregister('coreCIDRv4', z.core.$ZodCIDRv4, '$ZodCIDRv4')\nregister('coreCIDRv6', z.core.$ZodCIDRv6, '$ZodCIDRv6')\nregister('coreBase64', z.core.$ZodBase64, '$ZodBase64')\nregister('coreBase64URL', z.core.$ZodBase64URL, '$ZodBase64URL')\nregister('coreE164', z.core.$ZodE164, '$ZodE164')\nregister('coreJWT', z.core.$ZodJWT, '$ZodJWT')\nregister('coreISODateTime', z.core.$ZodISODateTime, '$ZodISODateTime')\nregister('coreISODate', z.core.$ZodISODate, '$ZodISODate')\nregister('coreISOTime', z.core.$ZodISOTime, '$ZodISOTime')\nregister('coreISODuration', z.core.$ZodISODuration, '$ZodISODuration')\nregister('coreCreditCard', z.core.$ZodCreditCard, '$ZodCreditCard')\nregister('coreIBAN', z.core.$ZodIBAN, '$ZodIBAN')\nregister('coreCustomStringFormat', z.core.$ZodCustomStringFormat, '$ZodCustomStringFormat')\nregister('email', z.ZodEmail, 'ZodEmail')\nregister('guid', z.ZodGUID, 'ZodGUID')\nregister('uuid', z.ZodUUID, 'ZodUUID')\nregister('url', z.ZodURL, 'ZodURL')\nregister('emoji', z.ZodEmoji, 'ZodEmoji')\nregister('nanoid', z.ZodNanoID, 'ZodNanoID')\nregister('cuid', z.ZodCUID, 'ZodCUID')\nregister('cuid2', z.ZodCUID2, 'ZodCUID2')\nregister('ulid', z.ZodULID, 'ZodULID')\nregister('xid', z.ZodXID, 'ZodXID')\nregister('ksuid', z.ZodKSUID, 'ZodKSUID')\nregister('ipv4', z.ZodIPv4, 'ZodIPv4')\nregister('ipv6', z.ZodIPv6, 'ZodIPv6')\nregister('mac', z.ZodMAC, 'ZodMAC')\nregister('cidrv4', z.ZodCIDRv4, 'ZodCIDRv4')\nregister('cidrv6', z.ZodCIDRv6, 'ZodCIDRv6')\nregister('base64', z.ZodBase64, 'ZodBase64')\nregister('base64url', z.ZodBase64URL, 'ZodBase64URL')\nregister('e164', z.ZodE164, 'ZodE164')\nregister('jwt', z.ZodJWT, 'ZodJWT')\nregister('isoDateTime', z.ZodISODateTime, 'ZodISODateTime')\nregister('isoDate', z.ZodISODate, 'ZodISODate')\nregister('isoTime', z.ZodISOTime, 'ZodISOTime')\nregister('isoDuration', z.ZodISODuration, 'ZodISODuration')\nregister('creditCard', z.ZodCreditCard, 'ZodCreditCard')\nregister('iban', z.ZodIBAN, 'ZodIBAN')\nregister('customStringFormat', z.ZodCustomStringFormat, 'ZodCustomStringFormat')\nconst dispatch = [...constructors.entries()].reverse()\nconst traitDispatch = new Map(\n\ttraitEntries.map(\n\t\t({ trait, rank, name }) =>\n\t\t\t[\n\t\t\t\ttrait,\n\t\t\t\tObject.freeze({ rank, entry: Object.freeze([name, constructors.get(name)!] as const) }),\n\t\t\t] as const,\n\t),\n)\n// The audited installed 4.5.4/4.6.5 constructors use literal trait membership,\n// with no Parent specialization. Unknown peer versions retain the original scan.\nconst ordinaryTraitDispatch = ['4.5.4', '4.6.5'].includes(\n\t`${z.core.version.major}.${z.core.version.minor}.${z.core.version.patch}`,\n)\nconst intrinsicSetHas = Set.prototype.has\nconst intrinsicSetForEach = Set.prototype.forEach\n\nexport function captureDto<Schema extends z.ZodType>(schema: Schema): DtoRecipe<Schema> {\n\tconst seen = new WeakMap<object, Recipe>()\n\tconst active = new WeakSet<object>()\n\tlet nodes = 0\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Recursively decode preflighted Zod definitions into owned recipes.\n\tfunction capture(value: unknown, depth: number): Recipe {\n\t\tif (value === null || Object(value) !== value || value instanceof Function)\n\t\t\treturn Object.freeze({ kind: 'value', value })\n\t\t// SAFETY: the boxing equality above excludes primitives.\n\t\tconst object = value as object\n\t\tif (active.has(object)) throw new Error('Unsupported cyclic DTO schema')\n\t\tconst cached = seen.get(object)\n\t\tif (cached) return cached\n\t\tif (depth > 64 || ++nodes > 8192) throw new Error('DTO schema graph budget exceeded')\n\t\tactive.add(object)\n\t\tlet recipe: Recipe\n\t\tif (value instanceof RegExp) {\n\t\t\trecipe = { kind: 'regexp', source: value.source, flags: value.flags }\n\t\t} else if (value instanceof z.core.$ZodType || value instanceof z.core.$ZodCheck) {\n\t\t\tif (\n\t\t\t\tvalue instanceof z.core.$ZodCheck &&\n\t\t\t\tvalue._zod.def.check === 'custom' &&\n\t\t\t\t!(value instanceof z.ZodCustom)\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported opaque DTO check/superRefine; use .refine() instead')\n\t\t\tconst entry =\n\t\t\t\tordinaryDispatch(value) ?? dispatch.find(([, constructor]) => constructor.matches(value))\n\t\t\tif (!entry) throw new Error('Unsupported DTO schema or check')\n\t\t\tlet id: string | undefined\n\t\t\tif (value instanceof z.ZodCustom) {\n\t\t\t\tconst native = nativeValidator(value)\n\t\t\t\tif (native.kind === 'id') id = native.tableName\n\t\t\t}\n\t\t\tconst definition =\n\t\t\t\tvalue instanceof z.ZodObject\n\t\t\t\t\t? // oxlint-disable-next-line anti-slop/no-shape-in-symbol-names -- The installed Zod object definition requires this exact property.\n\t\t\t\t\t\t{ ...value._zod.def, shape: value.shape }\n\t\t\t\t\t: value._zod.def\n\t\t\trecipe = {\n\t\t\t\tkind: 'node',\n\t\t\t\tconstructor: entry[0],\n\t\t\t\tdefinition: capture(definition, depth + 1),\n\t\t\t\tid,\n\t\t\t}\n\t\t} else if (Array.isArray(value)) {\n\t\t\trecipe = {\n\t\t\t\tkind: 'array',\n\t\t\t\titems: Object.freeze(value.map((child) => capture(child, depth + 1))),\n\t\t\t}\n\t\t} else {\n\t\t\tif (Object.hasOwn(object, '_zod'))\n\t\t\t\tthrow new Error('Unsupported opaque DTO check/superRefine; use .refine() instead')\n\t\t\tif (\n\t\t\t\tObject.getPrototypeOf(value) !== Object.prototype &&\n\t\t\t\tObject.getPrototypeOf(value) !== null\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported DTO definition object')\n\t\t\tconst entries: (readonly [string, Recipe])[] = []\n\t\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\t\tif (String(key) !== key) throw new Error('Unsupported DTO definition symbol')\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(object, key)!\n\t\t\t\tif (!('value' in descriptor)) throw new Error('Unsupported DTO schema accessor')\n\t\t\t\tentries.push(Object.freeze([key, capture(descriptor.value, depth + 1)]))\n\t\t\t}\n\t\t\trecipe = { kind: 'record', entries: Object.freeze(entries) }\n\t\t}\n\t\tactive.delete(object)\n\t\tObject.freeze(recipe)\n\t\tseen.set(object, recipe)\n\t\treturn recipe\n\t}\n\treturn Object.freeze({ root: capture(schema, 0) })\n}\n\n// Factories share immutable instructions only. Every occurrence invokes its factory\n// again, so shared recipe nodes never share mutable materialized definitions.\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- Schema recipes and runtime fixture adapters intentionally erase constructor-specific results; their callers validate or assert the result.\ntype Factory = () => unknown\nconst factories = new WeakMap<Recipe, Factory>()\n\nexport function materializeDto<Schema extends z.ZodType>(recipe: DtoRecipe<Schema>): Schema {\n\tconst result = compile(recipe.root)()\n\tif (!(result instanceof z.ZodType)) throw new Error('Expected classic DTO schema')\n\t// SAFETY: the recipe preserves the captured schema constructor and definition.\n\treturn result as Schema\n}\n\n/** Captured public boundary facts; these never require projection construction. */\nexport type DtoBoundary =\n\t| { readonly kind: 'object'; readonly keys: readonly string[] }\n\t| {\n\t\t\treadonly kind: 'variant'\n\t\t\treadonly discriminator: string\n\t\t\treadonly branches: Readonly<Record<string, readonly string[]>>\n\t }\n\ninterface NativeRecipe {\n\temit(): GenericValidator\n\tboundary?: DtoBoundary\n\tliteral?: readonly (string | number | boolean | bigint | null)[]\n\tfields?: ReadonlyMap<string, NativeRecipe>\n}\n\n// Initialize the ordinary classic container configuration before recording change\n// detectors. These descriptors do not attest pristine installed code (D1).\nz.object({})\nconst admissionConfig = z.core.globalConfig\nconst admissionDescriptors = Object.getOwnPropertyDescriptors(admissionConfig)\nconst installedMemoizer = z.core.memoizer()\nconst memoizerDescriptors = Object.getOwnPropertyDescriptors(installedMemoizer)\ninterface NativeDefinitionKeyDictionary {\n\treadonly [constructor: string]: readonly string[]\n}\nconst nativeDefinitionKeys: NativeDefinitionKeyDictionary = {\n\tstring: ['coerce'],\n\tnumber: ['coerce'],\n\tboolean: ['coerce'],\n\tbigint: ['coerce'],\n\tnull: [],\n\tnever: [],\n\tliteral: ['values'],\n\tobject: ['shape', 'catchall'],\n\tarray: ['element'],\n\toptional: ['innerType'],\n\tnullable: ['innerType'],\n\tunion: ['options'],\n\tdiscriminatedUnion: ['options', 'discriminator', 'inclusive'],\n\tcustom: ['check', 'fn', 'abort'],\n}\n\n/** Nonthrowing eligibility only; native factories run at the original conversion stage. */\nexport function classifyDto(recipe: DtoRecipe): NativeRecipe | undefined {\n\ttry {\n\t\tif (!ordinaryConstructorEnvironment()) return undefined\n\t} catch {\n\t\treturn undefined\n\t}\n\tconst completed = new Map<Recipe, NativeRecipe | undefined>()\n\tfunction classify(node: Recipe | undefined): NativeRecipe | undefined {\n\t\tif (!node || node.kind !== 'node') return undefined\n\t\tif (completed.has(node)) return completed.get(node)\n\t\tconst allowed = Object.hasOwn(nativeDefinitionKeys, node.constructor)\n\t\t\t? nativeDefinitionKeys[node.constructor]\n\t\t\t: undefined\n\t\tif (!allowed || node.definition.kind !== 'record') return undefined\n\t\tconst def = new Map(node.definition.entries)\n\t\tif ([...def.keys()].some((key) => !['type', 'checks', ...allowed].includes(key)))\n\t\t\treturn undefined\n\t\tif (\n\t\t\trecipeValue(def.get('type')) !==\n\t\t\t(node.constructor === 'discriminatedUnion' ? 'union' : node.constructor)\n\t\t)\n\t\t\treturn undefined\n\t\tif (def.has('checks') && denseItems(def.get('checks'))?.length !== 0) return undefined\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\tif (def.has('coerce') && typeof recipeValue(def.get('coerce')) !== 'boolean') return undefined\n\t\tlet result: NativeRecipe | undefined\n\t\tswitch (node.constructor) {\n\t\t\tcase 'string':\n\t\t\t\tresult = { emit: () => v.string() }\n\t\t\t\tbreak\n\t\t\tcase 'number':\n\t\t\t\tresult = { emit: () => v.number() }\n\t\t\t\tbreak\n\t\t\tcase 'boolean':\n\t\t\t\tresult = { emit: () => v.boolean() }\n\t\t\t\tbreak\n\t\t\tcase 'bigint':\n\t\t\t\tresult = { emit: () => v.int64() }\n\t\t\t\tbreak\n\t\t\tcase 'null':\n\t\t\t\tresult = { emit: () => v.null() }\n\t\t\t\tbreak\n\t\t\tcase 'never':\n\t\t\t\tresult = { emit: () => v.union() }\n\t\t\t\tbreak\n\t\t\tcase 'custom': {\n\t\t\t\tconst id = node.id\n\t\t\t\tif (\n\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\ttypeof id !== 'string' ||\n\t\t\t\t\trecipeValue(def.get('check')) !== 'custom' ||\n\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\ttypeof recipeValue(def.get('fn')) !== 'function' ||\n\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t(def.has('abort') && typeof recipeValue(def.get('abort')) !== 'boolean')\n\t\t\t\t)\n\t\t\t\t\treturn undefined\n\t\t\t\tresult = { emit: () => v.id(id) }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'literal': {\n\t\t\t\tconst items = denseItems(def.get('values'))\n\t\t\t\tif (!items) return undefined\n\t\t\t\tconst values: (string | number | boolean | bigint | null)[] = []\n\t\t\t\tfor (const item of items) {\n\t\t\t\t\tif (item.kind !== 'value') return undefined\n\t\t\t\t\tconst value = item.value\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalue !== null &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof value !== 'string' &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof value !== 'boolean' &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof value !== 'bigint' &&\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\t!(typeof value === 'number' && Number.isFinite(value))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\tvalues.push(value)\n\t\t\t\t}\n\t\t\t\tresult = {\n\t\t\t\t\tliteral: values,\n\t\t\t\t\temit: () => {\n\t\t\t\t\t\tconst validators = values.map((value) => (value === null ? v.null() : v.literal(value)))\n\t\t\t\t\t\treturn validators.length === 1 ? validators[0] : v.union(...validators)\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'object': {\n\t\t\t\tconst fieldDefinitions = def.get('shape')\n\t\t\t\tif (fieldDefinitions?.kind !== 'record') return undefined\n\t\t\t\tconst fields = new Map<string, NativeRecipe>()\n\t\t\t\tfor (const [key, value] of fieldDefinitions.entries) {\n\t\t\t\t\tconst child = classify(value)\n\t\t\t\t\tif (!child) return undefined\n\t\t\t\t\tfields.set(key, child)\n\t\t\t\t}\n\t\t\t\tconst catchall = def.get('catchall')\n\t\t\t\tif (\n\t\t\t\t\tcatchall &&\n\t\t\t\t\t!(catchall.kind === 'value' && catchall.value === undefined) &&\n\t\t\t\t\t!classify(catchall)\n\t\t\t\t)\n\t\t\t\t\treturn undefined\n\t\t\t\tresult = {\n\t\t\t\t\tfields,\n\t\t\t\t\tboundary: { kind: 'object', keys: [...fields.keys()] },\n\t\t\t\t\temit: () =>\n\t\t\t\t\t\tv.object(Object.fromEntries([...fields].map(([key, child]) => [key, child.emit()]))),\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'array':\n\t\t\tcase 'optional':\n\t\t\tcase 'nullable': {\n\t\t\t\tconst child = classify(def.get(node.constructor === 'array' ? 'element' : 'innerType'))\n\t\t\t\tif (!child) return undefined\n\t\t\t\tconst tag = node.constructor\n\t\t\t\tresult = {\n\t\t\t\t\temit: () => {\n\t\t\t\t\t\tconst native = child.emit()\n\t\t\t\t\t\tif (tag === 'optional') return v.optional(native)\n\t\t\t\t\t\tif (tag === 'nullable')\n\t\t\t\t\t\t\treturn native.isOptional === 'optional'\n\t\t\t\t\t\t\t\t? v.optional(v.union(vRequired(native), v.null()))\n\t\t\t\t\t\t\t\t: v.union(native, v.null())\n\t\t\t\t\t\tif (native.isOptional === 'optional')\n\t\t\t\t\t\t\tthrow new Error('Arrays of optional values are not supported')\n\t\t\t\t\t\treturn v.array(native)\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'union':\n\t\t\tcase 'discriminatedUnion': {\n\t\t\t\tconst items = denseItems(def.get('options'))\n\t\t\t\tif (!items) return undefined\n\t\t\t\tconst children: NativeRecipe[] = []\n\t\t\t\tfor (const item of items) {\n\t\t\t\t\tconst child = classify(item)\n\t\t\t\t\tif (!child) return undefined\n\t\t\t\t\tchildren.push(child)\n\t\t\t\t}\n\t\t\t\tlet boundary: DtoBoundary | undefined\n\t\t\t\tif (node.constructor === 'discriminatedUnion') {\n\t\t\t\t\tconst discriminator = recipeValue(def.get('discriminator'))\n\t\t\t\t\tif (\n\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\ttypeof discriminator !== 'string' ||\n\t\t\t\t\t\t!children.length ||\n\t\t\t\t\t\t(def.has('inclusive') && recipeValue(def.get('inclusive')) !== false)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\tconst branches: Record<string, readonly string[]> = Object.create(null)\n\t\t\t\t\tfor (const child of children) {\n\t\t\t\t\t\tconst tag = child.fields?.get(discriminator)?.literal\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tchild.boundary?.kind !== 'object' ||\n\t\t\t\t\t\t\ttag?.length !== 1 ||\n\t\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The recipe classifier is the semantic-value parser; primitive inspection preserves eligibility and fallback without invoking schemas or hooks.\n\t\t\t\t\t\t\ttypeof tag[0] !== 'string' ||\n\t\t\t\t\t\t\tObject.hasOwn(branches, tag[0])\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\tbranches[tag[0]] = child.boundary.keys\n\t\t\t\t\t}\n\t\t\t\t\tboundary = { kind: 'variant', discriminator, branches }\n\t\t\t\t}\n\t\t\t\tresult = { boundary, emit: () => v.union(...children.map((child) => child.emit())) }\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tcompleted.set(node, result)\n\t\treturn result\n\t}\n\treturn classify(recipe.root)\n}\n\n/** Eligibility only; hostile configuration readers keep the reconstruction path. */\nexport function ordinaryDtoConstruction(): boolean {\n\ttry {\n\t\treturn ordinaryConstructorEnvironment()\n\t} catch {\n\t\treturn false\n\t}\n}\n\nfunction ordinaryDispatch(value: Node): Readonly<(typeof dispatch)[number]> | undefined {\n\tif (!ordinaryTraitDispatch) return\n\ttry {\n\t\tconst internal = Object.getOwnPropertyDescriptor(value, '_zod')\n\t\tif (\n\t\t\t!internal ||\n\t\t\t!('value' in internal) ||\n\t\t\tinternal.value === null ||\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The low-level trait guard inspects descriptor values without invoking caller getters or parsers; ineligible values retain the installed membership scan.\n\t\t\ttypeof internal.value !== 'object'\n\t\t)\n\t\t\treturn\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(internal.value, 'traits')\n\t\tif (!descriptor || !('value' in descriptor)) return\n\t\tconst traits: unknown = descriptor.value\n\t\tif (\n\t\t\ttraits === null ||\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The low-level trait guard inspects descriptor values without invoking caller getters or parsers; ineligible values retain the installed membership scan.\n\t\t\ttypeof traits !== 'object' ||\n\t\t\tObject.getPrototypeOf(traits) !== Set.prototype ||\n\t\t\tObject.getOwnPropertyDescriptor(traits, 'has')\n\t\t)\n\t\t\treturn\n\t\tconst has = Object.getOwnPropertyDescriptor(Set.prototype, 'has')\n\t\tif (!has || !('value' in has) || has.value !== intrinsicSetHas) return\n\t\t// Intrinsic brand check rejects lookalikes/Proxy-wrapped Sets without readers.\n\t\tintrinsicSetHas.call(traits, '')\n\t\tlet selected: Readonly<(typeof dispatch)[number]> | undefined\n\t\tlet rank = -1\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Intrinsic Set iteration supplies arbitrary members; the adjacent primitive guard admits only literal trait names without invoking caller code.\n\t\tintrinsicSetForEach.call(traits, (trait: unknown) => {\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- The low-level trait guard inspects descriptor values without invoking caller getters or parsers; ineligible values retain the installed membership scan.\n\t\t\tif (typeof trait !== 'string') return\n\t\t\tconst entry = traitDispatch.get(trait)\n\t\t\tif (entry && entry.rank > rank) {\n\t\t\t\trank = entry.rank\n\t\t\t\tselected = entry.entry\n\t\t\t}\n\t\t})\n\t\treturn selected\n\t} catch {\n\t\t// Unsafe eligibility retains the original installed membership scan.\n\t\treturn\n\t}\n}\n\nfunction compile(recipe: Recipe): Factory {\n\tconst cached = factories.get(recipe)\n\tif (cached) return cached\n\tlet factory: Factory\n\tswitch (recipe.kind) {\n\t\tcase 'value':\n\t\t\tfactory = () => recipe.value\n\t\t\tbreak\n\t\tcase 'regexp':\n\t\t\tfactory = () => new RegExp(recipe.source, recipe.flags)\n\t\t\tbreak\n\t\tcase 'array': {\n\t\t\tconst items = recipe.items.map(compile)\n\t\t\tfactory = () => items.map((item) => item())\n\t\t\tbreak\n\t\t}\n\t\tcase 'record': {\n\t\t\tconst entries = recipe.entries.map(([key, child]) => [key, compile(child)] as const)\n\t\t\tfactory = () => Object.fromEntries(entries.map(([key, child]) => [key, child()]))\n\t\t\tbreak\n\t\t}\n\t\tcase 'node': {\n\t\t\tconst definition = compile(recipe.definition)\n\t\t\tif (recipe.id !== undefined) {\n\t\t\t\tconst id = recipe.id\n\t\t\t\tfactory = () => {\n\t\t\t\t\tconst restored = definition()\n\t\t\t\t\tconst result = zid(id)\n\t\t\t\t\t// The new zid is registered with convex-helpers. Added refinements are\n\t\t\t\t\t// reconstructed independently, never inherited via _zod.parent.\n\t\t\t\t\tif (restored instanceof Object && 'checks' in restored) {\n\t\t\t\t\t\tconst checks = restored.checks\n\t\t\t\t\t\tif (Array.isArray(checks)) return result.check(...checks)\n\t\t\t\t\t}\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst constructor = constructors.get(recipe.constructor)!\n\t\t\t\tfactory = () => constructor.create(definition())\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\tfactories.set(recipe, factory)\n\treturn factory\n}\n\nfunction nativeValidator(schema: z.ZodType): GenericValidator {\n\treturn zodToConvex(schema)\n}\n\nfunction register<T extends Node>(\n\tname: string,\n\tConstructor: z.core.$constructor<T> | undefined,\n\ttrait: string,\n): void {\n\tif (Constructor === undefined) return\n\ttraitEntries.push(Object.freeze({ trait, rank: constructors.size, name }))\n\tconstructors.set(name, {\n\t\tmatches: (node) => node instanceof Constructor,\n\t\tcreate: (definition) => {\n\t\t\t// SAFETY: capture selected this installed constructor and recursively copied\n\t\t\t// its own semantic definition; materialization restores every child first.\n\t\t\treturn new Constructor(definition as T['_zod']['def'])\n\t\t},\n\t})\n}\n\nfunction sameDescriptors(\n\t// oxlint-disable-next-line anti-slop/no-object-parameters -- Descriptor comparison accepts the installed config or memoizer object itself; parsing would change the observed identity and descriptors.\n\tobject: object,\n\tbefore: PropertyDescriptorMap,\n\tignored: readonly string[] = [],\n): boolean {\n\tconst after = Object.getOwnPropertyDescriptors(object)\n\tconst keys = new Set([...Object.keys(before), ...Object.keys(after)])\n\tfor (const key of keys) {\n\t\tif (ignored.includes(key)) continue\n\t\tconst a = before[key],\n\t\t\tb = after[key]\n\t\tif (!a || !b) {\n\t\t\tconst present = a ?? b\n\t\t\tif (present && 'value' in present && present.value === undefined) continue\n\t\t\treturn false\n\t\t}\n\t\tif (\n\t\t\t!('value' in a) ||\n\t\t\t!('value' in b) ||\n\t\t\t!Object.is(a.value, b.value) ||\n\t\t\ta.writable !== b.writable ||\n\t\t\ta.configurable !== b.configurable ||\n\t\t\ta.enumerable !== b.enumerable\n\t\t)\n\t\t\treturn false\n\t}\n\treturn true\n}\nfunction ordinaryConstructorEnvironment(): boolean {\n\tconst version: { major: number; minor: number; patch: number } = z.core.version\n\tif (\n\t\tversion.major !== 4 ||\n\t\t!((version.minor === 6 && version.patch === 5) || (version.minor === 5 && version.patch === 4))\n\t)\n\t\treturn false\n\tconst global = Object.getOwnPropertyDescriptor(globalThis, '__zod_globalConfig')\n\tif (!global || !('value' in global) || global.value !== admissionConfig) return false\n\tconst hook = Object.getOwnPropertyDescriptor(admissionConfig, 'postProcessor')\n\tif (hook && (!('value' in hook) || hook.value !== undefined)) return false\n\tconst memo = Object.getOwnPropertyDescriptor(admissionConfig, 'memoizer')\n\treturn (\n\t\t!!memo &&\n\t\t'value' in memo &&\n\t\tmemo.value === installedMemoizer &&\n\t\tsameDescriptors(admissionConfig, admissionDescriptors, ['postProcessor']) &&\n\t\tsameDescriptors(installedMemoizer, memoizerDescriptors)\n\t)\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-returns -- This recipe-parser accessor intentionally returns an unparsed semantic leaf; each classifier branch checks its required primitive contract before use.\nfunction recipeValue(recipe: Recipe | undefined): unknown {\n\treturn recipe?.kind === 'value' ? recipe.value : undefined\n}\nfunction denseItems(recipe: Recipe | undefined): readonly Recipe[] | undefined {\n\tif (recipe?.kind !== 'array') return undefined\n\tfor (let i = 0; i < recipe.items.length; i++)\n\t\tif (!Object.hasOwn(recipe.items, i)) return undefined\n\treturn recipe.items\n}\n"],"mappings":"iNA0BA,MAAME,kBAAe,IAAI,IAQnBC,EAA2F,CAAC,EAGlGC,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,WAAYC,EAAE,YAAa,aAAa,EACjDD,EAAS,gBAAiBC,EAAE,iBAAkB,kBAAkB,EAChED,EAAS,WAAYC,EAAE,YAAa,aAAa,EACjDD,EAAS,cAAeC,EAAE,eAAgB,gBAAgB,EAC1DD,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,qBAAsBC,EAAE,sBAAuB,uBAAuB,EAC/ED,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,UAAWC,EAAE,WAAY,YAAY,EAC9CD,EAAS,SAAUC,EAAE,UAAW,WAAW,EAC3CD,EAAS,OAAQC,EAAE,QAAS,SAAS,EACrCD,EAAS,QAASC,EAAE,SAAU,UAAU,EACxCD,EAAS,UAAWC,EAAE,WAAY,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Y,EAAqC,CACzD,OAAO7B,GAAQ,OAAS,QAAUA,EAAO,MAAQ,IAAA,EAClD,CACA,SAAS8B,EAAW,EAA2D,CAC9E,GAAI9B,GAAQ,OAAS,QACrB,KAAK,IAAIoE,EAAI,EAAGA,EAAIpE,EAAO,MAAM,OAAQ,IACxC,GAAI,CAAC,OAAO,OAAOA,EAAO,MAAOoE,CAAC,EAAG,OACtC,OAAOpE,EAAO,KAD+B,CAE9C"}
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ //#region src/querying/shared/page.d.ts
3
+ /** Construct only the result boundary when native pagination arguments are unused. */
4
+ export declare function pageResult<Dto extends z.ZodType>(dto: Dto): z.ZodObject<{
5
+ page: z.ZodArray<Dto>;
6
+ paginationMode: z.ZodOptional<z.ZodLiteral<"native-search">>;
7
+ isDone: z.ZodBoolean;
8
+ continueCursor: z.ZodString;
9
+ splitCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
10
+ pageStatus: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
11
+ SplitRecommended: "SplitRecommended";
12
+ SplitRequired: "SplitRequired";
13
+ }>>>;
14
+ completeness: z.ZodOptional<z.ZodEnum<{
15
+ "byte-budget": "byte-budget";
16
+ complete: "complete";
17
+ "native-limit": "native-limit";
18
+ "result-cap": "result-cap";
19
+ "row-budget": "row-budget";
20
+ }>>;
21
+ }, z.core.$strip>;
22
+ //#endregion
23
+ //# sourceMappingURL=page.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{z as e}from"zod";function t(t){return e.object({page:e.array(t),paginationMode:e.literal(`native-search`).optional(),isDone:e.boolean(),continueCursor:e.string(),splitCursor:e.string().nullable().optional(),pageStatus:e.enum([`SplitRecommended`,`SplitRequired`]).nullable().optional(),completeness:e.enum([`complete`,`row-budget`,`byte-budget`,`native-limit`,`result-cap`]).optional()})}export{t as pageResult};
2
+ //# sourceMappingURL=page.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.mjs","names":["pageResult","z","dto"],"sources":["../../../src/querying/shared/page.ts"],"sourcesContent":["import { z } from 'zod'\n\n/** Construct only the result boundary when native pagination arguments are unused. */\nexport function pageResult<Dto extends z.ZodType>(dto: Dto) {\n\treturn z.object({\n\t\tpage: z.array(dto),\n\t\tpaginationMode: z.literal('native-search').optional(),\n\t\tisDone: z.boolean(),\n\t\tcontinueCursor: z.string(),\n\t\tsplitCursor: z.string().nullable().optional(),\n\t\tpageStatus: z.enum(['SplitRecommended', 'SplitRequired']).nullable().optional(),\n\t\tcompleteness: z\n\t\t\t.enum(['complete', 'row-budget', 'byte-budget', 'native-limit', 'result-cap'])\n\t\t\t.optional(),\n\t})\n}\n"],"mappings":"wBAGA,SAAgBA,EAAkC,EAAU,CAC3D,OAAOC,EAAE,OAAO,CACf,KAAMA,EAAE,MAAMC,CAAG,EACjB,eAAgBD,EAAE,QAAQ,eAAe,CAAC,CAAC,SAAS,EACpD,OAAQA,EAAE,QAAQ,EAClB,eAAgBA,EAAE,OAAO,EACzB,YAAaA,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAC5C,WAAYA,EAAE,KAAK,CAAC,mBAAoB,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAC9E,aAAcA,EACZ,KAAK,CAAC,WAAY,aAAc,cAAe,eAAgB,YAAY,CAAC,CAAC,CAC7E,SAAS,CACZ,CAAC,CACF"}
@@ -1,2 +1,2 @@
1
- import{lazyRelationFilterSchema as e,relationFilterSchema as t}from"./querying/shared/filters.mjs";import{zodToConvex as n}from"./zod-convex.mjs";import{nativePagination as r,scalarPredicateSchema as i}from"./querying/filters.mjs";import{paginated as a}from"./zod-table.mjs";import{captureDto as o,classifyDto as s,materializeDto as c}from"./querying/schema-snapshot.mjs";import{convexToZod as l}from"convex-helpers/server/zod4";import{defineSchema as u,defineTable as d}from"convex/server";import{z as f}from"zod";import{v as p}from"convex/values";const m=o(r),h=Symbol(`relationField`),g=Symbol(`relationEdge`),ee=/* @__PURE__ */ new WeakMap,_=/* @__PURE__ */ new WeakMap,v=/* @__PURE__ */ new WeakMap,y=/* @__PURE__ */ new WeakMap,b=/* @__PURE__ */ new WeakSet,x=/* @__PURE__ */ new WeakMap,te=/* @__PURE__ */ new WeakSet,S=f.object({indexDescriptor:f.string(),searchField:f.string(),filterFields:f.array(f.string())}),C=f.object({searchIndexes:f.array(S),stagedSearchIndexes:f.array(S),indexes:f.array(f.object({indexDescriptor:f.string(),fields:f.array(f.string())}))}),ne=[`and`,`or`,`not`,`fields`,`then`,`__proto__`,`constructor`,`prototype`];function w(e,r){let i=Object.create(null),s={};for(let[t,n]of Object.entries(e)){if(n.tableName!==t||[`one`,`many`,`__proto__`,`constructor`,`prototype`].includes(t))throw Error(`Invalid relation table "${t}"`);let e=Object.getOwnPropertyDescriptor(n,`table`);if(!e||!(`value`in e))throw Error(`Unsupported native table accessor`);let r=e.value;i[t]={table:n,native:r,skeleton:ue(n,r)},s[t]=r}let l=Object.keys(i),d={},g=Object.create(null),S=Object.create(null);function C(e){let t=g[e]??={};if(t.failure)throw t.failure.error;let n=t.data??t.stored;if(n)return n;if(t.busy)throw Error(`Cyclic relation table materialization "${e}"`);t.busy=!0;try{return t.stored=ae(e,i[e].table,i[e].native)}catch(e){throw t.failure={error:e},e}finally{t.busy=!1}}function w(e){let t=g[e]??={};if(t.failure)throw t.failure.error;if(t.data)return t.data;if(t.busy)throw Error(`Cyclic relation table materialization "${e}"`);t.busy=!0;try{let{table:n,native:r}=i[e];t.data=t.stored?se(e,n,t.stored):oe(e,n,r);let a=S[e]??[];delete S[e];for(let e of a)e();return t.data}catch(e){throw t.data=void 0,t.failure={error:e},e}finally{t.busy=!1}}function T(e,t){g[e]?.data&&!g[e].busy?t():(S[e]??=[]).push(t)}for(let e of l)Object.defineProperty(d,e,{enumerable:!0,get:()=>w(e)});let E=/* @__PURE__ */ new Set,re=[],ie=Object.create(null),D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Set;function k(e,t,n){let r=C(e),i=n?r.branches?.options[n.tag]?.fields:r.fields;if(!i||!Object.hasOwn(i,t))throw Error(`Native stored document disagrees with boundary "${e}"`);return i[t]}let A=(e,t,n)=>{let r=Object.create(null);function i(t,r,a){let o={[h]:void 0,table:e,field:t,guard:n,forTable(a){if(n)throw Error(`forTable on branch-scoped fields is unsupported`);if(!Object.hasOwn(d,a))throw Error(`Native ID member table is not registered`);let o=j(()=>{let e=r();if(!me(e)?.includes(a))throw Error(`Invalid native ID member selection`);let t=ke(e)?p.union(p.id(a),p.null()):p.id(a);return e.isOptional===`optional`?p.optional(t):t});return T(e,o),i(t,o,Object.freeze({table:a}))},through(e){if(a||y.has(e))throw Error(`forTable with through is unsupported`);if(!E.has(e))throw Error(`Invalid junction field or registry`);let t=Object.freeze({base:o,junction:e}),n=j(()=>{if(!L(r(),v.get(e)()))throw Error(`Invalid junction field or registry`)});return b.add(t),x.set(t,n),re.push(n),t}};return v.set(o,r),a&&y.set(o,a),E.add(o),Object.freeze(o)}for(let a of t)r[a]=i(a,j(()=>k(e,a,n)));return Object.freeze(r)};function ce(e){return ie[e]??=A(e,i[e].skeleton?.common??Object.keys(w(e).fields))}let M={},N={},P={};for(let e of l)Object.defineProperty(P,e,{enumerable:!0,get:()=>ce(e)}),M[e]=t=>fe(e,`one`,t,E),N[e]=t=>fe(e,`many`,t,E);P.one=Object.freeze(M),P.many=Object.freeze(N);let pe=r(Object.freeze(P),((e,t)=>{let n=JSON.stringify([e,t]);if(!D.has(n)&&l.includes(e)&&!O.has(e)){O.add(e);let t=i[e].skeleton,n=t?t.branches??[]:Object.entries(w(e).branches?.options??{}).map(([e,t])=>[e,Object.keys(t.fields)]),r=t?t.discriminator:w(e).branches?.discriminator;for(let[t,i]of n)D.set(JSON.stringify([e,t]),A(e,i,Object.freeze({discriminator:r,tag:t})))}let r=D.get(n);if(!r)throw Error(`Unknown variant scope "${e}.${t}"`);return r})),R=Object.fromEntries(Object.entries(pe).map(([e,t])=>[e,Object.freeze({...t})]));for(let[e,t]of Object.entries(R)){if(!Object.hasOwn(d,e))throw Error(`Unknown source table "${e}"`);let n=i[e].skeleton;for(let[r,i]of Object.entries(t)){if(ne.includes(r)||n&&(n.fields.includes(r)||n.variant&&[`variant`,`variants`].includes(r)))throw Error(`Relation name collision "${r}"`);if(!te.has(i)||!E.has(I(i.from))||!E.has(I(i.to))||i.source!==e)throw Error(`Relation source bucket mismatch`);he(i)}}let z={};for(let[e,t]of Object.entries(R)){let n={};for(let[r,i]of Object.entries(t)){let t=j(()=>{let t=w(e);if(t.allFields.has(r)||t.branches&&[`variant`,`variants`].includes(r)||ne.includes(r))throw Error(`Relation name collision "${r}"`);ge(i,C),`base`in i.from&&w(i.from.junction.table)});Object.defineProperty(n,r,{enumerable:!0,get:()=>(t(),i)})}z[e]=Object.freeze(n)}Object.freeze(z);let Se=/* @__PURE__ */ new Set;function V(e){!Se.has(e)&&l.includes(e)&&(w(e),Se.add(e))}let H={metadata:d,declarations:z},U={};for(let e of l){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;U[e]={filters(t){if(V(e),d[e].branches)throw Error(`Shared scalar contracts do not support variant tables`);for(let[n,r]of Object.entries(t.native)){let t=d[e].fields[n];if(!t||JSON.stringify(q(t))!==JSON.stringify(r.json)||t.isOptional===`optional`!==r.optional)throw Error(`Shared filter field mismatch "${n}"`)}return c(m).extend({filters:t.schema.optional(),order:f.enum([`asc`,`desc`]).optional()})},paginationOpts(n,i){V(e),F(n);let a=JSON.stringify(n),o=r.get(a);return o||(o=B(be(H,e,n)),r.set(a,o)),c(m).extend({filters:t(ye(o),void 0,i).optional(),order:f.enum([`asc`,`desc`]).optional()})},pageDto(t,r={}){V(e),F(t),de(H,e,r);let i=JSON.stringify([t,r]),s=n.get(i);return s||(s=o(a(xe(H,e,t,0,r)).result),n.set(i,s)),c(s)}}}let W,G=/* @__PURE__ */ new Map;function K(){for(let e of l)V(e);for(let e of re)e();return JSON.stringify([2,Object.keys(d).sort((e,t)=>e.localeCompare(t)).map(Y),Object.keys(z).sort((e,t)=>e.localeCompare(t)).map(e=>we(e))])}function Ce(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map;for(let t of e){if(!l.includes(t))throw Error(`Unknown query table`);n.add(t)}for(let[e,i]of t){if(!Object.hasOwn(z,e)||!Object.hasOwn(z[e],i))throw Error(`Unknown relation`);let t=z[e][i];for(let r of[e,t.target,..._e(t.from),..._e(t.to)])n.add(r);let a=r.get(e)??/* @__PURE__ */ new Set;r.set(e,a.add(i))}for(let e of n)V(e);return JSON.stringify([3,[...n].sort((e,t)=>e.localeCompare(t)).map(Y),[...r.keys()].sort((e,t)=>e.localeCompare(t)).map(e=>we(e,r.get(e)))])}function we(e,t){return[e,Object.keys(z[e]).filter(e=>!t||t.has(e)).sort((e,t)=>e.localeCompare(t)).map(t=>{let n=z[e][t];return[t,n.cardinality,n.target,ve(n.from),ve(n.to)]})]}function Y(e){let t=G.get(e);if(!t){let r=d[e];t=[e,Object.entries(r.fields).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,t.isOptional,q(t)]),r.branches?[r.branches.discriminator,Object.entries(r.branches.options).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Object.entries(t.fields).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,t.isOptional,q(t)])])]:null,r.indexes,r.dtoNativeCanonical??J(q(n(r.dto))),...Object.keys(r.fieldGroups).length?[r.fieldGroups]:[],...r.searchIndexes.length?[{searchIndexes:r.searchIndexes}]:[]],G.set(e,t)}return t}let X=Object.freeze({get identity(){return W??=K()},version:1,tables:Object.freeze(U)}),Z={};for(let e of l){let t;Object.defineProperty(Z,e,{enumerable:!0,get:()=>(V(e),t??=Oe(d[e]))})}ee.set(X,Object.freeze({tables:Object.freeze(Z),declarations:z}));let Q={};for(let e of l){let t;Object.defineProperty(Q,e,{enumerable:!0,get:()=>(V(e),t??=le(d[e]))})}return _.set(X,{internal:H,nativeTables:Object.freeze(s),streamSchema:u(Object.freeze(Q)),use:V,scopedIdentity:Ce}),X}function T(e){if(!_.has(e))throw Error(`Unknown relation registry`);e.identity}function E(t){let n=_.get(t);if(!n)throw Error(`Unknown relation registry`);let r=e=>{let t=Object.keys(n.nativeTables);if(t.length!==Reflect.ownKeys(e).length||t.some(t=>{let r=Object.getOwnPropertyDescriptor(e,t);return!r||!(`value`in r)||r.value!==n.nativeTables[t]}))throw Error(`Native schema/table ownership disagrees with relation registry`)},a=/* @__PURE__ */ new WeakMap,o=/* @__PURE__ */ new WeakMap,s=/* @__PURE__ */ new WeakMap,u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new WeakMap;function g(e,t){n.use(e);let r=n.internal.metadata[e];if(!r)throw Error(`Unknown query table`);if(!r.branches)return;let i=t[r.branches.discriminator],o=typeof i==`string`&&Object.hasOwn(r.branches.options,i)?r.branches.options[i]:void 0;if(!o)throw Error(`Invalid variant document`);let s=a.get(o),c=s?.fieldKeys??Object.keys(o.fields),u=[];for(let e of c)Object.hasOwn(t,e)&&u.push([e,void 0]);for(let e of u)e[1]=t[e[0]];let d=Object.fromEntries(u);s||(s={validator:l(p.object(o.fields)),fieldKeys:c},a.set(o,s)),s.validator.parse(d)}return Object.freeze({streamSchema:n.streamSchema,scopedIdentity:n.scopedIdentity,groups(e,t){return n.use(e),de(n.internal,e,t)},validateDocument:g,assertSchema:r,pagination(t){n.use(t);let r=n.internal;function a(e,t,n){let s=JSON.stringify([e,t,n??null]),c=d.get(s);if(c)return c;let l=r.metadata[e];if(!l)throw Error(`Unknown query table`);let f=JSON.stringify([e,n??null]),p=u.get(f);if(!p){p={};for(let[e,t]of Object.entries(n===void 0?l.fields:l.branches.options[n].fields))P(t)&&(p[e]=i(t).optional());u.set(f,p)}let m={fields:p,variants:l.branches&&n===void 0&&t<4?{discriminator:l.branches.discriminator,options:Object.fromEntries(Object.keys(l.branches.options).map(n=>[n,a(e,t+1,n)]))}:void 0,relations:t>=4?{}:o(e,t)};return d.set(s,m),m}function o(e,t){let i={};for(let o of Object.keys(r.declarations[e]??{})){let s;Object.defineProperty(i,o,{enumerable:!0,get:()=>{if(!s){let i=r.declarations[e][o];n.use(i.target),s=Object.freeze({cardinality:i.cardinality,target:a(i.target,t+1)})}return s}})}return Object.freeze(i)}return c(m).extend({filters:e(a(t,0),h).optional(),order:f.enum([`asc`,`desc`]).optional()})},select(e,t){n.use(e),F(t);function r(e,t,i){if(!Object.hasOwn(n.internal.metadata,e))throw Error(`Unknown query table`);for(let[a,o]of Object.entries(t)){let t=n.internal.declarations[e]?.[a];if(!t||i>=4)throw Error(`Unknown or too deep relation "${e}.${a}"`);o!==!0&&r(t.target,o,i+1)}}r(e,t,0)},project(e,t,r,i=[]){if(!r())return null;n.use(e);let a=n.internal.metadata[e];if(!a)throw Error(`Unknown query table`);let c=a.branches?a.branches.options[String(t[a.branches.discriminator])]:void 0;if(a.branches&&!c)throw Error(`Invalid variant document`);let l=a.dto,u=c?.dto??(l instanceof f.ZodDiscriminatedUnion?l.options.find(e=>e instanceof f.ZodObject&&e.shape[a.branches.discriminator]instanceof f.ZodLiteral&&e.shape[a.branches.discriminator].value===t[a.branches.discriminator]):l);if(!(u instanceof f.ZodObject))throw Error(`Invalid variant DTO`);if(i.length){let e=s.get(u);e||(e=/* @__PURE__ */ new Map,s.set(u,e));let n=JSON.stringify([...i].sort()),r=e.get(n);r||(r=u.extend(N(a,i,void 0,a.branches?String(t[a.branches.discriminator]):void 0)).strict(),e.set(n,r)),u=r}g(e,t);let d=o.get(u);return d||(d=Object.keys(u.shape),o.set(u,d)),u.parse(Object.fromEntries(d.filter(e=>Object.hasOwn(t,e)).map(e=>[e,t[e]])))}})}function re(e){let t=ee.get(e);if(!t)throw Error(`Unknown relation registry`);return t}function ie(e,t){Ce(t),$(e,`stored`)}function D(e){$(e.publicDto,`dto`);let t=e.dto(!0);if(!(t instanceof f.ZodObject)&&!(t instanceof f.ZodDiscriminatedUnion))throw Error(`Expected object or discriminated union DTO`);$(t,`dto`);let n=o(t),r=s(n),i=r?.boundary?void 0:c(n);if(i&&!(i instanceof f.ZodObject)&&!(i instanceof f.ZodDiscriminatedUnion))throw Error(`Expected object or discriminated union DTO`);return{dtoRecipe:n,admission:r,dto:i}}function O(e){let t=we(e);return Y(t.documentType),t}function k(e){let t=C.parse(e);return{searchIndexList:[...t.searchIndexes.map(e=>({...e,staged:!1})),...t.stagedSearchIndexes.map(e=>({...e,staged:!0}))].map(e=>Object.freeze({name:e.indexDescriptor,searchField:e.searchField,filterFields:Object.freeze([...e.filterFields].sort()),staged:e.staged})),capturedIndexes:t.indexes.map(e=>({name:e.indexDescriptor,fields:[...e.fields]}))}}function A(e){if(e.capturedIndexes.some(e=>e.fields.length===0))throw Error(`Invalid empty active index`)}function ae(e,t,n){let r=t.schema;ie(r,n);let i=O(n),a={...W(e,r,i.documentType),...k(i),schema:r};return A(a),a}function oe(e,t,n){let r=t.schema;ie(r,n);let i=D(t),a=O(n);return ce(t,{...Se(e,r,i.dto,a.documentType,i.admission?.boundary),...k(a)},i)}function se(e,t,n){let r=D(t),{schema:i,...a}=n;$(i,`stored`);let o=r.admission?.boundary,s=V(e,i,r.dto,o);return ce(t,{...a,branches:H(a.branches,s,o)},r)}function ce(e,t,{dtoRecipe:r,admission:i,dto:a}){let s=a,u=q(s?n(s):i.emit());Y(u);let d=s?void 0:J(u),m=Object.create(null),h=Object.create(null),g=Object.getOwnPropertyDescriptor(e,`fieldGroups`);if(!g&&`fieldGroups`in e||g&&!(`value`in g))throw Error(`Invalid field groups`);M(g?.value??{});let ee=f.record(f.string(),f.array(f.string()).nonempty()).parse(g?.value??{}),_=/* @__PURE__ */ new Set,v=i?.boundary?i.boundary.kind===`object`?[i.boundary.keys]:Object.values(i.boundary.branches):void 0,y=s instanceof f.ZodObject?[s]:s?.options;for(let[e,n]of Object.entries(ee)){if(!e||[`__proto__`,`constructor`,`prototype`].includes(e))throw Error(`Invalid field groups`);for(let e of n){if(!t.allFields.has(e)||e.startsWith(`_`)||_.has(e)||(v?v.some(t=>t.includes(e)):y.some(t=>!(t instanceof f.ZodObject)||Object.hasOwn(t.shape,e))))throw Error(`Conflicting or incompatible field groups`);let n=t.branches?Object.values(t.branches.options).map(t=>t.fields[e]).filter(e=>e!==void 0):[t.fields[e]];if(!n.every(e=>J(q(e))===J(q(n[0]))&&e.isOptional===n[0].isOptional))throw Error(`Conflicting or incompatible field groups`);_.add(e)}m[e]=Object.freeze([...n].sort());for(let[r,i]of t.branches?Object.entries(t.branches.options).map(([e,t])=>[e,t.fields]):[[null,t.fields]]){let t=Object.fromEntries(n.filter(e=>Object.hasOwn(i,e)).map(e=>[e,i[e]]));h[JSON.stringify([e,r])]=o(l(p.object(t)).strict())}}A(t);let{capturedIndexes:b,searchIndexList:x,fields:te,branches:S,allFields:C}=t,ne,w,T={fields:te,allFields:C,capturedIndexes:b,searchIndexList:x,get indexes(){return ne??=[...b].sort((e,t)=>e.name.localeCompare(t.name))},get searchIndexes(){return w??=Object.freeze([...x].sort((e,t)=>e.name.localeCompare(t.name)))},get dto(){if(!s){let e=c(r);if(!(e instanceof f.ZodObject)&&!(e instanceof f.ZodDiscriminatedUnion))throw Error(`Expected object or discriminated union DTO`);s=e}return s},dtoNativeCanonical:d,dtoRecipe:r,fieldGroups:Object.freeze(m),groupRecipes:Object.freeze(h)};return S&&(T.branches=S),T}function le(e){let t=d({});for(let n of e.indexes){let[e,...r]=n.fields;if(e===void 0)throw Error(`Invalid empty active index`);t.index(n.name,[e,...r])}let n=Object.getOwnPropertyDescriptor(t,`indexes`).value;for(let e of n)Object.freeze(e.fields),Object.freeze(e);return Object.freeze(n),Object.freeze(t),t}function ue(e,t){let n=(e,t)=>{if(e===null||Object(e)!==e)return;let n=Object.getOwnPropertyDescriptor(e,t);return n&&`value`in n?n.value:void 0},r=e=>{let t=n(e,`fields`);if(n(e,`kind`)===`object`&&t!==null&&Object(t)===t)return t},i=[`_id`,`_creationTime`],a=n(t,`validator`),o=r(a);if(o){let e=[.../* @__PURE__ */ new Set([...Object.keys(o),...i])];return{fields:e,common:e,variant:!1}}let s=n(n(n(e.schema,`_zod`),`def`),`discriminator`);if(n(a,`kind`)!==`union`||!f.string().safeParse(s).success)return;try{Ce(t)}catch{return}let c=a.members.map(r);if(!c.length||c.some(e=>!e))return;let l=c,u=[];for(let e of l){let t=e[String(s)];if(t?.kind!==`literal`||!f.string().safeParse(t.value).success)return;u.push([String(t.value),[.../* @__PURE__ */ new Set([...Object.keys(e),...i])]])}let d=[...Object.keys(l[0]).filter(e=>l.every(t=>Object.hasOwn(t,e))&&(e===s||l.every(t=>G(t[e],l[0][e])))),...i];return{fields:[...new Set(u.flatMap(([,e])=>e))],common:[...new Set(d)],variant:!0,discriminator:String(s),branches:u}}function j(e){let t;return()=>{if(!t)try{t={value:e()}}catch(e){t={error:e}}if(`error`in t)throw t.error;return t.value}}function M(e,t=0){if(t>16)throw Error(`Invalid field groups`);if(typeof e!=`object`||!e)return;let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null&&n!==Array.prototype)throw Error(`Invalid field groups`);for(let n of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,n);if(!f.string().safeParse(n).success||!(`value`in r))throw Error(`Invalid field groups`);M(r.value,t+1)}}function de(e,t,n){M(n);function r(t,n,i){let a=f.object({fieldGroups:f.record(f.string(),f.enum([`required`,`if-permitted`])).optional(),relations:f.record(f.string(),f.unknown()).optional()}).strict().parse(n),o=e.metadata[t];if(!o)throw Error(`Unknown query table`);for(let e of Object.keys(a.fieldGroups??{}))if(!Object.hasOwn(o.fieldGroups,e))throw Error(`Unknown field group`);let s={};for(let[n,o]of Object.entries(a.relations??{})){let a=e.declarations[t]?.[n];if(!a||i>=4)throw Error(`Invalid field group relation`);s[n]=r(a.target,o,i+1)}return Object.freeze({fieldGroups:Object.freeze(a.fieldGroups??{}),relations:Object.freeze(s)})}return r(t,n,0)}function N(e,t,n,r){let i={};for(let a of t){let t=JSON.stringify([a,r??null]);if(!Object.hasOwn(e.groupRecipes,t))throw Error(`Unknown field group`);let o=c(e.groupRecipes[t]);if(!(o instanceof f.ZodObject))throw Error(`Invalid field group schema`);for(let[e,t]of Object.entries(o.shape))i[e]=n?.[a]===`if-permitted`?t.optional():t}return i}function P(e){return[`id`,`string`,`float64`,`int64`,`boolean`,`null`,`literal`].includes(e.kind)||e.kind===`union`&&e.members.every(P)}function F(e){let t=[{value:e,depth:0,ancestors:[]}],n=0;for(;t.length;){let{value:e,depth:r,ancestors:i}=t.pop();if(++n>256||r>4||i.includes(e))throw Error(`Selection cycle or depth/node budget exceeded`);let a=Object.getPrototypeOf(e);if(a!==Object.prototype&&a!==null)throw Error(`Invalid selection`);let o=Reflect.ownKeys(e);if(o.length+n+t.length>256)throw Error(`Selection node budget exceeded`);for(let a of o){let o=Object.getOwnPropertyDescriptor(e,a);if(!o.enumerable||!(`value`in o)||String(a)!==a)throw Error(`Invalid selection property`);if(o.value!==!0)t.push({value:o.value,depth:r+1,ancestors:[...i,e]});else if(++n>256)throw Error(`Selection node budget exceeded`)}}}function I(e){return`base`in e?e.base:e}function fe(e,t,n,r){for(let e of[n.from,n.to])if(!r.has(I(e))||`base`in e&&(!b.has(e)||!r.has(e.junction)))throw Error(`Foreign registry or invalid field reference`);if(I(n.to).table!==e)throw Error(`Wrong relation target table`);let i=Object.freeze({[g]:!0,source:I(n.from).table,target:e,cardinality:t,from:n.from,to:n.to,sourceGuard:I(n.from).guard,targetGuard:I(n.to).guard,junctionGuard:pe(n.from,n.to),sourceMember:y.get(I(n.from)),targetMember:y.get(I(n.to))});return te.add(i),i}function pe(e,t){let n=`base`in e?e.junction.guard:void 0,r=`base`in t?t.junction.guard:void 0;if(n&&r&&(n.discriminator!==r.discriminator||n.tag!==r.tag))throw Error(`Contradictory junction scopes`);return n??r}function me(e){if(e.kind===`id`)return[e.tableName];if(e.kind===`null`)return[];if(e.kind!==`union`)return null;let t=e.members.map(me);return t.some(e=>e===null)?null:[...new Set(t.flatMap(e=>e))].sort()}function L(e,t){let n=R(e);return n.length>0&&JSON.stringify(n)===JSON.stringify(R(t))}function R(e){if(e.kind===`union`)return[...new Set(e.members.flatMap(R))].sort();if(e.kind===`null`)return[];if(![`id`,`string`,`float64`,`int64`,`boolean`,`literal`].includes(e.kind))throw Error(`Unsupported relation field kind`);return[JSON.stringify(q(e))]}function he(e){let t=e.from,n=e.to;if(`base`in t!=`base`in n)throw Error(`Both relation legs must use through`);if(`base`in t&&`base`in n&&t.junction.table!==n.junction.table)throw Error(`Different junction tables`)}function ge(e,t){let n=e.from,r=e.to;if(he(e),`base`in n&&`base`in r){x.get(n)(),x.get(r)(),z(t(n.junction.table),n.junction.table,n.junction.field,e.junctionGuard),z(t(e.target),e.target,r.base.field,e.targetGuard);return}if(!L(v.get(I(n))(),v.get(I(r))()))throw Error(`Incompatible relation field types`);z(t(e.target),e.target,I(r).field,e.targetGuard)}function z(e,t,n,r){if(n!==`_id`&&!e.capturedIndexes.some(e=>{let t=e.fields.indexOf(n);return t>=0&&e.fields.slice(0,t).every(e=>e===r?.discriminator)}))throw Error(`No active index begins with or has a guarded prefix for "${t}.${n}"`)}function _e(e){return`base`in e?[e.base.table,e.junction.table]:[e.table]}function ve(e){return`base`in e?[e.base.table,e.base.field,e.base.guard??null,e.junction.table,e.junction.field,e.junction.guard??null]:y.has(e)?[e.table,e.field,e.guard??null,y.get(e)]:[e.table,e.field,e.guard??null]}function B(e){return{fields:o(f.object(e.fields)),relations:Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{cardinality:t.cardinality,target:B(t.target)}])),variants:e.variants?{discriminator:e.variants.discriminator,options:Object.fromEntries(Object.entries(e.variants.options).map(([e,t])=>[e,B(t)]))}:void 0}}function ye(e){return{fields:c(e.fields).shape,relations:Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{cardinality:t.cardinality,target:ye(t.target)}])),variants:e.variants?{discriminator:e.variants.discriminator,options:Object.fromEntries(Object.entries(e.variants.options).map(([e,t])=>[e,ye(t)]))}:void 0}}function be(e,t,n,r=0,a){let o={},s={},c=e.metadata[t],l={};for(let[u,d]of Object.entries(n)){if(u===`variants`&&d!==!0&&c.branches&&a===void 0){if(r>=4)throw Error(`Invalid variant selection`);for(let[i,a]of Object.entries(d)){if(!Object.hasOwn(c.branches.options,i)||a===!0)throw Error(`Unknown variant filter selection`);l[i]=be(e,t,{...Object.fromEntries(Object.entries(n).filter(([e])=>e!==`variants`)),...a},r+1,i)}continue}let f=(a===void 0?c.fields:c.branches.options[a].fields)[u],p=e.declarations[t]?.[u];if(d===!0&&f)o[u]=i(f).optional();else if(d!==!0&&p&&r<4)s[u]={cardinality:p.cardinality,target:be(e,p.target,d,r+1)};else throw Error(`Invalid relation filter selection "${t}.${u}"`)}return{fields:o,relations:s,variants:c.branches&&a===void 0?{discriminator:c.branches.discriminator,options:l}:void 0}}function xe(e,t,n,r=0,i={}){let o={};for(let[s,c]of Object.entries(n)){let n=e.declarations[t]?.[s];if(!n||r>=4)throw Error(`Unknown or too deep relation "${t}.${s}"`);let l=xe(e,n.target,c===!0?{}:c,r+1,i.relations?.[s]);if(n.targetGuard){if(!(l instanceof f.ZodDiscriminatedUnion))throw Error(`Invalid target scope`);l=l.options.filter(e=>e instanceof f.ZodObject).find(e=>e.shape[n.targetGuard.discriminator]instanceof f.ZodLiteral&&e.shape[n.targetGuard.discriminator].value===n.targetGuard.tag)}o[s]=n.cardinality===`one`?l.nullable():a(l).result}let s=e.metadata[t],l=c(s.dtoRecipe);function u(n,r){let a={...o};for(let n of Object.keys(a)){let i=e.declarations[t][n];i.sourceGuard&&r!==i.sourceGuard.tag&&i.cardinality===`one`&&(a[n]=f.null())}return n.extend({...N(s,Object.keys(i.fieldGroups??{}),i.fieldGroups,r),...a}).strict()}if(s.branches){if(!(l instanceof f.ZodDiscriminatedUnion))throw Error(`Invalid variant DTO`);let e=l.options.map(e=>{if(!(e instanceof f.ZodObject))throw Error(`Invalid variant DTO`);let t=e.shape[s.branches.discriminator];if(!(t instanceof f.ZodLiteral))throw Error(`Invalid variant tag`);return u(e,String(t.value))});return f.discriminatedUnion(s.branches.discriminator,[e[0],...e.slice(1)])}if(!(l instanceof f.ZodObject))throw Error(`Expected object DTO`);return u(l)}function Se(e,t,n,r,i){let a=V(e,t,n,i),o=W(e,t,r);return{...o,branches:H(o.branches,a,i)}}function V(e,t,n,r){if(t instanceof f.ZodObject&&(r?.kind===`object`||n instanceof f.ZodObject))return;if(!(t instanceof f.ZodDiscriminatedUnion)||!(r?.kind===`variant`||n instanceof f.ZodDiscriminatedUnion))throw Error(`Expected matching discriminated union boundaries "${e}"`);let i=t._zod.def.discriminator;if((r?.kind===`variant`?r.discriminator:n instanceof f.ZodDiscriminatedUnion?n._zod.def.discriminator:void 0)!==i)throw Error(`DTO discriminator mismatch`);let a=U(t,i),o=r?.kind===`variant`?r.branches:U(n instanceof f.ZodDiscriminatedUnion?n:t,i);if(Object.keys(a).sort().join(`\0`)!==Object.keys(o).sort().join(`\0`))throw Error(`DTO variant tags mismatch`);return o}function H(e,t,n){if(!e)return;let r=Object.create(null);for(let[i,a]of Object.entries(e.options)){let e=t?.[i];r[i]={fields:a.fields,dto:n?void 0:e instanceof f.ZodObject?e:void 0}}return{discriminator:e.discriminator,options:r}}function U(e,t){let n=Object.create(null);for(let r of e.options){if(!(r instanceof f.ZodObject))throw Error(`Variant branches must be objects`);let e=r.shape[t];if(!(e instanceof f.ZodLiteral)||e.values.size!==1)throw Error(`Variant tags must be unique required string literals`);let i=f.string().safeParse(e.value);if(!i.success||Object.hasOwn(n,i.data))throw Error(`Variant tags must be unique required string literals`);n[i.data]=r}if(Object.keys(n).length===0)throw Error(`Expected at least one variant branch`);return n}function W(e,t,r){if(t instanceof f.ZodObject){let i=n(t).fields;return X(e,i,r),{fields:i,allFields:new Set(Object.keys(i))}}if(!(t instanceof f.ZodDiscriminatedUnion))throw Error(`Expected matching discriminated union boundaries "${e}"`);let i=t._zod.def.discriminator,a=U(t,i),o={discriminator:i,options:Object.create(null)},s=[];for(let[t,r]of Object.entries(a)){let i=n(r).fields,{_id:a,_creationTime:c,...l}=i;Z(e,i),s.push(p.object(l)),o.options[t]={fields:i}}if(J(r)!==J(q(p.union(...s))))throw Error(`Native stored document disagrees with boundary "${e}"`);let c=Object.values(o.options).map(e=>e.fields),l={};for(let e of Object.keys(c[0])){if(!c.every(t=>Object.hasOwn(t,e))||e!==i&&!c.every(t=>G(t[e],c[0][e])))continue;let t=c.map(t=>t[e]),n=p.union(...t);l[e]=t.some(e=>e.isOptional===`optional`)?p.optional(n):n}return{fields:l,branches:o,allFields:new Set(c.flatMap(e=>Object.keys(e)))}}function G(e,t){try{return L(e,t)}catch{return J(q(e))===J(q(t))}}const K=/* @__PURE__ */ new Map;for(let e of[d(p.object({})),p.id(`sample`),p.null(),p.number(),p.int64(),p.commitTs(),p.boolean(),p.string(),p.bytes(),p.any(),p.object({}),p.literal(`sample`),p.array(p.string()),p.record(p.string(),p.string()),p.union(p.string(),p.null())]){let t=Object.getPrototypeOf(e);for(;t&&t!==Object.prototype;)K.has(t)||K.set(t,Object.getOwnPropertyDescriptors(t)),t=Object.getPrototypeOf(t)}function Ce(e){let t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new Set;function r(e,i,a=!1){if(n.has(e))throw Error(`Unsupported cyclic native schema`);if(t.has(e))return;if(i>64||t.size>=8192)throw Error(`Native schema graph budget exceeded`);t.add(e),n.add(e);let o=Object.getPrototypeOf(e),s=o&&K.get(o);if(o!==null&&o!==Object.prototype&&o!==Array.prototype&&!s)throw Error(`Unsupported native schema prototype`);if(Object.getOwnPropertySymbols(e).length)throw Error(`Unsupported native schema symbol`);let c=Object.getOwnPropertyNames(e).map(t=>Object.getOwnPropertyDescriptor(e,t));if(!a&&c.some(e=>!(`value`in e)||e.value instanceof Function))throw Error(`Unsupported native schema accessor or method`);if(s){let e=Object.getOwnPropertyNames(o);if(e.length!==Object.getOwnPropertyNames(s).length||e.some(e=>{let t=Object.getOwnPropertyDescriptor(o,e),n=Object.getOwnPropertyDescriptor(s,e)?.value;return!n||!Object.is(t.value,n.value)||t.get!==n.get||t.set!==n.set}))throw Error(`Unsupported native schema prototype mutation`);r(o,i+1,!0)}if(!a)for(let e of c)e.value!==null&&Object(e.value)===e.value&&r(e.value,i+1);n.delete(e)}r(e,0)}function we(e){return e.export()}function q(e){return e.json}function J(e){if(Array.isArray(e))return`[${e.map(J).join(`,`)}]`;if(e!==null&&Object(e)===e){let t=e,n=`{`,r=``;for(let e of Object.keys(t).sort())n+=`${r}${JSON.stringify(e)}:${J(t[e])}`,r=`,`;return`${n}}`}return JSON.stringify(e)}function Y(e){if(e===null||Object(e)!==e)return;let t=e;if(t.type===`any`)throw Error(`Unsupported native validation form`);for(let e of Object.values(t))Y(e)}function X(e,t,n){let{_id:r,_creationTime:i,...a}=t;if(Z(e,t),J(n)!==J(q(p.object(a))))throw Error(`Native stored document disagrees with boundary "${e}"`)}function Z(e,t){let{_id:n,_creationTime:r}=t;if(!n||!r||J(q(n))!==J(q(p.id(e)))||J(q(r))!==J(q(p.number()))||n.isOptional!==`required`||r.isOptional!==`required`)throw Error(`Native stored document disagrees with boundary "${e}"`)}const Q=f.object({field:f.string()}),Te=new Set([Q,Q.pick({field:!0}),Q.omit({field:!0}),Q.extend({other:f.string()}),Q.safeExtend({other:f.string()}),Q.merge(f.object({other:f.string()})),Q.partial(),Q.required()].flatMap(e=>{let t=Object.getOwnPropertyDescriptor(e._zod.def,`shape`)?.get;return t?[Function.prototype.toString.call(t)]:[]})),Ee=Function.prototype.toString.call(Object.getOwnPropertyDescriptor(f.string().default(``)._zod.def,`defaultValue`).get),De=Function.prototype.toString.call(Object.getOwnPropertyDescriptor(f.string().prefault(``)._zod.def,`defaultValue`).get);function $(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;function o(e,s){if(i.has(e))throw Error(`Unsupported cyclic DTO schema`);if(!r.has(e)){if(s>32||r.size>=4096)throw Error(`DTO schema graph budget exceeded`);r.add(e),i.add(e);try{let r=Object.getOwnPropertyDescriptor(e,`_zod`);if(r){if(!(`value`in r))throw Error(`Unsupported DTO schema accessor`);let e=Object.getOwnPropertyDescriptor(r.value,`def`);if(!e||!(`value`in e))throw Error(`Unsupported DTO schema accessor`)}if(e instanceof f.core.$ZodCheck&&!(e instanceof f.core.$ZodType)){if(t===`dto`&&e._zod.def.check===`overwrite`)throw Error(`Unsupported DTO overwrite check`);o(e._zod.def,s+1);return}if(e instanceof f.core.$ZodType){let r=e._zod.def;if(t===`dto`&&(![`object`,`array`,`optional`,`nullable`,`nonoptional`,`union`,`intersection`,`tuple`,`record`,`string`,`number`,`boolean`,`bigint`,`null`,`never`,`custom`,`literal`,`enum`].includes(r.type)||`coerce`in r&&r.coerce))throw Error(`Unsupported DTO schema "${r.type}"`);if(t===`stored`&&(r.type==="default"||r.type===`prefault`)){let e=Object.getOwnPropertyDescriptor(r,`defaultValue`);if(e?.get){if(e.set||Function.prototype.toString.call(e.get)!==(r.type==="default"?Ee:De))throw Error(`Unsupported stored schema accessor`);n.add(r)}}if(e instanceof f.ZodUnion&&o(e.options,s+1),r.type===`object`){let t=Object.getOwnPropertyDescriptor(r,`shape`);if(t?.get){if(t.set||!Te.has(Function.prototype.toString.call(t.get)))throw Error(`Unsupported DTO schema accessor`);let e=r.shape;o(e,s+1),a.add(r)}if(e instanceof f.ZodObject){let t=Object.getOwnPropertyDescriptor(e,`shape`);if(t&&!(`value`in t))throw Error(`Unsupported DTO schema accessor`);o(e.shape,s+1)}}o(r,s+1);return}let i=Reflect.ownKeys(e),c=i.map(t=>Object.getOwnPropertyDescriptor(e,t));if(c.some((t,r)=>!(`value`in t)&&!(a.has(e)&&i[r]===`shape`)&&!(n.has(e)&&i[r]===`defaultValue`)))throw Error(`Unsupported DTO schema accessor`);for(let e of c)e.value!==null&&Object(e.value)===e.value&&!(e.value instanceof Function)&&o(e.value,s+1)}finally{i.delete(e)}}}o(e,0)}function Oe(e){let t={};for(let[n,r]of Object.entries(e.fields))t[n]=Object.freeze({kind:r.kind,optional:r.isOptional===`optional`,nullable:ke(r),idTables:Object.freeze(Ae(r)),native:je(q(r))});return Object.freeze({fieldGroups:e.fieldGroups,searchIndexes:e.searchIndexes,fields:Object.freeze(t),variant:e.branches?Object.freeze({discriminator:e.branches.discriminator,tags:Object.freeze(Object.keys(e.branches.options))}):void 0,indexes:Object.freeze(e.indexes.map(e=>Object.freeze({name:e.name,fields:Object.freeze([...e.fields])})))})}function ke(e){return e.kind===`null`||e.kind===`union`&&e.members.some(ke)}function Ae(e){return e.kind===`id`?[e.tableName]:e.kind===`union`?[...new Set(e.members.flatMap(Ae))].sort():[]}function je(e){let t=structuredClone(e),n=[t];for(;n.length;){let e=n.pop();if(Object(e)!==e)continue;let t=e;Object.freeze(t),n.push(...Object.values(t))}return t}export{w as defineRelations,E as getRelationExecutor,re as getRelationMetadata,T as verifyRelations};
1
+ import{lazyRelationFilterSchema as e,relationFilterSchema as t}from"./querying/shared/filters.mjs";import{zodToConvex as n}from"./zod-convex.mjs";import{pageResult as r}from"./querying/shared/page.mjs";import{nativePagination as i,scalarPredicateSchema as a}from"./querying/filters.mjs";import{captureDto as o,classifyDto as s,materializeDto as c,ordinaryDtoConstruction as l}from"./querying/schema-snapshot.mjs";import{convexToZod as u}from"convex-helpers/server/zod4";import{defineSchema as d,defineTable as f}from"convex/server";import{z as p}from"zod";import{v as m}from"convex/values";const h=o(i),g=Symbol(`relationField`),_=Symbol(`relationEdge`),v=/* @__PURE__ */ new WeakMap,y=/* @__PURE__ */ new WeakMap,b=/* @__PURE__ */ new WeakMap,x=/* @__PURE__ */ new WeakMap,S=/* @__PURE__ */ new WeakSet,C=/* @__PURE__ */ new WeakMap,w=/* @__PURE__ */ new WeakSet,T=p.object({indexDescriptor:p.string(),searchField:p.string(),filterFields:p.array(p.string())}),E=p.object({searchIndexes:p.array(T),stagedSearchIndexes:p.array(T),indexes:p.array(p.object({indexDescriptor:p.string(),fields:p.array(p.string())}))}),ee=[`and`,`or`,`not`,`fields`,`then`,`__proto__`,`constructor`,`prototype`];function D(e,i){let a=Object.create(null),s={};for(let[t,n]of Object.entries(e)){if(n.tableName!==t||[`one`,`many`,`__proto__`,`constructor`,`prototype`].includes(t))throw Error(`Invalid relation table "${t}"`);let e=Object.getOwnPropertyDescriptor(n,`table`);if(!e||!(`value`in e))throw Error(`Unsupported native table accessor`);let r=e.value;a[t]={table:n,native:r,skeleton:le(n,r)},s[t]=r}let u=Object.keys(a),f={},_=Object.create(null),T=Object.create(null);function E(e){let t=_[e]??={};if(t.failure)throw t.failure.error;let n=t.data??t.stored;if(n)return n;if(t.busy)throw Error(`Cyclic relation table materialization "${e}"`);t.busy=!0;try{return t.stored=ie(e,a[e].table,a[e].native)}catch(e){throw t.failure={error:e},e}finally{t.busy=!1}}function D(e){let t=_[e]??={};if(t.failure)throw t.failure.error;if(t.data)return t.data;if(t.busy)throw Error(`Cyclic relation table materialization "${e}"`);t.busy=!0;try{let{table:n,native:r}=a[e];t.data=t.stored?oe(e,n,t.stored):ae(e,n,r);let i=T[e]??[];delete T[e];for(let e of i)e();return t.data}catch(e){throw t.data=void 0,t.failure={error:e},e}finally{t.busy=!1}}function te(e,t){_[e]?.data&&!_[e].busy?t():(T[e]??=[]).push(t)}for(let e of u)Object.defineProperty(f,e,{enumerable:!0,get:()=>D(e)});let O=/* @__PURE__ */ new Set,ne=[],k=Object.create(null),A=/* @__PURE__ */ new Map,j=/* @__PURE__ */ new Set;function re(e,t,n){let r=E(e),i=n?r.branches?.options[n.tag]?.fields:r.fields;if(!i||!Object.hasOwn(i,t))throw Error(`Native stored document disagrees with boundary "${e}"`);return i[t]}let M=(e,t,n)=>{let r=Object.create(null);function i(t,r,a){let o={[g]:void 0,table:e,field:t,guard:n,forTable(a){if(n)throw Error(`forTable on branch-scoped fields is unsupported`);if(!Object.hasOwn(f,a))throw Error(`Native ID member table is not registered`);let o=N(()=>{let e=r();if(!pe(e)?.includes(a))throw Error(`Invalid native ID member selection`);let t=Ae(e)?m.union(m.id(a),m.null()):m.id(a);return e.isOptional===`optional`?m.optional(t):t});return te(e,o),i(t,o,Object.freeze({table:a}))},through(e){if(a||x.has(e))throw Error(`forTable with through is unsupported`);if(!O.has(e))throw Error(`Invalid junction field or registry`);let t=Object.freeze({base:o,junction:e}),n=N(()=>{if(!me(r(),b.get(e)()))throw Error(`Invalid junction field or registry`)});return S.add(t),C.set(t,n),ne.push(n),t}};return b.set(o,r),a&&x.set(o,a),O.add(o),Object.freeze(o)}for(let a of t)r[a]=i(a,N(()=>re(e,a,n)));return Object.freeze(r)};function se(e){return k[e]??=M(e,a[e].skeleton?.common??Object.keys(D(e).fields))}let P={},F={},I={};for(let e of u)Object.defineProperty(I,e,{enumerable:!0,get:()=>se(e)}),P[e]=t=>de(e,`one`,t,O),F[e]=t=>de(e,`many`,t,O);I.one=Object.freeze(P),I.many=Object.freeze(F);let fe=i(Object.freeze(I),((e,t)=>{let n=JSON.stringify([e,t]);if(!A.has(n)&&u.includes(e)&&!j.has(e)){j.add(e);let t=a[e].skeleton,n=t?t.branches??[]:Object.entries(D(e).branches?.options??{}).map(([e,t])=>[e,Object.keys(t.fields)]),r=t?t.discriminator:D(e).branches?.discriminator;for(let[t,i]of n)A.set(JSON.stringify([e,t]),M(e,i,Object.freeze({discriminator:r,tag:t})))}let r=A.get(n);if(!r)throw Error(`Unknown variant scope "${e}.${t}"`);return r})),z=Object.fromEntries(Object.entries(fe).map(([e,t])=>[e,Object.freeze({...t})]));for(let[e,t]of Object.entries(z)){if(!Object.hasOwn(f,e))throw Error(`Unknown source table "${e}"`);let n=a[e].skeleton;for(let[r,i]of Object.entries(t)){if(ee.includes(r)||n&&(n.fields.includes(r)||n.variant&&[`variant`,`variants`].includes(r)))throw Error(`Relation name collision "${r}"`);if(!w.has(i)||!O.has(R(i.from))||!O.has(R(i.to))||i.source!==e)throw Error(`Relation source bucket mismatch`);he(i)}}let B={};for(let[e,t]of Object.entries(z)){let n={};for(let[r,i]of Object.entries(t)){let t=N(()=>{let t=D(e);if(t.allFields.has(r)||t.branches&&[`variant`,`variants`].includes(r)||ee.includes(r))throw Error(`Relation name collision "${r}"`);ge(i,E),`base`in i.from&&D(i.from.junction.table)});Object.defineProperty(n,r,{enumerable:!0,get:()=>(t(),i)})}B[e]=Object.freeze(n)}Object.freeze(B);let Ce=/* @__PURE__ */ new Set;function V(e){!Ce.has(e)&&u.includes(e)&&(D(e),Ce.add(e))}let H={metadata:f,declarations:B},U={};for(let e of u){let n=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;U[e]={filters(t){if(V(e),f[e].branches)throw Error(`Shared scalar contracts do not support variant tables`);for(let[n,r]of Object.entries(t.native)){let t=f[e].fields[n];if(!t||JSON.stringify(q(t))!==JSON.stringify(r.json)||t.isOptional===`optional`!==r.optional)throw Error(`Shared filter field mismatch "${n}"`)}return c(h).extend({filters:t.schema.optional(),order:p.enum([`asc`,`desc`]).optional()})},paginationOpts(n,r){V(e),L(n);let a=JSON.stringify(n),o=i.get(a);return o||(o=ye(xe(H,e,n)),i.set(a,o)),c(h).extend({filters:t(be(o),void 0,r).optional(),order:p.enum([`asc`,`desc`]).optional()})},pageDto(t,i={}){V(e),L(t),ue(H,e,i);let a=JSON.stringify([t,i]),s=n.get(a);if(!s){let c=l(),u=r(Se(H,e,t,0,i));if(s=o(u),n.set(a,s),c&&!f[e].branches&&Object.keys(t).length===0&&Object.keys(i).length===0&&l())return u}return c(s)}}}let we,W=/* @__PURE__ */ new Map;function G(){for(let e of u)V(e);for(let e of ne)e();return JSON.stringify([2,Object.keys(f).sort((e,t)=>e.localeCompare(t)).map(Y),Object.keys(B).sort((e,t)=>e.localeCompare(t)).map(e=>K(e))])}function Te(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map;for(let t of e){if(!u.includes(t))throw Error(`Unknown query table`);n.add(t)}for(let[e,i]of t){if(!Object.hasOwn(B,e)||!Object.hasOwn(B[e],i))throw Error(`Unknown relation`);let t=B[e][i];for(let r of[e,t.target,..._e(t.from),..._e(t.to)])n.add(r);let a=r.get(e)??/* @__PURE__ */ new Set;r.set(e,a.add(i))}for(let e of n)V(e);return JSON.stringify([3,[...n].sort((e,t)=>e.localeCompare(t)).map(Y),[...r.keys()].sort((e,t)=>e.localeCompare(t)).map(e=>K(e,r.get(e)))])}function K(e,t){return[e,Object.keys(B[e]).filter(e=>!t||t.has(e)).sort((e,t)=>e.localeCompare(t)).map(t=>{let n=B[e][t];return[t,n.cardinality,n.target,ve(n.from),ve(n.to)]})]}function Y(e){let t=W.get(e);if(!t){let r=f[e];t=[e,Object.entries(r.fields).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,t.isOptional,q(t)]),r.branches?[r.branches.discriminator,Object.entries(r.branches.options).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Object.entries(t.fields).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,t.isOptional,q(t)])])]:null,r.indexes,r.dtoNativeCanonical??J(q(n(r.dto))),...Object.keys(r.fieldGroups).length?[r.fieldGroups]:[],...r.searchIndexes.length?[{searchIndexes:r.searchIndexes}]:[]],W.set(e,t)}return t}let X=Object.freeze({get identity(){return we??=G()},version:1,tables:Object.freeze(U)}),Z={};for(let e of u){let t;Object.defineProperty(Z,e,{enumerable:!0,get:()=>(V(e),t??=ke(f[e]))})}v.set(X,Object.freeze({tables:Object.freeze(Z),declarations:B}));let Q={};for(let e of u){let t;Object.defineProperty(Q,e,{enumerable:!0,get:()=>(V(e),t??=ce(f[e]))})}return y.set(X,{internal:H,nativeTables:Object.freeze(s),streamSchema:d(Object.freeze(Q)),use:V,scopedIdentity:Te}),X}function te(e){if(!y.has(e))throw Error(`Unknown relation registry`);e.identity}function O(t){let n=y.get(t);if(!n)throw Error(`Unknown relation registry`);let r=e=>{let t=Object.keys(n.nativeTables);if(t.length!==Reflect.ownKeys(e).length||t.some(t=>{let r=Object.getOwnPropertyDescriptor(e,t);return!r||!(`value`in r)||r.value!==n.nativeTables[t]}))throw Error(`Native schema/table ownership disagrees with relation registry`)},i=/* @__PURE__ */ new WeakMap,o=/* @__PURE__ */ new WeakMap,s=/* @__PURE__ */ new WeakMap,l=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new WeakMap;function g(e,t){n.use(e);let r=n.internal.metadata[e];if(!r)throw Error(`Unknown query table`);if(!r.branches)return;let a=t[r.branches.discriminator],o=typeof a==`string`&&Object.hasOwn(r.branches.options,a)?r.branches.options[a]:void 0;if(!o)throw Error(`Invalid variant document`);let s=i.get(o),c=s?.fieldKeys??Object.keys(o.fields),l=[];for(let e of c)Object.hasOwn(t,e)&&l.push([e,void 0]);for(let e of l)e[1]=t[e[0]];let d=Object.fromEntries(l);s||(s={validator:u(m.object(o.fields)),fieldKeys:c},i.set(o,s)),s.validator.parse(d)}return Object.freeze({streamSchema:n.streamSchema,scopedIdentity:n.scopedIdentity,groups(e,t){return n.use(e),ue(n.internal,e,t)},validateDocument:g,assertSchema:r,pagination(t){n.use(t);let r=n.internal;function i(e,t,n){let s=JSON.stringify([e,t,n??null]),c=d.get(s);if(c)return c;let u=r.metadata[e];if(!u)throw Error(`Unknown query table`);let f=JSON.stringify([e,n??null]),p=l.get(f);if(!p){p={};for(let[e,t]of Object.entries(n===void 0?u.fields:u.branches.options[n].fields))I(t)&&(p[e]=a(t).optional());l.set(f,p)}let m={fields:p,variants:u.branches&&n===void 0&&t<4?{discriminator:u.branches.discriminator,options:Object.fromEntries(Object.keys(u.branches.options).map(n=>[n,i(e,t+1,n)]))}:void 0,relations:t>=4?{}:o(e,t)};return d.set(s,m),m}function o(e,t){let a={};for(let o of Object.keys(r.declarations[e]??{})){let s;Object.defineProperty(a,o,{enumerable:!0,get:()=>{if(!s){let a=r.declarations[e][o];n.use(a.target),s=Object.freeze({cardinality:a.cardinality,target:i(a.target,t+1)})}return s}})}return Object.freeze(a)}return c(h).extend({filters:e(i(t,0),f).optional(),order:p.enum([`asc`,`desc`]).optional()})},select(e,t){n.use(e),L(t);function r(e,t,i){if(!Object.hasOwn(n.internal.metadata,e))throw Error(`Unknown query table`);for(let[a,o]of Object.entries(t)){let t=n.internal.declarations[e]?.[a];if(!t||i>=4)throw Error(`Unknown or too deep relation "${e}.${a}"`);o!==!0&&r(t.target,o,i+1)}}r(e,t,0)},project(e,t,r,i=[]){if(!r())return null;n.use(e);let a=n.internal.metadata[e];if(!a)throw Error(`Unknown query table`);let c=a.branches?a.branches.options[String(t[a.branches.discriminator])]:void 0;if(a.branches&&!c)throw Error(`Invalid variant document`);let l=a.dto,u=c?.dto??(l instanceof p.ZodDiscriminatedUnion?l.options.find(e=>e instanceof p.ZodObject&&e.shape[a.branches.discriminator]instanceof p.ZodLiteral&&e.shape[a.branches.discriminator].value===t[a.branches.discriminator]):l);if(!(u instanceof p.ZodObject))throw Error(`Invalid variant DTO`);if(i.length){let e=s.get(u);e||(e=/* @__PURE__ */ new Map,s.set(u,e));let n=JSON.stringify([...i].sort()),r=e.get(n);r||(r=u.extend(F(a,i,void 0,a.branches?String(t[a.branches.discriminator]):void 0)).strict(),e.set(n,r)),u=r}g(e,t);let d=o.get(u);return d||(d=Object.keys(u.shape),o.set(u,d)),u.parse(Object.fromEntries(d.filter(e=>Object.hasOwn(t,e)).map(e=>[e,t[e]])))}})}function ne(e){let t=v.get(e);if(!t)throw Error(`Unknown relation registry`);return t}function k(e,t){Te(t),$(e,`stored`)}function A(e){$(e.publicDto,`dto`);let t=e.dto(!0);if(!(t instanceof p.ZodObject)&&!(t instanceof p.ZodDiscriminatedUnion))throw Error(`Expected object or discriminated union DTO`);$(t,`dto`);let n=o(t),r=s(n),i=r?.boundary?void 0:c(n);if(i&&!(i instanceof p.ZodObject)&&!(i instanceof p.ZodDiscriminatedUnion))throw Error(`Expected object or discriminated union DTO`);return{dtoRecipe:n,admission:r,dto:i}}function j(e){let t=K(e);return Y(t.documentType),t}function re(e){let t=E.parse(e);return{searchIndexList:[...t.searchIndexes.map(e=>({...e,staged:!1})),...t.stagedSearchIndexes.map(e=>({...e,staged:!0}))].map(e=>Object.freeze({name:e.indexDescriptor,searchField:e.searchField,filterFields:Object.freeze([...e.filterFields].sort()),staged:e.staged})),capturedIndexes:t.indexes.map(e=>({name:e.indexDescriptor,fields:[...e.fields]}))}}function M(e){if(e.capturedIndexes.some(e=>e.fields.length===0))throw Error(`Invalid empty active index`)}function ie(e,t,n){let r=t.schema;k(r,n);let i=j(n),a={...we(e,r,i.documentType),...re(i),schema:r};return M(a),a}function ae(e,t,n){let r=t.schema;k(r,n);let i=A(t),a=j(n);return se(t,{...Ce(e,r,i.dto,a.documentType,i.admission?.boundary),...re(a)},i)}function oe(e,t,n){let r=A(t),{schema:i,...a}=n;$(i,`stored`);let o=r.admission?.boundary,s=V(e,i,r.dto,o);return se(t,{...a,branches:H(a.branches,s,o)},r)}function se(e,t,{dtoRecipe:r,admission:i,dto:a}){let s=a,l=q(s?n(s):i.emit());Y(l);let d=s?void 0:J(l),f=Object.create(null),h=Object.create(null),g=Object.getOwnPropertyDescriptor(e,`fieldGroups`);if(!g&&`fieldGroups`in e||g&&!(`value`in g))throw Error(`Invalid field groups`);P(g?.value??{});let _=p.record(p.string(),p.array(p.string()).nonempty()).parse(g?.value??{}),v=/* @__PURE__ */ new Set,y=i?.boundary?i.boundary.kind===`object`?[i.boundary.keys]:Object.values(i.boundary.branches):void 0,b=s instanceof p.ZodObject?[s]:s?.options;for(let[e,n]of Object.entries(_)){if(!e||[`__proto__`,`constructor`,`prototype`].includes(e))throw Error(`Invalid field groups`);for(let e of n){if(!t.allFields.has(e)||e.startsWith(`_`)||v.has(e)||(y?y.some(t=>t.includes(e)):b.some(t=>!(t instanceof p.ZodObject)||Object.hasOwn(t.shape,e))))throw Error(`Conflicting or incompatible field groups`);let n=t.branches?Object.values(t.branches.options).map(t=>t.fields[e]).filter(e=>e!==void 0):[t.fields[e]];if(!n.every(e=>J(q(e))===J(q(n[0]))&&e.isOptional===n[0].isOptional))throw Error(`Conflicting or incompatible field groups`);v.add(e)}f[e]=Object.freeze([...n].sort());for(let[r,i]of t.branches?Object.entries(t.branches.options).map(([e,t])=>[e,t.fields]):[[null,t.fields]]){let t=Object.fromEntries(n.filter(e=>Object.hasOwn(i,e)).map(e=>[e,i[e]]));h[JSON.stringify([e,r])]=o(u(m.object(t)).strict())}}M(t);let{capturedIndexes:x,searchIndexList:S,fields:C,branches:w,allFields:T}=t,E,ee,D={fields:C,allFields:T,capturedIndexes:x,searchIndexList:S,get indexes(){return E??=[...x].sort((e,t)=>e.name.localeCompare(t.name))},get searchIndexes(){return ee??=Object.freeze([...S].sort((e,t)=>e.name.localeCompare(t.name)))},get dto(){if(!s){let e=c(r);if(!(e instanceof p.ZodObject)&&!(e instanceof p.ZodDiscriminatedUnion))throw Error(`Expected object or discriminated union DTO`);s=e}return s},dtoNativeCanonical:d,dtoRecipe:r,fieldGroups:Object.freeze(f),groupRecipes:Object.freeze(h)};return w&&(D.branches=w),D}function ce(e){let t=f({});for(let n of e.indexes){let[e,...r]=n.fields;if(e===void 0)throw Error(`Invalid empty active index`);t.index(n.name,[e,...r])}let n=Object.getOwnPropertyDescriptor(t,`indexes`).value;for(let e of n)Object.freeze(e.fields),Object.freeze(e);return Object.freeze(n),Object.freeze(t),t}function le(e,t){let n=(e,t)=>{if(e===null||Object(e)!==e)return;let n=Object.getOwnPropertyDescriptor(e,t);return n&&`value`in n?n.value:void 0},r=e=>{let t=n(e,`fields`);if(n(e,`kind`)===`object`&&t!==null&&Object(t)===t)return t},i=[`_id`,`_creationTime`],a=n(t,`validator`),o=r(a);if(o){let e=[.../* @__PURE__ */ new Set([...Object.keys(o),...i])];return{fields:e,common:e,variant:!1}}let s=n(n(n(e.schema,`_zod`),`def`),`discriminator`);if(n(a,`kind`)!==`union`||!p.string().safeParse(s).success)return;try{Te(t)}catch{return}let c=a.members.map(r);if(!c.length||c.some(e=>!e))return;let l=c,u=[];for(let e of l){let t=e[String(s)];if(t?.kind!==`literal`||!p.string().safeParse(t.value).success)return;u.push([String(t.value),[.../* @__PURE__ */ new Set([...Object.keys(e),...i])]])}let d=[...Object.keys(l[0]).filter(e=>l.every(t=>Object.hasOwn(t,e))&&(e===s||l.every(t=>W(t[e],l[0][e])))),...i];return{fields:[...new Set(u.flatMap(([,e])=>e))],common:[...new Set(d)],variant:!0,discriminator:String(s),branches:u}}function N(e){let t;return()=>{if(!t)try{t={value:e()}}catch(e){t={error:e}}if(`error`in t)throw t.error;return t.value}}function P(e,t=0){if(t>16)throw Error(`Invalid field groups`);if(typeof e!=`object`||!e)return;let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null&&n!==Array.prototype)throw Error(`Invalid field groups`);for(let n of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,n);if(!p.string().safeParse(n).success||!(`value`in r))throw Error(`Invalid field groups`);P(r.value,t+1)}}function ue(e,t,n){P(n);function r(t,n,i){let a=p.object({fieldGroups:p.record(p.string(),p.enum([`required`,`if-permitted`])).optional(),relations:p.record(p.string(),p.unknown()).optional()}).strict().parse(n),o=e.metadata[t];if(!o)throw Error(`Unknown query table`);for(let e of Object.keys(a.fieldGroups??{}))if(!Object.hasOwn(o.fieldGroups,e))throw Error(`Unknown field group`);let s={};for(let[n,o]of Object.entries(a.relations??{})){let a=e.declarations[t]?.[n];if(!a||i>=4)throw Error(`Invalid field group relation`);s[n]=r(a.target,o,i+1)}return Object.freeze({fieldGroups:Object.freeze(a.fieldGroups??{}),relations:Object.freeze(s)})}return r(t,n,0)}function F(e,t,n,r){let i={};for(let a of t){let t=JSON.stringify([a,r??null]);if(!Object.hasOwn(e.groupRecipes,t))throw Error(`Unknown field group`);let o=c(e.groupRecipes[t]);if(!(o instanceof p.ZodObject))throw Error(`Invalid field group schema`);for(let[e,t]of Object.entries(o.shape))i[e]=n?.[a]===`if-permitted`?t.optional():t}return i}function I(e){return[`id`,`string`,`float64`,`int64`,`boolean`,`null`,`literal`].includes(e.kind)||e.kind===`union`&&e.members.every(I)}function L(e){let t=[{value:e,depth:0,ancestors:[]}],n=0;for(;t.length;){let{value:e,depth:r,ancestors:i}=t.pop();if(++n>256||r>4||i.includes(e))throw Error(`Selection cycle or depth/node budget exceeded`);let a=Object.getPrototypeOf(e);if(a!==Object.prototype&&a!==null)throw Error(`Invalid selection`);let o=Reflect.ownKeys(e);if(o.length+n+t.length>256)throw Error(`Selection node budget exceeded`);for(let a of o){let o=Object.getOwnPropertyDescriptor(e,a);if(!o.enumerable||!(`value`in o)||String(a)!==a)throw Error(`Invalid selection property`);if(o.value!==!0)t.push({value:o.value,depth:r+1,ancestors:[...i,e]});else if(++n>256)throw Error(`Selection node budget exceeded`)}}}function R(e){return`base`in e?e.base:e}function de(e,t,n,r){for(let e of[n.from,n.to])if(!r.has(R(e))||`base`in e&&(!S.has(e)||!r.has(e.junction)))throw Error(`Foreign registry or invalid field reference`);if(R(n.to).table!==e)throw Error(`Wrong relation target table`);let i=Object.freeze({[_]:!0,source:R(n.from).table,target:e,cardinality:t,from:n.from,to:n.to,sourceGuard:R(n.from).guard,targetGuard:R(n.to).guard,junctionGuard:fe(n.from,n.to),sourceMember:x.get(R(n.from)),targetMember:x.get(R(n.to))});return w.add(i),i}function fe(e,t){let n=`base`in e?e.junction.guard:void 0,r=`base`in t?t.junction.guard:void 0;if(n&&r&&(n.discriminator!==r.discriminator||n.tag!==r.tag))throw Error(`Contradictory junction scopes`);return n??r}function pe(e){if(e.kind===`id`)return[e.tableName];if(e.kind===`null`)return[];if(e.kind!==`union`)return null;let t=e.members.map(pe);return t.some(e=>e===null)?null:[...new Set(t.flatMap(e=>e))].sort()}function me(e,t){let n=z(e);return n.length>0&&JSON.stringify(n)===JSON.stringify(z(t))}function z(e){if(e.kind===`union`)return[...new Set(e.members.flatMap(z))].sort();if(e.kind===`null`)return[];if(![`id`,`string`,`float64`,`int64`,`boolean`,`literal`].includes(e.kind))throw Error(`Unsupported relation field kind`);return[JSON.stringify(q(e))]}function he(e){let t=e.from,n=e.to;if(`base`in t!=`base`in n)throw Error(`Both relation legs must use through`);if(`base`in t&&`base`in n&&t.junction.table!==n.junction.table)throw Error(`Different junction tables`)}function ge(e,t){let n=e.from,r=e.to;if(he(e),`base`in n&&`base`in r){C.get(n)(),C.get(r)(),B(t(n.junction.table),n.junction.table,n.junction.field,e.junctionGuard),B(t(e.target),e.target,r.base.field,e.targetGuard);return}if(!me(b.get(R(n))(),b.get(R(r))()))throw Error(`Incompatible relation field types`);B(t(e.target),e.target,R(r).field,e.targetGuard)}function B(e,t,n,r){if(n!==`_id`&&!e.capturedIndexes.some(e=>{let t=e.fields.indexOf(n);return t>=0&&e.fields.slice(0,t).every(e=>e===r?.discriminator)}))throw Error(`No active index begins with or has a guarded prefix for "${t}.${n}"`)}function _e(e){return`base`in e?[e.base.table,e.junction.table]:[e.table]}function ve(e){return`base`in e?[e.base.table,e.base.field,e.base.guard??null,e.junction.table,e.junction.field,e.junction.guard??null]:x.has(e)?[e.table,e.field,e.guard??null,x.get(e)]:[e.table,e.field,e.guard??null]}function ye(e){return{fields:o(p.object(e.fields)),relations:Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{cardinality:t.cardinality,target:ye(t.target)}])),variants:e.variants?{discriminator:e.variants.discriminator,options:Object.fromEntries(Object.entries(e.variants.options).map(([e,t])=>[e,ye(t)]))}:void 0}}function be(e){return{fields:c(e.fields).shape,relations:Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{cardinality:t.cardinality,target:be(t.target)}])),variants:e.variants?{discriminator:e.variants.discriminator,options:Object.fromEntries(Object.entries(e.variants.options).map(([e,t])=>[e,be(t)]))}:void 0}}function xe(e,t,n,r=0,i){let o={},s={},c=e.metadata[t],l={};for(let[u,d]of Object.entries(n)){if(u===`variants`&&d!==!0&&c.branches&&i===void 0){if(r>=4)throw Error(`Invalid variant selection`);for(let[i,a]of Object.entries(d)){if(!Object.hasOwn(c.branches.options,i)||a===!0)throw Error(`Unknown variant filter selection`);l[i]=xe(e,t,{...Object.fromEntries(Object.entries(n).filter(([e])=>e!==`variants`)),...a},r+1,i)}continue}let f=(i===void 0?c.fields:c.branches.options[i].fields)[u],p=e.declarations[t]?.[u];if(d===!0&&f)o[u]=a(f).optional();else if(d!==!0&&p&&r<4)s[u]={cardinality:p.cardinality,target:xe(e,p.target,d,r+1)};else throw Error(`Invalid relation filter selection "${t}.${u}"`)}return{fields:o,relations:s,variants:c.branches&&i===void 0?{discriminator:c.branches.discriminator,options:l}:void 0}}function Se(e,t,n,i=0,a={}){let o={};for(let[s,c]of Object.entries(n)){let n=e.declarations[t]?.[s];if(!n||i>=4)throw Error(`Unknown or too deep relation "${t}.${s}"`);let l=Se(e,n.target,c===!0?{}:c,i+1,a.relations?.[s]);if(n.targetGuard){if(!(l instanceof p.ZodDiscriminatedUnion))throw Error(`Invalid target scope`);l=l.options.filter(e=>e instanceof p.ZodObject).find(e=>e.shape[n.targetGuard.discriminator]instanceof p.ZodLiteral&&e.shape[n.targetGuard.discriminator].value===n.targetGuard.tag)}o[s]=n.cardinality===`one`?l.nullable():r(l)}let s=e.metadata[t],l=c(s.dtoRecipe);function u(n,r){let i={...o};for(let n of Object.keys(i)){let a=e.declarations[t][n];a.sourceGuard&&r!==a.sourceGuard.tag&&a.cardinality===`one`&&(i[n]=p.null())}return n.extend({...F(s,Object.keys(a.fieldGroups??{}),a.fieldGroups,r),...i}).strict()}if(s.branches){if(!(l instanceof p.ZodDiscriminatedUnion))throw Error(`Invalid variant DTO`);let e=l.options.map(e=>{if(!(e instanceof p.ZodObject))throw Error(`Invalid variant DTO`);let t=e.shape[s.branches.discriminator];if(!(t instanceof p.ZodLiteral))throw Error(`Invalid variant tag`);return u(e,String(t.value))});return p.discriminatedUnion(s.branches.discriminator,[e[0],...e.slice(1)])}if(!(l instanceof p.ZodObject))throw Error(`Expected object DTO`);return u(l)}function Ce(e,t,n,r,i){let a=V(e,t,n,i),o=we(e,t,r);return{...o,branches:H(o.branches,a,i)}}function V(e,t,n,r){if(t instanceof p.ZodObject&&(r?.kind===`object`||n instanceof p.ZodObject))return;if(!(t instanceof p.ZodDiscriminatedUnion)||!(r?.kind===`variant`||n instanceof p.ZodDiscriminatedUnion))throw Error(`Expected matching discriminated union boundaries "${e}"`);let i=t._zod.def.discriminator;if((r?.kind===`variant`?r.discriminator:n instanceof p.ZodDiscriminatedUnion?n._zod.def.discriminator:void 0)!==i)throw Error(`DTO discriminator mismatch`);let a=U(t,i),o=r?.kind===`variant`?r.branches:U(n instanceof p.ZodDiscriminatedUnion?n:t,i);if(Object.keys(a).sort().join(`\0`)!==Object.keys(o).sort().join(`\0`))throw Error(`DTO variant tags mismatch`);return o}function H(e,t,n){if(!e)return;let r=Object.create(null);for(let[i,a]of Object.entries(e.options)){let e=t?.[i];r[i]={fields:a.fields,dto:n?void 0:e instanceof p.ZodObject?e:void 0}}return{discriminator:e.discriminator,options:r}}function U(e,t){let n=Object.create(null);for(let r of e.options){if(!(r instanceof p.ZodObject))throw Error(`Variant branches must be objects`);let e=r.shape[t];if(!(e instanceof p.ZodLiteral)||e.values.size!==1)throw Error(`Variant tags must be unique required string literals`);let i=p.string().safeParse(e.value);if(!i.success||Object.hasOwn(n,i.data))throw Error(`Variant tags must be unique required string literals`);n[i.data]=r}if(Object.keys(n).length===0)throw Error(`Expected at least one variant branch`);return n}function we(e,t,r){if(t instanceof p.ZodObject){let i=n(t).fields;return X(e,i,r),{fields:i,allFields:new Set(Object.keys(i))}}if(!(t instanceof p.ZodDiscriminatedUnion))throw Error(`Expected matching discriminated union boundaries "${e}"`);let i=t._zod.def.discriminator,a=U(t,i),o={discriminator:i,options:Object.create(null)},s=[];for(let[t,r]of Object.entries(a)){let i=n(r).fields,{_id:a,_creationTime:c,...l}=i;Z(e,i),s.push(m.object(l)),o.options[t]={fields:i}}if(J(r)!==J(q(m.union(...s))))throw Error(`Native stored document disagrees with boundary "${e}"`);let c=Object.values(o.options).map(e=>e.fields),l={};for(let e of Object.keys(c[0])){if(!c.every(t=>Object.hasOwn(t,e))||e!==i&&!c.every(t=>W(t[e],c[0][e])))continue;let t=c.map(t=>t[e]),n=m.union(...t);l[e]=t.some(e=>e.isOptional===`optional`)?m.optional(n):n}return{fields:l,branches:o,allFields:new Set(c.flatMap(e=>Object.keys(e)))}}function W(e,t){try{return me(e,t)}catch{return J(q(e))===J(q(t))}}const G=/* @__PURE__ */ new Map;for(let e of[f(m.object({})),m.id(`sample`),m.null(),m.number(),m.int64(),m.commitTs(),m.boolean(),m.string(),m.bytes(),m.any(),m.object({}),m.literal(`sample`),m.array(m.string()),m.record(m.string(),m.string()),m.union(m.string(),m.null())]){let t=Object.getPrototypeOf(e);for(;t&&t!==Object.prototype;)G.has(t)||G.set(t,Object.getOwnPropertyDescriptors(t)),t=Object.getPrototypeOf(t)}function Te(e){let t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new Set;function r(e,i,a=!1){if(n.has(e))throw Error(`Unsupported cyclic native schema`);if(t.has(e))return;if(i>64||t.size>=8192)throw Error(`Native schema graph budget exceeded`);t.add(e),n.add(e);let o=Object.getPrototypeOf(e),s=o&&G.get(o);if(o!==null&&o!==Object.prototype&&o!==Array.prototype&&!s)throw Error(`Unsupported native schema prototype`);if(Object.getOwnPropertySymbols(e).length)throw Error(`Unsupported native schema symbol`);let c=Object.getOwnPropertyNames(e).map(t=>Object.getOwnPropertyDescriptor(e,t));if(!a&&c.some(e=>!(`value`in e)||e.value instanceof Function))throw Error(`Unsupported native schema accessor or method`);if(s){let e=Object.getOwnPropertyNames(o);if(e.length!==Object.getOwnPropertyNames(s).length||e.some(e=>{let t=Object.getOwnPropertyDescriptor(o,e),n=Object.getOwnPropertyDescriptor(s,e)?.value;return!n||!Object.is(t.value,n.value)||t.get!==n.get||t.set!==n.set}))throw Error(`Unsupported native schema prototype mutation`);r(o,i+1,!0)}if(!a)for(let e of c)e.value!==null&&Object(e.value)===e.value&&r(e.value,i+1);n.delete(e)}r(e,0)}function K(e){return e.export()}function q(e){return e.json}function J(e){if(Array.isArray(e))return`[${e.map(J).join(`,`)}]`;if(e!==null&&Object(e)===e){let t=e,n=`{`,r=``;for(let e of Object.keys(t).sort())n+=`${r}${JSON.stringify(e)}:${J(t[e])}`,r=`,`;return`${n}}`}return JSON.stringify(e)}function Y(e){if(e===null||Object(e)!==e)return;let t=e;if(t.type===`any`)throw Error(`Unsupported native validation form`);for(let e of Object.values(t))Y(e)}function X(e,t,n){let{_id:r,_creationTime:i,...a}=t;if(Z(e,t),J(n)!==J(q(m.object(a))))throw Error(`Native stored document disagrees with boundary "${e}"`)}function Z(e,t){let{_id:n,_creationTime:r}=t;if(!n||!r||J(q(n))!==J(q(m.id(e)))||J(q(r))!==J(q(m.number()))||n.isOptional!==`required`||r.isOptional!==`required`)throw Error(`Native stored document disagrees with boundary "${e}"`)}const Q=p.object({field:p.string()}),Ee=new Set([Q,Q.pick({field:!0}),Q.omit({field:!0}),Q.extend({other:p.string()}),Q.safeExtend({other:p.string()}),Q.merge(p.object({other:p.string()})),Q.partial(),Q.required()].flatMap(e=>{let t=Object.getOwnPropertyDescriptor(e._zod.def,`shape`)?.get;return t?[Function.prototype.toString.call(t)]:[]})),De=Function.prototype.toString.call(Object.getOwnPropertyDescriptor(p.string().default(``)._zod.def,`defaultValue`).get),Oe=Function.prototype.toString.call(Object.getOwnPropertyDescriptor(p.string().prefault(``)._zod.def,`defaultValue`).get);function $(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;function o(e,s){if(i.has(e))throw Error(`Unsupported cyclic DTO schema`);if(!r.has(e)){if(s>32||r.size>=4096)throw Error(`DTO schema graph budget exceeded`);r.add(e),i.add(e);try{let r=Object.getOwnPropertyDescriptor(e,`_zod`);if(r){if(!(`value`in r))throw Error(`Unsupported DTO schema accessor`);let e=Object.getOwnPropertyDescriptor(r.value,`def`);if(!e||!(`value`in e))throw Error(`Unsupported DTO schema accessor`)}if(e instanceof p.core.$ZodCheck&&!(e instanceof p.core.$ZodType)){if(t===`dto`&&e._zod.def.check===`overwrite`)throw Error(`Unsupported DTO overwrite check`);o(e._zod.def,s+1);return}if(e instanceof p.core.$ZodType){let r=e._zod.def;if(t===`dto`&&(![`object`,`array`,`optional`,`nullable`,`nonoptional`,`union`,`intersection`,`tuple`,`record`,`string`,`number`,`boolean`,`bigint`,`null`,`never`,`custom`,`literal`,`enum`].includes(r.type)||`coerce`in r&&r.coerce))throw Error(`Unsupported DTO schema "${r.type}"`);if(t===`stored`&&(r.type==="default"||r.type===`prefault`)){let e=Object.getOwnPropertyDescriptor(r,`defaultValue`);if(e?.get){if(e.set||Function.prototype.toString.call(e.get)!==(r.type==="default"?De:Oe))throw Error(`Unsupported stored schema accessor`);n.add(r)}}if(e instanceof p.ZodUnion&&o(e.options,s+1),r.type===`object`){let t=Object.getOwnPropertyDescriptor(r,`shape`);if(t?.get){if(t.set||!Ee.has(Function.prototype.toString.call(t.get)))throw Error(`Unsupported DTO schema accessor`);let e=r.shape;o(e,s+1),a.add(r)}if(e instanceof p.ZodObject){let t=Object.getOwnPropertyDescriptor(e,`shape`);if(t&&!(`value`in t))throw Error(`Unsupported DTO schema accessor`);o(e.shape,s+1)}}o(r,s+1);return}let i=Reflect.ownKeys(e),c=i.map(t=>Object.getOwnPropertyDescriptor(e,t));if(c.some((t,r)=>!(`value`in t)&&!(a.has(e)&&i[r]===`shape`)&&!(n.has(e)&&i[r]===`defaultValue`)))throw Error(`Unsupported DTO schema accessor`);for(let e of c)e.value!==null&&Object(e.value)===e.value&&!(e.value instanceof Function)&&o(e.value,s+1)}finally{i.delete(e)}}}o(e,0)}function ke(e){let t={};for(let[n,r]of Object.entries(e.fields))t[n]=Object.freeze({kind:r.kind,optional:r.isOptional===`optional`,nullable:Ae(r),idTables:Object.freeze(je(r)),native:Me(q(r))});return Object.freeze({fieldGroups:e.fieldGroups,searchIndexes:e.searchIndexes,fields:Object.freeze(t),variant:e.branches?Object.freeze({discriminator:e.branches.discriminator,tags:Object.freeze(Object.keys(e.branches.options))}):void 0,indexes:Object.freeze(e.indexes.map(e=>Object.freeze({name:e.name,fields:Object.freeze([...e.fields])})))})}function Ae(e){return e.kind===`null`||e.kind===`union`&&e.members.some(Ae)}function je(e){return e.kind===`id`?[e.tableName]:e.kind===`union`?[...new Set(e.members.flatMap(je))].sort():[]}function Me(e){let t=structuredClone(e),n=[t];for(;n.length;){let e=n.pop();if(Object(e)!==e)continue;let t=e;Object.freeze(t),n.push(...Object.values(t))}return t}export{D as defineRelations,O as getRelationExecutor,ne as getRelationMetadata,te as verifyRelations};
2
2
  //# sourceMappingURL=relations.mjs.map