@mastra/mssql 1.10.5-alpha.0 → 1.10.6-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.
@@ -3,7 +3,7 @@ name: mastra-mssql
3
3
  description: Documentation for @mastra/mssql. Use when working with @mastra/mssql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mssql"
6
- version: "1.10.5-alpha.0"
6
+ version: "1.10.6-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.5-alpha.0",
2
+ "version": "1.10.6-alpha.0",
3
3
  "package": "@mastra/mssql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -294,7 +294,7 @@ const storage = new MongoDBStore({
294
294
 
295
295
  ## Reclaiming disk
296
296
 
297
- `prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist and are reused by future writes, so the file stops growing: for most users this alone solves the unbounded-growth problem.
297
+ `prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist for reuse by future writes. Reusing these pages prevents unbounded file growth for most users.
298
298
 
299
299
  Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself in a maintenance window. A full `VACUUM` locks the file and needs roughly twice the file size in free disk. On PostgreSQL, autovacuum reclaims dead tuples for reuse automatically. A manual `VACUUM FULL` is only needed if you must return disk to the OS.
300
300
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -16,11 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let _mastra_core_error = require("@mastra/core/error");
25
24
  let _mastra_core_storage = require("@mastra/core/storage");
26
25
  let mssql = require("mssql");
@@ -29,7 +28,7 @@ let _mastra_core_utils = require("@mastra/core/utils");
29
28
  let _mastra_core_base = require("@mastra/core/base");
30
29
  let _mastra_core_agent = require("@mastra/core/agent");
31
30
  let _mastra_core_evals = require("@mastra/core/evals");
32
- //#region src/storage/db/utils.ts
31
+ // src/storage/db/utils.ts
33
32
  function getSchemaName$1(schema) {
34
33
  return schema ? `[${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}]` : void 0;
35
34
  }
@@ -38,8 +37,7 @@ function getTableName$1({ indexName, schemaName }) {
38
37
  const quotedSchemaName = schemaName;
39
38
  return quotedSchemaName ? `${quotedSchemaName}.${quotedIndexName}` : quotedIndexName;
40
39
  }
