@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/types.ts CHANGED
@@ -1,226 +1,83 @@
1
1
  import type {
2
+ Contract,
2
3
  ResultType as CoreResultType,
3
4
  ExecutionPlan,
4
5
  PlanRefs,
5
6
  } from '@prisma-next/contract/types';
6
- import type { ArgSpec, ReturnSpec } from '@prisma-next/operations';
7
- import type { SqlContract, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';
8
- import type { SqlLoweringSpec } from '@prisma-next/sql-operations';
7
+ import type { ParamSpec } from '@prisma-next/operations';
9
8
  import type {
10
- BinaryOp,
11
- ColumnRef,
12
- Direction,
13
- Expression,
14
- ExpressionSource,
15
- OperationExpr,
16
- ParamRef,
17
- QueryAst,
18
- } from './ast/types';
9
+ ExtractFieldOutputTypes,
10
+ SqlStorage,
11
+ StorageColumn,
12
+ } from '@prisma-next/sql-contract/types';
13
+ import type { SqlLoweringSpec } from '@prisma-next/sql-operations';
14
+ import type { AnyQueryAst, ColumnRef, ParamRef } from './ast/types';
19
15
  import type { SqlQueryPlan } from './plan';
20
- import type { QueryLaneContext } from './query-lane-context';
21
-
22
- export interface ParamPlaceholder {
23
- readonly kind: 'param-placeholder';
24
- readonly name: string;
25
- }
26
-
27
- /**
28
- * ValueSource represents any value that can appear in a comparison or as an argument.
29
- * This includes:
30
- * - ParamPlaceholder: A parameter placeholder (e.g., `param('userId')`)
31
- * - ExpressionSource: Something that can be converted to an Expression (ColumnBuilder, ExpressionBuilder)
32
- */
33
- export type ValueSource = ParamPlaceholder | ExpressionSource;
34
-
35
- export interface OrderBuilder<
36
- _ColumnName extends string = string,
37
- _ColumnMeta extends StorageColumn = StorageColumn,
38
- _JsType = unknown,
39
- > {
40
- readonly kind: 'order';
41
- readonly expr: Expression;
42
- readonly dir: Direction;
43
- }
44
-
45
- /**
46
- * Creates an OrderBuilder for use in orderBy clauses.
47
- */
48
- export function createOrderBuilder(
49
- expr: AnyColumnBuilder | OperationExpr,
50
- dir: Direction,
51
- ): AnyOrderBuilder {
52
- return { kind: 'order', expr, dir } as AnyOrderBuilder;
53
- }
54
-
55
- /**
56
- * ColumnBuilder with optional operation methods based on the column's typeId.
57
- * When Operations is provided and the column's typeId matches, operation methods are included.
58
- * Implements ExpressionSource to provide type-safe conversion to ColumnRef.
59
- */
60
- export type ColumnBuilder<
61
- ColumnName extends string = string,
62
- ColumnMeta extends StorageColumn = StorageColumn,
63
- JsType = unknown,
64
- Operations extends OperationTypes = Record<string, never>,
65
- > = {
66
- readonly kind: 'column';
67
- readonly table: string;
68
- readonly column: ColumnName;
69
- readonly columnMeta: ColumnMeta;
70
- // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)
71
- eq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
72
- neq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
73
- gt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
74
- lt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
75
- gte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
76
- lte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
77
- asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
78
- desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
79
- /** Converts this column builder to a ColumnRef expression */
80
- toExpr(): ColumnRef;
81
- // Helper property for type extraction (not used at runtime)
82
- readonly __jsType: JsType;
83
- } & (ColumnMeta['codecId'] extends string
84
- ? ColumnMeta['codecId'] extends keyof Operations
85
- ? OperationMethods<
86
- OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>,
87
- ColumnName,
88
- StorageColumn,
89
- JsType
90
- >
91
- : Record<string, never>
92
- : Record<string, never>);
93
-
94
- export interface BinaryBuilder<
95
- _ColumnName extends string = string,
96
- _ColumnMeta extends StorageColumn = StorageColumn,
97
- _JsType = unknown,
98
- > {
99
- readonly kind: 'binary';
100
- readonly op: BinaryOp;
101
- readonly left: Expression;
102
- readonly right: ValueSource;
103
- }
104
-
105
- // Forward declare AnyBinaryBuilder and AnyOrderBuilder for use in ExpressionBuilder
106
- export type AnyBinaryBuilder = BinaryBuilder;
107
- export type AnyOrderBuilder = OrderBuilder;
108
-
109
- /**
110
- * ExpressionBuilder represents the result of an operation (e.g., col.distance(...)).
111
- * Unlike ColumnBuilder (which represents a column), ExpressionBuilder represents
112
- * an operation expression and provides the same DSL methods for chaining.
113
- *
114
- * Implements ExpressionSource to provide type-safe conversion to OperationExpr.
115
- */
116
- export interface ExpressionBuilder<JsType = unknown> extends ExpressionSource {
117
- readonly kind: 'expression';
118
- readonly expr: OperationExpr;
119
- readonly columnMeta: StorageColumn;
120
-
121
- // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)
122
- eq(value: ValueSource): AnyBinaryBuilder;
123
- neq(value: ValueSource): AnyBinaryBuilder;
124
- gt(value: ValueSource): AnyBinaryBuilder;
125
- lt(value: ValueSource): AnyBinaryBuilder;
126
- gte(value: ValueSource): AnyBinaryBuilder;
127
- lte(value: ValueSource): AnyBinaryBuilder;
128
- asc(): AnyOrderBuilder;
129
- desc(): AnyOrderBuilder;
16
+ import type { ExecutionContext } from './query-lane-context';
130
17
 
131
- /** Converts this expression builder to the underlying OperationExpr */
132
- toExpr(): OperationExpr;
133
-
134
- // Helper property for type extraction (not used at runtime)
135
- readonly __jsType: JsType;
136
- }
137
-
138
- // Helper aliases for usage sites where the specific column parameters are irrelevant
139
- // Accepts any ColumnBuilder regardless of its Operations parameter
140
- // Note: We use `any` here because TypeScript's variance rules don't allow us to express
141
- // "any type that extends OperationTypes" in a way that works for assignment.
142
- // Contract-specific OperationTypes (e.g., PgVectorOperationTypes) are not assignable
143
- // to the base OperationTypes in generic parameter position, even though they extend it structurally.
144
- // Helper type that accepts any ColumnBuilder regardless of its generic parameters
145
- // This is needed because conditional types in ColumnBuilder create incompatible intersection types
146
- // when Operations differs, even though structurally they're compatible
147
- export type AnyColumnBuilderBase = {
148
- readonly kind: 'column';
149
- readonly table: string;
150
- readonly column: string;
151
- readonly columnMeta: StorageColumn;
152
- // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)
153
- eq(value: ValueSource): AnyBinaryBuilder;
154
- neq(value: ValueSource): AnyBinaryBuilder;
155
- gt(value: ValueSource): AnyBinaryBuilder;
156
- lt(value: ValueSource): AnyBinaryBuilder;
157
- gte(value: ValueSource): AnyBinaryBuilder;
158
- lte(value: ValueSource): AnyBinaryBuilder;
159
- asc(): AnyOrderBuilder;
160
- desc(): AnyOrderBuilder;
161
- toExpr(): ColumnRef;
162
- readonly __jsType: unknown;
163
- // Allow any operation methods (from conditional type)
164
- readonly [key: string]: unknown;
165
- };
166
-
167
- export type AnyColumnBuilder =
168
- | ColumnBuilder<
169
- string,
170
- StorageColumn,
171
- unknown,
172
- // biome-ignore lint/suspicious/noExplicitAny: AnyColumnBuilder must accept column builders with any operation types
173
- any
174
- >
175
- | AnyColumnBuilderBase;
18
+ export type Expr = ColumnRef | ParamRef;
176
19
 
