@prisma-next/sql-relational-core 0.3.0-pr.99.6 → 0.3.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 (163) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +20 -6
  3. package/dist/codec-types-DcEITed4.d.mts +144 -0
  4. package/dist/codec-types-DcEITed4.d.mts.map +1 -0
  5. package/dist/errors-Cs52upp3.d.mts +8 -0
  6. package/dist/errors-Cs52upp3.d.mts.map +1 -0
  7. package/dist/errors-D3xmG4h-.mjs +35 -0
  8. package/dist/errors-D3xmG4h-.mjs.map +1 -0
  9. package/dist/exports/ast.d.mts +158 -0
  10. package/dist/exports/ast.d.mts.map +1 -0
  11. package/dist/exports/ast.mjs +1358 -0
  12. package/dist/exports/ast.mjs.map +1 -0
  13. package/dist/exports/errors.d.mts +5 -0
  14. package/dist/exports/errors.mjs +3 -0
  15. package/dist/exports/plan.d.mts +2 -0
  16. package/dist/exports/plan.mjs +17 -0
  17. package/dist/exports/plan.mjs.map +1 -0
  18. package/dist/exports/query-lane-context.d.mts +3 -0
  19. package/dist/exports/query-lane-context.mjs +1 -0
  20. package/dist/exports/types.d.mts +4 -0
  21. package/dist/exports/types.mjs +1 -0
  22. package/dist/index.d.mts +11 -0
  23. package/dist/index.mjs +7 -0
  24. package/dist/plan-5qUWdlJM.d.mts +28 -0
  25. package/dist/plan-5qUWdlJM.d.mts.map +1 -0
  26. package/dist/query-lane-context-UlR8vOkd.d.mts +89 -0
  27. package/dist/query-lane-context-UlR8vOkd.d.mts.map +1 -0
  28. package/dist/types-CLCtwVWx.d.mts +485 -0
  29. package/dist/types-CLCtwVWx.d.mts.map +1 -0
  30. package/dist/types-V1qiC5DO.d.mts +200 -0
  31. package/dist/types-V1qiC5DO.d.mts.map +1 -0
  32. package/package.json +29 -51
  33. package/src/ast/adapter-types.ts +11 -0
  34. package/src/ast/codec-types.ts +101 -53
  35. package/src/ast/driver-types.ts +20 -3
  36. package/src/ast/sql-codecs.ts +142 -0
  37. package/src/ast/types.ts +1678 -88
  38. package/src/errors.ts +47 -1
  39. package/src/exports/ast.ts +1 -8
  40. package/src/index.ts +0 -3
  41. package/src/plan.ts +4 -4
  42. package/src/query-lane-context.ts +74 -11
  43. package/src/types.ts +102 -404
  44. package/dist/ast/adapter-types.d.ts +0 -28
  45. package/dist/ast/adapter-types.d.ts.map +0 -1
  46. package/dist/ast/codec-types.d.ts +0 -141
  47. package/dist/ast/codec-types.d.ts.map +0 -1
  48. package/dist/ast/common.d.ts +0 -7
  49. package/dist/ast/common.d.ts.map +0 -1
  50. package/dist/ast/delete.d.ts +0 -8
  51. package/dist/ast/delete.d.ts.map +0 -1
  52. package/dist/ast/driver-types.d.ts +0 -20
  53. package/dist/ast/driver-types.d.ts.map +0 -1
  54. package/dist/ast/insert.d.ts +0 -8
  55. package/dist/ast/insert.d.ts.map +0 -1
  56. package/dist/ast/join.d.ts +0 -6
  57. package/dist/ast/join.d.ts.map +0 -1
  58. package/dist/ast/order.d.ts +0 -6
  59. package/dist/ast/order.d.ts.map +0 -1
  60. package/dist/ast/predicate.d.ts +0 -4
  61. package/dist/ast/predicate.d.ts.map +0 -1
  62. package/dist/ast/select.d.ts +0 -18
  63. package/dist/ast/select.d.ts.map +0 -1
  64. package/dist/ast/types.d.ts +0 -130
  65. package/dist/ast/types.d.ts.map +0 -1
  66. package/dist/ast/update.d.ts +0 -9
  67. package/dist/ast/update.d.ts.map +0 -1
  68. package/dist/ast/util.d.ts +0 -2
  69. package/dist/ast/util.d.ts.map +0 -1
  70. package/dist/chunk-2BWK6XEY.js +0 -13
  71. package/dist/chunk-2BWK6XEY.js.map +0 -1
  72. package/dist/chunk-2F7DSEOU.js +0 -8
  73. package/dist/chunk-2F7DSEOU.js.map +0 -1
  74. package/dist/chunk-2MAKNVCP.js +0 -86
  75. package/dist/chunk-2MAKNVCP.js.map +0 -1
  76. package/dist/chunk-36WJWNHT.js +0 -1
  77. package/dist/chunk-36WJWNHT.js.map +0 -1
  78. package/dist/chunk-3F4RFQIB.js +0 -169
  79. package/dist/chunk-3F4RFQIB.js.map +0 -1
  80. package/dist/chunk-7I3EMQID.js +0 -16
  81. package/dist/chunk-7I3EMQID.js.map +0 -1
  82. package/dist/chunk-G52ENULI.js +0 -1
  83. package/dist/chunk-G52ENULI.js.map +0 -1
  84. package/dist/chunk-HV334QHG.js +0 -320
  85. package/dist/chunk-HV334QHG.js.map +0 -1
  86. package/dist/chunk-KYSP7L5C.js +0 -16
  87. package/dist/chunk-KYSP7L5C.js.map +0 -1
  88. package/dist/chunk-U7AXAUJA.js +0 -1
  89. package/dist/chunk-U7AXAUJA.js.map +0 -1
  90. package/dist/chunk-YXD25S5I.js +0 -171
  91. package/dist/chunk-YXD25S5I.js.map +0 -1
  92. package/dist/errors.d.ts +0 -2
  93. package/dist/errors.d.ts.map +0 -1
  94. package/dist/exports/ast.d.ts +0 -14
  95. package/dist/exports/ast.d.ts.map +0 -1
  96. package/dist/exports/ast.js +0 -46
  97. package/dist/exports/ast.js.map +0 -1
  98. package/dist/exports/errors.d.ts +0 -2
  99. package/dist/exports/errors.d.ts.map +0 -1
  100. package/dist/exports/errors.js +0 -9
  101. package/dist/exports/errors.js.map +0 -1
  102. package/dist/exports/guards.d.ts +0 -2
  103. package/dist/exports/guards.d.ts.map +0 -1
  104. package/dist/exports/guards.js +0 -31
  105. package/dist/exports/guards.js.map +0 -1
  106. package/dist/exports/operations-registry.d.ts +0 -2
  107. package/dist/exports/operations-registry.d.ts.map +0 -1
  108. package/dist/exports/operations-registry.js +0 -9
  109. package/dist/exports/operations-registry.js.map +0 -1
  110. package/dist/exports/param.d.ts +0 -3
  111. package/dist/exports/param.d.ts.map +0 -1
  112. package/dist/exports/param.js +0 -7
  113. package/dist/exports/param.js.map +0 -1
  114. package/dist/exports/plan.d.ts +0 -2
  115. package/dist/exports/plan.d.ts.map +0 -1
  116. package/dist/exports/plan.js +0 -7
  117. package/dist/exports/plan.js.map +0 -1
  118. package/dist/exports/query-lane-context.d.ts +0 -2
  119. package/dist/exports/query-lane-context.d.ts.map +0 -1
  120. package/dist/exports/query-lane-context.js +0 -2
  121. package/dist/exports/query-lane-context.js.map +0 -1
  122. package/dist/exports/schema.d.ts +0 -3
  123. package/dist/exports/schema.d.ts.map +0 -1
  124. package/dist/exports/schema.js +0 -13
  125. package/dist/exports/schema.js.map +0 -1
  126. package/dist/exports/types.d.ts +0 -2
  127. package/dist/exports/types.d.ts.map +0 -1
  128. package/dist/exports/types.js +0 -10
  129. package/dist/exports/types.js.map +0 -1
  130. package/dist/index.d.ts +0 -9
  131. package/dist/index.d.ts.map +0 -1
  132. package/dist/index.js +0 -81
  133. package/dist/index.js.map +0 -1
  134. package/dist/operations-registry.d.ts +0 -5
  135. package/dist/operations-registry.d.ts.map +0 -1
  136. package/dist/param.d.ts +0 -4
  137. package/dist/param.d.ts.map +0 -1
  138. package/dist/plan.d.ts +0 -23
  139. package/dist/plan.d.ts.map +0 -1
  140. package/dist/query-lane-context.d.ts +0 -27
  141. package/dist/query-lane-context.d.ts.map +0 -1
  142. package/dist/schema.d.ts +0 -83
  143. package/dist/schema.d.ts.map +0 -1
  144. package/dist/types.d.ts +0 -371
  145. package/dist/types.d.ts.map +0 -1
  146. package/dist/utils/guards.d.ts +0 -82
  147. package/dist/utils/guards.d.ts.map +0 -1
  148. package/src/ast/common.ts +0 -36
  149. package/src/ast/delete.ts +0 -17
  150. package/src/ast/insert.ts +0 -17
  151. package/src/ast/join.ts +0 -54
  152. package/src/ast/order.ts +0 -11
  153. package/src/ast/predicate.ts +0 -22
  154. package/src/ast/select.ts +0 -39
  155. package/src/ast/update.ts +0 -19
  156. package/src/exports/guards.ts +0 -15
  157. package/src/exports/operations-registry.ts +0 -1
  158. package/src/exports/param.ts +0 -2
  159. package/src/exports/schema.ts +0 -6
  160. package/src/operations-registry.ts +0 -276
  161. package/src/param.ts +0 -15
  162. package/src/schema.ts +0 -406
  163. package/src/utils/guards.ts +0 -193
