cvx-kit 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -2
- package/dist/errors.d.mts +3 -2
- package/dist/errors.mjs +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/filters.d.mts +4 -0
- package/dist/filters.mjs +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/modules/contracts/errors.d.mts +218 -0
- package/dist/modules/contracts/errors.mjs +1 -1
- package/dist/modules/contracts/errors.mjs.map +1 -1
- package/dist/modules/effect/crud.d.mts +28 -0
- package/dist/querying/cursors.d.mts +30 -4
- package/dist/querying/cursors.mjs +1 -1
- package/dist/querying/cursors.mjs.map +1 -1
- package/dist/querying/execution.d.mts +14 -3
- package/dist/querying/execution.mjs +1 -1
- package/dist/querying/execution.mjs.map +1 -1
- package/dist/querying/failures.d.mts +13 -0
- package/dist/querying/failures.mjs +2 -0
- package/dist/querying/failures.mjs.map +1 -0
- package/dist/querying/filters.d.mts +39 -45
- package/dist/querying/filters.mjs +1 -1
- package/dist/querying/filters.mjs.map +1 -1
- package/dist/querying/planner.d.mts +11 -5
- package/dist/querying/planner.mjs +1 -1
- package/dist/querying/planner.mjs.map +1 -1
- package/dist/querying/relationships.d.mts +21 -4
- package/dist/querying/relationships.mjs +1 -1
- package/dist/querying/relationships.mjs.map +1 -1
- package/dist/querying/schema-snapshot.mjs +1 -1
- package/dist/querying/schema-snapshot.mjs.map +1 -1
- package/dist/querying/search.d.mts +69 -0
- package/dist/querying/search.mjs +2 -0
- package/dist/querying/search.mjs.map +1 -0
- package/dist/querying/security.d.mts +19 -2
- package/dist/querying/security.mjs +1 -1
- package/dist/querying/security.mjs.map +1 -1
- package/dist/querying/shared/ast.d.mts +28 -0
- package/dist/querying/shared/ast.mjs +2 -0
- package/dist/querying/shared/ast.mjs.map +1 -0
- package/dist/querying/shared/contract.d.mts +104 -0
- package/dist/querying/shared/contract.mjs +2 -0
- package/dist/querying/shared/contract.mjs.map +1 -0
- package/dist/querying/shared/evaluate.d.mts +7 -0
- package/dist/querying/shared/evaluate.mjs +2 -0
- package/dist/querying/shared/evaluate.mjs.map +1 -0
- package/dist/querying/shared/filters.d.mts +31 -0
- package/dist/querying/shared/filters.mjs +2 -0
- package/dist/querying/shared/filters.mjs.map +1 -0
- package/dist/querying.d.mts +47 -16
- package/dist/querying.mjs +1 -1
- package/dist/querying.mjs.map +1 -1
- package/dist/react/failures.d.mts +23 -0
- package/dist/react/failures.mjs +2 -0
- package/dist/react/failures.mjs.map +1 -0
- package/dist/react/optimistic.d.mts +47 -0
- package/dist/react/optimistic.mjs +2 -0
- package/dist/react/optimistic.mjs.map +1 -0
- package/dist/react/pagination-state.d.mts +40 -0
- package/dist/react/pagination-state.mjs +2 -0
- package/dist/react/pagination-state.mjs.map +1 -0
- package/dist/react/use-command.d.mts +23 -0
- package/dist/react/use-command.mjs +2 -0
- package/dist/react/use-command.mjs.map +1 -0
- package/dist/react/use-paginated-list.d.mts +32 -0
- package/dist/react/use-paginated-list.mjs +2 -0
- package/dist/react/use-paginated-list.mjs.map +1 -0
- package/dist/react.d.mts +6 -0
- package/dist/react.mjs +1 -0
- package/dist/relations-public.d.mts +2 -2
- package/dist/relations.d.mts +62 -7
- package/dist/relations.mjs +1 -1
- package/dist/relations.mjs.map +1 -1
- package/dist/zod-convex.mjs +1 -1
- package/dist/zod-convex.mjs.map +1 -1
- package/dist/zod-table.d.mts +15 -1
- package/dist/zod-table.mjs +1 -1
- package/dist/zod-table.mjs.map +1 -1
- package/package.json +21 -4
package/dist/relations.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relations.mjs","names":["paginationRecipe","captureDto","nativePagination","fieldBrand","edgeBrand","registries","executorRegistries","refs","memberRefs","throughRefs","edgeRefs","indexExport","z","defineRelations","metadata","nativeTables","ownRefs","branchRefs","fields","one","many","name","table","tables","nativeDescriptor","nativeTable","preflightNative","preflightSchema","sourceDto","dtoRecipe","dto","materializeDto","exported","nativeTableExport","assertNativeValidation","normalized","normalizeTable","indexes","index","a","b","nativeJson","zodToConvex","makeReferences","tableRefs","makeReference","ref","guard","nativeIdMembers","validator","selected","hasNull","v","field","member","junction","junctionValidator","compatible","result","validators","tag","branch","makeEdge","spec","supplied","declare","declarations","edges","source","edge","base","validatePath","internal","helpers","assertSelection","selection","relationFilterSchema","filterGrammar","paginated","rowSchema","identity","data","canonicalNative","serializeLeg","registry","snapshotMetadata","streamTables","defineTable","first","rest","defineSchema","getRelationExecutor","owned","assertSchema","names","descriptor","branchValidators","projectionKeys","scalarFields","grammars","filterNodes","validateDocument","row","cached","fieldKeys","entries","key","entry","values","convexToZod","grammar","grammarKey","depth","cacheKey","scalarValidator","scalarPredicateSchema","declaration","visit","mask","eligible","keys","getRelationMetadata","pending","nodes","ancestors","value","prototype","property","leg","own","target","junctionGuard","left","from","right","to","members","leftDomain","domain","requireIndex","position","relations","variants","relationFields","option","compose","options","schema","assertStoredDocument","document","discriminator","union","literal","documents","dtos","branches","stored","object","storage","commonCompatible","nativePrototypes","sample","seen","active","inherited","trusted","currentKeys","current","before","container","child","_id","_creationTime","objectAccessorSample","builtinObjectGetters","getter","builtinDefaultGetter","builtinPrefaultGetter","fallbackDefinitions","objectDefinitions","internals","definition","boundary","def","publicFields","i","idTables","frozenNative","snapshot","native","next"],"sources":["../src/relations.ts"],"sourcesContent":["import { z } from 'zod'\nimport { captureDto, materializeDto, type DtoRecipe } from './querying/schema-snapshot'\nimport { zodToConvex, convexToZod, type ConvexValidatorFromZod } from 'convex-helpers/server/zod4'\nimport {\n\tdefineSchema,\n\tdefineTable,\n\ttype TableDefinition,\n\ttype PaginationResult,\n} from 'convex/server'\nimport {\n\tv,\n\ttype GenericId,\n\ttype GenericValidator,\n\ttype ValidatorJSON,\n\ttype JSONValue,\n} from 'convex/values'\nimport { paginated } from './zod-table'\nimport {\n\tnativePagination,\n\trelationFilterSchema,\n\tscalarPredicateSchema,\n\ttype FieldSchemas,\n\ttype FilterGrammar,\n\ttype PaginationOptionsSchema,\n\ttype ScalarSelection,\n\ttype ScalarPredicate,\n} from './querying/filters'\n\nconst paginationRecipe = captureDto(nativePagination)\n\n/** Generated object or discriminated-union boundaries. */\nexport interface RelationTable {\n\ttableName: string\n\tschema: z.ZodObject | z.ZodDiscriminatedUnion<any, string>\n\tpublicDto: z.ZodObject | z.ZodDiscriminatedUnion<any, string>\n\ttable: TableDefinition\n\tdto(includeId: true): z.ZodType\n}\nexport type RelationTables = Record<string, RelationTable>\n/** Internal named declaration dependency; excluded from the supported relations facade. */\nexport interface SelectionMask {\n\t[key: string]: true | SelectionMask\n}\ntype DocumentFields<S> =\n\tS extends z.ZodObject<infer F>\n\t\t? F\n\t\t: S extends z.ZodDiscriminatedUnion<infer O, string>\n\t\t\t? O[number] extends infer B\n\t\t\t\t? B extends z.ZodObject<infer F>\n\t\t\t\t\t? F\n\t\t\t\t\t: never\n\t\t\t\t: never\n\t\t\t: never\ntype AllKeys<F> = F extends unknown ? keyof F : never\ntype FieldAt<F, K extends PropertyKey> = F extends unknown\n\t? K extends keyof F\n\t\t? F[K]\n\t\t: never\n\t: never\ntype NativeDomain<V> = V extends { kind: 'union'; members: infer M extends GenericValidator[] }\n\t? NativeDomain<M[number]>\n\t: V extends { kind: 'null' }\n\t\t? never\n\t\t: V extends { kind: infer K; type: infer Value }\n\t\t\t? readonly [K, Exclude<Value, undefined>]\n\t\t\t: never\ntype DomainAt<F, K extends PropertyKey> = F extends unknown\n\t? K extends keyof F\n\t\t? F[K] extends z.ZodType\n\t\t\t? NativeDomain<ConvexValidatorFromZod<F[K], 'required'>>\n\t\t\t: never\n\t\t: never\n\t: never\ntype CompatibleBranches<F, K extends keyof F, Domain = DomainAt<F, K>> = F extends unknown\n\t? Same<DomainAt<F, K>, Domain>\n\t: never\ntype Discriminator<T extends RelationTable> =\n\tT['schema'] extends z.ZodDiscriminatedUnion<any, string>\n\t\t? T['schema']['_zod']['def']['discriminator']\n\t\t: never\ntype Fields<\n\tT extends RelationTable,\n\tF = DocumentFields<T['schema']>,\n> = string extends T['tableName']\n\t? FieldSchemas\n\t: T['schema'] extends z.ZodObject<infer ObjectFields>\n\t\t? { [K in keyof ObjectFields]: Extract<ObjectFields[K], z.ZodType> }\n\t\t: {\n\t\t\t\t[\n\t\t\t\t\tK in Extract<keyof F, string> as K extends Discriminator<T>\n\t\t\t\t\t\t? K\n\t\t\t\t\t\t: false extends CompatibleBranches<F, K>\n\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t: K\n\t\t\t\t]: Extract<FieldAt<F, K>, z.ZodType>\n\t\t\t}\ntype BranchFields<T extends RelationTable, Tag extends string> =\n\tDocumentFields<T['schema']> extends infer F\n\t\t? F extends Record<Discriminator<T>, z.ZodType>\n\t\t\t? Tag extends z.output<F[Discriminator<T>]>\n\t\t\t\t? F\n\t\t\t\t: never\n\t\t\t: never\n\t\t: never\ntype Tags<T extends RelationTable> =\n\tT['schema'] extends z.ZodDiscriminatedUnion<any, string>\n\t\t? Extract<z.output<T['schema']>[Discriminator<T>], string>\n\t\t: never\ntype Native<T extends RelationTable, K extends keyof Fields<T>> = ConvexValidatorFromZod<\n\tFields<T>[K],\n\t'required'\n>['type']\nconst fieldBrand: unique symbol = Symbol('relationField')\nconst edgeBrand: unique symbol = Symbol('relationEdge')\ntype Comparable<Value> = Exclude<Value, null | undefined>\ntype IdMembers<Value, Registered extends string> = [Comparable<Value>] extends [never]\n\t? never\n\t: [Comparable<Value>] extends [GenericId<string>]\n\t\t? Extract<Comparable<Value>, GenericId<string>>['__tableName'] & Registered\n\t\t: never\ntype Same<A, B> = [Comparable<A> | Comparable<B>] extends [never]\n\t? false\n\t: [Comparable<A>] extends [Comparable<B>]\n\t\t? [Comparable<B>] extends [Comparable<A>]\n\t\t\t? true\n\t\t\t: false\n\t\t: false\n\nexport interface FieldReference<\n\tTable extends string,\n\tField extends string,\n\tValue,\n\tScope extends string = never,\n\tRegistered extends string = string,\n\tMember extends string = never,\n> {\n\treadonly guard?: RelationGuard<Scope>\n\treadonly [fieldBrand]: Value\n\treadonly table: Table\n\treadonly field: Field\n\t/** Select a registered native-ID member, retaining this field's nullish wrappers. */\n\tforTable<const T extends ([Scope] extends [never] ? IdMembers<Value, Registered> : never)>(\n\t\ttable: T,\n\t): FieldReference<\n\t\tTable,\n\t\tField,\n\t\tExtract<Value, GenericId<T> | null | undefined>,\n\t\tScope,\n\t\tRegistered,\n\t\tT\n\t>\n\tthrough<J extends AnyField>(\n\t\tjunction: J &\n\t\t\t([Member] extends [never] ? {} : never) &\n\t\t\t(J extends FieldReference<string, string, any, any, any, infer M>\n\t\t\t\t? [M] extends [never]\n\t\t\t\t\t? {}\n\t\t\t\t\t: never\n\t\t\t\t: never) &\n\t\t\t(Same<Value, J[typeof fieldBrand]> extends true ? {} : never),\n\t): ThroughReference<Table, Field, Value, J, Scope>\n}\nexport interface RelationGuard<Tag extends string = string> {\n\treadonly discriminator: string\n\treadonly tag: Tag\n}\ntype AnyField = FieldReference<string, string, any, any, any, any>\nexport interface ThroughReference<\n\tTable extends string,\n\tField extends string,\n\tValue,\n\tJunction extends AnyField,\n\tScope extends string = never,\n> {\n\treadonly base: FieldReference<Table, Field, Value, Scope>\n\treadonly junction: Junction\n}\ntype AnyThrough = ThroughReference<string, string, any, AnyField, any>\ntype Leg = AnyField | AnyThrough\ntype Base<L extends Leg> = L extends AnyThrough ? L['base'] : L\ntype JunctionTable<L extends Leg> = L extends AnyThrough ? L['junction']['table'] : never\ntype CompatibleLegs<F extends Leg, T extends Leg> = F extends AnyThrough\n\t? T extends AnyThrough\n\t\t? Same<JunctionTable<F>, JunctionTable<T>> extends true\n\t\t\t? {}\n\t\t\t: never\n\t\t: never\n\t: T extends AnyThrough\n\t\t? never\n\t\t: Same<Base<F>[typeof fieldBrand], Base<T>[typeof fieldBrand]> extends true\n\t\t\t? {}\n\t\t\t: never\n\nexport interface RelationEdge<\n\tSource extends string,\n\tTarget extends string,\n\tCardinality extends 'one' | 'many',\n\tSourceScope extends string = never,\n\tTargetScope extends string = never,\n> {\n\treadonly sourceGuard?: RelationGuard<SourceScope>\n\treadonly targetGuard?: RelationGuard<TargetScope>\n\treadonly junctionGuard?: RelationGuard\n\treadonly sourceMember?: RelationMember\n\treadonly targetMember?: RelationMember\n\treadonly [edgeBrand]: true\n\treadonly source: Source\n\treadonly target: Target\n\treadonly cardinality: Cardinality\n\treadonly from: Leg\n\treadonly to: Leg\n}\ninterface RelationMember {\n\treadonly table: string\n}\ntype AnyEdge = RelationEdge<string, string, 'one' | 'many', any, any>\ntype FieldReferences<Tables extends RelationTables> = {\n\t[T in keyof Tables]: {\n\t\t[K in Extract<keyof Fields<Tables[T]>, string>]: FieldReference<\n\t\t\tExtract<T, string>,\n\t\t\tK,\n\t\t\tNative<Tables[T], K>,\n\t\t\tnever,\n\t\t\tExtract<keyof Tables, string>\n\t\t>\n\t}\n}\nexport type BranchBuilder<Tables extends RelationTables> = <\n\tconst T extends keyof Tables & string,\n\tconst Tag extends Tags<Tables[T]>,\n>(\n\ttable: T,\n\ttag: Tag,\n) => {\n\t[K in keyof BranchFields<Tables[T], Tag> & string]: FieldReference<\n\t\tT,\n\t\tK,\n\t\tConvexValidatorFromZod<Extract<BranchFields<Tables[T], Tag>[K], z.ZodType>, 'required'>['type'],\n\t\tTag\n\t>\n}\ntype Scope<L extends Leg> = NonNullable<Base<L>['guard']>['tag']\ntype AllReferences<Tables extends RelationTables> = {\n\t[T in keyof Tables]: FieldReferences<Tables>[T][Extract<keyof FieldReferences<Tables>[T], string>]\n}[keyof Tables]\ntype Builders<Tables extends RelationTables, C extends 'one' | 'many'> = {\n\t[T in keyof Tables]: <\n\t\tF extends AllReferences<Tables> | AnyField | AnyThrough,\n\t\tTo extends\n\t\t\t| FieldReferences<Tables>[T][Extract<keyof FieldReferences<Tables>[T], string>]\n\t\t\t| AnyField\n\t\t\t| AnyThrough,\n\t>(\n\t\tspec: { from: F; to: To } & CompatibleLegs<F, To> & (Base<To>['table'] extends T ? {} : never),\n\t) => RelationEdge<Base<F>['table'], Extract<T, string>, C, Scope<F>, Scope<To>>\n}\nexport type RelationBuilder<Tables extends RelationTables> = FieldReferences<Tables> & {\n\tone: Builders<Tables, 'one'>\n\tmany: Builders<Tables, 'many'>\n}\nexport type RelationDeclarations = Record<string, Record<string, AnyEdge>>\ntype ExactDeclarations<Tables extends RelationTables, D extends RelationDeclarations> = {\n\t[T in keyof D]: T extends keyof Tables\n\t\t? {\n\t\t\t\t[K in keyof D[T]]: K extends\n\t\t\t\t\t| AllKeys<DocumentFields<Tables[T]['schema']>>\n\t\t\t\t\t| 'and'\n\t\t\t\t\t| 'or'\n\t\t\t\t\t| 'not'\n\t\t\t\t\t| 'fields'\n\t\t\t\t\t| 'then'\n\t\t\t\t\t| ([Tags<Tables[T]>] extends [never] ? never : 'variant' | 'variants')\n\t\t\t\t\t| '__proto__'\n\t\t\t\t\t| 'constructor'\n\t\t\t\t\t| 'prototype'\n\t\t\t\t\t? never\n\t\t\t\t\t: D[T][K]['source'] extends T\n\t\t\t\t\t\t? D[T][K]\n\t\t\t\t\t\t: never\n\t\t\t}\n\t\t: never\n}\ntype Depth = readonly [1, 1, 1, 1]\ntype Tail<D extends readonly 1[]> = D extends readonly [1, ...infer R extends 1[]] ? R : []\ntype Edges<D, T> = T extends keyof D ? D[T] : {}\ntype Target<E> = E extends AnyEdge ? E['target'] : never\nexport type RelationSelection<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tLevel extends readonly 1[] = Depth,\n> = Level extends readonly []\n\t? Record<string, never>\n\t: {\n\t\t\t[K in keyof Edges<D, T>]?:\n\t\t\t\t| true\n\t\t\t\t| RelationSelection<Tables, D, Extract<Target<Edges<D, T>[K]>, keyof Tables>, Tail<Level>>\n\t\t}\ntype BranchTables<Tables extends RelationTables, T extends keyof Tables, Tag extends string> = {\n\t[K in keyof Tables]: K extends T\n\t\t? Omit<Tables[K], 'schema'> & { schema: z.ZodObject<BranchFields<Tables[T], Tag>> }\n\t\t: Tables[K]\n}\ntype VariantSelections<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tLevel extends readonly 1[],\n> = {\n\t[Tag in Tags<Tables[T]>]?: RelationFilterSelection<BranchTables<Tables, T, Tag>, D, T, Level>\n}\nexport type RelationFilterSelection<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tLevel extends readonly 1[] = Depth,\n> = ([Tags<Tables[T]>] extends [never]\n\t? ScalarSelection<Fields<Tables[T]>>\n\t: Omit<ScalarSelection<Fields<Tables[T]>>, 'variants'> & {\n\t\t\tvariants?:\n\t\t\t\t| ('variants' extends keyof ScalarSelection<Fields<Tables[T]>> ? true : never)\n\t\t\t\t| VariantSelections<Tables, D, T, Level>\n\t\t}) &\n\t(Level extends readonly []\n\t\t? {}\n\t\t: {\n\t\t\t\t[K in keyof Edges<D, T>]?: RelationFilterSelection<\n\t\t\t\t\tTables,\n\t\t\t\t\tD,\n\t\t\t\t\tExtract<Target<Edges<D, T>[K]>, keyof Tables>,\n\t\t\t\t\tTail<Level>\n\t\t\t\t>\n\t\t\t})\ntype ExactOutputMask<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tL extends readonly 1[] = Depth,\n> = S & {\n\t[K in keyof S]: L extends readonly []\n\t\t? never\n\t\t: K extends keyof Edges<D, T>\n\t\t\t? S[K] extends true\n\t\t\t\t? true\n\t\t\t\t: ExactOutputMask<Tables, D, Extract<Target<Edges<D, T>[K]>, keyof Tables>, S[K], Tail<L>>\n\t\t\t: never\n}\ntype ExactFilterMask<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tL extends readonly 1[] = Depth,\n> = S & {\n\t[K in keyof S]: K extends ([Tags<Tables[T]>] extends [never] ? never : 'variants')\n\t\t? S[K] extends true\n\t\t\t? K extends keyof ScalarSelection<Fields<Tables[T]>>\n\t\t\t\t? true\n\t\t\t\t: never\n\t\t\t: S[K] & {\n\t\t\t\t\t[Tag in keyof S[K]]: Tag extends Tags<Tables[T]>\n\t\t\t\t\t\t? ExactFilterMask<\n\t\t\t\t\t\t\t\tBranchTables<Tables, T, Extract<Tag, string>>,\n\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\tS[K][Tag],\n\t\t\t\t\t\t\t\tTail<L>\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t: never\n\t\t\t\t}\n\t\t: K extends keyof ScalarSelection<Fields<Tables[T]>>\n\t\t\t? S[K] extends true\n\t\t\t\t? true\n\t\t\t\t: never\n\t\t\t: L extends readonly []\n\t\t\t\t? never\n\t\t\t\t: K extends keyof Edges<D, T>\n\t\t\t\t\t? S[K] extends true\n\t\t\t\t\t\t? never\n\t\t\t\t\t\t: ExactFilterMask<\n\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\tExtract<Target<Edges<D, T>[K]>, keyof Tables>,\n\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\tTail<L>\n\t\t\t\t\t\t\t>\n\t\t\t\t\t: never\n}\ntype ScalarValues<T extends RelationTable, S, Side extends 'input' | 'output'> = {\n\t[K in Extract<keyof S, keyof Fields<T>>]?: ScalarPredicate<Fields<T>[K], Side>\n}\nexport type RelationFilters<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tSide extends 'input' | 'output' = 'output',\n\tLevel extends readonly 1[] = Depth,\n> = Omit<\n\tScalarValues<Tables[T], S, Side>,\n\t'and' | 'or' | 'not' | 'fields' | ([Tags<Tables[T]>] extends [never] ? never : 'variant')\n> & {\n\tfields?: ScalarValues<Tables[T], S, Side>\n} & VariantFilters<Tables, D, T, S, Side, Level> &\n\t(Level extends readonly []\n\t\t? {}\n\t\t: {\n\t\t\t\t[K in Extract<keyof S, keyof Edges<D, T>>]?: Edges<D, T>[K] extends RelationEdge<\n\t\t\t\t\tstring,\n\t\t\t\t\tinfer Target,\n\t\t\t\t\tinfer C,\n\t\t\t\t\tany,\n\t\t\t\t\tany\n\t\t\t\t>\n\t\t\t\t\t? C extends 'one'\n\t\t\t\t\t\t? RelationFilters<\n\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t> | null\n\t\t\t\t\t\t:\n\t\t\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\t\t\tsome: RelationFilters<\n\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\t\t\tnone: RelationFilters<\n\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t: never\n\t\t\t} & {\n\t\t\t\tand?: readonly RelationFilters<Tables, D, T, S, Side, Tail<Level>>[]\n\t\t\t\tor?: readonly RelationFilters<Tables, D, T, S, Side, Tail<Level>>[]\n\t\t\t\tnot?: RelationFilters<Tables, D, T, S, Side, Tail<Level>>\n\t\t\t})\ntype VariantFilters<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tSide extends 'input' | 'output',\n\tL extends readonly 1[],\n> = L extends readonly []\n\t? {}\n\t: S extends { variants: infer V }\n\t\t? V extends true\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tvariant?: {\n\t\t\t\t\t\t[Tag in keyof V]: Tag extends Tags<Tables[T]>\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\ttag: Tag\n\t\t\t\t\t\t\t\t\tfilters: RelationFilters<\n\t\t\t\t\t\t\t\t\t\tBranchTables<Tables, T, Extract<Tag, string>>,\n\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t\tV[Tag] & Omit<S, 'variants'>,\n\t\t\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\t\t\tTail<L>\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t}[keyof V]\n\t\t\t\t}\n\t\t: {}\ntype PublicRow<T extends RelationTable> = z.output<T['publicDto']> & {\n\t_id: GenericId<T['tableName']>\n}\nexport type ScopedRelationRow<Row, Scope extends string, Key extends PropertyKey> = [\n\tScope,\n] extends [never]\n\t? Row\n\t: Extract<Row, Record<Key, Scope>>\ntype ComposeRelationRow<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tLevel extends readonly 1[],\n\tRow,\n> = Row extends unknown\n\t? Row &\n\t\t\t(Level extends readonly []\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\t[K in keyof S]: K extends keyof Edges<D, T>\n\t\t\t\t\t\t\t? Edges<D, T>[K] extends RelationEdge<\n\t\t\t\t\t\t\t\t\tstring,\n\t\t\t\t\t\t\t\t\tinfer Target,\n\t\t\t\t\t\t\t\t\tinfer C,\n\t\t\t\t\t\t\t\t\tinfer SourceScope,\n\t\t\t\t\t\t\t\t\tinfer TargetScope\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t? C extends 'one'\n\t\t\t\t\t\t\t\t\t? (\n\t\t\t\t\t\t\t\t\t\t\t[SourceScope] extends [never]\n\t\t\t\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t\t\t\t: Row extends ScopedRelationRow<Row, SourceScope, Discriminator<Tables[T]>>\n\t\t\t\t\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t\t\t\t\t: false\n\t\t\t\t\t\t\t\t\t\t) extends true\n\t\t\t\t\t\t\t\t\t\t? ScopedRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\tRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tS[K] extends true ? {} : S[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\t\t\t\t\tTargetScope,\n\t\t\t\t\t\t\t\t\t\t\t\tDiscriminator<Tables[Extract<Target, keyof Tables>]>\n\t\t\t\t\t\t\t\t\t\t\t> | null\n\t\t\t\t\t\t\t\t\t\t: null\n\t\t\t\t\t\t\t\t\t: PaginationResult<\n\t\t\t\t\t\t\t\t\t\t\tScopedRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\tRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tS[K] extends true ? {} : S[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\t\t\t\t\tTargetScope,\n\t\t\t\t\t\t\t\t\t\t\t\tDiscriminator<Tables[Extract<Target, keyof Tables>]>\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t: never\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t})\n\t: never\nexport type RelationRow<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tLevel extends readonly 1[] = Depth,\n> = ComposeRelationRow<Tables, D, T, S, Level, PublicRow<Tables[T]>>\nexport type RelationQueryRow<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tScope extends string = never,\n> = ScopedRelationRow<RelationRow<Tables, D, T, S>, Scope, Discriminator<Tables[T]>>\nexport interface RelationTableHelpers<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n> {\n\tpaginationOpts<const S extends RelationFilterSelection<Tables, D, T>>(\n\t\tselection: ExactFilterMask<Tables, D, T, S>,\n\t): PaginationOptionsSchema<\n\t\tRelationFilters<Tables, D, T, S>,\n\t\tRelationFilters<Tables, D, T, S, 'input'>\n\t>\n\tpageDto<const S extends RelationSelection<Tables, D, T>>(\n\t\tselection: ExactOutputMask<Tables, D, T, S>,\n\t): z.ZodType<PaginationResult<RelationRow<Tables, D, T, S>>>\n}\nexport interface RelationRegistryIdentity {\n\treadonly identity: string\n\treadonly version: 1\n}\nexport interface RelationRegistry<Tables extends RelationTables, D extends RelationDeclarations> {\n\treadonly identity: string\n\treadonly version: 1\n\treadonly tables: { [T in keyof Tables]: RelationTableHelpers<Tables, D, T> }\n}\n\nexport interface RelationFieldMetadata {\n\treadonly kind: string\n\treadonly optional: boolean\n\treadonly nullable: boolean\n\treadonly idTables: readonly string[]\n\treadonly native: Readonly<ValidatorJSON>\n}\nexport interface RelationTableMetadata {\n\treadonly fields: Readonly<Record<string, RelationFieldMetadata>>\n\treadonly variant?: { readonly discriminator: string; readonly tags: readonly string[] }\n\treadonly indexes: readonly { readonly name: string; readonly fields: readonly string[] }[]\n}\ninterface TableMetadata {\n\tfields: Record<string, GenericValidator>\n\tindexes: { name: string; fields: string[] }[]\n\tdto: z.ZodObject | z.ZodDiscriminatedUnion<any, string>\n\tbranches?: {\n\t\tdiscriminator: string\n\t\toptions: Record<string, { fields: Record<string, GenericValidator>; dto: z.ZodObject }>\n\t}\n\tallFields: ReadonlySet<string>\n\tdtoRecipe: DtoRecipe\n}\ninterface RegistryMetadata {\n\tmetadata: Record<string, TableMetadata>\n\tdeclarations: RelationDeclarations\n}\nexport interface RelationMetadata {\n\treadonly tables: Readonly<Record<string, RelationTableMetadata>>\n\treadonly declarations: Readonly<Record<string, Readonly<Record<string, AnyEdge>>>>\n}\n\nconst registries = new WeakMap<RelationRegistryIdentity, RelationMetadata>()\n// Private executor state retains validators and projection, never a database reader.\nconst executorRegistries = new WeakMap<\n\tRelationRegistryIdentity,\n\t{\n\t\tinternal: RegistryMetadata\n\t\tnativeTables: Readonly<Record<string, TableDefinition>>\n\t\tstreamSchema: ReturnType<typeof defineSchema>\n\t}\n>()\nconst refs = new WeakMap<AnyField, GenericValidator>()\nconst memberRefs = new WeakMap<AnyField, RelationMember>()\nconst throughRefs = new WeakSet<AnyThrough>()\nconst edgeRefs = new WeakSet<AnyEdge>()\nconst indexExport = z.object({\n\tindexes: z.array(z.object({ indexDescriptor: z.string(), fields: z.array(z.string()) })),\n})\n\n/** No ID-field inference and no readers: this registry owns declarations/schema helpers only. */\nexport function defineRelations<\n\tconst Tables extends RelationTables,\n\tconst D extends RelationDeclarations,\n>(\n\ttables: Tables,\n\tdeclare: (\n\t\tr: RelationBuilder<Tables>,\n\t\tbranch: BranchBuilder<Tables>,\n\t) => D & ExactDeclarations<Tables, D>,\n): RelationRegistry<Tables, D> {\n\tconst metadata: Record<string, TableMetadata> = {}\n\tconst nativeTables: Record<string, TableDefinition> = {}\n\tconst ownRefs = new Set<AnyField>()\n\tconst branchRefs = new Map<string, Record<string, AnyField>>()\n\tconst fields: Record<string, Record<string, AnyField>> = {}\n\tconst one: Record<string, (spec: { from: Leg; to: Leg }) => AnyEdge> = {}\n\tconst many: Record<string, (spec: { from: Leg; to: Leg }) => AnyEdge> = {}\n\tfor (const [name, table] of Object.entries(tables)) {\n\t\tif (\n\t\t\ttable.tableName !== name ||\n\t\t\t['one', 'many', '__proto__', 'constructor', 'prototype'].includes(name)\n\t\t)\n\t\t\tthrow new Error(`Invalid relation table \"${name}\"`)\n\t\t// Registration-only preflight rejects accessors before native export or DTO\n\t\t// conversion. Stored parsers and their default/pipe callbacks are never run.\n\t\tconst nativeDescriptor = Object.getOwnPropertyDescriptor(table, 'table')\n\t\tif (!nativeDescriptor || !('value' in nativeDescriptor))\n\t\t\tthrow new Error('Unsupported native table accessor')\n\t\tconst nativeTable: TableDefinition = nativeDescriptor.value\n\t\tpreflightNative(nativeTable)\n\t\tpreflightSchema(table.schema, 'stored')\n\t\tpreflightSchema(table.publicDto, 'dto')\n\t\tconst sourceDto = table.dto(true)\n\t\tif (!(sourceDto instanceof z.ZodObject) && !(sourceDto instanceof z.ZodDiscriminatedUnion))\n\t\t\tthrow new Error('Expected object or discriminated union DTO')\n\t\tpreflightSchema(sourceDto, 'dto')\n\t\tconst dtoRecipe = captureDto(sourceDto)\n\t\tconst dto = materializeDto(dtoRecipe)\n\t\tif (!(dto instanceof z.ZodObject) && !(dto instanceof z.ZodDiscriminatedUnion))\n\t\t\tthrow new Error('Expected object or discriminated union DTO')\n\t\tconst exported = nativeTableExport(nativeTable)\n\t\tassertNativeValidation(exported.documentType)\n\t\tconst normalized = normalizeTable(name, table.schema, dto, exported.documentType)\n\t\tconst indexes = indexExport\n\t\t\t.parse(exported)\n\t\t\t.indexes.map((index) => ({ name: index.indexDescriptor, fields: [...index.fields] }))\n\t\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\t\tassertNativeValidation(nativeJson(zodToConvex(dto)))\n\t\tnativeTables[name] = nativeTable\n\t\tmetadata[name] = { ...normalized, indexes, dto, dtoRecipe }\n\t\tconst makeReferences = (\n\t\t\tvalidators: Record<string, GenericValidator>,\n\t\t\tguard?: RelationGuard,\n\t\t) => {\n\t\t\tconst tableRefs: Record<string, AnyField> = Object.create(null)\n\t\t\tfunction makeReference(\n\t\t\t\tfield: string,\n\t\t\t\tvalidator: GenericValidator,\n\t\t\t\tmember?: RelationMember,\n\t\t\t): AnyField {\n\t\t\t\tconst ref: AnyField = {\n\t\t\t\t\t[fieldBrand]: undefined,\n\t\t\t\t\ttable: name,\n\t\t\t\t\tfield,\n\t\t\t\t\tguard,\n\t\t\t\t\tforTable(table: string) {\n\t\t\t\t\t\tif (guard) throw new Error('forTable on branch-scoped fields is unsupported')\n\t\t\t\t\t\tconst members = nativeIdMembers(validator)\n\t\t\t\t\t\tif (!members?.includes(table)) throw new Error('Invalid native ID member selection')\n\t\t\t\t\t\tif (!Object.hasOwn(metadata, table))\n\t\t\t\t\t\t\tthrow new Error('Native ID member table is not registered')\n\t\t\t\t\t\tconst selected = hasNull(validator) ? v.union(v.id(table), v.null()) : v.id(table)\n\t\t\t\t\t\treturn makeReference(\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalidator.isOptional === 'optional' ? v.optional(selected) : selected,\n\t\t\t\t\t\t\tObject.freeze({ table }),\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t\tthrough<J extends AnyField>(junction: J): ThroughReference<string, string, any, J, any> {\n\t\t\t\t\t\tif (member || memberRefs.has(junction))\n\t\t\t\t\t\t\tthrow new Error('forTable with through is unsupported')\n\t\t\t\t\t\tconst junctionValidator = refs.get(junction)\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!ownRefs.has(junction) ||\n\t\t\t\t\t\t\t!junctionValidator ||\n\t\t\t\t\t\t\t!compatible(validator, junctionValidator)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error('Invalid junction field or registry')\n\t\t\t\t\t\tconst result = Object.freeze({ base: ref, junction })\n\t\t\t\t\t\tthroughRefs.add(result)\n\t\t\t\t\t\treturn result\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\trefs.set(ref, validator)\n\t\t\t\tif (member) memberRefs.set(ref, member)\n\t\t\t\townRefs.add(ref)\n\t\t\t\treturn Object.freeze(ref)\n\t\t\t}\n\t\t\tfor (const [field, validator] of Object.entries(validators))\n\t\t\t\ttableRefs[field] = makeReference(field, validator)\n\t\t\treturn Object.freeze(tableRefs)\n\t\t}\n\t\tfields[name] = makeReferences(normalized.fields)\n\t\tif (normalized.branches)\n\t\t\tfor (const [tag, branch] of Object.entries(normalized.branches.options))\n\t\t\t\tbranchRefs.set(\n\t\t\t\t\tJSON.stringify([name, tag]),\n\t\t\t\t\tmakeReferences(\n\t\t\t\t\t\tbranch.fields,\n\t\t\t\t\t\tObject.freeze({ discriminator: normalized.branches.discriminator, tag }),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\tone[name] = (spec) => makeEdge(name, 'one', spec, ownRefs)\n\t\tmany[name] = (spec) => makeEdge(name, 'many', spec, ownRefs)\n\t}\n\t// SAFETY: every native field has a branded reference; mapped builders retain the literal names.\n\tconst builder = Object.freeze({\n\t\t...fields,\n\t\tone: Object.freeze(one),\n\t\tmany: Object.freeze(many),\n\t}) as RelationBuilder<Tables>\n\t// SAFETY: branch references are created only for validated table/tag pairs and retain literal native field types.\n\tconst branch = ((table: string, tag: string) => {\n\t\tconst result = branchRefs.get(JSON.stringify([table, tag]))\n\t\tif (!result) throw new Error(`Unknown variant scope \"${table}.${tag}\"`)\n\t\treturn result\n\t}) as BranchBuilder<Tables>\n\tconst supplied = declare(builder, branch)\n\tconst declarations: RelationDeclarations = Object.fromEntries(\n\t\tObject.entries(supplied).map(([name, edges]) => [name, Object.freeze({ ...edges })]),\n\t)\n\tObject.freeze(declarations)\n\tfor (const [source, edges] of Object.entries(declarations)) {\n\t\tif (!Object.hasOwn(metadata, source)) throw new Error(`Unknown source table \"${source}\"`)\n\t\tfor (const [name, edge] of Object.entries(edges)) {\n\t\t\tif (\n\t\t\t\tmetadata[source].allFields.has(name) ||\n\t\t\t\t(metadata[source].branches && ['variant', 'variants'].includes(name)) ||\n\t\t\t\t['and', 'or', 'not', 'fields', 'then', '__proto__', 'constructor', 'prototype'].includes(\n\t\t\t\t\tname,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error(`Relation name collision \"${name}\"`)\n\t\t\tif (\n\t\t\t\t!edgeRefs.has(edge) ||\n\t\t\t\t!ownRefs.has(base(edge.from)) ||\n\t\t\t\t!ownRefs.has(base(edge.to)) ||\n\t\t\t\tedge.source !== source\n\t\t\t)\n\t\t\t\tthrow new Error('Relation source bucket mismatch')\n\t\t\tvalidatePath(edge, metadata)\n\t\t}\n\t}\n\tconst internal: RegistryMetadata = { metadata, declarations }\n\tconst helpers: Record<\n\t\tstring,\n\t\t{\n\t\t\tpaginationOpts(selection: SelectionMask): z.ZodType\n\t\t\tpageDto(selection: SelectionMask): z.ZodType\n\t\t}\n\t> = {}\n\tfor (const table of Object.keys(metadata))\n\t\thelpers[table] = {\n\t\t\tpaginationOpts(selection: SelectionMask): z.ZodType {\n\t\t\t\tassertSelection(selection)\n\t\t\t\treturn materializeDto(paginationRecipe).extend({\n\t\t\t\t\tfilters: relationFilterSchema(filterGrammar(internal, table, selection)).optional(),\n\t\t\t\t\torder: z.enum(['asc', 'desc']).optional(),\n\t\t\t\t})\n\t\t\t},\n\t\t\tpageDto(selection: SelectionMask): z.ZodType {\n\t\t\t\tassertSelection(selection)\n\t\t\t\treturn paginated(rowSchema(internal, table, selection)).result\n\t\t\t},\n\t\t}\n\n\t// Stable, collision-free canonical metadata encoding. It is an identity, not a secret/hash.\n\tconst identity = JSON.stringify([\n\t\t2,\n\t\tObject.entries(metadata)\n\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t.map(([name, data]) => [\n\t\t\t\tname,\n\t\t\t\tObject.entries(data.fields)\n\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t.map(([field, validator]) => [field, validator.isOptional, nativeJson(validator)]),\n\t\t\t\tdata.branches\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tdata.branches.discriminator,\n\t\t\t\t\t\t\tObject.entries(data.branches.options)\n\t\t\t\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t\t\t\t.map(([tag, branch]) => [\n\t\t\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\t\t\tObject.entries(branch.fields)\n\t\t\t\t\t\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t\t\t\t\t\t.map(([field, validator]) => [\n\t\t\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\t\t\tvalidator.isOptional,\n\t\t\t\t\t\t\t\t\t\t\tnativeJson(validator),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]\n\t\t\t\t\t: null,\n\t\t\t\tdata.indexes,\n\t\t\t\tcanonicalNative(nativeJson(zodToConvex(data.dto))),\n\t\t\t]),\n\t\tObject.entries(declarations)\n\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t.map(([source, edges]) => [\n\t\t\t\tsource,\n\t\t\t\tObject.entries(edges)\n\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t.map(([name, edge]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tedge.cardinality,\n\t\t\t\t\t\tedge.target,\n\t\t\t\t\t\tserializeLeg(edge.from),\n\t\t\t\t\t\tserializeLeg(edge.to),\n\t\t\t\t\t]),\n\t\t\t]),\n\t])\n\t// SAFETY: helpers are assembled for every validated literal table and mask; schemas derive matching native fields/public DTOs.\n\tconst registry = Object.freeze({\n\t\tidentity,\n\t\tversion: 1,\n\t\ttables: Object.freeze(helpers),\n\t}) as RelationRegistry<Tables, D>\n\tregistries.set(registry, snapshotMetadata(internal))\n\t// convex-helpers reads schema.tables[table].indexes live. Supply a genuine\n\t// private Convex schema whose only purpose is stable stream index metadata.\n\tconst streamTables: Record<string, TableDefinition> = {}\n\tfor (const [name, data] of Object.entries(metadata)) {\n\t\tconst table: TableDefinition = defineTable({})\n\t\tfor (const index of data.indexes) {\n\t\t\tconst [first, ...rest] = index.fields\n\t\t\tif (first === undefined) throw new Error('Invalid empty active index')\n\t\t\ttable.index(index.name, [first, ...rest])\n\t\t}\n\t\tconst indexes = Object.getOwnPropertyDescriptor(table, 'indexes')!.value\n\t\tfor (const index of indexes) {\n\t\t\tObject.freeze(index.fields)\n\t\t\tObject.freeze(index)\n\t\t}\n\t\tObject.freeze(indexes)\n\t\tObject.freeze(table)\n\t\tstreamTables[name] = table\n\t}\n\texecutorRegistries.set(registry, {\n\t\tinternal,\n\t\tnativeTables: Object.freeze(nativeTables),\n\t\tstreamSchema: defineSchema(Object.freeze(streamTables)),\n\t})\n\treturn registry\n}\n\n/** Internal owned executor bridge. Source ownership is checked once by each engine. */\nexport function getRelationExecutor(registry: RelationRegistryIdentity) {\n\tconst owned = executorRegistries.get(registry)\n\tif (!owned) throw new Error('Unknown relation registry')\n\tconst assertSchema = (tables: Readonly<Record<string, TableDefinition>>) => {\n\t\tconst names = Object.keys(owned.nativeTables)\n\t\tif (\n\t\t\tnames.length !== Reflect.ownKeys(tables).length ||\n\t\t\tnames.some((name) => {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(tables, name)\n\t\t\t\treturn (\n\t\t\t\t\t!descriptor || !('value' in descriptor) || descriptor.value !== owned.nativeTables[name]\n\t\t\t\t)\n\t\t\t})\n\t\t)\n\t\t\tthrow new Error('Native schema/table ownership disagrees with relation registry')\n\t}\n\tconst branchValidators = new WeakMap<\n\t\tobject,\n\t\t{ validator: z.ZodType; fieldKeys: readonly string[] }\n\t>()\n\tconst projectionKeys = new WeakMap<z.ZodObject, readonly string[]>()\n\tconst scalarFields = new Map<string, FieldSchemas>()\n\tconst grammars = new Map<string, FilterGrammar>()\n\tconst filterNodes = new WeakMap<FilterGrammar, Map<number, z.ZodObject>>()\n\tfunction validateDocument(\n\t\ttable: string,\n\t\trow: Record<string, import('convex/values').Value>,\n\t): void {\n\t\tconst data = owned!.internal.metadata[table]\n\t\tif (!data) throw new Error('Unknown query table')\n\t\tif (!data.branches) return\n\t\tconst tag = row[data.branches.discriminator]\n\t\tconst branch =\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Native discriminator admission precedes the captured branch parser.\n\t\t\ttypeof tag === 'string' && Object.hasOwn(data.branches.options, tag)\n\t\t\t\t? data.branches.options[tag]\n\t\t\t\t: undefined\n\t\tif (!branch) throw new Error('Invalid variant document')\n\t\tlet cached = branchValidators.get(branch)\n\t\tconst fieldKeys = cached?.fieldKeys ?? Object.keys(branch.fields)\n\t\tconst entries: [string, import('convex/values').Value | undefined][] = []\n\t\t// Snapshot ownership before reading getters, as filter().map() did.\n\t\tfor (const key of fieldKeys) if (Object.hasOwn(row, key)) entries.push([key, undefined])\n\t\tfor (const entry of entries) entry[1] = row[entry[0]]\n\t\tconst values = Object.fromEntries(entries)\n\t\tif (!cached) {\n\t\t\tcached = { validator: convexToZod(v.object(branch.fields)), fieldKeys }\n\t\t\tbranchValidators.set(branch, cached)\n\t\t}\n\t\tcached.validator.parse(values)\n\t}\n\treturn Object.freeze({\n\t\tstreamSchema: owned.streamSchema,\n\t\tvalidateDocument,\n\t\tassertSchema,\n\t\tpagination(table: string) {\n\t\t\tconst internal = owned.internal\n\t\t\tfunction grammar(name: string, depth: number, tag?: string): FilterGrammar {\n\t\t\t\tconst grammarKey = JSON.stringify([name, depth, tag ?? null])\n\t\t\t\tconst cached = grammars.get(grammarKey)\n\t\t\t\tif (cached) return cached\n\t\t\t\tconst data = internal.metadata[name]\n\t\t\t\tif (!data) throw new Error('Unknown query table')\n\t\t\t\tconst cacheKey = JSON.stringify([name, tag ?? null])\n\t\t\t\tlet fields = scalarFields.get(cacheKey)\n\t\t\t\tif (!fields) {\n\t\t\t\t\tfields = {}\n\t\t\t\t\tfor (const [name, validator] of Object.entries(\n\t\t\t\t\t\ttag === undefined ? data.fields : data.branches!.options[tag].fields,\n\t\t\t\t\t)) {\n\t\t\t\t\t\t// Unsupported stored containers are not scalar-queryable. No validators\n\t\t\t\t\t\t// are reconstructed from JSON; these are the actual native validators.\n\t\t\t\t\t\tif (scalarValidator(validator))\n\t\t\t\t\t\t\tfields[name] = scalarPredicateSchema(validator).optional()\n\t\t\t\t\t}\n\t\t\t\t\tscalarFields.set(cacheKey, fields)\n\t\t\t\t}\n\t\t\t\tconst result: FilterGrammar = {\n\t\t\t\t\tfields,\n\t\t\t\t\tvariants:\n\t\t\t\t\t\tdata.branches && tag === undefined && depth < 4\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tdiscriminator: data.branches.discriminator,\n\t\t\t\t\t\t\t\t\toptions: Object.fromEntries(\n\t\t\t\t\t\t\t\t\t\tObject.keys(data.branches.options).map((tag) => [\n\t\t\t\t\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\t\t\t\t\tgrammar(name, depth + 1, tag),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\trelations:\n\t\t\t\t\t\tdepth >= 4\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.entries(internal.declarations[name] ?? {}).map(([edge, declaration]) => [\n\t\t\t\t\t\t\t\t\t\tedge,\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcardinality: declaration.cardinality,\n\t\t\t\t\t\t\t\t\t\t\ttarget: grammar(declaration.target, depth + 1),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t\tgrammars.set(grammarKey, result)\n\t\t\t\treturn result\n\t\t\t}\n\t\t\treturn materializeDto(paginationRecipe).extend({\n\t\t\t\tfilters: relationFilterSchema(grammar(table, 0), filterNodes).optional(),\n\t\t\t\torder: z.enum(['asc', 'desc']).optional(),\n\t\t\t})\n\t\t},\n\t\tselect(table: string, selection: SelectionMask) {\n\t\t\tassertSelection(selection)\n\t\t\tfunction visit(table: string, selected: SelectionMask, depth: number): void {\n\t\t\t\tif (!Object.hasOwn(owned!.internal.metadata, table)) throw new Error('Unknown query table')\n\t\t\t\tfor (const [name, mask] of Object.entries(selected)) {\n\t\t\t\t\tconst edge = owned!.internal.declarations[table]?.[name]\n\t\t\t\t\tif (!edge || depth >= 4)\n\t\t\t\t\t\tthrow new Error(`Unknown or too deep relation \"${table}.${name}\"`)\n\t\t\t\t\tif (mask !== true) visit(edge.target, mask, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\tvisit(table, selection, 0)\n\t\t},\n\t\tproject(\n\t\t\ttable: string,\n\t\t\trow: Record<string, import('convex/values').Value>,\n\t\t\teligible: () => boolean,\n\t\t) {\n\t\t\tif (!eligible()) return null\n\t\t\tconst data = owned.internal.metadata[table]\n\t\t\tif (!data) throw new Error('Unknown query table')\n\t\t\tconst branch = data.branches\n\t\t\t\t? data.branches.options[String(row[data.branches.discriminator])]\n\t\t\t\t: undefined\n\t\t\tif (data.branches && !branch) throw new Error('Invalid variant document')\n\t\t\tconst dto = branch?.dto ?? data.dto\n\t\t\tif (!(dto instanceof z.ZodObject)) throw new Error('Invalid variant DTO')\n\t\t\tvalidateDocument(table, row)\n\t\t\tlet keys = projectionKeys.get(dto)\n\t\t\tif (!keys) {\n\t\t\t\tkeys = Object.keys(dto.shape)\n\t\t\t\tprojectionKeys.set(dto, keys)\n\t\t\t}\n\t\t\t// The strict DTO remains the authority. Pick its fields before parsing,\n\t\t\t// matching table projection without spreading any storage-only fields.\n\t\t\treturn dto.parse(\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tkeys.filter((key) => Object.hasOwn(row, key)).map((key) => [key, row[key]]),\n\t\t\t\t),\n\t\t\t)\n\t\t},\n\t})\n}\n/** Internal compiler/engine adapter. Registry identity alone cannot forge a registry. */\nexport function getRelationMetadata(registry: RelationRegistryIdentity): RelationMetadata {\n\tconst metadata = registries.get(registry)\n\tif (!metadata) throw new Error('Unknown relation registry')\n\treturn metadata\n}\n\nfunction scalarValidator(validator: GenericValidator): boolean {\n\treturn (\n\t\t['id', 'string', 'float64', 'int64', 'boolean', 'null', 'literal'].includes(validator.kind) ||\n\t\t(validator.kind === 'union' && validator.members.every(scalarValidator))\n\t)\n}\n\nfunction assertSelection(selection: SelectionMask): void {\n\tconst pending: { value: SelectionMask; depth: number; ancestors: readonly SelectionMask[] }[] = [\n\t\t{ value: selection, depth: 0, ancestors: [] },\n\t]\n\tlet nodes = 0\n\twhile (pending.length) {\n\t\tconst { value, depth, ancestors } = pending.pop()!\n\t\tif (++nodes > 256 || depth > 4 || ancestors.includes(value))\n\t\t\tthrow new Error('Selection cycle or depth/node budget exceeded')\n\t\tconst prototype = Object.getPrototypeOf(value)\n\t\tif (prototype !== Object.prototype && prototype !== null) throw new Error('Invalid selection')\n\t\tconst keys = Reflect.ownKeys(value)\n\t\tif (keys.length + nodes + pending.length > 256)\n\t\t\tthrow new Error('Selection node budget exceeded')\n\t\tfor (const key of keys) {\n\t\t\tconst property = Object.getOwnPropertyDescriptor(value, key)!\n\t\t\tif (!property.enumerable || !('value' in property) || String(key) !== key)\n\t\t\t\tthrow new Error('Invalid selection property')\n\t\t\tif (property.value !== true)\n\t\t\t\tpending.push({ value: property.value, depth: depth + 1, ancestors: [...ancestors, value] })\n\t\t\telse if (++nodes > 256) throw new Error('Selection node budget exceeded')\n\t\t}\n\t}\n}\nfunction base(leg: Leg): AnyField {\n\treturn 'base' in leg ? leg.base : leg\n}\nfunction makeEdge(\n\ttarget: string,\n\tcardinality: 'one' | 'many',\n\tspec: { from: Leg; to: Leg },\n\town: Set<AnyField>,\n): AnyEdge {\n\tfor (const leg of [spec.from, spec.to]) {\n\t\tif (!own.has(base(leg)) || ('base' in leg && (!throughRefs.has(leg) || !own.has(leg.junction))))\n\t\t\tthrow new Error('Foreign registry or invalid field reference')\n\t}\n\tif (base(spec.to).table !== target) throw new Error('Wrong relation target table')\n\tconst result: AnyEdge = Object.freeze({\n\t\t[edgeBrand]: true as const,\n\t\tsource: base(spec.from).table,\n\t\ttarget,\n\t\tcardinality,\n\t\tfrom: spec.from,\n\t\tto: spec.to,\n\t\tsourceGuard: base(spec.from).guard,\n\t\ttargetGuard: base(spec.to).guard,\n\t\tjunctionGuard: junctionGuard(spec.from, spec.to),\n\t\tsourceMember: memberRefs.get(base(spec.from)),\n\t\ttargetMember: memberRefs.get(base(spec.to)),\n\t})\n\tedgeRefs.add(result)\n\treturn result\n}\nfunction junctionGuard(from: Leg, to: Leg): RelationGuard | undefined {\n\tconst left = 'base' in from ? from.junction.guard : undefined\n\tconst right = 'base' in to ? to.junction.guard : undefined\n\tif (left && right && (left.discriminator !== right.discriminator || left.tag !== right.tag))\n\t\tthrow new Error('Contradictory junction scopes')\n\treturn left ?? right\n}\nfunction nativeIdMembers(validator: GenericValidator): string[] | null {\n\tif (validator.kind === 'id') return [validator.tableName]\n\tif (validator.kind === 'null') return []\n\tif (validator.kind !== 'union') return null\n\tconst members = validator.members.map(nativeIdMembers)\n\treturn members.some((member) => member === null)\n\t\t? null\n\t\t: [...new Set(members.flatMap((member) => member!))].sort()\n}\nfunction compatible(left: GenericValidator, right: GenericValidator): boolean {\n\tconst leftDomain = domain(left)\n\treturn leftDomain.length > 0 && JSON.stringify(leftDomain) === JSON.stringify(domain(right))\n}\nfunction domain(validator: GenericValidator): string[] {\n\tif (validator.kind === 'union') return [...new Set(validator.members.flatMap(domain))].sort()\n\tif (validator.kind === 'null') return []\n\tif (!['id', 'string', 'float64', 'int64', 'boolean', 'literal'].includes(validator.kind))\n\t\tthrow new Error('Unsupported relation field kind')\n\treturn [JSON.stringify(nativeJson(validator))]\n}\nfunction validatePath(edge: AnyEdge, metadata: Record<string, TableMetadata>): void {\n\tconst from = edge.from\n\tconst to = edge.to\n\tif ('base' in from !== 'base' in to) throw new Error('Both relation legs must use through')\n\tif ('base' in from && 'base' in to) {\n\t\tif (from.junction.table !== to.junction.table) throw new Error('Different junction tables')\n\t\trequireIndex(metadata, from.junction.table, from.junction.field, edge.junctionGuard)\n\t\trequireIndex(metadata, edge.target, to.base.field, edge.targetGuard)\n\t\treturn\n\t}\n\tif (!compatible(refs.get(base(from))!, refs.get(base(to))!))\n\t\tthrow new Error('Incompatible relation field types')\n\trequireIndex(metadata, edge.target, base(to).field, edge.targetGuard)\n}\nfunction requireIndex(\n\tmetadata: Record<string, TableMetadata>,\n\ttable: string,\n\tfield: string,\n\tguard?: RelationGuard,\n): void {\n\tif (\n\t\tfield !== '_id' &&\n\t\t!metadata[table].indexes.some((index) => {\n\t\t\tconst position = index.fields.indexOf(field)\n\t\t\treturn (\n\t\t\t\tposition >= 0 &&\n\t\t\t\tindex.fields.slice(0, position).every((key) => key === guard?.discriminator)\n\t\t\t)\n\t\t})\n\t)\n\t\tthrow new Error(`No active index begins with or has a guarded prefix for \"${table}.${field}\"`)\n}\nfunction serializeLeg(leg: Leg): unknown[] {\n\treturn 'base' in leg\n\t\t? [\n\t\t\t\tleg.base.table,\n\t\t\t\tleg.base.field,\n\t\t\t\tleg.base.guard ?? null,\n\t\t\t\tleg.junction.table,\n\t\t\t\tleg.junction.field,\n\t\t\t\tleg.junction.guard ?? null,\n\t\t\t]\n\t\t: memberRefs.has(leg)\n\t\t\t? [leg.table, leg.field, leg.guard ?? null, memberRefs.get(leg)]\n\t\t\t: [leg.table, leg.field, leg.guard ?? null]\n}\nfunction filterGrammar(\n\tregistry: RegistryMetadata,\n\ttable: string,\n\tselection: SelectionMask,\n\tdepth: number = 0,\n\ttag?: string,\n): FilterGrammar {\n\tconst fields: FieldSchemas = {}\n\tconst relations: FilterGrammar['relations'] = {}\n\tconst data = registry.metadata[table]\n\tconst variants: Record<string, FilterGrammar> = {}\n\tfor (const [key, mask] of Object.entries(selection)) {\n\t\tif (key === 'variants' && mask !== true && data.branches && tag === undefined) {\n\t\t\tif (depth >= 4) throw new Error('Invalid variant selection')\n\t\t\tfor (const [tag, selected] of Object.entries(mask)) {\n\t\t\t\tif (!Object.hasOwn(data.branches.options, tag) || selected === true)\n\t\t\t\t\tthrow new Error('Unknown variant filter selection')\n\t\t\t\tconst common = Object.fromEntries(\n\t\t\t\t\tObject.entries(selection).filter(([key]) => key !== 'variants'),\n\t\t\t\t)\n\t\t\t\tvariants[tag] = filterGrammar(registry, table, { ...common, ...selected }, depth + 1, tag)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tconst validator = (tag === undefined ? data.fields : data.branches!.options[tag].fields)[key]\n\t\tconst edge = registry.declarations[table]?.[key]\n\t\tif (mask === true && validator) fields[key] = scalarPredicateSchema(validator).optional()\n\t\telse if (mask !== true && edge && depth < 4)\n\t\t\trelations[key] = {\n\t\t\t\tcardinality: edge.cardinality,\n\t\t\t\ttarget: filterGrammar(registry, edge.target, mask, depth + 1),\n\t\t\t}\n\t\telse throw new Error(`Invalid relation filter selection \"${table}.${key}\"`)\n\t}\n\treturn {\n\t\tfields,\n\t\trelations,\n\t\tvariants:\n\t\t\tdata.branches && tag === undefined\n\t\t\t\t? { discriminator: data.branches.discriminator, options: variants }\n\t\t\t\t: undefined,\n\t}\n}\nfunction rowSchema(\n\tregistry: RegistryMetadata,\n\ttable: string,\n\tselection: SelectionMask,\n\tdepth: number = 0,\n): z.ZodType {\n\tconst relationFields: FieldSchemas = {}\n\tfor (const [name, mask] of Object.entries(selection)) {\n\t\tconst edge = registry.declarations[table]?.[name]\n\t\tif (!edge || depth >= 4) throw new Error(`Unknown or too deep relation \"${table}.${name}\"`)\n\t\tlet target =\n\t\t\tmask === true\n\t\t\t\t? materializeDto(registry.metadata[edge.target].dtoRecipe)\n\t\t\t\t: rowSchema(registry, edge.target, mask, depth + 1)\n\t\tif (edge.targetGuard) {\n\t\t\tif (!(target instanceof z.ZodDiscriminatedUnion)) throw new Error('Invalid target scope')\n\t\t\ttarget = target.options\n\t\t\t\t.filter((option): option is z.ZodObject => option instanceof z.ZodObject)\n\t\t\t\t.find(\n\t\t\t\t\t(option: z.ZodObject) =>\n\t\t\t\t\t\toption.shape[edge.targetGuard!.discriminator] instanceof z.ZodLiteral &&\n\t\t\t\t\t\toption.shape[edge.targetGuard!.discriminator].value === edge.targetGuard!.tag,\n\t\t\t\t)!\n\t\t}\n\t\trelationFields[name] = edge.cardinality === 'one' ? target.nullable() : paginated(target).result\n\t}\n\tconst data = registry.metadata[table]\n\tconst dto = materializeDto(data.dtoRecipe)\n\tfunction compose(dto: z.ZodObject, tag?: string) {\n\t\tconst selected = { ...relationFields }\n\t\tfor (const name of Object.keys(selected)) {\n\t\t\tconst edge = registry.declarations[table][name]\n\t\t\tif (edge.sourceGuard && tag !== edge.sourceGuard.tag && edge.cardinality === 'one')\n\t\t\t\tselected[name] = z.null()\n\t\t}\n\t\treturn dto.extend(selected).strict()\n\t}\n\tif (data.branches) {\n\t\tif (!(dto instanceof z.ZodDiscriminatedUnion)) throw new Error('Invalid variant DTO')\n\t\tconst options = dto.options.map((option) => {\n\t\t\tif (!(option instanceof z.ZodObject)) throw new Error('Invalid variant DTO')\n\t\t\tconst tag = option.shape[data.branches!.discriminator]\n\t\t\tif (!(tag instanceof z.ZodLiteral)) throw new Error('Invalid variant tag')\n\t\t\treturn compose(option, String(tag.value))\n\t\t})\n\t\treturn z.discriminatedUnion(data.branches.discriminator, [options[0], ...options.slice(1)])\n\t}\n\tif (!(dto instanceof z.ZodObject)) throw new Error('Expected object DTO')\n\treturn compose(dto)\n}\n\nfunction normalizeTable(\n\tname: string,\n\tschema: RelationTable['schema'],\n\tdto: z.ZodObject | z.ZodDiscriminatedUnion<any, string>,\n\tdocument: ValidatorJSON,\n): Pick<TableMetadata, 'fields' | 'branches' | 'allFields'> {\n\tif (schema instanceof z.ZodObject && dto instanceof z.ZodObject) {\n\t\tconst fields = zodToConvex(schema).fields\n\t\tassertStoredDocument(name, fields, document)\n\t\treturn { fields, allFields: new Set(Object.keys(fields)) }\n\t}\n\tif (!(schema instanceof z.ZodDiscriminatedUnion) || !(dto instanceof z.ZodDiscriminatedUnion))\n\t\tthrow new Error(`Expected matching discriminated union boundaries \"${name}\"`)\n\tconst discriminator = schema._zod.def.discriminator\n\tif (dto._zod.def.discriminator !== discriminator) throw new Error('DTO discriminator mismatch')\n\tfunction options(union: z.ZodDiscriminatedUnion<any, string>): Record<string, z.ZodObject> {\n\t\tconst result: Record<string, z.ZodObject> = Object.create(null)\n\t\tfor (const option of union.options) {\n\t\t\tif (!(option instanceof z.ZodObject)) throw new Error('Variant branches must be objects')\n\t\t\tconst tag = option.shape[discriminator]\n\t\t\tif (!(tag instanceof z.ZodLiteral) || tag.values.size !== 1)\n\t\t\t\tthrow new Error('Variant tags must be unique required string literals')\n\t\t\tconst literal = z.string().safeParse(tag.value)\n\t\t\tif (!literal.success || Object.hasOwn(result, literal.data))\n\t\t\t\tthrow new Error('Variant tags must be unique required string literals')\n\t\t\tresult[literal.data] = option\n\t\t}\n\t\tif (Object.keys(result).length === 0) throw new Error('Expected at least one variant branch')\n\t\treturn result\n\t}\n\tconst documents = options(schema),\n\t\tdtos = options(dto)\n\tif (Object.keys(documents).sort().join('\\0') !== Object.keys(dtos).sort().join('\\0'))\n\t\tthrow new Error('DTO variant tags mismatch')\n\tconst branches: NonNullable<TableMetadata['branches']> = {\n\t\tdiscriminator,\n\t\toptions: Object.create(null),\n\t}\n\tconst stored: GenericValidator[] = []\n\tfor (const [tag, object] of Object.entries(documents)) {\n\t\tconst fields = zodToConvex(object).fields\n\t\tconst { _id, _creationTime, ...storage } = fields\n\t\tassertStoredDocument(name, fields, nativeJson(v.object(storage)))\n\t\tstored.push(v.object(storage))\n\t\tbranches.options[tag] = { fields, dto: dtos[tag] }\n\t}\n\tif (canonicalNative(document) !== canonicalNative(nativeJson(v.union(...stored))))\n\t\tthrow new Error(`Native stored document disagrees with boundary \"${name}\"`)\n\tconst members = Object.values(branches.options).map((branch) => branch.fields)\n\tconst fields: Record<string, GenericValidator> = {}\n\tfor (const key of Object.keys(members[0])) {\n\t\tif (!members.every((member) => Object.hasOwn(member, key))) continue\n\t\tif (\n\t\t\tkey !== discriminator &&\n\t\t\t!members.every((member) => commonCompatible(member[key], members[0][key]))\n\t\t)\n\t\t\tcontinue\n\t\tconst validators = members.map((member) => member[key])\n\t\tconst union = v.union(...validators)\n\t\tfields[key] = validators.some((validator) => validator.isOptional === 'optional')\n\t\t\t? v.optional(union)\n\t\t\t: union\n\t}\n\treturn { fields, branches, allFields: new Set(members.flatMap((member) => Object.keys(member))) }\n}\nfunction commonCompatible(left: GenericValidator, right: GenericValidator): boolean {\n\ttry {\n\t\treturn compatible(left, right)\n\t} catch {\n\t\treturn canonicalNative(nativeJson(left)) === canonicalNative(nativeJson(right))\n\t}\n}\n\ninterface NativeTableExport {\n\tindexes: { indexDescriptor: string; fields: string[] }[]\n\tdocumentType: ValidatorJSON\n}\n// Capture the installed peer's prototypes before accepting caller-owned instances.\n// Native json getters are trusted only on these prototypes; own accessors and\n// custom prototypes fail closed without evaluating them.\nconst nativePrototypes = new Map<object, PropertyDescriptorMap>()\nfor (const sample of [\n\tdefineTable(v.object({})),\n\tv.id('sample'),\n\tv.null(),\n\tv.number(),\n\tv.int64(),\n\tv.commitTs(),\n\tv.boolean(),\n\tv.string(),\n\tv.bytes(),\n\tv.any(),\n\tv.object({}),\n\tv.literal('sample'),\n\tv.array(v.string()),\n\tv.record(v.string(), v.string()),\n\tv.union(v.string(), v.null()),\n]) {\n\tlet prototype = Object.getPrototypeOf(sample)\n\twhile (prototype && prototype !== Object.prototype) {\n\t\tif (!nativePrototypes.has(prototype))\n\t\t\tnativePrototypes.set(prototype, Object.getOwnPropertyDescriptors(prototype))\n\t\tprototype = Object.getPrototypeOf(prototype)\n\t}\n}\n\n/** Registration-only descriptor preflight; caller accessors are never invoked. */\nfunction preflightNative(table: TableDefinition): void {\n\tconst seen = new Set<object>()\n\tconst active = new Set<object>()\n\t// oxlint-disable-next-line anti-slop/no-object-parameters -- This descriptor-only boundary admits arbitrary native graph nodes without invoking them.\n\tfunction visit(object: object, depth: number, trusted = false): void {\n\t\tif (active.has(object)) throw new Error('Unsupported cyclic native schema')\n\t\tif (seen.has(object)) return\n\t\tif (depth > 64 || seen.size >= 8192) throw new Error('Native schema graph budget exceeded')\n\t\tseen.add(object)\n\t\tactive.add(object)\n\t\tconst prototype = Object.getPrototypeOf(object)\n\t\tconst inherited = prototype && nativePrototypes.get(prototype)\n\t\tif (\n\t\t\tprototype !== null &&\n\t\t\tprototype !== Object.prototype &&\n\t\t\tprototype !== Array.prototype &&\n\t\t\t!inherited\n\t\t)\n\t\t\tthrow new Error('Unsupported native schema prototype')\n\t\tif (Object.getOwnPropertySymbols(object).length)\n\t\t\tthrow new Error('Unsupported native schema symbol')\n\t\tconst keys = Object.getOwnPropertyNames(object)\n\t\tconst values = keys.map((key) => Object.getOwnPropertyDescriptor(object, key)!)\n\t\tif (\n\t\t\t!trusted &&\n\t\t\tvalues.some((property) => !('value' in property) || property.value instanceof Function)\n\t\t)\n\t\t\tthrow new Error('Unsupported native schema accessor or method')\n\t\tif (inherited) {\n\t\t\t// Compare the trusted prototype before any native export can invoke it.\n\t\t\tconst currentKeys = Object.getOwnPropertyNames(prototype)\n\t\t\tif (\n\t\t\t\tcurrentKeys.length !== Object.getOwnPropertyNames(inherited).length ||\n\t\t\t\tcurrentKeys.some((key) => {\n\t\t\t\t\tconst current = Object.getOwnPropertyDescriptor(prototype, key)!\n\t\t\t\t\tconst before = Object.getOwnPropertyDescriptor(inherited, key)?.value\n\t\t\t\t\treturn (\n\t\t\t\t\t\t!before ||\n\t\t\t\t\t\t!Object.is(current.value, before.value) ||\n\t\t\t\t\t\tcurrent.get !== before.get ||\n\t\t\t\t\t\tcurrent.set !== before.set\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported native schema prototype mutation')\n\t\t\tvisit(prototype, depth + 1, true)\n\t\t}\n\t\tif (!trusted)\n\t\t\tfor (const property of values) {\n\t\t\t\tif (property.value !== null && Object(property.value) === property.value)\n\t\t\t\t\tvisit(property.value, depth + 1)\n\t\t\t}\n\t\tactive.delete(object)\n\t}\n\tvisit(table, 0)\n}\n\nfunction nativeTableExport(table: TableDefinition): NativeTableExport {\n\t// SAFETY: Convex exposes export at runtime but strips its internal signature from declarations.\n\treturn (table as TableDefinition & { export(): NativeTableExport }).export()\n}\nfunction nativeJson(validator: GenericValidator): ValidatorJSON {\n\t// SAFETY: native validators expose converter metadata at runtime; Convex strips json from declarations.\n\treturn (validator as GenericValidator & { json: ValidatorJSON }).json\n}\n\nfunction canonicalNative(value: JSONValue): string {\n\tif (Array.isArray(value)) return `[${value.map(canonicalNative).join(',')}]`\n\tif (value !== null && Object(value) === value) {\n\t\t// SAFETY: native JSON contains only JSON objects, arrays and primitives.\n\t\tconst object = value as { [key: string]: JSONValue }\n\t\treturn `{${Object.keys(object)\n\t\t\t.sort()\n\t\t\t.map((key) => `${JSON.stringify(key)}:${canonicalNative(object[key])}`)\n\t\t\t.join(',')}}`\n\t}\n\treturn JSON.stringify(value)\n}\n\nfunction assertNativeValidation(value: JSONValue): void {\n\tif (value === null || Object(value) !== value) return\n\t// SAFETY: native converter metadata contains only JSON containers and primitives.\n\tconst container = value as { [key: string]: JSONValue }\n\tif (container.type === 'any') throw new Error('Unsupported native validation form')\n\tfor (const child of Object.values(container)) assertNativeValidation(child)\n}\n\nfunction assertStoredDocument(\n\ttable: string,\n\tfields: Record<string, GenericValidator>,\n\tdocument: ValidatorJSON,\n): void {\n\tconst { _id, _creationTime, ...stored } = fields\n\tif (\n\t\t!_id ||\n\t\t!_creationTime ||\n\t\tcanonicalNative(nativeJson(_id)) !== canonicalNative(nativeJson(v.id(table))) ||\n\t\tcanonicalNative(nativeJson(_creationTime)) !== canonicalNative(nativeJson(v.number())) ||\n\t\t_id.isOptional !== 'required' ||\n\t\t_creationTime.isOptional !== 'required' ||\n\t\tcanonicalNative(document) !== canonicalNative(nativeJson(v.object(stored)))\n\t)\n\t\tthrow new Error(`Native stored document disagrees with boundary \"${table}\"`)\n}\n\n// Compare against this peer's own built-in accessor, using the intrinsic rather\n// than a caller-provided toString. Older Zod clones retain this accessor even\n// after reading shape, because it caches on the original definition.\nconst objectAccessorSample = z.object({ field: z.string() })\nconst builtinObjectGetters = new Set(\n\t[\n\t\tobjectAccessorSample,\n\t\tobjectAccessorSample.pick({ field: true }),\n\t\tobjectAccessorSample.omit({ field: true }),\n\t\tobjectAccessorSample.extend({ other: z.string() }),\n\t\tobjectAccessorSample.safeExtend({ other: z.string() }),\n\t\tobjectAccessorSample.merge(z.object({ other: z.string() })),\n\t\tobjectAccessorSample.partial(),\n\t\tobjectAccessorSample.required(),\n\t].flatMap((schema) => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(schema._zod.def, 'shape')?.get\n\t\treturn getter ? [Function.prototype.toString.call(getter)] : []\n\t}),\n)\n\n// Stored schemas already passed the native input boundary. Track their graph\n// independently of public DTO admissibility, without running any stored parser.\nconst builtinDefaultGetter = Function.prototype.toString.call(\n\tObject.getOwnPropertyDescriptor(z.string().default('')._zod.def, 'defaultValue')!.get!,\n)\nconst builtinPrefaultGetter = Function.prototype.toString.call(\n\tObject.getOwnPropertyDescriptor(z.string().prefault('')._zod.def, 'defaultValue')!.get!,\n)\n\n/** Registration-only admissibility traversal; never runs a stored parser. */\nfunction preflightSchema(dto: z.ZodType, boundary: 'dto' | 'stored'): void {\n\tconst fallbackDefinitions = new Set<object>()\n\tconst seen = new Set<object>()\n\tconst active = new Set<object>()\n\tconst objectDefinitions = new Set<object>()\n\t// oxlint-disable-next-line anti-slop/no-object-parameters -- Registration must inspect descriptors before trusting a Zod semantic node.\n\tfunction visit(value: object, depth: number): void {\n\t\tif (active.has(value)) throw new Error('Unsupported cyclic DTO schema')\n\t\tif (seen.has(value)) return\n\t\tif (depth > 32 || seen.size >= 4096) throw new Error('DTO schema graph budget exceeded')\n\t\tseen.add(value)\n\t\tactive.add(value)\n\t\ttry {\n\t\t\tconst internals = Object.getOwnPropertyDescriptor(value, '_zod')\n\t\t\tif (internals) {\n\t\t\t\tif (!('value' in internals)) throw new Error('Unsupported DTO schema accessor')\n\t\t\t\tconst definition = Object.getOwnPropertyDescriptor(internals.value, 'def')\n\t\t\t\tif (!definition || !('value' in definition))\n\t\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\t\t\t}\n\t\t\tif (value instanceof z.core.$ZodCheck && !(value instanceof z.core.$ZodType)) {\n\t\t\t\tif (boundary === 'dto' && value._zod.def.check === 'overwrite')\n\t\t\t\t\tthrow new Error('Unsupported DTO overwrite check')\n\t\t\t\tvisit(value._zod.def, depth + 1)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (value instanceof z.core.$ZodType) {\n\t\t\t\t// SAFETY: built-in Zod definitions form a discriminated union.\n\t\t\t\tconst def = (value as z.core.$ZodTypes)._zod.def\n\t\t\t\tif (\n\t\t\t\t\tboundary === 'dto' &&\n\t\t\t\t\t(![\n\t\t\t\t\t\t'object',\n\t\t\t\t\t\t'array',\n\t\t\t\t\t\t'optional',\n\t\t\t\t\t\t'nullable',\n\t\t\t\t\t\t'nonoptional',\n\t\t\t\t\t\t'union',\n\t\t\t\t\t\t'intersection',\n\t\t\t\t\t\t'tuple',\n\t\t\t\t\t\t'record',\n\t\t\t\t\t\t'string',\n\t\t\t\t\t\t'number',\n\t\t\t\t\t\t'boolean',\n\t\t\t\t\t\t'bigint',\n\t\t\t\t\t\t'null',\n\t\t\t\t\t\t'never',\n\t\t\t\t\t\t'custom',\n\t\t\t\t\t\t'literal',\n\t\t\t\t\t\t'enum',\n\t\t\t\t\t].includes(def.type) ||\n\t\t\t\t\t\t('coerce' in def && def.coerce))\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(`Unsupported DTO schema \"${def.type}\"`)\n\t\t\t\tif (boundary === 'stored' && (def.type === 'default' || def.type === 'prefault')) {\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(def, 'defaultValue')\n\t\t\t\t\tif (descriptor?.get) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdescriptor.set ||\n\t\t\t\t\t\t\tFunction.prototype.toString.call(descriptor.get) !==\n\t\t\t\t\t\t\t\t(def.type === 'default' ? builtinDefaultGetter : builtinPrefaultGetter)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error('Unsupported stored schema accessor')\n\t\t\t\t\t\t// Admit only the installed fallback accessor without evaluating it.\n\t\t\t\t\t\tfallbackDefinitions.add(def)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (value instanceof z.ZodUnion) {\n\t\t\t\t\tvisit(value.options, depth + 1)\n\t\t\t\t}\n\t\t\t\tif (def.type === 'object') {\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(def, 'shape')\n\t\t\t\t\tif (descriptor?.get) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdescriptor.set ||\n\t\t\t\t\t\t\t!builtinObjectGetters.has(Function.prototype.toString.call(descriptor.get))\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\t\t\t\t\t\tconst fields = def.shape\n\t\t\t\t\t\tvisit(fields, depth + 1)\n\t\t\t\t\t\tobjectDefinitions.add(def)\n\t\t\t\t\t}\n\t\t\t\t\tif (value instanceof z.ZodObject) {\n\t\t\t\t\t\tconst publicFields = Object.getOwnPropertyDescriptor(value, 'shape')\n\t\t\t\t\t\tif (publicFields && !('value' in publicFields))\n\t\t\t\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\t\t\t\t\t\tvisit(value.shape, depth + 1)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvisit(def, depth + 1)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst keys = Reflect.ownKeys(value)\n\t\t\tconst values = keys.map((key) => Object.getOwnPropertyDescriptor(value, key)!)\n\t\t\tif (\n\t\t\t\tvalues.some(\n\t\t\t\t\t(property, i) =>\n\t\t\t\t\t\t!('value' in property) &&\n\t\t\t\t\t\t!(objectDefinitions.has(value) && keys[i] === 'shape') &&\n\t\t\t\t\t\t!(fallbackDefinitions.has(value) && keys[i] === 'defaultValue'),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\n\t\t\tfor (const property of values) {\n\t\t\t\tif (\n\t\t\t\t\tproperty.value !== null &&\n\t\t\t\t\tObject(property.value) === property.value &&\n\t\t\t\t\t!(property.value instanceof Function)\n\t\t\t\t)\n\t\t\t\t\tvisit(property.value, depth + 1)\n\t\t\t}\n\t\t} finally {\n\t\t\tactive.delete(value)\n\t\t}\n\t}\n\tvisit(dto, 0)\n}\n\nfunction snapshotMetadata(registry: RegistryMetadata): RelationMetadata {\n\tconst tables: Record<string, RelationTableMetadata> = {}\n\tfor (const [name, data] of Object.entries(registry.metadata)) {\n\t\tconst fields: Record<string, RelationFieldMetadata> = {}\n\t\tfor (const [field, validator] of Object.entries(data.fields))\n\t\t\tfields[field] = Object.freeze({\n\t\t\t\tkind: validator.kind,\n\t\t\t\toptional: validator.isOptional === 'optional',\n\t\t\t\tnullable: hasNull(validator),\n\t\t\t\tidTables: Object.freeze(idTables(validator)),\n\t\t\t\tnative: frozenNative(nativeJson(validator)),\n\t\t\t})\n\t\ttables[name] = Object.freeze({\n\t\t\tfields: Object.freeze(fields),\n\t\t\tvariant: data.branches\n\t\t\t\t? Object.freeze({\n\t\t\t\t\t\tdiscriminator: data.branches.discriminator,\n\t\t\t\t\t\ttags: Object.freeze(Object.keys(data.branches.options)),\n\t\t\t\t\t})\n\t\t\t\t: undefined,\n\t\t\tindexes: Object.freeze(\n\t\t\t\tdata.indexes.map((index) =>\n\t\t\t\t\tObject.freeze({ name: index.name, fields: Object.freeze([...index.fields]) }),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\t}\n\treturn Object.freeze({ tables: Object.freeze(tables), declarations: registry.declarations })\n}\nfunction hasNull(validator: GenericValidator): boolean {\n\treturn (\n\t\tvalidator.kind === 'null' || (validator.kind === 'union' && validator.members.some(hasNull))\n\t)\n}\nfunction idTables(validator: GenericValidator): string[] {\n\treturn validator.kind === 'id'\n\t\t? [validator.tableName]\n\t\t: validator.kind === 'union'\n\t\t\t? [...new Set(validator.members.flatMap(idTables))].sort()\n\t\t\t: []\n}\nfunction frozenNative(native: ValidatorJSON): Readonly<ValidatorJSON> {\n\tconst snapshot = structuredClone(native)\n\tconst pending: JSONValue[] = [snapshot]\n\twhile (pending.length) {\n\t\tconst next = pending.pop()!\n\t\tif (Object(next) !== next) continue\n\t\t// SAFETY: native JSON metadata contains ordinary arrays/objects; the boxing test excludes primitives.\n\t\tconst container = next as JSONValue[] | { [key: string]: JSONValue }\n\t\tObject.freeze(container)\n\t\tpending.push(...Object.values(container))\n\t}\n\treturn snapshot\n}\n"],"mappings":"6aA4BA,MAAMA,EAAmBC,EAAWC,CAAgB,EAoF9CC,EAA4B,OAAO,eAAe,EAClDC,EAA2B,OAAO,cAAc,EAwfhDC,kBAAa,IAAI,QAEjBC,kBAAqB,IAAI,QAQzBC,kBAAO,IAAI,QACXC,kBAAa,IAAI,QACjBC,kBAAc,IAAI,QAClBC,kBAAW,IAAI,QACfC,EAAcC,EAAE,OAAO,CAC5B,QAASA,EAAE,MAAMA,EAAE,OAAO,CAAE,gBAAiBA,EAAE,OAAO,EAAG,OAAQA,EAAE,MAAMA,EAAE,OAAO,CAAC,CAAE,CAAC,CAAC,CACxF,CAAC,EAGD,SAAgBC,EAIf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WA,EAAU,QAAQ,KAAKE,CAAO,CAE5F,CACA,SAASuI,EAAS,EAAuC,CACxD,OAAOzI,EAAU,OAAS,KACvB,CAACA,EAAU,SAAS,EACpBA,EAAU,OAAS,QAClB,CAAC,GAAG,IAAI,IAAIA,EAAU,QAAQ,QAAQyI,CAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EACvD,CAAC,CACN,CACA,SAASC,GAAa,EAAgD,CACrE,IAAMC,EAAW,gBAAgBC,CAAM,EACjCnE,EAAuB,CAACkE,CAAQ,EACtC,KAAOlE,EAAQ,QAAQ,CACtB,IAAMoE,EAAOpE,EAAQ,IAAI,EACzB,GAAI,OAAOoE,CAAI,IAAMA,EAAM,SAE3B,IAAMrB,EAAYqB,EAClB,OAAO,OAAOrB,CAAS,EACvB/C,EAAQ,KAAK,GAAG,OAAO,OAAO+C,CAAS,CAAC,CACzC,CACA,OAAOmB,CACR"}
|
|
1
|
+
{"version":3,"file":"relations.mjs","names":["zodToConvex","zodToConvex$1","paginationRecipe","captureDto","nativePagination","fieldBrand","edgeBrand","registries","executorRegistries","refs","memberRefs","throughRefs","edgeRefs","searchIndexExport","z","indexExport","defineRelations","metadata","nativeTables","ownRefs","branchRefs","fields","one","many","name","table","tables","nativeDescriptor","nativeTable","preflightNative","preflightSchema","sourceDto","dtoRecipe","dto","materializeDto","exported","nativeTableExport","assertNativeValidation","normalized","normalizeTable","captured","searchIndexes","index","a","b","indexes","nativeJson","fieldGroups","groupRecipes","descriptor","assertGroupData","definitions","used","publicBranches","group","members","field","branch","validators","validator","canonicalNative","tag","storedFields","convexToZod","v","makeReferences","tableRefs","makeReference","ref","guard","nativeIdMembers","selected","hasNull","member","junction","junctionValidator","compatible","result","makeEdge","spec","supplied","declare","declarations","edges","source","edge","base","validatePath","internal","helpers","expected","contract","actual","assertSelection","selection","relationFilterSchema","filterGrammar","assertGroups","groups","paginated","rowSchema","identity","data","serializeLeg","registry","snapshotMetadata","streamTables","defineTable","first","rest","defineSchema","getRelationExecutor","owned","assertSchema","names","branchValidators","projectionKeys","groupDtos","scalarFields","grammars","filterNodes","validateDocument","row","cached","fieldKeys","entries","key","entry","values","grammar","grammarKey","depth","cacheKey","scalarValidator","scalarPredicateSchema","declaration","visit","mask","eligible","variants","composed","groupValidators","keys","getRelationMetadata","value","prototype","input","parsed","relations","nested","schema","modes","pending","nodes","ancestors","property","leg","own","target","junctionGuard","left","from","right","to","leftDomain","domain","requireIndex","position","relationFields","option","compose","options","assertStoredDocument","document","discriminator","union","literal","documents","dtos","branches","stored","object","storage","commonCompatible","nativePrototypes","sample","seen","active","inherited","trusted","currentKeys","current","before","container","child","_id","_creationTime","objectAccessorSample","builtinObjectGetters","getter","builtinDefaultGetter","builtinPrefaultGetter","fallbackDefinitions","objectDefinitions","internals","definition","boundary","def","publicFields","i","idTables","frozenNative","snapshot","native","next"],"sources":["../src/relations.ts"],"sourcesContent":["import type { FilterContract, SharedFilters } from './filters'\nimport { z } from 'zod'\nimport { captureDto, materializeDto, type DtoRecipe } from './querying/schema-snapshot'\nimport { convexToZod, type ConvexValidatorFromZod } from 'convex-helpers/server/zod4'\nimport { zodToConvex } from './zod-convex'\nimport { defineSchema, defineTable, type TableDefinition } from 'convex/server'\nimport {\n\tv,\n\ttype GenericId,\n\ttype GenericValidator,\n\ttype ValidatorJSON,\n\ttype JSONValue,\n} from 'convex/values'\nimport { paginated, type EnginePaginationResult } from './zod-table'\nimport {\n\tnativePagination,\n\trelationFilterSchema,\n\tscalarPredicateSchema,\n\ttype FieldSchemas,\n\ttype FilterGrammar,\n\ttype PaginationOptionsSchema,\n\ttype ScalarSelection,\n\ttype ScalarPredicate,\n} from './querying/filters'\n\nconst paginationRecipe = captureDto(nativePagination)\n\n/** Generated object or discriminated-union boundaries. */\nexport interface RelationTable {\n\ttableName: string\n\tschema: z.ZodObject | z.ZodDiscriminatedUnion<any, string>\n\tpublicDto: z.ZodObject | z.ZodDiscriminatedUnion<any, string>\n\ttable: TableDefinition\n\tdto(includeId: true): z.ZodType\n\t/** Whole stored fields; schemas are captured from the native table, never a DTO transform. */\n\tfieldGroups?: Readonly<Record<string, readonly string[]>>\n}\nexport type RelationTables = Record<string, RelationTable>\nexport type FieldGroupMode = 'if-permitted' | 'required'\nexport type FieldGroupRequest<T extends RelationTable> = {\n\t[K in keyof NonNullable<T['fieldGroups']>]?: FieldGroupMode\n}\n/** Separate from relation keys so existing selection syntax remains unambiguous. */\nexport type RelationGroupSelection<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tL extends readonly 1[] = readonly [1, 1, 1, 1],\n> = {\n\tfieldGroups?: FieldGroupRequest<Tables[T]>\n\trelations?: L extends readonly []\n\t\t? never\n\t\t: {\n\t\t\t\t[K in keyof Edges<D, T>]?: RelationGroupSelection<\n\t\t\t\t\tTables,\n\t\t\t\t\tD,\n\t\t\t\t\tExtract<Target<Edges<D, T>[K]>, keyof Tables>,\n\t\t\t\t\tTail<L>\n\t\t\t\t>\n\t\t\t}\n}\n/** Internal admitted runtime tree, independent of user relation names. */\nexport interface GroupSelection {\n\tfieldGroups?: Readonly<Record<string, FieldGroupMode>>\n\trelations?: Readonly<Record<string, GroupSelection>>\n}\nexport type ExactGroupSelection<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tG,\n> = G & {\n\t[K in keyof G]: K extends 'fieldGroups'\n\t\t? G[K] & {\n\t\t\t\t[N in keyof G[K]]: N extends keyof FieldGroupRequest<Tables[T]> ? FieldGroupMode : never\n\t\t\t}\n\t\t: K extends 'relations'\n\t\t\t? G[K] & {\n\t\t\t\t\t[N in keyof G[K]]: N extends keyof Edges<D, T>\n\t\t\t\t\t\t? ExactGroupSelection<Tables, D, Extract<Target<Edges<D, T>[N]>, keyof Tables>, G[K][N]>\n\t\t\t\t\t\t: never\n\t\t\t\t}\n\t\t\t: never\n}\ntype StoredValue<V extends GenericValidator> = GenericValidator extends V\n\t? V['type']\n\t: V extends {\n\t\t\t\tkind: 'object'\n\t\t\t\tfields: infer F extends Record<string, GenericValidator>\n\t\t }\n\t\t? { [K in keyof F as F[K]['isOptional'] extends 'optional' ? never : K]: StoredValue<F[K]> } & {\n\t\t\t\t[K in keyof F as F[K]['isOptional'] extends 'optional' ? K : never]?: StoredValue<F[K]>\n\t\t\t}\n\t\t: V extends { kind: 'array'; element: infer E extends GenericValidator }\n\t\t\t? StoredValue<E>[]\n\t\t\t: V extends { kind: 'union'; members: infer M extends GenericValidator[] }\n\t\t\t\t? StoredValue<M[number]>\n\t\t\t\t: V extends {\n\t\t\t\t\t\t\tkind: 'record'\n\t\t\t\t\t\t\tkey: infer K extends GenericValidator\n\t\t\t\t\t\t\tvalue: infer E extends GenericValidator\n\t\t\t\t\t }\n\t\t\t\t\t? Record<Extract<K['type'], string>, StoredValue<E>>\n\t\t\t\t\t: V['type']\ntype GroupStoredRow<\n\tT extends RelationTable,\n\tRow,\n\tStored = StoredValue<ConvexValidatorFromZod<T['schema'], 'required'>>,\n> = [Tags<T>] extends [never]\n\t? Stored\n\t: Extract<Stored, Pick<Row, Extract<Discriminator<T>, keyof Row>>>\ntype GroupFields<T extends RelationTable, G, Row> = T extends {\n\tfieldGroups: infer Definitions extends Readonly<Record<string, readonly string[]>>\n}\n\t? {\n\t\t\t[K in keyof G & keyof Definitions]: Pick<\n\t\t\t\tGroupStoredRow<T, Row>,\n\t\t\t\tExtract<Definitions[K][number], keyof GroupStoredRow<T, Row>>\n\t\t\t>\n\t\t}\n\t: {}\ntype UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (\n\tx: infer I,\n) => void\n\t? I\n\t: never\ntype IncludedFields<T extends RelationTable, G, Row> = G extends { fieldGroups: infer Requests }\n\t? UnionToIntersection<\n\t\t\t{\n\t\t\t\t[K in keyof Requests & keyof GroupFields<T, Requests, Row>]: Requests[K] extends 'required'\n\t\t\t\t\t? GroupFields<T, Requests, Row>[K]\n\t\t\t\t\t: Partial<GroupFields<T, Requests, Row>[K]>\n\t\t\t}[keyof Requests & keyof GroupFields<T, Requests, Row>]\n\t\t>\n\t: {}\ntype NestedGroups<G, K extends PropertyKey> = G extends { relations: infer R }\n\t? K extends keyof R\n\t\t? R[K]\n\t\t: {}\n\t: {}\n/** Internal named declaration dependency; excluded from the supported relations facade. */\nexport interface SelectionMask {\n\t[key: string]: true | SelectionMask\n}\ntype DocumentFields<S> =\n\tS extends z.ZodObject<infer F>\n\t\t? F\n\t\t: S extends z.ZodDiscriminatedUnion<infer O, string>\n\t\t\t? O[number] extends infer B\n\t\t\t\t? B extends z.ZodObject<infer F>\n\t\t\t\t\t? F\n\t\t\t\t\t: never\n\t\t\t\t: never\n\t\t\t: never\ntype AllKeys<F> = F extends unknown ? keyof F : never\ntype FieldAt<F, K extends PropertyKey> = F extends unknown\n\t? K extends keyof F\n\t\t? F[K]\n\t\t: never\n\t: never\ntype NativeDomain<V> = V extends {\n\tkind: 'union'\n\tmembers: infer M extends GenericValidator[]\n}\n\t? NativeDomain<M[number]>\n\t: V extends { kind: 'null' }\n\t\t? never\n\t\t: V extends { kind: infer K; type: infer Value }\n\t\t\t? readonly [K, Exclude<Value, undefined>]\n\t\t\t: never\ntype DomainAt<F, K extends PropertyKey> = F extends unknown\n\t? K extends keyof F\n\t\t? F[K] extends z.ZodType\n\t\t\t? NativeDomain<ConvexValidatorFromZod<F[K], 'required'>>\n\t\t\t: never\n\t\t: never\n\t: never\ntype CompatibleBranches<F, K extends keyof F, Domain = DomainAt<F, K>> = F extends unknown\n\t? Same<DomainAt<F, K>, Domain>\n\t: never\ntype Discriminator<T extends RelationTable> =\n\tT['schema'] extends z.ZodDiscriminatedUnion<any, string>\n\t\t? T['schema']['_zod']['def']['discriminator']\n\t\t: never\ntype Fields<\n\tT extends RelationTable,\n\tF = DocumentFields<T['schema']>,\n> = string extends T['tableName']\n\t? FieldSchemas\n\t: T['schema'] extends z.ZodObject<infer ObjectFields>\n\t\t? { [K in keyof ObjectFields]: Extract<ObjectFields[K], z.ZodType> }\n\t\t: {\n\t\t\t\t[\n\t\t\t\t\tK in Extract<keyof F, string> as K extends Discriminator<T>\n\t\t\t\t\t\t? K\n\t\t\t\t\t\t: false extends CompatibleBranches<F, K>\n\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t: K\n\t\t\t\t]: Extract<FieldAt<F, K>, z.ZodType>\n\t\t\t}\ntype BranchFields<T extends RelationTable, Tag extends string> =\n\tDocumentFields<T['schema']> extends infer F\n\t\t? F extends Record<Discriminator<T>, z.ZodType>\n\t\t\t? Tag extends z.output<F[Discriminator<T>]>\n\t\t\t\t? F\n\t\t\t\t: never\n\t\t\t: never\n\t\t: never\ntype Tags<T extends RelationTable> =\n\tT['schema'] extends z.ZodDiscriminatedUnion<any, string>\n\t\t? Extract<z.output<T['schema']>[Discriminator<T>], string>\n\t\t: never\ntype Native<T extends RelationTable, K extends keyof Fields<T>> = ConvexValidatorFromZod<\n\tFields<T>[K],\n\t'required'\n>['type']\nconst fieldBrand: unique symbol = Symbol('relationField')\nconst edgeBrand: unique symbol = Symbol('relationEdge')\ntype Comparable<Value> = Exclude<Value, null | undefined>\ntype IdMembers<Value, Registered extends string> = [Comparable<Value>] extends [never]\n\t? never\n\t: [Comparable<Value>] extends [GenericId<string>]\n\t\t? Extract<Comparable<Value>, GenericId<string>>['__tableName'] & Registered\n\t\t: never\ntype Same<A, B> = [Comparable<A> | Comparable<B>] extends [never]\n\t? false\n\t: [Comparable<A>] extends [Comparable<B>]\n\t\t? [Comparable<B>] extends [Comparable<A>]\n\t\t\t? true\n\t\t\t: false\n\t\t: false\n\nexport interface FieldReference<\n\tTable extends string,\n\tField extends string,\n\tValue,\n\tScope extends string = never,\n\tRegistered extends string = string,\n\tMember extends string = never,\n> {\n\treadonly guard?: RelationGuard<Scope>\n\treadonly [fieldBrand]: Value\n\treadonly table: Table\n\treadonly field: Field\n\t/** Select a registered native-ID member, retaining this field's nullish wrappers. */\n\tforTable<const T extends ([Scope] extends [never] ? IdMembers<Value, Registered> : never)>(\n\t\ttable: T,\n\t): FieldReference<\n\t\tTable,\n\t\tField,\n\t\tExtract<Value, GenericId<T> | null | undefined>,\n\t\tScope,\n\t\tRegistered,\n\t\tT\n\t>\n\tthrough<J extends AnyField>(\n\t\tjunction: J &\n\t\t\t([Member] extends [never] ? {} : never) &\n\t\t\t(J extends FieldReference<string, string, any, any, any, infer M>\n\t\t\t\t? [M] extends [never]\n\t\t\t\t\t? {}\n\t\t\t\t\t: never\n\t\t\t\t: never) &\n\t\t\t(Same<Value, J[typeof fieldBrand]> extends true ? {} : never),\n\t): ThroughReference<Table, Field, Value, J, Scope>\n}\nexport interface RelationGuard<Tag extends string = string> {\n\treadonly discriminator: string\n\treadonly tag: Tag\n}\ntype AnyField = FieldReference<string, string, any, any, any, any>\nexport interface ThroughReference<\n\tTable extends string,\n\tField extends string,\n\tValue,\n\tJunction extends AnyField,\n\tScope extends string = never,\n> {\n\treadonly base: FieldReference<Table, Field, Value, Scope>\n\treadonly junction: Junction\n}\ntype AnyThrough = ThroughReference<string, string, any, AnyField, any>\ntype Leg = AnyField | AnyThrough\ntype Base<L extends Leg> = L extends AnyThrough ? L['base'] : L\ntype JunctionTable<L extends Leg> = L extends AnyThrough ? L['junction']['table'] : never\ntype CompatibleLegs<F extends Leg, T extends Leg> = F extends AnyThrough\n\t? T extends AnyThrough\n\t\t? Same<JunctionTable<F>, JunctionTable<T>> extends true\n\t\t\t? {}\n\t\t\t: never\n\t\t: never\n\t: T extends AnyThrough\n\t\t? never\n\t\t: Same<Base<F>[typeof fieldBrand], Base<T>[typeof fieldBrand]> extends true\n\t\t\t? {}\n\t\t\t: never\n\nexport interface RelationEdge<\n\tSource extends string,\n\tTarget extends string,\n\tCardinality extends 'one' | 'many',\n\tSourceScope extends string = never,\n\tTargetScope extends string = never,\n> {\n\treadonly sourceGuard?: RelationGuard<SourceScope>\n\treadonly targetGuard?: RelationGuard<TargetScope>\n\treadonly junctionGuard?: RelationGuard\n\treadonly sourceMember?: RelationMember\n\treadonly targetMember?: RelationMember\n\treadonly [edgeBrand]: true\n\treadonly source: Source\n\treadonly target: Target\n\treadonly cardinality: Cardinality\n\treadonly from: Leg\n\treadonly to: Leg\n}\ninterface RelationMember {\n\treadonly table: string\n}\ntype AnyEdge = RelationEdge<string, string, 'one' | 'many', any, any>\ntype FieldReferences<Tables extends RelationTables> = {\n\t[T in keyof Tables]: {\n\t\t[K in Extract<keyof Fields<Tables[T]>, string>]: FieldReference<\n\t\t\tExtract<T, string>,\n\t\t\tK,\n\t\t\tNative<Tables[T], K>,\n\t\t\tnever,\n\t\t\tExtract<keyof Tables, string>\n\t\t>\n\t}\n}\nexport type BranchBuilder<Tables extends RelationTables> = <\n\tconst T extends keyof Tables & string,\n\tconst Tag extends Tags<Tables[T]>,\n>(\n\ttable: T,\n\ttag: Tag,\n) => {\n\t[K in keyof BranchFields<Tables[T], Tag> & string]: FieldReference<\n\t\tT,\n\t\tK,\n\t\tConvexValidatorFromZod<Extract<BranchFields<Tables[T], Tag>[K], z.ZodType>, 'required'>['type'],\n\t\tTag\n\t>\n}\ntype Scope<L extends Leg> = NonNullable<Base<L>['guard']>['tag']\ntype AllReferences<Tables extends RelationTables> = {\n\t[T in keyof Tables]: FieldReferences<Tables>[T][Extract<keyof FieldReferences<Tables>[T], string>]\n}[keyof Tables]\ntype Builders<Tables extends RelationTables, C extends 'one' | 'many'> = {\n\t[T in keyof Tables]: <\n\t\tF extends AllReferences<Tables> | AnyField | AnyThrough,\n\t\tTo extends\n\t\t\t| FieldReferences<Tables>[T][Extract<keyof FieldReferences<Tables>[T], string>]\n\t\t\t| AnyField\n\t\t\t| AnyThrough,\n\t>(\n\t\tspec: { from: F; to: To } & CompatibleLegs<F, To> & (Base<To>['table'] extends T ? {} : never),\n\t) => RelationEdge<Base<F>['table'], Extract<T, string>, C, Scope<F>, Scope<To>>\n}\nexport type RelationBuilder<Tables extends RelationTables> = FieldReferences<Tables> & {\n\tone: Builders<Tables, 'one'>\n\tmany: Builders<Tables, 'many'>\n}\nexport type RelationDeclarations = Record<string, Record<string, AnyEdge>>\ntype ExactDeclarations<Tables extends RelationTables, D extends RelationDeclarations> = {\n\t[T in keyof D]: T extends keyof Tables\n\t\t? {\n\t\t\t\t[K in keyof D[T]]: K extends\n\t\t\t\t\t| AllKeys<DocumentFields<Tables[T]['schema']>>\n\t\t\t\t\t| 'and'\n\t\t\t\t\t| 'or'\n\t\t\t\t\t| 'not'\n\t\t\t\t\t| 'fields'\n\t\t\t\t\t| 'then'\n\t\t\t\t\t| ([Tags<Tables[T]>] extends [never] ? never : 'variant' | 'variants')\n\t\t\t\t\t| '__proto__'\n\t\t\t\t\t| 'constructor'\n\t\t\t\t\t| 'prototype'\n\t\t\t\t\t? never\n\t\t\t\t\t: D[T][K]['source'] extends T\n\t\t\t\t\t\t? D[T][K]\n\t\t\t\t\t\t: never\n\t\t\t}\n\t\t: never\n}\ntype Depth = readonly [1, 1, 1, 1]\ntype Tail<D extends readonly 1[]> = D extends readonly [1, ...infer R extends 1[]] ? R : []\ntype Edges<D, T> = T extends keyof D ? D[T] : {}\ntype Target<E> = E extends AnyEdge ? E['target'] : never\nexport type RelationSelection<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tLevel extends readonly 1[] = Depth,\n> = Level extends readonly []\n\t? Record<string, never>\n\t: {\n\t\t\t[K in keyof Edges<D, T>]?:\n\t\t\t\t| true\n\t\t\t\t| RelationSelection<Tables, D, Extract<Target<Edges<D, T>[K]>, keyof Tables>, Tail<Level>>\n\t\t}\ntype BranchTables<Tables extends RelationTables, T extends keyof Tables, Tag extends string> = {\n\t[K in keyof Tables]: K extends T\n\t\t? Omit<Tables[K], 'schema'> & { schema: z.ZodObject<BranchFields<Tables[T], Tag>> }\n\t\t: Tables[K]\n}\ntype VariantSelections<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tLevel extends readonly 1[],\n> = {\n\t[Tag in Tags<Tables[T]>]?: RelationFilterSelection<BranchTables<Tables, T, Tag>, D, T, Level>\n}\nexport type RelationFilterSelection<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tLevel extends readonly 1[] = Depth,\n> = ([Tags<Tables[T]>] extends [never]\n\t? ScalarSelection<Fields<Tables[T]>>\n\t: Omit<ScalarSelection<Fields<Tables[T]>>, 'variants'> & {\n\t\t\tvariants?:\n\t\t\t\t| ('variants' extends keyof ScalarSelection<Fields<Tables[T]>> ? true : never)\n\t\t\t\t| VariantSelections<Tables, D, T, Level>\n\t\t}) &\n\t(Level extends readonly []\n\t\t? {}\n\t\t: {\n\t\t\t\t[K in keyof Edges<D, T>]?: RelationFilterSelection<\n\t\t\t\t\tTables,\n\t\t\t\t\tD,\n\t\t\t\t\tExtract<Target<Edges<D, T>[K]>, keyof Tables>,\n\t\t\t\t\tTail<Level>\n\t\t\t\t>\n\t\t\t})\ntype ExactOutputMask<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tL extends readonly 1[] = Depth,\n> = S & {\n\t[K in keyof S]: L extends readonly []\n\t\t? never\n\t\t: K extends keyof Edges<D, T>\n\t\t\t? S[K] extends true\n\t\t\t\t? true\n\t\t\t\t: ExactOutputMask<Tables, D, Extract<Target<Edges<D, T>[K]>, keyof Tables>, S[K], Tail<L>>\n\t\t\t: never\n}\ntype ExactFilterMask<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tL extends readonly 1[] = Depth,\n> = S & {\n\t[K in keyof S]: K extends ([Tags<Tables[T]>] extends [never] ? never : 'variants')\n\t\t? S[K] extends true\n\t\t\t? K extends keyof ScalarSelection<Fields<Tables[T]>>\n\t\t\t\t? true\n\t\t\t\t: never\n\t\t\t: S[K] & {\n\t\t\t\t\t[Tag in keyof S[K]]: Tag extends Tags<Tables[T]>\n\t\t\t\t\t\t? ExactFilterMask<\n\t\t\t\t\t\t\t\tBranchTables<Tables, T, Extract<Tag, string>>,\n\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\tS[K][Tag],\n\t\t\t\t\t\t\t\tTail<L>\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t: never\n\t\t\t\t}\n\t\t: K extends keyof ScalarSelection<Fields<Tables[T]>>\n\t\t\t? S[K] extends true\n\t\t\t\t? true\n\t\t\t\t: never\n\t\t\t: L extends readonly []\n\t\t\t\t? never\n\t\t\t\t: K extends keyof Edges<D, T>\n\t\t\t\t\t? S[K] extends true\n\t\t\t\t\t\t? never\n\t\t\t\t\t\t: ExactFilterMask<\n\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\tExtract<Target<Edges<D, T>[K]>, keyof Tables>,\n\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\tTail<L>\n\t\t\t\t\t\t\t>\n\t\t\t\t\t: never\n}\ntype ScalarValues<T extends RelationTable, S, Side extends 'input' | 'output'> = {\n\t[K in Extract<keyof S, keyof Fields<T>>]?: ScalarPredicate<Fields<T>[K], Side>\n}\nexport type RelationFilters<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tSide extends 'input' | 'output' = 'output',\n\tLevel extends readonly 1[] = Depth,\n> = Omit<\n\tScalarValues<Tables[T], S, Side>,\n\t'and' | 'or' | 'not' | 'fields' | ([Tags<Tables[T]>] extends [never] ? never : 'variant')\n> & {\n\tfields?: ScalarValues<Tables[T], S, Side>\n} & VariantFilters<Tables, D, T, S, Side, Level> &\n\t(Level extends readonly []\n\t\t? {}\n\t\t: {\n\t\t\t\t[K in Extract<keyof S, keyof Edges<D, T>>]?: Edges<D, T>[K] extends RelationEdge<\n\t\t\t\t\tstring,\n\t\t\t\t\tinfer Target,\n\t\t\t\t\tinfer C,\n\t\t\t\t\tany,\n\t\t\t\t\tany\n\t\t\t\t>\n\t\t\t\t\t? C extends 'one'\n\t\t\t\t\t\t? RelationFilters<\n\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t> | null\n\t\t\t\t\t\t:\n\t\t\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\t\t\tsome: RelationFilters<\n\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\t\t\tnone: RelationFilters<\n\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\tS[K],\n\t\t\t\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\t\t\t\tTail<Level>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t: never\n\t\t\t} & {\n\t\t\t\tand?: readonly RelationFilters<Tables, D, T, S, Side, Tail<Level>>[]\n\t\t\t\tor?: readonly RelationFilters<Tables, D, T, S, Side, Tail<Level>>[]\n\t\t\t\tnot?: RelationFilters<Tables, D, T, S, Side, Tail<Level>>\n\t\t\t})\ntype VariantFilters<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tSide extends 'input' | 'output',\n\tL extends readonly 1[],\n> = L extends readonly []\n\t? {}\n\t: S extends { variants: infer V }\n\t\t? V extends true\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tvariant?: {\n\t\t\t\t\t\t[Tag in keyof V]: Tag extends Tags<Tables[T]>\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\ttag: Tag\n\t\t\t\t\t\t\t\t\tfilters: RelationFilters<\n\t\t\t\t\t\t\t\t\t\tBranchTables<Tables, T, Extract<Tag, string>>,\n\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\tT,\n\t\t\t\t\t\t\t\t\t\tV[Tag] & Omit<S, 'variants'>,\n\t\t\t\t\t\t\t\t\t\tSide,\n\t\t\t\t\t\t\t\t\t\tTail<L>\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t}[keyof V]\n\t\t\t\t}\n\t\t: {}\ntype PublicRow<T extends RelationTable> = z.output<T['publicDto']> & {\n\t_id: GenericId<T['tableName']>\n}\nexport type ScopedRelationRow<Row, Scope extends string, Key extends PropertyKey> = [\n\tScope,\n] extends [never]\n\t? Row\n\t: Extract<Row, Record<Key, Scope>>\ntype ComposeRelationRow<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tLevel extends readonly 1[],\n\tRow,\n\tG = {},\n> = Row extends unknown\n\t? Row &\n\t\t\tIncludedFields<Tables[T], G, Row> &\n\t\t\t(Level extends readonly []\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\t[K in keyof S]: K extends keyof Edges<D, T>\n\t\t\t\t\t\t\t? Edges<D, T>[K] extends RelationEdge<\n\t\t\t\t\t\t\t\t\tstring,\n\t\t\t\t\t\t\t\t\tinfer Target,\n\t\t\t\t\t\t\t\t\tinfer C,\n\t\t\t\t\t\t\t\t\tinfer SourceScope,\n\t\t\t\t\t\t\t\t\tinfer TargetScope\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t? C extends 'one'\n\t\t\t\t\t\t\t\t\t? (\n\t\t\t\t\t\t\t\t\t\t\t[SourceScope] extends [never]\n\t\t\t\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t\t\t\t: Row extends ScopedRelationRow<Row, SourceScope, Discriminator<Tables[T]>>\n\t\t\t\t\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t\t\t\t\t: false\n\t\t\t\t\t\t\t\t\t\t) extends true\n\t\t\t\t\t\t\t\t\t\t? ScopedRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\tRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tS[K] extends true ? {} : S[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\tTail<Level>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tNestedGroups<G, K>\n\t\t\t\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\t\t\t\t\tTargetScope,\n\t\t\t\t\t\t\t\t\t\t\t\tDiscriminator<Tables[Extract<Target, keyof Tables>]>\n\t\t\t\t\t\t\t\t\t\t\t> | null\n\t\t\t\t\t\t\t\t\t\t: null\n\t\t\t\t\t\t\t\t\t: EnginePaginationResult<\n\t\t\t\t\t\t\t\t\t\t\tScopedRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\tRelationRow<\n\t\t\t\t\t\t\t\t\t\t\t\t\tTables,\n\t\t\t\t\t\t\t\t\t\t\t\t\tD,\n\t\t\t\t\t\t\t\t\t\t\t\t\tExtract<Target, keyof Tables>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tS[K] extends true ? {} : S[K],\n\t\t\t\t\t\t\t\t\t\t\t\t\tTail<Level>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tNestedGroups<G, K>\n\t\t\t\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\t\t\t\t\tTargetScope,\n\t\t\t\t\t\t\t\t\t\t\t\tDiscriminator<Tables[Extract<Target, keyof Tables>]>\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t: never\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t})\n\t: never\nexport type RelationRow<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tLevel extends readonly 1[] = Depth,\n\tG = {},\n> = ComposeRelationRow<Tables, D, T, S, Level, PublicRow<Tables[T]>, G>\nexport type RelationQueryRow<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n\tS,\n\tScope extends string = never,\n\tG = {},\n> = ScopedRelationRow<RelationRow<Tables, D, T, S, Depth, G>, Scope, Discriminator<Tables[T]>>\nexport interface RelationTableHelpers<\n\tTables extends RelationTables,\n\tD extends RelationDeclarations,\n\tT extends keyof Tables,\n> {\n\tfilters<F extends Record<string, GenericValidator>>(\n\t\tcontract: FilterContract<F>,\n\t): PaginationOptionsSchema<SharedFilters<F>, SharedFilters<F, 'input'>>\n\tpaginationOpts<const S extends RelationFilterSelection<Tables, D, T>>(\n\t\tselection: ExactFilterMask<Tables, D, T, S>,\n\t): PaginationOptionsSchema<\n\t\tRelationFilters<Tables, D, T, S>,\n\t\tRelationFilters<Tables, D, T, S, 'input'>\n\t>\n\tpageDto<\n\t\tconst S extends RelationSelection<Tables, D, T>,\n\t\tconst G extends RelationGroupSelection<Tables, D, T> = {},\n\t>(\n\t\tselection: ExactOutputMask<Tables, D, T, S>,\n\t\tgroups?: ExactGroupSelection<Tables, D, T, G>,\n\t): z.ZodType<EnginePaginationResult<RelationRow<Tables, D, T, S, Depth, G>>>\n}\nexport interface RelationRegistryIdentity {\n\treadonly identity: string\n\treadonly version: 1\n}\nexport interface RelationRegistry<Tables extends RelationTables, D extends RelationDeclarations> {\n\treadonly identity: string\n\treadonly version: 1\n\treadonly tables: { [T in keyof Tables]: RelationTableHelpers<Tables, D, T> }\n}\n\nexport interface RelationFieldMetadata {\n\treadonly kind: string\n\treadonly optional: boolean\n\treadonly nullable: boolean\n\treadonly idTables: readonly string[]\n\treadonly native: Readonly<ValidatorJSON>\n}\nexport interface SearchIndexMetadata {\n\treadonly name: string\n\treadonly searchField: string\n\treadonly filterFields: readonly string[]\n\treadonly staged: boolean\n}\nexport interface RelationTableMetadata {\n\treadonly searchIndexes: readonly SearchIndexMetadata[]\n\treadonly fieldGroups: Readonly<Record<string, readonly string[]>>\n\treadonly fields: Readonly<Record<string, RelationFieldMetadata>>\n\treadonly variant?: {\n\t\treadonly discriminator: string\n\t\treadonly tags: readonly string[]\n\t}\n\treadonly indexes: readonly {\n\t\treadonly name: string\n\t\treadonly fields: readonly string[]\n\t}[]\n}\ninterface TableMetadata {\n\tsearchIndexes: readonly SearchIndexMetadata[]\n\tfieldGroups: Readonly<Record<string, readonly string[]>>\n\tgroupRecipes: Readonly<Record<string, DtoRecipe>>\n\tfields: Record<string, GenericValidator>\n\tindexes: { name: string; fields: string[] }[]\n\tdto: z.ZodObject | z.ZodDiscriminatedUnion<any, string>\n\tbranches?: {\n\t\tdiscriminator: string\n\t\toptions: Record<string, { fields: Record<string, GenericValidator>; dto: z.ZodObject }>\n\t}\n\tallFields: ReadonlySet<string>\n\tdtoRecipe: DtoRecipe\n}\ninterface RegistryMetadata {\n\tmetadata: Record<string, TableMetadata>\n\tdeclarations: RelationDeclarations\n}\nexport interface RelationMetadata {\n\treadonly tables: Readonly<Record<string, RelationTableMetadata>>\n\treadonly declarations: Readonly<Record<string, Readonly<Record<string, AnyEdge>>>>\n}\n\nconst registries = new WeakMap<RelationRegistryIdentity, RelationMetadata>()\n// Private executor state retains validators and projection, never a database reader.\nconst executorRegistries = new WeakMap<\n\tRelationRegistryIdentity,\n\t{\n\t\tinternal: RegistryMetadata\n\t\tnativeTables: Readonly<Record<string, TableDefinition>>\n\t\tstreamSchema: ReturnType<typeof defineSchema>\n\t}\n>()\nconst refs = new WeakMap<AnyField, GenericValidator>()\nconst memberRefs = new WeakMap<AnyField, RelationMember>()\nconst throughRefs = new WeakSet<AnyThrough>()\nconst edgeRefs = new WeakSet<AnyEdge>()\nconst searchIndexExport = z.object({\n\tindexDescriptor: z.string(),\n\tsearchField: z.string(),\n\tfilterFields: z.array(z.string()),\n})\nconst indexExport = z.object({\n\tsearchIndexes: z.array(searchIndexExport),\n\tstagedSearchIndexes: z.array(searchIndexExport),\n\tindexes: z.array(z.object({ indexDescriptor: z.string(), fields: z.array(z.string()) })),\n})\n\n/** No ID-field inference and no readers: this registry owns declarations/schema helpers only. */\nexport function defineRelations<\n\tconst Tables extends RelationTables,\n\tconst D extends RelationDeclarations,\n>(\n\ttables: Tables,\n\tdeclare: (\n\t\tr: RelationBuilder<Tables>,\n\t\tbranch: BranchBuilder<Tables>,\n\t) => D & ExactDeclarations<Tables, D>,\n): RelationRegistry<Tables, D> {\n\tconst metadata: Record<string, TableMetadata> = {}\n\tconst nativeTables: Record<string, TableDefinition> = {}\n\tconst ownRefs = new Set<AnyField>()\n\tconst branchRefs = new Map<string, Record<string, AnyField>>()\n\tconst fields: Record<string, Record<string, AnyField>> = {}\n\tconst one: Record<string, (spec: { from: Leg; to: Leg }) => AnyEdge> = {}\n\tconst many: Record<string, (spec: { from: Leg; to: Leg }) => AnyEdge> = {}\n\tfor (const [name, table] of Object.entries(tables)) {\n\t\tif (\n\t\t\ttable.tableName !== name ||\n\t\t\t['one', 'many', '__proto__', 'constructor', 'prototype'].includes(name)\n\t\t)\n\t\t\tthrow new Error(`Invalid relation table \"${name}\"`)\n\t\t// Registration-only preflight rejects accessors before native export or DTO\n\t\t// conversion. Stored parsers and their default/pipe callbacks are never run.\n\t\tconst nativeDescriptor = Object.getOwnPropertyDescriptor(table, 'table')\n\t\tif (!nativeDescriptor || !('value' in nativeDescriptor))\n\t\t\tthrow new Error('Unsupported native table accessor')\n\t\tconst nativeTable: TableDefinition = nativeDescriptor.value\n\t\tpreflightNative(nativeTable)\n\t\tpreflightSchema(table.schema, 'stored')\n\t\tpreflightSchema(table.publicDto, 'dto')\n\t\tconst sourceDto = table.dto(true)\n\t\tif (!(sourceDto instanceof z.ZodObject) && !(sourceDto instanceof z.ZodDiscriminatedUnion))\n\t\t\tthrow new Error('Expected object or discriminated union DTO')\n\t\tpreflightSchema(sourceDto, 'dto')\n\t\tconst dtoRecipe = captureDto(sourceDto)\n\t\tconst dto = materializeDto(dtoRecipe)\n\t\tif (!(dto instanceof z.ZodObject) && !(dto instanceof z.ZodDiscriminatedUnion))\n\t\t\tthrow new Error('Expected object or discriminated union DTO')\n\t\tconst exported = nativeTableExport(nativeTable)\n\t\tassertNativeValidation(exported.documentType)\n\t\tconst normalized = normalizeTable(name, table.schema, dto, exported.documentType)\n\t\tconst captured = indexExport.parse(exported)\n\t\tconst searchIndexes = Object.freeze(\n\t\t\t[\n\t\t\t\t...captured.searchIndexes.map((index) => ({ ...index, staged: false })),\n\t\t\t\t...captured.stagedSearchIndexes.map((index) => ({\n\t\t\t\t\t...index,\n\t\t\t\t\tstaged: true,\n\t\t\t\t})),\n\t\t\t]\n\t\t\t\t.map((index) =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tname: index.indexDescriptor,\n\t\t\t\t\t\tsearchField: index.searchField,\n\t\t\t\t\t\tfilterFields: Object.freeze([...index.filterFields].sort()),\n\t\t\t\t\t\tstaged: index.staged,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.sort((a, b) => a.name.localeCompare(b.name)),\n\t\t)\n\t\tconst indexes = captured.indexes\n\t\t\t.map((index) => ({\n\t\t\t\tname: index.indexDescriptor,\n\t\t\t\tfields: [...index.fields],\n\t\t\t}))\n\t\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\t\tassertNativeValidation(nativeJson(zodToConvex(dto)))\n\t\tnativeTables[name] = nativeTable\n\t\tconst fieldGroups: Record<string, readonly string[]> = Object.create(null)\n\t\tconst groupRecipes: Record<string, DtoRecipe> = Object.create(null)\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(table, 'fieldGroups')\n\t\tif ((!descriptor && 'fieldGroups' in table) || (descriptor && !('value' in descriptor)))\n\t\t\tthrow new Error('Invalid field groups')\n\t\tassertGroupData(descriptor?.value ?? {})\n\t\tconst definitions = z\n\t\t\t.record(z.string(), z.array(z.string()).nonempty())\n\t\t\t.parse(descriptor?.value ?? {})\n\t\tconst used = new Set<string>()\n\t\tconst publicBranches = dto instanceof z.ZodObject ? [dto] : dto.options\n\t\tfor (const [group, members] of Object.entries(definitions)) {\n\t\t\tif (!group || ['__proto__', 'constructor', 'prototype'].includes(group))\n\t\t\t\tthrow new Error('Invalid field groups')\n\t\t\tfor (const field of members) {\n\t\t\t\tif (\n\t\t\t\t\t!normalized.allFields.has(field) ||\n\t\t\t\t\tfield.startsWith('_') ||\n\t\t\t\t\tused.has(field) ||\n\t\t\t\t\tpublicBranches.some(\n\t\t\t\t\t\t(branch) => !(branch instanceof z.ZodObject) || Object.hasOwn(branch.shape, field),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error('Conflicting or incompatible field groups')\n\t\t\t\tconst validators = normalized.branches\n\t\t\t\t\t? Object.values(normalized.branches.options)\n\t\t\t\t\t\t\t.map((branch) => branch.fields[field])\n\t\t\t\t\t\t\t.filter((validator) => validator !== undefined)\n\t\t\t\t\t: [normalized.fields[field]]\n\t\t\t\tif (\n\t\t\t\t\t!validators.every(\n\t\t\t\t\t\t(validator) =>\n\t\t\t\t\t\t\tcanonicalNative(nativeJson(validator)) ===\n\t\t\t\t\t\t\t\tcanonicalNative(nativeJson(validators[0])) &&\n\t\t\t\t\t\t\tvalidator.isOptional === validators[0].isOptional,\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error('Conflicting or incompatible field groups')\n\t\t\t\tused.add(field)\n\t\t\t}\n\t\t\tfieldGroups[group] = Object.freeze([...members].sort())\n\t\t\tfor (const [tag, fields] of normalized.branches\n\t\t\t\t? Object.entries(normalized.branches.options).map(\n\t\t\t\t\t\t([tag, branch]) => [tag, branch.fields] as const,\n\t\t\t\t\t)\n\t\t\t\t: [[null, normalized.fields] as const]) {\n\t\t\t\tconst storedFields = Object.fromEntries(\n\t\t\t\t\tmembers\n\t\t\t\t\t\t.filter((field) => Object.hasOwn(fields, field))\n\t\t\t\t\t\t.map((field) => [field, fields[field]]),\n\t\t\t\t)\n\t\t\t\tgroupRecipes[JSON.stringify([group, tag])] = captureDto(\n\t\t\t\t\tconvexToZod(v.object(storedFields)).strict(),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tmetadata[name] = {\n\t\t\t...normalized,\n\t\t\tindexes,\n\t\t\tsearchIndexes,\n\t\t\tdto,\n\t\t\tdtoRecipe,\n\t\t\tfieldGroups: Object.freeze(fieldGroups),\n\t\t\tgroupRecipes: Object.freeze(groupRecipes),\n\t\t}\n\t\tconst makeReferences = (\n\t\t\tvalidators: Record<string, GenericValidator>,\n\t\t\tguard?: RelationGuard,\n\t\t) => {\n\t\t\tconst tableRefs: Record<string, AnyField> = Object.create(null)\n\t\t\tfunction makeReference(\n\t\t\t\tfield: string,\n\t\t\t\tvalidator: GenericValidator,\n\t\t\t\tmember?: RelationMember,\n\t\t\t): AnyField {\n\t\t\t\tconst ref: AnyField = {\n\t\t\t\t\t[fieldBrand]: undefined,\n\t\t\t\t\ttable: name,\n\t\t\t\t\tfield,\n\t\t\t\t\tguard,\n\t\t\t\t\tforTable(table: string) {\n\t\t\t\t\t\tif (guard) throw new Error('forTable on branch-scoped fields is unsupported')\n\t\t\t\t\t\tconst members = nativeIdMembers(validator)\n\t\t\t\t\t\tif (!members?.includes(table)) throw new Error('Invalid native ID member selection')\n\t\t\t\t\t\tif (!Object.hasOwn(metadata, table))\n\t\t\t\t\t\t\tthrow new Error('Native ID member table is not registered')\n\t\t\t\t\t\tconst selected = hasNull(validator) ? v.union(v.id(table), v.null()) : v.id(table)\n\t\t\t\t\t\treturn makeReference(\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalidator.isOptional === 'optional' ? v.optional(selected) : selected,\n\t\t\t\t\t\t\tObject.freeze({ table }),\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t\tthrough<J extends AnyField>(junction: J): ThroughReference<string, string, any, J, any> {\n\t\t\t\t\t\tif (member || memberRefs.has(junction))\n\t\t\t\t\t\t\tthrow new Error('forTable with through is unsupported')\n\t\t\t\t\t\tconst junctionValidator = refs.get(junction)\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!ownRefs.has(junction) ||\n\t\t\t\t\t\t\t!junctionValidator ||\n\t\t\t\t\t\t\t!compatible(validator, junctionValidator)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error('Invalid junction field or registry')\n\t\t\t\t\t\tconst result = Object.freeze({ base: ref, junction })\n\t\t\t\t\t\tthroughRefs.add(result)\n\t\t\t\t\t\treturn result\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\trefs.set(ref, validator)\n\t\t\t\tif (member) memberRefs.set(ref, member)\n\t\t\t\townRefs.add(ref)\n\t\t\t\treturn Object.freeze(ref)\n\t\t\t}\n\t\t\tfor (const [field, validator] of Object.entries(validators))\n\t\t\t\ttableRefs[field] = makeReference(field, validator)\n\t\t\treturn Object.freeze(tableRefs)\n\t\t}\n\t\tfields[name] = makeReferences(normalized.fields)\n\t\tif (normalized.branches)\n\t\t\tfor (const [tag, branch] of Object.entries(normalized.branches.options))\n\t\t\t\tbranchRefs.set(\n\t\t\t\t\tJSON.stringify([name, tag]),\n\t\t\t\t\tmakeReferences(\n\t\t\t\t\t\tbranch.fields,\n\t\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\t\tdiscriminator: normalized.branches.discriminator,\n\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\tone[name] = (spec) => makeEdge(name, 'one', spec, ownRefs)\n\t\tmany[name] = (spec) => makeEdge(name, 'many', spec, ownRefs)\n\t}\n\t// SAFETY: every native field has a branded reference; mapped builders retain the literal names.\n\tconst builder = Object.freeze({\n\t\t...fields,\n\t\tone: Object.freeze(one),\n\t\tmany: Object.freeze(many),\n\t}) as RelationBuilder<Tables>\n\t// SAFETY: branch references are created only for validated table/tag pairs and retain literal native field types.\n\tconst branch = ((table: string, tag: string) => {\n\t\tconst result = branchRefs.get(JSON.stringify([table, tag]))\n\t\tif (!result) throw new Error(`Unknown variant scope \"${table}.${tag}\"`)\n\t\treturn result\n\t}) as BranchBuilder<Tables>\n\tconst supplied = declare(builder, branch)\n\tconst declarations: RelationDeclarations = Object.fromEntries(\n\t\tObject.entries(supplied).map(([name, edges]) => [name, Object.freeze({ ...edges })]),\n\t)\n\tObject.freeze(declarations)\n\tfor (const [source, edges] of Object.entries(declarations)) {\n\t\tif (!Object.hasOwn(metadata, source)) throw new Error(`Unknown source table \"${source}\"`)\n\t\tfor (const [name, edge] of Object.entries(edges)) {\n\t\t\tif (\n\t\t\t\tmetadata[source].allFields.has(name) ||\n\t\t\t\t(metadata[source].branches && ['variant', 'variants'].includes(name)) ||\n\t\t\t\t['and', 'or', 'not', 'fields', 'then', '__proto__', 'constructor', 'prototype'].includes(\n\t\t\t\t\tname,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error(`Relation name collision \"${name}\"`)\n\t\t\tif (\n\t\t\t\t!edgeRefs.has(edge) ||\n\t\t\t\t!ownRefs.has(base(edge.from)) ||\n\t\t\t\t!ownRefs.has(base(edge.to)) ||\n\t\t\t\tedge.source !== source\n\t\t\t)\n\t\t\t\tthrow new Error('Relation source bucket mismatch')\n\t\t\tvalidatePath(edge, metadata)\n\t\t}\n\t}\n\tconst internal: RegistryMetadata = { metadata, declarations }\n\tconst helpers: Record<\n\t\tstring,\n\t\t{\n\t\t\tfilters<F extends Record<string, GenericValidator>>(contract: FilterContract<F>): z.ZodType\n\t\t\tpaginationOpts(selection: SelectionMask): z.ZodType\n\t\t\tpageDto(selection: SelectionMask, groups?: GroupSelection): z.ZodType\n\t\t}\n\t> = {}\n\tfor (const table of Object.keys(metadata))\n\t\thelpers[table] = {\n\t\t\tfilters<F extends Record<string, GenericValidator>>(contract: FilterContract<F>) {\n\t\t\t\tif (metadata[table].branches)\n\t\t\t\t\tthrow new Error('Shared scalar contracts do not support variant tables')\n\t\t\t\tfor (const [field, expected] of Object.entries(contract.native)) {\n\t\t\t\t\tconst actual = metadata[table].fields[field]\n\t\t\t\t\tif (\n\t\t\t\t\t\t!actual ||\n\t\t\t\t\t\tJSON.stringify(nativeJson(actual)) !== JSON.stringify(expected.json) ||\n\t\t\t\t\t\t(actual.isOptional === 'optional') !== expected.optional\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(`Shared filter field mismatch \"${field}\"`)\n\t\t\t\t}\n\t\t\t\treturn materializeDto(paginationRecipe).extend({\n\t\t\t\t\tfilters: contract.schema.optional(),\n\t\t\t\t\torder: z.enum(['asc', 'desc']).optional(),\n\t\t\t\t})\n\t\t\t},\n\t\t\tpaginationOpts(selection: SelectionMask): z.ZodType {\n\t\t\t\tassertSelection(selection)\n\t\t\t\treturn materializeDto(paginationRecipe).extend({\n\t\t\t\t\tfilters: relationFilterSchema(filterGrammar(internal, table, selection)).optional(),\n\t\t\t\t\torder: z.enum(['asc', 'desc']).optional(),\n\t\t\t\t})\n\t\t\t},\n\t\t\tpageDto(selection: SelectionMask, groups: GroupSelection = {}): z.ZodType {\n\t\t\t\tassertSelection(selection)\n\t\t\t\tassertGroups(internal, table, groups)\n\t\t\t\treturn paginated(rowSchema(internal, table, selection, 0, groups)).result\n\t\t\t},\n\t\t}\n\n\t// Stable, collision-free canonical metadata encoding. It is an identity, not a secret/hash.\n\tconst identity = JSON.stringify([\n\t\t2,\n\t\tObject.entries(metadata)\n\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t.map(([name, data]) => [\n\t\t\t\tname,\n\t\t\t\tObject.entries(data.fields)\n\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t.map(([field, validator]) => [field, validator.isOptional, nativeJson(validator)]),\n\t\t\t\tdata.branches\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tdata.branches.discriminator,\n\t\t\t\t\t\t\tObject.entries(data.branches.options)\n\t\t\t\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t\t\t\t.map(([tag, branch]) => [\n\t\t\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\t\t\tObject.entries(branch.fields)\n\t\t\t\t\t\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t\t\t\t\t\t.map(([field, validator]) => [\n\t\t\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\t\t\tvalidator.isOptional,\n\t\t\t\t\t\t\t\t\t\t\tnativeJson(validator),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]\n\t\t\t\t\t: null,\n\t\t\t\tdata.indexes,\n\t\t\t\tcanonicalNative(nativeJson(zodToConvex(data.dto))),\n\t\t\t\t...(Object.keys(data.fieldGroups).length ? [data.fieldGroups] : []),\n\t\t\t\t...(data.searchIndexes.length ? [{ searchIndexes: data.searchIndexes }] : []),\n\t\t\t]),\n\t\tObject.entries(declarations)\n\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t.map(([source, edges]) => [\n\t\t\t\tsource,\n\t\t\t\tObject.entries(edges)\n\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t.map(([name, edge]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tedge.cardinality,\n\t\t\t\t\t\tedge.target,\n\t\t\t\t\t\tserializeLeg(edge.from),\n\t\t\t\t\t\tserializeLeg(edge.to),\n\t\t\t\t\t]),\n\t\t\t]),\n\t])\n\t// SAFETY: helpers are assembled for every validated literal table and mask; schemas derive matching native fields/public DTOs.\n\tconst registry = Object.freeze({\n\t\tidentity,\n\t\tversion: 1,\n\t\ttables: Object.freeze(helpers),\n\t}) as RelationRegistry<Tables, D>\n\tregistries.set(registry, snapshotMetadata(internal))\n\t// convex-helpers reads schema.tables[table].indexes live. Supply a genuine\n\t// private Convex schema whose only purpose is stable stream index metadata.\n\tconst streamTables: Record<string, TableDefinition> = {}\n\tfor (const [name, data] of Object.entries(metadata)) {\n\t\tconst table: TableDefinition = defineTable({})\n\t\tfor (const index of data.indexes) {\n\t\t\tconst [first, ...rest] = index.fields\n\t\t\tif (first === undefined) throw new Error('Invalid empty active index')\n\t\t\ttable.index(index.name, [first, ...rest])\n\t\t}\n\t\tconst indexes = Object.getOwnPropertyDescriptor(table, 'indexes')!.value\n\t\tfor (const index of indexes) {\n\t\t\tObject.freeze(index.fields)\n\t\t\tObject.freeze(index)\n\t\t}\n\t\tObject.freeze(indexes)\n\t\tObject.freeze(table)\n\t\tstreamTables[name] = table\n\t}\n\texecutorRegistries.set(registry, {\n\t\tinternal,\n\t\tnativeTables: Object.freeze(nativeTables),\n\t\tstreamSchema: defineSchema(Object.freeze(streamTables)),\n\t})\n\treturn registry\n}\n\n/** Internal owned executor bridge. Source ownership is checked once by each engine. */\nexport function getRelationExecutor(registry: RelationRegistryIdentity) {\n\tconst owned = executorRegistries.get(registry)\n\tif (!owned) throw new Error('Unknown relation registry')\n\tconst assertSchema = (tables: Readonly<Record<string, TableDefinition>>) => {\n\t\tconst names = Object.keys(owned.nativeTables)\n\t\tif (\n\t\t\tnames.length !== Reflect.ownKeys(tables).length ||\n\t\t\tnames.some((name) => {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(tables, name)\n\t\t\t\treturn (\n\t\t\t\t\t!descriptor || !('value' in descriptor) || descriptor.value !== owned.nativeTables[name]\n\t\t\t\t)\n\t\t\t})\n\t\t)\n\t\t\tthrow new Error('Native schema/table ownership disagrees with relation registry')\n\t}\n\tconst branchValidators = new WeakMap<\n\t\tobject,\n\t\t{ validator: z.ZodType; fieldKeys: readonly string[] }\n\t>()\n\tconst projectionKeys = new WeakMap<z.ZodObject, readonly string[]>()\n\tconst groupDtos = new WeakMap<z.ZodObject, Map<string, z.ZodObject>>()\n\tconst scalarFields = new Map<string, FieldSchemas>()\n\tconst grammars = new Map<string, FilterGrammar>()\n\tconst filterNodes = new WeakMap<FilterGrammar, Map<number, z.ZodObject>>()\n\tfunction validateDocument(\n\t\ttable: string,\n\t\trow: Record<string, import('convex/values').Value>,\n\t): void {\n\t\tconst data = owned!.internal.metadata[table]\n\t\tif (!data) throw new Error('Unknown query table')\n\t\tif (!data.branches) return\n\t\tconst tag = row[data.branches.discriminator]\n\t\tconst branch =\n\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Native discriminator admission precedes the captured branch parser.\n\t\t\ttypeof tag === 'string' && Object.hasOwn(data.branches.options, tag)\n\t\t\t\t? data.branches.options[tag]\n\t\t\t\t: undefined\n\t\tif (!branch) throw new Error('Invalid variant document')\n\t\tlet cached = branchValidators.get(branch)\n\t\tconst fieldKeys = cached?.fieldKeys ?? Object.keys(branch.fields)\n\t\tconst entries: [string, import('convex/values').Value | undefined][] = []\n\t\t// Snapshot ownership before reading getters, as filter().map() did.\n\t\tfor (const key of fieldKeys) if (Object.hasOwn(row, key)) entries.push([key, undefined])\n\t\tfor (const entry of entries) entry[1] = row[entry[0]]\n\t\tconst values = Object.fromEntries(entries)\n\t\tif (!cached) {\n\t\t\tcached = { validator: convexToZod(v.object(branch.fields)), fieldKeys }\n\t\t\tbranchValidators.set(branch, cached)\n\t\t}\n\t\tcached.validator.parse(values)\n\t}\n\treturn Object.freeze({\n\t\tstreamSchema: owned.streamSchema,\n\t\tgroups(table: string, groups: GroupSelection) {\n\t\t\treturn assertGroups(owned.internal, table, groups)\n\t\t},\n\t\tvalidateDocument,\n\t\tassertSchema,\n\t\tpagination(table: string) {\n\t\t\tconst internal = owned.internal\n\t\t\tfunction grammar(name: string, depth: number, tag?: string): FilterGrammar {\n\t\t\t\tconst grammarKey = JSON.stringify([name, depth, tag ?? null])\n\t\t\t\tconst cached = grammars.get(grammarKey)\n\t\t\t\tif (cached) return cached\n\t\t\t\tconst data = internal.metadata[name]\n\t\t\t\tif (!data) throw new Error('Unknown query table')\n\t\t\t\tconst cacheKey = JSON.stringify([name, tag ?? null])\n\t\t\t\tlet fields = scalarFields.get(cacheKey)\n\t\t\t\tif (!fields) {\n\t\t\t\t\tfields = {}\n\t\t\t\t\tfor (const [name, validator] of Object.entries(\n\t\t\t\t\t\ttag === undefined ? data.fields : data.branches!.options[tag].fields,\n\t\t\t\t\t)) {\n\t\t\t\t\t\t// Unsupported stored containers are not scalar-queryable. No validators\n\t\t\t\t\t\t// are reconstructed from JSON; these are the actual native validators.\n\t\t\t\t\t\tif (scalarValidator(validator))\n\t\t\t\t\t\t\tfields[name] = scalarPredicateSchema(validator).optional()\n\t\t\t\t\t}\n\t\t\t\t\tscalarFields.set(cacheKey, fields)\n\t\t\t\t}\n\t\t\t\tconst result: FilterGrammar = {\n\t\t\t\t\tfields,\n\t\t\t\t\tvariants:\n\t\t\t\t\t\tdata.branches && tag === undefined && depth < 4\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tdiscriminator: data.branches.discriminator,\n\t\t\t\t\t\t\t\t\toptions: Object.fromEntries(\n\t\t\t\t\t\t\t\t\t\tObject.keys(data.branches.options).map((tag) => [\n\t\t\t\t\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\t\t\t\t\tgrammar(name, depth + 1, tag),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\trelations:\n\t\t\t\t\t\tdepth >= 4\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.entries(internal.declarations[name] ?? {}).map(([edge, declaration]) => [\n\t\t\t\t\t\t\t\t\t\tedge,\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcardinality: declaration.cardinality,\n\t\t\t\t\t\t\t\t\t\t\ttarget: grammar(declaration.target, depth + 1),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t\tgrammars.set(grammarKey, result)\n\t\t\t\treturn result\n\t\t\t}\n\t\t\treturn materializeDto(paginationRecipe).extend({\n\t\t\t\tfilters: relationFilterSchema(grammar(table, 0), filterNodes).optional(),\n\t\t\t\torder: z.enum(['asc', 'desc']).optional(),\n\t\t\t})\n\t\t},\n\t\tselect(table: string, selection: SelectionMask) {\n\t\t\tassertSelection(selection)\n\t\t\tfunction visit(table: string, selected: SelectionMask, depth: number): void {\n\t\t\t\tif (!Object.hasOwn(owned!.internal.metadata, table)) throw new Error('Unknown query table')\n\t\t\t\tfor (const [name, mask] of Object.entries(selected)) {\n\t\t\t\t\tconst edge = owned!.internal.declarations[table]?.[name]\n\t\t\t\t\tif (!edge || depth >= 4)\n\t\t\t\t\t\tthrow new Error(`Unknown or too deep relation \"${table}.${name}\"`)\n\t\t\t\t\tif (mask !== true) visit(edge.target, mask, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\tvisit(table, selection, 0)\n\t\t},\n\t\tproject(\n\t\t\ttable: string,\n\t\t\trow: Record<string, import('convex/values').Value>,\n\t\t\teligible: () => boolean,\n\t\t\tgroups: readonly string[] = [],\n\t\t) {\n\t\t\tif (!eligible()) return null\n\t\t\tconst data = owned.internal.metadata[table]\n\t\t\tif (!data) throw new Error('Unknown query table')\n\t\t\tconst branch = data.branches\n\t\t\t\t? data.branches.options[String(row[data.branches.discriminator])]\n\t\t\t\t: undefined\n\t\t\tif (data.branches && !branch) throw new Error('Invalid variant document')\n\t\t\tlet dto = branch?.dto ?? data.dto\n\t\t\tif (!(dto instanceof z.ZodObject)) throw new Error('Invalid variant DTO')\n\t\t\tif (groups.length) {\n\t\t\t\tlet variants = groupDtos.get(dto)\n\t\t\t\tif (!variants) {\n\t\t\t\t\tvariants = new Map()\n\t\t\t\t\tgroupDtos.set(dto, variants)\n\t\t\t\t}\n\t\t\t\tconst key = JSON.stringify([...groups].sort())\n\t\t\t\tlet composed = variants.get(key)\n\t\t\t\tif (!composed) {\n\t\t\t\t\tcomposed = dto\n\t\t\t\t\t\t.extend(\n\t\t\t\t\t\t\tgroupValidators(\n\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\tgroups,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\tdata.branches ? String(row[data.branches.discriminator]) : undefined,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.strict()\n\t\t\t\t\tvariants.set(key, composed)\n\t\t\t\t}\n\t\t\t\tdto = composed\n\t\t\t}\n\t\t\tvalidateDocument(table, row)\n\t\t\tlet keys = projectionKeys.get(dto)\n\t\t\tif (!keys) {\n\t\t\t\tkeys = Object.keys(dto.shape)\n\t\t\t\tprojectionKeys.set(dto, keys)\n\t\t\t}\n\t\t\t// The strict DTO remains the authority. Pick its fields before parsing,\n\t\t\t// matching table projection without spreading any storage-only fields.\n\t\t\treturn dto.parse(\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tkeys.filter((key) => Object.hasOwn(row, key)).map((key) => [key, row[key]]),\n\t\t\t\t),\n\t\t\t)\n\t\t},\n\t})\n}\n/** Internal compiler/engine adapter. Registry identity alone cannot forge a registry. */\nexport function getRelationMetadata(registry: RelationRegistryIdentity): RelationMetadata {\n\tconst metadata = registries.get(registry)\n\tif (!metadata) throw new Error('Unknown relation registry')\n\treturn metadata\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Registration preflight inspects descriptors before Zod can invoke caller getters; typed parsing follows immediately.\nfunction assertGroupData(value: unknown, depth = 0): void {\n\tif (depth > 16) throw new Error('Invalid field groups')\n\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Descriptor preflight must distinguish primitive leaves without invoking caller-owned accessors.\n\tif (value === null || typeof value !== 'object') return\n\tconst prototype = Object.getPrototypeOf(value)\n\tif (prototype !== Object.prototype && prototype !== null && prototype !== Array.prototype)\n\t\tthrow new Error('Invalid field groups')\n\tfor (const key of Reflect.ownKeys(value)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key)!\n\t\tif (!z.string().safeParse(key).success || !('value' in descriptor))\n\t\t\tthrow new Error('Invalid field groups')\n\t\tassertGroupData(descriptor.value, depth + 1)\n\t}\n}\n\nfunction assertGroups(\n\tregistry: RegistryMetadata,\n\ttable: string,\n\tinput: GroupSelection,\n): GroupSelection {\n\tassertGroupData(input)\n\tfunction visit(table: string, input: GroupSelection, depth: number): GroupSelection {\n\t\tconst parsed = z\n\t\t\t.object({\n\t\t\t\tfieldGroups: z.record(z.string(), z.enum(['required', 'if-permitted'])).optional(),\n\t\t\t\trelations: z.record(z.string(), z.unknown()).optional(),\n\t\t\t})\n\t\t\t.strict()\n\t\t\t.parse(input)\n\t\tconst data = registry.metadata[table]\n\t\tif (!data) throw new Error('Unknown query table')\n\t\tfor (const name of Object.keys(parsed.fieldGroups ?? {}))\n\t\t\tif (!Object.hasOwn(data.fieldGroups, name)) throw new Error('Unknown field group')\n\t\tconst relations: Record<string, GroupSelection> = {}\n\t\tfor (const [name, nested] of Object.entries(parsed.relations ?? {})) {\n\t\t\tconst edge = registry.declarations[table]?.[name]\n\t\t\tif (!edge || depth >= 4) throw new Error('Invalid field group relation')\n\t\t\t// SAFETY: the recursive visitor validates each unknown node before using it.\n\t\t\trelations[name] = visit(edge.target, nested as GroupSelection, depth + 1)\n\t\t}\n\t\treturn Object.freeze({\n\t\t\tfieldGroups: Object.freeze(parsed.fieldGroups ?? {}),\n\t\t\trelations: Object.freeze(relations),\n\t\t})\n\t}\n\treturn visit(table, input, 0)\n}\n\nfunction groupValidators(\n\tdata: TableMetadata,\n\tgroups: readonly string[],\n\tmodes?: GroupSelection['fieldGroups'],\n\ttag?: string,\n): FieldSchemas {\n\tconst fields: FieldSchemas = {}\n\tfor (const name of groups) {\n\t\tconst key = JSON.stringify([name, tag ?? null])\n\t\tif (!Object.hasOwn(data.groupRecipes, key)) throw new Error('Unknown field group')\n\t\tconst schema = materializeDto(data.groupRecipes[key])\n\t\tif (!(schema instanceof z.ZodObject)) throw new Error('Invalid field group schema')\n\t\tfor (const [field, validator] of Object.entries(schema.shape))\n\t\t\tfields[field] = modes?.[name] === 'if-permitted' ? validator.optional() : validator\n\t}\n\treturn fields\n}\n\nfunction scalarValidator(validator: GenericValidator): boolean {\n\treturn (\n\t\t['id', 'string', 'float64', 'int64', 'boolean', 'null', 'literal'].includes(validator.kind) ||\n\t\t(validator.kind === 'union' && validator.members.every(scalarValidator))\n\t)\n}\n\nfunction assertSelection(selection: SelectionMask): void {\n\tconst pending: {\n\t\tvalue: SelectionMask\n\t\tdepth: number\n\t\tancestors: readonly SelectionMask[]\n\t}[] = [{ value: selection, depth: 0, ancestors: [] }]\n\tlet nodes = 0\n\twhile (pending.length) {\n\t\tconst { value, depth, ancestors } = pending.pop()!\n\t\tif (++nodes > 256 || depth > 4 || ancestors.includes(value))\n\t\t\tthrow new Error('Selection cycle or depth/node budget exceeded')\n\t\tconst prototype = Object.getPrototypeOf(value)\n\t\tif (prototype !== Object.prototype && prototype !== null) throw new Error('Invalid selection')\n\t\tconst keys = Reflect.ownKeys(value)\n\t\tif (keys.length + nodes + pending.length > 256)\n\t\t\tthrow new Error('Selection node budget exceeded')\n\t\tfor (const key of keys) {\n\t\t\tconst property = Object.getOwnPropertyDescriptor(value, key)!\n\t\t\tif (!property.enumerable || !('value' in property) || String(key) !== key)\n\t\t\t\tthrow new Error('Invalid selection property')\n\t\t\tif (property.value !== true)\n\t\t\t\tpending.push({\n\t\t\t\t\tvalue: property.value,\n\t\t\t\t\tdepth: depth + 1,\n\t\t\t\t\tancestors: [...ancestors, value],\n\t\t\t\t})\n\t\t\telse if (++nodes > 256) throw new Error('Selection node budget exceeded')\n\t\t}\n\t}\n}\nfunction base(leg: Leg): AnyField {\n\treturn 'base' in leg ? leg.base : leg\n}\nfunction makeEdge(\n\ttarget: string,\n\tcardinality: 'one' | 'many',\n\tspec: { from: Leg; to: Leg },\n\town: Set<AnyField>,\n): AnyEdge {\n\tfor (const leg of [spec.from, spec.to]) {\n\t\tif (!own.has(base(leg)) || ('base' in leg && (!throughRefs.has(leg) || !own.has(leg.junction))))\n\t\t\tthrow new Error('Foreign registry or invalid field reference')\n\t}\n\tif (base(spec.to).table !== target) throw new Error('Wrong relation target table')\n\tconst result: AnyEdge = Object.freeze({\n\t\t[edgeBrand]: true as const,\n\t\tsource: base(spec.from).table,\n\t\ttarget,\n\t\tcardinality,\n\t\tfrom: spec.from,\n\t\tto: spec.to,\n\t\tsourceGuard: base(spec.from).guard,\n\t\ttargetGuard: base(spec.to).guard,\n\t\tjunctionGuard: junctionGuard(spec.from, spec.to),\n\t\tsourceMember: memberRefs.get(base(spec.from)),\n\t\ttargetMember: memberRefs.get(base(spec.to)),\n\t})\n\tedgeRefs.add(result)\n\treturn result\n}\nfunction junctionGuard(from: Leg, to: Leg): RelationGuard | undefined {\n\tconst left = 'base' in from ? from.junction.guard : undefined\n\tconst right = 'base' in to ? to.junction.guard : undefined\n\tif (left && right && (left.discriminator !== right.discriminator || left.tag !== right.tag))\n\t\tthrow new Error('Contradictory junction scopes')\n\treturn left ?? right\n}\nfunction nativeIdMembers(validator: GenericValidator): string[] | null {\n\tif (validator.kind === 'id') return [validator.tableName]\n\tif (validator.kind === 'null') return []\n\tif (validator.kind !== 'union') return null\n\tconst members = validator.members.map(nativeIdMembers)\n\treturn members.some((member) => member === null)\n\t\t? null\n\t\t: [...new Set(members.flatMap((member) => member!))].sort()\n}\nfunction compatible(left: GenericValidator, right: GenericValidator): boolean {\n\tconst leftDomain = domain(left)\n\treturn leftDomain.length > 0 && JSON.stringify(leftDomain) === JSON.stringify(domain(right))\n}\nfunction domain(validator: GenericValidator): string[] {\n\tif (validator.kind === 'union') return [...new Set(validator.members.flatMap(domain))].sort()\n\tif (validator.kind === 'null') return []\n\tif (!['id', 'string', 'float64', 'int64', 'boolean', 'literal'].includes(validator.kind))\n\t\tthrow new Error('Unsupported relation field kind')\n\treturn [JSON.stringify(nativeJson(validator))]\n}\nfunction validatePath(edge: AnyEdge, metadata: Record<string, TableMetadata>): void {\n\tconst from = edge.from\n\tconst to = edge.to\n\tif ('base' in from !== 'base' in to) throw new Error('Both relation legs must use through')\n\tif ('base' in from && 'base' in to) {\n\t\tif (from.junction.table !== to.junction.table) throw new Error('Different junction tables')\n\t\trequireIndex(metadata, from.junction.table, from.junction.field, edge.junctionGuard)\n\t\trequireIndex(metadata, edge.target, to.base.field, edge.targetGuard)\n\t\treturn\n\t}\n\tif (!compatible(refs.get(base(from))!, refs.get(base(to))!))\n\t\tthrow new Error('Incompatible relation field types')\n\trequireIndex(metadata, edge.target, base(to).field, edge.targetGuard)\n}\nfunction requireIndex(\n\tmetadata: Record<string, TableMetadata>,\n\ttable: string,\n\tfield: string,\n\tguard?: RelationGuard,\n): void {\n\tif (\n\t\tfield !== '_id' &&\n\t\t!metadata[table].indexes.some((index) => {\n\t\t\tconst position = index.fields.indexOf(field)\n\t\t\treturn (\n\t\t\t\tposition >= 0 &&\n\t\t\t\tindex.fields.slice(0, position).every((key) => key === guard?.discriminator)\n\t\t\t)\n\t\t})\n\t)\n\t\tthrow new Error(`No active index begins with or has a guarded prefix for \"${table}.${field}\"`)\n}\nfunction serializeLeg(leg: Leg): unknown[] {\n\treturn 'base' in leg\n\t\t? [\n\t\t\t\tleg.base.table,\n\t\t\t\tleg.base.field,\n\t\t\t\tleg.base.guard ?? null,\n\t\t\t\tleg.junction.table,\n\t\t\t\tleg.junction.field,\n\t\t\t\tleg.junction.guard ?? null,\n\t\t\t]\n\t\t: memberRefs.has(leg)\n\t\t\t? [leg.table, leg.field, leg.guard ?? null, memberRefs.get(leg)]\n\t\t\t: [leg.table, leg.field, leg.guard ?? null]\n}\nfunction filterGrammar(\n\tregistry: RegistryMetadata,\n\ttable: string,\n\tselection: SelectionMask,\n\tdepth: number = 0,\n\ttag?: string,\n): FilterGrammar {\n\tconst fields: FieldSchemas = {}\n\tconst relations: FilterGrammar['relations'] = {}\n\tconst data = registry.metadata[table]\n\tconst variants: Record<string, FilterGrammar> = {}\n\tfor (const [key, mask] of Object.entries(selection)) {\n\t\tif (key === 'variants' && mask !== true && data.branches && tag === undefined) {\n\t\t\tif (depth >= 4) throw new Error('Invalid variant selection')\n\t\t\tfor (const [tag, selected] of Object.entries(mask)) {\n\t\t\t\tif (!Object.hasOwn(data.branches.options, tag) || selected === true)\n\t\t\t\t\tthrow new Error('Unknown variant filter selection')\n\t\t\t\tconst common = Object.fromEntries(\n\t\t\t\t\tObject.entries(selection).filter(([key]) => key !== 'variants'),\n\t\t\t\t)\n\t\t\t\tvariants[tag] = filterGrammar(registry, table, { ...common, ...selected }, depth + 1, tag)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tconst validator = (tag === undefined ? data.fields : data.branches!.options[tag].fields)[key]\n\t\tconst edge = registry.declarations[table]?.[key]\n\t\tif (mask === true && validator) fields[key] = scalarPredicateSchema(validator).optional()\n\t\telse if (mask !== true && edge && depth < 4)\n\t\t\trelations[key] = {\n\t\t\t\tcardinality: edge.cardinality,\n\t\t\t\ttarget: filterGrammar(registry, edge.target, mask, depth + 1),\n\t\t\t}\n\t\telse throw new Error(`Invalid relation filter selection \"${table}.${key}\"`)\n\t}\n\treturn {\n\t\tfields,\n\t\trelations,\n\t\tvariants:\n\t\t\tdata.branches && tag === undefined\n\t\t\t\t? { discriminator: data.branches.discriminator, options: variants }\n\t\t\t\t: undefined,\n\t}\n}\nfunction rowSchema(\n\tregistry: RegistryMetadata,\n\ttable: string,\n\tselection: SelectionMask,\n\tdepth: number = 0,\n\tgroups: GroupSelection = {},\n): z.ZodType {\n\tconst relationFields: FieldSchemas = {}\n\tfor (const [name, mask] of Object.entries(selection)) {\n\t\tconst edge = registry.declarations[table]?.[name]\n\t\tif (!edge || depth >= 4) throw new Error(`Unknown or too deep relation \"${table}.${name}\"`)\n\t\tlet target = rowSchema(\n\t\t\tregistry,\n\t\t\tedge.target,\n\t\t\tmask === true ? {} : mask,\n\t\t\tdepth + 1,\n\t\t\tgroups.relations?.[name],\n\t\t)\n\t\tif (edge.targetGuard) {\n\t\t\tif (!(target instanceof z.ZodDiscriminatedUnion)) throw new Error('Invalid target scope')\n\t\t\ttarget = target.options\n\t\t\t\t.filter((option): option is z.ZodObject => option instanceof z.ZodObject)\n\t\t\t\t.find(\n\t\t\t\t\t(option: z.ZodObject) =>\n\t\t\t\t\t\toption.shape[edge.targetGuard!.discriminator] instanceof z.ZodLiteral &&\n\t\t\t\t\t\toption.shape[edge.targetGuard!.discriminator].value === edge.targetGuard!.tag,\n\t\t\t\t)!\n\t\t}\n\t\trelationFields[name] = edge.cardinality === 'one' ? target.nullable() : paginated(target).result\n\t}\n\tconst data = registry.metadata[table]\n\tconst dto = materializeDto(data.dtoRecipe)\n\tfunction compose(dto: z.ZodObject, tag?: string) {\n\t\tconst selected = { ...relationFields }\n\t\tfor (const name of Object.keys(selected)) {\n\t\t\tconst edge = registry.declarations[table][name]\n\t\t\tif (edge.sourceGuard && tag !== edge.sourceGuard.tag && edge.cardinality === 'one')\n\t\t\t\tselected[name] = z.null()\n\t\t}\n\t\treturn dto\n\t\t\t.extend({\n\t\t\t\t...groupValidators(data, Object.keys(groups.fieldGroups ?? {}), groups.fieldGroups, tag),\n\t\t\t\t...selected,\n\t\t\t})\n\t\t\t.strict()\n\t}\n\tif (data.branches) {\n\t\tif (!(dto instanceof z.ZodDiscriminatedUnion)) throw new Error('Invalid variant DTO')\n\t\tconst options = dto.options.map((option) => {\n\t\t\tif (!(option instanceof z.ZodObject)) throw new Error('Invalid variant DTO')\n\t\t\tconst tag = option.shape[data.branches!.discriminator]\n\t\t\tif (!(tag instanceof z.ZodLiteral)) throw new Error('Invalid variant tag')\n\t\t\treturn compose(option, String(tag.value))\n\t\t})\n\t\treturn z.discriminatedUnion(data.branches.discriminator, [options[0], ...options.slice(1)])\n\t}\n\tif (!(dto instanceof z.ZodObject)) throw new Error('Expected object DTO')\n\treturn compose(dto)\n}\n\nfunction normalizeTable(\n\tname: string,\n\tschema: RelationTable['schema'],\n\tdto: z.ZodObject | z.ZodDiscriminatedUnion<any, string>,\n\tdocument: ValidatorJSON,\n): Pick<TableMetadata, 'fields' | 'branches' | 'allFields'> {\n\tif (schema instanceof z.ZodObject && dto instanceof z.ZodObject) {\n\t\tconst fields = zodToConvex(schema).fields\n\t\tassertStoredDocument(name, fields, document)\n\t\treturn { fields, allFields: new Set(Object.keys(fields)) }\n\t}\n\tif (!(schema instanceof z.ZodDiscriminatedUnion) || !(dto instanceof z.ZodDiscriminatedUnion))\n\t\tthrow new Error(`Expected matching discriminated union boundaries \"${name}\"`)\n\tconst discriminator = schema._zod.def.discriminator\n\tif (dto._zod.def.discriminator !== discriminator) throw new Error('DTO discriminator mismatch')\n\tfunction options(union: z.ZodDiscriminatedUnion<any, string>): Record<string, z.ZodObject> {\n\t\tconst result: Record<string, z.ZodObject> = Object.create(null)\n\t\tfor (const option of union.options) {\n\t\t\tif (!(option instanceof z.ZodObject)) throw new Error('Variant branches must be objects')\n\t\t\tconst tag = option.shape[discriminator]\n\t\t\tif (!(tag instanceof z.ZodLiteral) || tag.values.size !== 1)\n\t\t\t\tthrow new Error('Variant tags must be unique required string literals')\n\t\t\tconst literal = z.string().safeParse(tag.value)\n\t\t\tif (!literal.success || Object.hasOwn(result, literal.data))\n\t\t\t\tthrow new Error('Variant tags must be unique required string literals')\n\t\t\tresult[literal.data] = option\n\t\t}\n\t\tif (Object.keys(result).length === 0) throw new Error('Expected at least one variant branch')\n\t\treturn result\n\t}\n\tconst documents = options(schema),\n\t\tdtos = options(dto)\n\tif (Object.keys(documents).sort().join('\\0') !== Object.keys(dtos).sort().join('\\0'))\n\t\tthrow new Error('DTO variant tags mismatch')\n\tconst branches: NonNullable<TableMetadata['branches']> = {\n\t\tdiscriminator,\n\t\toptions: Object.create(null),\n\t}\n\tconst stored: GenericValidator[] = []\n\tfor (const [tag, object] of Object.entries(documents)) {\n\t\tconst fields = zodToConvex(object).fields\n\t\tconst { _id, _creationTime, ...storage } = fields\n\t\tassertStoredDocument(name, fields, nativeJson(v.object(storage)))\n\t\tstored.push(v.object(storage))\n\t\tbranches.options[tag] = { fields, dto: dtos[tag] }\n\t}\n\tif (canonicalNative(document) !== canonicalNative(nativeJson(v.union(...stored))))\n\t\tthrow new Error(`Native stored document disagrees with boundary \"${name}\"`)\n\tconst members = Object.values(branches.options).map((branch) => branch.fields)\n\tconst fields: Record<string, GenericValidator> = {}\n\tfor (const key of Object.keys(members[0])) {\n\t\tif (!members.every((member) => Object.hasOwn(member, key))) continue\n\t\tif (\n\t\t\tkey !== discriminator &&\n\t\t\t!members.every((member) => commonCompatible(member[key], members[0][key]))\n\t\t)\n\t\t\tcontinue\n\t\tconst validators = members.map((member) => member[key])\n\t\tconst union = v.union(...validators)\n\t\tfields[key] = validators.some((validator) => validator.isOptional === 'optional')\n\t\t\t? v.optional(union)\n\t\t\t: union\n\t}\n\treturn {\n\t\tfields,\n\t\tbranches,\n\t\tallFields: new Set(members.flatMap((member) => Object.keys(member))),\n\t}\n}\nfunction commonCompatible(left: GenericValidator, right: GenericValidator): boolean {\n\ttry {\n\t\treturn compatible(left, right)\n\t} catch {\n\t\treturn canonicalNative(nativeJson(left)) === canonicalNative(nativeJson(right))\n\t}\n}\n\ninterface NativeTableExport {\n\tindexes: { indexDescriptor: string; fields: string[] }[]\n\tdocumentType: ValidatorJSON\n}\n// Capture the installed peer's prototypes before accepting caller-owned instances.\n// Native json getters are trusted only on these prototypes; own accessors and\n// custom prototypes fail closed without evaluating them.\nconst nativePrototypes = new Map<object, PropertyDescriptorMap>()\nfor (const sample of [\n\tdefineTable(v.object({})),\n\tv.id('sample'),\n\tv.null(),\n\tv.number(),\n\tv.int64(),\n\tv.commitTs(),\n\tv.boolean(),\n\tv.string(),\n\tv.bytes(),\n\tv.any(),\n\tv.object({}),\n\tv.literal('sample'),\n\tv.array(v.string()),\n\tv.record(v.string(), v.string()),\n\tv.union(v.string(), v.null()),\n]) {\n\tlet prototype = Object.getPrototypeOf(sample)\n\twhile (prototype && prototype !== Object.prototype) {\n\t\tif (!nativePrototypes.has(prototype))\n\t\t\tnativePrototypes.set(prototype, Object.getOwnPropertyDescriptors(prototype))\n\t\tprototype = Object.getPrototypeOf(prototype)\n\t}\n}\n\n/** Registration-only descriptor preflight; caller accessors are never invoked. */\nfunction preflightNative(table: TableDefinition): void {\n\tconst seen = new Set<object>()\n\tconst active = new Set<object>()\n\t// oxlint-disable-next-line anti-slop/no-object-parameters -- This descriptor-only boundary admits arbitrary native graph nodes without invoking them.\n\tfunction visit(object: object, depth: number, trusted = false): void {\n\t\tif (active.has(object)) throw new Error('Unsupported cyclic native schema')\n\t\tif (seen.has(object)) return\n\t\tif (depth > 64 || seen.size >= 8192) throw new Error('Native schema graph budget exceeded')\n\t\tseen.add(object)\n\t\tactive.add(object)\n\t\tconst prototype = Object.getPrototypeOf(object)\n\t\tconst inherited = prototype && nativePrototypes.get(prototype)\n\t\tif (\n\t\t\tprototype !== null &&\n\t\t\tprototype !== Object.prototype &&\n\t\t\tprototype !== Array.prototype &&\n\t\t\t!inherited\n\t\t)\n\t\t\tthrow new Error('Unsupported native schema prototype')\n\t\tif (Object.getOwnPropertySymbols(object).length)\n\t\t\tthrow new Error('Unsupported native schema symbol')\n\t\tconst keys = Object.getOwnPropertyNames(object)\n\t\tconst values = keys.map((key) => Object.getOwnPropertyDescriptor(object, key)!)\n\t\tif (\n\t\t\t!trusted &&\n\t\t\tvalues.some((property) => !('value' in property) || property.value instanceof Function)\n\t\t)\n\t\t\tthrow new Error('Unsupported native schema accessor or method')\n\t\tif (inherited) {\n\t\t\t// Compare the trusted prototype before any native export can invoke it.\n\t\t\tconst currentKeys = Object.getOwnPropertyNames(prototype)\n\t\t\tif (\n\t\t\t\tcurrentKeys.length !== Object.getOwnPropertyNames(inherited).length ||\n\t\t\t\tcurrentKeys.some((key) => {\n\t\t\t\t\tconst current = Object.getOwnPropertyDescriptor(prototype, key)!\n\t\t\t\t\tconst before = Object.getOwnPropertyDescriptor(inherited, key)?.value\n\t\t\t\t\treturn (\n\t\t\t\t\t\t!before ||\n\t\t\t\t\t\t!Object.is(current.value, before.value) ||\n\t\t\t\t\t\tcurrent.get !== before.get ||\n\t\t\t\t\t\tcurrent.set !== before.set\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported native schema prototype mutation')\n\t\t\tvisit(prototype, depth + 1, true)\n\t\t}\n\t\tif (!trusted)\n\t\t\tfor (const property of values) {\n\t\t\t\tif (property.value !== null && Object(property.value) === property.value)\n\t\t\t\t\tvisit(property.value, depth + 1)\n\t\t\t}\n\t\tactive.delete(object)\n\t}\n\tvisit(table, 0)\n}\n\nfunction nativeTableExport(table: TableDefinition): NativeTableExport {\n\t// SAFETY: Convex exposes export at runtime but strips its internal signature from declarations.\n\treturn (table as TableDefinition & { export(): NativeTableExport }).export()\n}\nfunction nativeJson(validator: GenericValidator): ValidatorJSON {\n\t// SAFETY: native validators expose converter metadata at runtime; Convex strips json from declarations.\n\treturn (validator as GenericValidator & { json: ValidatorJSON }).json\n}\n\nfunction canonicalNative(value: JSONValue): string {\n\tif (Array.isArray(value)) return `[${value.map(canonicalNative).join(',')}]`\n\tif (value !== null && Object(value) === value) {\n\t\t// SAFETY: native JSON contains only JSON objects, arrays and primitives.\n\t\tconst object = value as { [key: string]: JSONValue }\n\t\treturn `{${Object.keys(object)\n\t\t\t.sort()\n\t\t\t.map((key) => `${JSON.stringify(key)}:${canonicalNative(object[key])}`)\n\t\t\t.join(',')}}`\n\t}\n\treturn JSON.stringify(value)\n}\n\nfunction assertNativeValidation(value: JSONValue): void {\n\tif (value === null || Object(value) !== value) return\n\t// SAFETY: native converter metadata contains only JSON containers and primitives.\n\tconst container = value as { [key: string]: JSONValue }\n\tif (container.type === 'any') throw new Error('Unsupported native validation form')\n\tfor (const child of Object.values(container)) assertNativeValidation(child)\n}\n\nfunction assertStoredDocument(\n\ttable: string,\n\tfields: Record<string, GenericValidator>,\n\tdocument: ValidatorJSON,\n): void {\n\tconst { _id, _creationTime, ...stored } = fields\n\tif (\n\t\t!_id ||\n\t\t!_creationTime ||\n\t\tcanonicalNative(nativeJson(_id)) !== canonicalNative(nativeJson(v.id(table))) ||\n\t\tcanonicalNative(nativeJson(_creationTime)) !== canonicalNative(nativeJson(v.number())) ||\n\t\t_id.isOptional !== 'required' ||\n\t\t_creationTime.isOptional !== 'required' ||\n\t\tcanonicalNative(document) !== canonicalNative(nativeJson(v.object(stored)))\n\t)\n\t\tthrow new Error(`Native stored document disagrees with boundary \"${table}\"`)\n}\n\n// Compare against this peer's own built-in accessor, using the intrinsic rather\n// than a caller-provided toString. Older Zod clones retain this accessor even\n// after reading shape, because it caches on the original definition.\nconst objectAccessorSample = z.object({ field: z.string() })\nconst builtinObjectGetters = new Set(\n\t[\n\t\tobjectAccessorSample,\n\t\tobjectAccessorSample.pick({ field: true }),\n\t\tobjectAccessorSample.omit({ field: true }),\n\t\tobjectAccessorSample.extend({ other: z.string() }),\n\t\tobjectAccessorSample.safeExtend({ other: z.string() }),\n\t\tobjectAccessorSample.merge(z.object({ other: z.string() })),\n\t\tobjectAccessorSample.partial(),\n\t\tobjectAccessorSample.required(),\n\t].flatMap((schema) => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(schema._zod.def, 'shape')?.get\n\t\treturn getter ? [Function.prototype.toString.call(getter)] : []\n\t}),\n)\n\n// Stored schemas already passed the native input boundary. Track their graph\n// independently of public DTO admissibility, without running any stored parser.\nconst builtinDefaultGetter = Function.prototype.toString.call(\n\tObject.getOwnPropertyDescriptor(z.string().default('')._zod.def, 'defaultValue')!.get!,\n)\nconst builtinPrefaultGetter = Function.prototype.toString.call(\n\tObject.getOwnPropertyDescriptor(z.string().prefault('')._zod.def, 'defaultValue')!.get!,\n)\n\n/** Registration-only admissibility traversal; never runs a stored parser. */\nfunction preflightSchema(dto: z.ZodType, boundary: 'dto' | 'stored'): void {\n\tconst fallbackDefinitions = new Set<object>()\n\tconst seen = new Set<object>()\n\tconst active = new Set<object>()\n\tconst objectDefinitions = new Set<object>()\n\t// oxlint-disable-next-line anti-slop/no-object-parameters -- Registration must inspect descriptors before trusting a Zod semantic node.\n\tfunction visit(value: object, depth: number): void {\n\t\tif (active.has(value)) throw new Error('Unsupported cyclic DTO schema')\n\t\tif (seen.has(value)) return\n\t\tif (depth > 32 || seen.size >= 4096) throw new Error('DTO schema graph budget exceeded')\n\t\tseen.add(value)\n\t\tactive.add(value)\n\t\ttry {\n\t\t\tconst internals = Object.getOwnPropertyDescriptor(value, '_zod')\n\t\t\tif (internals) {\n\t\t\t\tif (!('value' in internals)) throw new Error('Unsupported DTO schema accessor')\n\t\t\t\tconst definition = Object.getOwnPropertyDescriptor(internals.value, 'def')\n\t\t\t\tif (!definition || !('value' in definition))\n\t\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\t\t\t}\n\t\t\tif (value instanceof z.core.$ZodCheck && !(value instanceof z.core.$ZodType)) {\n\t\t\t\tif (boundary === 'dto' && value._zod.def.check === 'overwrite')\n\t\t\t\t\tthrow new Error('Unsupported DTO overwrite check')\n\t\t\t\tvisit(value._zod.def, depth + 1)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (value instanceof z.core.$ZodType) {\n\t\t\t\t// SAFETY: built-in Zod definitions form a discriminated union.\n\t\t\t\tconst def = (value as z.core.$ZodTypes)._zod.def\n\t\t\t\tif (\n\t\t\t\t\tboundary === 'dto' &&\n\t\t\t\t\t(![\n\t\t\t\t\t\t'object',\n\t\t\t\t\t\t'array',\n\t\t\t\t\t\t'optional',\n\t\t\t\t\t\t'nullable',\n\t\t\t\t\t\t'nonoptional',\n\t\t\t\t\t\t'union',\n\t\t\t\t\t\t'intersection',\n\t\t\t\t\t\t'tuple',\n\t\t\t\t\t\t'record',\n\t\t\t\t\t\t'string',\n\t\t\t\t\t\t'number',\n\t\t\t\t\t\t'boolean',\n\t\t\t\t\t\t'bigint',\n\t\t\t\t\t\t'null',\n\t\t\t\t\t\t'never',\n\t\t\t\t\t\t'custom',\n\t\t\t\t\t\t'literal',\n\t\t\t\t\t\t'enum',\n\t\t\t\t\t].includes(def.type) ||\n\t\t\t\t\t\t('coerce' in def && def.coerce))\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(`Unsupported DTO schema \"${def.type}\"`)\n\t\t\t\tif (boundary === 'stored' && (def.type === 'default' || def.type === 'prefault')) {\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(def, 'defaultValue')\n\t\t\t\t\tif (descriptor?.get) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdescriptor.set ||\n\t\t\t\t\t\t\tFunction.prototype.toString.call(descriptor.get) !==\n\t\t\t\t\t\t\t\t(def.type === 'default' ? builtinDefaultGetter : builtinPrefaultGetter)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error('Unsupported stored schema accessor')\n\t\t\t\t\t\t// Admit only the installed fallback accessor without evaluating it.\n\t\t\t\t\t\tfallbackDefinitions.add(def)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (value instanceof z.ZodUnion) {\n\t\t\t\t\tvisit(value.options, depth + 1)\n\t\t\t\t}\n\t\t\t\tif (def.type === 'object') {\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(def, 'shape')\n\t\t\t\t\tif (descriptor?.get) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdescriptor.set ||\n\t\t\t\t\t\t\t!builtinObjectGetters.has(Function.prototype.toString.call(descriptor.get))\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\t\t\t\t\t\tconst fields = def.shape\n\t\t\t\t\t\tvisit(fields, depth + 1)\n\t\t\t\t\t\tobjectDefinitions.add(def)\n\t\t\t\t\t}\n\t\t\t\t\tif (value instanceof z.ZodObject) {\n\t\t\t\t\t\tconst publicFields = Object.getOwnPropertyDescriptor(value, 'shape')\n\t\t\t\t\t\tif (publicFields && !('value' in publicFields))\n\t\t\t\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\t\t\t\t\t\tvisit(value.shape, depth + 1)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvisit(def, depth + 1)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst keys = Reflect.ownKeys(value)\n\t\t\tconst values = keys.map((key) => Object.getOwnPropertyDescriptor(value, key)!)\n\t\t\tif (\n\t\t\t\tvalues.some(\n\t\t\t\t\t(property, i) =>\n\t\t\t\t\t\t!('value' in property) &&\n\t\t\t\t\t\t!(objectDefinitions.has(value) && keys[i] === 'shape') &&\n\t\t\t\t\t\t!(fallbackDefinitions.has(value) && keys[i] === 'defaultValue'),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error('Unsupported DTO schema accessor')\n\n\t\t\tfor (const property of values) {\n\t\t\t\tif (\n\t\t\t\t\tproperty.value !== null &&\n\t\t\t\t\tObject(property.value) === property.value &&\n\t\t\t\t\t!(property.value instanceof Function)\n\t\t\t\t)\n\t\t\t\t\tvisit(property.value, depth + 1)\n\t\t\t}\n\t\t} finally {\n\t\t\tactive.delete(value)\n\t\t}\n\t}\n\tvisit(dto, 0)\n}\n\nfunction snapshotMetadata(registry: RegistryMetadata): RelationMetadata {\n\tconst tables: Record<string, RelationTableMetadata> = {}\n\tfor (const [name, data] of Object.entries(registry.metadata)) {\n\t\tconst fields: Record<string, RelationFieldMetadata> = {}\n\t\tfor (const [field, validator] of Object.entries(data.fields))\n\t\t\tfields[field] = Object.freeze({\n\t\t\t\tkind: validator.kind,\n\t\t\t\toptional: validator.isOptional === 'optional',\n\t\t\t\tnullable: hasNull(validator),\n\t\t\t\tidTables: Object.freeze(idTables(validator)),\n\t\t\t\tnative: frozenNative(nativeJson(validator)),\n\t\t\t})\n\t\ttables[name] = Object.freeze({\n\t\t\tfieldGroups: data.fieldGroups,\n\t\t\tsearchIndexes: data.searchIndexes,\n\t\t\tfields: Object.freeze(fields),\n\t\t\tvariant: data.branches\n\t\t\t\t? Object.freeze({\n\t\t\t\t\t\tdiscriminator: data.branches.discriminator,\n\t\t\t\t\t\ttags: Object.freeze(Object.keys(data.branches.options)),\n\t\t\t\t\t})\n\t\t\t\t: undefined,\n\t\t\tindexes: Object.freeze(\n\t\t\t\tdata.indexes.map((index) =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tname: index.name,\n\t\t\t\t\t\tfields: Object.freeze([...index.fields]),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\t}\n\treturn Object.freeze({\n\t\ttables: Object.freeze(tables),\n\t\tdeclarations: registry.declarations,\n\t})\n}\nfunction hasNull(validator: GenericValidator): boolean {\n\treturn (\n\t\tvalidator.kind === 'null' || (validator.kind === 'union' && validator.members.some(hasNull))\n\t)\n}\nfunction idTables(validator: GenericValidator): string[] {\n\treturn validator.kind === 'id'\n\t\t? [validator.tableName]\n\t\t: validator.kind === 'union'\n\t\t\t? [...new Set(validator.members.flatMap(idTables))].sort()\n\t\t\t: []\n}\nfunction frozenNative(native: ValidatorJSON): Readonly<ValidatorJSON> {\n\tconst snapshot = structuredClone(native)\n\tconst pending: JSONValue[] = [snapshot]\n\twhile (pending.length) {\n\t\tconst next = pending.pop()!\n\t\tif (Object(next) !== next) continue\n\t\t// SAFETY: native JSON metadata contains ordinary arrays/objects; the boxing test excludes primitives.\n\t\tconst container = next as JSONValue[] | { [key: string]: JSONValue }\n\t\tObject.freeze(container)\n\t\tpending.push(...Object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OAAO,OAAOjF,CAAM,EAC5B,QAASiF,EAAK,SACX,OAAO,OAAO,CACd,cAAeA,EAAK,SAAS,cAC7B,KAAM,OAAO,OAAO,OAAO,KAAKA,EAAK,SAAS,OAAO,CAAC,CACvD,CAAC,EACA,IAAA,GACH,QAAS,OAAO,OACfA,EAAK,QAAQ,IAAK,GACjB,OAAO,OAAO,CACb,KAAM5D,EAAM,KACZ,OAAQ,OAAO,OAAO,CAAC,GAAGA,EAAM,MAAM,CAAC,CACxC,CAAC,CACF,CACD,CACD,CAAC,CACF,CACA,OAAO,OAAO,OAAO,CACpB,OAAQ,OAAO,OAAOhB,CAAM,EAC5B,aAAc8E,EAAS,YACxB,CAAC,CACF,CACA,SAAShC,EAAQ,EAAsC,CACtD,OACCb,EAAU,OAAS,QAAWA,EAAU,OAAS,SAAWA,EAAU,QAAQ,KAAKa,CAAO,CAE5F,CACA,SAAS0I,EAAS,EAAuC,CACxD,OAAOvJ,EAAU,OAAS,KACvB,CAACA,EAAU,SAAS,EACpBA,EAAU,OAAS,QAClB,CAAC,GAAG,IAAI,IAAIA,EAAU,QAAQ,QAAQuJ,CAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EACvD,CAAC,CACN,CACA,SAASC,GAAa,EAAgD,CACrE,IAAMC,EAAW,gBAAgBC,CAAM,EACjC7D,EAAuB,CAAC4D,CAAQ,EACtC,KAAO5D,EAAQ,QAAQ,CACtB,IAAM8D,EAAO9D,EAAQ,IAAI,EACzB,GAAI,OAAO8D,CAAI,IAAMA,EAAM,SAE3B,IAAMrB,EAAYqB,EAClB,OAAO,OAAOrB,CAAS,EACvBzC,EAAQ,KAAK,GAAG,OAAO,OAAOyC,CAAS,CAAC,CACzC,CACA,OAAOmB,CACR"}
|
package/dist/zod-convex.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{sharedNativeValidator as e}from"./querying/shared/contract.mjs";import{zodToConvex 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";function a(a){let o=/* @__PURE__ */ new WeakMap,s=/* @__PURE__ */ new WeakSet;function c(a){if(s.has(a))throw Error(`CYCLIC_FILTER_SCHEMA`);let l=o.get(a);if(l)return l;s.add(a);try{let s,l=e(a);if(l)s=l;else if(a instanceof n.core.$ZodObject)s=r.object(Object.fromEntries(Object.entries(a._zod.def.shape).map(([e,t])=>[e,c(t)])));else if(a instanceof n.core.$ZodArray){let e=c(a._zod.def.element);if(e.isOptional===`optional`)throw Error(`Arrays of optional values are not supported`);s=r.array(e)}else if(a instanceof n.core.$ZodUnion)s=r.union(...a._zod.def.options.map(c));else if(a instanceof n.core.$ZodOptional)s=r.optional(c(a._zod.def.innerType));else if(a instanceof n.core.$ZodNonOptional)s=i(c(a._zod.def.innerType));else if(a instanceof n.core.$ZodNullable){let e=c(a._zod.def.innerType);s=e.isOptional===`optional`?r.optional(r.union(i(e),r.null())):r.union(e,r.null())}else return t(a);return o.set(a,s),s}finally{s.delete(a)}}return c(a)}export{a as zodToConvex};
|
|
2
2
|
//# sourceMappingURL=zod-convex.mjs.map
|
package/dist/zod-convex.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-convex.mjs","names":["helperZodToConvex","zodToConvex$1","zodToConvex","completed","ancestors","convert","node","cached","result","z","v","key","child","inner","vRequired","schema"],"sources":["../src/zod-convex.ts"],"sourcesContent":["import {\n\tzodToConvex as helperZodToConvex,\n\ttype ConvexValidatorFromZod,\n} from 'convex-helpers/server/zod4'\nimport { vRequired } from 'convex-helpers/validators'\nimport { v, type GenericValidator } from 'convex/values'\nimport { z } from 'zod'\n\n/** Convert Zod inputs with the helper's grammar and native ID registry.\n * Repeated filter containers share completed native validators within this call.\n * Other schemas retain the helper's conversion behavior, including its errors.\n */\nexport function zodToConvex<Z extends z.core.$ZodType>(\n\tschema: Z,\n): ConvexValidatorFromZod<Z, 'required'> {\n\tconst completed = new WeakMap<z.core.$ZodType, GenericValidator>()\n\tconst ancestors = new WeakSet<z.core.$ZodType>()\n\n\tfunction convert(node: z.core.$ZodType): GenericValidator {\n\t\tif (ancestors.has(node)) throw new Error('CYCLIC_FILTER_SCHEMA')\n\t\tconst cached = completed.get(node)\n\t\tif (cached) return cached\n\t\tancestors.add(node)\n\t\ttry {\n\t\t\tlet result: GenericValidator\n\t\t\t// Public core definitions work for both standard Zod and Zod Mini.\n\t\t\tif (node instanceof z.core.$ZodObject) {\n\t\t\t\tresult = v.object(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(node._zod.def.shape).map(([key, child]) => [key, convert(child)]),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t} else if (node instanceof z.core.$ZodArray) {\n\t\t\t\tconst inner = convert(node._zod.def.element)\n\t\t\t\tif (inner.isOptional === 'optional') {\n\t\t\t\t\tthrow new Error('Arrays of optional values are not supported')\n\t\t\t\t}\n\t\t\t\tresult = v.array(inner)\n\t\t\t} else if (node instanceof z.core.$ZodUnion) {\n\t\t\t\tresult = v.union(...node._zod.def.options.map(convert))\n\t\t\t} else if (node instanceof z.core.$ZodOptional) {\n\t\t\t\tresult = v.optional(convert(node._zod.def.innerType))\n\t\t\t} else if (node instanceof z.core.$ZodNonOptional) {\n\t\t\t\tresult = vRequired(convert(node._zod.def.innerType))\n\t\t\t} else if (node instanceof z.core.$ZodNullable) {\n\t\t\t\tconst inner = convert(node._zod.def.innerType)\n\t\t\t\tresult =\n\t\t\t\t\tinner.isOptional === 'optional'\n\t\t\t\t\t\t? v.optional(v.union(vRequired(inner), v.null()))\n\t\t\t\t\t\t: v.union(inner, v.null())\n\t\t\t} else {\n\t\t\t\t// Keep arbitrary non-filter schemas and native IDs helper-owned.\n\t\t\t\treturn helperZodToConvex(node)\n\t\t\t}\n\t\t\t// Never publish a partial validator; ancestor cycles fail before reuse.\n\t\t\tcompleted.set(node, result)\n\t\t\treturn result\n\t\t} finally {\n\t\t\tancestors.delete(node)\n\t\t}\n\t}\n\t// SAFETY: handled containers mirror helper conversion; all other nodes delegate\n\t// to that helper, retaining its original input-side validator type relationship.\n\treturn convert(schema) as ConvexValidatorFromZod<Z, 'required'>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"zod-convex.mjs","names":["helperZodToConvex","zodToConvex$1","zodToConvex","completed","ancestors","convert","node","cached","result","shared","sharedNativeValidator","z","v","key","child","inner","vRequired","schema"],"sources":["../src/zod-convex.ts"],"sourcesContent":["import { sharedNativeValidator } from './querying/shared/contract'\nimport {\n\tzodToConvex as helperZodToConvex,\n\ttype ConvexValidatorFromZod,\n} from 'convex-helpers/server/zod4'\nimport { vRequired } from 'convex-helpers/validators'\nimport { v, type GenericValidator } from 'convex/values'\nimport { z } from 'zod'\n\n/** Convert Zod inputs with the helper's grammar and native ID registry.\n * Repeated filter containers share completed native validators within this call.\n * Other schemas retain the helper's conversion behavior, including its errors.\n */\nexport function zodToConvex<Z extends z.core.$ZodType>(\n\tschema: Z,\n): ConvexValidatorFromZod<Z, 'required'> {\n\tconst completed = new WeakMap<z.core.$ZodType, GenericValidator>()\n\tconst ancestors = new WeakSet<z.core.$ZodType>()\n\n\tfunction convert(node: z.core.$ZodType): GenericValidator {\n\t\tif (ancestors.has(node)) throw new Error('CYCLIC_FILTER_SCHEMA')\n\t\tconst cached = completed.get(node)\n\t\tif (cached) return cached\n\t\tancestors.add(node)\n\t\ttry {\n\t\t\tlet result: GenericValidator\n\t\t\t// Public core definitions work for both standard Zod and Zod Mini.\n\t\t\tconst shared = sharedNativeValidator(node)\n\t\t\tif (shared) {\n\t\t\t\tresult = shared\n\t\t\t} else if (node instanceof z.core.$ZodObject) {\n\t\t\t\tresult = v.object(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(node._zod.def.shape).map(([key, child]) => [key, convert(child)]),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t} else if (node instanceof z.core.$ZodArray) {\n\t\t\t\tconst inner = convert(node._zod.def.element)\n\t\t\t\tif (inner.isOptional === 'optional') {\n\t\t\t\t\tthrow new Error('Arrays of optional values are not supported')\n\t\t\t\t}\n\t\t\t\tresult = v.array(inner)\n\t\t\t} else if (node instanceof z.core.$ZodUnion) {\n\t\t\t\tresult = v.union(...node._zod.def.options.map(convert))\n\t\t\t} else if (node instanceof z.core.$ZodOptional) {\n\t\t\t\tresult = v.optional(convert(node._zod.def.innerType))\n\t\t\t} else if (node instanceof z.core.$ZodNonOptional) {\n\t\t\t\tresult = vRequired(convert(node._zod.def.innerType))\n\t\t\t} else if (node instanceof z.core.$ZodNullable) {\n\t\t\t\tconst inner = convert(node._zod.def.innerType)\n\t\t\t\tresult =\n\t\t\t\t\tinner.isOptional === 'optional'\n\t\t\t\t\t\t? v.optional(v.union(vRequired(inner), v.null()))\n\t\t\t\t\t\t: v.union(inner, v.null())\n\t\t\t} else {\n\t\t\t\t// Keep arbitrary non-filter schemas and native IDs helper-owned.\n\t\t\t\treturn helperZodToConvex(node)\n\t\t\t}\n\t\t\t// Never publish a partial validator; ancestor cycles fail before reuse.\n\t\t\tcompleted.set(node, result)\n\t\t\treturn result\n\t\t} finally {\n\t\t\tancestors.delete(node)\n\t\t}\n\t}\n\t// SAFETY: handled containers mirror helper conversion; all other nodes delegate\n\t// to that helper, retaining its original input-side validator type relationship.\n\treturn convert(schema) as ConvexValidatorFromZod<Z, 'required'>\n}\n"],"mappings":"gPAaA,SAAgBE,EACf,EACwC,CACxC,IAAMC,kBAAY,IAAI,QAChBC,kBAAY,IAAI,QAEtB,SAASC,EAAQ,EAAyC,CACzD,GAAID,EAAU,IAAIE,CAAI,EAAG,MAAU,MAAM,sBAAsB,EAC/D,IAAMC,EAASJ,EAAU,IAAIG,CAAI,EACjC,GAAIC,EAAQ,OAAOA,EACnBH,EAAU,IAAIE,CAAI,EAClB,GAAI,CACH,IAAIE,EAEEC,EAASC,EAAsBJ,CAAI,EACzC,GAAIG,EACH,EAASA,OACH,GAAIH,aAA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