@mastra/mssql 1.5.1-alpha.0 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # @mastra/mssql
2
2
 
3
+ ## 1.6.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Stored workflow definitions now persist across restarts on every major database backend. ([#20471](https://github.com/mastra-ai/mastra/pull/20471))
8
+
9
+ Implement the `workflowDefinitions` storage domain for libsql, pg, mysql, mssql, mongodb, and spanner. Previously the stored-workflow persistence path (`POST /stored/workflows`, `Mastra.addStoredWorkflow`) only worked against `@mastra/core`'s in-memory store. Persistent adapters returned `undefined` from `storage.getStore('workflowDefinitions')` and threw when the HTTP handler tried to read/write a workflow.
10
+
11
+ ```ts
12
+ const workflowDefinitions = await storage.getStore('workflowDefinitions');
13
+ if (!workflowDefinitions) {
14
+ throw new Error('This storage adapter does not support the workflowDefinitions domain');
15
+ }
16
+
17
+ await workflowDefinitions.upsert({
18
+ id: 'greeting-workflow',
19
+ inputSchema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
20
+ outputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
21
+ graph: [{ type: 'agent', id: 'greet', agentId: 'greeter-agent' }],
22
+ });
23
+
24
+ const { definitions, total } = await workflowDefinitions.list({ status: 'active' });
25
+ const definition = await workflowDefinitions.get('greeting-workflow');
26
+ await workflowDefinitions.delete('greeting-workflow');
27
+ ```
28
+
29
+ Each adapter now ships a `WorkflowDefinitions*` domain that:
30
+
31
+ - Creates the shared `mastra_workflow_definitions` table (or Mongo collection) from `WORKFLOW_DEFINITIONS_SCHEMA` during `init()`, plus a default index on `status`.
32
+ - Implements `upsert` / `get` / `list` / `delete` matching `WorkflowDefinitionsStorage` semantics (`list` supports `status` and `authorId` filters and orders by `updatedAt` desc). Partial upserts preserve unspecified fields, including `authorId` updates and `createdAt` / `updatedAt` semantics.
33
+ - Handles concurrent first-writes race-safely: if two callers upsert the same new id simultaneously, the losing insert detects the duplicate key, re-reads the row, and applies the partial-update path instead of failing.
34
+ - Round-trips the JSON columns (`inputSchema`, `outputSchema`, `stateSchema`, `requestContextSchema`, `metadata`, `graph`) through each adapter's JSON handling, so declarative workflow graphs rehydrate identically no matter which backend they were stored in. Malformed persisted JSON surfaces as an actionable error naming the row and column instead of hydrating raw strings.
35
+
36
+ Exported class names by adapter: `WorkflowDefinitionsLibSQL`, `WorkflowDefinitionsPG`, `WorkflowDefinitionsMySQL`, `WorkflowDefinitionsMSSQL`, `MongoDBWorkflowDefinitionsStore`, `WorkflowDefinitionsSpanner`. The composite stores (`LibSQLStore`, `PostgresStore`, `MySQLStore`, `MSSQLStore`, `MongoDBStore`, `SpannerStore`) auto-wire the new domain, so callers do not need to construct it manually — `storage.getStore('workflowDefinitions')` now returns a live handle.
37
+
38
+ The pg adapter reads `createdAt` / `updatedAt` from the auto-added `createdAtZ` / `updatedAtZ` `timestamptz` companion columns to avoid the naive-timestamp / local-TZ drift that a plain `TIMESTAMP` read exhibits under node-pg.
39
+
40
+ `@mastra/clickhouse` and `@mastra/cloudflare` register the new `mastra_workflow_definitions` table in their table/type maps so shared table constants stay exhaustive (no workflow-definitions domain implementation yet).
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [[`4844167`](https://github.com/mastra-ai/mastra/commit/4844167cff2d5ec5004e94edd34970833040fa3f), [`5faf93f`](https://github.com/mastra-ai/mastra/commit/5faf93f03e19daea394b9e2a923f2e4f833407f2), [`80ad891`](https://github.com/mastra-ai/mastra/commit/80ad891f8cd10379aa5b5af7510c763783b2ab56), [`a1cb98d`](https://github.com/mastra-ai/mastra/commit/a1cb98d11990b560b98482292a1f34aa1a2d9092), [`598ad82`](https://github.com/mastra-ai/mastra/commit/598ad82d41c41389a686338a1d0e50b7400e1938), [`1fd6aad`](https://github.com/mastra-ai/mastra/commit/1fd6aad1ea4a9d32f65efa832307c35e981a4c0a)]:
45
+ - @mastra/core@1.56.0-alpha.4
46
+
47
+ ## 1.5.1
48
+
49
+ ### Patch Changes
50
+
51
+ - dependencies updates: ([#19779](https://github.com/mastra-ai/mastra/pull/19779))
52
+ - Updated dependency [`mssql@^12.7.0` ↗︎](https://www.npmjs.com/package/mssql/v/12.7.0) (from `^12.5.5`, in `dependencies`)
53
+ - Updated dependencies [[`3f472b4`](https://github.com/mastra-ai/mastra/commit/3f472b468892a1ff14ccb43cc0343b86f7d8fd7d), [`ba369f2`](https://github.com/mastra-ai/mastra/commit/ba369f2a0aaf998da0d6aa033d26f64f96bef8ac), [`35b929b`](https://github.com/mastra-ai/mastra/commit/35b929b7abc3d20d85c7985880960ac2d04a6c86), [`55c9e24`](https://github.com/mastra-ai/mastra/commit/55c9e248c27c1d72b5bb7e94ea6b8a3999eee49f), [`dcfed93`](https://github.com/mastra-ai/mastra/commit/dcfed93e1e256c6abfa792cbb7ca836f5d0e8638), [`2876e15`](https://github.com/mastra-ai/mastra/commit/2876e15b4d2f616a3bc1ed3af57d546c268384ce), [`9b3626a`](https://github.com/mastra-ai/mastra/commit/9b3626aeb1d16fcd34b0a8e94c114ddb80a3b240), [`4696963`](https://github.com/mastra-ai/mastra/commit/469696312ac4c618bc8475b0c5ed7949b8a3455e), [`723aa54`](https://github.com/mastra-ai/mastra/commit/723aa5437106bdb708ae03c0ef6b77aa11291e73), [`07f5b4b`](https://github.com/mastra-ai/mastra/commit/07f5b4ba9d608d88865030732e580298296adf99), [`723aa54`](https://github.com/mastra-ai/mastra/commit/723aa5437106bdb708ae03c0ef6b77aa11291e73), [`723aa54`](https://github.com/mastra-ai/mastra/commit/723aa5437106bdb708ae03c0ef6b77aa11291e73), [`598080f`](https://github.com/mastra-ai/mastra/commit/598080f224edb3f0f5b801035b067fac50a56a03)]:
54
+ - @mastra/core@1.55.0
55
+
3
56
  ## 1.5.1-alpha.0
4
57
 
5
58
  ### Patch Changes
@@ -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.5.1-alpha.0"
6
+ version: "1.6.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.1-alpha.0",
2
+ "version": "1.6.0-alpha.0",
3
3
  "package": "@mastra/mssql",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -4111,6 +4111,197 @@ var ScoresMSSQL = class ScoresMSSQL extends _mastra_core_storage.ScoresStorage {
4111
4111
  }
4112
4112
  };
4113
4113
  //#endregion
4114
+ //#region src/storage/domains/workflow-definitions/index.ts
4115
+ function parseJson(value, column, rowId) {
4116
+ if (value == null) return null;
4117
+ if (typeof value === "string") try {
4118
+ return JSON.parse(value);
4119
+ } catch {
4120
+ throw new Error(`Workflow definition row "${String(rowId)}" has malformed JSON in column "${column}".`);
4121
+ }
4122
+ return value;
4123
+ }
4124
+ function rowToDefinition(row) {
4125
+ const inputSchema = parseJson(row.inputSchema, "inputSchema", row.id);
4126
+ const outputSchema = parseJson(row.outputSchema, "outputSchema", row.id);
4127
+ const graph = parseJson(row.graph, "graph", row.id);
4128
+ if (inputSchema == null || outputSchema == null || graph == null) throw new Error(`Workflow definition row "${String(row.id)}" is missing required JSON columns.`);
4129
+ const def = {
4130
+ id: String(row.id),
4131
+ inputSchema,
4132
+ outputSchema,
4133
+ graph,
4134
+ status: String(row.status),
4135
+ source: String(row.source),
4136
+ createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
4137
+ updatedAt: row.updatedAt instanceof Date ? row.updatedAt : new Date(row.updatedAt)
4138
+ };
4139
+ if (row.description != null) def.description = String(row.description);
4140
+ const metadata = parseJson(row.metadata, "metadata", row.id);
4141
+ if (metadata != null) def.metadata = metadata;
4142
+ const stateSchema = parseJson(row.stateSchema, "stateSchema", row.id);
4143
+ if (stateSchema != null) def.stateSchema = stateSchema;
4144
+ const requestContextSchema = parseJson(row.requestContextSchema, "requestContextSchema", row.id);
4145
+ if (requestContextSchema != null) def.requestContextSchema = requestContextSchema;
4146
+ if (row.authorId != null) def.authorId = String(row.authorId);
4147
+ return def;
4148
+ }
4149
+ var WorkflowDefinitionsMSSQL = class WorkflowDefinitionsMSSQL extends _mastra_core_storage.WorkflowDefinitionsStorage {
4150
+ pool;
4151
+ schema;
4152
+ db;
4153
+ needsConnect;
4154
+ skipDefaultIndexes;
4155
+ indexes;
4156
+ static MANAGED_TABLES = [_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS];
4157
+ constructor(config) {
4158
+ super();
4159
+ const { pool, schemaName, skipDefaultIndexes, indexes, needsConnect } = resolveMssqlConfig(config);
4160
+ this.pool = pool;
4161
+ this.schema = schemaName;
4162
+ this.db = new MssqlDB({
4163
+ pool,
4164
+ schemaName,
4165
+ skipDefaultIndexes
4166
+ });
4167
+ this.needsConnect = needsConnect;
4168
+ this.skipDefaultIndexes = skipDefaultIndexes;
4169
+ this.indexes = indexes?.filter((idx) => WorkflowDefinitionsMSSQL.MANAGED_TABLES.includes(idx.table));
4170
+ }
4171
+ async init() {
4172
+ if (this.needsConnect) {
4173
+ await this.pool.connect();
4174
+ this.needsConnect = false;
4175
+ }
4176
+ await this.db.createTable({
4177
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4178
+ schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA
4179
+ });
4180
+ await this.createDefaultIndexes();
4181
+ await this.createCustomIndexes();
4182
+ }
4183
+ getDefaultIndexDefinitions() {
4184
+ return [{
4185
+ name: `${this.schema && this.schema !== "dbo" ? `${this.schema}_` : ""}mastra_workflow_definitions_status_idx`,
4186
+ table: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4187
+ columns: ["status"]
4188
+ }];
4189
+ }
4190
+ async createDefaultIndexes() {
4191
+ if (this.skipDefaultIndexes) return;
4192
+ for (const indexDef of this.getDefaultIndexDefinitions()) try {
4193
+ await this.db.createIndex(indexDef);
4194
+ } catch (error) {
4195
+ this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
4196
+ }
4197
+ }
4198
+ async createCustomIndexes() {
4199
+ if (!this.indexes || this.indexes.length === 0) return;
4200
+ for (const indexDef of this.indexes) try {
4201
+ await this.db.createIndex(indexDef);
4202
+ } catch (error) {
4203
+ this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
4204
+ }
4205
+ }
4206
+ async dangerouslyClearAll() {
4207
+ await this.db.clearTable({ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS });
4208
+ }
4209
+ async upsert(input) {
4210
+ const now = /* @__PURE__ */ new Date();
4211
+ if (!await this.get(input.id)) {
4212
+ if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
4213
+ if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
4214
+ if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
4215
+ const record = {
4216
+ id: input.id,
4217
+ description: input.description ?? null,
4218
+ metadata: input.metadata ?? null,
4219
+ inputSchema: input.inputSchema,
4220
+ outputSchema: input.outputSchema,
4221
+ stateSchema: input.stateSchema ?? null,
4222
+ requestContextSchema: input.requestContextSchema ?? null,
4223
+ graph: input.graph,
4224
+ status: "active",
4225
+ source: "storage",
4226
+ authorId: "authorId" in input ? input.authorId ?? null : null,
4227
+ createdAt: now,
4228
+ updatedAt: now
4229
+ };
4230
+ try {
4231
+ await this.db.insert({
4232
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4233
+ record
4234
+ });
4235
+ } catch (error) {
4236
+ if (!await this.get(input.id)) throw error;
4237
+ return this.applyUpdate(input, now);
4238
+ }
4239
+ const created = await this.get(input.id);
4240
+ if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
4241
+ return created;
4242
+ }
4243
+ return this.applyUpdate(input, now);
4244
+ }
4245
+ async applyUpdate(input, now) {
4246
+ const data = { updatedAt: now };
4247
+ if ("description" in input && input.description !== void 0) data.description = input.description;
4248
+ if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
4249
+ if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
4250
+ if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
4251
+ if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
4252
+ if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
4253
+ if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
4254
+ if ("status" in input && input.status !== void 0) data.status = input.status;
4255
+ if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
4256
+ await this.db.update({
4257
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4258
+ keys: { id: input.id },
4259
+ data
4260
+ });
4261
+ const updated = await this.get(input.id);
4262
+ if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
4263
+ return updated;
4264
+ }
4265
+ async get(id) {
4266
+ const row = await this.db.load({
4267
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4268
+ keys: { id }
4269
+ });
4270
+ return row ? rowToDefinition(row) : null;
4271
+ }
4272
+ async list(args) {
4273
+ const tableName = getTableName({
4274
+ indexName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4275
+ schemaName: getSchemaName(this.schema)
4276
+ });
4277
+ const request = this.pool.request();
4278
+ const conditions = [];
4279
+ if (args?.status) {
4280
+ request.input("status", args.status);
4281
+ conditions.push(`[status] = @status`);
4282
+ }
4283
+ if (args?.authorId !== void 0) {
4284
+ request.input("authorId", args.authorId);
4285
+ conditions.push(`[authorId] = @authorId`);
4286
+ }
4287
+ const where = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
4288
+ const definitions = (await request.query(`SELECT * FROM ${tableName} ${where} ORDER BY [updatedAt] DESC`)).recordset.map(rowToDefinition);
4289
+ return {
4290
+ definitions,
4291
+ total: definitions.length
4292
+ };
4293
+ }
4294
+ async delete(id) {
4295
+ const tableName = getTableName({
4296
+ indexName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
4297
+ schemaName: getSchemaName(this.schema)
4298
+ });
4299
+ const request = this.pool.request();
4300
+ request.input("id", id);
4301
+ await request.query(`DELETE FROM ${tableName} WHERE [id] = @id`);
4302
+ }
4303
+ };
4304
+ //#endregion
4114
4305
  //#region src/storage/domains/workflows/index.ts
4115
4306
  var WorkflowsMSSQL = class WorkflowsMSSQL extends _mastra_core_storage.WorkflowsStorage {
4116
4307
  pool;
@@ -4582,13 +4773,15 @@ var MSSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
4582
4773
  const observability = new ObservabilityMSSQL(domainConfig);
4583
4774
  const backgroundTasks = new BackgroundTasksMSSQL(domainConfig);
4584
4775
  const agents = new AgentsMSSQL(domainConfig);
4776
+ const workflowDefinitions = new WorkflowDefinitionsMSSQL(domainConfig);
4585
4777
  this.stores = {
4586
4778
  scores,
4587
4779
  workflows,
4588
4780
  memory,
4589
4781
  observability,
4590
4782
  backgroundTasks,
4591
- agents
4783
+ agents,
4784
+ workflowDefinitions
4592
4785
  };
4593
4786
  } catch (e) {
4594
4787
  throw new _mastra_core_error.MastraError({
@@ -4637,6 +4830,7 @@ exports.MSSQLStore = MSSQLStore;
4637
4830
  exports.MemoryMSSQL = MemoryMSSQL;
4638
4831
  exports.ObservabilityMSSQL = ObservabilityMSSQL;
4639
4832
  exports.ScoresMSSQL = ScoresMSSQL;
4833
+ exports.WorkflowDefinitionsMSSQL = WorkflowDefinitionsMSSQL;
4640
4834
  exports.WorkflowsMSSQL = WorkflowsMSSQL;
4641
4835
 
4642
4836
  //# sourceMappingURL=index.cjs.map