@prisma-next/sql-relational-core 0.5.0-dev.8 → 0.5.0-dev.81
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 +59 -25
- package/dist/codec-types-BUfBna4G.d.mts +107 -0
- package/dist/codec-types-BUfBna4G.d.mts.map +1 -0
- package/dist/{errors-D3xmG4h-.mjs → errors-BF7W5uUd.mjs} +2 -2
- package/dist/{errors-D3xmG4h-.mjs.map → errors-BF7W5uUd.mjs.map} +1 -1
- package/dist/{errors-DI_RVH66.d.mts → errors-BgNpVAT8.d.mts} +2 -2
- package/dist/errors-BgNpVAT8.d.mts.map +1 -0
- package/dist/exports/ast.d.mts +155 -85
- package/dist/exports/ast.d.mts.map +1 -1
- package/dist/exports/ast.mjs +207 -1322
- package/dist/exports/ast.mjs.map +1 -1
- package/dist/exports/codec-descriptor-registry.d.mts +18 -0
- package/dist/exports/codec-descriptor-registry.d.mts.map +1 -0
- package/dist/exports/codec-descriptor-registry.mjs +40 -0
- package/dist/exports/codec-descriptor-registry.mjs.map +1 -0
- package/dist/exports/errors.d.mts +1 -4
- package/dist/exports/errors.mjs +2 -3
- package/dist/exports/expression.d.mts +84 -0
- package/dist/exports/expression.d.mts.map +1 -0
- package/dist/exports/expression.mjs +62 -0
- package/dist/exports/expression.mjs.map +1 -0
- package/dist/exports/middleware.d.mts +2 -0
- package/dist/exports/middleware.mjs +2 -0
- package/dist/exports/plan.d.mts +3 -2
- package/dist/exports/plan.mjs +27 -10
- package/dist/exports/plan.mjs.map +1 -1
- package/dist/exports/query-lane-context.d.mts +2 -3
- package/dist/exports/query-lane-context.mjs +1 -1
- package/dist/exports/types.d.mts +3 -4
- package/dist/exports/types.mjs +1 -1
- package/dist/index.d.mts +12 -11
- package/dist/index.mjs +8 -5
- package/dist/middleware-D2Wv9QIf.mjs +82 -0
- package/dist/middleware-D2Wv9QIf.mjs.map +1 -0
- package/dist/middleware-USDeR8p1.d.mts +121 -0
- package/dist/middleware-USDeR8p1.d.mts.map +1 -0
- package/dist/plan-DFpOIsKB.d.mts +44 -0
- package/dist/plan-DFpOIsKB.d.mts.map +1 -0
- package/dist/query-lane-context-C2tLZGp4.d.mts +72 -0
- package/dist/query-lane-context-C2tLZGp4.d.mts.map +1 -0
- package/dist/sql-execution-plan-ffz8TSfr.d.mts +32 -0
- package/dist/sql-execution-plan-ffz8TSfr.d.mts.map +1 -0
- package/dist/{types-C3Hg-CVz.d.mts → types-BZcKgaYA.d.mts} +61 -24
- package/dist/types-BZcKgaYA.d.mts.map +1 -0
- package/dist/types-CK9ZJ6OU.mjs +1112 -0
- package/dist/types-CK9ZJ6OU.mjs.map +1 -0
- package/dist/types-CL18G37a.d.mts +23 -0
- package/dist/types-CL18G37a.d.mts.map +1 -0
- package/dist/{types-D3vVZzRZ.d.mts → types-D6Pk1DTr.d.mts} +18 -25
- package/dist/types-D6Pk1DTr.d.mts.map +1 -0
- package/dist/util-DWmhUCEO.mjs +34 -0
- package/dist/util-DWmhUCEO.mjs.map +1 -0
- package/package.json +17 -14
- package/src/ast/adapter-types.ts +6 -14
- package/src/ast/codec-types.ts +87 -419
- package/src/ast/sql-codec-helpers.ts +79 -0
- package/src/ast/sql-codecs.ts +285 -125
- package/src/ast/types.ts +222 -173
- package/src/ast/util.ts +23 -0
- package/src/ast/validate-param-refs.ts +39 -0
- package/src/codec-descriptor-registry.ts +52 -0
- package/src/exports/ast.ts +2 -0
- package/src/exports/codec-descriptor-registry.ts +1 -0
- package/src/exports/expression.ts +1 -0
- package/src/exports/middleware.ts +8 -0
- package/src/exports/plan.ts +1 -0
- package/src/exports/types.ts +1 -0
- package/src/expression.ts +134 -0
- package/src/index.ts +2 -0
- package/src/middleware/param-ref-mutator.ts +230 -0
- package/src/plan.ts +43 -26
- package/src/query-lane-context.ts +35 -55
- package/src/runtime-scope.ts +20 -0
- package/src/sql-execution-plan.ts +28 -0
- package/src/types.ts +9 -22
- package/dist/codec-types-B2Xdq0Wr.d.mts +0 -167
- package/dist/codec-types-B2Xdq0Wr.d.mts.map +0 -1
- package/dist/errors-DI_RVH66.d.mts.map +0 -1
- package/dist/plan-Cs65hb-E.d.mts +0 -28
- package/dist/plan-Cs65hb-E.d.mts.map +0 -1
- package/dist/query-lane-context-D2H78Mg0.d.mts +0 -89
- package/dist/query-lane-context-D2H78Mg0.d.mts.map +0 -1
- package/dist/types-C3Hg-CVz.d.mts.map +0 -1
- package/dist/types-D3vVZzRZ.d.mts.map +0 -1
package/dist/exports/plan.mjs
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
//#region src/plan.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Wraps an `AnyQueryAst` (typically a `RawSqlExpr` constructed package-internally
|
|
4
|
+
* by an extension's migration factory) in a fully-populated `SqlQueryPlan`
|
|
5
|
+
* whose `meta` is sourced from the supplied contract.
|
|
6
|
+
*
|
|
7
|
+
* Centralising the envelope here means consumers (cipherstash migration
|
|
8
|
+
* factories today; future raw-sql callers) cannot drift on `storageHash` /
|
|
9
|
+
* `target` / `targetFamily`, which would otherwise surface as a subtle
|
|
10
|
+
* `assertContractMatches` failure inside `dataTransform`. `params` defaults
|
|
11
|
+
* to `[]` because parameters embedded in the AST as `ParamRef`s are resolved
|
|
12
|
+
* at lowering time (`encodeParams` walks `plan.ast.collectParamRefs()`),
|
|
13
|
+
* not at plan-construction time.
|
|
14
|
+
*
|
|
15
|
+
* The default `laneId` of `'raw'` reflects raw-SQL plans' standard lane tag;
|
|
16
|
+
* callers (e.g. a future `sql-raw-factory`) may override to differentiate
|
|
17
|
+
* the plan's provenance.
|
|
5
18
|
*/
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
function planFromAst(ast, contract, laneId = "raw") {
|
|
20
|
+
return {
|
|
21
|
+
ast,
|
|
22
|
+
params: [],
|
|
23
|
+
meta: {
|
|
24
|
+
target: contract.target,
|
|
25
|
+
targetFamily: contract.targetFamily,
|
|
26
|
+
storageHash: contract.storage.storageHash,
|
|
27
|
+
lane: laneId
|
|
28
|
+
}
|
|
12
29
|
};
|
|
13
30
|
}
|
|
14
|
-
|
|
15
31
|
//#endregion
|
|
16
|
-
export {
|
|
32
|
+
export { planFromAst };
|
|
33
|
+
|
|
17
34
|
//# sourceMappingURL=plan.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.mjs","names":[],"sources":["../../src/plan.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"plan.mjs","names":[],"sources":["../../src/plan.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { QueryPlan } from '@prisma-next/framework-components/runtime';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { AnyQueryAst } 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. The `sql`\n * field is absent — `RuntimeCore` (the runtime base class in\n * `@prisma-next/framework-components/runtime`) drives lowering via the\n * SQL adapter and produces a `SqlExecutionPlan`.\n *\n * Extends the framework-level `QueryPlan<Row>` marker (`meta + _row`) and\n * adds SQL-specific fields (`ast`, `params`). The phantom `_row` property\n * (inherited from `QueryPlan`) is what `ResultType<P>` inspects to recover\n * the row type.\n */\nexport interface SqlQueryPlan<Row = unknown> extends QueryPlan<Row> {\n readonly ast: AnyQueryAst;\n readonly params: readonly unknown[];\n}\n\n/**\n * Wraps an `AnyQueryAst` (typically a `RawSqlExpr` constructed package-internally\n * by an extension's migration factory) in a fully-populated `SqlQueryPlan`\n * whose `meta` is sourced from the supplied contract.\n *\n * Centralising the envelope here means consumers (cipherstash migration\n * factories today; future raw-sql callers) cannot drift on `storageHash` /\n * `target` / `targetFamily`, which would otherwise surface as a subtle\n * `assertContractMatches` failure inside `dataTransform`. `params` defaults\n * to `[]` because parameters embedded in the AST as `ParamRef`s are resolved\n * at lowering time (`encodeParams` walks `plan.ast.collectParamRefs()`),\n * not at plan-construction time.\n *\n * The default `laneId` of `'raw'` reflects raw-SQL plans' standard lane tag;\n * callers (e.g. a future `sql-raw-factory`) may override to differentiate\n * the plan's provenance.\n */\nexport function planFromAst<Row = unknown>(\n ast: AnyQueryAst,\n contract: Contract<SqlStorage>,\n laneId = 'raw',\n): SqlQueryPlan<Row> {\n return {\n ast,\n params: [],\n meta: {\n target: contract.target,\n targetFamily: contract.targetFamily,\n storageHash: contract.storage.storageHash,\n lane: laneId,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,SAAgB,YACd,KACA,UACA,SAAS,OACU;CACnB,OAAO;EACL;EACA,QAAQ,EAAE;EACV,MAAM;GACJ,QAAQ,SAAS;GACjB,cAAc,SAAS;GACvB,aAAa,SAAS,QAAQ;GAC9B,MAAM;GACP;EACF"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
|
|
3
|
-
export { AppliedMutationDefault, ExecutionContext, JsonSchemaValidateFn, JsonSchemaValidationError, JsonSchemaValidationResult, JsonSchemaValidatorRegistry, MutationDefaultsOp, MutationDefaultsOptions, TypeHelperRegistry };
|
|
1
|
+
import { a as MutationDefaultsOptions, i as MutationDefaultsOp, n as CodecDescriptorRegistry, o as TypeHelperRegistry, r as ExecutionContext, t as AppliedMutationDefault } from "../query-lane-context-C2tLZGp4.mjs";
|
|
2
|
+
export { AppliedMutationDefault, CodecDescriptorRegistry, ExecutionContext, MutationDefaultsOp, MutationDefaultsOptions, TypeHelperRegistry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/exports/types.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
|
|
4
|
-
export { BuildOptions, BuildParamsMap, CodecTypes, ColumnsOf, ComputeColumnJsType, Expr, HasIncludeManyCapabilities, META, Meta, ModelDef, ModelMetadata, OperationTypeSignature, OperationTypes, OperationsForTypeId, RawFactory, RawFunctionOptions, RawTemplateFactory, RawTemplateOptions, ResultType, RuntimeError, SqlBuilderOptions, SqlPlan, TableDef, TableKey, TableMetadata, TablesOf };
|
|
1
|
+
import { C as TableKey, S as TableDef, T as TablesOf, _ as RawTemplateFactory, a as ComputeColumnJsType, b as SqlBuilderOptions, c as META, d as ModelMetadata, f as OperationTypeSignature, g as RawFunctionOptions, h as RawFactory, i as ColumnsOf, l as Meta, m as OperationsForTypeId, n as BuildParamsMap, o as Expr, p as OperationTypes, r as CodecTypes, s as HasIncludeManyCapabilities, t as BuildOptions, u as ModelDef, v as RawTemplateOptions, w as TableMetadata, x as SqlPlan, y as RuntimeError } from "../types-D6Pk1DTr.mjs";
|
|
2
|
+
import { n as SqlOrmPlan, t as RuntimeScope } from "../types-CL18G37a.mjs";
|
|
3
|
+
export { BuildOptions, BuildParamsMap, CodecTypes, ColumnsOf, ComputeColumnJsType, Expr, HasIncludeManyCapabilities, META, Meta, ModelDef, ModelMetadata, OperationTypeSignature, OperationTypes, OperationsForTypeId, RawFactory, RawFunctionOptions, RawTemplateFactory, RawTemplateOptions, RuntimeError, RuntimeScope, SqlBuilderOptions, SqlOrmPlan, SqlPlan, TableDef, TableKey, TableMetadata, TablesOf };
|
package/dist/exports/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { C as
|
|
7
|
-
import { n as planUnsupported, t as planInvalid } from "./errors-
|
|
8
|
-
import "./exports/
|
|
9
|
-
import "./
|
|
10
|
-
import "./
|
|
11
|
-
|
|
1
|
+
import { $ as TableRef, A as InsertOnConflict, B as NotExpr, C as ExistsExpr, D as ExpressionSource, E as ExpressionRewriter, F as JsonObjectEntry, G as ParamRef, H as OperationExpr, I as JsonObjectExpr, J as ProjectionItem, K as ParamRefBindingRefs, L as ListExpression, M as JoinAst, N as JoinOnExpr, O as IdentifierRef, P as JsonArrayAggExpr, Q as SubqueryExpr, R as LiteralExpr, S as EqColJoinOn, T as ExpressionFolder, U as OrExpr, V as NullCheckExpr, W as OrderByItem, X as SelectAst, Y as RawSqlExpr, Z as SelectAstOptions, _ as DeleteAst, a as AndExpr, at as isWhereExpr, b as DoNothingConflictAction, c as AnyInsertOnConflictAction, d as AnyQueryAst, et as TableSource, f as AstRewriter, g as DefaultValueExpr, h as ColumnRef, i as AggregateOpFn, it as isQueryAst, j as InsertValue, k as InsertAst, l as AnyInsertValue, m as BinaryOp, n as AggregateExpr, nt as UpdateAst, o as AnyExpression, ot as queryAstKinds, p as BinaryExpr, q as ProjectionExpr, r as AggregateFn, rt as WhereArg, s as AnyFromSource, st as whereExprKinds, t as AggregateCountFn, tt as ToWhereExpr, u as AnyOperationArg, v as DerivedTableSource, w as ExprVisitor, x as DoUpdateSetConflictAction, y as Direction, z as LoweredStatement } from "./types-BZcKgaYA.mjs";
|
|
2
|
+
import { a as CodecMeta, c as DescriptorCodecId, d as ExtractCodecTypes, f as SqlCodecCallContext, i as CodecDescriptor, l as DescriptorCodecInput, m as SqlColumnRef, n as Codec, o as CodecTrait, p as SqlCodecInstanceContext, r as CodecCallContext, s as ContractCodecRegistry, t as AnyCodecDescriptor, u as DescriptorCodecTraits } from "./codec-types-BUfBna4G.mjs";
|
|
3
|
+
import { a as MutationDefaultsOptions, i as MutationDefaultsOp, n as CodecDescriptorRegistry, o as TypeHelperRegistry, r as ExecutionContext, t as AppliedMutationDefault } from "./query-lane-context-C2tLZGp4.mjs";
|
|
4
|
+
import { Adapter, AdapterProfile, AdapterTarget, Lowerer, LowererContext, MarkerStatement, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SqlCharCodec, SqlCharDescriptor, SqlConnection, SqlDriver, SqlDriverState, SqlExecuteRequest, SqlExplainResult, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlQueryResult, SqlQueryable, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlTransaction, SqlVarcharCodec, SqlVarcharDescriptor, collectOrderedParamRefs, compact, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType, validateParamRefRefs } from "./exports/ast.mjs";
|
|
5
|
+
import { t as SqlExecutionPlan } from "./sql-execution-plan-ffz8TSfr.mjs";
|
|
6
|
+
import { C as TableKey, S as TableDef, T as TablesOf, _ as RawTemplateFactory, a as ComputeColumnJsType, b as SqlBuilderOptions, c as META, d as ModelMetadata, f as OperationTypeSignature, g as RawFunctionOptions, h as RawFactory, i as ColumnsOf, l as Meta, m as OperationsForTypeId, n as BuildParamsMap, o as Expr, p as OperationTypes, r as CodecTypes, s as HasIncludeManyCapabilities, t as BuildOptions, u as ModelDef, v as RawTemplateOptions, w as TableMetadata, x as SqlPlan, y as RuntimeError } from "./types-D6Pk1DTr.mjs";
|
|
7
|
+
import { n as planUnsupported, t as planInvalid } from "./errors-BgNpVAT8.mjs";
|
|
8
|
+
import { BuildOperationSpec, CodecExpression, Expression, ScopeField, TraitExpression, buildOperation, refsOf, toExpr } from "./exports/expression.mjs";
|
|
9
|
+
import { a as SqlParamRefMutatorInternal, i as SqlParamRefMutator, n as ParamRefEntryUnion, o as createSqlParamRefMutator, r as ParamRefHandle, t as ParamRefEntry } from "./middleware-USDeR8p1.mjs";
|
|
10
|
+
import { n as planFromAst, t as SqlQueryPlan } from "./plan-DFpOIsKB.mjs";
|
|
11
|
+
import { n as SqlOrmPlan, t as RuntimeScope } from "./types-CL18G37a.mjs";
|
|
12
|
+
export { Adapter, AdapterProfile, AdapterTarget, AggregateCountFn, AggregateExpr, AggregateFn, AggregateOpFn, AndExpr, AnyCodecDescriptor, AnyExpression, AnyFromSource, AnyInsertOnConflictAction, AnyInsertValue, AnyOperationArg, AnyQueryAst, AppliedMutationDefault, AstRewriter, BinaryExpr, BinaryOp, BuildOperationSpec, BuildOptions, BuildParamsMap, Codec, CodecCallContext, CodecDescriptor, CodecDescriptorRegistry, CodecExpression, CodecMeta, CodecTrait, CodecTypes, ColumnRef, ColumnsOf, ComputeColumnJsType, ContractCodecRegistry, DefaultValueExpr, DeleteAst, DerivedTableSource, DescriptorCodecId, DescriptorCodecInput, DescriptorCodecTraits, Direction, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExecutionContext, ExistsExpr, Expr, ExprVisitor, Expression, ExpressionFolder, ExpressionRewriter, ExpressionSource, ExtractCodecTypes, HasIncludeManyCapabilities, IdentifierRef, InsertAst, InsertOnConflict, InsertValue, JoinAst, JoinOnExpr, JsonArrayAggExpr, JsonObjectEntry, JsonObjectExpr, ListExpression, LiteralExpr, LoweredStatement, Lowerer, LowererContext, META, MarkerStatement, Meta, ModelDef, ModelMetadata, MutationDefaultsOp, MutationDefaultsOptions, NotExpr, NullCheckExpr, OperationExpr, OperationTypeSignature, OperationTypes, OperationsForTypeId, OrExpr, OrderByItem, ParamRef, ParamRefBindingRefs, ParamRefEntry, ParamRefEntryUnion, ParamRefHandle, ProjectionExpr, ProjectionItem, RawFactory, RawFunctionOptions, RawSqlExpr, RawTemplateFactory, RawTemplateOptions, RuntimeError, RuntimeScope, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, ScopeField, SelectAst, SelectAstOptions, SqlBuilderOptions, SqlCharCodec, SqlCharDescriptor, SqlCodecCallContext, SqlCodecInstanceContext, SqlColumnRef, SqlConnection, SqlDriver, SqlDriverState, SqlExecuteRequest, SqlExecutionPlan, SqlExplainResult, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlOrmPlan, SqlParamRefMutator, SqlParamRefMutatorInternal, SqlPlan, SqlQueryPlan, SqlQueryResult, SqlQueryable, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlTransaction, SqlVarcharCodec, SqlVarcharDescriptor, SubqueryExpr, TableDef, TableKey, TableMetadata, TableRef, TableSource, TablesOf, ToWhereExpr, TraitExpression, TypeHelperRegistry, UpdateAst, WhereArg, buildOperation, collectOrderedParamRefs, compact, createSqlParamRefMutator, isQueryAst, isWhereExpr, planFromAst, planInvalid, planUnsupported, queryAstKinds, refsOf, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType, toExpr, validateParamRefRefs, whereExprKinds };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
1
|
+
import { A as TableSource, C as OrExpr, D as RawSqlExpr, E as ProjectionItem, F as whereExprKinds, M as isQueryAst, N as isWhereExpr, O as SelectAst, P as queryAstKinds, S as OperationExpr, T as ParamRef, _ as JsonObjectExpr, a as DefaultValueExpr, b as NotExpr, c as DoNothingConflictAction, d as ExistsExpr, f as IdentifierRef, g as JsonArrayAggExpr, h as JoinAst, i as ColumnRef, j as UpdateAst, k as SubqueryExpr, l as DoUpdateSetConflictAction, m as InsertOnConflict, n as AndExpr, o as DeleteAst, p as InsertAst, r as BinaryExpr, s as DerivedTableSource, t as AggregateExpr, u as EqColJoinOn, v as ListExpression, w as OrderByItem, x as NullCheckExpr, y as LiteralExpr } from "./types-CK9ZJ6OU.mjs";
|
|
2
|
+
import { n as compact, t as collectOrderedParamRefs } from "./util-DWmhUCEO.mjs";
|
|
3
|
+
import { SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SqlCharCodec, SqlCharDescriptor, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlVarcharCodec, SqlVarcharDescriptor, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType, validateParamRefRefs } from "./exports/ast.mjs";
|
|
4
|
+
import { n as planUnsupported, t as planInvalid } from "./errors-BF7W5uUd.mjs";
|
|
5
|
+
import { buildOperation, refsOf, toExpr } from "./exports/expression.mjs";
|
|
6
|
+
import { t as createSqlParamRefMutator } from "./middleware-D2Wv9QIf.mjs";
|
|
7
|
+
import { planFromAst } from "./exports/plan.mjs";
|
|
4
8
|
import "./exports/query-lane-context.mjs";
|
|
5
9
|
import "./exports/types.mjs";
|
|
6
|
-
|
|
7
|
-
export { AggregateExpr, AndExpr, BinaryExpr, ColumnRef, DefaultValueExpr, DeleteAst, DerivedTableSource, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExistsExpr, IdentifierRef, InsertAst, InsertOnConflict, JoinAst, JsonArrayAggExpr, JsonObjectExpr, ListExpression, LiteralExpr, NotExpr, NullCheckExpr, OperationExpr, OrExpr, OrderByItem, ParamRef, ProjectionItem, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SubqueryExpr, TableSource, UpdateAst, augmentDescriptorWithColumnMeta, codec, compact, createCodecRegistry, defineCodecs, isQueryAst, isWhereExpr, planInvalid, planUnsupported, queryAstKinds, sqlCodecDefinitions, sqlDataTypes, whereExprKinds };
|
|
10
|
+
export { AggregateExpr, AndExpr, BinaryExpr, ColumnRef, DefaultValueExpr, DeleteAst, DerivedTableSource, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExistsExpr, IdentifierRef, InsertAst, InsertOnConflict, JoinAst, JsonArrayAggExpr, JsonObjectExpr, ListExpression, LiteralExpr, NotExpr, NullCheckExpr, OperationExpr, OrExpr, OrderByItem, ParamRef, ProjectionItem, RawSqlExpr, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SqlCharCodec, SqlCharDescriptor, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlVarcharCodec, SqlVarcharDescriptor, SubqueryExpr, TableSource, UpdateAst, buildOperation, collectOrderedParamRefs, compact, createSqlParamRefMutator, isQueryAst, isWhereExpr, planFromAst, planInvalid, planUnsupported, queryAstKinds, refsOf, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType, toExpr, validateParamRefRefs, whereExprKinds };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { t as collectOrderedParamRefs } from "./util-DWmhUCEO.mjs";
|
|
2
|
+
//#region src/middleware/param-ref-mutator.ts
|
|
3
|
+
/**
|
|
4
|
+
* Build a {@link SqlParamRefMutatorInternal} for the given lowered plan.
|
|
5
|
+
*
|
|
6
|
+
* The mutator captures `plan.params` by reference and walks
|
|
7
|
+
* `plan.ast` (via `collectOrderedParamRefs`) on demand to build
|
|
8
|
+
* entries. Mutations write to a lazily-allocated working copy so the
|
|
9
|
+
* fast path (no mutation) preserves bit-for-bit reference identity to
|
|
10
|
+
* the original `plan.params`.
|
|
11
|
+
*
|
|
12
|
+
* Threading: `plan.ast` carries the canonical `ParamRef` ordering used
|
|
13
|
+
* by every consumer (renderer's `$N` index map, encode-side metadata
|
|
14
|
+
* walk, etc.). The mutator's `entries()` yields the same order so
|
|
15
|
+
* middleware that filters by codec id sees ParamRefs in the order the
|
|
16
|
+
* runtime will encode them.
|
|
17
|
+
*/
|
|
18
|
+
function createSqlParamRefMutator(plan) {
|
|
19
|
+
const originalParams = plan.params;
|
|
20
|
+
const refs = plan.ast ? collectOrderedParamRefs(plan.ast) : [];
|
|
21
|
+
let workingParams;
|
|
22
|
+
const indexOfRef = (handle) => {
|
|
23
|
+
return refs.indexOf(handle);
|
|
24
|
+
};
|
|
25
|
+
const ensureWorkingParams = () => {
|
|
26
|
+
if (!workingParams) workingParams = [...originalParams];
|
|
27
|
+
return workingParams;
|
|
28
|
+
};
|
|
29
|
+
const writeAt = (index, value) => {
|
|
30
|
+
const buffer = ensureWorkingParams();
|
|
31
|
+
buffer[index] = value;
|
|
32
|
+
};
|
|
33
|
+
function* entries() {
|
|
34
|
+
const view = workingParams ?? originalParams;
|
|
35
|
+
for (let i = 0; i < refs.length; i++) {
|
|
36
|
+
const ref = refs[i];
|
|
37
|
+
if (!ref) continue;
|
|
38
|
+
const handle = ref;
|
|
39
|
+
const value = i < view.length ? view[i] : ref.value;
|
|
40
|
+
const codecId = ref.codecId;
|
|
41
|
+
const column = ref.refs ? {
|
|
42
|
+
table: ref.refs.table,
|
|
43
|
+
name: ref.refs.column
|
|
44
|
+
} : void 0;
|
|
45
|
+
yield column ? {
|
|
46
|
+
ref: handle,
|
|
47
|
+
value,
|
|
48
|
+
codecId,
|
|
49
|
+
column
|
|
50
|
+
} : {
|
|
51
|
+
ref: handle,
|
|
52
|
+
value,
|
|
53
|
+
codecId
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function replaceValue(handle, newValue) {
|
|
58
|
+
const index = indexOfRef(handle);
|
|
59
|
+
if (index < 0) return;
|
|
60
|
+
writeAt(index, newValue);
|
|
61
|
+
}
|
|
62
|
+
function replaceValues(updates) {
|
|
63
|
+
for (const { ref, newValue } of updates) {
|
|
64
|
+
const index = indexOfRef(ref);
|
|
65
|
+
if (index < 0) continue;
|
|
66
|
+
writeAt(index, newValue);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
entries,
|
|
71
|
+
replaceValue,
|
|
72
|
+
replaceValues,
|
|
73
|
+
currentParams() {
|
|
74
|
+
if (!workingParams) return originalParams;
|
|
75
|
+
return Object.freeze([...workingParams]);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createSqlParamRefMutator as t };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=middleware-D2Wv9QIf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-D2Wv9QIf.mjs","names":[],"sources":["../src/middleware/param-ref-mutator.ts"],"sourcesContent":["import type { ParamRefMutator } from '@prisma-next/framework-components/runtime';\nimport type { SqlColumnRef } from '../ast/codec-types';\nimport type { ParamRef } from '../ast/types';\nimport { collectOrderedParamRefs } from '../ast/util';\nimport type { SqlExecutionPlan } from '../sql-execution-plan';\n\n/**\n * Brand applied to {@link ParamRefHandle} so user-constructed handles\n * are rejected by the type system. The mutator only accepts handles it\n * produced from `entries()`.\n *\n * The brand is a phantom type — there is no runtime token. At runtime\n * the handle is the underlying `ParamRef` instance from the plan's\n * `ast`; the brand only narrows the type-level surface so callers\n * cannot fabricate a handle from a fresh `ParamRef.of(...)`.\n */\ndeclare const paramRefHandleBrand: unique symbol;\n\n/**\n * Opaque token identifying a single `ParamRef` in the plan. Produced by\n * {@link SqlParamRefMutator.entries}; consumed by `replaceValue` /\n * `replaceValues`.\n *\n * The phantom `TCodecId` parameter records the codec id of the\n * referenced `ParamRef` so type-level inference can route replacement\n * values through `TCodecMap` to the codec's declared `TInput`.\n */\nexport interface ParamRefHandle<TCodecId extends string | undefined = string | undefined> {\n readonly [paramRefHandleBrand]: TCodecId;\n}\n\n/**\n * One outbound `ParamRef` slot in the plan exposed to middleware.\n * `value` is the current value (post any prior middleware mutations);\n * `codecId` is the codec id declared on the underlying `ParamRef`;\n * `column` is populated for `ParamRef`s the lowering site could resolve\n * to a single `(table, column)` via `ParamRef.refs` (encode-side column\n * metadata is the middleware's domain — encode itself currently leaves\n * `ctx.column` unset).\n */\nexport interface ParamRefEntry<TCodecId extends string | undefined = string | undefined> {\n readonly ref: ParamRefHandle<TCodecId>;\n readonly value: unknown;\n readonly codecId: TCodecId;\n readonly column?: SqlColumnRef;\n}\n\n/**\n * Discriminated entry union over a codec map. For each `K` in\n * `TCodecMap`, `entries()` may yield a `ParamRefEntry<K>`; ParamRefs\n * with no codec id (or a codec id outside the map) yield a\n * `ParamRefEntry<undefined>`. Pattern-matching on `entry.codecId`\n * narrows `entry.ref` to a `ParamRefHandle<K>`, which routes through\n * the typed `replaceValue` overload.\n */\nexport type ParamRefEntryUnion<TCodecMap extends Record<string, unknown>> =\n | { [K in keyof TCodecMap & string]: ParamRefEntry<K> }[keyof TCodecMap & string]\n | ParamRefEntry<undefined>;\n\n/**\n * SQL-family mutator threaded into `SqlMiddleware.beforeExecute` as\n * `params`. Scope is `ParamRef.value` slots only — middleware cannot\n * insert / remove `ParamRef`s, rewrite SQL, or modify projection. The\n * type-level `ParamRefHandle` brand and the `replaceValue(ref,\n * newValue)` shape enforce this at compile time.\n *\n * Allocation discipline: the mutator is constructed lazily from the\n * plan. `entries()` walks the plan's existing AST without allocating\n * an intermediate array; the working params buffer is only allocated\n * on the first `replaceValue` / `replaceValues` call. If no middleware\n * mutates, `currentParams()` returns the plan's original `params` by\n * reference identity.\n *\n * The `TCodecMap` parameter is a record keyed by codec id; `replaceValue`\n * infers `newValue` from `TCodecMap[H['codecId']]` for handles whose\n * codec id is statically resolvable. For codec ids the type system\n * cannot resolve, `newValue` falls back to `unknown` and the middleware\n * is on the hook for runtime correctness.\n */\nexport interface SqlParamRefMutator<\n TCodecMap extends Record<string, unknown> = Record<string, unknown>,\n> extends ParamRefMutator {\n /** Iterate every outbound `ParamRef` the plan currently carries, in canonical order. */\n entries(): IterableIterator<ParamRefEntryUnion<TCodecMap>>;\n\n /**\n * Replace one `ParamRef`'s value with the result of bulk processing.\n * `newValue` is constrained to the codec's declared `TInput` for codec\n * ids the type system can resolve via `TCodecMap`; for unresolvable\n * codec ids `newValue` is `unknown` (the second overload).\n */\n replaceValue<TCodecId extends keyof TCodecMap & string>(\n ref: ParamRefHandle<TCodecId>,\n newValue: TCodecMap[TCodecId],\n ): void;\n replaceValue(ref: ParamRefHandle<undefined>, newValue: unknown): void;\n\n /** Replace many at once (typical for bulk-pattern middleware). */\n replaceValues(\n updates: Iterable<{\n readonly ref: ParamRefHandle<(keyof TCodecMap & string) | undefined>;\n readonly newValue: unknown;\n }>,\n ): void;\n}\n\n/**\n * Internal-only view of the mutator that exposes the post-mutation params\n * array to the SQL runtime. The runtime calls `currentParams()` after the\n * `beforeExecute` chain has run; the result is the plan's original\n * `params` by reference identity if no middleware mutated, otherwise a\n * frozen new array carrying the mutations applied in chain order.\n *\n * Family-internal contract — `SqlMiddleware` consumers never see this\n * shape; they receive the public `SqlParamRefMutator` view above.\n */\nexport interface SqlParamRefMutatorInternal<\n TCodecMap extends Record<string, unknown> = Record<string, unknown>,\n> extends SqlParamRefMutator<TCodecMap> {\n currentParams(): readonly unknown[];\n}\n\ntype AnyHandle = ParamRefHandle<string | undefined>;\n\n/**\n * Build a {@link SqlParamRefMutatorInternal} for the given lowered plan.\n *\n * The mutator captures `plan.params` by reference and walks\n * `plan.ast` (via `collectOrderedParamRefs`) on demand to build\n * entries. Mutations write to a lazily-allocated working copy so the\n * fast path (no mutation) preserves bit-for-bit reference identity to\n * the original `plan.params`.\n *\n * Threading: `plan.ast` carries the canonical `ParamRef` ordering used\n * by every consumer (renderer's `$N` index map, encode-side metadata\n * walk, etc.). The mutator's `entries()` yields the same order so\n * middleware that filters by codec id sees ParamRefs in the order the\n * runtime will encode them.\n */\nexport function createSqlParamRefMutator<\n TCodecMap extends Record<string, unknown> = Record<string, unknown>,\n>(plan: SqlExecutionPlan): SqlParamRefMutatorInternal<TCodecMap> {\n const originalParams = plan.params;\n const refs: ReadonlyArray<ParamRef> = plan.ast ? collectOrderedParamRefs(plan.ast) : [];\n let workingParams: unknown[] | undefined;\n\n const indexOfRef = (handle: AnyHandle): number => {\n // The handle is the underlying ParamRef instance the mutator yielded\n // from entries(); equality is identity equality on the ParamRef. The\n // brand on ParamRefHandle is unforgeable from outside, so the only\n // legal handles came from this mutator's entries().\n return refs.indexOf(handle as unknown as ParamRef);\n };\n\n const ensureWorkingParams = (): unknown[] => {\n if (!workingParams) {\n workingParams = [...originalParams];\n }\n return workingParams;\n };\n\n const writeAt = (index: number, value: unknown): void => {\n const buffer = ensureWorkingParams();\n buffer[index] = value;\n };\n\n function* entries(): IterableIterator<ParamRefEntryUnion<TCodecMap>> {\n const view = workingParams ?? originalParams;\n for (let i = 0; i < refs.length; i++) {\n const ref = refs[i];\n if (!ref) continue;\n const handle = ref as unknown as ParamRefHandle<string | undefined>;\n const value = i < view.length ? view[i] : ref.value;\n const codecId = ref.codecId;\n // Surface the column binding the lowering site resolved onto\n // `ParamRef.refs` so column-aware middleware (e.g. cipherstash\n // routing-key resolution) can address the cell without\n // re-walking the AST. ParamRefs without a column binding stay\n // `column: undefined`.\n const column = ref.refs\n ? ({ table: ref.refs.table, name: ref.refs.column } as const)\n : undefined;\n // The runtime erases the discriminated union to a single shape; the\n // public type pins each entry's `ref` to the matching `codecId`\n // arm at compile time.\n const entry: ParamRefEntry<string | undefined> = column\n ? { ref: handle, value, codecId, column }\n : { ref: handle, value, codecId };\n yield entry as ParamRefEntryUnion<TCodecMap>;\n }\n }\n\n function replaceValue(handle: AnyHandle, newValue: unknown): void {\n const index = indexOfRef(handle);\n if (index < 0) {\n // Handle does not belong to this plan. The type system pins this\n // at the brand level; this runtime check guards against handles\n // smuggled across plans.\n return;\n }\n writeAt(index, newValue);\n }\n\n function replaceValues(\n updates: Iterable<{ readonly ref: AnyHandle; readonly newValue: unknown }>,\n ): void {\n for (const { ref, newValue } of updates) {\n const index = indexOfRef(ref);\n if (index < 0) continue;\n writeAt(index, newValue);\n }\n }\n\n // The public `SqlParamRefMutator` declares overloaded `replaceValue`\n // signatures (typed-by-codec / unresolvable-codec). The implementation\n // is one function with a permissive runtime signature; the cast is the\n // single point at which the runtime function meets the typed overload\n // surface, matching the overload-implementation pattern.\n return {\n entries,\n replaceValue: replaceValue as SqlParamRefMutator<TCodecMap>['replaceValue'],\n replaceValues,\n currentParams(): readonly unknown[] {\n if (!workingParams) {\n return originalParams;\n }\n return Object.freeze([...workingParams]);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2IA,SAAgB,yBAEd,MAA+D;CAC/D,MAAM,iBAAiB,KAAK;CAC5B,MAAM,OAAgC,KAAK,MAAM,wBAAwB,KAAK,IAAI,GAAG,EAAE;CACvF,IAAI;CAEJ,MAAM,cAAc,WAA8B;EAKhD,OAAO,KAAK,QAAQ,OAA8B;;CAGpD,MAAM,4BAAuC;EAC3C,IAAI,CAAC,eACH,gBAAgB,CAAC,GAAG,eAAe;EAErC,OAAO;;CAGT,MAAM,WAAW,OAAe,UAAyB;EACvD,MAAM,SAAS,qBAAqB;EACpC,OAAO,SAAS;;CAGlB,UAAU,UAA2D;EACnE,MAAM,OAAO,iBAAiB;EAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GACjB,IAAI,CAAC,KAAK;GACV,MAAM,SAAS;GACf,MAAM,QAAQ,IAAI,KAAK,SAAS,KAAK,KAAK,IAAI;GAC9C,MAAM,UAAU,IAAI;GAMpB,MAAM,SAAS,IAAI,OACd;IAAE,OAAO,IAAI,KAAK;IAAO,MAAM,IAAI,KAAK;IAAQ,GACjD,KAAA;GAOJ,MAHiD,SAC7C;IAAE,KAAK;IAAQ;IAAO;IAAS;IAAQ,GACvC;IAAE,KAAK;IAAQ;IAAO;IAAS;;;CAKvC,SAAS,aAAa,QAAmB,UAAyB;EAChE,MAAM,QAAQ,WAAW,OAAO;EAChC,IAAI,QAAQ,GAIV;EAEF,QAAQ,OAAO,SAAS;;CAG1B,SAAS,cACP,SACM;EACN,KAAK,MAAM,EAAE,KAAK,cAAc,SAAS;GACvC,MAAM,QAAQ,WAAW,IAAI;GAC7B,IAAI,QAAQ,GAAG;GACf,QAAQ,OAAO,SAAS;;;CAS5B,OAAO;EACL;EACc;EACd;EACA,gBAAoC;GAClC,IAAI,CAAC,eACH,OAAO;GAET,OAAO,OAAO,OAAO,CAAC,GAAG,cAAc,CAAC;;EAE3C"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { m as SqlColumnRef } from "./codec-types-BUfBna4G.mjs";
|
|
2
|
+
import { t as SqlExecutionPlan } from "./sql-execution-plan-ffz8TSfr.mjs";
|
|
3
|
+
import { ParamRefMutator } from "@prisma-next/framework-components/runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/param-ref-mutator.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Brand applied to {@link ParamRefHandle} so user-constructed handles
|
|
8
|
+
* are rejected by the type system. The mutator only accepts handles it
|
|
9
|
+
* produced from `entries()`.
|
|
10
|
+
*
|
|
11
|
+
* The brand is a phantom type — there is no runtime token. At runtime
|
|
12
|
+
* the handle is the underlying `ParamRef` instance from the plan's
|
|
13
|
+
* `ast`; the brand only narrows the type-level surface so callers
|
|
14
|
+
* cannot fabricate a handle from a fresh `ParamRef.of(...)`.
|
|
15
|
+
*/
|
|
16
|
+
declare const paramRefHandleBrand: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Opaque token identifying a single `ParamRef` in the plan. Produced by
|
|
19
|
+
* {@link SqlParamRefMutator.entries}; consumed by `replaceValue` /
|
|
20
|
+
* `replaceValues`.
|
|
21
|
+
*
|
|
22
|
+
* The phantom `TCodecId` parameter records the codec id of the
|
|
23
|
+
* referenced `ParamRef` so type-level inference can route replacement
|
|
24
|
+
* values through `TCodecMap` to the codec's declared `TInput`.
|
|
25
|
+
*/
|
|
26
|
+
interface ParamRefHandle<TCodecId extends string | undefined = string | undefined> {
|
|
27
|
+
readonly [paramRefHandleBrand]: TCodecId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One outbound `ParamRef` slot in the plan exposed to middleware.
|
|
31
|
+
* `value` is the current value (post any prior middleware mutations);
|
|
32
|
+
* `codecId` is the codec id declared on the underlying `ParamRef`;
|
|
33
|
+
* `column` is populated for `ParamRef`s the lowering site could resolve
|
|
34
|
+
* to a single `(table, column)` via `ParamRef.refs` (encode-side column
|
|
35
|
+
* metadata is the middleware's domain — encode itself currently leaves
|
|
36
|
+
* `ctx.column` unset).
|
|
37
|
+
*/
|
|
38
|
+
interface ParamRefEntry<TCodecId extends string | undefined = string | undefined> {
|
|
39
|
+
readonly ref: ParamRefHandle<TCodecId>;
|
|
40
|
+
readonly value: unknown;
|
|
41
|
+
readonly codecId: TCodecId;
|
|
42
|
+
readonly column?: SqlColumnRef;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Discriminated entry union over a codec map. For each `K` in
|
|
46
|
+
* `TCodecMap`, `entries()` may yield a `ParamRefEntry<K>`; ParamRefs
|
|
47
|
+
* with no codec id (or a codec id outside the map) yield a
|
|
48
|
+
* `ParamRefEntry<undefined>`. Pattern-matching on `entry.codecId`
|
|
49
|
+
* narrows `entry.ref` to a `ParamRefHandle<K>`, which routes through
|
|
50
|
+
* the typed `replaceValue` overload.
|
|
51
|
+
*/
|
|
52
|
+
type ParamRefEntryUnion<TCodecMap extends Record<string, unknown>> = { [K in keyof TCodecMap & string]: ParamRefEntry<K> }[keyof TCodecMap & string] | ParamRefEntry<undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* SQL-family mutator threaded into `SqlMiddleware.beforeExecute` as
|
|
55
|
+
* `params`. Scope is `ParamRef.value` slots only — middleware cannot
|
|
56
|
+
* insert / remove `ParamRef`s, rewrite SQL, or modify projection. The
|
|
57
|
+
* type-level `ParamRefHandle` brand and the `replaceValue(ref,
|
|
58
|
+
* newValue)` shape enforce this at compile time.
|
|
59
|
+
*
|
|
60
|
+
* Allocation discipline: the mutator is constructed lazily from the
|
|
61
|
+
* plan. `entries()` walks the plan's existing AST without allocating
|
|
62
|
+
* an intermediate array; the working params buffer is only allocated
|
|
63
|
+
* on the first `replaceValue` / `replaceValues` call. If no middleware
|
|
64
|
+
* mutates, `currentParams()` returns the plan's original `params` by
|
|
65
|
+
* reference identity.
|
|
66
|
+
*
|
|
67
|
+
* The `TCodecMap` parameter is a record keyed by codec id; `replaceValue`
|
|
68
|
+
* infers `newValue` from `TCodecMap[H['codecId']]` for handles whose
|
|
69
|
+
* codec id is statically resolvable. For codec ids the type system
|
|
70
|
+
* cannot resolve, `newValue` falls back to `unknown` and the middleware
|
|
71
|
+
* is on the hook for runtime correctness.
|
|
72
|
+
*/
|
|
73
|
+
interface SqlParamRefMutator<TCodecMap extends Record<string, unknown> = Record<string, unknown>> extends ParamRefMutator {
|
|
74
|
+
/** Iterate every outbound `ParamRef` the plan currently carries, in canonical order. */
|
|
75
|
+
entries(): IterableIterator<ParamRefEntryUnion<TCodecMap>>;
|
|
76
|
+
/**
|
|
77
|
+
* Replace one `ParamRef`'s value with the result of bulk processing.
|
|
78
|
+
* `newValue` is constrained to the codec's declared `TInput` for codec
|
|
79
|
+
* ids the type system can resolve via `TCodecMap`; for unresolvable
|
|
80
|
+
* codec ids `newValue` is `unknown` (the second overload).
|
|
81
|
+
*/
|
|
82
|
+
replaceValue<TCodecId extends keyof TCodecMap & string>(ref: ParamRefHandle<TCodecId>, newValue: TCodecMap[TCodecId]): void;
|
|
83
|
+
replaceValue(ref: ParamRefHandle<undefined>, newValue: unknown): void;
|
|
84
|
+
/** Replace many at once (typical for bulk-pattern middleware). */
|
|
85
|
+
replaceValues(updates: Iterable<{
|
|
86
|
+
readonly ref: ParamRefHandle<(keyof TCodecMap & string) | undefined>;
|
|
87
|
+
readonly newValue: unknown;
|
|
88
|
+
}>): void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Internal-only view of the mutator that exposes the post-mutation params
|
|
92
|
+
* array to the SQL runtime. The runtime calls `currentParams()` after the
|
|
93
|
+
* `beforeExecute` chain has run; the result is the plan's original
|
|
94
|
+
* `params` by reference identity if no middleware mutated, otherwise a
|
|
95
|
+
* frozen new array carrying the mutations applied in chain order.
|
|
96
|
+
*
|
|
97
|
+
* Family-internal contract — `SqlMiddleware` consumers never see this
|
|
98
|
+
* shape; they receive the public `SqlParamRefMutator` view above.
|
|
99
|
+
*/
|
|
100
|
+
interface SqlParamRefMutatorInternal<TCodecMap extends Record<string, unknown> = Record<string, unknown>> extends SqlParamRefMutator<TCodecMap> {
|
|
101
|
+
currentParams(): readonly unknown[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Build a {@link SqlParamRefMutatorInternal} for the given lowered plan.
|
|
105
|
+
*
|
|
106
|
+
* The mutator captures `plan.params` by reference and walks
|
|
107
|
+
* `plan.ast` (via `collectOrderedParamRefs`) on demand to build
|
|
108
|
+
* entries. Mutations write to a lazily-allocated working copy so the
|
|
109
|
+
* fast path (no mutation) preserves bit-for-bit reference identity to
|
|
110
|
+
* the original `plan.params`.
|
|
111
|
+
*
|
|
112
|
+
* Threading: `plan.ast` carries the canonical `ParamRef` ordering used
|
|
113
|
+
* by every consumer (renderer's `$N` index map, encode-side metadata
|
|
114
|
+
* walk, etc.). The mutator's `entries()` yields the same order so
|
|
115
|
+
* middleware that filters by codec id sees ParamRefs in the order the
|
|
116
|
+
* runtime will encode them.
|
|
117
|
+
*/
|
|
118
|
+
declare function createSqlParamRefMutator<TCodecMap extends Record<string, unknown> = Record<string, unknown>>(plan: SqlExecutionPlan): SqlParamRefMutatorInternal<TCodecMap>;
|
|
119
|
+
//#endregion
|
|
120
|
+
export { SqlParamRefMutatorInternal as a, SqlParamRefMutator as i, ParamRefEntryUnion as n, createSqlParamRefMutator as o, ParamRefHandle as r, ParamRefEntry as t };
|
|
121
|
+
//# sourceMappingURL=middleware-USDeR8p1.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-USDeR8p1.d.mts","names":[],"sources":["../src/middleware/param-ref-mutator.ts"],"mappings":";;;;;;;AAI8D;;;;;AAuB9D;;;cAXc,mBAAA;;;;;;AAwBd;;;;UAbiB,cAAA;EAAA,UACL,mBAAA,GAAsB,QAAA;AAAA;;;;;;;;;;UAYjB,aAAA;EAAA,SACN,GAAA,EAAK,cAAA,CAAe,QAAA;EAAA,SACpB,KAAA;EAAA,SACA,OAAA,EAAS,QAAA;EAAA,SACT,MAAA,GAAS,YAAA;AAAA;;;;;;;;;KAWR,kBAAA,mBAAqC,MAAA,mCAC/B,SAAA,YAAqB,aAAA,CAAc,CAAA,UAAW,SAAA,aAC5D,aAAA;;;;;;;;;AAsBJ;;;;;;;;;;;;UAAiB,kBAAA,mBACG,MAAA,oBAA0B,MAAA,2BACpC,eAAA;EAcU;EAZlB,OAAA,IAAW,gBAAA,CAAiB,kBAAA,CAAmB,SAAA;EAiB7B;;;;;;EATlB,YAAA,wBAAoC,SAAA,WAClC,GAAA,EAAK,cAAA,CAAe,QAAA,GACpB,QAAA,EAAU,SAAA,CAAU,QAAA;EAEtB,YAAA,CAAa,GAAA,EAAK,cAAA,aAA2B,QAAA;EAdrC;EAiBR,aAAA,CACE,OAAA,EAAS,QAAA;IAAA,SACE,GAAA,EAAK,cAAA,QAAsB,SAAA;IAAA,SAC3B,QAAA;EAAA;AAAA;;;;;;;;;;;UAeE,0BAAA,mBACG,MAAA,oBAA0B,MAAA,2BACpC,kBAAA,CAAmB,SAAA;EAC3B,aAAA;AAAA;;;;;;;;;AAHF;;;;;;;iBAuBgB,wBAAA,mBACI,MAAA,oBAA0B,MAAA,kBAAA,CAC5C,IAAA,EAAM,gBAAA,GAAmB,0BAAA,CAA2B,SAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { d as AnyQueryAst } from "./types-BZcKgaYA.mjs";
|
|
2
|
+
import { QueryPlan } from "@prisma-next/framework-components/runtime";
|
|
3
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
5
|
+
|
|
6
|
+
//#region src/plan.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* SQL query plan produced by lanes before lowering.
|
|
9
|
+
*
|
|
10
|
+
* Lanes build ASTs and metadata but do not perform SQL lowering. The `sql`
|
|
11
|
+
* field is absent — `RuntimeCore` (the runtime base class in
|
|
12
|
+
* `@prisma-next/framework-components/runtime`) drives lowering via the
|
|
13
|
+
* SQL adapter and produces a `SqlExecutionPlan`.
|
|
14
|
+
*
|
|
15
|
+
* Extends the framework-level `QueryPlan<Row>` marker (`meta + _row`) and
|
|
16
|
+
* adds SQL-specific fields (`ast`, `params`). The phantom `_row` property
|
|
17
|
+
* (inherited from `QueryPlan`) is what `ResultType<P>` inspects to recover
|
|
18
|
+
* the row type.
|
|
19
|
+
*/
|
|
20
|
+
interface SqlQueryPlan<Row = unknown> extends QueryPlan<Row> {
|
|
21
|
+
readonly ast: AnyQueryAst;
|
|
22
|
+
readonly params: readonly unknown[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Wraps an `AnyQueryAst` (typically a `RawSqlExpr` constructed package-internally
|
|
26
|
+
* by an extension's migration factory) in a fully-populated `SqlQueryPlan`
|
|
27
|
+
* whose `meta` is sourced from the supplied contract.
|
|
28
|
+
*
|
|
29
|
+
* Centralising the envelope here means consumers (cipherstash migration
|
|
30
|
+
* factories today; future raw-sql callers) cannot drift on `storageHash` /
|
|
31
|
+
* `target` / `targetFamily`, which would otherwise surface as a subtle
|
|
32
|
+
* `assertContractMatches` failure inside `dataTransform`. `params` defaults
|
|
33
|
+
* to `[]` because parameters embedded in the AST as `ParamRef`s are resolved
|
|
34
|
+
* at lowering time (`encodeParams` walks `plan.ast.collectParamRefs()`),
|
|
35
|
+
* not at plan-construction time.
|
|
36
|
+
*
|
|
37
|
+
* The default `laneId` of `'raw'` reflects raw-SQL plans' standard lane tag;
|
|
38
|
+
* callers (e.g. a future `sql-raw-factory`) may override to differentiate
|
|
39
|
+
* the plan's provenance.
|
|
40
|
+
*/
|
|
41
|
+
declare function planFromAst<Row = unknown>(ast: AnyQueryAst, contract: Contract<SqlStorage>, laneId?: string): SqlQueryPlan<Row>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { planFromAst as n, SqlQueryPlan as t };
|
|
44
|
+
//# sourceMappingURL=plan-DFpOIsKB.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-DFpOIsKB.d.mts","names":[],"sources":["../src/plan.ts"],"mappings":";;;;;;;;AAkBA;;;;;;;;;;;UAAiB,YAAA,wBAAoC,SAAA,CAAU,GAAA;EAAA,SACpD,GAAA,EAAK,WAAA;EAAA,SACL,MAAA;AAAA;;AAoBX;;;;;;;;;;;;;;;;iBAAgB,WAAA,eAAA,CACd,GAAA,EAAK,WAAA,EACL,QAAA,EAAU,QAAA,CAAS,UAAA,GACnB,MAAA,YACC,YAAA,CAAa,GAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { s as ContractCodecRegistry } from "./codec-types-BUfBna4G.mjs";
|
|
2
|
+
import { CodecDescriptor } from "@prisma-next/framework-components/codec";
|
|
3
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
import { SqlOperationRegistry } from "@prisma-next/sql-operations";
|
|
5
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
6
|
+
|
|
7
|
+
//#region src/query-lane-context.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Codec-id-keyed accessor for descriptor metadata. The unified read API for codec-id-keyed metadata (`traits`, `targetTypes`, `meta`) — non-branching for parameterized vs. non-parameterized codecs. Every codec ships natively as a `CodecDescriptor` through the unified `codecs:` contributor slot (see ADR 208).
|
|
10
|
+
*/
|
|
11
|
+
interface CodecDescriptorRegistry {
|
|
12
|
+
/**
|
|
13
|
+
* Descriptors carry distinct param shapes per codec id; the registry is heterogeneous and the consumer narrows per codec.
|
|
14
|
+
*/
|
|
15
|
+
descriptorFor(codecId: string): CodecDescriptor<unknown> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* All registered descriptors. Used by `validateCodecRegistryCompleteness` and other startup-time consumers that enumerate descriptors.
|
|
18
|
+
*/
|
|
19
|
+
values(): IterableIterator<CodecDescriptor<unknown>>;
|
|
20
|
+
/**
|
|
21
|
+
* Descriptors indexed by `targetTypes[i]` (each scalar type the codec advertises). Multiple descriptors may map to the same scalar type; ordering reflects registration order.
|
|
22
|
+
*/
|
|
23
|
+
byTargetType(targetType: string): readonly CodecDescriptor<unknown>[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Registry of initialized type helpers from storage.types. Each key is a type name from storage.types, and the value is the resolved codec materialized once for that named instance via `descriptor.factory(typeParams)(ctx)` (or the raw `StorageTypeInstance` metadata for codec ids whose descriptor isn't registered).
|
|
27
|
+
*/
|
|
28
|
+
type TypeHelperRegistry = Record<string, unknown>;
|
|
29
|
+
type MutationDefaultsOp = 'create' | 'update';
|
|
30
|
+
type AppliedMutationDefault = {
|
|
31
|
+
readonly column: string;
|
|
32
|
+
readonly value: unknown;
|
|
33
|
+
};
|
|
34
|
+
type MutationDefaultsOptions = {
|
|
35
|
+
readonly op: MutationDefaultsOp;
|
|
36
|
+
readonly table: string;
|
|
37
|
+
readonly values: Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Per-ORM-operation cache for generators that declare `stability: 'query'`. The caller passes the same `Map` across every `applyMutationDefaults` invocation in one bulk operation; the framework keys by `generatorId` so the same value is reused across all rows and columns. Generators with `stability: 'row'` use a fresh per-call cache the framework manages internally; generators with `stability: 'field'` skip caching
|
|
40
|
+
* entirely. Omit to make every call independent (degrades `'query'` to per-call behavior).
|
|
41
|
+
*/
|
|
42
|
+
readonly defaultValueCache?: Map<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Minimal context interface for SQL query lanes.
|
|
46
|
+
*
|
|
47
|
+
* Lanes only need contract, operations, and codecs to build typed ASTs and attach operation builders. This interface explicitly excludes runtime concerns like adapters, connection management, and transaction state.
|
|
48
|
+
*/
|
|
49
|
+
interface ExecutionContext<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
|
|
50
|
+
readonly contract: TContract;
|
|
51
|
+
/**
|
|
52
|
+
* Contract-bound codec registry built once at context-construction time by walking the contract's columns and resolving each through its descriptor's factory. The dispatch path (`encodeParam` / `decodeRow`) consults `forColumn(table, column)` for column-bound call sites; `forCodecId(codecId)` is the refs-less fallback, permitted only for non-parameterized codec ids (the builder-pipeline validator pass enforces refs on
|
|
53
|
+
* every parameterized `ParamRef`). Pre-populated with one canonical instance per non-parameterized descriptor so `forCodecId` covers refs-less codec ids that no contract column declares.
|
|
54
|
+
*/
|
|
55
|
+
readonly contractCodecs: ContractCodecRegistry;
|
|
56
|
+
/**
|
|
57
|
+
* Codec-id-keyed descriptor map. Single source of truth for codec-id-keyed metadata (`traits`, `targetTypes`, `meta`) — every codec, parameterized or not, resolves through this map without branching.
|
|
58
|
+
*/
|
|
59
|
+
readonly codecDescriptors: CodecDescriptorRegistry;
|
|
60
|
+
readonly queryOperations: SqlOperationRegistry;
|
|
61
|
+
/**
|
|
62
|
+
* Type helper registry for parameterized types. Schema builders expose these helpers via schema.types.
|
|
63
|
+
*/
|
|
64
|
+
readonly types: TypeHelperRegistry;
|
|
65
|
+
/**
|
|
66
|
+
* Applies execution-time mutation defaults for the given table. Returns the applied defaults (caller-provided values always win).
|
|
67
|
+
*/
|
|
68
|
+
applyMutationDefaults(options: MutationDefaultsOptions): ReadonlyArray<AppliedMutationDefault>;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { MutationDefaultsOptions as a, MutationDefaultsOp as i, CodecDescriptorRegistry as n, TypeHelperRegistry as o, ExecutionContext as r, AppliedMutationDefault as t };
|
|
72
|
+
//# sourceMappingURL=query-lane-context-C2tLZGp4.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-lane-context-C2tLZGp4.d.mts","names":[],"sources":["../src/query-lane-context.ts"],"mappings":";;;;;;;;;AASA;UAAiB,uBAAA;;;;EAIf,aAAA,CAAc,OAAA,WAAkB,eAAA;EAQW;;;EAJ3C,MAAA,IAAU,gBAAA,CAAiB,eAAA;EAJb;;;EAQd,YAAA,CAAa,UAAA,oBAA8B,eAAA;AAAA;;;;KAMjC,kBAAA,GAAqB,MAAA;AAAA,KAErB,kBAAA;AAAA,KAEA,sBAAA;EAAA,SACD,MAAA;EAAA,SACA,KAAA;AAAA;AAAA,KAGC,uBAAA;EAAA,SACD,EAAA,EAAI,kBAAA;EAAA,SACJ,KAAA;EAAA,SACA,MAAA,EAAQ,MAAA;EAVW;;AAE9B;;EAF8B,SAenB,iBAAA,GAAoB,GAAA;AAAA;;AAR/B;;;;UAgBiB,gBAAA,mBAAmC,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA;EAAA,SACzE,QAAA,EAAU,SAAA;EATa;;;;EAAA,SAcvB,cAAA,EAAgB,qBAAA;EAnBhB;;;EAAA,SAuBA,gBAAA,EAAkB,uBAAA;EAAA,SAClB,eAAA,EAAiB,oBAAA;EAnBM;AAQlC;;EARkC,SAuBvB,KAAA,EAAO,kBAAA;EAf2C;;;EAmB3D,qBAAA,CAAsB,OAAA,EAAS,uBAAA,GAA0B,aAAA,CAAc,sBAAA;AAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { d as AnyQueryAst } from "./types-BZcKgaYA.mjs";
|
|
2
|
+
import { ExecutionPlan } from "@prisma-next/framework-components/runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/sql-execution-plan.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* SQL-domain execution plan: a query lowered to the wire-level shape that a
|
|
7
|
+
* SQL driver can run.
|
|
8
|
+
*
|
|
9
|
+
* The plan carries:
|
|
10
|
+
* - `sql` — the rendered SQL text
|
|
11
|
+
* - `params` — the bound parameter list
|
|
12
|
+
* - `ast` — optional pre-lowering AST, retained for telemetry / debugging
|
|
13
|
+
* - `meta` — family-agnostic plan metadata (target, lane, hashes, ...)
|
|
14
|
+
* - `_row` — phantom row type, propagated from the originating `SqlQueryPlan`
|
|
15
|
+
*
|
|
16
|
+
* Extends the framework-level `ExecutionPlan<Row>` marker so generic SPIs
|
|
17
|
+
* (`RuntimeExecutor<SqlExecutionPlan>`, `RuntimeMiddleware<SqlExecutionPlan>`)
|
|
18
|
+
* can be parameterized over it.
|
|
19
|
+
*
|
|
20
|
+
* Co-located with `SqlQueryPlan` (its pre-lowering counterpart) in the lanes
|
|
21
|
+
* layer because lane-level utilities (`RawTemplateFactory`, `RawFactory`,
|
|
22
|
+
* `SqlPlan`) compose against the executable shape and the lanes layer cannot
|
|
23
|
+
* depend on the runtime layer.
|
|
24
|
+
*/
|
|
25
|
+
interface SqlExecutionPlan<Row = unknown> extends ExecutionPlan<Row> {
|
|
26
|
+
readonly sql: string;
|
|
27
|
+
readonly params: readonly unknown[];
|
|
28
|
+
readonly ast?: AnyQueryAst;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { SqlExecutionPlan as t };
|
|
32
|
+
//# sourceMappingURL=sql-execution-plan-ffz8TSfr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-execution-plan-ffz8TSfr.d.mts","names":[],"sources":["../src/sql-execution-plan.ts"],"mappings":";;;;;;AAuBA;;;;;;;;;;;;;;;;;;UAAiB,gBAAA,wBAAwC,aAAA,CAAc,GAAA;EAAA,SAC5D,GAAA;EAAA,SACA,MAAA;EAAA,SACA,GAAA,GAAM,WAAA;AAAA"}
|