@mastra/cloudflare-d1 1.4.4-alpha.0 → 1.4.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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +48 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -36
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
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.4.4
|
|
6
|
+
version: "1.4.4"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
@@ -311,10 +311,11 @@ async function assertRunFence(db, { claimsTable, fence, operation }) {
|
|
|
311
311
|
params: [fence.runId],
|
|
312
312
|
first: true
|
|
313
313
|
});
|
|
314
|
-
|
|
314
|
+
const current = row ? {
|
|
315
315
|
generation: Number(row.generation),
|
|
316
316
|
ownerId: String(row.ownerId)
|
|
317
|
-
} : null
|
|
317
|
+
} : null;
|
|
318
|
+
if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
|
|
318
319
|
}
|
|
319
320
|
/**
|
|
320
321
|
* Runs one statement of a fenced write. With a check, `statement` must carry
|
|
@@ -403,15 +404,16 @@ var D1DB = class extends _mastra_core_base.MastraBase {
|
|
|
403
404
|
const statement = this.binding.prepare(sql);
|
|
404
405
|
const formattedParams = this.formatSqlParams(params);
|
|
405
406
|
let result;
|
|
406
|
-
if (formattedParams.length > 0)
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
407
|
+
if (formattedParams.length > 0) {
|
|
408
|
+
if (first) {
|
|
409
|
+
result = await statement.bind(...formattedParams).first();
|
|
410
|
+
if (!result) return null;
|
|
411
|
+
return result;
|
|
412
|
+
} else {
|
|
413
|
+
result = await statement.bind(...formattedParams).all();
|
|
414
|
+
return result.results || [];
|
|
415
|
+
}
|
|
416
|
+
} else if (first) {
|
|
415
417
|
result = await statement.first();
|
|
416
418
|
if (!result) return null;
|
|
417
419
|
return result;
|
|
@@ -900,15 +902,19 @@ var BackgroundTasksStorageD1 = class extends _mastra_core_storage.BackgroundTask
|
|
|
900
902
|
predicates += " AND status = ?";
|
|
901
903
|
params.push(options.expectedStatus);
|
|
902
904
|
}
|
|
903
|
-
if (options?.expectedOwnerId !== void 0)
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
905
|
+
if (options?.expectedOwnerId !== void 0) {
|
|
906
|
+
if (options.expectedOwnerId === null) predicates += " AND ownerId IS NULL";
|
|
907
|
+
else {
|
|
908
|
+
predicates += " AND ownerId = ?";
|
|
909
|
+
params.push(options.expectedOwnerId);
|
|
910
|
+
}
|
|
907
911
|
}
|
|
908
|
-
if (options?.expectedLeaseExpiresAt !== void 0)
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
+
if (options?.expectedLeaseExpiresAt !== void 0) {
|
|
913
|
+
if (options.expectedLeaseExpiresAt === null) predicates += " AND leaseExpiresAt IS NULL";
|
|
914
|
+
else {
|
|
915
|
+
predicates += " AND leaseExpiresAt = ?";
|
|
916
|
+
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
917
|
+
}
|
|
912
918
|
}
|
|
913
919
|
const fullTableName = this.#db.getTableName(_mastra_core_storage.TABLE_BACKGROUND_TASKS);
|
|
914
920
|
const result = await this.#db.executeQuery({
|
|
@@ -1121,13 +1127,14 @@ var MemoryStorageD1 = class MemoryStorageD1 extends _mastra_core_storage.MemoryS
|
|
|
1121
1127
|
});
|
|
1122
1128
|
}
|
|
1123
1129
|
async prune(policies, options) {
|
|
1130
|
+
const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
|
|
1131
|
+
policies,
|
|
1132
|
+
descriptor: MemoryStorageD1.retentionTables,
|
|
1133
|
+
order: ["runFences"]
|
|
1134
|
+
});
|
|
1124
1135
|
return (0, _mastra_core_storage.executeRetentionPrune)({
|
|
1125
1136
|
domain: "memory",
|
|
1126
|
-
targets
|
|
1127
|
-
policies,
|
|
1128
|
-
descriptor: MemoryStorageD1.retentionTables,
|
|
1129
|
-
order: ["runFences"]
|
|
1130
|
-
}),
|
|
1137
|
+
targets,
|
|
1131
1138
|
options,
|
|
1132
1139
|
cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
|
|
1133
1140
|
deleteBatch: (_target, cutoff, limit) => this.#db.pruneRunRows({
|
|
@@ -2120,9 +2127,10 @@ var ScoresStorageD1 = class extends _mastra_core_storage.ScoresStorage {
|
|
|
2120
2127
|
try {
|
|
2121
2128
|
const fullTableName = this.#db.getTableName(_mastra_core_storage.TABLE_SCORERS);
|
|
2122
2129
|
const serializedRecord = {};
|
|
2123
|
-
for (const [key, value] of Object.entries(parsedScore)) if (value !== null && value !== void 0)
|
|
2124
|
-
|
|
2125
|
-
|
|
2130
|
+
for (const [key, value] of Object.entries(parsedScore)) if (value !== null && value !== void 0) {
|
|
2131
|
+
if (typeof value === "object") serializedRecord[key] = JSON.stringify(value);
|
|
2132
|
+
else serializedRecord[key] = value;
|
|
2133
|
+
} else serializedRecord[key] = null;
|
|
2126
2134
|
const now = /* @__PURE__ */ new Date();
|
|
2127
2135
|
serializedRecord.id = id;
|
|
2128
2136
|
serializedRecord.createdAt = now.toISOString();
|
|
@@ -2393,13 +2401,14 @@ var WorkflowsStorageD1 = class WorkflowsStorageD1 extends _mastra_core_storage.W
|
|
|
2393
2401
|
});
|
|
2394
2402
|
}
|
|
2395
2403
|
async prune(policies, options) {
|
|
2404
|
+
const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
|
|
2405
|
+
policies,
|
|
2406
|
+
descriptor: WorkflowsStorageD1.retentionTables,
|
|
2407
|
+
order: ["runOwnership"]
|
|
2408
|
+
});
|
|
2396
2409
|
return (0, _mastra_core_storage.executeRetentionPrune)({
|
|
2397
2410
|
domain: "workflows",
|
|
2398
|
-
targets
|
|
2399
|
-
policies,
|
|
2400
|
-
descriptor: WorkflowsStorageD1.retentionTables,
|
|
2401
|
-
order: ["runOwnership"]
|
|
2402
|
-
}),
|
|
2411
|
+
targets,
|
|
2403
2412
|
options,
|
|
2404
2413
|
cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
|
|
2405
2414
|
deleteBatch: (_target, cutoff, limit) => this.#db.pruneRunRows({
|
|
@@ -2660,10 +2669,12 @@ var WorkflowsStorageD1 = class WorkflowsStorageD1 extends _mastra_core_storage.W
|
|
|
2660
2669
|
builder.whereAnd("CASE WHEN json_valid(snapshot) THEN json_extract(snapshot, '$.status') END = ?", status);
|
|
2661
2670
|
countBuilder.whereAnd("CASE WHEN json_valid(snapshot) THEN json_extract(snapshot, '$.status') END = ?", status);
|
|
2662
2671
|
}
|
|
2663
|
-
if (resourceId)
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2672
|
+
if (resourceId) {
|
|
2673
|
+
if (await this.#db.hasColumn(fullTableName, "resourceId")) {
|
|
2674
|
+
builder.whereAnd("resourceId = ?", resourceId);
|
|
2675
|
+
countBuilder.whereAnd("resourceId = ?", resourceId);
|
|
2676
|
+
} else this.logger.warn(`[${fullTableName}] resourceId column not found. Skipping resourceId filter.`);
|
|
2677
|
+
}
|
|
2667
2678
|
if (fromDate) {
|
|
2668
2679
|
builder.whereAnd("createdAt >= ?", fromDate instanceof Date ? fromDate.toISOString() : fromDate);
|
|
2669
2680
|
countBuilder.whereAnd("createdAt >= ?", fromDate instanceof Date ? fromDate.toISOString() : fromDate);
|