@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 @@
|
|
|
1
|
+
{"version":3,"file":"plan.mjs","names":[],"sources":["../../src/plan.ts"],"sourcesContent":["import type { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';\nimport type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { QueryAst } from './ast/types';\n\n/**\n * SQL query plan produced by lanes before lowering.\n *\n * Lanes build ASTs and metadata but do not perform SQL lowering.\n * The `sql` field is absent - lowering happens in the runtime executor.\n *\n * Structurally aligns with ExecutionPlan<Row, QueryAst> (without sql field) to maintain\n * compatibility with ExecutionPlan/Plan-based utilities.\n * The generic parameter `_Row` is preserved for type extraction via ResultType.\n */\nexport interface SqlQueryPlan<_Row = unknown>\n extends Pick<ExecutionPlan<_Row, QueryAst>, 'params' | 'meta'> {\n readonly ast: QueryAst;\n // Phantom property to preserve generic parameter for type extraction\n // This allows ResultType to extract _Row for SqlQueryPlan values.\n readonly _Row?: _Row;\n}\n\n/**\n * Augments the last ParamDescriptor in the array with codecId and nativeType from columnMeta.\n * This is used when building WHERE expressions to ensure param descriptors have type information.\n */\nexport function augmentDescriptorWithColumnMeta(\n descriptors: ParamDescriptor[],\n columnMeta: StorageColumn | undefined,\n): void {\n const descriptor = descriptors[descriptors.length - 1];\n if (descriptor && columnMeta) {\n descriptors[descriptors.length - 1] = {\n ...descriptor,\n codecId: columnMeta.codecId,\n nativeType: columnMeta.nativeType,\n };\n }\n}\n"],"mappings":";;;;;AA0BA,SAAgB,gCACd,aACA,YACM;CACN,MAAM,aAAa,YAAY,YAAY,SAAS;AACpD,KAAI,cAAc,WAChB,aAAY,YAAY,SAAS,KAAK;EACpC,GAAG;EACH,SAAS,WAAW;EACpB,YAAY,WAAW;EACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "../query-lane-context-wr_XXnB5.mjs";
|
|
2
|
+
import "../plan-9PvH-Tu3.mjs";
|
|
3
|
+
import "../types-Bg2kUmUA.mjs";
|
|
4
|
+
import { i as schema, n as SchemaHandle, r as TableBuilderImpl, t as ColumnBuilderImpl } from "../schema-Dse48uyP.mjs";
|
|
5
|
+
export { ColumnBuilderImpl as Column, ColumnBuilderImpl, SchemaHandle, TableBuilderImpl as Table, TableBuilderImpl, schema };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import "../query-lane-context-wr_XXnB5.mjs";
|
|
2
|
+
import "../plan-9PvH-Tu3.mjs";
|
|
3
|
+
import { A as ParamPlaceholder, B as TableKey, C as ModelDef, D as OperationTypes, E as OperationTypeSignature, F as ResultType, G as isColumnBuilder, H as TablesOf, I as RuntimeError, L as SqlBuilderOptions, M as RawFunctionOptions, N as RawTemplateFactory, O as OperationsForTypeId, P as RawTemplateOptions, R as SqlPlan, S as Meta, T as NestedProjection, U as ValueSource, V as TableMetadata, W as createOrderBuilder, _ as InferProjectionRow, a as AnyOrderBuilder, b as JoinOnPredicate, c as BuildParamsMap, d as ColumnsOf, f as ComputeColumnJsType, g as InferNestedProjectionRow, h as HasIncludeManyCapabilities, i as AnyExpressionSource, j as RawFactory, k as OrderBuilder, l as CodecTypes, m as ExpressionBuilder, n as AnyColumnBuilder, o as BinaryBuilder, p as Expr, r as AnyColumnBuilderBase, s as BuildOptions, t as AnyBinaryBuilder, u as ColumnBuilder, v as InferReturningRow, w as ModelMetadata, x as META, y as JoinOnBuilder, z as TableDef } from "../types-Bg2kUmUA.mjs";
|
|
4
|
+
export { AnyBinaryBuilder, AnyColumnBuilder, AnyColumnBuilderBase, AnyExpressionSource, AnyOrderBuilder, BinaryBuilder, BuildOptions, BuildParamsMap, CodecTypes, ColumnBuilder, ColumnsOf, ComputeColumnJsType, Expr, ExpressionBuilder, HasIncludeManyCapabilities, InferNestedProjectionRow, InferProjectionRow, InferReturningRow, JoinOnBuilder, JoinOnPredicate, META, Meta, ModelDef, ModelMetadata, NestedProjection, OperationTypeSignature, OperationTypes, OperationsForTypeId, OrderBuilder, ParamPlaceholder, RawFactory, RawFunctionOptions, RawTemplateFactory, RawTemplateOptions, ResultType, RuntimeError, SqlBuilderOptions, SqlPlan, TableDef, TableKey, TableMetadata, TablesOf, ValueSource, createOrderBuilder, isColumnBuilder };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//#region src/utils/guards.ts
|
|
2
|
+
/**
|
|
3
|
+
* Helper to extract columnMeta from a ColumnBuilder or ExpressionBuilder.
|
|
4
|
+
* Returns StorageColumn if present, undefined otherwise.
|
|
5
|
+
* Both ColumnBuilder and ExpressionBuilder have columnMeta property.
|
|
6
|
+
*/
|
|
7
|
+
function getColumnMeta(expr) {
|
|
8
|
+
if ("columnMeta" in expr) return expr.columnMeta;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Type predicate to check if a value is a ParamPlaceholder.
|
|
12
|
+
*/
|
|
13
|
+
function isParamPlaceholder(value) {
|
|
14
|
+
return typeof value === "object" && value !== null && "kind" in value && value.kind === "param-placeholder" && "name" in value && typeof value.name === "string";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Recursively extracts the base ColumnRef from an OperationExpr.
|
|
18
|
+
* If the expression is already a ColumnRef, it is returned directly.
|
|
19
|
+
*/
|
|
20
|
+
function extractBaseColumnRef(expr) {
|
|
21
|
+
if (expr.kind === "col") return expr;
|
|
22
|
+
return extractBaseColumnRef(expr.self);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Recursively collects all ColumnRef nodes from an expression tree.
|
|
26
|
+
* Handles nested OperationExpr structures by traversing both self and args.
|
|
27
|
+
*/
|
|
28
|
+
function collectColumnRefs(expr) {
|
|
29
|
+
if (expr.kind === "col") return [expr];
|
|
30
|
+
if (expr.kind === "operation") {
|
|
31
|
+
const refs = collectColumnRefs(expr.self);
|
|
32
|
+
for (const arg of expr.args) refs.push(...collectColumnRefs(arg));
|
|
33
|
+
return refs;
|
|
34
|
+
}
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Type predicate to check if an expression is an OperationExpr.
|
|
39
|
+
*/
|
|
40
|
+
function isOperationExpr(expr) {
|
|
41
|
+
return typeof expr === "object" && expr !== null && "kind" in expr && expr.kind === "operation";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Helper to extract table and column from a ColumnBuilder, ExpressionBuilder, or OperationExpr.
|
|
45
|
+
* For ExpressionBuilder or OperationExpr, recursively unwraps to find the base ColumnRef.
|
|
46
|
+
*/
|
|
47
|
+
function getColumnInfo(expr) {
|
|
48
|
+
if (isOperationExpr(expr)) {
|
|
49
|
+
const baseCol = extractBaseColumnRef(expr);
|
|
50
|
+
return {
|
|
51
|
+
table: baseCol.table,
|
|
52
|
+
column: baseCol.column
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (isExpressionBuilder(expr)) {
|
|
56
|
+
const baseCol = extractBaseColumnRef(expr.expr);
|
|
57
|
+
return {
|
|
58
|
+
table: baseCol.table,
|
|
59
|
+
column: baseCol.column
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const colBuilder = expr;
|
|
63
|
+
return {
|
|
64
|
+
table: colBuilder.table,
|
|
65
|
+
column: colBuilder.column
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Type predicate to check if a value is a ColumnBuilder.
|
|
70
|
+
*/
|
|
71
|
+
function isColumnBuilder(value) {
|
|
72
|
+
return typeof value === "object" && value !== null && "kind" in value && value.kind === "column";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Type predicate to check if a value is an ExpressionBuilder.
|
|
76
|
+
*/
|
|
77
|
+
function isExpressionBuilder(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && "kind" in value && value.kind === "expression";
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Type predicate to check if a value is an ExpressionSource (has toExpr method).
|
|
82
|
+
*/
|
|
83
|
+
function isExpressionSource(value) {
|
|
84
|
+
return typeof value === "object" && value !== null && "toExpr" in value && typeof value.toExpr === "function";
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts any ExpressionSource to an Expression.
|
|
88
|
+
* This is the canonical way to get an AST Expression from a builder.
|
|
89
|
+
*
|
|
90
|
+
* @param source - A ColumnBuilder or ExpressionBuilder
|
|
91
|
+
* @returns The corresponding Expression (ColumnRef or OperationExpr)
|
|
92
|
+
*/
|
|
93
|
+
function toExpression(source) {
|
|
94
|
+
return source.toExpr();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Converts an AnyExpressionSource to an Expression.
|
|
98
|
+
* Handles both ColumnBuilder and ExpressionBuilder.
|
|
99
|
+
*
|
|
100
|
+
* @param source - A ColumnBuilder or ExpressionBuilder
|
|
101
|
+
* @returns The corresponding Expression (ColumnRef or OperationExpr)
|
|
102
|
+
*/
|
|
103
|
+
function expressionFromSource(source) {
|
|
104
|
+
return source.toExpr();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Type predicate to check if a value is a ValueSource.
|
|
108
|
+
* ValueSource is either a ParamPlaceholder or an ExpressionSource.
|
|
109
|
+
*/
|
|
110
|
+
function isValueSource(value) {
|
|
111
|
+
return isParamPlaceholder(value) || isExpressionSource(value);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Extracts and returns an OperationExpr from a builder.
|
|
115
|
+
* Returns the OperationExpr if the builder is an OperationExpr or has an _operationExpr property,
|
|
116
|
+
* otherwise returns undefined.
|
|
117
|
+
*
|
|
118
|
+
* @deprecated Use isExpressionBuilder() instead. This function exists for backward compatibility
|
|
119
|
+
* with code that uses the hidden _operationExpr property pattern.
|
|
120
|
+
*
|
|
121
|
+
* @design-note: This function accesses the hidden `_operationExpr` property, which is a code smell.
|
|
122
|
+
* The ExpressionBuilder type (introduced in the operation-expr-refactoring) provides a cleaner
|
|
123
|
+
* approach by explicitly representing operation results as a distinct type.
|
|
124
|
+
*/
|
|
125
|
+
function getOperationExpr(builder) {
|
|
126
|
+
if (isOperationExpr(builder)) return builder;
|
|
127
|
+
return builder._operationExpr;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { getColumnMeta as a, isExpressionBuilder as c, isParamPlaceholder as d, isValueSource as f, getColumnInfo as i, isExpressionSource as l, expressionFromSource as n, getOperationExpr as o, toExpression as p, extractBaseColumnRef as r, isColumnBuilder as s, collectColumnRefs as t, isOperationExpr as u };
|
|
132
|
+
//# sourceMappingURL=guards-4T0IByJo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards-4T0IByJo.mjs","names":["refs: ColumnRef[]"],"sources":["../src/utils/guards.ts"],"sourcesContent":["import type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type {\n ColumnRef,\n Expression,\n ExpressionSource,\n LiteralExpr,\n OperationExpr,\n ParamRef,\n} from '../ast/types';\nimport type {\n AnyColumnBuilder,\n AnyExpressionSource,\n ExpressionBuilder,\n ParamPlaceholder,\n ValueSource,\n} from '../types';\n\n/**\n * Helper to extract columnMeta from a ColumnBuilder or ExpressionBuilder.\n * Returns StorageColumn if present, undefined otherwise.\n * Both ColumnBuilder and ExpressionBuilder have columnMeta property.\n */\nexport function getColumnMeta(expr: AnyExpressionSource): StorageColumn | undefined {\n // Both ColumnBuilder and ExpressionBuilder have columnMeta: StorageColumn\n // TypeScript should narrow the type after the 'in' check\n if ('columnMeta' in expr) {\n return expr.columnMeta;\n }\n return undefined;\n}\n\n/**\n * Type predicate to check if a value is a ParamPlaceholder.\n */\nexport function isParamPlaceholder(value: unknown): value is ParamPlaceholder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'param-placeholder' &&\n 'name' in value &&\n typeof (value as { name: unknown }).name === 'string'\n );\n}\n\n/**\n * Recursively extracts the base ColumnRef from an OperationExpr.\n * If the expression is already a ColumnRef, it is returned directly.\n */\nexport function extractBaseColumnRef(expr: ColumnRef | OperationExpr): ColumnRef {\n if (expr.kind === 'col') {\n return expr;\n }\n return extractBaseColumnRef(expr.self);\n}\n\n/**\n * Recursively collects all ColumnRef nodes from an expression tree.\n * Handles nested OperationExpr structures by traversing both self and args.\n */\nexport function collectColumnRefs(\n expr: ColumnRef | ParamRef | LiteralExpr | OperationExpr,\n): ColumnRef[] {\n if (expr.kind === 'col') {\n return [expr];\n }\n if (expr.kind === 'operation') {\n const refs: ColumnRef[] = collectColumnRefs(expr.self);\n for (const arg of expr.args) {\n refs.push(...collectColumnRefs(arg));\n }\n return refs;\n }\n return [];\n}\n\n/**\n * Type predicate to check if an expression is an OperationExpr.\n */\nexport function isOperationExpr(\n expr: AnyExpressionSource | OperationExpr | Expression,\n): expr is OperationExpr {\n return typeof expr === 'object' && expr !== null && 'kind' in expr && expr.kind === 'operation';\n}\n\n/**\n * Helper to extract table and column from a ColumnBuilder, ExpressionBuilder, or OperationExpr.\n * For ExpressionBuilder or OperationExpr, recursively unwraps to find the base ColumnRef.\n */\nexport function getColumnInfo(expr: AnyExpressionSource | OperationExpr): {\n table: string;\n column: string;\n} {\n if (isOperationExpr(expr)) {\n const baseCol = extractBaseColumnRef(expr);\n return { table: baseCol.table, column: baseCol.column };\n }\n if (isExpressionBuilder(expr)) {\n const baseCol = extractBaseColumnRef(expr.expr);\n return { table: baseCol.table, column: baseCol.column };\n }\n // expr is ColumnBuilder - TypeScript can't narrow properly\n const colBuilder = expr as unknown as { table: string; column: string };\n return { table: colBuilder.table, column: colBuilder.column };\n}\n\n/**\n * Type predicate to check if a value is a ColumnBuilder.\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\n/**\n * Type predicate to check if a value is an ExpressionBuilder.\n */\nexport function isExpressionBuilder(value: unknown): value is ExpressionBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'expression'\n );\n}\n\n/**\n * Type predicate to check if a value is an ExpressionSource (has toExpr method).\n */\nexport function isExpressionSource(value: unknown): value is ExpressionSource {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'toExpr' in value &&\n typeof (value as ExpressionSource).toExpr === 'function'\n );\n}\n\n/**\n * Converts any ExpressionSource to an Expression.\n * This is the canonical way to get an AST Expression from a builder.\n *\n * @param source - A ColumnBuilder or ExpressionBuilder\n * @returns The corresponding Expression (ColumnRef or OperationExpr)\n */\nexport function toExpression(source: ExpressionSource): Expression {\n return source.toExpr();\n}\n\n/**\n * Converts an AnyExpressionSource to an Expression.\n * Handles both ColumnBuilder and ExpressionBuilder.\n *\n * @param source - A ColumnBuilder or ExpressionBuilder\n * @returns The corresponding Expression (ColumnRef or OperationExpr)\n */\nexport function expressionFromSource(source: AnyExpressionSource): Expression {\n return source.toExpr();\n}\n\n/**\n * Type predicate to check if a value is a ValueSource.\n * ValueSource is either a ParamPlaceholder or an ExpressionSource.\n */\nexport function isValueSource(value: unknown): value is ValueSource {\n return isParamPlaceholder(value) || isExpressionSource(value);\n}\n\n/**\n * Extracts and returns an OperationExpr from a builder.\n * Returns the OperationExpr if the builder is an OperationExpr or has an _operationExpr property,\n * otherwise returns undefined.\n *\n * @deprecated Use isExpressionBuilder() instead. This function exists for backward compatibility\n * with code that uses the hidden _operationExpr property pattern.\n *\n * @design-note: This function accesses the hidden `_operationExpr` property, which is a code smell.\n * The ExpressionBuilder type (introduced in the operation-expr-refactoring) provides a cleaner\n * approach by explicitly representing operation results as a distinct type.\n */\nexport function getOperationExpr(\n builder: AnyColumnBuilder | OperationExpr,\n): OperationExpr | undefined {\n if (isOperationExpr(builder)) {\n return builder;\n }\n const builderWithExpr = builder as unknown as { _operationExpr?: OperationExpr };\n return builderWithExpr._operationExpr;\n}\n"],"mappings":";;;;;;AAsBA,SAAgB,cAAc,MAAsD;AAGlF,KAAI,gBAAgB,KAClB,QAAO,KAAK;;;;;AAQhB,SAAgB,mBAAmB,OAA2C;AAC5E,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS,uBACtC,UAAU,SACV,OAAQ,MAA4B,SAAS;;;;;;AAQjD,SAAgB,qBAAqB,MAA4C;AAC/E,KAAI,KAAK,SAAS,MAChB,QAAO;AAET,QAAO,qBAAqB,KAAK,KAAK;;;;;;AAOxC,SAAgB,kBACd,MACa;AACb,KAAI,KAAK,SA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;AAC3B,KAAI,gBAAgB,QAAQ,CAC1B,QAAO;AAGT,QADwB,QACD"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as CodecInput, c as CodecRegistry, d as codec, f as createCodecRegistry, i as CodecId, l as ExtractCodecTypes, n as Codec, o as CodecMeta, p as defineCodecs, r as CodecDefBuilder, s as CodecOutput, t as QueryLaneContext, u as ExtractDataTypes } from "./query-lane-context-wr_XXnB5.mjs";
|
|
2
|
+
import { C as UpdateAst, S as TableRef, _ as LoweredStatement, a as ColumnRef, b as QueryAst, c as ExistsExpr, d as IncludeAst, f as IncludeRef, g as LiteralExpr, h as JoinOnExpr, i as BinaryOp, l as Expression, m as JoinAst, n as augmentDescriptorWithColumnMeta, o as DeleteAst, p as InsertAst, r as BinaryExpr, s as Direction, t as SqlQueryPlan, u as ExpressionSource, v as OperationExpr, w as isOperationExpr, x as SelectAst, y as ParamRef } from "./plan-9PvH-Tu3.mjs";
|
|
3
|
+
import { A as ParamPlaceholder, B as TableKey, C as ModelDef, D as OperationTypes, E as OperationTypeSignature, F as ResultType, G as isColumnBuilder, H as TablesOf, I as RuntimeError, L as SqlBuilderOptions, M as RawFunctionOptions, N as RawTemplateFactory, O as OperationsForTypeId, P as RawTemplateOptions, R as SqlPlan, S as Meta, T as NestedProjection, U as ValueSource, V as TableMetadata, W as createOrderBuilder, _ as InferProjectionRow, a as AnyOrderBuilder, b as JoinOnPredicate, c as BuildParamsMap, d as ColumnsOf, f as ComputeColumnJsType, g as InferNestedProjectionRow, h as HasIncludeManyCapabilities, i as AnyExpressionSource, j as RawFactory, k as OrderBuilder, l as CodecTypes, m as ExpressionBuilder, n as AnyColumnBuilder, o as BinaryBuilder, p as Expr, r as AnyColumnBuilderBase, s as BuildOptions, t as AnyBinaryBuilder, u as ColumnBuilder, v as InferReturningRow, w as ModelMetadata, x as META, y as JoinOnBuilder, z as TableDef } from "./types-Bg2kUmUA.mjs";
|
|
4
|
+
import { 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.mjs";
|
|
5
|
+
import { n as planUnsupported, t as planInvalid } from "./errors-CLx1Ylq0.mjs";
|
|
6
|
+
import { t as attachOperationsToColumnBuilder } from "./operations-registry-CIcn4f2P.mjs";
|
|
7
|
+
import { n as param, t as Parameter } from "./param-B4LzVPv2.mjs";
|
|
8
|
+
import "./exports/plan.mjs";
|
|
9
|
+
import "./exports/query-lane-context.mjs";
|
|
10
|
+
import { i as schema, n as SchemaHandle, r as TableBuilderImpl, t as ColumnBuilderImpl } from "./schema-Dse48uyP.mjs";
|
|
11
|
+
import "./exports/types.mjs";
|
|
12
|
+
export { Adapter, AdapterProfile, AdapterTarget, AnyBinaryBuilder, AnyColumnBuilder, AnyColumnBuilderBase, AnyExpressionSource, AnyOrderBuilder, BinaryBuilder, BinaryExpr, BinaryOp, BuildOptions, BuildParamsMap, Codec, CodecDefBuilder, CodecId, CodecInput, CodecMeta, CodecOutput, CodecRegistry, CodecTypes, ColumnBuilderImpl as Column, ColumnBuilderImpl, ColumnBuilder, ColumnRef, ColumnsOf, ComputeColumnJsType, CreateDeleteAstOptions, CreateInsertAstOptions, CreateSelectAstOptions, CreateUpdateAstOptions, DeleteAst, Direction, ExistsExpr, Expr, Expression, ExpressionBuilder, ExpressionSource, ExtractCodecTypes, ExtractDataTypes, HasIncludeManyCapabilities, IncludeAst, IncludeRef, InferNestedProjectionRow, InferProjectionRow, InferReturningRow, InsertAst, JoinAst, JoinOnBuilder, JoinOnExpr, JoinOnPredicate, LiteralExpr, LoweredPayload, LoweredStatement, Lowerer, LowererContext, META, Meta, ModelDef, ModelMetadata, NestedProjection, OperationExpr, OperationTypeSignature, OperationTypes, OperationsForTypeId, OrderBuilder, ParamPlaceholder, ParamRef, Parameter, QueryAst, QueryLaneContext, RawFactory, RawFunctionOptions, RawTemplateFactory, RawTemplateOptions, ResultType, RuntimeError, SchemaHandle, SelectAst, SqlBuilderOptions, SqlDriver, SqlExecuteRequest, SqlExplainResult, SqlPlan, SqlQueryPlan, SqlQueryResult, TableBuilderImpl as Table, TableBuilderImpl, TableDef, TableKey, TableMetadata, TableRef, TablesOf, UpdateAst, ValueSource, attachOperationsToColumnBuilder, augmentDescriptorWithColumnMeta, codec, compact, createBinaryExpr, createCodecRegistry, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createOperationExpr, createOrderBuilder, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst, defineCodecs, isColumnBuilder, isOperationExpr, param, planInvalid, planUnsupported, schema };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as isColumnBuilder, t as createOrderBuilder } from "./types-D_FRJvm0.mjs";
|
|
2
|
+
import { codec, compact, createBinaryExpr, createCodecRegistry, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createOperationExpr, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst, defineCodecs, isOperationExpr } from "./exports/ast.mjs";
|
|
3
|
+
import { n as planUnsupported, t as planInvalid } from "./errors-BwxypN2Q.mjs";
|
|
4
|
+
import { t as attachOperationsToColumnBuilder } from "./operations-registry-7R5KE2-5.mjs";
|
|
5
|
+
import "./exports/operations-registry.mjs";
|
|
6
|
+
import { t as param } from "./param-BFvNAaHR.mjs";
|
|
7
|
+
import { augmentDescriptorWithColumnMeta } from "./exports/plan.mjs";
|
|
8
|
+
import "./exports/query-lane-context.mjs";
|
|
9
|
+
import { n as TableBuilderImpl, r as schema, t as ColumnBuilderImpl } from "./schema-BsY2EXAf.mjs";
|
|
10
|
+
import "./exports/types.mjs";
|
|
11
|
+
|
|
12
|
+
export { ColumnBuilderImpl, TableBuilderImpl, attachOperationsToColumnBuilder, augmentDescriptorWithColumnMeta, codec, compact, createBinaryExpr, createCodecRegistry, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createOperationExpr, createOrderBuilder, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst, defineCodecs, isColumnBuilder, isOperationExpr, param, planInvalid, planUnsupported, schema };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { d as isParamPlaceholder } from "./guards-4T0IByJo.mjs";
|
|
2
|
+
import { planInvalid } from "@prisma-next/plan";
|
|
3
|
+
import { hasAllCapabilities } from "@prisma-next/operations";
|
|
4
|
+
|
|
5
|
+
//#region src/operations-registry.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if a value is an ExpressionSource (has toExpr method).
|
|
8
|
+
*/
|
|
9
|
+
function isExpressionSource(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && "toExpr" in value && typeof value.toExpr === "function";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Executes an operation and returns an ExpressionBuilder.
|
|
14
|
+
* This is the canonical entrypoint for operation invocation, enabling
|
|
15
|
+
* future enhancements like telemetry, caching, or tracing.
|
|
16
|
+
*
|
|
17
|
+
* The returned ExpressionBuilder:
|
|
18
|
+
* - Has `kind: 'expression'` to distinguish it from ColumnBuilder
|
|
19
|
+
* - Contains the operation expression in `expr`
|
|
20
|
+
* - Provides `toExpr()` method to get the Expression
|
|
21
|
+
* - Provides comparison and ordering methods for chaining
|
|
22
|
+
*
|
|
23
|
+
* @param signature - The operation signature from the registry
|
|
24
|
+
* @param selfBuilder - The expression source that the operation is called on
|
|
25
|
+
* @param args - The arguments passed to the operation
|
|
26
|
+
* @param columnMeta - The metadata of the column the operation is called on
|
|
27
|
+
* @returns An ExpressionBuilder containing the operation expression
|
|
28
|
+
*/
|
|
29
|
+
function executeOperation(signature, selfBuilder, args, columnMeta, operationRegistry, contractCapabilities) {
|
|
30
|
+
if (args.length !== signature.args.length) throw planInvalid(`Operation ${signature.method} expects ${signature.args.length} arguments, got ${args.length}`);
|
|
31
|
+
const selfExpr = selfBuilder.toExpr();
|
|
32
|
+
const operationArgs = [];
|
|
33
|
+
for (let i = 0; i < args.length; i++) {
|
|
34
|
+
const arg = args[i];
|
|
35
|
+
const argSpec = signature.args[i];
|
|
36
|
+
if (!argSpec) throw planInvalid(`Missing argument spec for argument ${i}`);
|
|
37
|
+
if (argSpec.kind === "param") {
|
|
38
|
+
if (!isParamPlaceholder(arg)) throw planInvalid(`Argument ${i} must be a parameter placeholder`);
|
|
39
|
+
operationArgs.push({
|
|
40
|
+
kind: "param",
|
|
41
|
+
index: 0,
|
|
42
|
+
name: arg.name
|
|
43
|
+
});
|
|
44
|
+
} else if (argSpec.kind === "typeId") {
|
|
45
|
+
if (!isExpressionSource(arg)) throw planInvalid(`Argument ${i} must be an ExpressionSource (ColumnBuilder or ExpressionBuilder)`);
|
|
46
|
+
operationArgs.push(arg.toExpr());
|
|
47
|
+
} else if (argSpec.kind === "literal") operationArgs.push({
|
|
48
|
+
kind: "literal",
|
|
49
|
+
value: arg
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const operationExpr = {
|
|
53
|
+
kind: "operation",
|
|
54
|
+
method: signature.method,
|
|
55
|
+
forTypeId: signature.forTypeId,
|
|
56
|
+
self: selfExpr,
|
|
57
|
+
args: operationArgs,
|
|
58
|
+
returns: signature.returns,
|
|
59
|
+
lowering: signature.lowering
|
|
60
|
+
};
|
|
61
|
+
const returnTypeId = signature.returns.kind === "typeId" ? signature.returns.type : void 0;
|
|
62
|
+
const returnColumnMeta = returnTypeId ? {
|
|
63
|
+
...columnMeta,
|
|
64
|
+
codecId: returnTypeId
|
|
65
|
+
} : columnMeta;
|
|
66
|
+
const createComparisonMethod = (op) => (value) => Object.freeze({
|
|
67
|
+
kind: "binary",
|
|
68
|
+
op,
|
|
69
|
+
left: operationExpr,
|
|
70
|
+
right: value
|
|
71
|
+
});
|
|
72
|
+
const baseResult = {
|
|
73
|
+
kind: "expression",
|
|
74
|
+
expr: operationExpr,
|
|
75
|
+
get columnMeta() {
|
|
76
|
+
return returnColumnMeta;
|
|
77
|
+
},
|
|
78
|
+
eq: createComparisonMethod("eq"),
|
|
79
|
+
neq: createComparisonMethod("neq"),
|
|
80
|
+
gt: createComparisonMethod("gt"),
|
|
81
|
+
lt: createComparisonMethod("lt"),
|
|
82
|
+
gte: createComparisonMethod("gte"),
|
|
83
|
+
lte: createComparisonMethod("lte"),
|
|
84
|
+
asc() {
|
|
85
|
+
return Object.freeze({
|
|
86
|
+
kind: "order",
|
|
87
|
+
expr: operationExpr,
|
|
88
|
+
dir: "asc"
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
desc() {
|
|
92
|
+
return Object.freeze({
|
|
93
|
+
kind: "order",
|
|
94
|
+
expr: operationExpr,
|
|
95
|
+
dir: "desc"
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
toExpr() {
|
|
99
|
+
return operationExpr;
|
|
100
|
+
},
|
|
101
|
+
get __jsType() {}
|
|
102
|
+
};
|
|
103
|
+
if (returnTypeId && operationRegistry) {
|
|
104
|
+
const resultWithOps = attachOperationsToExpressionBuilder(baseResult, returnColumnMeta, operationRegistry, contractCapabilities);
|
|
105
|
+
return Object.freeze(resultWithOps);
|
|
106
|
+
}
|
|
107
|
+
return Object.freeze(baseResult);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Attaches operation methods to an ExpressionBuilder for chained operations.
|
|
111
|
+
* When an operation returns a typeId, the result ExpressionBuilder needs
|
|
112
|
+
* operation methods for that type.
|
|
113
|
+
*/
|
|
114
|
+
function attachOperationsToExpressionBuilder(expressionBuilder, columnMeta, registry, contractCapabilities) {
|
|
115
|
+
const codecId = columnMeta.codecId;
|
|
116
|
+
if (!codecId) return expressionBuilder;
|
|
117
|
+
const operations = registry.byType(codecId);
|
|
118
|
+
if (operations.length === 0) return expressionBuilder;
|
|
119
|
+
const builderWithOps = expressionBuilder;
|
|
120
|
+
for (const operation of operations) {
|
|
121
|
+
if (operation.capabilities && operation.capabilities.length > 0) {
|
|
122
|
+
if (!contractCapabilities) continue;
|
|
123
|
+
if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) continue;
|
|
124
|
+
}
|
|
125
|
+
builderWithOps[operation.method] = function(...args) {
|
|
126
|
+
return executeOperation(operation, this, args, columnMeta, registry, contractCapabilities);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return builderWithOps;
|
|
130
|
+
}
|
|
131
|
+
function attachOperationsToColumnBuilder(columnBuilder, columnMeta, registry, contractCapabilities) {
|
|
132
|
+
if (!registry) return columnBuilder;
|
|
133
|
+
const codecId = columnMeta.codecId;
|
|
134
|
+
if (!codecId) return columnBuilder;
|
|
135
|
+
const operations = registry.byType(codecId);
|
|
136
|
+
if (operations.length === 0) return columnBuilder;
|
|
137
|
+
const builderWithOps = columnBuilder;
|
|
138
|
+
for (const operation of operations) {
|
|
139
|
+
if (operation.capabilities && operation.capabilities.length > 0) {
|
|
140
|
+
if (!contractCapabilities) continue;
|
|
141
|
+
if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) continue;
|
|
142
|
+
}
|
|
143
|
+
builderWithOps[operation.method] = function(...args) {
|
|
144
|
+
return executeOperation(operation, this, args, columnMeta, registry, contractCapabilities);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return builderWithOps;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
export { attachOperationsToColumnBuilder as t };
|
|
152
|
+
//# sourceMappingURL=operations-registry-7R5KE2-5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations-registry-7R5KE2-5.mjs","names":["selfExpr: Expression","operationArgs: Array<Expression | ParamRef | LiteralExpr>","operationExpr: OperationExpr","returnColumnMeta: StorageColumn","baseResult: ExpressionBuilder"],"sources":["../src/operations-registry.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport { hasAllCapabilities } from '@prisma-next/operations';\nimport { planInvalid } from '@prisma-next/plan';\nimport type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type {\n BinaryOp,\n Expression,\n ExpressionSource,\n LiteralExpr,\n OperationExpr,\n ParamRef,\n} from './ast/types';\nimport type {\n AnyBinaryBuilder,\n AnyOrderBuilder,\n ColumnBuilder,\n ExpressionBuilder,\n OperationTypes,\n ParamPlaceholder,\n} from './types';\nimport { isParamPlaceholder } from './utils/guards';\n\n/**\n * Type guard to check if a value is an ExpressionSource (has toExpr method).\n */\nfunction isExpressionSource(value: unknown): value is ExpressionSource {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'toExpr' in value &&\n typeof (value as ExpressionSource).toExpr === 'function'\n );\n}\n\n/**\n * Executes an operation and returns an ExpressionBuilder.\n * This is the canonical entrypoint for operation invocation, enabling\n * future enhancements like telemetry, caching, or tracing.\n *\n * The returned ExpressionBuilder:\n * - Has `kind: 'expression'` to distinguish it from ColumnBuilder\n * - Contains the operation expression in `expr`\n * - Provides `toExpr()` method to get the Expression\n * - Provides comparison and ordering methods for chaining\n *\n * @param signature - The operation signature from the registry\n * @param selfBuilder - The expression source that the operation is called on\n * @param args - The arguments passed to the operation\n * @param columnMeta - The metadata of the column the operation is called on\n * @returns An ExpressionBuilder containing the operation expression\n */\nfunction executeOperation(\n signature: SqlOperationSignature,\n selfBuilder: ExpressionSource,\n args: unknown[],\n columnMeta: StorageColumn,\n operationRegistry?: OperationRegistry,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): ExpressionBuilder {\n if (args.length !== signature.args.length) {\n throw planInvalid(\n `Operation ${signature.method} expects ${signature.args.length} arguments, got ${args.length}`,\n );\n }\n\n // Get the Expression from the self builder using toExpr()\n const selfExpr: Expression = selfBuilder.toExpr();\n\n const operationArgs: Array<Expression | ParamRef | LiteralExpr> = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const argSpec = signature.args[i];\n if (!argSpec) {\n throw planInvalid(`Missing argument spec for argument ${i}`);\n }\n\n if (argSpec.kind === 'param') {\n if (!isParamPlaceholder(arg)) {\n throw planInvalid(`Argument ${i} must be a parameter placeholder`);\n }\n operationArgs.push({\n kind: 'param',\n index: 0,\n name: arg.name,\n });\n } else if (argSpec.kind === 'typeId') {\n // Accept ExpressionSource (ColumnBuilder or ExpressionBuilder)\n if (!isExpressionSource(arg)) {\n throw planInvalid(\n `Argument ${i} must be an ExpressionSource (ColumnBuilder or ExpressionBuilder)`,\n );\n }\n // Use toExpr() to get the Expression\n operationArgs.push(arg.toExpr());\n } else if (argSpec.kind === 'literal') {\n operationArgs.push({\n kind: 'literal',\n value: arg,\n });\n }\n }\n\n const operationExpr: OperationExpr = {\n kind: 'operation',\n method: signature.method,\n forTypeId: signature.forTypeId,\n self: selfExpr,\n args: operationArgs,\n returns: signature.returns,\n lowering: signature.lowering,\n };\n\n const returnTypeId = signature.returns.kind === 'typeId' ? signature.returns.type : undefined;\n const returnColumnMeta: StorageColumn = returnTypeId\n ? {\n ...columnMeta,\n codecId: returnTypeId,\n }\n : columnMeta;\n\n const createComparisonMethod =\n (op: BinaryOp) =>\n (value: ParamPlaceholder | ExpressionSource): AnyBinaryBuilder =>\n Object.freeze({\n kind: 'binary' as const,\n op,\n left: operationExpr,\n right: value,\n }) as AnyBinaryBuilder;\n\n const baseResult: ExpressionBuilder = {\n kind: 'expression' as const,\n expr: operationExpr,\n get columnMeta() {\n return returnColumnMeta;\n },\n eq: createComparisonMethod('eq'),\n neq: createComparisonMethod('neq'),\n gt: createComparisonMethod('gt'),\n lt: createComparisonMethod('lt'),\n gte: createComparisonMethod('gte'),\n lte: createComparisonMethod('lte'),\n asc(): AnyOrderBuilder {\n return Object.freeze({\n kind: 'order' as const,\n expr: operationExpr,\n dir: 'asc' as const,\n });\n },\n desc(): AnyOrderBuilder {\n return Object.freeze({\n kind: 'order' as const,\n expr: operationExpr,\n dir: 'desc' as const,\n });\n },\n toExpr(): OperationExpr {\n return operationExpr;\n },\n get __jsType(): unknown {\n return undefined;\n },\n };\n\n // If the return type is a typeId, attach operations for that type\n if (returnTypeId && operationRegistry) {\n const resultWithOps = attachOperationsToExpressionBuilder(\n baseResult,\n returnColumnMeta,\n operationRegistry,\n contractCapabilities,\n );\n return Object.freeze(resultWithOps);\n }\n\n return Object.freeze(baseResult);\n}\n\n/**\n * Attaches operation methods to an ExpressionBuilder for chained operations.\n * When an operation returns a typeId, the result ExpressionBuilder needs\n * operation methods for that type.\n */\nfunction attachOperationsToExpressionBuilder(\n expressionBuilder: ExpressionBuilder,\n columnMeta: StorageColumn,\n registry: OperationRegistry,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): ExpressionBuilder {\n const codecId = columnMeta.codecId;\n if (!codecId) {\n return expressionBuilder;\n }\n\n const operations = registry.byType(codecId) as SqlOperationSignature[];\n if (operations.length === 0) {\n return expressionBuilder;\n }\n\n const builderWithOps = expressionBuilder as ExpressionBuilder & Record<string, unknown>;\n\n for (const operation of operations) {\n if (operation.capabilities && operation.capabilities.length > 0) {\n if (!contractCapabilities) {\n continue;\n }\n\n if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) {\n continue;\n }\n }\n // Method sugar: attach operation as a method on the expression builder\n builderWithOps[operation.method] = function (this: ExpressionBuilder, ...args: unknown[]) {\n return executeOperation(operation, this, args, columnMeta, registry, contractCapabilities);\n };\n }\n\n return builderWithOps;\n}\n\nexport function attachOperationsToColumnBuilder<\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n>(\n columnBuilder: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,\n columnMeta: ColumnMeta,\n registry: OperationRegistry | undefined,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations> {\n if (!registry) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n // Use codecId to look up operations registered for this column's type\n const codecId = columnMeta.codecId;\n if (!codecId) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n const operations = registry.byType(codecId) as SqlOperationSignature[];\n if (operations.length === 0) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n const builderWithOps = columnBuilder as unknown as ColumnBuilder<\n ColumnName,\n ColumnMeta,\n JsType,\n Operations\n >;\n\n for (const operation of operations) {\n if (operation.capabilities && operation.capabilities.length > 0) {\n if (!contractCapabilities) {\n continue;\n }\n\n if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) {\n continue;\n }\n }\n // Method sugar: attach operation as a method on the column builder\n // Operations return ExpressionBuilder, not ColumnBuilder\n (builderWithOps as Record<string, unknown>)[operation.method] = function (\n this: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,\n ...args: unknown[]\n ) {\n return executeOperation(operation, this, args, columnMeta, registry, contractCapabilities);\n };\n }\n\n return builderWithOps;\n}\n"],"mappings":";;;;;;;;AA0BA,SAAS,mBAAmB,OAA2C;AACrE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,OAAQ,MAA2B,WAAW;;;;;;;;;;;;;;;;;;;AAqBlD,SAAS,iBACP,WACA,aACA,MACA,YACA,mBACA,sBACmB;AACnB,KAAI,KAAK,WAAW,UAAU,KAAK,OACjC,OAAM,YACJ,aAAa,UAAU,OAAO,WAAW,UAAU,KAAK,OAAO,kBAAkB,KAAK,SACvF;CAIH,MAAMA,WAAuB,YAAY,QAAQ;CAEjD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AU,qBAAqB;;;AAI9F,QAAO"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { D as OperationTypes, u as ColumnBuilder } from "./types-Bg2kUmUA.mjs";
|
|
2
|
+
import { OperationRegistry } from "@prisma-next/operations";
|
|
3
|
+
import { StorageColumn } from "@prisma-next/sql-contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/operations-registry.d.ts
|
|
6
|
+
declare function attachOperationsToColumnBuilder<ColumnName extends string, ColumnMeta extends StorageColumn, JsType = unknown, Operations extends OperationTypes = Record<string, never>>(columnBuilder: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>, columnMeta: ColumnMeta, registry: OperationRegistry | undefined, contractCapabilities?: Record<string, Record<string, boolean>>): ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { attachOperationsToColumnBuilder as t };
|
|
9
|
+
//# sourceMappingURL=operations-registry-CIcn4f2P.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations-registry-CIcn4f2P.d.mts","names":[],"sources":["../src/operations-registry.ts"],"sourcesContent":[],"mappings":";;;;;iBA6NgB,8EAEK,oDAEA,iBAAiB,sCAErB,cAAc,YAAY,YAAY,QAAQ,oCACjD,sBACF,sDACa,eAAe,2BACrC,cAAc,YAAY,YAAY,QAAQ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { A as ParamPlaceholder } from "./types-Bg2kUmUA.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/param.d.ts
|
|
4
|
+
type Parameter = ParamPlaceholder;
|
|
5
|
+
declare function param(name: string): Parameter;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { param as n, Parameter as t };
|
|
8
|
+
//# sourceMappingURL=param-B4LzVPv2.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"param-B4LzVPv2.d.mts","names":[],"sources":["../src/param.ts"],"sourcesContent":[],"mappings":";;;KAGY,SAAA,GAAY;iBAER,KAAA,gBAAqB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { planInvalid } from "@prisma-next/plan";
|
|
2
|
+
|
|
3
|
+
//#region src/param.ts
|
|
4
|
+
function param(name) {
|
|
5
|
+
if (typeof name !== "string" || name.length === 0) throw planInvalid("Parameter name must be a non-empty string");
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
kind: "param-placeholder",
|
|
8
|
+
name
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { param as t };
|
|
14
|
+
//# sourceMappingURL=param-BFvNAaHR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"param-BFvNAaHR.mjs","names":[],"sources":["../src/param.ts"],"sourcesContent":["import { planInvalid } from '@prisma-next/plan';\nimport type { ParamPlaceholder } from './types';\n\nexport type Parameter = ParamPlaceholder;\n\nexport function param(name: string): Parameter {\n if (typeof name !== 'string' || name.length === 0) {\n throw planInvalid('Parameter name must be a non-empty string');\n }\n\n return Object.freeze({\n kind: 'param-placeholder' as const,\n name,\n }) satisfies Parameter;\n}\n"],"mappings":";;;AAKA,SAAgB,MAAM,MAAyB;AAC7C,KAAI,OAAO,SAAS,YAAY,KAAK,WAAW,EAC9C,OAAM,YAAY,4CAA4C;AAGhE,QAAO,OAAO,OAAO;EACnB,MAAM;EACN;EACD,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ReturnSpec } from "@prisma-next/operations";
|
|
2
|
+
import { SqlLoweringSpec } from "@prisma-next/sql-operations";
|
|
3
|
+
import { ExecutionPlan, ParamDescriptor } from "@prisma-next/contract/types";
|
|
4
|
+
import { StorageColumn } from "@prisma-next/sql-contract/types";
|
|
5
|
+
|
|
6
|
+
//#region src/ast/types.d.ts
|
|
7
|
+
type Direction = 'asc' | 'desc';
|
|
8
|
+
interface TableRef {
|
|
9
|
+
readonly kind: 'table';
|
|
10
|
+
readonly name: string;
|
|
11
|
+
}
|
|
12
|
+
interface ColumnRef {
|
|
13
|
+
readonly kind: 'col';
|
|
14
|
+
readonly table: string;
|
|
15
|
+
readonly column: string;
|
|
16
|
+
}
|
|
17
|
+
interface ParamRef {
|
|
18
|
+
readonly kind: 'param';
|
|
19
|
+
readonly index: number;
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
}
|
|
22
|
+
interface LiteralExpr {
|
|
23
|
+
readonly kind: 'literal';
|
|
24
|
+
readonly value: unknown;
|
|
25
|
+
}
|
|
26
|
+
interface OperationExpr {
|
|
27
|
+
readonly kind: 'operation';
|
|
28
|
+
readonly method: string;
|
|
29
|
+
readonly forTypeId: string;
|
|
30
|
+
readonly self: Expression;
|
|
31
|
+
readonly args: ReadonlyArray<Expression | ParamRef | LiteralExpr>;
|
|
32
|
+
readonly returns: ReturnSpec;
|
|
33
|
+
readonly lowering: SqlLoweringSpec;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unified expression type - the canonical AST representation for column references
|
|
37
|
+
* and operation expressions. This is what all builders convert to via toExpr().
|
|
38
|
+
*/
|
|
39
|
+
type Expression = ColumnRef | OperationExpr;
|
|
40
|
+
/**
|
|
41
|
+
* Interface for any builder that can produce an Expression.
|
|
42
|
+
* Implemented by ColumnBuilder and ExpressionBuilder.
|
|
43
|
+
*/
|
|
44
|
+
interface ExpressionSource {
|
|
45
|
+
toExpr(): Expression;
|
|
46
|
+
}
|
|
47
|
+
declare function isOperationExpr(expr: Expression): expr is OperationExpr;
|
|
48
|
+
type BinaryOp = 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte';
|
|
49
|
+
interface BinaryExpr {
|
|
50
|
+
readonly kind: 'bin';
|
|
51
|
+
readonly op: BinaryOp;
|
|
52
|
+
readonly left: Expression;
|
|
53
|
+
readonly right: Expression | ParamRef;
|
|
54
|
+
}
|
|
55
|
+
interface ExistsExpr {
|
|
56
|
+
readonly kind: 'exists';
|
|
57
|
+
readonly not: boolean;
|
|
58
|
+
readonly subquery: SelectAst;
|
|
59
|
+
}
|
|
60
|
+
type JoinOnExpr = {
|
|
61
|
+
readonly kind: 'eqCol';
|
|
62
|
+
readonly left: ColumnRef;
|
|
63
|
+
readonly right: ColumnRef;
|
|
64
|
+
};
|
|
65
|
+
interface JoinAst {
|
|
66
|
+
readonly kind: 'join';
|
|
67
|
+
readonly joinType: 'inner' | 'left' | 'right' | 'full';
|
|
68
|
+
readonly table: TableRef;
|
|
69
|
+
readonly on: JoinOnExpr;
|
|
70
|
+
}
|
|
71
|
+
interface IncludeRef {
|
|
72
|
+
readonly kind: 'includeRef';
|
|
73
|
+
readonly alias: string;
|
|
74
|
+
}
|
|
75
|
+
interface IncludeAst {
|
|
76
|
+
readonly kind: 'includeMany';
|
|
77
|
+
readonly alias: string;
|
|
78
|
+
readonly child: {
|
|
79
|
+
readonly table: TableRef;
|
|
80
|
+
readonly on: JoinOnExpr;
|
|
81
|
+
readonly where?: BinaryExpr | ExistsExpr;
|
|
82
|
+
readonly orderBy?: ReadonlyArray<{
|
|
83
|
+
expr: Expression;
|
|
84
|
+
dir: Direction;
|
|
85
|
+
}>;
|
|
86
|
+
readonly limit?: number;
|
|
87
|
+
readonly project: ReadonlyArray<{
|
|
88
|
+
alias: string;
|
|
89
|
+
expr: Expression;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
interface SelectAst {
|
|
94
|
+
readonly kind: 'select';
|
|
95
|
+
readonly from: TableRef;
|
|
96
|
+
readonly joins?: ReadonlyArray<JoinAst>;
|
|
97
|
+
readonly includes?: ReadonlyArray<IncludeAst>;
|
|
98
|
+
readonly project: ReadonlyArray<{
|
|
99
|
+
alias: string;
|
|
100
|
+
expr: Expression | IncludeRef | LiteralExpr;
|
|
101
|
+
}>;
|
|
102
|
+
readonly where?: BinaryExpr | ExistsExpr;
|
|
103
|
+
readonly orderBy?: ReadonlyArray<{
|
|
104
|
+
expr: Expression;
|
|
105
|
+
dir: Direction;
|
|
106
|
+
}>;
|
|
107
|
+
readonly limit?: number;
|
|
108
|
+
}
|
|
109
|
+
interface InsertAst {
|
|
110
|
+
readonly kind: 'insert';
|
|
111
|
+
readonly table: TableRef;
|
|
112
|
+
readonly values: Record<string, ColumnRef | ParamRef>;
|
|
113
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
114
|
+
}
|
|
115
|
+
interface UpdateAst {
|
|
116
|
+
readonly kind: 'update';
|
|
117
|
+
readonly table: TableRef;
|
|
118
|
+
readonly set: Record<string, ColumnRef | ParamRef>;
|
|
119
|
+
readonly where: BinaryExpr;
|
|
120
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
121
|
+
}
|
|
122
|
+
interface DeleteAst {
|
|
123
|
+
readonly kind: 'delete';
|
|
124
|
+
readonly table: TableRef;
|
|
125
|
+
readonly where: BinaryExpr;
|
|
126
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
127
|
+
}
|
|
128
|
+
type QueryAst = SelectAst | InsertAst | UpdateAst | DeleteAst;
|
|
129
|
+
interface LoweredStatement {
|
|
130
|
+
readonly sql: string;
|
|
131
|
+
readonly params: readonly unknown[];
|
|
132
|
+
readonly annotations?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/plan.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* SQL query plan produced by lanes before lowering.
|
|
138
|
+
*
|
|
139
|
+
* Lanes build ASTs and metadata but do not perform SQL lowering.
|
|
140
|
+
* The `sql` field is absent - lowering happens in the runtime executor.
|
|
141
|
+
*
|
|
142
|
+
* Structurally aligns with ExecutionPlan<Row, QueryAst> (without sql field) to maintain
|
|
143
|
+
* compatibility with ExecutionPlan/Plan-based utilities.
|
|
144
|
+
* The generic parameter `_Row` is preserved for type extraction via ResultType.
|
|
145
|
+
*/
|
|
146
|
+
interface SqlQueryPlan<_Row = unknown> extends Pick<ExecutionPlan<_Row, QueryAst>, 'params' | 'meta'> {
|
|
147
|
+
readonly ast: QueryAst;
|
|
148
|
+
readonly _Row?: _Row;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Augments the last ParamDescriptor in the array with codecId and nativeType from columnMeta.
|
|
152
|
+
* This is used when building WHERE expressions to ensure param descriptors have type information.
|
|
153
|
+
*/
|
|
154
|
+
declare function augmentDescriptorWithColumnMeta(descriptors: ParamDescriptor[], columnMeta: StorageColumn | undefined): void;
|
|
155
|
+
//#endregion
|
|
156
|
+
export { UpdateAst as C, TableRef as S, LoweredStatement as _, ColumnRef as a, QueryAst as b, ExistsExpr as c, IncludeAst as d, IncludeRef as f, LiteralExpr as g, JoinOnExpr as h, BinaryOp as i, Expression as l, JoinAst as m, augmentDescriptorWithColumnMeta as n, DeleteAst as o, InsertAst as p, BinaryExpr as r, Direction as s, SqlQueryPlan as t, ExpressionSource as u, OperationExpr as v, isOperationExpr as w, SelectAst as x, ParamRef as y };
|
|
157
|
+
//# sourceMappingURL=plan-9PvH-Tu3.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-9PvH-Tu3.d.mts","names":[],"sources":["../src/ast/types.ts","../src/plan.ts"],"sourcesContent":[],"mappings":";;;;;;KAMY,SAAA;UAEK,QAAA;;;AAFjB;AAEiB,UAKA,SAAA,CALQ;EAKR,SAAA,IAAS,EAAA,KAAA;EAMT,SAAA,KAAQ,EAAA,MAAA;EAMR,SAAA,MAAW,EAAA,MAAA;AAK5B;AAIiB,UAfA,QAAA,CAeA;EACc,SAAA,IAAA,EAAA,OAAA;EAAa,SAAA,KAAA,EAAA,MAAA;EAAW,SAAA,IAAA,CAAA,EAAA,MAAA;;AACnC,UAXH,WAAA,CAWG;EACC,SAAA,IAAA,EAAA,SAAA;EAAe,SAAA,KAAA,EAAA,OAAA;AAOpC;AAMiB,UApBA,aAAA,CAoBgB;EAIjB,SAAA,IAAA,EAAA,WAAe;EAInB,SAAA,MAAQ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