@mastra/dynamodb 1.4.5 → 1.5.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
@@ -176,6 +176,15 @@ const backgroundTaskEntity = new Entity({
176
176
  leaseExpiresAtIso: {
177
177
  type: "string",
178
178
  required: false
179
+ },
180
+ expiresAtIso: {
181
+ type: "string",
182
+ required: false
183
+ },
184
+ metadata: {
185
+ type: "string",
186
+ required: false,
187
+ ...jsonSetGet
179
188
  }
180
189
  },
181
190
  indexes: {
@@ -1303,7 +1312,9 @@ function toElectroRecord(task) {
1303
1312
  suspendedAtIso: task.suspendedAt?.toISOString(),
1304
1313
  completedAtIso: task.completedAt?.toISOString(),
1305
1314
  ownerId: task.ownerId ?? void 0,
1306
- leaseExpiresAtIso: task.leaseExpiresAt?.toISOString()
1315
+ leaseExpiresAtIso: task.leaseExpiresAt?.toISOString(),
1316
+ expiresAtIso: task.expiresAt?.toISOString(),
1317
+ metadata: serializeJson(task.metadata)
1307
1318
  };
1308
1319
  }
1309
1320
  function fromElectroRecord(data) {
@@ -1338,10 +1349,13 @@ function fromElectroRecord(data) {
1338
1349
  suspendedAt: asDate(data.suspendedAtIso),
1339
1350
  completedAt: asDate(data.completedAtIso),
1340
1351
  ownerId: data.ownerId != null && data.ownerId !== "" ? String(data.ownerId) : void 0,
1341
- leaseExpiresAt: asDate(data.leaseExpiresAtIso)
1352
+ leaseExpiresAt: asDate(data.leaseExpiresAtIso),
1353
+ expiresAt: asDate(data.expiresAtIso),
1354
+ metadata: parseJson(data.metadata)
1342
1355
  };
1343
1356
  }
1344
1357
  var BackgroundTasksStorageDynamoDB = class extends BackgroundTasksStorage {
1358
+ supportsTaskExpiry = true;
1345
1359
  service;
1346
1360
  constructor(config) {
1347
1361
  super();
@@ -1401,6 +1415,14 @@ var BackgroundTasksStorageDynamoDB = class extends BackgroundTasksStorage {
1401
1415
  if (update.leaseExpiresAt === void 0 || update.leaseExpiresAt === null) removeFields.push("leaseExpiresAtIso");
1402
1416
  else setFields.leaseExpiresAtIso = update.leaseExpiresAt.toISOString();
1403
1417
  }
1418
+ if ("expiresAt" in update) {
1419
+ if (update.expiresAt === void 0 || update.expiresAt === null) removeFields.push("expiresAtIso");
1420
+ else setFields.expiresAtIso = update.expiresAt.toISOString();
1421
+ }
1422
+ if ("metadata" in update) {
1423
+ if (update.metadata === void 0 || update.metadata === null) removeFields.push("metadata");
1424
+ else setFields.metadata = serializeJson(update.metadata);
1425
+ }
1404
1426
  if (Object.keys(setFields).length === 0 && removeFields.length === 0) return false;
1405
1427
  let op = this.service.entities.background_task.patch({
1406
1428
  entity: ENTITY,
@@ -1417,9 +1439,13 @@ var BackgroundTasksStorageDynamoDB = class extends BackgroundTasksStorage {
1417
1439
  const expectedLeaseExpiresAt = options.expectedLeaseExpiresAt;
1418
1440
  op = op.where(({ leaseExpiresAtIso }, { eq, notExists }) => expectedLeaseExpiresAt === null ? notExists(leaseExpiresAtIso) : eq(leaseExpiresAtIso, expectedLeaseExpiresAt.toISOString()));
1419
1441
  }
1442
+ if (options?.expectedSuspendedAt !== void 0) {
1443
+ const expectedSuspendedAt = options.expectedSuspendedAt;
1444
+ op = op.where(({ suspendedAtIso }, { eq, notExists }) => expectedSuspendedAt === null ? notExists(suspendedAtIso) : eq(suspendedAtIso, expectedSuspendedAt.toISOString()));
1445
+ }
1420
1446
  await op.go();
1421
1447
  } catch (error) {
1422
- if ((options?.expectedStatus !== void 0 || options?.expectedOwnerId !== void 0 || options?.expectedLeaseExpiresAt !== void 0) && error?.cause?.name === "ConditionalCheckFailedException") return false;
1448
+ if ((options?.expectedStatus !== void 0 || options?.expectedOwnerId !== void 0 || options?.expectedLeaseExpiresAt !== void 0 || options?.expectedSuspendedAt !== void 0) && error?.cause?.name === "ConditionalCheckFailedException") return false;
1423
1449
  throw new MastraError({
1424
1450
  id: createStorageErrorId("DYNAMODB", "BACKGROUND_TASKS_UPDATE", "FAILED"),
1425
1451
  domain: ErrorDomain.STORAGE,
@@ -1473,6 +1499,7 @@ var BackgroundTasksStorageDynamoDB = class extends BackgroundTasksStorage {
1473
1499
  if (filter.toolName) tasks = tasks.filter((t) => t.toolName === filter.toolName);
1474
1500
  if (filter.toolCallId) tasks = tasks.filter((t) => t.toolCallId === filter.toolCallId);
1475
1501
  if (filter.runId) tasks = tasks.filter((t) => t.runId === filter.runId);
1502
+ if (filter.hasExpiresAt !== void 0) tasks = tasks.filter((t) => t.expiresAt != null === filter.hasExpiresAt);
1476
1503
  const dateCol = filter.dateFilterBy ?? "createdAt";
1477
1504
  if (filter.fromDate) tasks = tasks.filter((t) => {
1478
1505
  const val = t[dateCol];