@prisma-next/sql-builder 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{db-875GHteW.d.mts → db-Tp8O0y-a.d.mts} +8 -3
- package/dist/{db-875GHteW.d.mts.map → db-Tp8O0y-a.d.mts.map} +1 -1
- package/dist/exports/types.d.mts +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/index.mjs +45 -24
- package/dist/runtime/index.mjs.map +1 -1
- package/package.json +15 -16
- package/src/exports/types.ts +1 -1
- package/src/runtime/mutation-impl.ts +71 -48
- package/src/runtime/table-proxy-impl.ts +43 -5
- package/src/types/table-proxy.ts +23 -6
|
@@ -323,6 +323,10 @@ type ResolvedInsertValues<C, Table extends StorageTable, TableName extends strin
|
|
|
323
323
|
type ResolvedUpdateValues<C, Table extends StorageTable, TableName extends string, CT extends Record<string, {
|
|
324
324
|
readonly input: unknown;
|
|
325
325
|
}>, FieldInputs extends Record<string, Record<string, unknown>>> = ResolvedInsertValues<C, Table, TableName, CT, FieldInputs>;
|
|
326
|
+
type ResolvedUpdateExpressions<Table extends StorageTable> = { [K in keyof Table['columns']]?: Expression$1<{
|
|
327
|
+
codecId: Table['columns'][K]['codecId'];
|
|
328
|
+
nullable: boolean;
|
|
329
|
+
}> };
|
|
326
330
|
type ContractToQC<C extends TableProxyContract, Name extends string = string> = {
|
|
327
331
|
readonly codecTypes: ExtractCodecTypes<C>;
|
|
328
332
|
readonly capabilities: C['capabilities'];
|
|
@@ -331,8 +335,9 @@ type ContractToQC<C extends TableProxyContract, Name extends string = string> =
|
|
|
331
335
|
};
|
|
332
336
|
interface TableProxy<C extends TableProxyContract, Name extends string & keyof UnboundTables<C>, Alias extends string = Name, AvailableScope extends Scope = DefaultScope<Name, UnboundTables<C>[Name]>, QC extends QueryContext = ContractToQC<C, Name>> extends JoinSource<StorageTableToScopeTable<UnboundTables<C>[Name]>, Alias>, WithSelect<QC, AvailableScope, EmptyRow>, WithJoin<QC, AvailableScope, C['capabilities']> {
|
|
333
337
|
as<NewAlias extends string>(newAlias: NewAlias): TableProxy<C, Name, NewAlias, RebindScope<AvailableScope, Alias, NewAlias>>;
|
|
334
|
-
insert(
|
|
338
|
+
insert(rows: ReadonlyArray<ResolvedInsertValues<C, UnboundTables<C>[Name], Name, QC['codecTypes'], ExtractFieldInputTypes<C>>>): InsertQuery<QC, AvailableScope, EmptyRow>;
|
|
335
339
|
update(set: ResolvedUpdateValues<C, UnboundTables<C>[Name], Name, QC['codecTypes'], ExtractFieldInputTypes<C>>): UpdateQuery<QC, AvailableScope, EmptyRow>;
|
|
340
|
+
update(callback: (fields: FieldProxy<AvailableScope>, fns: Functions<QC>) => ResolvedUpdateExpressions<UnboundTables<C>[Name]>): UpdateQuery<QC, AvailableScope, EmptyRow>;
|
|
336
341
|
delete(): DeleteQuery<QC, AvailableScope, EmptyRow>;
|
|
337
342
|
}
|
|
338
343
|
//#endregion
|
|
@@ -351,5 +356,5 @@ type TableNamesAcrossNamespaces<C extends TableProxyContract> = { [NSId in keyof
|
|
|
351
356
|
type TableInAnyNamespace<C extends TableProxyContract, Name extends string> = { [NSId in keyof C['storage']['namespaces']]: Name extends keyof C['storage']['namespaces'][NSId]['tables'] ? C['storage']['namespaces'][NSId]['tables'][Name] : never }[keyof C['storage']['namespaces']];
|
|
352
357
|
type Db<C extends TableProxyContract> = { [Name in TableNamesAcrossNamespaces<C>]: TableProxy<C, Name> };
|
|
353
358
|
//#endregion
|
|
354
|
-
export {
|
|
355
|
-
//# sourceMappingURL=db-
|
|
359
|
+
export { Scope as _, GroupedQuery as a, UpdateQuery as c, BooleanCodecType as d, Expression$1 as f, QueryContext as g, GatedMethod as h, SelectQuery as i, ResolveRow as l, Functions as m, TableProxyContract as n, DeleteQuery as o, FieldProxy as p, TableProxy as r, InsertQuery as s, Db as t, AggregateFunctions as u, ScopeField as v, Subquery as y };
|
|
360
|
+
//# sourceMappingURL=db-Tp8O0y-a.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-875GHteW.d.mts","names":[],"sources":["../src/scope.ts","../src/expression.ts","../src/resolve.ts","../src/types/mutation-query.ts","../src/types/joined-tables.ts","../src/types/grouped-query.ts","../src/types/select-query.ts","../src/types/shared.ts","../src/types/table-proxy.ts","../src/types/db.ts"],"mappings":";;;;;;;KASY,WAAA,mCAA8C,YAAA,SAAqB,QAAA,GAC3E,MAAA;AAAA,cAGiB,cAAA;AAAA,cACA,cAAA;AAAA,KAET,MAAA,oBAA0B,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KAChC,QAAA,GAAW,MAAA,QAAc,UAAA;AAAA,KAEzB,UAAA,GAAa,MAAA,SAAe,UAAA;AAAA,KAE5B,KAAA;EACV,QAAA,EAAU,UAAA;EACV,UAAA,EAAY,MAAA,SAAe,UAAA;AAAA;AAAA,KAGjB,UAAA,aAAuB,UAAA;EAAA,UACvB,cAAA;IACR,QAAA,EAAU,GAAA;IACV,UAAA,EAAY,MAAA,CAAO,KAAA,EAAO,GAAA;EAAA;EAG5B,iBAAA,IAAqB,KAAA;EACrB,QAAA,IAAY,aAAA;AAAA;AAAA,KAGF,YAAA,oCAAgD,cAAA;EAC1D,QAAA,EAAU,wBAAA,CAAyB,KAAA;EACnC,UAAA,UACQ,IAAA,GAAO,wBAAA,CAAyB,KAAA;AAAA;AAAA,KAI9B,wBAAA,WAAmC,cAAA,kBACjC,CAAA;EACV,OAAA,EAAS,CAAA,YAAa,CAAA;EACtB,QAAA,EAAU,CAAA,YAAa,CAAA;AAAA;AAAA,KAIf,WAAA,WAAsB,KAAA,YAAiB,KAAA;EACjD,QAAA,EAAU,MAAA,CACR,IAAA,CAAK,CAAA,oBAAqB,CAAA,gBAAiB,IAAA,CAAK,CAAA,oBAAqB,CAAA;EAEvE,UAAA,EAAY,MAAA,CAAO,CAAA,iBAAkB,CAAA;AAAA;AAAA,KAG3B,W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AAA,CACE,GAAA,EAAK,oBAAA,CACH,CAAA,EACA,aAAA,CAAc,CAAA,EAAG,IAAA,GACjB,IAAA,EACA,EAAA,gBACA,sBAAA,CAAuB,CAAA,KAExB,WAAA,CAAY,EAAA,EAAI,cAAA,EAAgB,QAAA;EAEnC,MAAA,IAAU,WAAA,CAAY,EAAA,EAAI,cAAA,EAAgB,QAAA;AAAA;;;KCtJhC,gBAAA,GAAmB,MAAA,SAAe,MAAA;AAAA,KAQlC,kBAAA;EAAA,SACD,OAAA;IAAA,SACE,UAAA,EAAY,QAAA,CACnB,MAAA;MAAA,SAA0B,MAAA,EAAQ,QAAA,CAAS,MAAA,SAAe,YAAA;IAAA;EAAA;EAAA,SAGrD,YAAA,EAAc,gBAAA;AAAA;AAAA,KAKb,aAAA,WAAwB,kBAAA,wBAChB,0BAAA,CAA2B,CAAA,IAAK,mBAAA,CAAoB,CAAA,EAAG,IAAA;AAAA,KAGtE,0BAAA,WAAqC,kBAAA,qBACzB,CAAA,kCAAmC,CAAA,0BAA2B,IAAA,6BAEvE,CAAA;AAAA,KAEH,mBAAA,WAA8B,kBAAA,0CAClB,CAAA,4BAA6B,IAAA,eAAmB,CAAA,0BAA2B,IAAA,cACtF,CAAA,0BAA2B,IAAA,YAAgB,IAAA,kBAEzC,CAAA;AAAA,KAEI,EAAA,WAAa,kBAAA,eACd,0BAAA,CAA2B,CAAA,IAAK,UAAA,CAAW,CAAA,EAAG,IAAA"}
|
|
1
|
+
{"version":3,"file":"db-Tp8O0y-a.d.mts","names":[],"sources":["../src/scope.ts","../src/expression.ts","../src/resolve.ts","../src/types/mutation-query.ts","../src/types/joined-tables.ts","../src/types/grouped-query.ts","../src/types/select-query.ts","../src/types/shared.ts","../src/types/table-proxy.ts","../src/types/db.ts"],"mappings":";;;;;;;KASY,WAAA,mCAA8C,YAAA,SAAqB,QAAA,GAC3E,MAAA;AAAA,cAGiB,cAAA;AAAA,cACA,cAAA;AAAA,KAET,MAAA,oBAA0B,CAAA,GA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,CAAU,EAAA,MACZ,yBAAA,CAA0B,aAAA,CAAc,CAAA,EAAG,IAAA,KAC/C,WAAA,CAAY,EAAA,EAAI,cAAA,EAAgB,QAAA;EAEnC,MAAA,IAAU,WAAA,CAAY,EAAA,EAAI,cAAA,EAAgB,QAAA;AAAA;;;KCvKhC,gBAAA,GAAmB,MAAA,SAAe,MAAA;AAAA,KAQlC,kBAAA;EAAA,SACD,OAAA;IAAA,SACE,UAAA,EAAY,QAAA,CACnB,MAAA;MAAA,SAA0B,MAAA,EAAQ,QAAA,CAAS,MAAA,SAAe,YAAA;IAAA;EAAA;EAAA,SAGrD,YAAA,EAAc,gBAAA;AAAA;AAAA,KAKb,aAAA,WAAwB,kBAAA,wBAChB,0BAAA,CAA2B,CAAA,IAAK,mBAAA,CAAoB,CAAA,EAAG,IAAA;AAAA,KAGtE,0BAAA,WAAqC,kBAAA,qBACzB,CAAA,kCAAmC,CAAA,0BAA2B,IAAA,6BAEvE,CAAA;AAAA,KAEH,mBAAA,WAA8B,kBAAA,0CAClB,CAAA,4BAA6B,IAAA,eAAmB,CAAA,0BAA2B,IAAA,cACtF,CAAA,0BAA2B,IAAA,YAAgB,IAAA,kBAEzC,CAAA;AAAA,KAEI,EAAA,WAAa,kBAAA,eACd,0BAAA,CAA2B,CAAA,IAAK,UAAA,CAAW,CAAA,EAAG,IAAA"}
|
package/dist/exports/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { type AggregateFunctions, type Db, type DeleteQuery, type Expression, type Functions, type GatedMethod, type GroupedQuery, type InsertQuery, type QueryContext, type ResolveRow, type Scope, type ScopeField, type SelectQuery, type Subquery, type TableProxy, type TableProxyContract, type UpdateQuery };
|
|
1
|
+
import { _ as Scope, a as GroupedQuery, c as UpdateQuery, d as BooleanCodecType, f as Expression, g as QueryContext, h as GatedMethod, i as SelectQuery, l as ResolveRow, m as Functions, n as TableProxyContract, o as DeleteQuery, r as TableProxy, s as InsertQuery, t as Db, u as AggregateFunctions, v as ScopeField, y as Subquery } from "../db-Tp8O0y-a.mjs";
|
|
2
|
+
export { type AggregateFunctions, type BooleanCodecType, type Db, type DeleteQuery, type Expression, type Functions, type GatedMethod, type GroupedQuery, type InsertQuery, type QueryContext, type ResolveRow, type Scope, type ScopeField, type SelectQuery, type Subquery, type TableProxy, type TableProxyContract, type UpdateQuery };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as Scope, a as GroupedQuery, c as UpdateQuery, f as Expression, g as QueryContext, h as GatedMethod, i as SelectQuery, l as ResolveRow, m as Functions, o as DeleteQuery, r as TableProxy, s as InsertQuery, t as Db, u as AggregateFunctions, v as ScopeField, y as Subquery } from "./db-Tp8O0y-a.mjs";
|
|
2
2
|
export { type AggregateFunctions, type Db, type DeleteQuery, type Expression, type Functions, type GatedMethod, type GroupedQuery, type InsertQuery, type QueryContext, type ResolveRow, type Scope, type ScopeField, type SelectQuery, type Subquery, type TableProxy, type UpdateQuery };
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as Scope, g as QueryContext, m as Functions, n as TableProxyContract, p as FieldProxy, t as Db, u as AggregateFunctions, v as ScopeField } from "../db-Tp8O0y-a.mjs";
|
|
2
2
|
import { AnyExpression } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
import { Expression } from "@prisma-next/sql-relational-core/expression";
|
|
4
4
|
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -644,20 +644,38 @@ function buildReturningProjections(tableName, columns, rowFields) {
|
|
|
644
644
|
function evaluateWhere(whereCallback, scope, queryOperationTypes) {
|
|
645
645
|
return whereCallback(createFieldProxy(scope), createFunctions(queryOperationTypes)).buildAst();
|
|
646
646
|
}
|
|
647
|
+
function evaluateUpdateCallback(callback, scope, queryOperationTypes) {
|
|
648
|
+
const result = callback(createFieldProxy(scope), createFunctions(queryOperationTypes));
|
|
649
|
+
const set = {};
|
|
650
|
+
for (const [col, expr] of Object.entries(result)) if (expr !== void 0) set[col] = expr.buildAst();
|
|
651
|
+
return set;
|
|
652
|
+
}
|
|
653
|
+
function buildSetExpressions(exprs, table, tableName, op, ctx) {
|
|
654
|
+
const set = { ...exprs };
|
|
655
|
+
for (const def of ctx.applyMutationDefaults({
|
|
656
|
+
op,
|
|
657
|
+
table: tableName,
|
|
658
|
+
values: exprs
|
|
659
|
+
})) if (!(def.column in set)) {
|
|
660
|
+
const codec = table.columns[def.column] ? codecRefFor(ctx, tableName, def.column) : void 0;
|
|
661
|
+
set[def.column] = ParamRef.of(def.value, ifDefined("codec", codec));
|
|
662
|
+
}
|
|
663
|
+
return set;
|
|
664
|
+
}
|
|
647
665
|
var InsertQueryImpl = class InsertQueryImpl extends BuilderBase {
|
|
648
666
|
#tableName;
|
|
649
667
|
#table;
|
|
650
668
|
#scope;
|
|
651
|
-
#
|
|
669
|
+
#rows;
|
|
652
670
|
#returningColumns;
|
|
653
671
|
#rowFields;
|
|
654
672
|
#annotations;
|
|
655
|
-
constructor(tableName, table, scope,
|
|
673
|
+
constructor(tableName, table, scope, rows, ctx, returningColumns = [], rowFields = {}, annotations = /* @__PURE__ */ new Map()) {
|
|
656
674
|
super(ctx);
|
|
657
675
|
this.#tableName = tableName;
|
|
658
676
|
this.#table = table;
|
|
659
677
|
this.#scope = scope;
|
|
660
|
-
this.#
|
|
678
|
+
this.#rows = rows;
|
|
661
679
|
this.#returningColumns = returningColumns;
|
|
662
680
|
this.#rowFields = rowFields;
|
|
663
681
|
this.#annotations = annotations;
|
|
@@ -669,7 +687,7 @@ var InsertQueryImpl = class InsertQueryImpl extends BuilderBase {
|
|
|
669
687
|
if (!field) throw new Error(`Column "${col}" not found in scope`);
|
|
670
688
|
newRowFields[col] = field;
|
|
671
689
|
}
|
|
672
|
-
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, this.#
|
|
690
|
+
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, this.#rows, this.ctx, columns, newRowFields, this.#annotations);
|
|
673
691
|
});
|
|
674
692
|
/**
|
|
675
693
|
* Attach one or more write-typed annotations to this query plan.
|
|
@@ -679,37 +697,37 @@ var InsertQueryImpl = class InsertQueryImpl extends BuilderBase {
|
|
|
679
697
|
* in `./query-impl.ts` for the read-builder counterpart.
|
|
680
698
|
*/
|
|
681
699
|
annotate(...annotations) {
|
|
682
|
-
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, this.#
|
|
700
|
+
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, this.#rows, this.ctx, this.#returningColumns, this.#rowFields, mergeWriteAnnotations(this.#annotations, annotations));
|
|
683
701
|
}
|
|
684
702
|
build() {
|
|
685
|
-
|
|
686
|
-
|
|
703
|
+
if (this.#rows.length === 0) throw new Error("insert() called with an empty row array — at least one row is required");
|
|
704
|
+
const paramRows = this.#rows.map((rowValues) => buildParamValues(rowValues, this.#table, this.#tableName, "create", this.ctx));
|
|
705
|
+
let ast = InsertAst.into(TableSource.named(this.#tableName)).withRows(paramRows);
|
|
687
706
|
if (this.#returningColumns.length > 0) ast = ast.withReturning(buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields));
|
|
688
707
|
return buildQueryPlan(ast, this.ctx, this.#annotations);
|
|
689
708
|
}
|
|
690
709
|
};
|
|
691
710
|
var UpdateQueryImpl = class UpdateQueryImpl extends BuilderBase {
|
|
692
711
|
#tableName;
|
|
693
|
-
#table;
|
|
694
712
|
#scope;
|
|
695
|
-
#
|
|
696
|
-
#
|
|
713
|
+
#setExpressions;
|
|
714
|
+
#whereExprs;
|
|
697
715
|
#returningColumns;
|
|
698
716
|
#rowFields;
|
|
699
717
|
#annotations;
|
|
700
|
-
constructor(tableName,
|
|
718
|
+
constructor(tableName, scope, setExpressions, ctx, whereExprs = [], returningColumns = [], rowFields = {}, annotations = /* @__PURE__ */ new Map()) {
|
|
701
719
|
super(ctx);
|
|
702
720
|
this.#tableName = tableName;
|
|
703
|
-
this.#table = table;
|
|
704
721
|
this.#scope = scope;
|
|
705
|
-
this.#
|
|
706
|
-
this.#
|
|
722
|
+
this.#setExpressions = setExpressions;
|
|
723
|
+
this.#whereExprs = whereExprs;
|
|
707
724
|
this.#returningColumns = returningColumns;
|
|
708
725
|
this.#rowFields = rowFields;
|
|
709
726
|
this.#annotations = annotations;
|
|
710
727
|
}
|
|
711
728
|
where(expr) {
|
|
712
|
-
|
|
729
|
+
const result = expr(createFieldProxy(this.#scope), createFunctions(this.ctx.queryOperationTypes));
|
|
730
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, this.#setExpressions, this.ctx, [...this.#whereExprs, result.buildAst()], this.#returningColumns, this.#rowFields, this.#annotations);
|
|
713
731
|
}
|
|
714
732
|
returning = this._gate({ sql: { returning: true } }, "returning", (...columns) => {
|
|
715
733
|
const newRowFields = {};
|
|
@@ -718,7 +736,7 @@ var UpdateQueryImpl = class UpdateQueryImpl extends BuilderBase {
|
|
|
718
736
|
if (!field) throw new Error(`Column "${col}" not found in scope`);
|
|
719
737
|
newRowFields[col] = field;
|
|
720
738
|
}
|
|
721
|
-
return new UpdateQueryImpl(this.#tableName, this.#
|
|
739
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, this.#setExpressions, this.ctx, this.#whereExprs, columns, newRowFields, this.#annotations);
|
|
722
740
|
});
|
|
723
741
|
/**
|
|
724
742
|
* Attach one or more write-typed annotations to this query plan.
|
|
@@ -726,12 +744,10 @@ var UpdateQueryImpl = class UpdateQueryImpl extends BuilderBase {
|
|
|
726
744
|
* fails closed for callers that bypass the type-level gate.
|
|
727
745
|
*/
|
|
728
746
|
annotate(...annotations) {
|
|
729
|
-
return new UpdateQueryImpl(this.#tableName, this.#
|
|
747
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, this.#setExpressions, this.ctx, this.#whereExprs, this.#returningColumns, this.#rowFields, mergeWriteAnnotations(this.#annotations, annotations));
|
|
730
748
|
}
|
|
731
749
|
build() {
|
|
732
|
-
|
|
733
|
-
const whereExpr = combineWhereExprs(this.#whereCallbacks.map((cb) => evaluateWhere(cb, this.#scope, this.ctx.queryOperationTypes)));
|
|
734
|
-
let ast = UpdateAst.table(TableSource.named(this.#tableName)).withSet(setParams).withWhere(whereExpr);
|
|
750
|
+
let ast = UpdateAst.table(TableSource.named(this.#tableName)).withSet(this.#setExpressions).withWhere(combineWhereExprs(this.#whereExprs));
|
|
735
751
|
if (this.#returningColumns.length > 0) ast = ast.withReturning(buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields));
|
|
736
752
|
return buildQueryPlan(ast, this.ctx, this.#annotations);
|
|
737
753
|
}
|
|
@@ -825,11 +841,16 @@ var TableProxyImpl = class TableProxyImpl extends BuilderBase {
|
|
|
825
841
|
outerFullJoin(other, on) {
|
|
826
842
|
return this.#toJoined().outerFullJoin(other, on);
|
|
827
843
|
}
|
|
828
|
-
insert(
|
|
829
|
-
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope,
|
|
844
|
+
insert(rows) {
|
|
845
|
+
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, rows, this.ctx);
|
|
830
846
|
}
|
|
831
|
-
update(
|
|
832
|
-
|
|
847
|
+
update(setOrCallback) {
|
|
848
|
+
if (typeof setOrCallback === "function") {
|
|
849
|
+
const setExpressions = buildSetExpressions(evaluateUpdateCallback(setOrCallback, this.#scope, this.ctx.queryOperationTypes), this.#table, this.#tableName, "update", this.ctx);
|
|
850
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, setExpressions, this.ctx);
|
|
851
|
+
}
|
|
852
|
+
const setExpressions = buildParamValues(setOrCallback, this.#table, this.#tableName, "update", this.ctx);
|
|
853
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, setExpressions, this.ctx);
|
|
833
854
|
}
|
|
834
855
|
delete() {
|
|
835
856
|
return new DeleteQueryImpl(this.#tableName, this.#scope, this.ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#state","#buildLateral","#addLateralJoin","#addJoin","#tableName","#table","#scope","#values","#returningColumns","#rowFields","#annotations","#setValues","#whereCallbacks","#tableName","#table","#fromSource","#scope","#toJoined"],"sources":["../../src/runtime/expression-impl.ts","../../src/runtime/field-proxy.ts","../../src/runtime/functions.ts","../../../../../1-framework/0-foundation/utils/dist/defined-BYcWqtXq.mjs","../../src/runtime/builder-base.ts","../../src/runtime/query-impl.ts","../../src/runtime/joined-tables-impl.ts","../../src/runtime/mutation-impl.ts","../../src/runtime/table-proxy-impl.ts","../../src/runtime/sql.ts"],"sourcesContent":["import type { CodecRef } from '@prisma-next/framework-components/codec';\nimport type { AnyExpression as AstExpression } from '@prisma-next/sql-relational-core/ast';\nimport type { Expression } from '@prisma-next/sql-relational-core/expression';\nimport type { ScopeField } from '../scope';\n\n/**\n * Runtime wrapper around a relational-core AST expression node. Carries ScopeField metadata (codecId, nullable) so aggregate-like combinators can propagate the input codec onto their result.\n *\n * `codec` records the column-bound {@link CodecRef} when the field-proxy knows the binding — both the namespaced form (`f.user.email` → `ColumnRef`) and the top-level shortcut (`f.email` → `IdentifierRef`) stamp the ref derived from contract storage. `codecOf(expression)` exposes it for operation implementations forwarding the ref to `toExpr`.\n */\nexport class ExpressionImpl<T extends ScopeField = ScopeField> implements Expression<T> {\n private readonly ast: AstExpression;\n readonly returnType: T;\n readonly codec: CodecRef | undefined;\n\n constructor(ast: AstExpression, returnType: T, codec?: CodecRef) {\n this.ast = ast;\n this.returnType = returnType;\n this.codec = codec;\n }\n\n buildAst(): AstExpression {\n return this.ast;\n }\n}\n","import { ColumnRef, IdentifierRef } from '@prisma-next/sql-relational-core/ast';\nimport type { FieldProxy } from '../expression';\nimport type { Scope, ScopeTable } from '../scope';\nimport { ExpressionImpl } from './expression-impl';\n\nexport function createFieldProxy<S extends Scope>(scope: S): FieldProxy<S> {\n return new Proxy({} as FieldProxy<S>, {\n get(_target, prop: string) {\n if (Object.hasOwn(scope.topLevel, prop)) {\n const topField = scope.topLevel[prop];\n if (topField) {\n return new ExpressionImpl(IdentifierRef.of(prop), topField, topField.codec);\n }\n }\n\n if (Object.hasOwn(scope.namespaces, prop)) {\n const nsFields = scope.namespaces[prop];\n if (nsFields) return createNamespaceProxy(prop, nsFields);\n }\n\n return undefined;\n },\n });\n}\n\nfunction createNamespaceProxy(\n namespaceName: string,\n fields: ScopeTable,\n): Record<string, ExpressionImpl> {\n return new Proxy({} as Record<string, ExpressionImpl>, {\n get(_target, prop: string) {\n if (Object.hasOwn(fields, prop)) {\n const field = fields[prop];\n if (field) return new ExpressionImpl(ColumnRef.of(namespaceName, prop), field, field.codec);\n }\n return undefined;\n },\n });\n}\n","import type { SqlOperationEntry } from '@prisma-next/sql-operations';\nimport {\n AggregateExpr,\n AndExpr,\n type AnyExpression as AstExpression,\n BinaryExpr,\n type BinaryOp,\n type CodecRef,\n ExistsExpr,\n ListExpression,\n LiteralExpr,\n NullCheckExpr,\n OrExpr,\n SubqueryExpr,\n} from '@prisma-next/sql-relational-core/ast';\nimport { codecOf, toExpr } from '@prisma-next/sql-relational-core/expression';\nimport type {\n AggregateFunctions,\n AggregateOnlyFunctions,\n BooleanCodecType,\n BuiltinFunctions,\n CodecExpression,\n Expression,\n Functions,\n} from '../expression';\nimport type { QueryContext, ScopeField, Subquery } from '../scope';\nimport { ExpressionImpl } from './expression-impl';\n\ntype CodecTypes = Record<string, { readonly input: unknown }>;\n// Runtime-level ExprOrVal — accepts any codec, any nullability. Concrete codec typing lives on the public BuiltinFunctions surface in `../expression`.\ntype ExprOrVal<CodecId extends string = string, N extends boolean = boolean> = CodecExpression<\n CodecId,\n N,\n CodecTypes\n>;\n\nconst BOOL_FIELD: BooleanCodecType = { codecId: 'pg/bool@1', nullable: false };\n\nconst resolve = toExpr;\n\n/**\n * Resolve a binary-comparison operand into an AST expression, threading the column-bound side's {@link CodecRef} to the raw-value side.\n *\n * For `fns.eq(f.email, 'alice@example.com')`, `f.email` is the column-bound expression carrying a `ColumnRef` AST and a `CodecRef` derived from contract storage; the raw string operand has no codec context. By deriving the codec context from the column-bound side and forwarding it via `toExpr(value, codec)`, the resulting `ParamRef` carries the `CodecRef` that encode-side dispatch needs to materialise the per-instance codec for parameterized codec ids (`vector(1024)` vs. `vector(1536)`).\n */\nfunction resolveOperand(operand: ExprOrVal, otherCodec?: CodecRef): AstExpression {\n if (isExpressionLike(operand)) return operand.buildAst();\n return toExpr(operand, otherCodec);\n}\n\nfunction isExpressionLike(\n value: unknown,\n): value is { buildAst: () => AstExpression; returnType?: { codecId: string } } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'buildAst' in value &&\n typeof (value as { buildAst: unknown }).buildAst === 'function'\n );\n}\n\n/**\n * Resolves an Expression via `buildAst()`, or wraps a raw value as a `LiteralExpr` — an SQL literal inlined into the query text, not a bound parameter.\n *\n * Used for `and` / `or` operands. The usual operand is an `Expression<bool>` (e.g. the result of `fns.eq`), which this function passes through by calling `buildAst()`. The only time the raw-value branch fires is when the caller writes `fns.and(true, x)` or similar — inlining `TRUE`/`FALSE` literals lets the SQL planner statically simplify `TRUE AND x` to `x`, which it cannot do for an opaque `ParamRef`.\n */\nfunction toLiteralExpr(value: unknown): AstExpression {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'buildAst' in value &&\n typeof (value as { buildAst: unknown }).buildAst === 'function'\n ) {\n return (value as { buildAst(): AstExpression }).buildAst();\n }\n return new LiteralExpr(value);\n}\n\nfunction boolExpr(astNode: AstExpression): ExpressionImpl<BooleanCodecType> {\n return new ExpressionImpl(astNode, BOOL_FIELD);\n}\n\nfunction binaryWithSharedCodec(\n a: ExprOrVal,\n b: ExprOrVal,\n build: (left: AstExpression, right: AstExpression) => AstExpression,\n): AstExpression {\n const aCodec = codecOf(a);\n const bCodec = codecOf(b);\n const left = resolveOperand(a, bCodec);\n const right = resolveOperand(b, aCodec);\n return build(left, right);\n}\n\nfunction eq(a: ExprOrVal, b: ExprOrVal): ExpressionImpl<BooleanCodecType> {\n if (b === null) return boolExpr(NullCheckExpr.isNull(resolve(a)));\n if (a === null) return boolExpr(NullCheckExpr.isNull(resolve(b)));\n return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr('eq', l, r)));\n}\n\nfunction ne(a: ExprOrVal, b: ExprOrVal): ExpressionImpl<BooleanCodecType> {\n if (b === null) return boolExpr(NullCheckExpr.isNotNull(resolve(a)));\n if (a === null) return boolExpr(NullCheckExpr.isNotNull(resolve(b)));\n return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr('neq', l, r)));\n}\n\nfunction comparison(a: ExprOrVal, b: ExprOrVal, op: BinaryOp): ExpressionImpl<BooleanCodecType> {\n return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr(op, l, r)));\n}\n\nfunction inOrNotIn(\n expr: Expression<ScopeField>,\n valuesOrSubquery: Subquery<Record<string, ScopeField>> | ExprOrVal[],\n op: 'in' | 'notIn',\n): ExpressionImpl<BooleanCodecType> {\n const left = expr.buildAst();\n const leftCodec = codecOf(expr);\n const binaryFn = op === 'in' ? BinaryExpr.in : BinaryExpr.notIn;\n\n if (Array.isArray(valuesOrSubquery)) {\n const refs = valuesOrSubquery.map((v) => resolveOperand(v, leftCodec));\n return boolExpr(binaryFn(left, ListExpression.of(refs)));\n }\n return boolExpr(binaryFn(left, SubqueryExpr.of(valuesOrSubquery.buildAst())));\n}\n\nfunction numericAgg(\n fn: 'sum' | 'avg' | 'min' | 'max',\n expr: Expression<ScopeField>,\n): ExpressionImpl<{ codecId: string; nullable: true }> {\n return new ExpressionImpl(AggregateExpr[fn](expr.buildAst()), {\n codecId: expr.returnType.codecId,\n nullable: true as const,\n });\n}\n\nfunction createBuiltinFunctions() {\n return {\n eq: (a: ExprOrVal, b: ExprOrVal) => eq(a, b),\n ne: (a: ExprOrVal, b: ExprOrVal) => ne(a, b),\n gt: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'gt'),\n gte: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'gte'),\n lt: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'lt'),\n lte: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'lte'),\n and: (...exprs: ExprOrVal<'pg/bool@1', boolean>[]) =>\n boolExpr(AndExpr.of(exprs.map(toLiteralExpr))),\n or: (...exprs: ExprOrVal<'pg/bool@1', boolean>[]) =>\n boolExpr(OrExpr.of(exprs.map(toLiteralExpr))),\n exists: (subquery: Subquery<Record<string, ScopeField>>) =>\n boolExpr(ExistsExpr.exists(subquery.buildAst())),\n notExists: (subquery: Subquery<Record<string, ScopeField>>) =>\n boolExpr(ExistsExpr.notExists(subquery.buildAst())),\n in: (\n expr: Expression<ScopeField>,\n valuesOrSubquery: Subquery<Record<string, ScopeField>> | ExprOrVal[],\n ) => inOrNotIn(expr, valuesOrSubquery, 'in'),\n notIn: (\n expr: Expression<ScopeField>,\n valuesOrSubquery: Subquery<Record<string, ScopeField>> | ExprOrVal[],\n ) => inOrNotIn(expr, valuesOrSubquery, 'notIn'),\n } satisfies BuiltinFunctions<CodecTypes>;\n}\n\nfunction createAggregateOnlyFunctions() {\n return {\n count: (expr?: Expression<ScopeField>) => {\n const astExpr = expr ? expr.buildAst() : undefined;\n return new ExpressionImpl(AggregateExpr.count(astExpr), {\n codecId: 'pg/int8@1',\n nullable: false,\n });\n },\n sum: (expr: Expression<ScopeField>) => numericAgg('sum', expr),\n avg: (expr: Expression<ScopeField>) => numericAgg('avg', expr),\n min: (expr: Expression<ScopeField>) => numericAgg('min', expr),\n max: (expr: Expression<ScopeField>) => numericAgg('max', expr),\n } satisfies AggregateOnlyFunctions;\n}\n\nexport function createFunctions<QC extends QueryContext>(\n operations: Readonly<Record<string, SqlOperationEntry>>,\n): Functions<QC> {\n const builtins = createBuiltinFunctions();\n\n return new Proxy({} as Functions<QC>, {\n get(_target, prop: string) {\n const builtin = (builtins as Record<string, unknown>)[prop];\n if (builtin) return builtin;\n\n const op = operations[prop];\n if (op) return op.impl;\n return undefined;\n },\n });\n}\n\nexport function createAggregateFunctions<QC extends QueryContext>(\n operations: Readonly<Record<string, SqlOperationEntry>>,\n): AggregateFunctions<QC> {\n const baseFns = createFunctions<QC>(operations);\n const aggregates = createAggregateOnlyFunctions();\n\n return new Proxy({} as AggregateFunctions<QC>, {\n get(_target, prop: string) {\n const agg = (aggregates as Record<string, unknown>)[prop];\n if (agg) return agg;\n\n return (baseFns as Record<string, unknown>)[prop];\n },\n });\n}\n","//#region src/defined.ts\n/**\n* Returns an object with the key/value if value is defined, otherwise an empty object.\n*\n* Use with spread to conditionally include optional properties while satisfying\n* exactOptionalPropertyTypes. This is explicit about which properties are optional\n* and won't inadvertently strip other undefined values.\n*\n* @example\n* ```typescript\n* // Instead of:\n* const obj = {\n* required: 'value',\n* ...(optional ? { optional } : {}),\n* };\n*\n* // Use:\n* const obj = {\n* required: 'value',\n* ...ifDefined('optional', optional),\n* };\n* ```\n*/\nfunction ifDefined(key, value) {\n\treturn value !== void 0 ? { [key]: value } : {};\n}\n//#endregion\nexport { ifDefined as t };\n\n//# sourceMappingURL=defined-BYcWqtXq.mjs.map","import type { PlanMeta } from '@prisma-next/contract/types';\nimport type { CodecRef } from '@prisma-next/framework-components/codec';\nimport type { AnnotationValue, OperationKind } from '@prisma-next/framework-components/runtime';\nimport type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';\nimport type { SqlOperationEntry } from '@prisma-next/sql-operations';\nimport {\n AndExpr,\n type AnyExpression as AstExpression,\n collectOrderedParamRefs,\n IdentifierRef,\n type LimitOffsetValue,\n OrderByItem,\n ProjectionItem,\n SelectAst,\n type TableSource,\n} from '@prisma-next/sql-relational-core/ast';\nimport { codecRefForStorageColumn } from '@prisma-next/sql-relational-core/codec-descriptor-registry';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n AppliedMutationDefault,\n MutationDefaultsOptions,\n} from '@prisma-next/sql-relational-core/query-lane-context';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type {\n AggregateFunctions,\n Expression,\n FieldProxy,\n OrderByOptions,\n OrderByScope,\n} from '../expression';\nimport type {\n GatedMethod,\n MergeScopes,\n NullableScope,\n QueryContext,\n Scope,\n ScopeField,\n ScopeTable,\n} from '../scope';\nimport { createFieldProxy } from './field-proxy';\nimport { createAggregateFunctions, createFunctions } from './functions';\n\nexport type ExprCallback = (fields: FieldProxy<Scope>, fns: unknown) => Expression<ScopeField>;\n\nexport class BuilderBase<Capabilities = unknown> {\n protected readonly ctx: BuilderContext;\n\n constructor(ctx: BuilderContext) {\n this.ctx = ctx;\n }\n\n protected _gate<Req extends Record<string, Record<string, boolean>>, Args extends unknown[], R>(\n required: Req,\n methodName: string,\n method: (...args: Args) => R,\n ): GatedMethod<Capabilities, Req, (...args: Args) => R> {\n return ((...args: Args): R => {\n assertCapability(this.ctx, required, methodName);\n return method(...args);\n }) as GatedMethod<Capabilities, Req, (...args: Args) => R>;\n }\n}\n\nexport interface BuilderState {\n readonly from: TableSource;\n readonly joins: readonly import('@prisma-next/sql-relational-core/ast').JoinAst[];\n readonly projections: readonly ProjectionItem[];\n readonly where: readonly AstExpression[];\n readonly orderBy: readonly OrderByItem[];\n readonly groupBy: readonly AstExpression[];\n readonly having: AstExpression | undefined;\n readonly limit: LimitOffsetValue | undefined;\n readonly offset: LimitOffsetValue | undefined;\n readonly distinct: true | undefined;\n readonly distinctOn: readonly AstExpression[] | undefined;\n readonly scope: Scope;\n readonly rowFields: Record<string, ScopeField>;\n /**\n * Annotations accumulated through `.annotate(...)` calls. Stored as\n * a `Map<namespace, AnnotationValue>` so duplicate namespaces\n * last-write-win. Empty on a fresh state.\n */\n readonly annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n}\n\nexport interface BuilderContext {\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly queryOperationTypes: Readonly<Record<string, SqlOperationEntry>>;\n readonly target: string;\n readonly storageHash: string;\n /**\n * Contract storage carried by the builder context so column-bound `ParamRef` / `ProjectionItem` construction sites can derive a {@link CodecRef} for each `(table, column)` via {@link codecRefFor}. Builder paths that mint AST nodes without storage (rare — tests, ad-hoc lower paths) leave it undefined; the codec slot then stays `undefined` on the resulting nodes.\n */\n readonly storage: SqlStorage | undefined;\n readonly applyMutationDefaults: (\n options: MutationDefaultsOptions,\n ) => ReadonlyArray<AppliedMutationDefault>;\n}\n\n/**\n * Derive the canonical {@link CodecRef} for a `(table, column)` from the builder context's storage. Returns `undefined` when the builder context has no storage attached or when the column is unknown to the contract.\n */\nexport function codecRefFor(\n ctx: BuilderContext,\n tableName: string,\n columnName: string,\n): CodecRef | undefined {\n if (!ctx.storage) return undefined;\n return codecRefForStorageColumn(ctx.storage, tableName, columnName);\n}\n\nexport function emptyState(from: TableSource, scope: Scope): BuilderState {\n return {\n from,\n joins: [],\n projections: [],\n where: [],\n orderBy: [],\n groupBy: [],\n having: undefined,\n limit: undefined,\n offset: undefined,\n distinct: undefined,\n distinctOn: undefined,\n scope,\n rowFields: {},\n annotations: new Map(),\n };\n}\n\nexport function cloneState(state: BuilderState, overrides: Partial<BuilderState>): BuilderState {\n return { ...state, ...overrides };\n}\n\nexport function combineWhereExprs(exprs: readonly AstExpression[]): AstExpression | undefined {\n if (exprs.length === 0) return undefined;\n if (exprs.length === 1) return exprs[0];\n return AndExpr.of(exprs);\n}\n\nexport function buildSelectAst(state: BuilderState): SelectAst {\n const where = combineWhereExprs(state.where);\n return new SelectAst({\n from: state.from,\n joins: state.joins.length > 0 ? state.joins : undefined,\n projection: state.projections,\n where,\n orderBy: state.orderBy.length > 0 ? state.orderBy : undefined,\n distinct: state.distinct,\n distinctOn: state.distinctOn && state.distinctOn.length > 0 ? state.distinctOn : undefined,\n groupBy: state.groupBy.length > 0 ? state.groupBy : undefined,\n having: state.having,\n limit: state.limit,\n offset: state.offset,\n selectAllIntent: undefined,\n });\n}\n\nexport function buildQueryPlan<Row = unknown>(\n ast: import('@prisma-next/sql-relational-core/ast').AnyQueryAst,\n ctx: BuilderContext,\n annotations?: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>,\n): SqlQueryPlan<Row> {\n const paramValues = collectOrderedParamRefs(ast).map((r) =>\n r.kind === 'param-ref' ? r.value : undefined,\n );\n\n // SQL DSL has no framework-reserved namespace keys (e.g. `codecs`) in\n // scope at `.build()` time, so user annotations land verbatim here. The\n // ORM dispatch path — which compiles to plans that may already carry\n // reserved keys — enforces the precedence rule in `mergeAnnotations`\n // (`sql-orm-client/src/query-plan-meta.ts`).\n const annotationsRecord =\n annotations !== undefined && annotations.size > 0\n ? Object.freeze(Object.fromEntries(annotations))\n : undefined;\n const meta: PlanMeta = Object.freeze({\n target: ctx.target,\n storageHash: ctx.storageHash,\n lane: 'dsl',\n ...ifDefined('annotations', annotationsRecord),\n });\n\n return Object.freeze({ ast, params: paramValues, meta });\n}\n\nexport function buildPlan<Row = unknown>(\n state: BuilderState,\n ctx: BuilderContext,\n): SqlQueryPlan<Row> {\n return buildQueryPlan<Row>(buildSelectAst(state), ctx, state.annotations);\n}\n\nexport function tableToScope(\n alias: string,\n table: StorageTable,\n options?: { readonly storage?: SqlStorage | undefined; readonly tableName?: string | undefined },\n): Scope {\n const storage = options?.storage;\n const lookupName = options?.tableName;\n const fields: ScopeTable = {};\n for (const [colName, col] of Object.entries(table.columns)) {\n const codec =\n storage && lookupName ? codecRefForStorageColumn(storage, lookupName, colName) : undefined;\n fields[colName] = {\n codecId: col.codecId,\n nullable: col.nullable,\n ...(codec !== undefined ? { codec } : {}),\n };\n }\n return { topLevel: { ...fields }, namespaces: { [alias]: fields } };\n}\n\nexport function mergeScopes<A extends Scope, B extends Scope>(a: A, b: B): MergeScopes<A, B> {\n const topLevel: ScopeTable = {};\n for (const [k, v] of Object.entries(a.topLevel)) {\n if (!(k in b.topLevel)) topLevel[k] = v;\n }\n for (const [k, v] of Object.entries(b.topLevel)) {\n if (!(k in a.topLevel)) topLevel[k] = v;\n }\n return {\n topLevel,\n namespaces: { ...a.namespaces, ...b.namespaces },\n } as MergeScopes<A, B>;\n}\n\nexport function nullableScope<S extends Scope>(scope: S): NullableScope<S> {\n const mkNullable = (tbl: ScopeTable): ScopeTable => {\n const result: ScopeTable = {};\n for (const [k, v] of Object.entries(tbl)) {\n result[k] = {\n codecId: v.codecId,\n nullable: true,\n ...(v.codec !== undefined ? { codec: v.codec } : {}),\n };\n }\n return result;\n };\n const namespaces: Record<string, ScopeTable> = {};\n for (const [k, v] of Object.entries(scope.namespaces)) {\n namespaces[k] = mkNullable(v);\n }\n return { topLevel: mkNullable(scope.topLevel), namespaces } as NullableScope<S>;\n}\n\nexport function orderByScopeOf<S extends Scope, R extends Record<string, ScopeField>>(\n scope: S,\n rowFields: R,\n): OrderByScope<S, R> {\n return {\n topLevel: { ...scope.topLevel, ...rowFields },\n namespaces: scope.namespaces,\n };\n}\n\nexport function assertCapability(\n ctx: BuilderContext,\n required: Record<string, Record<string, boolean>>,\n methodName: string,\n): void {\n for (const [ns, keys] of Object.entries(required)) {\n for (const key of Object.keys(keys)) {\n if (!ctx.capabilities[ns]?.[key]) {\n throw new Error(`${methodName}() requires capability ${ns}.${key}`);\n }\n }\n }\n}\n\nexport function resolveSelectArgs(\n args: unknown[],\n scope: Scope,\n ctx: BuilderContext,\n): { projections: ProjectionItem[]; newRowFields: Record<string, ScopeField> } {\n const projections: ProjectionItem[] = [];\n const newRowFields: Record<string, ScopeField> = {};\n\n if (args.length === 0) return { projections, newRowFields };\n\n if (typeof args[0] === 'string' && (args.length === 1 || typeof args[1] !== 'function')) {\n for (const colName of args as string[]) {\n const field = scope.topLevel[colName];\n if (!field) throw new Error(`Column \"${colName}\" not found in scope`);\n projections.push(ProjectionItem.of(colName, IdentifierRef.of(colName), field.codec));\n newRowFields[colName] = field;\n }\n return { projections, newRowFields };\n }\n\n if (typeof args[0] === 'string' && typeof args[1] === 'function') {\n const alias = args[0] as string;\n const exprFn = args[1] as (\n f: FieldProxy<Scope>,\n fns: AggregateFunctions<QueryContext>,\n ) => Expression<ScopeField>;\n const fns = createAggregateFunctions(ctx.queryOperationTypes);\n const result = exprFn(createFieldProxy(scope), fns);\n const field = result.returnType;\n projections.push(ProjectionItem.of(alias, result.buildAst(), field.codec));\n newRowFields[alias] = field;\n return { projections, newRowFields };\n }\n\n if (typeof args[0] === 'function') {\n const callbackFn = args[0] as (\n f: FieldProxy<Scope>,\n fns: AggregateFunctions<QueryContext>,\n ) => Record<string, Expression<ScopeField>>;\n const fns = createAggregateFunctions(ctx.queryOperationTypes);\n const record = callbackFn(createFieldProxy(scope), fns);\n for (const [key, expr] of Object.entries(record)) {\n const field = expr.returnType;\n projections.push(ProjectionItem.of(key, expr.buildAst(), field.codec));\n newRowFields[key] = field;\n }\n return { projections, newRowFields };\n }\n\n throw new Error('Invalid .select() arguments');\n}\n\nexport function resolveOrderBy(\n arg: unknown,\n options: OrderByOptions | undefined,\n scope: Scope,\n rowFields: Record<string, ScopeField>,\n ctx: BuilderContext,\n useAggregateFns: boolean,\n): OrderByItem {\n const dir = options?.direction ?? 'asc';\n\n if (typeof arg === 'string') {\n const combined = orderByScopeOf(scope, rowFields);\n if (!(arg in combined.topLevel))\n throw new Error(`Column \"${arg}\" not found in scope for orderBy`);\n const expr = IdentifierRef.of(arg);\n return dir === 'asc' ? OrderByItem.asc(expr) : OrderByItem.desc(expr);\n }\n\n if (typeof arg === 'function') {\n const combined = orderByScopeOf(scope, rowFields);\n const fns = useAggregateFns\n ? createAggregateFunctions(ctx.queryOperationTypes)\n : createFunctions(ctx.queryOperationTypes);\n const result = (arg as ExprCallback)(createFieldProxy(combined), fns);\n return dir === 'asc' ? OrderByItem.asc(result.buildAst()) : OrderByItem.desc(result.buildAst());\n }\n\n throw new Error('Invalid orderBy argument');\n}\n\nexport function resolveGroupBy(\n args: unknown[],\n scope: Scope,\n rowFields: Record<string, ScopeField>,\n ctx: BuilderContext,\n): AstExpression[] {\n if (typeof args[0] === 'string') {\n const combined = orderByScopeOf(scope, rowFields);\n return (args as string[]).map((colName) => {\n if (!(colName in combined.topLevel))\n throw new Error(`Column \"${colName}\" not found in scope for groupBy`);\n return IdentifierRef.of(colName);\n });\n }\n\n if (typeof args[0] === 'function') {\n const combined = orderByScopeOf(scope, rowFields);\n const fns = createFunctions(ctx.queryOperationTypes);\n const result = (args[0] as ExprCallback)(createFieldProxy(combined), fns);\n return [result.buildAst()];\n }\n\n throw new Error('Invalid groupBy arguments');\n}\n\nexport function resolveDistinctOn(\n args: unknown[],\n scope: Scope,\n rowFields: Record<string, ScopeField>,\n ctx: BuilderContext,\n): AstExpression[] {\n if (args.length === 1 && typeof args[0] === 'function') {\n const combined = orderByScopeOf(scope, rowFields);\n const fns = createFunctions(ctx.queryOperationTypes);\n const result = (args[0] as ExprCallback)(createFieldProxy(combined), fns);\n return [result.buildAst()];\n }\n const combined = orderByScopeOf(scope, rowFields);\n return (args as string[]).map((colName) => {\n if (!(colName in combined.topLevel))\n throw new Error(`Column \"${colName}\" not found in scope for distinctOn`);\n return IdentifierRef.of(colName);\n });\n}\n","import type {\n AnnotationValue,\n OperationKind,\n ValidAnnotations,\n} from '@prisma-next/framework-components/runtime';\nimport { assertAnnotationsApplicable } from '@prisma-next/framework-components/runtime';\nimport { DerivedTableSource, type SelectAst } from '@prisma-next/sql-relational-core/ast';\nimport { toExpr } from '@prisma-next/sql-relational-core/expression';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n AggregateFunctions,\n BooleanCodecType,\n Expression,\n ExpressionBuilder,\n ExtractScopeFields,\n FieldProxy,\n Functions,\n OrderByOptions,\n OrderByScope,\n WithField,\n WithFields,\n} from '../expression';\nimport type { ResolveRow } from '../resolve';\nimport type {\n Expand,\n JoinOuterScope,\n JoinSource,\n QueryContext,\n Scope,\n ScopeField,\n // biome-ignore lint/correctness/noUnusedImports: used in `declare` property\n SubqueryMarker,\n} from '../scope';\nimport type { GroupedQuery } from '../types/grouped-query';\nimport type { SelectQuery } from '../types/select-query';\nimport type { PaginationValue } from '../types/shared';\nimport {\n BuilderBase,\n type BuilderContext,\n type BuilderState,\n buildPlan,\n buildSelectAst,\n cloneState,\n orderByScopeOf,\n resolveDistinctOn,\n resolveGroupBy,\n resolveOrderBy,\n resolveSelectArgs,\n} from './builder-base';\nimport { createFieldProxy } from './field-proxy';\nimport { createAggregateFunctions, createFunctions } from './functions';\n\nabstract class QueryBase<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n> extends BuilderBase<QC['capabilities']> {\n protected readonly state: BuilderState;\n\n constructor(state: BuilderState, ctx: BuilderContext) {\n super(ctx);\n this.state = state;\n }\n\n protected abstract clone(state: BuilderState): this;\n\n distinctOn = this._gate(\n { postgres: { distinctOn: true } },\n 'distinctOn',\n (...args: unknown[]) => {\n const exprs = resolveDistinctOn(args, this.state.scope, this.state.rowFields, this.ctx);\n return this.clone(\n cloneState(this.state, {\n distinctOn: [...(this.state.distinctOn ?? []), ...exprs],\n }),\n );\n },\n );\n\n limit(count: PaginationValue<QC>): this {\n const limit = typeof count === 'number' ? count : toExpr(count);\n return this.clone(cloneState(this.state, { limit }));\n }\n\n offset(count: PaginationValue<QC>): this {\n const offset = typeof count === 'number' ? count : toExpr(count);\n return this.clone(cloneState(this.state, { offset }));\n }\n\n distinct(): this {\n return this.clone(cloneState(this.state, { distinct: true }));\n }\n\n /**\n * Attach one or more annotations to this query plan.\n *\n * Read builders (`SelectQueryImpl`, `GroupedQueryImpl`) accept\n * annotations whose declared `applicableTo` includes `'read'`.\n * The type-level `As & ValidAnnotations<'read', As>` gate rejects\n * write-only annotations at the call site; the runtime check below\n * fails closed for callers that bypass the type gate (cast / `any`).\n *\n * Multiple `.annotate(...)` calls compose; duplicate namespaces use\n * last-write-wins. The accumulated annotations are merged into\n * `plan.meta.annotations` at `.build()` time, alongside any framework-\n * internal metadata under reserved namespaces (e.g. `codecs`).\n *\n * Chainable in any position (before / after `.where`, `.select`,\n * `.limit`, etc.); the returned builder has the same row type.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'read', As>\n ): this {\n assertAnnotationsApplicable(\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n 'read',\n 'sql-dsl.annotate',\n );\n const next = new Map(this.state.annotations);\n for (const annotation of annotations as readonly AnnotationValue<unknown, OperationKind>[]) {\n next.set(annotation.namespace, annotation);\n }\n return this.clone(cloneState(this.state, { annotations: next }));\n }\n\n groupBy(\n ...fields: ((keyof RowType | keyof AvailableScope['topLevel']) & string)[]\n ): GroupedQuery<QC, AvailableScope, RowType>;\n groupBy(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: Functions<QC>,\n ) => Expression<ScopeField>,\n ): GroupedQuery<QC, AvailableScope, RowType>;\n groupBy(...args: unknown[]): unknown {\n const exprs = resolveGroupBy(args, this.state.scope, this.state.rowFields, this.ctx);\n return new GroupedQueryImpl<QC, AvailableScope, RowType>(\n cloneState(this.state, { groupBy: [...this.state.groupBy, ...exprs] }),\n this.ctx,\n );\n }\n\n as<Alias extends string>(alias: Alias): JoinSource<RowType, Alias> {\n const ast = buildSelectAst(this.state);\n const derivedSource = DerivedTableSource.as(alias, ast);\n const scope = {\n topLevel: this.state.rowFields as RowType,\n namespaces: { [alias]: this.state.rowFields } as Record<Alias, RowType>,\n };\n return {\n getJoinOuterScope: () => scope,\n buildAst: () => derivedSource,\n\n // `as unknown` is necessary, because JoinOuterScope is a phantom type-only property that does not exist at runtime\n } satisfies Omit<JoinSource<RowType, Alias>, typeof JoinOuterScope> as unknown as JoinSource<\n RowType,\n Alias\n >;\n }\n\n getRowFields(): Record<string, ScopeField> {\n return this.state.rowFields;\n }\n\n buildAst(): SelectAst {\n return buildSelectAst(this.state);\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n return buildPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n this.state,\n this.ctx,\n );\n }\n}\n\nexport class SelectQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends QueryBase<QC, AvailableScope, RowType>\n implements SelectQuery<QC, AvailableScope, RowType>\n{\n declare readonly [SubqueryMarker]: RowType;\n\n protected clone(state: BuilderState): this {\n return new SelectQueryImpl<QC, AvailableScope, RowType>(state, this.ctx) as this;\n }\n\n select<Columns extends (keyof AvailableScope['topLevel'] & string)[]>(\n ...columns: Columns\n ): SelectQuery<QC, AvailableScope, WithFields<RowType, AvailableScope['topLevel'], Columns>>;\n select<Alias extends string, Field extends ScopeField>(\n alias: Alias,\n expr: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Expression<Field>,\n ): SelectQuery<QC, AvailableScope, WithField<RowType, Field, Alias>>;\n select<Result extends Record<string, Expression<ScopeField>>>(\n callback: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Result,\n ): SelectQuery<QC, AvailableScope, Expand<RowType & ExtractScopeFields<Result>>>;\n select(...args: unknown[]): unknown {\n const { projections, newRowFields } = resolveSelectArgs(args, this.state.scope, this.ctx);\n return new SelectQueryImpl(\n cloneState(this.state, {\n projections: [...this.state.projections, ...projections],\n rowFields: { ...this.state.rowFields, ...newRowFields },\n }),\n this.ctx,\n );\n }\n\n where(expr: ExpressionBuilder<AvailableScope, QC>): SelectQuery<QC, AvailableScope, RowType> {\n const fieldProxy = createFieldProxy(this.state.scope);\n const fns = createFunctions<QC>(this.ctx.queryOperationTypes);\n const result = (expr as ExpressionBuilder<Scope, QueryContext>)(fieldProxy, fns as never);\n return new SelectQueryImpl(\n cloneState(this.state, {\n where: [...this.state.where, result.buildAst()],\n }),\n this.ctx,\n );\n }\n\n orderBy(\n field: (keyof RowType | keyof AvailableScope['topLevel']) & string,\n options?: OrderByOptions,\n ): SelectQuery<QC, AvailableScope, RowType>;\n orderBy(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: Functions<QC>,\n ) => Expression<ScopeField>,\n options?: OrderByOptions,\n ): SelectQuery<QC, AvailableScope, RowType>;\n orderBy(arg: unknown, options?: OrderByOptions): unknown {\n const item = resolveOrderBy(\n arg,\n options,\n this.state.scope,\n this.state.rowFields,\n this.ctx,\n false,\n );\n return this.clone(cloneState(this.state, { orderBy: [...this.state.orderBy, item] }));\n }\n}\n\nexport class GroupedQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends QueryBase<QC, AvailableScope, RowType>\n implements GroupedQuery<QC, AvailableScope, RowType>\n{\n declare readonly [SubqueryMarker]: RowType;\n\n protected clone(state: BuilderState): this {\n return new GroupedQueryImpl<QC, AvailableScope, RowType>(state, this.ctx) as this;\n }\n\n having(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: AggregateFunctions<QC>,\n ) => Expression<BooleanCodecType>,\n ): GroupedQuery<QC, AvailableScope, RowType> {\n const combined = orderByScopeOf(\n this.state.scope as AvailableScope,\n this.state.rowFields as RowType,\n );\n const fns = createAggregateFunctions(this.ctx.queryOperationTypes);\n const result = expr(createFieldProxy(combined), fns);\n return new GroupedQueryImpl(cloneState(this.state, { having: result.buildAst() }), this.ctx);\n }\n\n orderBy(\n field: (keyof RowType | keyof AvailableScope['topLevel']) & string,\n options?: OrderByOptions,\n ): GroupedQuery<QC, AvailableScope, RowType>;\n orderBy(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: AggregateFunctions<QC>,\n ) => Expression<ScopeField>,\n options?: OrderByOptions,\n ): GroupedQuery<QC, AvailableScope, RowType>;\n orderBy(arg: unknown, options?: OrderByOptions): unknown {\n const item = resolveOrderBy(\n arg,\n options,\n this.state.scope,\n this.state.rowFields,\n this.ctx,\n true,\n );\n return this.clone(cloneState(this.state, { orderBy: [...this.state.orderBy, item] }));\n }\n}\n","import {\n AndExpr,\n DerivedTableSource,\n JoinAst,\n type TableSource,\n} from '@prisma-next/sql-relational-core/ast';\nimport type {\n AggregateFunctions,\n Expression,\n ExpressionBuilder,\n ExtractScopeFields,\n FieldProxy,\n WithField,\n WithFields,\n} from '../expression';\nimport type {\n EmptyRow,\n Expand,\n JoinOuterScope,\n JoinSource,\n MergeScopes,\n NullableScope,\n QueryContext,\n Scope,\n ScopeField,\n ScopeTable,\n Subquery,\n} from '../scope';\nimport type { JoinedTables } from '../types/joined-tables';\nimport type { SelectQuery } from '../types/select-query';\nimport type { LateralBuilder } from '../types/shared';\nimport {\n BuilderBase,\n type BuilderContext,\n type BuilderState,\n cloneState,\n emptyState,\n mergeScopes,\n nullableScope,\n resolveSelectArgs,\n} from './builder-base';\nimport { createFieldProxy } from './field-proxy';\nimport { createFunctions } from './functions';\nimport { SelectQueryImpl } from './query-impl';\n\nexport class JoinedTablesImpl<QC extends QueryContext, AvailableScope extends Scope>\n extends BuilderBase<QC['capabilities']>\n implements JoinedTables<QC, AvailableScope>\n{\n readonly #state: BuilderState;\n\n constructor(state: BuilderState, ctx: BuilderContext) {\n super(ctx);\n this.#state = state;\n }\n\n lateralJoin = this._gate(\n { sql: { lateral: true } },\n 'lateralJoin',\n <Alias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: Alias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<AvailableScope, { topLevel: LateralRow; namespaces: Record<Alias, LateralRow> }>\n > => {\n const { derivedSource, lateralScope } = this.#buildLateral(alias, builder);\n const resultScope = mergeScopes(\n this.#state.scope as AvailableScope,\n lateralScope as { topLevel: LateralRow; namespaces: Record<Alias, LateralRow> },\n );\n return this.#addLateralJoin('inner', resultScope, derivedSource);\n },\n ) as JoinedTables<QC, AvailableScope>['lateralJoin'];\n\n outerLateralJoin = this._gate(\n { sql: { lateral: true } },\n 'outerLateralJoin',\n <Alias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: Alias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<\n AvailableScope,\n NullableScope<{ topLevel: LateralRow; namespaces: Record<Alias, LateralRow> }>\n >\n > => {\n const { derivedSource, lateralScope } = this.#buildLateral(alias, builder);\n const resultScope = mergeScopes(\n this.#state.scope as AvailableScope,\n nullableScope(\n lateralScope as { topLevel: LateralRow; namespaces: Record<Alias, LateralRow> },\n ),\n );\n return this.#addLateralJoin('left', resultScope, derivedSource);\n },\n ) as JoinedTables<QC, AvailableScope>['outerLateralJoin'];\n\n select<Columns extends (keyof AvailableScope['topLevel'] & string)[]>(\n ...columns: Columns\n ): SelectQuery<QC, AvailableScope, WithFields<EmptyRow, AvailableScope['topLevel'], Columns>>;\n select<Alias extends string, Field extends ScopeField>(\n alias: Alias,\n expr: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Expression<Field>,\n ): SelectQuery<QC, AvailableScope, WithField<EmptyRow, Field, Alias>>;\n select<Result extends Record<string, Expression<ScopeField>>>(\n callback: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Result,\n ): SelectQuery<QC, AvailableScope, Expand<ExtractScopeFields<Result>>>;\n select(...args: unknown[]): unknown {\n const { projections, newRowFields } = resolveSelectArgs(args, this.#state.scope, this.ctx);\n return new SelectQueryImpl<QC, AvailableScope>(\n cloneState(this.#state, {\n projections: [...this.#state.projections, ...projections],\n rowFields: { ...this.#state.rowFields, ...newRowFields },\n }),\n this.ctx,\n );\n }\n\n innerJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>> {\n const targetScope = mergeScopes(\n this.#state.scope as AvailableScope,\n other.getJoinOuterScope() as Other[typeof JoinOuterScope],\n );\n return this.#addJoin(other, 'inner', targetScope, on);\n }\n\n outerLeftJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, NullableScope<Other[typeof JoinOuterScope]>>> {\n const targetScope = mergeScopes(\n this.#state.scope as AvailableScope,\n nullableScope(other.getJoinOuterScope() as Other[typeof JoinOuterScope]),\n );\n return this.#addJoin(other, 'left', targetScope, on);\n }\n\n outerRightJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<NullableScope<AvailableScope>, Other[typeof JoinOuterScope]>> {\n const targetScope = mergeScopes(\n nullableScope(this.#state.scope as AvailableScope),\n other.getJoinOuterScope() as Other[typeof JoinOuterScope],\n );\n return this.#addJoin(other, 'right', targetScope, on);\n }\n\n outerFullJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<\n QC,\n MergeScopes<NullableScope<AvailableScope>, NullableScope<Other[typeof JoinOuterScope]>>\n > {\n const targetScope = mergeScopes(\n nullableScope(this.#state.scope as AvailableScope),\n nullableScope(other.getJoinOuterScope() as Other[typeof JoinOuterScope]),\n );\n return this.#addJoin(other, 'full', targetScope, on);\n }\n\n #addJoin<Other extends JoinSource<ScopeTable, string | never>, ResultScope extends Scope>(\n other: Other,\n joinType: 'inner' | 'left' | 'right' | 'full',\n resultScope: ResultScope,\n onExpr: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, ResultScope> {\n const fieldProxy = createFieldProxy(\n mergeScopes(\n this.#state.scope as AvailableScope,\n other.getJoinOuterScope() as Other[typeof JoinOuterScope],\n ),\n ) as FieldProxy<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>>;\n const fns = createFunctions<QC>(this.ctx.queryOperationTypes);\n const onResult = onExpr(fieldProxy, fns);\n const joinAst = new JoinAst(joinType, other.buildAst(), onResult.buildAst());\n\n return new JoinedTablesImpl(\n cloneState(this.#state, {\n joins: [...this.#state.joins, joinAst],\n scope: resultScope,\n }),\n this.ctx,\n );\n }\n\n #buildLateral(\n alias: string,\n builderFn: (\n lateral: LateralBuilder<QC, AvailableScope>,\n ) => Subquery<Record<string, ScopeField>>,\n ) {\n const lateralBuilder: LateralBuilder<QC, AvailableScope> = {\n from: (other) => {\n const otherScope = other.getJoinOuterScope();\n const parentMerged = mergeScopes(this.#state.scope, otherScope);\n return new SelectQueryImpl(\n emptyState(other.buildAst() as TableSource, parentMerged),\n this.ctx,\n ) as unknown as SelectQuery<QC, AvailableScope, EmptyRow>;\n },\n };\n\n const subquery = builderFn(lateralBuilder);\n const subqueryAst = subquery.buildAst();\n const derivedSource = DerivedTableSource.as(alias, subqueryAst);\n const subqueryRowFields: ScopeTable = subquery.getRowFields();\n const lateralScope: Scope = {\n topLevel: subqueryRowFields,\n namespaces: { [alias]: subqueryRowFields },\n };\n\n return { derivedSource, lateralScope };\n }\n\n #addLateralJoin<ResultScope extends Scope>(\n joinType: 'inner' | 'left',\n resultScope: ResultScope,\n derivedSource: DerivedTableSource,\n ): JoinedTables<QC, ResultScope> {\n const onExpr = AndExpr.of([]);\n const joinAst = new JoinAst(joinType, derivedSource, onExpr, true);\n\n return new JoinedTablesImpl(\n cloneState(this.#state, {\n joins: [...this.#state.joins, joinAst],\n scope: resultScope,\n }),\n this.ctx,\n );\n }\n}\n","import type {\n AnnotationValue,\n OperationKind,\n ValidAnnotations,\n} from '@prisma-next/framework-components/runtime';\nimport { assertAnnotationsApplicable } from '@prisma-next/framework-components/runtime';\nimport type { StorageTable } from '@prisma-next/sql-contract/types';\nimport {\n type AnyExpression as AstExpression,\n ColumnRef,\n DeleteAst,\n InsertAst,\n ParamRef,\n ProjectionItem,\n TableSource,\n UpdateAst,\n} from '@prisma-next/sql-relational-core/ast';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type { MutationDefaultsOp } from '@prisma-next/sql-relational-core/query-lane-context';\nimport type { ExpressionBuilder } from '../expression';\nimport type { ResolveRow } from '../resolve';\nimport type { QueryContext, Scope, ScopeField } from '../scope';\nimport type {\n DeleteQuery,\n InsertQuery,\n ReturningCapability,\n UpdateQuery,\n} from '../types/mutation-query';\nimport {\n BuilderBase,\n type BuilderContext,\n buildQueryPlan,\n codecRefFor,\n combineWhereExprs,\n} from './builder-base';\nimport { createFieldProxy } from './field-proxy';\nimport { createFunctions } from './functions';\n\n/**\n * Validates and merges a variadic annotations call into a builder's\n * accumulated user-annotations map. Used by `.annotate(...)` on each of\n * the three mutation builders (`InsertQueryImpl`, `UpdateQueryImpl`,\n * `DeleteQueryImpl`); the read builders share the same logic via\n * `QueryBase.annotate()` in `./query-impl.ts`.\n *\n * Runs `assertAnnotationsApplicable` at call time (not at `.build()`) so\n * inapplicable annotations forced through casts surface immediately\n * rather than at plan-construction time.\n */\nfunction mergeWriteAnnotations(\n current: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>,\n annotations: readonly AnnotationValue<unknown, OperationKind>[],\n): ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> {\n assertAnnotationsApplicable(annotations, 'write', 'sql-dsl.annotate');\n const next = new Map(current);\n for (const annotation of annotations) {\n next.set(annotation.namespace, annotation);\n }\n return next;\n}\n\ntype WhereCallback = ExpressionBuilder<Scope, QueryContext>;\n\nfunction buildParamValues(\n values: Record<string, unknown>,\n table: StorageTable,\n tableName: string,\n op: MutationDefaultsOp,\n ctx: BuilderContext,\n): Record<string, ParamRef> {\n const params: Record<string, ParamRef> = {};\n for (const [col, value] of Object.entries(values)) {\n const column = table.columns[col];\n const codec = column ? codecRefFor(ctx, tableName, col) : undefined;\n params[col] = ParamRef.of(value, codec ? { codec } : undefined);\n }\n for (const def of ctx.applyMutationDefaults({ op, table: tableName, values })) {\n const column = table.columns[def.column];\n const codec = column ? codecRefFor(ctx, tableName, def.column) : undefined;\n params[def.column] = ParamRef.of(def.value, codec ? { codec } : undefined);\n }\n return params;\n}\n\nfunction buildReturningProjections(\n tableName: string,\n columns: string[],\n rowFields: Record<string, ScopeField>,\n): ProjectionItem[] {\n return columns.map((col) =>\n ProjectionItem.of(col, ColumnRef.of(tableName, col), rowFields[col]?.codec),\n );\n}\n\nfunction evaluateWhere(\n whereCallback: WhereCallback,\n scope: Scope,\n queryOperationTypes: BuilderContext['queryOperationTypes'],\n): AstExpression {\n const fieldProxy = createFieldProxy(scope);\n const fns = createFunctions(queryOperationTypes);\n const result = whereCallback(fieldProxy, fns as never);\n return result.buildAst();\n}\n\nexport class InsertQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends BuilderBase<QC['capabilities']>\n implements InsertQuery<QC, AvailableScope, RowType>\n{\n readonly #tableName: string;\n readonly #table: StorageTable;\n readonly #scope: Scope;\n readonly #values: Record<string, unknown>;\n readonly #returningColumns: string[];\n readonly #rowFields: Record<string, ScopeField>;\n readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n\n constructor(\n tableName: string,\n table: StorageTable,\n scope: Scope,\n values: Record<string, unknown>,\n ctx: BuilderContext,\n returningColumns: string[] = [],\n rowFields: Record<string, ScopeField> = {},\n annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),\n ) {\n super(ctx);\n this.#tableName = tableName;\n this.#table = table;\n this.#scope = scope;\n this.#values = values;\n this.#returningColumns = returningColumns;\n this.#rowFields = rowFields;\n this.#annotations = annotations;\n }\n\n returning = this._gate<ReturningCapability, string[], InsertQuery<QC, AvailableScope, never>>(\n { sql: { returning: true } },\n 'returning',\n (...columns: string[]) => {\n const newRowFields: Record<string, ScopeField> = {};\n for (const col of columns) {\n const field = this.#scope.topLevel[col];\n if (!field) throw new Error(`Column \"${col}\" not found in scope`);\n newRowFields[col] = field;\n }\n return new InsertQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#values,\n this.ctx,\n columns,\n newRowFields,\n this.#annotations,\n ) as unknown as InsertQuery<QC, AvailableScope, never>;\n },\n );\n\n /**\n * Attach one or more write-typed annotations to this query plan.\n * The type-level `As & ValidAnnotations<'write', As>` gate rejects\n * read-only annotations at the call site; the runtime check fails\n * closed for callers that bypass the type gate. See `QueryBase.annotate`\n * in `./query-impl.ts` for the read-builder counterpart.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'write', As>\n ): InsertQuery<QC, AvailableScope, RowType> {\n return new InsertQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#values,\n this.ctx,\n this.#returningColumns,\n this.#rowFields,\n mergeWriteAnnotations(\n this.#annotations,\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n ),\n );\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n const paramValues = buildParamValues(\n this.#values,\n this.#table,\n this.#tableName,\n 'create',\n this.ctx,\n );\n\n let ast = InsertAst.into(TableSource.named(this.#tableName)).withValues(paramValues);\n\n if (this.#returningColumns.length > 0) {\n ast = ast.withReturning(\n buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields),\n );\n }\n\n return buildQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n ast,\n this.ctx,\n this.#annotations,\n );\n }\n}\n\nexport class UpdateQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends BuilderBase<QC['capabilities']>\n implements UpdateQuery<QC, AvailableScope, RowType>\n{\n readonly #tableName: string;\n readonly #table: StorageTable;\n readonly #scope: Scope;\n readonly #setValues: Record<string, unknown>;\n readonly #whereCallbacks: readonly WhereCallback[];\n readonly #returningColumns: string[];\n readonly #rowFields: Record<string, ScopeField>;\n readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n\n constructor(\n tableName: string,\n table: StorageTable,\n scope: Scope,\n setValues: Record<string, unknown>,\n ctx: BuilderContext,\n whereCallbacks: readonly WhereCallback[] = [],\n returningColumns: string[] = [],\n rowFields: Record<string, ScopeField> = {},\n annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),\n ) {\n super(ctx);\n this.#tableName = tableName;\n this.#table = table;\n this.#scope = scope;\n this.#setValues = setValues;\n this.#whereCallbacks = whereCallbacks;\n this.#returningColumns = returningColumns;\n this.#rowFields = rowFields;\n this.#annotations = annotations;\n }\n\n where(expr: ExpressionBuilder<AvailableScope, QC>): UpdateQuery<QC, AvailableScope, RowType> {\n return new UpdateQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#setValues,\n this.ctx,\n [...this.#whereCallbacks, expr as unknown as WhereCallback],\n this.#returningColumns,\n this.#rowFields,\n this.#annotations,\n );\n }\n\n returning = this._gate<ReturningCapability, string[], UpdateQuery<QC, AvailableScope, never>>(\n { sql: { returning: true } },\n 'returning',\n (...columns: string[]) => {\n const newRowFields: Record<string, ScopeField> = {};\n for (const col of columns) {\n const field = this.#scope.topLevel[col];\n if (!field) throw new Error(`Column \"${col}\" not found in scope`);\n newRowFields[col] = field;\n }\n return new UpdateQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#setValues,\n this.ctx,\n this.#whereCallbacks,\n columns,\n newRowFields,\n this.#annotations,\n ) as unknown as UpdateQuery<QC, AvailableScope, never>;\n },\n );\n\n /**\n * Attach one or more write-typed annotations to this query plan.\n * See `InsertQueryImpl.annotate` for semantics; the runtime check\n * fails closed for callers that bypass the type-level gate.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'write', As>\n ): UpdateQuery<QC, AvailableScope, RowType> {\n return new UpdateQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#setValues,\n this.ctx,\n this.#whereCallbacks,\n this.#returningColumns,\n this.#rowFields,\n mergeWriteAnnotations(\n this.#annotations,\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n ),\n );\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n const setParams = buildParamValues(\n this.#setValues,\n this.#table,\n this.#tableName,\n 'update',\n this.ctx,\n );\n\n const whereExpr = combineWhereExprs(\n this.#whereCallbacks.map((cb) =>\n evaluateWhere(cb, this.#scope, this.ctx.queryOperationTypes),\n ),\n );\n\n let ast = UpdateAst.table(TableSource.named(this.#tableName))\n .withSet(setParams)\n .withWhere(whereExpr);\n\n if (this.#returningColumns.length > 0) {\n ast = ast.withReturning(\n buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields),\n );\n }\n\n return buildQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n ast,\n this.ctx,\n this.#annotations,\n );\n }\n}\n\nexport class DeleteQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends BuilderBase<QC['capabilities']>\n implements DeleteQuery<QC, AvailableScope, RowType>\n{\n readonly #tableName: string;\n readonly #scope: Scope;\n readonly #whereCallbacks: readonly WhereCallback[];\n readonly #returningColumns: string[];\n readonly #rowFields: Record<string, ScopeField>;\n readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n\n constructor(\n tableName: string,\n scope: Scope,\n ctx: BuilderContext,\n whereCallbacks: readonly WhereCallback[] = [],\n returningColumns: string[] = [],\n rowFields: Record<string, ScopeField> = {},\n annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),\n ) {\n super(ctx);\n this.#tableName = tableName;\n this.#scope = scope;\n this.#whereCallbacks = whereCallbacks;\n this.#returningColumns = returningColumns;\n this.#rowFields = rowFields;\n this.#annotations = annotations;\n }\n\n where(expr: ExpressionBuilder<AvailableScope, QC>): DeleteQuery<QC, AvailableScope, RowType> {\n return new DeleteQueryImpl(\n this.#tableName,\n this.#scope,\n this.ctx,\n [...this.#whereCallbacks, expr as unknown as WhereCallback],\n this.#returningColumns,\n this.#rowFields,\n this.#annotations,\n );\n }\n\n returning = this._gate<ReturningCapability, string[], DeleteQuery<QC, AvailableScope, never>>(\n { sql: { returning: true } },\n 'returning',\n (...columns: string[]) => {\n const newRowFields: Record<string, ScopeField> = {};\n for (const col of columns) {\n const field = this.#scope.topLevel[col];\n if (!field) throw new Error(`Column \"${col}\" not found in scope`);\n newRowFields[col] = field;\n }\n return new DeleteQueryImpl(\n this.#tableName,\n this.#scope,\n this.ctx,\n this.#whereCallbacks,\n columns,\n newRowFields,\n this.#annotations,\n ) as unknown as DeleteQuery<QC, AvailableScope, never>;\n },\n );\n\n /**\n * Attach one or more write-typed annotations to this query plan.\n * See `InsertQueryImpl.annotate` for semantics.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'write', As>\n ): DeleteQuery<QC, AvailableScope, RowType> {\n return new DeleteQueryImpl(\n this.#tableName,\n this.#scope,\n this.ctx,\n this.#whereCallbacks,\n this.#returningColumns,\n this.#rowFields,\n mergeWriteAnnotations(\n this.#annotations,\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n ),\n );\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n const whereExpr = combineWhereExprs(\n this.#whereCallbacks.map((cb) =>\n evaluateWhere(cb, this.#scope, this.ctx.queryOperationTypes),\n ),\n );\n\n let ast = DeleteAst.from(TableSource.named(this.#tableName)).withWhere(whereExpr);\n\n if (this.#returningColumns.length > 0) {\n ast = ast.withReturning(\n buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields),\n );\n }\n\n return buildQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n ast,\n this.ctx,\n this.#annotations,\n );\n }\n}\n","import type { StorageTable } from '@prisma-next/sql-contract/types';\nimport { type AnyFromSource, TableSource } from '@prisma-next/sql-relational-core/ast';\nimport type {\n AggregateFunctions,\n Expression,\n ExpressionBuilder,\n ExtractScopeFields,\n FieldProxy,\n WithField,\n WithFields,\n} from '../expression';\nimport type {\n EmptyRow,\n Expand,\n JoinOuterScope,\n JoinSource,\n MergeScopes,\n NullableScope,\n QueryContext,\n RebindScope,\n Scope,\n ScopeField,\n ScopeTable,\n StorageTableToScopeTable,\n Subquery,\n} from '../scope';\nimport type { TableProxyContract, UnboundTables } from '../types/db';\nimport type { JoinedTables } from '../types/joined-tables';\nimport type { DeleteQuery, InsertQuery, UpdateQuery } from '../types/mutation-query';\nimport type { SelectQuery } from '../types/select-query';\nimport type { LateralBuilder } from '../types/shared';\nimport type { TableProxy } from '../types/table-proxy';\nimport { BuilderBase, type BuilderContext, emptyState, tableToScope } from './builder-base';\nimport { JoinedTablesImpl } from './joined-tables-impl';\nimport { DeleteQueryImpl, InsertQueryImpl, UpdateQueryImpl } from './mutation-impl';\nimport { SelectQueryImpl } from './query-impl';\n\nexport class TableProxyImpl<\n C extends TableProxyContract,\n Name extends string & keyof UnboundTables<C>,\n Alias extends string,\n AvailableScope extends Scope,\n QC extends QueryContext,\n >\n extends BuilderBase<C['capabilities']>\n implements TableProxy<C, Name, Alias, AvailableScope, QC>\n{\n declare readonly [JoinOuterScope]: JoinSource<\n StorageTableToScopeTable<UnboundTables<C>[Name]>,\n Alias\n >[typeof JoinOuterScope];\n\n readonly #tableName: string;\n readonly #table: StorageTable;\n readonly #fromSource: TableSource;\n readonly #scope: Scope;\n\n constructor(tableName: string, table: StorageTable, alias: string, ctx: BuilderContext) {\n super(ctx);\n this.#tableName = tableName;\n this.#table = table;\n this.#scope = tableToScope(alias, table, { storage: ctx.storage, tableName });\n this.#fromSource = TableSource.named(tableName, alias !== tableName ? alias : undefined);\n }\n\n lateralJoin = this._gate(\n { sql: { lateral: true } },\n 'lateralJoin',\n <LAlias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: LAlias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<AvailableScope, { topLevel: LateralRow; namespaces: Record<LAlias, LateralRow> }>\n > => {\n return this.#toJoined().lateralJoin(alias, builder);\n },\n ) as TableProxy<C, Name, Alias, AvailableScope, QC>['lateralJoin'];\n\n outerLateralJoin = this._gate(\n { sql: { lateral: true } },\n 'outerLateralJoin',\n <LAlias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: LAlias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<\n AvailableScope,\n NullableScope<{ topLevel: LateralRow; namespaces: Record<LAlias, LateralRow> }>\n >\n > => {\n return this.#toJoined().outerLateralJoin(alias, builder);\n },\n ) as TableProxy<C, Name, Alias, AvailableScope, QC>['outerLateralJoin'];\n\n getJoinOuterScope(): Scope {\n return this.#scope;\n }\n\n buildAst(): AnyFromSource {\n return this.#fromSource;\n }\n\n as<NewAlias extends string>(\n newAlias: NewAlias,\n ): TableProxy<C, Name, NewAlias, RebindScope<AvailableScope, Alias, NewAlias>> {\n return new TableProxyImpl(this.#tableName, this.#table, newAlias, this.ctx);\n }\n\n select<Columns extends (keyof AvailableScope['topLevel'] & string)[]>(\n ...columns: Columns\n ): SelectQuery<QC, AvailableScope, WithFields<EmptyRow, AvailableScope['topLevel'], Columns>>;\n select<LAlias extends string, Field extends ScopeField>(\n alias: LAlias,\n expr: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Expression<Field>,\n ): SelectQuery<QC, AvailableScope, WithField<EmptyRow, Field, LAlias>>;\n select<Result extends Record<string, Expression<ScopeField>>>(\n callback: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Result,\n ): SelectQuery<QC, AvailableScope, Expand<ExtractScopeFields<Result>>>;\n select(...args: unknown[]): unknown {\n return new SelectQueryImpl(emptyState(this.#fromSource, this.#scope), this.ctx).select(\n ...(args as string[]),\n );\n }\n\n innerJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>> {\n return this.#toJoined().innerJoin(other, on);\n }\n\n outerLeftJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, NullableScope<Other[typeof JoinOuterScope]>>> {\n return this.#toJoined().outerLeftJoin(other, on);\n }\n\n outerRightJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<NullableScope<AvailableScope>, Other[typeof JoinOuterScope]>> {\n return this.#toJoined().outerRightJoin(other, on);\n }\n\n outerFullJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<\n QC,\n MergeScopes<NullableScope<AvailableScope>, NullableScope<Other[typeof JoinOuterScope]>>\n > {\n return this.#toJoined().outerFullJoin(other, on);\n }\n\n insert(values: Record<string, unknown>): InsertQuery<QC, AvailableScope, EmptyRow> {\n return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, values, this.ctx);\n }\n\n update(set: Record<string, unknown>): UpdateQuery<QC, AvailableScope, EmptyRow> {\n return new UpdateQueryImpl(this.#tableName, this.#table, this.#scope, set, this.ctx);\n }\n\n delete(): DeleteQuery<QC, AvailableScope, EmptyRow> {\n return new DeleteQueryImpl(this.#tableName, this.#scope, this.ctx);\n }\n\n #toJoined(): JoinedTables<QC, AvailableScope> {\n return new JoinedTablesImpl(emptyState(this.#fromSource, this.#scope), this.ctx);\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';\nimport type { ExecutionContext } from '@prisma-next/sql-relational-core/query-lane-context';\nimport type { Db, TableProxyContract } from '../types/db';\nimport type { BuilderContext } from './builder-base';\nimport { TableProxyImpl } from './table-proxy-impl';\n\nexport interface SqlOptions<C extends Contract<SqlStorage> & TableProxyContract> {\n readonly context: ExecutionContext<C>;\n}\n\n// Find a table by name across every declared namespace. Mirrors the\n// flat-DSL contract (db.<tableName>): the first namespace that declares\n// `name` wins. Name collisions across namespaces are a type-level error\n// at the DSL call site; landing the namespace-aware DSL is tracked\n// separately.\nfunction findTableAcrossNamespaces(storage: SqlStorage, name: string): StorageTable | undefined {\n for (const ns of Object.values(storage.namespaces)) {\n const tables = (ns as { tables?: Readonly<Record<string, StorageTable>> }).tables ?? {};\n if (Object.hasOwn(tables, name)) {\n return tables[name];\n }\n }\n return undefined;\n}\n\nexport function sql<C extends Contract<SqlStorage> & TableProxyContract>(\n options: SqlOptions<C>,\n): Db<C> {\n const { context } = options;\n const ctx: BuilderContext = {\n capabilities: context.contract.capabilities,\n queryOperationTypes: context.queryOperations.entries(),\n target: context.contract.target ?? 'unknown',\n storageHash: context.contract.storage.storageHash ?? 'unknown',\n storage: context.contract.storage,\n applyMutationDefaults: (options) => context.applyMutationDefaults(options),\n };\n\n return new Proxy({} as Db<C>, {\n get(_target, prop: string) {\n const table = findTableAcrossNamespaces(context.contract.storage, prop);\n if (table) {\n return new TableProxyImpl(prop, table, pr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,sBAAsB,QAAQ;EAC3E;CAED,OAAO,IAAI,MAAM,EAAE,EAAW,EAC5B,IAAI,SAAS,MAAc;EACzB,MAAM,QAAQ,0BAA0B,QAAQ,SAAS,SAAS,KAAK;EACvE,IAAI,OACF,OAAO,IAAI,eAAe,MAAM,OAAO,MAAM,IAAI;IAItD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#state","#buildLateral","#addLateralJoin","#addJoin","#tableName","#table","#scope","#rows","#returningColumns","#rowFields","#annotations","#setExpressions","#whereExprs","#whereCallbacks","#tableName","#table","#fromSource","#scope","#toJoined"],"sources":["../../src/runtime/expression-impl.ts","../../src/runtime/field-proxy.ts","../../src/runtime/functions.ts","../../../../../1-framework/0-foundation/utils/dist/defined-BYcWqtXq.mjs","../../src/runtime/builder-base.ts","../../src/runtime/query-impl.ts","../../src/runtime/joined-tables-impl.ts","../../src/runtime/mutation-impl.ts","../../src/runtime/table-proxy-impl.ts","../../src/runtime/sql.ts"],"sourcesContent":["import type { CodecRef } from '@prisma-next/framework-components/codec';\nimport type { AnyExpression as AstExpression } from '@prisma-next/sql-relational-core/ast';\nimport type { Expression } from '@prisma-next/sql-relational-core/expression';\nimport type { ScopeField } from '../scope';\n\n/**\n * Runtime wrapper around a relational-core AST expression node. Carries ScopeField metadata (codecId, nullable) so aggregate-like combinators can propagate the input codec onto their result.\n *\n * `codec` records the column-bound {@link CodecRef} when the field-proxy knows the binding — both the namespaced form (`f.user.email` → `ColumnRef`) and the top-level shortcut (`f.email` → `IdentifierRef`) stamp the ref derived from contract storage. `codecOf(expression)` exposes it for operation implementations forwarding the ref to `toExpr`.\n */\nexport class ExpressionImpl<T extends ScopeField = ScopeField> implements Expression<T> {\n private readonly ast: AstExpression;\n readonly returnType: T;\n readonly codec: CodecRef | undefined;\n\n constructor(ast: AstExpression, returnType: T, codec?: CodecRef) {\n this.ast = ast;\n this.returnType = returnType;\n this.codec = codec;\n }\n\n buildAst(): AstExpression {\n return this.ast;\n }\n}\n","import { ColumnRef, IdentifierRef } from '@prisma-next/sql-relational-core/ast';\nimport type { FieldProxy } from '../expression';\nimport type { Scope, ScopeTable } from '../scope';\nimport { ExpressionImpl } from './expression-impl';\n\nexport function createFieldProxy<S extends Scope>(scope: S): FieldProxy<S> {\n return new Proxy({} as FieldProxy<S>, {\n get(_target, prop: string) {\n if (Object.hasOwn(scope.topLevel, prop)) {\n const topField = scope.topLevel[prop];\n if (topField) {\n return new ExpressionImpl(IdentifierRef.of(prop), topField, topField.codec);\n }\n }\n\n if (Object.hasOwn(scope.namespaces, prop)) {\n const nsFields = scope.namespaces[prop];\n if (nsFields) return createNamespaceProxy(prop, nsFields);\n }\n\n return undefined;\n },\n });\n}\n\nfunction createNamespaceProxy(\n namespaceName: string,\n fields: ScopeTable,\n): Record<string, ExpressionImpl> {\n return new Proxy({} as Record<string, ExpressionImpl>, {\n get(_target, prop: string) {\n if (Object.hasOwn(fields, prop)) {\n const field = fields[prop];\n if (field) return new ExpressionImpl(ColumnRef.of(namespaceName, prop), field, field.codec);\n }\n return undefined;\n },\n });\n}\n","import type { SqlOperationEntry } from '@prisma-next/sql-operations';\nimport {\n AggregateExpr,\n AndExpr,\n type AnyExpression as AstExpression,\n BinaryExpr,\n type BinaryOp,\n type CodecRef,\n ExistsExpr,\n ListExpression,\n LiteralExpr,\n NullCheckExpr,\n OrExpr,\n SubqueryExpr,\n} from '@prisma-next/sql-relational-core/ast';\nimport { codecOf, toExpr } from '@prisma-next/sql-relational-core/expression';\nimport type {\n AggregateFunctions,\n AggregateOnlyFunctions,\n BooleanCodecType,\n BuiltinFunctions,\n CodecExpression,\n Expression,\n Functions,\n} from '../expression';\nimport type { QueryContext, ScopeField, Subquery } from '../scope';\nimport { ExpressionImpl } from './expression-impl';\n\ntype CodecTypes = Record<string, { readonly input: unknown }>;\n// Runtime-level ExprOrVal — accepts any codec, any nullability. Concrete codec typing lives on the public BuiltinFunctions surface in `../expression`.\ntype ExprOrVal<CodecId extends string = string, N extends boolean = boolean> = CodecExpression<\n CodecId,\n N,\n CodecTypes\n>;\n\nconst BOOL_FIELD: BooleanCodecType = { codecId: 'pg/bool@1', nullable: false };\n\nconst resolve = toExpr;\n\n/**\n * Resolve a binary-comparison operand into an AST expression, threading the column-bound side's {@link CodecRef} to the raw-value side.\n *\n * For `fns.eq(f.email, 'alice@example.com')`, `f.email` is the column-bound expression carrying a `ColumnRef` AST and a `CodecRef` derived from contract storage; the raw string operand has no codec context. By deriving the codec context from the column-bound side and forwarding it via `toExpr(value, codec)`, the resulting `ParamRef` carries the `CodecRef` that encode-side dispatch needs to materialise the per-instance codec for parameterized codec ids (`vector(1024)` vs. `vector(1536)`).\n */\nfunction resolveOperand(operand: ExprOrVal, otherCodec?: CodecRef): AstExpression {\n if (isExpressionLike(operand)) return operand.buildAst();\n return toExpr(operand, otherCodec);\n}\n\nfunction isExpressionLike(\n value: unknown,\n): value is { buildAst: () => AstExpression; returnType?: { codecId: string } } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'buildAst' in value &&\n typeof (value as { buildAst: unknown }).buildAst === 'function'\n );\n}\n\n/**\n * Resolves an Expression via `buildAst()`, or wraps a raw value as a `LiteralExpr` — an SQL literal inlined into the query text, not a bound parameter.\n *\n * Used for `and` / `or` operands. The usual operand is an `Expression<bool>` (e.g. the result of `fns.eq`), which this function passes through by calling `buildAst()`. The only time the raw-value branch fires is when the caller writes `fns.and(true, x)` or similar — inlining `TRUE`/`FALSE` literals lets the SQL planner statically simplify `TRUE AND x` to `x`, which it cannot do for an opaque `ParamRef`.\n */\nfunction toLiteralExpr(value: unknown): AstExpression {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'buildAst' in value &&\n typeof (value as { buildAst: unknown }).buildAst === 'function'\n ) {\n return (value as { buildAst(): AstExpression }).buildAst();\n }\n return new LiteralExpr(value);\n}\n\nfunction boolExpr(astNode: AstExpression): ExpressionImpl<BooleanCodecType> {\n return new ExpressionImpl(astNode, BOOL_FIELD);\n}\n\nfunction binaryWithSharedCodec(\n a: ExprOrVal,\n b: ExprOrVal,\n build: (left: AstExpression, right: AstExpression) => AstExpression,\n): AstExpression {\n const aCodec = codecOf(a);\n const bCodec = codecOf(b);\n const left = resolveOperand(a, bCodec);\n const right = resolveOperand(b, aCodec);\n return build(left, right);\n}\n\nfunction eq(a: ExprOrVal, b: ExprOrVal): ExpressionImpl<BooleanCodecType> {\n if (b === null) return boolExpr(NullCheckExpr.isNull(resolve(a)));\n if (a === null) return boolExpr(NullCheckExpr.isNull(resolve(b)));\n return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr('eq', l, r)));\n}\n\nfunction ne(a: ExprOrVal, b: ExprOrVal): ExpressionImpl<BooleanCodecType> {\n if (b === null) return boolExpr(NullCheckExpr.isNotNull(resolve(a)));\n if (a === null) return boolExpr(NullCheckExpr.isNotNull(resolve(b)));\n return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr('neq', l, r)));\n}\n\nfunction comparison(a: ExprOrVal, b: ExprOrVal, op: BinaryOp): ExpressionImpl<BooleanCodecType> {\n return boolExpr(binaryWithSharedCodec(a, b, (l, r) => new BinaryExpr(op, l, r)));\n}\n\nfunction inOrNotIn(\n expr: Expression<ScopeField>,\n valuesOrSubquery: Subquery<Record<string, ScopeField>> | ExprOrVal[],\n op: 'in' | 'notIn',\n): ExpressionImpl<BooleanCodecType> {\n const left = expr.buildAst();\n const leftCodec = codecOf(expr);\n const binaryFn = op === 'in' ? BinaryExpr.in : BinaryExpr.notIn;\n\n if (Array.isArray(valuesOrSubquery)) {\n const refs = valuesOrSubquery.map((v) => resolveOperand(v, leftCodec));\n return boolExpr(binaryFn(left, ListExpression.of(refs)));\n }\n return boolExpr(binaryFn(left, SubqueryExpr.of(valuesOrSubquery.buildAst())));\n}\n\nfunction numericAgg(\n fn: 'sum' | 'avg' | 'min' | 'max',\n expr: Expression<ScopeField>,\n): ExpressionImpl<{ codecId: string; nullable: true }> {\n return new ExpressionImpl(AggregateExpr[fn](expr.buildAst()), {\n codecId: expr.returnType.codecId,\n nullable: true as const,\n });\n}\n\nfunction createBuiltinFunctions() {\n return {\n eq: (a: ExprOrVal, b: ExprOrVal) => eq(a, b),\n ne: (a: ExprOrVal, b: ExprOrVal) => ne(a, b),\n gt: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'gt'),\n gte: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'gte'),\n lt: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'lt'),\n lte: (a: ExprOrVal, b: ExprOrVal) => comparison(a, b, 'lte'),\n and: (...exprs: ExprOrVal<'pg/bool@1', boolean>[]) =>\n boolExpr(AndExpr.of(exprs.map(toLiteralExpr))),\n or: (...exprs: ExprOrVal<'pg/bool@1', boolean>[]) =>\n boolExpr(OrExpr.of(exprs.map(toLiteralExpr))),\n exists: (subquery: Subquery<Record<string, ScopeField>>) =>\n boolExpr(ExistsExpr.exists(subquery.buildAst())),\n notExists: (subquery: Subquery<Record<string, ScopeField>>) =>\n boolExpr(ExistsExpr.notExists(subquery.buildAst())),\n in: (\n expr: Expression<ScopeField>,\n valuesOrSubquery: Subquery<Record<string, ScopeField>> | ExprOrVal[],\n ) => inOrNotIn(expr, valuesOrSubquery, 'in'),\n notIn: (\n expr: Expression<ScopeField>,\n valuesOrSubquery: Subquery<Record<string, ScopeField>> | ExprOrVal[],\n ) => inOrNotIn(expr, valuesOrSubquery, 'notIn'),\n } satisfies BuiltinFunctions<CodecTypes>;\n}\n\nfunction createAggregateOnlyFunctions() {\n return {\n count: (expr?: Expression<ScopeField>) => {\n const astExpr = expr ? expr.buildAst() : undefined;\n return new ExpressionImpl(AggregateExpr.count(astExpr), {\n codecId: 'pg/int8@1',\n nullable: false,\n });\n },\n sum: (expr: Expression<ScopeField>) => numericAgg('sum', expr),\n avg: (expr: Expression<ScopeField>) => numericAgg('avg', expr),\n min: (expr: Expression<ScopeField>) => numericAgg('min', expr),\n max: (expr: Expression<ScopeField>) => numericAgg('max', expr),\n } satisfies AggregateOnlyFunctions;\n}\n\nexport function createFunctions<QC extends QueryContext>(\n operations: Readonly<Record<string, SqlOperationEntry>>,\n): Functions<QC> {\n const builtins = createBuiltinFunctions();\n\n return new Proxy({} as Functions<QC>, {\n get(_target, prop: string) {\n const builtin = (builtins as Record<string, unknown>)[prop];\n if (builtin) return builtin;\n\n const op = operations[prop];\n if (op) return op.impl;\n return undefined;\n },\n });\n}\n\nexport function createAggregateFunctions<QC extends QueryContext>(\n operations: Readonly<Record<string, SqlOperationEntry>>,\n): AggregateFunctions<QC> {\n const baseFns = createFunctions<QC>(operations);\n const aggregates = createAggregateOnlyFunctions();\n\n return new Proxy({} as AggregateFunctions<QC>, {\n get(_target, prop: string) {\n const agg = (aggregates as Record<string, unknown>)[prop];\n if (agg) return agg;\n\n return (baseFns as Record<string, unknown>)[prop];\n },\n });\n}\n","//#region src/defined.ts\n/**\n* Returns an object with the key/value if value is defined, otherwise an empty object.\n*\n* Use with spread to conditionally include optional properties while satisfying\n* exactOptionalPropertyTypes. This is explicit about which properties are optional\n* and won't inadvertently strip other undefined values.\n*\n* @example\n* ```typescript\n* // Instead of:\n* const obj = {\n* required: 'value',\n* ...(optional ? { optional } : {}),\n* };\n*\n* // Use:\n* const obj = {\n* required: 'value',\n* ...ifDefined('optional', optional),\n* };\n* ```\n*/\nfunction ifDefined(key, value) {\n\treturn value !== void 0 ? { [key]: value } : {};\n}\n//#endregion\nexport { ifDefined as t };\n\n//# sourceMappingURL=defined-BYcWqtXq.mjs.map","import type { PlanMeta } from '@prisma-next/contract/types';\nimport type { CodecRef } from '@prisma-next/framework-components/codec';\nimport type { AnnotationValue, OperationKind } from '@prisma-next/framework-components/runtime';\nimport type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';\nimport type { SqlOperationEntry } from '@prisma-next/sql-operations';\nimport {\n AndExpr,\n type AnyExpression as AstExpression,\n collectOrderedParamRefs,\n IdentifierRef,\n type LimitOffsetValue,\n OrderByItem,\n ProjectionItem,\n SelectAst,\n type TableSource,\n} from '@prisma-next/sql-relational-core/ast';\nimport { codecRefForStorageColumn } from '@prisma-next/sql-relational-core/codec-descriptor-registry';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n AppliedMutationDefault,\n MutationDefaultsOptions,\n} from '@prisma-next/sql-relational-core/query-lane-context';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type {\n AggregateFunctions,\n Expression,\n FieldProxy,\n OrderByOptions,\n OrderByScope,\n} from '../expression';\nimport type {\n GatedMethod,\n MergeScopes,\n NullableScope,\n QueryContext,\n Scope,\n ScopeField,\n ScopeTable,\n} from '../scope';\nimport { createFieldProxy } from './field-proxy';\nimport { createAggregateFunctions, createFunctions } from './functions';\n\nexport type ExprCallback = (fields: FieldProxy<Scope>, fns: unknown) => Expression<ScopeField>;\n\nexport class BuilderBase<Capabilities = unknown> {\n protected readonly ctx: BuilderContext;\n\n constructor(ctx: BuilderContext) {\n this.ctx = ctx;\n }\n\n protected _gate<Req extends Record<string, Record<string, boolean>>, Args extends unknown[], R>(\n required: Req,\n methodName: string,\n method: (...args: Args) => R,\n ): GatedMethod<Capabilities, Req, (...args: Args) => R> {\n return ((...args: Args): R => {\n assertCapability(this.ctx, required, methodName);\n return method(...args);\n }) as GatedMethod<Capabilities, Req, (...args: Args) => R>;\n }\n}\n\nexport interface BuilderState {\n readonly from: TableSource;\n readonly joins: readonly import('@prisma-next/sql-relational-core/ast').JoinAst[];\n readonly projections: readonly ProjectionItem[];\n readonly where: readonly AstExpression[];\n readonly orderBy: readonly OrderByItem[];\n readonly groupBy: readonly AstExpression[];\n readonly having: AstExpression | undefined;\n readonly limit: LimitOffsetValue | undefined;\n readonly offset: LimitOffsetValue | undefined;\n readonly distinct: true | undefined;\n readonly distinctOn: readonly AstExpression[] | undefined;\n readonly scope: Scope;\n readonly rowFields: Record<string, ScopeField>;\n /**\n * Annotations accumulated through `.annotate(...)` calls. Stored as\n * a `Map<namespace, AnnotationValue>` so duplicate namespaces\n * last-write-win. Empty on a fresh state.\n */\n readonly annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n}\n\nexport interface BuilderContext {\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly queryOperationTypes: Readonly<Record<string, SqlOperationEntry>>;\n readonly target: string;\n readonly storageHash: string;\n /**\n * Contract storage carried by the builder context so column-bound `ParamRef` / `ProjectionItem` construction sites can derive a {@link CodecRef} for each `(table, column)` via {@link codecRefFor}. Builder paths that mint AST nodes without storage (rare — tests, ad-hoc lower paths) leave it undefined; the codec slot then stays `undefined` on the resulting nodes.\n */\n readonly storage: SqlStorage | undefined;\n readonly applyMutationDefaults: (\n options: MutationDefaultsOptions,\n ) => ReadonlyArray<AppliedMutationDefault>;\n}\n\n/**\n * Derive the canonical {@link CodecRef} for a `(table, column)` from the builder context's storage. Returns `undefined` when the builder context has no storage attached or when the column is unknown to the contract.\n */\nexport function codecRefFor(\n ctx: BuilderContext,\n tableName: string,\n columnName: string,\n): CodecRef | undefined {\n if (!ctx.storage) return undefined;\n return codecRefForStorageColumn(ctx.storage, tableName, columnName);\n}\n\nexport function emptyState(from: TableSource, scope: Scope): BuilderState {\n return {\n from,\n joins: [],\n projections: [],\n where: [],\n orderBy: [],\n groupBy: [],\n having: undefined,\n limit: undefined,\n offset: undefined,\n distinct: undefined,\n distinctOn: undefined,\n scope,\n rowFields: {},\n annotations: new Map(),\n };\n}\n\nexport function cloneState(state: BuilderState, overrides: Partial<BuilderState>): BuilderState {\n return { ...state, ...overrides };\n}\n\nexport function combineWhereExprs(exprs: readonly AstExpression[]): AstExpression | undefined {\n if (exprs.length === 0) return undefined;\n if (exprs.length === 1) return exprs[0];\n return AndExpr.of(exprs);\n}\n\nexport function buildSelectAst(state: BuilderState): SelectAst {\n const where = combineWhereExprs(state.where);\n return new SelectAst({\n from: state.from,\n joins: state.joins.length > 0 ? state.joins : undefined,\n projection: state.projections,\n where,\n orderBy: state.orderBy.length > 0 ? state.orderBy : undefined,\n distinct: state.distinct,\n distinctOn: state.distinctOn && state.distinctOn.length > 0 ? state.distinctOn : undefined,\n groupBy: state.groupBy.length > 0 ? state.groupBy : undefined,\n having: state.having,\n limit: state.limit,\n offset: state.offset,\n selectAllIntent: undefined,\n });\n}\n\nexport function buildQueryPlan<Row = unknown>(\n ast: import('@prisma-next/sql-relational-core/ast').AnyQueryAst,\n ctx: BuilderContext,\n annotations?: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>,\n): SqlQueryPlan<Row> {\n const paramValues = collectOrderedParamRefs(ast).map((r) =>\n r.kind === 'param-ref' ? r.value : undefined,\n );\n\n // SQL DSL has no framework-reserved namespace keys (e.g. `codecs`) in\n // scope at `.build()` time, so user annotations land verbatim here. The\n // ORM dispatch path — which compiles to plans that may already carry\n // reserved keys — enforces the precedence rule in `mergeAnnotations`\n // (`sql-orm-client/src/query-plan-meta.ts`).\n const annotationsRecord =\n annotations !== undefined && annotations.size > 0\n ? Object.freeze(Object.fromEntries(annotations))\n : undefined;\n const meta: PlanMeta = Object.freeze({\n target: ctx.target,\n storageHash: ctx.storageHash,\n lane: 'dsl',\n ...ifDefined('annotations', annotationsRecord),\n });\n\n return Object.freeze({ ast, params: paramValues, meta });\n}\n\nexport function buildPlan<Row = unknown>(\n state: BuilderState,\n ctx: BuilderContext,\n): SqlQueryPlan<Row> {\n return buildQueryPlan<Row>(buildSelectAst(state), ctx, state.annotations);\n}\n\nexport function tableToScope(\n alias: string,\n table: StorageTable,\n options?: { readonly storage?: SqlStorage | undefined; readonly tableName?: string | undefined },\n): Scope {\n const storage = options?.storage;\n const lookupName = options?.tableName;\n const fields: ScopeTable = {};\n for (const [colName, col] of Object.entries(table.columns)) {\n const codec =\n storage && lookupName ? codecRefForStorageColumn(storage, lookupName, colName) : undefined;\n fields[colName] = {\n codecId: col.codecId,\n nullable: col.nullable,\n ...(codec !== undefined ? { codec } : {}),\n };\n }\n return { topLevel: { ...fields }, namespaces: { [alias]: fields } };\n}\n\nexport function mergeScopes<A extends Scope, B extends Scope>(a: A, b: B): MergeScopes<A, B> {\n const topLevel: ScopeTable = {};\n for (const [k, v] of Object.entries(a.topLevel)) {\n if (!(k in b.topLevel)) topLevel[k] = v;\n }\n for (const [k, v] of Object.entries(b.topLevel)) {\n if (!(k in a.topLevel)) topLevel[k] = v;\n }\n return {\n topLevel,\n namespaces: { ...a.namespaces, ...b.namespaces },\n } as MergeScopes<A, B>;\n}\n\nexport function nullableScope<S extends Scope>(scope: S): NullableScope<S> {\n const mkNullable = (tbl: ScopeTable): ScopeTable => {\n const result: ScopeTable = {};\n for (const [k, v] of Object.entries(tbl)) {\n result[k] = {\n codecId: v.codecId,\n nullable: true,\n ...(v.codec !== undefined ? { codec: v.codec } : {}),\n };\n }\n return result;\n };\n const namespaces: Record<string, ScopeTable> = {};\n for (const [k, v] of Object.entries(scope.namespaces)) {\n namespaces[k] = mkNullable(v);\n }\n return { topLevel: mkNullable(scope.topLevel), namespaces } as NullableScope<S>;\n}\n\nexport function orderByScopeOf<S extends Scope, R extends Record<string, ScopeField>>(\n scope: S,\n rowFields: R,\n): OrderByScope<S, R> {\n return {\n topLevel: { ...scope.topLevel, ...rowFields },\n namespaces: scope.namespaces,\n };\n}\n\nexport function assertCapability(\n ctx: BuilderContext,\n required: Record<string, Record<string, boolean>>,\n methodName: string,\n): void {\n for (const [ns, keys] of Object.entries(required)) {\n for (const key of Object.keys(keys)) {\n if (!ctx.capabilities[ns]?.[key]) {\n throw new Error(`${methodName}() requires capability ${ns}.${key}`);\n }\n }\n }\n}\n\nexport function resolveSelectArgs(\n args: unknown[],\n scope: Scope,\n ctx: BuilderContext,\n): { projections: ProjectionItem[]; newRowFields: Record<string, ScopeField> } {\n const projections: ProjectionItem[] = [];\n const newRowFields: Record<string, ScopeField> = {};\n\n if (args.length === 0) return { projections, newRowFields };\n\n if (typeof args[0] === 'string' && (args.length === 1 || typeof args[1] !== 'function')) {\n for (const colName of args as string[]) {\n const field = scope.topLevel[colName];\n if (!field) throw new Error(`Column \"${colName}\" not found in scope`);\n projections.push(ProjectionItem.of(colName, IdentifierRef.of(colName), field.codec));\n newRowFields[colName] = field;\n }\n return { projections, newRowFields };\n }\n\n if (typeof args[0] === 'string' && typeof args[1] === 'function') {\n const alias = args[0] as string;\n const exprFn = args[1] as (\n f: FieldProxy<Scope>,\n fns: AggregateFunctions<QueryContext>,\n ) => Expression<ScopeField>;\n const fns = createAggregateFunctions(ctx.queryOperationTypes);\n const result = exprFn(createFieldProxy(scope), fns);\n const field = result.returnType;\n projections.push(ProjectionItem.of(alias, result.buildAst(), field.codec));\n newRowFields[alias] = field;\n return { projections, newRowFields };\n }\n\n if (typeof args[0] === 'function') {\n const callbackFn = args[0] as (\n f: FieldProxy<Scope>,\n fns: AggregateFunctions<QueryContext>,\n ) => Record<string, Expression<ScopeField>>;\n const fns = createAggregateFunctions(ctx.queryOperationTypes);\n const record = callbackFn(createFieldProxy(scope), fns);\n for (const [key, expr] of Object.entries(record)) {\n const field = expr.returnType;\n projections.push(ProjectionItem.of(key, expr.buildAst(), field.codec));\n newRowFields[key] = field;\n }\n return { projections, newRowFields };\n }\n\n throw new Error('Invalid .select() arguments');\n}\n\nexport function resolveOrderBy(\n arg: unknown,\n options: OrderByOptions | undefined,\n scope: Scope,\n rowFields: Record<string, ScopeField>,\n ctx: BuilderContext,\n useAggregateFns: boolean,\n): OrderByItem {\n const dir = options?.direction ?? 'asc';\n\n if (typeof arg === 'string') {\n const combined = orderByScopeOf(scope, rowFields);\n if (!(arg in combined.topLevel))\n throw new Error(`Column \"${arg}\" not found in scope for orderBy`);\n const expr = IdentifierRef.of(arg);\n return dir === 'asc' ? OrderByItem.asc(expr) : OrderByItem.desc(expr);\n }\n\n if (typeof arg === 'function') {\n const combined = orderByScopeOf(scope, rowFields);\n const fns = useAggregateFns\n ? createAggregateFunctions(ctx.queryOperationTypes)\n : createFunctions(ctx.queryOperationTypes);\n const result = (arg as ExprCallback)(createFieldProxy(combined), fns);\n return dir === 'asc' ? OrderByItem.asc(result.buildAst()) : OrderByItem.desc(result.buildAst());\n }\n\n throw new Error('Invalid orderBy argument');\n}\n\nexport function resolveGroupBy(\n args: unknown[],\n scope: Scope,\n rowFields: Record<string, ScopeField>,\n ctx: BuilderContext,\n): AstExpression[] {\n if (typeof args[0] === 'string') {\n const combined = orderByScopeOf(scope, rowFields);\n return (args as string[]).map((colName) => {\n if (!(colName in combined.topLevel))\n throw new Error(`Column \"${colName}\" not found in scope for groupBy`);\n return IdentifierRef.of(colName);\n });\n }\n\n if (typeof args[0] === 'function') {\n const combined = orderByScopeOf(scope, rowFields);\n const fns = createFunctions(ctx.queryOperationTypes);\n const result = (args[0] as ExprCallback)(createFieldProxy(combined), fns);\n return [result.buildAst()];\n }\n\n throw new Error('Invalid groupBy arguments');\n}\n\nexport function resolveDistinctOn(\n args: unknown[],\n scope: Scope,\n rowFields: Record<string, ScopeField>,\n ctx: BuilderContext,\n): AstExpression[] {\n if (args.length === 1 && typeof args[0] === 'function') {\n const combined = orderByScopeOf(scope, rowFields);\n const fns = createFunctions(ctx.queryOperationTypes);\n const result = (args[0] as ExprCallback)(createFieldProxy(combined), fns);\n return [result.buildAst()];\n }\n const combined = orderByScopeOf(scope, rowFields);\n return (args as string[]).map((colName) => {\n if (!(colName in combined.topLevel))\n throw new Error(`Column \"${colName}\" not found in scope for distinctOn`);\n return IdentifierRef.of(colName);\n });\n}\n","import type {\n AnnotationValue,\n OperationKind,\n ValidAnnotations,\n} from '@prisma-next/framework-components/runtime';\nimport { assertAnnotationsApplicable } from '@prisma-next/framework-components/runtime';\nimport { DerivedTableSource, type SelectAst } from '@prisma-next/sql-relational-core/ast';\nimport { toExpr } from '@prisma-next/sql-relational-core/expression';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n AggregateFunctions,\n BooleanCodecType,\n Expression,\n ExpressionBuilder,\n ExtractScopeFields,\n FieldProxy,\n Functions,\n OrderByOptions,\n OrderByScope,\n WithField,\n WithFields,\n} from '../expression';\nimport type { ResolveRow } from '../resolve';\nimport type {\n Expand,\n JoinOuterScope,\n JoinSource,\n QueryContext,\n Scope,\n ScopeField,\n // biome-ignore lint/correctness/noUnusedImports: used in `declare` property\n SubqueryMarker,\n} from '../scope';\nimport type { GroupedQuery } from '../types/grouped-query';\nimport type { SelectQuery } from '../types/select-query';\nimport type { PaginationValue } from '../types/shared';\nimport {\n BuilderBase,\n type BuilderContext,\n type BuilderState,\n buildPlan,\n buildSelectAst,\n cloneState,\n orderByScopeOf,\n resolveDistinctOn,\n resolveGroupBy,\n resolveOrderBy,\n resolveSelectArgs,\n} from './builder-base';\nimport { createFieldProxy } from './field-proxy';\nimport { createAggregateFunctions, createFunctions } from './functions';\n\nabstract class QueryBase<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n> extends BuilderBase<QC['capabilities']> {\n protected readonly state: BuilderState;\n\n constructor(state: BuilderState, ctx: BuilderContext) {\n super(ctx);\n this.state = state;\n }\n\n protected abstract clone(state: BuilderState): this;\n\n distinctOn = this._gate(\n { postgres: { distinctOn: true } },\n 'distinctOn',\n (...args: unknown[]) => {\n const exprs = resolveDistinctOn(args, this.state.scope, this.state.rowFields, this.ctx);\n return this.clone(\n cloneState(this.state, {\n distinctOn: [...(this.state.distinctOn ?? []), ...exprs],\n }),\n );\n },\n );\n\n limit(count: PaginationValue<QC>): this {\n const limit = typeof count === 'number' ? count : toExpr(count);\n return this.clone(cloneState(this.state, { limit }));\n }\n\n offset(count: PaginationValue<QC>): this {\n const offset = typeof count === 'number' ? count : toExpr(count);\n return this.clone(cloneState(this.state, { offset }));\n }\n\n distinct(): this {\n return this.clone(cloneState(this.state, { distinct: true }));\n }\n\n /**\n * Attach one or more annotations to this query plan.\n *\n * Read builders (`SelectQueryImpl`, `GroupedQueryImpl`) accept\n * annotations whose declared `applicableTo` includes `'read'`.\n * The type-level `As & ValidAnnotations<'read', As>` gate rejects\n * write-only annotations at the call site; the runtime check below\n * fails closed for callers that bypass the type gate (cast / `any`).\n *\n * Multiple `.annotate(...)` calls compose; duplicate namespaces use\n * last-write-wins. The accumulated annotations are merged into\n * `plan.meta.annotations` at `.build()` time, alongside any framework-\n * internal metadata under reserved namespaces (e.g. `codecs`).\n *\n * Chainable in any position (before / after `.where`, `.select`,\n * `.limit`, etc.); the returned builder has the same row type.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'read', As>\n ): this {\n assertAnnotationsApplicable(\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n 'read',\n 'sql-dsl.annotate',\n );\n const next = new Map(this.state.annotations);\n for (const annotation of annotations as readonly AnnotationValue<unknown, OperationKind>[]) {\n next.set(annotation.namespace, annotation);\n }\n return this.clone(cloneState(this.state, { annotations: next }));\n }\n\n groupBy(\n ...fields: ((keyof RowType | keyof AvailableScope['topLevel']) & string)[]\n ): GroupedQuery<QC, AvailableScope, RowType>;\n groupBy(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: Functions<QC>,\n ) => Expression<ScopeField>,\n ): GroupedQuery<QC, AvailableScope, RowType>;\n groupBy(...args: unknown[]): unknown {\n const exprs = resolveGroupBy(args, this.state.scope, this.state.rowFields, this.ctx);\n return new GroupedQueryImpl<QC, AvailableScope, RowType>(\n cloneState(this.state, { groupBy: [...this.state.groupBy, ...exprs] }),\n this.ctx,\n );\n }\n\n as<Alias extends string>(alias: Alias): JoinSource<RowType, Alias> {\n const ast = buildSelectAst(this.state);\n const derivedSource = DerivedTableSource.as(alias, ast);\n const scope = {\n topLevel: this.state.rowFields as RowType,\n namespaces: { [alias]: this.state.rowFields } as Record<Alias, RowType>,\n };\n return {\n getJoinOuterScope: () => scope,\n buildAst: () => derivedSource,\n\n // `as unknown` is necessary, because JoinOuterScope is a phantom type-only property that does not exist at runtime\n } satisfies Omit<JoinSource<RowType, Alias>, typeof JoinOuterScope> as unknown as JoinSource<\n RowType,\n Alias\n >;\n }\n\n getRowFields(): Record<string, ScopeField> {\n return this.state.rowFields;\n }\n\n buildAst(): SelectAst {\n return buildSelectAst(this.state);\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n return buildPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n this.state,\n this.ctx,\n );\n }\n}\n\nexport class SelectQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends QueryBase<QC, AvailableScope, RowType>\n implements SelectQuery<QC, AvailableScope, RowType>\n{\n declare readonly [SubqueryMarker]: RowType;\n\n protected clone(state: BuilderState): this {\n return new SelectQueryImpl<QC, AvailableScope, RowType>(state, this.ctx) as this;\n }\n\n select<Columns extends (keyof AvailableScope['topLevel'] & string)[]>(\n ...columns: Columns\n ): SelectQuery<QC, AvailableScope, WithFields<RowType, AvailableScope['topLevel'], Columns>>;\n select<Alias extends string, Field extends ScopeField>(\n alias: Alias,\n expr: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Expression<Field>,\n ): SelectQuery<QC, AvailableScope, WithField<RowType, Field, Alias>>;\n select<Result extends Record<string, Expression<ScopeField>>>(\n callback: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Result,\n ): SelectQuery<QC, AvailableScope, Expand<RowType & ExtractScopeFields<Result>>>;\n select(...args: unknown[]): unknown {\n const { projections, newRowFields } = resolveSelectArgs(args, this.state.scope, this.ctx);\n return new SelectQueryImpl(\n cloneState(this.state, {\n projections: [...this.state.projections, ...projections],\n rowFields: { ...this.state.rowFields, ...newRowFields },\n }),\n this.ctx,\n );\n }\n\n where(expr: ExpressionBuilder<AvailableScope, QC>): SelectQuery<QC, AvailableScope, RowType> {\n const fieldProxy = createFieldProxy(this.state.scope);\n const fns = createFunctions<QC>(this.ctx.queryOperationTypes);\n const result = (expr as ExpressionBuilder<Scope, QueryContext>)(fieldProxy, fns as never);\n return new SelectQueryImpl(\n cloneState(this.state, {\n where: [...this.state.where, result.buildAst()],\n }),\n this.ctx,\n );\n }\n\n orderBy(\n field: (keyof RowType | keyof AvailableScope['topLevel']) & string,\n options?: OrderByOptions,\n ): SelectQuery<QC, AvailableScope, RowType>;\n orderBy(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: Functions<QC>,\n ) => Expression<ScopeField>,\n options?: OrderByOptions,\n ): SelectQuery<QC, AvailableScope, RowType>;\n orderBy(arg: unknown, options?: OrderByOptions): unknown {\n const item = resolveOrderBy(\n arg,\n options,\n this.state.scope,\n this.state.rowFields,\n this.ctx,\n false,\n );\n return this.clone(cloneState(this.state, { orderBy: [...this.state.orderBy, item] }));\n }\n}\n\nexport class GroupedQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends QueryBase<QC, AvailableScope, RowType>\n implements GroupedQuery<QC, AvailableScope, RowType>\n{\n declare readonly [SubqueryMarker]: RowType;\n\n protected clone(state: BuilderState): this {\n return new GroupedQueryImpl<QC, AvailableScope, RowType>(state, this.ctx) as this;\n }\n\n having(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: AggregateFunctions<QC>,\n ) => Expression<BooleanCodecType>,\n ): GroupedQuery<QC, AvailableScope, RowType> {\n const combined = orderByScopeOf(\n this.state.scope as AvailableScope,\n this.state.rowFields as RowType,\n );\n const fns = createAggregateFunctions(this.ctx.queryOperationTypes);\n const result = expr(createFieldProxy(combined), fns);\n return new GroupedQueryImpl(cloneState(this.state, { having: result.buildAst() }), this.ctx);\n }\n\n orderBy(\n field: (keyof RowType | keyof AvailableScope['topLevel']) & string,\n options?: OrderByOptions,\n ): GroupedQuery<QC, AvailableScope, RowType>;\n orderBy(\n expr: (\n fields: FieldProxy<OrderByScope<AvailableScope, RowType>>,\n fns: AggregateFunctions<QC>,\n ) => Expression<ScopeField>,\n options?: OrderByOptions,\n ): GroupedQuery<QC, AvailableScope, RowType>;\n orderBy(arg: unknown, options?: OrderByOptions): unknown {\n const item = resolveOrderBy(\n arg,\n options,\n this.state.scope,\n this.state.rowFields,\n this.ctx,\n true,\n );\n return this.clone(cloneState(this.state, { orderBy: [...this.state.orderBy, item] }));\n }\n}\n","import {\n AndExpr,\n DerivedTableSource,\n JoinAst,\n type TableSource,\n} from '@prisma-next/sql-relational-core/ast';\nimport type {\n AggregateFunctions,\n Expression,\n ExpressionBuilder,\n ExtractScopeFields,\n FieldProxy,\n WithField,\n WithFields,\n} from '../expression';\nimport type {\n EmptyRow,\n Expand,\n JoinOuterScope,\n JoinSource,\n MergeScopes,\n NullableScope,\n QueryContext,\n Scope,\n ScopeField,\n ScopeTable,\n Subquery,\n} from '../scope';\nimport type { JoinedTables } from '../types/joined-tables';\nimport type { SelectQuery } from '../types/select-query';\nimport type { LateralBuilder } from '../types/shared';\nimport {\n BuilderBase,\n type BuilderContext,\n type BuilderState,\n cloneState,\n emptyState,\n mergeScopes,\n nullableScope,\n resolveSelectArgs,\n} from './builder-base';\nimport { createFieldProxy } from './field-proxy';\nimport { createFunctions } from './functions';\nimport { SelectQueryImpl } from './query-impl';\n\nexport class JoinedTablesImpl<QC extends QueryContext, AvailableScope extends Scope>\n extends BuilderBase<QC['capabilities']>\n implements JoinedTables<QC, AvailableScope>\n{\n readonly #state: BuilderState;\n\n constructor(state: BuilderState, ctx: BuilderContext) {\n super(ctx);\n this.#state = state;\n }\n\n lateralJoin = this._gate(\n { sql: { lateral: true } },\n 'lateralJoin',\n <Alias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: Alias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<AvailableScope, { topLevel: LateralRow; namespaces: Record<Alias, LateralRow> }>\n > => {\n const { derivedSource, lateralScope } = this.#buildLateral(alias, builder);\n const resultScope = mergeScopes(\n this.#state.scope as AvailableScope,\n lateralScope as { topLevel: LateralRow; namespaces: Record<Alias, LateralRow> },\n );\n return this.#addLateralJoin('inner', resultScope, derivedSource);\n },\n ) as JoinedTables<QC, AvailableScope>['lateralJoin'];\n\n outerLateralJoin = this._gate(\n { sql: { lateral: true } },\n 'outerLateralJoin',\n <Alias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: Alias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<\n AvailableScope,\n NullableScope<{ topLevel: LateralRow; namespaces: Record<Alias, LateralRow> }>\n >\n > => {\n const { derivedSource, lateralScope } = this.#buildLateral(alias, builder);\n const resultScope = mergeScopes(\n this.#state.scope as AvailableScope,\n nullableScope(\n lateralScope as { topLevel: LateralRow; namespaces: Record<Alias, LateralRow> },\n ),\n );\n return this.#addLateralJoin('left', resultScope, derivedSource);\n },\n ) as JoinedTables<QC, AvailableScope>['outerLateralJoin'];\n\n select<Columns extends (keyof AvailableScope['topLevel'] & string)[]>(\n ...columns: Columns\n ): SelectQuery<QC, AvailableScope, WithFields<EmptyRow, AvailableScope['topLevel'], Columns>>;\n select<Alias extends string, Field extends ScopeField>(\n alias: Alias,\n expr: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Expression<Field>,\n ): SelectQuery<QC, AvailableScope, WithField<EmptyRow, Field, Alias>>;\n select<Result extends Record<string, Expression<ScopeField>>>(\n callback: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Result,\n ): SelectQuery<QC, AvailableScope, Expand<ExtractScopeFields<Result>>>;\n select(...args: unknown[]): unknown {\n const { projections, newRowFields } = resolveSelectArgs(args, this.#state.scope, this.ctx);\n return new SelectQueryImpl<QC, AvailableScope>(\n cloneState(this.#state, {\n projections: [...this.#state.projections, ...projections],\n rowFields: { ...this.#state.rowFields, ...newRowFields },\n }),\n this.ctx,\n );\n }\n\n innerJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>> {\n const targetScope = mergeScopes(\n this.#state.scope as AvailableScope,\n other.getJoinOuterScope() as Other[typeof JoinOuterScope],\n );\n return this.#addJoin(other, 'inner', targetScope, on);\n }\n\n outerLeftJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, NullableScope<Other[typeof JoinOuterScope]>>> {\n const targetScope = mergeScopes(\n this.#state.scope as AvailableScope,\n nullableScope(other.getJoinOuterScope() as Other[typeof JoinOuterScope]),\n );\n return this.#addJoin(other, 'left', targetScope, on);\n }\n\n outerRightJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<NullableScope<AvailableScope>, Other[typeof JoinOuterScope]>> {\n const targetScope = mergeScopes(\n nullableScope(this.#state.scope as AvailableScope),\n other.getJoinOuterScope() as Other[typeof JoinOuterScope],\n );\n return this.#addJoin(other, 'right', targetScope, on);\n }\n\n outerFullJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<\n QC,\n MergeScopes<NullableScope<AvailableScope>, NullableScope<Other[typeof JoinOuterScope]>>\n > {\n const targetScope = mergeScopes(\n nullableScope(this.#state.scope as AvailableScope),\n nullableScope(other.getJoinOuterScope() as Other[typeof JoinOuterScope]),\n );\n return this.#addJoin(other, 'full', targetScope, on);\n }\n\n #addJoin<Other extends JoinSource<ScopeTable, string | never>, ResultScope extends Scope>(\n other: Other,\n joinType: 'inner' | 'left' | 'right' | 'full',\n resultScope: ResultScope,\n onExpr: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, ResultScope> {\n const fieldProxy = createFieldProxy(\n mergeScopes(\n this.#state.scope as AvailableScope,\n other.getJoinOuterScope() as Other[typeof JoinOuterScope],\n ),\n ) as FieldProxy<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>>;\n const fns = createFunctions<QC>(this.ctx.queryOperationTypes);\n const onResult = onExpr(fieldProxy, fns);\n const joinAst = new JoinAst(joinType, other.buildAst(), onResult.buildAst());\n\n return new JoinedTablesImpl(\n cloneState(this.#state, {\n joins: [...this.#state.joins, joinAst],\n scope: resultScope,\n }),\n this.ctx,\n );\n }\n\n #buildLateral(\n alias: string,\n builderFn: (\n lateral: LateralBuilder<QC, AvailableScope>,\n ) => Subquery<Record<string, ScopeField>>,\n ) {\n const lateralBuilder: LateralBuilder<QC, AvailableScope> = {\n from: (other) => {\n const otherScope = other.getJoinOuterScope();\n const parentMerged = mergeScopes(this.#state.scope, otherScope);\n return new SelectQueryImpl(\n emptyState(other.buildAst() as TableSource, parentMerged),\n this.ctx,\n ) as unknown as SelectQuery<QC, AvailableScope, EmptyRow>;\n },\n };\n\n const subquery = builderFn(lateralBuilder);\n const subqueryAst = subquery.buildAst();\n const derivedSource = DerivedTableSource.as(alias, subqueryAst);\n const subqueryRowFields: ScopeTable = subquery.getRowFields();\n const lateralScope: Scope = {\n topLevel: subqueryRowFields,\n namespaces: { [alias]: subqueryRowFields },\n };\n\n return { derivedSource, lateralScope };\n }\n\n #addLateralJoin<ResultScope extends Scope>(\n joinType: 'inner' | 'left',\n resultScope: ResultScope,\n derivedSource: DerivedTableSource,\n ): JoinedTables<QC, ResultScope> {\n const onExpr = AndExpr.of([]);\n const joinAst = new JoinAst(joinType, derivedSource, onExpr, true);\n\n return new JoinedTablesImpl(\n cloneState(this.#state, {\n joins: [...this.#state.joins, joinAst],\n scope: resultScope,\n }),\n this.ctx,\n );\n }\n}\n","import type {\n AnnotationValue,\n OperationKind,\n ValidAnnotations,\n} from '@prisma-next/framework-components/runtime';\nimport { assertAnnotationsApplicable } from '@prisma-next/framework-components/runtime';\nimport type { StorageTable } from '@prisma-next/sql-contract/types';\nimport {\n type AnyExpression as AstExpression,\n ColumnRef,\n DeleteAst,\n InsertAst,\n ParamRef,\n ProjectionItem,\n TableSource,\n UpdateAst,\n} from '@prisma-next/sql-relational-core/ast';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type { MutationDefaultsOp } from '@prisma-next/sql-relational-core/query-lane-context';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Expression, ExpressionBuilder } from '../expression';\nimport type { ResolveRow } from '../resolve';\nimport type { QueryContext, Scope, ScopeField } from '../scope';\nimport type {\n DeleteQuery,\n InsertQuery,\n ReturningCapability,\n UpdateQuery,\n} from '../types/mutation-query';\nimport {\n BuilderBase,\n type BuilderContext,\n buildQueryPlan,\n codecRefFor,\n combineWhereExprs,\n} from './builder-base';\nimport { createFieldProxy } from './field-proxy';\nimport { createFunctions } from './functions';\n\n/**\n * Validates and merges a variadic annotations call into a builder's\n * accumulated user-annotations map. Used by `.annotate(...)` on each of\n * the three mutation builders (`InsertQueryImpl`, `UpdateQueryImpl`,\n * `DeleteQueryImpl`); the read builders share the same logic via\n * `QueryBase.annotate()` in `./query-impl.ts`.\n *\n * Runs `assertAnnotationsApplicable` at call time (not at `.build()`) so\n * inapplicable annotations forced through casts surface immediately\n * rather than at plan-construction time.\n */\nfunction mergeWriteAnnotations(\n current: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>,\n annotations: readonly AnnotationValue<unknown, OperationKind>[],\n): ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> {\n assertAnnotationsApplicable(annotations, 'write', 'sql-dsl.annotate');\n const next = new Map(current);\n for (const annotation of annotations) {\n next.set(annotation.namespace, annotation);\n }\n return next;\n}\n\ntype WhereCallback = ExpressionBuilder<Scope, QueryContext>;\nexport type UpdateSetCallback = (\n fields: ReturnType<typeof createFieldProxy>,\n fns: ReturnType<typeof createFunctions>,\n) => Record<string, Expression<ScopeField> | undefined>;\n\nexport function buildParamValues(\n values: Record<string, unknown>,\n table: StorageTable,\n tableName: string,\n op: MutationDefaultsOp,\n ctx: BuilderContext,\n): Record<string, ParamRef> {\n const params: Record<string, ParamRef> = {};\n for (const [col, value] of Object.entries(values)) {\n const column = table.columns[col];\n const codec = column ? codecRefFor(ctx, tableName, col) : undefined;\n params[col] = ParamRef.of(value, codec ? { codec } : undefined);\n }\n for (const def of ctx.applyMutationDefaults({ op, table: tableName, values })) {\n const column = table.columns[def.column];\n const codec = column ? codecRefFor(ctx, tableName, def.column) : undefined;\n params[def.column] = ParamRef.of(def.value, codec ? { codec } : undefined);\n }\n return params;\n}\n\nfunction buildReturningProjections(\n tableName: string,\n columns: string[],\n rowFields: Record<string, ScopeField>,\n): ProjectionItem[] {\n return columns.map((col) =>\n ProjectionItem.of(col, ColumnRef.of(tableName, col), rowFields[col]?.codec),\n );\n}\n\nfunction evaluateWhere(\n whereCallback: WhereCallback,\n scope: Scope,\n queryOperationTypes: BuilderContext['queryOperationTypes'],\n): AstExpression {\n const fieldProxy = createFieldProxy(scope);\n const fns = createFunctions(queryOperationTypes);\n const result = whereCallback(fieldProxy, fns as never);\n return result.buildAst();\n}\n\nexport function evaluateUpdateCallback(\n callback: UpdateSetCallback,\n scope: Scope,\n queryOperationTypes: BuilderContext['queryOperationTypes'],\n): Record<string, AstExpression> {\n const fieldProxy = createFieldProxy(scope);\n const fns = createFunctions(queryOperationTypes);\n const result = callback(fieldProxy, fns as never);\n const set: Record<string, AstExpression> = {};\n for (const [col, expr] of Object.entries(result)) {\n if (expr !== undefined) {\n set[col] = expr.buildAst();\n }\n }\n return set;\n}\n\nexport function buildSetExpressions(\n exprs: Record<string, AstExpression>,\n table: StorageTable,\n tableName: string,\n op: MutationDefaultsOp,\n ctx: BuilderContext,\n): Record<string, AstExpression> {\n const set: Record<string, AstExpression> = { ...exprs };\n for (const def of ctx.applyMutationDefaults({ op, table: tableName, values: exprs })) {\n if (!(def.column in set)) {\n const column = table.columns[def.column];\n const codec = column ? codecRefFor(ctx, tableName, def.column) : undefined;\n set[def.column] = ParamRef.of(def.value, ifDefined('codec', codec));\n }\n }\n return set;\n}\n\nexport class InsertQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends BuilderBase<QC['capabilities']>\n implements InsertQuery<QC, AvailableScope, RowType>\n{\n readonly #tableName: string;\n readonly #table: StorageTable;\n readonly #scope: Scope;\n readonly #rows: ReadonlyArray<Record<string, unknown>>;\n readonly #returningColumns: string[];\n readonly #rowFields: Record<string, ScopeField>;\n readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n\n constructor(\n tableName: string,\n table: StorageTable,\n scope: Scope,\n rows: ReadonlyArray<Record<string, unknown>>,\n ctx: BuilderContext,\n returningColumns: string[] = [],\n rowFields: Record<string, ScopeField> = {},\n annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),\n ) {\n super(ctx);\n this.#tableName = tableName;\n this.#table = table;\n this.#scope = scope;\n this.#rows = rows;\n this.#returningColumns = returningColumns;\n this.#rowFields = rowFields;\n this.#annotations = annotations;\n }\n\n returning = this._gate<ReturningCapability, string[], InsertQuery<QC, AvailableScope, never>>(\n { sql: { returning: true } },\n 'returning',\n (...columns: string[]) => {\n const newRowFields: Record<string, ScopeField> = {};\n for (const col of columns) {\n const field = this.#scope.topLevel[col];\n if (!field) throw new Error(`Column \"${col}\" not found in scope`);\n newRowFields[col] = field;\n }\n return new InsertQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#rows,\n this.ctx,\n columns,\n newRowFields,\n this.#annotations,\n ) as unknown as InsertQuery<QC, AvailableScope, never>;\n },\n );\n\n /**\n * Attach one or more write-typed annotations to this query plan.\n * The type-level `As & ValidAnnotations<'write', As>` gate rejects\n * read-only annotations at the call site; the runtime check fails\n * closed for callers that bypass the type gate. See `QueryBase.annotate`\n * in `./query-impl.ts` for the read-builder counterpart.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'write', As>\n ): InsertQuery<QC, AvailableScope, RowType> {\n return new InsertQueryImpl(\n this.#tableName,\n this.#table,\n this.#scope,\n this.#rows,\n this.ctx,\n this.#returningColumns,\n this.#rowFields,\n mergeWriteAnnotations(\n this.#annotations,\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n ),\n );\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n if (this.#rows.length === 0) {\n throw new Error('insert() called with an empty row array — at least one row is required');\n }\n\n const paramRows = this.#rows.map((rowValues) =>\n buildParamValues(rowValues, this.#table, this.#tableName, 'create', this.ctx),\n );\n\n let ast = InsertAst.into(TableSource.named(this.#tableName)).withRows(paramRows);\n\n if (this.#returningColumns.length > 0) {\n ast = ast.withReturning(\n buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields),\n );\n }\n\n return buildQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n ast,\n this.ctx,\n this.#annotations,\n );\n }\n}\n\nexport class UpdateQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends BuilderBase<QC['capabilities']>\n implements UpdateQuery<QC, AvailableScope, RowType>\n{\n readonly #tableName: string;\n readonly #scope: Scope;\n readonly #setExpressions: Record<string, AstExpression>;\n readonly #whereExprs: readonly AstExpression[];\n readonly #returningColumns: string[];\n readonly #rowFields: Record<string, ScopeField>;\n readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n\n constructor(\n tableName: string,\n scope: Scope,\n setExpressions: Record<string, AstExpression>,\n ctx: BuilderContext,\n whereExprs: readonly AstExpression[] = [],\n returningColumns: string[] = [],\n rowFields: Record<string, ScopeField> = {},\n annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),\n ) {\n super(ctx);\n this.#tableName = tableName;\n this.#scope = scope;\n this.#setExpressions = setExpressions;\n this.#whereExprs = whereExprs;\n this.#returningColumns = returningColumns;\n this.#rowFields = rowFields;\n this.#annotations = annotations;\n }\n\n where(expr: ExpressionBuilder<AvailableScope, QC>): UpdateQuery<QC, AvailableScope, RowType> {\n const fieldProxy = createFieldProxy(this.#scope);\n const fns = createFunctions(this.ctx.queryOperationTypes);\n const result = (expr as ExpressionBuilder<Scope, QueryContext>)(fieldProxy, fns as never);\n return new UpdateQueryImpl(\n this.#tableName,\n this.#scope,\n this.#setExpressions,\n this.ctx,\n [...this.#whereExprs, result.buildAst()],\n this.#returningColumns,\n this.#rowFields,\n this.#annotations,\n );\n }\n\n returning = this._gate<ReturningCapability, string[], UpdateQuery<QC, AvailableScope, never>>(\n { sql: { returning: true } },\n 'returning',\n (...columns: string[]) => {\n const newRowFields: Record<string, ScopeField> = {};\n for (const col of columns) {\n const field = this.#scope.topLevel[col];\n if (!field) throw new Error(`Column \"${col}\" not found in scope`);\n newRowFields[col] = field;\n }\n return new UpdateQueryImpl(\n this.#tableName,\n this.#scope,\n this.#setExpressions,\n this.ctx,\n this.#whereExprs,\n columns,\n newRowFields,\n this.#annotations,\n ) as unknown as UpdateQuery<QC, AvailableScope, never>;\n },\n );\n\n /**\n * Attach one or more write-typed annotations to this query plan.\n * See `InsertQueryImpl.annotate` for semantics; the runtime check\n * fails closed for callers that bypass the type-level gate.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'write', As>\n ): UpdateQuery<QC, AvailableScope, RowType> {\n return new UpdateQueryImpl(\n this.#tableName,\n this.#scope,\n this.#setExpressions,\n this.ctx,\n this.#whereExprs,\n this.#returningColumns,\n this.#rowFields,\n mergeWriteAnnotations(\n this.#annotations,\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n ),\n );\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n let ast = UpdateAst.table(TableSource.named(this.#tableName))\n .withSet(this.#setExpressions)\n .withWhere(combineWhereExprs(this.#whereExprs));\n\n if (this.#returningColumns.length > 0) {\n ast = ast.withReturning(\n buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields),\n );\n }\n\n return buildQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n ast,\n this.ctx,\n this.#annotations,\n );\n }\n}\n\nexport class DeleteQueryImpl<\n QC extends QueryContext = QueryContext,\n AvailableScope extends Scope = Scope,\n RowType extends Record<string, ScopeField> = Record<string, ScopeField>,\n >\n extends BuilderBase<QC['capabilities']>\n implements DeleteQuery<QC, AvailableScope, RowType>\n{\n readonly #tableName: string;\n readonly #scope: Scope;\n readonly #whereCallbacks: readonly WhereCallback[];\n readonly #returningColumns: string[];\n readonly #rowFields: Record<string, ScopeField>;\n readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;\n\n constructor(\n tableName: string,\n scope: Scope,\n ctx: BuilderContext,\n whereCallbacks: readonly WhereCallback[] = [],\n returningColumns: string[] = [],\n rowFields: Record<string, ScopeField> = {},\n annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),\n ) {\n super(ctx);\n this.#tableName = tableName;\n this.#scope = scope;\n this.#whereCallbacks = whereCallbacks;\n this.#returningColumns = returningColumns;\n this.#rowFields = rowFields;\n this.#annotations = annotations;\n }\n\n where(expr: ExpressionBuilder<AvailableScope, QC>): DeleteQuery<QC, AvailableScope, RowType> {\n return new DeleteQueryImpl(\n this.#tableName,\n this.#scope,\n this.ctx,\n [...this.#whereCallbacks, expr as unknown as WhereCallback],\n this.#returningColumns,\n this.#rowFields,\n this.#annotations,\n );\n }\n\n returning = this._gate<ReturningCapability, string[], DeleteQuery<QC, AvailableScope, never>>(\n { sql: { returning: true } },\n 'returning',\n (...columns: string[]) => {\n const newRowFields: Record<string, ScopeField> = {};\n for (const col of columns) {\n const field = this.#scope.topLevel[col];\n if (!field) throw new Error(`Column \"${col}\" not found in scope`);\n newRowFields[col] = field;\n }\n return new DeleteQueryImpl(\n this.#tableName,\n this.#scope,\n this.ctx,\n this.#whereCallbacks,\n columns,\n newRowFields,\n this.#annotations,\n ) as unknown as DeleteQuery<QC, AvailableScope, never>;\n },\n );\n\n /**\n * Attach one or more write-typed annotations to this query plan.\n * See `InsertQueryImpl.annotate` for semantics.\n */\n annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(\n ...annotations: As & ValidAnnotations<'write', As>\n ): DeleteQuery<QC, AvailableScope, RowType> {\n return new DeleteQueryImpl(\n this.#tableName,\n this.#scope,\n this.ctx,\n this.#whereCallbacks,\n this.#returningColumns,\n this.#rowFields,\n mergeWriteAnnotations(\n this.#annotations,\n annotations as readonly AnnotationValue<unknown, OperationKind>[],\n ),\n );\n }\n\n build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {\n const whereExpr = combineWhereExprs(\n this.#whereCallbacks.map((cb) =>\n evaluateWhere(cb, this.#scope, this.ctx.queryOperationTypes),\n ),\n );\n\n let ast = DeleteAst.from(TableSource.named(this.#tableName)).withWhere(whereExpr);\n\n if (this.#returningColumns.length > 0) {\n ast = ast.withReturning(\n buildReturningProjections(this.#tableName, this.#returningColumns, this.#rowFields),\n );\n }\n\n return buildQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>>(\n ast,\n this.ctx,\n this.#annotations,\n );\n }\n}\n","import type { StorageTable } from '@prisma-next/sql-contract/types';\nimport { type AnyFromSource, TableSource } from '@prisma-next/sql-relational-core/ast';\nimport type {\n AggregateFunctions,\n Expression,\n ExpressionBuilder,\n ExtractScopeFields,\n FieldProxy,\n Functions,\n WithField,\n WithFields,\n} from '../expression';\nimport type {\n EmptyRow,\n Expand,\n JoinOuterScope,\n JoinSource,\n MergeScopes,\n NullableScope,\n QueryContext,\n RebindScope,\n Scope,\n ScopeField,\n ScopeTable,\n StorageTableToScopeTable,\n Subquery,\n} from '../scope';\nimport type { TableProxyContract, UnboundTables } from '../types/db';\nimport type { JoinedTables } from '../types/joined-tables';\nimport type { DeleteQuery, InsertQuery, UpdateQuery } from '../types/mutation-query';\nimport type { SelectQuery } from '../types/select-query';\nimport type { LateralBuilder } from '../types/shared';\nimport type { TableProxy } from '../types/table-proxy';\nimport { BuilderBase, type BuilderContext, emptyState, tableToScope } from './builder-base';\nimport { JoinedTablesImpl } from './joined-tables-impl';\nimport {\n buildParamValues,\n buildSetExpressions,\n DeleteQueryImpl,\n evaluateUpdateCallback,\n InsertQueryImpl,\n UpdateQueryImpl,\n type UpdateSetCallback,\n} from './mutation-impl';\nimport { SelectQueryImpl } from './query-impl';\n\nexport class TableProxyImpl<\n C extends TableProxyContract,\n Name extends string & keyof UnboundTables<C>,\n Alias extends string,\n AvailableScope extends Scope,\n QC extends QueryContext,\n >\n extends BuilderBase<C['capabilities']>\n implements TableProxy<C, Name, Alias, AvailableScope, QC>\n{\n declare readonly [JoinOuterScope]: JoinSource<\n StorageTableToScopeTable<UnboundTables<C>[Name]>,\n Alias\n >[typeof JoinOuterScope];\n\n readonly #tableName: string;\n readonly #table: StorageTable;\n readonly #fromSource: TableSource;\n readonly #scope: Scope;\n\n constructor(tableName: string, table: StorageTable, alias: string, ctx: BuilderContext) {\n super(ctx);\n this.#tableName = tableName;\n this.#table = table;\n this.#scope = tableToScope(alias, table, { storage: ctx.storage, tableName });\n this.#fromSource = TableSource.named(tableName, alias !== tableName ? alias : undefined);\n }\n\n lateralJoin = this._gate(\n { sql: { lateral: true } },\n 'lateralJoin',\n <LAlias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: LAlias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<AvailableScope, { topLevel: LateralRow; namespaces: Record<LAlias, LateralRow> }>\n > => {\n return this.#toJoined().lateralJoin(alias, builder);\n },\n ) as TableProxy<C, Name, Alias, AvailableScope, QC>['lateralJoin'];\n\n outerLateralJoin = this._gate(\n { sql: { lateral: true } },\n 'outerLateralJoin',\n <LAlias extends string, LateralRow extends Record<string, ScopeField>>(\n alias: LAlias,\n builder: (lateral: LateralBuilder<QC, AvailableScope>) => Subquery<LateralRow>,\n ): JoinedTables<\n QC,\n MergeScopes<\n AvailableScope,\n NullableScope<{ topLevel: LateralRow; namespaces: Record<LAlias, LateralRow> }>\n >\n > => {\n return this.#toJoined().outerLateralJoin(alias, builder);\n },\n ) as TableProxy<C, Name, Alias, AvailableScope, QC>['outerLateralJoin'];\n\n getJoinOuterScope(): Scope {\n return this.#scope;\n }\n\n buildAst(): AnyFromSource {\n return this.#fromSource;\n }\n\n as<NewAlias extends string>(\n newAlias: NewAlias,\n ): TableProxy<C, Name, NewAlias, RebindScope<AvailableScope, Alias, NewAlias>> {\n return new TableProxyImpl(this.#tableName, this.#table, newAlias, this.ctx);\n }\n\n select<Columns extends (keyof AvailableScope['topLevel'] & string)[]>(\n ...columns: Columns\n ): SelectQuery<QC, AvailableScope, WithFields<EmptyRow, AvailableScope['topLevel'], Columns>>;\n select<LAlias extends string, Field extends ScopeField>(\n alias: LAlias,\n expr: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Expression<Field>,\n ): SelectQuery<QC, AvailableScope, WithField<EmptyRow, Field, LAlias>>;\n select<Result extends Record<string, Expression<ScopeField>>>(\n callback: (fields: FieldProxy<AvailableScope>, fns: AggregateFunctions<QC>) => Result,\n ): SelectQuery<QC, AvailableScope, Expand<ExtractScopeFields<Result>>>;\n select(...args: unknown[]): unknown {\n return new SelectQueryImpl(emptyState(this.#fromSource, this.#scope), this.ctx).select(\n ...(args as string[]),\n );\n }\n\n innerJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>> {\n return this.#toJoined().innerJoin(other, on);\n }\n\n outerLeftJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<AvailableScope, NullableScope<Other[typeof JoinOuterScope]>>> {\n return this.#toJoined().outerLeftJoin(other, on);\n }\n\n outerRightJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<QC, MergeScopes<NullableScope<AvailableScope>, Other[typeof JoinOuterScope]>> {\n return this.#toJoined().outerRightJoin(other, on);\n }\n\n outerFullJoin<Other extends JoinSource<ScopeTable, string | never>>(\n other: Other,\n on: ExpressionBuilder<MergeScopes<AvailableScope, Other[typeof JoinOuterScope]>, QC>,\n ): JoinedTables<\n QC,\n MergeScopes<NullableScope<AvailableScope>, NullableScope<Other[typeof JoinOuterScope]>>\n > {\n return this.#toJoined().outerFullJoin(other, on);\n }\n\n insert(rows: ReadonlyArray<Record<string, unknown>>): InsertQuery<QC, AvailableScope, EmptyRow> {\n return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, rows, this.ctx);\n }\n\n update(\n setOrCallback:\n | Record<string, unknown>\n | ((\n fields: FieldProxy<AvailableScope>,\n fns: Functions<QC>,\n ) => Record<string, Expression<ScopeField> | undefined>),\n ): UpdateQuery<QC, AvailableScope, EmptyRow> {\n if (typeof setOrCallback === 'function') {\n const callbackExprs = evaluateUpdateCallback(\n setOrCallback as UpdateSetCallback,\n this.#scope,\n this.ctx.queryOperationTypes,\n );\n const setExpressions = buildSetExpressions(\n callbackExprs,\n this.#table,\n this.#tableName,\n 'update',\n this.ctx,\n );\n return new UpdateQueryImpl(this.#tableName, this.#scope, setExpressions, this.ctx);\n }\n const setExpressions = buildParamValues(\n setOrCallback,\n this.#table,\n this.#tableName,\n 'update',\n this.ctx,\n );\n return new UpdateQueryImpl(this.#tableName, this.#scope, setExpressions, this.ctx);\n }\n\n delete(): DeleteQuery<QC, AvailableScope, EmptyRow> {\n return new DeleteQueryImpl(this.#tableName, this.#scope, this.ctx);\n }\n\n #toJoined(): JoinedTables<QC, AvailableScope> {\n return new JoinedTablesImpl(emptyState(this.#fromSource, this.#scope), this.ctx);\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';\nimport type { ExecutionContext } from '@prisma-next/sql-relational-core/query-lane-context';\nimport type { Db, TableProxyContract } from '../types/db';\nimport type { BuilderContext } from './builder-base';\nimport { TableProxyImpl } from './table-proxy-impl';\n\nexport interface SqlOptions<C extends Contract<SqlStorage> & TableProxyContract> {\n readonly context: ExecutionContext<C>;\n}\n\n// Find a table by name across every declared namespace. Mirrors the\n// flat-DSL contract (db.<tableName>): the first namespace that declares\n// `name` wins. Name collisions across namespaces are a type-level error\n// at the DSL call site; landing the namespace-aware DSL is tracked\n// separately.\nfunction findTableAcrossNamespaces(storage: SqlStorage, name: string): StorageTable | undefined {\n for (const ns of Object.values(storage.namespaces)) {\n const tables = (ns as { tables?: Readonly<Record<string, StorageTable>> }).tables ?? {};\n if (Object.hasOwn(tables, name)) {\n return tables[name];\n }\n }\n return undefined;\n}\n\nexport function sql<C extends Contract<SqlStorage> & TableProxyContract>(\n options: SqlOptions<C>,\n): Db<C> {\n const { context } = options;\n const ctx: BuilderContext = {\n capabilities: context.contract.capabilities,\n queryOperationTypes: context.queryOperations.entries(),\n target: context.contract.target ?? 'unknown',\n storageHash: context.contract.storage.storageHash ?? 'unknown',\n storage: context.contract.storage,\n applyMutationDefaults: (options) => context.applyMutationDefaults(options),\n };\n\n return new Proxy({} as Db<C>, {\n get(_target, prop: string) {\n const table = findTableAcrossNamespaces(context.contract.storage, prop);\n if (table) {\n return new TableProxyImpl(prop, table, prop, ctx);\n }\n return undefined;\n },\n });\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,iBAAb,MAAwF;CACtF;CACA;CACA;CAEA,YAAY,KAAoB,YAAe,OAAkB;EAC/D,KAAK,MAAM;EACX,KAAK,aAAa;EAClB,KAAK,QAAQ;;CAGf,WAA0B;EACxB,OAAO,KAAK;;;;;ACjBhB,SAAgB,iBAAkC,OAAyB;CACzE,OAAO,IAAI,MAAM,EAAE,EAAmB,EACpC,IAAI,SAAS,MAAc;EACzB,IAAI,OAAO,OAAO,MAAM,UAAU,KAAK,EAAE;GACvC,MAAM,WAAW,MAAM,SAAS;GAChC,IAAI,UACF,OAAO,IAAI,eAAe,cAAc,GAAG,KAAK,EAAE,UAAU,SAAS,MAAM;;EAI/E,IAAI,OAAO,OAAO,MAAM,YAAY,KAAK,EAAE;GACzC,MAAM,WAAW,MAAM,WAAW;GAClC,IAAI,UAAU,OAAO,qBAAqB,MAAM,SAAS;;IAK9D,CAAC;;AAGJ,SAAS,qBACP,eACA,QACgC;CAChC,OAAO,IAAI,MAAM,EAAE,EAAoC,EACrD,IAAI,SAAS,MAAc;EACzB,IAAI,OAAO,OAAO,QAAQ,KAAK,EAAE;GAC/B,MAAM,QAAQ,OAAO;GACrB,IAAI,OAAO,OAAO,IAAI,eAAe,UAAU,GAAG,eAAe,KAAK,EAAE,OAAO,MAAM,MAAM;;IAIhG,CAAC;;;;ACDJ,MAAM,aAA+B;CAAE,SAAS;CAAa,UAAU;CAAO;AAE9E,MAAM,UAAU;;;;;;AAOhB,SAAS,eAAe,SAAoB,YAAsC;CAChF,IAAI,iBAAiB,QAAQ,EAAE,OAAO,QAAQ,UAAU;CACxD,OAAO,OAAO,SAAS,WA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,OAAO,MAAM,IAAI;IAItD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "SQL builder lane for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/contract": "0.
|
|
10
|
-
"@prisma-next/framework-components": "0.
|
|
11
|
-
"@prisma-next/sql-contract": "0.
|
|
12
|
-
"@prisma-next/sql-operations": "0.
|
|
13
|
-
"@prisma-next/sql-relational-core": "0.
|
|
9
|
+
"@prisma-next/contract": "0.11.0",
|
|
10
|
+
"@prisma-next/framework-components": "0.11.0",
|
|
11
|
+
"@prisma-next/sql-contract": "0.11.0",
|
|
12
|
+
"@prisma-next/sql-operations": "0.11.0",
|
|
13
|
+
"@prisma-next/sql-relational-core": "0.11.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@prisma-next/adapter-postgres": "0.
|
|
17
|
-
"@prisma-next/
|
|
18
|
-
"@prisma-next/
|
|
19
|
-
"@prisma-next/
|
|
20
|
-
"@prisma-next/
|
|
21
|
-
"@prisma-next/
|
|
22
|
-
"@prisma-next/
|
|
23
|
-
"@prisma-next/
|
|
24
|
-
"@prisma-next/tsdown": "0.10.0",
|
|
16
|
+
"@prisma-next/adapter-postgres": "0.11.0",
|
|
17
|
+
"@prisma-next/ids": "0.11.0",
|
|
18
|
+
"@prisma-next/sql-contract-ts": "0.11.0",
|
|
19
|
+
"@prisma-next/target-postgres": "0.11.0",
|
|
20
|
+
"@prisma-next/test-utils": "0.11.0",
|
|
21
|
+
"@prisma-next/utils": "0.11.0",
|
|
22
|
+
"@prisma-next/tsconfig": "0.11.0",
|
|
23
|
+
"@prisma-next/tsdown": "0.11.0",
|
|
25
24
|
"tsdown": "0.22.0",
|
|
26
25
|
"typescript": "5.9.3",
|
|
27
26
|
"vitest": "4.1.6"
|
|
@@ -47,7 +46,7 @@
|
|
|
47
46
|
},
|
|
48
47
|
"scripts": {
|
|
49
48
|
"build": "tsdown",
|
|
50
|
-
"emit": "cd ../../../../test/integration && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-builder/fixtures/prisma-next.config.ts && cp test/sql-builder/fixtures/generated/contract.json
|
|
49
|
+
"emit": "cd ../../../../test/integration && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-builder/fixtures/prisma-next.config.ts && cp test/sql-builder/fixtures/generated/contract.json ../../packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/",
|
|
51
50
|
"emit:check": "pnpm emit && git diff --exit-code test/fixtures/generated/",
|
|
52
51
|
"test": "vitest run --passWithNoTests",
|
|
53
52
|
"~test:coverage": "vitest run --coverage --passWithNoTests",
|
package/src/exports/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AggregateFunctions, Expression, Functions } from '../expression';
|
|
1
|
+
export type { AggregateFunctions, BooleanCodecType, Expression, Functions } from '../expression';
|
|
2
2
|
export type { ResolveRow } from '../resolve';
|
|
3
3
|
export type { GatedMethod, QueryContext, Scope, ScopeField, Subquery } from '../scope';
|
|
4
4
|
export type { Db, TableProxyContract } from '../types/db';
|
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
} from '@prisma-next/sql-relational-core/ast';
|
|
18
18
|
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
19
19
|
import type { MutationDefaultsOp } from '@prisma-next/sql-relational-core/query-lane-context';
|
|
20
|
-
import
|
|
20
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
21
|
+
import type { Expression, ExpressionBuilder } from '../expression';
|
|
21
22
|
import type { ResolveRow } from '../resolve';
|
|
22
23
|
import type { QueryContext, Scope, ScopeField } from '../scope';
|
|
23
24
|
import type {
|
|
@@ -60,8 +61,12 @@ function mergeWriteAnnotations(
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
type WhereCallback = ExpressionBuilder<Scope, QueryContext>;
|
|
64
|
+
export type UpdateSetCallback = (
|
|
65
|
+
fields: ReturnType<typeof createFieldProxy>,
|
|
66
|
+
fns: ReturnType<typeof createFunctions>,
|
|
67
|
+
) => Record<string, Expression<ScopeField> | undefined>;
|
|
63
68
|
|
|
64
|
-
function buildParamValues(
|
|
69
|
+
export function buildParamValues(
|
|
65
70
|
values: Record<string, unknown>,
|
|
66
71
|
table: StorageTable,
|
|
67
72
|
tableName: string,
|
|
@@ -103,6 +108,41 @@ function evaluateWhere(
|
|
|
103
108
|
return result.buildAst();
|
|
104
109
|
}
|
|
105
110
|
|
|
111
|
+
export function evaluateUpdateCallback(
|
|
112
|
+
callback: UpdateSetCallback,
|
|
113
|
+
scope: Scope,
|
|
114
|
+
queryOperationTypes: BuilderContext['queryOperationTypes'],
|
|
115
|
+
): Record<string, AstExpression> {
|
|
116
|
+
const fieldProxy = createFieldProxy(scope);
|
|
117
|
+
const fns = createFunctions(queryOperationTypes);
|
|
118
|
+
const result = callback(fieldProxy, fns as never);
|
|
119
|
+
const set: Record<string, AstExpression> = {};
|
|
120
|
+
for (const [col, expr] of Object.entries(result)) {
|
|
121
|
+
if (expr !== undefined) {
|
|
122
|
+
set[col] = expr.buildAst();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return set;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function buildSetExpressions(
|
|
129
|
+
exprs: Record<string, AstExpression>,
|
|
130
|
+
table: StorageTable,
|
|
131
|
+
tableName: string,
|
|
132
|
+
op: MutationDefaultsOp,
|
|
133
|
+
ctx: BuilderContext,
|
|
134
|
+
): Record<string, AstExpression> {
|
|
135
|
+
const set: Record<string, AstExpression> = { ...exprs };
|
|
136
|
+
for (const def of ctx.applyMutationDefaults({ op, table: tableName, values: exprs })) {
|
|
137
|
+
if (!(def.column in set)) {
|
|
138
|
+
const column = table.columns[def.column];
|
|
139
|
+
const codec = column ? codecRefFor(ctx, tableName, def.column) : undefined;
|
|
140
|
+
set[def.column] = ParamRef.of(def.value, ifDefined('codec', codec));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return set;
|
|
144
|
+
}
|
|
145
|
+
|
|
106
146
|
export class InsertQueryImpl<
|
|
107
147
|
QC extends QueryContext = QueryContext,
|
|
108
148
|
AvailableScope extends Scope = Scope,
|
|
@@ -114,7 +154,7 @@ export class InsertQueryImpl<
|
|
|
114
154
|
readonly #tableName: string;
|
|
115
155
|
readonly #table: StorageTable;
|
|
116
156
|
readonly #scope: Scope;
|
|
117
|
-
readonly #
|
|
157
|
+
readonly #rows: ReadonlyArray<Record<string, unknown>>;
|
|
118
158
|
readonly #returningColumns: string[];
|
|
119
159
|
readonly #rowFields: Record<string, ScopeField>;
|
|
120
160
|
readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;
|
|
@@ -123,7 +163,7 @@ export class InsertQueryImpl<
|
|
|
123
163
|
tableName: string,
|
|
124
164
|
table: StorageTable,
|
|
125
165
|
scope: Scope,
|
|
126
|
-
|
|
166
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
127
167
|
ctx: BuilderContext,
|
|
128
168
|
returningColumns: string[] = [],
|
|
129
169
|
rowFields: Record<string, ScopeField> = {},
|
|
@@ -133,7 +173,7 @@ export class InsertQueryImpl<
|
|
|
133
173
|
this.#tableName = tableName;
|
|
134
174
|
this.#table = table;
|
|
135
175
|
this.#scope = scope;
|
|
136
|
-
this.#
|
|
176
|
+
this.#rows = rows;
|
|
137
177
|
this.#returningColumns = returningColumns;
|
|
138
178
|
this.#rowFields = rowFields;
|
|
139
179
|
this.#annotations = annotations;
|
|
@@ -153,7 +193,7 @@ export class InsertQueryImpl<
|
|
|
153
193
|
this.#tableName,
|
|
154
194
|
this.#table,
|
|
155
195
|
this.#scope,
|
|
156
|
-
this.#
|
|
196
|
+
this.#rows,
|
|
157
197
|
this.ctx,
|
|
158
198
|
columns,
|
|
159
199
|
newRowFields,
|
|
@@ -176,7 +216,7 @@ export class InsertQueryImpl<
|
|
|
176
216
|
this.#tableName,
|
|
177
217
|
this.#table,
|
|
178
218
|
this.#scope,
|
|
179
|
-
this.#
|
|
219
|
+
this.#rows,
|
|
180
220
|
this.ctx,
|
|
181
221
|
this.#returningColumns,
|
|
182
222
|
this.#rowFields,
|
|
@@ -188,15 +228,15 @@ export class InsertQueryImpl<
|
|
|
188
228
|
}
|
|
189
229
|
|
|
190
230
|
build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.ctx,
|
|
231
|
+
if (this.#rows.length === 0) {
|
|
232
|
+
throw new Error('insert() called with an empty row array — at least one row is required');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const paramRows = this.#rows.map((rowValues) =>
|
|
236
|
+
buildParamValues(rowValues, this.#table, this.#tableName, 'create', this.ctx),
|
|
197
237
|
);
|
|
198
238
|
|
|
199
|
-
let ast = InsertAst.into(TableSource.named(this.#tableName)).
|
|
239
|
+
let ast = InsertAst.into(TableSource.named(this.#tableName)).withRows(paramRows);
|
|
200
240
|
|
|
201
241
|
if (this.#returningColumns.length > 0) {
|
|
202
242
|
ast = ast.withReturning(
|
|
@@ -221,44 +261,43 @@ export class UpdateQueryImpl<
|
|
|
221
261
|
implements UpdateQuery<QC, AvailableScope, RowType>
|
|
222
262
|
{
|
|
223
263
|
readonly #tableName: string;
|
|
224
|
-
readonly #table: StorageTable;
|
|
225
264
|
readonly #scope: Scope;
|
|
226
|
-
readonly #
|
|
227
|
-
readonly #
|
|
265
|
+
readonly #setExpressions: Record<string, AstExpression>;
|
|
266
|
+
readonly #whereExprs: readonly AstExpression[];
|
|
228
267
|
readonly #returningColumns: string[];
|
|
229
268
|
readonly #rowFields: Record<string, ScopeField>;
|
|
230
269
|
readonly #annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;
|
|
231
270
|
|
|
232
271
|
constructor(
|
|
233
272
|
tableName: string,
|
|
234
|
-
table: StorageTable,
|
|
235
273
|
scope: Scope,
|
|
236
|
-
|
|
274
|
+
setExpressions: Record<string, AstExpression>,
|
|
237
275
|
ctx: BuilderContext,
|
|
238
|
-
|
|
276
|
+
whereExprs: readonly AstExpression[] = [],
|
|
239
277
|
returningColumns: string[] = [],
|
|
240
278
|
rowFields: Record<string, ScopeField> = {},
|
|
241
279
|
annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>> = new Map(),
|
|
242
280
|
) {
|
|
243
281
|
super(ctx);
|
|
244
282
|
this.#tableName = tableName;
|
|
245
|
-
this.#table = table;
|
|
246
283
|
this.#scope = scope;
|
|
247
|
-
this.#
|
|
248
|
-
this.#
|
|
284
|
+
this.#setExpressions = setExpressions;
|
|
285
|
+
this.#whereExprs = whereExprs;
|
|
249
286
|
this.#returningColumns = returningColumns;
|
|
250
287
|
this.#rowFields = rowFields;
|
|
251
288
|
this.#annotations = annotations;
|
|
252
289
|
}
|
|
253
290
|
|
|
254
291
|
where(expr: ExpressionBuilder<AvailableScope, QC>): UpdateQuery<QC, AvailableScope, RowType> {
|
|
292
|
+
const fieldProxy = createFieldProxy(this.#scope);
|
|
293
|
+
const fns = createFunctions(this.ctx.queryOperationTypes);
|
|
294
|
+
const result = (expr as ExpressionBuilder<Scope, QueryContext>)(fieldProxy, fns as never);
|
|
255
295
|
return new UpdateQueryImpl(
|
|
256
296
|
this.#tableName,
|
|
257
|
-
this.#table,
|
|
258
297
|
this.#scope,
|
|
259
|
-
this.#
|
|
298
|
+
this.#setExpressions,
|
|
260
299
|
this.ctx,
|
|
261
|
-
[...this.#
|
|
300
|
+
[...this.#whereExprs, result.buildAst()],
|
|
262
301
|
this.#returningColumns,
|
|
263
302
|
this.#rowFields,
|
|
264
303
|
this.#annotations,
|
|
@@ -277,11 +316,10 @@ export class UpdateQueryImpl<
|
|
|
277
316
|
}
|
|
278
317
|
return new UpdateQueryImpl(
|
|
279
318
|
this.#tableName,
|
|
280
|
-
this.#table,
|
|
281
319
|
this.#scope,
|
|
282
|
-
this.#
|
|
320
|
+
this.#setExpressions,
|
|
283
321
|
this.ctx,
|
|
284
|
-
this.#
|
|
322
|
+
this.#whereExprs,
|
|
285
323
|
columns,
|
|
286
324
|
newRowFields,
|
|
287
325
|
this.#annotations,
|
|
@@ -299,11 +337,10 @@ export class UpdateQueryImpl<
|
|
|
299
337
|
): UpdateQuery<QC, AvailableScope, RowType> {
|
|
300
338
|
return new UpdateQueryImpl(
|
|
301
339
|
this.#tableName,
|
|
302
|
-
this.#table,
|
|
303
340
|
this.#scope,
|
|
304
|
-
this.#
|
|
341
|
+
this.#setExpressions,
|
|
305
342
|
this.ctx,
|
|
306
|
-
this.#
|
|
343
|
+
this.#whereExprs,
|
|
307
344
|
this.#returningColumns,
|
|
308
345
|
this.#rowFields,
|
|
309
346
|
mergeWriteAnnotations(
|
|
@@ -314,23 +351,9 @@ export class UpdateQueryImpl<
|
|
|
314
351
|
}
|
|
315
352
|
|
|
316
353
|
build(): SqlQueryPlan<ResolveRow<RowType, QC['codecTypes'], QC['resolvedColumnOutputTypes']>> {
|
|
317
|
-
const setParams = buildParamValues(
|
|
318
|
-
this.#setValues,
|
|
319
|
-
this.#table,
|
|
320
|
-
this.#tableName,
|
|
321
|
-
'update',
|
|
322
|
-
this.ctx,
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
const whereExpr = combineWhereExprs(
|
|
326
|
-
this.#whereCallbacks.map((cb) =>
|
|
327
|
-
evaluateWhere(cb, this.#scope, this.ctx.queryOperationTypes),
|
|
328
|
-
),
|
|
329
|
-
);
|
|
330
|
-
|
|
331
354
|
let ast = UpdateAst.table(TableSource.named(this.#tableName))
|
|
332
|
-
.withSet(
|
|
333
|
-
.withWhere(
|
|
355
|
+
.withSet(this.#setExpressions)
|
|
356
|
+
.withWhere(combineWhereExprs(this.#whereExprs));
|
|
334
357
|
|
|
335
358
|
if (this.#returningColumns.length > 0) {
|
|
336
359
|
ast = ast.withReturning(
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ExpressionBuilder,
|
|
7
7
|
ExtractScopeFields,
|
|
8
8
|
FieldProxy,
|
|
9
|
+
Functions,
|
|
9
10
|
WithField,
|
|
10
11
|
WithFields,
|
|
11
12
|
} from '../expression';
|
|
@@ -32,7 +33,15 @@ import type { LateralBuilder } from '../types/shared';
|
|
|
32
33
|
import type { TableProxy } from '../types/table-proxy';
|
|
33
34
|
import { BuilderBase, type BuilderContext, emptyState, tableToScope } from './builder-base';
|
|
34
35
|
import { JoinedTablesImpl } from './joined-tables-impl';
|
|
35
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
buildParamValues,
|
|
38
|
+
buildSetExpressions,
|
|
39
|
+
DeleteQueryImpl,
|
|
40
|
+
evaluateUpdateCallback,
|
|
41
|
+
InsertQueryImpl,
|
|
42
|
+
UpdateQueryImpl,
|
|
43
|
+
type UpdateSetCallback,
|
|
44
|
+
} from './mutation-impl';
|
|
36
45
|
import { SelectQueryImpl } from './query-impl';
|
|
37
46
|
|
|
38
47
|
export class TableProxyImpl<
|
|
@@ -155,12 +164,41 @@ export class TableProxyImpl<
|
|
|
155
164
|
return this.#toJoined().outerFullJoin(other, on);
|
|
156
165
|
}
|
|
157
166
|
|
|
158
|
-
insert(
|
|
159
|
-
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope,
|
|
167
|
+
insert(rows: ReadonlyArray<Record<string, unknown>>): InsertQuery<QC, AvailableScope, EmptyRow> {
|
|
168
|
+
return new InsertQueryImpl(this.#tableName, this.#table, this.#scope, rows, this.ctx);
|
|
160
169
|
}
|
|
161
170
|
|
|
162
|
-
update(
|
|
163
|
-
|
|
171
|
+
update(
|
|
172
|
+
setOrCallback:
|
|
173
|
+
| Record<string, unknown>
|
|
174
|
+
| ((
|
|
175
|
+
fields: FieldProxy<AvailableScope>,
|
|
176
|
+
fns: Functions<QC>,
|
|
177
|
+
) => Record<string, Expression<ScopeField> | undefined>),
|
|
178
|
+
): UpdateQuery<QC, AvailableScope, EmptyRow> {
|
|
179
|
+
if (typeof setOrCallback === 'function') {
|
|
180
|
+
const callbackExprs = evaluateUpdateCallback(
|
|
181
|
+
setOrCallback as UpdateSetCallback,
|
|
182
|
+
this.#scope,
|
|
183
|
+
this.ctx.queryOperationTypes,
|
|
184
|
+
);
|
|
185
|
+
const setExpressions = buildSetExpressions(
|
|
186
|
+
callbackExprs,
|
|
187
|
+
this.#table,
|
|
188
|
+
this.#tableName,
|
|
189
|
+
'update',
|
|
190
|
+
this.ctx,
|
|
191
|
+
);
|
|
192
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, setExpressions, this.ctx);
|
|
193
|
+
}
|
|
194
|
+
const setExpressions = buildParamValues(
|
|
195
|
+
setOrCallback,
|
|
196
|
+
this.#table,
|
|
197
|
+
this.#tableName,
|
|
198
|
+
'update',
|
|
199
|
+
this.ctx,
|
|
200
|
+
);
|
|
201
|
+
return new UpdateQueryImpl(this.#tableName, this.#scope, setExpressions, this.ctx);
|
|
164
202
|
}
|
|
165
203
|
|
|
166
204
|
delete(): DeleteQuery<QC, AvailableScope, EmptyRow> {
|
package/src/types/table-proxy.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
ExtractQueryOperationTypes,
|
|
6
6
|
StorageTable,
|
|
7
7
|
} from '@prisma-next/sql-contract/types';
|
|
8
|
+
import type { Expression, FieldProxy, Functions } from '../expression';
|
|
8
9
|
import type {
|
|
9
10
|
DefaultScope,
|
|
10
11
|
EmptyRow,
|
|
@@ -111,6 +112,13 @@ type ResolvedUpdateValues<
|
|
|
111
112
|
FieldInputs extends Record<string, Record<string, unknown>>,
|
|
112
113
|
> = ResolvedInsertValues<C, Table, TableName, CT, FieldInputs>;
|
|
113
114
|
|
|
115
|
+
type ResolvedUpdateExpressions<Table extends StorageTable> = {
|
|
116
|
+
[K in keyof Table['columns']]?: Expression<{
|
|
117
|
+
codecId: Table['columns'][K]['codecId'];
|
|
118
|
+
nullable: boolean;
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
|
|
114
122
|
type ContractToQC<C extends TableProxyContract, Name extends string = string> = {
|
|
115
123
|
readonly codecTypes: ExtractCodecTypes<C>;
|
|
116
124
|
readonly capabilities: C['capabilities'];
|
|
@@ -132,12 +140,14 @@ export interface TableProxy<
|
|
|
132
140
|
): TableProxy<C, Name, NewAlias, RebindScope<AvailableScope, Alias, NewAlias>>;
|
|
133
141
|
|
|
134
142
|
insert(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
rows: ReadonlyArray<
|
|
144
|
+
ResolvedInsertValues<
|
|
145
|
+
C,
|
|
146
|
+
UnboundTables<C>[Name],
|
|
147
|
+
Name,
|
|
148
|
+
QC['codecTypes'],
|
|
149
|
+
ExtractFieldInputTypes<C>
|
|
150
|
+
>
|
|
141
151
|
>,
|
|
142
152
|
): InsertQuery<QC, AvailableScope, EmptyRow>;
|
|
143
153
|
|
|
@@ -151,5 +161,12 @@ export interface TableProxy<
|
|
|
151
161
|
>,
|
|
152
162
|
): UpdateQuery<QC, AvailableScope, EmptyRow>;
|
|
153
163
|
|
|
164
|
+
update(
|
|
165
|
+
callback: (
|
|
166
|
+
fields: FieldProxy<AvailableScope>,
|
|
167
|
+
fns: Functions<QC>,
|
|
168
|
+
) => ResolvedUpdateExpressions<UnboundTables<C>[Name]>,
|
|
169
|
+
): UpdateQuery<QC, AvailableScope, EmptyRow>;
|
|
170
|
+
|
|
154
171
|
delete(): DeleteQuery<QC, AvailableScope, EmptyRow>;
|
|
155
172
|
}
|