Comparing version 0.2.1 to 0.3.0
@@ -9,2 +9,7 @@ # Changelog | ||
## 0.3.0 | ||
* `CHORE`: add `exports` package JSON field | ||
* `CHORE`: require `Node >= 14` | ||
## 0.2.1 | ||
@@ -11,0 +16,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.AsyncDidi = {})); | ||
}(this, function (exports) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.AsyncDidi = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
var CLASS_PATTERN = /^class /; | ||
/** | ||
* @param {function} fn | ||
* | ||
* @return {boolean} | ||
*/ | ||
function isClass(fn) { | ||
@@ -13,10 +19,26 @@ return CLASS_PATTERN.test(fn.toString()); | ||
function isArray(obj) { | ||
/** | ||
* @param {any} obj | ||
* | ||
* @return {boolean} | ||
*/ | ||
function isArray$1(obj) { | ||
return Object.prototype.toString.call(obj) === '[object Array]'; | ||
} | ||
/** | ||
* @typedef {import('./types').InjectAnnotated } InjectAnnotated | ||
*/ | ||
/** | ||
* @template T | ||
* | ||
* @params {[...string[], T] | ...string[], T} args | ||
* | ||
* @return {T & InjectAnnotated} | ||
*/ | ||
function annotate() { | ||
var args = Array.prototype.slice.call(arguments); | ||
if (args.length === 1 && isArray(args[0])) { | ||
if (args.length === 1 && isArray$1(args[0])) { | ||
args = args[0]; | ||
@@ -50,2 +72,7 @@ } | ||
/** | ||
* @param {Function} fn | ||
* | ||
* @return {string[]} | ||
*/ | ||
function parseAnnotations(fn) { | ||
@@ -70,5 +97,17 @@ | ||
/** | ||
* @typedef {[ string, string, any ]} Provider; | ||
*/ | ||
function Module() { | ||
var providers = []; | ||
var providers = /** @type {Provider[]} */ []; | ||
/** | ||
* Create a named service via a factory function. | ||
* | ||
* @param {string} name | ||
* @param {import('./types').FactoryDeclaration<?>} factory | ||
* | ||
* @return {Module} | ||
*/ | ||
this.factory = function(name, factory) { | ||
@@ -79,2 +118,10 @@ providers.push([name, 'factory', factory]); | ||
/** | ||
* Provide a named service by value. | ||
* | ||
* @param {string} name | ||
* @param {import('./types').ValueDeclaration<?>} value | ||
* | ||
* @return {Module} | ||
*/ | ||
this.value = function(name, value) { | ||
@@ -85,2 +132,10 @@ providers.push([name, 'value', value]); | ||
/** | ||
* Provide a named service via a constructor. | ||
* | ||
* @param {string} name | ||
* @param {import('./types').TypeDeclaration<?>} type | ||
* | ||
* @return {Module} | ||
*/ | ||
this.type = function(name, type) { | ||
@@ -91,2 +146,7 @@ providers.push([name, 'type', type]); | ||
/** | ||
* Iterate over all providers. | ||
* | ||
* @param { (provider: Provider) => void } iterator | ||
*/ | ||
this.forEach = function(iterator) { | ||
@@ -98,3 +158,3 @@ providers.forEach(iterator); | ||
function isArray$1(obj) { | ||
function isArray(obj) { | ||
return Object.prototype.toString.call(obj) === '[object Array]'; | ||
@@ -125,3 +185,3 @@ } | ||
var currentlyResolving = []; | ||
var providers = this._providers = Object.create( null); | ||
var providers = this._providers = Object.create(null); | ||
var instances = this._instances = Object.create(null); | ||
@@ -191,3 +251,3 @@ var loadingInstances = this._loadingInstances = Object.create(null); | ||
if (typeof fn !== 'function') { | ||
if (isArray$1(fn)) { | ||
if (isArray(fn)) { | ||
fn = annotate(fn.slice()); | ||
@@ -248,3 +308,3 @@ } else { | ||
function arrayUnwrap(type, value) { | ||
if (type !== 'value' && isArray$1(value)) { | ||
if (type !== 'value' && isArray(value)) { | ||
value = annotate(value.slice()); | ||
@@ -251,0 +311,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).AsyncDidi={})}(this,function(t){"use strict";var n=/^class /;function e(){var t,n=Array.prototype.slice.call(arguments);1===n.length&&(t=n[0],"[object Array]"===Object.prototype.toString.call(t))&&(n=n[0]);var e=n.pop();return e.$inject=n,e}var r=/constructor\s*[^(]*\(\s*([^)]*)\)/m,o=/^(?:async )?(?:function\s*)?[^(]*\(\s*([^)]*)\)/m,i=/\/\*([^*]*)\*\//m;function c(t){if("function"!=typeof t)throw new Error('Cannot annotate "'+t+'". Expected a function!');var e=t.toString().match(function(t){return n.test(t.toString())}(t)?r:o);return e&&e[1]&&e[1].split(",").map(function(t){return(e=t.match(i))?e[1].trim():t.trim()})||[]}function a(){var t=[];this.factory=function(n,e){return t.push([n,"factory",e]),this},this.value=function(n,e){return t.push([n,"value",e]),this},this.type=function(n,e){return t.push([n,"type",e]),this},this.forEach=function(n){t.forEach(n)}}function u(t){return"[object Array]"===Object.prototype.toString.call(t)}function f(t,n){return Object.prototype.hasOwnProperty.call(t,n)}t.AsyncInjector=function(t){var n={get:function(t,n){if(r.push(t),!1===n)return null;throw p('No provider for "'+t+'"!')}},r=[],o=this._providers=Object.create(null),i=this._instances=Object.create(null),s=this._loadingInstances=Object.create(null);function p(t){var n=r.join(" -> ");return r.length=0,new Error(n?t+" (Resolving: "+n+")":t)}async function l(t,e){if(!o[t]&&-1!==t.indexOf(".")){for(var c=t.split("."),a=await l(c.shift());c.length;)a=a[c.shift()];return a}if(f(i,t))return i[t];if(f(s,t))return s[t];if(f(o,t)){if(-1!==r.indexOf(t))throw r.push(t),p("Cannot resolve circular dependency!");return r.push(t),s[t]=o[t][0](o[t][1]),i[t]=await s[t],r.pop(),i[t]}return n.get(t,e)}async function h(t,n){if(void 0===n&&(n={}),"function"!=typeof t){if(!u(t))throw new Error('Cannot invoke "'+t+'". Expected a function!');t=e(t.slice())}var r=t.$inject||c(t);return{fn:t,dependencies:await Promise.all(r.map(function(t){return f(n,t)?n[t]:l(t)}))}}async function d(t){var n=await h(t),e=n.fn,r=n.dependencies;return new(Function.prototype.bind.apply(e,[null].concat(r)))}async function y(t,n,e){var r=await h(t,e),o=r.fn,i=r.dependencies;return o.apply(n,i)}i.injector=this;var v={factory:y,type:d,value:function(t){return t}};t.forEach(function(t){function n(t,n){return"value"!==t&&u(n)&&(n=e(n.slice())),n}if(t instanceof a)t.forEach(function(t){var e=t[0],r=t[1],i=t[2];o[e]=[v[r],n(r,i),r]});else if("object"==typeof t){if(t.__exports__)throw new Error("private modules are not supported");Object.keys(t).forEach(function(e){var r=t[e][0],i=t[e][1];o[e]=[v[r],n(r,i),r]})}}),this.get=l,this.invoke=y,this.instantiate=d,this.createChild=function(){throw p("child injectors are not supported")}},t.Module=a,t.annotate=e,t.parseAnnotations=c,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).AsyncDidi={})}(this,(function(t){"use strict";var n=/^class /;function e(t){return"[object Array]"===Object.prototype.toString.call(t)}function r(){var t=Array.prototype.slice.call(arguments);1===t.length&&e(t[0])&&(t=t[0]);var n=t.pop();return n.$inject=t,n}var o=/constructor\s*[^(]*\(\s*([^)]*)\)/m,i=/^(?:async )?(?:function\s*)?[^(]*\(\s*([^)]*)\)/m,c=/\/\*([^*]*)\*\//m;function a(t){if("function"!=typeof t)throw new Error('Cannot annotate "'+t+'". Expected a function!');var e=t.toString().match(function(t){return n.test(t.toString())}(t)?o:i);return e&&e[1]&&e[1].split(",").map((function(t){return(e=t.match(c))?e[1].trim():t.trim()}))||[]}function u(){var t=[];this.factory=function(n,e){return t.push([n,"factory",e]),this},this.value=function(n,e){return t.push([n,"value",e]),this},this.type=function(n,e){return t.push([n,"type",e]),this},this.forEach=function(n){t.forEach(n)}}function f(t){return"[object Array]"===Object.prototype.toString.call(t)}function s(t,n){return Object.prototype.hasOwnProperty.call(t,n)}t.AsyncInjector=function(t){var n=function(t,n){if(e.push(t),!1===n)return null;throw p('No provider for "'+t+'"!')},e=[],o=this._providers=Object.create(null),i=this._instances=Object.create(null),c=this._loadingInstances=Object.create(null);function p(t){var n=e.join(" -> ");return e.length=0,new Error(n?t+" (Resolving: "+n+")":t)}async function l(t,r){if(!o[t]&&-1!==t.indexOf(".")){for(var a=t.split("."),u=await l(a.shift());a.length;)u=u[a.shift()];return u}if(s(i,t))return i[t];if(s(c,t))return c[t];if(s(o,t)){if(-1!==e.indexOf(t))throw e.push(t),p("Cannot resolve circular dependency!");return e.push(t),c[t]=o[t][0](o[t][1]),i[t]=await c[t],e.pop(),i[t]}return n(t,r)}async function h(t,n){if(void 0===n&&(n={}),"function"!=typeof t){if(!f(t))throw new Error('Cannot invoke "'+t+'". Expected a function!');t=r(t.slice())}var e=t.$inject||a(t);return{fn:t,dependencies:await Promise.all(e.map((function(t){return s(n,t)?n[t]:l(t)})))}}async function d(t){var n=await h(t),e=n.fn,r=n.dependencies;return new(Function.prototype.bind.apply(e,[null].concat(r)))}async function y(t,n,e){var r=await h(t,e),o=r.fn,i=r.dependencies;return o.apply(n,i)}i.injector=this;var v={factory:y,type:d,value:function(t){return t}};t.forEach((function(t){function n(t,n){return"value"!==t&&f(n)&&(n=r(n.slice())),n}if(t instanceof u)t.forEach((function(t){var e=t[0],r=t[1],i=t[2];o[e]=[v[r],n(r,i),r]}));else if("object"==typeof t){if(t.__exports__)throw new Error("private modules are not supported");Object.keys(t).forEach((function(e){var r=t[e][0],i=t[e][1];o[e]=[v[r],n(r,i),r]}))}})),this.get=l,this.invoke=y,this.instantiate=d,this.createChild=function(){throw p("child injectors are not supported")}},t.Module=u,t.annotate=r,t.parseAnnotations=a,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "async-didi", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Async Dependency Injection for JavaScript", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"umd:main": "dist/async-didi.umd.js", | ||
"source": "lib/index.js", | ||
"source": "lib/index.mjs", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"all": "run-s lint test bundle test:integration", | ||
"all": "run-s lint bundle test test:integration", | ||
"bundle": "NODE_ENV=production rollup -c", | ||
"lint": "eslint .", | ||
"test": "mocha -r esm test/*.spec.js", | ||
"test": "mocha test/*.spec.mjs", | ||
"test:integration": "mocha test/integration/*.spec.js", | ||
@@ -31,17 +37,22 @@ "prepare": "run-s bundle", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"didi": "^5.2.1", | ||
"eslint": "^5.6.1", | ||
"eslint-plugin-bpmn-io": "^0.6.0", | ||
"esm": "^3.0.84", | ||
"mocha": "^5.2.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.6", | ||
"chai": "^4.3.4", | ||
"didi": "^6.0.0", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-bpmn-io": "^0.12.0", | ||
"mocha": "^9.1.3", | ||
"npm-run-all": "^4.1.2", | ||
"rollup": "^1.17.0", | ||
"rollup-plugin-commonjs": "^10.0.1", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-terser": "^5.1.1" | ||
"rollup": "^2.59.0", | ||
"rollup-plugin-terser": "^7.0.2" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"author": "Nico Rehwaldt <git_nikku@nixis.de>", | ||
"license": "MIT", | ||
"sideEffects": false | ||
"sideEffects": false, | ||
"files": [ | ||
"dist" | ||
] | ||
} |
# `async-didi` | ||
[![Build Status](https://travis-ci.com/nikku/async-didi.svg?branch=master)](https://travis-ci.com/nikku/async-didi) | ||
[![Build Status](https://github.com/nikku/async-didi/workflows/CI/badge.svg)](https://github.com/nikku/async-didi/actions?query=workflow%3ACI) | ||
@@ -11,2 +11,6 @@ An async version of [`didi`](didi), the tiny dependency injection container for JavaScript. | ||
```js | ||
import { | ||
AsyncInjector | ||
} from 'async-didi'; | ||
function Car(engine) { | ||
@@ -26,6 +30,2 @@ this.start = function() { | ||
const { | ||
AsyncInjector | ||
} = require('async-didi'); | ||
const injector = new AsyncInjector([ | ||
@@ -32,0 +32,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
30972
8
831
1