@mastra/dynamodb 0.10.1 → 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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/storage/index.test.ts +55 -0
- package/src/storage/index.ts +4 -4
package/dist/index.cjs
CHANGED
|
@@ -904,7 +904,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
904
904
|
try {
|
|
905
905
|
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
906
906
|
if (selectBy?.last && typeof selectBy.last === "number") {
|
|
907
|
-
const results2 = await query.go({ limit: selectBy.last,
|
|
907
|
+
const results2 = await query.go({ limit: selectBy.last, order: "desc" });
|
|
908
908
|
const list2 = new agent.MessageList({ threadId, resourceId }).add(
|
|
909
909
|
results2.data.map((data) => this.parseMessageData(data)),
|
|
910
910
|
"memory"
|
package/dist/index.js
CHANGED
|
@@ -902,7 +902,7 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
902
902
|
try {
|
|
903
903
|
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
904
904
|
if (selectBy?.last && typeof selectBy.last === "number") {
|
|
905
|
-
const results2 = await query.go({ limit: selectBy.last,
|
|
905
|
+
const results2 = await query.go({ limit: selectBy.last, order: "desc" });
|
|
906
906
|
const list2 = new MessageList({ threadId, resourceId }).add(
|
|
907
907
|
results2.data.map((data) => this.parseMessageData(data)),
|
|
908
908
|
"memory"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/dynamodb",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "DynamoDB storage adapter for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"tsup": "^8.4.0",
|
|
41
41
|
"typescript": "^5.8.2",
|
|
42
42
|
"vitest": "^3.0.9",
|
|
43
|
-
"@internal/lint": "0.0.
|
|
43
|
+
"@internal/lint": "0.0.9",
|
|
44
44
|
"@mastra/core": "0.10.2"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
@@ -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', () => {
|
package/src/storage/index.ts
CHANGED
|
@@ -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
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
const results = await query.go({ limit: selectBy.last,
|
|
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)),
|