@mastra/mongodb 1.7.4-alpha.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 1.8.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added the `schedules` storage domain so MongoDB-backed Mastra apps can use scheduled workflows. Creates `mastra_schedules` and `mastra_schedule_triggers` collections on init, with default indexes on `(status, next_fire_at)` for due-schedule polling and `(schedule_id, actual_fire_at)` for trigger-history queries. ([#15830](https://github.com/mastra-ai/mastra/pull/15830))
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
12
+ - @mastra/core@1.32.0-alpha.1
13
+
14
+ ## 1.7.4
15
+
16
+ ### Patch Changes
17
+
18
+ - Removed unsupported `minScore` query option from MongoDB vector store docs and README. Exported `MongoDBQueryVectorParams` so callers can type `documentFilter` for `MongoDBVector.query()`. ([#15936](https://github.com/mastra-ai/mastra/pull/15936))
19
+
20
+ Fixes #15715
21
+
22
+ - Updated dependencies [[`1723e09`](https://github.com/mastra-ai/mastra/commit/1723e099829892419ddbfe49287acfeac2522724), [`629f9e9`](https://github.com/mastra-ai/mastra/commit/629f9e9a7e56aa8f129515a3923c5813298790c7), [`25168fb`](https://github.com/mastra-ai/mastra/commit/25168fb9c1de9db7f8171df4f58ceb842c53aa29), [`ab34b5a`](https://github.com/mastra-ai/mastra/commit/ab34b5a2191b8e4353df1dbf7b9155e7d6628d79), [`5fb6c2a`](https://github.com/mastra-ai/mastra/commit/5fb6c2a95c1843cc231704b91354311fc1f34a71), [`2b0f355`](https://github.com/mastra-ai/mastra/commit/2b0f3553be3e9e5524da539a66e5cf82668440a4), [`394f0cf`](https://github.com/mastra-ai/mastra/commit/394f0cfc31e6b4d801219fdef2e9cc69e5bc8682), [`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`e109607`](https://github.com/mastra-ai/mastra/commit/e10960749251e34d46b480a20648c490fd30381b), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`3d7f709`](https://github.com/mastra-ai/mastra/commit/3d7f709b615e588050bb6283c4ee5cfe2978cbde), [`48a42f1`](https://github.com/mastra-ai/mastra/commit/48a42f114a4006a95e0b7a1b5ad1a24815a175c2), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006), [`2c83efc`](https://github.com/mastra-ai/mastra/commit/2c83efc4482b3efe50830e3b8b4ba9a8d219edff), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e), [`282a10c`](https://github.com/mastra-ai/mastra/commit/282a10c9446e9922afe80e10e3770481c8ac8a28), [`04151c7`](https://github.com/mastra-ai/mastra/commit/04151c7dcea934b4fe9076708a23fac161195414), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006)]:
23
+ - @mastra/core@1.31.0
24
+
3
25
  ## 1.7.4-alpha.0
4
26
 
5
27
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.7.4-alpha.0"
6
+ version: "1.8.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.4-alpha.0",
2
+ "version": "1.8.0-alpha.0",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ var evals = require('@mastra/core/evals');
14
14
 
15
15
  // package.json
16
16
  var package_default = {
17
- version: "1.7.4-alpha.0"};
17
+ version: "1.8.0-alpha.0"};
18
18
  var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
19
19
  getSupportedOperators() {
20
20
  return {
@@ -7595,6 +7595,206 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
7595
7595
  return result;
7596
7596
  }
7597
7597
  };
7598
+ function scheduleToDoc(schedule) {
7599
+ return {
7600
+ id: schedule.id,
7601
+ target: schedule.target,
7602
+ cron: schedule.cron,
7603
+ timezone: schedule.timezone ?? null,
7604
+ status: schedule.status,
7605
+ next_fire_at: schedule.nextFireAt,
7606
+ last_fire_at: schedule.lastFireAt ?? null,
7607
+ last_run_id: schedule.lastRunId ?? null,
7608
+ created_at: schedule.createdAt,
7609
+ updated_at: schedule.updatedAt,
7610
+ metadata: schedule.metadata ?? null
7611
+ };
7612
+ }
7613
+ function docToSchedule(doc) {
7614
+ const target = doc.target;
7615
+ if (!target) {
7616
+ throw new Error(`Schedule ${doc.id} has invalid target`);
7617
+ }
7618
+ const schedule = {
7619
+ id: String(doc.id),
7620
+ target,
7621
+ cron: String(doc.cron),
7622
+ status: String(doc.status),
7623
+ nextFireAt: Number(doc.next_fire_at),
7624
+ createdAt: Number(doc.created_at),
7625
+ updatedAt: Number(doc.updated_at)
7626
+ };
7627
+ if (doc.timezone != null) schedule.timezone = String(doc.timezone);
7628
+ if (doc.last_fire_at != null) schedule.lastFireAt = Number(doc.last_fire_at);
7629
+ if (doc.last_run_id != null) schedule.lastRunId = String(doc.last_run_id);
7630
+ if (doc.metadata != null) schedule.metadata = doc.metadata;
7631
+ return schedule;
7632
+ }
7633
+ function triggerToDoc(trigger) {
7634
+ return {
7635
+ schedule_id: trigger.scheduleId,
7636
+ run_id: trigger.runId,
7637
+ scheduled_fire_at: trigger.scheduledFireAt,
7638
+ actual_fire_at: trigger.actualFireAt,
7639
+ status: trigger.status,
7640
+ error: trigger.error ?? null
7641
+ };
7642
+ }
7643
+ function docToTrigger(doc) {
7644
+ const trigger = {
7645
+ scheduleId: String(doc.schedule_id),
7646
+ runId: String(doc.run_id),
7647
+ scheduledFireAt: Number(doc.scheduled_fire_at),
7648
+ actualFireAt: Number(doc.actual_fire_at),
7649
+ status: String(doc.status)
7650
+ };
7651
+ if (doc.error != null) trigger.error = String(doc.error);
7652
+ return trigger;
7653
+ }
7654
+ var SchedulesMongoDB = class _SchedulesMongoDB extends storage.SchedulesStorage {
7655
+ #connector;
7656
+ #skipDefaultIndexes;
7657
+ #indexes;
7658
+ static MANAGED_COLLECTIONS = [storage.TABLE_SCHEDULES, storage.TABLE_SCHEDULE_TRIGGERS];
7659
+ constructor(config) {
7660
+ super();
7661
+ this.#connector = resolveMongoDBConfig(config);
7662
+ this.#skipDefaultIndexes = config.skipDefaultIndexes;
7663
+ this.#indexes = config.indexes?.filter(
7664
+ (idx) => _SchedulesMongoDB.MANAGED_COLLECTIONS.includes(idx.collection)
7665
+ );
7666
+ }
7667
+ getSchedulesCollection() {
7668
+ return this.#connector.getCollection(storage.TABLE_SCHEDULES);
7669
+ }
7670
+ getTriggersCollection() {
7671
+ return this.#connector.getCollection(storage.TABLE_SCHEDULE_TRIGGERS);
7672
+ }
7673
+ getDefaultIndexDefinitions() {
7674
+ return [
7675
+ { collection: storage.TABLE_SCHEDULES, keys: { id: 1 }, options: { unique: true } },
7676
+ { collection: storage.TABLE_SCHEDULES, keys: { status: 1, next_fire_at: 1 } },
7677
+ { collection: storage.TABLE_SCHEDULES, keys: { "target.workflowId": 1 } },
7678
+ { collection: storage.TABLE_SCHEDULE_TRIGGERS, keys: { schedule_id: 1, actual_fire_at: -1 } },
7679
+ { collection: storage.TABLE_SCHEDULE_TRIGGERS, keys: { run_id: 1 }, options: { unique: true } }
7680
+ ];
7681
+ }
7682
+ async createDefaultIndexes() {
7683
+ if (this.#skipDefaultIndexes) return;
7684
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
7685
+ try {
7686
+ const collection = await this.#connector.getCollection(indexDef.collection);
7687
+ await collection.createIndex(indexDef.keys, indexDef.options);
7688
+ } catch (error) {
7689
+ this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
7690
+ }
7691
+ }
7692
+ }
7693
+ async createCustomIndexes() {
7694
+ if (!this.#indexes || this.#indexes.length === 0) return;
7695
+ for (const indexDef of this.#indexes) {
7696
+ try {
7697
+ const collection = await this.#connector.getCollection(indexDef.collection);
7698
+ await collection.createIndex(indexDef.keys, indexDef.options);
7699
+ } catch (error) {
7700
+ this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
7701
+ }
7702
+ }
7703
+ }
7704
+ async init() {
7705
+ await this.createDefaultIndexes();
7706
+ await this.createCustomIndexes();
7707
+ }
7708
+ async dangerouslyClearAll() {
7709
+ const triggers = await this.getTriggersCollection();
7710
+ await triggers.deleteMany({});
7711
+ const schedules = await this.getSchedulesCollection();
7712
+ await schedules.deleteMany({});
7713
+ }
7714
+ async createSchedule(schedule) {
7715
+ const collection = await this.getSchedulesCollection();
7716
+ const existing = await collection.findOne({ id: schedule.id });
7717
+ if (existing) {
7718
+ throw new Error(`Schedule with id "${schedule.id}" already exists`);
7719
+ }
7720
+ await collection.insertOne(scheduleToDoc(schedule));
7721
+ return schedule;
7722
+ }
7723
+ async getSchedule(id) {
7724
+ const collection = await this.getSchedulesCollection();
7725
+ const doc = await collection.findOne({ id });
7726
+ return doc ? docToSchedule(doc) : null;
7727
+ }
7728
+ async listSchedules(filter) {
7729
+ const query = {};
7730
+ if (filter?.status) query.status = filter.status;
7731
+ if (filter?.workflowId) query["target.workflowId"] = filter.workflowId;
7732
+ const collection = await this.getSchedulesCollection();
7733
+ const docs = await collection.find(query).sort({ created_at: 1 }).toArray();
7734
+ return docs.map(docToSchedule);
7735
+ }
7736
+ async listDueSchedules(now, limit) {
7737
+ const cap = limit ?? 100;
7738
+ const collection = await this.getSchedulesCollection();
7739
+ const docs = await collection.find({ status: "active", next_fire_at: { $lte: now } }).sort({ next_fire_at: 1 }).limit(cap).toArray();
7740
+ return docs.map(docToSchedule);
7741
+ }
7742
+ async updateSchedule(id, patch) {
7743
+ const $set = {};
7744
+ if ("cron" in patch && patch.cron !== void 0) $set.cron = patch.cron;
7745
+ if ("timezone" in patch) $set.timezone = patch.timezone ?? null;
7746
+ if ("status" in patch && patch.status !== void 0) $set.status = patch.status;
7747
+ if ("nextFireAt" in patch && patch.nextFireAt !== void 0) $set.next_fire_at = patch.nextFireAt;
7748
+ if ("target" in patch && patch.target !== void 0) $set.target = patch.target;
7749
+ if ("metadata" in patch) $set.metadata = patch.metadata ?? null;
7750
+ $set.updated_at = Date.now();
7751
+ const collection = await this.getSchedulesCollection();
7752
+ const result = await collection.findOneAndUpdate({ id }, { $set }, { returnDocument: "after" });
7753
+ if (!result) throw new Error(`Schedule ${id} not found`);
7754
+ return docToSchedule(result);
7755
+ }
7756
+ async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
7757
+ const collection = await this.getSchedulesCollection();
7758
+ const result = await collection.updateOne(
7759
+ { id, next_fire_at: expectedNextFireAt, status: "active" },
7760
+ {
7761
+ $set: {
7762
+ next_fire_at: newNextFireAt,
7763
+ last_fire_at: lastFireAt,
7764
+ last_run_id: lastRunId,
7765
+ updated_at: Date.now()
7766
+ }
7767
+ }
7768
+ );
7769
+ return result.matchedCount > 0;
7770
+ }
7771
+ async deleteSchedule(id) {
7772
+ const triggers = await this.getTriggersCollection();
7773
+ await triggers.deleteMany({ schedule_id: id });
7774
+ const schedules = await this.getSchedulesCollection();
7775
+ await schedules.deleteOne({ id });
7776
+ }
7777
+ async recordTrigger(trigger) {
7778
+ const collection = await this.getTriggersCollection();
7779
+ await collection.insertOne(triggerToDoc(trigger));
7780
+ }
7781
+ async listTriggers(scheduleId, opts) {
7782
+ const query = { schedule_id: scheduleId };
7783
+ if (opts?.fromActualFireAt != null || opts?.toActualFireAt != null) {
7784
+ const range = {};
7785
+ if (opts?.fromActualFireAt != null) range.$gte = opts.fromActualFireAt;
7786
+ if (opts?.toActualFireAt != null) range.$lt = opts.toActualFireAt;
7787
+ query.actual_fire_at = range;
7788
+ }
7789
+ const collection = await this.getTriggersCollection();
7790
+ let cursor = collection.find(query).sort({ actual_fire_at: -1 });
7791
+ if (opts?.limit != null) {
7792
+ cursor = cursor.limit(Math.floor(opts.limit));
7793
+ }
7794
+ const docs = await cursor.toArray();
7795
+ return docs.map(docToTrigger);
7796
+ }
7797
+ };
7598
7798
  var SNAPSHOT_FIELDS5 = [
7599
7799
  "name",
7600
7800
  "description",
@@ -10107,6 +10307,7 @@ var MongoDBStore = class extends storage.MastraCompositeStore {
10107
10307
  const datasets = new MongoDBDatasetsStorage(domainConfig);
10108
10308
  const experiments = new MongoDBExperimentsStorage(domainConfig);
10109
10309
  const backgroundTasks = new BackgroundTasksStorageMongoDB(domainConfig);
10310
+ const schedules = new SchedulesMongoDB(domainConfig);
10110
10311
  this.stores = {
10111
10312
  memory,
10112
10313
  scores,
@@ -10122,7 +10323,8 @@ var MongoDBStore = class extends storage.MastraCompositeStore {
10122
10323
  blobs,
10123
10324
  backgroundTasks,
10124
10325
  datasets,
10125
- experiments
10326
+ experiments,
10327
+ schedules
10126
10328
  };
10127
10329
  }
10128
10330
  /**
@@ -10257,6 +10459,7 @@ exports.MongoDBStore = MongoDBStore;
10257
10459
  exports.MongoDBVector = MongoDBVector;
10258
10460
  exports.MongoDBWorkspacesStorage = MongoDBWorkspacesStorage;
10259
10461
  exports.ObservabilityMongoDB = ObservabilityMongoDB;
10462
+ exports.SchedulesMongoDB = SchedulesMongoDB;
10260
10463
  exports.ScoresStorageMongoDB = ScoresStorageMongoDB;
10261
10464
  exports.WorkflowsStorageMongoDB = WorkflowsStorageMongoDB;
10262
10465
  //# sourceMappingURL=index.cjs.map