mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
Deduplicate enabled tables filtering
This commit is contained in:
parent
68d1bb840f
commit
2aefebd1d9
3 changed files with 23 additions and 34 deletions
|
|
@ -3,6 +3,7 @@ import { request as httpRequest } from 'node:http';
|
|||
import { request as httpsRequest } from 'node:https';
|
||||
import { URL } from 'node:url';
|
||||
import type { KtxProjectConnectionConfig } from '../../../project/config.js';
|
||||
import { filterSnapshotTables, resolveEnabledTables } from '../../../scan/enabled-tables.js';
|
||||
import type { KtxSchemaColumn, KtxSchemaForeignKey, KtxSchemaSnapshot, KtxSchemaTable } from '../../../scan/types.js';
|
||||
import { inferKtxDimensionType, normalizeKtxNativeType } from '../../../scan/type-normalization.js';
|
||||
import type { LiveDatabaseIntrospectionPort } from './types.js';
|
||||
|
|
@ -248,24 +249,8 @@ export function createDaemonLiveDatabaseIntrospection(
|
|||
extractedAt: now().toISOString(),
|
||||
schemas,
|
||||
});
|
||||
return applyEnabledTablesFilter(snapshot, connection);
|
||||
const enabledTables = resolveEnabledTables(connection);
|
||||
return enabledTables ? filterSnapshotTables(snapshot, enabledTables) : snapshot;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function applyEnabledTablesFilter(
|
||||
snapshot: KtxSchemaSnapshot,
|
||||
connection: KtxProjectConnectionConfig,
|
||||
): KtxSchemaSnapshot {
|
||||
const allowlist = (connection as { enabled_tables?: unknown }).enabled_tables;
|
||||
if (!Array.isArray(allowlist) || allowlist.length === 0) return snapshot;
|
||||
const allowed = new Set(allowlist.filter((value): value is string => typeof value === 'string'));
|
||||
if (allowed.size === 0) return snapshot;
|
||||
return {
|
||||
...snapshot,
|
||||
tables: snapshot.tables.filter((table) => {
|
||||
const qualified = table.db ? `${table.db}.${table.name}` : table.name;
|
||||
return allowed.has(qualified);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
17
packages/context/src/scan/enabled-tables.ts
Normal file
17
packages/context/src/scan/enabled-tables.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import type { KtxSchemaSnapshot } from './types.js';
|
||||
|
||||
export function resolveEnabledTables(connection: Record<string, unknown> | undefined): Set<string> | null {
|
||||
const raw = connection?.enabled_tables;
|
||||
if (!Array.isArray(raw) || raw.length === 0) return null;
|
||||
return new Set(raw.filter((v): v is string => typeof v === 'string'));
|
||||
}
|
||||
|
||||
export function filterSnapshotTables(snapshot: KtxSchemaSnapshot, enabledTables: Set<string>): KtxSchemaSnapshot {
|
||||
return {
|
||||
...snapshot,
|
||||
tables: snapshot.tables.filter((table) => {
|
||||
const key = table.db ? `${table.db}.${table.name}` : table.name;
|
||||
return enabledTables.has(key);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import type { KtxProjectLlmConfig, KtxScanEnrichmentConfig, KtxScanRelationshipC
|
|||
import type { KtxLocalProject } from '../project/index.js';
|
||||
import { ktxLocalStateDbPath } from '../project/local-state-db.js';
|
||||
import { redactKtxScanReport } from './credentials.js';
|
||||
import { filterSnapshotTables, resolveEnabledTables } from './enabled-tables.js';
|
||||
import { completedKtxScanEnrichmentStateSummary } from './enrichment-state.js';
|
||||
import { failedKtxScanEnrichmentSummary, ktxScanErrorMessage } from './enrichment-summary.js';
|
||||
import {
|
||||
|
|
@ -320,22 +321,6 @@ async function readScanReport(
|
|||
}
|
||||
}
|
||||
|
||||
export function resolveEnabledTables(connection: Record<string, unknown> | undefined): Set<string> | null {
|
||||
const raw = connection?.enabled_tables;
|
||||
if (!Array.isArray(raw) || raw.length === 0) return null;
|
||||
return new Set(raw.filter((v): v is string => typeof v === 'string'));
|
||||
}
|
||||
|
||||
export function filterSnapshotTables(snapshot: KtxSchemaSnapshot, enabledTables: Set<string>): KtxSchemaSnapshot {
|
||||
return {
|
||||
...snapshot,
|
||||
tables: snapshot.tables.filter((table) => {
|
||||
const key = table.db ? `${table.db}.${table.name}` : table.name;
|
||||
return enabledTables.has(key);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function createFilteredConnector(connector: KtxScanConnector, enabledTables: Set<string>): KtxScanConnector {
|
||||
return {
|
||||
...connector,
|
||||
|
|
@ -346,6 +331,8 @@ function createFilteredConnector(connector: KtxScanConnector, enabledTables: Set
|
|||
};
|
||||
}
|
||||
|
||||
export { filterSnapshotTables, resolveEnabledTables } from './enabled-tables.js';
|
||||
|
||||
function withInternalLiveDatabaseAdapter(project: KtxLocalProject): KtxLocalProject {
|
||||
if (project.config.ingest.adapters.includes(LIVE_DATABASE_ADAPTER)) {
|
||||
return project;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue