@mastra/mongodb 0.12.4 → 0.13.0-alpha.2

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,6 +1,6 @@
1
1
  import { MongoClient } from 'mongodb';
2
- import type { ConnectorHandler } from './connectors/base';
3
- import type { DatabaseConfig } from './types';
2
+ import type { ConnectorHandler } from './connectors/base.js';
3
+ import type { DatabaseConfig } from './types.js';
4
4
  type MongoDBConnectorOptions = {
5
5
  client: MongoClient;
6
6
  dbName: string;
@@ -1,6 +1,6 @@
1
1
  import { MongoClient } from 'mongodb';
2
- import type { DatabaseConfig } from '../types';
3
- import type { ConnectorHandler } from './base';
2
+ import type { DatabaseConfig } from '../types.js';
3
+ import type { ConnectorHandler } from './base.js';
4
4
  type MongoDBConnectorOptions = {
5
5
  client: MongoClient;
6
6
  dbName: string;
@@ -1,6 +1,6 @@
1
1
  import { LegacyEvalsStorage } from '@mastra/core/storage';
2
2
  import type { PaginationArgs, PaginationInfo, EvalRow } from '@mastra/core/storage';
3
- import type { StoreOperationsMongoDB } from '../operations';
3
+ import type { StoreOperationsMongoDB } from '../operations/index.js';
4
4
  export declare class LegacyEvalsMongoDB extends LegacyEvalsStorage {
5
5
  private operations;
6
6
  constructor({ operations }: {
@@ -2,7 +2,7 @@ import type { MastraMessageContentV2 } from '@mastra/core/agent';
2
2
  import type { MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastra/core/memory';
3
3
  import { MemoryStorage } from '@mastra/core/storage';
4
4
  import type { PaginationInfo, StorageGetMessagesArg, StorageResourceType } from '@mastra/core/storage';
5
- import type { StoreOperationsMongoDB } from '../operations';
5
+ import type { StoreOperationsMongoDB } from '../operations/index.js';
6
6
  export declare class MemoryStorageMongoDB extends MemoryStorage {
7
7
  private operations;
8
8
  constructor({ operations }: {
@@ -1,6 +1,6 @@
1
1
  import { StoreOperations } from '@mastra/core/storage';
2
2
  import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
3
- import type { ConnectorHandler } from '../../connectors/base';
3
+ import type { ConnectorHandler } from '../../connectors/base.js';
4
4
  export interface MongoDBOperationsConfig {
5
5
  connector: ConnectorHandler;
6
6
  }
@@ -1,7 +1,7 @@
1
1
  import type { ScoreRowData } from '@mastra/core/scores';
2
2
  import { ScoresStorage } from '@mastra/core/storage';
3
3
  import type { PaginationInfo, StoragePagination } from '@mastra/core/storage';
4
- import type { StoreOperationsMongoDB } from '../operations';
4
+ import type { StoreOperationsMongoDB } from '../operations/index.js';
5
5
  export declare class ScoresStorageMongoDB extends ScoresStorage {
6
6
  private operations;
7
7
  constructor({ operations }: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAkC,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAiG5D,qBAAa,oBAAqB,SAAQ,aAAa;IACrD,OAAO,CAAC,UAAU,CAAyB;gBAE/B,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,sBAAsB,CAAA;KAAE;IAK5D,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAuBlE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IA+DxG,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,GACX,EAAE;QACD,QAAQ,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AE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAuBlE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IAiExG,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,GACX,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IA4D7D,gBAAgB,CAAC,EACrB,KAAK,EACL,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAkD7D,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,UAAU,GACX,EAAE;QACD,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CAiDpE"}
@@ -1,7 +1,7 @@
1
1
  import type { PaginationInfo, StorageGetTracesArg, StorageGetTracesPaginatedArg } from '@mastra/core/storage';
2
2
  import { TracesStorage } from '@mastra/core/storage';
3
3
  import type { Trace } from '@mastra/core/telemetry';
4
- import type { StoreOperationsMongoDB } from '../operations';
4
+ import type { StoreOperationsMongoDB } from '../operations/index.js';
5
5
  export declare class TracesStorageMongoDB extends TracesStorage {
6
6
  private operations;
7
7
  constructor({ operations }: {
@@ -1,7 +1,7 @@
1
1
  import { WorkflowsStorage } from '@mastra/core/storage';
2
2
  import type { WorkflowRun, WorkflowRuns } from '@mastra/core/storage';
3
3
  import type { WorkflowRunState } from '@mastra/core/workflows';
4
- import type { StoreOperationsMongoDB } from '../operations';
4
+ import type { StoreOperationsMongoDB } from '../operations/index.js';
5
5
  export declare class WorkflowsStorageMongoDB extends WorkflowsStorage {
6
6
  private operations;
7
7
  constructor({ operations }: {
@@ -5,7 +5,7 @@ import type { EvalRow, PaginationArgs, PaginationInfo, StorageColumn, StorageDom
5
5
  import { MastraStorage } from '@mastra/core/storage';
6
6
  import type { Trace } from '@mastra/core/telemetry';
7
7
  import type { WorkflowRunState } from '@mastra/core/workflows';
8
- import type { MongoDBConfig } from './types';
8
+ import type { MongoDBConfig } from './types.js';
9
9
  export declare class MongoDBStore extends MastraStorage {
10
10
  #private;
11
11
  stores: StorageDomains;
@@ -1,5 +1,5 @@
1
1
  import type { MongoClientOptions } from 'mongodb';
2
- import type { ConnectorHandler } from './connectors/base';
2
+ import type { ConnectorHandler } from './connectors/base.js';
3
3
  export type MongoDBConfig = DatabaseConfig | {
4
4
  connectorHandler: ConnectorHandler;
5
5
  };
@@ -1,7 +1,7 @@
1
1
  import { MastraVector } from '@mastra/core/vector';
2
2
  import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
3
3
  import type { MongoClientOptions } from 'mongodb';
4
- import type { MongoDBVectorFilter } from './filter';
4
+ import type { MongoDBVectorFilter } from './filter.js';
5
5
  export interface MongoDBUpsertVectorParams extends UpsertVectorParams {
6
6
  documents?: string[];
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mongodb",
3
- "version": "0.12.4",
3
+ "version": "0.13.0-alpha.2",
4
4
  "description": "MongoDB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "default": "./dist/index.js"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/index.d.cts",
15
+ "types": "./dist/index.d.ts",
16
16
  "default": "./dist/index.cjs"
17
17
  }
18
18
  },
@@ -31,12 +31,13 @@
31
31
  "tsup": "^8.5.0",
32
32
  "typescript": "^5.8.3",
33
33
  "vitest": "^3.2.4",
34
- "@mastra/core": "0.12.1",
35
- "@internal/lint": "0.0.25",
36
- "@internal/storage-test-utils": "0.0.21"
34
+ "@internal/lint": "0.0.26",
35
+ "@internal/storage-test-utils": "0.0.22",
36
+ "@internal/types-builder": "0.0.1",
37
+ "@mastra/core": "0.13.0-alpha.2"
37
38
  },
38
39
  "peerDependencies": {
39
- "@mastra/core": ">=0.10.7-0 <0.13.0-0"
40
+ "@mastra/core": ">=0.13.0-0 <0.14.0-0"
40
41
  },
41
42
  "scripts": {
42
43
  "build": "tsup --silent --config tsup.config.ts",
@@ -14,13 +14,15 @@ function transformScoreRow(row: Record<string, any>): ScoreRowData {
14
14
  }
15
15
  }
16
16
 
17
- let extractStepResultValue: any = null;
18
- if (row.extractStepResult) {
17
+ let preprocessStepResultValue: any = null;
18
+ if (row.preprocessStepResult) {
19
19
  try {
20
- extractStepResultValue =
21
- typeof row.extractStepResult === 'string' ? safelyParseJSON(row.extractStepResult) : row.extractStepResult;
20
+ preprocessStepResultValue =
21
+ typeof row.preprocessStepResult === 'string'
22
+ ? safelyParseJSON(row.preprocessStepResult)
23
+ : row.preprocessStepResult;
22
24
  } catch (e) {
23
- console.warn('Failed to parse extractStepResult:', e);
25
+ console.warn('Failed to parse preprocessStepResult:', e);
24
26
  }
25
27
  }
26
28
 
@@ -79,7 +81,7 @@ function transformScoreRow(row: Record<string, any>): ScoreRowData {
79
81
  traceId: row.traceId as string,
80
82
  runId: row.runId as string,
81
83
  scorer: scorerValue,
82
- extractStepResult: extractStepResultValue,
84
+ preprocessStepResult: preprocessStepResultValue,
83
85
  analyzeStepResult: analyzeStepResultValue,
84
86
  score: row.score as number,
85
87
  reason: row.reason as string,
@@ -143,17 +145,19 @@ export class ScoresStorageMongoDB extends ScoresStorage {
143
145
  traceId: score.traceId || '',
144
146
  runId: score.runId,
145
147
  scorer: typeof score.scorer === 'string' ? safelyParseJSON(score.scorer) : score.scorer,
146
- extractStepResult:
147
- typeof score.extractStepResult === 'string'
148
- ? safelyParseJSON(score.extractStepResult)
149
- : score.extractStepResult,
148
+ preprocessStepResult:
149
+ typeof score.preprocessStepResult === 'string'
150
+ ? safelyParseJSON(score.preprocessStepResult)
151
+ : score.preprocessStepResult,
150
152
  analyzeStepResult:
151
153
  typeof score.analyzeStepResult === 'string'
152
154
  ? safelyParseJSON(score.analyzeStepResult)
153
155
  : score.analyzeStepResult,
154
156
  score: score.score,
155
157
  reason: score.reason,
156
- extractPrompt: score.extractPrompt,
158
+ preprocessPrompt: score.preprocessPrompt,
159
+ generateScorePrompt: score.generateScorePrompt,
160
+ generateReasonPrompt: score.generateReasonPrompt,
157
161
  analyzePrompt: score.analyzePrompt,
158
162
  reasonPrompt: score.reasonPrompt,
159
163
  input: typeof score.input === 'string' ? safelyParseJSON(score.input) : score.input,
@@ -103,13 +103,13 @@ export class TracesStorageMongoDB extends TracesStorage {
103
103
  name: row.name,
104
104
  scope: row.scope,
105
105
  kind: row.kind,
106
- status: safelyParseJSON(row.status as string),
107
- events: safelyParseJSON(row.events as string),
108
- links: safelyParseJSON(row.links as string),
109
- attributes: safelyParseJSON(row.attributes as string),
106
+ status: safelyParseJSON(row.status),
107
+ events: safelyParseJSON(row.events),
108
+ links: safelyParseJSON(row.links),
109
+ attributes: safelyParseJSON(row.attributes),
110
110
  startTime: row.startTime,
111
111
  endTime: row.endTime,
112
- other: safelyParseJSON(row.other as string),
112
+ other: safelyParseJSON(row.other),
113
113
  createdAt: row.createdAt,
114
114
  })) as Trace[];
115
115
 
@@ -93,6 +93,7 @@ describe('MongoDBVector Integration Tests', () => {
93
93
  let vectorDB: MongoDBVector;
94
94
  const testIndexName = 'my_vectors';
95
95
  const testIndexName2 = 'my_vectors_2';
96
+ const emptyIndexName = 'empty-index';
96
97
 
97
98
  beforeAll(async () => {
98
99
  vectorDB = new MongoDBVector({ uri, dbName });
@@ -114,6 +115,7 @@ describe('MongoDBVector Integration Tests', () => {
114
115
 
115
116
  await createIndexAndWait(vectorDB, testIndexName, 4, 'cosine');
116
117
  await createIndexAndWait(vectorDB, testIndexName2, 4, 'cosine');
118
+ await createIndexAndWait(vectorDB, emptyIndexName, 4, 'cosine');
117
119
  }, 500000);
118
120
 
119
121
  afterAll(async () => {
@@ -127,6 +129,11 @@ describe('MongoDBVector Integration Tests', () => {
127
129
  } catch (error) {
128
130
  console.error('Failed to delete test collection:', error);
129
131
  }
132
+ try {
133
+ await vectorDB.deleteIndex({ indexName: emptyIndexName });
134
+ } catch (error) {
135
+ console.error('Failed to delete test collection:', error);
136
+ }
130
137
  await vectorDB.disconnect();
131
138
  });
132
139
 
@@ -482,5 +489,29 @@ describe('MongoDBVector Integration Tests', () => {
482
489
  const invalidVector = [1, 2, 3]; // 3D vector for 4D index
483
490
  await expect(vectorDB.upsert({ indexName: testIndexName, vectors: [invalidVector] })).rejects.toThrow();
484
491
  });
492
+ it('should return empty results and not throw when semantic search filter matches zero documents', async () => {
493
+ // Use a valid embedding vector matching your test index dimension
494
+ const testEmbedding = [0.1, 0.2, 0.3, 0.4]; // Adjust dimension as needed
495
+
496
+ // Should not throw, should return an empty array
497
+ let error: unknown = null;
498
+ let results: any[] = [];
499
+ try {
500
+ results = await vectorDB.query({
501
+ indexName: emptyIndexName,
502
+ queryVector: testEmbedding,
503
+ topK: 2,
504
+ filter: {
505
+ 'metadata.label': 'test_filter_validation',
506
+ },
507
+ });
508
+ } catch (e) {
509
+ error = e;
510
+ }
511
+
512
+ expect(error).toBeNull();
513
+ expect(Array.isArray(results)).toBe(true);
514
+ expect(results.length).toBe(0);
515
+ });
485
516
  });
486
517
  });
package/tsup.config.ts CHANGED
@@ -1,9 +1,6 @@
1
- import { spawn } from 'child_process';
2
- import { promisify } from 'util';
1
+ import { generateTypes } from '@internal/types-builder';
3
2
  import { defineConfig } from 'tsup';
4
3
 
5
- const exec = promisify(spawn);
6
-
7
4
  export default defineConfig({
8
5
  entry: ['src/index.ts'],
9
6
  format: ['esm', 'cjs'],
@@ -15,8 +12,6 @@ export default defineConfig({
15
12
  },
16
13
  sourcemap: true,
17
14
  onSuccess: async () => {
18
- await exec('pnpm', ['tsc', '-p', 'tsconfig.build.json'], {
19
- stdio: 'inherit',
20
- });
15
+ await generateTypes(process.cwd());
21
16
  },
22
17
  });