@ecubelabs/mysql-mcp 1.0.0-next.3 → 1.0.0-next.5
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 +133 -120
- package/dist/index.js +55 -60
- package/dist/src/catalog/branch.js +35 -14
- package/dist/src/catalog/collect.js +33 -40
- package/dist/src/catalog/docs.js +4 -3
- package/dist/src/catalog/index.js +100 -31
- package/dist/src/catalog/owner.js +35 -0
- package/dist/src/catalog/render.js +38 -15
- package/dist/src/catalog/store.js +47 -14
- package/dist/src/catalog/types.js +3 -11
- package/dist/src/config/index.js +0 -36
- package/dist/src/db/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { loadedCodeBranches } from './branch.js';
|
|
4
4
|
import { normalizeDocumentPath, normalizeGithubRepo } from './docs.js';
|
|
5
|
+
import { loadedSchemaOwner, schemaOwnerOf } from './owner.js';
|
|
5
6
|
import { CATALOG_VERSION, emptyCatalog, emptyTable, normalizeName, pruneJoins } from './types.js';
|
|
6
7
|
const FLUSH_DELAY_MS = 2_000;
|
|
7
8
|
const LOCK_RETRY_MS = 25;
|
|
@@ -200,6 +201,11 @@ function mergeTable(external, local, base) {
|
|
|
200
201
|
curated: mergeCurated(external.curated ?? { notes: [], aliases: [] }, local.curated ?? { notes: [], aliases: [] }, base?.curated),
|
|
201
202
|
};
|
|
202
203
|
}
|
|
204
|
+
function mergeOwner(external, local, base) {
|
|
205
|
+
const localOwner = schemaOwnerOf(local);
|
|
206
|
+
const baseOwner = base ? schemaOwnerOf(base) : null;
|
|
207
|
+
return JSON.stringify(localOwner) !== JSON.stringify(baseOwner) ? localOwner : schemaOwnerOf(external);
|
|
208
|
+
}
|
|
203
209
|
function mergeSchema(external, local, base) {
|
|
204
210
|
const newerInventory = timestamp(local.scannedAt) >= timestamp(external.scannedAt) ? local : external;
|
|
205
211
|
const olderInventory = newerInventory === local ? external : local;
|
|
@@ -209,7 +215,17 @@ function mergeSchema(external, local, base) {
|
|
|
209
215
|
? mergeTable(newerInventory === local ? olderInventory.tables[name] : table, newerInventory === local ? table : olderInventory.tables[name], base?.tables[name])
|
|
210
216
|
: table;
|
|
211
217
|
}
|
|
212
|
-
return { ...newerInventory, tables };
|
|
218
|
+
return { ...mergeOwner(external, local, base), scannedAt: newerInventory.scannedAt, tables };
|
|
219
|
+
}
|
|
220
|
+
function mergeCodeBranches(external, local, base) {
|
|
221
|
+
const merged = {};
|
|
222
|
+
for (const repo of new Set([...Object.keys(external), ...Object.keys(local), ...Object.keys(base)])) {
|
|
223
|
+
const branch = local[repo] !== base[repo] ? local[repo] : external[repo];
|
|
224
|
+
if (branch !== undefined) {
|
|
225
|
+
merged[repo] = branch;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return merged;
|
|
213
229
|
}
|
|
214
230
|
function mergeCatalog(external, local, base) {
|
|
215
231
|
const schemas = {};
|
|
@@ -217,7 +233,7 @@ function mergeCatalog(external, local, base) {
|
|
|
217
233
|
if (external.schemas[name] && local.schemas[name]) {
|
|
218
234
|
schemas[name] = mergeSchema(external.schemas[name], local.schemas[name], base.schemas[name]);
|
|
219
235
|
}
|
|
220
|
-
else {
|
|
236
|
+
else if (!base.schemas[name]) {
|
|
221
237
|
schemas[name] = external.schemas[name] ?? local.schemas[name];
|
|
222
238
|
}
|
|
223
239
|
}
|
|
@@ -246,7 +262,7 @@ function mergeCatalog(external, local, base) {
|
|
|
246
262
|
}
|
|
247
263
|
return {
|
|
248
264
|
...local,
|
|
249
|
-
|
|
265
|
+
codeBranches: mergeCodeBranches(external.codeBranches, local.codeBranches, base.codeBranches),
|
|
250
266
|
schemas,
|
|
251
267
|
joins: pruneJoins([...joins.values()]),
|
|
252
268
|
};
|
|
@@ -332,13 +348,18 @@ export class CatalogStore {
|
|
|
332
348
|
}
|
|
333
349
|
sanitizeLoaded(loaded) {
|
|
334
350
|
const fresh = emptyCatalog(this.options);
|
|
335
|
-
fresh.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (!cached) {
|
|
351
|
+
fresh.codeBranches = loadedCodeBranches(loaded.codeBranches);
|
|
352
|
+
const loadedSchemas = loaded.schemas && typeof loaded.schemas === 'object' ? loaded.schemas : {};
|
|
353
|
+
for (const [schemaName, cached] of Object.entries(loadedSchemas)) {
|
|
354
|
+
if (!cached || typeof cached !== 'object') {
|
|
339
355
|
continue;
|
|
340
356
|
}
|
|
341
|
-
schema
|
|
357
|
+
const schema = {
|
|
358
|
+
...loadedSchemaOwner(cached),
|
|
359
|
+
scannedAt: cached.scannedAt ?? null,
|
|
360
|
+
tables: {},
|
|
361
|
+
};
|
|
362
|
+
fresh.schemas[schemaName] = schema;
|
|
342
363
|
for (const [tableName, raw] of Object.entries(cached.tables ?? {})) {
|
|
343
364
|
const base = emptyTable();
|
|
344
365
|
const table = {
|
|
@@ -400,8 +421,8 @@ export class CatalogStore {
|
|
|
400
421
|
snapshot() {
|
|
401
422
|
return structuredClone(this.data);
|
|
402
423
|
}
|
|
403
|
-
|
|
404
|
-
return this.data.
|
|
424
|
+
codeBranches() {
|
|
425
|
+
return this.data.codeBranches;
|
|
405
426
|
}
|
|
406
427
|
lookup(schemaHint, table) {
|
|
407
428
|
const index = this.ensureNameIndex();
|
|
@@ -419,9 +440,21 @@ export class CatalogStore {
|
|
|
419
440
|
}
|
|
420
441
|
return matches;
|
|
421
442
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
443
|
+
schemaScanTimes() {
|
|
444
|
+
return Object.values(this.data.schemas).map((schema) => schema.scannedAt);
|
|
445
|
+
}
|
|
446
|
+
schemaName(input) {
|
|
447
|
+
return this.ensureNameIndex().get(normalizeName(input))?.schema ?? null;
|
|
448
|
+
}
|
|
449
|
+
schemaOwners() {
|
|
450
|
+
const owners = {};
|
|
451
|
+
for (const [name, schema] of Object.entries(this.data.schemas)) {
|
|
452
|
+
const owner = schemaOwnerOf(schema);
|
|
453
|
+
if (owner) {
|
|
454
|
+
owners[name] = owner;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return owners;
|
|
425
458
|
}
|
|
426
459
|
tableMeta(schema, table) {
|
|
427
460
|
const entry = this.data.schemas[schema]?.tables[table];
|
|
@@ -6,6 +6,7 @@ export function pruneJoins(joins) {
|
|
|
6
6
|
}
|
|
7
7
|
return [...joins].sort((a, b) => b.lastUsedAt.localeCompare(a.lastUsedAt)).slice(0, JOIN_EDGE_LIMIT);
|
|
8
8
|
}
|
|
9
|
+
export const SYSTEM_SCHEMAS = ['information_schema', 'mysql', 'performance_schema', 'sys'];
|
|
9
10
|
export function normalizeName(value) {
|
|
10
11
|
return value.trim().toLowerCase();
|
|
11
12
|
}
|
|
@@ -32,21 +33,12 @@ export function emptyUsage() {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
export function emptyCatalog(options) {
|
|
35
|
-
const schemas = {};
|
|
36
|
-
for (const entry of options.appSchemas) {
|
|
37
|
-
schemas[entry.schema] = {
|
|
38
|
-
app: entry.app,
|
|
39
|
-
...(entry.description ? { description: entry.description } : {}),
|
|
40
|
-
scannedAt: null,
|
|
41
|
-
tables: {},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
36
|
return {
|
|
45
37
|
version: CATALOG_VERSION,
|
|
46
38
|
profile: options.profile,
|
|
47
39
|
fingerprint: options.fingerprint,
|
|
48
|
-
|
|
49
|
-
schemas,
|
|
40
|
+
codeBranches: {},
|
|
41
|
+
schemas: {},
|
|
50
42
|
joins: [],
|
|
51
43
|
};
|
|
52
44
|
}
|
package/dist/src/config/index.js
CHANGED
|
@@ -61,42 +61,6 @@ export const MYSQL_PROFILE = (process.env.MYSQL_PROFILE ?? '').trim().toLowerCas
|
|
|
61
61
|
const WRITE_FORBIDDEN_PROFILES = new Set(['prod', 'production']);
|
|
62
62
|
export const IS_WRITE_FORBIDDEN_PROFILE = WRITE_FORBIDDEN_PROFILES.has(MYSQL_PROFILE);
|
|
63
63
|
export const PROFILE_LABEL = MYSQL_PROFILE ? MYSQL_PROFILE.toUpperCase() : 'UNSPECIFIED';
|
|
64
|
-
function parseAppSchemas(raw) {
|
|
65
|
-
if (!raw) {
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
const entries = [];
|
|
69
|
-
const seen = new Set();
|
|
70
|
-
for (const entry of raw.split(/[;\n]/)) {
|
|
71
|
-
const trimmed = entry.trim();
|
|
72
|
-
if (!trimmed || trimmed.startsWith('#')) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const firstColon = trimmed.indexOf(':');
|
|
76
|
-
if (firstColon === -1) {
|
|
77
|
-
console.error(`[config] ignoring MYSQL_APP_SCHEMAS entry "${trimmed}": expected "app:schema" or "app:schema:description".`);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const app = trimmed.slice(0, firstColon).trim();
|
|
81
|
-
const rest = trimmed.slice(firstColon + 1);
|
|
82
|
-
const secondColon = rest.indexOf(':');
|
|
83
|
-
const schema = (secondColon === -1 ? rest : rest.slice(0, secondColon)).trim();
|
|
84
|
-
const description = secondColon === -1 ? undefined : rest.slice(secondColon + 1).trim() || undefined;
|
|
85
|
-
if (!app || !schema) {
|
|
86
|
-
console.error(`[config] ignoring MYSQL_APP_SCHEMAS entry "${trimmed}": app and schema must both be non-empty.`);
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const pair = `${app.toLowerCase()}\u0000${schema.toLowerCase()}`;
|
|
90
|
-
if (seen.has(pair)) {
|
|
91
|
-
console.error(`[config] MYSQL_APP_SCHEMAS repeats "${app}:${schema}"; keeping the first.`);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
seen.add(pair);
|
|
95
|
-
entries.push({ app, schema, description });
|
|
96
|
-
}
|
|
97
|
-
return entries;
|
|
98
|
-
}
|
|
99
|
-
export const APP_SCHEMAS = parseAppSchemas(process.env.MYSQL_APP_SCHEMAS);
|
|
100
64
|
export const MYSQL_CATALOG_ENABLED = process.env.MYSQL_CATALOG_ENABLED !== 'false';
|
|
101
65
|
export const MYSQL_CATALOG_PATH = process.env.MYSQL_CATALOG_PATH?.trim() || undefined;
|
|
102
66
|
function parseCatalogTtl(raw) {
|
package/dist/src/db/index.js
CHANGED
|
@@ -122,7 +122,7 @@ function profileBanner() {
|
|
|
122
122
|
parts.push(`database: ${db}`);
|
|
123
123
|
const branch = codeBranchSource?.();
|
|
124
124
|
if (branch) {
|
|
125
|
-
parts.push(`code: ${branch}
|
|
125
|
+
parts.push(`code: ${branch}`);
|
|
126
126
|
}
|
|
127
127
|
const tunnel = describeTunnel();
|
|
128
128
|
if (tunnel) {
|
package/package.json
CHANGED