@mastra/cloudflare-d1 1.4.5 → 1.5.0-alpha.0

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.
@@ -3,7 +3,7 @@ name: mastra-cloudflare-d1
3
3
  description: Documentation for @mastra/cloudflare-d1. Use when working with @mastra/cloudflare-d1 APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/cloudflare-d1"
6
- version: "1.4.5"
6
+ version: "1.5.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.5",
2
+ "version": "1.5.0-alpha.0",
3
3
  "package": "@mastra/cloudflare-d1",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -585,7 +585,7 @@ var D1DB = class extends _mastra_core_base.MastraBase {
585
585
  const existingColumns = await this.getTableColumns(fullTableName);
586
586
  const existingColumnNames = new Set(existingColumns.map((col) => col.name));
587
587
  for (const [columnName, column] of Object.entries(args.schema)) if (!existingColumnNames.has(columnName) && args.ifNotExists.includes(columnName)) {
588
- const sql = `ALTER TABLE ${fullTableName} ADD COLUMN ${columnName} ${this.getSqlType(column.type)} ${this.getDefaultValue(column.type)}`;
588
+ const sql = `ALTER TABLE ${fullTableName} ADD COLUMN ${columnName} ${this.getSqlType(column.type)} ${column.nullable ? "DEFAULT NULL" : this.getDefaultValue(column.type)}`;
589
589
  await this.executeQuery({ sql });
590
590
  this.logger.debug(`Added column ${columnName} to table ${fullTableName}`);
591
591
  }
@@ -764,10 +764,13 @@ function rowToTask(row) {
764
764
  suspendedAt: row.suspendedAt ? new Date(row.suspendedAt) : void 0,
765
765
  completedAt: row.completedAt ? new Date(row.completedAt) : void 0,
766
766
  ownerId: row.ownerId || void 0,
767
- leaseExpiresAt: row.leaseExpiresAt ? new Date(row.leaseExpiresAt) : void 0
767
+ leaseExpiresAt: row.leaseExpiresAt ? new Date(row.leaseExpiresAt) : void 0,
768
+ expiresAt: row.expiresAt ? new Date(row.expiresAt) : void 0,
769
+ metadata: parseJson(row.metadata)
768
770
  };
769
771
  }
770
772
  var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTasksStorage {
773
+ supportsTaskExpiry = true;
771
774
  #db;
772
775
  constructor(config) {
773
776
  super();
@@ -786,7 +789,9 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
786
789
  "suspend_payload",
787
790
  "suspendedAt",
788
791
  "ownerId",
789
- "leaseExpiresAt"
792
+ "leaseExpiresAt",
793
+ "expiresAt",
794
+ "metadata"
790
795
  ]
791
796
  });
792
797
  }
@@ -816,7 +821,9 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
816
821
  "suspendedAt",
817
822
  "completedAt",
818
823
  "ownerId",
819
- "leaseExpiresAt"
824
+ "leaseExpiresAt",
825
+ "expiresAt",
826
+ "metadata"
820
827
  ], [
821
828
  task.id,
822
829
  task.toolCallId,
@@ -838,7 +845,9 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
838
845
  task.suspendedAt?.toISOString() ?? null,
839
846
  task.completedAt?.toISOString() ?? null,
840
847
  task.ownerId ?? null,
841
- task.leaseExpiresAt?.toISOString() ?? null
848
+ task.leaseExpiresAt?.toISOString() ?? null,
849
+ task.expiresAt?.toISOString() ?? null,
850
+ serializeJson(task.metadata)
842
851
  ]).build();
843
852
  await this.#db.executeQuery({
844
853
  sql,
@@ -888,6 +897,14 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
888
897
  sets.push("leaseExpiresAt = ?");
889
898
  params.push(update.leaseExpiresAt?.toISOString() ?? null);
890
899
  }
900
+ if ("expiresAt" in update) {
901
+ sets.push("expiresAt = ?");
902
+ params.push(update.expiresAt?.toISOString() ?? null);
903
+ }
904
+ if ("metadata" in update) {
905
+ sets.push("metadata = ?");
906
+ params.push(serializeJson(update.metadata));
907
+ }
891
908
  if (sets.length === 0) return false;
892
909
  params.push(taskId);
893
910
  let predicates = "";
@@ -909,6 +926,13 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
909
926
  params.push(options.expectedLeaseExpiresAt.toISOString());
910
927
  }
911
928
  }
929
+ if (options?.expectedSuspendedAt !== void 0) {
930
+ if (options.expectedSuspendedAt === null) predicates += " AND suspendedAt IS NULL";
931
+ else {
932
+ predicates += " AND suspendedAt = ?";
933
+ params.push(options.expectedSuspendedAt.toISOString());
934
+ }
935
+ }
912
936
  const fullTableName = this.#db.getTableName(_mastra_core_storage.TABLE_BACKGROUND_TASKS);
913
937
  const result = await this.#db.executeQuery({
914
938
  sql: `UPDATE ${fullTableName} SET ${sets.join(", ")} WHERE id = ?${predicates} RETURNING id`,
@@ -955,7 +979,12 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
955
979
  builder = builder.whereAnd("tool_call_id = ?", filter.toolCallId);
956
980
  countBuilder = countBuilder.whereAnd("tool_call_id = ?", filter.toolCallId);
957
981
  }
958
- const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
982
+ const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
983
+ if (filter.hasExpiresAt !== void 0) {
984
+ const clause = filter.hasExpiresAt ? "expiresAt IS NOT NULL" : "expiresAt IS NULL";
985
+ builder = builder.whereAnd(clause);
986
+ countBuilder = countBuilder.whereAnd(clause);
987
+ }
959
988
  if (filter.fromDate) {
960
989
  builder = builder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
961
990
  countBuilder = countBuilder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
@@ -1001,7 +1030,8 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
1001
1030
  conditions.push(`status IN (${statuses.map(() => "?").join(",")})`);
1002
1031
  params.push(...statuses);
1003
1032
  }
1004
- const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
1033
+ const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
1034
+ if (filter.hasExpiresAt !== void 0) conditions.push(filter.hasExpiresAt ? "expiresAt IS NOT NULL" : "expiresAt IS NULL");
1005
1035
  if (filter.fromDate) {
1006
1036
  conditions.push(`${dateCol} >= ?`);
1007
1037
  params.push(filter.fromDate.toISOString());