@mastra/mysql 0.17.0-alpha.0 → 0.17.1-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 +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +4 -4
- package/dist/index.cjs +49 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +8 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -12370,6 +12370,8 @@ const OWNER_ID = quoteIdentifier("ownerId", "column name");
|
|
|
12370
12370
|
const LEASE_EXPIRES_AT = quoteIdentifier("leaseExpiresAt", "column name");
|
|
12371
12371
|
const UPDATED_AT = quoteIdentifier("updatedAt", "column name");
|
|
12372
12372
|
const RUN_OWNER_COLUMNS = `generation, ${OWNER_ID} AS ownerId, ${LEASE_EXPIRES_AT} AS leaseExpiresAt, ${DB_NOW_MS} AS nowMs`;
|
|
12373
|
+
/** Run ids per query in `getRunOwnerships`, keeping each prepared statement small. */
|
|
12374
|
+
const RUN_OWNERSHIP_BATCH_SIZE = 500;
|
|
12373
12375
|
function toRunOwnershipRecord(runId, row) {
|
|
12374
12376
|
const leaseExpiresAt = row.leaseExpiresAt === null ? null : Number(row.leaseExpiresAt);
|
|
12375
12377
|
return {
|
|
@@ -12384,6 +12386,21 @@ async function readRunOwner(q, runId) {
|
|
|
12384
12386
|
const [rows] = await q.execute(`SELECT ${RUN_OWNER_COLUMNS} FROM ${RUN_OWNERS_TABLE} WHERE ${RUN_ID} = ?`, [runId]);
|
|
12385
12387
|
return rows[0] ? toRunOwnershipRecord(runId, rows[0]) : null;
|
|
12386
12388
|
}
|
|
12389
|
+
const SUMMARY_WORKFLOW_ID_SQL = `JSON_EXTRACT(snapshot, '$.parentWorkflow.workflowId')`;
|
|
12390
|
+
const SUMMARY_RUN_ID_SQL = `JSON_EXTRACT(snapshot, '$.parentWorkflow.runId')`;
|
|
12391
|
+
/**
|
|
12392
|
+
* The summary snapshot `listWorkflowRuns({ summary: true })` returns: `status` and `timestamp`
|
|
12393
|
+
* when set, and `parentWorkflow` with only its `workflowId` and `runId` when both are non-empty
|
|
12394
|
+
* strings. Only these paths are read, so `context` is never sent. JSON_OBJECT() keeps a SQL NULL
|
|
12395
|
+
* as a JSON null, and merge-patching `{}` with it drops those keys. The snapshot column is JSON,
|
|
12396
|
+
* stored parsed, so each JSON_EXTRACT reads it without parsing it again.
|
|
12397
|
+
*/
|
|
12398
|
+
const SUMMARY_SNAPSHOT_SQL = `JSON_MERGE_PATCH('{}', JSON_OBJECT(
|
|
12399
|
+
'status', JSON_EXTRACT(snapshot, '$.status'),
|
|
12400
|
+
'timestamp', JSON_EXTRACT(snapshot, '$.timestamp'),
|
|
12401
|
+
'parentWorkflow', CASE WHEN JSON_TYPE(${SUMMARY_WORKFLOW_ID_SQL}) = 'STRING' AND JSON_TYPE(${SUMMARY_RUN_ID_SQL}) = 'STRING'
|
|
12402
|
+
AND JSON_UNQUOTE(${SUMMARY_WORKFLOW_ID_SQL}) <> '' AND JSON_UNQUOTE(${SUMMARY_RUN_ID_SQL}) <> ''
|
|
12403
|
+
THEN JSON_OBJECT('workflowId', ${SUMMARY_WORKFLOW_ID_SQL}, 'runId', ${SUMMARY_RUN_ID_SQL}) END))`;
|
|
12387
12404
|
function mapWorkflowRow(row) {
|
|
12388
12405
|
return {
|
|
12389
12406
|
workflowName: row.workflow_name,
|
|
@@ -12609,6 +12626,31 @@ var WorkflowsMySQL = class WorkflowsMySQL extends WorkflowsStorage {
|
|
|
12609
12626
|
throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
|
|
12610
12627
|
}
|
|
12611
12628
|
}
|
|
12629
|
+
/** Reads the records with one query per {@link RUN_OWNERSHIP_BATCH_SIZE} runs. */
|
|
12630
|
+
async getRunOwnerships({ runIds }) {
|
|
12631
|
+
const records = /* @__PURE__ */ new Map();
|
|
12632
|
+
const ids = [...new Set(runIds)];
|
|
12633
|
+
try {
|
|
12634
|
+
for (let start = 0; start < ids.length; start += RUN_OWNERSHIP_BATCH_SIZE) {
|
|
12635
|
+
const chunk = ids.slice(start, start + RUN_OWNERSHIP_BATCH_SIZE);
|
|
12636
|
+
const requested = chunk.map((_, i) => i === 0 ? "SELECT ? AS reqId" : "SELECT ?").join(" UNION ALL ");
|
|
12637
|
+
const [rows] = await this.pool.execute(`SELECT j.reqId, ${RUN_OWNER_COLUMNS} FROM (${requested}) j
|
|
12638
|
+
JOIN ${RUN_OWNERS_TABLE} o ON o.${RUN_ID} = j.reqId`, chunk);
|
|
12639
|
+
for (const row of rows) {
|
|
12640
|
+
const runId = String(row.reqId);
|
|
12641
|
+
records.set(runId, toRunOwnershipRecord(runId, row));
|
|
12642
|
+
}
|
|
12643
|
+
}
|
|
12644
|
+
return records;
|
|
12645
|
+
} catch (error) {
|
|
12646
|
+
throw new MastraError({
|
|
12647
|
+
id: createStorageErrorId("MYSQL", "GET_RUN_OWNERSHIPS", "FAILED"),
|
|
12648
|
+
domain: ErrorDomain.STORAGE,
|
|
12649
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
12650
|
+
details: { runCount: ids.length }
|
|
12651
|
+
}, error);
|
|
12652
|
+
}
|
|
12653
|
+
}
|
|
12612
12654
|
async deleteWorkflowRunById({ runId, workflowName, fence }) {
|
|
12613
12655
|
try {
|
|
12614
12656
|
await withRunFence(this.pool, RUN_OWNERS_TABLE, resolveRunFence(this, fence, runId), "deleteWorkflowRunById", (q) => q.execute(`DELETE FROM ${formatTableName(TABLE_WORKFLOW_SNAPSHOT)} WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} = ?`, [workflowName, runId]));
|
|
@@ -12828,8 +12870,12 @@ var WorkflowsMySQL = class WorkflowsMySQL extends WorkflowsStorage {
|
|
|
12828
12870
|
}, error);
|
|
12829
12871
|
}
|
|
12830
12872
|
}
|
|
12873
|
+
/**
|
|
12874
|
+
* Lists runs newest first, with optional filters and pagination. With `summary`, each run's
|
|
12875
|
+
* snapshot holds only `status`, `timestamp` and `parentWorkflow`.
|
|
12876
|
+
*/
|
|
12831
12877
|
async listWorkflowRuns(args = {}) {
|
|
12832
|
-
const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
|
|
12878
|
+
const { workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = args;
|
|
12833
12879
|
const conditions = [];
|
|
12834
12880
|
const params = [];
|
|
12835
12881
|
if (workflowName) {
|
|
@@ -12871,7 +12917,8 @@ var WorkflowsMySQL = class WorkflowsMySQL extends WorkflowsStorage {
|
|
|
12871
12917
|
const offset = page * normalizedPerPage;
|
|
12872
12918
|
paginationClause = ` LIMIT ${Number(normalizedPerPage)} OFFSET ${Number(offset)}`;
|
|
12873
12919
|
}
|
|
12874
|
-
const
|
|
12920
|
+
const snapshot = summary ? `${SUMMARY_SNAPSHOT_SQL} AS snapshot` : "snapshot";
|
|
12921
|
+
const [rows] = await this.pool.execute(`SELECT workflow_name, run_id, resourceId, ${snapshot}, createdAt, updatedAt FROM ${tableName}${whereSql} ORDER BY ${quoteIdentifier("createdAt", "column name")} DESC${paginationClause}`, params);
|
|
12875
12922
|
const runs = rows.map(mapWorkflowRow);
|
|
12876
12923
|
return {
|
|
12877
12924
|
runs,
|