@mastra/upstash 1.5.5 → 1.6.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
@@ -186,7 +186,9 @@ function toStorageRecord(task) {
186
186
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
187
187
  completedAt: task.completedAt?.toISOString() ?? null,
188
188
  ownerId: task.ownerId ?? null,
189
- leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
189
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
190
+ expiresAt: task.expiresAt?.toISOString() ?? null,
191
+ metadata: task.metadata ?? null
190
192
  };
191
193
  }
192
194
  function fromStorageRecord(record) {
@@ -211,10 +213,13 @@ function fromStorageRecord(record) {
211
213
  suspendedAt: record.suspendedAt ? new Date(record.suspendedAt) : void 0,
212
214
  completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
213
215
  ownerId: record.ownerId ?? void 0,
214
- leaseExpiresAt: record.leaseExpiresAt ? new Date(record.leaseExpiresAt) : void 0
216
+ leaseExpiresAt: record.leaseExpiresAt ? new Date(record.leaseExpiresAt) : void 0,
217
+ expiresAt: record.expiresAt ? new Date(record.expiresAt) : void 0,
218
+ metadata: record.metadata ?? void 0
215
219
  };
216
220
  }
217
221
  var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
222
+ supportsTaskExpiry = true;
218
223
  client;
219
224
  #db;
220
225
  constructor(config) {
@@ -243,6 +248,8 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
243
248
  if ("completedAt" in update) patch.completedAt = update.completedAt?.toISOString() ?? null;
244
249
  if ("ownerId" in update) patch.ownerId = update.ownerId ?? null;
245
250
  if ("leaseExpiresAt" in update) patch.leaseExpiresAt = update.leaseExpiresAt?.toISOString() ?? null;
251
+ if ("expiresAt" in update) patch.expiresAt = update.expiresAt?.toISOString() ?? null;
252
+ if ("metadata" in update) patch.metadata = update.metadata ?? null;
246
253
  if (Object.keys(patch).length === 0) return false;
247
254
  const key = getKey(TABLE_BACKGROUND_TASKS, { id: taskId });
248
255
  const result = await this.client.eval(`
@@ -260,6 +267,9 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
260
267
  if ARGV[5] == '1' then
261
268
  if normalize(record.leaseExpiresAt) ~= normalize(cjson.decode(ARGV[6])) then return 0 end
262
269
  end
270
+ if ARGV[7] == '1' then
271
+ if normalize(record.suspendedAt) ~= normalize(cjson.decode(ARGV[8])) then return 0 end
272
+ end
263
273
  local patch = cjson.decode(ARGV[2])
264
274
  for field, value in pairs(patch) do record[field] = value end
265
275
  redis.call('SET', KEYS[1], cjson.encode(record))
@@ -270,7 +280,9 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
270
280
  options?.expectedOwnerId !== void 0 ? "1" : "0",
271
281
  JSON.stringify(options?.expectedOwnerId ?? null),
272
282
  options?.expectedLeaseExpiresAt !== void 0 ? "1" : "0",
273
- JSON.stringify(options?.expectedLeaseExpiresAt?.toISOString() ?? null)
283
+ JSON.stringify(options?.expectedLeaseExpiresAt?.toISOString() ?? null),
284
+ options?.expectedSuspendedAt !== void 0 ? "1" : "0",
285
+ JSON.stringify(options?.expectedSuspendedAt?.toISOString() ?? null)
274
286
  ]);
275
287
  return Number(result) === 1;
276
288
  }
@@ -297,6 +309,7 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
297
309
  if (filter.threadId) tasks = tasks.filter((t) => t.threadId === filter.threadId);
298
310
  if (filter.resourceId) tasks = tasks.filter((t) => t.resourceId === filter.resourceId);
299
311
  if (filter.runId) tasks = tasks.filter((t) => t.runId === filter.runId);
312
+ if (filter.hasExpiresAt !== void 0) tasks = tasks.filter((t) => t.expiresAt != null === filter.hasExpiresAt);
300
313
  if (filter.toolName) tasks = tasks.filter((t) => t.toolName === filter.toolName);
301
314
  if (filter.toolCallId) tasks = tasks.filter((t) => t.toolCallId === filter.toolCallId);
302
315
  const dateCol = filter.dateFilterBy ?? "createdAt";