@mastra/dynamodb 1.4.4 → 1.4.5-alpha.1
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/docs/references/integrations-databases-dynamodb.md +4 -4
- package/dist/index.cjs +24 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -44
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BackgroundTasksStorage, MastraCompositeStore, MemoryStorage, RunFenceCo
|
|
|
5
5
|
import { Entity, Service } from "electrodb";
|
|
6
6
|
import { MessageList } from "@mastra/core/agent";
|
|
7
7
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
8
|
-
|
|
8
|
+
// src/entities/utils.ts
|
|
9
9
|
const baseAttributes = {
|
|
10
10
|
createdAt: {
|
|
11
11
|
type: "string",
|
|
@@ -61,8 +61,7 @@ const baseAttributes = {
|
|
|
61
61
|
required: false
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
|
|
65
|
-
//#region src/entities/background-task.ts
|
|
64
|
+
// src/entities/background-task.ts
|
|
66
65
|
/**
|
|
67
66
|
* JSON field helpers — DynamoDB stores JSON as stringified strings,
|
|
68
67
|
* and parses them on get.
|
|
@@ -225,8 +224,7 @@ const backgroundTaskEntity = new Entity({
|
|
|
225
224
|
}
|
|
226
225
|
}
|
|
227
226
|
});
|
|
228
|
-
|
|
229
|
-
//#region src/entities/eval.ts
|
|
227
|
+
// src/entities/eval.ts
|
|
230
228
|
const evalEntity = new Entity({
|
|
231
229
|
model: {
|
|
232
230
|
entity: "eval",
|
|
@@ -324,8 +322,7 @@ const evalEntity = new Entity({
|
|
|
324
322
|
}
|
|
325
323
|
}
|
|
326
324
|
});
|
|
327
|
-
|
|
328
|
-
//#region src/entities/message.ts
|
|
325
|
+
// src/entities/message.ts
|
|
329
326
|
const messageEntity = new Entity({
|
|
330
327
|
model: {
|
|
331
328
|
entity: "message",
|
|
@@ -447,8 +444,7 @@ const messageEntity = new Entity({
|
|
|
447
444
|
}
|
|
448
445
|
}
|
|
449
446
|
});
|
|
450
|
-
|
|
451
|
-
//#region src/entities/resource.ts
|
|
447
|
+
// src/entities/resource.ts
|
|
452
448
|
const resourceEntity = new Entity({
|
|
453
449
|
model: {
|
|
454
450
|
entity: "resource",
|
|
@@ -497,8 +493,7 @@ const resourceEntity = new Entity({
|
|
|
497
493
|
}
|
|
498
494
|
} }
|
|
499
495
|
});
|
|
500
|
-
|
|
501
|
-
//#region src/entities/run-fencing.ts
|
|
496
|
+
// src/entities/run-fencing.ts
|
|
502
497
|
/**
|
|
503
498
|
* The current claim on a durable workflow run. `leaseExpiresAt` holds the
|
|
504
499
|
* lease's expiry in epoch milliseconds and is removed when the owner releases
|
|
@@ -571,8 +566,7 @@ const memoryRunFenceEntity = new Entity({
|
|
|
571
566
|
}
|
|
572
567
|
} }
|
|
573
568
|
});
|
|
574
|
-
|
|
575
|
-
//#region src/entities/score.ts
|
|
569
|
+
// src/entities/score.ts
|
|
576
570
|
const scoreEntity = new Entity({
|
|
577
571
|
model: {
|
|
578
572
|
entity: "score",
|
|
@@ -932,8 +926,7 @@ const scoreEntity = new Entity({
|
|
|
932
926
|
}
|
|
933
927
|
}
|
|
934
928
|
});
|
|
935
|
-
|
|
936
|
-
//#region src/entities/thread.ts
|
|
929
|
+
// src/entities/thread.ts
|
|
937
930
|
const threadEntity = new Entity({
|
|
938
931
|
model: {
|
|
939
932
|
entity: "thread",
|
|
@@ -999,8 +992,7 @@ const threadEntity = new Entity({
|
|
|
999
992
|
}
|
|
1000
993
|
}
|
|
1001
994
|
});
|
|
1002
|
-
|
|
1003
|
-
//#region src/entities/trace.ts
|
|
995
|
+
// src/entities/trace.ts
|
|
1004
996
|
const traceEntity = new Entity({
|
|
1005
997
|
model: {
|
|
1006
998
|
entity: "trace",
|
|
@@ -1129,8 +1121,7 @@ const traceEntity = new Entity({
|
|
|
1129
1121
|
}
|
|
1130
1122
|
}
|
|
1131
1123
|
});
|
|
1132
|
-
|
|
1133
|
-
//#region src/entities/workflow-snapshot.ts
|
|
1124
|
+
// src/entities/workflow-snapshot.ts
|
|
1134
1125
|
const workflowSnapshotEntity = new Entity({
|
|
1135
1126
|
model: {
|
|
1136
1127
|
entity: "workflow_snapshot",
|
|
@@ -1191,8 +1182,7 @@ const workflowSnapshotEntity = new Entity({
|
|
|
1191
1182
|
}
|
|
1192
1183
|
}
|
|
1193
1184
|
});
|
|
1194
|
-
|
|
1195
|
-
//#region src/entities/index.ts
|
|
1185
|
+
// src/entities/index.ts
|
|
1196
1186
|
function getElectroDbService(client, tableName) {
|
|
1197
1187
|
return new Service({
|
|
1198
1188
|
thread: threadEntity,
|
|
@@ -1210,8 +1200,7 @@ function getElectroDbService(client, tableName) {
|
|
|
1210
1200
|
table: tableName
|
|
1211
1201
|
});
|
|
1212
1202
|
}
|
|
1213
|
-
|
|
1214
|
-
//#region src/storage/db/index.ts
|
|
1203
|
+
// src/storage/db/index.ts
|
|
1215
1204
|
/**
|
|
1216
1205
|
* Resolves DynamoDBDomainConfig to an ElectroDB service and TTL config.
|
|
1217
1206
|
* Handles creating a new service if config is provided.
|
|
@@ -1231,8 +1220,7 @@ function resolveDynamoDBConfig(config) {
|
|
|
1231
1220
|
ttl: config.ttl
|
|
1232
1221
|
};
|
|
1233
1222
|
}
|
|
1234
|
-
|
|
1235
|
-
//#region src/storage/domains/utils.ts
|
|
1223
|
+
// src/storage/domains/utils.ts
|
|
1236
1224
|
/**
|
|
1237
1225
|
* Maps table names to ElectroDB entity names
|
|
1238
1226
|
*/
|
|
@@ -1286,8 +1274,7 @@ async function deleteTableData(service, tableName) {
|
|
|
1286
1274
|
await entity.delete(keysToDelete).go();
|
|
1287
1275
|
}
|
|
1288
1276
|
}
|
|
1289
|
-
|
|
1290
|
-
//#region src/storage/domains/background-tasks/index.ts
|
|
1277
|
+
// src/storage/domains/background-tasks/index.ts
|
|
1291
1278
|
const ENTITY = "background_task";
|
|
1292
1279
|
function serializeJson(v) {
|
|
1293
1280
|
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
@@ -1562,8 +1549,7 @@ var BackgroundTasksStorageDynamoDB = class extends BackgroundTasksStorage {
|
|
|
1562
1549
|
return total;
|
|
1563
1550
|
}
|
|
1564
1551
|
};
|
|
1565
|
-
|
|
1566
|
-
//#region src/storage/ttl.ts
|
|
1552
|
+
// src/storage/ttl.ts
|
|
1567
1553
|
/**
|
|
1568
1554
|
* Calculate TTL value for a given entity type.
|
|
1569
1555
|
*
|
|
@@ -1617,8 +1603,7 @@ function getTtlProps(entityName, ttlConfig, customTtlSeconds) {
|
|
|
1617
1603
|
if (ttlValue === void 0) return {};
|
|
1618
1604
|
return { [getTtlAttributeName(entityName, ttlConfig)]: ttlValue };
|
|
1619
1605
|
}
|
|
1620
|
-
|
|
1621
|
-
//#region src/storage/domains/run-fencing.ts
|
|
1606
|
+
// src/storage/domains/run-fencing.ts
|
|
1622
1607
|
const MAX_CONFLICT_RETRIES = 8;
|
|
1623
1608
|
const BASE_DELAY_MS$1 = 20;
|
|
1624
1609
|
async function backoff(attempt) {
|
|
@@ -1734,8 +1719,7 @@ async function pruneRunClaims(service, entityName, attribute, cutoff, limit) {
|
|
|
1734
1719
|
} while (cursor);
|
|
1735
1720
|
return deleted;
|
|
1736
1721
|
}
|
|
1737
|
-
|
|
1738
|
-
//#region src/storage/domains/memory/index.ts
|
|
1722
|
+
// src/storage/domains/memory/index.ts
|
|
1739
1723
|
var MemoryStorageDynamoDB = class MemoryStorageDynamoDB extends MemoryStorage {
|
|
1740
1724
|
/**
|
|
1741
1725
|
* Tables `prune()` can clean up. Run fences anchor on `retiredAt` (epoch ms), which stays unset until the
|
|
@@ -2582,8 +2566,7 @@ var MemoryStorageDynamoDB = class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
2582
2566
|
}
|
|
2583
2567
|
}
|
|
2584
2568
|
};
|
|
2585
|
-
|
|
2586
|
-
//#region src/storage/domains/scores/index.ts
|
|
2569
|
+
// src/storage/domains/scores/index.ts
|
|
2587
2570
|
/** Returns true when a score matches the multi-tenant scope filters (or none provided). */
|
|
2588
2571
|
function matchesTenancy(score, filters) {
|
|
2589
2572
|
if (filters?.organizationId !== void 0 && score.organizationId !== filters.organizationId) return false;
|
|
@@ -2882,8 +2865,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2882
2865
|
}
|
|
2883
2866
|
}
|
|
2884
2867
|
};
|
|
2885
|
-
|
|
2886
|
-
//#region src/storage/domains/workflows/index.ts
|
|
2868
|
+
// src/storage/domains/workflows/index.ts
|
|
2887
2869
|
function formatWorkflowRun(snapshotData) {
|
|
2888
2870
|
return {
|
|
2889
2871
|
workflowName: snapshotData.workflow_name,
|
|
@@ -3093,7 +3075,7 @@ var WorkflowStorageDynamoDB = class WorkflowStorageDynamoDB extends WorkflowsSto
|
|
|
3093
3075
|
entity: "workflow_snapshot",
|
|
3094
3076
|
workflow_name: workflowName,
|
|
3095
3077
|
run_id: runId
|
|
3096
|
-
}).go();
|
|
3078
|
+
}).go({ consistent: true });
|
|
3097
3079
|
const now = /* @__PURE__ */ new Date();
|
|
3098
3080
|
let snapshot;
|
|
3099
3081
|
let previousUpdatedAt;
|
|
@@ -3171,7 +3153,7 @@ var WorkflowStorageDynamoDB = class WorkflowStorageDynamoDB extends WorkflowsSto
|
|
|
3171
3153
|
entity: "workflow_snapshot",
|
|
3172
3154
|
workflow_name: workflowName,
|
|
3173
3155
|
run_id: runId
|
|
3174
|
-
}).go();
|
|
3156
|
+
}).go({ consistent: true });
|
|
3175
3157
|
const existingSnapshot = existingRecord.data?.snapshot;
|
|
3176
3158
|
const { expectedStatus, ...state } = opts;
|
|
3177
3159
|
if (!existingSnapshot?.context || !matchesExpectedWorkflowStatus(existingSnapshot.status, expectedStatus)) {
|
|
@@ -3283,7 +3265,7 @@ var WorkflowStorageDynamoDB = class WorkflowStorageDynamoDB extends WorkflowsSto
|
|
|
3283
3265
|
entity: "workflow_snapshot",
|
|
3284
3266
|
workflow_name: workflowName,
|
|
3285
3267
|
run_id: runId
|
|
3286
|
-
}).go();
|
|
3268
|
+
}).go({ consistent: true });
|
|
3287
3269
|
if (!result.data?.snapshot) return null;
|
|
3288
3270
|
return result.data.snapshot;
|
|
3289
3271
|
} catch (error) {
|
|
@@ -3380,7 +3362,7 @@ var WorkflowStorageDynamoDB = class WorkflowStorageDynamoDB extends WorkflowsSto
|
|
|
3380
3362
|
entity: "workflow_snapshot",
|
|
3381
3363
|
workflow_name: workflowName,
|
|
3382
3364
|
run_id: runId
|
|
3383
|
-
}).go();
|
|
3365
|
+
}).go({ consistent: true });
|
|
3384
3366
|
if (!result.data) return null;
|
|
3385
3367
|
const snapshot = result.data.snapshot;
|
|
3386
3368
|
return {
|
|
@@ -3445,8 +3427,7 @@ var WorkflowStorageDynamoDB = class WorkflowStorageDynamoDB extends WorkflowsSto
|
|
|
3445
3427
|
}
|
|
3446
3428
|
}
|
|
3447
3429
|
};
|
|
3448
|
-
|
|
3449
|
-
//#region src/storage/index.ts
|
|
3430
|
+
// src/storage/index.ts
|
|
3450
3431
|
/**
|
|
3451
3432
|
* Type guard for pre-configured client config
|
|
3452
3433
|
*/
|
|
@@ -3591,7 +3572,6 @@ var DynamoDBStore = class extends MastraCompositeStore {
|
|
|
3591
3572
|
}
|
|
3592
3573
|
}
|
|
3593
3574
|
};
|
|
3594
|
-
//#endregion
|
|
3595
3575
|
export { BackgroundTasksStorageDynamoDB, DynamoDBStore, MemoryStorageDynamoDB, ScoresStorageDynamoDB, WorkflowStorageDynamoDB, calculateTtl, getTtlAttributeName, getTtlProps, isTtlEnabled };
|
|
3596
3576
|
|
|
3597
3577
|
//# sourceMappingURL=index.js.map
|