@memberjunction/db-auto-doc 3.4.0 → 4.1.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/README.md +58 -26
- package/bin/run.js +4 -7
- package/dist/api/DBAutoDocAPI.js +14 -41
- package/dist/api/DBAutoDocAPI.js.map +1 -1
- package/dist/api/index.js +1 -5
- package/dist/api/index.js.map +1 -1
- package/dist/commands/analyze.d.ts +1 -1
- package/dist/commands/analyze.js +30 -36
- package/dist/commands/analyze.js.map +1 -1
- package/dist/commands/export-sample-queries.d.ts +1 -1
- package/dist/commands/export-sample-queries.js +65 -94
- package/dist/commands/export-sample-queries.js.map +1 -1
- package/dist/commands/export.d.ts +2 -2
- package/dist/commands/export.js +49 -78
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/generate-queries.d.ts +2 -2
- package/dist/commands/generate-queries.d.ts.map +1 -1
- package/dist/commands/generate-queries.js +47 -73
- package/dist/commands/generate-queries.js.map +1 -1
- package/dist/commands/init.js +21 -27
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/reset.js +16 -22
- package/dist/commands/reset.js.map +1 -1
- package/dist/commands/status.js +16 -22
- package/dist/commands/status.js.map +1 -1
- package/dist/core/AnalysisEngine.js +7 -11
- package/dist/core/AnalysisEngine.js.map +1 -1
- package/dist/core/AnalysisOrchestrator.d.ts.map +1 -1
- package/dist/core/AnalysisOrchestrator.js +45 -56
- package/dist/core/AnalysisOrchestrator.js.map +1 -1
- package/dist/core/BackpropagationEngine.js +1 -5
- package/dist/core/BackpropagationEngine.js.map +1 -1
- package/dist/core/ConvergenceDetector.js +1 -5
- package/dist/core/ConvergenceDetector.js.map +1 -1
- package/dist/core/GuardrailsManager.js +1 -5
- package/dist/core/GuardrailsManager.js.map +1 -1
- package/dist/core/index.js +3 -9
- package/dist/core/index.js.map +1 -1
- package/dist/database/Database.d.ts.map +1 -1
- package/dist/database/Database.js +42 -37
- package/dist/database/Database.js.map +1 -1
- package/dist/database/TopologicalSorter.js +1 -5
- package/dist/database/TopologicalSorter.js.map +1 -1
- package/dist/database/index.js +2 -10
- package/dist/database/index.js.map +1 -1
- package/dist/discovery/ColumnStatsCache.js +1 -5
- package/dist/discovery/ColumnStatsCache.js.map +1 -1
- package/dist/discovery/DiscoveryEngine.js +11 -15
- package/dist/discovery/DiscoveryEngine.js.map +1 -1
- package/dist/discovery/DiscoveryTriggerAnalyzer.js +1 -5
- package/dist/discovery/DiscoveryTriggerAnalyzer.js.map +1 -1
- package/dist/discovery/FKDetector.js +1 -5
- package/dist/discovery/FKDetector.js.map +1 -1
- package/dist/discovery/LLMDiscoveryValidator.js +4 -8
- package/dist/discovery/LLMDiscoveryValidator.js.map +1 -1
- package/dist/discovery/LLMSanityChecker.js +3 -7
- package/dist/discovery/LLMSanityChecker.js.map +1 -1
- package/dist/discovery/PKDetector.js +1 -5
- package/dist/discovery/PKDetector.js.map +1 -1
- package/dist/discovery/index.js +4 -20
- package/dist/discovery/index.js.map +1 -1
- package/dist/drivers/BaseAutoDocDriver.js +1 -5
- package/dist/drivers/BaseAutoDocDriver.js.map +1 -1
- package/dist/drivers/MySQLDriver.js +8 -14
- package/dist/drivers/MySQLDriver.js.map +1 -1
- package/dist/drivers/PostgreSQLDriver.js +8 -11
- package/dist/drivers/PostgreSQLDriver.js.map +1 -1
- package/dist/drivers/SQLServerDriver.d.ts.map +1 -1
- package/dist/drivers/SQLServerDriver.js +27 -46
- package/dist/drivers/SQLServerDriver.js.map +1 -1
- package/dist/generators/CSVGenerator.js +1 -5
- package/dist/generators/CSVGenerator.js.map +1 -1
- package/dist/generators/HTMLGenerator.js +1 -5
- package/dist/generators/HTMLGenerator.js.map +1 -1
- package/dist/generators/MarkdownGenerator.js +1 -5
- package/dist/generators/MarkdownGenerator.js.map +1 -1
- package/dist/generators/MermaidGenerator.js +1 -5
- package/dist/generators/MermaidGenerator.js.map +1 -1
- package/dist/generators/ReportGenerator.js +1 -5
- package/dist/generators/ReportGenerator.js.map +1 -1
- package/dist/generators/SQLGenerator.js +1 -5
- package/dist/generators/SQLGenerator.js.map +1 -1
- package/dist/generators/SampleQueryGenerator.d.ts +1 -1
- package/dist/generators/SampleQueryGenerator.d.ts.map +1 -1
- package/dist/generators/SampleQueryGenerator.js +36 -40
- package/dist/generators/SampleQueryGenerator.js.map +1 -1
- package/dist/generators/index.js +6 -15
- package/dist/generators/index.js.map +1 -1
- package/dist/index.js +9 -25
- package/dist/index.js.map +1 -1
- package/dist/prompts/PromptEngine.d.ts.map +1 -1
- package/dist/prompts/PromptEngine.js +22 -49
- package/dist/prompts/PromptEngine.js.map +1 -1
- package/dist/prompts/PromptFileLoader.d.ts +1 -1
- package/dist/prompts/PromptFileLoader.d.ts.map +1 -1
- package/dist/prompts/PromptFileLoader.js +4 -31
- package/dist/prompts/PromptFileLoader.js.map +1 -1
- package/dist/prompts/index.js +2 -7
- package/dist/prompts/index.js.map +1 -1
- package/dist/state/IterationTracker.js +1 -5
- package/dist/state/IterationTracker.js.map +1 -1
- package/dist/state/StateManager.js +3 -30
- package/dist/state/StateManager.js.map +1 -1
- package/dist/state/StateValidator.js +1 -5
- package/dist/state/StateValidator.js.map +1 -1
- package/dist/state/index.js +3 -9
- package/dist/state/index.js.map +1 -1
- package/dist/types/analysis.js +1 -2
- package/dist/types/analysis.js.map +1 -1
- package/dist/types/config.js +1 -2
- package/dist/types/config.js.map +1 -1
- package/dist/types/discovery.js +1 -2
- package/dist/types/discovery.js.map +1 -1
- package/dist/types/driver.js +1 -2
- package/dist/types/driver.js.map +1 -1
- package/dist/types/index.js +4 -20
- package/dist/types/index.js.map +1 -1
- package/dist/types/prompts.js +1 -2
- package/dist/types/prompts.js.map +1 -1
- package/dist/types/sample-queries.js +1 -2
- package/dist/types/sample-queries.js.map +1 -1
- package/dist/types/state.js +1 -2
- package/dist/types/state.js.map +1 -1
- package/dist/utils/config-loader.js +3 -30
- package/dist/utils/config-loader.js.map +1 -1
- package/dist/utils/index.js +1 -5
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/llm-factory.js +6 -12
- package/dist/utils/llm-factory.js.map +1 -1
- package/package.json +25 -23
- package/prompts/backpropagation.md +55 -0
- package/prompts/convergence-check.md +79 -0
- package/prompts/cross-schema-check.md +61 -0
- package/prompts/cross-schema-sanity-check.md +133 -0
- package/prompts/dependency-level-sanity-check.md +92 -0
- package/prompts/query-fix.md +141 -0
- package/prompts/query-planning.md +144 -0
- package/prompts/query-refinement.md +151 -0
- package/prompts/schema-level-sanity-check.md +114 -0
- package/prompts/schema-sanity-check.md +54 -0
- package/prompts/semantic-comparison.md +78 -0
- package/prompts/single-query-generation.md +155 -0
- package/prompts/table-analysis.md +139 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
You are analyzing a database table to generate comprehensive documentation. Your task is to infer the table's purpose based on the evidence provided.
|
|
2
|
+
|
|
3
|
+
## Table Information
|
|
4
|
+
- **Name**: {{ tableName }}
|
|
5
|
+
- **Schema**: {{ schemaName }}
|
|
6
|
+
- **Row Count**: {{ rowCount }}
|
|
7
|
+
{% if dependencyLevel is defined %}- **Dependency Level**: {{ dependencyLevel }} (0 = no dependencies){% endif %}
|
|
8
|
+
|
|
9
|
+
## Columns
|
|
10
|
+
{% for col in columns %}
|
|
11
|
+
- **{{ col.name }}** ({{ col.dataType }}){% if not col.isNullable %} NOT NULL{% endif %}
|
|
12
|
+
{% if col.isPrimaryKey %}- **PRIMARY KEY**{% endif %}
|
|
13
|
+
{% if col.isForeignKey %}- **FOREIGN KEY** → {{ col.foreignKeyReferences.schema }}.{{ col.foreignKeyReferences.table }}.{{ col.foreignKeyReferences.column }}{% endif %}
|
|
14
|
+
{% if col.checkConstraint %}- Check Constraint: {{ col.checkConstraint }}{% endif %}
|
|
15
|
+
{% if col.defaultValue %}- Default: {{ col.defaultValue }}{% endif %}
|
|
16
|
+
{% if col.statistics %}- Distinct Values: {{ col.statistics.distinctCount }} ({{ (col.statistics.uniquenessRatio * 100) | round(1) }}% unique){% endif %}
|
|
17
|
+
{% if col.statistics and col.statistics.nullPercentage > 0 %}- Nulls: {{ col.statistics.nullPercentage | round(1) }}%{% endif %}
|
|
18
|
+
{% if col.possibleValues %}- Possible Values: {{ col.possibleValues | join(', ') }}{% endif %}
|
|
19
|
+
{% if col.statistics and col.statistics.min is defined %}- Range: {{ col.statistics.min }} to {{ col.statistics.max }}{% if col.statistics.avg %} (avg: {{ col.statistics.avg | round(2) }}){% endif %}{% endif %}
|
|
20
|
+
{% if col.statistics and col.statistics.avgLength %}- Avg Length: {{ col.statistics.avgLength | round(1) }} chars{% endif %}
|
|
21
|
+
{% if col.statistics.sampleValues and col.statistics.sampleValues.length > 0 %}- Sample Values: {{ col.statistics.sampleValues | jsoninline }}{% endif %}
|
|
22
|
+
{% endfor %}
|
|
23
|
+
|
|
24
|
+
## Relationships
|
|
25
|
+
{% if dependsOn and dependsOn.length > 0 %}
|
|
26
|
+
**This table references (depends on):**
|
|
27
|
+
{% for dep in dependsOn %}
|
|
28
|
+
- {{ dep.schema }}.{{ dep.table }} (via column: {{ dep.column }} → {{ dep.referencedColumn }})
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% endif %}
|
|
31
|
+
|
|
32
|
+
{% if dependents and dependents.length > 0 %}
|
|
33
|
+
**Referenced by (dependents):**
|
|
34
|
+
{% for dep in dependents %}
|
|
35
|
+
- {{ dep.schema }}.{{ dep.table }}
|
|
36
|
+
{% endfor %}
|
|
37
|
+
{% endif %}
|
|
38
|
+
|
|
39
|
+
{% if not dependsOn or dependsOn.length === 0 %}
|
|
40
|
+
**Note**: This table has no foreign key dependencies (dependency level 0). It is likely a foundational/lookup table.
|
|
41
|
+
{% endif %}
|
|
42
|
+
|
|
43
|
+
{% if parentDescriptions and parentDescriptions.length > 0 %}
|
|
44
|
+
## Parent Table Context
|
|
45
|
+
Understanding from tables this table references:
|
|
46
|
+
|
|
47
|
+
{% for parent in parentDescriptions %}
|
|
48
|
+
**{{ parent.schema }}.{{ parent.table }}**: {{ parent.description }}
|
|
49
|
+
{% endfor %}
|
|
50
|
+
{% endif %}
|
|
51
|
+
|
|
52
|
+
{% if userNotes %}
|
|
53
|
+
## User Notes
|
|
54
|
+
{{ userNotes }}
|
|
55
|
+
{% endif %}
|
|
56
|
+
|
|
57
|
+
{% if seedContext %}
|
|
58
|
+
## Database Context
|
|
59
|
+
{% if seedContext.overallPurpose %}- **Purpose**: {{ seedContext.overallPurpose }}{% endif %}
|
|
60
|
+
{% if seedContext.businessDomains %}- **Business Domains**: {{ seedContext.businessDomains | join(', ') }}{% endif %}
|
|
61
|
+
{% if seedContext.industryContext %}- **Industry**: {{ seedContext.industryContext }}{% endif %}
|
|
62
|
+
{% if seedContext.customInstructions %}- **Special Instructions**: {{ seedContext.customInstructions }}{% endif %}
|
|
63
|
+
{% endif %}
|
|
64
|
+
|
|
65
|
+
{% if allTables %}
|
|
66
|
+
## All Database Tables
|
|
67
|
+
**IMPORTANT**: When referring to foreign key relationships, you MUST use one of these exact table names:
|
|
68
|
+
{% for tbl in allTables %}
|
|
69
|
+
- {{ tbl.schema }}.{{ tbl.name }}
|
|
70
|
+
{% endfor %}
|
|
71
|
+
|
|
72
|
+
**Do NOT make up table names** - only use the exact names listed above.
|
|
73
|
+
{% endif %}
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Your Task
|
|
78
|
+
|
|
79
|
+
Based on the evidence above, generate a JSON response with this exact structure:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"tableDescription": "A clear, concise description of what this table stores and its purpose in the database",
|
|
84
|
+
"reasoning": "Explain the evidence that led to this conclusion (column names, data types, relationships, sample values, etc.)",
|
|
85
|
+
"confidence": 0.95,
|
|
86
|
+
"columnDescriptions": [
|
|
87
|
+
{
|
|
88
|
+
"columnName": "ColumnName",
|
|
89
|
+
"description": "What this column represents and why it exists",
|
|
90
|
+
"reasoning": "Brief explanation of the evidence"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"foreignKeys": [
|
|
94
|
+
{
|
|
95
|
+
"columnName": "prd_id",
|
|
96
|
+
"referencesSchema": "inv",
|
|
97
|
+
"referencesTable": "prd",
|
|
98
|
+
"referencesColumn": "prd_id",
|
|
99
|
+
"confidence": 0.95
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"inferredBusinessDomain": "Sales",
|
|
103
|
+
"parentTableInsights": [
|
|
104
|
+
{
|
|
105
|
+
"parentTable": "schema.table",
|
|
106
|
+
"insight": "What this analysis reveals about the parent table that wasn't known before",
|
|
107
|
+
"confidence": 0.85
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Guidelines:**
|
|
114
|
+
1. **Table Description**: Focus on WHAT the table stores and WHY it exists. Be specific about the real-world entities or business processes it represents.
|
|
115
|
+
2. **Reasoning**: Reference specific evidence (column names, FK relationships, sample values, cardinality patterns)
|
|
116
|
+
3. **Confidence**: 0-1 scale. Be conservative. Use < 0.7 if ambiguous.
|
|
117
|
+
4. **Column Descriptions**: Every column should be described. Explain its role and meaning.
|
|
118
|
+
5. **Foreign Keys**: **CRITICAL** - Use structured format for ALL foreign key relationships:
|
|
119
|
+
- Include EVERY column that references another table
|
|
120
|
+
- Use EXACT schema and table names from the "All Database Tables" list above
|
|
121
|
+
- Specify confidence (0-1 scale) based on evidence strength
|
|
122
|
+
- Example: If `prd_id` exists, add: `{"columnName": "prd_id", "referencesSchema": "inv", "referencesTable": "prd", "referencesColumn": "prd_id", "confidence": 0.95}`
|
|
123
|
+
- **Leave empty array if no foreign keys detected**
|
|
124
|
+
6. **Business Domain**: Infer from table name and purpose (e.g., "Sales", "HR", "Inventory", "Billing", "Security")
|
|
125
|
+
7. **Parent Table Insights**: If analyzing this child table reveals new information about parent tables, include it. Examples:
|
|
126
|
+
- Discovering enum values in the parent (e.g., "Member table has a 'Type' column with values: Individual, Corporate, Student")
|
|
127
|
+
- Revealing parent table classification/purpose (e.g., "BoardMember reveals that Member table includes leadership roles, not just general members")
|
|
128
|
+
- Identifying parent table patterns (e.g., "Multiple child tables suggest Organization serves as a multi-tenant partition key")
|
|
129
|
+
- **Leave empty array if no new insights about parents**
|
|
130
|
+
|
|
131
|
+
**Important:**
|
|
132
|
+
- **When mentioning table names in descriptions, ALWAYS use the exact `schema.table` format from the "All Database Tables" list**
|
|
133
|
+
- If column has low cardinality (< 20 distinct values), those are likely enum/category values - use them to understand meaning
|
|
134
|
+
- Foreign keys reveal relationships and context - use parent table descriptions to inform your analysis
|
|
135
|
+
- High uniqueness ratio (> 95%) suggests identifier/code column
|
|
136
|
+
- String length patterns can reveal format (e.g., phone, email, code)
|
|
137
|
+
- Null percentage reveals whether column is required or optional
|
|
138
|
+
|
|
139
|
+
Return ONLY valid JSON. Do not include markdown code fences or explanatory text.
|