@prisma-next/sql-orm-lane 0.3.0-pr.95.1 → 0.3.0-pr.96.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.
@@ -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
- leftExpr = where.left;
128
- if (leftExpr.kind === "col") {
129
- const { table, column } = leftExpr;
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 (leftExpr.kind === "col") {
148
- const { table, column } = leftExpr;
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
- ...columnMeta && typeof columnMeta.nullable === "boolean" ? { nullable: columnMeta.nullable } : {}
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) || isExpressionBuilder(where.right)) {
161
- rightExpr = where.right.toExpr();
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
- getColumnMeta,
617
- isColumnBuilder as isColumnBuilder2,
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 collectRefsFromExpressionSource(source, refsColumns) {
622
- if (isExpressionBuilder2(source)) {
623
- const allRefs = collectColumnRefs(source.expr);
624
- for (const ref of allRefs) {
625
- if (ref.table && ref.column) {
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
- collectRefsFromExpression(include.childWhere.left, refsColumns);
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
- collectRefsFromExpression(include.childOrderBy.expr, refsColumns);
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 leftExpr = args.where.left;
698
- if (isOperationExpr(leftExpr)) {
699
- const allRefs = collectColumnRefs(leftExpr);
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
- refsColumns.set(`${leftExpr.table}.${leftExpr.column}`, {
708
- table: leftExpr.table,
709
- column: leftExpr.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 orderByExpr = args.orderBy.expr;
715
- if (isOperationExpr(orderByExpr)) {
716
- const allRefs = collectColumnRefs(orderByExpr);
717
- for (const ref of allRefs) {
718
- refsColumns.set(`${ref.table}.${ref.column}`, {
719
- table: ref.table,
720
- column: ref.column
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
- if (isExpressionBuilder2(col)) {
761
- const operationExpr = col.expr;
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 = getColumnMeta(col);
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
- if (isExpressionBuilder2(column)) {
786
- const operationExpr = column.expr;
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 = getColumnMeta(column);
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 (isColumnBuilder3(value) || isExpressionBuilder3(value)) {
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 (isColumnBuilder3(value) || isExpressionBuilder3(value)) {
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
- if (isExpressionBuilder4(column)) {
1066
- childProjectionItems.push({ alias, expr: column.expr });
1072
+ const operationExpr = column._operationExpr;
1073
+ if (operationExpr) {
1074
+ childProjectionItems.push({ alias, expr: operationExpr });
1067
1075
  } else {
1068
- childProjectionItems.push({ alias, expr: column.toExpr() });
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 expr = column.toExpr();
1211
- if (expr.kind === "col" && (!expr.table || !expr.column)) {
1212
- errorInvalidColumn(alias, i);
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-C4EECZ4E.js.map
1736
+ //# sourceMappingURL=chunk-3DNKIXXB.js.map