import { AzureService, ServiceResult } from './base-service.js';
import { StorageService } from './storage.js';
import { CosmosService } from './cosmos.js';
import { SearchService } from './search.js';
import { KustoService } from './kusto.js';
import { MonitorService } from './monitor.js';
import { AppConfigService } from './appconfig.js';
import { KeyVaultService } from './keyvault.js';
import { PostgresService } from './postgres.js';
export type ServiceType =
| 'storage'
| 'cosmos'
| 'search'
| 'kusto'
| 'monitor'
| 'appconfig'
| 'keyvault'
| 'postgres';
const serviceMap = new Map<ServiceType, () => AzureService>([
['storage', () => new StorageService()],
['cosmos', () => new CosmosService()],
['search', () => new SearchService()],
['kusto', () => new KustoService()],
['monitor', () => new MonitorService()],
['appconfig', () => new AppConfigService()],
['keyvault', () => new KeyVaultService()],
['postgres', () => new PostgresService()],
]);
const instanceCache = new Map<ServiceType, AzureService>();
export function getService<T extends AzureService>(type: ServiceType): T {
let instance = instanceCache.get(type);
if (!instance) {
const factory = serviceMap.get(type);
if (!factory) throw new Error(`Unknown service type: ${type}`);
instance = factory();
instanceCache.set(type, instance);
}
return instance as T;
}
export function listServiceTypes(): ServiceType[] {
return Array.from(serviceMap.keys());
}
export function isValidServiceType(type: string): type is ServiceType {
return serviceMap.has(type as ServiceType);
}
export async function listResources(type: ServiceType, resourceGroup?: string): Promise<ServiceResult> {
const service = getService(type);
return service.list(resourceGroup);
}
export {
StorageService,
CosmosService,
SearchService,
KustoService,
MonitorService,
AppConfigService,
KeyVaultService,
PostgresService,
AzureService,
ServiceResult,
};