UNPKG

@canmertinyo/fast-di

Version:

A LIGHTWEIGHT DEPENDENCY INJECTION LIB

3 lines (2 loc) 15.1 kB
var t,e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(t){!function(){var r="object"==typeof globalThis?globalThis:"object"==typeof e?e:"object"==typeof self?self:"object"==typeof this?this:function(){try{return Function("return this;")()}catch(t){}}()||function(){try{return(0,eval)("(function() { return this; })()")}catch(t){}}(),n=o(t);function o(t,e){return function(r,n){Object.defineProperty(t,r,{configurable:!0,writable:!0,value:n}),e&&e(r,n)}}void 0!==r.Reflect&&(n=o(r.Reflect,n)),function(t,e){var r=Object.prototype.hasOwnProperty,n="function"==typeof Symbol,o=n&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",i=n&&void 0!==Symbol.iterator?Symbol.iterator:"@@iterator",a="function"==typeof Object.create,u={__proto__:[]}instanceof Array,f=!a&&!u,c={create:a?function(){return G(Object.create(null))}:u?function(){return G({__proto__:null})}:function(){return G({})},has:f?function(t,e){return r.call(t,e)}:function(t,e){return e in t},get:f?function(t,e){return r.call(t,e)?t[e]:void 0}:function(t,e){return t[e]}},s=Object.getPrototypeOf(Function),p="function"==typeof Map&&"function"==typeof Map.prototype.entries?Map:function(){var t={},e=[],r=function(){function t(t,e,r){this._index=0,this._keys=t,this._values=e,this._selector=r}return t.prototype["@@iterator"]=function(){return this},t.prototype[i]=function(){return this},t.prototype.next=function(){var t=this._index;if(t>=0&&t<this._keys.length){var r=this._selector(this._keys[t],this._values[t]);return t+1>=this._keys.length?(this._index=-1,this._keys=e,this._values=e):this._index++,{value:r,done:!1}}return{value:void 0,done:!0}},t.prototype.throw=function(t){throw this._index>=0&&(this._index=-1,this._keys=e,this._values=e),t},t.prototype.return=function(t){return this._index>=0&&(this._index=-1,this._keys=e,this._values=e),{value:t,done:!0}},t}();return function(){function e(){this._keys=[],this._values=[],this._cacheKey=t,this._cacheIndex=-2}return Object.defineProperty(e.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),e.prototype.has=function(t){return this._find(t,!1)>=0},e.prototype.get=function(t){var e=this._find(t,!1);return e>=0?this._values[e]:void 0},e.prototype.set=function(t,e){var r=this._find(t,!0);return this._values[r]=e,this},e.prototype.delete=function(e){var r=this._find(e,!1);if(r>=0){for(var n=this._keys.length,o=r+1;o<n;o++)this._keys[o-1]=this._keys[o],this._values[o-1]=this._values[o];return this._keys.length--,this._values.length--,I(e,this._cacheKey)&&(this._cacheKey=t,this._cacheIndex=-2),!0}return!1},e.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=t,this._cacheIndex=-2},e.prototype.keys=function(){return new r(this._keys,this._values,n)},e.prototype.values=function(){return new r(this._keys,this._values,o)},e.prototype.entries=function(){return new r(this._keys,this._values,a)},e.prototype["@@iterator"]=function(){return this.entries()},e.prototype[i]=function(){return this.entries()},e.prototype._find=function(t,e){if(!I(this._cacheKey,t)){this._cacheIndex=-1;for(var r=0;r<this._keys.length;r++)if(I(this._keys[r],t)){this._cacheIndex=r;break}}return this._cacheIndex<0&&e&&(this._cacheIndex=this._keys.length,this._keys.push(t),this._values.push(void 0)),this._cacheIndex},e}();function n(t,e){return t}function o(t,e){return e}function a(t,e){return[t,e]}}(),l="function"==typeof Set&&"function"==typeof Set.prototype.entries?Set:function(){function t(){this._map=new p}return Object.defineProperty(t.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this._map.has(t)},t.prototype.add=function(t){return this._map.set(t,t),this},t.prototype.delete=function(t){return this._map.delete(t)},t.prototype.clear=function(){this._map.clear()},t.prototype.keys=function(){return this._map.keys()},t.prototype.values=function(){return this._map.keys()},t.prototype.entries=function(){return this._map.entries()},t.prototype["@@iterator"]=function(){return this.keys()},t.prototype[i]=function(){return this.keys()},t}(),y="function"==typeof WeakMap?WeakMap:function(){var t=16,e=c.create(),n=o();return function(){function t(){this._key=o()}return t.prototype.has=function(t){var e=i(t,!1);return void 0!==e&&c.has(e,this._key)},t.prototype.get=function(t){var e=i(t,!1);return void 0!==e?c.get(e,this._key):void 0},t.prototype.set=function(t,e){return i(t,!0)[this._key]=e,this},t.prototype.delete=function(t){var e=i(t,!1);return void 0!==e&&delete e[this._key]},t.prototype.clear=function(){this._key=o()},t}();function o(){var t;do{t="@@WeakMap@@"+u()}while(c.has(e,t));return e[t]=!0,t}function i(t,e){if(!r.call(t,n)){if(!e)return;Object.defineProperty(t,n,{value:c.create()})}return t[n]}function a(t,e){for(var r=0;r<e;++r)t[r]=255*Math.random()|0;return t}function u(){var e=function(t){if("function"==typeof Uint8Array){var e=new Uint8Array(t);return"undefined"!=typeof crypto?crypto.getRandomValues(e):"undefined"!=typeof msCrypto?msCrypto.getRandomValues(e):a(e,t),e}return a(new Array(t),t)}(t);e[6]=79&e[6]|64,e[8]=191&e[8]|128;for(var r="",n=0;n<t;++n){var o=e[n];4!==n&&6!==n&&8!==n||(r+="-"),o<16&&(r+="0"),r+=o.toString(16).toLowerCase()}return r}}(),h=n?Symbol.for("@reflect-metadata:registry"):void 0,d=function(){var t;return!x(h)&&T(e.Reflect)&&Object.isExtensible(e.Reflect)&&(t=e.Reflect[h]),x(t)&&(t=function(){var t,r,n,o,i,a,u,f,c,s,d;x(h)||void 0===e.Reflect||h in e.Reflect||"function"!=typeof e.Reflect.defineMetadata||(a=(i=e.Reflect).defineMetadata,u=i.hasOwnMetadata,f=i.getOwnMetadata,c=i.getOwnMetadataKeys,s=i.deleteMetadata,d=new y,t={isProviderFor:function(t,e){var r=d.get(t);return!(x(r)||!r.has(e))||!!c(t,e).length&&(x(r)&&(r=new l,d.set(t,r)),r.add(e),!0)},OrdinaryDefineOwnMetadata:a,OrdinaryHasOwnMetadata:u,OrdinaryGetOwnMetadata:f,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:s});var v=new y,w={registerProvider:function(e){if(!Object.isExtensible(w))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case t===e:break;case x(r):r=e;break;case r===e:break;case x(n):n=e;break;case n===e:break;default:void 0===o&&(o=new l),o.add(e)}},getProvider:_,setProvider:function(t,e,i){if(!function(t){if(x(t))throw new TypeError;return r===t||n===t||!x(o)&&o.has(t)}(i))throw new Error("Metadata provider not registered.");var a=_(t,e);if(a!==i){if(!x(a))return!1;var u=v.get(t);x(u)&&(u=new p,v.set(t,u)),u.set(e,i)}return!0}};return w;function _(e,i){var a,u=v.get(e);return x(u)||(a=u.get(i)),x(a)?(x(a=function(e,i){if(!x(r)){if(r.isProviderFor(e,i))return r;if(!x(n)){if(n.isProviderFor(e,i))return r;if(!x(o))for(var a=F(o);;){var u=L(a);if(!u)return;var f=K(u);if(f.isProviderFor(e,i))return D(a),f}}}if(!x(t)&&t.isProviderFor(e,i))return t}(e,i))||(x(u)&&(u=new p,v.set(e,u)),u.set(i,a)),a):a}}()),!x(h)&&T(e.Reflect)&&Object.isExtensible(e.Reflect)&&Object.defineProperty(e.Reflect,h,{enumerable:!1,configurable:!1,writable:!1,value:t}),t}(),v=function(t){var e=new y,r={isProviderFor:function(t,r){var n=e.get(t);return!x(n)&&n.has(r)},OrdinaryDefineOwnMetadata:function(t,e,r,o){n(r,o,!0).set(t,e)},OrdinaryHasOwnMetadata:function(t,e,r){var o=n(e,r,!1);return!x(o)&&j(o.has(t))},OrdinaryGetOwnMetadata:function(t,e,r){var o=n(e,r,!1);if(!x(o))return o.get(t)},OrdinaryOwnMetadataKeys:function(t,e){var r=[],o=n(t,e,!1);if(x(o))return r;for(var i=F(o.keys()),a=0;;){var u=L(i);if(!u)return r.length=a,r;var f=K(u);try{r[a]=f}catch(t){try{D(i)}finally{throw t}}a++}},OrdinaryDeleteMetadata:function(t,r,o){var i=n(r,o,!1);if(x(i))return!1;if(!i.delete(t))return!1;if(0===i.size){var a=e.get(r);x(a)||(a.delete(o),0===a.size&&e.delete(a))}return!0}};return d.registerProvider(r),r;function n(n,o,i){var a=e.get(n),u=!1;if(x(a)){if(!i)return;a=new p,e.set(n,a),u=!0}var f=a.get(o);if(x(f)){if(!i)return;if(f=new p,a.set(o,f),!t.setProvider(n,o,r))throw a.delete(o),u&&e.delete(n),new Error("Wrong provider for target.")}return f}}(d);function w(t,e,r){if(_(t,e,r))return!0;var n=z(e);return!m(n)&&w(t,n,r)}function _(t,e,r){var n=B(e,r,!1);return!x(n)&&j(n.OrdinaryHasOwnMetadata(t,e,r))}function g(t,e,r){if(_(t,e,r))return b(t,e,r);var n=z(e);return m(n)?void 0:g(t,n,r)}function b(t,e,r){var n=B(e,r,!1);if(!x(n))return n.OrdinaryGetOwnMetadata(t,e,r)}function O(t,e,r,n){B(r,n,!0).OrdinaryDefineOwnMetadata(t,e,r,n)}function M(t,e){var r=k(t,e),n=z(t);if(null===n)return r;var o=M(n,e);if(o.length<=0)return r;if(r.length<=0)return o;for(var i=new l,a=[],u=0,f=r;u<f.length;u++)i.has(p=f[u])||(i.add(p),a.push(p));for(var c=0,s=o;c<s.length;c++){var p;i.has(p=s[c])||(i.add(p),a.push(p))}return a}function k(t,e){var r=B(t,e,!1);return r?r.OrdinaryOwnMetadataKeys(t,e):[]}function E(t){if(null===t)return 1;switch(typeof t){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return null===t?1:6;default:return 6}}function x(t){return void 0===t}function m(t){return null===t}function T(t){return"object"==typeof t?null!==t:"function"==typeof t}function j(t){return!!t}function P(t){var e=function(t){switch(E(t)){case 0:case 1:case 2:case 3:case 4:case 5:return t}var e=A(t,o);if(void 0!==e){var r=e.call(t,"string");if(T(r))throw new TypeError;return r}return function(t){var e,r,n=t.toString;if(S(n)&&!T(r=n.call(t)))return r;if(S(e=t.valueOf)&&!T(r=e.call(t)))return r;throw new TypeError}(t)}(t);return"symbol"==typeof e?e:function(t){return""+t}(e)}function R(t){return Array.isArray?Array.isArray(t):t instanceof Object?t instanceof Array:"[object Array]"===Object.prototype.toString.call(t)}function S(t){return"function"==typeof t}function C(t){return"function"==typeof t}function I(t,e){return t===e||t!=t&&e!=e}function A(t,e){var r=t[e];if(null!=r){if(!S(r))throw new TypeError;return r}}function F(t){var e=A(t,i);if(!S(e))throw new TypeError;var r=e.call(t);if(!T(r))throw new TypeError;return r}function K(t){return t.value}function L(t){var e=t.next();return!e.done&&e}function D(t){var e=t.return;e&&e.call(t)}function z(t){var e=Object.getPrototypeOf(t);if("function"!=typeof t||t===s)return e;if(e!==s)return e;var r=t.prototype,n=r&&Object.getPrototypeOf(r);if(null==n||n===Object.prototype)return e;var o=n.constructor;return"function"!=typeof o||o===t?e:o}function B(t,e,r){var n=d.getProvider(t,e);if(!x(n))return n;if(r){if(d.setProvider(t,e,v))return v;throw new Error("Illegal state.")}}function G(t){return t.__=void 0,delete t.__,t}t("decorate",function(t,e,r,n){if(x(r)){if(!R(t))throw new TypeError;if(!C(e))throw new TypeError;return function(t,e){for(var r=t.length-1;r>=0;--r){var n=(0,t[r])(e);if(!x(n)&&!m(n)){if(!C(n))throw new TypeError;e=n}}return e}(t,e)}if(!R(t))throw new TypeError;if(!T(e))throw new TypeError;if(!T(n)&&!x(n)&&!m(n))throw new TypeError;return m(n)&&(n=void 0),function(t,e,r,n){for(var o=t.length-1;o>=0;--o){var i=(0,t[o])(e,r,n);if(!x(i)&&!m(i)){if(!T(i))throw new TypeError;n=i}}return n}(t,e,r=P(r),n)}),t("metadata",function(t,e){return function(r,n){if(!T(r))throw new TypeError;if(!x(n)&&!function(t){switch(E(t)){case 3:case 4:return!0;default:return!1}}(n))throw new TypeError;O(t,e,r,n)}}),t("defineMetadata",function(t,e,r,n){if(!T(r))throw new TypeError;return x(n)||(n=P(n)),O(t,e,r,n)}),t("hasMetadata",function(t,e,r){if(!T(e))throw new TypeError;return x(r)||(r=P(r)),w(t,e,r)}),t("hasOwnMetadata",function(t,e,r){if(!T(e))throw new TypeError;return x(r)||(r=P(r)),_(t,e,r)}),t("getMetadata",function(t,e,r){if(!T(e))throw new TypeError;return x(r)||(r=P(r)),g(t,e,r)}),t("getOwnMetadata",function(t,e,r){if(!T(e))throw new TypeError;return x(r)||(r=P(r)),b(t,e,r)}),t("getMetadataKeys",function(t,e){if(!T(t))throw new TypeError;return x(e)||(e=P(e)),M(t,e)}),t("getOwnMetadataKeys",function(t,e){if(!T(t))throw new TypeError;return x(e)||(e=P(e)),k(t,e)}),t("deleteMetadata",function(t,e,r){if(!T(e))throw new TypeError;if(x(r)||(r=P(r)),!T(e))throw new TypeError;x(r)||(r=P(r));var n=B(e,r,!1);return!x(n)&&n.OrdinaryDeleteMetadata(t,e,r)})}(n,r),void 0===r.Reflect&&(r.Reflect=t)}()}(t||(t={}));var r,n="injectable",o="providers",i="design:paramtypes",a="lifecycle";function u(t,e,r){if(s())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&p(o,r.prototype),o}function f(t){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},f(t)}function c(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,p(t,e)}function s(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(s=function(){return!!t})()}function p(t,e){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},p(t,e)}function l(t){var e="function"==typeof Map?new Map:void 0;return l=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,f(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),p(r,t)},l(t)}exports.LifeCycle=void 0,(r=exports.LifeCycle||(exports.LifeCycle={}))[r.Singleton=0]="Singleton",r[r.Transient=1]="Transient";var y=/*#__PURE__*/function(t){function e(e,r){var n;return(n=t.call(this,e)||this).statusCode=void 0,n.statusCode=r,Error.captureStackTrace(n,n.constructor),n}return c(e,t),e}(/*#__PURE__*/l(Error)),h=/*#__PURE__*/function(t){function e(e){return void 0===e&&(e="Validation error occured."),t.call(this,e,400)||this}return c(e,t),e}(y),d=/*#__PURE__*/function(){function t(){}return t.get=function(e){if((Reflect.getMetadata(a,e)||exports.LifeCycle.Singleton)===exports.LifeCycle.Transient)return u(e,(Reflect.getMetadata(i,e)||[]).map(function(e){return t.get(e)}));if(!this.instances.has(e)){var r=u(e,(Reflect.getMetadata(i,e)||[]).map(function(e){return t.get(e)}));this.instances.set(e,r)}var n=this.instances.get(e);if(!n)throw new h("Instance for "+e.name+" not found in the container.");return n},t.loadModules=function(e){this.instances.has(e)&&((Reflect.getMetadata(o,e)||[]).forEach(function(e){t.get(e)}),this.modules.add(e))},t}();d.modules=new Set,d.instances=new Map,exports.BaseException=y,exports.Container=d,exports.DESIGN_PARAM_TYPES=i,exports.INJECTABLE=n,exports.Injectable=function(t){return void 0===t&&(t={}),function(e){Reflect.defineMetadata(n,!0,e),Reflect.defineMetadata(a,t.lifeCycle||exports.LifeCycle.Singleton,e)}},exports.LIFE_CYCLE=a,exports.Module=function(t){return function(e){Reflect.defineMetadata(o,t.providers,e)}},exports.NotFoundException=h,exports.PROVIDERS=o; //# sourceMappingURL=index.js.map