@mastra/duckdb 1.15.0-alpha.3 → 1.15.0-alpha.4

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.
@@ -1,4 +1,4 @@
1
- const require_features = require("./features-DxaUwIC2.cjs");
1
+ const require_features = require("./features-D7U4aB_V.cjs");
2
2
  let _mastra_core_error = require("@mastra/core/error");
3
3
  let _mastra_core_storage = require("@mastra/core/storage");
4
4
  _mastra_core_storage = require_features.__toESM(_mastra_core_storage, 1);
@@ -3617,15 +3617,15 @@ ORDER BY delta_rows.deltaWatermark ASC NULLS LAST, delta_rows.traceId ASC`,
3617
3617
  };
3618
3618
  }
3619
3619
  const orderField = plan.orderBy.field;
3620
- const direction = plan.orderBy.direction === "asc" ? "ASC" : "DESC";
3620
+ const order = `${orderField} ${plan.orderBy.direction === "asc" ? "ASC" : "DESC"} NULLS LAST, traceId ASC`;
3621
3621
  if (plan.paginationMode === "page") {
3622
3622
  values.push(plan.perPage, plan.page * plan.perPage);
3623
3623
  return {
3624
3624
  sql: `${candidates},
3625
3625
  page_rows AS (
3626
- SELECT *, row_number() OVER (ORDER BY ${orderField} ${direction}, traceId ASC) AS __row_position
3626
+ SELECT *, row_number() OVER (ORDER BY ${order}) AS __row_position
3627
3627
  FROM candidates
3628
- ORDER BY ${orderField} ${direction}, traceId ASC
3628
+ ORDER BY ${order}
3629
3629
  LIMIT ? OFFSET ?
3630
3630
  ),
3631
3631
  page_total AS (
@@ -3640,8 +3640,13 @@ ORDER BY page_rows.__row_position ASC NULLS LAST`,
3640
3640
  };
3641
3641
  }
3642
3642
  let pageCondition = "";
3643
- if (plan.cursor) {
3644
- pageCondition = `WHERE (${orderField} ${plan.orderBy.direction === "asc" ? ">" : "<"} CAST(? AS TIMESTAMP) OR (${orderField} = CAST(? AS TIMESTAMP) AND traceId > ?))`;
3643
+ if (plan.cursor?.sortValue === null) {
3644
+ pageCondition = `WHERE ${orderField} IS NULL AND traceId > ?`;
3645
+ values.push(plan.cursor.traceId);
3646
+ } else if (plan.cursor) {
3647
+ const comparison = plan.orderBy.direction === "asc" ? ">" : "<";
3648
+ const value = `CAST(? AS ${typeof plan.cursor.sortValue === "number" ? "DOUBLE" : "TIMESTAMP"})`;
3649
+ pageCondition = `WHERE (${orderField} ${comparison} ${value} OR ${orderField} IS NULL OR (${orderField} = ${value} AND traceId > ?))`;
3645
3650
  values.push(plan.cursor.sortValue, plan.cursor.sortValue, plan.cursor.traceId);
3646
3651
  }
3647
3652
  values.push(plan.limit + 1);
@@ -3650,7 +3655,7 @@ ORDER BY page_rows.__row_position ASC NULLS LAST`,
3650
3655
  SELECT *
3651
3656
  FROM candidates
3652
3657
  ${pageCondition}
3653
- ORDER BY ${orderField} ${direction}, traceId ASC
3658
+ ORDER BY ${order}
3654
3659
  LIMIT ?`,
3655
3660
  values
3656
3661
  };
@@ -3910,7 +3915,7 @@ async function queryTraces(db, plan) {
3910
3915
  traces,
3911
3916
  page: { next: rows.length > plan.limit && last ? _mastra_core_storage.encodeTraceQueryCursor(plan, {
3912
3917
  result: "traces",
3913
- sortValue: last[plan.orderBy.field],
3918
+ sortValue: last[plan.orderBy.field] ?? null,
3914
3919
  traceId: last.traceId
3915
3920
  }) : null }
3916
3921
  });
@@ -3996,13 +4001,16 @@ function afterCursor(plan) {
3996
4001
  values: []
3997
4002
  };
3998
4003
  const cursor = plan.cursor;
3999
- const comparisons = [`s.${plan.orderBy.field} ${plan.orderBy.direction === "asc" ? ">" : "<"} CAST(? AS TIMESTAMP)`];
4000
- const values = [cursor.sortValue];
4004
+ const sort = `s.${plan.orderBy.field}`;
4005
+ const empty = cursor.sortValue === null;
4006
+ const value = `CAST(? AS ${typeof cursor.sortValue === "number" ? "DOUBLE" : "TIMESTAMP"})`;
4007
+ const comparisons = empty ? [] : [`${sort} ${plan.orderBy.direction === "asc" ? ">" : "<"} ${value}`, `${sort} IS NULL`];
4008
+ const values = empty ? [] : [cursor.sortValue];
4001
4009
  for (let i = 0; i < identityFields.length; i++) {
4002
4010
  const field = identityFields[i];
4003
4011
  if (cursor[field] === null) continue;
4004
- const equal = [`s.${plan.orderBy.field} = CAST(? AS TIMESTAMP)`];
4005
- values.push(cursor.sortValue);
4012
+ const equal = [empty ? `${sort} IS NULL` : `${sort} = ${value}`];
4013
+ if (!empty) values.push(cursor.sortValue);
4006
4014
  for (const prior of identityFields.slice(0, i)) {
4007
4015
  equal.push(`s.${prior} IS NOT DISTINCT FROM ?`);
4008
4016
  values.push(cursor[prior]);
@@ -4061,7 +4069,7 @@ function compileDuckDBSpanQuery(plan) {
4061
4069
  "cursorId"
4062
4070
  ].map((field) => `s.${field}`).join(", ")}
4063
4071
  FROM ranked s WHERE rank = 1 AND endedAt IS NOT NULL AND startedAt >= CAST(? AS TIMESTAMP) AND startedAt < CAST(? AS TIMESTAMP) AND (${predicate.sql}) AND ${after.sql}
4064
- ORDER BY s.${plan.orderBy.field} ${plan.orderBy.direction === "asc" ? "ASC" : "DESC"}, ${identityFields.map((field) => `s.${field} ASC NULLS LAST`).join(", ")}
4072
+ ORDER BY s.${plan.orderBy.field} ${plan.orderBy.direction === "asc" ? "ASC" : "DESC"} NULLS LAST, ${identityFields.map((field) => `s.${field} ASC NULLS LAST`).join(", ")}
4065
4073
  LIMIT ?`,
4066
4074
  values
4067
4075
  };
@@ -6360,4 +6368,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends _mastr
6360
6368
  //#endregion
6361
6369
  exports.ObservabilityStorageDuckDB = ObservabilityStorageDuckDB;
6362
6370
 
6363
- //# sourceMappingURL=observability-D70dyGYt.cjs.map
6371
+ //# sourceMappingURL=observability-TeHp5JpN.cjs.map