26 lines
877 B
TypeScript
26 lines
877 B
TypeScript
|
|
import type { BaseIntegration } from './classes.baseintegration.js';
|
||
|
|
import type { DiscoveryDescriptor } from './classes.discoverydescriptor.js';
|
||
|
|
|
||
|
|
export class IntegrationRegistry {
|
||
|
|
private readonly integrations = new Map<string, BaseIntegration>();
|
||
|
|
|
||
|
|
public register(integrationArg: BaseIntegration): void {
|
||
|
|
if (this.integrations.has(integrationArg.domain)) {
|
||
|
|
throw new Error(`Integration already registered: ${integrationArg.domain}`);
|
||
|
|
}
|
||
|
|
this.integrations.set(integrationArg.domain, integrationArg);
|
||
|
|
}
|
||
|
|
|
||
|
|
public get(domainArg: string): BaseIntegration | undefined {
|
||
|
|
return this.integrations.get(domainArg);
|
||
|
|
}
|
||
|
|
|
||
|
|
public list(): BaseIntegration[] {
|
||
|
|
return [...this.integrations.values()];
|
||
|
|
}
|
||
|
|
|
||
|
|
public getDiscoveryDescriptors(): DiscoveryDescriptor[] {
|
||
|
|
return this.list().map((integrationArg) => integrationArg.discoveryDescriptor);
|
||
|
|
}
|
||
|
|
}
|