@prisma-next/sql-orm-lane 0.3.0-pr.99.1 → 0.3.0-pr.99.3

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