mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Add Exception helper class for consistent error handling and logging. Replace throw statements and console.error calls with Exception methods. Update service methods to return Error | T instead of mixed success/failure objects. Improve type safety in Claude.extractContents with explicit return type. Add WikiLinks helper to VaultCacheService for managing wiki link references. Update unit tests.
30 lines
No EOL
786 B
TypeScript
30 lines
No EOL
786 B
TypeScript
import { Exception } from "Helpers/Exception";
|
|
|
|
const services = new Map<symbol, unknown>();
|
|
|
|
export function RegisterSingleton<T>(type: symbol, instance: T) {
|
|
services.set(type, instance);
|
|
}
|
|
|
|
export function RegisterTransient<T>(type: symbol, factory: () => T) {
|
|
services.set(type, factory);
|
|
}
|
|
|
|
export function Resolve<T>(type: symbol): T {
|
|
const service = services.get(type);
|
|
if (!service) {
|
|
Exception.throw(`Service not found for type: ${type.description}`);
|
|
}
|
|
|
|
if (typeof service === 'function') {
|
|
// It's a transient factory, return a new instance
|
|
return (service as () => T)();
|
|
}
|
|
|
|
// It's a singleton, return the existing instance
|
|
return service as T;
|
|
}
|
|
|
|
export function DeregisterAllServices() {
|
|
services.clear();
|
|
} |