177
20
  /**
178
- * Union type for any builder that can produce an Expression.
179
- * Used in DSL method signatures where either a column or operation result can be passed.
21
+ * Extracts the model name for a given table by iterating models to find the one
22
+ * whose `storage.table` matches.
180
23
  */
181
- export type AnyExpressionSource = AnyColumnBuilder | ExpressionBuilder;
182
-
183
- export function isColumnBuilder(value: unknown): value is AnyColumnBuilder {
184
- return (
185
- typeof value === 'object' &&
186
- value !== null &&
187
- 'kind' in value &&
188
- (value as { kind: unknown }).kind === 'column'
189
- );
190
- }
191
-
192
- export interface JoinOnBuilder {
193
- eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;
194
- }
195
-
196
- export interface JoinOnPredicate {
197
- readonly kind: 'join-on';
198
- readonly left: AnyColumnBuilder;
199
- readonly right: AnyColumnBuilder;
200
- }
201
-
202
- export type Expr = ColumnRef | ParamRef;
24
+ type ExtractTableToModel<
25
+ TContract extends Contract<SqlStorage>,
26
+ TableName extends string,
27
+ > = TContract['models'] extends infer Models extends Record<string, unknown>
28
+ ? {
29
+ [M in keyof Models & string]: Models[M] extends {
30
+ readonly storage: { readonly table: TableName };
31
+ }
32
+ ? M
33
+ : never;
34
+ }[keyof Models & string]
35
+ : never;
203
36
 
