@mastra/dynamodb 1.0.0-beta.10 → 1.0.0-beta.11
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 +46 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +43 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -14
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +2 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# @mastra/dynamodb
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added new `listThreads` method for flexible thread filtering across all storage adapters. ([#11832](https://github.com/mastra-ai/mastra/pull/11832))
|
|
8
|
+
|
|
9
|
+
**New Features**
|
|
10
|
+
- Filter threads by `resourceId`, `metadata`, or both (with AND logic for metadata key-value pairs)
|
|
11
|
+
- All filter parameters are optional, allowing you to list all threads or filter as needed
|
|
12
|
+
- Full pagination and sorting support
|
|
13
|
+
|
|
14
|
+
**Example Usage**
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// List all threads
|
|
18
|
+
const allThreads = await memory.listThreads({});
|
|
19
|
+
|
|
20
|
+
// Filter by resourceId only
|
|
21
|
+
const userThreads = await memory.listThreads({
|
|
22
|
+
filter: { resourceId: 'user-123' },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Filter by metadata only
|
|
26
|
+
const supportThreads = await memory.listThreads({
|
|
27
|
+
filter: { metadata: { category: 'support' } },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Filter by both with pagination
|
|
31
|
+
const filteredThreads = await memory.listThreads({
|
|
32
|
+
filter: {
|
|
33
|
+
resourceId: 'user-123',
|
|
34
|
+
metadata: { priority: 'high', status: 'open' },
|
|
35
|
+
},
|
|
36
|
+
orderBy: { field: 'updatedAt', direction: 'DESC' },
|
|
37
|
+
page: 0,
|
|
38
|
+
perPage: 20,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Security Improvements**
|
|
43
|
+
- Added validation to prevent SQL injection via malicious metadata keys
|
|
44
|
+
- Added pagination parameter validation to prevent integer overflow attacks
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [[`ed3e3dd`](https://github.com/mastra-ai/mastra/commit/ed3e3ddec69d564fe2b125e083437f76331f1283), [`6833c69`](https://github.com/mastra-ai/mastra/commit/6833c69607418d257750bbcdd84638993d343539), [`47b1c16`](https://github.com/mastra-ai/mastra/commit/47b1c16a01c7ffb6765fe1e499b49092f8b7eba3), [`3a76a80`](https://github.com/mastra-ai/mastra/commit/3a76a80284cb71a0faa975abb3d4b2a9631e60cd), [`8538a0d`](https://github.com/mastra-ai/mastra/commit/8538a0d232619bf55dad7ddc2a8b0ca77c679a87), [`9312dcd`](https://github.com/mastra-ai/mastra/commit/9312dcd1c6f5b321929e7d382e763d95fdc030f5)]:
|
|
47
|
+
- @mastra/core@1.0.0-beta.25
|
|
48
|
+
|
|
3
49
|
## 1.0.0-beta.10
|
|
4
50
|
|
|
5
51
|
### Minor Changes
|
package/dist/docs/README.md
CHANGED
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1506,33 +1506,57 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1506
1506
|
);
|
|
1507
1507
|
}
|
|
1508
1508
|
}
|
|
1509
|
-
async
|
|
1510
|
-
const {
|
|
1511
|
-
|
|
1512
|
-
|
|
1509
|
+
async listThreads(args) {
|
|
1510
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
1511
|
+
try {
|
|
1512
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
1513
|
+
} catch (error$1) {
|
|
1513
1514
|
throw new error.MastraError(
|
|
1514
1515
|
{
|
|
1515
|
-
id: storage.createStorageErrorId("DYNAMODB", "
|
|
1516
|
+
id: storage.createStorageErrorId("DYNAMODB", "LIST_THREADS", "INVALID_PAGE"),
|
|
1516
1517
|
domain: error.ErrorDomain.STORAGE,
|
|
1517
1518
|
category: error.ErrorCategory.USER,
|
|
1518
|
-
details: {
|
|
1519
|
+
details: {
|
|
1520
|
+
page,
|
|
1521
|
+
...perPageInput !== void 0 && { perPage: perPageInput }
|
|
1522
|
+
}
|
|
1519
1523
|
},
|
|
1520
|
-
new Error("
|
|
1524
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
|
|
1521
1525
|
);
|
|
1522
1526
|
}
|
|
1527
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1523
1528
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1524
1529
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1525
|
-
this.logger.debug("
|
|
1526
|
-
resourceId,
|
|
1530
|
+
this.logger.debug("Listing threads with filters", {
|
|
1531
|
+
resourceId: filter?.resourceId,
|
|
1532
|
+
metadataKeys: filter?.metadata ? Object.keys(filter.metadata) : [],
|
|
1527
1533
|
page,
|
|
1528
1534
|
perPage,
|
|
1529
1535
|
field,
|
|
1530
1536
|
direction
|
|
1531
1537
|
});
|
|
1532
1538
|
try {
|
|
1533
|
-
const
|
|
1534
|
-
|
|
1535
|
-
|
|
1539
|
+
const rawThreads = filter?.resourceId ? (await this.service.entities.thread.query.byResource({
|
|
1540
|
+
entity: "thread",
|
|
1541
|
+
resourceId: filter.resourceId
|
|
1542
|
+
}).go({ pages: "all" })).data : (await this.service.entities.thread.scan.go({ pages: "all" })).data;
|
|
1543
|
+
let allThreads = this.transformAndSortThreads(rawThreads, field, direction);
|
|
1544
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
1545
|
+
allThreads = allThreads.filter((thread) => {
|
|
1546
|
+
let threadMeta = null;
|
|
1547
|
+
if (typeof thread.metadata === "string") {
|
|
1548
|
+
try {
|
|
1549
|
+
threadMeta = JSON.parse(thread.metadata);
|
|
1550
|
+
} catch {
|
|
1551
|
+
return false;
|
|
1552
|
+
}
|
|
1553
|
+
} else if (thread.metadata && typeof thread.metadata === "object") {
|
|
1554
|
+
threadMeta = thread.metadata;
|
|
1555
|
+
}
|
|
1556
|
+
if (!threadMeta) return false;
|
|
1557
|
+
return Object.entries(filter.metadata).every(([key, value]) => threadMeta[key] === value);
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1536
1560
|
const endIndex = offset + perPage;
|
|
1537
1561
|
const paginatedThreads = allThreads.slice(offset, endIndex);
|
|
1538
1562
|
const total = allThreads.length;
|
|
@@ -1547,10 +1571,15 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1547
1571
|
} catch (error$1) {
|
|
1548
1572
|
throw new error.MastraError(
|
|
1549
1573
|
{
|
|
1550
|
-
id: storage.createStorageErrorId("DYNAMODB", "
|
|
1574
|
+
id: storage.createStorageErrorId("DYNAMODB", "LIST_THREADS", "FAILED"),
|
|
1551
1575
|
domain: error.ErrorDomain.STORAGE,
|
|
1552
1576
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1553
|
-
details: {
|
|
1577
|
+
details: {
|
|
1578
|
+
...filter?.resourceId && { resourceId: filter.resourceId },
|
|
1579
|
+
hasMetadataFilter: !!(filter?.metadata && Object.keys(filter.metadata).length),
|
|
1580
|
+
page,
|
|
1581
|
+
perPage: perPageForResponse
|
|
1582
|
+
}
|
|
1554
1583
|
},
|
|
1555
1584
|
error$1
|
|
1556
1585
|
);
|