@prisma-next/sql-orm-lane 0.3.0-pr.95.1 → 0.3.0-pr.98.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-C4EECZ4E.js → chunk-3DNKIXXB.js} +119 -106
- package/dist/chunk-3DNKIXXB.js.map +1 -0
- package/dist/exports/orm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/orm/state.d.ts +3 -3
- package/dist/orm/state.d.ts.map +1 -1
- package/dist/plan/plan-assembly.d.ts.map +1 -1
- package/dist/relations/include-plan.d.ts.map +1 -1
- package/dist/selection/predicates.d.ts.map +1 -1
- package/dist/selection/projection.d.ts +4 -4
- package/dist/selection/projection.d.ts.map +1 -1
- package/dist/selection/select-builder.d.ts +4 -4
- package/dist/selection/select-builder.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/orm/state.ts +3 -3
- package/src/plan/plan-assembly.ts +80 -95
- package/src/relations/include-plan.ts +5 -5
- package/src/selection/predicates.ts +41 -25
- package/src/selection/projection.ts +10 -16
- package/src/selection/select-builder.ts +24 -22
- package/dist/chunk-C4EECZ4E.js.map +0 -1
|
@@ -5,8 +5,10 @@ import { schema as schema4 } from "@prisma-next/sql-relational-core/schema";
|
|
|
5
5
|
// src/selection/predicates.ts
|
|
6
6
|
import { augmentDescriptorWithColumnMeta } from "@prisma-next/sql-relational-core/plan";
|
|
7
7
|
import {
|
|
8
|
+
getColumnInfo,
|
|
9
|
+
getColumnMeta,
|
|
10
|
+
getOperationExpr,
|
|
8
11
|
isColumnBuilder,
|
|
9
|
-
isExpressionBuilder,
|
|
10
12
|
isParamPlaceholder
|
|
11
13
|
} from "@prisma-next/sql-relational-core/utils/guards";
|
|
12
14
|
|
|
@@ -124,9 +126,11 @@ function buildWhereExpr(where, contract, paramsMap, descriptors, values) {
|
|
|
124
126
|
let codecId;
|
|
125
127
|
let rightExpr;
|
|
126
128
|
let paramName;
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
129
|
+
const operationExpr = getOperationExpr(where.left);
|
|
130
|
+
if (operationExpr) {
|
|
131
|
+
leftExpr = operationExpr;
|
|
132
|
+
} else if (isColumnBuilder(where.left)) {
|
|
133
|
+
const { table, column } = getColumnInfo(where.left);
|
|
130
134
|
const contractTable = contract.storage.tables[table];
|
|
131
135
|
if (!contractTable) {
|
|
132
136
|
errorUnknownTable(table);
|
|
@@ -135,6 +139,9 @@ function buildWhereExpr(where, contract, paramsMap, descriptors, values) {
|
|
|
135
139
|
if (columnMeta) {
|
|
136
140
|
codecId = columnMeta.codecId;
|
|
137
141
|
}
|
|
142
|
+
leftExpr = createColumnRef(table, column);
|
|
143
|
+
} else {
|
|
144
|
+
errorFailedToBuildWhereClause();
|
|
138
145
|
}
|
|
139
146
|
if (isParamPlaceholder(where.right)) {
|
|
140
147
|
const placeholder = where.right;
|
|
@@ -144,21 +151,27 @@ function buildWhereExpr(where, contract, paramsMap, descriptors, values) {
|
|
|
144
151
|
}
|
|
145
152
|
const value = paramsMap[paramName];
|
|
146
153
|
const index = values.push(value);
|
|
147
|
-
if (
|
|
148
|
-
const { table, column } =
|
|
154
|
+
if (isColumnBuilder(where.left)) {
|
|
155
|
+
const { table, column } = getColumnInfo(where.left);
|
|
149
156
|
const contractTable = contract.storage.tables[table];
|
|
150
157
|
const columnMeta = contractTable?.columns[column];
|
|
158
|
+
const builderColumnMeta = getColumnMeta(where.left);
|
|
151
159
|
descriptors.push({
|
|
152
160
|
name: paramName,
|
|
153
161
|
source: "dsl",
|
|
154
162
|
refs: { table, column },
|
|
155
|
-
...
|
|
163
|
+
...typeof builderColumnMeta?.nullable === "boolean" ? { nullable: builderColumnMeta.nullable } : {}
|
|
156
164
|
});
|
|
157
165
|
augmentDescriptorWithColumnMeta(descriptors, columnMeta);
|
|
158
166
|
}
|
|
159
167
|
rightExpr = createParamRef(index, paramName);
|
|
160
|
-
} else if (isColumnBuilder(where.right)
|
|
161
|
-
|
|
168
|
+
} else if (isColumnBuilder(where.right)) {
|
|
169
|
+
const { table, column } = getColumnInfo(where.right);
|
|
170
|
+
const contractTable = contract.storage.tables[table];
|
|
171
|
+
if (!contractTable) {
|
|
172
|
+
errorUnknownTable(table);
|
|
173
|
+
}
|
|
174
|
+
rightExpr = createColumnRef(table, column);
|
|
162
175
|
paramName = "";
|
|
163
176
|
} else {
|
|
164
177
|
errorFailedToBuildWhereClause();
|
|
@@ -613,53 +626,32 @@ import { planInvalid as planInvalid4 } from "@prisma-next/plan";
|
|
|
613
626
|
import { compact } from "@prisma-next/sql-relational-core/ast";
|
|
614
627
|
import {
|
|
615
628
|
collectColumnRefs,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
isExpressionBuilder as isExpressionBuilder2,
|
|
629
|
+
getColumnInfo as getColumnInfo2,
|
|
630
|
+
getColumnMeta as getColumnMeta2,
|
|
619
631
|
isOperationExpr
|
|
620
632
|
} from "@prisma-next/sql-relational-core/utils/guards";
|
|
621
|
-
function
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
633
|
+
function buildMeta(args) {
|
|
634
|
+
const refsColumns = /* @__PURE__ */ new Map();
|
|
635
|
+
const refsTables = /* @__PURE__ */ new Set([args.table.name]);
|
|
636
|
+
for (const column of args.projection.columns) {
|
|
637
|
+
const operationExpr = column._operationExpr;
|
|
638
|
+
if (operationExpr) {
|
|
639
|
+
const allRefs = collectColumnRefs(operationExpr);
|
|
640
|
+
for (const ref of allRefs) {
|
|
626
641
|
refsColumns.set(`${ref.table}.${ref.column}`, {
|
|
627
642
|
table: ref.table,
|
|
628
643
|
column: ref.column
|
|
629
644
|
});
|
|
630
645
|
}
|
|
646
|
+
} else {
|
|
647
|
+
const col = column;
|
|
648
|
+
if (col.table && col.column) {
|
|
649
|
+
refsColumns.set(`${col.table}.${col.column}`, {
|
|
650
|
+
table: col.table,
|
|
651
|
+
column: col.column
|
|
652
|
+
});
|
|
653
|
+
}
|
|
631
654
|
}
|
|
632
|
-
} else if (isColumnBuilder2(source)) {
|
|
633
|
-
const col = source;
|
|
634
|
-
if (col.table && col.column) {
|
|
635
|
-
refsColumns.set(`${col.table}.${col.column}`, {
|
|
636
|
-
table: col.table,
|
|
637
|
-
column: col.column
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
function collectRefsFromExpression(expr, refsColumns) {
|
|
643
|
-
if (isOperationExpr(expr)) {
|
|
644
|
-
const allRefs = collectColumnRefs(expr);
|
|
645
|
-
for (const ref of allRefs) {
|
|
646
|
-
refsColumns.set(`${ref.table}.${ref.column}`, {
|
|
647
|
-
table: ref.table,
|
|
648
|
-
column: ref.column
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
} else if (expr.kind === "col") {
|
|
652
|
-
refsColumns.set(`${expr.table}.${expr.column}`, {
|
|
653
|
-
table: expr.table,
|
|
654
|
-
column: expr.column
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
function buildMeta(args) {
|
|
659
|
-
const refsColumns = /* @__PURE__ */ new Map();
|
|
660
|
-
const refsTables = /* @__PURE__ */ new Set([args.table.name]);
|
|
661
|
-
for (const column of args.projection.columns) {
|
|
662
|
-
collectRefsFromExpressionSource(column, refsColumns);
|
|
663
655
|
}
|
|
664
656
|
if (args.includes) {
|
|
665
657
|
for (const include of args.includes) {
|
|
@@ -686,17 +678,29 @@ function buildMeta(args) {
|
|
|
686
678
|
}
|
|
687
679
|
}
|
|
688
680
|
if (include.childWhere) {
|
|
689
|
-
|
|
681
|
+
const colInfo = getColumnInfo2(include.childWhere.left);
|
|
682
|
+
refsColumns.set(`${colInfo.table}.${colInfo.column}`, {
|
|
683
|
+
table: colInfo.table,
|
|
684
|
+
column: colInfo.column
|
|
685
|
+
});
|
|
690
686
|
}
|
|
691
687
|
if (include.childOrderBy) {
|
|
692
|
-
|
|
688
|
+
const orderBy = include.childOrderBy;
|
|
689
|
+
if (orderBy.expr) {
|
|
690
|
+
const colInfo = getColumnInfo2(orderBy.expr);
|
|
691
|
+
refsColumns.set(`${colInfo.table}.${colInfo.column}`, {
|
|
692
|
+
table: colInfo.table,
|
|
693
|
+
column: colInfo.column
|
|
694
|
+
});
|
|
695
|
+
}
|
|
693
696
|
}
|
|
694
697
|
}
|
|
695
698
|
}
|
|
696
699
|
if (args.where) {
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
+
const whereLeft = args.where.left;
|
|
701
|
+
const operationExpr = whereLeft._operationExpr;
|
|
702
|
+
if (operationExpr) {
|
|
703
|
+
const allRefs = collectColumnRefs(operationExpr);
|
|
700
704
|
for (const ref of allRefs) {
|
|
701
705
|
refsColumns.set(`${ref.table}.${ref.column}`, {
|
|
702
706
|
table: ref.table,
|
|
@@ -704,27 +708,36 @@ function buildMeta(args) {
|
|
|
704
708
|
});
|
|
705
709
|
}
|
|
706
710
|
} else {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
column
|
|
710
|
-
|
|
711
|
+
const colBuilder = whereLeft;
|
|
712
|
+
if (colBuilder.table && colBuilder.column) {
|
|
713
|
+
refsColumns.set(`${colBuilder.table}.${colBuilder.column}`, {
|
|
714
|
+
table: colBuilder.table,
|
|
715
|
+
column: colBuilder.column
|
|
716
|
+
});
|
|
717
|
+
}
|
|
711
718
|
}
|
|
712
719
|
}
|
|
713
720
|
if (args.orderBy) {
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
721
|
+
const orderBy = args.orderBy;
|
|
722
|
+
const orderByExpr = orderBy.expr;
|
|
723
|
+
if (orderByExpr) {
|
|
724
|
+
if (isOperationExpr(orderByExpr)) {
|
|
725
|
+
const allRefs = collectColumnRefs(orderByExpr);
|
|
726
|
+
for (const ref of allRefs) {
|
|
727
|
+
refsColumns.set(`${ref.table}.${ref.column}`, {
|
|
728
|
+
table: ref.table,
|
|
729
|
+
column: ref.column
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
} else {
|
|
733
|
+
const colBuilder = orderByExpr;
|
|
734
|
+
if (colBuilder.table && colBuilder.column) {
|
|
735
|
+
refsColumns.set(`${colBuilder.table}.${colBuilder.column}`, {
|
|
736
|
+
table: colBuilder.table,
|
|
737
|
+
column: colBuilder.column
|
|
738
|
+
});
|
|
739
|
+
}
|
|
722
740
|
}
|
|
723
|
-
} else {
|
|
724
|
-
refsColumns.set(`${orderByExpr.table}.${orderByExpr.column}`, {
|
|
725
|
-
table: orderByExpr.table,
|
|
726
|
-
column: orderByExpr.column
|
|
727
|
-
});
|
|
728
741
|
}
|
|
729
742
|
}
|
|
730
743
|
const includeAliases = new Set(args.includes?.map((inc) => inc.alias) ?? []);
|
|
@@ -737,13 +750,14 @@ function buildMeta(args) {
|
|
|
737
750
|
if (!column) {
|
|
738
751
|
throw planInvalid4(`Missing column for alias ${alias} at index ${index}`);
|
|
739
752
|
}
|
|
740
|
-
if (isExpressionBuilder2(column)) {
|
|
741
|
-
return [alias, `operation:${column.expr.method}`];
|
|
742
|
-
}
|
|
743
753
|
const col = column;
|
|
744
754
|
if (!col.table || !col.column) {
|
|
745
755
|
return [alias, `include:${alias}`];
|
|
746
756
|
}
|
|
757
|
+
const operationExpr = col._operationExpr;
|
|
758
|
+
if (operationExpr) {
|
|
759
|
+
return [alias, `operation:${operationExpr.method}`];
|
|
760
|
+
}
|
|
747
761
|
return [alias, `${col.table}.${col.column}`];
|
|
748
762
|
})
|
|
749
763
|
);
|
|
@@ -757,15 +771,15 @@ function buildMeta(args) {
|
|
|
757
771
|
if (!col) {
|
|
758
772
|
continue;
|
|
759
773
|
}
|
|
760
|
-
|
|
761
|
-
|
|
774
|
+
const operationExpr = col._operationExpr;
|
|
775
|
+
if (operationExpr) {
|
|
762
776
|
if (operationExpr.returns.kind === "typeId") {
|
|
763
777
|
projectionTypes[alias] = operationExpr.returns.type;
|
|
764
778
|
} else if (operationExpr.returns.kind === "builtin") {
|
|
765
779
|
projectionTypes[alias] = operationExpr.returns.type;
|
|
766
780
|
}
|
|
767
781
|
} else {
|
|
768
|
-
const columnMeta =
|
|
782
|
+
const columnMeta = getColumnMeta2(col);
|
|
769
783
|
const codecId = columnMeta?.codecId;
|
|
770
784
|
if (codecId) {
|
|
771
785
|
projectionTypes[alias] = codecId;
|
|
@@ -782,13 +796,13 @@ function buildMeta(args) {
|
|
|
782
796
|
if (!column) {
|
|
783
797
|
continue;
|
|
784
798
|
}
|
|
785
|
-
|
|
786
|
-
|
|
799
|
+
const operationExpr = column._operationExpr;
|
|
800
|
+
if (operationExpr) {
|
|
787
801
|
if (operationExpr.returns.kind === "typeId") {
|
|
788
802
|
projectionCodecs[alias] = operationExpr.returns.type;
|
|
789
803
|
}
|
|
790
804
|
} else {
|
|
791
|
-
const columnMeta =
|
|
805
|
+
const columnMeta = getColumnMeta2(column);
|
|
792
806
|
const codecId = columnMeta?.codecId;
|
|
793
807
|
if (codecId) {
|
|
794
808
|
projectionCodecs[alias] = codecId;
|
|
@@ -821,7 +835,6 @@ function buildMeta(args) {
|
|
|
821
835
|
// src/relations/include-plan.ts
|
|
822
836
|
import { compact as compact2 } from "@prisma-next/sql-relational-core/ast";
|
|
823
837
|
import { schema as schema3 } from "@prisma-next/sql-relational-core/schema";
|
|
824
|
-
import { isExpressionBuilder as isExpressionBuilder4 } from "@prisma-next/sql-relational-core/utils/guards";
|
|
825
838
|
|
|
826
839
|
// src/orm/capabilities.ts
|
|
827
840
|
function checkIncludeCapabilities(contract) {
|
|
@@ -878,10 +891,7 @@ function buildChildOrderByClause(orderBy) {
|
|
|
878
891
|
}
|
|
879
892
|
|
|
880
893
|
// src/selection/projection.ts
|
|
881
|
-
import {
|
|
882
|
-
isColumnBuilder as isColumnBuilder3,
|
|
883
|
-
isExpressionBuilder as isExpressionBuilder3
|
|
884
|
-
} from "@prisma-next/sql-relational-core/utils/guards";
|
|
894
|
+
import { isColumnBuilder as isColumnBuilder2 } from "@prisma-next/sql-relational-core/utils/guards";
|
|
885
895
|
function generateAlias(path) {
|
|
886
896
|
if (path.length === 0) {
|
|
887
897
|
errorAliasPathEmpty();
|
|
@@ -913,7 +923,7 @@ function flattenProjection(projection, tracker, currentPath = []) {
|
|
|
913
923
|
const columns = [];
|
|
914
924
|
for (const [key, value] of Object.entries(projection)) {
|
|
915
925
|
const path = [...currentPath, key];
|
|
916
|
-
if (
|
|
926
|
+
if (isColumnBuilder2(value)) {
|
|
917
927
|
const alias = tracker.register(path);
|
|
918
928
|
aliases.push(alias);
|
|
919
929
|
columns.push(value);
|
|
@@ -946,12 +956,9 @@ function buildProjectionState(_table, projection, includes) {
|
|
|
946
956
|
nativeType: "jsonb",
|
|
947
957
|
codecId: "core/json@1",
|
|
948
958
|
nullable: true
|
|
949
|
-
},
|
|
950
|
-
toExpr() {
|
|
951
|
-
return { kind: "col", table: matchingInclude.table.name, column: "" };
|
|
952
959
|
}
|
|
953
960
|
});
|
|
954
|
-
} else if (
|
|
961
|
+
} else if (isColumnBuilder2(value)) {
|
|
955
962
|
const alias = tracker.register([key]);
|
|
956
963
|
aliases.push(alias);
|
|
957
964
|
columns.push(value);
|
|
@@ -1062,10 +1069,12 @@ function buildIncludeAsts(input) {
|
|
|
1062
1069
|
if (!column) {
|
|
1063
1070
|
errorMissingColumn(alias, i);
|
|
1064
1071
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1072
|
+
const operationExpr = column._operationExpr;
|
|
1073
|
+
if (operationExpr) {
|
|
1074
|
+
childProjectionItems.push({ alias, expr: operationExpr });
|
|
1067
1075
|
} else {
|
|
1068
|
-
|
|
1076
|
+
const col = column;
|
|
1077
|
+
childProjectionItems.push({ alias, expr: createColumnRef(col.table, col.column) });
|
|
1069
1078
|
}
|
|
1070
1079
|
}
|
|
1071
1080
|
const includeAst = compact2({
|
|
@@ -1183,7 +1192,6 @@ function combineWhereClauses(mainWhere, existsExprs) {
|
|
|
1183
1192
|
}
|
|
1184
1193
|
|
|
1185
1194
|
// src/selection/select-builder.ts
|
|
1186
|
-
import { isExpressionBuilder as isExpressionBuilder5 } from "@prisma-next/sql-relational-core/utils/guards";
|
|
1187
1195
|
function buildProjectionItems(projectionState, includesForMeta) {
|
|
1188
1196
|
const projectEntries = [];
|
|
1189
1197
|
for (let i = 0; i < projectionState.aliases.length; i++) {
|
|
@@ -1201,20 +1209,25 @@ function buildProjectionItems(projectionState, includesForMeta) {
|
|
|
1201
1209
|
alias,
|
|
1202
1210
|
expr: { kind: "includeRef", alias }
|
|
1203
1211
|
});
|
|
1204
|
-
} else if (isExpressionBuilder5(column)) {
|
|
1205
|
-
projectEntries.push({
|
|
1206
|
-
alias,
|
|
1207
|
-
expr: column.expr
|
|
1208
|
-
});
|
|
1209
1212
|
} else {
|
|
1210
|
-
const
|
|
1211
|
-
if (
|
|
1212
|
-
|
|
1213
|
+
const operationExpr = column._operationExpr;
|
|
1214
|
+
if (operationExpr) {
|
|
1215
|
+
projectEntries.push({
|
|
1216
|
+
alias,
|
|
1217
|
+
expr: operationExpr
|
|
1218
|
+
});
|
|
1219
|
+
} else {
|
|
1220
|
+
const col = column;
|
|
1221
|
+
const tableName = col.table;
|
|
1222
|
+
const columnName = col.column;
|
|
1223
|
+
if (!tableName || !columnName) {
|
|
1224
|
+
errorInvalidColumn(alias, i);
|
|
1225
|
+
}
|
|
1226
|
+
projectEntries.push({
|
|
1227
|
+
alias,
|
|
1228
|
+
expr: createColumnRef(tableName, columnName)
|
|
1229
|
+
});
|
|
1213
1230
|
}
|
|
1214
|
-
projectEntries.push({
|
|
1215
|
-
alias,
|
|
1216
|
-
expr
|
|
1217
|
-
});
|
|
1218
1231
|
}
|
|
1219
1232
|
}
|
|
1220
1233
|
return projectEntries;
|
|
@@ -1720,4 +1733,4 @@ export {
|
|
|
1720
1733
|
OrmModelBuilderImpl,
|
|
1721
1734
|
orm
|
|
1722
1735
|
};
|
|
1723
|
-
//# sourceMappingURL=chunk-
|
|
1736
|
+
//# sourceMappingURL=chunk-3DNKIXXB.js.map
|