@mastra/dynamodb 0.10.1-alpha.2 → 0.10.2

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/index.cjs CHANGED
@@ -560,9 +560,12 @@ function getElectroDbService(client, tableName) {
560
560
 
561
561
  // src/storage/index.ts
562
562
  var DynamoDBStore = class extends storage.MastraStorage {
563
+ tableName;
564
+ client;
565
+ service;
566
+ hasInitialized = null;
563
567
  constructor({ name, config }) {
564
568
  super({ name });
565
- this.hasInitialized = null;
566
569
  if (!config.tableName || typeof config.tableName !== "string" || config.tableName.trim() === "") {
567
570
  throw new Error("DynamoDBStore: config.tableName must be provided and cannot be empty.");
568
571
  }
@@ -901,7 +904,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
901
904
  try {
902
905
  const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
903
906
  if (selectBy?.last && typeof selectBy.last === "number") {
904
- const results2 = await query.go({ limit: selectBy.last, reverse: true });
907
+ const results2 = await query.go({ limit: selectBy.last, order: "desc" });
905
908
  const list2 = new agent.MessageList({ threadId, resourceId }).add(
906
909
  results2.data.map((data) => this.parseMessageData(data)),
907
910
  "memory"
@@ -0,0 +1,2 @@
1
+ export { DynamoDBStoreConfig } from './_tsup-dts-rollup.cjs';
2
+ export { DynamoDBStore } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { DynamoDBStoreConfig } from './_tsup-dts-rollup.js';
2
+ export { DynamoDBStore } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -558,9 +558,12 @@ function getElectroDbService(client, tableName) {
558
558
 
559
559
  // src/storage/index.ts
560
560
  var DynamoDBStore = class extends MastraStorage {
561
+ tableName;
562
+ client;
563
+ service;
564
+ hasInitialized = null;
561
565
  constructor({ name, config }) {
562
566
  super({ name });
563
- this.hasInitialized = null;
564
567
  if (!config.tableName || typeof config.tableName !== "string" || config.tableName.trim() === "") {
565
568
  throw new Error("DynamoDBStore: config.tableName must be provided and cannot be empty.");
566
569
  }
@@ -899,7 +902,7 @@ var DynamoDBStore = class extends MastraStorage {
899
902
  try {
900
903
  const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
901
904
  if (selectBy?.last && typeof selectBy.last === "number") {
902
- const results2 = await query.go({ limit: selectBy.last, reverse: true });
905
+ const results2 = await query.go({ limit: selectBy.last, order: "desc" });
903
906
  const list2 = new MessageList({ threadId, resourceId }).add(
904
907
  results2.data.map((data) => this.parseMessageData(data)),
905
908
  "memory"
package/package.json CHANGED
@@ -1,10 +1,23 @@
1
1
  {
2
2
  "name": "@mastra/dynamodb",
3
- "version": "0.10.1-alpha.2",
3
+ "version": "0.10.2",
4
4
  "description": "DynamoDB storage adapter for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
8
21
  "files": [
9
22
  "dist",
10
23
  "src"
@@ -15,7 +28,7 @@
15
28
  "electrodb": "^3.4.1"
16
29
  },
17
30
  "peerDependencies": {
18
- "@mastra/core": "^0.10.0-alpha.0"
31
+ "@mastra/core": "^0.10.2-alpha.0"
19
32
  },
20
33
  "devDependencies": {
21
34
  "@microsoft/api-extractor": "^7.52.1",
@@ -27,11 +40,11 @@
27
40
  "tsup": "^8.4.0",
28
41
  "typescript": "^5.8.2",
29
42
  "vitest": "^3.0.9",
30
- "@internal/lint": "0.0.7",
31
- "@mastra/core": "0.10.2-alpha.4"
43
+ "@internal/lint": "0.0.9",
44
+ "@mastra/core": "0.10.2"
32
45
  },
33
46
  "scripts": {
34
- "build": "tsup src/index.ts --format esm,cjs --clean --treeshake=smallest --splitting",
47
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
35
48
  "dev": "tsup --watch",
36
49
  "clean": "rm -rf dist",
37
50
  "lint": "eslint .",
@@ -387,6 +387,61 @@ describe('DynamoDBStore Integration Tests', () => {
387
387
  expect(retrieved?.title).toBe('Updated Thread 2');
388
388
  expect(retrieved?.metadata?.update).toBe(2);
389
389
  });
390
+
391
+ test('getMessages should return the N most recent messages [v2 storage]', async () => {
392
+ const threadId = 'last-selector-thread';
393
+ const start = Date.now();
394
+
395
+ // Insert 10 messages with increasing timestamps
396
+ const messages: MastraMessageV2[] = Array.from({ length: 10 }, (_, i) => ({
397
+ id: `m-${i}`,
398
+ threadId,
399
+ resourceId: 'r',
400
+ content: { format: 2, parts: [{ type: 'text', text: `msg-${i}` }] },
401
+ createdAt: new Date(start + i), // 0..9 ms apart
402
+ role: 'user',
403
+ type: 'text',
404
+ }));
405
+ await store.saveMessages({ messages, format: 'v2' });
406
+
407
+ const last3 = await store.getMessages({
408
+ format: 'v2',
409
+ threadId,
410
+ selectBy: { last: 3 },
411
+ });
412
+
413
+ expect(last3).toHaveLength(3);
414
+ expect(last3.map(m => (m.content.parts[0] as { type: string; text: string }).text)).toEqual([
415
+ 'msg-7',
416
+ 'msg-8',
417
+ 'msg-9',
418
+ ]);
419
+ });
420
+
421
+ test('getMessages should return the N most recent messages [v1 storage]', async () => {
422
+ const threadId = 'last-selector-thread';
423
+ const start = Date.now();
424
+
425
+ // Insert 10 messages with increasing timestamps
426
+ const messages: MastraMessageV1[] = Array.from({ length: 10 }, (_, i) => ({
427
+ id: `m-${i}`,
428
+ threadId,
429
+ resourceId: 'r',
430
+ content: `msg-${i}`,
431
+ createdAt: new Date(start + i), // 0..9 ms apart
432
+ role: 'user',
433
+ type: 'text',
434
+ }));
435
+ await store.saveMessages({ messages });
436
+
437
+ const last3 = await store.getMessages({
438
+ threadId,
439
+ selectBy: { last: 3 },
440
+ });
441
+
442
+ expect(last3).toHaveLength(3);
443
+ expect(last3.map(m => m.content)).toEqual(['msg-7', 'msg-8', 'msg-9']);
444
+ });
390
445
  });
391
446
 
392
447
  describe('Batch Operations', () => {
@@ -532,10 +532,10 @@ export class DynamoDBStore extends MastraStorage {
532
532
 
533
533
  // Apply the 'last' limit if provided
534
534
  if (selectBy?.last && typeof selectBy.last === 'number') {
535
- // Use ElectroDB's limit parameter (descending sort assumed on GSI SK)
536
- // Ensure GSI sk (createdAt) is sorted descending for 'last' to work correctly
537
- // Assuming default sort is ascending on SK, use reverse: true for descending
538
- const results = await query.go({ limit: selectBy.last, reverse: true });
535
+ // Use ElectroDB's limit parameter
536
+ // DDB GSIs are sorted in ascending order
537
+ // Use ElectroDB's order parameter to sort in descending order to retrieve 'latest' messages
538
+ const results = await query.go({ limit: selectBy.last, order: 'desc' });
539
539
  // Use arrow function in map to preserve 'this' context for parseMessageData
540
540
  const list = new MessageList({ threadId, resourceId }).add(
541
541
  results.data.map((data: any) => this.parseMessageData(data)),