19 lines
587 B
TypeScript
19 lines
587 B
TypeScript
import type { StorageAdapter, StorageConfig } from './types.js';
|
|
|
|
type StorageType = StorageConfig['type'];
|
|
|
|
const registry = new Map<StorageType, (config: StorageConfig) => StorageAdapter>();
|
|
|
|
export function registerStorageAdapter(
|
|
type: StorageType,
|
|
factory: (config: StorageConfig) => StorageAdapter,
|
|
): void {
|
|
registry.set(type, factory);
|
|
}
|
|
|
|
export function createStorageAdapter(config: StorageConfig): StorageAdapter {
|
|
const factory = registry.get(config.type);
|
|
if (!factory) throw new Error(`No adapter registered for type: ${config.type}`);
|
|
return factory(config);
|
|
}
|