@prisma-next/sql-relational-core 0.3.0-pr.93.5 → 0.3.0-pr.94.2
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/errors-BwxypN2Q.mjs +3 -0
- package/dist/errors-CLx1Ylq0.d.mts +2 -0
- package/dist/exports/ast.d.mts +123 -0
- package/dist/exports/ast.d.mts.map +1 -0
- package/dist/exports/ast.mjs +304 -0
- package/dist/exports/ast.mjs.map +1 -0
- package/dist/exports/errors.d.mts +2 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/guards.d.mts +88 -0
- package/dist/exports/guards.d.mts.map +1 -0
- package/dist/exports/guards.mjs +3 -0
- package/dist/exports/operations-registry.d.mts +5 -0
- package/dist/exports/operations-registry.mjs +3 -0
- package/dist/exports/param.d.mts +5 -0
- package/dist/exports/param.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 +2 -0
- package/dist/exports/query-lane-context.mjs +1 -0
- package/dist/exports/schema.d.mts +5 -0
- package/dist/exports/schema.mjs +4 -0
- package/dist/exports/types.d.mts +4 -0
- package/dist/exports/types.mjs +3 -0
- package/dist/guards-4T0IByJo.mjs +132 -0
- package/dist/guards-4T0IByJo.mjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -0
- package/dist/operations-registry-7R5KE2-5.mjs +152 -0
- package/dist/operations-registry-7R5KE2-5.mjs.map +1 -0
- package/dist/operations-registry-CIcn4f2P.d.mts +9 -0
- package/dist/operations-registry-CIcn4f2P.d.mts.map +1 -0
- package/dist/param-B4LzVPv2.d.mts +8 -0
- package/dist/param-B4LzVPv2.d.mts.map +1 -0
- package/dist/param-BFvNAaHR.mjs +14 -0
- package/dist/param-BFvNAaHR.mjs.map +1 -0
- package/dist/plan-9PvH-Tu3.d.mts +157 -0
- package/dist/plan-9PvH-Tu3.d.mts.map +1 -0
- package/dist/query-lane-context-wr_XXnB5.d.mts +143 -0
- package/dist/query-lane-context-wr_XXnB5.d.mts.map +1 -0
- package/dist/schema-BsY2EXAf.mjs +148 -0
- package/dist/schema-BsY2EXAf.mjs.map +1 -0
- package/dist/schema-Dse48uyP.d.mts +63 -0
- package/dist/schema-Dse48uyP.d.mts.map +1 -0
- package/dist/types-Bg2kUmUA.d.mts +359 -0
- package/dist/types-Bg2kUmUA.d.mts.map +1 -0
- package/dist/types-D_FRJvm0.mjs +18 -0
- package/dist/types-D_FRJvm0.mjs.map +1 -0
- package/package.json +28 -50
- package/src/ast/predicate.ts +3 -11
- package/src/ast/types.ts +23 -9
- package/src/exports/guards.ts +5 -0
- package/src/operations-registry.ts +112 -73
- package/src/schema.ts +40 -29
- package/src/types.ts +102 -52
- package/src/utils/guards.ts +88 -18
- 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
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { t as QueryLaneContext } from "./query-lane-context-wr_XXnB5.mjs";
|
|
2
|
+
import { a as ColumnRef, b as QueryAst, i as BinaryOp, l as Expression, s as Direction, t as SqlQueryPlan, u as ExpressionSource, v as OperationExpr, y as ParamRef } from "./plan-9PvH-Tu3.mjs";
|
|
3
|
+
import { RuntimeError } from "@prisma-next/plan";
|
|
4
|
+
import { ArgSpec, ReturnSpec } from "@prisma-next/operations";
|
|
5
|
+
import { SqlLoweringSpec } from "@prisma-next/sql-operations";
|
|
6
|
+
import { ExecutionPlan, PlanRefs, ResultType } from "@prisma-next/contract/types";
|
|
7
|
+
import { SqlContract, SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
8
|
+
|
|
9
|
+
//#region src/types.d.ts
|
|
10
|
+
interface ParamPlaceholder {
|
|
11
|
+
readonly kind: 'param-placeholder';
|
|
12
|
+
readonly name: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* ValueSource represents any value that can appear in a comparison or as an argument.
|
|
16
|
+
* This includes:
|
|
17
|
+
* - ParamPlaceholder: A parameter placeholder (e.g., `param('userId')`)
|
|
18
|
+
* - ExpressionSource: Something that can be converted to an Expression (ColumnBuilder, ExpressionBuilder)
|
|
19
|
+
*/
|
|
20
|
+
type ValueSource = ParamPlaceholder | ExpressionSource;
|
|
21
|
+
interface OrderBuilder<_ColumnName extends string = string, _ColumnMeta extends StorageColumn = StorageColumn, _JsType = unknown> {
|
|
22
|
+
readonly kind: 'order';
|
|
23
|
+
readonly expr: Expression;
|
|
24
|
+
readonly dir: Direction;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an OrderBuilder for use in orderBy clauses.
|
|
28
|
+
*/
|
|
29
|
+
declare function createOrderBuilder(expr: AnyColumnBuilder | OperationExpr, dir: Direction): AnyOrderBuilder;
|
|
30
|
+
/**
|
|
31
|
+
* ColumnBuilder with optional operation methods based on the column's typeId.
|
|
32
|
+
* When Operations is provided and the column's typeId matches, operation methods are included.
|
|
33
|
+
* Implements ExpressionSource to provide type-safe conversion to ColumnRef.
|
|
34
|
+
*/
|
|
35
|
+
type ColumnBuilder<ColumnName extends string = string, ColumnMeta extends StorageColumn = StorageColumn, JsType$1 = unknown, Operations extends OperationTypes = Record<string, never>> = {
|
|
36
|
+
readonly kind: 'column';
|
|
37
|
+
readonly table: string;
|
|
38
|
+
readonly column: ColumnName;
|
|
39
|
+
readonly columnMeta: ColumnMeta;
|
|
40
|
+
eq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
41
|
+
neq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
42
|
+
gt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
43
|
+
lt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
44
|
+
gte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
45
|
+
lte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
46
|
+
asc(): OrderBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
47
|
+
desc(): OrderBuilder<ColumnName, ColumnMeta, JsType$1>;
|
|
48
|
+
/** Converts this column builder to a ColumnRef expression */
|
|
49
|
+
toExpr(): ColumnRef;
|
|
50
|
+
readonly __jsType: JsType$1;
|
|
51
|
+
} & (ColumnMeta['codecId'] extends string ? ColumnMeta['codecId'] extends keyof Operations ? OperationMethods<OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>, ColumnName, StorageColumn, JsType$1> : Record<string, never> : Record<string, never>);
|
|
52
|
+
interface BinaryBuilder<_ColumnName extends string = string, _ColumnMeta extends StorageColumn = StorageColumn, _JsType = unknown> {
|
|
53
|
+
readonly kind: 'binary';
|
|
54
|
+
readonly op: BinaryOp;
|
|
55
|
+
readonly left: Expression;
|
|
56
|
+
readonly right: ValueSource;
|
|
57
|
+
}
|
|
58
|
+
type AnyBinaryBuilder = BinaryBuilder;
|
|
59
|
+
type AnyOrderBuilder = OrderBuilder;
|
|
60
|
+
/**
|
|
61
|
+
* ExpressionBuilder represents the result of an operation (e.g., col.distance(...)).
|
|
62
|
+
* Unlike ColumnBuilder (which represents a column), ExpressionBuilder represents
|
|
63
|
+
* an operation expression and provides the same DSL methods for chaining.
|
|
64
|
+
*
|
|
65
|
+
* Implements ExpressionSource to provide type-safe conversion to OperationExpr.
|
|
66
|
+
*/
|
|
67
|
+
interface ExpressionBuilder<JsType$1 = unknown> extends ExpressionSource {
|
|
68
|
+
readonly kind: 'expression';
|
|
69
|
+
readonly expr: OperationExpr;
|
|
70
|
+
readonly columnMeta: StorageColumn;
|
|
71
|
+
eq(value: ValueSource): AnyBinaryBuilder;
|
|
72
|
+
neq(value: ValueSource): AnyBinaryBuilder;
|
|
73
|
+
gt(value: ValueSource): AnyBinaryBuilder;
|
|
74
|
+
lt(value: ValueSource): AnyBinaryBuilder;
|
|
75
|
+
gte(value: ValueSource): AnyBinaryBuilder;
|
|
76
|
+
lte(value: ValueSource): AnyBinaryBuilder;
|
|
77
|
+
asc(): AnyOrderBuilder;
|
|
78
|
+
desc(): AnyOrderBuilder;
|
|
79
|
+
/** Converts this expression builder to the underlying OperationExpr */
|
|
80
|
+
toExpr(): OperationExpr;
|
|
81
|
+
readonly __jsType: JsType$1;
|
|
82
|
+
}
|
|
83
|
+
type AnyColumnBuilderBase = {
|
|
84
|
+
readonly kind: 'column';
|
|
85
|
+
readonly table: string;
|
|
86
|
+
readonly column: string;
|
|
87
|
+
readonly columnMeta: StorageColumn;
|
|
88
|
+
eq(value: ValueSource): AnyBinaryBuilder;
|
|
89
|
+
neq(value: ValueSource): AnyBinaryBuilder;
|
|
90
|
+
gt(value: ValueSource): AnyBinaryBuilder;
|
|
91
|
+
lt(value: ValueSource): AnyBinaryBuilder;
|
|
92
|
+
gte(value: ValueSource): AnyBinaryBuilder;
|
|
93
|
+
lte(value: ValueSource): AnyBinaryBuilder;
|
|
94
|
+
asc(): AnyOrderBuilder;
|
|
95
|
+
desc(): AnyOrderBuilder;
|
|
96
|
+
toExpr(): ColumnRef;
|
|
97
|
+
readonly __jsType: unknown;
|
|
98
|
+
readonly [key: string]: unknown;
|
|
99
|
+
};
|
|
100
|
+
type AnyColumnBuilder = ColumnBuilder<string, StorageColumn, unknown, any> | AnyColumnBuilderBase;
|
|
101
|
+
/**
|
|
102
|
+
* Union type for any builder that can produce an Expression.
|
|
103
|
+
* Used in DSL method signatures where either a column or operation result can be passed.
|
|
104
|
+
*/
|
|
105
|
+
type AnyExpressionSource = AnyColumnBuilder | ExpressionBuilder;
|
|
106
|
+
declare function isColumnBuilder(value: unknown): value is AnyColumnBuilder;
|
|
107
|
+
interface JoinOnBuilder {
|
|
108
|
+
eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;
|
|
109
|
+
}
|
|
110
|
+
interface JoinOnPredicate {
|
|
111
|
+
readonly kind: 'join-on';
|
|
112
|
+
readonly left: AnyColumnBuilder;
|
|
113
|
+
readonly right: AnyColumnBuilder;
|
|
114
|
+
}
|
|
115
|
+
type Expr = ColumnRef | ParamRef;
|
|
116
|
+
/**
|
|
117
|
+
* Helper type to extract codec output type from CodecTypes.
|
|
118
|
+
* Returns never if the codecId is not found in CodecTypes.
|
|
119
|
+
*/
|
|
120
|
+
type ExtractCodecOutputType<CodecId extends string, CodecTypes$1 extends Record<string, {
|
|
121
|
+
readonly output: unknown;
|
|
122
|
+
}>> = CodecId extends keyof CodecTypes$1 ? CodecTypes$1[CodecId] extends {
|
|
123
|
+
readonly output: infer Output;
|
|
124
|
+
} ? Output : never : never;
|
|
125
|
+
/**
|
|
126
|
+
* Type-level operation signature.
|
|
127
|
+
* Represents an operation at the type level, similar to OperationSignature at runtime.
|
|
128
|
+
*/
|
|
129
|
+
type OperationTypeSignature = {
|
|
130
|
+
readonly args: ReadonlyArray<ArgSpec>;
|
|
131
|
+
readonly returns: ReturnSpec;
|
|
132
|
+
readonly lowering: SqlLoweringSpec;
|
|
133
|
+
readonly capabilities?: ReadonlyArray<string>;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Type-level operation registry.
|
|
137
|
+
* Maps typeId → operations, where operations is a record of method name → operation signature.
|
|
138
|
+
*
|
|
139
|
+
* Example:
|
|
140
|
+
* ```typescript
|
|
141
|
+
* type MyOperations: OperationTypes = {
|
|
142
|
+
* 'pg/vector@1': {
|
|
143
|
+
* cosineDistance: {
|
|
144
|
+
* args: [{ kind: 'typeId'; type: 'pg/vector@1' }];
|
|
145
|
+
* returns: { kind: 'builtin'; type: 'number' };
|
|
146
|
+
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
147
|
+
* };
|
|
148
|
+
* };
|
|
149
|
+
* };
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;
|
|
153
|
+
/**
|
|
154
|
+
* CodecTypes represents a map of typeId to codec definitions.
|
|
155
|
+
* Each codec definition must have an `output` property indicating the JavaScript type.
|
|
156
|
+
*
|
|
157
|
+
* Example:
|
|
158
|
+
* ```typescript
|
|
159
|
+
* type MyCodecTypes: CodecTypes = {
|
|
160
|
+
* 'pg/int4@1': { output: number };
|
|
161
|
+
* 'pg/text@1': { output: string };
|
|
162
|
+
* };
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
type CodecTypes = Record<string, {
|
|
166
|
+
readonly output: unknown;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Extracts operations for a given typeId from the operation registry.
|
|
170
|
+
* Returns an empty record if the typeId is not found.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;
|
|
175
|
+
* // Ops = { cosineDistance: { ... }, l2Distance: { ... } }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
type OperationsForTypeId<TypeId$1 extends string, Operations extends OperationTypes> = Operations extends Record<string, never> ? Record<string, never> : TypeId$1 extends keyof Operations ? Operations[TypeId$1] : Record<string, never>;
|
|
179
|
+
/**
|
|
180
|
+
* Maps operation signatures to method signatures on ColumnBuilder.
|
|
181
|
+
* Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder
|
|
182
|
+
* based on the return type.
|
|
183
|
+
*/
|
|
184
|
+
type OperationMethods<Ops extends Record<string, OperationTypeSignature>, ColumnName extends string, ColumnMeta extends StorageColumn, JsType$1> = { [K in keyof Ops]: Ops[K] extends OperationTypeSignature ? (...args: OperationArgs<Ops[K]['args']>) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType$1> : never };
|
|
185
|
+
/**
|
|
186
|
+
* Maps operation argument specs to TypeScript argument types.
|
|
187
|
+
* - typeId args: ColumnBuilder (accepts base columns or operation results)
|
|
188
|
+
* - param args: ParamPlaceholder
|
|
189
|
+
* - literal args: unknown (could be more specific in future)
|
|
190
|
+
*/
|
|
191
|
+
type OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [infer First, ...infer Rest] ? First extends ArgSpec ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])] : [] : [];
|
|
192
|
+
type ArgToType<Arg extends ArgSpec> = Arg extends {
|
|
193
|
+
kind: 'typeId';
|
|
194
|
+
} ? AnyExpressionSource : Arg extends {
|
|
195
|
+
kind: 'param';
|
|
196
|
+
} ? ParamPlaceholder : Arg extends {
|
|
197
|
+
kind: 'literal';
|
|
198
|
+
} ? unknown : never;
|
|
199
|
+
/**
|
|
200
|
+
* Maps operation return spec to return type.
|
|
201
|
+
* Operations return ExpressionBuilder, not ColumnBuilder, because the result
|
|
202
|
+
* represents an expression (OperationExpr) rather than a column reference.
|
|
203
|
+
*/
|
|
204
|
+
type OperationReturn<Returns extends ReturnSpec, _ColumnName extends string, _ColumnMeta extends StorageColumn, _JsType> = Returns extends {
|
|
205
|
+
kind: 'builtin';
|
|
206
|
+
type: infer T;
|
|
207
|
+
} ? T extends 'number' ? ExpressionBuilder<number> : T extends 'boolean' ? ExpressionBuilder<boolean> : T extends 'string' ? ExpressionBuilder<string> : ExpressionBuilder<unknown> : Returns extends {
|
|
208
|
+
kind: 'typeId';
|
|
209
|
+
} ? ExpressionBuilder<unknown> : ExpressionBuilder<unknown>;
|
|
210
|
+
/**
|
|
211
|
+
* Computes JavaScript type for a column at column creation time.
|
|
212
|
+
*
|
|
213
|
+
* Type inference:
|
|
214
|
+
* - Read columnMeta.codecId as typeId string literal
|
|
215
|
+
* - Look up CodecTypes[typeId].output
|
|
216
|
+
* - Apply nullability: nullable ? Output | null : Output
|
|
217
|
+
*/
|
|
218
|
+
type ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends {
|
|
219
|
+
codecId: infer CodecId extends string;
|
|
220
|
+
} ? CodecId : ColumnMeta extends {
|
|
221
|
+
type: infer TypeId extends string;
|
|
222
|
+
} ? TypeId : never;
|
|
223
|
+
type ComputeColumnJsType<_Contract extends SqlContract<SqlStorage>, _TableName extends string, _ColumnName extends string, ColumnMeta extends StorageColumn, CodecTypes$1 extends Record<string, {
|
|
224
|
+
readonly output: unknown;
|
|
225
|
+
}>> = ColumnMeta extends {
|
|
226
|
+
nullable: infer Nullable;
|
|
227
|
+
} ? ColumnMetaTypeId<ColumnMeta> extends infer TypeId ? TypeId extends string ? ExtractCodecOutputType<TypeId, CodecTypes$1> extends infer CodecOutput ? [CodecOutput] extends [never] ? unknown : Nullable extends true ? CodecOutput | null : CodecOutput : unknown : unknown : unknown : unknown;
|
|
228
|
+
/**
|
|
229
|
+
* Infers Row type from a projection object.
|
|
230
|
+
* Maps Record<string, ColumnBuilder> to Record<string, JSType>
|
|
231
|
+
*
|
|
232
|
+
* Extracts the pre-computed JsType from each ColumnBuilder in the projection.
|
|
233
|
+
*/
|
|
234
|
+
/**
|
|
235
|
+
* Extracts the inferred JsType carried by a ColumnBuilder.
|
|
236
|
+
*/
|
|
237
|
+
type ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> = CB extends ColumnBuilder<infer _ColumnName extends string, infer _ColumnMeta extends StorageColumn, infer JsType, infer _Ops> ? JsType : never;
|
|
238
|
+
type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = { [K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]> };
|
|
239
|
+
/**
|
|
240
|
+
* Nested projection type - allows recursive nesting of ColumnBuilder, ExpressionBuilder, or nested objects.
|
|
241
|
+
*/
|
|
242
|
+
type NestedProjection = Record<string, AnyExpressionSource | Record<string, AnyExpressionSource | Record<string, AnyExpressionSource | Record<string, AnyExpressionSource | Record<string, AnyExpressionSource>>>>>;
|
|
243
|
+
/**
|
|
244
|
+
* Helper type to extract include type from Includes map.
|
|
245
|
+
* Returns the value type if K is a key of Includes, otherwise returns unknown.
|
|
246
|
+
*/
|
|
247
|
+
type ExtractIncludeType<K$1 extends string, Includes extends Record<string, unknown>> = K$1 extends keyof Includes ? Includes[K$1] : unknown;
|
|
248
|
+
/**
|
|
249
|
+
* Infers Row type from a nested projection object.
|
|
250
|
+
* Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.
|
|
251
|
+
*
|
|
252
|
+
* Extracts the pre-computed JsType from each ColumnBuilder at leaves.
|
|
253
|
+
* When a value is `true`, it represents an include reference and infers `Array<ChildShape>`
|
|
254
|
+
* by looking up the include alias in the Includes type map.
|
|
255
|
+
*/
|
|
256
|
+
type InferNestedProjectionRow<P extends Record<string, AnyExpressionSource | boolean | NestedProjection>, CodecTypes$1 extends Record<string, {
|
|
257
|
+
readonly output: unknown;
|
|
258
|
+
}> = Record<string, never>, Includes extends Record<string, unknown> = Record<string, never>> = { [K in keyof P]: P[K] extends ExpressionBuilder<infer JsType> ? JsType : P[K] extends AnyColumnBuilder ? ExtractJsTypeFromColumnBuilder<P[K]> : P[K] extends true ? Array<ExtractIncludeType<K & string, Includes>> : P[K] extends NestedProjection ? InferNestedProjectionRow<P[K], CodecTypes$1, Includes> : never };
|
|
259
|
+
/**
|
|
260
|
+
* Infers Row type from a tuple of ColumnBuilders used in returning() clause.
|
|
261
|
+
* Extracts column name and JsType from each ColumnBuilder and creates a Record.
|
|
262
|
+
*/
|
|
263
|
+
type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> = Columns extends readonly [infer First, ...infer Rest] ? First extends ColumnBuilder<infer Name, infer _Meta, infer JsType, infer _Ops extends OperationTypes> ? Name extends string ? Rest extends readonly AnyColumnBuilder[] ? { [K in Name]: JsType } & InferReturningRow<Rest> : { [K in Name]: JsType } : never : never : Record<string, never>;
|
|
264
|
+
/**
|
|
265
|
+
* Utility type to check if a contract has the required capabilities for includeMany.
|
|
266
|
+
* Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.
|
|
267
|
+
* Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`
|
|
268
|
+
*/
|
|
269
|
+
type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> = TContract extends {
|
|
270
|
+
capabilities: infer C;
|
|
271
|
+
target: infer T;
|
|
272
|
+
} ? T extends string ? C extends Record<string, Record<string, boolean>> ? C extends { [K in T]: infer TargetCaps } ? TargetCaps extends {
|
|
273
|
+
lateral: true;
|
|
274
|
+
jsonAgg: true;
|
|
275
|
+
} ? true : false : false : false : false : false;
|
|
276
|
+
/**
|
|
277
|
+
* SQL-specific Plan type that refines the ast field to use QueryAst.
|
|
278
|
+
* This is the type used by SQL query builders.
|
|
279
|
+
*/
|
|
280
|
+
type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;
|
|
281
|
+
/**
|
|
282
|
+
* Helper types for extracting contract structure.
|
|
283
|
+
*/
|
|
284
|
+
type TablesOf<TContract> = TContract extends {
|
|
285
|
+
storage: {
|
|
286
|
+
tables: infer U;
|
|
287
|
+
};
|
|
288
|
+
} ? U : never;
|
|
289
|
+
type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;
|
|
290
|
+
/**
|
|
291
|
+
* Unique symbol for metadata property to avoid collisions with user-defined properties
|
|
292
|
+
*/
|
|
293
|
+
declare const META: unique symbol;
|
|
294
|
+
/**
|
|
295
|
+
* Extracts metadata from a type that has a META property
|
|
296
|
+
*/
|
|
297
|
+
type Meta<T$1 extends {
|
|
298
|
+
[META]: unknown;
|
|
299
|
+
}> = T$1[typeof META];
|
|
300
|
+
/**
|
|
301
|
+
* Metadata interface for table definitions
|
|
302
|
+
*/
|
|
303
|
+
interface TableMetadata<Name$1 extends string> {
|
|
304
|
+
name: Name$1;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Metadata interface for model definitions
|
|
308
|
+
*/
|
|
309
|
+
interface ModelMetadata<Name$1 extends string> {
|
|
310
|
+
name: Name$1;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Base interface for table definitions with metadata
|
|
314
|
+
* Used in contract.d.ts to define storage-level table types
|
|
315
|
+
*/
|
|
316
|
+
interface TableDef<Name$1 extends string> {
|
|
317
|
+
readonly [META]: TableMetadata<Name$1>;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Base interface for model definitions with metadata
|
|
321
|
+
* Used in contract.d.ts to define application-level model types
|
|
322
|
+
*/
|
|
323
|
+
interface ModelDef<Name$1 extends string> {
|
|
324
|
+
readonly [META]: ModelMetadata<Name$1>;
|
|
325
|
+
}
|
|
326
|
+
type ColumnsOf<TContract, K$1 extends TableKey<TContract>> = K$1 extends keyof TablesOf<TContract> ? TablesOf<TContract>[K$1] extends {
|
|
327
|
+
columns: infer C;
|
|
328
|
+
} ? C : never : never;
|
|
329
|
+
interface RawTemplateOptions {
|
|
330
|
+
readonly refs?: PlanRefs;
|
|
331
|
+
readonly annotations?: Record<string, unknown>;
|
|
332
|
+
readonly projection?: ReadonlyArray<string>;
|
|
333
|
+
}
|
|
334
|
+
interface RawFunctionOptions extends RawTemplateOptions {
|
|
335
|
+
readonly params: ReadonlyArray<unknown>;
|
|
336
|
+
}
|
|
337
|
+
type RawTemplateFactory = (strings: TemplateStringsArray, ...values: readonly unknown[]) => ExecutionPlan;
|
|
338
|
+
interface RawFactory extends RawTemplateFactory {
|
|
339
|
+
(text: string, options: RawFunctionOptions): ExecutionPlan;
|
|
340
|
+
with(options: RawTemplateOptions): RawTemplateFactory;
|
|
341
|
+
}
|
|
342
|
+
interface BuildParamsMap {
|
|
343
|
+
readonly [name: string]: unknown;
|
|
344
|
+
}
|
|
345
|
+
interface BuildOptions {
|
|
346
|
+
readonly params?: BuildParamsMap;
|
|
347
|
+
}
|
|
348
|
+
interface SqlBuilderOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
|
|
349
|
+
readonly context: QueryLaneContext<TContract>;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* SQL-specific ResultType that works with both Plan and SqlQueryPlan.
|
|
353
|
+
* This extends the core ResultType to also handle SqlQueryPlan.
|
|
354
|
+
* Example: `type Row = ResultType<typeof plan>`
|
|
355
|
+
*/
|
|
356
|
+
type ResultType$1<P> = P extends SqlQueryPlan<infer R> ? R : ResultType<P>;
|
|
357
|
+
//#endregion
|
|
358
|
+
export { ParamPlaceholder as A, TableKey as B, ModelDef as C, OperationTypes as D, OperationTypeSignature as E, ResultType$1 as F, isColumnBuilder as G, TablesOf as H, RuntimeError as I, SqlBuilderOptions as L, RawFunctionOptions as M, RawTemplateFactory as N, OperationsForTypeId as O, RawTemplateOptions as P, SqlPlan as R, Meta as S, NestedProjection as T, ValueSource as U, TableMetadata as V, createOrderBuilder as W, InferProjectionRow as _, AnyOrderBuilder as a, JoinOnPredicate as b, BuildParamsMap as c, ColumnsOf as d, ComputeColumnJsType as f, InferNestedProjectionRow as g, HasIncludeManyCapabilities as h, AnyExpressionSource as i, RawFactory as j, OrderBuilder as k, CodecTypes as l, ExpressionBuilder as m, AnyColumnBuilder as n, BinaryBuilder as o, Expr as p, AnyColumnBuilderBase as r, BuildOptions as s, AnyBinaryBuilder as t, ColumnBuilder as u, InferReturningRow as v, ModelMetadata as w, META as x, JoinOnBuilder as y, TableDef as z };
|
|
359
|
+
//# sourceMappingURL=types-Bg2kUmUA.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-Bg2kUmUA.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;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lCC;;AACjB,UAoCa,iBApCb,CAAA,kBAqCgB,WArChB,CAqC4B,UArC5B,CAAA,GAqC0C,WArC1C,CAqCsD,UArCtD,CAAA,CAAA,CAAA;EAAyB,SAAA,OAAA,EAuCT,gBAvCS,CAuCQ,SAvCR,CAAA;;;;;;AAM7B;AACkB,KAwCN,YAxCM,CAAA,CAAA,CAAA,GAwCU,CAxCV,SAwCoB,YAxCpB,CAAA,KAAA,EAAA,CAAA,GAAA,CAAA,GAwCgD,UAxChD,CAwC+D,CAxC/D,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates an OrderBuilder for use in orderBy clauses.
|
|
4
|
+
*/
|
|
5
|
+
function createOrderBuilder(expr, dir) {
|
|
6
|
+
return {
|
|
7
|
+
kind: "order",
|
|
8
|
+
expr,
|
|
9
|
+
dir
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function isColumnBuilder(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && "kind" in value && value.kind === "column";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { isColumnBuilder as n, createOrderBuilder as t };
|
|
18
|
+
//# sourceMappingURL=types-D_FRJvm0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-D_FRJvm0.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n ResultType as CoreResultType,\n ExecutionPlan,\n PlanRefs,\n} from '@prisma-next/contract/types';\nimport type { ArgSpec, ReturnSpec } from '@prisma-next/operations';\nimport type { SqlContract, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlLoweringSpec } from '@prisma-next/sql-operations';\nimport type {\n BinaryOp,\n ColumnRef,\n Direction,\n Expression,\n ExpressionSource,\n OperationExpr,\n ParamRef,\n QueryAst,\n} from './ast/types';\nimport type { SqlQueryPlan } from './plan';\nimport type { QueryLaneContext } from './query-lane-context';\n\nexport interface ParamPlaceholder {\n readonly kind: 'param-placeholder';\n readonly name: string;\n}\n\n/**\n * ValueSource represents any value that can appear in a comparison or as an argument.\n * This includes:\n * - ParamPlaceholder: A parameter placeholder (e.g., `param('userId')`)\n * - ExpressionSource: Something that can be converted to an Expression (ColumnBuilder, ExpressionBuilder)\n */\nexport type ValueSource = ParamPlaceholder | ExpressionSource;\n\nexport interface OrderBuilder<\n _ColumnName extends string = string,\n _ColumnMeta extends StorageColumn = StorageColumn,\n _JsType = unknown,\n> {\n readonly kind: 'order';\n readonly expr: Expression;\n readonly dir: Direction;\n}\n\n/**\n * Creates an OrderBuilder for use in orderBy clauses.\n */\nexport function createOrderBuilder(\n expr: AnyColumnBuilder | OperationExpr,\n dir: Direction,\n): AnyOrderBuilder {\n return { kind: 'order', expr, dir } as AnyOrderBuilder;\n}\n\n/**\n * ColumnBuilder with optional operation methods based on the column's typeId.\n * When Operations is provided and the column's typeId matches, operation methods are included.\n * Implements ExpressionSource to provide type-safe conversion to ColumnRef.\n */\nexport type ColumnBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n> = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: ColumnName;\n readonly columnMeta: ColumnMeta;\n // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)\n eq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n neq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n gt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n lt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n gte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n lte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n /** Converts this column builder to a ColumnRef expression */\n toExpr(): ColumnRef;\n // Helper property for type extraction (not used at runtime)\n readonly __jsType: JsType;\n} & (ColumnMeta['codecId'] extends string\n ? ColumnMeta['codecId'] extends keyof Operations\n ? OperationMethods<\n OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>,\n ColumnName,\n StorageColumn,\n JsType\n >\n : Record<string, never>\n : Record<string, never>);\n\nexport interface BinaryBuilder<\n _ColumnName extends string = string,\n _ColumnMeta extends StorageColumn = StorageColumn,\n _JsType = unknown,\n> {\n readonly kind: 'binary';\n readonly op: BinaryOp;\n readonly left: Expression;\n readonly right: ValueSource;\n}\n\n// Forward declare AnyBinaryBuilder and AnyOrderBuilder for use in ExpressionBuilder\nexport type AnyBinaryBuilder = BinaryBuilder;\nexport type AnyOrderBuilder = OrderBuilder;\n\n/**\n * ExpressionBuilder represents the result of an operation (e.g., col.distance(...)).\n * Unlike ColumnBuilder (which represents a column), ExpressionBuilder represents\n * an operation expression and provides the same DSL methods for chaining.\n *\n * Implements ExpressionSource to provide type-safe conversion to OperationExpr.\n */\nexport interface ExpressionBuilder<JsType = unknown> extends ExpressionSource {\n readonly kind: 'expression';\n readonly expr: OperationExpr;\n readonly columnMeta: StorageColumn;\n\n // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)\n eq(value: ValueSource): AnyBinaryBuilder;\n neq(value: ValueSource): AnyBinaryBuilder;\n gt(value: ValueSource): AnyBinaryBuilder;\n lt(value: ValueSource): AnyBinaryBuilder;\n gte(value: ValueSource): AnyBinaryBuilder;\n lte(value: ValueSource): AnyBinaryBuilder;\n asc(): AnyOrderBuilder;\n desc(): AnyOrderBuilder;\n\n /** Converts this expression builder to the underlying OperationExpr */\n toExpr(): OperationExpr;\n\n // Helper property for type extraction (not used at runtime)\n readonly __jsType: JsType;\n}\n\n// Helper aliases for usage sites where the specific column parameters are irrelevant\n// Accepts any ColumnBuilder regardless of its Operations parameter\n// Note: We use `any` here because TypeScript's variance rules don't allow us to express\n// \"any type that extends OperationTypes\" in a way that works for assignment.\n// Contract-specific OperationTypes (e.g., PgVectorOperationTypes) are not assignable\n// to the base OperationTypes in generic parameter position, even though they extend it structurally.\n// Helper type that accepts any ColumnBuilder regardless of its generic parameters\n// This is needed because conditional types in ColumnBuilder create incompatible intersection types\n// when Operations differs, even though structurally they're compatible\nexport type AnyColumnBuilderBase = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: string;\n readonly columnMeta: StorageColumn;\n // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)\n eq(value: ValueSource): AnyBinaryBuilder;\n neq(value: ValueSource): AnyBinaryBuilder;\n gt(value: ValueSource): AnyBinaryBuilder;\n lt(value: ValueSource): AnyBinaryBuilder;\n gte(value: ValueSource): AnyBinaryBuilder;\n lte(value: ValueSource): AnyBinaryBuilder;\n asc(): AnyOrderBuilder;\n desc(): AnyOrderBuilder;\n toExpr(): ColumnRef;\n readonly __jsType: unknown;\n // Allow any operation methods (from conditional type)\n readonly [key: string]: unknown;\n};\n\nexport type AnyColumnBuilder =\n | ColumnBuilder<\n string,\n StorageColumn,\n unknown,\n // biome-ignore lint/suspicious/noExplicitAny: AnyColumnBuilder must accept column builders with any operation types\n any\n >\n | AnyColumnBuilderBase;\n\n/**\n * Union type for any builder that can produce an Expression.\n * Used in DSL method signatures where either a column or operation result can be passed.\n */\nexport type AnyExpressionSource = AnyColumnBuilder | ExpressionBuilder;\n\nexport function isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\nexport interface JoinOnBuilder {\n eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;\n}\n\nexport interface JoinOnPredicate {\n readonly kind: 'join-on';\n readonly left: AnyColumnBuilder;\n readonly right: AnyColumnBuilder;\n}\n\nexport type Expr = ColumnRef | ParamRef;\n\n/**\n * Helper type to extract codec output type from CodecTypes.\n * Returns never if the codecId is not found in CodecTypes.\n */\ntype ExtractCodecOutputType<\n CodecId extends string,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = CodecId extends keyof CodecTypes\n ? CodecTypes[CodecId] extends { readonly output: infer Output }\n ? Output\n : never\n : never;\n\n/**\n * Type-level operation signature.\n * Represents an operation at the type level, similar to OperationSignature at runtime.\n */\nexport type OperationTypeSignature = {\n readonly args: ReadonlyArray<ArgSpec>;\n readonly returns: ReturnSpec;\n readonly lowering: SqlLoweringSpec;\n readonly capabilities?: ReadonlyArray<string>;\n};\n\n/**\n * Type-level operation registry.\n * Maps typeId → operations, where operations is a record of method name → operation signature.\n *\n * Example:\n * ```typescript\n * type MyOperations: OperationTypes = {\n * 'pg/vector@1': {\n * cosineDistance: {\n * args: [{ kind: 'typeId'; type: 'pg/vector@1' }];\n * returns: { kind: 'builtin'; type: 'number' };\n * lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };\n * };\n * };\n * };\n * ```\n */\nexport type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;\n\n/**\n * CodecTypes represents a map of typeId to codec definitions.\n * Each codec definition must have an `output` property indicating the JavaScript type.\n *\n * Example:\n * ```typescript\n * type MyCodecTypes: CodecTypes = {\n * 'pg/int4@1': { output: number };\n * 'pg/text@1': { output: string };\n * };\n * ```\n */\nexport type CodecTypes = Record<string, { readonly output: unknown }>;\n\n/**\n * Extracts operations for a given typeId from the operation registry.\n * Returns an empty record if the typeId is not found.\n *\n * @example\n * ```typescript\n * type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;\n * // Ops = { cosineDistance: { ... }, l2Distance: { ... } }\n * ```\n */\nexport type OperationsForTypeId<\n TypeId extends string,\n Operations extends OperationTypes,\n> = Operations extends Record<string, never>\n ? Record<string, never>\n : TypeId extends keyof Operations\n ? Operations[TypeId]\n : Record<string, never>;\n\n/**\n * Maps operation signatures to method signatures on ColumnBuilder.\n * Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder\n * based on the return type.\n */\ntype OperationMethods<\n Ops extends Record<string, OperationTypeSignature>,\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType,\n> = {\n [K in keyof Ops]: Ops[K] extends OperationTypeSignature\n ? (\n ...args: OperationArgs<Ops[K]['args']>\n ) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType>\n : never;\n};\n\n/**\n * Maps operation argument specs to TypeScript argument types.\n * - typeId args: ColumnBuilder (accepts base columns or operation results)\n * - param args: ParamPlaceholder\n * - literal args: unknown (could be more specific in future)\n */\ntype OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [\n infer First,\n ...infer Rest,\n]\n ? First extends ArgSpec\n ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])]\n : []\n : [];\n\ntype ArgToType<Arg extends ArgSpec> = Arg extends { kind: 'typeId' }\n ? AnyExpressionSource\n : Arg extends { kind: 'param' }\n ? ParamPlaceholder\n : Arg extends { kind: 'literal' }\n ? unknown\n : never;\n\n/**\n * Maps operation return spec to return type.\n * Operations return ExpressionBuilder, not ColumnBuilder, because the result\n * represents an expression (OperationExpr) rather than a column reference.\n */\ntype OperationReturn<\n Returns extends ReturnSpec,\n _ColumnName extends string,\n _ColumnMeta extends StorageColumn,\n _JsType,\n> = Returns extends { kind: 'builtin'; type: infer T }\n ? T extends 'number'\n ? ExpressionBuilder<number>\n : T extends 'boolean'\n ? ExpressionBuilder<boolean>\n : T extends 'string'\n ? ExpressionBuilder<string>\n : ExpressionBuilder<unknown>\n : Returns extends { kind: 'typeId' }\n ? ExpressionBuilder<unknown>\n : ExpressionBuilder<unknown>;\n\n/**\n * Computes JavaScript type for a column at column creation time.\n *\n * Type inference:\n * - Read columnMeta.codecId as typeId string literal\n * - Look up CodecTypes[typeId].output\n * - Apply nullability: nullable ? Output | null : Output\n */\ntype ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends { codecId: infer CodecId extends string }\n ? CodecId\n : ColumnMeta extends { type: infer TypeId extends string }\n ? TypeId\n : never;\n\nexport type ComputeColumnJsType<\n _Contract extends SqlContract<SqlStorage>,\n _TableName extends string,\n _ColumnName extends string,\n ColumnMeta extends StorageColumn,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = ColumnMeta extends { nullable: infer Nullable }\n ? ColumnMetaTypeId<ColumnMeta> extends infer TypeId\n ? TypeId extends string\n ? ExtractCodecOutputType<TypeId, CodecTypes> extends infer CodecOutput\n ? [CodecOutput] extends [never]\n ? unknown // Codec not found in CodecTypes\n : Nullable extends true\n ? CodecOutput | null\n : CodecOutput\n : unknown\n : unknown\n : unknown\n : unknown;\n\n/**\n * Infers Row type from a projection object.\n * Maps Record<string, ColumnBuilder> to Record<string, JSType>\n *\n * Extracts the pre-computed JsType from each ColumnBuilder in the projection.\n */\n/**\n * Extracts the inferred JsType carried by a ColumnBuilder.\n */\ntype ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> =\n CB extends ColumnBuilder<\n infer _ColumnName extends string,\n infer _ColumnMeta extends StorageColumn,\n infer JsType,\n infer _Ops\n >\n ? JsType\n : never;\n\nexport type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {\n [K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;\n};\n\n/**\n * Nested projection type - allows recursive nesting of ColumnBuilder, ExpressionBuilder, or nested objects.\n */\nexport type NestedProjection = Record<\n string,\n | AnyExpressionSource\n | Record<\n string,\n | AnyExpressionSource\n | Record<\n string,\n | AnyExpressionSource\n | Record<string, AnyExpressionSource | Record<string, AnyExpressionSource>>\n >\n >\n>;\n\n/**\n * Helper type to extract include type from Includes map.\n * Returns the value type if K is a key of Includes, otherwise returns unknown.\n */\ntype ExtractIncludeType<\n K extends string,\n Includes extends Record<string, unknown>,\n> = K extends keyof Includes ? Includes[K] : unknown;\n\n/**\n * Infers Row type from a nested projection object.\n * Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.\n *\n * Extracts the pre-computed JsType from each ColumnBuilder at leaves.\n * When a value is `true`, it represents an include reference and infers `Array<ChildShape>`\n * by looking up the include alias in the Includes type map.\n */\nexport type InferNestedProjectionRow<\n P extends Record<string, AnyExpressionSource | boolean | NestedProjection>,\n CodecTypes extends Record<string, { readonly output: unknown }> = Record<string, never>,\n Includes extends Record<string, unknown> = Record<string, never>,\n> = {\n [K in keyof P]: P[K] extends ExpressionBuilder<infer JsType>\n ? JsType\n : P[K] extends AnyColumnBuilder\n ? ExtractJsTypeFromColumnBuilder<P[K]>\n : P[K] extends true\n ? Array<ExtractIncludeType<K & string, Includes>> // Include reference - infers Array<ChildShape> from Includes map\n : P[K] extends NestedProjection\n ? InferNestedProjectionRow<P[K], CodecTypes, Includes>\n : never;\n};\n\n/**\n * Infers Row type from a tuple of ColumnBuilders used in returning() clause.\n * Extracts column name and JsType from each ColumnBuilder and creates a Record.\n */\nexport type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> =\n Columns extends readonly [infer First, ...infer Rest]\n ? First extends ColumnBuilder<\n infer Name,\n infer _Meta,\n infer JsType,\n infer _Ops extends OperationTypes\n >\n ? Name extends string\n ? Rest extends readonly AnyColumnBuilder[]\n ? { [K in Name]: JsType } & InferReturningRow<Rest>\n : { [K in Name]: JsType }\n : never\n : never\n : Record<string, never>;\n\n/**\n * Utility type to check if a contract has the required capabilities for includeMany.\n * Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.\n * Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`\n */\nexport type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> =\n TContract extends { capabilities: infer C; target: infer T }\n ? T extends string\n ? C extends Record<string, Record<string, boolean>>\n ? C extends { [K in T]: infer TargetCaps }\n ? TargetCaps extends { lateral: true; jsonAgg: true }\n ? true\n : false\n : false\n : false\n : false\n : false;\n\n/**\n * SQL-specific Plan type that refines the ast field to use QueryAst.\n * This is the type used by SQL query builders.\n */\nexport type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;\n\n/**\n * Helper types for extracting contract structure.\n */\nexport type TablesOf<TContract> = TContract extends {\n storage: { tables: infer U };\n}\n ? U\n : never;\n\nexport type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;\n\n// Common types for contract.d.ts generation (SQL-specific)\n// These types are used by emitted contract.d.ts files to provide type-safe DSL/ORM types\n\n/**\n * Unique symbol for metadata property to avoid collisions with user-defined properties\n */\nexport declare const META: unique symbol;\n\n/**\n * Extracts metadata from a type that has a META property\n */\nexport type Meta<T extends { [META]: unknown }> = T[typeof META];\n\n/**\n * Metadata interface for table definitions\n */\nexport interface TableMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Metadata interface for model definitions\n */\nexport interface ModelMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Base interface for table definitions with metadata\n * Used in contract.d.ts to define storage-level table types\n */\nexport interface TableDef<Name extends string> {\n readonly [META]: TableMetadata<Name>;\n}\n\n/**\n * Base interface for model definitions with metadata\n * Used in contract.d.ts to define application-level model types\n */\nexport interface ModelDef<Name extends string> {\n readonly [META]: ModelMetadata<Name>;\n}\n\nexport type ColumnsOf<\n TContract,\n K extends TableKey<TContract>,\n> = K extends keyof TablesOf<TContract>\n ? TablesOf<TContract>[K] extends { columns: infer C }\n ? C\n : never\n : never;\n\nexport interface RawTemplateOptions {\n readonly refs?: PlanRefs;\n readonly annotations?: Record<string, unknown>;\n readonly projection?: ReadonlyArray<string>;\n}\n\nexport interface RawFunctionOptions extends RawTemplateOptions {\n readonly params: ReadonlyArray<unknown>;\n}\n\nexport type RawTemplateFactory = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n) => ExecutionPlan;\n\nexport interface RawFactory extends RawTemplateFactory {\n (text: string, options: RawFunctionOptions): ExecutionPlan;\n with(options: RawTemplateOptions): RawTemplateFactory;\n}\n\nexport type { RuntimeError } from '@prisma-next/plan';\n\nexport interface BuildParamsMap {\n readonly [name: string]: unknown;\n}\n\nexport interface BuildOptions {\n readonly params?: BuildParamsMap;\n}\n\nexport interface SqlBuilderOptions<\n TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,\n> {\n readonly context: QueryLaneContext<TContract>;\n}\n\n/**\n * SQL-specific ResultType that works with both Plan and SqlQueryPlan.\n * This extends the core ResultType to also handle SqlQueryPlan.\n * Example: `type Row = ResultType<typeof plan>`\n */\nexport type ResultType<P> = P extends SqlQueryPlan<infer R> ? R : CoreResultType<P>;\n"],"mappings":";;;;AA+CA,SAAgB,mBACd,MACA,KACiB;AACjB,QAAO;EAAE,MAAM;EAAS;EAAM;EAAK;;AAmIrC,SAAgB,gBAAgB,OAA2C;AACzE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,73 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-relational-core",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.94.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Schema and column builders, operation attachment, and AST types for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"ts-toolbelt": "^9.6.0",
|
|
9
|
-
"@prisma-next/contract": "0.3.0-pr.
|
|
10
|
-
"@prisma-next/operations": "0.3.0-pr.
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/sql-operations": "0.3.0-pr.
|
|
9
|
+
"@prisma-next/contract": "0.3.0-pr.94.2",
|
|
10
|
+
"@prisma-next/operations": "0.3.0-pr.94.2",
|
|
11
|
+
"@prisma-next/plan": "0.3.0-pr.94.2",
|
|
12
|
+
"@prisma-next/sql-contract": "0.3.0-pr.94.2",
|
|
13
|
+
"@prisma-next/sql-operations": "0.3.0-pr.94.2"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"
|
|
16
|
+
"tsdown": "0.18.4",
|
|
17
17
|
"typescript": "5.9.3",
|
|
18
18
|
"vitest": "4.0.16",
|
|
19
|
-
"@prisma-next/sql-contract-ts": "0.3.0-pr.
|
|
19
|
+
"@prisma-next/sql-contract-ts": "0.3.0-pr.94.2",
|
|
20
20
|
"@prisma-next/test-utils": "0.0.1",
|
|
21
|
-
"@prisma-next/tsconfig": "0.0.0"
|
|
21
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
22
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
25
26
|
"src"
|
|
26
27
|
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
27
31
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"./
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"./
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
"./types": {
|
|
41
|
-
"types": "./dist/exports/types.d.ts",
|
|
42
|
-
"import": "./dist/exports/types.js"
|
|
43
|
-
},
|
|
44
|
-
"./operations-registry": {
|
|
45
|
-
"types": "./dist/exports/operations-registry.d.ts",
|
|
46
|
-
"import": "./dist/exports/operations-registry.js"
|
|
47
|
-
},
|
|
48
|
-
"./errors": {
|
|
49
|
-
"types": "./dist/exports/errors.d.ts",
|
|
50
|
-
"import": "./dist/exports/errors.js"
|
|
51
|
-
},
|
|
52
|
-
"./ast": {
|
|
53
|
-
"types": "./dist/exports/ast.d.ts",
|
|
54
|
-
"import": "./dist/exports/ast.js"
|
|
55
|
-
},
|
|
56
|
-
"./plan": {
|
|
57
|
-
"types": "./dist/exports/plan.d.ts",
|
|
58
|
-
"import": "./dist/exports/plan.js"
|
|
59
|
-
},
|
|
60
|
-
"./query-lane-context": {
|
|
61
|
-
"types": "./dist/exports/query-lane-context.d.ts",
|
|
62
|
-
"import": "./dist/exports/query-lane-context.js"
|
|
63
|
-
},
|
|
64
|
-
"./utils/guards": {
|
|
65
|
-
"types": "./dist/exports/guards.d.ts",
|
|
66
|
-
"import": "./dist/exports/guards.js"
|
|
67
|
-
}
|
|
32
|
+
".": "./dist/index.mjs",
|
|
33
|
+
"./ast": "./dist/exports/ast.mjs",
|
|
34
|
+
"./errors": "./dist/exports/errors.mjs",
|
|
35
|
+
"./guards": "./dist/exports/guards.mjs",
|
|
36
|
+
"./operations-registry": "./dist/exports/operations-registry.mjs",
|
|
37
|
+
"./param": "./dist/exports/param.mjs",
|
|
38
|
+
"./plan": "./dist/exports/plan.mjs",
|
|
39
|
+
"./query-lane-context": "./dist/exports/query-lane-context.mjs",
|
|
40
|
+
"./schema": "./dist/exports/schema.mjs",
|
|
41
|
+
"./types": "./dist/exports/types.mjs",
|
|
42
|
+
"./package.json": "./package.json"
|
|
68
43
|
},
|
|
44
|
+
"main": "./dist/index.mjs",
|
|
45
|
+
"module": "./dist/index.mjs",
|
|
46
|
+
"types": "./dist/index.d.mts",
|
|
69
47
|
"scripts": {
|
|
70
|
-
"build": "
|
|
48
|
+
"build": "tsdown",
|
|
71
49
|
"test": "vitest run",
|
|
72
50
|
"test:coverage": "vitest run --coverage",
|
|
73
51
|
"typecheck": "tsc --noEmit",
|
package/src/ast/predicate.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BinaryExpr,
|
|
3
|
-
BinaryOp,
|
|
4
|
-
ColumnRef,
|
|
5
|
-
ExistsExpr,
|
|
6
|
-
OperationExpr,
|
|
7
|
-
ParamRef,
|
|
8
|
-
SelectAst,
|
|
9
|
-
} from './types';
|
|
1
|
+
import type { BinaryExpr, BinaryOp, ExistsExpr, Expression, ParamRef, SelectAst } from './types';
|
|
10
2
|
|
|
11
3
|
export function createBinaryExpr(
|
|
12
4
|
op: BinaryOp,
|
|
13
|
-
left:
|
|
14
|
-
right:
|
|
5
|
+
left: Expression,
|
|
6
|
+
right: Expression | ParamRef,
|
|
15
7
|
): BinaryExpr {
|
|
16
8
|
return {
|
|
17
9
|
kind: 'bin',
|
package/src/ast/types.ts
CHANGED
|
@@ -32,13 +32,27 @@ export interface OperationExpr {
|
|
|
32
32
|
readonly kind: 'operation';
|
|
33
33
|
readonly method: string;
|
|
34
34
|
readonly forTypeId: string;
|
|
35
|
-
readonly self:
|
|
36
|
-
readonly args: ReadonlyArray<
|
|
35
|
+
readonly self: Expression;
|
|
36
|
+
readonly args: ReadonlyArray<Expression | ParamRef | LiteralExpr>;
|
|
37
37
|
readonly returns: ReturnSpec;
|
|
38
38
|
readonly lowering: SqlLoweringSpec;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Unified expression type - the canonical AST representation for column references
|
|
43
|
+
* and operation expressions. This is what all builders convert to via toExpr().
|
|
44
|
+
*/
|
|
45
|
+
export type Expression = ColumnRef | OperationExpr;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Interface for any builder that can produce an Expression.
|
|
49
|
+
* Implemented by ColumnBuilder and ExpressionBuilder.
|
|
50
|
+
*/
|
|
51
|
+
export interface ExpressionSource {
|
|
52
|
+
toExpr(): Expression;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isOperationExpr(expr: Expression): expr is OperationExpr {
|
|
42
56
|
return expr.kind === 'operation';
|
|
43
57
|
}
|
|
44
58
|
|
|
@@ -47,8 +61,8 @@ export type BinaryOp = 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte';
|
|
|
47
61
|
export interface BinaryExpr {
|
|
48
62
|
readonly kind: 'bin';
|
|
49
63
|
readonly op: BinaryOp;
|
|
50
|
-
readonly left:
|
|
51
|
-
readonly right:
|
|
64
|
+
readonly left: Expression;
|
|
65
|
+
readonly right: Expression | ParamRef;
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
export interface ExistsExpr {
|
|
@@ -82,9 +96,9 @@ export interface IncludeAst {
|
|
|
82
96
|
readonly table: TableRef;
|
|
83
97
|
readonly on: JoinOnExpr;
|
|
84
98
|
readonly where?: BinaryExpr | ExistsExpr;
|
|
85
|
-
readonly orderBy?: ReadonlyArray<{ expr:
|
|
99
|
+
readonly orderBy?: ReadonlyArray<{ expr: Expression; dir: Direction }>;
|
|
86
100
|
readonly limit?: number;
|
|
87
|
-
readonly project: ReadonlyArray<{ alias: string; expr:
|
|
101
|
+
readonly project: ReadonlyArray<{ alias: string; expr: Expression }>;
|
|
88
102
|
};
|
|
89
103
|
}
|
|
90
104
|
|
|
@@ -95,10 +109,10 @@ export interface SelectAst {
|
|
|
95
109
|
readonly includes?: ReadonlyArray<IncludeAst>;
|
|
96
110
|
readonly project: ReadonlyArray<{
|
|
97
111
|
alias: string;
|
|
98
|
-
expr:
|
|
112
|
+
expr: Expression | IncludeRef | LiteralExpr;
|
|
99
113
|
}>;
|
|
100
114
|
readonly where?: BinaryExpr | ExistsExpr;
|
|
101
|
-
readonly orderBy?: ReadonlyArray<{ expr:
|
|
115
|
+
readonly orderBy?: ReadonlyArray<{ expr: Expression; dir: Direction }>;
|
|
102
116
|
readonly limit?: number;
|
|
103
117
|
}
|
|
104
118
|
|