@mastra/dynamodb 1.4.5-alpha.0 → 1.4.5
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 +20 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -40
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
package/dist/docs/SKILL.md
CHANGED
|
@@ -50,7 +50,7 @@ bun add @mastra/dynamodb@latest
|
|
|
50
50
|
|
|
51
51
|
Before using this package, you **must** create a DynamoDB table with a specific structure, including primary keys and Global Secondary Indexes (GSIs). This adapter expects the DynamoDB table and its GSIs to be provisioned externally.
|
|
52
52
|
|
|
53
|
-
Detailed instructions for setting up the table using AWS CloudFormation or AWS CDK are available in [
|
|
53
|
+
Detailed instructions for setting up the table using AWS CloudFormation or AWS CDK are available in [TABLE_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md). Please ensure your table is configured according to those instructions before proceeding.
|
|
54
54
|
|
|
55
55
|
## Usage
|
|
56
56
|
|
|
@@ -122,7 +122,7 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
|
|
|
122
122
|
|
|
123
123
|
**config.credentials** (`object`): AWS credentials object with accessKeyId and secretAccessKey. If not provided, the AWS SDK will attempt to source credentials from environment variables, IAM roles (e.g., for EC2/Lambda), or the shared AWS credentials file.
|
|
124
124
|
|
|
125
|
-
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval,
|
|
125
|
+
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
|
|
126
126
|
|
|
127
127
|
## TTL (time to live) configuration
|
|
128
128
|
|
|
@@ -254,7 +254,7 @@ The IAM role or user executing the code needs appropriate permissions to interac
|
|
|
254
254
|
|
|
255
255
|
Before diving into the architectural details, keep these key points in mind when working with the DynamoDB storage adapter:
|
|
256
256
|
|
|
257
|
-
- **External Table Provisioning:** This adapter _requires_ you to create and configure the DynamoDB table and its Global Secondary Indexes (GSIs) yourself, prior to using the adapter. Follow the guide in [
|
|
257
|
+
- **External Table Provisioning:** This adapter _requires_ you to create and configure the DynamoDB table and its Global Secondary Indexes (GSIs) yourself, prior to using the adapter. Follow the guide in [TABLE_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md).
|
|
258
258
|
- **Single-Table Design:** All Mastra data (threads, messages, etc.) is stored in one DynamoDB table. This is a deliberate design choice optimized for DynamoDB, differing from relational database approaches.
|
|
259
259
|
- **Understanding GSIs:** Familiarity with how the GSIs are structured (as per `TABLE_SETUP.md`) is important for understanding data retrieval and potential query patterns.
|
|
260
260
|
- **ElectroDB:** The adapter uses ElectroDB to manage interactions with DynamoDB, providing a layer of abstraction and type safety over raw DynamoDB operations.
|
|
@@ -266,7 +266,7 @@ This storage adapter utilizes a **single-table design pattern** with [ElectroDB]
|
|
|
266
266
|
Key aspects of this approach:
|
|
267
267
|
|
|
268
268
|
- **DynamoDB Native:** The single-table design is optimized for DynamoDB's key-value and query capabilities, often leading to better performance and capacity compared to mimicking relational models.
|
|
269
|
-
- **External Table Management:** Unlike some adapters that might offer helper functions to create tables via code, this adapter **expects the DynamoDB table and its associated Global Secondary Indexes (GSIs) to be provisioned externally** before use. Please refer to [
|
|
269
|
+
- **External Table Management:** Unlike some adapters that might offer helper functions to create tables via code, this adapter **expects the DynamoDB table and its associated Global Secondary Indexes (GSIs) to be provisioned externally** before use. Please refer to [TABLE_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md) for detailed instructions using tools like AWS CloudFormation or CDK. The adapter focuses solely on interacting with the pre-existing table structure.
|
|
270
270
|
- **Consistency via Interface:** While the underlying storage model differs, this adapter adheres to the same `MastraStorage` interface as other adapters, ensuring it can be used interchangeably within the Mastra `Memory` component.
|
|
271
271
|
|
|
272
272
|
### Mastra Data in the Single Table
|
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ let _mastra_core_storage = require("@mastra/core/storage");
|
|
|
6
6
|
let electrodb = require("electrodb");
|
|
7
7
|
let _mastra_core_agent = require("@mastra/core/agent");
|
|
8
8
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
9
|
-
|
|
9
|
+
// src/entities/utils.ts
|
|
10
10
|
const baseAttributes = {
|
|
11
11
|
createdAt: {
|
|
12
12
|
type: "string",
|
|
@@ -62,8 +62,7 @@ const baseAttributes = {
|
|
|
62
62
|
required: false
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
|
|
66
|
-
//#region src/entities/background-task.ts
|
|
65
|
+
// src/entities/background-task.ts
|
|
67
66
|
/**
|
|
68
67
|
* JSON field helpers — DynamoDB stores JSON as stringified strings,
|
|
69
68
|
* and parses them on get.
|
|
@@ -226,8 +225,7 @@ const backgroundTaskEntity = new electrodb.Entity({
|
|
|
226
225
|
}
|
|
227
226
|
}
|
|
228
227
|
});
|
|
229
|
-
|
|
230
|
-
//#region src/entities/eval.ts
|
|
228
|
+
// src/entities/eval.ts
|
|
231
229
|
const evalEntity = new electrodb.Entity({
|
|
232
230
|
model: {
|
|
233
231
|
entity: "eval",
|
|
@@ -325,8 +323,7 @@ const evalEntity = new electrodb.Entity({
|
|
|
325
323
|
}
|
|
326
324
|
}
|
|
327
325
|
});
|
|
328
|
-
|
|
329
|
-
//#region src/entities/message.ts
|
|
326
|
+
// src/entities/message.ts
|
|
330
327
|
const messageEntity = new electrodb.Entity({
|
|
331
328
|
model: {
|
|
332
329
|
entity: "message",
|
|
@@ -448,8 +445,7 @@ const messageEntity = new electrodb.Entity({
|
|
|
448
445
|
}
|
|
449
446
|
}
|
|
450
447
|
});
|
|
451
|
-
|
|
452
|
-
//#region src/entities/resource.ts
|
|
448
|
+
// src/entities/resource.ts
|
|
453
449
|
const resourceEntity = new electrodb.Entity({
|
|
454
450
|
model: {
|
|
455
451
|
entity: "resource",
|
|
@@ -498,8 +494,7 @@ const resourceEntity = new electrodb.Entity({
|
|
|
498
494
|
}
|
|
499
495
|
} }
|
|
500
496
|
});
|
|
501
|
-
|
|
502
|
-
//#region src/entities/run-fencing.ts
|
|
497
|
+
// src/entities/run-fencing.ts
|
|
503
498
|
/**
|
|
504
499
|
* The current claim on a durable workflow run. `leaseExpiresAt` holds the
|
|
505
500
|
* lease's expiry in epoch milliseconds and is removed when the owner releases
|
|
@@ -572,8 +567,7 @@ const memoryRunFenceEntity = new electrodb.Entity({
|
|
|
572
567
|
}
|
|
573
568
|
} }
|
|
574
569
|
});
|
|
575
|
-
|
|
576
|
-
//#region src/entities/score.ts
|
|
570
|
+
// src/entities/score.ts
|
|
577
571
|
const scoreEntity = new electrodb.Entity({
|
|
578
572
|
model: {
|
|
579
573
|
entity: "score",
|
|
@@ -933,8 +927,7 @@ const scoreEntity = new electrodb.Entity({
|
|
|
933
927
|
}
|
|
934
928
|
}
|
|
935
929
|
});
|
|
936
|
-
|
|
937
|
-
//#region src/entities/thread.ts
|
|
930
|
+
// src/entities/thread.ts
|
|
938
931
|
const threadEntity = new electrodb.Entity({
|
|
939
932
|
model: {
|
|
940
933
|
entity: "thread",
|
|
@@ -1000,8 +993,7 @@ const threadEntity = new electrodb.Entity({
|
|
|
1000
993
|
}
|
|
1001
994
|
}
|
|
1002
995
|
});
|
|
1003
|
-
|
|
1004
|
-
//#region src/entities/trace.ts
|
|
996
|
+
// src/entities/trace.ts
|
|
1005
997
|
const traceEntity = new electrodb.Entity({
|
|
1006
998
|
model: {
|
|
1007
999
|
entity: "trace",
|
|
@@ -1130,8 +1122,7 @@ const traceEntity = new electrodb.Entity({
|
|
|
1130
1122
|
}
|
|
1131
1123
|
}
|
|
1132
1124
|
});
|
|
1133
|
-
|
|
1134
|
-
//#region src/entities/workflow-snapshot.ts
|
|
1125
|
+
// src/entities/workflow-snapshot.ts
|
|
1135
1126
|
const workflowSnapshotEntity = new electrodb.Entity({
|
|
1136
1127
|
model: {
|
|
1137
1128
|
entity: "workflow_snapshot",
|
|
@@ -1192,8 +1183,7 @@ const workflowSnapshotEntity = new electrodb.Entity({
|
|
|
1192
1183
|
}
|
|
1193
1184
|
}
|
|
1194
1185
|
});
|
|
1195
|
-
|
|
1196
|
-
//#region src/entities/index.ts
|
|
1186
|
+
// src/entities/index.ts
|
|
1197
1187
|
function getElectroDbService(client, tableName) {
|
|
1198
1188
|
return new electrodb.Service({
|
|
1199
1189
|
thread: threadEntity,
|
|
@@ -1211,8 +1201,7 @@ function getElectroDbService(client, tableName) {
|
|
|
1211
1201
|
table: tableName
|
|
1212
1202
|
});
|
|
1213
1203
|
}
|
|
1214
|
-
|
|
1215
|
-
//#region src/storage/db/index.ts
|
|
1204
|
+
// src/storage/db/index.ts
|
|
1216
1205
|
/**
|
|
1217
1206
|
* Resolves DynamoDBDomainConfig to an ElectroDB service and TTL config.
|
|
1218
1207
|
* Handles creating a new service if config is provided.
|
|
@@ -1232,8 +1221,7 @@ function resolveDynamoDBConfig(config) {
|
|
|
1232
1221
|
ttl: config.ttl
|
|
1233
1222
|
};
|
|
1234
1223
|
}
|
|
1235
|
-
|
|
1236
|
-
//#region src/storage/domains/utils.ts
|
|
1224
|
+
// src/storage/domains/utils.ts
|
|
1237
1225
|
/**
|
|
1238
1226
|
* Maps table names to ElectroDB entity names
|
|
1239
1227
|
*/
|
|
@@ -1287,8 +1275,7 @@ async function deleteTableData(service, tableName) {
|
|
|
1287
1275
|
await entity.delete(keysToDelete).go();
|
|
1288
1276
|
}
|
|
1289
1277
|
}
|
|
1290
|
-
|
|
1291
|
-
//#region src/storage/domains/background-tasks/index.ts
|
|
1278
|
+
// src/storage/domains/background-tasks/index.ts
|
|
1292
1279
|
const ENTITY = "background_task";
|
|
1293
1280
|
function serializeJson(v) {
|
|
1294
1281
|
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
@@ -1563,8 +1550,7 @@ var BackgroundTasksStorageDynamoDB = class extends _mastra_core_storage.Backgrou
|
|
|
1563
1550
|
return total;
|
|
1564
1551
|
}
|
|
1565
1552
|
};
|
|
1566
|
-
|
|
1567
|
-
//#region src/storage/ttl.ts
|
|
1553
|
+
// src/storage/ttl.ts
|
|
1568
1554
|
/**
|
|
1569
1555
|
* Calculate TTL value for a given entity type.
|
|
1570
1556
|
*
|
|
@@ -1618,8 +1604,7 @@ function getTtlProps(entityName, ttlConfig, customTtlSeconds) {
|
|
|
1618
1604
|
if (ttlValue === void 0) return {};
|
|
1619
1605
|
return { [getTtlAttributeName(entityName, ttlConfig)]: ttlValue };
|
|
1620
1606
|
}
|
|
1621
|
-
|
|
1622
|
-
//#region src/storage/domains/run-fencing.ts
|
|
1607
|
+
// src/storage/domains/run-fencing.ts
|
|
1623
1608
|
const MAX_CONFLICT_RETRIES = 8;
|
|
1624
1609
|
const BASE_DELAY_MS$1 = 20;
|
|
1625
1610
|
async function backoff(attempt) {
|
|
@@ -1735,8 +1720,7 @@ async function pruneRunClaims(service, entityName, attribute, cutoff, limit) {
|
|
|
1735
1720
|
} while (cursor);
|
|
1736
1721
|
return deleted;
|
|
1737
1722
|
}
|
|
1738
|
-
|
|
1739
|
-
//#region src/storage/domains/memory/index.ts
|
|
1723
|
+
// src/storage/domains/memory/index.ts
|
|
1740
1724
|
var MemoryStorageDynamoDB = class MemoryStorageDynamoDB extends _mastra_core_storage.MemoryStorage {
|
|
1741
1725
|
/**
|
|
1742
1726
|
* Tables `prune()` can clean up. Run fences anchor on `retiredAt` (epoch ms), which stays unset until the
|
|
@@ -2583,8 +2567,7 @@ var MemoryStorageDynamoDB = class MemoryStorageDynamoDB extends _mastra_core_sto
|
|
|
2583
2567
|
}
|
|
2584
2568
|
}
|
|
2585
2569
|
};
|
|
2586
|
-
|
|
2587
|
-
//#region src/storage/domains/scores/index.ts
|
|
2570
|
+
// src/storage/domains/scores/index.ts
|
|
2588
2571
|
/** Returns true when a score matches the multi-tenant scope filters (or none provided). */
|
|
2589
2572
|
function matchesTenancy(score, filters) {
|
|
2590
2573
|
if (filters?.organizationId !== void 0 && score.organizationId !== filters.organizationId) return false;
|
|
@@ -2883,8 +2866,7 @@ var ScoresStorageDynamoDB = class extends _mastra_core_storage.ScoresStorage {
|
|
|
2883
2866
|
}
|
|
2884
2867
|
}
|
|
2885
2868
|
};
|
|
2886
|
-
|
|
2887
|
-
//#region src/storage/domains/workflows/index.ts
|
|
2869
|
+
// src/storage/domains/workflows/index.ts
|
|
2888
2870
|
function formatWorkflowRun(snapshotData) {
|
|
2889
2871
|
return {
|
|
2890
2872
|
workflowName: snapshotData.workflow_name,
|
|
@@ -3446,8 +3428,7 @@ var WorkflowStorageDynamoDB = class WorkflowStorageDynamoDB extends _mastra_core
|
|
|
3446
3428
|
}
|
|
3447
3429
|
}
|
|
3448
3430
|
};
|
|
3449
|
-
|
|
3450
|
-
//#region src/storage/index.ts
|
|
3431
|
+
// src/storage/index.ts
|
|
3451
3432
|
/**
|
|
3452
3433
|
* Type guard for pre-configured client config
|
|
3453
3434
|
*/
|
|
@@ -3592,7 +3573,6 @@ var DynamoDBStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
3592
3573
|
}
|
|
3593
3574
|
}
|
|
3594
3575
|
};
|
|
3595
|
-
//#endregion
|
|
3596
3576
|
exports.BackgroundTasksStorageDynamoDB = BackgroundTasksStorageDynamoDB;
|
|
3597
3577
|
exports.DynamoDBStore = DynamoDBStore;
|
|
3598
3578
|
exports.MemoryStorageDynamoDB = MemoryStorageDynamoDB;
|