di-tory
Version:
Compose applications with dependency injection
34 lines (33 loc) • 1.06 kB
JavaScript
const Scope = {
transient: 'transient',
singleton: 'singleton',
module: 'module',
async: 'async',
forced: {
module: '!module',
async: '!async',
},
};
export const normalizeScope = (scope) => scope?.charAt(0) === '!' ? scope.slice(1) : scope;
export const overrideScope = (resolverScope, scope) => {
if (scope === undefined)
return resolverScope;
const normalizedScope = 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;
};
export default Scope;