@mastra/clickhouse 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 +58 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -13
- 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 +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
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
|
### Patch Changes
|
package/dist/docs/README.md
CHANGED
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1068,26 +1068,68 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1068
1068
|
);
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
|
-
async
|
|
1072
|
-
const {
|
|
1071
|
+
async listThreads(args) {
|
|
1072
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
1073
|
+
try {
|
|
1074
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
1075
|
+
} catch (error$1) {
|
|
1076
|
+
throw new error.MastraError(
|
|
1077
|
+
{
|
|
1078
|
+
id: storage.createStorageErrorId("CLICKHOUSE", "LIST_THREADS", "INVALID_PAGE"),
|
|
1079
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1080
|
+
category: error.ErrorCategory.USER,
|
|
1081
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
1082
|
+
},
|
|
1083
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1073
1086
|
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1074
|
-
|
|
1087
|
+
try {
|
|
1088
|
+
this.validateMetadataKeys(filter?.metadata);
|
|
1089
|
+
} catch (error$1) {
|
|
1075
1090
|
throw new error.MastraError(
|
|
1076
1091
|
{
|
|
1077
|
-
id: storage.createStorageErrorId("CLICKHOUSE", "
|
|
1092
|
+
id: storage.createStorageErrorId("CLICKHOUSE", "LIST_THREADS", "INVALID_METADATA_KEY"),
|
|
1078
1093
|
domain: error.ErrorDomain.STORAGE,
|
|
1079
1094
|
category: error.ErrorCategory.USER,
|
|
1080
|
-
details: {
|
|
1095
|
+
details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
|
|
1081
1096
|
},
|
|
1082
|
-
new Error("
|
|
1097
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid metadata key")
|
|
1083
1098
|
);
|
|
1084
1099
|
}
|
|
1085
1100
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1086
1101
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1087
1102
|
try {
|
|
1103
|
+
const whereClauses = [];
|
|
1104
|
+
const queryParams = {};
|
|
1105
|
+
if (filter?.resourceId) {
|
|
1106
|
+
whereClauses.push("resourceId = {resourceId:String}");
|
|
1107
|
+
queryParams.resourceId = filter.resourceId;
|
|
1108
|
+
}
|
|
1109
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
1110
|
+
let metadataIndex = 0;
|
|
1111
|
+
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
1112
|
+
const paramName = `metadata${metadataIndex}`;
|
|
1113
|
+
whereClauses.push(`JSONExtractRaw(metadata, '${key}') = {${paramName}:String}`);
|
|
1114
|
+
queryParams[paramName] = JSON.stringify(value);
|
|
1115
|
+
metadataIndex++;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1088
1118
|
const countResult = await this.client.query({
|
|
1089
|
-
query: `
|
|
1090
|
-
|
|
1119
|
+
query: `
|
|
1120
|
+
WITH ranked_threads AS (
|
|
1121
|
+
SELECT
|
|
1122
|
+
id,
|
|
1123
|
+
resourceId,
|
|
1124
|
+
metadata,
|
|
1125
|
+
ROW_NUMBER() OVER (PARTITION BY id ORDER BY updatedAt DESC) as row_num
|
|
1126
|
+
FROM ${storage.TABLE_THREADS}
|
|
1127
|
+
)
|
|
1128
|
+
SELECT count(*) as total
|
|
1129
|
+
FROM ranked_threads
|
|
1130
|
+
WHERE row_num = 1 ${whereClauses.length > 0 ? `AND ${whereClauses.join(" AND ")}` : ""}
|
|
1131
|
+
`,
|
|
1132
|
+
query_params: queryParams,
|
|
1091
1133
|
clickhouse_settings: {
|
|
1092
1134
|
date_time_input_format: "best_effort",
|
|
1093
1135
|
date_time_output_format: "iso",
|
|
@@ -1118,7 +1160,6 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1118
1160
|
toDateTime64(updatedAt, 3) as updatedAt,
|
|
1119
1161
|
ROW_NUMBER() OVER (PARTITION BY id ORDER BY updatedAt DESC) as row_num
|
|
1120
1162
|
FROM ${storage.TABLE_THREADS}
|
|
1121
|
-
WHERE resourceId = {resourceId:String}
|
|
1122
1163
|
)
|
|
1123
1164
|
SELECT
|
|
1124
1165
|
id,
|
|
@@ -1128,12 +1169,12 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1128
1169
|
createdAt,
|
|
1129
1170
|
updatedAt
|
|
1130
1171
|
FROM ranked_threads
|
|
1131
|
-
WHERE row_num = 1
|
|
1172
|
+
WHERE row_num = 1 ${whereClauses.length > 0 ? `AND ${whereClauses.join(" AND ")}` : ""}
|
|
1132
1173
|
ORDER BY "${field}" ${direction === "DESC" ? "DESC" : "ASC"}
|
|
1133
1174
|
LIMIT {perPage:Int64} OFFSET {offset:Int64}
|
|
1134
1175
|
`,
|
|
1135
1176
|
query_params: {
|
|
1136
|
-
|
|
1177
|
+
...queryParams,
|
|
1137
1178
|
perPage,
|
|
1138
1179
|
offset
|
|
1139
1180
|
},
|
|
@@ -1159,10 +1200,14 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1159
1200
|
} catch (error$1) {
|
|
1160
1201
|
throw new error.MastraError(
|
|
1161
1202
|
{
|
|
1162
|
-
id: storage.createStorageErrorId("CLICKHOUSE", "
|
|
1203
|
+
id: storage.createStorageErrorId("CLICKHOUSE", "LIST_THREADS", "FAILED"),
|
|
1163
1204
|
domain: error.ErrorDomain.STORAGE,
|
|
1164
1205
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1165
|
-
details: {
|
|
1206
|
+
details: {
|
|
1207
|
+
...filter?.resourceId && { resourceId: filter.resourceId },
|
|
1208
|
+
hasMetadataFilter: !!filter?.metadata,
|
|
1209
|
+
page
|
|
1210
|
+
}
|
|
1166
1211
|
},
|
|
1167
1212
|
error$1
|
|
1168
1213
|
);
|