@mastra/mysql 0.14.1-alpha.0 → 0.14.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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +47 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -6
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +9 -3
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -11336,6 +11336,7 @@ var WorkflowDefinitionsMySQL = class extends _mastra_core_storage.WorkflowDefini
|
|
|
11336
11336
|
}
|
|
11337
11337
|
};
|
|
11338
11338
|
// src/storage/domains/workflows/index.ts
|
|
11339
|
+
const DUPLICATE_KEY_ERROR_CODES = /* @__PURE__ */ new Set([1062, "ER_DUP_ENTRY"]);
|
|
11339
11340
|
function parseSnapshot(snapshot) {
|
|
11340
11341
|
if (typeof snapshot === "string") try {
|
|
11341
11342
|
return JSON.parse(snapshot);
|
|
@@ -11419,6 +11420,9 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
11419
11420
|
this.#skipDefaultIndexes = skipDefaultIndexes;
|
|
11420
11421
|
this.#indexes = indexes?.filter((idx) => WorkflowsMySQL.MANAGED_TABLES.includes(idx.table));
|
|
11421
11422
|
}
|
|
11423
|
+
supportsGuardedSnapshotWrites() {
|
|
11424
|
+
return true;
|
|
11425
|
+
}
|
|
11422
11426
|
supportsConcurrentUpdates() {
|
|
11423
11427
|
return true;
|
|
11424
11428
|
}
|
|
@@ -11703,25 +11707,45 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
11703
11707
|
connection.release();
|
|
11704
11708
|
}
|
|
11705
11709
|
}
|
|
11706
|
-
async persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, fence }) {
|
|
11710
|
+
async persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, fence, expectedStatus }) {
|
|
11707
11711
|
const now = /* @__PURE__ */ new Date();
|
|
11712
|
+
const expectedStatuses = expectedStatus === void 0 ? void 0 : Array.isArray(expectedStatus) ? expectedStatus : [expectedStatus];
|
|
11713
|
+
const guard = expectedStatuses === void 0 ? "" : expectedStatuses.length === 0 ? " AND FALSE" : ` AND JSON_UNQUOTE(JSON_EXTRACT(${quoteIdentifier("snapshot", "column name")}, '$.status')) IN (${expectedStatuses.map(() => "?").join(", ")})`;
|
|
11708
11714
|
const createdAtValue = createdAt ?? now;
|
|
11709
11715
|
const updatedAtValue = updatedAt ?? now;
|
|
11710
11716
|
const tableName = formatTableName(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
11711
11717
|
try {
|
|
11712
|
-
await withRunFence(this.pool, RUN_OWNERS_TABLE, (0, _mastra_core_storage.resolveRunFence)(this, fence, runId), "persistWorkflowSnapshot", async (q) => {
|
|
11713
|
-
const
|
|
11718
|
+
return await withRunFence(this.pool, RUN_OWNERS_TABLE, (0, _mastra_core_storage.resolveRunFence)(this, fence, runId), "persistWorkflowSnapshot", async (q) => {
|
|
11719
|
+
const update = () => q.execute(`UPDATE ${tableName}
|
|
11714
11720
|
SET ${quoteIdentifier("resourceId", "column name")} = ?,
|
|
11715
11721
|
${quoteIdentifier("snapshot", "column name")} = ?,
|
|
11716
11722
|
${quoteIdentifier("updatedAt", "column name")} = ?
|
|
11717
|
-
WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} =
|
|
11723
|
+
WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} = ?${guard}`, [
|
|
11718
11724
|
resourceId ?? null,
|
|
11719
11725
|
JSON.stringify(snapshot),
|
|
11720
11726
|
transformToSqlValue(updatedAtValue),
|
|
11721
11727
|
workflowName,
|
|
11722
|
-
runId
|
|
11728
|
+
runId,
|
|
11729
|
+
...expectedStatuses ?? []
|
|
11723
11730
|
]);
|
|
11724
|
-
|
|
11731
|
+
const [updateResult] = await update();
|
|
11732
|
+
if (updateResult.affectedRows > 0) return true;
|
|
11733
|
+
if (expectedStatuses !== void 0) try {
|
|
11734
|
+
await q.execute(`INSERT INTO ${tableName} (${quoteIdentifier("workflow_name", "column name")}, ${quoteIdentifier("run_id", "column name")}, ${quoteIdentifier("resourceId", "column name")}, ${quoteIdentifier("snapshot", "column name")}, ${quoteIdentifier("createdAt", "column name")}, ${quoteIdentifier("updatedAt", "column name")})
|
|
11735
|
+
VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
11736
|
+
workflowName,
|
|
11737
|
+
runId,
|
|
11738
|
+
resourceId ?? null,
|
|
11739
|
+
JSON.stringify(snapshot),
|
|
11740
|
+
transformToSqlValue(createdAtValue),
|
|
11741
|
+
transformToSqlValue(updatedAtValue)
|
|
11742
|
+
]);
|
|
11743
|
+
return true;
|
|
11744
|
+
} catch (error) {
|
|
11745
|
+
if (!(0, _mastra_core_storage.hasErrorCode)(error, DUPLICATE_KEY_ERROR_CODES)) throw error;
|
|
11746
|
+
const [retryResult] = await update();
|
|
11747
|
+
return retryResult.affectedRows > 0;
|
|
11748
|
+
}
|
|
11725
11749
|
await q.execute(`INSERT INTO ${tableName} (${quoteIdentifier("workflow_name", "column name")}, ${quoteIdentifier("run_id", "column name")}, ${quoteIdentifier("resourceId", "column name")}, ${quoteIdentifier("snapshot", "column name")}, ${quoteIdentifier("createdAt", "column name")}, ${quoteIdentifier("updatedAt", "column name")})
|
|
11726
11750
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
11727
11751
|
ON DUPLICATE KEY UPDATE ${quoteIdentifier("resourceId", "column name")} = VALUES(${quoteIdentifier("resourceId", "column name")}), ${quoteIdentifier("snapshot", "column name")} = VALUES(${quoteIdentifier("snapshot", "column name")}), ${quoteIdentifier("updatedAt", "column name")} = VALUES(${quoteIdentifier("updatedAt", "column name")})`, [
|
|
@@ -11732,6 +11756,7 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
11732
11756
|
transformToSqlValue(createdAtValue),
|
|
11733
11757
|
transformToSqlValue(updatedAtValue)
|
|
11734
11758
|
]);
|
|
11759
|
+
return true;
|
|
11735
11760
|
});
|
|
11736
11761
|
} catch (error) {
|
|
11737
11762
|
if ((0, _mastra_core_storage.isRunFenceConflictError)(error)) throw error;
|
|
@@ -11746,6 +11771,22 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
11746
11771
|
}, error);
|
|
11747
11772
|
}
|
|
11748
11773
|
}
|
|
11774
|
+
async loadWorkflowRunStatus({ workflowName, runId }) {
|
|
11775
|
+
try {
|
|
11776
|
+
const [rows] = await this.pool.execute(`SELECT JSON_UNQUOTE(JSON_EXTRACT(${quoteIdentifier("snapshot", "column name")}, '$.status')) AS status FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT)} WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} = ? LIMIT 1`, [workflowName, runId]);
|
|
11777
|
+
return rows[0]?.status ?? null;
|
|
11778
|
+
} catch (error) {
|
|
11779
|
+
throw new _mastra_core_error.MastraError({
|
|
11780
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "LOAD_WORKFLOW_RUN_STATUS", "FAILED"),
|
|
11781
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
11782
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
11783
|
+
details: {
|
|
11784
|
+
workflowName,
|
|
11785
|
+
runId
|
|
11786
|
+
}
|
|
11787
|
+
}, error);
|
|
11788
|
+
}
|
|
11789
|
+
}
|
|
11749
11790
|
async loadWorkflowSnapshot({ workflowName, runId }) {
|
|
11750
11791
|
try {
|
|
11751
11792
|
const row = await this.operations.load({
|