@prisma-next/sql-relational-core 0.0.1
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/README.md +123 -0
- package/dist/chunk-2F7DSEOU.js +8 -0
- package/dist/chunk-2F7DSEOU.js.map +1 -0
- package/dist/chunk-7FMQVMSM.js +128 -0
- package/dist/chunk-7FMQVMSM.js.map +1 -0
- package/dist/chunk-7I3EMQID.js +16 -0
- package/dist/chunk-7I3EMQID.js.map +1 -0
- package/dist/chunk-ENOLRQZS.js +320 -0
- package/dist/chunk-ENOLRQZS.js.map +1 -0
- package/dist/chunk-FMVAOBWJ.js +151 -0
- package/dist/chunk-FMVAOBWJ.js.map +1 -0
- package/dist/chunk-G52ENULI.js +1 -0
- package/dist/chunk-G52ENULI.js.map +1 -0
- package/dist/chunk-ILC64YWE.js +9 -0
- package/dist/chunk-ILC64YWE.js.map +1 -0
- package/dist/chunk-U7AXAUJA.js +1 -0
- package/dist/chunk-U7AXAUJA.js.map +1 -0
- package/dist/chunk-UVFWELV2.js +1 -0
- package/dist/chunk-UVFWELV2.js.map +1 -0
- package/dist/exports/ast.d.ts +119 -0
- package/dist/exports/ast.js +46 -0
- package/dist/exports/ast.js.map +1 -0
- package/dist/exports/errors.d.ts +1 -0
- package/dist/exports/errors.js +9 -0
- package/dist/exports/errors.js.map +1 -0
- package/dist/exports/operations-registry.d.ts +13 -0
- package/dist/exports/operations-registry.js +8 -0
- package/dist/exports/operations-registry.js.map +1 -0
- package/dist/exports/param.d.ts +14 -0
- package/dist/exports/param.js +7 -0
- package/dist/exports/param.js.map +1 -0
- package/dist/exports/plan.d.ts +4 -0
- package/dist/exports/plan.js +2 -0
- package/dist/exports/plan.js.map +1 -0
- package/dist/exports/query-lane-context.d.ts +4 -0
- package/dist/exports/query-lane-context.js +2 -0
- package/dist/exports/query-lane-context.js.map +1 -0
- package/dist/exports/schema.d.ts +63 -0
- package/dist/exports/schema.js +12 -0
- package/dist/exports/schema.js.map +1 -0
- package/dist/exports/types.d.ts +306 -0
- package/dist/exports/types.js +7 -0
- package/dist/exports/types.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/plan-D6dOf1wQ.d.ts +135 -0
- package/dist/query-lane-context-BhOMmb_K.d.ts +158 -0
- package/package.json +72 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { StorageColumn, SqlContract, SqlStorage, ExtractCodecTypes, ExtractOperationTypes } from '@prisma-next/sql-contract/types';
|
|
2
|
+
import { T as TableRef } from '../plan-D6dOf1wQ.js';
|
|
3
|
+
import { Q as QueryLaneContext } from '../query-lane-context-BhOMmb_K.js';
|
|
4
|
+
import { ParamPlaceholder, BinaryBuilder, OrderBuilder, CodecTypes, OperationTypes, ColumnBuilder, ComputeColumnJsType, OperationTypeSignature } from './types.js';
|
|
5
|
+
import '@prisma-next/contract/types';
|
|
6
|
+
import '@prisma-next/operations';
|
|
7
|
+
import '@prisma-next/sql-operations';
|
|
8
|
+
import 'ts-toolbelt';
|
|
9
|
+
import '@prisma-next/plan';
|
|
10
|
+
|
|
11
|
+
type TableColumns<Table extends {
|
|
12
|
+
columns: Record<string, StorageColumn>;
|
|
13
|
+
}> = Table['columns'];
|
|
14
|
+
type ColumnBuilders<Contract extends SqlContract<SqlStorage>, TableName extends string, Columns extends Record<string, StorageColumn>, CodecTypes extends CodecTypes, Operations extends OperationTypes> = {
|
|
15
|
+
readonly [K in keyof Columns]: ColumnBuilder<K & string, Columns[K], ComputeColumnJsType<Contract, TableName, K & string, Columns[K], CodecTypes>, Operations>;
|
|
16
|
+
};
|
|
17
|
+
declare class ColumnBuilderImpl<ColumnName extends string, ColumnMeta extends StorageColumn, JsType = unknown> {
|
|
18
|
+
readonly table: string;
|
|
19
|
+
readonly column: ColumnName;
|
|
20
|
+
private readonly storageColumn;
|
|
21
|
+
readonly kind: "column";
|
|
22
|
+
constructor(table: string, column: ColumnName, storageColumn: ColumnMeta);
|
|
23
|
+
get columnMeta(): ColumnMeta;
|
|
24
|
+
get __jsType(): JsType;
|
|
25
|
+
eq(this: ColumnBuilderImpl<ColumnName, ColumnMeta, JsType>, value: ParamPlaceholder): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
26
|
+
asc(this: ColumnBuilderImpl<ColumnName, ColumnMeta, JsType>): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
27
|
+
desc(this: ColumnBuilderImpl<ColumnName, ColumnMeta, JsType>): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
28
|
+
}
|
|
29
|
+
declare class TableBuilderImpl<Contract extends SqlContract<SqlStorage>, TableName extends string, Columns extends Record<string, StorageColumn>, CodecTypes extends CodecTypes, Operations extends OperationTypes> implements TableRef {
|
|
30
|
+
readonly kind: "table";
|
|
31
|
+
readonly columns: ColumnBuilders<Contract, TableName, Columns, CodecTypes, Operations>;
|
|
32
|
+
private readonly _name;
|
|
33
|
+
constructor(name: TableName, columns: ColumnBuilders<Contract, TableName, Columns, CodecTypes, Operations>);
|
|
34
|
+
get name(): string;
|
|
35
|
+
}
|
|
36
|
+
type ExtractSchemaTables<Contract extends SqlContract<SqlStorage>, CodecTypes extends CodecTypes, Operations extends OperationTypes> = {
|
|
37
|
+
readonly [TableName in keyof Contract['storage']['tables']]: TableBuilderImpl<Contract, TableName & string, TableColumns<Contract['storage']['tables'][TableName]>, CodecTypes, Operations> & TableRef;
|
|
38
|
+
};
|
|
39
|
+
type SchemaHandle<Contract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, CodecTypes extends CodecTypes = CodecTypes, Operations extends OperationTypes = Record<string, never>> = {
|
|
40
|
+
readonly tables: ExtractSchemaTables<Contract, CodecTypes, Operations>;
|
|
41
|
+
};
|
|
42
|
+
type SchemaReturnType<Contract extends SqlContract<SqlStorage>> = SchemaHandle<Contract, ExtractCodecTypes<Contract>, ToOperationTypes<ExtractOperationTypes<Contract>>>;
|
|
43
|
+
type NormalizeOperationTypes<T> = {
|
|
44
|
+
[TypeId in keyof T]: {
|
|
45
|
+
[Method in keyof T[TypeId]]: T[TypeId][Method] extends OperationTypeSignature ? T[TypeId][Method] : OperationTypeSignature;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type ToOperationTypes<T> = T extends OperationTypes ? T : NormalizeOperationTypes<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a schema handle for building SQL queries.
|
|
51
|
+
*
|
|
52
|
+
* @param context - Query lane context containing contract, codec and operation registries
|
|
53
|
+
* @returns A schema handle with typed table builders
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const schemaHandle = schema<Contract>(context);
|
|
58
|
+
* const userTable = schemaHandle.tables.user;
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function schema<Contract extends SqlContract<SqlStorage>>(context: QueryLaneContext<Contract>): SchemaReturnType<Contract>;
|
|
62
|
+
|
|
63
|
+
export { ColumnBuilderImpl as Column, ColumnBuilderImpl, type SchemaHandle, TableBuilderImpl as Table, TableBuilderImpl, schema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { ExecutionPlan, PlanRefs, ResultType as ResultType$1 } from '@prisma-next/contract/types';
|
|
2
|
+
import { ArgSpec, ReturnSpec } from '@prisma-next/operations';
|
|
3
|
+
import { StorageColumn, SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
4
|
+
import { SqlLoweringSpec } from '@prisma-next/sql-operations';
|
|
5
|
+
import { O as OperationExpr, D as Direction, C as ColumnRef, P as ParamRef, Q as QueryAst, f as SqlQueryPlan } from '../plan-D6dOf1wQ.js';
|
|
6
|
+
import { Q as QueryLaneContext } from '../query-lane-context-BhOMmb_K.js';
|
|
7
|
+
export { RuntimeError } from '@prisma-next/plan';
|
|
8
|
+
import 'ts-toolbelt';
|
|
9
|
+
|
|
10
|
+
interface ParamPlaceholder {
|
|
11
|
+
readonly kind: 'param-placeholder';
|
|
12
|
+
readonly name: string;
|
|
13
|
+
}
|
|
14
|
+
interface OrderBuilder<ColumnName extends string = string, ColumnMeta extends StorageColumn = StorageColumn, JsType = unknown> {
|
|
15
|
+
readonly kind: 'order';
|
|
16
|
+
readonly expr: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;
|
|
17
|
+
readonly dir: Direction;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* ColumnBuilder with optional operation methods based on the column's typeId.
|
|
21
|
+
* When Operations is provided and the column's typeId matches, operation methods are included.
|
|
22
|
+
*/
|
|
23
|
+
type ColumnBuilder<ColumnName extends string = string, ColumnMeta extends StorageColumn = StorageColumn, JsType = unknown, Operations extends OperationTypes = Record<string, never>> = {
|
|
24
|
+
readonly kind: 'column';
|
|
25
|
+
readonly table: string;
|
|
26
|
+
readonly column: ColumnName;
|
|
27
|
+
readonly columnMeta: ColumnMeta;
|
|
28
|
+
eq(value: ParamPlaceholder): BinaryBuilder<ColumnName, ColumnMeta, JsType>;
|
|
29
|
+
asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
30
|
+
desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
31
|
+
readonly __jsType: JsType;
|
|
32
|
+
} & (ColumnMeta['type'] extends keyof Operations ? OperationMethods<OperationsForTypeId<ColumnMeta['type'], Operations>, ColumnName, StorageColumn, JsType> : Record<string, never>);
|
|
33
|
+
interface BinaryBuilder<ColumnName extends string = string, ColumnMeta extends StorageColumn = StorageColumn, JsType = unknown> {
|
|
34
|
+
readonly kind: 'binary';
|
|
35
|
+
readonly op: 'eq';
|
|
36
|
+
readonly left: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;
|
|
37
|
+
readonly right: ParamPlaceholder;
|
|
38
|
+
}
|
|
39
|
+
type AnyColumnBuilder = ColumnBuilder<string, StorageColumn, unknown, any>;
|
|
40
|
+
type AnyBinaryBuilder = BinaryBuilder<string, StorageColumn, unknown>;
|
|
41
|
+
type AnyOrderBuilder = OrderBuilder<string, StorageColumn, unknown>;
|
|
42
|
+
declare function isColumnBuilder(value: unknown): value is AnyColumnBuilder;
|
|
43
|
+
interface JoinOnBuilder {
|
|
44
|
+
eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;
|
|
45
|
+
}
|
|
46
|
+
interface JoinOnPredicate {
|
|
47
|
+
readonly kind: 'join-on';
|
|
48
|
+
readonly left: AnyColumnBuilder;
|
|
49
|
+
readonly right: AnyColumnBuilder;
|
|
50
|
+
}
|
|
51
|
+
type Expr = ColumnRef | ParamRef;
|
|
52
|
+
/**
|
|
53
|
+
* Helper type to extract codec output type from CodecTypes.
|
|
54
|
+
* Returns never if the codecId is not found in CodecTypes.
|
|
55
|
+
*/
|
|
56
|
+
type ExtractCodecOutputType<CodecId extends string, CodecTypes extends Record<string, {
|
|
57
|
+
readonly output: unknown;
|
|
58
|
+
}>> = CodecId extends keyof CodecTypes ? CodecTypes[CodecId] extends {
|
|
59
|
+
readonly output: infer Output;
|
|
60
|
+
} ? Output : never : never;
|
|
61
|
+
/**
|
|
62
|
+
* Type-level operation signature.
|
|
63
|
+
* Represents an operation at the type level, similar to OperationSignature at runtime.
|
|
64
|
+
*/
|
|
65
|
+
type OperationTypeSignature = {
|
|
66
|
+
readonly args: ReadonlyArray<ArgSpec>;
|
|
67
|
+
readonly returns: ReturnSpec;
|
|
68
|
+
readonly lowering: SqlLoweringSpec;
|
|
69
|
+
readonly capabilities?: ReadonlyArray<string>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Type-level operation registry.
|
|
73
|
+
* Maps typeId → operations, where operations is a record of method name → operation signature.
|
|
74
|
+
*
|
|
75
|
+
* Example:
|
|
76
|
+
* ```typescript
|
|
77
|
+
* type MyOperations: OperationTypes = {
|
|
78
|
+
* 'pgvector/vector@1': {
|
|
79
|
+
* cosineDistance: {
|
|
80
|
+
* args: [{ kind: 'typeId'; type: 'pgvector/vector@1' }];
|
|
81
|
+
* returns: { kind: 'builtin'; type: 'number' };
|
|
82
|
+
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
83
|
+
* };
|
|
84
|
+
* };
|
|
85
|
+
* };
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;
|
|
89
|
+
/**
|
|
90
|
+
* CodecTypes represents a map of typeId to codec definitions.
|
|
91
|
+
* Each codec definition must have an `output` property indicating the JavaScript type.
|
|
92
|
+
*
|
|
93
|
+
* Example:
|
|
94
|
+
* ```typescript
|
|
95
|
+
* type MyCodecTypes: CodecTypes = {
|
|
96
|
+
* 'pg/int4@1': { output: number };
|
|
97
|
+
* 'pg/text@1': { output: string };
|
|
98
|
+
* };
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
type CodecTypes = Record<string, {
|
|
102
|
+
readonly output: unknown;
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Extracts operations for a given typeId from the operation registry.
|
|
106
|
+
* Returns an empty record if the typeId is not found.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* type Ops = OperationsForTypeId<'pgvector/vector@1', MyOperations>;
|
|
111
|
+
* // Ops = { cosineDistance: { ... }, l2Distance: { ... } }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
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>;
|
|
115
|
+
/**
|
|
116
|
+
* Maps operation signatures to method signatures on ColumnBuilder.
|
|
117
|
+
* Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder
|
|
118
|
+
* based on the return type.
|
|
119
|
+
*/
|
|
120
|
+
type OperationMethods<Ops extends Record<string, OperationTypeSignature>, ColumnName extends string, ColumnMeta extends StorageColumn, JsType> = {
|
|
121
|
+
[K in keyof Ops]: Ops[K] extends OperationTypeSignature ? (...args: OperationArgs<Ops[K]['args']>) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType> : never;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Maps operation argument specs to TypeScript argument types.
|
|
125
|
+
* - typeId args: ColumnBuilder (accepts base columns or operation results)
|
|
126
|
+
* - param args: ParamPlaceholder
|
|
127
|
+
* - literal args: unknown (could be more specific in future)
|
|
128
|
+
*/
|
|
129
|
+
type OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [
|
|
130
|
+
infer First,
|
|
131
|
+
...infer Rest
|
|
132
|
+
] ? First extends ArgSpec ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])] : [] : [];
|
|
133
|
+
type ArgToType<Arg extends ArgSpec> = Arg extends {
|
|
134
|
+
kind: 'typeId';
|
|
135
|
+
} ? AnyColumnBuilder : Arg extends {
|
|
136
|
+
kind: 'param';
|
|
137
|
+
} ? ParamPlaceholder : Arg extends {
|
|
138
|
+
kind: 'literal';
|
|
139
|
+
} ? unknown : never;
|
|
140
|
+
/**
|
|
141
|
+
* Maps operation return spec to return type.
|
|
142
|
+
* - builtin types: ColumnBuilder with appropriate JsType (matches runtime behavior)
|
|
143
|
+
* - typeId types: ColumnBuilder (for now, could be more specific in future)
|
|
144
|
+
*/
|
|
145
|
+
type OperationReturn<Returns extends ReturnSpec, ColumnName extends string, ColumnMeta extends StorageColumn, _JsType> = Returns extends {
|
|
146
|
+
kind: 'builtin';
|
|
147
|
+
type: infer T;
|
|
148
|
+
} ? T extends 'number' ? ColumnBuilder<ColumnName, ColumnMeta, number> : T extends 'boolean' ? ColumnBuilder<ColumnName, ColumnMeta, boolean> : T extends 'string' ? ColumnBuilder<ColumnName, ColumnMeta, string> : ColumnBuilder<ColumnName, ColumnMeta, unknown> : Returns extends {
|
|
149
|
+
kind: 'typeId';
|
|
150
|
+
} ? AnyColumnBuilder : ColumnBuilder<ColumnName, ColumnMeta, unknown>;
|
|
151
|
+
/**
|
|
152
|
+
* Computes JavaScript type for a column at column creation time.
|
|
153
|
+
*
|
|
154
|
+
* Type inference:
|
|
155
|
+
* - Read columnMeta.type as typeId string literal
|
|
156
|
+
* - Look up CodecTypes[typeId].output
|
|
157
|
+
* - Apply nullability: nullable ? Output | null : Output
|
|
158
|
+
*/
|
|
159
|
+
type ComputeColumnJsType<_Contract extends SqlContract<SqlStorage>, _TableName extends string, _ColumnName extends string, ColumnMeta extends StorageColumn, CodecTypes extends Record<string, {
|
|
160
|
+
readonly output: unknown;
|
|
161
|
+
}>> = ColumnMeta extends {
|
|
162
|
+
type: infer T;
|
|
163
|
+
nullable: infer N;
|
|
164
|
+
} ? T extends string ? ExtractCodecOutputType<T, CodecTypes> extends infer CodecOutput ? [CodecOutput] extends [never] ? unknown : N extends true ? CodecOutput | null : CodecOutput : unknown : unknown : unknown;
|
|
165
|
+
/**
|
|
166
|
+
* Infers Row type from a projection object.
|
|
167
|
+
* Maps Record<string, ColumnBuilder> to Record<string, JSType>
|
|
168
|
+
*
|
|
169
|
+
* Extracts the pre-computed JsType from each ColumnBuilder in the projection.
|
|
170
|
+
*/
|
|
171
|
+
/**
|
|
172
|
+
* Extracts the inferred JsType carried by a ColumnBuilder.
|
|
173
|
+
*/
|
|
174
|
+
type ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> = CB extends ColumnBuilder<infer _ColumnName extends string, infer _ColumnMeta extends StorageColumn, infer JsType, infer _Ops> ? JsType : never;
|
|
175
|
+
type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {
|
|
176
|
+
[K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Nested projection type - allows recursive nesting of ColumnBuilder or nested objects.
|
|
180
|
+
*/
|
|
181
|
+
type NestedProjection = Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder>>>>>;
|
|
182
|
+
/**
|
|
183
|
+
* Helper type to extract include type from Includes map.
|
|
184
|
+
* Returns the value type if K is a key of Includes, otherwise returns unknown.
|
|
185
|
+
*/
|
|
186
|
+
type ExtractIncludeType<K extends string, Includes extends Record<string, unknown>> = K extends keyof Includes ? Includes[K] : unknown;
|
|
187
|
+
/**
|
|
188
|
+
* Infers Row type from a nested projection object.
|
|
189
|
+
* Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.
|
|
190
|
+
*
|
|
191
|
+
* Extracts the pre-computed JsType from each ColumnBuilder at leaves.
|
|
192
|
+
* When a value is `true`, it represents an include reference and infers `Array<ChildShape>`
|
|
193
|
+
* by looking up the include alias in the Includes type map.
|
|
194
|
+
*/
|
|
195
|
+
type InferNestedProjectionRow<P extends Record<string, AnyColumnBuilder | boolean | NestedProjection>, CodecTypes extends Record<string, {
|
|
196
|
+
readonly output: unknown;
|
|
197
|
+
}> = Record<string, never>, Includes extends Record<string, unknown> = Record<string, never>> = {
|
|
198
|
+
[K in keyof P]: P[K] extends AnyColumnBuilder ? ExtractJsTypeFromColumnBuilder<P[K]> : P[K] extends true ? Array<ExtractIncludeType<K & string, Includes>> : P[K] extends NestedProjection ? InferNestedProjectionRow<P[K], CodecTypes, Includes> : never;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Infers Row type from a tuple of ColumnBuilders used in returning() clause.
|
|
202
|
+
* Extracts column name and JsType from each ColumnBuilder and creates a Record.
|
|
203
|
+
*/
|
|
204
|
+
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[] ? {
|
|
205
|
+
[K in Name]: JsType;
|
|
206
|
+
} & InferReturningRow<Rest> : {
|
|
207
|
+
[K in Name]: JsType;
|
|
208
|
+
} : never : never : Record<string, never>;
|
|
209
|
+
/**
|
|
210
|
+
* Utility type to check if a contract has the required capabilities for includeMany.
|
|
211
|
+
* Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.
|
|
212
|
+
* Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`
|
|
213
|
+
*/
|
|
214
|
+
type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> = TContract extends {
|
|
215
|
+
capabilities: infer C;
|
|
216
|
+
target: infer T;
|
|
217
|
+
} ? T extends string ? C extends Record<string, Record<string, boolean>> ? C extends {
|
|
218
|
+
[K in T]: infer TargetCaps;
|
|
219
|
+
} ? TargetCaps extends {
|
|
220
|
+
lateral: true;
|
|
221
|
+
jsonAgg: true;
|
|
222
|
+
} ? true : false : false : false : false : false;
|
|
223
|
+
/**
|
|
224
|
+
* SQL-specific Plan type that refines the ast field to use QueryAst.
|
|
225
|
+
* This is the type used by SQL query builders.
|
|
226
|
+
*/
|
|
227
|
+
type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;
|
|
228
|
+
/**
|
|
229
|
+
* Helper types for extracting contract structure.
|
|
230
|
+
*/
|
|
231
|
+
type TablesOf<TContract> = TContract extends {
|
|
232
|
+
storage: {
|
|
233
|
+
tables: infer U;
|
|
234
|
+
};
|
|
235
|
+
} ? U : never;
|
|
236
|
+
type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;
|
|
237
|
+
/**
|
|
238
|
+
* Unique symbol for metadata property to avoid collisions with user-defined properties
|
|
239
|
+
*/
|
|
240
|
+
declare const META: unique symbol;
|
|
241
|
+
/**
|
|
242
|
+
* Extracts metadata from a type that has a META property
|
|
243
|
+
*/
|
|
244
|
+
type Meta<T extends {
|
|
245
|
+
[META]: unknown;
|
|
246
|
+
}> = T[typeof META];
|
|
247
|
+
/**
|
|
248
|
+
* Metadata interface for table definitions
|
|
249
|
+
*/
|
|
250
|
+
interface TableMetadata<Name extends string> {
|
|
251
|
+
name: Name;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Metadata interface for model definitions
|
|
255
|
+
*/
|
|
256
|
+
interface ModelMetadata<Name extends string> {
|
|
257
|
+
name: Name;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Base interface for table definitions with metadata
|
|
261
|
+
* Used in contract.d.ts to define storage-level table types
|
|
262
|
+
*/
|
|
263
|
+
interface TableDef<Name extends string> {
|
|
264
|
+
readonly [META]: TableMetadata<Name>;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Base interface for model definitions with metadata
|
|
268
|
+
* Used in contract.d.ts to define application-level model types
|
|
269
|
+
*/
|
|
270
|
+
interface ModelDef<Name extends string> {
|
|
271
|
+
readonly [META]: ModelMetadata<Name>;
|
|
272
|
+
}
|
|
273
|
+
type ColumnsOf<TContract, K extends TableKey<TContract>> = K extends keyof TablesOf<TContract> ? TablesOf<TContract>[K] extends {
|
|
274
|
+
columns: infer C;
|
|
275
|
+
} ? C : never : never;
|
|
276
|
+
interface RawTemplateOptions {
|
|
277
|
+
readonly refs?: PlanRefs;
|
|
278
|
+
readonly annotations?: Record<string, unknown>;
|
|
279
|
+
readonly projection?: ReadonlyArray<string>;
|
|
280
|
+
}
|
|
281
|
+
interface RawFunctionOptions extends RawTemplateOptions {
|
|
282
|
+
readonly params: ReadonlyArray<unknown>;
|
|
283
|
+
}
|
|
284
|
+
type RawTemplateFactory = (strings: TemplateStringsArray, ...values: readonly unknown[]) => ExecutionPlan;
|
|
285
|
+
interface RawFactory extends RawTemplateFactory {
|
|
286
|
+
(text: string, options: RawFunctionOptions): ExecutionPlan;
|
|
287
|
+
with(options: RawTemplateOptions): RawTemplateFactory;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface BuildParamsMap {
|
|
291
|
+
readonly [name: string]: unknown;
|
|
292
|
+
}
|
|
293
|
+
interface BuildOptions {
|
|
294
|
+
readonly params?: BuildParamsMap;
|
|
295
|
+
}
|
|
296
|
+
interface SqlBuilderOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
|
|
297
|
+
readonly context: QueryLaneContext<TContract>;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* SQL-specific ResultType that works with both Plan and SqlQueryPlan.
|
|
301
|
+
* This extends the core ResultType to also handle SqlQueryPlan.
|
|
302
|
+
* Example: `type Row = ResultType<typeof plan>`
|
|
303
|
+
*/
|
|
304
|
+
type ResultType<P> = P extends SqlQueryPlan<infer R> ? R : ResultType$1<P>;
|
|
305
|
+
|
|
306
|
+
export { type AnyBinaryBuilder, type AnyColumnBuilder, type AnyOrderBuilder, type BinaryBuilder, type BuildOptions, type BuildParamsMap, type CodecTypes, type ColumnBuilder, type ColumnsOf, type ComputeColumnJsType, type Expr, type HasIncludeManyCapabilities, type InferNestedProjectionRow, type InferProjectionRow, type InferReturningRow, type JoinOnBuilder, type JoinOnPredicate, META, type Meta, type ModelDef, type ModelMetadata, type NestedProjection, type OperationTypeSignature, type OperationTypes, type OperationsForTypeId, type OrderBuilder, type ParamPlaceholder, type RawFactory, type RawFunctionOptions, type RawTemplateFactory, type RawTemplateOptions, type ResultType, type SqlBuilderOptions, type SqlPlan, type TableDef, type TableKey, type TableMetadata, type TablesOf, isColumnBuilder };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Adapter, AdapterProfile, AdapterTarget, CreateDeleteAstOptions, CreateInsertAstOptions, CreateSelectAstOptions, CreateUpdateAstOptions, LoweredPayload, Lowerer, LowererContext, SqlDriver, SqlExecuteRequest, SqlExplainResult, SqlQueryResult, compact, createBinaryExpr, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createOperationExpr, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst } from './exports/ast.js';
|
|
2
|
+
export { a as Codec, h as CodecDefBuilder, d as CodecId, e as CodecInput, C as CodecMeta, f as CodecOutput, b as CodecRegistry, E as ExtractCodecTypes, g as ExtractDataTypes, Q as QueryLaneContext, c as codec, i as createCodecRegistry, j as defineCodecs } from './query-lane-context-BhOMmb_K.js';
|
|
3
|
+
export { B as BinaryExpr, C as ColumnRef, d as DeleteAst, D as Direction, E as ExistsExpr, b as IncludeAst, I as IncludeRef, c as InsertAst, a as JoinAst, J as JoinOnExpr, L as LiteralExpr, e as LoweredStatement, O as OperationExpr, P as ParamRef, Q as QueryAst, S as SelectAst, f as SqlQueryPlan, T as TableRef, U as UpdateAst, i as isOperationExpr } from './plan-D6dOf1wQ.js';
|
|
4
|
+
export { RuntimeError, planInvalid, planUnsupported } from '@prisma-next/plan';
|
|
5
|
+
export { attachOperationsToColumnBuilder } from './exports/operations-registry.js';
|
|
6
|
+
export { Parameter, param } from './exports/param.js';
|
|
7
|
+
export { Column, Column as ColumnBuilderImpl, SchemaHandle, Table, Table as TableBuilderImpl, schema } from './exports/schema.js';
|
|
8
|
+
export { AnyBinaryBuilder, AnyColumnBuilder, AnyOrderBuilder, BinaryBuilder, BuildOptions, BuildParamsMap, CodecTypes, ColumnBuilder, ColumnsOf, ComputeColumnJsType, Expr, HasIncludeManyCapabilities, InferNestedProjectionRow, InferProjectionRow, InferReturningRow, JoinOnBuilder, JoinOnPredicate, META, Meta, ModelDef, ModelMetadata, NestedProjection, OperationTypeSignature, OperationTypes, OperationsForTypeId, OrderBuilder, ParamPlaceholder, RawFactory, RawFunctionOptions, RawTemplateFactory, RawTemplateOptions, ResultType, SqlBuilderOptions, SqlPlan, TableDef, TableKey, TableMetadata, TablesOf, isColumnBuilder } from './exports/types.js';
|
|
9
|
+
import '@prisma-next/operations';
|
|
10
|
+
import '@prisma-next/sql-contract/types';
|
|
11
|
+
import 'ts-toolbelt';
|
|
12
|
+
import '@prisma-next/contract/types';
|
|
13
|
+
import '@prisma-next/sql-operations';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import "./chunk-U7AXAUJA.js";
|
|
2
|
+
import {
|
|
3
|
+
ColumnBuilderImpl,
|
|
4
|
+
TableBuilderImpl,
|
|
5
|
+
schema
|
|
6
|
+
} from "./chunk-7FMQVMSM.js";
|
|
7
|
+
import {
|
|
8
|
+
param
|
|
9
|
+
} from "./chunk-7I3EMQID.js";
|
|
10
|
+
import "./chunk-G52ENULI.js";
|
|
11
|
+
import {
|
|
12
|
+
attachOperationsToColumnBuilder
|
|
13
|
+
} from "./chunk-FMVAOBWJ.js";
|
|
14
|
+
import {
|
|
15
|
+
planInvalid,
|
|
16
|
+
planUnsupported
|
|
17
|
+
} from "./chunk-2F7DSEOU.js";
|
|
18
|
+
import {
|
|
19
|
+
codec,
|
|
20
|
+
compact,
|
|
21
|
+
createBinaryExpr,
|
|
22
|
+
createCodecRegistry,
|
|
23
|
+
createColumnRef,
|
|
24
|
+
createDeleteAst,
|
|
25
|
+
createExistsExpr,
|
|
26
|
+
createInsertAst,
|
|
27
|
+
createJoin,
|
|
28
|
+
createJoinOnBuilder,
|
|
29
|
+
createJoinOnExpr,
|
|
30
|
+
createLiteralExpr,
|
|
31
|
+
createOperationExpr,
|
|
32
|
+
createOrderByItem,
|
|
33
|
+
createParamRef,
|
|
34
|
+
createSelectAst,
|
|
35
|
+
createTableRef,
|
|
36
|
+
createUpdateAst,
|
|
37
|
+
defineCodecs,
|
|
38
|
+
isOperationExpr
|
|
39
|
+
} from "./chunk-ENOLRQZS.js";
|
|
40
|
+
import {
|
|
41
|
+
isColumnBuilder
|
|
42
|
+
} from "./chunk-ILC64YWE.js";
|
|
43
|
+
import "./chunk-UVFWELV2.js";
|
|
44
|
+
export {
|
|
45
|
+
ColumnBuilderImpl,
|
|
46
|
+
TableBuilderImpl,
|
|
47
|
+
attachOperationsToColumnBuilder,
|
|
48
|
+
codec,
|
|
49
|
+
compact,
|
|
50
|
+
createBinaryExpr,
|
|
51
|
+
createCodecRegistry,
|
|
52
|
+
createColumnRef,
|
|
53
|
+
createDeleteAst,
|
|
54
|
+
createExistsExpr,
|
|
55
|
+
createInsertAst,
|
|
56
|
+
createJoin,
|
|
57
|
+
createJoinOnBuilder,
|
|
58
|
+
createJoinOnExpr,
|
|
59
|
+
createLiteralExpr,
|
|
60
|
+
createOperationExpr,
|
|
61
|
+
createOrderByItem,
|
|
62
|
+
createParamRef,
|
|
63
|
+
createSelectAst,
|
|
64
|
+
createTableRef,
|
|
65
|
+
createUpdateAst,
|
|
66
|
+
defineCodecs,
|
|
67
|
+
isColumnBuilder,
|
|
68
|
+
isOperationExpr,
|
|
69
|
+
param,
|
|
70
|
+
planInvalid,
|
|
71
|
+
planUnsupported,
|
|
72
|
+
schema
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import { ReturnSpec } from '@prisma-next/operations';
|
|
3
|
+
import { SqlLoweringSpec } from '@prisma-next/sql-operations';
|
|
4
|
+
|
|
5
|
+
type Direction = 'asc' | 'desc';
|
|
6
|
+
interface TableRef {
|
|
7
|
+
readonly kind: 'table';
|
|
8
|
+
readonly name: string;
|
|
9
|
+
}
|
|
10
|
+
interface ColumnRef {
|
|
11
|
+
readonly kind: 'col';
|
|
12
|
+
readonly table: string;
|
|
13
|
+
readonly column: string;
|
|
14
|
+
}
|
|
15
|
+
interface ParamRef {
|
|
16
|
+
readonly kind: 'param';
|
|
17
|
+
readonly index: number;
|
|
18
|
+
readonly name?: string;
|
|
19
|
+
}
|
|
20
|
+
interface LiteralExpr {
|
|
21
|
+
readonly kind: 'literal';
|
|
22
|
+
readonly value: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface OperationExpr {
|
|
25
|
+
readonly kind: 'operation';
|
|
26
|
+
readonly method: string;
|
|
27
|
+
readonly forTypeId: string;
|
|
28
|
+
readonly self: ColumnRef | OperationExpr;
|
|
29
|
+
readonly args: ReadonlyArray<ColumnRef | ParamRef | LiteralExpr | OperationExpr>;
|
|
30
|
+
readonly returns: ReturnSpec;
|
|
31
|
+
readonly lowering: SqlLoweringSpec;
|
|
32
|
+
}
|
|
33
|
+
declare function isOperationExpr(expr: ColumnRef | OperationExpr): expr is OperationExpr;
|
|
34
|
+
interface BinaryExpr {
|
|
35
|
+
readonly kind: 'bin';
|
|
36
|
+
readonly op: 'eq';
|
|
37
|
+
readonly left: ColumnRef | OperationExpr;
|
|
38
|
+
readonly right: ParamRef;
|
|
39
|
+
}
|
|
40
|
+
interface ExistsExpr {
|
|
41
|
+
readonly kind: 'exists';
|
|
42
|
+
readonly not: boolean;
|
|
43
|
+
readonly subquery: SelectAst;
|
|
44
|
+
}
|
|
45
|
+
type JoinOnExpr = {
|
|
46
|
+
readonly kind: 'eqCol';
|
|
47
|
+
readonly left: ColumnRef;
|
|
48
|
+
readonly right: ColumnRef;
|
|
49
|
+
};
|
|
50
|
+
interface JoinAst {
|
|
51
|
+
readonly kind: 'join';
|
|
52
|
+
readonly joinType: 'inner' | 'left' | 'right' | 'full';
|
|
53
|
+
readonly table: TableRef;
|
|
54
|
+
readonly on: JoinOnExpr;
|
|
55
|
+
}
|
|
56
|
+
interface IncludeRef {
|
|
57
|
+
readonly kind: 'includeRef';
|
|
58
|
+
readonly alias: string;
|
|
59
|
+
}
|
|
60
|
+
interface IncludeAst {
|
|
61
|
+
readonly kind: 'includeMany';
|
|
62
|
+
readonly alias: string;
|
|
63
|
+
readonly child: {
|
|
64
|
+
readonly table: TableRef;
|
|
65
|
+
readonly on: JoinOnExpr;
|
|
66
|
+
readonly where?: BinaryExpr | ExistsExpr;
|
|
67
|
+
readonly orderBy?: ReadonlyArray<{
|
|
68
|
+
expr: ColumnRef | OperationExpr;
|
|
69
|
+
dir: Direction;
|
|
70
|
+
}>;
|
|
71
|
+
readonly limit?: number;
|
|
72
|
+
readonly project: ReadonlyArray<{
|
|
73
|
+
alias: string;
|
|
74
|
+
expr: ColumnRef | OperationExpr;
|
|
75
|
+
}>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface SelectAst {
|
|
79
|
+
readonly kind: 'select';
|
|
80
|
+
readonly from: TableRef;
|
|
81
|
+
readonly joins?: ReadonlyArray<JoinAst>;
|
|
82
|
+
readonly includes?: ReadonlyArray<IncludeAst>;
|
|
83
|
+
readonly project: ReadonlyArray<{
|
|
84
|
+
alias: string;
|
|
85
|
+
expr: ColumnRef | IncludeRef | OperationExpr | LiteralExpr;
|
|
86
|
+
}>;
|
|
87
|
+
readonly where?: BinaryExpr | ExistsExpr;
|
|
88
|
+
readonly orderBy?: ReadonlyArray<{
|
|
89
|
+
expr: ColumnRef | OperationExpr;
|
|
90
|
+
dir: Direction;
|
|
91
|
+
}>;
|
|
92
|
+
readonly limit?: number;
|
|
93
|
+
}
|
|
94
|
+
interface InsertAst {
|
|
95
|
+
readonly kind: 'insert';
|
|
96
|
+
readonly table: TableRef;
|
|
97
|
+
readonly values: Record<string, ColumnRef | ParamRef>;
|
|
98
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
99
|
+
}
|
|
100
|
+
interface UpdateAst {
|
|
101
|
+
readonly kind: 'update';
|
|
102
|
+
readonly table: TableRef;
|
|
103
|
+
readonly set: Record<string, ColumnRef | ParamRef>;
|
|
104
|
+
readonly where: BinaryExpr;
|
|
105
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
106
|
+
}
|
|
107
|
+
interface DeleteAst {
|
|
108
|
+
readonly kind: 'delete';
|
|
109
|
+
readonly table: TableRef;
|
|
110
|
+
readonly where: BinaryExpr;
|
|
111
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
112
|
+
}
|
|
113
|
+
type QueryAst = SelectAst | InsertAst | UpdateAst | DeleteAst;
|
|
114
|
+
interface LoweredStatement {
|
|
115
|
+
readonly sql: string;
|
|
116
|
+
readonly params: readonly unknown[];
|
|
117
|
+
readonly annotations?: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* SQL query plan produced by lanes before lowering.
|
|
122
|
+
*
|
|
123
|
+
* Lanes build ASTs and metadata but do not perform SQL lowering.
|
|
124
|
+
* The `sql` field is absent - lowering happens in the runtime executor.
|
|
125
|
+
*
|
|
126
|
+
* Structurally aligns with ExecutionPlan<Row, QueryAst> (without sql field) to maintain
|
|
127
|
+
* compatibility with ExecutionPlan/Plan-based utilities.
|
|
128
|
+
* The generic parameter `_Row` is preserved for type extraction via ResultType.
|
|
129
|
+
*/
|
|
130
|
+
interface SqlQueryPlan<_Row = unknown> extends Pick<ExecutionPlan<_Row, QueryAst>, 'params' | 'meta'> {
|
|
131
|
+
readonly ast: QueryAst;
|
|
132
|
+
readonly _Row?: _Row;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { type BinaryExpr as B, type ColumnRef as C, type Direction as D, type ExistsExpr as E, type IncludeRef as I, type JoinOnExpr as J, type LiteralExpr as L, type OperationExpr as O, type ParamRef as P, type QueryAst as Q, type SelectAst as S, type TableRef as T, type UpdateAst as U, type JoinAst as a, type IncludeAst as b, type InsertAst as c, type DeleteAst as d, type LoweredStatement as e, type SqlQueryPlan as f, isOperationExpr as i };
|