@prisma/orm-family-sql 8.0.0-rc.17-dev.21 → 8.0.0-rc.17-dev.23

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 (61) hide show
  1. package/dist/builder.d.mts +3 -2
  2. package/dist/builder__runtime.d.mts +7 -24
  3. package/dist/builder__runtime.d.mts.map +1 -1
  4. package/dist/builder__runtime.mjs +61 -185
  5. package/dist/builder__runtime.mjs.map +1 -1
  6. package/dist/builder__types.d.mts +4 -2
  7. package/dist/{db-DB1FVK1P-DbwoL7vg.d.mts → db-BmrN9nRS-DEogPltL.d.mts} +11 -97
  8. package/dist/db-BmrN9nRS-DEogPltL.d.mts.map +1 -0
  9. package/dist/expression-CNBCbbzU-BG3rv8Wb.d.mts +22 -0
  10. package/dist/expression-CNBCbbzU-BG3rv8Wb.d.mts.map +1 -0
  11. package/dist/{expression-CvXfXCGs.d.mts → expression-Ck1wys3N-RNyviMcU.d.mts} +15 -3
  12. package/dist/expression-Ck1wys3N-RNyviMcU.d.mts.map +1 -0
  13. package/dist/expression-DWcDQHh9.d.mts +2 -0
  14. package/dist/{expression-JOe6lo4g.mjs → expression-impl-B-XNINxr-vYwKVFeP.mjs} +26 -3
  15. package/dist/expression-impl-B-XNINxr-vYwKVFeP.mjs.map +1 -0
  16. package/dist/functions-0YWByawj.mjs +88 -0
  17. package/dist/functions-0YWByawj.mjs.map +1 -0
  18. package/dist/functions-CJ8Yf8uL.d.mts +73 -0
  19. package/dist/functions-CJ8Yf8uL.d.mts.map +1 -0
  20. package/dist/{index-BzAG1PFV.d.mts → index-ZHk0SsBA.d.mts} +5 -5
  21. package/dist/{index-BzAG1PFV.d.mts.map → index-ZHk0SsBA.d.mts.map} +1 -1
  22. package/dist/index-reference-CflkzYSd.d.mts +58 -0
  23. package/dist/index-reference-CflkzYSd.d.mts.map +1 -0
  24. package/dist/index-reference-D693Lu-E.mjs +42 -0
  25. package/dist/index-reference-D693Lu-E.mjs.map +1 -0
  26. package/dist/orm-client.d.mts +96 -26
  27. package/dist/orm-client.d.mts.map +1 -1
  28. package/dist/orm-client.mjs +172 -8
  29. package/dist/orm-client.mjs.map +1 -1
  30. package/dist/{prepared-statement-YtgdlN7e-D4MSU3i0.d.mts → prepared-statement-YtgdlN7e-DqHHwo30.d.mts} +8 -7
  31. package/dist/prepared-statement-YtgdlN7e-DqHHwo30.d.mts.map +1 -0
  32. package/dist/query-lane-context-BsZs5lvB.d.mts +1 -0
  33. package/dist/{query-lane-context-CJoNBspB--ieuKEei.d.mts → query-lane-context-C2AXsoFa-COSQOvZz.d.mts} +7 -2
  34. package/dist/query-lane-context-C2AXsoFa-COSQOvZz.d.mts.map +1 -0
  35. package/dist/relational-core.d.mts +7 -6
  36. package/dist/relational-core.mjs +2 -2
  37. package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
  38. package/dist/relational-core__codec-descriptor-registry.d.mts +1 -1
  39. package/dist/relational-core__expression.d.mts +4 -2
  40. package/dist/relational-core__expression.mjs +2 -2
  41. package/dist/relational-core__functions.d.mts +2 -0
  42. package/dist/relational-core__functions.mjs +2 -0
  43. package/dist/relational-core__index-reference.d.mts +2 -0
  44. package/dist/relational-core__index-reference.mjs +2 -0
  45. package/dist/relational-core__query-lane-context.d.mts +2 -2
  46. package/dist/relational-core__types.d.mts +2 -2
  47. package/dist/runtime.d.mts +3 -3
  48. package/dist/runtime.mjs +2 -1
  49. package/dist/runtime.mjs.map +1 -1
  50. package/dist/runtime__internal__prepared-query.d.mts +1 -1
  51. package/dist/{types-BJQcLx-8-BHNxJ_df.d.mts → types-D09NAayg-CNrpjo7Z.d.mts} +3 -3
  52. package/dist/{types-BJQcLx-8-BHNxJ_df.d.mts.map → types-D09NAayg-CNrpjo7Z.d.mts.map} +1 -1
  53. package/dist/types-DAkmn9FV.d.mts +1 -0
  54. package/package.json +20 -18
  55. package/dist/db-DB1FVK1P-DbwoL7vg.d.mts.map +0 -1
  56. package/dist/expression-CvXfXCGs.d.mts.map +0 -1
  57. package/dist/expression-JOe6lo4g.mjs.map +0 -1
  58. package/dist/prepared-statement-YtgdlN7e-D4MSU3i0.d.mts.map +0 -1
  59. package/dist/query-lane-context-CJoNBspB--ieuKEei.d.mts.map +0 -1
  60. package/dist/query-lane-context-DNt2DeQu.d.mts +0 -1
  61. package/dist/types-BCPHaykc.d.mts +0 -1
