mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-01 08:59:39 +02:00
fix(cli): close driver registry type export gaps
This commit is contained in:
parent
8a8d40c993
commit
853ab10be2
2 changed files with 27 additions and 12 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
import type { KtxConnectionDriver, KtxScanConnector } from '../scan/types.js';
|
import type { KtxConnectionDriver, KtxScanConnector } from '../scan/types.js';
|
||||||
|
|
||||||
type KtxScopeConfigKey = 'dataset_ids' | 'databases' | 'schemas' | 'schema_names';
|
/** @internal */
|
||||||
|
export type KtxScopeConfigKey = 'dataset_ids' | 'databases' | 'schemas' | 'schema_names';
|
||||||
|
|
||||||
interface KtxDriverConnectorModule {
|
/** @internal */
|
||||||
|
export interface KtxDriverConnectorModule {
|
||||||
isConnectionConfig(connection: unknown): boolean;
|
isConnectionConfig(connection: unknown): boolean;
|
||||||
createScanConnector(args: {
|
createScanConnector(args: {
|
||||||
connectionId: string;
|
connectionId: string;
|
||||||
|
|
@ -181,15 +183,7 @@ export const driverRegistrations: Record<KtxConnectionDriver, KtxDriverRegistrat
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const supportedDrivers: KtxConnectionDriver[] = [
|
const supportedDrivers = Object.keys(driverRegistrations).sort() as KtxConnectionDriver[];
|
||||||
'bigquery',
|
|
||||||
'clickhouse',
|
|
||||||
'mysql',
|
|
||||||
'postgres',
|
|
||||||
'sqlite',
|
|
||||||
'snowflake',
|
|
||||||
'sqlserver',
|
|
||||||
];
|
|
||||||
|
|
||||||
function isRegisteredDriver(driver: string): driver is KtxConnectionDriver {
|
function isRegisteredDriver(driver: string): driver is KtxConnectionDriver {
|
||||||
return Object.prototype.hasOwnProperty.call(driverRegistrations, driver);
|
return Object.prototype.hasOwnProperty.call(driverRegistrations, driver);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ import {
|
||||||
getDriverRegistration,
|
getDriverRegistration,
|
||||||
listSupportedDrivers,
|
listSupportedDrivers,
|
||||||
} from '../../../src/context/connections/drivers.js';
|
} from '../../../src/context/connections/drivers.js';
|
||||||
|
import type {
|
||||||
|
KtxDriverConnectorModule,
|
||||||
|
KtxScopeConfigKey,
|
||||||
|
} from '../../../src/context/connections/drivers.js';
|
||||||
import type { KtxConnectionDriver } from '../../../src/context/scan/types.js';
|
import type { KtxConnectionDriver } from '../../../src/context/scan/types.js';
|
||||||
|
|
||||||
type FixtureFactory = (projectDir: string) => Record<string, unknown>;
|
type FixtureFactory = (projectDir: string) => Record<string, unknown>;
|
||||||
|
|
@ -66,6 +70,16 @@ const allowedScopeKeys = new Set(['dataset_ids', 'databases', 'schemas', 'schema
|
||||||
const historicSqlReaderDrivers = new Set<KtxConnectionDriver>(['postgres', 'bigquery', 'snowflake']);
|
const historicSqlReaderDrivers = new Set<KtxConnectionDriver>(['postgres', 'bigquery', 'snowflake']);
|
||||||
const localExecutorDrivers = new Set<KtxConnectionDriver>(['postgres', 'sqlite']);
|
const localExecutorDrivers = new Set<KtxConnectionDriver>(['postgres', 'sqlite']);
|
||||||
|
|
||||||
|
function assertExportedRegistryBoundaryTypes(input: {
|
||||||
|
scopeConfigKey: KtxScopeConfigKey;
|
||||||
|
connectorModule: KtxDriverConnectorModule;
|
||||||
|
}): {
|
||||||
|
scopeConfigKey: KtxScopeConfigKey;
|
||||||
|
connectorModule: KtxDriverConnectorModule;
|
||||||
|
} {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
describe('driverRegistrations', () => {
|
describe('driverRegistrations', () => {
|
||||||
let projectDir: string;
|
let projectDir: string;
|
||||||
|
|
||||||
|
|
@ -78,13 +92,15 @@ describe('driverRegistrations', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lists every supported warehouse driver', () => {
|
it('lists every supported warehouse driver', () => {
|
||||||
|
const registryDrivers = Object.keys(driverRegistrations).sort();
|
||||||
|
expect(listSupportedDrivers()).toEqual(registryDrivers);
|
||||||
expect(listSupportedDrivers()).toEqual([
|
expect(listSupportedDrivers()).toEqual([
|
||||||
'bigquery',
|
'bigquery',
|
||||||
'clickhouse',
|
'clickhouse',
|
||||||
'mysql',
|
'mysql',
|
||||||
'postgres',
|
'postgres',
|
||||||
'sqlite',
|
|
||||||
'snowflake',
|
'snowflake',
|
||||||
|
'sqlite',
|
||||||
'sqlserver',
|
'sqlserver',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
@ -97,6 +113,11 @@ describe('driverRegistrations', () => {
|
||||||
it.each(Object.values(driverRegistrations))('adapts $driver connector exports', async (registration) => {
|
it.each(Object.values(driverRegistrations))('adapts $driver connector exports', async (registration) => {
|
||||||
const connectorModule = await registration.load();
|
const connectorModule = await registration.load();
|
||||||
const connection = connectionFixtures[registration.driver](projectDir);
|
const connection = connectionFixtures[registration.driver](projectDir);
|
||||||
|
const exportedBoundary = assertExportedRegistryBoundaryTypes({
|
||||||
|
scopeConfigKey: registration.scopeConfigKey ?? 'schemas',
|
||||||
|
connectorModule,
|
||||||
|
});
|
||||||
|
expect(exportedBoundary.connectorModule.createScanConnector).toEqual(expect.any(Function));
|
||||||
|
|
||||||
expect(connectorModule.isConnectionConfig(connection)).toBe(true);
|
expect(connectorModule.isConnectionConfig(connection)).toBe(true);
|
||||||
expect(connectorModule.isConnectionConfig({})).toBe(false);
|
expect(connectorModule.isConnectionConfig({})).toBe(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue