@mastra/mssql 1.11.1 → 1.11.2
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/dist/docs/SKILL.md +1 -5
- package/dist/docs/assets/SOURCE_MAP.json +43 -2
- package/dist/index.cjs +65 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +65 -3
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +9 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/docs/references/reference-storage-retention.md +0 -310
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.11.
|
|
6
|
+
version: "1.11.2"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -18,9 +18,5 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
18
18
|
|
|
19
19
|
- [MSSQL](references/integrations-databases-mssql.md) - Persist Mastra application data in Microsoft SQL Server with MSSQL connection options, schema initialization, and direct database or pool access.
|
|
20
20
|
|
|
21
|
-
### Reference
|
|
22
|
-
|
|
23
|
-
- [Reference: Storage retention (prune)](references/reference-storage-retention.md) - prune() deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable).
|
|
24
|
-
|
|
25
21
|
|
|
26
22
|
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.11.
|
|
2
|
+
"version": "1.11.2",
|
|
3
3
|
"package": "@mastra/mssql",
|
|
4
|
-
"exports": {
|
|
4
|
+
"exports": {
|
|
5
|
+
"AgentsMSSQL": {
|
|
6
|
+
"types": "dist/storage/domains/agents/index.d.ts",
|
|
7
|
+
"implementation": "dist/index.js",
|
|
8
|
+
"line": 1158
|
|
9
|
+
},
|
|
10
|
+
"BackgroundTasksMSSQL": {
|
|
11
|
+
"types": "dist/storage/domains/background-tasks/index.d.ts",
|
|
12
|
+
"implementation": "dist/index.js",
|
|
13
|
+
"line": 1793
|
|
14
|
+
},
|
|
15
|
+
"MSSQLStore": {
|
|
16
|
+
"types": "dist/storage/index.d.ts",
|
|
17
|
+
"implementation": "dist/index.js",
|
|
18
|
+
"line": 5287
|
|
19
|
+
},
|
|
20
|
+
"MemoryMSSQL": {
|
|
21
|
+
"types": "dist/storage/domains/memory/index.d.ts",
|
|
22
|
+
"implementation": "dist/index.js",
|
|
23
|
+
"line": 2241
|
|
24
|
+
},
|
|
25
|
+
"ObservabilityMSSQL": {
|
|
26
|
+
"types": "dist/storage/domains/observability/index.d.ts",
|
|
27
|
+
"implementation": "dist/index.js",
|
|
28
|
+
"line": 3373
|
|
29
|
+
},
|
|
30
|
+
"ScoresMSSQL": {
|
|
31
|
+
"types": "dist/storage/domains/scores/index.d.ts",
|
|
32
|
+
"implementation": "dist/index.js",
|
|
33
|
+
"line": 4041
|
|
34
|
+
},
|
|
35
|
+
"WorkflowDefinitionsMSSQL": {
|
|
36
|
+
"types": "dist/storage/domains/workflow-definitions/index.d.ts",
|
|
37
|
+
"implementation": "dist/index.js",
|
|
38
|
+
"line": 4470
|
|
39
|
+
},
|
|
40
|
+
"WorkflowsMSSQL": {
|
|
41
|
+
"types": "dist/storage/domains/workflows/index.d.ts",
|
|
42
|
+
"implementation": "dist/index.js",
|
|
43
|
+
"line": 4666
|
|
44
|
+
}
|
|
45
|
+
},
|
|
5
46
|
"modules": {}
|
|
6
47
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -4654,6 +4654,28 @@ var WorkflowDefinitionsMSSQL = class WorkflowDefinitionsMSSQL extends _mastra_co
|
|
|
4654
4654
|
};
|
|
4655
4655
|
// src/storage/domains/workflows/index.ts
|
|
4656
4656
|
const RUN_OWNER_COLUMNS = `[generation], [ownerId], [leaseExpiresAt], ${DB_NOW_MS} AS [nowMs]`;
|
|
4657
|
+
/** Run ids per query in `getRunOwnerships`, well under SQL Server's 2,100 parameters per request. */
|
|
4658
|
+
const RUN_OWNERSHIP_BATCH_SIZE = 500;
|
|
4659
|
+
/**
|
|
4660
|
+
* The summary snapshot `listWorkflowRuns({ summary: true })` returns: `status` and `timestamp`
|
|
4661
|
+
* when set, and `parentWorkflow` with only its `workflowId` and `runId` when both are non-empty.
|
|
4662
|
+
* Only these paths are read, so `context` is never sent. OPENJSON parses each snapshot once, and
|
|
4663
|
+
* FOR JSON PATH leaves out NULL values. A snapshot that isn't valid JSON lists as `{}`, since
|
|
4664
|
+
* OPENJSON would fail the whole listing on it. OPENJSON returns one row per element of a JSON
|
|
4665
|
+
* array, so `TOP (1)` keeps the summary to one object.
|
|
4666
|
+
*/
|
|
4667
|
+
const SUMMARY_SNAPSHOT_SQL = `COALESCE(CASE WHEN ISJSON([snapshot]) = 1 THEN (
|
|
4668
|
+
SELECT TOP (1) s.[status],
|
|
4669
|
+
TRY_CAST(s.[timestamp] AS BIGINT) AS [timestamp],
|
|
4670
|
+
CASE WHEN s.[workflowId] <> '' AND s.[runId] <> '' THEN s.[workflowId] END AS [parentWorkflow.workflowId],
|
|
4671
|
+
CASE WHEN s.[workflowId] <> '' AND s.[runId] <> '' THEN s.[runId] END AS [parentWorkflow.runId]
|
|
4672
|
+
FROM OPENJSON([snapshot]) WITH (
|
|
4673
|
+
[status] NVARCHAR(MAX) '$.status',
|
|
4674
|
+
[timestamp] NVARCHAR(64) '$.timestamp',
|
|
4675
|
+
[workflowId] NVARCHAR(MAX) '$.parentWorkflow.workflowId',
|
|
4676
|
+
[runId] NVARCHAR(MAX) '$.parentWorkflow.runId'
|
|
4677
|
+
) AS s
|
|
4678
|
+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER) END, '{}')`;
|
|
4657
4679
|
function toRunOwnershipRecord(runId, row) {
|
|
4658
4680
|
const leaseExpiresAt = row.leaseExpiresAt === null ? null : Number(row.leaseExpiresAt);
|
|
4659
4681
|
return {
|
|
@@ -4671,6 +4693,8 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
4671
4693
|
needsConnect;
|
|
4672
4694
|
skipDefaultIndexes;
|
|
4673
4695
|
indexes;
|
|
4696
|
+
/** Set once the snapshot table is seen with a `resourceId` column, which is never dropped. */
|
|
4697
|
+
#hasResourceIdColumn = false;
|
|
4674
4698
|
/** Tables managed by this domain */
|
|
4675
4699
|
static MANAGED_TABLES = [_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT];
|
|
4676
4700
|
/**
|
|
@@ -4859,6 +4883,38 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
4859
4883
|
throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
|
|
4860
4884
|
}
|
|
4861
4885
|
}
|
|
4886
|
+
/** Reads the records with one query per {@link RUN_OWNERSHIP_BATCH_SIZE} runs. */
|
|
4887
|
+
async getRunOwnerships({ runIds }) {
|
|
4888
|
+
const records = /* @__PURE__ */ new Map();
|
|
4889
|
+
const ids = [...new Set(runIds)];
|
|
4890
|
+
try {
|
|
4891
|
+
for (let start = 0; start < ids.length; start += RUN_OWNERSHIP_BATCH_SIZE) {
|
|
4892
|
+
const chunk = ids.slice(start, start + RUN_OWNERSHIP_BATCH_SIZE);
|
|
4893
|
+
const request = this.pool.request();
|
|
4894
|
+
chunk.forEach((runId, i) => request.input(`runId${i}`, runId));
|
|
4895
|
+
const rows = (await request.query(`SELECT j.[reqId], ${RUN_OWNER_COLUMNS}
|
|
4896
|
+
FROM (VALUES ${chunk.map((_, i) => `(@runId${i})`).join(", ")}) AS j ([reqId])
|
|
4897
|
+
JOIN ${this.#runOwnersTable} o ON o.[runId] = j.[reqId]`)).recordset;
|
|
4898
|
+
for (const row of rows) {
|
|
4899
|
+
const runId = String(row.reqId);
|
|
4900
|
+
records.set(runId, toRunOwnershipRecord(runId, row));
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
return records;
|
|
4904
|
+
} catch (error) {
|
|
4905
|
+
throw new _mastra_core_error.MastraError({
|
|
4906
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("MSSQL", "GET_RUN_OWNERSHIPS", "FAILED"),
|
|
4907
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
4908
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
4909
|
+
details: { runCount: ids.length }
|
|
4910
|
+
}, error);
|
|
4911
|
+
}
|
|
4912
|
+
}
|
|
4913
|
+
/** Whether the snapshot table has `resourceId`, which tables created before it existed lack. */
|
|
4914
|
+
async #resourceIdColumnExists() {
|
|
4915
|
+
if (!this.#hasResourceIdColumn) this.#hasResourceIdColumn = await this.db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
4916
|
+
return this.#hasResourceIdColumn;
|
|
4917
|
+
}
|
|
4862
4918
|
parseWorkflowRun(row) {
|
|
4863
4919
|
let parsedSnapshot = row.snapshot;
|
|
4864
4920
|
if (typeof parsedSnapshot === "string") try {
|
|
@@ -5150,7 +5206,11 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
5150
5206
|
}, error);
|
|
5151
5207
|
}
|
|
5152
5208
|
}
|
|
5153
|
-
|
|
5209
|
+
/**
|
|
5210
|
+
* Lists runs newest first, with optional filters and pagination. With `summary`, each run's
|
|
5211
|
+
* snapshot holds only `status`, `timestamp` and `parentWorkflow`.
|
|
5212
|
+
*/
|
|
5213
|
+
async listWorkflowRuns({ workflowName, fromDate, toDate, page, perPage, resourceId, status, summary } = {}) {
|
|
5154
5214
|
try {
|
|
5155
5215
|
const conditions = [];
|
|
5156
5216
|
const paramMap = {};
|
|
@@ -5163,7 +5223,7 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
5163
5223
|
paramMap["status"] = status;
|
|
5164
5224
|
}
|
|
5165
5225
|
if (resourceId) {
|
|
5166
|
-
if (await this
|
|
5226
|
+
if (await this.#resourceIdColumnExists()) {
|
|
5167
5227
|
conditions.push(`[resourceId] = @resourceId`);
|
|
5168
5228
|
paramMap["resourceId"] = resourceId;
|
|
5169
5229
|
} else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
@@ -5193,7 +5253,9 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
5193
5253
|
const countResult = await request.query(countQuery);
|
|
5194
5254
|
total = Number(countResult.recordset[0]?.count || 0);
|
|
5195
5255
|
}
|
|
5196
|
-
let
|
|
5256
|
+
let columns = "*";
|
|
5257
|
+
if (summary) columns = `[workflow_name], [run_id], ${await this.#resourceIdColumnExists() ? "[resourceId], " : ""}${SUMMARY_SNAPSHOT_SQL} AS [snapshot], [createdAt], [updatedAt]`;
|
|
5258
|
+
let query = `SELECT ${columns} FROM ${tableName} ${whereClause} ORDER BY [seq_id] DESC`;
|
|
5197
5259
|
if (usePagination) {
|
|
5198
5260
|
const normalizedPerPage = (0, _mastra_core_storage.normalizePerPage)(perPage, Number.MAX_SAFE_INTEGER);
|
|
5199
5261
|
const offset = page * normalizedPerPage;
|