@mastra/mssql 1.8.0 → 1.9.0-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.
- package/dist/docs/SKILL.md +5 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-retention.md +302 -0
- package/dist/index.cjs +33 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +6 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +3 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
2
|
-
import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, MastraCompositeStore, MemoryStorage, ObservabilityStorage, SPAN_SCHEMA, ScoresStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SPANS, TABLE_THREADS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, calculatePagination, createStorageErrorId, getDefaultValue, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
2
|
+
import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, MastraCompositeStore, MemoryStorage, ObservabilityStorage, SPAN_SCHEMA, ScoresStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SPANS, TABLE_THREADS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, calculatePagination, createStorageErrorId, executeRetentionPrune, getDefaultValue, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, resolveRetentionTargets, retentionCutoffMs, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
3
|
import sql from "mssql";
|
|
4
4
|
import { randomUUID } from "crypto";
|
|
5
5
|
import { parseSqlIdentifier } from "@mastra/core/utils";
|
|
@@ -215,6 +215,14 @@ var MssqlDB = class extends MastraBase {
|
|
|
215
215
|
}, error);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
+
async pruneBatch({ tableName, column, cutoff, limit }) {
|
|
219
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(column)) throw new Error(`Invalid retention identifier: ${tableName}.${column}`);
|
|
220
|
+
const fullTableName = getTableName$1({
|
|
221
|
+
indexName: tableName,
|
|
222
|
+
schemaName: getSchemaName$1(this.schemaName)
|
|
223
|
+
});
|
|
224
|
+
return (await this.pool.request().input("limit", sql.Int, limit).input("cutoff", sql.DateTime2, cutoff).query(`DELETE TOP (@limit) FROM ${fullTableName} WHERE [${column}] < @cutoff`)).rowsAffected[0] ?? 0;
|
|
225
|
+
}
|
|
218
226
|
async clearTable({ tableName }) {
|
|
219
227
|
const fullTableName = getTableName$1({
|
|
220
228
|
indexName: tableName,
|
|
@@ -3127,6 +3135,11 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
3127
3135
|
//#endregion
|
|
3128
3136
|
//#region src/storage/domains/observability/index.ts
|
|
3129
3137
|
var ObservabilityMSSQL = class ObservabilityMSSQL extends ObservabilityStorage {
|
|
3138
|
+
static retentionTables = { spans: {
|
|
3139
|
+
table: TABLE_SPANS,
|
|
3140
|
+
column: "startedAt",
|
|
3141
|
+
indexed: true
|
|
3142
|
+
} };
|
|
3130
3143
|
pool;
|
|
3131
3144
|
db;
|
|
3132
3145
|
schema;
|
|
@@ -3149,6 +3162,24 @@ var ObservabilityMSSQL = class ObservabilityMSSQL extends ObservabilityStorage {
|
|
|
3149
3162
|
this.skipDefaultIndexes = skipDefaultIndexes;
|
|
3150
3163
|
this.indexes = indexes?.filter((idx) => ObservabilityMSSQL.MANAGED_TABLES.includes(idx.table));
|
|
3151
3164
|
}
|
|
3165
|
+
async prune(policies, options) {
|
|
3166
|
+
return executeRetentionPrune({
|
|
3167
|
+
domain: "observability",
|
|
3168
|
+
targets: resolveRetentionTargets({
|
|
3169
|
+
policies,
|
|
3170
|
+
descriptor: ObservabilityMSSQL.retentionTables,
|
|
3171
|
+
order: ["spans"]
|
|
3172
|
+
}),
|
|
3173
|
+
options,
|
|
3174
|
+
cutoffFor: (target, now) => new Date(retentionCutoffMs(target.policy, now)),
|
|
3175
|
+
deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
|
|
3176
|
+
tableName: target.table,
|
|
3177
|
+
column: target.column,
|
|
3178
|
+
cutoff,
|
|
3179
|
+
limit
|
|
3180
|
+
})
|
|
3181
|
+
});
|
|
3182
|
+
}
|
|
3152
3183
|
async init() {
|
|
3153
3184
|
if (this.needsConnect) {
|
|
3154
3185
|
await this.pool.connect();
|
|
@@ -4801,7 +4832,8 @@ var MSSQLStore = class extends MastraCompositeStore {
|
|
|
4801
4832
|
super({
|
|
4802
4833
|
id: config.id,
|
|
4803
4834
|
name: "MSSQLStore",
|
|
4804
|
-
disableInit: config.disableInit
|
|
4835
|
+
disableInit: config.disableInit,
|
|
4836
|
+
retention: config.retention
|
|
4805
4837
|
});
|
|
4806
4838
|
try {
|
|
4807
4839
|
this.schema = config.schemaName || "dbo";
|