@outsidedata/dolex 9.0.0 → 9.0.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.
Files changed (39) hide show
  1. package/dist/src/cli/commands/sources.js +2 -1
  2. package/dist/src/cli/data-source.d.ts +0 -2
  3. package/dist/src/cli/data-source.js +0 -1
  4. package/dist/src/connectors/manager.js +71 -52
  5. package/dist/src/connectors/mongo/index.d.ts +8 -0
  6. package/dist/src/connectors/mongo/index.js +42 -6
  7. package/dist/src/connectors/pg/index.js +90 -22
  8. package/dist/src/connectors/sql-safety.d.ts +59 -17
  9. package/dist/src/connectors/sql-safety.js +275 -54
  10. package/dist/src/connectors/types.d.ts +8 -0
  11. package/dist/src/connectors/types.js +22 -0
  12. package/dist/src/mcp/index.js +23 -4
  13. package/dist/src/mcp/tools/analyze.js +1 -1
  14. package/dist/src/mcp/tools/clean-schemas.js +1 -1
  15. package/dist/src/mcp/tools/query-source.js +2 -2
  16. package/dist/src/mcp/tools/sources.d.ts +1 -1
  17. package/dist/src/mcp/tools/sources.js +7 -5
  18. package/dist/src/mcp/tools/transform-schemas.js +4 -4
  19. package/dist/src/mcp/tools/visualize-cli.js +1 -1
  20. package/dist/src/mcp/tools/visualize.js +2 -2
  21. package/dist/src/patterns/index.d.ts +1 -1
  22. package/dist/src/patterns/index.js +1 -1
  23. package/dist/src/patterns/registry.d.ts +1 -12
  24. package/dist/src/patterns/registry.js +0 -13
  25. package/dist/src/patterns/utils.d.ts +0 -24
  26. package/dist/src/patterns/utils.js +0 -71
  27. package/dist/src/renderers/d3/shared.d.ts +0 -18
  28. package/dist/src/renderers/d3/shared.js +0 -62
  29. package/dist/src/types.d.ts +1 -1
  30. package/dist/src/utils/capabilities.js +1 -1
  31. package/package.json +4 -4
  32. package/dist/src/analysis/clean-exec.d.ts +0 -23
  33. package/dist/src/analysis/clean-exec.js +0 -87
  34. package/dist/src/cleaning/author.d.ts +0 -30
  35. package/dist/src/cleaning/author.js +0 -7
  36. package/dist/src/cleaning/handlers.d.ts +0 -16
  37. package/dist/src/cleaning/handlers.js +0 -82
  38. package/dist/src/cleaning/manifest.d.ts +0 -35
  39. package/dist/src/cleaning/manifest.js +0 -95
