@mastra/pg 1.27.2-alpha.0 → 1.28.0-alpha.2

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
@@ -5024,6 +5024,7 @@ function rowToTask(row) {
5024
5024
  const startedAt = row.startedAtZ || row.startedAt;
5025
5025
  const suspendedAt = row.suspendedAtZ || row.suspendedAt;
5026
5026
  const completedAt = row.completedAtZ || row.completedAt;
5027
+ const leaseExpiresAt = row.leaseExpiresAtZ || row.leaseExpiresAt;
5027
5028
  return {
5028
5029
  id: row.id,
5029
5030
  status: row.status,
@@ -5043,7 +5044,9 @@ function rowToTask(row) {
5043
5044
  createdAt: createdAt instanceof Date ? createdAt : new Date(createdAt),
5044
5045
  startedAt: startedAt ? startedAt instanceof Date ? startedAt : new Date(startedAt) : void 0,
5045
5046
  suspendedAt: suspendedAt ? suspendedAt instanceof Date ? suspendedAt : new Date(suspendedAt) : void 0,
5046
- completedAt: completedAt ? completedAt instanceof Date ? completedAt : new Date(completedAt) : void 0
5047
+ completedAt: completedAt ? completedAt instanceof Date ? completedAt : new Date(completedAt) : void 0,
5048
+ ownerId: row.ownerId ?? void 0,
5049
+ leaseExpiresAt: leaseExpiresAt ? leaseExpiresAt instanceof Date ? leaseExpiresAt : new Date(leaseExpiresAt) : void 0
5047
5050
  };
5048
5051
  }
5049
5052
  var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
@@ -5083,7 +5086,12 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
5083
5086
  await this.#db.alterTable({
5084
5087
  tableName: TABLE_BACKGROUND_TASKS,
5085
5088
  schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
5086
- ifNotExists: ["suspend_payload", "suspendedAt"]
5089
+ ifNotExists: [
5090
+ "suspend_payload",
5091
+ "suspendedAt",
5092
+ "ownerId",
5093
+ "leaseExpiresAt"
5094
+ ]
5087
5095
  });
5088
5096
  await this.createDefaultIndexes();
5089
5097
  await this.createCustomIndexes();
@@ -5213,7 +5221,10 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
5213
5221
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
5214
5222
  suspendedAtZ: task.suspendedAt?.toISOString() ?? null,
5215
5223
  completedAt: task.completedAt?.toISOString() ?? null,
5216
- completedAtZ: task.completedAt?.toISOString() ?? null
5224
+ completedAtZ: task.completedAt?.toISOString() ?? null,
5225
+ ownerId: task.ownerId ?? null,
5226
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
5227
+ leaseExpiresAtZ: task.leaseExpiresAt?.toISOString() ?? null
5217
5228
  }
5218
5229
  });
5219
5230
  }
@@ -5259,14 +5270,34 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
5259
5270
  const val = update.completedAt?.toISOString() ?? null;
5260
5271
  params.push(val, val);
5261
5272
  }
5273
+ if ("ownerId" in update) {
5274
+ setClauses.push(`"ownerId" = $${paramIdx++}`);
5275
+ params.push(update.ownerId ?? null);
5276
+ }
5277
+ if ("leaseExpiresAt" in update) {
5278
+ setClauses.push(`"leaseExpiresAt" = $${paramIdx++}`);
5279
+ setClauses.push(`"leaseExpiresAtZ" = $${paramIdx++}`);
5280
+ const val = update.leaseExpiresAt?.toISOString() ?? null;
5281
+ params.push(val, val);
5282
+ }
5262
5283
  if (setClauses.length === 0) return false;
5263
5284
  const table = getTableName$4(getSchemaName$4(this.#schema));
5264
5285
  params.push(taskId);
5265
5286
  let where = `"id" = $${paramIdx++}`;
5266
5287
  if (options?.expectedStatus) {
5267
- where += ` AND "status" = $${paramIdx}`;
5288
+ where += ` AND "status" = $${paramIdx++}`;
5268
5289
  params.push(options.expectedStatus);
5269
5290
  }
5291
+ if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
5292
+ else {
5293
+ where += ` AND "ownerId" = $${paramIdx++}`;
5294
+ params.push(options.expectedOwnerId);
5295
+ }
5296
+ if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
5297
+ else {
5298
+ where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
5299
+ params.push(options.expectedLeaseExpiresAt.toISOString());
5300
+ }
5270
5301
  return ((await this.#db.client.query(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE ${where}`, params)).rowCount ?? 0) > 0;
5271
5302
  }
5272
5303
  async getTask(taskId) {
@@ -23007,7 +23038,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
23007
23038
  }, error);
23008
23039
  }
23009
23040
  }
23010
- async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, threadId, status } = {}) {
23041
+ async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, threadId, status, summary } = {}) {
23011
23042
  try {
23012
23043
  const conditions = [];
23013
23044
  const values = [];
@@ -23055,8 +23086,13 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
23055
23086
  }
23056
23087
  const normalizedPerPage = usePagination ? normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
23057
23088
  const offset = usePagination ? page * normalizedPerPage : void 0;
23089
+ let selectList = "*";
23090
+ if (summary) {
23091
+ const snapshotJson = await this.#db.getColumnType(TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb" ? "snapshot" : `regexp_replace(snapshot::text, '\\\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})', '', 'g')::jsonb`;
23092
+ selectList = `workflow_name, run_id, "resourceId", "createdAt", "createdAtZ", "updatedAt", "updatedAtZ", jsonb_build_object('status', ${snapshotJson} -> 'status', 'timestamp', ${snapshotJson} -> 'timestamp') AS snapshot`;
23093
+ }
23058
23094
  const query = `
23059
- SELECT * FROM ${getTableName({
23095
+ SELECT ${selectList} FROM ${getTableName({
23060
23096
  indexName: TABLE_WORKFLOW_SNAPSHOT,
23061
23097
  schemaName: getSchemaName(this.#schema)
23062
23098
  })}