41
- //#endregion
42
- //#region src/storage/db/index.ts
40
+ // src/storage/db/index.ts
43
41
  /**
44
42
  * Resolves MssqlDomainConfig to pool and schema.
45
43
  * Domain classes create their own MssqlDB instance from the returned pool.
@@ -1057,8 +1055,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
1057
1055
  }
1058
1056
  }
1059
1057
  };
1060
- //#endregion
1061
- //#region src/storage/domains/utils.ts
1058
+ // src/storage/domains/utils.ts
1062
1059
  function getSchemaName(schema) {
1063
1060
  return schema ? `[${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}]` : void 0;
1064
1061
  }
@@ -1134,21 +1131,22 @@ function prepareWhereClause(filters, _schema) {
1134
1131
  }
1135
1132
  conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] IN (${inParamNames.join(", ")})`);
1136
1133
  }
1137
- } else if (Array.isArray(value)) if (value.length === 0) conditions.push("1 = 0");
1138
- else if (value.length === 1) {
1139
- const paramName = `p${paramIndex++}`;
1140
- conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] = @${paramName}`);
1141
- params[paramName] = value[0] instanceof Date ? value[0].toISOString() : value[0];
1142
- } else {
1143
- const inParamNames = [];
1144
- for (const item of value) {
1134
+ } else if (Array.isArray(value)) {
1135
+ if (value.length === 0) conditions.push("1 = 0");
1136
+ else if (value.length === 1) {
1145
1137
  const paramName = `p${paramIndex++}`;
1146
- inParamNames.push(`@${paramName}`);
1147
- params[paramName] = item instanceof Date ? item.toISOString() : item;
1138
+ conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] = @${paramName}`);
1139
+ params[paramName] = value[0] instanceof Date ? value[0].toISOString() : value[0];
1140
+ } else {
1141
+ const inParamNames = [];
1142
+ for (const item of value) {
1143
+ const paramName = `p${paramIndex++}`;
1144
+ inParamNames.push(`@${paramName}`);
1145
+ params[paramName] = item instanceof Date ? item.toISOString() : item;
1146
+ }
1147
+ conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] IN (${inParamNames.join(", ")})`);
1148
1148
  }
1149
- conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] IN (${inParamNames.join(", ")})`);
1150
- }
1151
- else {
1149
+ } else {
1152
1150
  const paramName = `p${paramIndex++}`;
1153
1151
  conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] = @${paramName}`);
1154
1152
  params[paramName] = value instanceof Date ? value.toISOString() : value;
@@ -1179,8 +1177,7 @@ function transformFromSqlRow({ tableName, sqlRow }) {
1179
1177
  });
1180
1178
  return result;
1181
1179
  }
1182
- //#endregion
1183
- //#region src/storage/domains/agents/index.ts
1180
+ // src/storage/domains/agents/index.ts
1184
1181
  var AgentsMSSQL = class AgentsMSSQL extends _mastra_core_storage.AgentsStorage {
1185
1182
  pool;
1186
1183
  schema;
@@ -1768,8 +1765,7 @@ var AgentsMSSQL = class AgentsMSSQL extends _mastra_core_storage.AgentsStorage {
1768
1765
  }
1769
1766
  }
1770
1767
  };
1771
- //#endregion
1772
- //#region src/storage/domains/background-tasks/index.ts
1768
+ // src/storage/domains/background-tasks/index.ts
1773
1769
  function serializeJson(v) {
1774
1770
  if (typeof v === "object" && v != null) return JSON.stringify(v);
1775
1771
  return v ?? null;
@@ -1983,15 +1979,19 @@ var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends _mastra_core_stora
1983
1979
  params[`p${idx}`] = options.expectedStatus;
1984
1980
  predicates.push(`[status] = @p${idx++}`);
1985
1981
  }
1986
- if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates.push(`[ownerId] IS NULL`);
1987
- else {
1988
- params[`p${idx}`] = options.expectedOwnerId;
1989
- predicates.push(`[ownerId] = @p${idx++}`);
1982
+ if (options?.expectedOwnerId !== void 0) {
1983
+ if (options.expectedOwnerId === null) predicates.push(`[ownerId] IS NULL`);
1984
+ else {
1985
+ params[`p${idx}`] = options.expectedOwnerId;
1986
+ predicates.push(`[ownerId] = @p${idx++}`);
1987
+ }
1990
1988
  }
1991
- if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates.push(`[leaseExpiresAt] IS NULL`);
1992
- else {
1993
- params[`p${idx}`] = options.expectedLeaseExpiresAt.toISOString();
1994
- predicates.push(`[leaseExpiresAt] = @p${idx++}`);
1989
+ if (options?.expectedLeaseExpiresAt !== void 0) {
1990
+ if (options.expectedLeaseExpiresAt === null) predicates.push(`[leaseExpiresAt] IS NULL`);
1991
+ else {
1992
+ params[`p${idx}`] = options.expectedLeaseExpiresAt.toISOString();
1993
+ predicates.push(`[leaseExpiresAt] = @p${idx++}`);
1994
+ }
1995
1995
  }
1996
1996
  const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
1997
1997
  const request = this.pool.request();
@@ -2126,8 +2126,7 @@ var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends _mastra_core_stora
2126
2126
  return Number(result.recordset[0]?.count ?? 0);
2127
2127
  }
2128
2128
  };
2129
- //#endregion
2130
- //#region src/storage/db/run-fencing.ts
2129
+ // src/storage/db/run-fencing.ts
2131
2130
  /**
2132
2131
  * Epoch milliseconds on the database clock. SQL Server evaluates
2133
2132
  * `SYSUTCDATETIME()` once when a statement starts, so a statement that waits
@@ -2148,10 +2147,11 @@ const MAX_CLAIM_ATTEMPTS = 5;
2148
2147
  */
2149
2148
  async function assertRunFence(q, claimsTable, fence, operation) {
2150
2149
  const row = (await q.request().input("runId", fence.runId).query(`SELECT [generation], [ownerId] FROM ${claimsTable} WITH (HOLDLOCK) WHERE [runId] = @runId`)).recordset[0];
2151
- if (!(0, _mastra_core_storage.matchesRunFence)(row ? {
2150
+ const current = row ? {
2152
2151
  generation: Number(row.generation),
2153
2152
  ownerId: String(row.ownerId)
2154
- } : null, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
2153
+ } : null;
2154
+ if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
2155
2155
  }
2156
2156
  /** Runs `fn` in a transaction. */
2157
2157
  async function inTransaction(pool, fn) {
@@ -2193,8 +2193,7 @@ async function claimTransaction(pool, fn) {
2193
2193
  if (attempt >= MAX_CLAIM_ATTEMPTS || !(number === ERR_DEADLOCK_VICTIM || number === ERR_PRIMARY_KEY || number === ERR_UNIQUE_INDEX)) throw error;
2194
2194
  }
2195
2195
  }
2196
- //#endregion
2197
- //#region src/storage/domains/memory/index.ts
2196
+ // src/storage/domains/memory/index.ts
2198
2197
  function bindMssqlMetadataParams(request, params) {
2199
2198
  for (const [paramName, paramValue] of Object.entries(params)) request.input(paramName, paramValue);
2200
2199
  }
@@ -2396,13 +2395,14 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2396
2395
  }
2397
2396
  }
