@mastra/cloudflare-d1 1.4.5-alpha.2 → 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 +43 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -15
- 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/dist/storage/sql-builder.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.
|
|
6
|
+
version: "1.5.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -87,7 +87,7 @@ var SqlBuilder = class {
|
|
|
87
87
|
*/
|
|
88
88
|
whereAnd(condition, ...params) {
|
|
89
89
|
if (this.whereAdded) return this.andWhere(condition, ...params);
|
|
90
|
-
|
|
90
|
+
return this.where(condition, ...params);
|
|
91
91
|
}
|
|
92
92
|
andWhere(condition, ...params) {
|
|
93
93
|
this.sql += ` AND ${condition}`;
|
|
@@ -405,18 +405,16 @@ var D1DB = class extends _mastra_core_base.MastraBase {
|
|
|
405
405
|
result = await statement.bind(...formattedParams).first();
|
|
406
406
|
if (!result) return null;
|
|
407
407
|
return result;
|
|
408
|
-
} else {
|
|
409
|
-
result = await statement.bind(...formattedParams).all();
|
|
410
|
-
return result.results || [];
|
|
411
408
|
}
|
|
409
|
+
result = await statement.bind(...formattedParams).all();
|
|
410
|
+
return result.results || [];
|
|
412
411
|
} else if (first) {
|
|
413
412
|
result = await statement.first();
|
|
414
413
|
if (!result) return null;
|
|
415
414
|
return result;
|
|
416
|
-
} else {
|
|
417
|
-
result = await statement.all();
|
|
418
|
-
return result.results || [];
|
|
419
415
|
}
|
|
416
|
+
result = await statement.all();
|
|
417
|
+
return result.results || [];
|
|
420
418
|
} catch (error) {
|
|
421
419
|
throw new _mastra_core_error.MastraError({
|
|
422
420
|
id: (0, _mastra_core_storage.createStorageErrorId)("CLOUDFLARE_D1", "WORKERS_BINDING_QUERY", "FAILED"),
|
|
@@ -463,7 +461,7 @@ var D1DB = class extends _mastra_core_base.MastraBase {
|
|
|
463
461
|
async executeQuery(options) {
|
|
464
462
|
if (this.binding) return this.executeWorkersBindingQuery(options);
|
|
465
463
|
else if (this.client) return this.executeRestQuery(options);
|
|
466
|
-
|
|
464
|
+
throw new Error("Neither binding nor client is configured");
|
|
467
465
|
}
|
|
468
466
|
/**
|
|
469
467
|
* Gets the set of column names that actually exist in the database table.
|
|
@@ -587,7 +585,7 @@ var D1DB = class extends _mastra_core_base.MastraBase {
|
|
|
587
585
|
const existingColumns = await this.getTableColumns(fullTableName);
|
|
588
586
|
const existingColumnNames = new Set(existingColumns.map((col) => col.name));
|
|
589
587
|
for (const [columnName, column] of Object.entries(args.schema)) if (!existingColumnNames.has(columnName) && args.ifNotExists.includes(columnName)) {
|
|
590
|
-
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)}`;
|
|
591
589
|
await this.executeQuery({ sql });
|
|
592
590
|
this.logger.debug(`Added column ${columnName} to table ${fullTableName}`);
|
|
593
591
|
}
|
|
@@ -766,10 +764,13 @@ function rowToTask(row) {
|
|
|
766
764
|
suspendedAt: row.suspendedAt ? new Date(row.suspendedAt) : void 0,
|
|
767
765
|
completedAt: row.completedAt ? new Date(row.completedAt) : void 0,
|
|
768
766
|
ownerId: row.ownerId || void 0,
|
|
769
|
-
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)
|
|
770
770
|
};
|
|
771
771
|
}
|
|
772
772
|
var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTasksStorage {
|
|
773
|
+
supportsTaskExpiry = true;
|
|
773
774
|
#db;
|
|
774
775
|
constructor(config) {
|
|
775
776
|
super();
|
|
@@ -788,7 +789,9 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
788
789
|
"suspend_payload",
|
|
789
790
|
"suspendedAt",
|
|
790
791
|
"ownerId",
|
|
791
|
-
"leaseExpiresAt"
|
|
792
|
+
"leaseExpiresAt",
|
|
793
|
+
"expiresAt",
|
|
794
|
+
"metadata"
|
|
792
795
|
]
|
|
793
796
|
});
|
|
794
797
|
}
|
|
@@ -818,7 +821,9 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
818
821
|
"suspendedAt",
|
|
819
822
|
"completedAt",
|
|
820
823
|
"ownerId",
|
|
821
|
-
"leaseExpiresAt"
|
|
824
|
+
"leaseExpiresAt",
|
|
825
|
+
"expiresAt",
|
|
826
|
+
"metadata"
|
|
822
827
|
], [
|
|
823
828
|
task.id,
|
|
824
829
|
task.toolCallId,
|
|
@@ -840,7 +845,9 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
840
845
|
task.suspendedAt?.toISOString() ?? null,
|
|
841
846
|
task.completedAt?.toISOString() ?? null,
|
|
842
847
|
task.ownerId ?? null,
|
|
843
|
-
task.leaseExpiresAt?.toISOString() ?? null
|
|
848
|
+
task.leaseExpiresAt?.toISOString() ?? null,
|
|
849
|
+
task.expiresAt?.toISOString() ?? null,
|
|
850
|
+
serializeJson(task.metadata)
|
|
844
851
|
]).build();
|
|
845
852
|
await this.#db.executeQuery({
|
|
846
853
|
sql,
|
|
@@ -890,6 +897,14 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
890
897
|
sets.push("leaseExpiresAt = ?");
|
|
891
898
|
params.push(update.leaseExpiresAt?.toISOString() ?? null);
|
|
892
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
|
+
}
|
|
893
908
|
if (sets.length === 0) return false;
|
|
894
909
|
params.push(taskId);
|
|
895
910
|
let predicates = "";
|
|
@@ -911,6 +926,13 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
911
926
|
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
912
927
|
}
|
|
913
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
|
+
}
|
|
914
936
|
const fullTableName = this.#db.getTableName(_mastra_core_storage.TABLE_BACKGROUND_TASKS);
|
|
915
937
|
const result = await this.#db.executeQuery({
|
|
916
938
|
sql: `UPDATE ${fullTableName} SET ${sets.join(", ")} WHERE id = ?${predicates} RETURNING id`,
|
|
@@ -957,7 +979,12 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
957
979
|
builder = builder.whereAnd("tool_call_id = ?", filter.toolCallId);
|
|
958
980
|
countBuilder = countBuilder.whereAnd("tool_call_id = ?", filter.toolCallId);
|
|
959
981
|
}
|
|
960
|
-
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
|
+
}
|
|
961
988
|
if (filter.fromDate) {
|
|
962
989
|
builder = builder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
|
|
963
990
|
countBuilder = countBuilder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
|
|
@@ -1003,7 +1030,8 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
1003
1030
|
conditions.push(`status IN (${statuses.map(() => "?").join(",")})`);
|
|
1004
1031
|
params.push(...statuses);
|
|
1005
1032
|
}
|
|
1006
|
-
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");
|
|
1007
1035
|
if (filter.fromDate) {
|
|
1008
1036
|
conditions.push(`${dateCol} >= ?`);
|
|
1009
1037
|
params.push(filter.fromDate.toISOString());
|