@prisma-next/sql-relational-core 0.3.0-dev.16 → 0.3.0-dev.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +20 -6
- package/dist/codec-types-DcEITed4.d.mts +144 -0
- package/dist/codec-types-DcEITed4.d.mts.map +1 -0
- package/dist/errors-Cs52upp3.d.mts +8 -0
- package/dist/errors-Cs52upp3.d.mts.map +1 -0
- package/dist/errors-D3xmG4h-.mjs +35 -0
- package/dist/errors-D3xmG4h-.mjs.map +1 -0
- package/dist/exports/ast.d.mts +158 -0
- package/dist/exports/ast.d.mts.map +1 -0
- package/dist/exports/ast.mjs +1358 -0
- package/dist/exports/ast.mjs.map +1 -0
- package/dist/exports/errors.d.mts +5 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/plan.d.mts +2 -0
- package/dist/exports/plan.mjs +17 -0
- package/dist/exports/plan.mjs.map +1 -0
- package/dist/exports/query-lane-context.d.mts +3 -0
- package/dist/exports/query-lane-context.mjs +1 -0
- package/dist/exports/types.d.mts +4 -0
- package/dist/exports/types.mjs +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +7 -0
- package/dist/plan-5qUWdlJM.d.mts +28 -0
- package/dist/plan-5qUWdlJM.d.mts.map +1 -0
- package/dist/query-lane-context-UlR8vOkd.d.mts +89 -0
- package/dist/query-lane-context-UlR8vOkd.d.mts.map +1 -0
- package/dist/types-CLCtwVWx.d.mts +485 -0
- package/dist/types-CLCtwVWx.d.mts.map +1 -0
- package/dist/types-V1qiC5DO.d.mts +200 -0
- package/dist/types-V1qiC5DO.d.mts.map +1 -0
- package/package.json +31 -53
- package/src/ast/adapter-types.ts +11 -0
- package/src/ast/codec-types.ts +101 -53
- package/src/ast/driver-types.ts +20 -3
- package/src/ast/sql-codecs.ts +142 -0
- package/src/ast/types.ts +1681 -77
- package/src/errors.ts +47 -1
- package/src/exports/ast.ts +1 -8
- package/src/index.ts +0 -3
- package/src/plan.ts +4 -4
- package/src/query-lane-context.ts +81 -6
- package/src/types.ts +102 -354
- package/dist/ast/adapter-types.d.ts +0 -28
- package/dist/ast/adapter-types.d.ts.map +0 -1
- package/dist/ast/codec-types.d.ts +0 -141
- package/dist/ast/codec-types.d.ts.map +0 -1
- package/dist/ast/common.d.ts +0 -7
- package/dist/ast/common.d.ts.map +0 -1
- package/dist/ast/delete.d.ts +0 -8
- package/dist/ast/delete.d.ts.map +0 -1
- package/dist/ast/driver-types.d.ts +0 -20
- package/dist/ast/driver-types.d.ts.map +0 -1
- package/dist/ast/insert.d.ts +0 -8
- package/dist/ast/insert.d.ts.map +0 -1
- package/dist/ast/join.d.ts +0 -6
- package/dist/ast/join.d.ts.map +0 -1
- package/dist/ast/order.d.ts +0 -6
- package/dist/ast/order.d.ts.map +0 -1
- package/dist/ast/predicate.d.ts +0 -4
- package/dist/ast/predicate.d.ts.map +0 -1
- package/dist/ast/select.d.ts +0 -18
- package/dist/ast/select.d.ts.map +0 -1
- package/dist/ast/types.d.ts +0 -118
- package/dist/ast/types.d.ts.map +0 -1
- package/dist/ast/update.d.ts +0 -9
- package/dist/ast/update.d.ts.map +0 -1
- package/dist/ast/util.d.ts +0 -2
- package/dist/ast/util.d.ts.map +0 -1
- package/dist/chunk-2F7DSEOU.js +0 -8
- package/dist/chunk-2F7DSEOU.js.map +0 -1
- package/dist/chunk-36WJWNHT.js +0 -1
- package/dist/chunk-36WJWNHT.js.map +0 -1
- package/dist/chunk-5N34PNVZ.js +0 -62
- package/dist/chunk-5N34PNVZ.js.map +0 -1
- package/dist/chunk-7I3EMQID.js +0 -16
- package/dist/chunk-7I3EMQID.js.map +0 -1
- package/dist/chunk-D4JLPIWO.js +0 -13
- package/dist/chunk-D4JLPIWO.js.map +0 -1
- package/dist/chunk-G52ENULI.js +0 -1
- package/dist/chunk-G52ENULI.js.map +0 -1
- package/dist/chunk-J6O2HVBM.js +0 -320
- package/dist/chunk-J6O2HVBM.js.map +0 -1
- package/dist/chunk-KYSP7L5C.js +0 -16
- package/dist/chunk-KYSP7L5C.js.map +0 -1
- package/dist/chunk-M23L3JHG.js +0 -159
- package/dist/chunk-M23L3JHG.js.map +0 -1
- package/dist/chunk-U7AXAUJA.js +0 -1
- package/dist/chunk-U7AXAUJA.js.map +0 -1
- package/dist/chunk-U7IAFPVU.js +0 -152
- package/dist/chunk-U7IAFPVU.js.map +0 -1
- package/dist/errors.d.ts +0 -2
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/ast.d.ts +0 -14
- package/dist/exports/ast.d.ts.map +0 -1
- package/dist/exports/ast.js +0 -46
- package/dist/exports/ast.js.map +0 -1
- package/dist/exports/errors.d.ts +0 -2
- package/dist/exports/errors.d.ts.map +0 -1
- package/dist/exports/errors.js +0 -9
- package/dist/exports/errors.js.map +0 -1
- package/dist/exports/guards.d.ts +0 -2
- package/dist/exports/guards.d.ts.map +0 -1
- package/dist/exports/guards.js +0 -21
- package/dist/exports/guards.js.map +0 -1
- package/dist/exports/operations-registry.d.ts +0 -2
- package/dist/exports/operations-registry.d.ts.map +0 -1
- package/dist/exports/operations-registry.js +0 -9
- package/dist/exports/operations-registry.js.map +0 -1
- package/dist/exports/param.d.ts +0 -3
- package/dist/exports/param.d.ts.map +0 -1
- package/dist/exports/param.js +0 -7
- package/dist/exports/param.js.map +0 -1
- package/dist/exports/plan.d.ts +0 -2
- package/dist/exports/plan.d.ts.map +0 -1
- package/dist/exports/plan.js +0 -7
- package/dist/exports/plan.js.map +0 -1
- package/dist/exports/query-lane-context.d.ts +0 -2
- package/dist/exports/query-lane-context.d.ts.map +0 -1
- package/dist/exports/query-lane-context.js +0 -2
- package/dist/exports/query-lane-context.js.map +0 -1
- package/dist/exports/schema.d.ts +0 -3
- package/dist/exports/schema.d.ts.map +0 -1
- package/dist/exports/schema.js +0 -14
- package/dist/exports/schema.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -10
- package/dist/exports/types.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/operations-registry.d.ts +0 -5
- package/dist/operations-registry.d.ts.map +0 -1
- package/dist/param.d.ts +0 -4
- package/dist/param.d.ts.map +0 -1
- package/dist/plan.d.ts +0 -23
- package/dist/plan.d.ts.map +0 -1
- package/dist/query-lane-context.d.ts +0 -16
- package/dist/query-lane-context.d.ts.map +0 -1
- package/dist/schema.d.ts +0 -63
- package/dist/schema.d.ts.map +0 -1
- package/dist/types.d.ts +0 -332
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/guards.d.ts +0 -55
- package/dist/utils/guards.d.ts.map +0 -1
- package/src/ast/common.ts +0 -36
- package/src/ast/delete.ts +0 -17
- package/src/ast/insert.ts +0 -17
- package/src/ast/join.ts +0 -54
- package/src/ast/order.ts +0 -11
- package/src/ast/predicate.ts +0 -30
- package/src/ast/select.ts +0 -39
- package/src/ast/update.ts +0 -19
- package/src/exports/guards.ts +0 -10
- package/src/exports/operations-registry.ts +0 -1
- package/src/exports/param.ts +0 -2
- package/src/exports/schema.ts +0 -6
- package/src/operations-registry.ts +0 -237
- package/src/param.ts +0 -15
- package/src/schema.ts +0 -373
- package/src/utils/guards.ts +0 -123
package/src/types.ts
CHANGED
|
@@ -1,179 +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 {
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} 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';
|
|
17
15
|
import type { SqlQueryPlan } from './plan';
|
|
18
|
-
import type {
|
|
19
|
-
|
|
20
|
-
export interface ParamPlaceholder {
|
|
21
|
-
readonly kind: 'param-placeholder';
|
|
22
|
-
readonly name: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface OrderBuilder<
|
|
26
|
-
ColumnName extends string = string,
|
|
27
|
-
ColumnMeta extends StorageColumn = StorageColumn,
|
|
28
|
-
JsType = unknown,
|
|
29
|
-
> {
|
|
30
|
-
readonly kind: 'order';
|
|
31
|
-
readonly expr: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;
|
|
32
|
-
readonly dir: Direction;
|
|
33
|
-
}
|
|
16
|
+
import type { ExecutionContext } from './query-lane-context';
|
|
34
17
|
|
|
35
|
-
|
|
36
|
-
* Creates an OrderBuilder for use in orderBy clauses.
|
|
37
|
-
*/
|
|
38
|
-
export function createOrderBuilder(
|
|
39
|
-
expr: AnyColumnBuilder | OperationExpr,
|
|
40
|
-
dir: Direction,
|
|
41
|
-
): AnyOrderBuilder {
|
|
42
|
-
return { kind: 'order', expr, dir } as AnyOrderBuilder;
|
|
43
|
-
}
|
|
18
|
+
export type Expr = ColumnRef | ParamRef;
|
|
44
19
|
|
|
45
20
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
21
|
+
* Extracts the model name for a given table by iterating models to find the one
|
|
22
|
+
* whose `storage.table` matches.
|
|
48
23
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
value: ParamPlaceholder | AnyColumnBuilderBase,
|
|
62
|
-
): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
63
|
-
gt(value: ParamPlaceholder | AnyColumnBuilderBase): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
64
|
-
lt(value: ParamPlaceholder | AnyColumnBuilderBase): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
65
|
-
gte(
|
|
66
|
-
value: ParamPlaceholder | AnyColumnBuilderBase,
|
|
67
|
-
): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
68
|
-
lte(
|
|
69
|
-
value: ParamPlaceholder | AnyColumnBuilderBase,
|
|
70
|
-
): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
71
|
-
asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
72
|
-
desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
73
|
-
// Helper property for type extraction (not used at runtime)
|
|
74
|
-
readonly __jsType: JsType;
|
|
75
|
-
} & (ColumnMeta['codecId'] extends string
|
|
76
|
-
? ColumnMeta['codecId'] extends keyof Operations
|
|
77
|
-
? OperationMethods<
|
|
78
|
-
OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>,
|
|
79
|
-
ColumnName,
|
|
80
|
-
StorageColumn,
|
|
81
|
-
JsType
|
|
82
|
-
>
|
|
83
|
-
: Record<string, never>
|
|
84
|
-
: Record<string, never>);
|
|
85
|
-
|
|
86
|
-
export interface BinaryBuilder<
|
|
87
|
-
ColumnName extends string = string,
|
|
88
|
-
ColumnMeta extends StorageColumn = StorageColumn,
|
|
89
|
-
JsType = unknown,
|
|
90
|
-
> {
|
|
91
|
-
readonly kind: 'binary';
|
|
92
|
-
readonly op: BinaryOp;
|
|
93
|
-
readonly left: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;
|
|
94
|
-
readonly right: ParamPlaceholder | AnyColumnBuilderBase;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Helper aliases for usage sites where the specific column parameters are irrelevant
|
|
98
|
-
// Accepts any ColumnBuilder regardless of its Operations parameter
|
|
99
|
-
// Note: We use `any` here because TypeScript's variance rules don't allow us to express
|
|
100
|
-
// "any type that extends OperationTypes" in a way that works for assignment.
|
|
101
|
-
// Contract-specific OperationTypes (e.g., PgVectorOperationTypes) are not assignable
|
|
102
|
-
// to the base OperationTypes in generic parameter position, even though they extend it structurally.
|
|
103
|
-
// Helper type that accepts any ColumnBuilder regardless of its generic parameters
|
|
104
|
-
// This is needed because conditional types in ColumnBuilder create incompatible intersection types
|
|
105
|
-
// when Operations differs, even though structurally they're compatible
|
|
106
|
-
export type AnyColumnBuilderBase = {
|
|
107
|
-
readonly kind: 'column';
|
|
108
|
-
readonly table: string;
|
|
109
|
-
readonly column: string;
|
|
110
|
-
readonly columnMeta: StorageColumn;
|
|
111
|
-
eq(value: ParamPlaceholder | AnyColumnBuilderBase): AnyBinaryBuilder;
|
|
112
|
-
neq(value: ParamPlaceholder | AnyColumnBuilderBase): AnyBinaryBuilder;
|
|
113
|
-
gt(value: ParamPlaceholder | AnyColumnBuilderBase): AnyBinaryBuilder;
|
|
114
|
-
lt(value: ParamPlaceholder | AnyColumnBuilderBase): AnyBinaryBuilder;
|
|
115
|
-
gte(value: ParamPlaceholder | AnyColumnBuilderBase): AnyBinaryBuilder;
|
|
116
|
-
lte(value: ParamPlaceholder | AnyColumnBuilderBase): AnyBinaryBuilder;
|
|
117
|
-
asc(): AnyOrderBuilder;
|
|
118
|
-
desc(): AnyOrderBuilder;
|
|
119
|
-
readonly __jsType: unknown;
|
|
120
|
-
// Allow any operation methods (from conditional type)
|
|
121
|
-
readonly [key: string]: unknown;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export type AnyColumnBuilder =
|
|
125
|
-
| ColumnBuilder<
|
|
126
|
-
string,
|
|
127
|
-
StorageColumn,
|
|
128
|
-
unknown,
|
|
129
|
-
// biome-ignore lint/suspicious/noExplicitAny: AnyColumnBuilder must accept column builders with any operation types
|
|
130
|
-
any
|
|
131
|
-
>
|
|
132
|
-
| AnyColumnBuilderBase;
|
|
133
|
-
export type AnyBinaryBuilder = BinaryBuilder<string, StorageColumn, unknown>;
|
|
134
|
-
export type AnyOrderBuilder = OrderBuilder<string, StorageColumn, unknown>;
|
|
135
|
-
|
|
136
|
-
export function isColumnBuilder(value: unknown): value is AnyColumnBuilder {
|
|
137
|
-
return (
|
|
138
|
-
typeof value === 'object' &&
|
|
139
|
-
value !== null &&
|
|
140
|
-
'kind' in value &&
|
|
141
|
-
(value as { kind: unknown }).kind === 'column'
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface JoinOnBuilder {
|
|
146
|
-
eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface JoinOnPredicate {
|
|
150
|
-
readonly kind: 'join-on';
|
|
151
|
-
readonly left: AnyColumnBuilder;
|
|
152
|
-
readonly right: AnyColumnBuilder;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
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;
|
|
156
36
|
|
|
157
37
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
38
|
+
* Extracts the field name for a given column by finding the field in
|
|
39
|
+
* `model.storage.fields` whose `column` matches.
|
|
160
40
|
*/
|
|
161
|
-
type
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
167
58
|
: never
|
|
168
59
|
: never;
|
|
169
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
|
+
|
|
170
74
|
/**
|
|
171
75
|
* Type-level operation signature.
|
|
172
|
-
* Represents an operation at the type level
|
|
76
|
+
* Represents an operation at the type level for use in contract type maps.
|
|
173
77
|
*/
|
|
174
78
|
export type OperationTypeSignature = {
|
|
175
|
-
readonly args: ReadonlyArray<
|
|
176
|
-
readonly returns:
|
|
79
|
+
readonly args: ReadonlyArray<ParamSpec>;
|
|
80
|
+
readonly returns: ParamSpec;
|
|
177
81
|
readonly lowering: SqlLoweringSpec;
|
|
178
82
|
readonly capabilities?: ReadonlyArray<string>;
|
|
179
83
|
};
|
|
@@ -187,8 +91,8 @@ export type OperationTypeSignature = {
|
|
|
187
91
|
* type MyOperations: OperationTypes = {
|
|
188
92
|
* 'pg/vector@1': {
|
|
189
93
|
* cosineDistance: {
|
|
190
|
-
* args: [{
|
|
191
|
-
* returns: {
|
|
94
|
+
* args: [{ codecId: 'pg/vector@1'; nullable: false }];
|
|
95
|
+
* returns: { codecId: 'core/float8'; nullable: false };
|
|
192
96
|
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
193
97
|
* };
|
|
194
98
|
* };
|
|
@@ -230,216 +134,55 @@ export type OperationsForTypeId<
|
|
|
230
134
|
? Operations[TypeId]
|
|
231
135
|
: Record<string, never>;
|
|
232
136
|
|
|
233
|
-
/**
|
|
234
|
-
* Maps operation signatures to method signatures on ColumnBuilder.
|
|
235
|
-
* Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder
|
|
236
|
-
* based on the return type.
|
|
237
|
-
*/
|
|
238
|
-
type OperationMethods<
|
|
239
|
-
Ops extends Record<string, OperationTypeSignature>,
|
|
240
|
-
ColumnName extends string,
|
|
241
|
-
ColumnMeta extends StorageColumn,
|
|
242
|
-
JsType,
|
|
243
|
-
> = {
|
|
244
|
-
[K in keyof Ops]: Ops[K] extends OperationTypeSignature
|
|
245
|
-
? (
|
|
246
|
-
...args: OperationArgs<Ops[K]['args']>
|
|
247
|
-
) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType>
|
|
248
|
-
: never;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Maps operation argument specs to TypeScript argument types.
|
|
253
|
-
* - typeId args: ColumnBuilder (accepts base columns or operation results)
|
|
254
|
-
* - param args: ParamPlaceholder
|
|
255
|
-
* - literal args: unknown (could be more specific in future)
|
|
256
|
-
*/
|
|
257
|
-
type OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [
|
|
258
|
-
infer First,
|
|
259
|
-
...infer Rest,
|
|
260
|
-
]
|
|
261
|
-
? First extends ArgSpec
|
|
262
|
-
? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])]
|
|
263
|
-
: []
|
|
264
|
-
: [];
|
|
265
|
-
|
|
266
|
-
type ArgToType<Arg extends ArgSpec> = Arg extends { kind: 'typeId' }
|
|
267
|
-
? AnyColumnBuilder
|
|
268
|
-
: Arg extends { kind: 'param' }
|
|
269
|
-
? ParamPlaceholder
|
|
270
|
-
: Arg extends { kind: 'literal' }
|
|
271
|
-
? unknown
|
|
272
|
-
: never;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Maps operation return spec to return type.
|
|
276
|
-
* - builtin types: ColumnBuilder with appropriate JsType (matches runtime behavior)
|
|
277
|
-
* - typeId types: ColumnBuilder (for now, could be more specific in future)
|
|
278
|
-
*/
|
|
279
|
-
type OperationReturn<
|
|
280
|
-
Returns extends ReturnSpec,
|
|
281
|
-
ColumnName extends string,
|
|
282
|
-
ColumnMeta extends StorageColumn,
|
|
283
|
-
_JsType,
|
|
284
|
-
> = Returns extends { kind: 'builtin'; type: infer T }
|
|
285
|
-
? T extends 'number'
|
|
286
|
-
? ColumnBuilder<ColumnName, ColumnMeta, number>
|
|
287
|
-
: T extends 'boolean'
|
|
288
|
-
? ColumnBuilder<ColumnName, ColumnMeta, boolean>
|
|
289
|
-
: T extends 'string'
|
|
290
|
-
? ColumnBuilder<ColumnName, ColumnMeta, string>
|
|
291
|
-
: ColumnBuilder<ColumnName, ColumnMeta, unknown>
|
|
292
|
-
: Returns extends { kind: 'typeId' }
|
|
293
|
-
? AnyColumnBuilder
|
|
294
|
-
: ColumnBuilder<ColumnName, ColumnMeta, unknown>;
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Computes JavaScript type for a column at column creation time.
|
|
298
|
-
*
|
|
299
|
-
* Type inference:
|
|
300
|
-
* - Read columnMeta.codecId as typeId string literal
|
|
301
|
-
* - Look up CodecTypes[typeId].output
|
|
302
|
-
* - Apply nullability: nullable ? Output | null : Output
|
|
303
|
-
*/
|
|
304
|
-
type ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends { codecId: infer CodecId extends string }
|
|
305
|
-
? CodecId
|
|
306
|
-
: ColumnMeta extends { type: infer TypeId extends string }
|
|
307
|
-
? TypeId
|
|
308
|
-
: never;
|
|
309
|
-
|
|
310
137
|
export type ComputeColumnJsType<
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
138
|
+
TContract extends Contract<SqlStorage>,
|
|
139
|
+
TableName extends string,
|
|
140
|
+
ColumnName extends string,
|
|
314
141
|
ColumnMeta extends StorageColumn,
|
|
315
142
|
CodecTypes extends Record<string, { readonly output: unknown }>,
|
|
316
|
-
> =
|
|
317
|
-
?
|
|
318
|
-
?
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Infers Row type from a projection object.
|
|
332
|
-
* Maps Record<string, ColumnBuilder> to Record<string, JSType>
|
|
333
|
-
*
|
|
334
|
-
* Extracts the pre-computed JsType from each ColumnBuilder in the projection.
|
|
335
|
-
*/
|
|
336
|
-
/**
|
|
337
|
-
* Extracts the inferred JsType carried by a ColumnBuilder.
|
|
338
|
-
*/
|
|
339
|
-
type ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> =
|
|
340
|
-
CB extends ColumnBuilder<
|
|
341
|
-
infer _ColumnName extends string,
|
|
342
|
-
infer _ColumnMeta extends StorageColumn,
|
|
343
|
-
infer JsType,
|
|
344
|
-
infer _Ops
|
|
345
|
-
>
|
|
346
|
-
? JsType
|
|
347
|
-
: never;
|
|
348
|
-
|
|
349
|
-
export type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {
|
|
350
|
-
[K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Nested projection type - allows recursive nesting of ColumnBuilder or nested objects.
|
|
355
|
-
*/
|
|
356
|
-
export type NestedProjection = Record<
|
|
357
|
-
string,
|
|
358
|
-
| AnyColumnBuilder
|
|
359
|
-
| Record<
|
|
360
|
-
string,
|
|
361
|
-
| AnyColumnBuilder
|
|
362
|
-
| Record<
|
|
363
|
-
string,
|
|
364
|
-
AnyColumnBuilder | Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder>>
|
|
365
|
-
>
|
|
366
|
-
>
|
|
367
|
-
>;
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Helper type to extract include type from Includes map.
|
|
371
|
-
* Returns the value type if K is a key of Includes, otherwise returns unknown.
|
|
372
|
-
*/
|
|
373
|
-
type ExtractIncludeType<
|
|
374
|
-
K extends string,
|
|
375
|
-
Includes extends Record<string, unknown>,
|
|
376
|
-
> = K extends keyof Includes ? Includes[K] : unknown;
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Infers Row type from a nested projection object.
|
|
380
|
-
* Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.
|
|
381
|
-
*
|
|
382
|
-
* Extracts the pre-computed JsType from each ColumnBuilder at leaves.
|
|
383
|
-
* When a value is `true`, it represents an include reference and infers `Array<ChildShape>`
|
|
384
|
-
* by looking up the include alias in the Includes type map.
|
|
385
|
-
*/
|
|
386
|
-
export type InferNestedProjectionRow<
|
|
387
|
-
P extends Record<string, AnyColumnBuilder | boolean | NestedProjection>,
|
|
388
|
-
CodecTypes extends Record<string, { readonly output: unknown }> = Record<string, never>,
|
|
389
|
-
Includes extends Record<string, unknown> = Record<string, never>,
|
|
390
|
-
> = {
|
|
391
|
-
[K in keyof P]: P[K] extends AnyColumnBuilder
|
|
392
|
-
? ExtractJsTypeFromColumnBuilder<P[K]>
|
|
393
|
-
: P[K] extends true
|
|
394
|
-
? Array<ExtractIncludeType<K & string, Includes>> // Include reference - infers Array<ChildShape> from Includes map
|
|
395
|
-
: P[K] extends NestedProjection
|
|
396
|
-
? InferNestedProjectionRow<P[K], CodecTypes, Includes>
|
|
397
|
-
: never;
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Infers Row type from a tuple of ColumnBuilders used in returning() clause.
|
|
402
|
-
* Extracts column name and JsType from each ColumnBuilder and creates a Record.
|
|
403
|
-
*/
|
|
404
|
-
export type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> =
|
|
405
|
-
Columns extends readonly [infer First, ...infer Rest]
|
|
406
|
-
? First extends ColumnBuilder<
|
|
407
|
-
infer Name,
|
|
408
|
-
infer _Meta,
|
|
409
|
-
infer JsType,
|
|
410
|
-
infer _Ops extends OperationTypes
|
|
411
|
-
>
|
|
412
|
-
? Name extends string
|
|
413
|
-
? Rest extends readonly AnyColumnBuilder[]
|
|
414
|
-
? { [K in Name]: JsType } & InferReturningRow<Rest>
|
|
415
|
-
: { [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
|
|
416
157
|
: never
|
|
417
158
|
: never
|
|
418
|
-
|
|
159
|
+
: never;
|
|
419
160
|
|
|
420
161
|
/**
|
|
421
162
|
* Utility type to check if a contract has the required capabilities for includeMany.
|
|
422
163
|
* Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.
|
|
423
164
|
* Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`
|
|
424
165
|
*/
|
|
425
|
-
export type HasIncludeManyCapabilities<TContract extends
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
|
433
175
|
: false
|
|
434
176
|
: false
|
|
435
177
|
: false
|
|
436
|
-
: false
|
|
178
|
+
: false
|
|
179
|
+
: false;
|
|
437
180
|
|
|
438
181
|
/**
|
|
439
|
-
* SQL-specific Plan type that refines the ast field to use
|
|
182
|
+
* SQL-specific Plan type that refines the ast field to use AnyQueryAst.
|
|
440
183
|
* This is the type used by SQL query builders.
|
|
441
184
|
*/
|
|
442
|
-
export type SqlPlan<Row = unknown> = ExecutionPlan<Row,
|
|
185
|
+
export type SqlPlan<Row = unknown> = ExecutionPlan<Row, AnyQueryAst>;
|
|
443
186
|
|
|
444
187
|
/**
|
|
445
188
|
* Helper types for extracting contract structure.
|
|
@@ -524,7 +267,14 @@ export interface RawFactory extends RawTemplateFactory {
|
|
|
524
267
|
with(options: RawTemplateOptions): RawTemplateFactory;
|
|
525
268
|
}
|
|
526
269
|
|
|
527
|
-
export
|
|
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
|
+
}
|
|
528
278
|
|
|
529
279
|
export interface BuildParamsMap {
|
|
530
280
|
readonly [name: string]: unknown;
|
|
@@ -534,10 +284,8 @@ export interface BuildOptions {
|
|
|
534
284
|
readonly params?: BuildParamsMap;
|
|
535
285
|
}
|
|
536
286
|
|
|
537
|
-
export interface SqlBuilderOptions<
|
|
538
|
-
|
|
539
|
-
> {
|
|
540
|
-
readonly context: QueryLaneContext<TContract>;
|
|
287
|
+
export interface SqlBuilderOptions<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
|
|
288
|
+
readonly context: ExecutionContext<TContract>;
|
|
541
289
|
}
|
|
542
290
|
|
|
543
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"}
|