@@ -1,3 +1,4 @@
1
- import { o as Expression, x as ScopeField } from "./expression-CvXfXCGs.mjs";
2
- import { C as TableProxy, D as WhereFilter, E as UpdateQuery, _ as ResolveRow, a as DeleteQuery, b as Subquery, c as GatedMethod, f as InsertQuery, i as Db, l as GroupedQuery, m as QueryContext, s as Functions, t as AggregateFunctions, v as Scope, y as SelectQuery } from "./db-DB1FVK1P-DbwoL7vg.mjs";
1
+ import { o as Expression, x as ScopeField } from "./expression-Ck1wys3N-RNyviMcU.mjs";
2
+ import { a as Subquery, r as Functions } from "./functions-CJ8Yf8uL.mjs";
3
+ import { C as WhereFilter, S as UpdateQuery, d as QueryContext, g as SelectQuery, h as Scope, i as DeleteQuery, l as InsertQuery, m as ResolveRow, o as GatedMethod, r as Db, s as GroupedQuery, t as AggregateFunctions, y as TableProxy } from "./db-BmrN9nRS-DEogPltL.mjs";
3
4
  export type { AggregateFunctions, Db, DeleteQuery, Expression, Functions, GatedMethod, GroupedQuery, InsertQuery, QueryContext, ResolveRow, Scope, ScopeField, SelectQuery, Subquery, TableProxy, UpdateQuery, WhereFilter };
@@ -1,36 +1,19 @@
1
1
  import { l as SqlStorage } from "./sql-storage-BTlJLUID-CGy3wuH4.mjs";
2
2
  import "./types-Uv3oTMAb.mjs";
3
3
  import { i as SqlOperationEntry } from "./index-We-mbWnZ.mjs";
