@kiyeonjeon21/datacontext 0.4.0 → 0.5.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/.cursorrules CHANGED
@@ -86,6 +86,38 @@ REST API/MCP Tool 변경 시 아래 파일들도 확인:
86
86
  - `vscode-datacontext/README.md` — 문서
87
87
  - 자세한 내용: `docs/SYNC_GUIDE.md`
88
88
 
89
+ ## 🔴 Version Management (CRITICAL)
90
+
91
+ ### 버전 변경 시 반드시 업데이트할 파일들
92
+ 버전을 올릴 때 **모든 파일을 동시에** 업데이트하세요:
93
+
94
+ | 파일 | 위치 | 예시 |
95
+ |------|------|------|
96
+ | `package.json` | `"version": "X.Y.Z"` | `"version": "0.4.1"` |
97
+ | `CHANGELOG.md` | `## [X.Y.Z] - YYYY-MM-DD` | `## [0.4.1] - 2026-01-01` |
98
+
99
+ ### 버전 올리기 체크리스트
100
+ ```bash
101
+ # 1. package.json 버전 업데이트
102
+ # 2. CHANGELOG.md에 새 버전 엔트리 추가 (맨 위에)
103
+ # 3. 빌드 및 테스트
104
+ npm run build && npm test
105
+
106
+ # 4. 배포
107
+ npm publish --access public
108
+ ```
109
+
110
+ ### CHANGELOG 규칙
111
+ - 버전 순서: 최신이 맨 위 (0.4.1 → 0.4.0 → 0.3.0 → ...)
112
+ - 누락된 버전 없이 연속적으로 유지
113
+ - 각 버전에 Added/Changed/Fixed/Removed 섹션 포함
114
+
115
+ ### ⚠️ 흔한 실수
116
+ - ❌ package.json만 올리고 CHANGELOG 누락
117
+ - ❌ CHANGELOG에 버전 순서 건너뛰기
118
+ - ❌ 배포 후 버전 업데이트
119
+ - ❌ VS Code Extension과 버전 싱크 누락 (별도 패키지지만 관련 변경 시 함께 배포)
120
+
89
121
  ## Testing
90
122
  ```bash
91
123
  npm test # Run all tests
package/CHANGELOG.md CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-01-01
11
+
12
+ ### Added
13
+ - **MongoDB Adapter**: Full support for MongoDB/NoSQL databases
14
+ - Schema inference from sample documents (auto-detects field types)
15
+ - Native MongoDB query execution (find, findOne, aggregate, count, distinct)
16
+ - Array and nested object type detection
17
+ - Collection indexing and statistics
18
+ - Connection string support: `mongodb://` and `mongodb+srv://`
19
+ - New CLI command: `datacontext connect mongodb://...`
20
+ - MongoDB support in REST API server
21
+ - Test suite for MongoDB adapter
22
+
23
+ ### Changed
24
+ - CLI now supports MongoDB connection strings
25
+ - Updated documentation to include MongoDB examples
26
+
27
+ ## [0.4.1] - 2026-01-01
28
+
29
+ ### Added
30
+ - **Relationships in Knowledge API**: `/api/knowledge` now includes `relationships` array
31
+ - All harvested FK relationships included in knowledge summary
32
+ - VS Code extension can now display relationships in Knowledge panel
33
+
34
+ ### Changed
35
+ - `KnowledgeSummary` type now includes `relationships` and `totalRelationships` stat
36
+
10
37
  ## [0.3.0] - 2025-01-01
11
38
 
12
39
  ### Added
package/README.md CHANGED
@@ -42,7 +42,7 @@ Every time you use AI to write SQL, you explain the same things:
42
42
  └─────────────────────────┬───────────────────────────────────────┘
43
43
 
44
44
  ┌─────────────────────────▼───────────────────────────────────────┐
45
- │ Your Database (PostgreSQL, MySQL, SQLite)
45
+ │ Your Database (PostgreSQL, MySQL, SQLite, MongoDB)
46
46
  └─────────────────────────────────────────────────────────────────┘
47
47
  ```
48
48
 
@@ -53,7 +53,7 @@ Every time you use AI to write SQL, you explain the same things:
53
53
  | Feature | Description |
54
54
  |---------|-------------|
55
55
  | 🔌 **MCP Protocol** | Works with Claude Desktop, Cursor IDE, and any MCP client |
56
- | 🗄️ **Multi-Database** | PostgreSQL, MySQL/MariaDB, SQLite |
56
+ | 🗄️ **Multi-Database** | PostgreSQL, MySQL/MariaDB, SQLite, MongoDB |
57
57
  | 🔒 **Safety First** | Read-only by default, query validation, timeout protection |
58
58
  | 📚 **Knowledge Layer** | Store descriptions, business rules, query examples |
59
59
  | 🤖 **AI Glossary** | Auto-generate business terms from natural language (requires Anthropic API key) |
@@ -352,9 +352,28 @@ await service.shutdown();
352
352
  | PostgreSQL | ✅ Full | `postgres://` |
