@mastra/mysql 0.6.0-alpha.0 → 0.6.0-alpha.1

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/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, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, ExperimentsStorage, FAVORITES_SCHEMA, FavoritesStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, MastraCompositeStore, MemoryStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORERS_SCHEMA, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, SPAN_SCHEMA, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, StoreOperations, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ToolProviderConnectionsStorage, TraceStatus, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, hasErrorCode, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
2
+ import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, ExperimentsStorage, FAVORITES_SCHEMA, FavoritesStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, MastraCompositeStore, MemoryStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORERS_SCHEMA, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, SPAN_SCHEMA, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, StoreOperations, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ToolProviderConnectionsStorage, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, hasErrorCode, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
3
3
  import { createPool } from "mysql2/promise";
4
4
  import { parseSqlIdentifier } from "@mastra/core/utils";
5
5
  import { randomUUID } from "crypto";
@@ -9176,6 +9176,140 @@ var ToolProviderConnectionsMySQL = class ToolProviderConnectionsMySQL extends To
9176
9176
  }
9177
9177
  };
9178
9178
  //#endregion
9179
+ //#region src/storage/domains/workflow-definitions/index.ts
9180
+ function rowToDefinition(row) {
9181
+ const transformed = transformFromSqlRow({
9182
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
9183
+ sqlRow: row
9184
+ });
9185
+ const def = {
9186
+ id: String(transformed.id),
9187
+ inputSchema: transformed.inputSchema,
9188
+ outputSchema: transformed.outputSchema,
9189
+ graph: transformed.graph,
9190
+ status: String(transformed.status),
9191
+ source: String(transformed.source),
9192
+ createdAt: transformed.createdAt,
9193
+ updatedAt: transformed.updatedAt
9194
+ };
9195
+ if (transformed.description != null) def.description = String(transformed.description);
9196
+ if (transformed.metadata != null) def.metadata = transformed.metadata;
9197
+ if (transformed.stateSchema != null) def.stateSchema = transformed.stateSchema;
9198
+ if (transformed.requestContextSchema != null) def.requestContextSchema = transformed.requestContextSchema;
9199
+ if (transformed.authorId != null) def.authorId = String(transformed.authorId);
9200
+ return def;
9201
+ }
9202
+ var WorkflowDefinitionsMySQL = class extends WorkflowDefinitionsStorage {
9203
+ pool;
9204
+ operations;
9205
+ database;
9206
+ static MANAGED_TABLES = [TABLE_WORKFLOW_DEFINITIONS];
9207
+ static getExportDDL() {
9208
+ return [generateTableSQL({
9209
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
9210
+ schema: WORKFLOW_DEFINITIONS_SCHEMA
9211
+ })];
9212
+ }
9213
+ constructor({ pool, operations, database }) {
9214
+ super();
9215
+ this.pool = pool;
9216
+ this.operations = operations;
9217
+ this.database = database;
9218
+ }
9219
+ async init() {
9220
+ await this.operations.createTable({
9221
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
9222
+ schema: WORKFLOW_DEFINITIONS_SCHEMA
9223
+ });
9224
+ }
9225
+ async dangerouslyClearAll() {
9226
+ await this.operations.clearTable({ tableName: TABLE_WORKFLOW_DEFINITIONS });
9227
+ }
9228
+ async upsert(input) {
9229
+ const now = /* @__PURE__ */ new Date();
9230
+ if (!await this.get(input.id)) {
9231
+ if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
9232
+ if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
9233
+ if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
9234
+ const record = {
9235
+ id: input.id,
9236
+ description: input.description ?? null,
9237
+ metadata: input.metadata ?? null,
9238
+ inputSchema: input.inputSchema,
9239
+ outputSchema: input.outputSchema,
9240
+ stateSchema: input.stateSchema ?? null,
9241
+ requestContextSchema: input.requestContextSchema ?? null,
9242
+ graph: input.graph,
9243
+ status: "active",
9244
+ source: "storage",
9245
+ authorId: "authorId" in input ? input.authorId ?? null : null,
9246
+ createdAt: now,
9247
+ updatedAt: now
9248
+ };
9249
+ try {
9250
+ await this.operations.insertOnly({
9251
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
9252
+ record
9253
+ });
9254
+ } catch (error) {
9255
+ if (!await this.get(input.id)) throw error;
9256
+ return this.applyUpdate(input, now);
9257
+ }
9258
+ const created = await this.get(input.id);
9259
+ if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
9260
+ return created;
9261
+ }
9262
+ return this.applyUpdate(input, now);
9263
+ }
9264
+ async applyUpdate(input, now) {
9265
+ const data = { updatedAt: now };
9266
+ if ("description" in input && input.description !== void 0) data.description = input.description;
9267
+ if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
9268
+ if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
9269
+ if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
9270
+ if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
9271
+ if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
9272
+ if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
9273
+ if ("status" in input && input.status !== void 0) data.status = input.status;
9274
+ if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
9275
+ await this.operations.update({
9276
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
9277
+ keys: { id: input.id },
9278
+ data
9279
+ });
9280
+ const updated = await this.get(input.id);
9281
+ if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
9282
+ return updated;
9283
+ }
9284
+ async get(id) {
9285
+ const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
9286
+ if (!rows.length) return null;
9287
+ return rowToDefinition(rows[0]);
9288
+ }
9289
+ async list(args) {
9290
+ const conditions = [];
9291
+ const params = [];
9292
+ if (args?.status) {
9293
+ conditions.push(`${quoteIdentifier("status", "column name")} = ?`);
9294
+ params.push(args.status);
9295
+ }
9296
+ if (args?.authorId !== void 0) {
9297
+ conditions.push(`${quoteIdentifier("authorId", "column name")} = ?`);
9298
+ params.push(args.authorId);
9299
+ }
9300
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
9301
+ const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(TABLE_WORKFLOW_DEFINITIONS, this.database)}${where} ORDER BY ${quoteIdentifier("updatedAt", "column name")} DESC`, params);
9302
+ const definitions = rows.map((row) => rowToDefinition(row));
9303
+ return {
9304
+ definitions,
9305
+ total: definitions.length
9306
+ };
9307
+ }
9308
+ async delete(id) {
9309
+ await this.pool.execute(`DELETE FROM ${formatTableName(TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
9310
+ }
9311
+ };
9312
+ //#endregion
9179
9313
  //#region src/storage/domains/workflows/index.ts
9180
9314
  function parseSnapshot(snapshot) {
9181
9315
  if (typeof snapshot === "string") try {
@@ -10256,6 +10390,11 @@ var MySQLStore = class extends MastraCompositeStore {
10256
10390
  skipDefaultIndexes: config.skipDefaultIndexes,
10257
10391
  indexes: config.indexes
10258
10392
  });
10393
+ const workflowDefinitions = new WorkflowDefinitionsMySQL({
10394
+ pool: this.pool,
10395
+ operations,
10396
+ database
10397
+ });
10259
10398
  this.stores = {
10260
10399
  memory,
10261
10400
  workflows,
@@ -10275,7 +10414,8 @@ var MySQLStore = class extends MastraCompositeStore {
10275
10414
  channels,
10276
10415
  favorites,
10277
10416
  schedules,
10278
- toolProviderConnections
10417
+ toolProviderConnections,
10418
+ workflowDefinitions
10279
10419
  };
10280
10420
  }
10281
10421
  async init() {