@mastra/mongodb 0.10.3-alpha.0 → 0.10.3-alpha.1

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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/mongodb@0.10.3-alpha.0 build /home/runner/work/mastra/mastra/stores/mongodb
2
+ > @mastra/mongodb@0.10.3-alpha.1 build /home/runner/work/mastra/mastra/stores/mongodb
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 9251ms
9
+ TSC ⚡️ Build success in 8770ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 12497ms
16
+ DTS ⚡️ Build success in 11972ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 33.58 KB
21
- CJS ⚡️ Build success in 1142ms
22
- ESM dist/index.js 33.45 KB
23
- ESM ⚡️ Build success in 1142ms
20
+ CJS dist/index.cjs 33.85 KB
21
+ CJS ⚡️ Build success in 1239ms
22
+ ESM dist/index.js 33.73 KB
23
+ ESM ⚡️ Build success in 1239ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 0.10.3-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 925ab94: added paginated functions to base class and added boilerplate and updated imports
8
+ - Updated dependencies [925ab94]
9
+ - @mastra/core@0.10.4-alpha.3
10
+
3
11
  ## 0.10.3-alpha.0
4
12
 
5
13
  ### Patch Changes
@@ -11,12 +11,15 @@ import { MastraStorage } from '@mastra/core/storage';
11
11
  import { MastraVector } from '@mastra/core/vector';
12
12
  import type { MongoClientOptions } from 'mongodb';
13
13
  import type { OperatorSupport } from '@mastra/core/vector/filter';
14
+ import type { PaginationInfo } from '@mastra/core/storage';
14
15
  import type { QueryResult } from '@mastra/core/vector';
15
16
  import type { QueryVectorParams } from '@mastra/core/vector';
16
17
  import type { StorageColumn } from '@mastra/core/storage';
17
18
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
19
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
18
20
  import type { StorageThreadType } from '@mastra/core/memory';
19
21
  import type { TABLE_NAMES } from '@mastra/core/storage';
22
+ import type { Trace } from '@mastra/core/telemetry';
20
23
  import type { UpdateVectorParams } from '@mastra/core/vector';
21
24
  import type { UpsertVectorParams } from '@mastra/core/vector';
22
25
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -170,6 +173,19 @@ declare class MongoDBStore extends MastraStorage {
170
173
  private parseWorkflowRun;
171
174
  private parseRow;
172
175
  private transformEvalRow;
176
+ getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
177
+ traces: Trace[];
178
+ }>;
179
+ getThreadsByResourceIdPaginated(_args: {
180
+ resourceId: string;
181
+ page?: number;
182
+ perPage?: number;
183
+ }): Promise<PaginationInfo & {
184
+ threads: StorageThreadType[];
185
+ }>;
186
+ getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
187
+ messages: MastraMessageV1[] | MastraMessageV2[];
188
+ }>;
173
189
  close(): Promise<void>;
174
190
  }
175
191
  export { MongoDBStore }
@@ -11,12 +11,15 @@ import { MastraStorage } from '@mastra/core/storage';
11
11
  import { MastraVector } from '@mastra/core/vector';
12
12
  import type { MongoClientOptions } from 'mongodb';
13
13
  import type { OperatorSupport } from '@mastra/core/vector/filter';
14
+ import type { PaginationInfo } from '@mastra/core/storage';
14
15
  import type { QueryResult } from '@mastra/core/vector';
15
16
  import type { QueryVectorParams } from '@mastra/core/vector';
16
17
  import type { StorageColumn } from '@mastra/core/storage';
17
18
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
19
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
18
20
  import type { StorageThreadType } from '@mastra/core/memory';
19
21
  import type { TABLE_NAMES } from '@mastra/core/storage';
22
+ import type { Trace } from '@mastra/core/telemetry';
20
23
  import type { UpdateVectorParams } from '@mastra/core/vector';
21
24
  import type { UpsertVectorParams } from '@mastra/core/vector';
22
25
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -170,6 +173,19 @@ declare class MongoDBStore extends MastraStorage {
170
173
  private parseWorkflowRun;
171
174
  private parseRow;
172
175
  private transformEvalRow;
176
+ getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
177
+ traces: Trace[];
178
+ }>;
179
+ getThreadsByResourceIdPaginated(_args: {
180
+ resourceId: string;
181
+ page?: number;
182
+ perPage?: number;
183
+ }): Promise<PaginationInfo & {
184
+ threads: StorageThreadType[];
185
+ }>;
186
+ getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
187
+ messages: MastraMessageV1[] | MastraMessageV2[];
188
+ }>;
173
189
  close(): Promise<void>;
174
190
  }
175
191
  export { MongoDBStore }