353
353
  | MySQL/MariaDB | ✅ Full | `mysql://` |
354
354
  | SQLite | ✅ Full | `./file.sqlite` |
355
+ | MongoDB | ✅ Full | `mongodb://` |
355
356
  | BigQuery | 🔜 Planned | — |
356
357
  | Snowflake | 🔜 Planned | — |
357
358
 
359
+ ### MongoDB Support
360
+
361
+ MongoDB is schema-less, but DataContext infers schema from sample documents:
362
+
363
+ ```bash
364
+ # Connect to MongoDB
365
+ datacontext serve mongodb://user:pass@localhost:27017/mydb
366
+
367
+ # Or with authentication
368
+ datacontext serve "mongodb://user:pass@localhost:27017/mydb?authSource=admin"
369
+ ```
370
+
371
+ DataContext will:
372
+ - List all collections
373
+ - Infer field types from sample documents
374
+ - Detect nested objects and arrays
375
+ - Support native MongoDB queries (find, aggregate, etc.)
376
+
358
377
  ---
359
378
 
360
379
  ## License
@@ -0,0 +1,207 @@
1
+ /**
2
+ * MongoDB Database Adapter
3
+ * Implements DatabaseAdapter for MongoDB databases
4
+ *
5
+ * Key differences from SQL adapters:
6
+ * - MongoDB is schema-less, so we infer schema from sample documents
7
+ * - Collections are analogous to tables
8
+ * - No native SQL support - query() accepts MongoDB query JSON
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const adapter = createMongoDBAdapter('mongodb://localhost:27017/mydb');
13
+ * await adapter.connect();
14
+ *
15
+ * // Get inferred schema
16
+ * const schema = await adapter.getSchema();
17
+ * console.log(schema.tables); // Collections with inferred fields
18
+ *
19
+ * // Execute MongoDB query (JSON format)
20
+ * const result = await adapter.query(JSON.stringify({
21
+ * collection: "users",
22
+ * operation: "find",
23
+ * filter: { status: "active" },
24
+ * limit: 10
25
+ * }));
26
+ * ```
27
+ */
28
+ import { Document } from 'mongodb';
29
+ import type { DatabaseAdapter, QueryResult, ConnectionConfig } from './base.js';
30
+ import type { SchemaInfo, TableInfo } from '../schema/types.js';
31
+ /**
32
+ * MongoDB query format for the query() method
33
+ */
34
+ export interface MongoDBQuery {
35
+ /** Collection name to query */
36
+ collection: string;
37
+ /** Operation type */
38
+ operation: 'find' | 'findOne' | 'aggregate' | 'count' | 'distinct';
39
+ /** Query filter (for find, findOne, count) */
40
+ filter?: Document;
41
+ /** Aggregation pipeline (for aggregate) */
42
+ pipeline?: Document[];
43
+ /** Projection (fields to include/exclude) */
44
+ projection?: Document;
45
+ /** Sort specification */
46
+ sort?: Document;
47
+ /** Maximum documents to return */
48
+ limit?: number;
49
+ /** Documents to skip */
50
+ skip?: number;
51
+ /** Field name for distinct operation */
52
+ field?: string;
53
+ }
54
+ /**
55
+ * Configuration for schema inference
56
+ */
57
+ export interface SchemaInferenceConfig {
58
+ /** Number of documents to sample per collection (default: 100) */
59
+ sampleSize: number;
60
+ /** Maximum depth for nested document analysis (default: 5) */
61
+ maxDepth: number;
62
+ /** Include array element type inference (default: true) */
63
+ inferArrayTypes: boolean;
64
+ }
65
+ /**
66
+ * MongoDB Adapter Implementation
67
+ */
68
+ export declare class MongoDBAdapter implements DatabaseAdapter {
69
+ readonly name = "mongodb";
70
+ private client;
71
+ private db;
72
+ private config;
73
+ private databaseName;
74
+ private inferenceConfig;
75
+ constructor(config: ConnectionConfig, inferenceConfig?: Partial<SchemaInferenceConfig>);
76
+ connect(): Promise<void>;
77
+ disconnect(): Promise<void>;
78
+ isConnected(): boolean;
79
+ getDatabaseName(): string;
80
+ /**
81
+ * Execute a MongoDB query.
82
+ *
83
+ * Accepts a JSON string representing a MongoDB query operation.
84
+ * This is different from SQL adapters which accept SQL strings.
85
+ *
86
+ * @param queryJson - JSON string containing MongoDB query specification
87
+ * @returns Query result with rows, metadata, and timing
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * // Find documents
92
+ * const result = await adapter.query(JSON.stringify({
93
+ * collection: "users",
94
+ * operation: "find",
95
+ * filter: { age: { $gt: 25 } },
96
+ * projection: { name: 1, email: 1 },
97
+ * limit: 10
98
+ * }));
99
+ *
100
+ * // Aggregate
101
+ * const result = await adapter.query(JSON.stringify({
102
+ * collection: "orders",
103
+ * operation: "aggregate",
104
+ * pipeline: [
105
+ * { $match: { status: "completed" } },
106
+ * { $group: { _id: "$userId", total: { $sum: "$amount" } } }
107
+ * ]
108
+ * }));
109
+ * ```
110
+ */
111
+ query(queryJson: string): Promise<QueryResult>;
112
+ /**
113
+ * List all collections in the database.
114
+ *
115
+ * @param schema - Ignored for MongoDB (uses database instead)
116
+ * @returns Array of collection names
117
+ */
118
+ listTables(schema?: string): Promise<string[]>;
119
+ /**
120
+ * Get detailed information about a collection.
121
+ *
122
+ * Infers schema from sample documents since MongoDB is schema-less.
123
+ *
124
+ * @param tableName - Collection name
125
+ * @param schema - Ignored for MongoDB
126
+ * @returns Inferred table info with columns representing document fields
127
+ */
128
+ getTable(tableName: string, schema?: string): Promise<TableInfo | null>;
129
+ /**
130
+ * Get complete schema information for the database.
131
+ *
132
+ * @param schema - Ignored for MongoDB
133
+ * @returns Schema info with all collections and their inferred structures
134
+ */
135
+ getSchema(schema?: string): Promise<SchemaInfo>;
136
+ /**
137
+ * Build connection string from individual config parameters
138
+ */
139
+ private buildConnectionString;
140
+ /**
141
+ * Infer column definitions from sample documents
142
+ */
143
+ private inferColumnsFromDocuments;
144
+ /**
145
+ * Create default field stats object
146
+ */
147
+ private createDefaultFieldStats;
148
+ /**
149
+ * Recursively collect field statistics from a document
150
+ */
151
+ private collectFieldStats;
152
+ /**
153
+ * Get MongoDB type name for a value
154
+ */
155
+ private getMongoDBType;
156
+ /**
157
+ * Get the most common type from type statistics
158
+ */
159
+ private getMostCommonType;
160
+ /**
161
+ * Generate a comment for a field based on statistics
162
+ */
163
+ private generateFieldComment;
164
+ /**
165
+ * Get indexes for a collection
166
+ */
167
+ private getIndexes;
168
+ /**
169
+ * Format bytes to human-readable string
170
+ */
171
+ private formatBytes;
172
+ }
173
+ /**
174
+ * Create a MongoDB adapter from connection string
175
+ *
176
+ * @param connectionString - MongoDB connection string (e.g., mongodb://localhost:27017/mydb)
177
+ * @param inferenceConfig - Optional schema inference configuration
178
+ * @returns MongoDB adapter instance
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const adapter = createMongoDBAdapter('mongodb://localhost:27017/mydb');
183
+ * await adapter.connect();
184
+ * ```
185
+ */
186
+ export declare function createMongoDBAdapter(connectionString: string, inferenceConfig?: Partial<SchemaInferenceConfig>): MongoDBAdapter;
187
+ /**
188
+ * Create a MongoDB adapter from config object
189
+ *
190
+ * @param config - Connection configuration
191
+ * @param inferenceConfig - Optional schema inference configuration
192
+ * @returns MongoDB adapter instance
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const adapter = createMongoDBAdapterFromConfig({
197
+ * host: 'localhost',
198
+ * port: 27017,
199
+ * database: 'mydb',
200
+ * user: 'admin',
201
+ * password: 'secret'
202
+ * });
203
+ * await adapter.connect();
204
+ * ```
205
+ */
206
+ export declare function createMongoDBAdapterFromConfig(config: ConnectionConfig, inferenceConfig?: Partial<SchemaInferenceConfig>): MongoDBAdapter;
207
+ //# sourceMappingURL=mongodb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb.d.ts","sourceRoot":"","sources":["../../src/adapters/mongodb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAmB,QAAQ,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AAavF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,O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