@prisma-next/sql-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.
@@ -160,7 +160,7 @@ import { createJoinOnBuilder as createJoinOnBuilder2 } from "@prisma-next/sql-re
160
160
 
161
161
  // src/sql/mutation-builder.ts
162
162
  import {
163
- createColumnRef,
163
+ createColumnRef as createColumnRef2,
164
164
  createDeleteAst,
165
165
  createInsertAst,
166
166
  createParamRef as createParamRef2,
@@ -246,7 +246,7 @@ function errorMissingParameter(paramName) {
246
246
  }
247
247
  function errorInvalidProjectionValue(path) {
248
248
  throw planInvalid2(
249
- `Invalid projection value at path ${path.join(".")}: expected ExpressionSource (ColumnBuilder or ExpressionBuilder) or nested object`
249
+ `Invalid projection value at path ${path.join(".")}: expected ColumnBuilder or nested object`
250
250
  );
251
251
  }
252
252
  function errorIncludeAliasNotFound(alias) {
@@ -337,8 +337,9 @@ function checkReturningCapability(contract) {
337
337
  import { compact } from "@prisma-next/sql-relational-core/ast";
338
338
  import {
339
339
  collectColumnRefs,
340
+ getColumnInfo,
341
+ getOperationExpr,
340
342
  isColumnBuilder,
341
- isExpressionBuilder,
342
343
  isOperationExpr
343
344
  } from "@prisma-next/sql-relational-core/utils/guards";
344
345
 
@@ -352,44 +353,28 @@ function assertColumnBuilder(col, context) {
352
353
  }
353
354
 
354
355
  // src/sql/plan.ts
355
- function collectRefsFromExpressionSource(source, refsColumns) {
356
- if (isExpressionBuilder(source)) {
357
- const allRefs = collectColumnRefs(source.expr);
358
- for (const ref of allRefs) {
359
- refsColumns.set(`${ref.table}.${ref.column}`, {
360
- table: ref.table,
361
- column: ref.column
362
- });
363
- }
364
- } else if (isColumnBuilder(source)) {
365
- const col = source;
366
- refsColumns.set(`${col.table}.${col.column}`, {
367
- table: col.table,
368
- column: col.column
369
- });
370
- }
371
- }
372
- function collectRefsFromExpression(expr, refsColumns) {
373
- if (isOperationExpr(expr)) {
374
- const allRefs = collectColumnRefs(expr);
375
- for (const ref of allRefs) {
376
- refsColumns.set(`${ref.table}.${ref.column}`, {
377
- table: ref.table,
378
- column: ref.column
379
- });
380
- }
381
- } else if (expr.kind === "col") {
382
- refsColumns.set(`${expr.table}.${expr.column}`, {
383
- table: expr.table,
384
- column: expr.column
385
- });
386
- }
387
- }
388
356
  function buildMeta(args) {
389
357
  const refsColumns = /* @__PURE__ */ new Map();
390
358
  const refsTables = /* @__PURE__ */ new Set([args.table.name]);
391
359
  for (const column of args.projection.columns) {
392
- collectRefsFromExpressionSource(column, refsColumns);
360
+ if (!column) {
361
+ continue;
362
+ }
363
+ const operationExpr = getOperationExpr(column);
364
+ if (operationExpr) {
365
+ const allRefs = collectColumnRefs(operationExpr);
366
+ for (const ref of allRefs) {
367
+ refsColumns.set(`${ref.table}.${ref.column}`, {
368
+ table: ref.table,
369
+ column: ref.column
370
+ });
371
+ }
372
+ } else {
373
+ refsColumns.set(`${column.table}.${column.column}`, {
374
+ table: column.table,
375
+ column: column.column
376
+ });
377
+ }
393
378
  }
394
379
  if (args.joins) {
395
380
  for (const join of args.joins) {
@@ -427,21 +412,36 @@ function buildMeta(args) {
427
412
  });
428
413
  }
429
414
  if (include.childWhere) {
430
- collectRefsFromExpression(include.childWhere.left, refsColumns);
415
+ const colInfo = getColumnInfo(include.childWhere.left);
416
+ refsColumns.set(`${colInfo.table}.${colInfo.column}`, {
417
+ table: colInfo.table,
418
+ column: colInfo.column
419
+ });
431
420
  const childWhereRight = include.childWhere.right;
432
- if (isColumnBuilder(childWhereRight) || isExpressionBuilder(childWhereRight)) {
433
- collectRefsFromExpressionSource(childWhereRight, refsColumns);
421
+ if (isColumnBuilder(childWhereRight)) {
422
+ const rightColInfo = getColumnInfo(childWhereRight);
423
+ refsColumns.set(`${rightColInfo.table}.${rightColInfo.column}`, {
424
+ table: rightColInfo.table,
425
+ column: rightColInfo.column
426
+ });
434
427
  }
435
428
  }
436
429
  if (include.childOrderBy) {
437
- collectRefsFromExpression(include.childOrderBy.expr, refsColumns);
430
+ const orderBy = include.childOrderBy;
431
+ if (orderBy.expr) {
432
+ const colInfo = getColumnInfo(orderBy.expr);
433
+ refsColumns.set(`${colInfo.table}.${colInfo.column}`, {
434
+ table: colInfo.table,
435
+ column: colInfo.column
436
+ });
437
+ }
438
438
  }
439
439
  }
440
440
  }
441
441
  if (args.where) {
442
- const leftExpr = args.where.left;
443
- if (isOperationExpr(leftExpr)) {
444
- const allRefs = collectColumnRefs(leftExpr);
442
+ const whereLeft = args.where.left;
443
+ if (isOperationExpr(whereLeft)) {
444
+ const allRefs = collectColumnRefs(whereLeft);
445
445
  for (const ref of allRefs) {
446
446
  refsColumns.set(`${ref.table}.${ref.column}`, {
447
447
  table: ref.table,
@@ -449,31 +449,50 @@ function buildMeta(args) {
449
449
  });
450
450
  }
451
451
  } else {
452
- refsColumns.set(`${leftExpr.table}.${leftExpr.column}`, {
453
- table: leftExpr.table,
454
- column: leftExpr.column
455
- });
452
+ const operationExpr = whereLeft._operationExpr;
453
+ if (operationExpr) {
454
+ const allRefs = collectColumnRefs(operationExpr);
455
+ for (const ref of allRefs) {
456
+ refsColumns.set(`${ref.table}.${ref.column}`, {
457
+ table: ref.table,
458
+ column: ref.column
459
+ });
460
+ }
461
+ } else {
462
+ const colBuilder = assertColumnBuilder(whereLeft, "where clause must be a ColumnBuilder");
463
+ refsColumns.set(`${colBuilder.table}.${colBuilder.column}`, {
464
+ table: colBuilder.table,
465
+ column: colBuilder.column
466
+ });
467
+ }
456
468
  }
457
469
  const whereRight = args.where.right;
458
- if (isColumnBuilder(whereRight) || isExpressionBuilder(whereRight)) {
459
- collectRefsFromExpressionSource(whereRight, refsColumns);
470
+ if (isColumnBuilder(whereRight)) {
471
+ const colInfo = getColumnInfo(whereRight);
472
+ refsColumns.set(`${colInfo.table}.${colInfo.column}`, {
473
+ table: colInfo.table,
474
+ column: colInfo.column
475
+ });
460
476
  }
461
477
  }
462
478
  if (args.orderBy) {
463
- const orderByExpr = args.orderBy.expr;
464
- if (isOperationExpr(orderByExpr)) {
465
- const allRefs = collectColumnRefs(orderByExpr);
466
- for (const ref of allRefs) {
467
- refsColumns.set(`${ref.table}.${ref.column}`, {
468
- table: ref.table,
469
- column: ref.column
479
+ const orderBy = args.orderBy;
480
+ const orderByExpr = orderBy.expr;
481
+ if (orderByExpr) {
482
+ if (isOperationExpr(orderByExpr)) {
483
+ const allRefs = collectColumnRefs(orderByExpr);
484
+ for (const ref of allRefs) {
485
+ refsColumns.set(`${ref.table}.${ref.column}`, {
486
+ table: ref.table,
487
+ column: ref.column
488
+ });
489
+ }
490
+ } else {
491
+ refsColumns.set(`${orderByExpr.table}.${orderByExpr.column}`, {
492
+ table: orderByExpr.table,
493
+ column: orderByExpr.column
470
494
  });
471
495
  }
472
- } else {
473
- refsColumns.set(`${orderByExpr.table}.${orderByExpr.column}`, {
474
- table: orderByExpr.table,
475
- column: orderByExpr.column
476
- });
477
496
  }
478
497
  }
479
498
  const includeAliases = new Set(args.includes?.map((inc) => inc.alias) ?? []);
@@ -486,14 +505,11 @@ function buildMeta(args) {
486
505
  if (!column) {
487
506
  errorMissingColumnForAlias(alias, index);
488
507
  }
489
- if (isExpressionBuilder(column)) {
490
- return [alias, `operation:${column.expr.method}`];
508
+ const operationExpr = getOperationExpr(column);
509
+ if (operationExpr) {
510
+ return [alias, `operation:${operationExpr.method}`];
491
511
  }
492
- const col = column;
493
- if (!col.table || !col.column) {
494
- return [alias, `include:${alias}`];
495
- }
496
- return [alias, `${col.table}.${col.column}`];
512
+ return [alias, `${column.table}.${column.column}`];
497
513
  })
498
514
  );
499
515
  const projectionTypes = {};
@@ -506,8 +522,8 @@ function buildMeta(args) {
506
522
  if (!column) {
507
523
  continue;
508
524
  }
509
- if (isExpressionBuilder(column)) {
510
- const operationExpr = column.expr;
525
+ const operationExpr = column._operationExpr;
526
+ if (operationExpr) {
511
527
  if (operationExpr.returns.kind === "typeId") {
512
528
  projectionTypes[alias] = operationExpr.returns.type;
513
529
  } else if (operationExpr.returns.kind === "builtin") {
@@ -532,8 +548,8 @@ function buildMeta(args) {
532
548
  if (!column) {
533
549
  continue;
534
550
  }
535
- if (isExpressionBuilder(column)) {
536
- const operationExpr = column.expr;
551
+ const operationExpr = column._operationExpr;
552
+ if (operationExpr) {
537
553
  if (operationExpr.returns.kind === "typeId") {
538
554
  projectionCodecs[alias] = operationExpr.returns.type;
539
555
  }
@@ -570,10 +586,15 @@ function buildMeta(args) {
570
586
  }
571
587
 
572
588
  // src/sql/predicate-builder.ts
573
- import { createBinaryExpr, createParamRef } from "@prisma-next/sql-relational-core/ast";
574
589
  import {
590
+ createBinaryExpr,
591
+ createColumnRef,
592
+ createParamRef
593
+ } from "@prisma-next/sql-relational-core/ast";
594
+ import {
595
+ getColumnInfo as getColumnInfo2,
596
+ getOperationExpr as getOperationExpr2,
575
597
  isColumnBuilder as isColumnBuilder2,
576
- isExpressionBuilder as isExpressionBuilder2,
577
598
  isParamPlaceholder
578
599
  } from "@prisma-next/sql-relational-core/utils/guards";
579
600
  function buildWhereExpr(contract, where, paramsMap, descriptors, values) {
@@ -581,13 +602,11 @@ function buildWhereExpr(contract, where, paramsMap, descriptors, values) {
581
602
  let codecId;
582
603
  let rightExpr;
583
604
  let paramName;
584
- const validExpressionKinds = ["col", "operation"];
585
- if (!where.left || typeof where.left !== "object" || !validExpressionKinds.includes(where.left.kind ?? "")) {
586
- errorFailedToBuildWhereClause();
587
- }
588
- leftExpr = where.left;
589
- if (leftExpr.kind === "col") {
590
- const { table, column } = leftExpr;
605
+ const operationExpr = getOperationExpr2(where.left);
606
+ if (operationExpr) {
607
+ leftExpr = operationExpr;
608
+ } else if (isColumnBuilder2(where.left)) {
609
+ const { table, column } = getColumnInfo2(where.left);
591
610
  const contractTable = contract.storage.tables[table];
592
611
  if (!contractTable) {
593
612
  errorUnknownTable(table);
@@ -597,6 +616,9 @@ function buildWhereExpr(contract, where, paramsMap, descriptors, values) {
597
616
  errorUnknownColumn(column, table);
598
617
  }
599
618
  codecId = columnMeta.codecId;
619
+ leftExpr = createColumnRef(table, column);
620
+ } else {
621
+ errorFailedToBuildWhereClause();
600
622
  }
601
623
  if (isParamPlaceholder(where.right)) {
602
624
  const placeholder = where.right;
@@ -606,8 +628,8 @@ function buildWhereExpr(contract, where, paramsMap, descriptors, values) {
606
628
  }
607
629
  const value = paramsMap[paramName];
608
630
  const index = values.push(value);
609
- if (leftExpr.kind === "col") {
610
- const { table, column } = leftExpr;
631
+ if (isColumnBuilder2(where.left)) {
632
+ const { table, column } = getColumnInfo2(where.left);
611
633
  const contractTable = contract.storage.tables[table];
612
634
  const columnMeta = contractTable?.columns[column];
613
635
  if (columnMeta) {
@@ -622,19 +644,17 @@ function buildWhereExpr(contract, where, paramsMap, descriptors, values) {
622
644
  }
623
645
  }
624
646
  rightExpr = createParamRef(index, paramName);
625
- } else if (isColumnBuilder2(where.right) || isExpressionBuilder2(where.right)) {
626
- rightExpr = where.right.toExpr();
627
- if (rightExpr.kind === "col") {
628
- const { table, column } = rightExpr;
629
- const contractTable = contract.storage.tables[table];
630
- if (!contractTable) {
631
- errorUnknownTable(table);
632
- }
633
- const columnMeta = contractTable.columns[column];
634
- if (!columnMeta) {
635
- errorUnknownColumn(column, table);
636
- }
647
+ } else if (isColumnBuilder2(where.right)) {
648
+ const { table, column } = getColumnInfo2(where.right);
649
+ const contractTable = contract.storage.tables[table];
650
+ if (!contractTable) {
651
+ errorUnknownTable(table);
637
652
  }
653
+ const columnMeta = contractTable.columns[column];
654
+ if (!columnMeta) {
655
+ errorUnknownColumn(column, table);
656
+ }
657
+ rightExpr = createColumnRef(table, column);
638
658
  paramName = "";
639
659
  } else {
640
660
  errorFailedToBuildWhereClause();
@@ -708,7 +728,7 @@ var InsertBuilderImpl = class _InsertBuilderImpl {
708
728
  }
709
729
  const returning = this.returningColumns.map((col) => {
710
730
  const c = col;
711
- return createColumnRef(c.table, c.column);
731
+ return createColumnRef2(c.table, c.column);
712
732
  });
713
733
  const ast = createInsertAst({
714
734
  table: createTableRef(this.table.name),
@@ -839,7 +859,7 @@ var UpdateBuilderImpl = class _UpdateBuilderImpl {
839
859
  }
840
860
  const returning = this.returningColumns.map((col) => {
841
861
  const c = col;
842
- return createColumnRef(c.table, c.column);
862
+ return createColumnRef2(c.table, c.column);
843
863
  });
844
864
  const ast = createUpdateAst({
845
865
  table: createTableRef(this.table.name),
@@ -943,7 +963,7 @@ var DeleteBuilderImpl = class _DeleteBuilderImpl {
943
963
  }
944
964
  const returning = this.returningColumns.map((col) => {
945
965
  const c = col;
946
- return createColumnRef(c.table, c.column);
966
+ return createColumnRef2(c.table, c.column);
947
967
  });
948
968
  const ast = createDeleteAst({
949
969
  table: createTableRef(this.table.name),
@@ -985,16 +1005,17 @@ var DeleteBuilderImpl = class _DeleteBuilderImpl {
985
1005
 
986
1006
  // src/sql/select-builder.ts
987
1007
  import {
1008
+ createColumnRef as createColumnRef5,
988
1009
  createJoinOnBuilder,
989
1010
  createOrderByItem as createOrderByItem2,
990
1011
  createSelectAst,
991
1012
  createTableRef as createTableRef4
992
1013
  } from "@prisma-next/sql-relational-core/ast";
993
- import { isExpressionBuilder as isExpressionBuilder3 } from "@prisma-next/sql-relational-core/utils/guards";
1014
+ import { getOperationExpr as getOperationExpr3 } from "@prisma-next/sql-relational-core/utils/guards";
994
1015
 
995
1016
  // src/sql/include-builder.ts
996
1017
  import {
997
- createColumnRef as createColumnRef2,
1018
+ createColumnRef as createColumnRef3,
998
1019
  createJoinOnExpr,
999
1020
  createOrderByItem,
1000
1021
  createTableRef as createTableRef2
@@ -1005,7 +1026,7 @@ import {
1005
1026
  } from "@prisma-next/sql-relational-core/utils/guards";
1006
1027
 
1007
1028
  // src/sql/projection.ts
1008
- import { isExpressionSource } from "@prisma-next/sql-relational-core/utils/guards";
1029
+ import { isColumnBuilder as isColumnBuilder3 } from "@prisma-next/sql-relational-core/utils/guards";
1009
1030
  function generateAlias(path) {
1010
1031
  if (path.length === 0) {
1011
1032
  errorAliasPathEmpty();
@@ -1037,7 +1058,7 @@ function flattenProjection(projection, tracker, currentPath = []) {
1037
1058
  const columns = [];
1038
1059
  for (const [key, value] of Object.entries(projection)) {
1039
1060
  const path = [...currentPath, key];
1040
- if (isExpressionSource(value)) {
1061
+ if (isColumnBuilder3(value)) {
1041
1062
  const alias = tracker.register(path);
1042
1063
  aliases.push(alias);
1043
1064
  columns.push(value);
@@ -1062,14 +1083,8 @@ function buildProjectionState(_table, projection, includes) {
1062
1083
  errorIncludeAliasNotFound(key);
1063
1084
  }
1064
1085
  aliases.push(key);
1065
- columns.push({
1066
- kind: "column",
1067
- table: matchingInclude.table.name,
1068
- column: "",
1069
- columnMeta: { nativeType: "jsonb", codecId: "core/json@1", nullable: true },
1070
- toExpr: () => ({ kind: "col", table: matchingInclude.table.name, column: "" })
1071
- });
1072
- } else if (isExpressionSource(value)) {
1086
+ columns.push(null);
1087
+ } else if (isColumnBuilder3(value)) {
1073
1088
  const alias = tracker.register([key]);
1074
1089
  aliases.push(alias);
1075
1090
  columns.push(value);
@@ -1199,10 +1214,10 @@ function buildIncludeAst(include, contract, paramsMap, paramDescriptors, paramVa
1199
1214
  const expr = (() => {
1200
1215
  if (isOperationExpr2(orderExpr)) {
1201
1216
  const baseCol = extractBaseColumnRef(orderExpr);
1202
- return createColumnRef2(baseCol.table, baseCol.column);
1217
+ return createColumnRef3(baseCol.table, baseCol.column);
1203
1218
  }
1204
1219
  const colBuilder = orderExpr;
1205
- return createColumnRef2(colBuilder.table, colBuilder.column);
1220
+ return createColumnRef3(colBuilder.table, colBuilder.column);
1206
1221
  })();
1207
1222
  return [createOrderByItem(expr, orderBy.dir)];
1208
1223
  })() : void 0;
@@ -1219,8 +1234,8 @@ function buildIncludeAst(include, contract, paramsMap, paramDescriptors, paramVa
1219
1234
  }
1220
1235
  const onLeft = include.on.left;
1221
1236
  const onRight = include.on.right;
1222
- const leftCol = createColumnRef2(onLeft.table, onLeft.column);
1223
- const rightCol = createColumnRef2(onRight.table, onRight.column);
1237
+ const leftCol = createColumnRef3(onLeft.table, onLeft.column);
1238
+ const rightCol = createColumnRef3(onRight.table, onRight.column);
1224
1239
  const onExpr = createJoinOnExpr(leftCol, rightCol);
1225
1240
  return {
1226
1241
  kind: "includeMany",
@@ -1238,7 +1253,7 @@ function buildIncludeAst(include, contract, paramsMap, paramDescriptors, paramVa
1238
1253
  }
1239
1254
  return {
1240
1255
  alias,
1241
- expr: column.toExpr()
1256
+ expr: createColumnRef3(column.table, column.column)
1242
1257
  };
1243
1258
  })
1244
1259
  }
@@ -1247,7 +1262,7 @@ function buildIncludeAst(include, contract, paramsMap, paramDescriptors, paramVa
1247
1262
 
1248
1263
  // src/sql/join-builder.ts
1249
1264
  import {
1250
- createColumnRef as createColumnRef3,
1265
+ createColumnRef as createColumnRef4,
1251
1266
  createJoin,
1252
1267
  createJoinOnExpr as createJoinOnExpr2,
1253
1268
  createTableRef as createTableRef3
@@ -1255,8 +1270,8 @@ import {
1255
1270
  function buildJoinAst(join) {
1256
1271
  const onLeft = join.on.left;
1257
1272
  const onRight = join.on.right;
1258
- const leftCol = createColumnRef3(onLeft.table, onLeft.column);
1259
- const rightCol = createColumnRef3(onRight.table, onRight.column);
1273
+ const leftCol = createColumnRef4(onLeft.table, onLeft.column);
1274
+ const rightCol = createColumnRef4(onRight.table, onRight.column);
1260
1275
  const onExpr = createJoinOnExpr2(leftCol, rightCol);
1261
1276
  return createJoin(join.joinType, createTableRef3(join.table.name), onExpr);
1262
1277
  }
@@ -1425,7 +1440,13 @@ var SelectBuilderImpl = class _SelectBuilderImpl {
1425
1440
  }
1426
1441
  const orderByClause = this.state.orderBy ? (() => {
1427
1442
  const orderBy = this.state.orderBy;
1428
- return [createOrderByItem2(orderBy.expr, orderBy.dir)];
1443
+ const orderExpr = orderBy.expr;
1444
+ const operationExpr = getOperationExpr3(orderExpr);
1445
+ const expr = operationExpr ? operationExpr : (() => {
1446
+ const colBuilder = orderExpr;
1447
+ return createColumnRef5(colBuilder.table, colBuilder.column);
1448
+ })();
1449
+ return [createOrderByItem2(expr, orderBy.dir)];
1429
1450
  })() : void 0;
1430
1451
  const joins = this.state.joins?.map((join) => buildJoinAst(join));
1431
1452
  const includes = this.state.includes?.map(
@@ -1444,17 +1465,24 @@ var SelectBuilderImpl = class _SelectBuilderImpl {
1444
1465
  alias,
1445
1466
  expr: { kind: "includeRef", alias }
1446
1467
  });
1447
- } else if (column && isExpressionBuilder3(column)) {
1448
- projectEntries.push({
1449
- alias,
1450
- expr: column.expr
1451
- });
1452
- } else if (column) {
1453
- const columnRef = column.toExpr();
1454
- projectEntries.push({
1455
- alias,
1456
- expr: columnRef
1457
- });
1468
+ } else {
1469
+ if (!column) {
1470
+ errorMissingColumnForAlias(alias, i);
1471
+ }
1472
+ const operationExpr = column._operationExpr;
1473
+ if (operationExpr) {
1474
+ projectEntries.push({
1475
+ alias,
1476
+ expr: operationExpr
1477
+ });
1478
+ } else {
1479
+ const col = column;
1480
+ assertColumnBuilder(col, "projection column");
1481
+ projectEntries.push({
1482
+ alias,
1483
+ expr: createColumnRef5(col.table, col.column)
1484
+ });
1485
+ }
1458
1486
  }
1459
1487
  }
1460
1488
  const ast = createSelectAst({
@@ -1538,4 +1566,4 @@ export {
1538
1566
  createJoinOnBuilder2 as createJoinOnBuilder,
1539
1567
  sql
1540
1568
  };
1541
- //# sourceMappingURL=chunk-72PNERR5.js.map
1569
+ //# sourceMappingURL=chunk-AWSKRSFP.js.map