@mastra/spanner 1.12.0 → 1.12.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/index.js CHANGED
@@ -12566,6 +12566,37 @@ const RUN_ID = quoteIdent("runId", "column name");
12566
12566
  const OWNER_ID = quoteIdent("ownerId", "column name");
12567
12567
  const LEASE_EXPIRES_AT = quoteIdent("leaseExpiresAt", "column name");
12568
12568
  const UPDATED_AT = quoteIdent("updatedAt", "column name");
12569
+ const SNAPSHOT = quoteIdent("snapshot", "column name");
12570
+ /**
12571
+ * Columns of a `listWorkflowRuns({ summary: true })` row: the snapshot fields a summary returns
12572
+ * are read in SQL, so the snapshot itself is never sent.
12573
+ */
12574
+ const WORKFLOW_SUMMARY_COLUMNS = [
12575
+ quoteIdent("workflow_name", "column name"),
12576
+ quoteIdent("run_id", "column name"),
12577
+ quoteIdent("resourceId", "column name"),
12578
+ quoteIdent("createdAt", "column name"),
12579
+ quoteIdent("updatedAt", "column name"),
12580
+ `JSON_VALUE(${SNAPSHOT}, '$.status') AS summaryStatus`,
12581
+ `JSON_VALUE(${SNAPSHOT}, '$.timestamp') AS summaryTimestamp`,
12582
+ `JSON_VALUE(${SNAPSHOT}, '$.parentWorkflow.workflowId') AS summaryParentWorkflowId`,
12583
+ `JSON_VALUE(${SNAPSHOT}, '$.parentWorkflow.runId') AS summaryParentRunId`
12584
+ ].join(", ");
12585
+ /**
12586
+ * The reduced snapshot of a summary row: `status` and `timestamp` when set, and `parentWorkflow`
12587
+ * only when both of its IDs are non-empty strings.
12588
+ */
12589
+ function summarySnapshot(row) {
12590
+ const snapshot = {};
12591
+ if (row.summaryStatus !== null && row.summaryStatus !== void 0) snapshot.status = row.summaryStatus;
12592
+ if (row.summaryTimestamp !== null && row.summaryTimestamp !== void 0) snapshot.timestamp = Number(row.summaryTimestamp);
12593
+ const { summaryParentWorkflowId: workflowId, summaryParentRunId: runId } = row;
12594
+ if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") snapshot.parentWorkflow = {
12595
+ workflowId,
12596
+ runId
12597
+ };
12598
+ return snapshot;
12599
+ }
12569
12600
  /** Reads a run's ownership record, judging the lease against the database clock. */
12570
12601
  async function readRunOwner(q, runId) {
12571
12602
  const [rows] = await q.run({
@@ -12872,13 +12903,16 @@ var WorkflowsSpanner = class WorkflowsSpanner extends WorkflowsStorage {
12872
12903
  throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
12873
12904
  }
12874
12905
  }
12875
- /** Decodes a raw Spanner snapshot row into the public `WorkflowRun` shape. */
12876
- parseWorkflowRun(row) {
12906
+ /**
12907
+ * Decodes a raw Spanner snapshot row into the public `WorkflowRun` shape. With `summary`, the
12908
+ * row has the `WORKFLOW_SUMMARY_COLUMNS` columns instead of the snapshot.
12909
+ */
12910
+ parseWorkflowRun(row, { summary } = {}) {
12877
12911
  const transformed = transformFromSpannerRow({
12878
12912
  tableName: TABLE_WORKFLOW_SNAPSHOT,
12879
12913
  row
12880
12914
  });
12881
- let snapshot = transformed.snapshot;
12915
+ let snapshot = summary ? summarySnapshot(transformed) : transformed.snapshot;
12882
12916
  if (typeof snapshot === "string") try {
12883
12917
  snapshot = JSON.parse(snapshot);
12884
12918
  } catch (e) {
@@ -13195,8 +13229,11 @@ var WorkflowsSpanner = class WorkflowsSpanner extends WorkflowsStorage {
13195
13229
  }, error);
13196
13230
  }
13197
13231
  }
13198
- /** Paginated listing with optional workflowName, status, resourceId, and date-range filters. */
13199
- async listWorkflowRuns({ workflowName, fromDate, toDate, page, perPage, resourceId, status } = {}) {
13232
+ /**
13233
+ * Paginated listing with optional workflowName, status, resourceId, and date-range filters.
13234
+ * With `summary`, each run's snapshot holds only `status`, `timestamp` and `parentWorkflow`.
13235
+ */
13236
+ async listWorkflowRuns({ workflowName, fromDate, toDate, page, perPage, resourceId, status, summary } = {}) {
13200
13237
  try {
13201
13238
  const conditions = [];
13202
13239
  const params = {};
@@ -13237,7 +13274,7 @@ var WorkflowsSpanner = class WorkflowsSpanner extends WorkflowsStorage {
13237
13274
  });
13238
13275
  total = Number(countRows[0]?.count ?? 0);
13239
13276
  }
13240
- let sql = `SELECT * FROM ${tableName} ${whereSql} ORDER BY ${quoteIdent("createdAt", "column name")} DESC, ${quoteIdent("run_id", "column name")} DESC`;
13277
+ let sql = `SELECT ${summary ? WORKFLOW_SUMMARY_COLUMNS : "*"} FROM ${tableName} ${whereSql} ORDER BY ${quoteIdent("createdAt", "column name")} DESC, ${quoteIdent("run_id", "column name")} DESC`;
13241
13278
  if (usePagination) {
13242
13279
  const normalized = normalizePerPage(perPage, Number.MAX_SAFE_INTEGER);
13243
13280
  const offset = page * normalized;
@@ -13251,7 +13288,7 @@ var WorkflowsSpanner = class WorkflowsSpanner extends WorkflowsStorage {
13251
13288
  types,
13252
13289
  json: true
13253
13290
  });
13254
- const runs = rows.map((r) => this.parseWorkflowRun(r));
13291
+ const runs = rows.map((r) => this.parseWorkflowRun(r, { summary }));
13255
13292
  return {
13256
13293
  runs,
13257
13294
  total: total || runs.length