package/src/ast/delete.ts DELETED
@@ -1,17 +0,0 @@
1
- import type { BinaryExpr, ColumnRef, DeleteAst, TableRef } from './types';
2
- import { compact } from './util';
3
-
4
- export interface CreateDeleteAstOptions {
5
- readonly table: TableRef;
6
- readonly where: BinaryExpr;
7
- readonly returning?: ReadonlyArray<ColumnRef>;
8
- }
9
-
10
- export function createDeleteAst(options: CreateDeleteAstOptions): DeleteAst {
11
- return compact({
12
- kind: 'delete',
13
- table: options.table,
14
- where: options.where,
15
- returning: options.returning,
16
- }) as DeleteAst;
17
- }
package/src/ast/insert.ts DELETED
@@ -1,17 +0,0 @@
1
- import type { ColumnRef, InsertAst, ParamRef, TableRef } from './types';
2
- import { compact } from './util';
3
-
4
- export interface CreateInsertAstOptions {
5
- readonly table: TableRef;
6
- readonly values: Record<string, ColumnRef | ParamRef>;
7
- readonly returning?: ReadonlyArray<ColumnRef>;
8
- }
9
-
10
- export function createInsertAst(options: CreateInsertAstOptions): InsertAst {
11
- return compact({
12
- kind: 'insert',
13
- table: options.table,
14
- values: options.values,
15
- returning: options.returning,
16
- }) as InsertAst;
17
- }
package/src/ast/join.ts DELETED
@@ -1,54 +0,0 @@
1
- import { planInvalid } from '@prisma-next/plan';
2
- import type { AnyColumnBuilder, JoinOnBuilder, JoinOnPredicate } from '../types';
3
- import { isColumnBuilder } from '../types';
4
- import type { ColumnRef, JoinAst, JoinOnExpr, TableRef } from './types';
5
-
6
- export function createJoin(
7
- joinType: 'inner' | 'left' | 'right' | 'full',
8
- table: TableRef,
9
- on: JoinOnExpr,
10
- ): JoinAst {
11
- return {
12
- kind: 'join',
13
- joinType,
14
- table,
15
- on,
16
- };
17
- }
18
-
19
- export function createJoinOnExpr(left: ColumnRef, right: ColumnRef): JoinOnExpr {
20
- return {
21
- kind: 'eqCol',
22
- left,
23
- right,
24
- };
25
- }
26
-
27
- class JoinOnBuilderImpl implements JoinOnBuilder {
28
- eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate {
29
- if (!left || !isColumnBuilder(left)) {
30
- throw planInvalid('Join ON left operand must be a column');
31
- }
32
-
33
- if (!right || !isColumnBuilder(right)) {
34
- throw planInvalid('Join ON right operand must be a column');
35
- }
36
-
37
- // TypeScript can't narrow ColumnBuilder properly, so we assert
38
- const leftCol = left as unknown as { table: string; column: string };
39
- const rightCol = right as unknown as { table: string; column: string };
40
- if (leftCol.table === rightCol.table) {
41
- throw planInvalid('Self-joins are not supported in MVP');
42
- }
43
-
44
- return {
45
- kind: 'join-on',
46
- left: left as AnyColumnBuilder,
47
- right: right as AnyColumnBuilder,
48
- };
49
- }
50
- }
51
-
52
- export function createJoinOnBuilder(): JoinOnBuilder {
53
- return new JoinOnBuilderImpl();
54
- }
package/src/ast/order.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { ColumnRef, Direction, OperationExpr } from './types';
2
-
3
- export function createOrderByItem(
4
- expr: ColumnRef | OperationExpr,
5
- dir: 'asc' | 'desc',
6
- ): { expr: ColumnRef | OperationExpr; dir: Direction } {
7
- return {
8
- expr,
9
- dir,
10
- };
11
- }
@@ -1,22 +0,0 @@
1
- import type { BinaryExpr, BinaryOp, ExistsExpr, Expression, ParamRef, SelectAst } from './types';
2
-
3
- export function createBinaryExpr(
4
- op: BinaryOp,
5
- left: Expression,
6
- right: Expression | ParamRef,
7
- ): BinaryExpr {
8
- return {
9
- kind: 'bin',
10
- op,
11
- left,
12
- right,
13
- };
14
- }
15
-
16
- export function createExistsExpr(not: boolean, subquery: SelectAst): ExistsExpr {
17
- return {
18
- kind: 'exists',
19
- not,
20
- subquery,
21
- };
22
- }
package/src/ast/select.ts DELETED
@@ -1,39 +0,0 @@
1
- import type {
2
- BinaryExpr,
3
- ColumnRef,
4
- Direction,
5
- ExistsExpr,
6
- IncludeAst,
7
- IncludeRef,
8
- JoinAst,
9
- OperationExpr,
10
- SelectAst,
11
- TableRef,
12
- } from './types';
13
- import { compact } from './util';
14
-
15
- export interface CreateSelectAstOptions {
16
- readonly from: TableRef;
17
- readonly joins?: ReadonlyArray<JoinAst>;
18
- readonly includes?: ReadonlyArray<IncludeAst>;
19
- readonly project: ReadonlyArray<{
20
- alias: string;
21
- expr: ColumnRef | IncludeRef | OperationExpr;
22
- }>;
23
- readonly where?: BinaryExpr | ExistsExpr;
24
- readonly orderBy?: ReadonlyArray<{ expr: ColumnRef | OperationExpr; dir: Direction }>;
25
- readonly limit?: number;
26
- }
27
-
28
- export function createSelectAst(options: CreateSelectAstOptions): SelectAst {
29
- return compact({
30
- kind: 'select',
31
- from: options.from,
32
- joins: options.joins,
33
- includes: options.includes,
34
- project: options.project,
35
- where: options.where,
36
- orderBy: options.orderBy,
37
- limit: options.limit,
38
- }) as SelectAst;
39
- }
package/src/ast/update.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { BinaryExpr, ColumnRef, ParamRef, TableRef, UpdateAst } from './types';
2
- import { compact } from './util';
3
-
4
- export interface CreateUpdateAstOptions {
5
- readonly table: TableRef;
6
- readonly set: Record<string, ColumnRef | ParamRef>;
7
- readonly where: BinaryExpr;
8
- readonly returning?: ReadonlyArray<ColumnRef>;
9
- }
10
-
11
- export function createUpdateAst(options: CreateUpdateAstOptions): UpdateAst {
12
- return compact({
13
- kind: 'update',
14
- table: options.table,
15
- set: options.set,
16
- where: options.where,
17
- returning: options.returning,
18
- }) as UpdateAst;
19
- }
@@ -1,15 +0,0 @@
1
- export {
2
- collectColumnRefs,
3
- expressionFromSource,
4
- extractBaseColumnRef,
5
- getColumnInfo,
6
- getColumnMeta,
7
- getOperationExpr,
8
- isColumnBuilder,
9
- isExpressionBuilder,
10
- isExpressionSource,
11
- isOperationExpr,
12
- isParamPlaceholder,
13
- isValueSource,
14
- toExpression,
15
- } from '../utils/guards';
@@ -1 +0,0 @@
1
- export { attachOperationsToColumnBuilder } from '../operations-registry';
@@ -1,2 +0,0 @@
1
- export type { Parameter } from '../param';
2
- export { param } from '../param';
@@ -1,6 +0,0 @@
1
- export type {
2
- ColumnBuilderImpl as Column,
3
- SchemaHandle,
4
- TableBuilderImpl as Table,
5
- } from '../schema';
6
- export { ColumnBuilderImpl, schema, TableBuilderImpl } from '../schema';
@@ -1,276 +0,0 @@
1
- import type { OperationRegistry } from '@prisma-next/operations';
2
- import { hasAllCapabilities } from '@prisma-next/operations';
3
- import { planInvalid } from '@prisma-next/plan';
4
- import type { StorageColumn } from '@prisma-next/sql-contract/types';
5
- import type { SqlOperationSignature } from '@prisma-next/sql-operations';
6
- import type {
7
- BinaryOp,
8
- Expression,
9
- ExpressionSource,
10
- LiteralExpr,
11
- OperationExpr,
12
- ParamRef,
13
- } from './ast/types';
14
- import type {
15
- AnyBinaryBuilder,
16
- AnyOrderBuilder,
17
- ColumnBuilder,
18
- ExpressionBuilder,
19
- OperationTypes,
20
- ParamPlaceholder,
21
- } from './types';
22
- import { isParamPlaceholder } from './utils/guards';
23
-
24
- /**
25
- * Type guard to check if a value is an ExpressionSource (has toExpr method).
26
- */
27
- function isExpressionSource(value: unknown): value is ExpressionSource {
28
- return (
29
- typeof value === 'object' &&
30
- value !== null &&
31
- 'toExpr' in value &&
32
- typeof (value as ExpressionSource).toExpr === 'function'
33
- );
34
- }
35
-
36
- /**
37
- * Executes an operation and returns an ExpressionBuilder.
38
- * This is the canonical entrypoint for operation invocation, enabling
39
- * future enhancements like telemetry, caching, or tracing.
40
- *
41
- * The returned ExpressionBuilder:
42
- * - Has `kind: 'expression'` to distinguish it from ColumnBuilder
43
- * - Contains the operation expression in `expr`
44
- * - Provides `toExpr()` method to get the Expression
45
- * - Provides comparison and ordering methods for chaining
46
- *
47
- * @param signature - The operation signature from the registry
48
- * @param selfBuilder - The expression source that the operation is called on
49
- * @param args - The arguments passed to the operation
50
- * @param columnMeta - The metadata of the column the operation is called on
51
- * @returns An ExpressionBuilder containing the operation expression
52
- */
53
- function executeOperation(
54
- signature: SqlOperationSignature,
55
- selfBuilder: ExpressionSource,
56
- args: unknown[],
57
- columnMeta: StorageColumn,
58
- operationRegistry?: OperationRegistry,
59
- contractCapabilities?: Record<string, Record<string, boolean>>,
60
- ): ExpressionBuilder {
61
- if (args.length !== signature.args.length) {
62
- throw planInvalid(
63
- `Operation ${signature.method} expects ${signature.args.length} arguments, got ${args.length}`,
64
- );
65
- }
66
-
67
- // Get the Expression from the self builder using toExpr()
68
- const selfExpr: Expression = selfBuilder.toExpr();
69
-
70
- const operationArgs: Array<Expression | ParamRef | LiteralExpr> = [];
71
- for (let i = 0; i < args.length; i++) {
72
- const arg = args[i];
73
- const argSpec = signature.args[i];
74
- if (!argSpec) {
75
- throw planInvalid(`Missing argument spec for argument ${i}`);
76
- }
77
-
78
- if (argSpec.kind === 'param') {
79
- if (!isParamPlaceholder(arg)) {
80
- throw planInvalid(`Argument ${i} must be a parameter placeholder`);
81
- }
82
- operationArgs.push({
83
- kind: 'param',
84
- index: 0,
85
- name: arg.name,
86
- });
87
- } else if (argSpec.kind === 'typeId') {
88
- // Accept ExpressionSource (ColumnBuilder or ExpressionBuilder)
89
- if (!isExpressionSource(arg)) {
90
- throw planInvalid(
91
- `Argument ${i} must be an ExpressionSource (ColumnBuilder or ExpressionBuilder)`,
92
- );
93
- }
94
- // Use toExpr() to get the Expression
95
- operationArgs.push(arg.toExpr());
96
- } else if (argSpec.kind === 'literal') {
97
- operationArgs.push({
98
- kind: 'literal',
99
- value: arg,
100
- });
101
- }
102
- }
103
-
104
- const operationExpr: OperationExpr = {
105
- kind: 'operation',
106
- method: signature.method,
107
- forTypeId: signature.forTypeId,
108
- self: selfExpr,
109
- args: operationArgs,
110
- returns: signature.returns,
111
- lowering: signature.lowering,
112
- };
113
-
114
- const returnTypeId = signature.returns.kind === 'typeId' ? signature.returns.type : undefined;
115
- const returnColumnMeta: StorageColumn = returnTypeId
116
- ? {
117
- ...columnMeta,
118
- codecId: returnTypeId,
119
- }
120
- : columnMeta;
121
-
122
- const createComparisonMethod =
123
- (op: BinaryOp) =>
124
- (value: ParamPlaceholder | ExpressionSource): AnyBinaryBuilder =>
125
- Object.freeze({
126
- kind: 'binary' as const,
127
- op,
128
- left: operationExpr,
129
- right: value,
130
- }) as AnyBinaryBuilder;
131
-
132
- const baseResult: ExpressionBuilder = {
133
- kind: 'expression' as const,
134
- expr: operationExpr,
135
- get columnMeta() {
136
- return returnColumnMeta;
137
- },
138
- eq: createComparisonMethod('eq'),
139
- neq: createComparisonMethod('neq'),
140
- gt: createComparisonMethod('gt'),
141
- lt: createComparisonMethod('lt'),
142
- gte: createComparisonMethod('gte'),
143
- lte: createComparisonMethod('lte'),
144
- asc(): AnyOrderBuilder {
145
- return Object.freeze({
146
- kind: 'order' as const,
147
- expr: operationExpr,
148
- dir: 'asc' as const,
149
- });
150
- },
151
- desc(): AnyOrderBuilder {
152
- return Object.freeze({
153
- kind: 'order' as const,
154
- expr: operationExpr,
155
- dir: 'desc' as const,
156
- });
157
- },
158
- toExpr(): OperationExpr {
159
- return operationExpr;
160
- },
161
- get __jsType(): unknown {
162
- return undefined;
163
- },
164
- };
165
-
166
- // If the return type is a typeId, attach operations for that type
167
- if (returnTypeId && operationRegistry) {
168
- const resultWithOps = attachOperationsToExpressionBuilder(
169
- baseResult,
170
- returnColumnMeta,
171
- operationRegistry,
172
- contractCapabilities,
173
- );
174
- return Object.freeze(resultWithOps);
175
- }
176
-
177
- return Object.freeze(baseResult);
178
- }
179
-
180
- /**
181
- * Attaches operation methods to an ExpressionBuilder for chained operations.
182
- * When an operation returns a typeId, the result ExpressionBuilder needs
183
- * operation methods for that type.
184
- */
185
- function attachOperationsToExpressionBuilder(
186
- expressionBuilder: ExpressionBuilder,
187
- columnMeta: StorageColumn,
188
- registry: OperationRegistry,
189
- contractCapabilities?: Record<string, Record<string, boolean>>,
190
- ): ExpressionBuilder {
191
- const codecId = columnMeta.codecId;
192
- if (!codecId) {
193
- return expressionBuilder;
194
- }
195
-
196
- const operations = registry.byType(codecId) as SqlOperationSignature[];
197
- if (operations.length === 0) {
198
- return expressionBuilder;
199
- }
200
-
201
- const builderWithOps = expressionBuilder as ExpressionBuilder & Record<string, unknown>;
202
-
203
- for (const operation of operations) {
204
- if (operation.capabilities && operation.capabilities.length > 0) {
205
- if (!contractCapabilities) {
206
- continue;
207
- }
208
-
209
- if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) {
210
- continue;
211
- }
212
- }
213
- // Method sugar: attach operation as a method on the expression builder
214
- builderWithOps[operation.method] = function (this: ExpressionBuilder, ...args: unknown[]) {
215
- return executeOperation(operation, this, args, columnMeta, registry, contractCapabilities);
216
- };
217
- }
218
-
219
- return builderWithOps;
220
- }
221
-
222
- export function attachOperationsToColumnBuilder<
223
- ColumnName extends string,
224
- ColumnMeta extends StorageColumn,
225
- JsType = unknown,
226
- Operations extends OperationTypes = Record<string, never>,
227
- >(
228
- columnBuilder: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,
229
- columnMeta: ColumnMeta,
230
- registry: OperationRegistry | undefined,
231
- contractCapabilities?: Record<string, Record<string, boolean>>,
232
- ): ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations> {
233
- if (!registry) {
234
- return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;
235
- }
236
-
237
- // Use codecId to look up operations registered for this column's type
238
- const codecId = columnMeta.codecId;
239
- if (!codecId) {
240
- return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;
241
- }
242
-
243
- const operations = registry.byType(codecId) as SqlOperationSignature[];
244
- if (operations.length === 0) {
245
- return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;
246
- }
247
-
248
- const builderWithOps = columnBuilder as unknown as ColumnBuilder<
249
- ColumnName,
250
- ColumnMeta,
251
- JsType,
252
- Operations
253
- >;
254
-
255
- for (const operation of operations) {
256
- if (operation.capabilities && operation.capabilities.length > 0) {
257
- if (!contractCapabilities) {
258
- continue;
259
- }
260
-
261
- if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) {
262
- continue;
263
- }
264
- }
265
- // Method sugar: attach operation as a method on the column builder
266
- // Operations return ExpressionBuilder, not ColumnBuilder
267
- (builderWithOps as Record<string, unknown>)[operation.method] = function (
268
- this: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,
269
- ...args: unknown[]
270
- ) {
271
- return executeOperation(operation, this, args, columnMeta, registry, contractCapabilities);
272
- };
273
- }
274
-
275
- return builderWithOps;
276
- }
package/src/param.ts DELETED
@@ -1,15 +0,0 @@
1
- import { planInvalid } from '@prisma-next/plan';
2
- import type { ParamPlaceholder } from './types';
3
-
4
- export type Parameter = ParamPlaceholder;
5
-
6
- export function param(name: string): Parameter {
7
- if (typeof name !== 'string' || name.length === 0) {
8
- throw planInvalid('Parameter name must be a non-empty string');
9
- }
10
-
11
- return Object.freeze({
12
- kind: 'param-placeholder' as const,
13
- name,
14
- }) satisfies Parameter;
15
- }