@mastra/mssql 1.9.0 → 1.10.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
@@ -1780,7 +1780,9 @@ function rowToTask(row) {
1780
1780
  createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
1781
1781
  startedAt: row.startedAt ? row.startedAt instanceof Date ? row.startedAt : new Date(row.startedAt) : void 0,
1782
1782
  suspendedAt: row.suspendedAt ? row.suspendedAt instanceof Date ? row.suspendedAt : new Date(row.suspendedAt) : void 0,
1783
- completedAt: row.completedAt ? row.completedAt instanceof Date ? row.completedAt : new Date(row.completedAt) : void 0
1783
+ completedAt: row.completedAt ? row.completedAt instanceof Date ? row.completedAt : new Date(row.completedAt) : void 0,
1784
+ ownerId: row.ownerId ?? void 0,
1785
+ leaseExpiresAt: row.leaseExpiresAt ? row.leaseExpiresAt instanceof Date ? row.leaseExpiresAt : new Date(row.leaseExpiresAt) : void 0
1784
1786
  };
1785
1787
  }
1786
1788
  var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends BackgroundTasksStorage {
@@ -1817,7 +1819,12 @@ var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends BackgroundTasksSto
1817
1819
  await this.db.alterTable({
1818
1820
  tableName: TABLE_BACKGROUND_TASKS,
1819
1821
  schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
1820
- ifNotExists: ["suspend_payload", "suspendedAt"]
1822
+ ifNotExists: [
1823
+ "suspend_payload",
1824
+ "suspendedAt",
1825
+ "ownerId",
1826
+ "leaseExpiresAt"
1827
+ ]
1821
1828
  });
1822
1829
  await this.createDefaultIndexes();
1823
1830
  await this.createCustomIndexes();
@@ -1894,7 +1901,9 @@ var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends BackgroundTasksSto
1894
1901
  createdAt: task.createdAt.toISOString(),
1895
1902
  startedAt: task.startedAt?.toISOString() ?? null,
1896
1903
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
1897
- completedAt: task.completedAt?.toISOString() ?? null
1904
+ completedAt: task.completedAt?.toISOString() ?? null,
1905
+ ownerId: task.ownerId ?? null,
1906
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
1898
1907
  }
1899
1908
  });
1900
1909
  }
@@ -1934,18 +1943,37 @@ var BackgroundTasksMSSQL = class BackgroundTasksMSSQL extends BackgroundTasksSto
1934
1943
  setClauses.push(`[completedAt] = @p${idx}`);
1935
1944
  params[`p${idx++}`] = update.completedAt?.toISOString() ?? null;
1936
1945
  }
1946
+ if ("ownerId" in update) {
1947
+ setClauses.push(`[ownerId] = @p${idx}`);
1948
+ params[`p${idx++}`] = update.ownerId ?? null;
1949
+ }
1950
+ if ("leaseExpiresAt" in update) {
1951
+ setClauses.push(`[leaseExpiresAt] = @p${idx}`);
1952
+ params[`p${idx++}`] = update.leaseExpiresAt?.toISOString() ?? null;
1953
+ }
1937
1954
  if (setClauses.length === 0) return false;
1938
1955
  setClauses.push(`[id] = [id]`);
1939
1956
  params[`p${idx}`] = taskId;
1940
1957
  const taskIdParam = `p${idx++}`;
1941
- let statusPredicate = "";
1958
+ const predicates = [];
1942
1959
  if (options?.expectedStatus) {
1943
1960
  params[`p${idx}`] = options.expectedStatus;
1944
- statusPredicate = ` AND [status] = @p${idx}`;
1961
+ predicates.push(`[status] = @p${idx++}`);
1962
+ }
1963
+ if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates.push(`[ownerId] IS NULL`);
1964
+ else {
1965
+ params[`p${idx}`] = options.expectedOwnerId;
1966
+ predicates.push(`[ownerId] = @p${idx++}`);
1967
+ }
1968
+ if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates.push(`[leaseExpiresAt] IS NULL`);
1969
+ else {
1970
+ params[`p${idx}`] = options.expectedLeaseExpiresAt.toISOString();
1971
+ predicates.push(`[leaseExpiresAt] = @p${idx++}`);
1945
1972
  }
1973
+ const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
1946
1974
  const request = this.pool.request();
1947
1975
  for (const [name, value] of Object.entries(params)) request.input(name, value);
1948
- return ((await request.query(`UPDATE ${this.tableName()} SET ${setClauses.join(", ")} WHERE [id] = @${taskIdParam}${statusPredicate}`)).rowsAffected[0] ?? 0) > 0;
1976
+ return ((await request.query(`UPDATE ${this.tableName()} SET ${setClauses.join(", ")} WHERE [id] = @${taskIdParam}${predicateSql}`)).rowsAffected[0] ?? 0) > 0;
1949
1977
  }
1950
1978
  async getTask(taskId) {
1951
1979
  const request = this.pool.request();