@mastra/dynamodb 1.0.0-beta.7 → 1.0.0-beta.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,94 @@
1
1
  # @mastra/dynamodb
2
2
 
3
+ ## 1.0.0-beta.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
8
+
9
+ Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
10
+
11
+ Each package includes:
12
+ - **SKILL.md** - Entry point explaining the package's purpose and capabilities
13
+ - **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
14
+ - **Topic folders** - Conceptual documentation organized by feature area
15
+
16
+ Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
17
+
18
+ - Added `startExclusive` and `endExclusive` options to `dateRange` filter for message queries. ([#11479](https://github.com/mastra-ai/mastra/pull/11479))
19
+
20
+ **What changed:** The `filter.dateRange` parameter in `listMessages()` and `Memory.recall()` now supports `startExclusive` and `endExclusive` boolean options. When set to `true`, messages with timestamps exactly matching the boundary are excluded from results.
21
+
22
+ **Why this matters:** Enables cursor-based pagination for chat applications. When new messages arrive during a session, offset-based pagination can skip or duplicate messages. Using `endExclusive: true` with the oldest message's timestamp as a cursor ensures consistent pagination without gaps or duplicates.
23
+
24
+ **Example:**
25
+
26
+ ```typescript
27
+ // Get first page
28
+ const page1 = await memory.recall({
29
+ threadId: 'thread-123',
30
+ perPage: 10,
31
+ orderBy: { field: 'createdAt', direction: 'DESC' },
32
+ });
33
+
34
+ // Get next page using cursor-based pagination
35
+ const oldestMessage = page1.messages[page1.messages.length - 1];
36
+ const page2 = await memory.recall({
37
+ threadId: 'thread-123',
38
+ perPage: 10,
39
+ orderBy: { field: 'createdAt', direction: 'DESC' },
40
+ filter: {
41
+ dateRange: {
42
+ end: oldestMessage.createdAt,
43
+ endExclusive: true, // Excludes the cursor message
44
+ },
45
+ },
46
+ });
47
+ ```
48
+
49
+ - Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
50
+ - @mastra/core@1.0.0-beta.20
51
+
52
+ ## 1.0.0-beta.8
53
+
54
+ ### Patch Changes
55
+
56
+ - Add storage composition to MastraStorage ([#11401](https://github.com/mastra-ai/mastra/pull/11401))
57
+
58
+ `MastraStorage` can now compose storage domains from different adapters. Use it when you need different databases for different purposes - for example, PostgreSQL for memory and workflows, but a different database for observability.
59
+
60
+ ```typescript
61
+ import { MastraStorage } from '@mastra/core/storage';
62
+ import { MemoryPG, WorkflowsPG, ScoresPG } from '@mastra/pg';
63
+ import { MemoryLibSQL } from '@mastra/libsql';
64
+
65
+ // Compose domains from different stores
66
+ const storage = new MastraStorage({
67
+ id: 'composite',
68
+ domains: {
69
+ memory: new MemoryLibSQL({ url: 'file:./local.db' }),
70
+ workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
71
+ scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
72
+ },
73
+ });
74
+ ```
75
+
76
+ **Breaking changes:**
77
+ - `storage.supports` property no longer exists
78
+ - `StorageSupports` type is no longer exported from `@mastra/core/storage`
79
+
80
+ All stores now support the same features. For domain availability, use `getStore()`:
81
+
82
+ ```typescript
83
+ const store = await storage.getStore('memory');
84
+ if (store) {
85
+ // domain is available
86
+ }
87
+ ```
88
+
89
+ - Updated dependencies [[`3d93a15`](https://github.com/mastra-ai/mastra/commit/3d93a15796b158c617461c8b98bede476ebb43e2), [`efe406a`](https://github.com/mastra-ai/mastra/commit/efe406a1353c24993280ebc2ed61dd9f65b84b26), [`119e5c6`](https://github.com/mastra-ai/mastra/commit/119e5c65008f3e5cfca954eefc2eb85e3bf40da4), [`74e504a`](https://github.com/mastra-ai/mastra/commit/74e504a3b584eafd2f198001c6a113bbec589fd3), [`e33fdbd`](https://github.com/mastra-ai/mastra/commit/e33fdbd07b33920d81e823122331b0c0bee0bb59), [`929f69c`](https://github.com/mastra-ai/mastra/commit/929f69c3436fa20dd0f0e2f7ebe8270bd82a1529), [`8a73529`](https://github.com/mastra-ai/mastra/commit/8a73529ca01187f604b1f3019d0a725ac63ae55f)]:
90
+ - @mastra/core@1.0.0-beta.16
91
+
3
92
  ## 1.0.0-beta.7
4
93
 
5
94
  ### Minor Changes
@@ -0,0 +1,31 @@
1
+ # @mastra/dynamodb Documentation
2
+
3
+ > Embedded documentation for coding agents
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Read the skill overview
9
+ cat docs/SKILL.md
10
+
11
+ # Get the source map
12
+ cat docs/SOURCE_MAP.json
13
+
14
+ # Read topic documentation
15
+ cat docs/<topic>/01-overview.md
16
+ ```
17
+
18
+ ## Structure
19
+
20
+ ```
21
+ docs/
22
+ ├── SKILL.md # Entry point
23
+ ├── README.md # This file
24
+ ├── SOURCE_MAP.json # Export index
25
+ ├── storage/ (1 files)
26
+ ```
27
+
28
+ ## Version
29
+
30
+ Package: @mastra/dynamodb
31
+ Version: 1.0.0-beta.9
@@ -0,0 +1,32 @@
1
+ ---
2
+ name: mastra-dynamodb-docs
3
+ description: Documentation for @mastra/dynamodb. Includes links to type definitions and readable implementation code in dist/.
4
+ ---
5
+
6
+ # @mastra/dynamodb Documentation
7
+
8
+ > **Version**: 1.0.0-beta.9
9
+ > **Package**: @mastra/dynamodb
10
+
11
+ ## Quick Navigation
12
+
13
+ Use SOURCE_MAP.json to find any export:
14
+
15
+ ```bash
16
+ cat docs/SOURCE_MAP.json
17
+ ```
18
+
19
+ Each export maps to:
20
+ - **types**: `.d.ts` file with JSDoc and API signatures
21
+ - **implementation**: `.js` chunk file with readable source
22
+ - **docs**: Conceptual documentation in `docs/`
23
+
24
+ ## Top Exports
25
+
26
+
27
+
28
+ See SOURCE_MAP.json for the complete list.
29
+
30
+ ## Available Topics
31
+
32
+ - [Storage](storage/) - 1 file(s)
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "1.0.0-beta.9",
3
+ "package": "@mastra/dynamodb",
4
+ "exports": {},
5
+ "modules": {}
6
+ }
@@ -0,0 +1,162 @@
1
+ # Storage API Reference
2
+
3
+ > API reference for storage - 1 entries
4
+
5
+
6
+ ---
7
+
8
+ ## Reference: DynamoDB Storage
9
+
10
+ > Documentation for the DynamoDB storage implementation in Mastra, using a single-table design with ElectroDB.
11
+
12
+ The DynamoDB storage implementation provides a scalable and performant NoSQL database solution for Mastra, leveraging a single-table design pattern with [ElectroDB](https://electrodb.dev/).
13
+
14
+ ## Features
15
+
16
+ - Efficient single-table design for all Mastra storage needs
17
+ - Based on ElectroDB for type-safe DynamoDB access
18
+ - Support for AWS credentials, regions, and endpoints
19
+ - Compatible with AWS DynamoDB Local for development
20
+ - Stores Thread, Message, Trace, Eval, and Workflow data
21
+ - Optimized for serverless environments
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @mastra/dynamodb@beta
27
+ # or
28
+ pnpm add @mastra/dynamodb@beta
29
+ # or
30
+ yarn add @mastra/dynamodb@beta
31
+ ```
32
+
33
+ ## Prerequisites
34
+
35
+ 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.
36
+
37
+ 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.
38
+
39
+ ## Usage
40
+
41
+ ### Basic Usage
42
+
43
+ ```typescript
44
+ import { Memory } from "@mastra/memory";
45
+ import { DynamoDBStore } from "@mastra/dynamodb";
46
+
47
+ // Initialize the DynamoDB storage
48
+ const storage = new DynamoDBStore({
49
+ name: "dynamodb", // A name for this storage instance
50
+ config: {
51
+ tableName: "mastra-single-table", // Name of your DynamoDB table
52
+ region: "us-east-1", // Optional: AWS region, defaults to 'us-east-1'
53
+ // endpoint: "http://localhost:8000", // Optional: For local DynamoDB
54
+ // credentials: { accessKeyId: "YOUR_ACCESS_KEY", secretAccessKey: "YOUR_SECRET_KEY" } // Optional
55
+ },
56
+ });
57
+
58
+ // Example: Initialize Memory with DynamoDB storage
59
+ const memory = new Memory({
60
+ storage,
61
+ options: {
62
+ lastMessages: 10,
63
+ },
64
+ });
65
+ ```
66
+
67
+ ### Local Development with DynamoDB Local
68
+
69
+ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html).
70
+
71
+ 1. **Run DynamoDB Local (e.g., using Docker):**
72
+
73
+ ```bash
74
+ docker run -p 8000:8000 amazon/dynamodb-local
75
+ ```
76
+
77
+ 2. **Configure `DynamoDBStore` to use the local endpoint:**
78
+
79
+ ```typescript
80
+ import { DynamoDBStore } from "@mastra/dynamodb";
81
+
82
+ const storage = new DynamoDBStore({
83
+ name: "dynamodb-local",
84
+ config: {
85
+ tableName: "mastra-single-table", // Ensure this table is created in your local DynamoDB
86
+ region: "localhost", // Can be any string for local, 'localhost' is common
87
+ endpoint: "http://localhost:8000",
88
+ // For DynamoDB Local, credentials are not typically required unless configured.
89
+ // If you've configured local credentials:
90
+ // credentials: { accessKeyId: "fakeMyKeyId", secretAccessKey: "fakeSecretAccessKey" }
91
+ },
92
+ });
93
+ ```
94
+
95
+ You will still need to create the table and GSIs in your local DynamoDB instance, for example, using the AWS CLI pointed to your local endpoint.
96
+
97
+ ## Parameters
98
+
99
+ ## AWS IAM Permissions
100
+
101
+ The IAM role or user executing the code needs appropriate permissions to interact with the specified DynamoDB table and its indexes. Below is a sample policy. Replace `${YOUR_TABLE_NAME}` with your actual table name and `${YOUR_AWS_REGION}` and `${YOUR_AWS_ACCOUNT_ID}` with appropriate values.
102
+
103
+ ```json
104
+ {
105
+ "Version": "2012-10-17",
106
+ "Statement": [
107
+ {
108
+ "Effect": "Allow",
109
+ "Action": [
110
+ "dynamodb:DescribeTable",
111
+ "dynamodb:GetItem",
112
+ "dynamodb:PutItem",
113
+ "dynamodb:UpdateItem",
114
+ "dynamodb:DeleteItem",
115
+ "dynamodb:Query",
116
+ "dynamodb:Scan",
117
+ "dynamodb:BatchGetItem",
118
+ "dynamodb:BatchWriteItem"
119
+ ],
120
+ "Resource": [
121
+ "arn:aws:dynamodb:${YOUR_AWS_REGION}:${YOUR_AWS_ACCOUNT_ID}:table/${YOUR_TABLE_NAME}",
122
+ "arn:aws:dynamodb:${YOUR_AWS_REGION}:${YOUR_AWS_ACCOUNT_ID}:table/${YOUR_TABLE_NAME}/index/*"
123
+ ]
124
+ }
125
+ ]
126
+ }
127
+ ```
128
+
129
+ ## Key Considerations
130
+
131
+ Before diving into the architectural details, keep these key points in mind when working with the DynamoDB storage adapter:
132
+
133
+ - **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).
134
+ - **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.
135
+ - **Understanding GSIs:** Familiarity with how the GSIs are structured (as per `TABLE_SETUP.md`) is important for understanding data retrieval and potential query patterns.
136
+ - **ElectroDB:** The adapter uses ElectroDB to manage interactions with DynamoDB, providing a layer of abstraction and type safety over raw DynamoDB operations.
137
+
138
+ ## Architectural Approach
139
+
140
+ This storage adapter utilizes a **single-table design pattern** leveraging [ElectroDB](https://electrodb.dev/), a common and recommended approach for DynamoDB. This differs architecturally from relational database adapters (like `@mastra/pg` or `@mastra/libsql`) that typically use multiple tables, each dedicated to a specific entity (threads, messages, etc.).
141
+
142
+ Key aspects of this approach:
143
+
144
+ - **DynamoDB Native:** The single-table design is optimized for DynamoDB's key-value and query capabilities, often leading to better performance and scalability compared to mimicking relational models.
145
+ - **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.
146
+ - **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.
147
+
148
+ ### Mastra Data in the Single Table
149
+
150
+ Within the single DynamoDB table, different Mastra data entities (such as Threads, Messages, Traces, Evals, and Workflows) are managed and distinguished using ElectroDB. ElectroDB defines specific models for each entity type, which include unique key structures and attributes. This allows the adapter to store and retrieve diverse data types efficiently within the same table.
151
+
152
+ For example, a `Thread` item might have a primary key like `THREAD#<threadId>`, while a `Message` item belonging to that thread might use `THREAD#<threadId>` as a partition key and `MESSAGE#<messageId>` as a sort key. The Global Secondary Indexes (GSIs), detailed in `TABLE_SETUP.md`, are strategically designed to support common access patterns across these different entities, such as fetching all messages for a thread or querying traces associated with a particular workflow.
153
+
154
+ ### Advantages of Single-Table Design
155
+
156
+ This implementation uses a single-table design pattern with ElectroDB, which offers several advantages within the context of DynamoDB:
157
+
158
+ 1. **Lower cost (potentially):** Fewer tables can simplify Read/Write Capacity Unit (RCU/WCU) provisioning and management, especially with on-demand capacity.
159
+ 2. **Better performance:** Related data can be co-located or accessed efficiently through GSIs, enabling fast lookups for common access patterns.
160
+ 3. **Simplified administration:** Fewer distinct tables to monitor, back up, and manage.
161
+ 4. **Reduced complexity in access patterns:** ElectroDB helps manage the complexity of item types and access patterns on a single table.
162
+ 5. **Transaction support:** DynamoDB transactions can be used across different "entity" types stored within the same table if needed.
package/dist/index.cjs CHANGED
@@ -1279,21 +1279,11 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1279
1279
  if (resourceId) {
1280
1280
  allThreadMessages = allThreadMessages.filter((msg) => msg.resourceId === resourceId);
1281
1281
  }
1282
- if (filter?.dateRange) {
1283
- const dateRange = filter.dateRange;
1284
- allThreadMessages = allThreadMessages.filter((msg) => {
1285
- const createdAt = new Date(msg.createdAt).getTime();
1286
- if (dateRange.start) {
1287
- const startTime = dateRange.start instanceof Date ? dateRange.start.getTime() : new Date(dateRange.start).getTime();
1288
- if (createdAt < startTime) return false;
1289
- }
1290
- if (dateRange.end) {
1291
- const endTime = dateRange.end instanceof Date ? dateRange.end.getTime() : new Date(dateRange.end).getTime();
1292
- if (createdAt > endTime) return false;
1293
- }
1294
- return true;
1295
- });
1296
- }
1282
+ allThreadMessages = storage.filterByDateRange(
1283
+ allThreadMessages,
1284
+ (msg) => new Date(msg.createdAt),
1285
+ filter?.dateRange
1286
+ );
1297
1287
  allThreadMessages.sort((a, b) => {
1298
1288
  const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
1299
1289
  const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
@@ -2403,19 +2393,6 @@ var DynamoDBStore = class extends storage.MastraStorage {
2403
2393
  );
2404
2394
  }
2405
2395
  }
2406
- get supports() {
2407
- return {
2408
- selectByIncludeResourceScope: true,
2409
- resourceWorkingMemory: true,
2410
- hasColumn: false,
2411
- createTable: false,
2412
- deleteMessages: true,
2413
- observability: false,
2414
- indexManagement: false,
2415
- listScoresBySpan: true,
2416
- agents: false
2417
- };
2418
- }
2419
2396
  /**
2420
2397
  * Validates that the required DynamoDB table exists and is accessible.
2421
2398
  * This does not check the table structure - it assumes the table
@@ -2507,5 +2484,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2507
2484
  };
2508
2485
 
2509
2486
  exports.DynamoDBStore = DynamoDBStore;
2487
+ exports.MemoryStorageDynamoDB = MemoryStorageDynamoDB;
2488
+ exports.ScoresStorageDynamoDB = ScoresStorageDynamoDB;
2489
+ exports.WorkflowStorageDynamoDB = WorkflowStorageDynamoDB;
2510
2490
  //# sourceMappingURL=index.cjs.map
2511
2491
  //# sourceMappingURL=index.cjs.map