@mastra/lance 1.5.2 → 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
@@ -464,7 +464,9 @@ function toRecord(task) {
464
464
  suspendedAt: task.suspendedAt ?? /* @__PURE__ */ new Date(0),
465
465
  completedAt: task.completedAt ?? /* @__PURE__ */ new Date(0),
466
466
  ownerId: task.ownerId ?? null,
467
- leaseExpiresAt: task.leaseExpiresAt ?? null
467
+ leaseExpiresAt: task.leaseExpiresAt ?? null,
468
+ expiresAt: task.expiresAt ?? null,
469
+ metadata: serializeJson(task.metadata) ?? null
468
470
  };
469
471
  }
470
472
  function fromRecord(row) {
@@ -481,6 +483,7 @@ function fromRecord(row) {
481
483
  const suspendedAt = row.suspendedAt instanceof Date ? row.suspendedAt : row.suspendedAt ? new Date(row.suspendedAt) : void 0;
482
484
  const completedAt = row.completedAt instanceof Date ? row.completedAt : row.completedAt ? new Date(row.completedAt) : void 0;
483
485
  const leaseExpiresAt = row.leaseExpiresAt instanceof Date ? row.leaseExpiresAt : row.leaseExpiresAt ? new Date(row.leaseExpiresAt) : void 0;
486
+ const expiresAt = row.expiresAt instanceof Date ? row.expiresAt : row.expiresAt ? new Date(row.expiresAt) : void 0;
484
487
  return {
485
488
  id: String(row.id),
486
489
  status: String(row.status),
@@ -502,13 +505,16 @@ function fromRecord(row) {
502
505
  suspendedAt: suspendedAt && suspendedAt.getTime() > 0 ? suspendedAt : void 0,
503
506
  completedAt: completedAt && completedAt.getTime() > 0 ? completedAt : void 0,
504
507
  ownerId: row.ownerId != null && row.ownerId !== "" ? String(row.ownerId) : void 0,
505
- leaseExpiresAt
508
+ leaseExpiresAt,
509
+ expiresAt,
510
+ metadata: parseJson(row.metadata)
506
511
  };
507
512
  }
508
513
  function escapeStr(val) {
509
514
  return val.replace(/'/g, "''");
510
515
  }
511
516
  var StoreBackgroundTasksLance = class extends BackgroundTasksStorage {
517
+ supportsTaskExpiry = true;
512
518
  client;
513
519
  #db;
514
520
  constructor(config) {
@@ -529,7 +535,9 @@ var StoreBackgroundTasksLance = class extends BackgroundTasksStorage {
529
535
  "suspend_payload",
530
536
  "suspendedAt",
531
537
  "ownerId",
532
- "leaseExpiresAt"
538
+ "leaseExpiresAt",
539
+ "expiresAt",
540
+ "metadata"
533
541
  ]
534
542
  });
535
543
  }
@@ -551,11 +559,14 @@ var StoreBackgroundTasksLance = class extends BackgroundTasksStorage {
551
559
  if ("completedAt" in update) values.completedAt = update.completedAt?.getTime() ?? 0;
552
560
  if ("ownerId" in update) values.ownerId = update.ownerId ?? null;
553
561
  if ("leaseExpiresAt" in update) values.leaseExpiresAt = update.leaseExpiresAt?.getTime() ?? null;
562
+ if ("expiresAt" in update) values.expiresAt = update.expiresAt?.getTime() ?? null;
563
+ if ("metadata" in update) values.metadata = serializeJson(update.metadata) ?? null;
554
564
  if (Object.keys(values).length === 0) return false;
555
565
  const conditions = [`id = '${escapeStr(taskId)}'`];
556
566
  if (options?.expectedStatus) conditions.push(`status = '${escapeStr(options.expectedStatus)}'`);
557
567
  if (options?.expectedOwnerId !== void 0) conditions.push(options.expectedOwnerId === null ? "ownerId IS NULL" : `ownerId = '${escapeStr(options.expectedOwnerId)}'`);
558
568
  if (options?.expectedLeaseExpiresAt !== void 0) conditions.push(options.expectedLeaseExpiresAt === null ? "leaseExpiresAt IS NULL" : `leaseExpiresAt = ${options.expectedLeaseExpiresAt.getTime()}`);
569
+ if (options?.expectedSuspendedAt !== void 0) conditions.push(options.expectedSuspendedAt === null ? "(suspendedAt IS NULL OR suspendedAt = 0)" : `suspendedAt = ${options.expectedSuspendedAt.getTime()}`);
559
570
  return (await (await this.client.openTable(TABLE_BACKGROUND_TASKS)).update({
560
571
  where: conditions.join(" AND "),
561
572
  values
@@ -587,6 +598,7 @@ var StoreBackgroundTasksLance = class extends BackgroundTasksStorage {
587
598
  let query = table.query();
588
599
  if (conditions.length > 0) query = query.where(conditions.join(" AND "));
589
600
  let tasks = (await query.toArray()).map(fromRecord);
601
+ if (filter.hasExpiresAt !== void 0) tasks = tasks.filter((t) => t.expiresAt != null === filter.hasExpiresAt);
590
602
  const dateCol = filter.dateFilterBy ?? "createdAt";
591
603
  if (filter.fromDate) tasks = tasks.filter((t) => {
592
604
  const val = t[dateCol];