Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

awilix

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awilix - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0

135

lib/awilix.browser.js

@@ -419,3 +419,3 @@ /*! *****************************************************************************

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -434,3 +434,3 @@ function isWhiteSpace(ch) {

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -499,3 +499,3 @@ function isStringQuote(ch) {

* @param {Function} fn
* @return {Boolean}
* @return {boolean}
*/

@@ -527,3 +527,3 @@ function isClass(fn) {

*
* @return {Boolean}
* @return {boolean}
* true if the value is a function, false otherwise.

@@ -592,4 +592,5 @@ */

*
* @return {Array<Parameter>}
* Returns an array of parameters.
* @return {Array<Parameter> | null}
* Returns an array of parameters, or `null` if no
* constructor was found for a class.
*/

@@ -605,2 +606,7 @@ function parseParameterList(source) {

skipUntilConstructor();
// If we didn't find a constructor token, then we know that there
// are no dependencies in the defined class.
if (!isConstructorToken()) {
return null;
}
// Next token is the constructor identifier.

@@ -685,2 +691,3 @@ nextToken();

* Determines if the current token represents a constructor, and the next token after it is a paren
* @return {boolean}
*/

@@ -903,3 +910,3 @@ function isConstructorToken() {

var locals = injector(container);
var allKeys = uniq(__spreadArray(__spreadArray([], Reflect.ownKeys(container.cradle)), Reflect.ownKeys(locals)));
var allKeys = uniq(__spreadArray(__spreadArray([], Reflect.ownKeys(container.cradle), true), Reflect.ownKeys(locals)));
// TODO: Lots of duplication here from the container proxy.

@@ -1038,14 +1045,17 @@ // Need to refactor.

* Parses the dependencies from the given function.
* If it's a class and has an extends clause, and no reported dependencies, attempt to parse it's super constructor.
* If it's a class that extends another class, and it does
* not have a defined constructor, attempt to parse it's super constructor.
*/
function parseDependencies(fn) {
var result = parseParameterList(fn.toString());
if (result.length > 0) {
return result;
if (!result) {
// No defined constructor for a class, check if there is a parent
// we can parse.
var parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return [];
}
var parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return result;

@@ -1056,3 +1066,2 @@ }

* Family tree symbol.
* @type {Symbol}
*/

@@ -1062,3 +1071,2 @@ var FAMILY_TREE = Symbol('familyTree');

* Roll Up Registrations symbol.
* @type {Symbol}
*/

@@ -1075,3 +1083,3 @@ var ROLL_UP_REGISTRATIONS = Symbol('rollUpRegistrations');

*
* @return {object}
* @return {AwilixContainer<T>}
* The container.

@@ -1087,5 +1095,2 @@ */

var resolutionStack = [];
// For performance reasons, we store
// the rolled-up registrations when starting a resolve.
var computedRegistrations = null;
// Internal registration store for this container.

@@ -1104,3 +1109,3 @@ var registrations = {};

*
* @param {object} target
* @param {object} _target
* The proxy target. Irrelevant.

@@ -1114,3 +1119,3 @@ *

*/
get: function (target, name) { return resolve(name); },
get: function (_target, name) { return resolve(name); },
/**

@@ -1122,3 +1127,3 @@ * Setting things on the cradle throws an error.

*/
set: function (_target, name, value) {
set: function (_target, name) {
throw new Error("Attempted setting property \"" + name + "\" on container cradle - this is not allowed.");

@@ -1157,4 +1162,5 @@ },

resolve: resolve,
has: has,
dispose: dispose
hasRegistration: hasRegistration,
dispose: dispose,
getRegistration: getRegistration
},

@@ -1184,3 +1190,3 @@ /* removed in browser build */

*/
function inspect(depth, opts) {
function inspect() {
return "[AwilixContainer (" + (parentContainer ? 'scoped, ' : '') + "registrations: " + Object.keys(container.registrations).length + ")]";

@@ -1190,4 +1196,7 @@ }

* Rolls up registrations from the family tree.
* This is cached until `bustCache` clears it.
*
* This can get pretty expensive. Only used when
* iterating the cradle proxy, which is not something
* that should be done in day-to-day use, mostly for debugging.
*
* @param {boolean} bustCache

@@ -1199,10 +1208,4 @@ * Forces a recomputation.

*/
function rollUpRegistrations(bustCache) {
if (bustCache === void 0) { bustCache = false; }
if (computedRegistrations && !bustCache) {
return computedRegistrations;
}
computedRegistrations = __assign(__assign({}, (parentContainer &&
parentContainer[ROLL_UP_REGISTRATIONS](bustCache))), registrations);
return computedRegistrations;
function rollUpRegistrations() {
return __assign(__assign({}, (parentContainer && parentContainer[ROLL_UP_REGISTRATIONS]())), registrations);
}

@@ -1212,3 +1215,3 @@ /**

*/
function registrationNamesIterator() {
function cradleIterator() {
var registrations, _a, _b, _i, registrationName;

@@ -1252,3 +1255,3 @@ return __generator(this, function (_c) {

var obj = nameValueToObject(arg1, arg2);
var keys = __spreadArray(__spreadArray([], Object.keys(obj)), Object.getOwnPropertySymbols(obj));
var keys = __spreadArray(__spreadArray([], Object.keys(obj), true), Object.getOwnPropertySymbols(obj));
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {

@@ -1259,4 +1262,2 @@ var key = keys_1[_i];

}
// Invalidates the computed registrations.
computedRegistrations = null;
return container;

@@ -1272,2 +1273,18 @@ }

/**
* Recursively gets a registration by name if it exists in the
* current container or any of its' parents.
*
* @param name {string | symbol} The registration name.
*/
function getRegistration(name) {
var resolver = registrations[name];
if (resolver) {
return resolver;
}
if (parentContainer) {
return parentContainer.getRegistration(name);
}
return null;
}
/**
* Resolves the registration with the given name.

@@ -1286,9 +1303,5 @@ *

resolveOpts = resolveOpts || {};
if (!resolutionStack.length) {
// Root resolve busts the registration cache.
rollUpRegistrations(true);
}
try {
// Grab the registration by name.
var resolver = computedRegistrations[name];
var resolver = getRegistration(name);
if (resolutionStack.indexOf(name) > -1) {

@@ -1306,17 +1319,17 @@ throw new AwilixResolutionError(name, resolutionStack, 'Cyclic dependencies detected.');

if (!resolver) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
if (name === 'inspect') {
return inspectCradle;
// Checks for some edge cases.
switch (name) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
case 'inspect':
return inspectCradle;
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
case 'then':
return undefined;
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
case Symbol.iterator:
return cradleIterator;
}
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
if (name === 'then') {
return undefined;
}
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
if (name === Symbol.iterator) {
return registrationNamesIterator;
}
if (resolveOpts.allowUnregistered) {

@@ -1385,4 +1398,4 @@ return undefined;

*/
function has(name) {
return name in rollUpRegistrations();
function hasRegistration(name) {
return !!getRegistration(name);
}

@@ -1389,0 +1402,0 @@ /**

@@ -332,3 +332,3 @@ import * as glob from 'glob';

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -347,3 +347,3 @@ function isWhiteSpace(ch) {

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -429,3 +429,3 @@ function isStringQuote(ch) {

* @param {Function} fn
* @return {Boolean}
* @return {boolean}
*/

@@ -457,3 +457,3 @@ function isClass(fn) {

*
* @return {Boolean}
* @return {boolean}
* true if the value is a function, false otherwise.

@@ -497,3 +497,3 @@ */

let patternOpts = null;
if (globPattern instanceof Array) {
if (Array.isArray(globPattern)) {
patternOpts = globPattern[1];

@@ -602,4 +602,5 @@ globPattern = globPattern[0];

*
* @return {Array<Parameter>}
* Returns an array of parameters.
* @return {Array<Parameter> | null}
* Returns an array of parameters, or `null` if no
* constructor was found for a class.
*/

@@ -615,2 +616,7 @@ function parseParameterList(source) {

skipUntilConstructor();
// If we didn't find a constructor token, then we know that there
// are no dependencies in the defined class.
if (!isConstructorToken()) {
return null;
}
// Next token is the constructor identifier.

@@ -695,2 +701,3 @@ nextToken();

* Determines if the current token represents a constructor, and the next token after it is a paren
* @return {boolean}
*/

@@ -1011,14 +1018,17 @@ function isConstructorToken() {

* Parses the dependencies from the given function.
* If it's a class and has an extends clause, and no reported dependencies, attempt to parse it's super constructor.
* If it's a class that extends another class, and it does
* not have a defined constructor, attempt to parse it's super constructor.
*/
function parseDependencies(fn) {
const result = parseParameterList(fn.toString());
if (result.length > 0) {
return result;
if (!result) {
// No defined constructor for a class, check if there is a parent
// we can parse.
const parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return [];
}
const parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return result;

@@ -1207,3 +1217,2 @@ }

* Family tree symbol.
* @type {Symbol}
*/

@@ -1213,3 +1222,2 @@ const FAMILY_TREE = Symbol('familyTree');

* Roll Up Registrations symbol.
* @type {Symbol}
*/

@@ -1226,3 +1234,3 @@ const ROLL_UP_REGISTRATIONS = Symbol('rollUpRegistrations');

*
* @return {object}
* @return {AwilixContainer<T>}
* The container.

@@ -1237,5 +1245,2 @@ */

let resolutionStack = [];
// For performance reasons, we store
// the rolled-up registrations when starting a resolve.
let computedRegistrations = null;
// Internal registration store for this container.

@@ -1254,3 +1259,3 @@ const registrations = {};

*
* @param {object} target
* @param {object} _target
* The proxy target. Irrelevant.

@@ -1264,3 +1269,3 @@ *

*/
get: (target, name) => resolve(name),
get: (_target, name) => resolve(name),
/**

@@ -1272,3 +1277,3 @@ * Setting things on the cradle throws an error.

*/
set: (_target, name, value) => {
set: (_target, name) => {
throw new Error(`Attempted setting property "${name}" on container cradle - this is not allowed.`);

@@ -1307,4 +1312,5 @@ },

resolve,
has,
hasRegistration,
dispose,
getRegistration,
[util.inspect.custom]: inspect,

@@ -1329,3 +1335,3 @@ // tslint:disable-next-line

*/
function inspect(depth, opts) {
function inspect() {
return `[AwilixContainer (${parentContainer ? 'scoped, ' : ''}registrations: ${Object.keys(container.registrations).length})]`;

@@ -1335,4 +1341,7 @@ }

* Rolls up registrations from the family tree.
* This is cached until `bustCache` clears it.
*
* This can get pretty expensive. Only used when
* iterating the cradle proxy, which is not something
* that should be done in day-to-day use, mostly for debugging.
*
* @param {boolean} bustCache

@@ -1344,9 +1353,4 @@ * Forces a recomputation.

*/
function rollUpRegistrations(bustCache = false) {
if (computedRegistrations && !bustCache) {
return computedRegistrations;
}
computedRegistrations = Object.assign(Object.assign({}, (parentContainer &&
parentContainer[ROLL_UP_REGISTRATIONS](bustCache))), registrations);
return computedRegistrations;
function rollUpRegistrations() {
return Object.assign(Object.assign({}, (parentContainer && parentContainer[ROLL_UP_REGISTRATIONS]())), registrations);
}

@@ -1356,3 +1360,3 @@ /**

*/
function* registrationNamesIterator() {
function* cradleIterator() {
const registrations = rollUpRegistrations();

@@ -1382,4 +1386,2 @@ for (const registrationName in registrations) {

}
// Invalidates the computed registrations.
computedRegistrations = null;
return container;

@@ -1395,2 +1397,18 @@ }

/**
* Recursively gets a registration by name if it exists in the
* current container or any of its' parents.
*
* @param name {string | symbol} The registration name.
*/
function getRegistration(name) {
const resolver = registrations[name];
if (resolver) {
return resolver;
}
if (parentContainer) {
return parentContainer.getRegistration(name);
}
return null;
}
/**
* Resolves the registration with the given name.

@@ -1409,9 +1427,5 @@ *

resolveOpts = resolveOpts || {};
if (!resolutionStack.length) {
// Root resolve busts the registration cache.
rollUpRegistrations(true);
}
try {
// Grab the registration by name.
const resolver = computedRegistrations[name];
const resolver = getRegistration(name);
if (resolutionStack.indexOf(name) > -1) {

@@ -1429,17 +1443,18 @@ throw new AwilixResolutionError(name, resolutionStack, 'Cyclic dependencies detected.');

if (!resolver) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
if (name === util.inspect.custom || name === 'inspect') {
return inspectCradle;
// Checks for some edge cases.
switch (name) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
case util.inspect.custom:
case 'inspect':
return inspectCradle;
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
case 'then':
return undefined;
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
case Symbol.iterator:
return cradleIterator;
}
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
if (name === 'then') {
return undefined;
}
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
if (name === Symbol.iterator) {
return registrationNamesIterator;
}
if (resolveOpts.allowUnregistered) {

@@ -1508,4 +1523,4 @@ return undefined;

*/
function has(name) {
return name in rollUpRegistrations();
function hasRegistration(name) {
return !!getRegistration(name);
}

@@ -1512,0 +1527,0 @@ /**

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Awilix = {}));
}(this, (function (exports) { 'use strict';
})(this, (function (exports) { 'use strict';

@@ -426,3 +426,3 @@ /*! *****************************************************************************

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -441,3 +441,3 @@ function isWhiteSpace(ch) {

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -506,3 +506,3 @@ function isStringQuote(ch) {

* @param {Function} fn
* @return {Boolean}
* @return {boolean}
*/

@@ -534,3 +534,3 @@ function isClass(fn) {

*
* @return {Boolean}
* @return {boolean}
* true if the value is a function, false otherwise.

@@ -599,4 +599,5 @@ */

*
* @return {Array<Parameter>}
* Returns an array of parameters.
* @return {Array<Parameter> | null}
* Returns an array of parameters, or `null` if no
* constructor was found for a class.
*/

@@ -612,2 +613,7 @@ function parseParameterList(source) {

skipUntilConstructor();
// If we didn't find a constructor token, then we know that there
// are no dependencies in the defined class.
if (!isConstructorToken()) {
return null;
}
// Next token is the constructor identifier.

@@ -692,2 +698,3 @@ nextToken();

* Determines if the current token represents a constructor, and the next token after it is a paren
* @return {boolean}
*/

@@ -910,3 +917,3 @@ function isConstructorToken() {

var locals = injector(container);
var allKeys = uniq(__spreadArray(__spreadArray([], Reflect.ownKeys(container.cradle)), Reflect.ownKeys(locals)));
var allKeys = uniq(__spreadArray(__spreadArray([], Reflect.ownKeys(container.cradle), true), Reflect.ownKeys(locals)));
// TODO: Lots of duplication here from the container proxy.

@@ -1045,14 +1052,17 @@ // Need to refactor.

* Parses the dependencies from the given function.
* If it's a class and has an extends clause, and no reported dependencies, attempt to parse it's super constructor.
* If it's a class that extends another class, and it does
* not have a defined constructor, attempt to parse it's super constructor.
*/
function parseDependencies(fn) {
var result = parseParameterList(fn.toString());
if (result.length > 0) {
return result;
if (!result) {
// No defined constructor for a class, check if there is a parent
// we can parse.
var parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return [];
}
var parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return result;

@@ -1063,3 +1073,2 @@ }

* Family tree symbol.
* @type {Symbol}
*/

@@ -1069,3 +1078,2 @@ var FAMILY_TREE = Symbol('familyTree');

* Roll Up Registrations symbol.
* @type {Symbol}
*/

@@ -1082,3 +1090,3 @@ var ROLL_UP_REGISTRATIONS = Symbol('rollUpRegistrations');

*
* @return {object}
* @return {AwilixContainer<T>}
* The container.

@@ -1094,5 +1102,2 @@ */

var resolutionStack = [];
// For performance reasons, we store
// the rolled-up registrations when starting a resolve.
var computedRegistrations = null;
// Internal registration store for this container.

@@ -1111,3 +1116,3 @@ var registrations = {};

*
* @param {object} target
* @param {object} _target
* The proxy target. Irrelevant.

@@ -1121,3 +1126,3 @@ *

*/
get: function (target, name) { return resolve(name); },
get: function (_target, name) { return resolve(name); },
/**

@@ -1129,3 +1134,3 @@ * Setting things on the cradle throws an error.

*/
set: function (_target, name, value) {
set: function (_target, name) {
throw new Error("Attempted setting property \"" + name + "\" on container cradle - this is not allowed.");

@@ -1164,4 +1169,5 @@ },

resolve: resolve,
has: has,
dispose: dispose
hasRegistration: hasRegistration,
dispose: dispose,
getRegistration: getRegistration
},

@@ -1191,3 +1197,3 @@ /* removed in browser build */

*/
function inspect(depth, opts) {
function inspect() {
return "[AwilixContainer (" + (parentContainer ? 'scoped, ' : '') + "registrations: " + Object.keys(container.registrations).length + ")]";

@@ -1197,4 +1203,7 @@ }

* Rolls up registrations from the family tree.
* This is cached until `bustCache` clears it.
*
* This can get pretty expensive. Only used when
* iterating the cradle proxy, which is not something
* that should be done in day-to-day use, mostly for debugging.
*
* @param {boolean} bustCache

@@ -1206,10 +1215,4 @@ * Forces a recomputation.

*/
function rollUpRegistrations(bustCache) {
if (bustCache === void 0) { bustCache = false; }
if (computedRegistrations && !bustCache) {
return computedRegistrations;
}
computedRegistrations = __assign(__assign({}, (parentContainer &&
parentContainer[ROLL_UP_REGISTRATIONS](bustCache))), registrations);
return computedRegistrations;
function rollUpRegistrations() {
return __assign(__assign({}, (parentContainer && parentContainer[ROLL_UP_REGISTRATIONS]())), registrations);
}

@@ -1219,3 +1222,3 @@ /**

*/
function registrationNamesIterator() {
function cradleIterator() {
var registrations, _a, _b, _i, registrationName;

@@ -1259,3 +1262,3 @@ return __generator(this, function (_c) {

var obj = nameValueToObject(arg1, arg2);
var keys = __spreadArray(__spreadArray([], Object.keys(obj)), Object.getOwnPropertySymbols(obj));
var keys = __spreadArray(__spreadArray([], Object.keys(obj), true), Object.getOwnPropertySymbols(obj));
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {

@@ -1266,4 +1269,2 @@ var key = keys_1[_i];

}
// Invalidates the computed registrations.
computedRegistrations = null;
return container;

@@ -1279,2 +1280,18 @@ }

/**
* Recursively gets a registration by name if it exists in the
* current container or any of its' parents.
*
* @param name {string | symbol} The registration name.
*/
function getRegistration(name) {
var resolver = registrations[name];
if (resolver) {
return resolver;
}
if (parentContainer) {
return parentContainer.getRegistration(name);
}
return null;
}
/**
* Resolves the registration with the given name.

@@ -1293,9 +1310,5 @@ *

resolveOpts = resolveOpts || {};
if (!resolutionStack.length) {
// Root resolve busts the registration cache.
rollUpRegistrations(true);
}
try {
// Grab the registration by name.
var resolver = computedRegistrations[name];
var resolver = getRegistration(name);
if (resolutionStack.indexOf(name) > -1) {

@@ -1313,17 +1326,17 @@ throw new AwilixResolutionError(name, resolutionStack, 'Cyclic dependencies detected.');

if (!resolver) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
if (name === 'inspect') {
return inspectCradle;
// Checks for some edge cases.
switch (name) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
case 'inspect':
return inspectCradle;
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
case 'then':
return undefined;
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
case Symbol.iterator:
return cradleIterator;
}
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
if (name === 'then') {
return undefined;
}
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
if (name === Symbol.iterator) {
return registrationNamesIterator;
}
if (resolveOpts.allowUnregistered) {

@@ -1392,4 +1405,4 @@ return undefined;

*/
function has(name) {
return name in rollUpRegistrations();
function hasRegistration(name) {
return !!getRegistration(name);
}

@@ -1453,2 +1466,2 @@ /**

})));
}));

@@ -82,4 +82,18 @@ import { GlobWithOptions } from './list-modules';

*/
has(name: string | symbol): boolean;
hasRegistration(name: string | symbol): boolean;
/**
* Recursively gets a registration by name if it exists in the
* current container or any of its' parents.
*
* @param name {string | symbol} The registration name.
*/
getRegistration<K extends keyof Cradle>(name: K): Resolver<Cradle[K]> | null;
/**
* Recursively gets a registration by name if it exists in the
* current container or any of its' parents.
*
* @param name {string | symbol} The registration name.
*/
getRegistration<T = unknown>(name: string | symbol): Resolver<T> | null;
/**
* Given a resolver, class or function, builds it up and returns it.

@@ -140,3 +154,2 @@ * Does not cache it, this means that any lifetime configured in case of passing

* The options for the createContainer function.
* @interface ContainerOptions
*/

@@ -165,5 +178,5 @@ export interface ContainerOptions {

*
* @return {object}
* @return {AwilixContainer<T>}
* The container.
*/
export declare function createContainer<T extends object = any, U extends object = any>(options?: ContainerOptions, parentContainer?: AwilixContainer<U>): AwilixContainer<T>;

@@ -15,3 +15,2 @@ "use strict";

* Family tree symbol.
* @type {Symbol}
*/

@@ -21,3 +20,2 @@ const FAMILY_TREE = Symbol('familyTree');

* Roll Up Registrations symbol.
* @type {Symbol}
*/

@@ -34,3 +32,3 @@ const ROLL_UP_REGISTRATIONS = Symbol('rollUpRegistrations');

*
* @return {object}
* @return {AwilixContainer<T>}
* The container.

@@ -45,5 +43,2 @@ */

let resolutionStack = [];
// For performance reasons, we store
// the rolled-up registrations when starting a resolve.
let computedRegistrations = null;
// Internal registration store for this container.

@@ -62,3 +57,3 @@ const registrations = {};

*
* @param {object} target
* @param {object} _target
* The proxy target. Irrelevant.

@@ -72,3 +67,3 @@ *

*/
get: (target, name) => resolve(name),
get: (_target, name) => resolve(name),
/**

@@ -80,3 +75,3 @@ * Setting things on the cradle throws an error.

*/
set: (_target, name, value) => {
set: (_target, name) => {
throw new Error(`Attempted setting property "${name}" on container cradle - this is not allowed.`);

@@ -115,4 +110,5 @@ },

resolve,
has,
hasRegistration,
dispose,
getRegistration,
[util.inspect.custom]: inspect,

@@ -132,3 +128,3 @@ // tslint:disable-next-line

// so we can retrieve and store singletons.
const rootContainer = utils_1.last(familyTree);
const rootContainer = (0, utils_1.last)(familyTree);
return container;

@@ -138,3 +134,3 @@ /**

*/
function inspect(depth, opts) {
function inspect() {
return `[AwilixContainer (${parentContainer ? 'scoped, ' : ''}registrations: ${Object.keys(container.registrations).length})]`;

@@ -144,4 +140,7 @@ }

* Rolls up registrations from the family tree.
* This is cached until `bustCache` clears it.
*
* This can get pretty expensive. Only used when
* iterating the cradle proxy, which is not something
* that should be done in day-to-day use, mostly for debugging.
*
* @param {boolean} bustCache

@@ -153,9 +152,4 @@ * Forces a recomputation.

*/
function rollUpRegistrations(bustCache = false) {
if (computedRegistrations && !bustCache) {
return computedRegistrations;
}
computedRegistrations = Object.assign(Object.assign({}, (parentContainer &&
parentContainer[ROLL_UP_REGISTRATIONS](bustCache))), registrations);
return computedRegistrations;
function rollUpRegistrations() {
return Object.assign(Object.assign({}, (parentContainer && parentContainer[ROLL_UP_REGISTRATIONS]())), registrations);
}

@@ -165,3 +159,3 @@ /**

*/
function* registrationNamesIterator() {
function* cradleIterator() {
const registrations = rollUpRegistrations();

@@ -185,3 +179,3 @@ for (const registrationName in registrations) {

function register(arg1, arg2) {
const obj = utils_1.nameValueToObject(arg1, arg2);
const obj = (0, utils_1.nameValueToObject)(arg1, arg2);
const keys = [...Object.keys(obj), ...Object.getOwnPropertySymbols(obj)];

@@ -192,4 +186,2 @@ for (const key of keys) {

}
// Invalidates the computed registrations.
computedRegistrations = null;
return container;

@@ -205,2 +197,18 @@ }

/**
* Recursively gets a registration by name if it exists in the
* current container or any of its' parents.
*
* @param name {string | symbol} The registration name.
*/
function getRegistration(name) {
const resolver = registrations[name];
if (resolver) {
return resolver;
}
if (parentContainer) {
return parentContainer.getRegistration(name);
}
return null;
}
/**
* Resolves the registration with the given name.

@@ -219,9 +227,5 @@ *

resolveOpts = resolveOpts || {};
if (!resolutionStack.length) {
// Root resolve busts the registration cache.
rollUpRegistrations(true);
}
try {
// Grab the registration by name.
const resolver = computedRegistrations[name];
const resolver = getRegistration(name);
if (resolutionStack.indexOf(name) > -1) {

@@ -239,17 +243,18 @@ throw new errors_1.AwilixResolutionError(name, resolutionStack, 'Cyclic dependencies detected.');

if (!resolver) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
if (name === util.inspect.custom || name === 'inspect') {
return inspectCradle;
// Checks for some edge cases.
switch (name) {
// The following checks ensure that console.log on the cradle does not
// throw an error (issue #7).
case util.inspect.custom:
case 'inspect':
return inspectCradle;
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
case 'then':
return undefined;
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
case Symbol.iterator:
return cradleIterator;
}
// Edge case: Promise unwrapping will look for a "then" property and attempt to call it.
// Return undefined so that we won't cause a resolution error. (issue #109)
if (name === 'then') {
return undefined;
}
// When using `Array.from` or spreading the cradle, this will
// return the registration names.
if (name === Symbol.iterator) {
return registrationNamesIterator;
}
if (resolveOpts.allowUnregistered) {

@@ -318,4 +323,4 @@ return undefined;

*/
function has(name) {
return name in rollUpRegistrations();
function hasRegistration(name) {
return !!getRegistration(name);
}

@@ -338,5 +343,5 @@ /**

errors_1.AwilixTypeError.assert(typeof targetOrResolver === 'function', funcName, paramName, 'a function or class', targetOrResolver);
const resolver = utils_1.isClass(targetOrResolver)
? resolvers_1.asClass(targetOrResolver, opts)
: resolvers_1.asFunction(targetOrResolver, opts);
const resolver = (0, utils_1.isClass)(targetOrResolver)
? (0, resolvers_1.asClass)(targetOrResolver, opts)
: (0, resolvers_1.asFunction)(targetOrResolver, opts);
return resolver.resolve(container);

@@ -364,6 +369,6 @@ }

_loadModulesDeps.require = load_module_native_js_1.importModule;
return load_modules_1.loadModules(_loadModulesDeps, globPatterns, opts).then(() => container);
return (0, load_modules_1.loadModules)(_loadModulesDeps, globPatterns, opts).then(() => container);
}
else {
load_modules_1.loadModules(_loadModulesDeps, globPatterns, opts);
(0, load_modules_1.loadModules)(_loadModulesDeps, globPatterns, opts);
return container;

@@ -370,0 +375,0 @@ }

@@ -215,3 +215,3 @@ "use strict";

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -230,3 +230,3 @@ function isWhiteSpace(ch) {

* @param {string} ch
* @return {Boolean}
* @return {boolean}
*/

@@ -233,0 +233,0 @@ function isStringQuote(ch) {

@@ -27,3 +27,3 @@ "use strict";

let patternOpts = null;
if (globPattern instanceof Array) {
if (Array.isArray(globPattern)) {
patternOpts = globPattern[1];

@@ -57,3 +57,3 @@ globPattern = globPattern[0];

if (Array.isArray(globPatterns)) {
return utils_1.flatten(globPatterns.map((p) => _listModules(p, opts)));
return (0, utils_1.flatten)(globPatterns.map((p) => _listModules(p, opts)));
}

@@ -60,0 +60,0 @@ return _listModules(globPatterns, opts);

@@ -19,3 +19,3 @@ "use strict";

const nameFormatters = {
camelCase: (s) => camel_case_1.camelCase(s),
camelCase: (s) => (0, camel_case_1.camelCase)(s),
};

@@ -78,3 +78,3 @@ /**

for (const m of modules) {
const fileUrl = url_1.pathToFileURL(m.path).toString();
const fileUrl = (0, url_1.pathToFileURL)(m.path).toString();
importPromises.push(dependencies.require(fileUrl));

@@ -102,3 +102,3 @@ }

}
if (utils_1.isFunction(loaded)) {
if ((0, utils_1.isFunction)(loaded)) {
// for module.exports = ...

@@ -113,3 +113,3 @@ items.push({

}
if (loaded.default && utils_1.isFunction(loaded.default)) {
if (loaded.default && (0, utils_1.isFunction)(loaded.default)) {
// ES6 default export

@@ -130,3 +130,3 @@ items.push({

}
if (utils_1.isFunction(loaded[key]) && resolvers_1.RESOLVER in loaded[key]) {
if ((0, utils_1.isFunction)(loaded[key]) && resolvers_1.RESOLVER in loaded[key]) {
items.push({

@@ -196,3 +196,3 @@ name: key,

? regOpts.register
: utils_1.isClass(moduleDescriptor.value)
: (0, utils_1.isClass)(moduleDescriptor.value)
? resolvers_1.asClass

@@ -199,0 +199,0 @@ : resolvers_1.asFunction;

@@ -14,2 +14,2 @@ /**

}
export declare function parseParameterList(source: string): Array<Parameter>;
export declare function parseParameterList(source: string): Array<Parameter> | null;

@@ -11,7 +11,8 @@ "use strict";

*
* @return {Array<Parameter>}
* Returns an array of parameters.
* @return {Array<Parameter> | null}
* Returns an array of parameters, or `null` if no
* constructor was found for a class.
*/
function parseParameterList(source) {
const { next: _next, done } = function_tokenizer_1.createTokenizer(source);
const { next: _next, done } = (0, function_tokenizer_1.createTokenizer)(source);
const params = [];

@@ -24,2 +25,7 @@ let t = null;

skipUntilConstructor();
// If we didn't find a constructor token, then we know that there
// are no dependencies in the defined class.
if (!isConstructorToken()) {
return null;
}
// Next token is the constructor identifier.

@@ -104,2 +110,3 @@ nextToken();

* Determines if the current token represents a constructor, and the next token after it is a paren
* @return {boolean}
*/

@@ -106,0 +113,0 @@ function isConstructorToken() {

@@ -49,3 +49,3 @@ "use strict";

function asFunction(fn, opts) {
if (!utils_1.isFunction(fn)) {
if (!(0, utils_1.isFunction)(fn)) {
throw new errors_1.AwilixTypeError('asFunction', 'fn', 'function', fn);

@@ -78,3 +78,3 @@ }

function asClass(Type, opts) {
if (!utils_1.isFunction(Type)) {
if (!(0, utils_1.isFunction)(Type)) {
throw new errors_1.AwilixTypeError('asClass', 'Type', 'class', Type);

@@ -209,3 +209,3 @@ }

const locals = injector(container);
const allKeys = utils_1.uniq([
const allKeys = (0, utils_1.uniq)([
...Reflect.ownKeys(container.cradle),

@@ -313,16 +313,19 @@ ...Reflect.ownKeys(locals),

* Parses the dependencies from the given function.
* If it's a class and has an extends clause, and no reported dependencies, attempt to parse it's super constructor.
* If it's a class that extends another class, and it does
* not have a defined constructor, attempt to parse it's super constructor.
*/
function parseDependencies(fn) {
const result = param_parser_1.parseParameterList(fn.toString());
if (result.length > 0) {
return result;
const result = (0, param_parser_1.parseParameterList)(fn.toString());
if (!result) {
// No defined constructor for a class, check if there is a parent
// we can parse.
const parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return [];
}
const parent = Object.getPrototypeOf(fn);
if (typeof parent === 'function' && parent !== Function.prototype) {
// Try to parse the parent
return parseDependencies(parent);
}
return result;
}
//# sourceMappingURL=resolvers.js.map

@@ -38,3 +38,3 @@ import { Constructor } from './resolvers';

* @param {Function} fn
* @return {Boolean}
* @return {boolean}
*/

@@ -48,3 +48,3 @@ export declare function isClass(fn: Function | Constructor<any>): boolean;

*
* @return {Boolean}
* @return {boolean}
* true if the value is a function, false otherwise.

@@ -51,0 +51,0 @@ */

@@ -60,3 +60,3 @@ "use strict";

* @param {Function} fn
* @return {Boolean}
* @return {boolean}
*/

@@ -69,3 +69,3 @@ function isClass(fn) {

// Should only need 2 tokens.
const tokenizer = function_tokenizer_1.createTokenizer(fn.toString());
const tokenizer = (0, function_tokenizer_1.createTokenizer)(fn.toString());
const first = tokenizer.next();

@@ -90,3 +90,3 @@ if (first.type === 'class') {

*
* @return {Boolean}
* @return {boolean}
* true if the value is a function, false otherwise.

@@ -93,0 +93,0 @@ */

{
"name": "awilix",
"version": "5.0.1",
"version": "6.0.0",
"description": "Extremely powerful dependency injection container.",

@@ -53,19 +53,19 @@ "main": "lib/awilix.js",

"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/runtime": "^7.15.3",
"@types/glob": "^7.1.4",
"@types/jest": "^27.0.1",
"@types/node": "^16.6.1",
"@types/prettier": "^2.3.2",
"babel-jest": "^27.0.6",
"@babel/core": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/runtime": "^7.16.0",
"@types/glob": "^7.2.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.6",
"@types/prettier": "^2.4.1",
"babel-jest": "^27.3.1",
"coveralls": "^3.1.1",
"husky": "^7.0.0",
"husky": "^7.0.4",
"istanbul": "^0.4.5",
"jest": "^27.0.6",
"lint-staged": "^11.1.2",
"prettier": "^2.3.2",
"jest": "^27.3.1",
"lint-staged": "^11.2.6",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"rollup": "^2.56.2",
"rollup": "^2.58.3",
"rollup-plugin-commonjs": "^10.1.0",

@@ -77,3 +77,3 @@ "rollup-plugin-copy": "^3.4.0",

"smid": "^0.1.1",
"ts-jest": "^27.0.4",
"ts-jest": "^27.0.7",
"tslib": "^2.3.1",

@@ -83,7 +83,7 @@ "tslint": "^6.1.3",

"tslint-config-standard": "^9.0.0",
"typescript": "^4.3.5"
"typescript": "^4.4.4"
},
"dependencies": {
"camel-case": "^4.1.2",
"glob": "^7.1.7"
"glob": "^7.2.0"
},

@@ -106,4 +106,3 @@ "lint-staged": {

"targets": {
"browsers": "last 2 versions",
"node": "8.0.0"
"node": "12.0.0"
}

@@ -110,0 +109,0 @@ }

@@ -56,3 +56,3 @@ # Awilix

- [Universal Module (Browser Support)](#universal-module-browser-support)
- [Contributing](#contributing)
- [Contributing](#contributing)
- [What's in a name?](#whats-in-a-name)

@@ -355,4 +355,8 @@ - [Author](#author)

- `InjectionMode.CLASSIC`: Parses the function/constructor parameters, and
matches them with registrations in the container. _Don't use this if you
minify your code!_
matches them with registrations in the container. `CLASSIC` mode has a
slightly higher initialization cost as it has to parse the function/class
to figure out the dependencies at the time of registration, however resolving
them will be **much faster** than when using `PROXY`. _Don't use `CLASSIC` if
you minify your code!_ We recommend using `CLASSIC` in Node and `PROXY` in
environments where minification is needed.

@@ -368,3 +372,4 @@ ```js

Additionally, if the class has a base class but does not report any dependencies, the base class dependencies are passed in.
Additionally, if the class has a base class but does not declare a constructor of its own, Awilix
simply invokes the base constructor with whatever dependencies it requires.

@@ -379,5 +384,4 @@ ```js

class Porsche extends Car {
constructor() {
super(...arguments)
console.log(arguments[0]) // whatever "engine" is
vroom() {
console.log(this.engine) // whatever "engine" is
}

@@ -1071,3 +1075,4 @@ }

the lifetime, injection mode and more of the loaded modules.
- `opts.esModules`: Loads modules using Node's native ES modules. This is only supported on Node 14.0+ and should only be used if you're using the [Native Node ES modules](https://nodejs.org/api/esm.html)
- `opts.esModules`: Loads modules using Node's native ES modules. This is only
supported on Node 14.0+ and should only be used if you're using the [Native Node ES modules](https://nodejs.org/api/esm.html)

@@ -1345,13 +1350,6 @@ Example:

# Contributing
## Contributing
Clone repo, run `npm install` to install all dependencies, run `npm run build` to create an initial build, and then
`npm run test -- --watchAll` to start writing code.
Please see our [contributing.md](./CONTRIBUTING.md)
For code coverage, run `npm run cover`.
If you submit a PR, please aim for 100% code coverage and no linting errors.
Travis will fail if there are linting errors. Thank you for considering
contributing. :)
# What's in a name?

@@ -1358,0 +1356,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc