@mastra/oracledb 0.5.6 → 0.5.7-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
@@ -8603,7 +8603,11 @@ var WorkflowsOracle = class WorkflowsOracle extends WorkflowsStorage {
8603
8603
  }, error);
8604
8604
  }
8605
8605
  }
8606
- async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status } = {}) {
8606
+ /**
8607
+ * Lists runs newest first, with optional filters and pagination. With `summary`, each run's
8608
+ * snapshot holds only `status`, `timestamp` and `parentWorkflow`.
8609
+ */
8610
+ async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = {}) {
8607
8611
  try {
8608
8612
  const { whereClause, binds } = this.workflowWhereClause({
8609
8613
  workflowName,
@@ -8616,7 +8620,7 @@ var WorkflowsOracle = class WorkflowsOracle extends WorkflowsStorage {
8616
8620
  const normalizedPerPage = usePagination ? normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
8617
8621
  const offset = usePagination ? page * normalizedPerPage : 0;
8618
8622
  const count = usePagination ? Number((await this.db.one(`SELECT COUNT(*) AS "count" FROM ${this.table()} ${whereClause}`, binds)).count ?? 0) : 0;
8619
- const runs = (await this.db.manyOrNone(`${this.workflowSelect()} FROM ${this.table()} ${whereClause} ORDER BY ${WORKFLOW_CREATED_AT} DESC ${usePagination ? "OFFSET :offset ROWS FETCH NEXT :limit ROWS ONLY" : ""}`, usePagination ? {
8623
+ const runs = (await this.db.manyOrNone(`${summary ? this.workflowSummarySelect() : this.workflowSelect()} FROM ${this.table()} ${whereClause} ORDER BY ${WORKFLOW_CREATED_AT} DESC ${usePagination ? "OFFSET :offset ROWS FETCH NEXT :limit ROWS ONLY" : ""}`, usePagination ? {
8620
8624
  ...binds,
8621
8625
  offset,
8622
8626
  limit: normalizedPerPage
@@ -8800,12 +8804,25 @@ var WorkflowsOracle = class WorkflowsOracle extends WorkflowsStorage {
8800
8804
  workflowSelect() {
8801
8805
  return `SELECT workflow_name AS "workflowName", run_id AS "runId", ${WORKFLOW_RESOURCE_ID} AS "resourceId", snapshot AS "snapshot", ${WORKFLOW_CREATED_AT} AS "createdAt", ${WORKFLOW_UPDATED_AT} AS "updatedAt"`;
8802
8806
  }
8807
+ /**
8808
+ * Selects only the snapshot fields a summary listing returns, so the snapshot itself is never
8809
+ * sent. `NULL ON ERROR` keeps a row whose snapshot isn't valid JSON from failing the listing.
8810
+ */
8811
+ workflowSummarySelect() {
8812
+ return `SELECT workflow_name AS "workflowName", run_id AS "runId", ${WORKFLOW_RESOURCE_ID} AS "resourceId",
8813
+ JSON_VALUE(snapshot, '$.status' RETURNING VARCHAR2(64) NULL ON ERROR) AS "status",
8814
+ JSON_VALUE(snapshot, '$.timestamp' RETURNING NUMBER NULL ON ERROR) AS "timestamp",
8815
+ JSON_VALUE(snapshot, '$.parentWorkflow.workflowId' NULL ON ERROR) AS "parentWorkflowId",
8816
+ JSON_VALUE(snapshot, '$.parentWorkflow.runId' NULL ON ERROR) AS "parentRunId",
8817
+ ${WORKFLOW_CREATED_AT} AS "createdAt", ${WORKFLOW_UPDATED_AT} AS "updatedAt"`;
8818
+ }
8819
+ /** Maps a full row, or a summary row from `workflowSummarySelect()`, to a workflow run. */
8803
8820
  parseWorkflowRun(row) {
8804
8821
  return {
8805
8822
  workflowName: String(row.workflowName),
8806
8823
  runId: String(row.runId),
8807
8824
  resourceId: row.resourceId === null || row.resourceId === void 0 ? void 0 : String(row.resourceId),
8808
- snapshot: parseSnapshot(row.snapshot),
8825
+ snapshot: "snapshot" in row ? parseSnapshot(row.snapshot) : summarySnapshot(row),
8809
8826
  createdAt: toDate(row.createdAt),
8810
8827
  updatedAt: toDate(row.updatedAt)
8811
8828
  };
@@ -8849,6 +8866,21 @@ function createDefaultSnapshot(runId) {
8849
8866
  requestContext: {}
8850
8867
  };
8851
8868
  }
8869
+ /**
8870
+ * The reduced snapshot of a summary row from `workflowSummarySelect()`: `status` and `timestamp`
8871
+ * when set, and `parentWorkflow` only when both of its IDs are non-empty strings.
8872
+ */
8873
+ function summarySnapshot(row) {
8874
+ const snapshot = {};
8875
+ if (row.status !== null && row.status !== void 0) snapshot.status = row.status;
8876
+ if (row.timestamp !== null && row.timestamp !== void 0) snapshot.timestamp = Number(row.timestamp);
8877
+ const { parentWorkflowId: workflowId, parentRunId: runId } = row;
8878
+ if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") snapshot.parentWorkflow = {
8879
+ workflowId,
8880
+ runId
8881
+ };
8882
+ return snapshot;
8883
+ }
8852
8884
  function parseSnapshot(value) {
8853
8885
  if (typeof value === "string") return JSON.parse(value);
8854
8886
  if (Buffer.isBuffer(value)) return JSON.parse(value.toString("utf8"));