@outsidedata/dolex 0.2.0 → 1.0.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.
Files changed (86) hide show
  1. package/README.md +15 -13
  2. package/dist/src/connectors/dsl-compiler.d.ts +3 -6
  3. package/dist/src/connectors/dsl-compiler.d.ts.map +1 -1
  4. package/dist/src/connectors/dsl-compiler.js +23 -63
  5. package/dist/src/connectors/dsl-compiler.js.map +1 -1
  6. package/dist/src/connectors/index.d.ts +0 -3
  7. package/dist/src/connectors/index.d.ts.map +1 -1
  8. package/dist/src/connectors/index.js +0 -3
  9. package/dist/src/connectors/index.js.map +1 -1
  10. package/dist/src/connectors/js-aggregation.d.ts +4 -4
  11. package/dist/src/connectors/js-aggregation.d.ts.map +1 -1
  12. package/dist/src/connectors/js-aggregation.js +4 -4
  13. package/dist/src/connectors/js-aggregation.js.map +1 -1
  14. package/dist/src/connectors/manager.d.ts.map +1 -1
  15. package/dist/src/connectors/manager.js +4 -21
  16. package/dist/src/connectors/manager.js.map +1 -1
  17. package/dist/src/mcp/app-shell.js +1 -1
  18. package/dist/src/mcp/index.d.ts +8 -8
  19. package/dist/src/mcp/index.js +51 -51
  20. package/dist/src/mcp/index.js.map +1 -1
  21. package/dist/src/mcp/prompts.js +4 -4
  22. package/dist/src/mcp/prompts.js.map +1 -1
  23. package/dist/src/mcp/tools/analyze.d.ts +1 -1
  24. package/dist/src/mcp/tools/analyze.js +2 -2
  25. package/dist/src/mcp/tools/analyze.js.map +1 -1
  26. package/dist/src/mcp/tools/bug-report.d.ts.map +1 -1
  27. package/dist/src/mcp/tools/bug-report.js +2 -10
  28. package/dist/src/mcp/tools/bug-report.js.map +1 -1
  29. package/dist/src/mcp/tools/dashboard.js +1 -1
  30. package/dist/src/mcp/tools/dashboard.js.map +1 -1
  31. package/dist/src/mcp/tools/dsl-schemas.d.ts +1 -1
  32. package/dist/src/mcp/tools/dsl-schemas.js +2 -2
  33. package/dist/src/mcp/tools/dsl-schemas.js.map +1 -1
  34. package/dist/src/mcp/tools/export-html.d.ts +1 -1
  35. package/dist/src/mcp/tools/export-html.js +2 -2
  36. package/dist/src/mcp/tools/export-html.js.map +1 -1
  37. package/dist/src/mcp/tools/query-source.d.ts +1 -1
  38. package/dist/src/mcp/tools/query-source.js +4 -4
  39. package/dist/src/mcp/tools/query-source.js.map +1 -1
  40. package/dist/src/mcp/tools/refine.d.ts +2 -2
  41. package/dist/src/mcp/tools/result-cache.d.ts +1 -1
  42. package/dist/src/mcp/tools/result-cache.js +1 -1
  43. package/dist/src/mcp/tools/screenshot.js +1 -1
  44. package/dist/src/mcp/tools/screenshot.js.map +1 -1
  45. package/dist/src/mcp/tools/server-privacy.d.ts.map +1 -1
  46. package/dist/src/mcp/tools/server-privacy.js +6 -7
  47. package/dist/src/mcp/tools/server-privacy.js.map +1 -1
  48. package/dist/src/mcp/tools/sources.d.ts +5 -113
  49. package/dist/src/mcp/tools/sources.d.ts.map +1 -1
  50. package/dist/src/mcp/tools/sources.js +15 -44
  51. package/dist/src/mcp/tools/sources.js.map +1 -1
  52. package/dist/src/mcp/tools/visualize-from-source.d.ts +1 -1
  53. package/dist/src/mcp/tools/visualize-from-source.js +4 -4
  54. package/dist/src/mcp/tools/visualize-from-source.js.map +1 -1
  55. package/dist/src/mcp/tools/visualize.d.ts +2 -2
  56. package/dist/src/mcp/tools/visualize.js +5 -5
  57. package/dist/src/mcp/tools/visualize.js.map +1 -1
  58. package/dist/src/renderers/html/builders/dashboard.js +2 -2
  59. package/dist/src/types.d.ts +3 -24
  60. package/dist/src/types.d.ts.map +1 -1
  61. package/dist/src/types.js.map +1 -1
  62. package/package.json +1 -4
  63. package/src/connectors/dsl-compiler.ts +22 -64
  64. package/src/connectors/index.ts +0 -3
  65. package/src/connectors/js-aggregation.ts +4 -4
  66. package/src/connectors/manager.ts +4 -24
  67. package/src/mcp/app-shell.ts +1 -1
  68. package/src/mcp/index.ts +51 -51
  69. package/src/mcp/prompts.ts +4 -4
  70. package/src/mcp/tools/analyze.ts +2 -2
  71. package/src/mcp/tools/bug-report.ts +2 -10
  72. package/src/mcp/tools/dashboard.ts +1 -1
  73. package/src/mcp/tools/dsl-schemas.ts +2 -2
  74. package/src/mcp/tools/export-html.ts +2 -2
  75. package/src/mcp/tools/query-source.ts +4 -4
  76. package/src/mcp/tools/result-cache.ts +1 -1
  77. package/src/mcp/tools/screenshot.ts +1 -1
  78. package/src/mcp/tools/server-privacy.ts +6 -7
  79. package/src/mcp/tools/sources.ts +18 -46
  80. package/src/mcp/tools/visualize-from-source.ts +4 -4
  81. package/src/mcp/tools/visualize.ts +5 -5
  82. package/src/renderers/html/builders/dashboard.ts +2 -2
  83. package/src/types.ts +3 -31
  84. package/src/connectors/mysql.ts +0 -378
  85. package/src/connectors/postgres.ts +0 -367
  86. package/src/connectors/sqlite.ts +0 -364
