@mastra/spanner 1.8.2-alpha.0 → 1.9.0-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
@@ -1859,7 +1859,9 @@ function rowToTask(row) {
1859
1859
  createdAt: transformed.createdAt instanceof Date ? transformed.createdAt : new Date(transformed.createdAt),
1860
1860
  startedAt: transformed.startedAt ? transformed.startedAt instanceof Date ? transformed.startedAt : new Date(transformed.startedAt) : void 0,
1861
1861
  suspendedAt: transformed.suspendedAt ? transformed.suspendedAt instanceof Date ? transformed.suspendedAt : new Date(transformed.suspendedAt) : void 0,
1862
- completedAt: transformed.completedAt ? transformed.completedAt instanceof Date ? transformed.completedAt : new Date(transformed.completedAt) : void 0
1862
+ completedAt: transformed.completedAt ? transformed.completedAt instanceof Date ? transformed.completedAt : new Date(transformed.completedAt) : void 0,
1863
+ ownerId: transformed.ownerId != null ? String(transformed.ownerId) : void 0,
1864
+ leaseExpiresAt: transformed.leaseExpiresAt ? transformed.leaseExpiresAt instanceof Date ? transformed.leaseExpiresAt : new Date(transformed.leaseExpiresAt) : void 0
1863
1865
  };
1864
1866
  }
1865
1867
  var BackgroundTasksSpanner = class BackgroundTasksSpanner extends BackgroundTasksStorage {
@@ -1885,6 +1887,16 @@ var BackgroundTasksSpanner = class BackgroundTasksSpanner extends BackgroundTask
1885
1887
  tableName: TABLE_BACKGROUND_TASKS,
1886
1888
  schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
1887
1889
  });
1890
+ await this.db.alterTable({
1891
+ tableName: TABLE_BACKGROUND_TASKS,
1892
+ schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
1893
+ ifNotExists: [
1894
+ "suspend_payload",
1895
+ "suspendedAt",
1896
+ "ownerId",
1897
+ "leaseExpiresAt"
1898
+ ]
1899
+ });
1888
1900
  await this.createDefaultIndexes();
1889
1901
  await this.createCustomIndexes();
1890
1902
  }
@@ -1963,7 +1975,9 @@ var BackgroundTasksSpanner = class BackgroundTasksSpanner extends BackgroundTask
1963
1975
  createdAt: task.createdAt,
1964
1976
  startedAt: task.startedAt ?? null,
1965
1977
  suspendedAt: task.suspendedAt ?? null,
1966
- completedAt: task.completedAt ?? null
1978
+ completedAt: task.completedAt ?? null,
1979
+ ownerId: task.ownerId ?? null,
1980
+ leaseExpiresAt: task.leaseExpiresAt ?? null
1967
1981
  }
1968
1982
  });
1969
1983
  }
@@ -1977,16 +1991,32 @@ var BackgroundTasksSpanner = class BackgroundTasksSpanner extends BackgroundTask
1977
1991
  if ("startedAt" in update) data.startedAt = update.startedAt ?? null;
1978
1992
  if ("suspendedAt" in update) data.suspendedAt = update.suspendedAt ?? null;
1979
1993
  if ("completedAt" in update) data.completedAt = update.completedAt ?? null;
1994
+ if ("ownerId" in update) data.ownerId = update.ownerId ?? null;
1995
+ if ("leaseExpiresAt" in update) data.leaseExpiresAt = update.leaseExpiresAt ?? null;
1980
1996
  if (Object.keys(data).length === 0) return false;
1981
1997
  const setClauses = Object.keys(data).map((field) => `${quoteIdent(field, "column name")} = @${field}`);
1982
1998
  const params = {
1983
1999
  ...data,
1984
- id: taskId,
1985
- expectedStatus: options?.expectedStatus
2000
+ id: taskId
1986
2001
  };
1987
- const statusPredicate = options?.expectedStatus ? " AND status = @expectedStatus" : "";
2002
+ const predicates = [];
2003
+ if (options?.expectedStatus) {
2004
+ predicates.push("status = @expectedStatus");
2005
+ params.expectedStatus = options.expectedStatus;
2006
+ }
2007
+ if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates.push("ownerId IS NULL");
2008
+ else {
2009
+ predicates.push("ownerId = @expectedOwnerId");
2010
+ params.expectedOwnerId = options.expectedOwnerId;
2011
+ }
2012
+ if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates.push("leaseExpiresAt IS NULL");
2013
+ else {
2014
+ predicates.push("leaseExpiresAt = @expectedLeaseExpiresAt");
2015
+ params.expectedLeaseExpiresAt = options.expectedLeaseExpiresAt;
2016
+ }
2017
+ const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
1988
2018
  const [rowCount] = await this.database.runUpdate({
1989
- sql: `UPDATE ${this.tableName()} SET ${setClauses.join(", ")} WHERE id = @id${statusPredicate}`,
2019
+ sql: `UPDATE ${this.tableName()} SET ${setClauses.join(", ")} WHERE id = @id${predicateSql}`,
1990
2020
  params
1991
2021
  });
1992
2022
  return rowCount > 0;