@mastra/mssql 1.0.0-beta.5 → 1.0.0-beta.6
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 +13 -0
- package/dist/index.cjs +62 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -29
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +4 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
2
|
import { MastraStorage, createStorageErrorId, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCHEMAS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS, TABLE_SPANS, ScoresStorage, normalizePerPage, calculatePagination, WorkflowsStorage, MemoryStorage, TABLE_RESOURCES, ObservabilityStorage, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
3
|
-
import
|
|
3
|
+
import sql3 from 'mssql';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { parseSqlIdentifier } from '@mastra/core/utils';
|
|
6
6
|
import { randomUUID } from 'crypto';
|
|
@@ -227,7 +227,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
227
227
|
dataRequest.input("resourceId", resourceId);
|
|
228
228
|
dataRequest.input("offset", offset);
|
|
229
229
|
if (limitValue > 2147483647) {
|
|
230
|
-
dataRequest.input("perPage",
|
|
230
|
+
dataRequest.input("perPage", sql3.BigInt, limitValue);
|
|
231
231
|
} else {
|
|
232
232
|
dataRequest.input("perPage", limitValue);
|
|
233
233
|
}
|
|
@@ -291,12 +291,12 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
291
291
|
req.input("title", thread.title);
|
|
292
292
|
const metadata = thread.metadata ? JSON.stringify(thread.metadata) : null;
|
|
293
293
|
if (metadata === null) {
|
|
294
|
-
req.input("metadata",
|
|
294
|
+
req.input("metadata", sql3.NVarChar, null);
|
|
295
295
|
} else {
|
|
296
296
|
req.input("metadata", metadata);
|
|
297
297
|
}
|
|
298
|
-
req.input("createdAt",
|
|
299
|
-
req.input("updatedAt",
|
|
298
|
+
req.input("createdAt", sql3.DateTime2, thread.createdAt);
|
|
299
|
+
req.input("updatedAt", sql3.DateTime2, thread.updatedAt);
|
|
300
300
|
await req.query(mergeSql);
|
|
301
301
|
return thread;
|
|
302
302
|
} catch (error) {
|
|
@@ -592,7 +592,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
592
592
|
return result2.recordset || [];
|
|
593
593
|
}
|
|
594
594
|
request.input("offset", offset);
|
|
595
|
-
request.input("limit", perPage > 2147483647 ?
|
|
595
|
+
request.input("limit", perPage > 2147483647 ? sql3.BigInt : sql3.Int, perPage);
|
|
596
596
|
const result = await request.query(
|
|
597
597
|
`${baseQuery}${actualWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`
|
|
598
598
|
);
|
|
@@ -717,7 +717,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
717
717
|
"content",
|
|
718
718
|
typeof message.content === "string" ? message.content : JSON.stringify(message.content)
|
|
719
719
|
);
|
|
720
|
-
request.input("createdAt",
|
|
720
|
+
request.input("createdAt", sql3.DateTime2, message.createdAt);
|
|
721
721
|
request.input("role", message.role);
|
|
722
722
|
request.input("type", message.type || "v2");
|
|
723
723
|
request.input("resourceId", message.resourceId);
|
|
@@ -736,7 +736,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
736
736
|
await request.query(mergeSql);
|
|
737
737
|
}
|
|
738
738
|
const threadReq = transaction.request();
|
|
739
|
-
threadReq.input("updatedAt",
|
|
739
|
+
threadReq.input("updatedAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
740
740
|
threadReq.input("id", threadId);
|
|
741
741
|
await threadReq.query(`UPDATE ${tableThreads} SET [updatedAt] = @updatedAt WHERE id = @id`);
|
|
742
742
|
await transaction.commit();
|
|
@@ -1437,7 +1437,7 @@ var StoreOperationsMSSQL = class extends StoreOperations {
|
|
|
1437
1437
|
const value = record[col];
|
|
1438
1438
|
const preparedValue = this.prepareValue(value, col, tableName);
|
|
1439
1439
|
if (preparedValue instanceof Date) {
|
|
1440
|
-
request.input(`param${i}`,
|
|
1440
|
+
request.input(`param${i}`, sql3.DateTime2, preparedValue);
|
|
1441
1441
|
} else if (preparedValue === null || preparedValue === void 0) {
|
|
1442
1442
|
request.input(`param${i}`, this.getMssqlType(tableName, col), null);
|
|
1443
1443
|
} else {
|
|
@@ -1775,23 +1775,23 @@ ${columns}
|
|
|
1775
1775
|
const col = TABLE_SCHEMAS[tableName]?.[columnName];
|
|
1776
1776
|
switch (col?.type) {
|
|
1777
1777
|
case "text":
|
|
1778
|
-
return
|
|
1778
|
+
return sql3.NVarChar;
|
|
1779
1779
|
case "timestamp":
|
|
1780
|
-
return
|
|
1780
|
+
return sql3.DateTime2;
|
|
1781
1781
|
case "uuid":
|
|
1782
|
-
return
|
|
1782
|
+
return sql3.UniqueIdentifier;
|
|
1783
1783
|
case "jsonb":
|
|
1784
|
-
return
|
|
1784
|
+
return sql3.NVarChar;
|
|
1785
1785
|
case "integer":
|
|
1786
|
-
return
|
|
1786
|
+
return sql3.Int;
|
|
1787
1787
|
case "bigint":
|
|
1788
|
-
return
|
|
1788
|
+
return sql3.BigInt;
|
|
1789
1789
|
case "float":
|
|
1790
|
-
return
|
|
1790
|
+
return sql3.Float;
|
|
1791
1791
|
case "boolean":
|
|
1792
|
-
return
|
|
1792
|
+
return sql3.Bit;
|
|
1793
1793
|
default:
|
|
1794
|
-
return
|
|
1794
|
+
return sql3.NVarChar;
|
|
1795
1795
|
}
|
|
1796
1796
|
}
|
|
1797
1797
|
/**
|
|
@@ -2691,7 +2691,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2691
2691
|
const transaction = this.pool.transaction();
|
|
2692
2692
|
try {
|
|
2693
2693
|
await transaction.begin();
|
|
2694
|
-
const selectRequest = new
|
|
2694
|
+
const selectRequest = new sql3.Request(transaction);
|
|
2695
2695
|
selectRequest.input("workflow_name", workflowName);
|
|
2696
2696
|
selectRequest.input("run_id", runId);
|
|
2697
2697
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2719,12 +2719,12 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2719
2719
|
}
|
|
2720
2720
|
snapshot.context[stepId] = result;
|
|
2721
2721
|
snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
|
|
2722
|
-
const upsertReq = new
|
|
2722
|
+
const upsertReq = new sql3.Request(transaction);
|
|
2723
2723
|
upsertReq.input("workflow_name", workflowName);
|
|
2724
2724
|
upsertReq.input("run_id", runId);
|
|
2725
2725
|
upsertReq.input("snapshot", JSON.stringify(snapshot));
|
|
2726
|
-
upsertReq.input("createdAt",
|
|
2727
|
-
upsertReq.input("updatedAt",
|
|
2726
|
+
upsertReq.input("createdAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
2727
|
+
upsertReq.input("updatedAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
2728
2728
|
await upsertReq.query(
|
|
2729
2729
|
`MERGE ${table} AS target
|
|
2730
2730
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
@@ -2764,7 +2764,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2764
2764
|
const transaction = this.pool.transaction();
|
|
2765
2765
|
try {
|
|
2766
2766
|
await transaction.begin();
|
|
2767
|
-
const selectRequest = new
|
|
2767
|
+
const selectRequest = new sql3.Request(transaction);
|
|
2768
2768
|
selectRequest.input("workflow_name", workflowName);
|
|
2769
2769
|
selectRequest.input("run_id", runId);
|
|
2770
2770
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2792,11 +2792,11 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2792
2792
|
);
|
|
2793
2793
|
}
|
|
2794
2794
|
const updatedSnapshot = { ...snapshot, ...opts };
|
|
2795
|
-
const updateRequest = new
|
|
2795
|
+
const updateRequest = new sql3.Request(transaction);
|
|
2796
2796
|
updateRequest.input("snapshot", JSON.stringify(updatedSnapshot));
|
|
2797
2797
|
updateRequest.input("workflow_name", workflowName);
|
|
2798
2798
|
updateRequest.input("run_id", runId);
|
|
2799
|
-
updateRequest.input("updatedAt",
|
|
2799
|
+
updateRequest.input("updatedAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
2800
2800
|
await updateRequest.query(
|
|
2801
2801
|
`UPDATE ${table} SET snapshot = @snapshot, [updatedAt] = @updatedAt WHERE workflow_name = @workflow_name AND run_id = @run_id`
|
|
2802
2802
|
);
|
|
@@ -2836,8 +2836,8 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2836
2836
|
request.input("run_id", runId);
|
|
2837
2837
|
request.input("resourceId", resourceId);
|
|
2838
2838
|
request.input("snapshot", JSON.stringify(snapshot));
|
|
2839
|
-
request.input("createdAt",
|
|
2840
|
-
request.input("updatedAt",
|
|
2839
|
+
request.input("createdAt", sql3.DateTime2, new Date(now));
|
|
2840
|
+
request.input("updatedAt", sql3.DateTime2, new Date(now));
|
|
2841
2841
|
const mergeSql = `MERGE INTO ${table} AS target
|
|
2842
2842
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
2843
2843
|
ON target.workflow_name = src.workflow_name AND target.run_id = src.run_id
|
|
@@ -2934,6 +2934,35 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2934
2934
|
);
|
|
2935
2935
|
}
|
|
2936
2936
|
}
|
|
2937
|
+
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
2938
|
+
const table = getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName(this.schema) });
|
|
2939
|
+
const transaction = this.pool.transaction();
|
|
2940
|
+
try {
|
|
2941
|
+
await transaction.begin();
|
|
2942
|
+
const deleteRequest = new sql3.Request(transaction);
|
|
2943
|
+
deleteRequest.input("workflow_name", workflowName);
|
|
2944
|
+
deleteRequest.input("run_id", runId);
|
|
2945
|
+
await deleteRequest.query(`DELETE FROM ${table} WHERE workflow_name = @workflow_name AND run_id = @run_id`);
|
|
2946
|
+
await transaction.commit();
|
|
2947
|
+
} catch (error) {
|
|
2948
|
+
try {
|
|
2949
|
+
await transaction.rollback();
|
|
2950
|
+
} catch {
|
|
2951
|
+
}
|
|
2952
|
+
throw new MastraError(
|
|
2953
|
+
{
|
|
2954
|
+
id: createStorageErrorId("MSSQL", "DELETE_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
2955
|
+
domain: ErrorDomain.STORAGE,
|
|
2956
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2957
|
+
details: {
|
|
2958
|
+
runId,
|
|
2959
|
+
workflowName
|
|
2960
|
+
}
|
|
2961
|
+
},
|
|
2962
|
+
error
|
|
2963
|
+
);
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2937
2966
|
async listWorkflowRuns({
|
|
2938
2967
|
workflowName,
|
|
2939
2968
|
fromDate,
|
|
@@ -2977,7 +3006,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2977
3006
|
const request = this.pool.request();
|
|
2978
3007
|
Object.entries(paramMap).forEach(([key, value]) => {
|
|
2979
3008
|
if (value instanceof Date) {
|
|
2980
|
-
request.input(key,
|
|
3009
|
+
request.input(key, sql3.DateTime, value);
|
|
2981
3010
|
} else {
|
|
2982
3011
|
request.input(key, value);
|
|
2983
3012
|
}
|
|
@@ -3040,7 +3069,7 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3040
3069
|
}
|
|
3041
3070
|
}
|
|
3042
3071
|
this.schema = config.schemaName || "dbo";
|
|
3043
|
-
this.pool = "connectionString" in config ? new
|
|
3072
|
+
this.pool = "connectionString" in config ? new sql3.ConnectionPool(config.connectionString) : new sql3.ConnectionPool({
|
|
3044
3073
|
server: config.server,
|
|
3045
3074
|
database: config.database,
|
|
3046
3075
|
user: config.user,
|
|
@@ -3231,6 +3260,9 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3231
3260
|
}) {
|
|
3232
3261
|
return this.stores.workflows.getWorkflowRunById({ runId, workflowName });
|
|
3233
3262
|
}
|
|
3263
|
+
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
3264
|
+
return this.stores.workflows.deleteWorkflowRunById({ runId, workflowName });
|
|
3265
|
+
}
|
|
3234
3266
|
async close() {
|
|
3235
3267
|
await this.pool.close();
|
|
3236
3268
|
}
|