@mastra/mssql 1.0.0-beta.10 → 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,60 @@
1
1
  # @mastra/mssql
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
+
49
+ ## 1.0.0-beta.11
50
+
51
+ ### Patch Changes
52
+
53
+ - dependencies updates: ([#10197](https://github.com/mastra-ai/mastra/pull/10197))
54
+ - Updated dependency [`mssql@^12.2.0` ↗︎](https://www.npmjs.com/package/mssql/v/12.2.0) (from `^11.0.1`, in `dependencies`)
55
+ - Updated dependencies [[`08766f1`](https://github.com/mastra-ai/mastra/commit/08766f15e13ac0692fde2a8bd366c2e16e4321df), [`ae8baf7`](https://github.com/mastra-ai/mastra/commit/ae8baf7d8adcb0ff9dac11880400452bc49b33ff), [`cfabdd4`](https://github.com/mastra-ai/mastra/commit/cfabdd4aae7a726b706942d6836eeca110fb6267), [`a0e437f`](https://github.com/mastra-ai/mastra/commit/a0e437fac561b28ee719e0302d72b2f9b4c138f0), [`bec5efd`](https://github.com/mastra-ai/mastra/commit/bec5efde96653ccae6604e68c696d1bc6c1a0bf5), [`9eedf7d`](https://github.com/mastra-ai/mastra/commit/9eedf7de1d6e0022a2f4e5e9e6fe1ec468f9b43c)]:
56
+ - @mastra/core@1.0.0-beta.21
57
+
3
58
  ## 1.0.0-beta.10
4
59
 
5
60
  ### Patch Changes
@@ -28,4 +28,4 @@ docs/
28
28
  ## Version
29
29
 
30
30
  Package: @mastra/mssql
31
- Version: 1.0.0-beta.10
31
+ Version: 1.0.0-beta.12
@@ -5,7 +5,7 @@ description: Documentation for @mastra/mssql. Includes links to type definitions
5
5
 
6
6
  # @mastra/mssql Documentation
7
7
 
8
- > **Version**: 1.0.0-beta.10
8
+ > **Version**: 1.0.0-beta.12
9
9
  > **Package**: @mastra/mssql
10
10
 
11
11
  ## Quick Navigation
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.10",
2
+ "version": "1.0.0-beta.12",
3
3
  "package": "@mastra/mssql",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -1265,28 +1265,76 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
1265
1265
  );
1266
1266
  }
1267
1267
  }
1268
- async listThreadsByResourceId(args) {
1269
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
1270
- if (page < 0) {
1268
+ async listThreads(args) {
1269
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
1270
+ try {
1271
+ this.validatePaginationInput(page, perPageInput ?? 100);
1272
+ } catch (error$1) {
1271
1273
  throw new error.MastraError({
1272
- id: storage.createStorageErrorId("MSSQL", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1274
+ id: storage.createStorageErrorId("MSSQL", "LIST_THREADS", "INVALID_PAGE"),
1273
1275
  domain: error.ErrorDomain.STORAGE,
1274
1276
  category: error.ErrorCategory.USER,
1275
- text: "Page number must be non-negative",
1276
- details: {
1277
- resourceId,
1278
- page
1279
- }
1277
+ text: error$1 instanceof Error ? error$1.message : "Invalid pagination parameters",
1278
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
1280
1279
  });
1281
1280
  }
1282
1281
  const perPage = storage.normalizePerPage(perPageInput, 100);
1282
+ try {
1283
+ this.validateMetadataKeys(filter?.metadata);
1284
+ } catch (error$1) {
1285
+ throw new error.MastraError({
1286
+ id: storage.createStorageErrorId("MSSQL", "LIST_THREADS", "INVALID_METADATA_KEY"),
1287
+ domain: error.ErrorDomain.STORAGE,
1288
+ category: error.ErrorCategory.USER,
1289
+ text: error$1 instanceof Error ? error$1.message : "Invalid metadata key",
1290
+ details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
1291
+ });
1292
+ }
1283
1293
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1284
1294
  const { field, direction } = this.parseOrderBy(orderBy);
1285
1295
  try {
1286
- const baseQuery = `FROM ${getTableName2({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName2(this.schema) })} WHERE [resourceId] = @resourceId`;
1296
+ const tableName = getTableName2({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName2(this.schema) });
1297
+ const whereClauses = [];
1298
+ const params = {};
1299
+ if (filter?.resourceId) {
1300
+ whereClauses.push("[resourceId] = @resourceId");
1301
+ params.resourceId = filter.resourceId;
1302
+ }
1303
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
1304
+ let metadataIndex = 0;
1305
+ for (const [key, value] of Object.entries(filter.metadata)) {
1306
+ if (value !== null && typeof value === "object") {
1307
+ throw new error.MastraError({
1308
+ id: storage.createStorageErrorId("MSSQL", "LIST_THREADS", "INVALID_METADATA_VALUE"),
1309
+ domain: error.ErrorDomain.STORAGE,
1310
+ category: error.ErrorCategory.USER,
1311
+ text: `Metadata filter value for key "${key}" must be a scalar type (string, number, boolean, or null), got ${Array.isArray(value) ? "array" : "object"}`,
1312
+ details: { key, valueType: Array.isArray(value) ? "array" : "object" }
1313
+ });
1314
+ }
1315
+ if (value === null) {
1316
+ whereClauses.push(`JSON_VALUE(metadata, '$.${key}') IS NULL`);
1317
+ } else {
1318
+ const paramName = `metadata${metadataIndex}`;
1319
+ whereClauses.push(`JSON_VALUE(metadata, '$.${key}') = @${paramName}`);
1320
+ if (typeof value === "string") {
1321
+ params[paramName] = value;
1322
+ } else if (typeof value === "boolean") {
1323
+ params[paramName] = value ? "true" : "false";
1324
+ } else {
1325
+ params[paramName] = String(value);
1326
+ }
1327
+ }
1328
+ metadataIndex++;
1329
+ }
1330
+ }
1331
+ const whereClause = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
1332
+ const baseQuery = `FROM ${tableName} ${whereClause}`;
1287
1333
  const countQuery = `SELECT COUNT(*) as count ${baseQuery}`;
1288
1334
  const countRequest = this.pool.request();
1289
- countRequest.input("resourceId", resourceId);
1335
+ for (const [key, value] of Object.entries(params)) {
1336
+ countRequest.input(key, value);
1337
+ }
1290
1338
  const countResult = await countRequest.query(countQuery);
1291
1339
  const total = parseInt(countResult.recordset[0]?.count ?? "0", 10);
1292
1340
  if (total === 0) {
@@ -1303,7 +1351,9 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
1303
1351
  const limitValue = perPageInput === false ? total : perPage;
1304
1352
  const dataQuery = `SELECT id, [resourceId], title, metadata, [createdAt], [updatedAt] ${baseQuery} ORDER BY ${orderByField} ${dir} OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
1305
1353
  const dataRequest = this.pool.request();
1306
- dataRequest.input("resourceId", resourceId);
1354
+ for (const [key, value] of Object.entries(params)) {
1355
+ dataRequest.input(key, value);
1356
+ }
1307
1357
  dataRequest.input("offset", offset);
1308
1358
  if (limitValue > 2147483647) {
1309
1359
  dataRequest.input("perPage", sql__default.default.BigInt, limitValue);
@@ -1326,13 +1376,17 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
1326
1376
  hasMore: perPageInput === false ? false : offset + perPage < total
1327
1377
  };
1328
1378
  } catch (error$1) {
1379
+ if (error$1 instanceof error.MastraError && error$1.category === error.ErrorCategory.USER) {
1380
+ throw error$1;
1381
+ }
1329
1382
  const mastraError = new error.MastraError(
1330
1383
  {
1331
- id: storage.createStorageErrorId("MSSQL", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1384
+ id: storage.createStorageErrorId("MSSQL", "LIST_THREADS", "FAILED"),
1332
1385
  domain: error.ErrorDomain.STORAGE,
1333
1386
  category: error.ErrorCategory.THIRD_PARTY,
1334
1387
  details: {
1335
- resourceId,
1388
+ ...filter?.resourceId && { resourceId: filter.resourceId },
1389
+ hasMetadataFilter: !!filter?.metadata,
1336
1390
  page
1337
1391
  }
1338
1392
  },