204
37
  /**
205
- * Helper type to extract codec output type from CodecTypes.
206
- * Returns never if the codecId is not found in CodecTypes.
38
+ * Extracts the field name for a given column by finding the field in
39
+ * `model.storage.fields` whose `column` matches.
207
40
  */
208
- type ExtractCodecOutputType<
209
- CodecId extends string,
210
- CodecTypes extends Record<string, { readonly output: unknown }>,
211
- > = CodecId extends keyof CodecTypes
212
- ? CodecTypes[CodecId] extends { readonly output: infer Output }
213
- ? Output
41
+ type ExtractColumnToField<
42
+ TContract extends Contract<SqlStorage>,
43
+ TableName extends string,
44
+ ColumnName extends string,
45
+ > = ExtractTableToModel<TContract, TableName> extends infer ModelName extends string
46
+ ? TContract['models'] extends infer Models extends Record<string, unknown>
47
+ ? ModelName & keyof Models extends infer MKey extends string
48
+ ? Models[MKey] extends {
49
+ readonly storage: { readonly fields: infer Fields extends Record<string, unknown> };
50
+ }
51
+ ? {
52
+ [F in keyof Fields & string]: Fields[F] extends { readonly column: ColumnName }
53
+ ? F
54
+ : never;
55
+ }[keyof Fields & string]
56
+ : never
57
+ : never
214
58
  : never
215
59
  : never;
216
60
 
61
+ type FallbackCodecLookup<
62
+ ColumnMeta extends StorageColumn,
63
+ CodecTypes extends Record<string, { readonly output: unknown }>,
64
+ > = ColumnMeta extends { codecId: infer CodecId extends string }
65
+ ? CodecId extends keyof CodecTypes
66
+ ? CodecTypes[CodecId] extends { readonly output: infer O }
67
+ ? ColumnMeta extends { nullable: true }
68
+ ? O | null
69
+ : O
70
+ : unknown
71
+ : unknown
72
+ : unknown;
73
+
217
74
  /**
218
75
  * Type-level operation signature.
219
- * Represents an operation at the type level, similar to OperationSignature at runtime.
76
+ * Represents an operation at the type level for use in contract type maps.
220
77
  */
221
78
  export type OperationTypeSignature = {
222
- readonly args: ReadonlyArray<ArgSpec>;
223
- readonly returns: ReturnSpec;
79
+ readonly args: ReadonlyArray<ParamSpec>;
80
+ readonly returns: ParamSpec;
224
81
  readonly lowering: SqlLoweringSpec;
225
82
  readonly capabilities?: ReadonlyArray<string>;
226
83
  };
