@mastra/mysql 0.6.0-alpha.0 → 0.6.0-alpha.2
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 +60 -0
- package/dist/index.cjs +157 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -7
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/workflow-definitions/index.d.ts +24 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @mastra/mysql
|
|
2
2
|
|
|
3
|
+
## 0.6.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Dataset item scorer selections now persist across MySQL writes and reads. Setting `scorerIds` to `null` clears an item override, while `[]` remains an explicit override with no scorers. ([#20191](https://github.com/mastra-ai/mastra/pull/20191))
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
await dataset.addItem({
|
|
11
|
+
input: 'Evaluate this response',
|
|
12
|
+
scorerIds: [],
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`82201f7`](https://github.com/mastra-ai/mastra/commit/82201f75fae8e050a8de2df08b74875ee74c6b83), [`fb18da5`](https://github.com/mastra-ai/mastra/commit/fb18da56fc35689ae370621a8f10b5b0d8606e20), [`fb18da5`](https://github.com/mastra-ai/mastra/commit/fb18da56fc35689ae370621a8f10b5b0d8606e20), [`0a6598b`](https://github.com/mastra-ai/mastra/commit/0a6598bde80bde008986ad6616bed9632b9294cb), [`9e1dad8`](https://github.com/mastra-ai/mastra/commit/9e1dad8f7b1cab2bb7ade90e5b7561f24577b88a), [`2f43145`](https://github.com/mastra-ai/mastra/commit/2f4314504c03cbba280414ac81ba3197448ee6b0), [`34d34d8`](https://github.com/mastra-ai/mastra/commit/34d34d8c811df512fef4dd5459f79b7821be1866)]:
|
|
17
|
+
- @mastra/core@1.56.0-alpha.6
|
|
18
|
+
|
|
19
|
+
## 0.6.0-alpha.1
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- Stored workflow definitions now persist across restarts on every major database backend. ([#20471](https://github.com/mastra-ai/mastra/pull/20471))
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
const workflowDefinitions = await storage.getStore('workflowDefinitions');
|
|
29
|
+
if (!workflowDefinitions) {
|
|
30
|
+
throw new Error('This storage adapter does not support the workflowDefinitions domain');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await workflowDefinitions.upsert({
|
|
34
|
+
id: 'greeting-workflow',
|
|
35
|
+
inputSchema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
|
|
36
|
+
outputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
|
|
37
|
+
graph: [{ type: 'agent', id: 'greet', agentId: 'greeter-agent' }],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const { definitions, total } = await workflowDefinitions.list({ status: 'active' });
|
|
41
|
+
const definition = await workflowDefinitions.get('greeting-workflow');
|
|
42
|
+
await workflowDefinitions.delete('greeting-workflow');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Each adapter now ships a `WorkflowDefinitions*` domain that:
|
|
46
|
+
|
|
47
|
+
- Creates the shared `mastra_workflow_definitions` table (or Mongo collection) from `WORKFLOW_DEFINITIONS_SCHEMA` during `init()`, plus a default index on `status`.
|
|
48
|
+
- 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.
|
|
49
|
+
- 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.
|
|
50
|
+
- 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.
|
|
51
|
+
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
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.
|
|
55
|
+
|
|
56
|
+
`@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).
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- 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)]:
|
|
61
|
+
- @mastra/core@1.56.0-alpha.4
|
|
62
|
+
|
|
3
63
|
## 0.6.0-alpha.0
|
|
4
64
|
|
|
5
65
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1908,6 +1908,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
1908
1908
|
"expectedTrajectory",
|
|
1909
1909
|
"toolMocks",
|
|
1910
1910
|
"unmockedToolPolicy",
|
|
1911
|
+
"scorerIds",
|
|
1911
1912
|
"externalId"
|
|
1912
1913
|
]
|
|
1913
1914
|
});
|
|
@@ -1964,6 +1965,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
1964
1965
|
expectedTrajectory: row.expectedTrajectory ? parseJSON$3(row.expectedTrajectory) : void 0,
|
|
1965
1966
|
toolMocks: row.toolMocks ? parseJSON$3(row.toolMocks) : void 0,
|
|
1966
1967
|
unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
|
|
1968
|
+
scorerIds: row.scorerIds ? parseJSON$3(row.scorerIds) : void 0,
|
|
1967
1969
|
requestContext: row.requestContext ? parseJSON$3(row.requestContext) : void 0,
|
|
1968
1970
|
metadata: row.metadata ? parseJSON$3(row.metadata) : void 0,
|
|
1969
1971
|
source: row.source ? parseJSON$3(row.source) : void 0,
|
|
@@ -1986,6 +1988,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
1986
1988
|
expectedTrajectory: row.expectedTrajectory ? parseJSON$3(row.expectedTrajectory) : void 0,
|
|
1987
1989
|
toolMocks: row.toolMocks ? parseJSON$3(row.toolMocks) : void 0,
|
|
1988
1990
|
unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
|
|
1991
|
+
scorerIds: row.scorerIds ? parseJSON$3(row.scorerIds) : void 0,
|
|
1989
1992
|
requestContext: row.requestContext ? parseJSON$3(row.requestContext) : void 0,
|
|
1990
1993
|
metadata: row.metadata ? parseJSON$3(row.metadata) : void 0,
|
|
1991
1994
|
source: row.source ? parseJSON$3(row.source) : void 0,
|
|
@@ -2267,7 +2270,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2267
2270
|
const newVersion = parentRow?.version;
|
|
2268
2271
|
const parentOrganizationId = parentRow?.organizationId ?? null;
|
|
2269
2272
|
const parentProjectId = parentRow?.projectId ?? null;
|
|
2270
|
-
await connection.execute(`INSERT INTO ${tableItemsName} (\`id
|
|
2273
|
+
await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`,\`datasetId\`,\`datasetVersion\`,\`organizationId\`,\`projectId\`,\`validTo\`,\`isDeleted\`,\`input\`,\`groundTruth\`,\`unmockedToolPolicy\`,\`scorerIds\`,\`metadata\`,\`createdAt\`,\`updatedAt\`) VALUES (?,?,?,?,?,NULL,0,?,?,?,?,?,?,?)`, [
|
|
2271
2274
|
id,
|
|
2272
2275
|
args.datasetId,
|
|
2273
2276
|
newVersion,
|
|
@@ -2276,6 +2279,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2276
2279
|
jsonArg(args.input),
|
|
2277
2280
|
jsonArg(args.groundTruth),
|
|
2278
2281
|
args.unmockedToolPolicy ?? null,
|
|
2282
|
+
jsonArg(args.scorerIds),
|
|
2279
2283
|
jsonArg(args.metadata),
|
|
2280
2284
|
transformToSqlValue(now),
|
|
2281
2285
|
transformToSqlValue(now)
|
|
@@ -2296,6 +2300,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2296
2300
|
input: args.input,
|
|
2297
2301
|
groundTruth: args.groundTruth,
|
|
2298
2302
|
unmockedToolPolicy: args.unmockedToolPolicy,
|
|
2303
|
+
scorerIds: args.scorerIds,
|
|
2299
2304
|
metadata: args.metadata,
|
|
2300
2305
|
createdAt: now,
|
|
2301
2306
|
updatedAt: now
|
|
@@ -2344,6 +2349,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2344
2349
|
const mergedExpectedTrajectory = args.expectedTrajectory ?? existing.expectedTrajectory;
|
|
2345
2350
|
const mergedToolMocks = args.toolMocks ?? existing.toolMocks;
|
|
2346
2351
|
const mergedUnmockedToolPolicy = args.unmockedToolPolicy ?? existing.unmockedToolPolicy;
|
|
2352
|
+
const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
|
|
2347
2353
|
const mergedRequestContext = args.requestContext ?? existing.requestContext;
|
|
2348
2354
|
const mergedMetadata = args.metadata ?? existing.metadata;
|
|
2349
2355
|
const mergedSource = args.source ?? existing.source;
|
|
@@ -2354,7 +2360,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2354
2360
|
const parentOrganizationId = parentRow?.organizationId ?? null;
|
|
2355
2361
|
const parentProjectId = parentRow?.projectId ?? null;
|
|
2356
2362
|
await connection.execute(`UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [newVersion, args.id]);
|
|
2357
|
-
await connection.execute(`INSERT INTO ${tableItemsName} (\`id
|
|
2363
|
+
await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`,\`datasetId\`,\`datasetVersion\`,\`externalId\`,\`organizationId\`,\`projectId\`,\`validTo\`,\`isDeleted\`,\`input\`,\`groundTruth\`,\`expectedTrajectory\`,\`toolMocks\`,\`unmockedToolPolicy\`,\`scorerIds\`,\`requestContext\`,\`metadata\`,\`source\`,\`createdAt\`,\`updatedAt\`) VALUES (?,?,?,?,?,?,NULL,0,?,?,?,?,?,?,?,?,?,?,?)`, [
|
|
2358
2364
|
args.id,
|
|
2359
2365
|
args.datasetId,
|
|
2360
2366
|
newVersion,
|
|
@@ -2366,6 +2372,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2366
2372
|
jsonArg(mergedExpectedTrajectory),
|
|
2367
2373
|
jsonArg(mergedToolMocks),
|
|
2368
2374
|
mergedUnmockedToolPolicy ?? null,
|
|
2375
|
+
jsonArg(mergedScorerIds),
|
|
2369
2376
|
jsonArg(mergedRequestContext),
|
|
2370
2377
|
jsonArg(mergedMetadata),
|
|
2371
2378
|
jsonArg(mergedSource),
|
|
@@ -2389,6 +2396,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2389
2396
|
expectedTrajectory: mergedExpectedTrajectory,
|
|
2390
2397
|
toolMocks: mergedToolMocks,
|
|
2391
2398
|
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
2399
|
+
scorerIds: mergedScorerIds,
|
|
2392
2400
|
requestContext: mergedRequestContext,
|
|
2393
2401
|
metadata: mergedMetadata,
|
|
2394
2402
|
source: mergedSource,
|
|
@@ -2434,7 +2442,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2434
2442
|
const parentOrganizationId = parentRow?.organizationId ?? null;
|
|
2435
2443
|
const parentProjectId = parentRow?.projectId ?? null;
|
|
2436
2444
|
await connection.execute(`UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [newVersion, id]);
|
|
2437
|
-
await connection.execute(`INSERT INTO ${tableItemsName} (\`id
|
|
2445
|
+
await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`,\`datasetId\`,\`datasetVersion\`,\`externalId\`,\`organizationId\`,\`projectId\`,\`validTo\`,\`isDeleted\`,\`input\`,\`groundTruth\`,\`expectedTrajectory\`,\`toolMocks\`,\`unmockedToolPolicy\`,\`scorerIds\`,\`requestContext\`,\`metadata\`,\`source\`,\`createdAt\`,\`updatedAt\`) VALUES (?,?,?,?,?,?,NULL,1,?,?,?,?,?,?,?,?,?,?,?)`, [
|
|
2438
2446
|
id,
|
|
2439
2447
|
datasetId,
|
|
2440
2448
|
newVersion,
|
|
@@ -2446,6 +2454,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2446
2454
|
jsonArg(existing.expectedTrajectory),
|
|
2447
2455
|
jsonArg(existing.toolMocks),
|
|
2448
2456
|
existing.unmockedToolPolicy ?? null,
|
|
2457
|
+
jsonArg(existing.scorerIds),
|
|
2449
2458
|
jsonArg(existing.requestContext),
|
|
2450
2459
|
jsonArg(existing.metadata),
|
|
2451
2460
|
jsonArg(existing.source),
|
|
@@ -2684,7 +2693,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2684
2693
|
await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = ? WHERE id = ?`, [newVersion, input.datasetId]);
|
|
2685
2694
|
const inserted = /* @__PURE__ */ new Map();
|
|
2686
2695
|
for (const { id, item } of plan.inserts) {
|
|
2687
|
-
await connection.execute(`INSERT INTO ${tableItemsName} (\`id
|
|
2696
|
+
await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`,\`datasetId\`,\`datasetVersion\`,\`externalId\`,\`organizationId\`,\`projectId\`,\`validTo\`,\`isDeleted\`,\`input\`,\`groundTruth\`,\`expectedTrajectory\`,\`toolMocks\`,\`unmockedToolPolicy\`,\`scorerIds\`,\`requestContext\`,\`metadata\`,\`source\`,\`createdAt\`,\`updatedAt\`) VALUES (?,?,?,?,?,?,NULL,0,?,?,?,?,?,?,?,?,?,?,?)`, [
|
|
2688
2697
|
id,
|
|
2689
2698
|
input.datasetId,
|
|
2690
2699
|
newVersion,
|
|
@@ -2696,6 +2705,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2696
2705
|
jsonArg(item.expectedTrajectory),
|
|
2697
2706
|
jsonArg(item.toolMocks),
|
|
2698
2707
|
item.unmockedToolPolicy ?? null,
|
|
2708
|
+
jsonArg(item.scorerIds),
|
|
2699
2709
|
jsonArg(item.requestContext),
|
|
2700
2710
|
jsonArg(item.metadata),
|
|
2701
2711
|
jsonArg(item.source),
|
|
@@ -2763,7 +2773,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2763
2773
|
const parentProjectId = dataset.projectId ?? null;
|
|
2764
2774
|
for (const item of currentItems) {
|
|
2765
2775
|
await connection.execute(`UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [newVersion, item.id]);
|
|
2766
|
-
await connection.execute(`INSERT INTO ${tableItemsName} (\`id
|
|
2776
|
+
await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`,\`datasetId\`,\`datasetVersion\`,\`externalId\`,\`organizationId\`,\`projectId\`,\`validTo\`,\`isDeleted\`,\`input\`,\`groundTruth\`,\`expectedTrajectory\`,\`toolMocks\`,\`unmockedToolPolicy\`,\`scorerIds\`,\`requestContext\`,\`metadata\`,\`source\`,\`createdAt\`,\`updatedAt\`) VALUES (?,?,?,?,?,?,NULL,1,?,?,?,?,?,?,?,?,?,?,?)`, [
|
|
2767
2777
|
item.id,
|
|
2768
2778
|
input.datasetId,
|
|
2769
2779
|
newVersion,
|
|
@@ -2775,6 +2785,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2775
2785
|
jsonArg(item.expectedTrajectory),
|
|
2776
2786
|
jsonArg(item.toolMocks),
|
|
2777
2787
|
item.unmockedToolPolicy ?? null,
|
|
2788
|
+
jsonArg(item.scorerIds),
|
|
2778
2789
|
jsonArg(item.requestContext),
|
|
2779
2790
|
jsonArg(item.metadata),
|
|
2780
2791
|
jsonArg(item.source),
|
|
@@ -9177,6 +9188,140 @@ var ToolProviderConnectionsMySQL = class ToolProviderConnectionsMySQL extends _m
|
|
|
9177
9188
|
}
|
|
9178
9189
|
};
|
|
9179
9190
|
//#endregion
|
|
9191
|
+
//#region src/storage/domains/workflow-definitions/index.ts
|
|
9192
|
+
function rowToDefinition(row) {
|
|
9193
|
+
const transformed = transformFromSqlRow({
|
|
9194
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9195
|
+
sqlRow: row
|
|
9196
|
+
});
|
|
9197
|
+
const def = {
|
|
9198
|
+
id: String(transformed.id),
|
|
9199
|
+
inputSchema: transformed.inputSchema,
|
|
9200
|
+
outputSchema: transformed.outputSchema,
|
|
9201
|
+
graph: transformed.graph,
|
|
9202
|
+
status: String(transformed.status),
|
|
9203
|
+
source: String(transformed.source),
|
|
9204
|
+
createdAt: transformed.createdAt,
|
|
9205
|
+
updatedAt: transformed.updatedAt
|
|
9206
|
+
};
|
|
9207
|
+
if (transformed.description != null) def.description = String(transformed.description);
|
|
9208
|
+
if (transformed.metadata != null) def.metadata = transformed.metadata;
|
|
9209
|
+
if (transformed.stateSchema != null) def.stateSchema = transformed.stateSchema;
|
|
9210
|
+
if (transformed.requestContextSchema != null) def.requestContextSchema = transformed.requestContextSchema;
|
|
9211
|
+
if (transformed.authorId != null) def.authorId = String(transformed.authorId);
|
|
9212
|
+
return def;
|
|
9213
|
+
}
|
|
9214
|
+
var WorkflowDefinitionsMySQL = class extends _mastra_core_storage.WorkflowDefinitionsStorage {
|
|
9215
|
+
pool;
|
|
9216
|
+
operations;
|
|
9217
|
+
database;
|
|
9218
|
+
static MANAGED_TABLES = [_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS];
|
|
9219
|
+
static getExportDDL() {
|
|
9220
|
+
return [generateTableSQL({
|
|
9221
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9222
|
+
schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA
|
|
9223
|
+
})];
|
|
9224
|
+
}
|
|
9225
|
+
constructor({ pool, operations, database }) {
|
|
9226
|
+
super();
|
|
9227
|
+
this.pool = pool;
|
|
9228
|
+
this.operations = operations;
|
|
9229
|
+
this.database = database;
|
|
9230
|
+
}
|
|
9231
|
+
async init() {
|
|
9232
|
+
await this.operations.createTable({
|
|
9233
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9234
|
+
schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA
|
|
9235
|
+
});
|
|
9236
|
+
}
|
|
9237
|
+
async dangerouslyClearAll() {
|
|
9238
|
+
await this.operations.clearTable({ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS });
|
|
9239
|
+
}
|
|
9240
|
+
async upsert(input) {
|
|
9241
|
+
const now = /* @__PURE__ */ new Date();
|
|
9242
|
+
if (!await this.get(input.id)) {
|
|
9243
|
+
if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
|
|
9244
|
+
if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
|
|
9245
|
+
if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
|
|
9246
|
+
const record = {
|
|
9247
|
+
id: input.id,
|
|
9248
|
+
description: input.description ?? null,
|
|
9249
|
+
metadata: input.metadata ?? null,
|
|
9250
|
+
inputSchema: input.inputSchema,
|
|
9251
|
+
outputSchema: input.outputSchema,
|
|
9252
|
+
stateSchema: input.stateSchema ?? null,
|
|
9253
|
+
requestContextSchema: input.requestContextSchema ?? null,
|
|
9254
|
+
graph: input.graph,
|
|
9255
|
+
status: "active",
|
|
9256
|
+
source: "storage",
|
|
9257
|
+
authorId: "authorId" in input ? input.authorId ?? null : null,
|
|
9258
|
+
createdAt: now,
|
|
9259
|
+
updatedAt: now
|
|
9260
|
+
};
|
|
9261
|
+
try {
|
|
9262
|
+
await this.operations.insertOnly({
|
|
9263
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9264
|
+
record
|
|
9265
|
+
});
|
|
9266
|
+
} catch (error) {
|
|
9267
|
+
if (!await this.get(input.id)) throw error;
|
|
9268
|
+
return this.applyUpdate(input, now);
|
|
9269
|
+
}
|
|
9270
|
+
const created = await this.get(input.id);
|
|
9271
|
+
if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
|
|
9272
|
+
return created;
|
|
9273
|
+
}
|
|
9274
|
+
return this.applyUpdate(input, now);
|
|
9275
|
+
}
|
|
9276
|
+
async applyUpdate(input, now) {
|
|
9277
|
+
const data = { updatedAt: now };
|
|
9278
|
+
if ("description" in input && input.description !== void 0) data.description = input.description;
|
|
9279
|
+
if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
|
|
9280
|
+
if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
|
|
9281
|
+
if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
|
|
9282
|
+
if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
|
|
9283
|
+
if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
|
|
9284
|
+
if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
|
|
9285
|
+
if ("status" in input && input.status !== void 0) data.status = input.status;
|
|
9286
|
+
if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
|
|
9287
|
+
await this.operations.update({
|
|
9288
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9289
|
+
keys: { id: input.id },
|
|
9290
|
+
data
|
|
9291
|
+
});
|
|
9292
|
+
const updated = await this.get(input.id);
|
|
9293
|
+
if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
|
|
9294
|
+
return updated;
|
|
9295
|
+
}
|
|
9296
|
+
async get(id) {
|
|
9297
|
+
const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
|
|
9298
|
+
if (!rows.length) return null;
|
|
9299
|
+
return rowToDefinition(rows[0]);
|
|
9300
|
+
}
|
|
9301
|
+
async list(args) {
|
|
9302
|
+
const conditions = [];
|
|
9303
|
+
const params = [];
|
|
9304
|
+
if (args?.status) {
|
|
9305
|
+
conditions.push(`${quoteIdentifier("status", "column name")} = ?`);
|
|
9306
|
+
params.push(args.status);
|
|
9307
|
+
}
|
|
9308
|
+
if (args?.authorId !== void 0) {
|
|
9309
|
+
conditions.push(`${quoteIdentifier("authorId", "column name")} = ?`);
|
|
9310
|
+
params.push(args.authorId);
|
|
9311
|
+
}
|
|
9312
|
+
const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
|
|
9313
|
+
const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)}${where} ORDER BY ${quoteIdentifier("updatedAt", "column name")} DESC`, params);
|
|
9314
|
+
const definitions = rows.map((row) => rowToDefinition(row));
|
|
9315
|
+
return {
|
|
9316
|
+
definitions,
|
|
9317
|
+
total: definitions.length
|
|
9318
|
+
};
|
|
9319
|
+
}
|
|
9320
|
+
async delete(id) {
|
|
9321
|
+
await this.pool.execute(`DELETE FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
|
|
9322
|
+
}
|
|
9323
|
+
};
|
|
9324
|
+
//#endregion
|
|
9180
9325
|
//#region src/storage/domains/workflows/index.ts
|
|
9181
9326
|
function parseSnapshot(snapshot) {
|
|
9182
9327
|
if (typeof snapshot === "string") try {
|
|
@@ -10257,6 +10402,11 @@ var MySQLStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
10257
10402
|
skipDefaultIndexes: config.skipDefaultIndexes,
|
|
10258
10403
|
indexes: config.indexes
|
|
10259
10404
|
});
|
|
10405
|
+
const workflowDefinitions = new WorkflowDefinitionsMySQL({
|
|
10406
|
+
pool: this.pool,
|
|
10407
|
+
operations,
|
|
10408
|
+
database
|
|
10409
|
+
});
|
|
10260
10410
|
this.stores = {
|
|
10261
10411
|
memory,
|
|
10262
10412
|
workflows,
|
|
@@ -10276,7 +10426,8 @@ var MySQLStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
10276
10426
|
channels,
|
|
10277
10427
|
favorites,
|
|
10278
10428
|
schedules,
|
|
10279
|
-
toolProviderConnections
|
|
10429
|
+
toolProviderConnections,
|
|
10430
|
+
workflowDefinitions
|
|
10280
10431
|
};
|
|
10281
10432
|
}
|
|
10282
10433
|
async init() {
|