joist-core 2.3.0-next.99 → 2.4.0

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.
Files changed (131) hide show
  1. package/build/EntityManager.cjs +1 -1
  2. package/build/EntityManager.cjs.map +1 -1
  3. package/build/EntityManager.d.cts +9 -8
  4. package/build/EntityManager.d.cts.map +1 -1
  5. package/build/EntityManager.d.mts +9 -8
  6. package/build/EntityManager.d.mts.map +1 -1
  7. package/build/EntityManager.js +1 -1
  8. package/build/EntityManager.js.map +1 -1
  9. package/build/dataloaders/findCountDataLoader.cjs +2 -0
  10. package/build/dataloaders/findCountDataLoader.cjs.map +1 -1
  11. package/build/dataloaders/findCountDataLoader.d.cts.map +1 -1
  12. package/build/dataloaders/findCountDataLoader.d.mts.map +1 -1
  13. package/build/dataloaders/findCountDataLoader.js +2 -0
  14. package/build/dataloaders/findCountDataLoader.js.map +1 -1
  15. package/build/dataloaders/findDataLoader.cjs +1 -0
  16. package/build/dataloaders/findDataLoader.cjs.map +1 -1
  17. package/build/dataloaders/findDataLoader.d.cts.map +1 -1
  18. package/build/dataloaders/findDataLoader.d.mts.map +1 -1
  19. package/build/dataloaders/findDataLoader.js +2 -1
  20. package/build/dataloaders/findDataLoader.js.map +1 -1
  21. package/build/dataloaders/findIdsDataLoader.cjs +2 -0
  22. package/build/dataloaders/findIdsDataLoader.cjs.map +1 -1
  23. package/build/dataloaders/findIdsDataLoader.d.cts.map +1 -1
  24. package/build/dataloaders/findIdsDataLoader.d.mts.map +1 -1
  25. package/build/dataloaders/findIdsDataLoader.js +2 -0
  26. package/build/dataloaders/findIdsDataLoader.js.map +1 -1
  27. package/build/dataloaders/findPaginatedDataLoader.cjs +2 -0
  28. package/build/dataloaders/findPaginatedDataLoader.cjs.map +1 -1
  29. package/build/dataloaders/findPaginatedDataLoader.d.cts.map +1 -1
  30. package/build/dataloaders/findPaginatedDataLoader.d.mts.map +1 -1
  31. package/build/dataloaders/findPaginatedDataLoader.js +2 -0
  32. package/build/dataloaders/findPaginatedDataLoader.js.map +1 -1
  33. package/build/index.cjs +6 -3
  34. package/build/index.cjs.map +1 -1
  35. package/build/index.d.cts +6 -4
  36. package/build/index.d.cts.map +1 -1
  37. package/build/index.d.mts +6 -4
  38. package/build/index.d.mts.map +1 -1
  39. package/build/index.js +6 -5
  40. package/build/index.js.map +1 -1
  41. package/build/keys.cjs +6 -1
  42. package/build/keys.cjs.map +1 -1
  43. package/build/keys.d.cts +3 -1
  44. package/build/keys.d.cts.map +1 -1
  45. package/build/keys.d.mts +3 -1
  46. package/build/keys.d.mts.map +1 -1
  47. package/build/keys.js +6 -2
  48. package/build/keys.js.map +1 -1
  49. package/build/queries/find/QueryParser.cjs +1 -2
  50. package/build/queries/find/QueryParser.cjs.map +1 -1
  51. package/build/queries/find/QueryParser.d.cts.map +1 -1
  52. package/build/queries/find/QueryParser.d.mts.map +1 -1
  53. package/build/queries/find/QueryParser.js +2 -3
  54. package/build/queries/find/QueryParser.js.map +1 -1
  55. package/build/queries/find/QueryVisitor.cjs +17 -0
  56. package/build/queries/find/QueryVisitor.cjs.map +1 -1
  57. package/build/queries/find/QueryVisitor.d.cts +3 -1
  58. package/build/queries/find/QueryVisitor.d.cts.map +1 -1
  59. package/build/queries/find/QueryVisitor.d.mts +3 -1
  60. package/build/queries/find/QueryVisitor.d.mts.map +1 -1
  61. package/build/queries/find/QueryVisitor.js +17 -1
  62. package/build/queries/find/QueryVisitor.js.map +1 -1
  63. package/build/queries/sql/Expr.cjs +18 -1
  64. package/build/queries/sql/Expr.cjs.map +1 -1
  65. package/build/queries/sql/Expr.d.cts +13 -3
  66. package/build/queries/sql/Expr.d.cts.map +1 -1
  67. package/build/queries/sql/Expr.d.mts +13 -3
  68. package/build/queries/sql/Expr.d.mts.map +1 -1
  69. package/build/queries/sql/Expr.js +18 -2
  70. package/build/queries/sql/Expr.js.map +1 -1
  71. package/build/queries/sql/JoinTree.cjs +72 -0
  72. package/build/queries/sql/JoinTree.cjs.map +1 -0
  73. package/build/queries/sql/JoinTree.d.cts +107 -0
  74. package/build/queries/sql/JoinTree.d.cts.map +1 -0
  75. package/build/queries/sql/JoinTree.d.mts +107 -0
  76. package/build/queries/sql/JoinTree.d.mts.map +1 -0
  77. package/build/queries/sql/JoinTree.js +71 -0
  78. package/build/queries/sql/JoinTree.js.map +1 -0
  79. package/build/queries/sql/Tables.cjs +103 -6
  80. package/build/queries/sql/Tables.cjs.map +1 -1
  81. package/build/queries/sql/Tables.d.cts +72 -13
  82. package/build/queries/sql/Tables.d.cts.map +1 -1
  83. package/build/queries/sql/Tables.d.mts +72 -13
  84. package/build/queries/sql/Tables.d.mts.map +1 -1
  85. package/build/queries/sql/Tables.js +101 -10
  86. package/build/queries/sql/Tables.js.map +1 -1
  87. package/build/queries/sql/custom.cjs +52 -0
  88. package/build/queries/sql/custom.cjs.map +1 -0
  89. package/build/queries/sql/custom.d.cts +85 -0
  90. package/build/queries/sql/custom.d.cts.map +1 -0
  91. package/build/queries/sql/custom.d.mts +85 -0
  92. package/build/queries/sql/custom.d.mts.map +1 -0
  93. package/build/queries/sql/custom.js +49 -0
  94. package/build/queries/sql/custom.js.map +1 -0
  95. package/build/queries/sql/execute.cjs +68 -28
  96. package/build/queries/sql/execute.cjs.map +1 -1
  97. package/build/queries/sql/execute.d.cts +110 -11
  98. package/build/queries/sql/execute.d.cts.map +1 -1
  99. package/build/queries/sql/execute.d.mts +110 -11
  100. package/build/queries/sql/execute.d.mts.map +1 -1
  101. package/build/queries/sql/execute.js +69 -29
  102. package/build/queries/sql/execute.js.map +1 -1
  103. package/build/queries/sql/expressions/types.d.cts +5 -5
  104. package/build/queries/sql/expressions/types.d.cts.map +1 -1
  105. package/build/queries/sql/expressions/types.d.mts +5 -5
  106. package/build/queries/sql/expressions/types.d.mts.map +1 -1
  107. package/build/queries/sql/keywords.cjs +1 -1
  108. package/build/queries/sql/keywords.cjs.map +1 -1
  109. package/build/queries/sql/keywords.d.cts +1 -1
  110. package/build/queries/sql/keywords.d.mts +1 -1
  111. package/build/queries/sql/keywords.js +1 -1
  112. package/build/queries/sql/keywords.js.map +1 -1
  113. package/build/queries/sql/query.cjs +100 -38
  114. package/build/queries/sql/query.cjs.map +1 -1
  115. package/build/queries/sql/query.d.cts +96 -46
  116. package/build/queries/sql/query.d.cts.map +1 -1
  117. package/build/queries/sql/query.d.mts +96 -46
  118. package/build/queries/sql/query.d.mts.map +1 -1
  119. package/build/queries/sql/query.js +102 -40
  120. package/build/queries/sql/query.js.map +1 -1
  121. package/build/queries/valueFilters.cjs +28 -36
  122. package/build/queries/valueFilters.cjs.map +1 -1
  123. package/build/queries/valueFilters.d.cts +2 -4
  124. package/build/queries/valueFilters.d.cts.map +1 -1
  125. package/build/queries/valueFilters.d.mts +2 -4
  126. package/build/queries/valueFilters.d.mts.map +1 -1
  127. package/build/queries/valueFilters.js +29 -36
  128. package/build/queries/valueFilters.js.map +1 -1
  129. package/build/serde/serde.cjs.map +1 -1
  130. package/build/serde/serde.js.map +1 -1
  131. package/package.json +2 -2
