@prisma-next/sql-relational-core 0.13.0 → 0.14.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.
- package/dist/{ddl-types-D3vlEjMA.d.mts → ddl-types-BVO002FS.d.mts} +6 -2
- package/dist/ddl-types-BVO002FS.d.mts.map +1 -0
- package/dist/{ddl-types-X9_XHUl0.mjs → ddl-types-DAox2c8w.mjs} +4 -1
- package/dist/ddl-types-DAox2c8w.mjs.map +1 -0
- package/dist/{errors-CPLfzKkw.d.mts → errors-COyZClzw.d.mts} +2 -2
- package/dist/{errors-CPLfzKkw.d.mts.map → errors-COyZClzw.d.mts.map} +1 -1
- package/dist/exports/ast.d.mts +11 -3
- package/dist/exports/ast.d.mts.map +1 -1
- package/dist/exports/ast.mjs +3 -3
- package/dist/exports/codec-descriptor-registry.d.mts +1 -1
- package/dist/exports/codec-descriptor-registry.d.mts.map +1 -1
- package/dist/exports/codec-descriptor-registry.mjs +2 -13
- package/dist/exports/codec-descriptor-registry.mjs.map +1 -1
- package/dist/exports/contract-free.d.mts +60 -3
- package/dist/exports/contract-free.d.mts.map +1 -1
- package/dist/exports/contract-free.mjs +123 -3
- package/dist/exports/contract-free.mjs.map +1 -1
- package/dist/exports/errors.d.mts +1 -1
- package/dist/exports/expression.d.mts +1 -1
- package/dist/exports/expression.mjs +1 -1
- package/dist/exports/middleware.d.mts +1 -1
- package/dist/exports/plan.d.mts +2 -2
- package/dist/exports/query-lane-context.d.mts +1 -1
- package/dist/exports/types.d.mts +3 -3
- package/dist/index.d.mts +10 -10
- package/dist/index.mjs +3 -3
- package/dist/{middleware-BXSFukKU.d.mts → middleware-Dyyo4IP1.d.mts} +2 -2
- package/dist/{middleware-BXSFukKU.d.mts.map → middleware-Dyyo4IP1.d.mts.map} +1 -1
- package/dist/{plan-DObuWSWi.d.mts → plan-DUjdGLY3.d.mts} +2 -2
- package/dist/{plan-DObuWSWi.d.mts.map → plan-DUjdGLY3.d.mts.map} +1 -1
- package/dist/{query-lane-context-CY0-e8Qo.d.mts → query-lane-context-DFnJVqUH.d.mts} +9 -1
- package/dist/query-lane-context-DFnJVqUH.d.mts.map +1 -0
- package/dist/{sql-execution-plan-JwVeAzXt.d.mts → sql-execution-plan-DjMEAjKK.d.mts} +2 -2
- package/dist/{sql-execution-plan-JwVeAzXt.d.mts.map → sql-execution-plan-DjMEAjKK.d.mts.map} +1 -1
- package/dist/{types-LGikJRYV.d.mts → types-CUHnDsdV.d.mts} +3 -3
- package/dist/{types-LGikJRYV.d.mts.map → types-CUHnDsdV.d.mts.map} +1 -1
- package/dist/{types-BbGUx5Bi.d.mts → types-DQrmgP8Y.d.mts} +17 -5
- package/dist/{types-BbGUx5Bi.d.mts.map → types-DQrmgP8Y.d.mts.map} +1 -1
- package/dist/{types-D72v8s92.mjs → types-lJUc6cY-.mjs} +78 -18
- package/dist/types-lJUc6cY-.mjs.map +1 -0
- package/dist/types-lWs6p0ny.d.mts +233 -0
- package/dist/types-lWs6p0ny.d.mts.map +1 -0
- package/package.json +11 -11
- package/src/ast/ddl-types.ts +5 -0
- package/src/ast/driver-types.ts +8 -0
- package/src/ast/types.ts +98 -19
- package/src/codec-ref-for-column.ts +2 -35
- package/src/contract-free/column.ts +2 -0
- package/src/contract-free/dml.ts +5 -0
- package/src/contract-free/table.ts +191 -1
- package/src/exports/contract-free.ts +5 -0
- package/src/query-lane-context.ts +8 -0
- package/src/types.ts +134 -22
- package/dist/ddl-types-D3vlEjMA.d.mts.map +0 -1
- package/dist/ddl-types-X9_XHUl0.mjs.map +0 -1
- package/dist/query-lane-context-CY0-e8Qo.d.mts.map +0 -1
- package/dist/types-CQVke4QO.d.mts +0 -181
- package/dist/types-CQVke4QO.d.mts.map +0 -1
- package/dist/types-D72v8s92.mjs.map +0 -1
|
@@ -1,19 +1,28 @@
|
|
|
1
|
+
import type { ParamSpec } from '@prisma-next/operations';
|
|
1
2
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
2
3
|
import {
|
|
4
|
+
AggregateExpr,
|
|
3
5
|
AndExpr,
|
|
4
6
|
type AnyExpression,
|
|
7
|
+
type AnyFromSource,
|
|
5
8
|
BinaryExpr,
|
|
6
9
|
ColumnRef,
|
|
10
|
+
ExistsExpr,
|
|
11
|
+
IdentifierRef,
|
|
7
12
|
InsertAst,
|
|
8
13
|
InsertOnConflict,
|
|
9
14
|
type InsertValue,
|
|
15
|
+
JoinAst,
|
|
16
|
+
LiteralExpr,
|
|
10
17
|
NullCheckExpr,
|
|
18
|
+
OperationExpr,
|
|
11
19
|
OrderByItem,
|
|
12
20
|
OrExpr,
|
|
13
21
|
ParamRef,
|
|
14
22
|
ProjectionItem,
|
|
23
|
+
RawExpr,
|
|
15
24
|
SelectAst,
|
|
16
|
-
|
|
25
|
+
TableSource,
|
|
17
26
|
UpdateAst,
|
|
18
27
|
} from '../ast/types';
|
|
19
28
|
|
|
@@ -43,6 +52,187 @@ export class CfExpr {
|
|
|
43
52
|
not(): CfExpr {
|
|
44
53
|
return new CfExpr(this.ast.not());
|
|
45
54
|
}
|
|
55
|
+
|
|
56
|
+
isNull(): CfExpr {
|
|
57
|
+
return new CfExpr(NullCheckExpr.isNull(this.ast));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
isNotNull(): CfExpr {
|
|
61
|
+
return new CfExpr(NullCheckExpr.isNotNull(this.ast));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
eqLit(value: number | string | boolean): CfExpr {
|
|
65
|
+
return new CfExpr(BinaryExpr.eq(this.ast, LiteralExpr.of(value)));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
gtLit(value: number | string | boolean): CfExpr {
|
|
69
|
+
return new CfExpr(BinaryExpr.gt(this.ast, LiteralExpr.of(value)));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
eqParam(value: unknown, codecId: string): CfExpr {
|
|
73
|
+
return new CfExpr(BinaryExpr.eq(this.ast, ParamRef.of(value, { codec: { codecId } })));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
eqExpr(other: CfExpr): CfExpr {
|
|
77
|
+
return new CfExpr(BinaryExpr.eq(this.ast, other.ast));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface CfFnOptions {
|
|
82
|
+
readonly method: string;
|
|
83
|
+
readonly template: string;
|
|
84
|
+
readonly self: CfExpr;
|
|
85
|
+
readonly args?: ReadonlyArray<CfExpr>;
|
|
86
|
+
readonly returns: ParamSpec;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const cfExpr = {
|
|
90
|
+
countStar(): CfExpr {
|
|
91
|
+
return new CfExpr(AggregateExpr.count());
|
|
92
|
+
},
|
|
93
|
+
lit(value: number | string | boolean): CfExpr {
|
|
94
|
+
return new CfExpr(LiteralExpr.of(value));
|
|
95
|
+
},
|
|
96
|
+
identifierRef(name: string): CfExpr {
|
|
97
|
+
return new CfExpr(IdentifierRef.of(name));
|
|
98
|
+
},
|
|
99
|
+
param(value: unknown, codecId: string): CfExpr {
|
|
100
|
+
return new CfExpr(ParamRef.of(value, { codec: { codecId } }));
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* Catalog function call lowered via a `'function'`-strategy template
|
|
104
|
+
* (e.g. `to_regclass({{self}})`). Owns the `OperationExpr` assembly so
|
|
105
|
+
* target packages only supply vocabulary: template, codec'd operands,
|
|
106
|
+
* and return spec.
|
|
107
|
+
*/
|
|
108
|
+
fn(options: CfFnOptions): CfExpr {
|
|
109
|
+
return new CfExpr(
|
|
110
|
+
new OperationExpr({
|
|
111
|
+
method: options.method,
|
|
112
|
+
self: options.self.ast,
|
|
113
|
+
args: options.args?.map((arg) => arg.ast),
|
|
114
|
+
returns: options.returns,
|
|
115
|
+
lowering: {
|
|
116
|
+
targetFamily: 'sql',
|
|
117
|
+
strategy: 'function',
|
|
118
|
+
template: options.template,
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
},
|
|
123
|
+
columnRef(qualifier: string, name: string): CfExpr {
|
|
124
|
+
return new CfExpr(ColumnRef.of(qualifier, name));
|
|
125
|
+
},
|
|
126
|
+
allOf(exprs: ReadonlyArray<CfExpr>): CfExpr {
|
|
127
|
+
return new CfExpr(AndExpr.of(exprs.map((expr) => expr.ast)));
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Opaque DB-side SQL expression (e.g. `current_schema()`) carried as a
|
|
131
|
+
* `RawExpr`. For zero-operand catalog functions where a `'function'`
|
|
132
|
+
* lowering template has nothing to substitute.
|
|
133
|
+
*/
|
|
134
|
+
raw(sql: string, returns: ParamSpec): CfExpr {
|
|
135
|
+
return new CfExpr(new RawExpr({ parts: [sql], returns }));
|
|
136
|
+
},
|
|
137
|
+
exists(query: CfExprSelectQuery): CfExpr {
|
|
138
|
+
return new CfExpr(ExistsExpr.exists(query.build()));
|
|
139
|
+
},
|
|
140
|
+
notExists(query: CfExprSelectQuery): CfExpr {
|
|
141
|
+
return new CfExpr(ExistsExpr.notExists(query.build()));
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** Aliased table source for catalog queries (no namespace coordinate). */
|
|
146
|
+
export function cfTable(name: string, alias?: string): TableSource {
|
|
147
|
+
return TableSource.named(name, alias);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export class CfExprSelectQuery {
|
|
151
|
+
constructor(
|
|
152
|
+
private readonly src: AnyFromSource | undefined,
|
|
153
|
+
private readonly projectionItems: ReadonlyArray<ProjectionItem>,
|
|
154
|
+
private readonly whereExpr: CfExpr | undefined,
|
|
155
|
+
private readonly joinItems: ReadonlyArray<JoinAst> = [],
|
|
156
|
+
private readonly limitValue: number | undefined = undefined,
|
|
157
|
+
) {}
|
|
158
|
+
|
|
159
|
+
from(source: AnyFromSource): CfExprSelectQuery {
|
|
160
|
+
return new CfExprSelectQuery(
|
|
161
|
+
source,
|
|
162
|
+
this.projectionItems,
|
|
163
|
+
this.whereExpr,
|
|
164
|
+
this.joinItems,
|
|
165
|
+
this.limitValue,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
join(source: AnyFromSource, on: CfExpr): CfExprSelectQuery {
|
|
170
|
+
return new CfExprSelectQuery(
|
|
171
|
+
this.src,
|
|
172
|
+
this.projectionItems,
|
|
173
|
+
this.whereExpr,
|
|
174
|
+
[...this.joinItems, JoinAst.inner(source, on.ast)],
|
|
175
|
+
this.limitValue,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
leftJoin(source: AnyFromSource, on: CfExpr): CfExprSelectQuery {
|
|
180
|
+
return new CfExprSelectQuery(
|
|
181
|
+
this.src,
|
|
182
|
+
this.projectionItems,
|
|
183
|
+
this.whereExpr,
|
|
184
|
+
[...this.joinItems, JoinAst.left(source, on.ast)],
|
|
185
|
+
this.limitValue,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
project(alias: string, expr: CfExpr): CfExprSelectQuery {
|
|
190
|
+
return new CfExprSelectQuery(
|
|
191
|
+
this.src,
|
|
192
|
+
[...this.projectionItems, ProjectionItem.of(alias, expr.ast)],
|
|
193
|
+
this.whereExpr,
|
|
194
|
+
this.joinItems,
|
|
195
|
+
this.limitValue,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
where(expr: CfExpr): CfExprSelectQuery {
|
|
200
|
+
return new CfExprSelectQuery(
|
|
201
|
+
this.src,
|
|
202
|
+
this.projectionItems,
|
|
203
|
+
expr,
|
|
204
|
+
this.joinItems,
|
|
205
|
+
this.limitValue,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
limit(value: number): CfExprSelectQuery {
|
|
210
|
+
return new CfExprSelectQuery(
|
|
211
|
+
this.src,
|
|
212
|
+
this.projectionItems,
|
|
213
|
+
this.whereExpr,
|
|
214
|
+
this.joinItems,
|
|
215
|
+
value,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
build(): SelectAst {
|
|
220
|
+
if (this.joinItems.length > 0 && this.src === undefined) {
|
|
221
|
+
throw new Error('CfExprSelectQuery: cannot add a JOIN without a FROM clause');
|
|
222
|
+
}
|
|
223
|
+
const base =
|
|
224
|
+
this.src !== undefined
|
|
225
|
+
? SelectAst.from(this.src).withProjection(this.projectionItems)
|
|
226
|
+
: SelectAst.noFrom().withProjection(this.projectionItems);
|
|
227
|
+
const withJoins = this.joinItems.length > 0 ? base.withJoins(this.joinItems) : base;
|
|
228
|
+
const withWhere =
|
|
229
|
+
this.whereExpr !== undefined ? withJoins.withWhere(this.whereExpr.ast) : withJoins;
|
|
230
|
+
return this.limitValue !== undefined ? withWhere.withLimit(this.limitValue) : withWhere;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function exprSelect(): CfExprSelectQuery {
|
|
235
|
+
return new CfExprSelectQuery(undefined, [], undefined);
|
|
46
236
|
}
|
|
47
237
|
|
|
48
238
|
/**
|
|
@@ -10,6 +10,8 @@ export {
|
|
|
10
10
|
export {
|
|
11
11
|
CfConflictClause,
|
|
12
12
|
CfExpr,
|
|
13
|
+
CfExprSelectQuery,
|
|
14
|
+
type CfFnOptions,
|
|
13
15
|
CfInsertQuery,
|
|
14
16
|
CfSelectQuery,
|
|
15
17
|
CfUpdateQuery,
|
|
@@ -18,7 +20,10 @@ export {
|
|
|
18
20
|
type ColumnDescriptor,
|
|
19
21
|
type ColumnProxy,
|
|
20
22
|
type ColumnSchema,
|
|
23
|
+
cfExpr,
|
|
24
|
+
cfTable,
|
|
21
25
|
type ExcludedProxy,
|
|
26
|
+
exprSelect,
|
|
22
27
|
type TableHandle,
|
|
23
28
|
type TableInsertRow,
|
|
24
29
|
type TableSetValues,
|
|
@@ -51,6 +51,14 @@ export type AppliedMutationDefault = {
|
|
|
51
51
|
export type MutationDefaultsOptions = {
|
|
52
52
|
readonly op: MutationDefaultsOp;
|
|
53
53
|
readonly table: string;
|
|
54
|
+
/**
|
|
55
|
+
* Namespace of the target table. Execution-default refs are namespace-scoped,
|
|
56
|
+
* so only defaults declared for `(namespace, table)` are applied — this is what
|
|
57
|
+
* disambiguates same-named tables across namespaces. Required so the coordinate
|
|
58
|
+
* is always part of the match; a missing namespace is a caller bug, not a
|
|
59
|
+
* silent degrade to table-name-only matching.
|
|
60
|
+
*/
|
|
61
|
+
readonly namespace: string;
|
|
54
62
|
readonly values: Record<string, unknown>;
|
|
55
63
|
/**
|
|
56
64
|
* Per-ORM-operation cache for generators that declare `stability: 'query'`. The caller passes the same `Map` across every `applyMutationDefaults` invocation in one bulk operation; the framework keys by `generatorId` so the same value is reused across all rows and columns. Generators with `stability: 'row'` use a fresh per-call cache the framework manages internally; generators with `stability: 'field'` skip caching
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Contract
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
2
2
|
import type { ParamSpec } from '@prisma-next/operations';
|
|
3
3
|
import type {
|
|
4
4
|
ExtractFieldOutputTypes,
|
|
@@ -13,11 +13,45 @@ import type { SqlExecutionPlan } from './sql-execution-plan';
|
|
|
13
13
|
export type Expr = ColumnRef | ParamRef;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* The minimal contract shape the per-namespace column resolver needs: the
|
|
17
|
+
* application-domain models and the storage tables, both keyed by namespace
|
|
18
|
+
* coordinate, plus (via the optional TypeMaps phantom key, read structurally by
|
|
19
|
+
* {@link ExtractFieldOutputTypes}) the refined field-output map. Every emitted
|
|
20
|
+
* `Contract<SqlStorage>` satisfies it, as does `sql-builder`'s `TableProxyContract`
|
|
21
|
+
* — so the resolver indexes the coordinate directly without forcing callers to
|
|
22
|
+
* carry the full `Contract`.
|
|
18
23
|
*/
|
|
19
|
-
type
|
|
20
|
-
|
|
24
|
+
export type ColumnResolutionContract = {
|
|
25
|
+
readonly domain: {
|
|
26
|
+
readonly namespaces: Readonly<
|
|
27
|
+
Record<string, { readonly models: Readonly<Record<string, unknown>> }>
|
|
28
|
+
>;
|
|
29
|
+
};
|
|
30
|
+
readonly storage: {
|
|
31
|
+
readonly namespaces: Readonly<
|
|
32
|
+
Record<
|
|
33
|
+
string,
|
|
34
|
+
{ readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>> }
|
|
35
|
+
>
|
|
36
|
+
>;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type NamespaceModels<
|
|
41
|
+
TContract extends ColumnResolutionContract,
|
|
42
|
+
NsId extends string,
|
|
43
|
+
> = TContract['domain']['namespaces'][NsId] extends {
|
|
44
|
+
readonly models: infer Models extends Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
? Models
|
|
47
|
+
: never;
|
|
48
|
+
|
|
49
|
+
type ExtractTableToModel<
|
|
50
|
+
TContract extends ColumnResolutionContract,
|
|
51
|
+
NsId extends string,
|
|
52
|
+
TableName extends string,
|
|
53
|
+
> =
|
|
54
|
+
NamespaceModels<TContract, NsId> extends infer Models extends Record<string, unknown>
|
|
21
55
|
? {
|
|
22
56
|
[M in keyof Models & string]: Models[M] extends {
|
|
23
57
|
readonly storage: { readonly table: TableName };
|
|
@@ -27,17 +61,14 @@ type ExtractTableToModel<TContract extends Contract<SqlStorage>, TableName exten
|
|
|
27
61
|
}[keyof Models & string]
|
|
28
62
|
: never;
|
|
29
63
|
|
|
30
|
-
/**
|
|
31
|
-
* Extracts the field name for a given column by finding the field in
|
|
32
|
-
* `model.storage.fields` whose `column` matches.
|
|
33
|
-
*/
|
|
34
64
|
type ExtractColumnToField<
|
|
35
|
-
TContract extends
|
|
65
|
+
TContract extends ColumnResolutionContract,
|
|
66
|
+
NsId extends string,
|
|
36
67
|
TableName extends string,
|
|
37
68
|
ColumnName extends string,
|
|
38
69
|
> =
|
|
39
|
-
ExtractTableToModel<TContract, TableName> extends infer ModelName extends string
|
|
40
|
-
?
|
|
70
|
+
ExtractTableToModel<TContract, NsId, TableName> extends infer ModelName extends string
|
|
71
|
+
? NamespaceModels<TContract, NsId> extends infer Models extends Record<string, unknown>
|
|
41
72
|
? ModelName & keyof Models extends infer MKey extends string
|
|
42
73
|
? Models[MKey] extends {
|
|
43
74
|
readonly storage: { readonly fields: infer Fields extends Record<string, unknown> };
|
|
@@ -52,6 +83,28 @@ type ExtractColumnToField<
|
|
|
52
83
|
: never
|
|
53
84
|
: never;
|
|
54
85
|
|
|
86
|
+
/** Resolves to `never` when the table or column is absent in the namespace. */
|
|
87
|
+
type NamespaceStorageColumn<
|
|
88
|
+
TContract extends ColumnResolutionContract,
|
|
89
|
+
NsId extends string,
|
|
90
|
+
TableName extends string,
|
|
91
|
+
ColumnName extends string,
|
|
92
|
+
> = TContract['storage']['namespaces'][NsId] extends {
|
|
93
|
+
readonly entries: { readonly table: infer Tables extends Record<string, unknown> };
|
|
94
|
+
}
|
|
95
|
+
? TableName extends keyof Tables
|
|
96
|
+
? Tables[TableName] extends {
|
|
97
|
+
readonly columns: infer Columns extends Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
? ColumnName extends keyof Columns
|
|
100
|
+
? Columns[ColumnName] extends StorageColumn
|
|
101
|
+
? Columns[ColumnName]
|
|
102
|
+
: never
|
|
103
|
+
: never
|
|
104
|
+
: never
|
|
105
|
+
: never
|
|
106
|
+
: never;
|
|
107
|
+
|
|
55
108
|
type FallbackCodecLookup<
|
|
56
109
|
ColumnMeta extends StorageColumn,
|
|
57
110
|
CodecTypes extends Record<string, { readonly output: unknown }>,
|
|
@@ -65,6 +118,53 @@ type FallbackCodecLookup<
|
|
|
65
118
|
: unknown
|
|
66
119
|
: unknown;
|
|
67
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The refined (typeParam-applied) JS output type for a field within a namespace
|
|
123
|
+
* coordinate, read from the emitter's namespace-nested `FieldOutputTypes` map at
|
|
124
|
+
* `FieldOutputTypes[NsId][Model][Field]`. This preserves parameterized codec
|
|
125
|
+
* refinements (e.g. `Vector<N>`, `Char<N>`) that a bare codec-output lookup
|
|
126
|
+
* would drop. Resolves to `never` when the coordinate is absent from the map.
|
|
127
|
+
*/
|
|
128
|
+
type NamespaceFieldOutput<
|
|
129
|
+
TContract extends ColumnResolutionContract,
|
|
130
|
+
NsId extends string,
|
|
131
|
+
ModelName extends string,
|
|
132
|
+
FieldName extends string,
|
|
133
|
+
> =
|
|
134
|
+
ExtractFieldOutputTypes<TContract> extends infer Outputs
|
|
135
|
+
? NsId extends keyof Outputs
|
|
136
|
+
? Outputs[NsId] extends infer NamespaceOutputs
|
|
137
|
+
? ModelName extends keyof NamespaceOutputs
|
|
138
|
+
? NamespaceOutputs[ModelName] extends infer ModelOutputs
|
|
139
|
+
? FieldName extends keyof ModelOutputs
|
|
140
|
+
? ModelOutputs[FieldName]
|
|
141
|
+
: never
|
|
142
|
+
: never
|
|
143
|
+
: never
|
|
144
|
+
: never
|
|
145
|
+
: never
|
|
146
|
+
: never;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The secondary resolution path, taken for a storage column not backed by a
|
|
150
|
+
* domain model field in the namespace (e.g. a column with no corresponding
|
|
151
|
+
* field); refined model fields resolve via {@link NamespaceFieldOutput}.
|
|
152
|
+
*/
|
|
153
|
+
type ColumnCodecFallback<
|
|
154
|
+
TContract extends ColumnResolutionContract,
|
|
155
|
+
NsId extends string,
|
|
156
|
+
TableName extends string,
|
|
157
|
+
ColumnName extends string,
|
|
158
|
+
CodecTypes extends Record<string, { readonly output: unknown }>,
|
|
159
|
+
> =
|
|
160
|
+
NamespaceStorageColumn<TContract, NsId, TableName, ColumnName> extends infer ColumnMeta
|
|
161
|
+
? [ColumnMeta] extends [never]
|
|
162
|
+
? never
|
|
163
|
+
: ColumnMeta extends StorageColumn
|
|
164
|
+
? FallbackCodecLookup<ColumnMeta, CodecTypes>
|
|
165
|
+
: never
|
|
166
|
+
: never;
|
|
167
|
+
|
|
68
168
|
/**
|
|
69
169
|
* Type-level operation signature.
|
|
70
170
|
* Represents an operation at the type level for use in contract type maps.
|
|
@@ -126,25 +226,37 @@ export type OperationsForTypeId<TypeId extends string, Operations extends Operat
|
|
|
126
226
|
? Operations[TypeId]
|
|
127
227
|
: Record<string, never>;
|
|
128
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Resolves the JavaScript output type of a column addressed by an explicit
|
|
231
|
+
* namespace coordinate.
|
|
232
|
+
*
|
|
233
|
+
* The table→model and column→field mapping is resolved per-namespace from
|
|
234
|
+
* `domain.namespaces[NsId]['models']`, and the refined output type from the
|
|
235
|
+
* emitter's namespace-nested `FieldOutputTypes[NsId][Model][Field]` — so a bare
|
|
236
|
+
* table name shared across namespaces resolves to each namespace's own field,
|
|
237
|
+
* and parameterized codec refinements (e.g. `Vector<N>`) are preserved. A
|
|
238
|
+
* storage column not backed by a model field in the namespace falls back to a
|
|
239
|
+
* codec-output lookup; a column absent in the namespace resolves to `never`.
|
|
240
|
+
*/
|
|
129
241
|
export type ComputeColumnJsType<
|
|
130
|
-
TContract extends
|
|
242
|
+
TContract extends ColumnResolutionContract,
|
|
243
|
+
NsId extends string,
|
|
131
244
|
TableName extends string,
|
|
132
245
|
ColumnName extends string,
|
|
133
|
-
ColumnMeta extends StorageColumn,
|
|
134
246
|
CodecTypes extends Record<string, { readonly output: unknown }>,
|
|
135
247
|
> =
|
|
136
|
-
ExtractTableToModel<TContract, TableName> extends infer ModelName
|
|
248
|
+
ExtractTableToModel<TContract, NsId, TableName> extends infer ModelName
|
|
137
249
|
? [ModelName] extends [never]
|
|
138
|
-
?
|
|
250
|
+
? ColumnCodecFallback<TContract, NsId, TableName, ColumnName, CodecTypes>
|
|
139
251
|
: ModelName extends string
|
|
140
|
-
? ExtractColumnToField<TContract, TableName, ColumnName> extends infer FieldName
|
|
252
|
+
? ExtractColumnToField<TContract, NsId, TableName, ColumnName> extends infer FieldName
|
|
141
253
|
? [FieldName] extends [never]
|
|
142
|
-
?
|
|
254
|
+
? ColumnCodecFallback<TContract, NsId, TableName, ColumnName, CodecTypes>
|
|
143
255
|
: FieldName extends string
|
|
144
|
-
? ModelName extends
|
|
145
|
-
?
|
|
146
|
-
?
|
|
147
|
-
:
|
|
256
|
+
? NamespaceFieldOutput<TContract, NsId, ModelName, FieldName> extends infer Out
|
|
257
|
+
? [Out] extends [never]
|
|
258
|
+
? ColumnCodecFallback<TContract, NsId, TableName, ColumnName, CodecTypes>
|
|
259
|
+
: Out
|
|
148
260
|
: never
|
|
149
261
|
: never
|
|
150
262
|
: never
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ddl-types-D3vlEjMA.d.mts","names":[],"sources":["../src/ast/ddl-types.ts"],"mappings":";;;;;;;AAcA;;;;AACqB;AAGrB;;UAJiB,sBAAA;EAAA,SACN,UAAU;AAAA;AAAA,UAGJ,uBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,oBAAA,EAAsB,GAAA,EAAK,sBAAA,GAAyB,CAAA;EAClE,QAAA,CAAS,IAAA,EAAM,qBAAA,EAAuB,GAAA,EAAK,sBAAA,GAAyB,CAAA;AAAA;AAAA,uBAGhD,gBAAA;EAAA,kBACF,IAAA;EAAA,SACT,MAAA,IAAU,OAAA,EAAS,uBAAA,CAAwB,CAAA,GAAI,GAAA,EAAK,sBAAA,GAAyB,CAAA;EAAA,UAE5E,MAAA;AAAA;AAAA,cAKC,oBAAA,SAA6B,gBAAA;EAAA,SAC/B,IAAA;EAAA,SACA,KAAA,EAAO,8BAAA;cAEJ,KAAA,EAAO,8BAAA;EASV,MAAA,IAAU,OAAA,EAAS,uBAAA,CAAwB,CAAA,GAAI,GAAA,EAAK,sBAAA,GAAyB,CAAA;AAAA;AAAA,cAK3E,qBAAA,SAA8B,gBAAA;EAAA,SAChC,IAAA;EAAA,SACA,UAAA;cAEG,UAAA;EAMH,MAAA,IAAU,OAAA,EAAS,uBAAA,CAAwB,CAAA,GAAI,GAAA,EAAK,sBA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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ddl-types-X9_XHUl0.mjs","names":[],"sources":["../src/ast/ddl-types.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport { isColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport type { AnyParamRef } from './types';\n\n/**\n * Render-time context the column-default visitor needs to make dialect\n * decisions that depend on the parent column. Today only the parent\n * column's native type (`\"jsonb\"`, `\"text\"`, …) — the Postgres renderer\n * uses it to decide whether to emit a `::jsonb` / `::json` cast on JSON\n * literal defaults so the emitted DDL matches the column type without\n * relying on Postgres's implicit text → jsonb cast at default-evaluation\n * time. Additional fields can join without re-shaping the interface.\n */\nexport interface DdlColumnRenderContext {\n readonly nativeType: string;\n}\n\nexport interface DdlColumnDefaultVisitor<R> {\n literal(node: LiteralColumnDefault, ctx: DdlColumnRenderContext): R;\n function(node: FunctionColumnDefault, ctx: DdlColumnRenderContext): R;\n}\n\nexport abstract class DdlColumnDefault {\n abstract readonly kind: string;\n abstract accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R;\n\n protected freeze(): void {\n Object.freeze(this);\n }\n}\n\nexport class LiteralColumnDefault extends DdlColumnDefault {\n readonly kind = 'literal' as const;\n readonly value: ColumnDefaultLiteralInputValue;\n\n constructor(value: ColumnDefaultLiteralInputValue) {\n super();\n if (!isColumnDefaultLiteralInputValue(value)) {\n throw new Error('Invalid column default literal value');\n }\n this.value = value;\n this.freeze();\n }\n\n override accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R {\n return visitor.literal(this, ctx);\n }\n}\n\nexport class FunctionColumnDefault extends DdlColumnDefault {\n readonly kind = 'function' as const;\n readonly expression: string;\n\n constructor(expression: string) {\n super();\n this.expression = expression;\n this.freeze();\n }\n\n override accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R {\n return visitor.function(this, ctx);\n }\n}\n\nexport type AnyDdlColumnDefault = LiteralColumnDefault | FunctionColumnDefault;\n\nexport class DdlColumn {\n readonly name: string;\n readonly type: string;\n readonly notNull?: boolean | undefined;\n readonly primaryKey?: boolean | undefined;\n readonly default?: AnyDdlColumnDefault | undefined;\n\n constructor(options: {\n readonly name: string;\n readonly type: string;\n readonly notNull?: boolean;\n readonly primaryKey?: boolean;\n readonly default?: AnyDdlColumnDefault;\n }) {\n this.name = options.name;\n this.type = options.type;\n this.notNull = options.notNull;\n this.primaryKey = options.primaryKey;\n this.default = options.default;\n Object.freeze(this);\n }\n}\n\nexport abstract class DdlNode {\n abstract readonly kind: string;\n\n /**\n * Structural brand: every DDL node answers `true`. Lets {@link isDdlNode}\n * recognise any `DdlNode` subclass — including target-contributed kinds —\n * without a central kind registry that subclasses would have to register\n * into.\n */\n isDdlNode(): true {\n return true;\n }\n\n protected freeze(): void {\n Object.freeze(this);\n }\n\n collectParamRefs(): AnyParamRef[] {\n return [];\n }\n}\n\nexport function isDdlNode(value: unknown): value is DdlNode {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'isDdlNode' in value &&\n typeof value.isDdlNode === 'function'\n );\n}\n\n// ---------------------------------------------------------------------------\n// Table-level constraint nodes\n// ---------------------------------------------------------------------------\n\n/**\n * A composite (or single-column) PRIMARY KEY constraint on a `CreateTable`\n * node. When `name` is set, the adapter renders `CONSTRAINT <name> PRIMARY KEY\n * (…)`; otherwise it renders an anonymous `PRIMARY KEY (…)`.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class PrimaryKeyConstraint {\n readonly kind = 'primary-key' as const;\n readonly columns: ReadonlyArray<string>;\n readonly name: string | undefined;\n\n constructor(options: { readonly columns: readonly string[]; readonly name?: string }) {\n this.columns = Object.freeze([...options.columns]);\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\n/**\n * A FOREIGN KEY constraint on a `CreateTable` node. `onDelete` and `onUpdate`\n * use the same `ReferentialAction` vocabulary already used by the migration\n * planner and the contract IR — no parallel string enum.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class ForeignKeyConstraint {\n readonly kind = 'foreign-key' as const;\n readonly columns: ReadonlyArray<string>;\n readonly refTable: string;\n readonly refColumns: ReadonlyArray<string>;\n readonly onDelete: ReferentialAction | undefined;\n readonly onUpdate: ReferentialAction | undefined;\n readonly name: string | undefined;\n\n constructor(options: {\n readonly columns: readonly string[];\n readonly refTable: string;\n readonly refColumns: readonly string[];\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly name?: string;\n }) {\n this.columns = Object.freeze([...options.columns]);\n this.refTable = options.refTable;\n this.refColumns = Object.freeze([...options.refColumns]);\n this.onDelete = options.onDelete;\n this.onUpdate = options.onUpdate;\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\n/**\n * A table-level UNIQUE constraint on a `CreateTable` node. When `name` is\n * set, the adapter renders `CONSTRAINT <name> UNIQUE (…)`; otherwise it\n * renders an anonymous `UNIQUE (…)`.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class UniqueConstraint {\n readonly kind = 'unique' as const;\n readonly columns: ReadonlyArray<string>;\n readonly name: string | undefined;\n\n constructor(options: { readonly columns: readonly string[]; readonly name?: string }) {\n this.columns = Object.freeze([...options.columns]);\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\nexport type DdlTableConstraint = PrimaryKeyConstraint | ForeignKeyConstraint | UniqueConstraint;\n"],"mappings":";;AAuBA,IAAsB,mBAAtB,MAAuC;CAIrC,SAAyB;EACvB,OAAO,OAAO,IAAI;CACpB;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,OAAuC;EACjD,MAAM;EACN,IAAI,CAAC,iCAAiC,KAAK,GACzC,MAAM,IAAI,MAAM,sCAAsC;EAExD,KAAK,QAAQ;EACb,KAAK,OAAO;CACd;CAEA,OAAmB,SAAqC,KAAgC;EACtF,OAAO,Q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AAAA"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { J as ParamRef, g as ColumnRef } from "./types-BbGUx5Bi.mjs";
|
|
2
|
-
import { r as ExecutionContext } from "./query-lane-context-CY0-e8Qo.mjs";
|
|
3
|
-
import { t as SqlExecutionPlan } from "./sql-execution-plan-JwVeAzXt.mjs";
|
|
4
|
-
import { Contract, ContractModelDefinitions } from "@prisma-next/contract/types";
|
|
5
|
-
import { ExtractFieldOutputTypes, SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
6
|
-
import { ParamSpec } from "@prisma-next/operations";
|
|
7
|
-
import { SqlLoweringSpec } from "@prisma-next/sql-operations";
|
|
8
|
-
|
|
9
|
-
//#region src/types.d.ts
|
|
10
|
-
type Expr = ColumnRef | ParamRef;
|
|
11
|
-
/**
|
|
12
|
-
* Extracts the model name for a given table by iterating models to find the one
|
|
13
|
-
* whose `storage.table` matches.
|
|
14
|
-
*/
|
|
15
|
-
type ExtractTableToModel<TContract extends Contract<SqlStorage>, TableName extends string> = ContractModelDefinitions<TContract> extends infer Models extends Record<string, unknown> ? { [M in keyof Models & string]: Models[M] extends {
|
|
16
|
-
readonly storage: {
|
|
17
|
-
readonly table: TableName;
|
|
18
|
-
};
|
|
19
|
-
} ? M : never }[keyof Models & string] : never;
|
|
20
|
-
/**
|
|
21
|
-
* Extracts the field name for a given column by finding the field in
|
|
22
|
-
* `model.storage.fields` whose `column` matches.
|
|
23
|
-
*/
|
|
24
|
-
type ExtractColumnToField<TContract extends Contract<SqlStorage>, TableName extends string, ColumnName extends string> = ExtractTableToModel<TContract, TableName> extends infer ModelName extends string ? ContractModelDefinitions<TContract> extends infer Models extends Record<string, unknown> ? ModelName & keyof Models extends infer MKey extends string ? Models[MKey] extends {
|
|
25
|
-
readonly storage: {
|
|
26
|
-
readonly fields: infer Fields extends Record<string, unknown>;
|
|
27
|
-
};
|
|
28
|
-
} ? { [F in keyof Fields & string]: Fields[F] extends {
|
|
29
|
-
readonly column: ColumnName;
|
|
30
|
-
} ? F : never }[keyof Fields & string] : never : never : never : never;
|
|
31
|
-
type FallbackCodecLookup<ColumnMeta extends StorageColumn, CodecTypes extends Record<string, {
|
|
32
|
-
readonly output: unknown;
|
|
33
|
-
}>> = ColumnMeta extends {
|
|
34
|
-
codecId: infer CodecId extends string;
|
|
35
|
-
} ? CodecId extends keyof CodecTypes ? CodecTypes[CodecId] extends {
|
|
36
|
-
readonly output: infer O;
|
|
37
|
-
} ? ColumnMeta extends {
|
|
38
|
-
nullable: true;
|
|
39
|
-
} ? O | null : O : unknown : unknown : unknown;
|
|
40
|
-
/**
|
|
41
|
-
* Type-level operation signature.
|
|
42
|
-
* Represents an operation at the type level for use in contract type maps.
|
|
43
|
-
*/
|
|
44
|
-
type OperationTypeSignature = {
|
|
45
|
-
readonly args: ReadonlyArray<ParamSpec>;
|
|
46
|
-
readonly returns: ParamSpec;
|
|
47
|
-
readonly lowering: SqlLoweringSpec;
|
|
48
|
-
readonly capabilities?: ReadonlyArray<string>;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Type-level operation registry.
|
|
52
|
-
* Maps typeId → operations, where operations is a record of method name → operation signature.
|
|
53
|
-
*
|
|
54
|
-
* Example:
|
|
55
|
-
* ```typescript
|
|
56
|
-
* type MyOperations: OperationTypes = {
|
|
57
|
-
* 'pg/vector@1': {
|
|
58
|
-
* cosineDistance: {
|
|
59
|
-
* args: [{ codecId: 'pg/vector@1'; nullable: false }];
|
|
60
|
-
* returns: { codecId: 'core/float8'; nullable: false };
|
|
61
|
-
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
62
|
-
* };
|
|
63
|
-
* };
|
|
64
|
-
* };
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;
|
|
68
|
-
/**
|
|
69
|
-
* CodecTypes represents a map of typeId to codec definitions.
|
|
70
|
-
* Each codec definition must have an `output` property indicating the JavaScript type.
|
|
71
|
-
*
|
|
72
|
-
* Example:
|
|
73
|
-
* ```typescript
|
|
74
|
-
* type MyCodecTypes: CodecTypes = {
|
|
75
|
-
* 'pg/int4@1': { output: number };
|
|
76
|
-
* 'pg/text@1': { output: string };
|
|
77
|
-
* };
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
type CodecTypes = Record<string, {
|
|
81
|
-
readonly output: unknown;
|
|
82
|
-
}>;
|
|
83
|
-
/**
|
|
84
|
-
* Extracts operations for a given typeId from the operation registry.
|
|
85
|
-
* Returns an empty record if the typeId is not found.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;
|
|
90
|
-
* // Ops = { cosineDistance: { ... }, l2Distance: { ... } }
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
type OperationsForTypeId<TypeId extends string, Operations extends OperationTypes> = Operations extends Record<string, never> ? Record<string, never> : TypeId extends keyof Operations ? Operations[TypeId] : Record<string, never>;
|
|
94
|
-
type ComputeColumnJsType<TContract extends Contract<SqlStorage>, TableName extends string, ColumnName extends string, ColumnMeta extends StorageColumn, CodecTypes extends Record<string, {
|
|
95
|
-
readonly output: unknown;
|
|
96
|
-
}>> = ExtractTableToModel<TContract, TableName> extends infer ModelName ? [ModelName] extends [never] ? FallbackCodecLookup<ColumnMeta, CodecTypes> : ModelName extends string ? ExtractColumnToField<TContract, TableName, ColumnName> extends infer FieldName ? [FieldName] extends [never] ? FallbackCodecLookup<ColumnMeta, CodecTypes> : FieldName extends string ? ModelName extends keyof ExtractFieldOutputTypes<TContract> ? FieldName extends keyof ExtractFieldOutputTypes<TContract>[ModelName] ? ExtractFieldOutputTypes<TContract>[ModelName][FieldName] : never : never : never : never : never : never;
|
|
97
|
-
/**
|
|
98
|
-
* Alias for the SQL-domain executable plan, exposed under the legacy
|
|
99
|
-
* `SqlPlan` name for compatibility with SQL builder/utility call sites.
|
|
100
|
-
* The canonical name is `SqlExecutionPlan` (`./sql-execution-plan`).
|
|
101
|
-
*/
|
|
102
|
-
type SqlPlan<Row = unknown> = SqlExecutionPlan<Row>;
|
|
103
|
-
/**
|
|
104
|
-
* Helper types for extracting contract structure.
|
|
105
|
-
*/
|
|
106
|
-
type TablesOf<TContract> = TContract extends {
|
|
107
|
-
storage: {
|
|
108
|
-
tables: infer U;
|
|
109
|
-
};
|
|
110
|
-
} ? U : never;
|
|
111
|
-
type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;
|
|
112
|
-
/**
|
|
113
|
-
* Unique symbol for metadata property to avoid collisions with user-defined properties
|
|
114
|
-
*/
|
|
115
|
-
declare const META: unique symbol;
|
|
116
|
-
/**
|
|
117
|
-
* Extracts metadata from a type that has a META property
|
|
118
|
-
*/
|
|
119
|
-
type Meta<T extends {
|
|
120
|
-
[META]: unknown;
|
|
121
|
-
}> = T[typeof META];
|
|
122
|
-
/**
|
|
123
|
-
* Metadata interface for table definitions
|
|
124
|
-
*/
|
|
125
|
-
interface TableMetadata<Name extends string> {
|
|
126
|
-
name: Name;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Metadata interface for model definitions
|
|
130
|
-
*/
|
|
131
|
-
interface ModelMetadata<Name extends string> {
|
|
132
|
-
name: Name;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Base interface for table definitions with metadata
|
|
136
|
-
* Used in contract.d.ts to define storage-level table types
|
|
137
|
-
*/
|
|
138
|
-
interface TableDef<Name extends string> {
|
|
139
|
-
readonly [META]: TableMetadata<Name>;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Base interface for model definitions with metadata
|
|
143
|
-
* Used in contract.d.ts to define application-level model types
|
|
144
|
-
*/
|
|
145
|
-
interface ModelDef<Name extends string> {
|
|
146
|
-
readonly [META]: ModelMetadata<Name>;
|
|
147
|
-
}
|
|
148
|
-
type ColumnsOf<TContract, K extends TableKey<TContract>> = K extends keyof TablesOf<TContract> ? TablesOf<TContract>[K] extends {
|
|
149
|
-
columns: infer C;
|
|
150
|
-
} ? C : never : never;
|
|
151
|
-
interface RawTemplateOptions {
|
|
152
|
-
readonly annotations?: Record<string, unknown>;
|
|
153
|
-
}
|
|
154
|
-
interface RawFunctionOptions extends RawTemplateOptions {
|
|
155
|
-
readonly params: ReadonlyArray<unknown>;
|
|
156
|
-
}
|
|
157
|
-
type RawTemplateFactory = (strings: TemplateStringsArray, ...values: readonly unknown[]) => SqlExecutionPlan;
|
|
158
|
-
interface RawFactory extends RawTemplateFactory {
|
|
159
|
-
(text: string, options: RawFunctionOptions): SqlExecutionPlan;
|
|
160
|
-
with(options: RawTemplateOptions): RawTemplateFactory;
|
|
161
|
-
}
|
|
162
|
-
interface RuntimeError extends Error {
|
|
163
|
-
readonly code: string;
|
|
164
|
-
readonly category: 'PLAN';
|
|
165
|
-
readonly severity: 'error';
|
|
166
|
-
readonly details?: Record<string, unknown>;
|
|
167
|
-
readonly hints?: readonly string[];
|
|
168
|
-
readonly docs?: readonly string[];
|
|
169
|
-
}
|
|
170
|
-
interface BuildParamsMap {
|
|
171
|
-
readonly [name: string]: unknown;
|
|
172
|
-
}
|
|
173
|
-
interface BuildOptions {
|
|
174
|
-
readonly params?: BuildParamsMap;
|
|
175
|
-
}
|
|
176
|
-
interface SqlBuilderOptions<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
|
|
177
|
-
readonly context: ExecutionContext<TContract>;
|
|
178
|
-
}
|
|
179
|
-
//#endregion
|
|
180
|
-
export { TableMetadata as C, TableKey as S, RawTemplateOptions as _, ComputeColumnJsType as a, SqlPlan as b, Meta as c, OperationTypeSignature as d, OperationTypes as f, RawTemplateFactory as g, RawFunctionOptions as h, ColumnsOf as i, ModelDef as l, RawFactory as m, BuildParamsMap as n, Expr as o, OperationsForTypeId as p, CodecTypes as r, META as s, BuildOptions as t, ModelMetadata as u, RuntimeError as v, TablesOf as w, TableDef as x, SqlBuilder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