@mastra/upstash 1.5.4-alpha.0 → 1.5.4

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
@@ -230,7 +230,8 @@ var BackgroundTasksUpstash = class extends BackgroundTasksStorage {
230
230
  await this.#db.deleteData({ tableName: TABLE_BACKGROUND_TASKS });
231
231
  }
232
232
  async createTask(task) {
233
- const { key, processedRecord } = processRecord(TABLE_BACKGROUND_TASKS, toStorageRecord(task));
233
+ const record = toStorageRecord(task);
234
+ const { key, processedRecord } = processRecord(TABLE_BACKGROUND_TASKS, record);
234
235
  await this.client.set(key, processedRecord);
235
236
  }
236
237
  async updateTask(taskId, update, options) {
@@ -355,7 +356,7 @@ function runClaimKey(claims, runId) {
355
356
  return `${claims}:run_id:${runId}`;
356
357
  }
357
358
  const RUN_FENCE_CONFLICT = "MASTRA_RUN_FENCE_CONFLICT";
358
- const RUN_CLAIM_RETENTION_MS = 10080 * 60 * 1e3;
359
+ const RUN_CLAIM_RETENTION_MS = 6048e5;
359
360
  const FENCE_GUARD = `
360
361
  local fenceClaim = redis.call('HMGET', KEYS[#KEYS], 'generation', 'ownerId')
361
362
  if tonumber(fenceClaim[1]) ~= tonumber(ARGV[#ARGV - 1]) or fenceClaim[2] ~= ARGV[#ARGV] then
@@ -1367,22 +1368,24 @@ var StoreMemoryUpstash = class extends MemoryStorage {
1367
1368
  }
1368
1369
  for (const key in fieldsToUpdate) if (Object.prototype.hasOwnProperty.call(fieldsToUpdate, key) && key !== "content") updatedMessage[key] = fieldsToUpdate[key];
1369
1370
  const key = messageIdToKey[id];
1370
- if (key) if (updatePayload.threadId && updatePayload.threadId !== existingMessage.threadId) {
1371
- const newThreadId = updatedMessage.threadId;
1372
- const oldThreadMessagesKey = getThreadMessagesKey(existingMessage.threadId);
1373
- pipeline.zrem(oldThreadMessagesKey, id);
1374
- pipeline.del(key);
1375
- const newKey = getMessageKey(newThreadId, id);
1376
- pipeline.set(newKey, updatedMessage);
1377
- pipeline.set(getMessageIndexKey(id), newThreadId);
1378
- messageIdToKey[id] = newKey;
1379
- const newThreadMessagesKey = getThreadMessagesKey(newThreadId);
1380
- const score = updatedMessage._index !== void 0 ? updatedMessage._index : new Date(updatedMessage.createdAt).getTime();
1381
- pipeline.zadd(newThreadMessagesKey, {
1382
- score,
1383
- member: id
1384
- });
1385
- } else pipeline.set(key, updatedMessage);
1371
+ if (key) {
1372
+ if (updatePayload.threadId && updatePayload.threadId !== existingMessage.threadId) {
1373
+ const newThreadId = updatedMessage.threadId;
1374
+ const oldThreadMessagesKey = getThreadMessagesKey(existingMessage.threadId);
1375
+ pipeline.zrem(oldThreadMessagesKey, id);
1376
+ pipeline.del(key);
1377
+ const newKey = getMessageKey(newThreadId, id);
1378
+ pipeline.set(newKey, updatedMessage);
1379
+ pipeline.set(getMessageIndexKey(id), newThreadId);
1380
+ messageIdToKey[id] = newKey;
1381
+ const newThreadMessagesKey = getThreadMessagesKey(newThreadId);
1382
+ const score = updatedMessage._index !== void 0 ? updatedMessage._index : new Date(updatedMessage.createdAt).getTime();
1383
+ pipeline.zadd(newThreadMessagesKey, {
1384
+ score,
1385
+ member: id
1386
+ });
1387
+ } else pipeline.set(key, updatedMessage);
1388
+ }
1386
1389
  }
1387
1390
  const now = /* @__PURE__ */ new Date();
1388
1391
  for (const threadId of threadIdsToUpdate) if (threadId) {
@@ -1714,12 +1717,13 @@ var ScoresUpstash = class extends ScoresStorage {
1714
1717
  const id = crypto.randomUUID();
1715
1718
  const createdAt = now;
1716
1719
  const updatedAt = now;
1717
- const { key, processedRecord } = processRecord(TABLE_SCORERS, {
1720
+ const scoreWithId = {
1718
1721
  ...validatedScore,
1719
1722
  id,
1720
1723
  createdAt,
1721
1724
  updatedAt
1722
- });
1725
+ };
1726
+ const { key, processedRecord } = processRecord(TABLE_SCORERS, scoreWithId);
1723
1727
  try {
1724
1728
  await this.client.set(key, processedRecord);
1725
1729
  return { score: {