@@ -1,95 +0,0 @@
1
- /**
2
- * Manifest build (discover → author[injected] → acceptance-test → store) + replay
3
- * (deterministic, no model). The model-free heart of the cleaning core.
4
- *
5
- * Ported from local-orchestration/src/clean.ts with two changes: the model author
6
- * is INJECTED (CleanAuthor) so the core stays model-free, and the python runner is
7
- * the shared exec (runPythonClean) so there is exactly ONE executor.
8
- */
9
- import * as fs from 'fs';
10
- import * as path from 'path';
11
- import Papa from 'papaparse';
12
- import { SourceManager } from '../connectors/manager.js';
13
- import { auditDataset } from '../analysis/quality.js';
14
- import { runPythonClean } from './exec.js';
15
- import { HANDLERS, validateFix } from './handlers.js';
16
- export async function buildCleanManifest(rawPath, author, opts = {}) {
17
- const log = opts.onLog ?? (() => { });
18
- const tries = opts.tries ?? 3;
19
- const rows = Papa.parse(fs.readFileSync(rawPath, 'utf8'), { header: true, skipEmptyLines: true }).data;
20
- const mgr = new SourceManager();
21
- const add = await mgr.add('ds', { type: 'csv', path: rawPath });
22
- const sid = add.entry.id;
23
- await mgr.connect(sid);
24
- const tables = (await mgr.getSchema(sid)).schema.tables;
25
- const findings = await auditDataset(tables, (s) => mgr.querySql(sid, s));
26
- const manifest = { dataset: path.basename(rawPath), createdBy: opts.createdBy ?? 'injected-author', createdAt: '', fixes: [] };
27
- for (const f of findings) {
28
- const handler = f.column ? HANDLERS[f.issue] : undefined;
29
- if (!handler)
30
- continue;
31
- const task = handler.task(f);
32
- if (!task)
33
- continue;
34
- if (manifest.fixes.some((x) => x.column === f.column))
35
- continue; // one fix per column
36
- const sampleVals = [...new Set(rows.map((r) => r[f.column]).filter((v) => v !== undefined))].slice(0, 200);
37
- // the acceptance test must SEE the sentinel/edge value or it can't validate the fix —
38
- // the first-200-distinct sample may miss a rare sentinel (e.g. odometer 999999).
39
- const sentinel = (f.detail.match(/non-numeric value "([^"]+)"/) || f.detail.match(/Extreme value ([\d.eE+-]+)/) || f.detail.match(/sentinel:\s*"([^"]+)"/) || [])[1];
40
- if (sentinel !== undefined && !sampleVals.includes(sentinel))
41
- sampleVals.push(sentinel);
42
- const samples = sampleVals.slice(0, 4);
43
- let feedback, stored = false;
44
- for (let attempt = 1; attempt <= tries; attempt++) {
45
- let code;
46
- try {
47
- code = await author({ column: f.column, issue: f.issue, task, samples, feedback });
48
- }
49
- catch (e) {
50
- log(` ${f.column} attempt ${attempt}: author error ${e?.message}`);
51
- continue;
52
- }
53
- let acc;
54
- try {
55
- acc = validateFix(f, code, sampleVals);
56
- }
57
- catch (e) {
58
- acc = { ok: false, summary: 'python error', fail: String(e?.message || e).slice(0, 80) };
59
- }
60
- log(` ${f.column} (${f.issue}) attempt ${attempt}: ${acc.summary} → ${acc.ok ? 'VALID' : 'FAIL ' + (acc.fail ?? '')}`);
61
- if (acc.ok) {
62
- manifest.fixes.push({ column: f.column, issue: f.issue, task, pythonCode: code, validated: true, summary: acc.summary });
63
- stored = true;
64
- break;
65
- }
66
- feedback = acc.fail;
67
- }
68
- if (!stored)
69
- log(` ${f.column}: no valid fix after ${tries} tries — skipped (never store an unvalidated fix)`);
70
- }
71
- return manifest;
72
- }
73
- /** Replay validated fixes over a CSV (NON-destructive: keep <col>_raw). NO model. */
74
- export function applyManifest(rawPath, manifest) {
75
- const parsed = Papa.parse(fs.readFileSync(rawPath, 'utf8'), { header: true, skipEmptyLines: true });
76
- const rows = parsed.data;
77
- for (const fix of manifest.fixes) {
78
- const { cleaned } = runPythonClean(fix.pythonCode, rows.map((r) => r[fix.column] ?? ''));
79
- rows.forEach((r, i) => { r[`${fix.column}_raw`] = r[fix.column] ?? ''; r[fix.column] = cleaned[i] === null || cleaned[i] === undefined ? '' : String(cleaned[i]); });
80
- }
81
- const fields = [...(parsed.meta.fields || []), ...manifest.fixes.map((f) => `${f.column}_raw`)];
82
- return { rows, fields };
83
- }
84
- /** Full activation: build manifest (via injected author) → materialize cleaned CSV + persist manifest. */
85
- export async function cleanDataset(rawPath, author, opts = {}) {
86
- const manifest = await buildCleanManifest(rawPath, author, { onLog: opts.onLog, createdBy: opts.createdBy });
87
- const outDir = opts.outDir ?? path.dirname(rawPath);
88
- const base = path.basename(rawPath, path.extname(rawPath));
89
- const manifestPath = path.join(outDir, `${base}.cleanfix.json`);
90
- fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
91
- const { rows, fields } = applyManifest(rawPath, manifest);
92
- const cleanedPath = path.join(outDir, `${base}.clean.csv`);
93
- fs.writeFileSync(cleanedPath, Papa.unparse(rows, { columns: fields }));
94
- return { cleanedPath, manifestPath, manifest };
95
- }