UNPKG

@elsikora/cladi

Version:

Zero-dependency TypeScript DI toolkit with typed tokens and scoped lifecycles.

92 lines (89 loc) 3.39 kB
'use strict'; class ResolveInterceptorDispatcher { LOGGER; RESOLVE_INTERCEPTORS; STRINGIFY_KEY; TO_ERROR; constructor(options) { this.LOGGER = options.logger; this.RESOLVE_INTERCEPTORS = options.resolveInterceptors; this.STRINGIFY_KEY = options.stringifyKey; this.TO_ERROR = options.toError; } notifyOnError(dependencyKeySymbol, isAsync, isResolveAll, isOptional, scopeId, error) { const providerKeyDescription = this.STRINGIFY_KEY(dependencyKeySymbol); for (const resolveInterceptor of this.RESOLVE_INTERCEPTORS) { try { resolveInterceptor.onError?.({ error, isAsync, isOptional, isResolveAll, scopeId, tokenDescription: providerKeyDescription, }); } catch (callbackError) { this.LOGGER.warn("Resolve interceptor onError callback failed", { context: { callbackError: this.TO_ERROR(callbackError).message, scopeId, token: providerKeyDescription, }, source: "DIContainer", }); } } } notifyOnStart(dependencyKeySymbol, isAsync, isResolveAll, isOptional, scopeId) { const providerKeyDescription = this.STRINGIFY_KEY(dependencyKeySymbol); for (const resolveInterceptor of this.RESOLVE_INTERCEPTORS) { try { resolveInterceptor.onStart?.({ isAsync, isOptional, isResolveAll, scopeId, tokenDescription: providerKeyDescription, }); } catch (callbackError) { this.LOGGER.warn("Resolve interceptor onStart callback failed", { context: { callbackError: this.TO_ERROR(callbackError).message, scopeId, token: providerKeyDescription, }, source: "DIContainer", }); } } } notifyOnSuccess(dependencyKeySymbol, isAsync, isResolveAll, isOptional, scopeId, result) { const providerKeyDescription = this.STRINGIFY_KEY(dependencyKeySymbol); for (const resolveInterceptor of this.RESOLVE_INTERCEPTORS) { try { resolveInterceptor.onSuccess?.({ isAsync, isOptional, isResolveAll, result, scopeId, tokenDescription: providerKeyDescription, }); } catch (callbackError) { this.LOGGER.warn("Resolve interceptor onSuccess callback failed", { context: { callbackError: this.TO_ERROR(callbackError).message, scopeId, token: providerKeyDescription, }, source: "DIContainer", }); } } } } exports.ResolveInterceptorDispatcher = ResolveInterceptorDispatcher; //# sourceMappingURL=dispatcher.class.js.map