4
- import { c as AnyExpression } from "./types-Sh5HuaZE-CqThc46M.mjs";
5
- import "./ast-Dp6lQXUX.mjs";
6
- import { l as RawCodecInferer, o as Expression, x as ScopeField } from "./expression-CvXfXCGs.mjs";
7
- import { h as RawLane, i as Db, m as QueryContext, o as FieldProxy, s as Functions, t as AggregateFunctions, v as Scope, w as TableProxyContract } from "./db-DB1FVK1P-DbwoL7vg.mjs";
8
- import { a as SqlAggregateDescriptorRegistry, n as ExecutionContext } from "./query-lane-context-CJoNBspB--ieuKEei.mjs";
9
- import "./query-lane-context-DNt2DeQu.mjs";
4
+ import { l as RawCodecInferer } from "./expression-Ck1wys3N-RNyviMcU.mjs";
5
+ import { t as ExpressionImpl } from "./expression-CNBCbbzU-BG3rv8Wb.mjs";
6
+ import "./expression-DWcDQHh9.mjs";
7
+ import { s as createFunctions } from "./functions-CJ8Yf8uL.mjs";
8
+ import { a as FieldProxy, b as TableProxyContract, d as QueryContext, f as RawLane, h as Scope, r as Db, t as AggregateFunctions } from "./db-BmrN9nRS-DEogPltL.mjs";
9
+ import { a as SqlAggregateDescriptorRegistry, n as ExecutionContext } from "./query-lane-context-C2AXsoFa-COSQOvZz.mjs";
10
+ import "./query-lane-context-BsZs5lvB.mjs";
10
11
  import { Contract } from "@prisma/orm-framework/contract/types";
11
12
  //#region ../../../2-sql/4-lanes/sql-builder/dist/runtime/index.d.mts
12
- //#region src/runtime/expression-impl.d.ts
13
- /**
14
- * Runtime wrapper around a relational-core AST expression node. Carries ScopeField metadata (codecId, nullable) so aggregate-like combinators can propagate the input codec onto their result.
15
- *
16
- * `returnType.codec` records the column-bound codec ref when the field-proxy knows the binding — both the namespaced form (`f.user.email` → `ColumnRef`) and the top-level shortcut (`f.email` → `IdentifierRef`) stamp the ref derived from contract storage. `codecOf(expression)` exposes it for operation implementations forwarding the ref to `toExpr`.
17
- *
18
- * `projectionAst` carries the descriptor-lowered rendering of the expression, where a target declares one (e.g. SQLite's `CAST(count(*) AS TEXT)`). Lowering exists to carry the value across the driver boundary, so only the projection site consumes it — predicate and ordering positions (`buildAst()`) keep the plain form, where the rendering would change SQL semantics.
19
- */
20
- declare class ExpressionImpl<T extends ScopeField = ScopeField> implements Expression<T> {
21
- private readonly ast;
22
- private readonly projectionAst;
23
- readonly returnType: T;
24
- constructor(ast: AnyExpression, returnType: T, projectionAst?: AnyExpression);
25
- buildAst(): AnyExpression;
26
- buildProjectionAst(): AnyExpression;
27
- }
28
- //#endregion
29
13
  //#region src/runtime/field-proxy.d.ts
30
14
  declare function createFieldProxy<S extends Scope>(scope: S): FieldProxy<S>;
31
15
  //#endregion
32
16
  //#region src/runtime/functions.d.ts
33
- declare function createFunctions<QC extends QueryContext>(operations: Readonly<Record<string, SqlOperationEntry>>, rawCodecInferer: RawCodecInferer): Functions<QC>;
34
17
  declare function createAggregateFunctions<QC extends QueryContext>(operations: Readonly<Record<string, SqlOperationEntry>>, rawCodecInferer: RawCodecInferer, aggregateRegistry: SqlAggregateDescriptorRegistry): AggregateFunctions<QC>;
35
18
  //#endregion