2398
2397
  async prune(policies, options) {
2398
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
2399
+ policies,
2400
+ descriptor: MemoryMSSQL.retentionTables,
2401
+ order: ["runFences"]
2402
+ });
2399
2403
  return (0, _mastra_core_storage.executeRetentionPrune)({
2400
2404
  domain: "memory",
2401
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
2402
- policies,
2403
- descriptor: MemoryMSSQL.retentionTables,
2404
- order: ["runFences"]
2405
- }),
2405
+ targets,
2406
2406
  options,
2407
2407
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
2408
2408
  deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
@@ -3353,8 +3353,7 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
3353
3353
  }
3354
3354
  }
3355
3355
  };
3356
- //#endregion
3357
- //#region src/storage/domains/observability/index.ts
3356
+ // src/storage/domains/observability/index.ts
3358
3357
  var ObservabilityMSSQL = class ObservabilityMSSQL extends _mastra_core_storage.ObservabilityStorage {
3359
3358
  static retentionTables = { spans: {
3360
3359
  table: _mastra_core_storage.TABLE_SPANS,
@@ -3384,13 +3383,14 @@ var ObservabilityMSSQL = class ObservabilityMSSQL extends _mastra_core_storage.O
3384
3383
  this.indexes = indexes?.filter((idx) => ObservabilityMSSQL.MANAGED_TABLES.includes(idx.table));
3385
3384
  }
3386
3385
  async prune(policies, options) {
3386
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
3387
+ policies,
3388
+ descriptor: ObservabilityMSSQL.retentionTables,
3389
+ order: ["spans"]
3390
+ });
3387
3391
  return (0, _mastra_core_storage.executeRetentionPrune)({
3388
3392
  domain: "observability",
3389
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
3390
- policies,
3391
- descriptor: ObservabilityMSSQL.retentionTables,
3392
- order: ["spans"]
3393
- }),
3393
+ targets,
3394
3394
  options,
3395
3395
  cutoffFor: (target, now) => new Date((0, _mastra_core_storage.retentionCutoffMs)(target.policy, now)),
3396
3396
  deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
@@ -3853,18 +3853,18 @@ var ObservabilityMSSQL = class ObservabilityMSSQL extends _mastra_core_storage.O
3853
3853
  case _mastra_core_storage.TraceStatus.RUNNING:
3854
3854
  conditions.push(`r.[endedAt] IS NULL AND r.[error] IS NULL`);
3855
3855
  break;
3856
- case _mastra_core_storage.TraceStatus.SUCCESS:
3857
- conditions.push(`r.[endedAt] IS NOT NULL AND r.[error] IS NULL`);
3858
- break;
3856
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r.[endedAt] IS NOT NULL AND r.[error] IS NULL`);
3859
3857
  }
3860
- if (filters.hasChildError !== void 0) if (filters.hasChildError) conditions.push(`EXISTS (
3858
+ if (filters.hasChildError !== void 0) {
3859
+ if (filters.hasChildError) conditions.push(`EXISTS (
3861
3860
  SELECT 1 FROM ${tableName} c
3862
3861
  WHERE c.[traceId] = r.[traceId] AND c.[error] IS NOT NULL
3863
3862
  )`);
3864
- else conditions.push(`NOT EXISTS (
3863
+ else conditions.push(`NOT EXISTS (
3865
3864
  SELECT 1 FROM ${tableName} c
3866
3865
  WHERE c.[traceId] = r.[traceId] AND c.[error] IS NOT NULL
3867
3866
  )`);
3867
+ }
3868
3868
  }
3869
3869
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
3870
3870
  const sortField = orderBy?.field ?? "startedAt";
@@ -3994,8 +3994,7 @@ var ObservabilityMSSQL = class ObservabilityMSSQL extends _mastra_core_storage.O
3994
3994
  }
3995
3995
  }
3996
3996
  };
3997
- //#endregion
3998
- //#region src/storage/domains/scores/index.ts
3997
+ // src/storage/domains/scores/index.ts
3999
3998
  /**
4000
3999
  * MSSQL-specific score row transformation.
4001
4000
  * Converts timestamp strings to Date objects.
@@ -4411,8 +4410,7 @@ var ScoresMSSQL = class ScoresMSSQL extends _mastra_core_storage.ScoresStorage {
4411
4410
  }
4412
4411
  }
4413
4412
  };
4414
- //#endregion
4415
- //#region src/storage/domains/workflow-definitions/index.ts
4413
+ // src/storage/domains/workflow-definitions/index.ts
4416
4414
  function parseJson(value, column, rowId) {
4417
4415
  if (value == null) return null;
4418
4416
  if (typeof value === "string") try {
@@ -4615,8 +4613,7 @@ var WorkflowDefinitionsMSSQL = class WorkflowDefinitionsMSSQL extends _mastra_co
4615
4613
  await request.query(`DELETE FROM ${tableName} WHERE [id] = @id`);
4616
4614
  }
4617
4615
  };
4618
- //#endregion
4619
- //#region src/storage/domains/workflows/index.ts
4616
+ // src/storage/domains/workflows/index.ts
4620
4617
  const RUN_OWNER_COLUMNS = `[generation], [ownerId], [leaseExpiresAt], ${DB_NOW_MS} AS [nowMs]`;
4621
4618
  function toRunOwnershipRecord(runId, row) {
4622
4619
  const leaseExpiresAt = row.leaseExpiresAt === null ? null : Number(row.leaseExpiresAt);
@@ -4707,13 +4704,14 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
4707
4704
  }
4708
4705
  }
4709
4706
  async prune(policies, options) {
4707
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
4708
+ policies,
4709
+ descriptor: WorkflowsMSSQL.retentionTables,
4710
+ order: ["runOwnership"]
4711
+ });
4710
4712
  return (0, _mastra_core_storage.executeRetentionPrune)({
4711
4713
  domain: "workflows",
4712
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
4713
- policies,
4714
- descriptor: WorkflowsMSSQL.retentionTables,
4715
- order: ["runOwnership"]
4716
- }),
4714
+ targets,
4717
4715
  options,
4718
4716
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
4719
4717
  deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
@@ -5098,10 +5096,12 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
5098
5096
  conditions.push(`JSON_VALUE([snapshot], '$.status') = @status`);
5099
5097
  paramMap["status"] = status;
5100
5098
  }
5101
- if (resourceId) if (await this.db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
5102
- conditions.push(`[resourceId] = @resourceId`);
5103
- paramMap["resourceId"] = resourceId;
5104
- } else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
5099
+ if (resourceId) {
5100
+ if (await this.db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
5101
+ conditions.push(`[resourceId] = @resourceId`);
5102
+ paramMap["resourceId"] = resourceId;
5103
+ } else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
5104
+ }
5105
5105
  if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
5106
5106
  conditions.push(`[createdAt] >= @fromDate`);
5107
5107
  paramMap[`fromDate`] = fromDate.toISOString();
@@ -5150,8 +5150,7 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
5150
5150
  }
5151
5151
  }
5152
5152
  };
5153
- //#endregion
5154
- //#region src/storage/index.ts
5153
+ // src/storage/index.ts
5155
5154
  /**
5156
5155
  * Type guard for pre-configured pool config
5157
5156
  */
@@ -5264,12 +5263,8 @@ var MSSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
5264
5263
  }
5265
5264
  }
5266
5265
  async _performInitializationAndStore() {
5267
- try {
5268
- await this.pool.connect();
5269
- return true;
5270
- } catch (err) {
5271
- throw err;
5272
- }
5266
+ await this.pool.connect();
5267
+ return true;
5273
5268
  }
5274
5269
  /**
5275
5270
  * Closes the MSSQL connection pool.
@@ -5280,7 +5275,6 @@ var MSSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
5280
5275
  await this.pool.close();
5281
5276
  }
5282
5277
  };
5283
- //#endregion
5284
5278
  exports.AgentsMSSQL = AgentsMSSQL;
5285
5279
  exports.BackgroundTasksMSSQL = BackgroundTasksMSSQL;
5286
5280
  exports.MSSQLStore = MSSQLStore;