@mastra/cloudflare-d1 1.3.2 → 1.4.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 +39 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -7
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +2 -4
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -666,7 +666,9 @@ function rowToTask(row) {
|
|
|
666
666
|
createdAt: new Date(row.createdAt),
|
|
667
667
|
startedAt: row.startedAt ? new Date(row.startedAt) : void 0,
|
|
668
668
|
suspendedAt: row.suspendedAt ? new Date(row.suspendedAt) : void 0,
|
|
669
|
-
completedAt: row.completedAt ? new Date(row.completedAt) : void 0
|
|
669
|
+
completedAt: row.completedAt ? new Date(row.completedAt) : void 0,
|
|
670
|
+
ownerId: row.ownerId || void 0,
|
|
671
|
+
leaseExpiresAt: row.leaseExpiresAt ? new Date(row.leaseExpiresAt) : void 0
|
|
670
672
|
};
|
|
671
673
|
}
|
|
672
674
|
var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
@@ -684,7 +686,12 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
684
686
|
await this.#db.alterTable({
|
|
685
687
|
tableName: TABLE_BACKGROUND_TASKS,
|
|
686
688
|
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
|
|
687
|
-
ifNotExists: [
|
|
689
|
+
ifNotExists: [
|
|
690
|
+
"suspend_payload",
|
|
691
|
+
"suspendedAt",
|
|
692
|
+
"ownerId",
|
|
693
|
+
"leaseExpiresAt"
|
|
694
|
+
]
|
|
688
695
|
});
|
|
689
696
|
}
|
|
690
697
|
async dangerouslyClearAll() {
|
|
@@ -711,7 +718,9 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
711
718
|
"createdAt",
|
|
712
719
|
"startedAt",
|
|
713
720
|
"suspendedAt",
|
|
714
|
-
"completedAt"
|
|
721
|
+
"completedAt",
|
|
722
|
+
"ownerId",
|
|
723
|
+
"leaseExpiresAt"
|
|
715
724
|
], [
|
|
716
725
|
task.id,
|
|
717
726
|
task.toolCallId,
|
|
@@ -731,7 +740,9 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
731
740
|
task.createdAt.toISOString(),
|
|
732
741
|
task.startedAt?.toISOString() ?? null,
|
|
733
742
|
task.suspendedAt?.toISOString() ?? null,
|
|
734
|
-
task.completedAt?.toISOString() ?? null
|
|
743
|
+
task.completedAt?.toISOString() ?? null,
|
|
744
|
+
task.ownerId ?? null,
|
|
745
|
+
task.leaseExpiresAt?.toISOString() ?? null
|
|
735
746
|
]).build();
|
|
736
747
|
await this.#db.executeQuery({
|
|
737
748
|
sql,
|
|
@@ -773,13 +784,34 @@ var BackgroundTasksStorageD1 = class extends BackgroundTasksStorage {
|
|
|
773
784
|
sets.push("completedAt = ?");
|
|
774
785
|
params.push(update.completedAt?.toISOString() ?? null);
|
|
775
786
|
}
|
|
787
|
+
if ("ownerId" in update) {
|
|
788
|
+
sets.push("ownerId = ?");
|
|
789
|
+
params.push(update.ownerId ?? null);
|
|
790
|
+
}
|
|
791
|
+
if ("leaseExpiresAt" in update) {
|
|
792
|
+
sets.push("leaseExpiresAt = ?");
|
|
793
|
+
params.push(update.leaseExpiresAt?.toISOString() ?? null);
|
|
794
|
+
}
|
|
776
795
|
if (sets.length === 0) return false;
|
|
777
796
|
params.push(taskId);
|
|
778
|
-
|
|
779
|
-
if (options?.expectedStatus)
|
|
797
|
+
let predicates = "";
|
|
798
|
+
if (options?.expectedStatus) {
|
|
799
|
+
predicates += " AND status = ?";
|
|
800
|
+
params.push(options.expectedStatus);
|
|
801
|
+
}
|
|
802
|
+
if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates += " AND ownerId IS NULL";
|
|
803
|
+
else {
|
|
804
|
+
predicates += " AND ownerId = ?";
|
|
805
|
+
params.push(options.expectedOwnerId);
|
|
806
|
+
}
|
|
807
|
+
if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates += " AND leaseExpiresAt IS NULL";
|
|
808
|
+
else {
|
|
809
|
+
predicates += " AND leaseExpiresAt = ?";
|
|
810
|
+
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
811
|
+
}
|
|
780
812
|
const fullTableName = this.#db.getTableName(TABLE_BACKGROUND_TASKS);
|
|
781
813
|
const result = await this.#db.executeQuery({
|
|
782
|
-
sql: `UPDATE ${fullTableName} SET ${sets.join(", ")} WHERE id = ?${
|
|
814
|
+
sql: `UPDATE ${fullTableName} SET ${sets.join(", ")} WHERE id = ?${predicates} RETURNING id`,
|
|
783
815
|
params
|
|
784
816
|
});
|
|
785
817
|
return Array.isArray(result) && result.length > 0;
|