@mastra/mssql 1.10.4 → 1.10.5
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 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +59 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -47
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ 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));
|
|
@@ -1134,21 +1134,22 @@ function prepareWhereClause(filters, _schema) {
|
|
|
1134
1134
|
}
|
|
1135
1135
|
conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] IN (${inParamNames.join(", ")})`);
|
|
1136
1136
|
}
|
|
1137
|
-
} else if (Array.isArray(value))
|
|
1138
|
-
|
|
1139
|
-
|
|
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) {
|
|
1137
|
+
} else if (Array.isArray(value)) {
|
|
1138
|
+
if (value.length === 0) conditions.push("1 = 0");
|
|
1139
|
+
else if (value.length === 1) {
|
|
1145
1140
|
const paramName = `p${paramIndex++}`;
|
|
1146
|
-
|
|
1147
|
-
params[paramName] =
|
|
1141
|
+
conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] = @${paramName}`);
|
|
1142
|
+
params[paramName] = value[0] instanceof Date ? value[0].toISOString() : value[0];
|
|
1143
|
+
} else {
|
|
1144
|
+
const inParamNames = [];
|
|
1145
|
+
for (const item of value) {
|
|
1146
|
+
const paramName = `p${paramIndex++}`;
|
|
1147
|
+
inParamNames.push(`@${paramName}`);
|
|
1148
|
+
params[paramName] = item instanceof Date ? item.toISOString() : item;
|
|
1149
|
+
}
|
|
1150
|
+
conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] IN (${inParamNames.join(", ")})`);
|
|
1148
1151
|
}
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
+
} else {
|
|
1152
1153
|
const paramName = `p${paramIndex++}`;
|
|
1153
1154
|
conditions.push(`[${(0, _mastra_core_utils.parseSqlIdentifier)(key, "field name")}] = @${paramName}`);
|
|
1154
1155
|
params[paramName] = value instanceof Date ? value.toISOString() : value;
|
|
@@ -1983,15 +1984,19 @@ var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends _mastra_core_stora
|
|
|
1983
1984
|
params[`p${idx}`] = options.expectedStatus;
|
|
1984
1985
|
predicates.push(`[status] = @p${idx++}`);
|
|
1985
1986
|
}
|
|
1986
|
-
if (options?.expectedOwnerId !== void 0)
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1987
|
+
if (options?.expectedOwnerId !== void 0) {
|
|
1988
|
+
if (options.expectedOwnerId === null) predicates.push(`[ownerId] IS NULL`);
|
|
1989
|
+
else {
|
|
1990
|
+
params[`p${idx}`] = options.expectedOwnerId;
|
|
1991
|
+
predicates.push(`[ownerId] = @p${idx++}`);
|
|
1992
|
+
}
|
|
1990
1993
|
}
|
|
1991
|
-
if (options?.expectedLeaseExpiresAt !== void 0)
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1994
|
+
if (options?.expectedLeaseExpiresAt !== void 0) {
|
|
1995
|
+
if (options.expectedLeaseExpiresAt === null) predicates.push(`[leaseExpiresAt] IS NULL`);
|
|
1996
|
+
else {
|
|
1997
|
+
params[`p${idx}`] = options.expectedLeaseExpiresAt.toISOString();
|
|
1998
|
+
predicates.push(`[leaseExpiresAt] = @p${idx++}`);
|
|
1999
|
+
}
|
|
1995
2000
|
}
|
|
1996
2001
|
const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
|
|
1997
2002
|
const request = this.pool.request();
|
|
@@ -2148,10 +2153,11 @@ const MAX_CLAIM_ATTEMPTS = 5;
|
|
|
2148
2153
|
*/
|
|
2149
2154
|
async function assertRunFence(q, claimsTable, fence, operation) {
|
|
2150
2155
|
const row = (await q.request().input("runId", fence.runId).query(`SELECT [generation], [ownerId] FROM ${claimsTable} WITH (HOLDLOCK) WHERE [runId] = @runId`)).recordset[0];
|
|
2151
|
-
|
|
2156
|
+
const current = row ? {
|
|
2152
2157
|
generation: Number(row.generation),
|
|
2153
2158
|
ownerId: String(row.ownerId)
|
|
2154
|
-
} : null
|
|
2159
|
+
} : null;
|
|
2160
|
+
if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
|
|
2155
2161
|
}
|
|
2156
2162
|
/** Runs `fn` in a transaction. */
|
|
2157
2163
|
async function inTransaction(pool, fn) {
|
|
@@ -2396,13 +2402,14 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2396
2402
|
}
|
|
2397
2403
|
}
|
|
2398
2404
|
async prune(policies, options) {
|
|
2405
|
+
const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
|
|
2406
|
+
policies,
|
|
2407
|
+
descriptor: MemoryMSSQL.retentionTables,
|
|
2408
|
+
order: ["runFences"]
|
|
2409
|
+
});
|
|
2399
2410
|
return (0, _mastra_core_storage.executeRetentionPrune)({
|
|
2400
2411
|
domain: "memory",
|
|
2401
|
-
targets
|
|
2402
|
-
policies,
|
|
2403
|
-
descriptor: MemoryMSSQL.retentionTables,
|
|
2404
|
-
order: ["runFences"]
|
|
2405
|
-
}),
|
|
2412
|
+
targets,
|
|
2406
2413
|
options,
|
|
2407
2414
|
cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
|
|
2408
2415
|
deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
|
|
@@ -3384,13 +3391,14 @@ var ObservabilityMSSQL = class ObservabilityMSSQL extends _mastra_core_storage.O
|
|
|
3384
3391
|
this.indexes = indexes?.filter((idx) => ObservabilityMSSQL.MANAGED_TABLES.includes(idx.table));
|
|
3385
3392
|
}
|
|
3386
3393
|
async prune(policies, options) {
|
|
3394
|
+
const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
|
|
3395
|
+
policies,
|
|
3396
|
+
descriptor: ObservabilityMSSQL.retentionTables,
|
|
3397
|
+
order: ["spans"]
|
|
3398
|
+
});
|
|
3387
3399
|
return (0, _mastra_core_storage.executeRetentionPrune)({
|
|
3388
3400
|
domain: "observability",
|
|
3389
|
-
targets
|
|
3390
|
-
policies,
|
|
3391
|
-
descriptor: ObservabilityMSSQL.retentionTables,
|
|
3392
|
-
order: ["spans"]
|
|
3393
|
-
}),
|
|
3401
|
+
targets,
|
|
3394
3402
|
options,
|
|
3395
3403
|
cutoffFor: (target, now) => new Date((0, _mastra_core_storage.retentionCutoffMs)(target.policy, now)),
|
|
3396
3404
|
deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
|
|
@@ -3853,18 +3861,18 @@ var ObservabilityMSSQL = class ObservabilityMSSQL extends _mastra_core_storage.O
|
|
|
3853
3861
|
case _mastra_core_storage.TraceStatus.RUNNING:
|
|
3854
3862
|
conditions.push(`r.[endedAt] IS NULL AND r.[error] IS NULL`);
|
|
3855
3863
|
break;
|
|
3856
|
-
case _mastra_core_storage.TraceStatus.SUCCESS:
|
|
3857
|
-
conditions.push(`r.[endedAt] IS NOT NULL AND r.[error] IS NULL`);
|
|
3858
|
-
break;
|
|
3864
|
+
case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r.[endedAt] IS NOT NULL AND r.[error] IS NULL`);
|
|
3859
3865
|
}
|
|
3860
|
-
if (filters.hasChildError !== void 0)
|
|
3866
|
+
if (filters.hasChildError !== void 0) {
|
|
3867
|
+
if (filters.hasChildError) conditions.push(`EXISTS (
|
|
3861
3868
|
SELECT 1 FROM ${tableName} c
|
|
3862
3869
|
WHERE c.[traceId] = r.[traceId] AND c.[error] IS NOT NULL
|
|
3863
3870
|
)`);
|
|
3864
|
-
|
|
3871
|
+
else conditions.push(`NOT EXISTS (
|
|
3865
3872
|
SELECT 1 FROM ${tableName} c
|
|
3866
3873
|
WHERE c.[traceId] = r.[traceId] AND c.[error] IS NOT NULL
|
|
3867
3874
|
)`);
|
|
3875
|
+
}
|
|
3868
3876
|
}
|
|
3869
3877
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
3870
3878
|
const sortField = orderBy?.field ?? "startedAt";
|
|
@@ -4707,13 +4715,14 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
4707
4715
|
}
|
|
4708
4716
|
}
|
|
4709
4717
|
async prune(policies, options) {
|
|
4718
|
+
const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
|
|
4719
|
+
policies,
|
|
4720
|
+
descriptor: WorkflowsMSSQL.retentionTables,
|
|
4721
|
+
order: ["runOwnership"]
|
|
4722
|
+
});
|
|
4710
4723
|
return (0, _mastra_core_storage.executeRetentionPrune)({
|
|
4711
4724
|
domain: "workflows",
|
|
4712
|
-
targets
|
|
4713
|
-
policies,
|
|
4714
|
-
descriptor: WorkflowsMSSQL.retentionTables,
|
|
4715
|
-
order: ["runOwnership"]
|
|
4716
|
-
}),
|
|
4725
|
+
targets,
|
|
4717
4726
|
options,
|
|
4718
4727
|
cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
|
|
4719
4728
|
deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
|
|
@@ -5098,10 +5107,12 @@ var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.Workflows
|
|
|
5098
5107
|
conditions.push(`JSON_VALUE([snapshot], '$.status') = @status`);
|
|
5099
5108
|
paramMap["status"] = status;
|
|
5100
5109
|
}
|
|
5101
|
-
if (resourceId)
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5110
|
+
if (resourceId) {
|
|
5111
|
+
if (await this.db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
|
|
5112
|
+
conditions.push(`[resourceId] = @resourceId`);
|
|
5113
|
+
paramMap["resourceId"] = resourceId;
|
|
5114
|
+
} else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
5115
|
+
}
|
|
5105
5116
|
if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
|
|
5106
5117
|
conditions.push(`[createdAt] >= @fromDate`);
|
|
5107
5118
|
paramMap[`fromDate`] = fromDate.toISOString();
|