@mastra/dsql 1.1.2 → 1.2.0-alpha.0
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 +25 -0
- package/dist/index.cjs +27 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -9
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +14 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/dsql
|
|
2
2
|
|
|
3
|
+
## 1.2.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added exact metadata filtering to message history queries across Memory APIs and supported storage providers. ([#19991](https://github.com/mastra-ai/mastra/pull/19991))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const messages = await memory.recall({
|
|
11
|
+
threadId: 'thread-1',
|
|
12
|
+
filter: {
|
|
13
|
+
metadata: {
|
|
14
|
+
status: 'done',
|
|
15
|
+
priority: 'high',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Multiple fields use AND semantics. Supported values are strings, finite numbers, booleans, and `null`.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa)]:
|
|
26
|
+
- @mastra/core@1.54.0-alpha.0
|
|
27
|
+
|
|
3
28
|
## 1.1.2
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2481,6 +2481,7 @@ var MemoryDSQL = class _MemoryDSQL extends storage.MemoryStorage {
|
|
|
2481
2481
|
}
|
|
2482
2482
|
const perPage = storage.normalizePerPage(perPageInput, 40);
|
|
2483
2483
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2484
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
2484
2485
|
try {
|
|
2485
2486
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
2486
2487
|
const orderByStatement = `ORDER BY "${field}" ${direction}`;
|
|
@@ -2502,13 +2503,31 @@ var MemoryDSQL = class _MemoryDSQL extends storage.MemoryStorage {
|
|
|
2502
2503
|
queryParams.push(filter.dateRange.end);
|
|
2503
2504
|
}
|
|
2504
2505
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2506
|
+
let total;
|
|
2507
|
+
let messages;
|
|
2508
|
+
if (metadataFilter) {
|
|
2509
|
+
const rows = await this.#db.client.manyOrNone(
|
|
2510
|
+
`${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement}`,
|
|
2511
|
+
queryParams
|
|
2512
|
+
);
|
|
2513
|
+
const filteredRows = (rows || []).filter(
|
|
2514
|
+
(row) => storage.storageMessageMatchesMetadataFilter(row.content, metadataFilter)
|
|
2515
|
+
);
|
|
2516
|
+
total = filteredRows.length;
|
|
2517
|
+
messages = perPageInput === false ? filteredRows : filteredRows.slice(offset, offset + perPage);
|
|
2518
|
+
} else {
|
|
2519
|
+
const countResult = await this.#db.client.one(`SELECT COUNT(*) FROM ${tableName} ${whereClause}`, queryParams);
|
|
2520
|
+
total = parseInt(countResult.count, 10);
|
|
2521
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
2522
|
+
const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} LIMIT $${paramIndex++} OFFSET $${paramIndex++}`;
|
|
2523
|
+
const rows = await this.#db.client.manyOrNone(dataQuery, [
|
|
2524
|
+
...queryParams,
|
|
2525
|
+
limitValue,
|
|
2526
|
+
offset
|
|
2527
|
+
]);
|
|
2528
|
+
messages = [...rows || []];
|
|
2529
|
+
}
|
|
2530
|
+
const primaryPageCount = messages.length;
|
|
2512
2531
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
2513
2532
|
return {
|
|
2514
2533
|
messages: [],
|
|
@@ -2552,7 +2571,7 @@ var MemoryDSQL = class _MemoryDSQL extends storage.MemoryStorage {
|
|
|
2552
2571
|
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
2553
2572
|
);
|
|
2554
2573
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
2555
|
-
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
2574
|
+
const hasMore = metadataFilter ? perPageInput !== false && offset + primaryPageCount < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
2556
2575
|
return {
|
|
2557
2576
|
messages: finalMessages,
|
|
2558
2577
|
total,
|