joist-core 2.3.0-next.90 → 2.3.0-next.92

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/build/Tables.cjs CHANGED
@@ -89,7 +89,7 @@ var TableColumn = class extends require_Expr.BaseExpr {
89
89
  this.column = column;
90
90
  this.mgmt = mgmt;
91
91
  }
92
- /** Author.id, Book.author_id, and Comment.parent_author_id use the same Author ID domain. */
92
+ /** Author.id, Book.authorId, and Comment.parentAuthorId use the same Author ID domain. */
93
93
  get outputType() {
94
94
  return this.column.outputType;
95
95
  }
@@ -421,7 +421,7 @@ var PolyReferenceImpl = class {
421
421
  }
422
422
  /** Returns the physical FK expression for one polymorphic target. */
423
423
  componentColumn(comp) {
424
- const descriptor = this.meta.columns[comp.columnName] ?? require_utils.fail(`No physical column ${comp.columnName} on ${this.meta.type}`);
424
+ const descriptor = comp.column;
425
425
  return new EntityColumnImpl(this.meta, descriptor, this.mgmt);
426
426
  }
427
427
  };
@@ -501,7 +501,7 @@ var OneToManyJoinImpl = class extends CollectionJoinImpl {
501
501
  joinEntry(kind, other) {
502
502
  const { field } = this;
503
503
  const otherMeta = getTableMetadata(other);
504
- const descriptor = otherMeta.columns[field.otherColumnName];
504
+ const descriptor = Object.values(otherMeta.columns).find((column) => column.columnName === field.otherColumnName);
505
505
  if (!descriptor) return require_utils.fail(`Cannot join ${getTableMetadata(this.proxy).type}.${field.fieldName} to ${otherMeta.type}: ${field.otherColumnName} is not physically present on ${otherMeta.tableName}; join the base table explicitly`);
506
506
  const on = new EntityColumnImpl(otherMeta, descriptor, other[tableMgmt]).eq(this.proxy.id);
507
507
  const filtered = field.kind === "o2m" ? field.softDeletes !== "include" : field.kind === "lo2m";
@@ -605,7 +605,7 @@ function physicalRelation(meta, key) {
605
605
  const field = [meta, ...require_EntityMetadata.getBaseSelfAndSubMetas(require_EntityMetadata.getBaseMeta(meta))].find((owner) => owner.tableName === meta.tableName && Object.hasOwn(owner.fields, key))?.fields[key];
606
606
  if (!isRelation(field)) return void 0;
607
607
  if (field?.kind === "m2o" || field?.kind === "poly") {
608
- if (!field.serde.columns.every((binding) => meta.columns[binding.columnName] === binding.column)) return void 0;
608
+ if (!field.serde.columns.every((binding) => Object.values(meta.columns).includes(binding.column))) return void 0;
609
609
  return field.kind === "poly" ? {
610
610
  ...field,
611
611
  components: field.components.map((component) => ({
@@ -634,7 +634,7 @@ function tableWhere(mgmt, filter) {
634
634
  "primitive",
635
635
  "enum",
636
636
  "m2o"
637
- ].includes(field.kind) || !field.serde || field.serde.columns.length !== 1 || !field.serde.columns.every((binding) => meta.columns[binding.columnName] === binding.column)) throw new Error(`Unsupported table filter field ${meta.type}.${key}; use an explicit join`);
637
+ ].includes(field.kind) || !field.serde || field.serde.columns.length !== 1 || !field.serde.columns.every((binding) => Object.values(meta.columns).includes(binding.column))) throw new Error(`Unsupported table filter field ${meta.type}.${key}; use an explicit join`);
638
638
  const column = new TableColumn(meta, field.serde.columns[0].column, mgmt);
639
639
  let leaves;
640
640
  if (field.kind === "m2o") {
@@ -1 +1 @@
1
- {"version":3,"file":"Tables.cjs","names":["getMetadata","fail","BaseExpr","kqDot","toIdOf","mapToDb","deferredCondition","buildValueCondition","isExpr","skipCondition","makeLike","groupBy","getConstructorFromTaggedId","maybeResolveReferenceToId","asNode","getBaseAndSelfMetas","getBaseSelfAndSubMetas","getBaseMeta","parseEntityFilter","parseValueFilter","isEntity"],"sources":["../src/Tables.ts"],"sourcesContent":["import { groupBy } from \"joist-utils\";\n\nimport { type Column } from \"./columns.ts\";\nimport { type SqlCondition } from \"./conditions.ts\";\n// Load-order only: without this, the built cjs/esm module graph evaluates relations/* before their\n// base classes exist (\"Class extends value undefined\"); keep it even though no symbol is imported.\nimport \"./configure.ts\";\nimport { buildValueCondition } from \"./drivers/buildUtils.ts\";\nimport { type Entity, isEntity } from \"./Entity.ts\";\nimport { type IdOf, type MaybeAbstractEntityConstructor, type TaggedId } from \"./EntityManager.ts\";\nimport {\n type EntityMetadata,\n type Field,\n type LargeOneToManyField,\n type ManyToManyField,\n type OneToManyField,\n type OneToOneField,\n type PolymorphicField,\n type PolymorphicFieldComponent,\n getBaseAndSelfMetas,\n getBaseMeta,\n getBaseSelfAndSubMetas,\n getMetadata,\n} from \"./EntityMetadata.ts\";\nimport {\n BaseExpr,\n type Expr,\n type ExprContext,\n type ExprLike,\n type InnerJoin,\n type LeftJoin,\n type SqlFragment,\n asNode,\n deferredCondition,\n isExpr,\n} from \"./Expr.ts\";\nimport { getConstructorFromTaggedId, maybeResolveReferenceToId } from \"./index.ts\";\nimport { toIdOf } from \"./keys.ts\";\nimport { kqDot } from \"./keywords.ts\";\nimport { type ParsedValueFilter, makeLike, mapToDb, parseEntityFilter, parseValueFilter } from \"./QueryParser.ts\";\nimport { skipCondition } from \"./skipCondition.ts\";\nimport { type TypeInfo } from \"./TypeInfo.ts\";\nimport { type ColumnsOf, type FieldsOf, type FilterOf, type TypeMap, type TypeNameOf } from \"./typeMap.ts\";\nimport { fail } from \"./utils.ts\";\n\n/** Creates physical column expressions and relationship joins for `T`. */\nexport function table<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>): Table<T>;\n/**\n * Creates a table with an explicit type-level name, i.e. `table(Author, \"m\")` for a self-join.\n *\n * The name is the table's source key in `em.query`: two bare `table(Author)`s share the key `\"Author\"`,\n * so a left-joined mentor would also mark the mentee's columns nullable; a named alias has its own key.\n */\nexport function table<T extends Entity, Name extends string>(\n cstr: MaybeAbstractEntityConstructor<T>,\n name: Name,\n): Table<T, Name>;\nexport function table<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>, _name?: string): Table<T, any> {\n // The name only exists at the type level; the SQL alias is still assigned by the query parser\n return newTableProxy(cstr);\n}\n\n/** Creates multiple physical table handles. */\nexport function tables<T extends readonly MaybeAbstractEntityConstructor<any>[]>(\n ...type: T\n): { [P in keyof T]: T[P] extends MaybeAbstractEntityConstructor<infer E extends Entity> ? Table<E> : never } {\n return type.map((t) => newTableProxy(t)) as any;\n}\n\n/**\n * The runtime management interface plus phantom type information for `em.query`.\n *\n * `__entity` lets `QueryRow` recover `T` for entity mode (you cannot `infer T` back out of a mapped\n * type), and `__name` is the table's source key (see `Expr`).\n */\nexport interface TableBrand<T, Name extends string> extends TableMgmt {\n readonly __entity: T;\n readonly __name: Name;\n}\n\n/**\n * A physical table for `T`: one expression per SQL column, with relationship names as join factories.\n * Selecting the table itself retains entity hydration; selecting columns returns decoded SQL values.\n *\n * Unlike an Alias, a Table is an explicit SQL source, not a place to bind in an em.find relationship\n * tree. I.e. with `a = table(Author)`, `{ from: a }` registers that handle in the query's scope.\n * Its columns already know their physical column and codec, but their SQL name still depends on the\n * query: the same Author handle might be `a` in one query and `a1` in a nested query.\n *\n * Each predicate occurrence renders through ExprContext.aliasFor using the current scope (or an\n * enclosing scope for a correlation). Rendering returns SQL, ordered bindings, and source references\n * together. A comparison records both sides' references; templates and subqueries carry their\n * references too. Join pruning follows these references and join dependencies, rather than guessing\n * which tables a SQL string mentions. It also accounts for select/order/group expressions and keep.\n *\n * I.e. if a joined Author is used only by `a.first_name.eq(name)`, supplying undefined removes that\n * predicate and lets the unused join prune. Both APIs share this undefined-condition pruning rule;\n * they differ in how they get the references: Alias resolves domain conditions against a relationship\n * tree, while Table renders SQL expressions against explicit sources. Neither caches SQL names on\n * the reusable handle or predicate, so one parse cannot overwrite another parse's bindings.\n *\n * `Name` is the table's type-level source key, defaulting to the entity's own type name, so a\n * LEFT-joined SmallPublisher does not make Publisher columns nullable. `table(Author, \"m\")`\n * gives a self-join table its own key.\n */\nexport type Table<T extends Entity, Name extends string = TableNameOf<T>> = TableShape<T, Name> &\n (\"where\" extends keyof TableShape<T, Name>\n ? {}\n : {\n /** Builds an AND condition from local domain fields, without implicit joins. */\n where(filter: TableFilter<T>): SqlCondition;\n });\n\n/** Domain filters for fields stored on this physical table, without relationship traversal. */\nexport type TableFilter<T extends Entity> = {\n [K in LocalFieldNames<T> & keyof FieldsOf<T>]?: FieldsOf<T>[K] extends {\n kind: \"m2o\";\n type: infer U extends Entity;\n nullable: infer N;\n }\n ? TableReferenceFilter<U, N extends undefined ? null : never>\n : FilterOf<T>[K];\n};\n\n/** Generated column ownership excludes CTI base fields and polymorphic components. */\ntype LocalFieldNames<T> = ColumnsOf<T>[keyof ColumnsOf<T>] extends { fieldName: infer F }\n ? Extract<F, keyof FilterOf<T>>\n : never;\n\n/** The owning-reference subset of find filters that only compares a foreign key. */\ntype TableReferenceFilter<T extends Entity, N> =\n | T\n | IdOf<T>\n | readonly (T | IdOf<T>)[]\n | boolean\n | N\n | undefined\n | { ne: T | IdOf<T> | N | undefined };\n\ntype TableShape<T extends Entity, Name extends string> = {\n readonly [tableMgmt]: TableBrand<T, Name>;\n} & {\n [P in keyof ColumnsOf<T>]: P extends \"id\"\n ? EntityColumn<T, never, Name>\n : ColumnsOf<T>[P] extends { entity: infer U extends Entity; nullable: infer N }\n ? ReferenceColumn<U, N extends true ? null : never, Name>\n : ColumnsOf<T>[P] extends { type: infer V; nullable: infer N }\n ? PrimitiveColumn<V, N extends true ? null : never, Name>\n : never;\n} & {\n [\n P in keyof FieldsOf<T> as P extends keyof ColumnsOf<T>\n ? never\n : FieldsOf<T>[P] extends { kind: \"m2o\" | \"poly\" | \"o2m\" | \"lo2m\" | \"m2m\" | \"o2o\" }\n ? P\n : never\n ]: FieldsOf<T>[P] extends { kind: \"m2o\"; type: infer U extends Entity; nullable: infer N }\n ? ReferenceJoin<U, N extends undefined ? null : never>\n : FieldsOf<T>[P] extends { kind: \"poly\"; type: infer U extends Entity; nullable: infer N }\n ? PolyReference<U, N extends undefined ? null : never>\n : FieldsOf<T>[P] extends { kind: \"o2m\" | \"lo2m\" | \"m2m\" | \"o2o\"; type: infer U extends Entity }\n ? CollectionJoin<U>\n : never;\n} & {\n [\n K in keyof TypeMap as TypeMap[K] extends {\n entityType: infer U extends Entity & { __type: { 0: TypeNameOf<T>; 1: string } };\n }\n ? Uncapitalize<TypeNameOf<U> & string>\n : never\n ]: TypeMap[K] extends { entityType: infer U extends Entity } ? SubtypeJoin<U> : never;\n};\n\n/** Keeps explicit base and subtype sources independent, with generic entities untracked. */\ntype TableNameOf<T> = T extends { __type: { 0: string } } ? TypeNameOf<T> & string : string;\n\n/** A relationship join factory, without a selectable FK expression. */\nexport interface ReferenceJoin<U extends Entity, N extends null | never> {\n as<A extends TableFor<U>>(other: A): [N] extends [never] ? InnerJoin<A> : LeftJoin<A>;\n inner<A extends TableFor<U>>(other: A): InnerJoin<A>;\n left<A extends TableFor<U>>(other: A): LeftJoin<A>;\n}\n\n/** Any table whose entity is (a subtype of) `U`, i.e. what a relation join factory accepts. */\nexport type TableFor<U> = { readonly [tableMgmt]: TableBrand<U, string> };\n\n/**\n * A collection relation (o2m/o2o/m2m) as a join factory: `a.books.as(b)` returns the same\n * `{ left: b, on: ... }` entry the expanded form writes, with the FK condition built from metadata, so\n * join-list inference, nullability, scope checking, and pruning are unchanged and both forms mix freely.\n *\n * `as` binds the joined alias, the same way em.find's `{ books: { as: b } }` does. The default is LEFT\n * (a collection may be empty, and a LEFT join never filters rows, so pruning it is always safe);\n * `.inner(b)` opts into filtering. An m2m entry carries a hidden second join through the join table,\n * which the parser expands; the pair prunes together.\n */\nexport interface CollectionJoin<U extends Entity> {\n as<A extends TableFor<U>>(other: A): LeftJoin<A>;\n inner<A extends TableFor<U>>(other: A): InnerJoin<A>;\n left<A extends TableFor<U>>(other: A): LeftJoin<A>;\n}\n\n/** A named subtype join, defaulting to LEFT because a root row may belong to another subtype. */\ninterface SubtypeJoin<U extends Entity> extends CollectionJoin<U> {\n <A extends TableFor<U>>(other: A): LeftJoin<A>;\n}\n\n/**\n * A physical FK column expression (`b.author_id` selects/compares the FK) plus a join factory\n * (`b.author_id.as(a)` joins). The default join kind follows physical column nullability:\n * a NOT NULL FK is INNER, a nullable one is LEFT, and the row type reflects it.\n */\nexport interface ReferenceColumn<U extends Entity, N extends null | never, Src extends string>\n extends EntityColumn<U, N, Src>, ReferenceJoin<U, N> {}\n\n/**\n * A polymorphic reference: condition methods (each resolving the component column from the value), plus\n * a join factory that picks the component from the argument's entity, i.e. `c.parent.as(a)` joins\n * through `parent_author_id`, like an explicit join with `on: c.parent.eq(a.id)`.\n */\nexport interface PolyReference<U extends Entity, N extends null | never> extends ReferenceJoin<U, N> {\n eq(value: U | TaggedId | ExprLike<IdOf<U> | null> | null | undefined): SqlCondition;\n ne(value: U | TaggedId | ExprLike<IdOf<U> | null> | null | undefined): SqlCondition;\n in(values: Array<U | TaggedId> | ExprLike<IdOf<U> | null> | undefined): SqlCondition;\n}\n\nexport interface PrimitiveColumn<V, N extends null | never, Src extends string = string> extends Expr<V | N, Src> {\n eq(value: V | ExprLike<V | N> | N | undefined): SqlCondition;\n ne(value: V | ExprLike<V | N> | N | undefined): SqlCondition;\n in(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition;\n nin(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition;\n gt(value: V | ExprLike<V | N> | undefined): SqlCondition;\n gte(value: V | ExprLike<V | N> | undefined): SqlCondition;\n lt(value: V | ExprLike<V | N> | undefined): SqlCondition;\n lte(value: V | ExprLike<V | N> | undefined): SqlCondition;\n like(value: V | undefined): SqlCondition;\n ilike(value: V | undefined): SqlCondition;\n search(value: V | undefined): SqlCondition;\n between(v1: V | undefined, v2: V | undefined): SqlCondition;\n // need to move to ArrayColumn\n // ...added the `string` to support jsonb contains like `WHERE profile @> '{\"age\": 25}'`\n // Ideally this would go in a JsonbColumn\n contains(value: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n ncontains(value: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n overlaps(value: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n noverlaps(value: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n\n /**\n * Adds a JSON path existence condition, using the `@?` operator.\n *\n * Any values should be embedded directly within the `jsonPath`, because postgres does not\n * support parameterized JSON path expressions. The entire `jsonPath` is treated as a parameter,\n * so this is safe from SQL injection.\n */\n pathExists(jsonPath: string | undefined): SqlCondition;\n\n /**\n * Adds a JSON path predicate condition, using the `@@` operator.\n *\n * Any values should be embedded directly within the `jsonPath`, because postgres does not\n * support parameterized JSON path expressions. The entire `jsonPath` is treated as a parameter,\n * so this is safe from SQL injection.\n */\n pathIsTrue(jsonPath: string | undefined): SqlCondition;\n\n /**\n * Add `exp` to the query, which should include the operator & expression and any\n * bound parameters (but not include the column name).\n *\n * We use knex-style placeholders, i.e. `?` and `\\\\?` to escape question marks, i.e.\n *\n * ```ts\n * a.address.raw(\"@\\\\? ?\", ['$.street ? (@ == \"rr2\")'])`\n * ```\n */\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition;\n}\n\nexport interface EntityColumn<T, N extends null | never = never, Src extends string = string> extends Expr<\n IdOf<T> | N,\n Src\n> {\n eq(value: T | IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n ne(value: T | IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n // Adding `| null` for GraphQL support\n in(value: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n nin(value: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n gt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n gte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n lt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n lte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition;\n}\n\nexport const tableMgmt = Symbol(\"tableMgmt\");\n\nexport function getTableMgmt(table: TableFor<unknown>): TableMgmt {\n return table[tableMgmt];\n}\n\n/** The identity SQL queries bind a table by, plus its original entity metadata. */\nexport interface TableMgmt {\n tableName: string;\n /**\n * The metadata this table was created with, i.e. `table(TaskNew)` keeps `taskNewMeta`.\n *\n * It cannot be re-derived from `tableName`: STI subtypes share their base's table (`Task`, `TaskNew`,\n * and `TaskOld` are all `tasks`), so a `getMetadataForTable(\"tasks\")` lookup can only return the base\n * `Task`, and the alias would lose its subtype identity for explicit subtype joins and entity hydration.\n */\n meta: EntityMetadata;\n}\n\n/** Returns the metadata for the entity that `table` is bound to. */\nexport function getTableMetadata<T extends Entity>(table: TableFor<T>): EntityMetadata<T> {\n const mgmt = table[tableMgmt];\n return mgmt.meta as EntityMetadata<T>;\n}\n\nexport function newTableProxy<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>): Table<T> {\n const meta = getMetadata(cstr);\n // The identity SQL queries bind to a source, retaining STI subtype metadata.\n const mgmt: TableMgmt = { tableName: meta.tableName, meta };\n const subtypes = new Map(meta.subTypes.map((m) => [m.type[0].toLowerCase() + m.type.slice(1), m]));\n const proxy: any = new Proxy(cstr, {\n /** Create a physical column expression or a relation join factory. */\n get(_, key: PropertyKey): any {\n if (key === tableMgmt) {\n return mgmt;\n }\n if (typeof key !== \"string\") return undefined;\n const descriptor = Object.hasOwn(meta.columns, key) ? meta.columns[key] : undefined;\n if (descriptor) {\n return descriptor.idMetadata && key !== \"id\"\n ? new EntityColumnImpl(meta, descriptor, mgmt)\n : new PrimitiveColumnImpl(meta, descriptor, mgmt);\n }\n const subtype = subtypes.get(key);\n if (subtype) {\n const join = new SubtypeJoinImpl(proxy, subtype);\n return Object.assign(join.as.bind(join), {\n as: join.as.bind(join),\n inner: join.inner.bind(join),\n left: join.left.bind(join),\n });\n }\n const relation = physicalRelation(meta, key);\n if (key === \"where\" && !isRelation(meta.allFields[key])) {\n return (filter: TableFilter<T>) => tableWhere(mgmt, filter);\n }\n const field = relation ?? fail(`No physical field ${key} on ${cstr.name}; join its base table explicitly`);\n switch (field.kind) {\n case \"m2o\":\n return new ReferenceJoinImpl(new EntityColumnImpl(meta, field.serde.columns[0].column, mgmt));\n case \"poly\":\n return new PolyReferenceImpl(meta, mgmt, field);\n case \"o2m\":\n case \"o2o\":\n case \"lo2m\":\n return new OneToManyJoinImpl(proxy, field);\n case \"m2m\":\n return new ManyToManyJoinImpl(proxy, field);\n default:\n throw new Error(`Unsupported table field kind ${field.kind}`);\n }\n },\n\n has(_, key) {\n return (\n key === tableMgmt ||\n (typeof key === \"string\" &&\n (key === \"where\" || Object.hasOwn(meta.columns, key) || !!physicalRelation(meta, key) || subtypes.has(key)))\n );\n },\n });\n return proxy;\n}\n\nexport function isTable(obj: unknown): obj is Table<any, any> {\n // Oddly enough `typeof` will be a function b/c we are proxying the constructors\n return typeof obj === \"function\" && tableMgmt in obj;\n}\n\n/**\n * A physical table column implements `Expr`: it renders as `alias.\"column\"`, decodes result\n * values through the column's shared scalar codec, and inherits aggregate methods from `BaseExpr`.\n */\nclass TableColumn extends BaseExpr {\n public constructor(\n readonly meta: EntityMetadata,\n readonly column: Column,\n readonly mgmt: TableMgmt,\n ) {\n super();\n }\n\n /** Author.id, Book.author_id, and Comment.parent_author_id use the same Author ID domain. */\n get outputType(): TypeInfo | undefined {\n return this.column.outputType;\n }\n\n get sqlNullable(): boolean | undefined {\n return this.column.sqlNullable;\n }\n\n get sqlSource(): object {\n return this.mgmt;\n }\n\n toSql(ctx: ExprContext): SqlFragment {\n const alias = ctx.aliasFor(this.mgmt);\n return { sql: kqDot(alias, this.column.columnName), bindings: [], refs: [alias] };\n }\n\n /** Decodes result-set values with public PK/FK ids, while hydration keeps internal tagged ids. */\n decode(value: unknown): unknown {\n if (value === null || value === undefined) return value;\n const idMeta = this.idMetadata;\n if (idMeta) return toIdOf(idMeta, this.column.mapFromDb(value) as TaggedId | undefined);\n return this.column.mapFromDb(value);\n }\n\n encode(value: unknown): unknown {\n return this.column.mapToDb(value);\n }\n\n /** Identifies the ID domain of a primary key, FK, or physical polymorphic component. */\n get idMetadata(): EntityMetadata | undefined {\n return this.column.idMetadata?.();\n }\n\n /** Encodes literals when the condition is created and renders with each query's aliases. */\n addCondition(value: ParsedValueFilter<unknown>): SqlCondition {\n const encoded = mapToDb(this.column, value);\n return deferredCondition((ctx) => {\n const left = this.toSql(ctx);\n const [sql, bindings] = buildValueCondition(left.sql, encoded);\n return { sql, bindings: [...left.bindings, ...bindings], refs: left.refs };\n });\n }\n\n /** Renders raw operators against the same quoted column SQL as other expressions. */\n protected addRawCondition(exp: string, bindings: readonly any[]): SqlCondition {\n return deferredCondition((ctx) => {\n const left = this.toSql(ctx);\n return { sql: `${left.sql} ${exp}`, bindings: [...left.bindings, ...bindings], refs: left.refs };\n });\n }\n\n /** Uses column filter conversions for literals and shared comparisons for expressions and null equality. */\n protected compare(op: string, value: unknown): SqlCondition {\n if (value === undefined || isExpr(value) || (value === null && (op === \"=\" || op === \"!=\"))) {\n return super.compare(op, value);\n }\n // Primitive relational comparisons historically bind null through mapToDb.\n const kind = ({ \"=\": \"eq\", \"!=\": \"ne\", \">\": \"gt\", \">=\": \"gte\", \"<\": \"lt\", \"<=\": \"lte\" } as const)[op];\n if (!kind) return fail(`Invalid operator ${op}`);\n return this.addCondition({ kind, value });\n }\n\n /**\n * Compares this column to another expression.\n *\n * Table columns, aggregates, subquery columns, and `sql` templates use the expression context\n * to render their complete SQL.\n * Negated array operators wrap the complete comparison in NOT.\n */\n protected compareToExpr(op: string, value: ExprLike<any>, negate = false): SqlCondition {\n if (negate) {\n return deferredCondition((ctx) => {\n const comparison = ctx.conditionToSql(this.compareToExpr(op, value))!;\n return { ...comparison, sql: `NOT (${comparison.sql})` };\n });\n }\n return super.compare(op, value);\n }\n}\n\nclass PrimitiveColumnImpl<V, N extends null | never> extends TableColumn implements PrimitiveColumn<V, N> {\n between(v1: V | undefined, v2: V | undefined): SqlCondition {\n if (v1 === undefined || v2 === undefined) return skipCondition;\n return this.addCondition({ kind: \"between\", value: [v1, v2] });\n }\n\n like(value: V | undefined): SqlCondition {\n if (value === undefined) return skipCondition;\n return this.addCondition({ kind: \"like\", value });\n }\n\n ilike(value: V | undefined): SqlCondition {\n if (value === undefined) return skipCondition;\n return this.addCondition({ kind: \"ilike\", value });\n }\n\n search(value: V | undefined): SqlCondition {\n // Check !value so that empty strings are pruned\n if (!value) return skipCondition;\n return this.addCondition({ kind: \"ilike\", value: makeLike(value) });\n }\n\n in(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition {\n if (values === undefined) return skipCondition;\n if (isExpr(values)) return this.inList(\"IN\", values);\n if (values.includes(null)) {\n const isNull = this.addCondition({ kind: \"is-null\" });\n const hasValue = this.addCondition({ kind: \"in\", value: values.filter((v) => v !== null) });\n return { or: [isNull, hasValue] };\n } else {\n return this.addCondition({ kind: \"in\", value: values as V[] });\n }\n }\n\n nin(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition {\n if (values === undefined) return skipCondition;\n if (isExpr(values)) return this.inList(\"NOT IN\", values);\n return this.addCondition({ kind: \"nin\", value: values.filter((v) => v !== null) as V[] });\n }\n\n // V will already be an array\n contains(v1: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"@>\", v1);\n return this.addCondition({ kind: \"contains\", value: v1 as any });\n }\n\n // V will already be an array\n ncontains(v1: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"@>\", v1, true);\n return this.addCondition({ kind: \"ncontains\", value: v1 as any });\n }\n\n // V will already be an array\n overlaps(v1: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"&&\", v1);\n return this.addCondition({ kind: \"overlaps\", value: v1 as any });\n }\n\n noverlaps(v1: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"&&\", v1, true);\n return this.addCondition({ kind: \"noverlaps\", value: v1 as any });\n }\n\n pathExists(jsonPath: string | undefined): SqlCondition {\n if (jsonPath === undefined) return skipCondition;\n return this.addCondition({ kind: \"jsonPathExists\", value: jsonPath });\n }\n\n pathIsTrue(jsonPath: string | undefined): SqlCondition {\n if (jsonPath === undefined) return skipCondition;\n return this.addCondition({ kind: \"jsonPathPredicate\", value: jsonPath });\n }\n\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition {\n if (bindings === undefined) return skipCondition;\n return this.addRawCondition(exp, bindings);\n }\n}\n\nclass EntityColumnImpl<T> extends TableColumn implements EntityColumn<T> {\n in(values: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n if (values === undefined) {\n return skipCondition;\n } else if (values === null) {\n throw new Error(\"Unsupported\");\n } else if (isExpr(values)) {\n return this.inList(\"IN\", values);\n } else if (values.includes(null)) {\n // Like `PrimitiveColumn.in`, split `[a1, null]` into `IS NULL OR IN (...)`\n const isNull = this.addCondition({ kind: \"is-null\" });\n const hasValue = this.addCondition({ kind: \"in\", value: values.filter((v) => v !== null) as any });\n return { or: [isNull, hasValue] };\n } else {\n return this.addCondition({ kind: \"in\", value: values as any });\n }\n }\n\n nin(values: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n if (values === undefined) {\n return skipCondition;\n } else if (values === null) {\n throw new Error(\"Unsupported\");\n } else if (isExpr(values)) {\n return this.inList(\"NOT IN\", values);\n } else {\n return this.addCondition({ kind: \"nin\", value: values.filter((v) => v !== null) as any });\n }\n }\n\n gt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\">\", \"gt\", value);\n }\n\n gte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\">=\", \"gte\", value);\n }\n\n lt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\"<\", \"lt\", value);\n }\n\n lte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\"<=\", \"lte\", value);\n }\n\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition {\n if (bindings === undefined) return skipCondition;\n return this.addRawCondition(exp, bindings);\n }\n\n /** Joins `other` via this FK, INNER for a required reference and LEFT for a nullable one. */\n as(other: object): object {\n return this.joinEntry(this.sqlNullable === false ? \"inner\" : \"left\", other);\n }\n\n inner(other: object): object {\n return this.joinEntry(\"inner\", other);\n }\n\n left(other: object): object {\n return this.joinEntry(\"left\", other);\n }\n\n private joinEntry(kind: JoinKind, other: object): object {\n return { [kind]: requireTable(other), on: this.eq(idColumnOf(other)) };\n }\n\n private compareId(op: string, kind: \"gt\" | \"gte\" | \"lt\" | \"lte\", value: unknown): SqlCondition {\n if (value === undefined) return skipCondition;\n if (value === null) throw new Error(\"Unsupported\");\n if (isExpr(value)) return this.compareToExpr(op, value);\n return this.addCondition({ kind, value: value as any });\n }\n}\n\nclass PolyReferenceImpl<T extends Entity> {\n public constructor(\n private meta: EntityMetadata,\n private mgmt: TableMgmt,\n private field: PolymorphicField,\n ) {}\n\n /** Compares to a tagged id, an entity, or another table's id column, which picks the component (`c.parent.eq(a.id)`). */\n eq(value: T | TaggedId | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.addEqOrNe(\"eq\", value);\n }\n\n ne(value: T | TaggedId | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.addEqOrNe(\"ne\", value);\n }\n\n // We required tagged ids for polys\n in(values: Array<T | TaggedId> | ExprLike<IdOf<T> | null> | undefined): SqlCondition {\n if (values === undefined) return skipCondition;\n if (isExpr(values)) return this.inSubquery(values);\n // Split up the ids by constructor\n const idsByConstructor = groupBy(values, (id) => getConstructorFromTaggedId(maybeResolveReferenceToId(id)!).name);\n // Or together `parent_book_id in (1,2,3) OR parent_author_id IN (4,5,6)`\n return {\n or: Object.entries(idsByConstructor).map(([cstrName, ids]) => {\n const comp =\n this.field.components.find((p) => p.otherMetadata().cstr.name === cstrName) ??\n fail(`No component for ${cstrName}`);\n return this.componentColumn(comp).addCondition({ kind: \"in\", value: ids });\n }),\n };\n }\n\n /** Joins `other` via this poly's component for its entity, INNER when the poly is required. */\n as(other: object): object {\n return this.joinEntry(this.field.required ? \"inner\" : \"left\", other);\n }\n\n inner(other: object): object {\n return this.joinEntry(\"inner\", other);\n }\n\n left(other: object): object {\n return this.joinEntry(\"left\", other);\n }\n\n private joinEntry(kind: JoinKind, other: object): object {\n return { [kind]: requireTable(other), on: this.eq(idColumnOf(other) as any) };\n }\n\n /**\n * i.e. `c.parent.in(query({ from: a, ..., select: a.id }))`: like `eq` against a table column, the\n * subquery's agreed ID domain picks the component, i.e. authors pick `parent_author_id`.\n */\n private inSubquery(values: ExprLike<any>): SqlCondition {\n // Only actual subqueries expose this getter; importing query.ts would create a load-order cycle.\n const selected = asNode(values).subquerySelect;\n const outputType = selected?.outputType;\n let otherMeta = outputType?.idMeta;\n if (!otherMeta) {\n // Ordinary reads can select an unknown key serde. Compounds validate codecs before exposing a select.\n if (!outputType && selected instanceof TableColumn) {\n otherMeta = selected.idMetadata;\n }\n if (!otherMeta) {\n return fail(\n selected instanceof TableColumn\n ? `${this.field.fieldName} \\`in\\` needs an id or FK column, got ${selected.column.columnName}`\n : `${this.field.fieldName} is polymorphic, so \\`in\\` needs a subquery selecting an id or FK column`,\n );\n }\n }\n const comp =\n this.field.components.find((p) => getBaseAndSelfMetas(otherMeta).includes(p.otherMetadata())) ??\n fail(`${this.field.fieldName} has no component for ${otherMeta.type}`);\n return this.componentColumn(comp).in(values);\n }\n\n private addEqOrNe(\n kind: \"eq\" | \"ne\",\n value: T | TaggedId | ExprLike<IdOf<T> | null> | null | undefined,\n ): SqlCondition {\n if (value === undefined) {\n return skipCondition;\n } else if (value instanceof TableColumn) {\n // Joining through the poly, i.e. `c.parent.eq(a.id)`: the other table column's ID domain picks the component\n const otherMeta = value.idMetadata ?? fail(`${this.field.fieldName} needs an id or FK column`);\n const comp =\n this.field.components.find((p) => getBaseAndSelfMetas(otherMeta).includes(p.otherMetadata())) ??\n fail(`${this.field.fieldName} has no component for ${otherMeta.type}`);\n return this.componentColumn(comp)[kind](value);\n } else if (isExpr(value)) {\n return fail(\n `${this.field.fieldName} is polymorphic, so it can only be compared to tagged ids or entity table columns`,\n );\n } else if (value === null) {\n // We can AND each of the components as many conditions\n const value = kind === \"eq\" ? ({ kind: \"is-null\" } as const) : ({ kind: \"not-null\" } as const);\n return {\n and: this.field.components.map((p) => this.componentColumn(p).addCondition(value)),\n };\n } else {\n // If we have a value, we can find the component\n const comp =\n this.field.components.find(\n (p) => p.otherMetadata().cstr === getConstructorFromTaggedId(maybeResolveReferenceToId(value) as string),\n ) || fail(`Could not find component for ${value}`);\n return this.componentColumn(comp)[kind](value);\n }\n }\n\n /** Returns the physical FK expression for one polymorphic target. */\n private componentColumn(comp: PolymorphicFieldComponent): EntityColumnImpl<T> {\n const descriptor =\n this.meta.columns[comp.columnName] ?? fail(`No physical column ${comp.columnName} on ${this.meta.type}`);\n return new EntityColumnImpl<T>(this.meta, descriptor, this.mgmt);\n }\n}\n\n/**\n * Marks a sugar join entry whose target is a *collection* (o2m/m2m), which filter soft-deletes like\n * em.find's \"collections filter out soft-deletes, but m2o/o2o references still return them\"; see\n * `QueryParser.addSoftDeleteCondition`'s call site. Reference joins and explicit joins are unmarked.\n */\nexport const collectionJoin: unique symbol = Symbol(\"joist.collectionJoin\");\n\n/** Marks a sugar m2m join entry (`a.tags.as(t)`) with its hidden join-table join; `parseQuery` expands it. */\nexport const m2mJoinTable: unique symbol = Symbol(\"joist.m2mJoinTable\");\n\nexport interface M2mJoinTable {\n handle: JoinTableHandle;\n on: SqlCondition;\n}\n\n/** The runtime identity of an m2m join table in a query, i.e. `authors_to_tags`; it has no entity. */\nexport class JoinTableHandle {\n constructor(readonly joinTableName: string) {}\n}\n\ntype JoinKind = \"inner\" | \"left\";\n\n/**\n * The `as`/`inner`/`left` join factory for collection relations, i.e. `a.books.as(b)` joins with the\n * relation's default kind (LEFT: a collection may be empty) and `.inner`/`.left` override. m2o/poly\n * relations implement the same three methods on their join factories. Physical FKs such as\n * `b.author_id` are expressions that also expose a join factory.\n */\nabstract class CollectionJoinImpl {\n as(other: object): object {\n return this.joinEntry(\"left\", requireTable(other));\n }\n\n inner(other: object): object {\n return this.joinEntry(\"inner\", requireTable(other));\n }\n\n left(other: object): object {\n return this.joinEntry(\"left\", requireTable(other));\n }\n\n protected abstract joinEntry(kind: JoinKind, other: TableFor<Entity>): object;\n}\n\n/** Joins a named subtype explicitly; only STI subtype sugar adds a discriminator to its ON. */\nclass SubtypeJoinImpl extends CollectionJoinImpl {\n constructor(\n private proxy: TableFor<Entity>,\n private subtype: EntityMetadata,\n ) {\n super();\n }\n\n protected joinEntry(kind: JoinKind, other: TableFor<Entity>): object {\n if (getTableMetadata(other) !== this.subtype) {\n return fail(`Expected table(${this.subtype.type}) for the explicit subtype join`);\n }\n const on = idColumnOf(this.proxy).eq(idColumnOf(other));\n if (this.subtype.inheritanceType !== \"sti\" || this.subtype.stiDiscriminatorValue === undefined) {\n return { [kind]: other, on };\n }\n const base = this.subtype.baseTypes.find((m) => m.stiDiscriminatorField !== undefined)!;\n const columnName = base.fields[base.stiDiscriminatorField!].serde!.columns[0].columnName;\n // Discriminator values are database enum ids, not domain enum values to pass through the field codec.\n const discriminator = deferredCondition((ctx) => {\n const alias = ctx.aliasFor(other[tableMgmt]);\n return {\n sql: `${kqDot(alias, columnName)} = ?`,\n bindings: [this.subtype.stiDiscriminatorValue],\n refs: [alias],\n };\n });\n return { [kind]: other, on: { and: [on, discriminator] } };\n }\n}\n\n/** An o2m/lo2m/o2o relation: the ON is the other side's FK (an m2o or a poly component) back to our id. */\nclass OneToManyJoinImpl extends CollectionJoinImpl {\n constructor(\n private proxy: any,\n private field: OneToManyField | LargeOneToManyField | OneToOneField,\n ) {\n super();\n }\n\n protected joinEntry(kind: JoinKind, other: TableFor<Entity>): object {\n const { field } = this;\n const otherMeta = getTableMetadata(other);\n const descriptor = otherMeta.columns[field.otherColumnName];\n if (!descriptor) {\n return fail(\n `Cannot join ${getTableMetadata(this.proxy).type}.${field.fieldName} to ${otherMeta.type}: ` +\n `${field.otherColumnName} is not physically present on ${otherMeta.tableName}; join the base table explicitly`,\n );\n }\n const column = new EntityColumnImpl(otherMeta, descriptor, other[tableMgmt]);\n const on = column.eq(this.proxy.id);\n // Collections (o2m/lo2m) filter soft-deletes like em.find; o2o references resolve them\n const filtered = field.kind === \"o2m\" ? field.softDeletes !== \"include\" : field.kind === \"lo2m\";\n return { [kind]: other, on, [collectionJoin]: filtered };\n }\n}\n\n/**\n * An m2m relation, i.e. `a.tags.as(t)`.\n *\n * The entry's own ON is `t.id = att.tag_id`, and the hidden `[m2mJoinTable]` half is\n * `att.author_id = a.id`; only the target's ON references the join table, so reference pruning keeps\n * or drops the pair together. Both are deferred conditions: the join table has no entity metadata, so\n * its alias only exists once the parser registers it.\n */\nclass ManyToManyJoinImpl extends CollectionJoinImpl {\n constructor(\n private proxy: any,\n private field: ManyToManyField,\n ) {\n super();\n }\n\n protected joinEntry(kind: JoinKind, other: TableFor<Entity>): object {\n const { joinTableName, columnNames } = this.field;\n const [ourColumn, otherColumn] = columnNames;\n const jt = new JoinTableHandle(joinTableName);\n const ourId = idColumnOf(this.proxy);\n const otherId = idColumnOf(other);\n const jtOn = deferredCondition((ctx) => {\n const jtAlias = ctx.aliasFor(jt);\n const id = ourId.toSql(ctx);\n return { sql: `${kqDot(jtAlias, ourColumn)} = ${id.sql}`, bindings: id.bindings, refs: id.refs };\n });\n const on = deferredCondition((ctx) => {\n const jtAlias = ctx.aliasFor(jt);\n const id = otherId.toSql(ctx);\n return { sql: `${id.sql} = ${kqDot(jtAlias, otherColumn)}`, bindings: id.bindings, refs: [...id.refs, jtAlias] };\n });\n const filtered = this.field.softDeletes !== \"include\";\n return {\n [kind]: other,\n on,\n [collectionJoin]: filtered,\n [m2mJoinTable]: { handle: jt, on: jtOn } satisfies M2mJoinTable,\n };\n }\n}\n\n/** Fails fast when a join factory is passed something other than a table. */\nfunction requireTable(other: object): TableFor<Entity> {\n if (!isTable(other)) return fail(`Expected a table to join, got ${other}`);\n return other;\n}\n\n/** The id column of a joined table, for building sugar ON conditions. */\nfunction idColumnOf(other: object): TableColumn {\n return (other as any).id;\n}\n\n/** Keeps relation names join-only; physical FK columns retain expression methods. */\nclass ReferenceJoinImpl {\n constructor(private column: EntityColumnImpl<unknown>) {}\n\n as(other: object): object {\n return this.column.sqlNullable === false ? this.column.inner(other) : this.column.left(other);\n }\n\n inner(other: object): object {\n return this.column.inner(other);\n }\n\n left(other: object): object {\n return this.column.left(other);\n }\n}\n\n/** Identifies domain relationship keys exposed alongside physical columns. */\nfunction isRelation(field: Field | undefined): boolean {\n return field !== undefined && [\"m2o\", \"poly\", \"o2m\", \"lo2m\", \"m2m\", \"o2o\"].includes(field.kind);\n}\n\n/** Resolves relationship sugar only from domain fields owned by this physical table. */\nfunction physicalRelation(meta: EntityMetadata, key: string): Field | undefined {\n const owners = [meta, ...getBaseSelfAndSubMetas(getBaseMeta(meta))];\n const owner = owners.find((owner) => owner.tableName === meta.tableName && Object.hasOwn(owner.fields, key));\n const field = owner?.fields[key];\n if (!isRelation(field)) return undefined;\n // I.e. TaskNew.copiedFrom uses Task's original FK domain, not its specialized TaskNew target.\n if (field?.kind === \"m2o\" || field?.kind === \"poly\") {\n if (!field.serde.columns.every((binding) => meta.columns[binding.columnName] === binding.column)) return undefined;\n return field.kind === \"poly\"\n ? {\n ...field,\n components: field.components.map((component) => ({\n column: component.column,\n columnName: component.columnName,\n otherFieldName: component.otherFieldName,\n otherMetadata: component.column.idMetadata!,\n })),\n }\n : field;\n }\n return field;\n}\n\n/**\n * Maps local domain fields to table-bound conditions, encoding each leaf once.\n * I.e. Author.firstName uses the first_name column but resolves its alias in each query scope.\n * Collections, polymorphic references, and inherited nonlocal fields require explicit expressions.\n */\nfunction tableWhere(mgmt: TableMgmt, filter: object): SqlCondition {\n const { meta } = mgmt;\n const conditions: SqlCondition[] = [];\n if (!filter || typeof filter !== \"object\" || Array.isArray(filter)) {\n throw new Error(`Expected a domain field filter for ${meta.type}`);\n }\n for (const [key, value] of Object.entries(filter)) {\n // CTI allFields.id points at the base key; the subtype has its own physical key.\n const field = key === \"id\" ? meta.fields.id : Object.hasOwn(meta.allFields, key) ? meta.allFields[key] : undefined;\n if (\n !field ||\n ![\"primaryKey\", \"primitive\", \"enum\", \"m2o\"].includes(field.kind) ||\n !field.serde ||\n field.serde.columns.length !== 1 ||\n !field.serde.columns.every((binding) => meta.columns[binding.columnName] === binding.column)\n ) {\n throw new Error(`Unsupported table filter field ${meta.type}.${key}; use an explicit join`);\n }\n const column = new TableColumn(meta, field.serde.columns[0].column, mgmt);\n let leaves: ParsedValueFilter<unknown>[];\n if (field.kind === \"m2o\") {\n if (!isTableReferenceFilter(value)) {\n throw new Error(`Unsupported table reference filter ${meta.type}.${key}; use an entity or ID`);\n }\n const parsed = parseEntityFilter(field.otherMetadata(), value);\n if (parsed?.kind === \"join\") {\n throw new Error(`Unsupported table reference filter ${meta.type}.${key}; use an entity or ID`);\n }\n leaves = parsed ? [parsed] : [];\n } else {\n leaves = parseValueFilter(value);\n }\n for (const leaf of leaves) {\n if (leaf.kind === \"between\" && leaf.value.some((v) => v === undefined)) {\n if (leaf.value[0] !== undefined) conditions.push(column.addCondition({ kind: \"gte\", value: leaf.value[0] }));\n if (leaf.value[1] !== undefined) conditions.push(column.addCondition({ kind: \"lte\", value: leaf.value[1] }));\n } else if (leaf.kind === \"in\" && !column.column.isArray && leaf.value.includes(null)) {\n conditions.push({\n or: [\n column.addCondition({ kind: \"is-null\" }),\n column.addCondition({ kind: \"in\", value: leaf.value.filter((v) => v !== null) }),\n ],\n });\n } else {\n conditions.push(column.addCondition(leaf));\n }\n }\n }\n return conditions.length === 0 ? skipCondition : { and: conditions };\n}\n\n/** Rejects nested relations, scopes, and aliases before parsing owning-reference values. */\nfunction isTableReferenceFilter(value: unknown): boolean {\n if (value == null || typeof value === \"boolean\" || isTableReferenceValue(value)) return true;\n if (Array.isArray(value)) return value.every(isTableReferenceValue);\n if (typeof value === \"object\" && Object.keys(value).length === 1 && Object.hasOwn(value, \"ne\")) {\n const excluded = (value as { ne: unknown }).ne;\n return excluded == null || isTableReferenceValue(excluded);\n }\n return false;\n}\n\n/** Recognizes an entity or public ID without accepting another filter object. */\nfunction isTableReferenceValue(value: unknown): boolean {\n return typeof value === \"string\" || typeof value === \"number\" || isEntity(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,SAAgB,MAAwB,MAAyC,OAA+B;CAE9G,OAAO,cAAc,IAAI;AAC3B;;AAGA,SAAgB,OACd,GAAG,MACyG;CAC5G,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC,CAAC;AACzC;AAmOA,MAAa,YAAY,OAAO,WAAW;AAE3C,SAAgB,aAAa,OAAqC;CAChE,OAAO,MAAM;AACf;;AAgBA,SAAgB,iBAAmC,OAAuC;CAExF,OADa,MAAM,UACR,CAAC;AACd;AAEA,SAAgB,cAAgC,MAAmD;CACjG,MAAM,OAAOA,uBAAAA,YAAY,IAAI;CAE7B,MAAM,OAAkB;EAAE,WAAW,KAAK;EAAW;CAAK;CAC1D,MAAM,WAAW,IAAI,IAAI,KAAK,SAAS,KAAK,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,YAAY,IAAI,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;CACjG,MAAM,QAAa,IAAI,MAAM,MAAM;;EAEjC,IAAI,GAAG,KAAuB;GAC5B,IAAI,QAAQ,WACV,OAAO;GAET,IAAI,OAAO,QAAQ,UAAU,OAAO,KAAA;GACpC,MAAM,aAAa,OAAO,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,QAAQ,OAAO,KAAA;GAC1E,IAAI,YACF,OAAO,WAAW,cAAc,QAAQ,OACpC,IAAI,iBAAiB,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M;GAAG,CAAC,CAAC;EAC7G,OAAO,IAAI,KAAK,SAAS,QAAQ,CAAC,OAAO,OAAO,WAAW,KAAK,MAAM,SAAS,IAAI,GACjF,WAAW,KAAK,EACd,IAAI,CACF,OAAO,aAAa,EAAE,MAAM,UAAU,CAAC,GACvC,OAAO,aAAa;GAAE,MAAM;GAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,MAAM,IAAI;EAAE,CAAC,CACjF,EACF,CAAC;OAED,WAAW,KAAK,OAAO,aAAa,IAAI,CAAC;CAG/C;CACA,OAAO,WAAW,WAAW,IAAIV,sBAAAA,gBAAgB,EAAE,KAAK,WAAW;AACrE;;AAGA,SAAS,uBAAuB,OAAyB;CACvD,IAAI,SAAS,QAAQ,OAAO,UAAU,aAAa,sBAAsB,KAAK,GAAG,OAAO;CACxF,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,MAAM,qBAAqB;CAClE,IAAI,OAAO,UAAU,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK,OAAO,OAAO,OAAO,IAAI,GAAG;EAC9F,MAAM,WAAY,MAA0B;EAC5C,OAAO,YAAY,QAAQ,sBAAsB,QAAQ;CAC3D;CACA,OAAO;AACT;;AAGA,SAAS,sBAAsB,OAAyB;CACtD,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,YAAYW,eAAAA,SAAS,KAAK;AACjF"}
1
+ {"version":3,"file":"Tables.cjs","names":["getMetadata","fail","BaseExpr","kqDot","toIdOf","mapToDb","deferredCondition","buildValueCondition","isExpr","skipCondition","makeLike","groupBy","getConstructorFromTaggedId","maybeResolveReferenceToId","asNode","getBaseAndSelfMetas","getBaseSelfAndSubMetas","getBaseMeta","parseEntityFilter","parseValueFilter","isEntity"],"sources":["../src/Tables.ts"],"sourcesContent":["import { groupBy } from \"joist-utils\";\n\nimport { type Column } from \"./columns.ts\";\nimport { type SqlCondition } from \"./conditions.ts\";\n// Load-order only: without this, the built cjs/esm module graph evaluates relations/* before their\n// base classes exist (\"Class extends value undefined\"); keep it even though no symbol is imported.\nimport \"./configure.ts\";\nimport { buildValueCondition } from \"./drivers/buildUtils.ts\";\nimport { type Entity, isEntity } from \"./Entity.ts\";\nimport { type IdOf, type MaybeAbstractEntityConstructor, type TaggedId } from \"./EntityManager.ts\";\nimport {\n type EntityMetadata,\n type Field,\n type LargeOneToManyField,\n type ManyToManyField,\n type OneToManyField,\n type OneToOneField,\n type PolymorphicField,\n type PolymorphicFieldComponent,\n getBaseAndSelfMetas,\n getBaseMeta,\n getBaseSelfAndSubMetas,\n getMetadata,\n} from \"./EntityMetadata.ts\";\nimport {\n BaseExpr,\n type Expr,\n type ExprContext,\n type ExprLike,\n type InnerJoin,\n type LeftJoin,\n type SqlFragment,\n asNode,\n deferredCondition,\n isExpr,\n} from \"./Expr.ts\";\nimport { getConstructorFromTaggedId, maybeResolveReferenceToId } from \"./index.ts\";\nimport { toIdOf } from \"./keys.ts\";\nimport { kqDot } from \"./keywords.ts\";\nimport { type ParsedValueFilter, makeLike, mapToDb, parseEntityFilter, parseValueFilter } from \"./QueryParser.ts\";\nimport { skipCondition } from \"./skipCondition.ts\";\nimport { type TypeInfo } from \"./TypeInfo.ts\";\nimport { type ColumnsOf, type FieldsOf, type FilterOf, type TypeMap, type TypeNameOf } from \"./typeMap.ts\";\nimport { fail } from \"./utils.ts\";\n\n/** Creates physical column expressions and relationship joins for `T`. */\nexport function table<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>): Table<T>;\n/**\n * Creates a table with an explicit type-level name, i.e. `table(Author, \"m\")` for a self-join.\n *\n * The name is the table's source key in `em.query`: two bare `table(Author)`s share the key `\"Author\"`,\n * so a left-joined mentor would also mark the mentee's columns nullable; a named alias has its own key.\n */\nexport function table<T extends Entity, Name extends string>(\n cstr: MaybeAbstractEntityConstructor<T>,\n name: Name,\n): Table<T, Name>;\nexport function table<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>, _name?: string): Table<T, any> {\n // The name only exists at the type level; the SQL alias is still assigned by the query parser\n return newTableProxy(cstr);\n}\n\n/** Creates multiple physical table handles. */\nexport function tables<T extends readonly MaybeAbstractEntityConstructor<any>[]>(\n ...type: T\n): { [P in keyof T]: T[P] extends MaybeAbstractEntityConstructor<infer E extends Entity> ? Table<E> : never } {\n return type.map((t) => newTableProxy(t)) as any;\n}\n\n/**\n * The runtime management interface plus phantom type information for `em.query`.\n *\n * `__entity` lets `QueryRow` recover `T` for entity mode (you cannot `infer T` back out of a mapped\n * type), and `__name` is the table's source key (see `Expr`).\n */\nexport interface TableBrand<T, Name extends string> extends TableMgmt {\n readonly __entity: T;\n readonly __name: Name;\n}\n\n/**\n * A physical table for `T`: one expression per SQL column, with relationship names as join factories.\n * Selecting the table itself retains entity hydration; selecting columns returns decoded SQL values.\n *\n * Unlike an Alias, a Table is an explicit SQL source, not a place to bind in an em.find relationship\n * tree. I.e. with `a = table(Author)`, `{ from: a }` registers that handle in the query's scope.\n * Its columns already know their physical column and codec, but their SQL name still depends on the\n * query: the same Author handle might be `a` in one query and `a1` in a nested query.\n *\n * Each predicate occurrence renders through ExprContext.aliasFor using the current scope (or an\n * enclosing scope for a correlation). Rendering returns SQL, ordered bindings, and source references\n * together. A comparison records both sides' references; templates and subqueries carry their\n * references too. Join pruning follows these references and join dependencies, rather than guessing\n * which tables a SQL string mentions. It also accounts for select/order/group expressions and keep.\n *\n * I.e. if a joined Author is used only by `a.firstName.eq(name)`, supplying undefined removes that\n * predicate and lets the unused join prune. Both APIs share this undefined-condition pruning rule;\n * they differ in how they get the references: Alias resolves domain conditions against a relationship\n * tree, while Table renders SQL expressions against explicit sources. Neither caches SQL names on\n * the reusable handle or predicate, so one parse cannot overwrite another parse's bindings.\n *\n * `Name` is the table's type-level source key, defaulting to the entity's own type name, so a\n * LEFT-joined SmallPublisher does not make Publisher columns nullable. `table(Author, \"m\")`\n * gives a self-join table its own key.\n */\nexport type Table<T extends Entity, Name extends string = TableNameOf<T>> = TableShape<T, Name> &\n (\"where\" extends keyof TableShape<T, Name>\n ? {}\n : {\n /** Builds an AND condition from local domain fields, without implicit joins. */\n where(filter: TableFilter<T>): SqlCondition;\n });\n\n/** Domain filters for fields stored on this physical table, without relationship traversal. */\nexport type TableFilter<T extends Entity> = {\n [K in LocalFieldNames<T> & keyof FieldsOf<T>]?: FieldsOf<T>[K] extends {\n kind: \"m2o\";\n type: infer U extends Entity;\n nullable: infer N;\n }\n ? TableReferenceFilter<U, N extends undefined ? null : never>\n : FilterOf<T>[K];\n};\n\n/** Generated column ownership excludes CTI base fields and polymorphic components. */\ntype LocalFieldNames<T> = ColumnsOf<T>[keyof ColumnsOf<T>] extends { fieldName: infer F }\n ? Extract<F, keyof FilterOf<T>>\n : never;\n\n/** The owning-reference subset of find filters that only compares a foreign key. */\ntype TableReferenceFilter<T extends Entity, N> =\n | T\n | IdOf<T>\n | readonly (T | IdOf<T>)[]\n | boolean\n | N\n | undefined\n | { ne: T | IdOf<T> | N | undefined };\n\ntype TableShape<T extends Entity, Name extends string> = {\n readonly [tableMgmt]: TableBrand<T, Name>;\n} & {\n [P in keyof ColumnsOf<T>]: P extends \"id\"\n ? EntityColumn<T, never, Name>\n : ColumnsOf<T>[P] extends { entity: infer U extends Entity; nullable: infer N }\n ? ReferenceColumn<U, N extends true ? null : never, Name>\n : ColumnsOf<T>[P] extends { type: infer V; nullable: infer N }\n ? PrimitiveColumn<V, N extends true ? null : never, Name>\n : never;\n} & {\n [\n P in keyof FieldsOf<T> as P extends keyof ColumnsOf<T>\n ? never\n : FieldsOf<T>[P] extends { kind: \"m2o\" | \"poly\" | \"o2m\" | \"lo2m\" | \"m2m\" | \"o2o\" }\n ? P\n : never\n ]: FieldsOf<T>[P] extends { kind: \"m2o\"; type: infer U extends Entity; nullable: infer N }\n ? ReferenceJoin<U, N extends undefined ? null : never>\n : FieldsOf<T>[P] extends { kind: \"poly\"; type: infer U extends Entity; nullable: infer N }\n ? PolyReference<U, N extends undefined ? null : never>\n : FieldsOf<T>[P] extends { kind: \"o2m\" | \"lo2m\" | \"m2m\" | \"o2o\"; type: infer U extends Entity }\n ? CollectionJoin<U>\n : never;\n} & {\n [\n K in keyof TypeMap as TypeMap[K] extends {\n entityType: infer U extends Entity & { __type: { 0: TypeNameOf<T>; 1: string } };\n }\n ? Uncapitalize<TypeNameOf<U> & string>\n : never\n ]: TypeMap[K] extends { entityType: infer U extends Entity } ? SubtypeJoin<U> : never;\n};\n\n/** Keeps explicit base and subtype sources independent, with generic entities untracked. */\ntype TableNameOf<T> = T extends { __type: { 0: string } } ? TypeNameOf<T> & string : string;\n\n/** A relationship join factory, without a selectable FK expression. */\nexport interface ReferenceJoin<U extends Entity, N extends null | never> {\n as<A extends TableFor<U>>(other: A): [N] extends [never] ? InnerJoin<A> : LeftJoin<A>;\n inner<A extends TableFor<U>>(other: A): InnerJoin<A>;\n left<A extends TableFor<U>>(other: A): LeftJoin<A>;\n}\n\n/** Any table whose entity is (a subtype of) `U`, i.e. what a relation join factory accepts. */\nexport type TableFor<U> = { readonly [tableMgmt]: TableBrand<U, string> };\n\n/**\n * A collection relation (o2m/o2o/m2m) as a join factory: `a.books.as(b)` returns the same\n * `{ left: b, on: ... }` entry the expanded form writes, with the FK condition built from metadata, so\n * join-list inference, nullability, scope checking, and pruning are unchanged and both forms mix freely.\n *\n * `as` binds the joined alias, the same way em.find's `{ books: { as: b } }` does. The default is LEFT\n * (a collection may be empty, and a LEFT join never filters rows, so pruning it is always safe);\n * `.inner(b)` opts into filtering. An m2m entry carries a hidden second join through the join table,\n * which the parser expands; the pair prunes together.\n */\nexport interface CollectionJoin<U extends Entity> {\n as<A extends TableFor<U>>(other: A): LeftJoin<A>;\n inner<A extends TableFor<U>>(other: A): InnerJoin<A>;\n left<A extends TableFor<U>>(other: A): LeftJoin<A>;\n}\n\n/** A named subtype join, defaulting to LEFT because a root row may belong to another subtype. */\ninterface SubtypeJoin<U extends Entity> extends CollectionJoin<U> {\n <A extends TableFor<U>>(other: A): LeftJoin<A>;\n}\n\n/**\n * A physical FK column expression (`b.authorId` selects/compares the `author_id` FK) plus a join factory\n * (`b.authorId.as(a)` joins). The default join kind follows physical column nullability:\n * a NOT NULL FK is INNER, a nullable one is LEFT, and the row type reflects it.\n */\nexport interface ReferenceColumn<U extends Entity, N extends null | never, Src extends string>\n extends EntityColumn<U, N, Src>, ReferenceJoin<U, N> {}\n\n/**\n * A polymorphic reference: condition methods (each resolving the component column from the value), plus\n * a join factory that picks the component from the argument's entity, i.e. `c.parent.as(a)` joins\n * through `parent_author_id`, like an explicit join with `on: c.parent.eq(a.id)`.\n */\nexport interface PolyReference<U extends Entity, N extends null | never> extends ReferenceJoin<U, N> {\n eq(value: U | TaggedId | ExprLike<IdOf<U> | null> | null | undefined): SqlCondition;\n ne(value: U | TaggedId | ExprLike<IdOf<U> | null> | null | undefined): SqlCondition;\n in(values: Array<U | TaggedId> | ExprLike<IdOf<U> | null> | undefined): SqlCondition;\n}\n\nexport interface PrimitiveColumn<V, N extends null | never, Src extends string = string> extends Expr<V | N, Src> {\n eq(value: V | ExprLike<V | N> | N | undefined): SqlCondition;\n ne(value: V | ExprLike<V | N> | N | undefined): SqlCondition;\n in(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition;\n nin(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition;\n gt(value: V | ExprLike<V | N> | undefined): SqlCondition;\n gte(value: V | ExprLike<V | N> | undefined): SqlCondition;\n lt(value: V | ExprLike<V | N> | undefined): SqlCondition;\n lte(value: V | ExprLike<V | N> | undefined): SqlCondition;\n like(value: V | undefined): SqlCondition;\n ilike(value: V | undefined): SqlCondition;\n search(value: V | undefined): SqlCondition;\n between(v1: V | undefined, v2: V | undefined): SqlCondition;\n // need to move to ArrayColumn\n // ...added the `string` to support jsonb contains like `WHERE profile @> '{\"age\": 25}'`\n // Ideally this would go in a JsonbColumn\n contains(value: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n ncontains(value: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n overlaps(value: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n noverlaps(value: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition;\n\n /**\n * Adds a JSON path existence condition, using the `@?` operator.\n *\n * Any values should be embedded directly within the `jsonPath`, because postgres does not\n * support parameterized JSON path expressions. The entire `jsonPath` is treated as a parameter,\n * so this is safe from SQL injection.\n */\n pathExists(jsonPath: string | undefined): SqlCondition;\n\n /**\n * Adds a JSON path predicate condition, using the `@@` operator.\n *\n * Any values should be embedded directly within the `jsonPath`, because postgres does not\n * support parameterized JSON path expressions. The entire `jsonPath` is treated as a parameter,\n * so this is safe from SQL injection.\n */\n pathIsTrue(jsonPath: string | undefined): SqlCondition;\n\n /**\n * Add `exp` to the query, which should include the operator & expression and any\n * bound parameters (but not include the column name).\n *\n * We use knex-style placeholders, i.e. `?` and `\\\\?` to escape question marks, i.e.\n *\n * ```ts\n * a.address.raw(\"@\\\\? ?\", ['$.street ? (@ == \"rr2\")'])`\n * ```\n */\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition;\n}\n\nexport interface EntityColumn<T, N extends null | never = never, Src extends string = string> extends Expr<\n IdOf<T> | N,\n Src\n> {\n eq(value: T | IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n ne(value: T | IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n // Adding `| null` for GraphQL support\n in(value: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n nin(value: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n gt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n gte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n lt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n lte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition;\n}\n\nexport const tableMgmt = Symbol(\"tableMgmt\");\n\nexport function getTableMgmt(table: TableFor<unknown>): TableMgmt {\n return table[tableMgmt];\n}\n\n/** The identity SQL queries bind a table by, plus its original entity metadata. */\nexport interface TableMgmt {\n tableName: string;\n /**\n * The metadata this table was created with, i.e. `table(TaskNew)` keeps `taskNewMeta`.\n *\n * It cannot be re-derived from `tableName`: STI subtypes share their base's table (`Task`, `TaskNew`,\n * and `TaskOld` are all `tasks`), so a `getMetadataForTable(\"tasks\")` lookup can only return the base\n * `Task`, and the alias would lose its subtype identity for explicit subtype joins and entity hydration.\n */\n meta: EntityMetadata;\n}\n\n/** Returns the metadata for the entity that `table` is bound to. */\nexport function getTableMetadata<T extends Entity>(table: TableFor<T>): EntityMetadata<T> {\n const mgmt = table[tableMgmt];\n return mgmt.meta as EntityMetadata<T>;\n}\n\nexport function newTableProxy<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>): Table<T> {\n const meta = getMetadata(cstr);\n // The identity SQL queries bind to a source, retaining STI subtype metadata.\n const mgmt: TableMgmt = { tableName: meta.tableName, meta };\n const subtypes = new Map(meta.subTypes.map((m) => [m.type[0].toLowerCase() + m.type.slice(1), m]));\n const proxy: any = new Proxy(cstr, {\n /** Create a physical column expression or a relation join factory. */\n get(_, key: PropertyKey): any {\n if (key === tableMgmt) {\n return mgmt;\n }\n if (typeof key !== \"string\") return undefined;\n const descriptor = Object.hasOwn(meta.columns, key) ? meta.columns[key] : undefined;\n if (descriptor) {\n return descriptor.idMetadata && key !== \"id\"\n ? new EntityColumnImpl(meta, descriptor, mgmt)\n : new PrimitiveColumnImpl(meta, descriptor, mgmt);\n }\n const subtype = subtypes.get(key);\n if (subtype) {\n const join = new SubtypeJoinImpl(proxy, subtype);\n return Object.assign(join.as.bind(join), {\n as: join.as.bind(join),\n inner: join.inner.bind(join),\n left: join.left.bind(join),\n });\n }\n const relation = physicalRelation(meta, key);\n if (key === \"where\" && !isRelation(meta.allFields[key])) {\n return (filter: TableFilter<T>) => tableWhere(mgmt, filter);\n }\n const field = relation ?? fail(`No physical field ${key} on ${cstr.name}; join its base table explicitly`);\n switch (field.kind) {\n case \"m2o\":\n return new ReferenceJoinImpl(new EntityColumnImpl(meta, field.serde.columns[0].column, mgmt));\n case \"poly\":\n return new PolyReferenceImpl(meta, mgmt, field);\n case \"o2m\":\n case \"o2o\":\n case \"lo2m\":\n return new OneToManyJoinImpl(proxy, field);\n case \"m2m\":\n return new ManyToManyJoinImpl(proxy, field);\n default:\n throw new Error(`Unsupported table field kind ${field.kind}`);\n }\n },\n\n has(_, key) {\n return (\n key === tableMgmt ||\n (typeof key === \"string\" &&\n (key === \"where\" || Object.hasOwn(meta.columns, key) || !!physicalRelation(meta, key) || subtypes.has(key)))\n );\n },\n });\n return proxy;\n}\n\nexport function isTable(obj: unknown): obj is Table<any, any> {\n // Oddly enough `typeof` will be a function b/c we are proxying the constructors\n return typeof obj === \"function\" && tableMgmt in obj;\n}\n\n/**\n * A physical table column implements `Expr`: it renders as `alias.\"column\"`, decodes result\n * values through the column's shared scalar codec, and inherits aggregate methods from `BaseExpr`.\n */\nclass TableColumn extends BaseExpr {\n public constructor(\n readonly meta: EntityMetadata,\n readonly column: Column,\n readonly mgmt: TableMgmt,\n ) {\n super();\n }\n\n /** Author.id, Book.authorId, and Comment.parentAuthorId use the same Author ID domain. */\n get outputType(): TypeInfo | undefined {\n return this.column.outputType;\n }\n\n get sqlNullable(): boolean | undefined {\n return this.column.sqlNullable;\n }\n\n get sqlSource(): object {\n return this.mgmt;\n }\n\n toSql(ctx: ExprContext): SqlFragment {\n const alias = ctx.aliasFor(this.mgmt);\n return { sql: kqDot(alias, this.column.columnName), bindings: [], refs: [alias] };\n }\n\n /** Decodes result-set values with public PK/FK ids, while hydration keeps internal tagged ids. */\n decode(value: unknown): unknown {\n if (value === null || value === undefined) return value;\n const idMeta = this.idMetadata;\n if (idMeta) return toIdOf(idMeta, this.column.mapFromDb(value) as TaggedId | undefined);\n return this.column.mapFromDb(value);\n }\n\n encode(value: unknown): unknown {\n return this.column.mapToDb(value);\n }\n\n /** Identifies the ID domain of a primary key, FK, or physical polymorphic component. */\n get idMetadata(): EntityMetadata | undefined {\n return this.column.idMetadata?.();\n }\n\n /** Encodes literals when the condition is created and renders with each query's aliases. */\n addCondition(value: ParsedValueFilter<unknown>): SqlCondition {\n const encoded = mapToDb(this.column, value);\n return deferredCondition((ctx) => {\n const left = this.toSql(ctx);\n const [sql, bindings] = buildValueCondition(left.sql, encoded);\n return { sql, bindings: [...left.bindings, ...bindings], refs: left.refs };\n });\n }\n\n /** Renders raw operators against the same quoted column SQL as other expressions. */\n protected addRawCondition(exp: string, bindings: readonly any[]): SqlCondition {\n return deferredCondition((ctx) => {\n const left = this.toSql(ctx);\n return { sql: `${left.sql} ${exp}`, bindings: [...left.bindings, ...bindings], refs: left.refs };\n });\n }\n\n /** Uses column filter conversions for literals and shared comparisons for expressions and null equality. */\n protected compare(op: string, value: unknown): SqlCondition {\n if (value === undefined || isExpr(value) || (value === null && (op === \"=\" || op === \"!=\"))) {\n return super.compare(op, value);\n }\n // Primitive relational comparisons historically bind null through mapToDb.\n const kind = ({ \"=\": \"eq\", \"!=\": \"ne\", \">\": \"gt\", \">=\": \"gte\", \"<\": \"lt\", \"<=\": \"lte\" } as const)[op];\n if (!kind) return fail(`Invalid operator ${op}`);\n return this.addCondition({ kind, value });\n }\n\n /**\n * Compares this column to another expression.\n *\n * Table columns, aggregates, subquery columns, and `sql` templates use the expression context\n * to render their complete SQL.\n * Negated array operators wrap the complete comparison in NOT.\n */\n protected compareToExpr(op: string, value: ExprLike<any>, negate = false): SqlCondition {\n if (negate) {\n return deferredCondition((ctx) => {\n const comparison = ctx.conditionToSql(this.compareToExpr(op, value))!;\n return { ...comparison, sql: `NOT (${comparison.sql})` };\n });\n }\n return super.compare(op, value);\n }\n}\n\nclass PrimitiveColumnImpl<V, N extends null | never> extends TableColumn implements PrimitiveColumn<V, N> {\n between(v1: V | undefined, v2: V | undefined): SqlCondition {\n if (v1 === undefined || v2 === undefined) return skipCondition;\n return this.addCondition({ kind: \"between\", value: [v1, v2] });\n }\n\n like(value: V | undefined): SqlCondition {\n if (value === undefined) return skipCondition;\n return this.addCondition({ kind: \"like\", value });\n }\n\n ilike(value: V | undefined): SqlCondition {\n if (value === undefined) return skipCondition;\n return this.addCondition({ kind: \"ilike\", value });\n }\n\n search(value: V | undefined): SqlCondition {\n // Check !value so that empty strings are pruned\n if (!value) return skipCondition;\n return this.addCondition({ kind: \"ilike\", value: makeLike(value) });\n }\n\n in(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition {\n if (values === undefined) return skipCondition;\n if (isExpr(values)) return this.inList(\"IN\", values);\n if (values.includes(null)) {\n const isNull = this.addCondition({ kind: \"is-null\" });\n const hasValue = this.addCondition({ kind: \"in\", value: values.filter((v) => v !== null) });\n return { or: [isNull, hasValue] };\n } else {\n return this.addCondition({ kind: \"in\", value: values as V[] });\n }\n }\n\n nin(values: readonly (V | null)[] | ExprLike<V | null> | undefined): SqlCondition {\n if (values === undefined) return skipCondition;\n if (isExpr(values)) return this.inList(\"NOT IN\", values);\n return this.addCondition({ kind: \"nin\", value: values.filter((v) => v !== null) as V[] });\n }\n\n // V will already be an array\n contains(v1: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"@>\", v1);\n return this.addCondition({ kind: \"contains\", value: v1 as any });\n }\n\n // V will already be an array\n ncontains(v1: string | V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"@>\", v1, true);\n return this.addCondition({ kind: \"ncontains\", value: v1 as any });\n }\n\n // V will already be an array\n overlaps(v1: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"&&\", v1);\n return this.addCondition({ kind: \"overlaps\", value: v1 as any });\n }\n\n noverlaps(v1: V | PrimitiveColumn<V, any> | N | undefined): SqlCondition {\n if (v1 === undefined) return skipCondition;\n if (isExpr(v1)) return this.compareToExpr(\"&&\", v1, true);\n return this.addCondition({ kind: \"noverlaps\", value: v1 as any });\n }\n\n pathExists(jsonPath: string | undefined): SqlCondition {\n if (jsonPath === undefined) return skipCondition;\n return this.addCondition({ kind: \"jsonPathExists\", value: jsonPath });\n }\n\n pathIsTrue(jsonPath: string | undefined): SqlCondition {\n if (jsonPath === undefined) return skipCondition;\n return this.addCondition({ kind: \"jsonPathPredicate\", value: jsonPath });\n }\n\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition {\n if (bindings === undefined) return skipCondition;\n return this.addRawCondition(exp, bindings);\n }\n}\n\nclass EntityColumnImpl<T> extends TableColumn implements EntityColumn<T> {\n in(values: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n if (values === undefined) {\n return skipCondition;\n } else if (values === null) {\n throw new Error(\"Unsupported\");\n } else if (isExpr(values)) {\n return this.inList(\"IN\", values);\n } else if (values.includes(null)) {\n // Like `PrimitiveColumn.in`, split `[a1, null]` into `IS NULL OR IN (...)`\n const isNull = this.addCondition({ kind: \"is-null\" });\n const hasValue = this.addCondition({ kind: \"in\", value: values.filter((v) => v !== null) as any });\n return { or: [isNull, hasValue] };\n } else {\n return this.addCondition({ kind: \"in\", value: values as any });\n }\n }\n\n nin(values: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n if (values === undefined) {\n return skipCondition;\n } else if (values === null) {\n throw new Error(\"Unsupported\");\n } else if (isExpr(values)) {\n return this.inList(\"NOT IN\", values);\n } else {\n return this.addCondition({ kind: \"nin\", value: values.filter((v) => v !== null) as any });\n }\n }\n\n gt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\">\", \"gt\", value);\n }\n\n gte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\">=\", \"gte\", value);\n }\n\n lt(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\"<\", \"lt\", value);\n }\n\n lte(value: IdOf<T> | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.compareId(\"<=\", \"lte\", value);\n }\n\n raw(exp: string, bindings: readonly any[] | undefined): SqlCondition {\n if (bindings === undefined) return skipCondition;\n return this.addRawCondition(exp, bindings);\n }\n\n /** Joins `other` via this FK, INNER for a required reference and LEFT for a nullable one. */\n as(other: object): object {\n return this.joinEntry(this.sqlNullable === false ? \"inner\" : \"left\", other);\n }\n\n inner(other: object): object {\n return this.joinEntry(\"inner\", other);\n }\n\n left(other: object): object {\n return this.joinEntry(\"left\", other);\n }\n\n private joinEntry(kind: JoinKind, other: object): object {\n return { [kind]: requireTable(other), on: this.eq(idColumnOf(other)) };\n }\n\n private compareId(op: string, kind: \"gt\" | \"gte\" | \"lt\" | \"lte\", value: unknown): SqlCondition {\n if (value === undefined) return skipCondition;\n if (value === null) throw new Error(\"Unsupported\");\n if (isExpr(value)) return this.compareToExpr(op, value);\n return this.addCondition({ kind, value: value as any });\n }\n}\n\nclass PolyReferenceImpl<T extends Entity> {\n public constructor(\n private meta: EntityMetadata,\n private mgmt: TableMgmt,\n private field: PolymorphicField,\n ) {}\n\n /** Compares to a tagged id, an entity, or another table's id column, which picks the component (`c.parent.eq(a.id)`). */\n eq(value: T | TaggedId | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.addEqOrNe(\"eq\", value);\n }\n\n ne(value: T | TaggedId | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition {\n return this.addEqOrNe(\"ne\", value);\n }\n\n // We required tagged ids for polys\n in(values: Array<T | TaggedId> | ExprLike<IdOf<T> | null> | undefined): SqlCondition {\n if (values === undefined) return skipCondition;\n if (isExpr(values)) return this.inSubquery(values);\n // Split up the ids by constructor\n const idsByConstructor = groupBy(values, (id) => getConstructorFromTaggedId(maybeResolveReferenceToId(id)!).name);\n // Or together `parent_book_id in (1,2,3) OR parent_author_id IN (4,5,6)`\n return {\n or: Object.entries(idsByConstructor).map(([cstrName, ids]) => {\n const comp =\n this.field.components.find((p) => p.otherMetadata().cstr.name === cstrName) ??\n fail(`No component for ${cstrName}`);\n return this.componentColumn(comp).addCondition({ kind: \"in\", value: ids });\n }),\n };\n }\n\n /** Joins `other` via this poly's component for its entity, INNER when the poly is required. */\n as(other: object): object {\n return this.joinEntry(this.field.required ? \"inner\" : \"left\", other);\n }\n\n inner(other: object): object {\n return this.joinEntry(\"inner\", other);\n }\n\n left(other: object): object {\n return this.joinEntry(\"left\", other);\n }\n\n private joinEntry(kind: JoinKind, other: object): object {\n return { [kind]: requireTable(other), on: this.eq(idColumnOf(other) as any) };\n }\n\n /**\n * i.e. `c.parent.in(query({ from: a, ..., select: a.id }))`: like `eq` against a table column, the\n * subquery's agreed ID domain picks the component, i.e. authors pick `parent_author_id`.\n */\n private inSubquery(values: ExprLike<any>): SqlCondition {\n // Only actual subqueries expose this getter; importing query.ts would create a load-order cycle.\n const selected = asNode(values).subquerySelect;\n const outputType = selected?.outputType;\n let otherMeta = outputType?.idMeta;\n if (!otherMeta) {\n // Ordinary reads can select an unknown key serde. Compounds validate codecs before exposing a select.\n if (!outputType && selected instanceof TableColumn) {\n otherMeta = selected.idMetadata;\n }\n if (!otherMeta) {\n return fail(\n selected instanceof TableColumn\n ? `${this.field.fieldName} \\`in\\` needs an id or FK column, got ${selected.column.columnName}`\n : `${this.field.fieldName} is polymorphic, so \\`in\\` needs a subquery selecting an id or FK column`,\n );\n }\n }\n const comp =\n this.field.components.find((p) => getBaseAndSelfMetas(otherMeta).includes(p.otherMetadata())) ??\n fail(`${this.field.fieldName} has no component for ${otherMeta.type}`);\n return this.componentColumn(comp).in(values);\n }\n\n private addEqOrNe(\n kind: \"eq\" | \"ne\",\n value: T | TaggedId | ExprLike<IdOf<T> | null> | null | undefined,\n ): SqlCondition {\n if (value === undefined) {\n return skipCondition;\n } else if (value instanceof TableColumn) {\n // Joining through the poly, i.e. `c.parent.eq(a.id)`: the other table column's ID domain picks the component\n const otherMeta = value.idMetadata ?? fail(`${this.field.fieldName} needs an id or FK column`);\n const comp =\n this.field.components.find((p) => getBaseAndSelfMetas(otherMeta).includes(p.otherMetadata())) ??\n fail(`${this.field.fieldName} has no component for ${otherMeta.type}`);\n return this.componentColumn(comp)[kind](value);\n } else if (isExpr(value)) {\n return fail(\n `${this.field.fieldName} is polymorphic, so it can only be compared to tagged ids or entity table columns`,\n );\n } else if (value === null) {\n // We can AND each of the components as many conditions\n const value = kind === \"eq\" ? ({ kind: \"is-null\" } as const) : ({ kind: \"not-null\" } as const);\n return {\n and: this.field.components.map((p) => this.componentColumn(p).addCondition(value)),\n };\n } else {\n // If we have a value, we can find the component\n const comp =\n this.field.components.find(\n (p) => p.otherMetadata().cstr === getConstructorFromTaggedId(maybeResolveReferenceToId(value) as string),\n ) || fail(`Could not find component for ${value}`);\n return this.componentColumn(comp)[kind](value);\n }\n }\n\n /** Returns the physical FK expression for one polymorphic target. */\n private componentColumn(comp: PolymorphicFieldComponent): EntityColumnImpl<T> {\n const descriptor = comp.column;\n return new EntityColumnImpl<T>(this.meta, descriptor, this.mgmt);\n }\n}\n\n/**\n * Marks a sugar join entry whose target is a *collection* (o2m/m2m), which filter soft-deletes like\n * em.find's \"collections filter out soft-deletes, but m2o/o2o references still return them\"; see\n * `QueryParser.addSoftDeleteCondition`'s call site. Reference joins and explicit joins are unmarked.\n */\nexport const collectionJoin: unique symbol = Symbol(\"joist.collectionJoin\");\n\n/** Marks a sugar m2m join entry (`a.tags.as(t)`) with its hidden join-table join; `parseQuery` expands it. */\nexport const m2mJoinTable: unique symbol = Symbol(\"joist.m2mJoinTable\");\n\nexport interface M2mJoinTable {\n handle: JoinTableHandle;\n on: SqlCondition;\n}\n\n/** The runtime identity of an m2m join table in a query, i.e. `authors_to_tags`; it has no entity. */\nexport class JoinTableHandle {\n constructor(readonly joinTableName: string) {}\n}\n\ntype JoinKind = \"inner\" | \"left\";\n\n/**\n * The `as`/`inner`/`left` join factory for collection relations, i.e. `a.books.as(b)` joins with the\n * relation's default kind (LEFT: a collection may be empty) and `.inner`/`.left` override. m2o/poly\n * relations implement the same three methods on their join factories. Physical FKs such as\n * `b.author_id` are expressions that also expose a join factory.\n */\nabstract class CollectionJoinImpl {\n as(other: object): object {\n return this.joinEntry(\"left\", requireTable(other));\n }\n\n inner(other: object): object {\n return this.joinEntry(\"inner\", requireTable(other));\n }\n\n left(other: object): object {\n return this.joinEntry(\"left\", requireTable(other));\n }\n\n protected abstract joinEntry(kind: JoinKind, other: TableFor<Entity>): object;\n}\n\n/** Joins a named subtype explicitly; only STI subtype sugar adds a discriminator to its ON. */\nclass SubtypeJoinImpl extends CollectionJoinImpl {\n constructor(\n private proxy: TableFor<Entity>,\n private subtype: EntityMetadata,\n ) {\n super();\n }\n\n protected joinEntry(kind: JoinKind, other: TableFor<Entity>): object {\n if (getTableMetadata(other) !== this.subtype) {\n return fail(`Expected table(${this.subtype.type}) for the explicit subtype join`);\n }\n const on = idColumnOf(this.proxy).eq(idColumnOf(other));\n if (this.subtype.inheritanceType !== \"sti\" || this.subtype.stiDiscriminatorValue === undefined) {\n return { [kind]: other, on };\n }\n const base = this.subtype.baseTypes.find((m) => m.stiDiscriminatorField !== undefined)!;\n const columnName = base.fields[base.stiDiscriminatorField!].serde!.columns[0].columnName;\n // Discriminator values are database enum ids, not domain enum values to pass through the field codec.\n const discriminator = deferredCondition((ctx) => {\n const alias = ctx.aliasFor(other[tableMgmt]);\n return {\n sql: `${kqDot(alias, columnName)} = ?`,\n bindings: [this.subtype.stiDiscriminatorValue],\n refs: [alias],\n };\n });\n return { [kind]: other, on: { and: [on, discriminator] } };\n }\n}\n\n/** An o2m/lo2m/o2o relation: the ON is the other side's FK (an m2o or a poly component) back to our id. */\nclass OneToManyJoinImpl extends CollectionJoinImpl {\n constructor(\n private proxy: any,\n private field: OneToManyField | LargeOneToManyField | OneToOneField,\n ) {\n super();\n }\n\n protected joinEntry(kind: JoinKind, other: TableFor<Entity>): object {\n const { field } = this;\n const otherMeta = getTableMetadata(other);\n const descriptor = Object.values(otherMeta.columns).find((column) => column.columnName === field.otherColumnName);\n if (!descriptor) {\n return fail(\n `Cannot join ${getTableMetadata(this.proxy).type}.${field.fieldName} to ${otherMeta.type}: ` +\n `${field.otherColumnName} is not physically present on ${otherMeta.tableName}; join the base table explicitly`,\n );\n }\n const column = new EntityColumnImpl(otherMeta, descriptor, other[tableMgmt]);\n const on = column.eq(this.proxy.id);\n // Collections (o2m/lo2m) filter soft-deletes like em.find; o2o references resolve them\n const filtered = field.kind === \"o2m\" ? field.softDeletes !== \"include\" : field.kind === \"lo2m\";\n return { [kind]: other, on, [collectionJoin]: filtered };\n }\n}\n\n/**\n * An m2m relation, i.e. `a.tags.as(t)`.\n *\n * The entry's own ON is `t.id = att.tag_id`, and the hidden `[m2mJoinTable]` half is\n * `att.author_id = a.id`; only the target's ON references the join table, so reference pruning keeps\n * or drops the pair together. Both are deferred conditions: the join table has no entity metadata, so\n * its alias only exists once the parser registers it.\n */\nclass ManyToManyJoinImpl extends CollectionJoinImpl {\n constructor(\n private proxy: any,\n private field: ManyToManyField,\n ) {\n super();\n }\n\n protected joinEntry(kind: JoinKind, other: TableFor<Entity>): object {\n const { joinTableName, columnNames } = this.field;\n const [ourColumn, otherColumn] = columnNames;\n const jt = new JoinTableHandle(joinTableName);\n const ourId = idColumnOf(this.proxy);\n const otherId = idColumnOf(other);\n const jtOn = deferredCondition((ctx) => {\n const jtAlias = ctx.aliasFor(jt);\n const id = ourId.toSql(ctx);\n return { sql: `${kqDot(jtAlias, ourColumn)} = ${id.sql}`, bindings: id.bindings, refs: id.refs };\n });\n const on = deferredCondition((ctx) => {\n const jtAlias = ctx.aliasFor(jt);\n const id = otherId.toSql(ctx);\n return { sql: `${id.sql} = ${kqDot(jtAlias, otherColumn)}`, bindings: id.bindings, refs: [...id.refs, jtAlias] };\n });\n const filtered = this.field.softDeletes !== \"include\";\n return {\n [kind]: other,\n on,\n [collectionJoin]: filtered,\n [m2mJoinTable]: { handle: jt, on: jtOn } satisfies M2mJoinTable,\n };\n }\n}\n\n/** Fails fast when a join factory is passed something other than a table. */\nfunction requireTable(other: object): TableFor<Entity> {\n if (!isTable(other)) return fail(`Expected a table to join, got ${other}`);\n return other;\n}\n\n/** The id column of a joined table, for building sugar ON conditions. */\nfunction idColumnOf(other: object): TableColumn {\n return (other as any).id;\n}\n\n/** Keeps relation names join-only; physical FK columns retain expression methods. */\nclass ReferenceJoinImpl {\n constructor(private column: EntityColumnImpl<unknown>) {}\n\n as(other: object): object {\n return this.column.sqlNullable === false ? this.column.inner(other) : this.column.left(other);\n }\n\n inner(other: object): object {\n return this.column.inner(other);\n }\n\n left(other: object): object {\n return this.column.left(other);\n }\n}\n\n/** Identifies domain relationship keys exposed alongside physical columns. */\nfunction isRelation(field: Field | undefined): boolean {\n return field !== undefined && [\"m2o\", \"poly\", \"o2m\", \"lo2m\", \"m2m\", \"o2o\"].includes(field.kind);\n}\n\n/** Resolves relationship sugar only from domain fields owned by this physical table. */\nfunction physicalRelation(meta: EntityMetadata, key: string): Field | undefined {\n const owners = [meta, ...getBaseSelfAndSubMetas(getBaseMeta(meta))];\n const owner = owners.find((owner) => owner.tableName === meta.tableName && Object.hasOwn(owner.fields, key));\n const field = owner?.fields[key];\n if (!isRelation(field)) return undefined;\n // I.e. TaskNew.copiedFrom uses Task's original FK domain, not its specialized TaskNew target.\n if (field?.kind === \"m2o\" || field?.kind === \"poly\") {\n if (!field.serde.columns.every((binding) => Object.values(meta.columns).includes(binding.column))) return undefined;\n return field.kind === \"poly\"\n ? {\n ...field,\n components: field.components.map((component) => ({\n column: component.column,\n columnName: component.columnName,\n otherFieldName: component.otherFieldName,\n otherMetadata: component.column.idMetadata!,\n })),\n }\n : field;\n }\n return field;\n}\n\n/**\n * Maps local domain fields to table-bound conditions, encoding each leaf once.\n * I.e. Author.firstName uses the first_name column but resolves its alias in each query scope.\n * Collections, polymorphic references, and inherited nonlocal fields require explicit expressions.\n */\nfunction tableWhere(mgmt: TableMgmt, filter: object): SqlCondition {\n const { meta } = mgmt;\n const conditions: SqlCondition[] = [];\n if (!filter || typeof filter !== \"object\" || Array.isArray(filter)) {\n throw new Error(`Expected a domain field filter for ${meta.type}`);\n }\n for (const [key, value] of Object.entries(filter)) {\n // CTI allFields.id points at the base key; the subtype has its own physical key.\n const field = key === \"id\" ? meta.fields.id : Object.hasOwn(meta.allFields, key) ? meta.allFields[key] : undefined;\n if (\n !field ||\n ![\"primaryKey\", \"primitive\", \"enum\", \"m2o\"].includes(field.kind) ||\n !field.serde ||\n field.serde.columns.length !== 1 ||\n !field.serde.columns.every((binding) => Object.values(meta.columns).includes(binding.column))\n ) {\n throw new Error(`Unsupported table filter field ${meta.type}.${key}; use an explicit join`);\n }\n const column = new TableColumn(meta, field.serde.columns[0].column, mgmt);\n let leaves: ParsedValueFilter<unknown>[];\n if (field.kind === \"m2o\") {\n if (!isTableReferenceFilter(value)) {\n throw new Error(`Unsupported table reference filter ${meta.type}.${key}; use an entity or ID`);\n }\n const parsed = parseEntityFilter(field.otherMetadata(), value);\n if (parsed?.kind === \"join\") {\n throw new Error(`Unsupported table reference filter ${meta.type}.${key}; use an entity or ID`);\n }\n leaves = parsed ? [parsed] : [];\n } else {\n leaves = parseValueFilter(value);\n }\n for (const leaf of leaves) {\n if (leaf.kind === \"between\" && leaf.value.some((v) => v === undefined)) {\n if (leaf.value[0] !== undefined) conditions.push(column.addCondition({ kind: \"gte\", value: leaf.value[0] }));\n if (leaf.value[1] !== undefined) conditions.push(column.addCondition({ kind: \"lte\", value: leaf.value[1] }));\n } else if (leaf.kind === \"in\" && !column.column.isArray && leaf.value.includes(null)) {\n conditions.push({\n or: [\n column.addCondition({ kind: \"is-null\" }),\n column.addCondition({ kind: \"in\", value: leaf.value.filter((v) => v !== null) }),\n ],\n });\n } else {\n conditions.push(column.addCondition(leaf));\n }\n }\n }\n return conditions.length === 0 ? skipCondition : { and: conditions };\n}\n\n/** Rejects nested relations, scopes, and aliases before parsing owning-reference values. */\nfunction isTableReferenceFilter(value: unknown): boolean {\n if (value == null || typeof value === \"boolean\" || isTableReferenceValue(value)) return true;\n if (Array.isArray(value)) return value.every(isTableReferenceValue);\n if (typeof value === \"object\" && Object.keys(value).length === 1 && Object.hasOwn(value, \"ne\")) {\n const excluded = (value as { ne: unknown }).ne;\n return excluded == null || isTableReferenceValue(excluded);\n }\n return false;\n}\n\n/** Recognizes an entity or public ID without accepting another filter object. */\nfunction isTableReferenceValue(value: unknown): boolean {\n return typeof value === \"string\" || typeof value === \"number\" || isEntity(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,SAAgB,MAAwB,MAAyC,OAA+B;CAE9G,OAAO,cAAc,IAAI;AAC3B;;AAGA,SAAgB,OACd,GAAG,MACyG;CAC5G,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC,CAAC;AACzC;AAmOA,MAAa,YAAY,OAAO,WAAW;AAE3C,SAAgB,aAAa,OAAqC;CAChE,OAAO,MAAM;AACf;;AAgBA,SAAgB,iBAAmC,OAAuC;CAExF,OADa,MAAM,UACR,CAAC;AACd;AAEA,SAAgB,cAAgC,MAAmD;CACjG,MAAM,OAAOA,uBAAAA,YAAY,IAAI;CAE7B,MAAM,OAAkB;EAAE,WAAW,KAAK;EAAW;CAAK;CAC1D,MAAM,WAAW,IAAI,IAAI,KAAK,SAAS,KAAK,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,YAAY,IAAI,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;CACjG,MAAM,QAAa,IAAI,MAAM,MAAM;;EAEjC,IAAI,GAAG,KAAuB;GAC5B,IAAI,QAAQ,WACV,OAAO;GAET,IAAI,OAAO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AW,KAAK,OAAO,aAAa;IAAE,MAAM;IAAO,OAAO,KAAK,MAAM;GAAG,CAAC,CAAC;GAC3G,IAAI,KAAK,MAAM,OAAO,KAAA,GAAW,WAAW,KAAK,OAAO,aAAa;IAAE,MAAM;IAAO,OAAO,KAAK,MAAM;GAAG,CAAC,CAAC;EAC7G,OAAO,IAAI,KAAK,SAAS,QAAQ,CAAC,OAAO,OAAO,WAAW,KAAK,MAAM,SAAS,IAAI,GACjF,WAAW,KAAK,EACd,IAAI,CACF,OAAO,aAAa,EAAE,MAAM,UAAU,CAAC,GACvC,OAAO,aAAa;GAAE,MAAM;GAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,MAAM,IAAI;EAAE,CAAC,CACjF,EACF,CAAC;OAED,WAAW,KAAK,OAAO,aAAa,IAAI,CAAC;CAG/C;CACA,OAAO,WAAW,WAAW,IAAIV,sBAAAA,gBAAgB,EAAE,KAAK,WAAW;AACrE;;AAGA,SAAS,uBAAuB,OAAyB;CACvD,IAAI,SAAS,QAAQ,OAAO,UAAU,aAAa,sBAAsB,KAAK,GAAG,OAAO;CACxF,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,MAAM,qBAAqB;CAClE,IAAI,OAAO,UAAU,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK,OAAO,OAAO,OAAO,IAAI,GAAG;EAC9F,MAAM,WAAY,MAA0B;EAC5C,OAAO,YAAY,QAAQ,sBAAsB,QAAQ;CAC3D;CACA,OAAO;AACT;;AAGA,SAAS,sBAAsB,OAAyB;CACtD,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,YAAYW,eAAAA,SAAS,KAAK;AACjF"}
@@ -42,7 +42,7 @@ interface TableBrand<T, Name extends string> extends TableMgmt {
42
42
  * references too. Join pruning follows these references and join dependencies, rather than guessing
43
43
  * which tables a SQL string mentions. It also accounts for select/order/group expressions and keep.
44
44
  *
45
- * I.e. if a joined Author is used only by `a.first_name.eq(name)`, supplying undefined removes that
45
+ * I.e. if a joined Author is used only by `a.firstName.eq(name)`, supplying undefined removes that
46
46
  * predicate and lets the unused join prune. Both APIs share this undefined-condition pruning rule;
47
47
  * they differ in how they get the references: Alias resolves domain conditions against a relationship
48
48
  * tree, while Table renders SQL expressions against explicit sources. Neither caches SQL names on
@@ -137,8 +137,8 @@ interface SubtypeJoin<U extends Entity> extends CollectionJoin<U> {
137
137
  <A extends TableFor<U>>(other: A): LeftJoin<A>;
138
138
  }
139
139
  /**
140
- * A physical FK column expression (`b.author_id` selects/compares the FK) plus a join factory
141
- * (`b.author_id.as(a)` joins). The default join kind follows physical column nullability:
140
+ * A physical FK column expression (`b.authorId` selects/compares the `author_id` FK) plus a join factory
141
+ * (`b.authorId.as(a)` joins). The default join kind follows physical column nullability:
142
142
  * a NOT NULL FK is INNER, a nullable one is LEFT, and the row type reflects it.
143
143
  */
144
144
  interface ReferenceColumn<U extends Entity, N extends null | never, Src extends string> extends EntityColumn<U, N, Src>, ReferenceJoin<U, N> {}
@@ -1 +1 @@
1
- {"version":3,"file":"Tables.d.cts","names":[],"sources":["../src/Tables.ts"],"mappings":";;;;;;;;;iBA8CgB,MAAM,UAAU,QAAQ,MAAM,+BAA+B,KAAK,MAAM;;;;;;;iBAOxE,MAAM,UAAU,QAAQ,qBACtC,MAAM,+BAA+B,IACrC,MAAM,OACL,MAAM,GAAG;;iBAOI,OAAO,mBAAmB,0CACrC,MAAM,OACL,WAAW,IAAI,EAAE,WAAW,qCAAqC,UAAU,UAAU,MAAM;;;;;;;UAUhF,WAAW,GAAG,6BAA6B;WACjD,UAAU;WACV,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BP,MAAM,UAAU,QAAQ,sBAAsB,YAAY,MAAM,WAAW,GAAG,+BACjE,WAAW,GAAG;;EAI/B,MAAM,QAAQ,YAAY,KAAK;;;KAI3B,YAAY,UAAU,aAC/B,KAAK,gBAAgB,WAAW,SAAS,MAAM,SAAS,GAAG;EAC1D;EACA,YAAY,U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WACU;EAArB,YAAqB"}
@@ -42,7 +42,7 @@ interface TableBrand<T, Name extends string> extends TableMgmt {
42
42
  * references too. Join pruning follows these references and join dependencies, rather than guessing
43
43
  * which tables a SQL string mentions. It also accounts for select/order/group expressions and keep.
44
44
  *
45
- * I.e. if a joined Author is used only by `a.first_name.eq(name)`, supplying undefined removes that
45
+ * I.e. if a joined Author is used only by `a.firstName.eq(name)`, supplying undefined removes that
46
46
  * predicate and lets the unused join prune. Both APIs share this undefined-condition pruning rule;
47
47
  * they differ in how they get the references: Alias resolves domain conditions against a relationship
48
48
  * tree, while Table renders SQL expressions against explicit sources. Neither caches SQL names on
@@ -137,8 +137,8 @@ interface SubtypeJoin<U extends Entity> extends CollectionJoin<U> {
137
137
  <A extends TableFor<U>>(other: A): LeftJoin<A>;
138
138
  }
139
139
  /**
140
- * A physical FK column expression (`b.author_id` selects/compares the FK) plus a join factory
141
- * (`b.author_id.as(a)` joins). The default join kind follows physical column nullability:
140
+ * A physical FK column expression (`b.authorId` selects/compares the `author_id` FK) plus a join factory
141
+ * (`b.authorId.as(a)` joins). The default join kind follows physical column nullability:
142
142
  * a NOT NULL FK is INNER, a nullable one is LEFT, and the row type reflects it.
143
143
  */
144
144
  interface ReferenceColumn<U extends Entity, N extends null | never, Src extends string> extends EntityColumn<U, N, Src>, ReferenceJoin<U, N> {}
@@ -1 +1 @@
1
- {"version":3,"file":"Tables.d.mts","names":[],"sources":["../src/Tables.ts"],"mappings":";;;;;;;;;iBA8CgB,MAAM,UAAU,QAAQ,MAAM,+BAA+B,KAAK,MAAM;;;;;;;iBAOxE,MAAM,UAAU,QAAQ,qBACtC,MAAM,+BAA+B,IACrC,MAAM,OACL,MAAM,GAAG;;iBAOI,OAAO,mBAAmB,0CACrC,MAAM,OACL,WAAW,IAAI,EAAE,WAAW,qCAAqC,UAAU,UAAU,MAAM;;;;;;;UAUhF,WAAW,GAAG,6BAA6B;WACjD,UAAU;WACV,QAAQ;;;;;;;;;;;;;;;;;;;;;;;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AQA,MAAM;;;iBAIQ,iBAAiB,UAAU,QAAQ,OAAO,SAAS,KAAK,eAAe;iBAKvE,cAAc,UAAU,QAAQ,MAAM,+BAA+B,KAAK,MAAM;iBA2DhF,QAAQ,eAAe,OAAO;;;;;;cA8XjC;;cAGA;UAEI;EACf,QAAQ;EACR,IAAI;;;cAIO;WACU;EAArB,YAAqB"}
package/build/Tables.js CHANGED
@@ -88,7 +88,7 @@ var TableColumn = class extends BaseExpr {
88
88
  this.column = column;
89
89
  this.mgmt = mgmt;
90
90
  }
91
- /** Author.id, Book.author_id, and Comment.parent_author_id use the same Author ID domain. */
91
+ /** Author.id, Book.authorId, and Comment.parentAuthorId use the same Author ID domain. */
92
92
  get outputType() {
93
93
  return this.column.outputType;
94
94
  }
@@ -420,7 +420,7 @@ var PolyReferenceImpl = class {
420
420
  }
421
421
  /** Returns the physical FK expression for one polymorphic target. */
422
422
  componentColumn(comp) {
423
- const descriptor = this.meta.columns[comp.columnName] ?? fail(`No physical column ${comp.columnName} on ${this.meta.type}`);
423
+ const descriptor = comp.column;
424
424
  return new EntityColumnImpl(this.meta, descriptor, this.mgmt);
425
425
  }
426
426
  };
@@ -500,7 +500,7 @@ var OneToManyJoinImpl = class extends CollectionJoinImpl {
500
500
  joinEntry(kind, other) {
501
501
  const { field } = this;
502
502
  const otherMeta = getTableMetadata(other);
503
- const descriptor = otherMeta.columns[field.otherColumnName];
503
+ const descriptor = Object.values(otherMeta.columns).find((column) => column.columnName === field.otherColumnName);
504
504
  if (!descriptor) return fail(`Cannot join ${getTableMetadata(this.proxy).type}.${field.fieldName} to ${otherMeta.type}: ${field.otherColumnName} is not physically present on ${otherMeta.tableName}; join the base table explicitly`);
505
505
  const on = new EntityColumnImpl(otherMeta, descriptor, other[tableMgmt]).eq(this.proxy.id);
506
506
  const filtered = field.kind === "o2m" ? field.softDeletes !== "include" : field.kind === "lo2m";
@@ -604,7 +604,7 @@ function physicalRelation(meta, key) {
604
604
  const field = [meta, ...getBaseSelfAndSubMetas(getBaseMeta(meta))].find((owner) => owner.tableName === meta.tableName && Object.hasOwn(owner.fields, key))?.fields[key];
605
605
  if (!isRelation(field)) return void 0;
606
606
  if (field?.kind === "m2o" || field?.kind === "poly") {
607
- if (!field.serde.columns.every((binding) => meta.columns[binding.columnName] === binding.column)) return void 0;
607
+ if (!field.serde.columns.every((binding) => Object.values(meta.columns).includes(binding.column))) return void 0;
608
608
  return field.kind === "poly" ? {
609
609
  ...field,
610
610
  components: field.components.map((component) => ({
@@ -633,7 +633,7 @@ function tableWhere(mgmt, filter) {
633
633
  "primitive",
634
634
  "enum",
635
635
  "m2o"
636
- ].includes(field.kind) || !field.serde || field.serde.columns.length !== 1 || !field.serde.columns.every((binding) => meta.columns[binding.columnName] === binding.column)) throw new Error(`Unsupported table filter field ${meta.type}.${key}; use an explicit join`);
636
+ ].includes(field.kind) || !field.serde || field.serde.columns.length !== 1 || !field.serde.columns.every((binding) => Object.values(meta.columns).includes(binding.column))) throw new Error(`Unsupported table filter field ${meta.type}.${key}; use an explicit join`);
637
637
  const column = new TableColumn(meta, field.serde.columns[0].column, mgmt);
638
638
  let leaves;
639
639
  if (field.kind === "m2o") {