@mastra/upstash 1.0.0-beta.11 → 1.0.0-beta.12

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 CHANGED
@@ -1,5 +1,51 @@
1
1
  # @mastra/upstash
2
2
 
3
+ ## 1.0.0-beta.12
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.11
4
50
 
5
51
  ### Patch Changes
@@ -31,4 +31,4 @@ docs/
31
31
  ## Version
32
32
 
33
33
  Package: @mastra/upstash
34
- Version: 1.0.0-beta.11
34
+ Version: 1.0.0-beta.12
@@ -5,7 +5,7 @@ description: Documentation for @mastra/upstash. Includes links to type definitio
5
5
 
6
6
  # @mastra/upstash Documentation
7
7
 
8
- > **Version**: 1.0.0-beta.11
8
+ > **Version**: 1.0.0-beta.12
9
9
  > **Package**: @mastra/upstash
10
10
 
11
11
  ## Quick Navigation
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.11",
2
+ "version": "1.0.0-beta.12",
3
3
  "package": "@mastra/upstash",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -27,7 +27,7 @@ await store.upsert({
27
27
  });
28
28
  ```
29
29
 
30
- ### Using MongoDB Atlas Vector search
30
+ <h3>Using MongoDB Atlas Vector search</h3>
31
31
 
32
32
  For detailed setup instructions and best practices, see the [official MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel&utm_source=third-party-content&utm_medium=cta&utm_content=mastra-docs).
33
33
 
@@ -55,7 +55,7 @@ await store.upsert({
55
55
  });
56
56
  ```
57
57
 
58
- ### Using PostgreSQL with pgvector
58
+ <h3>Using PostgreSQL with pgvector</h3>
59
59
 
60
60
  PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity.
61
61
  For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
@@ -323,7 +323,7 @@ await store.upsert({
323
323
  });
324
324
  ```
325
325
 
326
- ### Using LanceDB
326
+ <h3>Using LanceDB</h3>
327
327
 
328
328
  LanceDB is an embedded vector database built on the Lance columnar format, suitable for local development or cloud deployment.
329
329
  For detailed setup instructions and best practices, see the [official LanceDB documentation](https://lancedb.github.io/lancedb/).
package/dist/index.cjs CHANGED
@@ -192,19 +192,34 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
192
192
  );
193
193
  }
194
194
  }
195
- async listThreadsByResourceId(args) {
196
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
195
+ async listThreads(args) {
196
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
197
197
  const { field, direction } = this.parseOrderBy(orderBy);
198
+ try {
199
+ this.validatePaginationInput(page, perPageInput ?? 100);
200
+ } catch (error$1) {
201
+ throw new error.MastraError(
202
+ {
203
+ id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS", "INVALID_PAGE"),
204
+ domain: error.ErrorDomain.STORAGE,
205
+ category: error.ErrorCategory.USER,
206
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
207
+ },
208
+ error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
209
+ );
210
+ }
198
211
  const perPage = storage.normalizePerPage(perPageInput, 100);
199
- if (page < 0) {
212
+ try {
213
+ this.validateMetadataKeys(filter?.metadata);
214
+ } catch (error$1) {
200
215
  throw new error.MastraError(
201
216
  {
202
- id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
217
+ id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS", "INVALID_METADATA_KEY"),
203
218
  domain: error.ErrorDomain.STORAGE,
204
219
  category: error.ErrorCategory.USER,
205
- details: { page }
220
+ details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
206
221
  },
207
- new Error("page must be >= 0")
222
+ error$1 instanceof Error ? error$1 : new Error("Invalid metadata key")
208
223
  );
209
224
  }
210
225
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
@@ -212,19 +227,35 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
212
227
  let allThreads = [];
213
228
  const pattern = `${storage.TABLE_THREADS}:*`;
214
229
  const keys = await this.#db.scanKeys(pattern);
230
+ if (keys.length === 0) {
231
+ return {
232
+ threads: [],
233
+ total: 0,
234
+ page,
235
+ perPage: perPageForResponse,
236
+ hasMore: false
237
+ };
238
+ }
215
239
  const pipeline = this.client.pipeline();
216
240
  keys.forEach((key) => pipeline.get(key));
217
241
  const results = await pipeline.exec();
218
242
  for (let i = 0; i < results.length; i++) {
219
243
  const thread = results[i];
220
- if (thread && thread.resourceId === resourceId) {
221
- allThreads.push({
222
- ...thread,
223
- createdAt: storage.ensureDate(thread.createdAt),
224
- updatedAt: storage.ensureDate(thread.updatedAt),
225
- metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata
226
- });
244
+ if (!thread) continue;
245
+ if (filter?.resourceId && thread.resourceId !== filter.resourceId) {
246
+ continue;
227
247
  }
248
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
249
+ const threadMetadata = typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata;
250
+ const matches = Object.entries(filter.metadata).every(([key, value]) => threadMetadata?.[key] === value);
251
+ if (!matches) continue;
252
+ }
253
+ allThreads.push({
254
+ ...thread,
255
+ createdAt: storage.ensureDate(thread.createdAt),
256
+ updatedAt: storage.ensureDate(thread.updatedAt),
257
+ metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata
258
+ });
228
259
  }
229
260
  const sortedThreads = this.sortThreads(allThreads, field, direction);
230
261
  const total = sortedThreads.length;
@@ -241,11 +272,12 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
241
272
  } catch (error$1) {
242
273
  const mastraError = new error.MastraError(
243
274
  {
244
- id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
275
+ id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS", "FAILED"),
245
276
  domain: error.ErrorDomain.STORAGE,
246
277
  category: error.ErrorCategory.THIRD_PARTY,
247
278
  details: {
248
- resourceId,
279
+ ...filter?.resourceId && { resourceId: filter.resourceId },
280
+ hasMetadataFilter: !!filter?.metadata,
249
281
  page,
250
282
  perPage
251
283
  }