package/dist/index.cjs CHANGED
@@ -938,6 +938,15 @@ var MongoDBStore = class extends storage.MastraStorage {
938
938
  createdAt: row.created_at
939
939
  };
940
940
  }
941
+ async getTracesPaginated(_args) {
942
+ throw new Error("Method not implemented.");
943
+ }
944
+ async getThreadsByResourceIdPaginated(_args) {
945
+ throw new Error("Method not implemented.");
946
+ }
947
+ async getMessagesPaginated(_args) {
948
+ throw new Error("Method not implemented.");
949
+ }
941
950
  async close() {
942
951
  await this.#client.close();
943
952
  }
package/dist/index.js CHANGED
@@ -936,6 +936,15 @@ var MongoDBStore = class extends MastraStorage {
936
936
  createdAt: row.created_at
937
937
  };
938
938
  }
939
+ async getTracesPaginated(_args) {
940
+ throw new Error("Method not implemented.");
941
+ }
942
+ async getThreadsByResourceIdPaginated(_args) {
943
+ throw new Error("Method not implemented.");
944
+ }
945
+ async getMessagesPaginated(_args) {
946
+ throw new Error("Method not implemented.");
947
+ }
939
948
  async close() {
940
949
  await this.#client.close();
941
950
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mongodb",
3
- "version": "0.10.3-alpha.0",
3
+ "version": "0.10.3-alpha.1",
4
4
  "description": "MongoDB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,9 +31,9 @@
31
31
  "tsup": "^8.5.0",
32
32
  "typescript": "^5.8.2",
33
33
  "vitest": "^3.2.2",
34
- "@internal/storage-test-utils": "0.0.6",
35
34
  "@internal/lint": "0.0.10",
36
- "@mastra/core": "0.10.4-alpha.1"
35
+ "@mastra/core": "0.10.4-alpha.3",
36
+ "@internal/storage-test-utils": "0.0.6"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@mastra/core": "^0.10.2-alpha.0"
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from 'crypto';
2
- import type { MastraMessageV1, MetricResult, WorkflowRunState } from '@mastra/core';
2
+ import type { MastraMessageV1, MastraMessageV2, MetricResult, WorkflowRunState } from '@mastra/core';
3
3
  import type { TABLE_NAMES } from '@mastra/core/storage';
4
4
  import { TABLE_EVALS, TABLE_MESSAGES, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
5
5
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
@@ -41,15 +41,46 @@ class Test {
41
41
  };
42
42
  }
43
43
 
44
- generateSampleMessage(threadId: string): MastraMessageV1 {
44
+ generateSampleMessageV1({
45
+ threadId,
46
+ resourceId = randomUUID(),
47
+ content = 'Hello',
48
+ }: {
49
+ threadId: string;
50
+ resourceId?: string;
51
+ content?: string;
52
+ }): MastraMessageV1 {
45
53
  return {
46
54
  id: `msg-${randomUUID()}`,
47
55
  role: 'user',
48
56
  type: 'text',
49
57
  threadId,
50
- content: [{ type: 'text', text: 'Hello' }],
58
+ content: [{ type: 'text', text: content }],
51
59
  createdAt: new Date(),
52
- resourceId: randomUUID(),
60
+ resourceId,
61
+ };
62
+ }
63
+
64
+ generateSampleMessageV2({
65
+ threadId,
66
+ resourceId = randomUUID(),
67
+ content = 'Hello',
68
+ }: {
69
+ threadId: string;
70
+ resourceId?: string;
71
+ content?: string;
72
+ }): MastraMessageV2 {
73
+ return {
74
+ id: `msg-${randomUUID()}`,
75
+ role: 'user',
76
+ type: 'text',
77
+ threadId,
78
+ content: {
79
+ format: 2,
80
+ parts: [{ type: 'text', text: content }],
81
+ },
82
+ createdAt: new Date(),
83
+ resourceId,
53
84
  };
54
85
  }
55
86
 
@@ -203,11 +234,8 @@ describe('MongoDBStore', () => {
203
234
 
204
235
  // Add some messages
205
236
  const messages = [
206
- test.generateSampleMessage(thread.id),
207
- {
208
- ...test.generateSampleMessage(thread.id),
209
- role: 'assistant' as const,
210
- },
237
+ test.generateSampleMessageV1({ threadId: thread.id }),
238
+ test.generateSampleMessageV1({ threadId: thread.id }),
211
239
  ];
212
240
  await store.saveMessages({ messages });
213
241
 
@@ -253,8 +281,8 @@ describe('MongoDBStore', () => {
253
281
  await store.saveThread({ thread });
254
282
 
255
283
  const messages = [
256
- test.generateSampleMessage(thread.id),
257
- { ...test.generateSampleMessage(thread.id), role: 'assistant' as const },
284
+ test.generateSampleMessageV1({ threadId: thread.id }),
285
+ { ...test.generateSampleMessageV1({ threadId: thread.id }), role: 'assistant' as const },
258
286
  ];
259
287
 
260
288
  // Save messages
@@ -284,30 +312,129 @@ describe('MongoDBStore', () => {
284
312
 
285
313
  const messages = [
286
314
  {
287
- ...test.generateSampleMessage(thread.id),
288
- content: [{ type: 'text', text: 'First' }] satisfies MastraMessageV1['content'],
315
+ ...test.generateSampleMessageV2({ threadId: thread.id, content: 'First' }),
289
316
  },
290
317
  {
291
- ...test.generateSampleMessage(thread.id),
292
- role: 'assistant' as const,
293
- content: [{ type: 'text', text: 'Second' }] satisfies MastraMessageV1['content'],
318
+ ...test.generateSampleMessageV2({ threadId: thread.id, content: 'Second' }),
294
319
  },
295
320
  {
296
- ...test.generateSampleMessage(thread.id),
297
- content: [{ type: 'text', text: 'Third' }] satisfies MastraMessageV1['content'],
321
+ ...test.generateSampleMessageV2({ threadId: thread.id, content: 'Third' }),
298
322
  },
299
323
  ];
300
324
 
301
- await store.saveMessages({ messages, format: 'v1' });
325
+ await store.saveMessages({ messages, format: 'v2' });
302
326
 
303
- const retrievedMessages = await store.getMessages({ threadId: thread.id, format: 'v1' });
327
+ const retrievedMessages = await store.getMessages({ threadId: thread.id, format: 'v2' });
304
328
  expect(retrievedMessages).toHaveLength(3);
305
329
 
306
330
  // Verify order is maintained
307
331
  retrievedMessages.forEach((msg, idx) => {
308
- expect(((msg as any).content[0] as any).text).toBe((messages[idx]!.content[0] as any).text);
332
+ expect((msg as any).content.parts).toEqual(messages[idx]!.content.parts);
309
333
  });
310
334
  });
335
+
336
+ // it('should retrieve messages w/ next/prev messages by message id + resource id', async () => {
337
+ // const test = new Test(store).build();
338
+ // const messages: MastraMessageV2[] = [
339
+ // test.generateSampleMessageV2({ threadId: 'thread-one', content: 'First', resourceId: 'cross-thread-resource' }),
340
+ // test.generateSampleMessageV2({
341
+ // threadId: 'thread-one',
342
+ // content: 'Second',
343
+ // resourceId: 'cross-thread-resource',
344
+ // }),
345
+ // test.generateSampleMessageV2({ threadId: 'thread-one', content: 'Third', resourceId: 'cross-thread-resource' }),
346
+
347
+ // test.generateSampleMessageV2({
348
+ // threadId: 'thread-two',
349
+ // content: 'Fourth',
350
+ // resourceId: 'cross-thread-resource',
351
+ // }),
352
+ // test.generateSampleMessageV2({ threadId: 'thread-two', content: 'Fifth', resourceId: 'cross-thread-resource' }),
353
+ // test.generateSampleMessageV2({ threadId: 'thread-two', content: 'Sixth', resourceId: 'cross-thread-resource' }),
354
+
355
+ // test.generateSampleMessageV2({ threadId: 'thread-three', content: 'Seventh', resourceId: 'other-resource' }),
356
+ // test.generateSampleMessageV2({ threadId: 'thread-three', content: 'Eighth', resourceId: 'other-resource' }),
357
+ // ];
358
+
359
+ // await store.saveMessages({ messages: messages, format: 'v2' });
360
+
361
+ // const retrievedMessages: MastraMessageV2[] = await store.getMessages({ threadId: 'thread-one', format: 'v2' });
362
+ // expect(retrievedMessages).toHaveLength(3);
363
+ // expect(retrievedMessages.map(m => (m.content.parts[0] as any).text)).toEqual(['First', 'Second', 'Third']);
364
+
365
+ // const retrievedMessages2: MastraMessageV2[] = await store.getMessages({ threadId: 'thread-two', format: 'v2' });
366
+ // expect(retrievedMessages2).toHaveLength(3);
367
+ // expect(retrievedMessages2.map(m => (m.content.parts[0] as any).text)).toEqual(['Fourth', 'Fifth', 'Sixth']);
368
+
369
+ // const retrievedMessages3: MastraMessageV2[] = await store.getMessages({ threadId: 'thread-three', format: 'v2' });
370
+ // expect(retrievedMessages3).toHaveLength(2);
371
+ // expect(retrievedMessages3.map(m => (m.content.parts[0] as any).text)).toEqual(['Seventh', 'Eighth']);
372
+
373
+ // const crossThreadMessages: MastraMessageV2[] = await store.getMessages({
374
+ // threadId: 'thread-doesnt-exist',
375
+ // resourceId: 'cross-thread-resource',
376
+ // format: 'v2',
377
+ // selectBy: {
378
+ // last: 0,
379
+ // include: [
380
+ // {
381
+ // id: messages[1].id,
382
+ // withNextMessages: 2,
383
+ // withPreviousMessages: 2,
384
+ // },
385
+ // {
386
+ // id: messages[4].id,
387
+ // withPreviousMessages: 2,
388
+ // withNextMessages: 2,
389
+ // },
390
+ // ],
391
+ // },
392
+ // });
393
+
394
+ // expect(crossThreadMessages).toHaveLength(6);
395
+ // expect(crossThreadMessages.filter(m => m.threadId === `thread-one`)).toHaveLength(3);
396
+ // expect(crossThreadMessages.filter(m => m.threadId === `thread-two`)).toHaveLength(3);
397
+
398
+ // const crossThreadMessages2: MastraMessageV2[] = await store.getMessages({
399
+ // threadId: 'thread-one',
400
+ // resourceId: 'cross-thread-resource',
401
+ // format: 'v2',
402
+ // selectBy: {
403
+ // last: 0,
404
+ // include: [
405
+ // {
406
+ // id: messages[4].id,
407
+ // withPreviousMessages: 1,
408
+ // withNextMessages: 30,
409
+ // },
410
+ // ],
411
+ // },
412
+ // });
413
+
414
+ // expect(crossThreadMessages2).toHaveLength(3);
415
+ // expect(crossThreadMessages2.filter(m => m.threadId === `thread-one`)).toHaveLength(0);
416
+ // expect(crossThreadMessages2.filter(m => m.threadId === `thread-two`)).toHaveLength(3);
417
+
418
+ // const crossThreadMessages3: MastraMessageV2[] = await store.getMessages({
419
+ // threadId: 'thread-two',
420
+ // resourceId: 'cross-thread-resource',
421
+ // format: 'v2',
422
+ // selectBy: {
423
+ // last: 0,
424
+ // include: [
425
+ // {
426
+ // id: messages[1].id,
427
+ // withNextMessages: 1,
428
+ // withPreviousMessages: 1,
429
+ // },
430
+ // ],
431
+ // },
432
+ // });
433
+
434
+ // expect(crossThreadMessages3).toHaveLength(3);
435
+ // expect(crossThreadMessages3.filter(m => m.threadId === `thread-one`)).toHaveLength(3);
436
+ // expect(crossThreadMessages3.filter(m => m.threadId === `thread-two`)).toHaveLength(0);
437
+ // });
311
438
  });
312
439
 
313
440
  describe('Edge Cases and Error Handling', () => {
@@ -1,7 +1,15 @@
1
1
  import { MessageList } from '@mastra/core/agent';
2
2
  import type { MetricResult, TestInfo } from '@mastra/core/eval';
3
3
  import type { MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastra/core/memory';
4
- import type { EvalRow, StorageColumn, StorageGetMessagesArg, TABLE_NAMES, WorkflowRun } from '@mastra/core/storage';
4
+ import type {
5
+ EvalRow,
6
+ PaginationInfo,
7
+ StorageColumn,
8
+ StorageGetMessagesArg,
9
+ StorageGetTracesArg,
10
+ TABLE_NAMES,
11
+ WorkflowRun,
12
+ } from '@mastra/core/storage';
5
13
  import {
6
14
  MastraStorage,
7
15
  TABLE_EVALS,
@@ -10,6 +18,7 @@ import {
10
18
  TABLE_TRACES,
11
19
  TABLE_WORKFLOW_SNAPSHOT,
12
20
  } from '@mastra/core/storage';
21
+ import type { Trace } from '@mastra/core/telemetry';
13
22
  import type { WorkflowRunState } from '@mastra/core/workflows';
14
23
  import type { Db, MongoClientOptions } from 'mongodb';
15
24
  import { MongoClient } from 'mongodb';
@@ -704,6 +713,24 @@ export class MongoDBStore extends MastraStorage {
704
713
  };
705
714
  }
706
715
 
716
+ async getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & { traces: Trace[] }> {
717
+ throw new Error('Method not implemented.');
718
+ }
719
+
720
+ async getThreadsByResourceIdPaginated(_args: {
721
+ resourceId: string;
722
+ page?: number;
723
+ perPage?: number;
724
+ }): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
725
+ throw new Error('Method not implemented.');
726
+ }
727
+
728
+ async getMessagesPaginated(
729
+ _args: StorageGetMessagesArg,
730
+ ): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
731
+ throw new Error('Method not implemented.');
732
+ }
733
+
707
734
  async close(): Promise<void> {
708
735
  await this.#client.close();
709
736
  }