36
19
  //#region src/runtime/raw-lane.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"builder__runtime.d.mts","names":[],"sources":["../../../../2-sql/4-lanes/sql-builder/dist/runtime/index.d.mts"],"mappings":";;;;;;;;;;;;;;;;;;;cAec,eAAe,UAAU,aAAa,uBAAuB,WAAW;mBACnE;mBACA;WACR,YAAY;EACrB,YAAY,KAAK,eAAe,YAAY,GAAG,gBAAgB;EAC/D,YAAY;EACZ,sBAAsB;;;;iBAIP,iBAAiB,UAAU,OAAO,OAAO,IAAI,WAAW;;;iBAGxD,gBAAgB,WAAW,cAAc,YAAY,SAAS,eAAe,qBAAqB,iBAAiB,kBAAkB,UAAU;iBAC/I,yBAAyB,WAAW,cAAc,YAAY,SAAS,eAAe,qBAAqB,iBAAiB,iBAAiB,mBAAmB,iCAAiC,mBAAmB;;;UAG3N,eAAe,UAAU,SAAS,cAAc;WAC/C,SAAS,iBAAiB;WAC1B,iBAAiB;;;;;;;;;;;;iBAYX,cAAc,UAAU,SAAS,cAAc,oBAAoB,SAAS,eAAe,KAAK,QAAQ;;;UAG/G,WAAW,UAAU,SAAS,cAAc;WAC3C,SAAS,iBAAiB;WAC1B,iBAAiB;;iBAEX,IAAI,UAAU,SAAS,cAAc,oBAAoB,SAAS,WAAW,KAAK,GAAG"}
1
+ {"version":3,"file":"builder__runtime.d.mts","names":[],"sources":["../../../../2-sql/4-lanes/sql-builder/dist/runtime/index.d.mts"],"mappings":";;;;;;;;;;;;;iBAQiB,iBAAiB,UAAU,OAAO,OAAO,IAAI,WAAW;;;iBAGxD,yBAAyB,WAAW,cAAc,YAAY,SAAS,eAAe,qBAAqB,iBAAiB,iBAAiB,mBAAmB,iCAAiC,mBAAmB;;;UAG3N,eAAe,UAAU,SAAS,cAAc;WAC/C,SAAS,iBAAiB;WAC1B,iBAAiB;;;;;;;;;;;;iBAYX,cAAc,UAAU,SAAS,cAAc,oBAAoB,SAAS,eAAe,KAAK,QAAQ;;;UAG/G,WAAW,UAAU,SAAS,cAAc;WAC3C,SAAS,iBAAiB;WAC1B,iBAAiB;;iBAEX,IAAI,UAAU,SAAS,cAAc,oBAAoB,SAAS,WAAW,KAAK,GAAG"}
@@ -1,8 +1,10 @@
1
- import { A as ParamRef, C as LiteralExpr, E as NullCheckExpr, F as SelectAst, G as isOrderByNulls, I as SubqueryExpr, L as TableSource, M as ProjectionItem, O as OrExpr, R as UpdateAst, S as ListExpression, U as isAggregateFn, W as isOrderByDirection, _ as InsertAst, c as DeleteAst, g as IdentifierRef, k as OrderByItem, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, t as AggregateExpr, w as LockingClause, y as JoinAst } from "./types-NTQsD2MS-DAP2yVDn.mjs";
1
+ import { A as ParamRef, F as SelectAst, G as isOrderByNulls, L as TableSource, M as ProjectionItem, R as UpdateAst, U as isAggregateFn, W as isOrderByDirection, _ as InsertAst, c as DeleteAst, g as IdentifierRef, k as OrderByItem, l as DerivedTableSource, n as AndExpr, o as ColumnRef, t as AggregateExpr, w as LockingClause, y as JoinAst } from "./types-NTQsD2MS-DAP2yVDn.mjs";
2
2
  import { r as isAggregateProjection, t as collectOrderedParamRefs } from "./util-BBgcP3gI-XJBkxo1K.mjs";
3
3
  import { C as lockStrengthCapabilities, S as lockOptionCapabilities, w as lockWaitPolicyOf, x as lockIncompatible } from "./ast-De8XGuVW.mjs";
4
- import { i as isExpression, n as codecOf, o as toExpr, r as createRawSql } from "./expression-JOe6lo4g.mjs";
4
+ import { i as createRawSql, s as toExpr, t as ExpressionImpl } from "./expression-impl-B-XNINxr-vYwKVFeP.mjs";
5
5
  import { n as codecRefForStorageColumn } from "./codec-descriptor-registry-CYK0Wzja.mjs";
