@mastra/pg 1.27.2-alpha.1 → 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.
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.27.2-alpha.1"
6
+ version: "1.28.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.27.2-alpha.1",
2
+ "version": "1.28.0-alpha.2",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -5048,6 +5048,7 @@ function rowToTask(row) {
5048
5048
  const startedAt = row.startedAtZ || row.startedAt;
5049
5049
  const suspendedAt = row.suspendedAtZ || row.suspendedAt;
5050
5050
  const completedAt = row.completedAtZ || row.completedAt;
5051
+ const leaseExpiresAt = row.leaseExpiresAtZ || row.leaseExpiresAt;
5051
5052
  return {
5052
5053
  id: row.id,
5053
5054
  status: row.status,
@@ -5067,7 +5068,9 @@ function rowToTask(row) {
5067
5068
  createdAt: createdAt instanceof Date ? createdAt : new Date(createdAt),
5068
5069
  startedAt: startedAt ? startedAt instanceof Date ? startedAt : new Date(startedAt) : void 0,
5069
5070
  suspendedAt: suspendedAt ? suspendedAt instanceof Date ? suspendedAt : new Date(suspendedAt) : void 0,
5070
- completedAt: completedAt ? completedAt instanceof Date ? completedAt : new Date(completedAt) : void 0
5071
+ completedAt: completedAt ? completedAt instanceof Date ? completedAt : new Date(completedAt) : void 0,
5072
+ ownerId: row.ownerId ?? void 0,
5073
+ leaseExpiresAt: leaseExpiresAt ? leaseExpiresAt instanceof Date ? leaseExpiresAt : new Date(leaseExpiresAt) : void 0
5071
5074
  };
5072
5075
  }
5073
5076
  var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.BackgroundTasksStorage {
@@ -5107,7 +5110,12 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5107
5110
  await this.#db.alterTable({
5108
5111
  tableName: _mastra_core_storage.TABLE_BACKGROUND_TASKS,
5109
5112
  schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_BACKGROUND_TASKS],
5110
- ifNotExists: ["suspend_payload", "suspendedAt"]
5113
+ ifNotExists: [
5114
+ "suspend_payload",
5115
+ "suspendedAt",
5116
+ "ownerId",
5117
+ "leaseExpiresAt"
5118
+ ]
5111
5119
  });
5112
5120
  await this.createDefaultIndexes();
5113
5121
  await this.createCustomIndexes();
@@ -5237,7 +5245,10 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5237
5245
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
5238
5246
  suspendedAtZ: task.suspendedAt?.toISOString() ?? null,
5239
5247
  completedAt: task.completedAt?.toISOString() ?? null,
5240
- completedAtZ: task.completedAt?.toISOString() ?? null
5248
+ completedAtZ: task.completedAt?.toISOString() ?? null,
5249
+ ownerId: task.ownerId ?? null,
5250
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
5251
+ leaseExpiresAtZ: task.leaseExpiresAt?.toISOString() ?? null
5241
5252
  }
5242
5253
  });
5243
5254
  }
@@ -5283,14 +5294,34 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5283
5294
  const val = update.completedAt?.toISOString() ?? null;
5284
5295
  params.push(val, val);
5285
5296
  }
5297
+ if ("ownerId" in update) {
5298
+ setClauses.push(`"ownerId" = $${paramIdx++}`);
5299
+ params.push(update.ownerId ?? null);
5300
+ }
5301
+ if ("leaseExpiresAt" in update) {
5302
+ setClauses.push(`"leaseExpiresAt" = $${paramIdx++}`);
5303
+ setClauses.push(`"leaseExpiresAtZ" = $${paramIdx++}`);
5304
+ const val = update.leaseExpiresAt?.toISOString() ?? null;
5305
+ params.push(val, val);
5306
+ }
5286
5307
  if (setClauses.length === 0) return false;
5287
5308
  const table = getTableName$4(getSchemaName$4(this.#schema));
5288
5309
  params.push(taskId);
5289
5310
  let where = `"id" = $${paramIdx++}`;
5290
5311
  if (options?.expectedStatus) {
5291
- where += ` AND "status" = $${paramIdx}`;
5312
+ where += ` AND "status" = $${paramIdx++}`;
5292
5313
  params.push(options.expectedStatus);
5293
5314
  }
5315
+ if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
5316
+ else {
5317
+ where += ` AND "ownerId" = $${paramIdx++}`;
5318
+ params.push(options.expectedOwnerId);
5319
+ }
5320
+ if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
5321
+ else {
5322
+ where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
5323
+ params.push(options.expectedLeaseExpiresAt.toISOString());
5324
+ }
5294
5325
  return ((await this.#db.client.query(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE ${where}`, params)).rowCount ?? 0) > 0;
5295
5326
  }
5296
5327
  async getTask(taskId) {