@@ -234,8 +91,8 @@ export type OperationTypeSignature = {
234
91
  * type MyOperations: OperationTypes = {
235
92
  * 'pg/vector@1': {
236
93
  * cosineDistance: {
237
- * args: [{ kind: 'typeId'; type: 'pg/vector@1' }];
238
- * returns: { kind: 'builtin'; type: 'number' };
94
+ * args: [{ codecId: 'pg/vector@1'; nullable: false }];
95
+ * returns: { codecId: 'core/float8'; nullable: false };
239
96
  * lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
240
97
  * };
241
98
  * };
@@ -277,219 +134,55 @@ export type OperationsForTypeId<
277
134
  ? Operations[TypeId]
278
135
  : Record<string, never>;
279
136
 
280
- /**
281
- * Maps operation signatures to method signatures on ColumnBuilder.
282
- * Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder
283
- * based on the return type.
284
- */
285
- type OperationMethods<
286
- Ops extends Record<string, OperationTypeSignature>,
287
- ColumnName extends string,
288
- ColumnMeta extends StorageColumn,
289
- JsType,
290
- > = {
291
- [K in keyof Ops]: Ops[K] extends OperationTypeSignature
292
- ? (
293
- ...args: OperationArgs<Ops[K]['args']>
294
- ) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType>
295
- : never;
296
- };
297
-
298
- /**
299
- * Maps operation argument specs to TypeScript argument types.
300
- * - typeId args: ColumnBuilder (accepts base columns or operation results)
301
- * - param args: ParamPlaceholder
302
- * - literal args: unknown (could be more specific in future)
303
- */
304
- type OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [
305
- infer First,
306
- ...infer Rest,
307
- ]
308
- ? First extends ArgSpec
309
- ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])]
310
- : []
311
- : [];
312
-
313
- type ArgToType<Arg extends ArgSpec> = Arg extends { kind: 'typeId' }
314
- ? AnyExpressionSource
315
- : Arg extends { kind: 'param' }
316
- ? ParamPlaceholder
317
- : Arg extends { kind: 'literal' }
318
- ? unknown
319
- : never;
320
-
321
- /**
322
- * Maps operation return spec to return type.
323
- * Operations return ExpressionBuilder, not ColumnBuilder, because the result
324
- * represents an expression (OperationExpr) rather than a column reference.
325
- */
326
- type OperationReturn<
327
- Returns extends ReturnSpec,
328
- _ColumnName extends string,
329
- _ColumnMeta extends StorageColumn,
330
- _JsType,
331
- > = Returns extends { kind: 'builtin'; type: infer T }
332
- ? T extends 'number'
333
- ? ExpressionBuilder<number>
334
- : T extends 'boolean'
335
- ? ExpressionBuilder<boolean>
336
- : T extends 'string'
337
- ? ExpressionBuilder<string>
338
- : ExpressionBuilder<unknown>
339
- : Returns extends { kind: 'typeId' }
340
- ? ExpressionBuilder<unknown>
341
- : ExpressionBuilder<unknown>;
342
-
343
- /**
344
- * Computes JavaScript type for a column at column creation time.
345
- *
346
- * Type inference:
347
- * - Read columnMeta.codecId as typeId string literal
348
- * - Look up CodecTypes[typeId].output
349
- * - Apply nullability: nullable ? Output | null : Output
350
- */
351
- type ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends { codecId: infer CodecId extends string }
352
- ? CodecId
353
- : ColumnMeta extends { type: infer TypeId extends string }
354
- ? TypeId
355
- : never;
356
-
357
137
  export type ComputeColumnJsType<
358
- _Contract extends SqlContract<SqlStorage>,
359
- _TableName extends string,
360
- _ColumnName extends string,
138
+ TContract extends Contract<SqlStorage>,
139
+ TableName extends string,
140
+ ColumnName extends string,
361
141
  ColumnMeta extends StorageColumn,
362
142
  CodecTypes extends Record<string, { readonly output: unknown }>,
