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