{"version":3,"file":"filters.mjs","names":["MAX_FILTER_DEPTH","MAX_FILTER_NODES","MAX_FILTER_IN_VALUES","relationPredicates","variantPredicates","filterGrammars","compactFilters","compactFilterMetadata","entry","schema","relationFilterSchema","options","captured","captureGrammar","grammar","error","UnsupportedFilterCapture","boundedObject","filterNodeSchema","cache","semantic","lazyRelationFilterSchema","restricted","ids","nextId","idOf","id","source","restrict","key","used","names","a","b","result","build","state","depth","existing","states","name","relation","tag","option","paginationGrammar","z","filters","root","cached","predicate","normalizeFilters","children","value","expression","child","scoped","field","scalar","normalizeScalar","target","scalarPredicateFromSchema","equality","ranged","range","existence","optional","boundedFilterSchema","predicates","direct","relations","branch","node","depths","withinFilterBudget","pending","nodes","object","array","prototype","keys","consumed","descriptor","context","operator","expected","definition","expectedCatchall","inst","def","metadata","parse","resolve","payload","ctx","seen","schemas","copy","k","v","checks","check","copied"],"sources":["../../../src/querying/shared/filters.ts"],"sourcesContent":["import { z } from 'zod'\nimport type { FilterAst, FilterScalar, FilterOperator } from './ast'\nexport const MAX_FILTER_DEPTH = 4\nexport const MAX_FILTER_NODES = 256\nexport const MAX_FILTER_IN_VALUES = 100\nexport type FieldSchemas = Record<string, z.ZodType>\nexport type FilterTree =\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| FilterTree[]\n\t| { [key: string]: FilterTree }\n\n// Compose Zod's exported core constructor with its ordinary object initializer.\n// Clones use this constructor again, preserving preflight without replacing the\n// converter-recognized object definition or any native scalar/ID validators.\nconst relationPredicates = new WeakMap<\n\tz.core.$ZodType,\n\t{ cardinality: 'one' | 'many'; target: FilterGrammar }\n>()\nconst variantPredicates = new WeakMap<z.core.$ZodType, NonNullable<FilterGrammar['variants']>>()\nconst filterGrammars = new WeakMap<z.core.$ZodType, FilterGrammar>()\n\nexport interface PaginationValidatorOptions {\n\tvalidator: 'compact'\n}\n\nexport interface FilterBoundaryMetadata {\n\treadonly grammar: FilterGrammar\n\treadonly semantic: z.ZodType\n}\nconst compactFilters = new WeakMap<\n\tz.core.$ZodType,\n\t{\n\t\tmetadata: FilterBoundaryMetadata\n\t\tmatches(): boolean\n\t}\n>()\n\n/** Only constructors created here can carry permission to project a filter. */\nexport function compactFilterMetadata(schema: z.core.$ZodType): FilterBoundaryMetadata | undefined {\n\tconst entry = compactFilters.get(schema)\n\treturn entry?.matches() ? entry.metadata : undefined\n}\n\n/** Each boolean child and relation target expression consumes one of four edges.\n * some/none wrappers and fields namespaces consume nodes, but no extra depth.\n */\nexport interface FilterGrammar {\n\tfields: FieldSchemas\n\tvariants?: { discriminator: string; options: Record<string, FilterGrammar> }\n\trelations: Record<string, { cardinality: 'one' | 'many'; target: FilterGrammar }>\n}\n\nexport function relationFilterSchema(\n\tgrammar: FilterGrammar,\n\tcache = new WeakMap<FilterGrammar, Map<number, z.ZodObject>>(),\n\toptions?: PaginationValidatorOptions,\n): z.ZodType {\n\tif (options?.validator === 'compact') {\n\t\tlet captured: FilterGrammar\n\t\ttry {\n\t\t\tcaptured = captureGrammar(grammar)\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof UnsupportedFilterCapture)) throw error\n\t\t\treturn boundedObject(filterNodeSchema(grammar, 0, cache)._zod.def, grammar)\n\t\t}\n\t\tconst semantic = boundedObject(filterNodeSchema(captured, 0)._zod.def, captured)\n\t\treturn boundedObject(\n\t\t\tfilterNodeSchema(grammar, 0, cache)._zod.def,\n\t\t\tcaptured,\n\t\t\tObject.freeze({ grammar: captured, semantic }),\n\t\t)\n\t}\n\treturn boundedObject(filterNodeSchema(grammar, 0, cache)._zod.def, grammar)\n}\n\n/**\n * The engine's private filter boundary. It accepts exactly what\n * relationFilterSchema(grammar) accepts, but builds relation predicates only for\n * the relations an input names: absent optional relations validate nothing. So\n * a query never reads relation grammars, or their tables, that it does not use.\n */\nexport function lazyRelationFilterSchema(\n\tgrammar: FilterGrammar,\n\tcache = new WeakMap<FilterGrammar, Map<number, z.ZodObject>>(),\n): z.ZodType {\n\tconst restricted = new Map<string, FilterGrammar>()\n\tconst ids = new WeakMap<FilterGrammar, number>()\n\tlet nextId = 0\n\tconst idOf = (source: FilterGrammar) => {\n\t\tlet id = ids.get(source)\n\t\tif (id === undefined) ids.set(source, (id = nextId++))\n\t\treturn id\n\t}\n\t// A restriction is a function of the root grammar and the relation names used\n\t// per grammar, so that flat set is its key: no larger than the input.\n\tfunction restrict(used: Map<FilterGrammar, Set<string>>): FilterGrammar {\n\t\tconst key = JSON.stringify(\n\t\t\t[...used]\n\t\t\t\t.map(([source, names]) => [idOf(source), [...names].sort()] as const)\n\t\t\t\t.sort(([a], [b]) => a - b),\n\t\t)\n\t\tlet result = restricted.get(key)\n\t\tif (!result) {\n\t\t\tresult = build(used, grammar, 0, new Map())\n\t\t\tif (restricted.size >= 256) restricted.clear()\n\t\t\trestricted.set(key, result)\n\t\t}\n\t\treturn result\n\t}\n\t// One restricted grammar per source grammar and depth. filterNodeSchema builds\n\t// no relations at MAX_FILTER_DEPTH, so neither does a restriction; this also\n\t// bounds the walk over a cyclic grammar.\n\tfunction build(\n\t\tused: Map<FilterGrammar, Set<string>>,\n\t\tsource: FilterGrammar,\n\t\tdepth: number,\n\t\tstates: Map<string, FilterGrammar>,\n\t): FilterGrammar {\n\t\tconst state = `${idOf(source)}:${depth}`\n\t\tconst existing = states.get(state)\n\t\tif (existing) return existing\n\t\tconst result: FilterGrammar = { fields: source.fields, relations: {} }\n\t\tstates.set(state, result)\n\t\tif (depth < MAX_FILTER_DEPTH)\n\t\t\tfor (const name of [...(used.get(source) ?? [])].sort()) {\n\t\t\t\tconst relation = source.relations[name]\n\t\t\t\tresult.relations[name] = {\n\t\t\t\t\tcardinality: relation.cardinality,\n\t\t\t\t\ttarget: build(used, relation.target, depth + 1, states),\n\t\t\t\t}\n\t\t\t}\n\t\tif (source.variants)\n\t\t\tresult.variants = {\n\t\t\t\tdiscriminator: source.variants.discriminator,\n\t\t\t\toptions: Object.fromEntries(\n\t\t\t\t\tObject.entries(source.variants.options).map(([tag, option]) => [\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\tbuild(used, option, depth + 1, states),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t}\n\t\treturn result\n\t}\n\tconst scalar = restrict(new Map())\n\treturn boundedObject(filterNodeSchema(scalar, 0, cache)._zod.def, grammar, undefined, (used) =>\n\t\tfilterNodeSchema(restrict(used), 0, cache),\n\t)\n}\n\nexport function paginationGrammar(schema: z.ZodType): FilterGrammar | undefined {\n\tif (!(schema instanceof z.ZodObject)) return undefined\n\tconst filters = schema.shape.filters\n\tif (!(filters instanceof z.ZodOptional)) return undefined\n\tconst root = filters.unwrap()\n\tconst cached = filterGrammars.get(root)\n\tif (cached) return cached\n\tif (!(root instanceof z.ZodObject)) return undefined\n\treturn {\n\t\tfields: root.shape,\n\t\tvariants: variantPredicates.get(root.shape.variant),\n\t\trelations: Object.fromEntries(\n\t\t\tObject.entries(root.shape).flatMap(([name, predicate]) => {\n\t\t\t\t// SAFETY: object shapes contain Zod schemas; metadata only recognizes predicates created by our grammar.\n\t\t\t\tconst relation = relationPredicates.get(predicate as z.core.$ZodType)\n\t\t\t\treturn relation ? [[name, relation]] : []\n\t\t\t}),\n\t\t),\n\t}\n}\nexport function normalizeFilters(value: FilterTree, grammar?: FilterGrammar): FilterAst {\n\tconst children: FilterAst[] = []\n\tif (!value) return { kind: 'and', children }\n\t// SAFETY: the caller parsed a strict filter object; its grammar has no array/primitive expression.\n\tconst expression = value as Record<string, FilterTree>\n\tfor (const [name, predicate] of Object.entries(expression)) {\n\t\tif (predicate === undefined) continue\n\t\tif (name === 'and' || name === 'or') {\n\t\t\t// SAFETY: boolean composition is validated as an array of expressions.\n\t\t\tchildren.push({\n\t\t\t\tkind: name,\n\t\t\t\tchildren: (predicate as FilterTree[]).map((child) => normalizeFilters(child, grammar)),\n\t\t\t})\n\t\t} else if (name === 'variant' && grammar?.variants) {\n\t\t\t// SAFETY: strict branch grammar validates the literal tag and its selected target filters.\n\t\t\tconst scoped = predicate as { tag: string; filters: FilterTree }\n\t\t\tchildren.push({\n\t\t\t\tkind: 'variant',\n\t\t\t\tdiscriminator: grammar.variants.discriminator,\n\t\t\t\ttag: scoped.tag,\n\t\t\t\tchild: normalizeFilters(scoped.filters, grammar.variants.options[scoped.tag]),\n\t\t\t})\n\t\t} else if (name === 'not')\n\t\t\tchildren.push({ kind: 'not', child: normalizeFilters(predicate, grammar) })\n\t\telse if (name === 'fields') {\n\t\t\t// SAFETY: fields is a strict selected scalar namespace.\n\t\t\tfor (const [field, scalar] of Object.entries(predicate as Record<string, FilterTree>))\n\t\t\t\tchildren.push(...normalizeScalar(field, scalar))\n\t\t} else if (grammar?.relations[name]) {\n\t\t\tconst relation = grammar.relations[name]\n\t\t\tif (relation.cardinality === 'one')\n\t\t\t\tchildren.push({\n\t\t\t\t\tkind: 'relation',\n\t\t\t\t\tname,\n\t\t\t\t\tmode: 'one',\n\t\t\t\t\tpredicate: predicate === null ? null : normalizeFilters(predicate, relation.target),\n\t\t\t\t})\n\t\t\telse {\n\t\t\t\t// SAFETY: many predicates validate as exactly one some/none target expression.\n\t\t\t\tconst target = predicate as { some?: FilterTree; none?: FilterTree }\n\t\t\t\tchildren.push({\n\t\t\t\t\tkind: 'relation',\n\t\t\t\t\tname,\n\t\t\t\t\tmode: target.some === undefined ? 'none' : 'some',\n\t\t\t\t\tpredicate: normalizeFilters(target.some ?? target.none, relation.target),\n\t\t\t\t})\n\t\t\t}\n\t\t} else children.push(...normalizeScalar(name, predicate))\n\t}\n\treturn { kind: 'and', children }\n}\nexport function scalarPredicateFromSchema(\n\tscalar: z.ZodType,\n\trange: boolean,\n\toptional: boolean,\n): z.ZodType {\n\tconst equality = z.object({\n\t\teq: scalar.optional(),\n\t\tin: z.array(scalar).max(MAX_FILTER_IN_VALUES).optional(),\n\t})\n\tconst ranged = range\n\t\t? equality.extend({\n\t\t\t\tgt: scalar.optional(),\n\t\t\t\tgte: scalar.optional(),\n\t\t\t\tlt: scalar.optional(),\n\t\t\t\tlte: scalar.optional(),\n\t\t\t})\n\t\t: equality\n\tconst existence = optional ? ranged.extend({ exists: z.boolean().optional() }) : ranged\n\treturn z.union([\n\t\tscalar,\n\t\texistence\n\t\t\t.strict()\n\t\t\t.refine(\n\t\t\t\t(value) => Object.values(value).some((entry) => entry !== undefined),\n\t\t\t\t'At least one operator is required',\n\t\t\t),\n\t])\n}\n\nexport function boundedFilterSchema(\n\tpredicates: FieldSchemas,\n\toptions?: PaginationValidatorOptions,\n): z.ZodType {\n\treturn relationFilterSchema({ fields: predicates, relations: {} }, undefined, options)\n}\n\nfunction filterNodeSchema(\n\tgrammar: FilterGrammar,\n\tdepth: number,\n\tcache = new WeakMap<FilterGrammar, Map<number, z.ZodObject>>(),\n): z.ZodObject {\n\tconst cached = cache.get(grammar)?.get(depth)\n\tif (cached) return cached\n\tconst predicates = grammar.fields\n\tconst direct = Object.fromEntries(\n\t\tObject.entries(predicates).filter(\n\t\t\t([key]) =>\n\t\t\t\t!['and', 'or', 'not', 'fields', ...(grammar.variants ? ['variant'] : [])].includes(key),\n\t\t),\n\t)\n\tconst relations: FieldSchemas = {}\n\tfor (const [name, relation] of Object.entries(grammar.relations)) {\n\t\tif (depth === MAX_FILTER_DEPTH) continue\n\t\tconst target = filterNodeSchema(relation.target, depth + 1, cache)\n\t\trelations[name] = (\n\t\t\trelation.cardinality === 'one'\n\t\t\t\t? target.nullable()\n\t\t\t\t: z.union([z.object({ some: target }).strict(), z.object({ none: target }).strict()])\n\t\t).optional()\n\t\trelationPredicates.set(relations[name], relation)\n\t}\n\tif (grammar.variants && depth < MAX_FILTER_DEPTH) {\n\t\tconst options = Object.entries(grammar.variants.options).map(([tag, branch]) =>\n\t\t\tz.strictObject({ tag: z.literal(tag), filters: filterNodeSchema(branch, depth + 1, cache) }),\n\t\t)\n\t\tif (options.length) {\n\t\t\trelations.variant = z.union(options).optional()\n\t\t\tvariantPredicates.set(relations.variant, grammar.variants)\n\t\t}\n\t}\n\tconst node = z\n\t\t.object({ ...direct, ...relations, fields: z.object(predicates).strict().optional() })\n\t\t.strict()\n\tconst child = depth === MAX_FILTER_DEPTH ? undefined : filterNodeSchema(grammar, depth + 1, cache)\n\tconst result = child\n\t\t? node.extend({\n\t\t\t\tand: z.array(child).min(1).max(MAX_FILTER_NODES).optional(),\n\t\t\t\tor: z.array(child).min(1).max(MAX_FILTER_NODES).optional(),\n\t\t\t\tnot: child.optional(),\n\t\t\t})\n\t\t: node\n\tlet depths = cache.get(grammar)\n\tif (!depths) {\n\t\tdepths = new Map()\n\t\tcache.set(grammar, depths)\n\t}\n\tdepths.set(depth, result)\n\treturn result\n}\n\nfunction withinFilterBudget(\n\tvalue: FilterTree,\n\tgrammar: FilterGrammar,\n\tused?: Map<FilterGrammar, Set<string>>,\n): boolean {\n\ttype Context =\n\t\t| 'expression'\n\t\t| 'fields'\n\t\t| 'predicate'\n\t\t| 'composition'\n\t\t| 'many'\n\t\t| 'variant'\n\t\t| 'value'\n\tinterface Entry {\n\t\tvalue: FilterTree\n\t\tdepth: number\n\t\tcontext: Context\n\t\tgrammar: FilterGrammar\n\t}\n\tconst pending: Entry[] = [{ value, depth: 0, context: 'expression', grammar }]\n\tlet nodes = 0\n\twhile (pending.length) {\n\t\tconst entry = pending.pop()!\n\t\tif (++nodes > MAX_FILTER_NODES || entry.depth > MAX_FILTER_DEPTH) return false\n\t\tif (Object(entry.value) !== entry.value) continue\n\t\t// SAFETY: boxing excludes null and primitives; descriptors below avoid invoking getters.\n\t\tconst object = entry.value as FilterTree[] | Record<string, FilterTree>\n\t\tconst array = Array.isArray(object) ? object : undefined\n\t\tconst prototype = Object.getPrototypeOf(object)\n\t\tif (\n\t\t\tarray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null\n\t\t)\n\t\t\treturn false\n\t\tif (array && array.length + nodes + pending.length > MAX_FILTER_NODES) return false\n\t\tconst keys = Reflect.ownKeys(object)\n\t\tif (\n\t\t\tkeys.length - (array ? 1 : 0) + nodes + pending.length > MAX_FILTER_NODES ||\n\t\t\t(array && keys.length !== array.length + 1)\n\t\t)\n\t\t\treturn false\n\t\tlet consumed: string[]\n\t\tswitch (entry.context) {\n\t\t\tcase 'expression':\n\t\t\t\tconsumed = [\n\t\t\t\t\t...Object.keys(entry.grammar.fields),\n\t\t\t\t\t...Object.keys(entry.grammar.relations),\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...(entry.grammar.variants ? ['variant'] : []),\n\t\t\t\t]\n\t\t\t\tbreak\n\t\t\tcase 'variant':\n\t\t\t\tconsumed = ['tag', 'filters']\n\t\t\t\tbreak\n\t\t\tcase 'fields':\n\t\t\t\tconsumed = Object.keys(entry.grammar.fields)\n\t\t\t\tbreak\n\t\t\tcase 'predicate':\n\t\t\t\tconsumed = ['eq', 'in', 'gt', 'gte', 'lt', 'lte', 'exists']\n\t\t\t\tbreak\n\t\t\tcase 'many':\n\t\t\t\tconsumed = ['some', 'none']\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tconsumed = []\n\t\t}\n\t\tfor (const key of consumed) if (!Object.hasOwn(object, key) && key in object) return false\n\t\tfor (const key of keys) {\n\t\t\tif (array && key === 'length') continue\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(object, key)!\n\t\t\tconst name = String(key)\n\t\t\tif (!descriptor.enumerable || !('value' in descriptor) || name !== key) return false\n\t\t\tif (array && (!/^(0|[1-9]\\d*)$/.test(name) || Number(name) >= array.length)) return false\n\t\t\tlet context: Context = 'value'\n\t\t\tlet depth = entry.depth\n\t\t\tlet target = entry.grammar\n\t\t\tif (entry.context === 'expression') {\n\t\t\t\tcontext = 'predicate'\n\t\t\t\tif (name === 'variant' && entry.grammar.variants) {\n\t\t\t\t\tcontext = 'variant'\n\t\t\t\t\tdepth++\n\t\t\t\t} else if (name === 'fields') context = 'fields'\n\t\t\t\telse if (name === 'and' || name === 'or') {\n\t\t\t\t\tcontext = 'composition'\n\t\t\t\t\tdepth++\n\t\t\t\t} else if (name === 'not') {\n\t\t\t\t\tcontext = 'expression'\n\t\t\t\t\tdepth++\n\t\t\t\t} else if (Object.hasOwn(entry.grammar.relations, name)) {\n\t\t\t\t\tconst relation = entry.grammar.relations[name]\n\t\t\t\t\tcontext = relation.cardinality === 'one' ? 'expression' : 'many'\n\t\t\t\t\ttarget = relation.target\n\t\t\t\t\tdepth++\n\t\t\t\t\tif (used) {\n\t\t\t\t\t\tconst names = used.get(entry.grammar) ?? new Set<string>()\n\t\t\t\t\t\tused.set(entry.grammar, names.add(name))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (entry.context === 'variant' && name === 'filters') {\n\t\t\t\tconst tag = Object.getOwnPropertyDescriptor(object, 'tag')\n\t\t\t\tif (\n\t\t\t\t\t!tag ||\n\t\t\t\t\t!('value' in tag) ||\n\t\t\t\t\t!z.string().safeParse(tag.value).success ||\n\t\t\t\t\t!Object.hasOwn(entry.grammar.variants?.options ?? {}, tag.value)\n\t\t\t\t)\n\t\t\t\t\treturn false\n\t\t\t\tcontext = 'expression'\n\t\t\t\ttarget = entry.grammar.variants!.options[String(tag.value)]\n\t\t\t} else if (entry.context === 'fields') context = 'predicate'\n\t\t\telse if (entry.context === 'composition' || entry.context === 'many') context = 'expression'\n\t\t\tpending.push({ value: descriptor.value, depth, context, grammar: target })\n\t\t}\n\t}\n\treturn true\n}\nfunction normalizeScalar(field: string, predicate: FilterTree): FilterAst[] {\n\tif (predicate === undefined) return []\n\tif (Object(predicate) !== predicate) {\n\t\t// SAFETY: native scalar grammar excludes object/array values and preserves branded ID strings.\n\t\treturn [{ kind: 'scalar', field, operator: 'eq', value: predicate as FilterScalar }]\n\t}\n\t// SAFETY: only selected supported scalar operator objects survive validation.\n\treturn Object.entries(predicate as Record<FilterOperator, FilterScalar | FilterScalar[]>)\n\t\t.filter(([, value]) => value !== undefined)\n\t\t.map(([operator, value]) => ({\n\t\t\tkind: 'scalar',\n\t\t\tfield,\n\t\t\toperator: operator as FilterOperator,\n\t\t\tvalue,\n\t\t}))\n}\n\nfunction boundedObject(\n\tdefinition: z.ZodObject['_zod']['def'],\n\tgrammar: FilterGrammar,\n\tmetadata?: FilterBoundaryMetadata,\n\tresolve?: (used: Map<FilterGrammar, Set<string>>) => z.ZodObject,\n): z.ZodObject {\n\tconst expected = Object.entries(definition.shape)\n\tconst expectedCatchall = definition.catchall\n\tconst BoundedFilterObject = z.core.$constructor<z.ZodObject>(\n\t\t'BoundedFilterObject',\n\t\t(inst, def) => {\n\t\t\tz.ZodObject.init(inst, def)\n\t\t\tfilterGrammars.set(inst, grammar)\n\t\t\t// Clones/refinements retain the generated fields. Shape edits use full conversion.\n\t\t\tif (\n\t\t\t\tmetadata &&\n\t\t\t\tdef.catchall === expectedCatchall &&\n\t\t\t\tObject.keys(def.shape).length === expected.length &&\n\t\t\t\texpected.every(([key, value]) => def.shape[key] === value)\n\t\t\t)\n\t\t\t\tcompactFilters.set(inst, {\n\t\t\t\t\tmetadata,\n\t\t\t\t\tmatches: () =>\n\t\t\t\t\t\tinst._zod.def.catchall === expectedCatchall &&\n\t\t\t\t\t\tObject.keys(inst._zod.def.shape).length === expected.length &&\n\t\t\t\t\t\texpected.every(([key, value]) => inst._zod.def.shape[key] === value),\n\t\t\t\t})\n\t\t\tconst parse = inst._zod.parse\n\t\t\tinst._zod.parse = (payload, ctx) => {\n\t\t\t\tconst used = resolve && new Map<FilterGrammar, Set<string>>()\n\t\t\t\t// SAFETY: layout preflight precedes Zod's value traversal.\n\t\t\t\tif (!withinFilterBudget(payload.value as FilterTree, grammar, used)) {\n\t\t\t\t\tpayload.issues.push({\n\t\t\t\t\t\tcode: 'custom',\n\t\t\t\t\t\tinput: payload.value,\n\t\t\t\t\t\tmessage: 'Unsupported filter layout or depth/node budget exceeded',\n\t\t\t\t\t})\n\t\t\t\t\treturn payload\n\t\t\t\t}\n\t\t\t\t// Validate against the relations this input names; the rest are absent.\n\t\t\t\treturn used ? resolve(used)._zod.run(payload, ctx) : parse(payload, ctx)\n\t\t\t}\n\t\t},\n\t)\n\treturn new BoundedFilterObject(definition)\n}\n\nclass UnsupportedFilterCapture extends Error {}\n\n// Copy the generated schema graph before exposing the public filter. These are\n// generated scalar predicates, not arbitrary storage schemas or consumer hooks.\nfunction captureGrammar(\n\tsource: FilterGrammar,\n\tseen = new WeakMap<FilterGrammar, FilterGrammar>(),\n): FilterGrammar {\n\tconst cached = seen.get(source)\n\tif (cached) return cached\n\tconst schemas = new WeakMap<z.ZodType, z.ZodType>()\n\tfunction copy(schema: z.core.$ZodType): z.ZodType {\n\t\tif (!(schema instanceof z.ZodType)) throw new Error('Expected generated classic filter schema')\n\t\tconst cached = schemas.get(schema)\n\t\tif (cached) return cached\n\t\tlet result: z.ZodType\n\t\tif (schema instanceof z.ZodObject)\n\t\t\tresult = schema.clone({\n\t\t\t\t...schema._zod.def,\n\t\t\t\t// oxlint-disable-next-line anti-slop/no-shape-in-symbol-names -- Installed Zod object definition property.\n\t\t\t\tshape: Object.fromEntries(Object.entries(schema.shape).map(([k, v]) => [k, copy(v)])),\n\t\t\t\tcatchall: schema._zod.def.catchall ? copy(schema._zod.def.catchall) : undefined,\n\t\t\t})\n\t\telse if (schema instanceof z.ZodUnion)\n\t\t\tresult = schema.clone({ ...schema._zod.def, options: schema.options.map(copy) })\n\t\telse if (schema instanceof z.ZodArray)\n\t\t\tresult = schema.clone({ ...schema._zod.def, element: copy(schema.element) })\n\t\telse if (schema instanceof z.ZodOptional)\n\t\t\tresult = schema.clone({ ...schema._zod.def, innerType: copy(schema._zod.def.innerType) })\n\t\telse if (schema instanceof z.ZodNonOptional)\n\t\t\tresult = schema.clone({ ...schema._zod.def, innerType: copy(schema._zod.def.innerType) })\n\t\telse if (schema instanceof z.ZodNullable)\n\t\t\tresult = schema.clone({ ...schema._zod.def, innerType: copy(schema._zod.def.innerType) })\n\t\telse if (schema instanceof z.ZodEnum)\n\t\t\tresult = schema.clone({ ...schema._zod.def, entries: { ...schema._zod.def.entries } })\n\t\telse if (schema instanceof z.ZodLiteral)\n\t\t\tresult = schema.clone({ ...schema._zod.def, values: [...schema._zod.def.values] })\n\t\telse if (\n\t\t\tschema instanceof z.ZodString ||\n\t\t\tschema instanceof z.ZodNumber ||\n\t\t\tschema instanceof z.ZodBigInt ||\n\t\t\tschema instanceof z.ZodBoolean ||\n\t\t\tschema instanceof z.ZodNull ||\n\t\t\tschema instanceof z.ZodNever ||\n\t\t\tschema instanceof z.ZodCustom\n\t\t)\n\t\t\tresult = z.core.clone(schema, { ...schema._zod.def }, { parent: true })\n\t\telse throw new UnsupportedFilterCapture()\n\t\t// Generated membership limits and nonempty-operator refinements must not\n\t\t// share mutable check definitions with the public graph.\n\t\tif (schema._zod.def.checks) {\n\t\t\tconst checks = schema._zod.def.checks.map((check) => {\n\t\t\t\tif (check instanceof z.ZodCustom) {\n\t\t\t\t\tconst copied = copy(check)\n\t\t\t\t\tif (!(copied instanceof z.ZodCustom)) throw new UnsupportedFilterCapture()\n\t\t\t\t\treturn copied\n\t\t\t\t}\n\t\t\t\tif (check instanceof z.core.$ZodCheckMaxLength)\n\t\t\t\t\treturn new z.core.$ZodCheckMaxLength({ ...check._zod.def })\n\t\t\t\tif (check instanceof z.core.$ZodCheckMinLength)\n\t\t\t\t\treturn new z.core.$ZodCheckMinLength({ ...check._zod.def })\n\t\t\t\tthrow new UnsupportedFilterCapture()\n\t\t\t})\n\t\t\tresult = result.clone({ ...result._zod.def, checks })\n\t\t}\n\t\tschemas.set(schema, result)\n\t\treturn result\n\t}\n\tconst result: FilterGrammar = {\n\t\tfields: Object.freeze(\n\t\t\tObject.fromEntries(Object.entries(source.fields).map(([k, v]) => [k, copy(v)])),\n\t\t),\n\t\trelations: {},\n\t}\n\tseen.set(source, result)\n\tresult.relations = Object.freeze(\n\t\tObject.fromEntries(\n\t\t\tObject.entries(source.relations).map(([k, v]) => [\n\t\t\t\tk,\n\t\t\t\tObject.freeze({ cardinality: v.cardinality, target: captureGrammar(v.target, seen) }),\n\t\t\t]),\n\t\t),\n\t)\n\tif (source.variants)\n\t\tresult.variants = Object.freeze({\n\t\t\tdiscriminator: source.variants.discriminator,\n\t\t\toptions: Object.freeze(\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries(source.variants.options).map(([k, v]) => [k, captureGrammar(v, seen)]),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\treturn Object.freeze(result)\n}\n"],"mappings":"wBAEA,MAAaA,EAAmB,EACnBC,EAAmB,IACnBC,EAAuB,IAe9BC,kBAAqB,IAAI,QAIzBC,kBAAoB,IAAI,QACxBC,kBAAiB,IAAI,QAUrBC,kBAAiB,IAAI,QAS3B,SAAgBC,EAAsB,EAA6D,CAClG,IAAMC,EAAQF,EAAe,IAAIG,CAAM,EACvC,OAAOD,GAAO,QAAQ,EAAIA,EAAM,SAAW,IAAA,EAC5C,CAWA,SAAgBE,EACf,EACA,kBAAQ,IAAI,QACZ,EACY,CACZ,GAAIC,GAAS,YAAc,UAAW,CACrC,IAAIC,EACJ,GAAI,CACH,EAAWC,EAAeC,CAAO,CAClC,OAASC,EAAO,CACf,GAAI,EAAEA,aAAiBC,GAA2B,MAAMD,EACxD,OAAOE,EAAcC,EAAiBJ,EAAS,EAAGK,CAAK,CAAC,CAAC,KAAK,IAAKL,CAAO,CAC3E,CACA,IAAMM,EAAWH,EAAcC,EAAiBN,EAAU,CAAC,CAAC,CAAC,KAAK,IAAKA,CAAQ,EAC/E,OAAOK,EACNC,EAAiBJ,EAAS,EAAGK,CAAK,CAAC,CAAC,KAAK,IACzCP,EACA,OAAO,OAAO,CAAE,QAASA,EAAU,UAAS,CAAC,CAC9C,CACD,CACA,OAAOK,EAAcC,EAAiBJ,EAAS,EAAGK,CAAK,CAAC,CAAC,KAAK,IAAKL,CAAO,CAC3E,CAQA,SAAgBO,EACf,EACA,kBAAQ,IAAI,QACA,CACZ,IAAMC,kBAAa,IAAI,IACjBC,kBAAM,IAAI,QACZC,E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