@mastra/mongodb 1.24.1-alpha.1 → 1.25.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
@@ -9,7 +9,7 @@ import { MessageList } from "@mastra/core/agent";
9
9
  import { saveScorePayloadSchema } from "@mastra/core/evals";
10
10
  import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
11
11
  // package.json
12
- var version = "1.24.1-alpha.1";
12
+ var version = "1.25.0-alpha.0";
13
13
  // src/vector/filter.ts
14
14
  /**
15
15
  * Translator for MongoDB filter queries.
@@ -45,10 +45,9 @@ var MongoDBFilterTranslator = class extends BaseFilterTranslator {
45
45
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("$not operator requires an object");
46
46
  if (this.isEmpty(value)) throw new Error("$not operator cannot be empty");
47
47
  return this.translateNode(value);
48
- } else {
49
- if (!Array.isArray(value)) throw new Error(`Value for logical operator ${operator} must be an array`);
50
- return value.map((item) => this.translateNode(item));
51
48
  }
49
+ if (!Array.isArray(value)) throw new Error(`Value for logical operator ${operator} must be an array`);
50
+ return value.map((item) => this.translateNode(item));
52
51
  }
53
52
  if (this.isBasicOperator(operator) || this.isNumericOperator(operator)) {
54
53
  if (value instanceof Date) return value.toISOString();
@@ -2440,7 +2439,9 @@ function toDoc(task) {
2440
2439
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
2441
2440
  completedAt: task.completedAt?.toISOString() ?? null,
2442
2441
  ownerId: task.ownerId ?? null,
2443
- leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
2442
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
2443
+ expiresAt: task.expiresAt?.toISOString() ?? null,
2444
+ metadata: task.metadata ?? null
2444
2445
  };
2445
2446
  }
2446
2447
  function fromDoc(doc) {
@@ -2465,10 +2466,13 @@ function fromDoc(doc) {
2465
2466
  suspendedAt: doc.suspendedAt ? new Date(doc.suspendedAt) : void 0,
2466
2467
  completedAt: doc.completedAt ? new Date(doc.completedAt) : void 0,
2467
2468
  ownerId: doc.ownerId ?? void 0,
2468
- leaseExpiresAt: doc.leaseExpiresAt ? new Date(doc.leaseExpiresAt) : void 0
2469
+ leaseExpiresAt: doc.leaseExpiresAt ? new Date(doc.leaseExpiresAt) : void 0,
2470
+ expiresAt: doc.expiresAt ? new Date(doc.expiresAt) : void 0,
2471
+ metadata: doc.metadata ?? void 0
2469
2472
  };
2470
2473
  }
2471
2474
  var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends BackgroundTasksStorage {
2475
+ supportsTaskExpiry = true;
2472
2476
  #connector;
2473
2477
  #skipDefaultIndexes;
2474
2478
  #indexes;
@@ -2584,11 +2588,14 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
2584
2588
  if ("completedAt" in update) $set.completedAt = update.completedAt?.toISOString() ?? null;
2585
2589
  if ("ownerId" in update) $set.ownerId = update.ownerId ?? null;
2586
2590
  if ("leaseExpiresAt" in update) $set.leaseExpiresAt = update.leaseExpiresAt?.toISOString() ?? null;
2591
+ if ("expiresAt" in update) $set.expiresAt = update.expiresAt?.toISOString() ?? null;
2592
+ if ("metadata" in update) $set.metadata = update.metadata ?? null;
2587
2593
  if (Object.keys($set).length === 0) return false;
2588
2594
  const filter = { id: taskId };
2589
2595
  if (options?.expectedStatus) filter.status = options.expectedStatus;
2590
2596
  if (options?.expectedOwnerId !== void 0) filter.ownerId = options.expectedOwnerId;
2591
2597
  if (options?.expectedLeaseExpiresAt !== void 0) filter.leaseExpiresAt = options.expectedLeaseExpiresAt?.toISOString() ?? null;
2598
+ if (options?.expectedSuspendedAt !== void 0) filter.suspendedAt = options.expectedSuspendedAt?.toISOString() ?? null;
2592
2599
  return (await (await this.getCollection()).updateOne(filter, { $set })).matchedCount > 0;
2593
2600
  }
2594
2601
  async getTask(taskId) {
@@ -2607,7 +2614,8 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
2607
2614
  if (filter.runId) query.run_id = filter.runId;
2608
2615
  if (filter.toolName) query.tool_name = filter.toolName;
2609
2616
  if (filter.toolCallId) query.tool_call_id = filter.toolCallId;
2610
- const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
2617
+ const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
2618
+ if (filter.hasExpiresAt !== void 0) query.expiresAt = filter.hasExpiresAt ? { $ne: null } : { $eq: null };
2611
2619
  if (filter.fromDate) query[dateCol] = {
2612
2620
  ...query[dateCol] || {},
2613
2621
  $gte: filter.fromDate.toISOString()
@@ -2639,7 +2647,8 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
2639
2647
  const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
2640
2648
  query.status = statuses.length === 1 ? statuses[0] : { $in: statuses };
2641
2649
  }
2642
- const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
2650
+ const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
2651
+ if (filter.hasExpiresAt !== void 0) query.expiresAt = filter.hasExpiresAt ? { $ne: null } : { $eq: null };
2643
2652
  if (filter.fromDate) query[dateCol] = {
2644
2653
  ...query[dateCol] || {},
2645
2654
  $gte: filter.fromDate.toISOString()