363
- > = ColumnMeta extends { nullable: infer Nullable }
364
- ? ColumnMetaTypeId<ColumnMeta> extends infer TypeId
365
- ? TypeId extends string
366
- ? ExtractCodecOutputType<TypeId, CodecTypes> extends infer CodecOutput
367
- ? [CodecOutput] extends [never]
368
- ? unknown // Codec not found in CodecTypes
369
- : Nullable extends true
370
- ? CodecOutput | null
371
- : CodecOutput
372
- : unknown
373
- : unknown
374
- : unknown
375
- : unknown;
376
-
377
- /**
378
- * Infers Row type from a projection object.
379
- * Maps Record<string, ColumnBuilder> to Record<string, JSType>
380
- *
381
- * Extracts the pre-computed JsType from each ColumnBuilder in the projection.
382
- */
383
- /**
384
- * Extracts the inferred JsType carried by a ColumnBuilder.
385
- */
386
- type ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> =
387
- CB extends ColumnBuilder<
388
- infer _ColumnName extends string,
389
- infer _ColumnMeta extends StorageColumn,
390
- infer JsType,
391
- infer _Ops
392
- >
393
- ? JsType
394
- : never;
395
-
396
- export type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {
397
- [K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;
398
- };
399
-
400
- /**
401
- * Nested projection type - allows recursive nesting of ColumnBuilder, ExpressionBuilder, or nested objects.
402
- */
403
- export type NestedProjection = Record<
404
- string,
405
- | AnyExpressionSource
406
- | Record<
407
- string,
408
- | AnyExpressionSource
409
- | Record<
410
- string,
411
- | AnyExpressionSource
412
- | Record<string, AnyExpressionSource | Record<string, AnyExpressionSource>>
413
- >
414
- >
415
- >;
416
-
417
- /**
418
- * Helper type to extract include type from Includes map.
419
- * Returns the value type if K is a key of Includes, otherwise returns unknown.
420
- */
421
- type ExtractIncludeType<
422
- K extends string,
423
- Includes extends Record<string, unknown>,
424
- > = K extends keyof Includes ? Includes[K] : unknown;
425
-
426
- /**
427
- * Infers Row type from a nested projection object.
428
- * Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.
429
- *
430
- * Extracts the pre-computed JsType from each ColumnBuilder at leaves.
431
- * When a value is `true`, it represents an include reference and infers `Array<ChildShape>`
432
- * by looking up the include alias in the Includes type map.
433
- */
434
- export type InferNestedProjectionRow<
435
- P extends Record<string, AnyExpressionSource | boolean | NestedProjection>,
436
- CodecTypes extends Record<string, { readonly output: unknown }> = Record<string, never>,
437
- Includes extends Record<string, unknown> = Record<string, never>,
438
- > = {
439
- [K in keyof P]: P[K] extends ExpressionBuilder<infer JsType>
440
- ? JsType
441
- : P[K] extends AnyColumnBuilder
442
- ? ExtractJsTypeFromColumnBuilder<P[K]>
443
- : P[K] extends true
444
- ? Array<ExtractIncludeType<K & string, Includes>> // Include reference - infers Array<ChildShape> from Includes map
445
- : P[K] extends NestedProjection
446
- ? InferNestedProjectionRow<P[K], CodecTypes, Includes>
447
- : never;
448
- };
449
-
450
- /**
451
- * Infers Row type from a tuple of ColumnBuilders used in returning() clause.
452
- * Extracts column name and JsType from each ColumnBuilder and creates a Record.
453
- */
454
- export type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> =
455
- Columns extends readonly [infer First, ...infer Rest]
456
- ? First extends ColumnBuilder<
457
- infer Name,
458
- infer _Meta,
459
- infer JsType,
460
- infer _Ops extends OperationTypes
461
- >
462
- ? Name extends string
463
- ? Rest extends readonly AnyColumnBuilder[]
464
- ? { [K in Name]: JsType } & InferReturningRow<Rest>
465
- : { [K in Name]: JsType }
143
+ > = ExtractTableToModel<TContract, TableName> extends infer ModelName
144
+ ? [ModelName] extends [never]
145
+ ? FallbackCodecLookup<ColumnMeta, CodecTypes>
146
+ : ModelName extends string
147
+ ? ExtractColumnToField<TContract, TableName, ColumnName> extends infer FieldName
148
+ ? [FieldName] extends [never]
149
+ ? FallbackCodecLookup<ColumnMeta, CodecTypes>
150
+ : FieldName extends string
151
+ ? ModelName extends keyof ExtractFieldOutputTypes<TContract>
152
+ ? FieldName extends keyof ExtractFieldOutputTypes<TContract>[ModelName]
153
+ ? ExtractFieldOutputTypes<TContract>[ModelName][FieldName]
154
+ : never
155
+ : never
156
+ : never
466
157
  : never
467
158
  : never
468
- : Record<string, never>;
159
+ : never;
469
160
 
470
161
  /**
471
162
  * Utility type to check if a contract has the required capabilities for includeMany.
472
163
  * Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.
473
164
  * Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`
474
165
  */
475
- export type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> =
476
- TContract extends { capabilities: infer C; target: infer T }
477
- ? T extends string
478
- ? C extends Record<string, Record<string, boolean>>
479
- ? C extends { [K in T]: infer TargetCaps }
480
- ? TargetCaps extends { lateral: true; jsonAgg: true }
481
- ? true
482
- : false
166
+ export type HasIncludeManyCapabilities<TContract extends Contract<SqlStorage>> = TContract extends {
167
+ capabilities: infer C;
168
+ target: infer T;
169
+ }
170
+ ? T extends string
171
+ ? C extends Record<string, Record<string, boolean>>
172
+ ? C extends { [K in T]: infer TargetCaps }
173
+ ? TargetCaps extends { lateral: true; jsonAgg: true }
174
+ ? true
483
175
  : false
484
176
  : false
485
177
  : false
486
- : false;
178
+ : false
179
+ : false;
487
180
 
488
181
  /**
489
- * SQL-specific Plan type that refines the ast field to use QueryAst.
182
+ * SQL-specific Plan type that refines the ast field to use AnyQueryAst.
490
183
  * This is the type used by SQL query builders.
491
184
  */
492
- export type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;
185
+ export type SqlPlan<Row = unknown> = ExecutionPlan<Row, AnyQueryAst>;
493
186
 
494
187
  /**
495
188
  * Helper types for extracting contract structure.
@@ -574,7 +267,14 @@ export interface RawFactory extends RawTemplateFactory {
574
267
  with(options: RawTemplateOptions): RawTemplateFactory;
575
268
  }
576
269
 
577
- export type { RuntimeError } from '@prisma-next/plan';
270
+ export interface RuntimeError extends Error {
271
+ readonly code: string;
272
+ readonly category: 'PLAN';
273
+ readonly severity: 'error';
274
+ readonly details?: Record<string, unknown>;
275
+ readonly hints?: readonly string[];
276
+ readonly docs?: readonly string[];
277
+ }
578
278
 
579
279
  export interface BuildParamsMap {
580
280
  readonly [name: string]: unknown;
@@ -584,10 +284,8 @@ export interface BuildOptions {
584
284
  readonly params?: BuildParamsMap;
585
285
  }
586
286
 
587
- export interface SqlBuilderOptions<
588
- TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,
589
- > {
590
- readonly context: QueryLaneContext<TContract>;
287
+ export interface SqlBuilderOptions<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
288
+ readonly context: ExecutionContext<TContract>;
591
289
  }
592
290
 
593
291
  /**
@@ -1,28 +0,0 @@
1
- import type { CodecRegistry } from './codec-types';
2
- export type AdapterTarget = string;
3
- export interface AdapterProfile<TTarget extends AdapterTarget = AdapterTarget> {
4
- readonly id: string;
5
- readonly target: TTarget;
6
- readonly capabilities: Record<string, unknown>;
7
- /**
8
- * Returns the adapter's default codec registry.
9
- * The registry contains codecs provided by the adapter for converting
10
- * between wire types and JavaScript types.
11
- */
12
- codecs(): CodecRegistry;
13
- }
14
- export interface LoweredPayload<TBody = unknown> {
15
- readonly profileId?: string;
16
- readonly body: TBody;
17
- readonly annotations?: Record<string, unknown>;
18
- }
19
- export interface LowererContext<TContract = unknown> {
20
- readonly contract: TContract;
21
- readonly params?: readonly unknown[];
22
- }
23
- export type Lowerer<Ast = unknown, TContract = unknown, TBody = unknown> = (ast: Ast, context: LowererContext<TContract>) => LoweredPayload<TBody>;
24
- export interface Adapter<Ast = unknown, TContract = unknown, TBody = unknown> {
25
- readonly profile: AdapterProfile;
26
- lower(ast: Ast, context: LowererContext<TContract>): LoweredPayload<TBody>;
27
- }
28
- //# sourceMappingURL=adapter-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter-types.d.ts","sourceRoot":"","sources":["../../src/ast/adapter-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,aAAa,GAAG,aAAa;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C;;;;OAIG;IACH,MAAM,IAAI,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,cAAc,CAAC,KAAK,GAAG,OAAO;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,cAAc,CAAC,SAAS,GAAG,OAAO;IACjD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CACtC;AAED,MAAM,MAAM,OAAO,CAAC,GAAG,GAAG,OAAO,EAAE,SAAS,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,IAAI,CACzE,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,KAC/B,cAAc,CAAC,KAAK,CAAC,CAAC;AAE3B,MAAM,WAAW,OAAO,CAAC,GAAG,GAAG,OAAO,EAAE,SAAS,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IAC1E,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;CAC5E"}