6
+ import { t as createFunctions } from "./functions-0YWByawj.mjs";
7
+ import { t as createIndexReferences } from "./index-reference-D693Lu-E.mjs";
6
8
  import { assertAnnotationsApplicable } from "@prisma/orm-framework/components/runtime";
7
9
  //#region ../../../2-sql/4-lanes/sql-builder/dist/runtime/index.mjs
8
10
  /**
@@ -43,6 +45,55 @@ import { assertAnnotationsApplicable } from "@prisma/orm-framework/components/ru
43
45
  function blindCast(input) {
44
46
  return input;
45
47
  }
48
+ function createFieldProxy(scope) {
49
+ return new Proxy(blindCast({}), { get(_target, prop) {
50
+ if (Object.hasOwn(scope.topLevel, prop)) {
51
+ const topField = scope.topLevel[prop];
52
+ if (topField) return new ExpressionImpl(IdentifierRef.of(prop), topField);
53
+ }
54
+ if (Object.hasOwn(scope.namespaces, prop)) {
55
+ const nsFields = scope.namespaces[prop];
56
+ if (nsFields) return createNamespaceProxy(prop, nsFields);
57
+ }
58
+ } });
59
+ }
60
+ function createNamespaceProxy(namespaceName, fields) {
61
+ return new Proxy({}, { get(_target, prop) {
62
+ if (Object.hasOwn(fields, prop)) {
63
+ const field = fields[prop];
64
+ if (field) return new ExpressionImpl(ColumnRef.of(namespaceName, prop), field);
65
+ }
66
+ } });
67
+ }
68
+ /**
69
+ * A bug in Prisma 8, not a user error. Never catch this except at the
70
+ * outermost boundary for crash reporting — an InternalError means an invariant
71
+ * broke and the process cannot reliably continue. User-facing failures use
72
+ * `structuredError` with a dotted code instead.
73
+ */
74
+ var InternalError = class extends Error {
75
+ isPrismaInternalError = true;
76
+ constructor(message, options) {
77
+ super(message, options?.cause !== void 0 ? { cause: options.cause } : void 0);
78
+ this.name = "InternalError";
79
+ }
80
+ };
81
+ /**
82
+ * Asserts that a value is defined (not null or undefined).
83
+ * Use for invariants where the value should always exist at runtime.
84
+ *
85
+ * @throws Error if value is null or undefined
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const table = storage.namespaces[namespaceId].entries.table[tableName];
90
+ * assertDefined(table, `Table "${tableName}" not found`);
91
+ * // table is now narrowed to non-nullable
92
+ * ```
93
+ */
94
+ function assertDefined(value, message) {
95
+ if (value === null || value === void 0) throw new InternalError(message);
96
+ }
46
97
  /**
47
98
  * Returns an object with the key/value if value is defined, otherwise an empty object.
48
99
  *
@@ -86,29 +137,6 @@ function structuredError(code, message, options) {
86
137
  });
87
138
  }
88
139
  /**
89
- * Runtime wrapper around a relational-core AST expression node. Carries ScopeField metadata (codecId, nullable) so aggregate-like combinators can propagate the input codec onto their result.
90
- *
91
- * `returnType.codec` records the column-bound codec ref when the field-proxy knows the binding — both the namespaced form (`f.user.email` → `ColumnRef`) and the top-level shortcut (`f.email` → `IdentifierRef`) stamp the ref derived from contract storage. `codecOf(expression)` exposes it for operation implementations forwarding the ref to `toExpr`.
92
- *
93
- * `projectionAst` carries the descriptor-lowered rendering of the expression, where a target declares one (e.g. SQLite's `CAST(count(*) AS TEXT)`). Lowering exists to carry the value across the driver boundary, so only the projection site consumes it — predicate and ordering positions (`buildAst()`) keep the plain form, where the rendering would change SQL semantics.
94
- */
95
- var ExpressionImpl = class {
96
- ast;
97
- projectionAst;
98
- returnType;
99
- constructor(ast, returnType, projectionAst) {
100
- this.ast = ast;
101
- this.returnType = returnType;
102
- this.projectionAst = projectionAst;
103
- }
104
- buildAst() {
105
- return this.ast;
106
- }
107
- buildProjectionAst() {
108
- return this.projectionAst ?? this.ast;
109
- }
110
- };
111
- /**
112
140
  * An aggregate whose operation lies outside the SQL aggregate alphabet: the expression exists only in its descriptor-lowered form, so only the projection may consume it.
113
141
  *
114
142
  * Predicate and ordering positions build the plain form through `buildAst()` and are refused at authoring time — the lowered rendering exists to carry the value across the driver boundary, and comparing or sorting by it inside the database would change SQL semantics (a textual rendering compares lexicographically).
@@ -133,108 +161,6 @@ var ProjectionOnlyExpressionImpl = class extends ExpressionImpl {
133
161
  function projectionAstOf(expr) {
134
162
  return expr instanceof ExpressionImpl ? expr.buildProjectionAst() : expr.buildAst();
135
163
  }
136
- function createFieldProxy(scope) {
137
- return new Proxy(blindCast({}), { get(_target, prop) {
138
- if (Object.hasOwn(scope.topLevel, prop)) {
139
- const topField = scope.topLevel[prop];
140
- if (topField) return new ExpressionImpl(IdentifierRef.of(prop), topField);
141
- }
142
- if (Object.hasOwn(scope.namespaces, prop)) {
143
- const nsFields = scope.namespaces[prop];
144
- if (nsFields) return createNamespaceProxy(prop, nsFields);
145
- }
146
- } });
147
- }
148
- function createNamespaceProxy(namespaceName, fields) {
149
- return new Proxy({}, { get(_target, prop) {
150
- if (Object.hasOwn(fields, prop)) {
151
- const field = fields[prop];
152
- if (field) return new ExpressionImpl(ColumnRef.of(namespaceName, prop), field);
153
- }
154
- } });
155
- }
156
- /**
157
- * A bug in Prisma 8, not a user error. Never catch this except at the
158
- * outermost boundary for crash reporting — an InternalError means an invariant
159
- * broke and the process cannot reliably continue. User-facing failures use
160
- * `structuredError` with a dotted code instead.
161
- */
162
- var InternalError = class extends Error {
163
- isPrismaInternalError = true;
164
- constructor(message, options) {
165
- super(message, options?.cause !== void 0 ? { cause: options.cause } : void 0);
166
- this.name = "InternalError";
167
- }
168
- };
169
- /**
170
- * Asserts that a value is defined (not null or undefined).
171
- * Use for invariants where the value should always exist at runtime.
172
- *
173
- * @throws Error if value is null or undefined
174
- *
175
- * @example
176
- * ```typescript
177
- * const table = storage.namespaces[namespaceId].entries.table[tableName];
178
- * assertDefined(table, `Table "${tableName}" not found`);
179
- * // table is now narrowed to non-nullable
180
- * ```
181
- */
182
- function assertDefined(value, message) {
183
- if (value === null || value === void 0) throw new InternalError(message);
184
- }
185
- const BOOL_FIELD = {
186
- codecId: "pg/bool@1",
187
- nullable: false
188
- };
189
- const resolve = toExpr;
190
- /**
191
- * Resolve a binary-comparison operand into an AST expression, threading the column-bound side's {@link CodecRef} to the raw-value side.
192
- *
193
- * For `fns.eq(f.email, 'alice@example.com')`, `f.email` is the column-bound expression carrying a `ColumnRef` AST and a `CodecRef` derived from contract storage; the raw string operand has no codec context. By deriving the codec context from the column-bound side and forwarding it via `toExpr(value, codec)`, the resulting `ParamRef` carries the `CodecRef` that encode-side dispatch needs to materialise the per-instance codec for parameterized codec ids (`vector(1024)` vs. `vector(1536)`).
194
- */
195
- function resolveOperand(operand, otherCodec) {
196
- if (isExpression(operand)) return operand.buildAst();
197
- return toExpr(operand, otherCodec);
198
- }
199
- /**
200
- * Resolves an Expression via `buildAst()`, or wraps a raw value as a `LiteralExpr` — an SQL literal inlined into the query text, not a bound parameter.
201
- *
202
- * Used for `and` / `or` operands. The usual operand is an `Expression<bool>` (e.g. the result of `fns.eq`), which this function passes through by calling `buildAst()`. The only time the raw-value branch fires is when the caller writes `fns.and(true, x)` or similar — inlining `TRUE`/`FALSE` literals lets the SQL planner statically simplify `TRUE AND x` to `x`, which it cannot do for an opaque `ParamRef`.
203
- */
204
- function toLiteralExpr(value) {
205
- if (isExpression(value)) return value.buildAst();
206
- return new LiteralExpr(value);
207
- }
208
- function boolExpr(astNode) {
209
- return new ExpressionImpl(astNode, BOOL_FIELD);
210
- }
211
- function binaryWithSharedCodec(a, b, build) {
212
- const aCodec = codecOf(a);
213
- return build(resolveOperand(a, codecOf(b)), resolveOperand(b, aCodec));
214
- }
215
- function eq(a, b) {
216
- if (b === null) return boolExpr(NullCheckExpr.isNull(resolve(a)));
217
- if (a === null) return boolExpr(NullCheckExpr.isNull(resolve(b)));
218
- return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr("eq", l, r)));
219
- }
220
- function ne(a, b) {
221
- if (b === null) return boolExpr(NullCheckExpr.isNotNull(resolve(a)));
222
- if (a === null) return boolExpr(NullCheckExpr.isNotNull(resolve(b)));
223
- return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr("neq", l, r)));
224
- }
225
- function comparison(a, b, op) {
226
- return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr(op, l, r)));
227
- }
228
- function inOrNotIn(expr, valuesOrSubquery, op) {
229
- const left = expr.buildAst();
230
- const leftCodec = codecOf(expr);
231
- const binaryFn = op === "in" ? BinaryExpr.in : BinaryExpr.notIn;
232
- if (Array.isArray(valuesOrSubquery)) {
233
- const refs = valuesOrSubquery.map((v) => resolveOperand(v, leftCodec));
234
- return boolExpr(binaryFn(left, ListExpression.of(refs)));
235
- }
236
- return boolExpr(binaryFn(left, SubqueryExpr.of(valuesOrSubquery.buildAst())));
237
- }
238
164
  /**
239
165
  * Build an aggregate through the target's own answer for it.
240
166
  *
@@ -292,23 +218,6 @@ function aggregate(aggregates, operation, expr) {
292
218
  });
293
219
  return new ExpressionImpl(ast, returnType, projectionAst);
294
220
  }
295
- function createBuiltinFunctions(rawCodecInferer) {
296
- return {
297
- eq: (a, b) => eq(a, b),
298
- ne: (a, b) => ne(a, b),
299
- gt: (a, b) => comparison(a, b, "gt"),
300
- gte: (a, b) => comparison(a, b, "gte"),
301
- lt: (a, b) => comparison(a, b, "lt"),
302
- lte: (a, b) => comparison(a, b, "lte"),
303
- and: (...exprs) => boolExpr(AndExpr.of(exprs.map(toLiteralExpr))),
304
- or: (...exprs) => boolExpr(OrExpr.of(exprs.map(toLiteralExpr))),
305
- exists: (subquery) => boolExpr(ExistsExpr.exists(subquery.buildAst())),
306
- notExists: (subquery) => boolExpr(ExistsExpr.notExists(subquery.buildAst())),
307
- in: (expr, valuesOrSubquery) => inOrNotIn(expr, valuesOrSubquery, "in"),
308
- notIn: (expr, valuesOrSubquery) => inOrNotIn(expr, valuesOrSubquery, "notIn"),
309
- raw: createRawSql(rawCodecInferer)
310
- };
311
- }
312
221
  /**
313
222
  * The aggregate implementations, one per operation the registry contributes,
314
223
  * erased.
@@ -328,14 +237,6 @@ function createAggregateOnlyFunctions(aggregates) {
328
237
  }
329
238
  return Object.fromEntries(methods);
330
239
  }
331
- function createFunctions(operations, rawCodecInferer) {
332
- const builtins = createBuiltinFunctions(rawCodecInferer);
333
- return new Proxy(blindCast({}), { get(_target, prop) {
334
- if (Object.hasOwn(builtins, prop)) return blindCast(builtins)[prop];
335
- const op = operations[prop];
336
- if (op) return op.impl;
337
- } });
338
- }
339
240
  function createAggregateFunctions(operations, rawCodecInferer, aggregateRegistry) {
340
241
  const baseFns = createFunctions(operations, rawCodecInferer);
341
242
  const aggregates = createAggregateOnlyFunctions(aggregateRegistry);
@@ -1161,41 +1062,16 @@ var TableProxyImpl = class TableProxyImpl extends BuilderBase {
1161
1062
  #indexReferences() {
1162
1063
  const fields = this.#scope.namespaces[this.#alias];
1163
1064
  assertDefined(fields, "a table proxy scopes its own alias");
1164
- const byName = /* @__PURE__ */ new Map();
1165
- for (const index of this.#table.indexes) {
1166
- const authoredName = index.prefix ?? index.name;
1167
- const columns = Object.fromEntries((index.columns ?? []).map((column) => {
1065
+ return blindCast(createIndexReferences({
1066
+ namespaceId: this.#namespaceId,
1067
+ tableName: this.#tableName,
1068
+ table: this.#table,
1069
+ column: (column) => {
1168
1070
  const field = fields[column];
1169
- assertDefined(field, `index "${index.name}" covers a column of its table`);
1170
- return [column, new ExpressionImpl(ColumnRef.of(this.#alias, column), field)];
1171
- }));
1172
- const reference = Object.freeze({
1173
- columns: Object.freeze(columns),
1174
- type: index.type,
1175
- options: index.options
1176
- });
1177
- byName.set(authoredName, [...byName.get(authoredName) ?? [], reference]);
1178
- }
1179
- const references = {};
1180
- for (const [authoredName, [reference, ...others]] of byName) Object.defineProperty(references, authoredName, {
1181
- enumerable: true,
1182
- get: () => {
1183
- if (others.length > 0) throw this.#ambiguousIndexName(authoredName);
1184
- return reference;
1185
- }
1186
- });
1187
- return blindCast(Object.freeze(references));
1188
- }
1189
- #ambiguousIndexName(authoredName) {
1190
- return structuredError("ORM.ARGUMENT_INVALID", `Table "${this.#tableName}" has more than one index named "${authoredName}".`, {
1191
- why: "An index is read by the name its contract source gave it, and these indexes share that name.",
1192
- fix: `Give each of these indexes of table "${this.#tableName}" its own name in the contract source.`,
1193
- meta: {
1194
- namespaceId: this.#namespaceId,
1195
- tableName: this.#tableName,
1196
- index: authoredName
1071
+ assertDefined(field, `an index covers a column of table "${this.#tableName}"`);
1072
+ return new ExpressionImpl(ColumnRef.of(this.#alias, column), field);
1197
1073
  }
1198
- });
1074
+ }));
1199
1075
  }
1200
1076
  lateralJoin = this._gate({ sql: { lateral: true } }, "lateralJoin", (alias, builder) => {
1201
1077
  return this.#toJoined().lateralJoin(alias, builder);