mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-25 08:48:08 +02:00
29 lines
834 B
TypeScript
29 lines
834 B
TypeScript
import type { SourceAdapter } from './types.js';
|
|
|
|
export class SourceAdapterRegistry {
|
|
private readonly adapters = new Map<string, SourceAdapter>();
|
|
|
|
register(adapter: SourceAdapter): void {
|
|
if (this.adapters.has(adapter.source)) {
|
|
throw new Error(`source adapter already registered for '${adapter.source}'`);
|
|
}
|
|
this.adapters.set(adapter.source, adapter);
|
|
}
|
|
|
|
get(sourceKey: string): SourceAdapter {
|
|
const adapter = this.adapters.get(sourceKey);
|
|
if (!adapter) {
|
|
const known = [...this.adapters.keys()].join(', ') || '(none)';
|
|
throw new Error(`no source adapter registered for '${sourceKey}'. Known: ${known}`);
|
|
}
|
|
return adapter;
|
|
}
|
|
|
|
has(sourceKey: string): boolean {
|
|
return this.adapters.has(sourceKey);
|
|
}
|
|
|
|
list(): string[] {
|
|
return [...this.adapters.keys()];
|
|
}
|
|
}
|