@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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +37 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -7
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +1 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -562,7 +562,7 @@ var D1DB = class extends MastraBase {
|
|
|
562
562
|
const existingColumns = await this.getTableColumns(fullTableName);
|
|
563
563
|
const existingColumnNames = new Set(existingColumns.map((col) => col.name));
|
|
564
564
|
for (const [columnName, column] of Object.entries(args.schema)) if (!existingColumnNames.has(columnName) && args.ifNotExists.includes(columnName)) {
|
|
565
|
-
const sql = `ALTER TABLE ${fullTableName} ADD COLUMN ${columnName} ${this.getSqlType(column.type)} ${this.getDefaultValue(column.type)}`;
|
|
565
|
+
const sql = `ALTER TABLE ${fullTableName} ADD COLUMN ${columnName} ${this.getSqlType(column.type)} ${column.nullable ? "DEFAULT NULL" : this.getDefaultValue(column.type)}`;
|
|
566
566
|
await this.executeQuery({ sql });
|
|
567
567
|
this.logger.debug(`Added column ${columnName} to table ${fullTableName}`);
|
|
568
568
|
}
|
|
@@ -741,10 +741,13 @@ function rowToTask(row) {
|
|
|
741
741
|
suspendedAt: row.suspendedAt ? new Date(row.suspendedAt) : void 0,
|
|
742
742
|
completedAt: row.completedAt ? new Date(row.completedAt) : void 0,
|
|
743
743
|
ownerId: row.ownerId || void 0,
|
|
744
|
-
leaseExpiresAt: row.leaseExpiresAt ? new Date(row.leaseExpiresAt) : void 0
|
|
744
|
+
leaseExpiresAt: row.leaseExpiresAt ? new Date(row.leaseExpiresAt) : void 0,
|
|
745
|
+
expiresAt: row.expiresAt ? new Date(row.expiresAt) : void 0,
|
|
746
|
+
metadata: parseJson(row.metadata)
|
|
745
747
|
};
|
|
746
748
|
}
|
|
747
749
|
var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
750
|
+
supportsTaskExpiry = true;
|
|
748
751
|
#db;
|
|
749
752
|
constructor(config) {
|
|
750
753
|
super();
|
|
@@ -763,7 +766,9 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
763
766
|
"suspend_payload",
|
|
764
767
|
"suspendedAt",
|
|
765
768
|
"ownerId",
|
|
766
|
-
"leaseExpiresAt"
|
|
769
|
+
"leaseExpiresAt",
|
|
770
|
+
"expiresAt",
|
|
771
|
+
"metadata"
|
|
767
772
|
]
|
|
768
773
|
});
|
|
769
774
|
}
|
|
@@ -793,7 +798,9 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
793
798
|
"suspendedAt",
|
|
794
799
|
"completedAt",
|
|
795
800
|
"ownerId",
|
|
796
|
-
"leaseExpiresAt"
|
|
801
|
+
"leaseExpiresAt",
|
|
802
|
+
"expiresAt",
|
|
803
|
+
"metadata"
|
|
797
804
|
], [
|
|
798
805
|
task.id,
|
|
799
806
|
task.toolCallId,
|
|
@@ -815,7 +822,9 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
815
822
|
task.suspendedAt?.toISOString() ?? null,
|
|
816
823
|
task.completedAt?.toISOString() ?? null,
|
|
817
824
|
task.ownerId ?? null,
|
|
818
|
-
task.leaseExpiresAt?.toISOString() ?? null
|
|
825
|
+
task.leaseExpiresAt?.toISOString() ?? null,
|
|
826
|
+
task.expiresAt?.toISOString() ?? null,
|
|
827
|
+
serializeJson(task.metadata)
|
|
819
828
|
]).build();
|
|
820
829
|
await this.#db.executeQuery({
|
|
821
830
|
sql,
|
|
@@ -865,6 +874,14 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
865
874
|
sets.push("leaseExpiresAt = ?");
|
|
866
875
|
params.push(update.leaseExpiresAt?.toISOString() ?? null);
|
|
867
876
|
}
|
|
877
|
+
if ("expiresAt" in update) {
|
|
878
|
+
sets.push("expiresAt = ?");
|
|
879
|
+
params.push(update.expiresAt?.toISOString() ?? null);
|
|
880
|
+
}
|
|
881
|
+
if ("metadata" in update) {
|
|
882
|
+
sets.push("metadata = ?");
|
|
883
|
+
params.push(serializeJson(update.metadata));
|
|
884
|
+
}
|
|
868
885
|
if (sets.length === 0) return false;
|
|
869
886
|
params.push(taskId);
|
|
870
887
|
let predicates = "";
|
|
@@ -886,6 +903,13 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
886
903
|
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
887
904
|
}
|
|
888
905
|
}
|
|
906
|
+
if (options?.expectedSuspendedAt !== void 0) {
|
|
907
|
+
if (options.expectedSuspendedAt === null) predicates += " AND suspendedAt IS NULL";
|
|
908
|
+
else {
|
|
909
|
+
predicates += " AND suspendedAt = ?";
|
|
910
|
+
params.push(options.expectedSuspendedAt.toISOString());
|
|
911
|
+
}
|
|
912
|
+
}
|
|
889
913
|
const fullTableName = this.#db.getTableName(TABLE_BACKGROUND_TASKS);
|
|
890
914
|
const result = await this.#db.executeQuery({
|
|
891
915
|
sql: `UPDATE ${fullTableName} SET ${sets.join(", ")} WHERE id = ?${predicates} RETURNING id`,
|
|
@@ -932,7 +956,12 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
932
956
|
builder = builder.whereAnd("tool_call_id = ?", filter.toolCallId);
|
|
933
957
|
countBuilder = countBuilder.whereAnd("tool_call_id = ?", filter.toolCallId);
|
|
934
958
|
}
|
|
935
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
959
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
|
|
960
|
+
if (filter.hasExpiresAt !== void 0) {
|
|
961
|
+
const clause = filter.hasExpiresAt ? "expiresAt IS NOT NULL" : "expiresAt IS NULL";
|
|
962
|
+
builder = builder.whereAnd(clause);
|
|
963
|
+
countBuilder = countBuilder.whereAnd(clause);
|
|
964
|
+
}
|
|
936
965
|
if (filter.fromDate) {
|
|
937
966
|
builder = builder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
|
|
938
967
|
countBuilder = countBuilder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
|
|
@@ -978,7 +1007,8 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
978
1007
|
conditions.push(`status IN (${statuses.map(() => "?").join(",")})`);
|
|
979
1008
|
params.push(...statuses);
|
|
980
1009
|
}
|
|
981
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
1010
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
|
|
1011
|
+
if (filter.hasExpiresAt !== void 0) conditions.push(filter.hasExpiresAt ? "expiresAt IS NOT NULL" : "expiresAt IS NULL");
|
|
982
1012
|
if (filter.fromDate) {
|
|
983
1013
|
conditions.push(`${dateCol} >= ?`);
|
|
984
1014
|
params.push(filter.fromDate.toISOString());
|