@mastra/dsql 1.5.7 → 1.5.8-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/index.cjs
CHANGED
|
@@ -3906,6 +3906,33 @@ function toRunOwnershipRecord(runId, row) {
|
|
|
3906
3906
|
live: leaseExpiresAt !== null && leaseExpiresAt > Number(row.nowMs)
|
|
3907
3907
|
};
|
|
3908
3908
|
}
|
|
3909
|
+
/**
|
|
3910
|
+
* The snapshot fields a `listWorkflowRuns({ summary: true })` row carries instead of the
|
|
3911
|
+
* snapshot, so `context` is never sent. The snapshot is stored as TEXT. These columns use only the
|
|
3912
|
+
* `::jsonb` cast and `->>` that the status filter already runs on Aurora DSQL, plus `->`, and
|
|
3913
|
+
* `summarySnapshot` builds the summary from them in the app.
|
|
3914
|
+
*/
|
|
3915
|
+
const SUMMARY_COLUMNS_SQL = [
|
|
3916
|
+
`snapshot::jsonb ->> 'status' AS "summaryStatus"`,
|
|
3917
|
+
`snapshot::jsonb ->> 'timestamp' AS "summaryTimestamp"`,
|
|
3918
|
+
`snapshot::jsonb -> 'parentWorkflow' ->> 'workflowId' AS "summaryParentWorkflowId"`,
|
|
3919
|
+
`snapshot::jsonb -> 'parentWorkflow' ->> 'runId' AS "summaryParentRunId"`
|
|
3920
|
+
].join(", ");
|
|
3921
|
+
/**
|
|
3922
|
+
* The reduced snapshot of a summary row: `status` and `timestamp` when set, and `parentWorkflow`
|
|
3923
|
+
* only when both of its IDs are non-empty strings.
|
|
3924
|
+
*/
|
|
3925
|
+
function summarySnapshot(row) {
|
|
3926
|
+
const snapshot = {};
|
|
3927
|
+
if (row.summaryStatus !== null && row.summaryStatus !== void 0) snapshot.status = row.summaryStatus;
|
|
3928
|
+
if (row.summaryTimestamp !== null && row.summaryTimestamp !== void 0) snapshot.timestamp = Number(row.summaryTimestamp);
|
|
3929
|
+
const { summaryParentWorkflowId: workflowId, summaryParentRunId: runId } = row;
|
|
3930
|
+
if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") snapshot.parentWorkflow = {
|
|
3931
|
+
workflowId,
|
|
3932
|
+
runId
|
|
3933
|
+
};
|
|
3934
|
+
return snapshot;
|
|
3935
|
+
}
|
|
3909
3936
|
function parseWorkflowRun(row) {
|
|
3910
3937
|
let parsedSnapshot = row.snapshot;
|
|
3911
3938
|
if (typeof parsedSnapshot === "string") try {
|
|
@@ -4379,7 +4406,11 @@ var WorkflowsDSQL = class WorkflowsDSQL extends _mastra_core_storage.WorkflowsSt
|
|
|
4379
4406
|
}, error);
|
|
4380
4407
|
}
|
|
4381
4408
|
}
|
|
4382
|
-
|
|
4409
|
+
/**
|
|
4410
|
+
* Lists runs newest first, with optional filters and pagination. With `summary`, each run's
|
|
4411
|
+
* snapshot holds only `status`, `timestamp` and `parentWorkflow`.
|
|
4412
|
+
*/
|
|
4413
|
+
async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = {}) {
|
|
4383
4414
|
try {
|
|
4384
4415
|
const conditions = [];
|
|
4385
4416
|
const values = [];
|
|
@@ -4424,7 +4455,7 @@ var WorkflowsDSQL = class WorkflowsDSQL extends _mastra_core_storage.WorkflowsSt
|
|
|
4424
4455
|
const normalizedPerPage = usePagination ? (0, _mastra_core_storage.normalizePerPage)(perPage, Number.MAX_SAFE_INTEGER) : 0;
|
|
4425
4456
|
const offset = usePagination ? page * normalizedPerPage : void 0;
|
|
4426
4457
|
const query = `
|
|
4427
|
-
SELECT * FROM ${getTableName({
|
|
4458
|
+
SELECT ${summary ? `workflow_name, run_id, "resourceId", ${SUMMARY_COLUMNS_SQL}, "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"` : "*"} FROM ${getTableName({
|
|
4428
4459
|
indexName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
4429
4460
|
schemaName: getSchemaName(this.#schema)
|
|
4430
4461
|
})}
|
|
@@ -4438,7 +4469,10 @@ var WorkflowsDSQL = class WorkflowsDSQL extends _mastra_core_storage.WorkflowsSt
|
|
|
4438
4469
|
offset
|
|
4439
4470
|
] : values;
|
|
4440
4471
|
const runs = (await this.#db.client.manyOrNone(query, queryValues) || []).map((row) => {
|
|
4441
|
-
return
|
|
4472
|
+
return summary ? {
|
|
4473
|
+
...parseWorkflowRun(row),
|
|
4474
|
+
snapshot: summarySnapshot(row)
|
|
4475
|
+
} : parseWorkflowRun(row);
|
|
4442
4476
|
});
|
|
4443
4477
|
return {
|
|
4444
4478
|
runs,
|