@mastra/mssql 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 +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 +68 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -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 +4 -4
package/dist/index.js
CHANGED
|
@@ -1259,28 +1259,76 @@ var MemoryMSSQL = class _MemoryMSSQL extends MemoryStorage {
|
|
|
1259
1259
|
);
|
|
1260
1260
|
}
|
|
1261
1261
|
}
|
|
1262
|
-
async
|
|
1263
|
-
const {
|
|
1264
|
-
|
|
1262
|
+
async listThreads(args) {
|
|
1263
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
1264
|
+
try {
|
|
1265
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
1266
|
+
} catch (error) {
|
|
1265
1267
|
throw new MastraError({
|
|
1266
|
-
id: createStorageErrorId("MSSQL", "
|
|
1268
|
+
id: createStorageErrorId("MSSQL", "LIST_THREADS", "INVALID_PAGE"),
|
|
1267
1269
|
domain: ErrorDomain.STORAGE,
|
|
1268
1270
|
category: ErrorCategory.USER,
|
|
1269
|
-
text:
|
|
1270
|
-
details: {
|
|
1271
|
-
resourceId,
|
|
1272
|
-
page
|
|
1273
|
-
}
|
|
1271
|
+
text: error instanceof Error ? error.message : "Invalid pagination parameters",
|
|
1272
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
1274
1273
|
});
|
|
1275
1274
|
}
|
|
1276
1275
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
1276
|
+
try {
|
|
1277
|
+
this.validateMetadataKeys(filter?.metadata);
|
|
1278
|
+
} catch (error) {
|
|
1279
|
+
throw new MastraError({
|
|
1280
|
+
id: createStorageErrorId("MSSQL", "LIST_THREADS", "INVALID_METADATA_KEY"),
|
|
1281
|
+
domain: ErrorDomain.STORAGE,
|
|
1282
|
+
category: ErrorCategory.USER,
|
|
1283
|
+
text: error instanceof Error ? error.message : "Invalid metadata key",
|
|
1284
|
+
details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1277
1287
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1278
1288
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1279
1289
|
try {
|
|
1280
|
-
const
|
|
1290
|
+
const tableName = getTableName2({ indexName: TABLE_THREADS, schemaName: getSchemaName2(this.schema) });
|
|
1291
|
+
const whereClauses = [];
|
|
1292
|
+
const params = {};
|
|
1293
|
+
if (filter?.resourceId) {
|
|
1294
|
+
whereClauses.push("[resourceId] = @resourceId");
|
|
1295
|
+
params.resourceId = filter.resourceId;
|
|
1296
|
+
}
|
|
1297
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
1298
|
+
let metadataIndex = 0;
|
|
1299
|
+
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
1300
|
+
if (value !== null && typeof value === "object") {
|
|
1301
|
+
throw new MastraError({
|
|
1302
|
+
id: createStorageErrorId("MSSQL", "LIST_THREADS", "INVALID_METADATA_VALUE"),
|
|
1303
|
+
domain: ErrorDomain.STORAGE,
|
|
1304
|
+
category: ErrorCategory.USER,
|
|
1305
|
+
text: `Metadata filter value for key "${key}" must be a scalar type (string, number, boolean, or null), got ${Array.isArray(value) ? "array" : "object"}`,
|
|
1306
|
+
details: { key, valueType: Array.isArray(value) ? "array" : "object" }
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
if (value === null) {
|
|
1310
|
+
whereClauses.push(`JSON_VALUE(metadata, '$.${key}') IS NULL`);
|
|
1311
|
+
} else {
|
|
1312
|
+
const paramName = `metadata${metadataIndex}`;
|
|
1313
|
+
whereClauses.push(`JSON_VALUE(metadata, '$.${key}') = @${paramName}`);
|
|
1314
|
+
if (typeof value === "string") {
|
|
1315
|
+
params[paramName] = value;
|
|
1316
|
+
} else if (typeof value === "boolean") {
|
|
1317
|
+
params[paramName] = value ? "true" : "false";
|
|
1318
|
+
} else {
|
|
1319
|
+
params[paramName] = String(value);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
metadataIndex++;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
const whereClause = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
|
|
1326
|
+
const baseQuery = `FROM ${tableName} ${whereClause}`;
|
|
1281
1327
|
const countQuery = `SELECT COUNT(*) as count ${baseQuery}`;
|
|
1282
1328
|
const countRequest = this.pool.request();
|
|
1283
|
-
|
|
1329
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1330
|
+
countRequest.input(key, value);
|
|
1331
|
+
}
|
|
1284
1332
|
const countResult = await countRequest.query(countQuery);
|
|
1285
1333
|
const total = parseInt(countResult.recordset[0]?.count ?? "0", 10);
|
|
1286
1334
|
if (total === 0) {
|
|
@@ -1297,7 +1345,9 @@ var MemoryMSSQL = class _MemoryMSSQL extends MemoryStorage {
|
|
|
1297
1345
|
const limitValue = perPageInput === false ? total : perPage;
|
|
1298
1346
|
const dataQuery = `SELECT id, [resourceId], title, metadata, [createdAt], [updatedAt] ${baseQuery} ORDER BY ${orderByField} ${dir} OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
|
|
1299
1347
|
const dataRequest = this.pool.request();
|
|
1300
|
-
|
|
1348
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1349
|
+
dataRequest.input(key, value);
|
|
1350
|
+
}
|
|
1301
1351
|
dataRequest.input("offset", offset);
|
|
1302
1352
|
if (limitValue > 2147483647) {
|
|
1303
1353
|
dataRequest.input("perPage", sql.BigInt, limitValue);
|
|
@@ -1320,13 +1370,17 @@ var MemoryMSSQL = class _MemoryMSSQL extends MemoryStorage {
|
|
|
1320
1370
|
hasMore: perPageInput === false ? false : offset + perPage < total
|
|
1321
1371
|
};
|
|
1322
1372
|
} catch (error) {
|
|
1373
|
+
if (error instanceof MastraError && error.category === ErrorCategory.USER) {
|
|
1374
|
+
throw error;
|
|
1375
|
+
}
|
|
1323
1376
|
const mastraError = new MastraError(
|
|
1324
1377
|
{
|
|
1325
|
-
id: createStorageErrorId("MSSQL", "
|
|
1378
|
+
id: createStorageErrorId("MSSQL", "LIST_THREADS", "FAILED"),
|
|
1326
1379
|
domain: ErrorDomain.STORAGE,
|
|
1327
1380
|
category: ErrorCategory.THIRD_PARTY,
|
|
1328
1381
|
details: {
|
|
1329
|
-
resourceId,
|
|
1382
|
+
...filter?.resourceId && { resourceId: filter.resourceId },
|
|
1383
|
+
hasMetadataFilter: !!filter?.metadata,
|
|
1330
1384
|
page
|
|
1331
1385
|
}
|
|
1332
1386
|
},
|