@@ -8,11 +8,12 @@ const require_utils = require("../../utils.cjs");
8
8
  const require_configure = require("../../configure.cjs");
9
9
  const require_EntityMetadata = require("../../EntityMetadata.cjs");
10
10
  const require_queries_renderConditions = require("../renderConditions.cjs");
11
+ const require_queries_sql_custom = require("./custom.cjs");
11
12
  const require_Entity = require("../../Entity.cjs");
12
13
  let joist_utils = require("joist-utils");
13
14
  //#region src/queries/sql/Tables.ts
14
15
  function table(cstr, _name) {
15
- return newTableProxy(cstr);
16
+ return require_queries_sql_custom.isCustomTableDefinition(cstr) ? newCustomTableProxy(cstr) : newTableProxy(cstr);
16
17
  }
17
18
  /** Creates multiple physical table handles. */
18
19
  function tables(...type) {
@@ -21,9 +22,14 @@ function tables(...type) {
21
22
  /** The source of a default reference join, used to inherit optional paths within each query. */
22
23
  const referenceJoinSource = Symbol("joist.referenceJoinSource");
23
24
  const tableMgmt = Symbol("tableMgmt");
25
+ const inQueryCondition = Symbol("joist.inQueryCondition");
24
26
  function getTableMgmt(table) {
25
27
  return table[tableMgmt];
26
28
  }
29
+ /** Qualifies custom tables without changing SQL for tables on the default search path. */
30
+ function tableSqlName(table) {
31
+ return table.schema ? `${require_queries_sql_keywords.safeKq(table.schema)}.${require_queries_sql_keywords.kq(table.tableName)}` : require_queries_sql_keywords.kq(table.tableName);
32
+ }
27
33
  /** Returns the metadata for the entity that `table` is bound to. */
28
34
  function getTableMetadata(table) {
29
35
  return table[tableMgmt].meta;
@@ -41,7 +47,7 @@ function newTableProxy(cstr) {
41
47
  if (key === tableMgmt) return mgmt;
42
48
  if (typeof key !== "string") return void 0;
43
49
  const descriptor = Object.hasOwn(meta.columns, key) ? meta.columns[key] : void 0;
44
- if (descriptor) return descriptor.idMetadata && key !== "id" ? new EntityColumnImpl(meta, descriptor, mgmt) : new PrimitiveColumnImpl(meta, descriptor, mgmt);
50
+ if (descriptor) return descriptor.idMetadata ? new EntityColumnImpl(meta, descriptor, mgmt, key) : new PrimitiveColumnImpl(meta, descriptor, mgmt, key);
45
51
  const subtype = subtypes.get(key);
46
52
  if (subtype) {
47
53
  const join = new SubtypeJoinImpl(proxy, subtype);
@@ -53,6 +59,7 @@ function newTableProxy(cstr) {
53
59
  }
54
60
  const relation = physicalRelation(meta, key);
55
61
  if (key === "where" && !isRelation(meta.allFields[key])) return (filter) => tableWhere(mgmt, filter);
62
+ if (key === "column" && !isRelation(meta.allFields[key])) return (column) => new require_queries_sql_Expr.RefExpr(mgmt, column);
56
63
  const field = relation ?? require_utils.fail(`No physical field ${key} on ${cstr.name}; join its base table explicitly`);
57
64
  switch (field.kind) {
58
65
  case "m2o": return new ReferenceJoinImpl(new EntityColumnImpl(meta, field.serde.columns[0].column, mgmt));
@@ -65,13 +72,43 @@ function newTableProxy(cstr) {
65
72
  }
66
73
  },
67
74
  has(_, key) {
68
- return key === tableMgmt || typeof key === "string" && (key === "where" || Object.hasOwn(meta.columns, key) || !!physicalRelation(meta, key) || subtypes.has(key));
75
+ return key === tableMgmt || typeof key === "string" && (key === "where" || key === "column" || Object.hasOwn(meta.columns, key) || !!physicalRelation(meta, key) || subtypes.has(key));
69
76
  }
70
77
  });
71
78
  return proxy;
72
79
  }
80
+ /** Creates a typed handle for primitive columns declared outside Joist codegen. */
81
+ function newCustomTableProxy(definition) {
82
+ const { tableName, schema, columns } = require_queries_sql_custom.getCustomTableDefinition(definition);
83
+ const mgmt = {
84
+ tableName,
85
+ schema,
86
+ columns
87
+ };
88
+ return new Proxy({}, {
89
+ get(_, key) {
90
+ if (key === tableMgmt) return mgmt;
91
+ if (typeof key !== "string") return void 0;
92
+ const descriptor = Object.hasOwn(columns, key) ? columns[key] : void 0;
93
+ if (descriptor) return new PrimitiveColumnImpl(void 0, descriptor, mgmt, key);
94
+ if (key === "column") return (column) => new require_queries_sql_Expr.RefExpr(mgmt, column);
95
+ return require_utils.fail(`Custom table ${tableName} has no declared column ${key}; use .column("${key}")`);
96
+ },
97
+ has(_, key) {
98
+ return key === tableMgmt || key === "column" || typeof key === "string" && Object.hasOwn(columns, key);
99
+ }
100
+ });
101
+ }
73
102
  function isTable(obj) {
74
- return typeof obj === "function" && tableMgmt in obj;
103
+ return (typeof obj === "function" || typeof obj === "object" && obj !== null) && tableMgmt in obj;
104
+ }
105
+ /** Whether a physical table has generated entity metadata. */
106
+ function isEntityTable(obj) {
107
+ return isTable(obj) && "meta" in obj[tableMgmt];
108
+ }
109
+ /** Whether a physical table has columns declared through `declareTable`. */
110
+ function isCustomTable(obj) {
111
+ return isTable(obj) && "columns" in obj[tableMgmt];
75
112
  }
76
113
  /**
77
114
  * A physical table column implements `Expr`: it renders as `alias."column"`, decodes result
@@ -81,11 +118,16 @@ var TableColumn = class extends require_queries_sql_Expr.BaseExpr {
81
118
  meta;
82
119
  column;
83
120
  mgmt;
84
- constructor(meta, column, mgmt) {
121
+ selectKey;
122
+ constructor(meta, column, mgmt, selectKey = column.columnName) {
85
123
  super();
86
124
  this.meta = meta;
87
125
  this.column = column;
88
126
  this.mgmt = mgmt;
127
+ this.selectKey = selectKey;
128
+ }
129
+ get [require_queries_sql_Expr.selectKeyBrand]() {
130
+ return this.selectKey;
89
131
  }
90
132
  /** Author.id, Book.authorId, and Comment.parentAuthorId use the same Author ID domain. */
91
133
  get outputType() {
@@ -283,10 +325,18 @@ var PrimitiveColumnImpl = class extends TableColumn {
283
325
  }
284
326
  };
285
327
  var EntityColumnImpl = class extends TableColumn {
328
+ /** Uses the ID target's tag, including for foreign keys and polymorphic components. */
329
+ taggedId() {
330
+ return new TaggedIdExpr(this);
331
+ }
286
332
  in(values) {
287
333
  if (values === void 0) return require_queries_skipCondition.skipCondition;
288
334
  else if (values === null) throw new Error("Unsupported");
289
335
  else if (require_queries_sql_Expr.isExpr(values)) return this.inList("IN", values);
336
+ else if (!Array.isArray(values)) return { [inQueryCondition]: {
337
+ column: this,
338
+ query: values
339
+ } };
290
340
  else if (values.includes(null)) return { or: [this.addCondition({ kind: "is-null" }), this.addCondition({
291
341
  kind: "in",
292
342
  value: values.filter((v) => v !== null)
@@ -354,6 +404,36 @@ var EntityColumnImpl = class extends TableColumn {
354
404
  });
355
405
  }
356
406
  };
407
+ /** Converts a physical ID to SQL text so nested SQL expressions also receive the tag. */
408
+ var TaggedIdExpr = class extends require_queries_sql_Expr.BaseExpr {
409
+ column;
410
+ constructor(column) {
411
+ super();
412
+ this.column = column;
413
+ }
414
+ toSql(ctx) {
415
+ const fragment = this.column.toSql(ctx);
416
+ const meta = this.column.idMetadata ?? require_utils.fail("Tagged IDs require an ID column");
417
+ return {
418
+ ...fragment,
419
+ sql: `(? || ${fragment.sql}::text)`,
420
+ bindings: [require_keys.taggedIdPrefix(meta), ...fragment.bindings]
421
+ };
422
+ }
423
+ get outputType() {
424
+ return {
425
+ dbType: "text",
426
+ domain: String,
427
+ arrayElementSafe: true
428
+ };
429
+ }
430
+ get sqlNullable() {
431
+ return this.column.sqlNullable;
432
+ }
433
+ get sqlSource() {
434
+ return this.column.sqlSource;
435
+ }
436
+ };
357
437
  var PolyReferenceImpl = class {
358
438
  meta;
359
439
  mgmt;
@@ -582,7 +662,7 @@ var ManyToManyJoinImpl = class extends CollectionJoinImpl {
582
662
  };
583
663
  /** Fails fast when a join factory is passed something other than a table. */
584
664
  function requireTable(other) {
585
- if (!isTable(other)) return require_utils.fail(`Expected a table to join, got ${other}`);
665
+ if (!isEntityTable(other)) return require_utils.fail(`Expected an entity table to join, got ${other}`);
586
666
  return other;
587
667
  }
588
668
  /** The id column of a joined table, for building sugar ON conditions. */
@@ -676,6 +756,17 @@ function tableWhere(mgmt, filter) {
676
756
  }
677
757
  return conditions.length === 0 ? require_queries_skipCondition.skipCondition : { and: conditions };
678
758
  }
759
+ /**
760
+ * Converts relationship filters into conditions on the joined table's id column.
761
+ * I.e. Author's `join: { books: "b:1" }` filters Book.id to 1; `{ books: book }` uses book.id.
762
+ * Lists match any supplied ID, `true` requires a Book, and `null` or `false` requires no Book.
763
+ */
764
+ function tableEntityWhere(mgmt, value) {
765
+ const parsed = require_queries_valueFilters.parseEntityFilter(mgmt.meta, value);
766
+ if (!parsed) return require_queries_skipCondition.skipCondition;
767
+ if (parsed.kind === "join") require_utils.fail(`Expected an entity or ID filter for ${mgmt.meta.type}`);
768
+ return new TableColumn(mgmt.meta, mgmt.meta.fields.id.serde.columns[0].column, mgmt).addCondition(parsed);
769
+ }
679
770
  /** Rejects nested relations, scopes, and aliases before parsing owning-reference values. */
680
771
  function isTableReferenceFilter(value) {
681
772
  if (value == null || typeof value === "boolean" || isTableReferenceValue(value)) return true;
@@ -695,12 +786,18 @@ exports.JoinTableHandle = JoinTableHandle;
695
786
  exports.collectionJoin = collectionJoin;
696
787
  exports.getTableMetadata = getTableMetadata;
697
788
  exports.getTableMgmt = getTableMgmt;
789
+ exports.inQueryCondition = inQueryCondition;
790
+ exports.isCustomTable = isCustomTable;
791
+ exports.isEntityTable = isEntityTable;
698
792
  exports.isTable = isTable;
699
793
  exports.m2mJoinTable = m2mJoinTable;
700
794
  exports.newTableProxy = newTableProxy;
701
795
  exports.referenceJoinSource = referenceJoinSource;
702
796
  exports.table = table;
797
+ exports.tableEntityWhere = tableEntityWhere;
703
798
  exports.tableMgmt = tableMgmt;
799
+ exports.tableSqlName = tableSqlName;
800
+ exports.tableWhere = tableWhere;
704
801
  exports.tables = tables;
705
802
 
706
803
  //# sourceMappingURL=Tables.cjs.map
@@ -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/queries/sql/Tables.ts"],"sourcesContent":["import { groupBy } from \"joist-utils\";\n// Load configure first: otherwise the built cjs/esm module graph evaluates relations/* before their\n// base classes exist (\"Class extends value undefined\").\nimport { getConstructorFromTaggedId } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport type { IdOf, MaybeAbstractEntityConstructor, TaggedId } from \"src/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 \"src/EntityMetadata.ts\";\nimport { maybeResolveReferenceToId, toIdOf } from \"src/keys.ts\";\nimport type { SqlCondition } from \"src/queries/conditions.ts\";\nimport type { ParsedValueFilter } from \"src/queries/parsedConditions.ts\";\nimport { buildValueCondition } from \"src/queries/renderConditions.ts\";\nimport { skipCondition } from \"src/queries/skipCondition.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 \"src/queries/sql/Expr.ts\";\nimport { kqDot } from \"src/queries/sql/keywords.ts\";\nimport { makeLike, mapToDb, parseEntityFilter, parseValueFilter } from \"src/queries/valueFilters.ts\";\nimport type { Column } from \"src/serde/columns.ts\";\nimport type { TypeInfo } from \"src/serde/TypeInfo.ts\";\nimport type { ColumnsOf, FieldsOf, FilterOf, TypeMap, TypeNameOf } from \"src/typeMap.ts\";\nimport { fail } from \"src/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): unknown {\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, Name>\n : FieldsOf<T>[P] extends { kind: \"poly\"; type: infer U extends Entity; nullable: infer N }\n ? PolyReference<U, N extends undefined ? null : never, Name>\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/** Provides fluent methods for creating joins through an owning reference relationship. */\nexport interface ReferenceJoin<U extends Entity, N extends null | never, Src extends string = string> {\n /**\n * Required reference joins like `b.author.as(a)` are INNER unless `b` is already a LEFT-joined alias.\n * Nullable references are always LEFT joined.\n */\n as<A extends TableFor<U>>(other: A): [N] extends [never] ? DefaultReferenceJoin<A, Src> : 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/** The source of a default reference join, used to inherit optional paths within each query. */\nexport const referenceJoinSource: unique symbol = Symbol(\"joist.referenceJoinSource\");\n\n/** A required reference defaults to INNER unless its source was LEFT joined. */\nexport type DefaultReferenceJoin<A, Src extends string> = InnerJoin<A> & {\n readonly [referenceJoinSource]: Src;\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 unless its source was LEFT joined, 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, Src> {}\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<\n U extends Entity,\n N extends null | never,\n Src extends string = string,\n> extends ReferenceJoin<U, N, Src> {\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: readonly (U | TaggedId)[] | ExprLike<IdOf<U> | null> | undefined): SqlCondition;\n /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (U | TaggedId)[] | 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 /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (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 /** Applies an IN condition unless the list is empty, null, or undefined. */\n inNonEmpty(value: readonly (T | 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 /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (V | null)[] | undefined): SqlCondition {\n return values === undefined || values.length === 0 ? skipCondition : this.in(values);\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 /** Applies an IN condition unless the list is empty, null, or undefined. */\n inNonEmpty(values: readonly (T | IdOf<T> | null)[] | null | undefined): SqlCondition {\n return values === null || values === undefined || values.length === 0 ? skipCondition : this.in(values);\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 via this FK, inheriting the source's LEFT join for otherwise required references. */\n as(other: object): object {\n return {\n ...this.joinEntry(this.sqlNullable === false ? \"inner\" : \"left\", other),\n [referenceJoinSource]: this.mgmt,\n };\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: readonly (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 /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (T | TaggedId)[] | undefined): SqlCondition {\n return values === undefined || values.length === 0 ? skipCondition : this.in(values);\n }\n\n /** Joins via this poly's component, inheriting the source's LEFT join when the poly is required. */\n as(other: object): object {\n return { ...this.joinEntry(this.field.required ? \"inner\" : \"left\", other), [referenceJoinSource]: this.mgmt };\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.as(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":";;;;;;;;;;;;;AAwDA,SAAgB,MAAwB,MAAyC,OAAyB;CAExG,OAAO,cAAc,IAAI;AAC3B;;AAGA,SAAgB,OACd,GAAG,MACyG;CAC5G,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC,CAAC;AACzC;;AAyHA,MAAa,sBAAqC,OAAO,2BAA2B;AAgIpF,MAAa,YAAY,OAAO,WAAW;AAE3C,SAAgB,aAAa,OAAqC;CAChE,OAAO,MAAM;A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MAAM,QAAQ,MAAM,MAAM,IAAI;EAAE,CAAC,CACjF,EACF,CAAC;OAED,WAAW,KAAK,OAAO,aAAa,IAAI,CAAC;CAG/C;CACA,OAAO,WAAW,WAAW,IAAIV,8BAAAA,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":["isCustomTableDefinition","safeKq","kq","getMetadata","RefExpr","fail","getCustomTableDefinition","BaseExpr","selectKeyBrand","kqDot","toIdOf","mapToDb","deferredCondition","buildValueCondition","isExpr","skipCondition","makeLike","taggedIdPrefix","groupBy","getConstructorFromTaggedId","maybeResolveReferenceToId","asNode","getBaseAndSelfMetas","getBaseSelfAndSubMetas","getBaseMeta","parseEntityFilter","parseValueFilter","isEntity"],"sources":["../../../src/queries/sql/Tables.ts"],"sourcesContent":["import { groupBy } from \"joist-utils\";\n// Load configure first: otherwise the built cjs/esm module graph evaluates relations/* before their\n// base classes exist (\"Class extends value undefined\").\nimport { getConstructorFromTaggedId } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport type { IdOf, MaybeAbstractEntityConstructor, TaggedId } from \"src/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 \"src/EntityMetadata.ts\";\nimport { maybeResolveReferenceToId, taggedIdPrefix, toIdOf } from \"src/keys.ts\";\nimport type { SqlCondition } from \"src/queries/conditions.ts\";\nimport type { ParsedValueFilter } from \"src/queries/parsedConditions.ts\";\nimport { buildValueCondition } from \"src/queries/renderConditions.ts\";\nimport { skipCondition } from \"src/queries/skipCondition.ts\";\nimport {\n type CustomColumnInputs,\n type CustomTable,\n type CustomTableDefinition,\n type CustomTableFor,\n type CustomTableMgmt,\n getCustomTableDefinition,\n isCustomTableDefinition,\n} from \"src/queries/sql/custom.ts\";\nimport {\n BaseExpr,\n type Expr,\n type ExprContext,\n type ExprLike,\n type InnerJoin,\n type LeftJoin,\n RefExpr,\n type SqlFragment,\n asNode,\n deferredCondition,\n isExpr,\n selectKeyBrand,\n} from \"src/queries/sql/Expr.ts\";\nimport { kq, kqDot, safeKq } from \"src/queries/sql/keywords.ts\";\nimport type { QueryArg, QueryJoinInput, QuerySource } from \"src/queries/sql/query.ts\";\nimport { makeLike, mapToDb, parseEntityFilter, parseValueFilter } from \"src/queries/valueFilters.ts\";\nimport type { Column } from \"src/serde/columns.ts\";\nimport type { TypeInfo } from \"src/serde/TypeInfo.ts\";\nimport type { ColumnsOf, FieldsOf, FilterOf, TypeMap, TypeNameOf } from \"src/typeMap.ts\";\nimport { fail } from \"src/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/** Creates a typed physical handle for a table declared with `declareTable`. */\nexport function table<TableName extends string, C extends CustomColumnInputs>(\n definition: CustomTableDefinition<TableName, C>,\n): CustomTable<C, TableName>;\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>;\n/** Creates a named custom-table handle for joins and self-joins. */\nexport function table<C extends CustomColumnInputs, TableName extends string, Name extends string>(\n definition: CustomTableDefinition<TableName, C>,\n name: Name,\n): CustomTable<C, Name>;\nexport function table<T extends Entity>(\n cstr: MaybeAbstractEntityConstructor<T> | CustomTableDefinition<string, CustomColumnInputs>,\n _name?: string,\n): unknown {\n // The name only exists at the type level; the SQL alias is still assigned by the query parser\n return isCustomTableDefinition(cstr) ? newCustomTableProxy(cstr) : 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 TableSourceBrand<Name extends string> extends TableSourceMgmt {\n readonly __name: Name;\n}\n\n/** A modeled table source that can hydrate its generated entity type. */\nexport interface TableBrand<T, Name extends string> extends TableSourceBrand<Name>, TableMgmt {\n readonly __entity: T;\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 (\"column\" extends keyof TableShape<T, Name>\n ? {}\n : {\n /**\n * References a column Joist does not model, i.e. `a.column<string>(\"ts_search\")`.\n *\n * The expression keeps this table's source key, so it is scope-checked and nullified by a\n * LEFT join like any modeled column. `R` is unchecked: it asserts what the database returns,\n * and the value is not decoded through a codec.\n *\n * A schema that has its own `column` column or relation keeps that meaning, and then has no\n * escape hatch for unmodeled columns.\n */\n column<R = unknown>(column: string): Expr<R, Name>;\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\n/** Maps an entity's columns and relationships to expressions and joins for one typed table handle. */\ntype TableShape<T extends Entity, Name extends string> = {\n readonly [tableMgmt]: TableBrand<T, Name>;\n} & {\n // Add typed expressions for each physical column, including its property name for array selects.\n [P in keyof ColumnsOf<T> & string]: P extends \"id\"\n ? EntityColumn<T, never, Name, P>\n : ColumnsOf<T>[P] extends { entity: infer U extends Entity; nullable: infer N }\n ? ReferenceColumn<U, N extends true ? null : never, Name, P>\n : ColumnsOf<T>[P] extends { type: infer V; nullable: infer N }\n ? PrimitiveColumn<V, N extends true ? null : never, Name, P>\n : never;\n} & {\n // Add relation join sugar such as `a.books.as(b)` for fields that are not physical columns.\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, Name>\n : FieldsOf<T>[P] extends { kind: \"poly\"; type: infer U extends Entity; nullable: infer N }\n ? PolyReference<U, N extends undefined ? null : never, Name>\n : FieldsOf<T>[P] extends { kind: \"o2m\" | \"lo2m\" | \"m2m\" | \"o2o\"; type: infer U extends Entity }\n ? CollectionJoin<U>\n : never;\n} & {\n // Add subtype join sugar such as `p.smallPublisher(sp)` for entities whose __type root is T.\n // CTI joins the physical tables by ID; STI self-joins the shared table by ID plus its discriminator.\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/** Provides fluent methods for creating joins through an owning reference relationship. */\nexport interface ReferenceJoin<U extends Entity, N extends null | never, Src extends string = string> {\n /**\n * Required reference joins like `b.author.as(a)` are INNER unless `b` is already a LEFT-joined alias.\n * Nullable references are always LEFT joined.\n */\n as<A extends TableFor<U>>(other: A): [N] extends [never] ? DefaultReferenceJoin<A, Src> : 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/** The source of a default reference join, used to inherit optional paths within each query. */\nexport const referenceJoinSource: unique symbol = Symbol(\"joist.referenceJoinSource\");\n\n/** A required reference defaults to INNER unless its source was LEFT joined. */\nexport type DefaultReferenceJoin<A, Src extends string> = InnerJoin<A> & {\n readonly [referenceJoinSource]: Src;\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 unless its source was LEFT joined, a nullable one is LEFT, and the row type reflects it.\n */\nexport interface ReferenceColumn<\n U extends Entity,\n N extends null | never,\n Src extends string,\n Key extends string = string,\n>\n extends EntityColumn<U, N, Src, Key>, ReferenceJoin<U, N, Src> {}\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<\n U extends Entity,\n N extends null | never,\n Src extends string = string,\n> extends ReferenceJoin<U, N, Src> {\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: readonly (U | TaggedId)[] | ExprLike<IdOf<U> | null> | undefined): SqlCondition;\n /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (U | TaggedId)[] | undefined): SqlCondition;\n}\n\nexport interface PrimitiveColumn<\n V,\n N extends null | never,\n Src extends string = string,\n Key extends string = string,\n> extends Expr<V | N, Src> {\n readonly [selectKeyBrand]: Key;\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 /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (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<\n T,\n N extends null | never = never,\n Src extends string = string,\n Key extends string = string,\n> extends Expr<IdOf<T> | N, Src> {\n readonly [selectKeyBrand]: Key;\n /** Produces the tagged ID as SQL text, preserving NULL and the column's source. */\n taggedId(): Expr<string | N, Src>;\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<\n F extends QuerySource,\n const S extends ExprLike<IdOf<T> | null>,\n J extends QueryJoinInput = [],\n Name extends string = \"?\",\n >(\n value: QueryArg<F, S, J, Name>,\n ): SqlCondition;\n in(value: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n /** Applies an IN condition unless the list is empty, null, or undefined. */\n inNonEmpty(value: readonly (T | 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\");\nexport const inQueryCondition: unique symbol = Symbol(\"joist.inQueryCondition\");\n\n/** Defers a direct IN query literal to query.ts, which owns query pruning and SQL generation. */\nexport interface InQueryCondition {\n readonly [inQueryCondition]: { column: BaseExpr; query: object };\n}\n\nexport function getTableMgmt<T extends Entity>(table: TableFor<T>): TableMgmt;\nexport function getTableMgmt(table: CustomTableFor): CustomTableMgmt;\nexport function getTableMgmt(table: TableFor<Entity> | CustomTableFor): TableSourceMgmt;\nexport function getTableMgmt(table: TableFor<Entity> | CustomTableFor): TableSourceMgmt {\n return table[tableMgmt];\n}\n\n/** The identity SQL queries bind a table by, plus its original entity metadata. */\nexport interface TableSourceMgmt {\n tableName: string;\n schema?: string;\n}\n\n/** Qualifies custom tables without changing SQL for tables on the default search path. */\nexport function tableSqlName(table: TableSourceMgmt): string {\n return table.schema ? `${safeKq(table.schema)}.${kq(table.tableName)}` : kq(table.tableName);\n}\n\n/** The identity and generated metadata of a modeled entity table. */\nexport interface TableMgmt extends TableSourceMgmt {\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\n ? new EntityColumnImpl(meta, descriptor, mgmt, key)\n : new PrimitiveColumnImpl(meta, descriptor, mgmt, key);\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 if (key === \"column\" && !isRelation(meta.allFields[key])) {\n return (column: string) => new RefExpr(mgmt, column);\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\" ||\n key === \"column\" ||\n Object.hasOwn(meta.columns, key) ||\n !!physicalRelation(meta, key) ||\n subtypes.has(key)))\n );\n },\n });\n return proxy;\n}\n\n/** Creates a typed handle for primitive columns declared outside Joist codegen. */\nfunction newCustomTableProxy<TableName extends string, C extends CustomColumnInputs>(\n definition: CustomTableDefinition<TableName, C>,\n): CustomTable<C, TableName> {\n const { tableName, schema, columns } = getCustomTableDefinition(definition);\n const mgmt: CustomTableMgmt = { tableName, schema, columns };\n return new Proxy(\n {},\n {\n get(_, key: PropertyKey): unknown {\n if (key === tableMgmt) return mgmt;\n if (typeof key !== \"string\") return undefined;\n const descriptor = Object.hasOwn(columns, key) ? columns[key] : undefined;\n if (descriptor) return new PrimitiveColumnImpl(undefined, descriptor, mgmt, key);\n if (key === \"column\") return (column: string) => new RefExpr(mgmt, column);\n return fail(`Custom table ${tableName} has no declared column ${key}; use .column(\"${key}\")`);\n },\n has(_, key): boolean {\n return key === tableMgmt || key === \"column\" || (typeof key === \"string\" && Object.hasOwn(columns, key));\n },\n },\n ) as CustomTable<C, TableName>;\n}\n\nexport function isTable(obj: unknown): obj is Table<any, any> | CustomTableFor {\n return (typeof obj === \"function\" || (typeof obj === \"object\" && obj !== null)) && tableMgmt in obj;\n}\n\n/** Whether a physical table has generated entity metadata. */\nexport function isEntityTable(obj: unknown): obj is Table<any, any> {\n return isTable(obj) && \"meta\" in obj[tableMgmt];\n}\n\n/** Whether a physical table has columns declared through `declareTable`. */\nexport function isCustomTable(obj: unknown): obj is CustomTableFor {\n return isTable(obj) && \"columns\" in obj[tableMgmt];\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 | undefined,\n readonly column: Column,\n readonly mgmt: TableSourceMgmt,\n private readonly selectKey: string = column.columnName,\n ) {\n super();\n }\n\n get [selectKeyBrand](): string {\n return this.selectKey;\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 /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (V | null)[] | undefined): SqlCondition {\n return values === undefined || values.length === 0 ? skipCondition : this.in(values);\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 /** Uses the ID target's tag, including for foreign keys and polymorphic components. */\n taggedId(): Expr<string, string> {\n return new TaggedIdExpr(this) as unknown as Expr<string, string>;\n }\n\n in<\n F extends QuerySource,\n const S extends ExprLike<IdOf<T> | null>,\n J extends QueryJoinInput = [],\n Name extends string = \"?\",\n >(values: QueryArg<F, S, J, Name>): SqlCondition;\n in(values: readonly (T | IdOf<T> | null)[] | ExprLike<IdOf<T> | null> | null | undefined): SqlCondition;\n in(values: object | 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 (!Array.isArray(values)) {\n return { [inQueryCondition]: { column: this, query: values } } as unknown as SqlCondition;\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 /** Applies an IN condition unless the list is empty, null, or undefined. */\n inNonEmpty(values: readonly (T | IdOf<T> | null)[] | null | undefined): SqlCondition {\n return values === null || values === undefined || values.length === 0 ? skipCondition : this.in(values);\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 via this FK, inheriting the source's LEFT join for otherwise required references. */\n as(other: object): object {\n return {\n ...this.joinEntry(this.sqlNullable === false ? \"inner\" : \"left\", other),\n [referenceJoinSource]: this.mgmt,\n };\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\n/** Converts a physical ID to SQL text so nested SQL expressions also receive the tag. */\nclass TaggedIdExpr extends BaseExpr {\n constructor(private column: TableColumn) {\n super();\n }\n\n toSql(ctx: ExprContext): SqlFragment {\n const fragment = this.column.toSql(ctx);\n const meta = this.column.idMetadata ?? fail(\"Tagged IDs require an ID column\");\n return {\n ...fragment,\n sql: `(? || ${fragment.sql}::text)`,\n bindings: [taggedIdPrefix(meta), ...fragment.bindings],\n };\n }\n\n get outputType(): TypeInfo {\n return { dbType: \"text\", domain: String, arrayElementSafe: true };\n }\n\n get sqlNullable(): boolean | undefined {\n return this.column.sqlNullable;\n }\n\n get sqlSource(): object {\n return this.column.sqlSource;\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: readonly (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 /** Applies an IN condition unless the list is empty or undefined. */\n inNonEmpty(values: readonly (T | TaggedId)[] | undefined): SqlCondition {\n return values === undefined || values.length === 0 ? skipCondition : this.in(values);\n }\n\n /** Joins via this poly's component, inheriting the source's LEFT join when the poly is required. */\n as(other: object): object {\n return { ...this.joinEntry(this.field.required ? \"inner\" : \"left\", other), [referenceJoinSource]: this.mgmt };\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 (!isEntityTable(other)) return fail(`Expected an entity 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.as(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 */\nexport function 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/**\n * Converts relationship filters into conditions on the joined table's id column.\n * I.e. Author's `join: { books: \"b:1\" }` filters Book.id to 1; `{ books: book }` uses book.id.\n * Lists match any supplied ID, `true` requires a Book, and `null` or `false` requires no Book.\n */\nexport function tableEntityWhere(mgmt: TableMgmt, value: unknown): SqlCondition {\n const parsed = parseEntityFilter(mgmt.meta, value);\n if (!parsed) return skipCondition;\n if (parsed.kind === \"join\") fail(`Expected an entity or ID filter for ${mgmt.meta.type}`);\n return new TableColumn(mgmt.meta, mgmt.meta.fields.id.serde!.columns[0].column, mgmt).addCondition(parsed);\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":";;;;;;;;;;;;;;AA6EA,SAAgB,MACd,MACA,OACS;CAET,OAAOA,2BAAAA,wBAAwB,IAAI,IAAI,oBAAoB,IAAI,IAAI,cAAc,IAAI;AACvF;;AAGA,SAAgB,OACd,GAAG,MACyG;CAC5G,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC,CAAC;AACzC;;AAiJA,MAAa,sBAAqC,OAAO,2BAA2B;AAwJpF,MAAa,YAAY,OAAO,WAAW;AAC3C,MAAa,mBAAkC,OAAO,wBAAwB;AAU9E,SAAgB,aAAa,OAA2D;CACtF,OAAO,MAAM;AACf;;AASA,SAAgB,aAAa,OAAgC;CAC3D,OAAO,MAAM,SAAS,GAAGC,6BAAAA,OAAO,MAAM,MAAM,EAAE,GAAGC,6BAAAA,GAAG,MAAM,SAAS,MAAMA,6BAAAA,GAAG,MAAM,SAAS;AAC7F;;AAeA,SAAgB,iBAAmC,OAAuC;CAExF,OADa,MAAM,UACR,CAAC;AACd;AAEA,SAAgB,cAAgC,MAAmD;CACjG,MAAM,OAAOC,uBAAAA,YAAY,IAAI;CAE7B,MAAM,OAAkB;EAAE,WAAW,KAAK;EAAW;CAAK;CAC1D,MAAM,WAAW,IAAI,IAAI,KAAK,SAAS,KAAK,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