@@ -1,367 +0,0 @@
1
- /**
2
- * PostgreSQL Connector
3
- *
4
- * Connects to a PostgreSQL database via the `pg` library.
5
- * Introspects schema via information_schema views.
6
- * Detects foreign keys from database constraints.
7
- * Maps Postgres types to our column type system.
8
- */
9
-
10
- import pg from 'pg';
11
- import type {
12
- DataSourceType,
13
- DataSourceConfig,
14
- PostgresSourceConfig,
15
- DataSchema,
16
- DataTable,
17
- DataColumn,
18
- ForeignKey,
19
- } from '../types.js';
20
- import type { DataConnector, ConnectedSource, QueryExecutionResult } from './types.js';
21
-
22
- const { Client } = pg;
23
-
24
- const SAMPLE_LIMIT = 30;
25
- const SAMPLE_DISPLAY_LIMIT = 20;
26
-
27
- /**
28
- * Map a PostgreSQL data_type (from information_schema) to our column type system.
29
- */
30
- function mapPostgresType(
31
- pgType: string,
32
- columnName: string,
33
- uniqueCount: number,
34
- totalRows: number
35
- ): DataColumn['type'] {
36
- const lower = columnName.toLowerCase();
37
- const typeLower = pgType.toLowerCase();
38
-
39
- // ID detection by name
40
- if (lower === 'id' || lower === 'rowid') return 'id';
41
- if (lower.endsWith('_id')) return 'id';
42
-
43
- // Serial / identity types -> id
44
- if (typeLower.includes('serial') || typeLower.includes('bigserial')) {
45
- return 'id';
46
- }
47
-
48
- // Numeric types
49
- if (
50
- typeLower.includes('integer') ||
51
- typeLower.includes('int') ||
52
- typeLower === 'smallint' ||
53
- typeLower === 'bigint' ||
54
- typeLower.includes('float') ||
55
- typeLower.includes('real') ||
56
- typeLower.includes('double') ||
57
- typeLower.includes('numeric') ||
58
- typeLower.includes('decimal') ||
59
- typeLower === 'money'
60
- ) {
61
- // But if named like an ID with high cardinality, treat as ID
62
- if (lower.endsWith('id') && uniqueCount > totalRows * 0.5) {
63
- return 'id';
64
- }
65
- return 'numeric';
66
- }
67
-
68
- // Date/time types
69
- if (
70
- typeLower.includes('timestamp') ||
71
- typeLower === 'date' ||
72
- typeLower.includes('time') ||
73
- typeLower === 'interval'
74
- ) {
75
- return 'date';
76
- }
77
-
78
- // Date detection by column name
79
- if (
80
- lower.includes('date') ||
81
- lower.includes('time') ||
82
- lower.includes('year') ||
83
- lower.includes('timestamp')
84
- ) {
85
- return 'date';
86
- }
87
-
88
- // Boolean -> categorical
89
- if (typeLower === 'boolean' || typeLower === 'bool') {
90
- return 'categorical';
91
- }
92
-
93
- // Text types: determine categorical vs text by length heuristic
94
- if (
95
- typeLower.includes('varchar') ||
96
- typeLower.includes('character varying') ||
97
- typeLower.includes('char') ||
98
- typeLower === 'text' ||
99
- typeLower === 'name' ||
100
- typeLower === 'citext'
101
- ) {
102
- // High cardinality + text type -> likely free text
103
- if (typeLower === 'text' && uniqueCount > totalRows * 0.9) {
104
- return 'text';
105
- }
106
- return 'categorical';
107
- }
108
-
109
- // JSON types -> text
110
- if (typeLower === 'json' || typeLower === 'jsonb') {
111
- return 'text';
112
- }
113
-
114
- // UUID -> id
115
- if (typeLower === 'uuid') {
116
- return 'id';
117
- }
118
-
119
- // Array types -> text
120
- if (typeLower === 'array' || typeLower.startsWith('_')) {
121
- return 'text';
122
- }
123
-
124
- // Enum types -> categorical
125
- if (typeLower === 'user-defined') {
126
- return 'categorical';
127
- }
128
-
129
- return 'categorical';
130
- }
131
-
132
- /**
133
- * Build a pg Client from our config shape.
134
- */
135
- function buildClient(config: PostgresSourceConfig): pg.Client {
136
- return new Client({
137
- host: config.host,
138
- port: config.port,
139
- database: config.database,
140
- user: config.user,
141
- password: config.password,
142
- ssl: config.ssl ? { rejectUnauthorized: false } : undefined,
143
- });
144
- }
145
-
146
- class PostgresConnectedSource implements ConnectedSource {
147
- id: string;
148
- name: string;
149
- readonly type: DataSourceType = 'postgres';
150
- private client: pg.Client;
151
- private config: PostgresSourceConfig;
152
- private cachedSchema: DataSchema | null = null;
153
-
154
- constructor(
155
- id: string,
156
- name: string,
157
- client: pg.Client,
158
- config: PostgresSourceConfig
159
- ) {
160
- this.id = id;
161
- this.name = name;
162
- this.client = client;
163
- this.config = config;
164
- }
165
-
166
- async getSchema(): Promise<DataSchema> {
167
- if (this.cachedSchema) return this.cachedSchema;
168
-
169
- // Get all user tables (exclude system schemas)
170
- const tablesResult = await this.client.query(`
171
- SELECT table_name
172
- FROM information_schema.tables
173
- WHERE table_schema = 'public'
174
- AND table_type = 'BASE TABLE'
175
- ORDER BY table_name
176
- `);
177
-
178
- const tables: DataTable[] = [];
179
-
180
- for (const tableRow of tablesResult.rows) {
181
- const tableName = tableRow.table_name;
182
-
183
- // Get row count
184
- const countResult = await this.client.query(
185
- `SELECT COUNT(*) as cnt FROM "${tableName}"`
186
- );
187
- const rowCount = parseInt(countResult.rows[0].cnt, 10);
188
-
189
- // Get columns from information_schema
190
- const columnsResult = await this.client.query(
191
- `
192
- SELECT column_name, data_type, is_nullable, column_default
193
- FROM information_schema.columns
194
- WHERE table_schema = 'public' AND table_name = $1
195
- ORDER BY ordinal_position
196
- `,
197
- [tableName]
198
- );
199
-
200
- const columns: DataColumn[] = [];
201
-
202
- for (const colRow of columnsResult.rows) {
203
- const colName = colRow.column_name;
204
- const pgType = colRow.data_type;
205
-
206
- // Get sample values
207
- let samples: string[] = [];
208
- try {
209
- const sampleResult = await this.client.query(
210
- `SELECT DISTINCT "${colName}"::text AS val FROM "${tableName}" WHERE "${colName}" IS NOT NULL LIMIT ${SAMPLE_LIMIT}`
211
- );
212
- samples = sampleResult.rows.map((r: any) => r.val);
213
- } catch {
214
- // Some types may fail to cast to text; skip samples
215
- }
216
-
217
- // Get stats
218
- let uniqueCount = 0;
219
- let nullCount = 0;
220
- let totalCount = rowCount;
221
- try {
222
- const statsResult = await this.client.query(
223
- `SELECT COUNT(DISTINCT "${colName}") as uniq, COUNT(*) - COUNT("${colName}") as nulls, COUNT(*) as total FROM "${tableName}"`
224
- );
225
- uniqueCount = parseInt(statsResult.rows[0].uniq, 10);
226
- nullCount = parseInt(statsResult.rows[0].nulls, 10);
227
- totalCount = parseInt(statsResult.rows[0].total, 10);
228
- } catch {
229
- // Fallback
230
- }
231
-
232
- const type = mapPostgresType(pgType, colName, uniqueCount, rowCount);
233
-
234
- columns.push({
235
- name: colName,
236
- type,
237
- sampleValues: samples.slice(0, SAMPLE_DISPLAY_LIMIT),
238
- uniqueCount,
239
- nullCount,
240
- totalCount,
241
- });
242
- }
243
-
244
- tables.push({ name: tableName, columns, rowCount });
245
- }
246
-
247
- // Get foreign keys from constraints
248
- const foreignKeys = await this.getForeignKeys();
249
-
250
- this.cachedSchema = {
251
- tables,
252
- foreignKeys,
253
- source: {
254
- id: this.id,
255
- type: 'postgres',
256
- name: this.name,
257
- config: {
258
- ...this.config,
259
- password: '***', // Don't store password in schema output
260
- } as PostgresSourceConfig,
261
- },
262
- };
263
-
264
- return this.cachedSchema;
265
- }
266
-
267
- private async getForeignKeys(): Promise<ForeignKey[]> {
268
- const result = await this.client.query(`
269
- SELECT
270
- kcu.table_name AS from_table,
271
- kcu.column_name AS from_column,
272
- ccu.table_name AS to_table,
273
- ccu.column_name AS to_column
274
- FROM information_schema.table_constraints AS tc
275
- JOIN information_schema.key_column_usage AS kcu
276
- ON tc.constraint_name = kcu.constraint_name
277
- AND tc.table_schema = kcu.table_schema
278
- JOIN information_schema.constraint_column_usage AS ccu
279
- ON ccu.constraint_name = tc.constraint_name
280
- AND ccu.table_schema = tc.table_schema
281
- WHERE tc.constraint_type = 'FOREIGN KEY'
282
- AND tc.table_schema = 'public'
283
- ORDER BY kcu.table_name, kcu.column_name
284
- `);
285
-
286
- return result.rows.map((r: any) => ({
287
- fromTable: r.from_table,
288
- fromColumn: r.from_column,
289
- toTable: r.to_table,
290
- toColumn: r.to_column,
291
- }));
292
- }
293
-
294
- async getSampleRows(tableName: string, count: number = 5): Promise<Record<string, any>[]> {
295
- try {
296
- const result = await this.client.query(
297
- `SELECT * FROM "${tableName}" ORDER BY random() LIMIT $1`,
298
- [count]
299
- );
300
- return result.rows;
301
- } catch {
302
- return [];
303
- }
304
- }
305
-
306
- async executeQuery(sql: string): Promise<QueryExecutionResult> {
307
- try {
308
- const result = await this.client.query(sql);
309
- const columns = result.fields.map((f) => f.name);
310
- return { columns, rows: result.rows };
311
- } catch (err: any) {
312
- return { columns: [], rows: [{ error: err.message }] };
313
- }
314
- }
315
-
316
- async close(): Promise<void> {
317
- try {
318
- await this.client.end();
319
- } catch {
320
- // Already closed, ignore
321
- }
322
- }
323
- }
324
-
325
- export const postgresConnector: DataConnector = {
326
- type: 'postgres',
327
-
328
- async test(
329
- config: DataSourceConfig
330
- ): Promise<{ ok: boolean; error?: string }> {
331
- const pgConfig = config as PostgresSourceConfig;
332
- if (pgConfig.type !== 'postgres') {
333
- return { ok: false, error: 'Config type must be "postgres"' };
334
- }
335
-
336
- const client = buildClient(pgConfig);
337
- try {
338
- await client.connect();
339
- // Run a simple test query
340
- await client.query('SELECT 1');
341
- await client.end();
342
- return { ok: true };
343
- } catch (err: any) {
344
- try {
345
- await client.end();
346
- } catch {
347
- // Ignore cleanup error
348
- }
349
- return { ok: false, error: `PostgreSQL connection failed: ${err.message}` };
350
- }
351
- },
352
-
353
- async connect(config: DataSourceConfig): Promise<ConnectedSource> {
354
- const pgConfig = config as PostgresSourceConfig;
355
- if (pgConfig.type !== 'postgres') {
356
- throw new Error('Config type must be "postgres"');
357
- }
358
-
359
- const client = buildClient(pgConfig);
360
- await client.connect();
361
-
362
- const sourceName = pgConfig.database;
363
- const id = `postgres-${pgConfig.host}-${pgConfig.database}-${Date.now()}`;
364
-
365
- return new PostgresConnectedSource(id, sourceName, client, pgConfig);
366
- },
367
- };