UNPKG

di-tory

Version:

Compose applications with dependency injection

39 lines (38 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.overrideScope = exports.normalizeScope = void 0; const Scope = { transient: 'transient', singleton: 'singleton', module: 'module', async: 'async', forced: { module: '!module', async: '!async', }, }; const normalizeScope = (scope) => (scope === null || scope === void 0 ? void 0 : scope.charAt(0)) === '!' ? scope.slice(1) : scope; exports.normalizeScope = normalizeScope; const overrideScope = (resolverScope, scope) => { if (scope === undefined) return resolverScope; const normalizedScope = (0, exports.normalizeScope)(scope); if (resolverScope === undefined) return normalizedScope; if (resolverScope.charAt(0) === '!') return resolverScope; if (resolverScope === Scope.singleton) return resolverScope; if (resolverScope === Scope.module) return normalizedScope === Scope.async || normalizedScope === Scope.transient ? normalizedScope : resolverScope; if (resolverScope === Scope.async) return normalizedScope === Scope.transient ? normalizedScope : resolverScope; return resolverScope; }; exports.overrideScope = overrideScope; exports.default = Scope;