@mastra/upstash 1.4.7 → 1.5.0-alpha.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
@@ -188,7 +188,9 @@ function toStorageRecord(task) {
188
188
  createdAt: task.createdAt.toISOString(),
189
189
  startedAt: task.startedAt?.toISOString() ?? null,
190
190
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
191
- completedAt: task.completedAt?.toISOString() ?? null
191
+ completedAt: task.completedAt?.toISOString() ?? null,
192
+ ownerId: task.ownerId ?? null,
193
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
192
194
  };
193
195
  }
194
196
  function fromStorageRecord(record) {
@@ -211,7 +213,9 @@ function fromStorageRecord(record) {
211
213
  createdAt: new Date(record.createdAt),
212
214
  startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
213
215
  suspendedAt: record.suspendedAt ? new Date(record.suspendedAt) : void 0,
214
- completedAt: record.completedAt ? new Date(record.completedAt) : void 0
216
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
217
+ ownerId: record.ownerId ?? void 0,
218
+ leaseExpiresAt: record.leaseExpiresAt ? new Date(record.leaseExpiresAt) : void 0
215
219
  };
216
220
  }
217
221
  var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
@@ -240,6 +244,8 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
240
244
  if ("startedAt" in update) patch.startedAt = update.startedAt?.toISOString() ?? null;
241
245
  if ("suspendedAt" in update) patch.suspendedAt = update.suspendedAt?.toISOString() ?? null;
242
246
  if ("completedAt" in update) patch.completedAt = update.completedAt?.toISOString() ?? null;
247
+ if ("ownerId" in update) patch.ownerId = update.ownerId ?? null;
248
+ if ("leaseExpiresAt" in update) patch.leaseExpiresAt = update.leaseExpiresAt?.toISOString() ?? null;
243
249
  if (Object.keys(patch).length === 0) return false;
244
250
  const key = getKey(TABLE_BACKGROUND_TASKS, { id: taskId });
245
251
  const result = await this.client.eval(`
@@ -247,11 +253,28 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
247
253
  if not existing then return 0 end
248
254
  local record = cjson.decode(existing)
249
255
  if ARGV[1] ~= '' and record.status ~= ARGV[1] then return 0 end
256
+ local function normalize(value)
257
+ if value == nil or value == cjson.null then return nil end
258
+ return value
259
+ end
260
+ if ARGV[3] == '1' then
261
+ if normalize(record.ownerId) ~= normalize(cjson.decode(ARGV[4])) then return 0 end
262
+ end
263
+ if ARGV[5] == '1' then
264
+ if normalize(record.leaseExpiresAt) ~= normalize(cjson.decode(ARGV[6])) then return 0 end
265
+ end
250
266
  local patch = cjson.decode(ARGV[2])
251
267
  for field, value in pairs(patch) do record[field] = value end
252
268
  redis.call('SET', KEYS[1], cjson.encode(record))
253
269
  return 1
254
- `, [key], [options?.expectedStatus ?? "", JSON.stringify(patch)]);
270
+ `, [key], [
271
+ options?.expectedStatus ?? "",
272
+ JSON.stringify(patch),
273
+ options?.expectedOwnerId !== void 0 ? "1" : "0",
274
+ JSON.stringify(options?.expectedOwnerId ?? null),
275
+ options?.expectedLeaseExpiresAt !== void 0 ? "1" : "0",
276
+ JSON.stringify(options?.expectedLeaseExpiresAt?.toISOString() ?? null)
277
+ ]);
255
278
  return Number(result) === 1;
256
279
  }
257
280
  async getTask(taskId) {