@canmertinyo/fast-di
Version:
A LIGHTWEIGHT DEPENDENCY INJECTION LIB
3 lines (2 loc) • 15.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).fastDi={})}(this,function(t){var e,r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(t){!function(){var e="object"==typeof globalThis?globalThis:"object"==typeof r?r:"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=i(t);function i(t,e){return function(r,n){Object.defineProperty(t,r,{configurable:!0,writable:!0,value:n}),e&&e(r,n)}}void 0!==e.Reflect&&(n=i(e.Reflect,n)),function(t,e){var r=Object.prototype.hasOwnProperty,n="function"==typeof Symbol,i=n&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",o=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),l="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[o]=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,i=r+1;i<n;i++)this._keys[i-1]=this._keys[i],this._values[i-1]=this._values[i];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,i)},e.prototype.entries=function(){return new r(this._keys,this._values,a)},e.prototype["@@iterator"]=function(){return this.entries()},e.prototype[o]=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 i(t,e){return e}function a(t,e){return[t,e]}}(),y="function"==typeof Set&&"function"==typeof Set.prototype.entries?Set:function(){function t(){this._map=new l}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[o]=function(){return this.keys()},t}(),p="function"==typeof WeakMap?WeakMap:function(){var t=16,e=c.create(),n=i();return function(){function t(){this._key=i()}return t.prototype.has=function(t){var e=o(t,!1);return void 0!==e&&c.has(e,this._key)},t.prototype.get=function(t){var e=o(t,!1);return void 0!==e?c.get(e,this._key):void 0},t.prototype.set=function(t,e){return o(t,!0)[this._key]=e,this},t.prototype.delete=function(t){var e=o(t,!1);return void 0!==e&&delete e[this._key]},t.prototype.clear=function(){this._key=i()},t}();function i(){var t;do{t="@@WeakMap@@"+u()}while(c.has(e,t));return e[t]=!0,t}function o(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 i=e[n];4!==n&&6!==n&&8!==n||(r+="-"),i<16&&(r+="0"),r+=i.toString(16).toLowerCase()}return r}}(),d=n?Symbol.for("@reflect-metadata:registry"):void 0,h=function(){var t;return!m(d)&&j(e.Reflect)&&Object.isExtensible(e.Reflect)&&(t=e.Reflect[d]),m(t)&&(t=function(){var t,r,n,i,o,a,u,f,c,s,h;m(d)||void 0===e.Reflect||d in e.Reflect||"function"!=typeof e.Reflect.defineMetadata||(a=(o=e.Reflect).defineMetadata,u=o.hasOwnMetadata,f=o.getOwnMetadata,c=o.getOwnMetadataKeys,s=o.deleteMetadata,h=new p,t={isProviderFor:function(t,e){var r=h.get(t);return!(m(r)||!r.has(e))||!!c(t,e).length&&(m(r)&&(r=new y,h.set(t,r)),r.add(e),!0)},OrdinaryDefineOwnMetadata:a,OrdinaryHasOwnMetadata:u,OrdinaryGetOwnMetadata:f,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:s});var v=new p,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 m(r):r=e;break;case r===e:break;case m(n):n=e;break;case n===e:break;default:void 0===i&&(i=new y),i.add(e)}},getProvider:_,setProvider:function(t,e,o){if(!function(t){if(m(t))throw new TypeError;return r===t||n===t||!m(i)&&i.has(t)}(o))throw new Error("Metadata provider not registered.");var a=_(t,e);if(a!==o){if(!m(a))return!1;var u=v.get(t);m(u)&&(u=new l,v.set(t,u)),u.set(e,o)}return!0}};return w;function _(e,o){var a,u=v.get(e);return m(u)||(a=u.get(o)),m(a)?(m(a=function(e,o){if(!m(r)){if(r.isProviderFor(e,o))return r;if(!m(n)){if(n.isProviderFor(e,o))return r;if(!m(i))for(var a=F(i);;){var u=L(a);if(!u)return;var f=K(u);if(f.isProviderFor(e,o))return D(a),f}}}if(!m(t)&&t.isProviderFor(e,o))return t}(e,o))||(m(u)&&(u=new l,v.set(e,u)),u.set(o,a)),a):a}}()),!m(d)&&j(e.Reflect)&&Object.isExtensible(e.Reflect)&&Object.defineProperty(e.Reflect,d,{enumerable:!1,configurable:!1,writable:!1,value:t}),t}(),v=function(t){var e=new p,r={isProviderFor:function(t,r){var n=e.get(t);return!m(n)&&n.has(r)},OrdinaryDefineOwnMetadata:function(t,e,r,i){n(r,i,!0).set(t,e)},OrdinaryHasOwnMetadata:function(t,e,r){var i=n(e,r,!1);return!m(i)&&P(i.has(t))},OrdinaryGetOwnMetadata:function(t,e,r){var i=n(e,r,!1);if(!m(i))return i.get(t)},OrdinaryOwnMetadataKeys:function(t,e){var r=[],i=n(t,e,!1);if(m(i))return r;for(var o=F(i.keys()),a=0;;){var u=L(o);if(!u)return r.length=a,r;var f=K(u);try{r[a]=f}catch(t){try{D(o)}finally{throw t}}a++}},OrdinaryDeleteMetadata:function(t,r,i){var o=n(r,i,!1);if(m(o))return!1;if(!o.delete(t))return!1;if(0===o.size){var a=e.get(r);m(a)||(a.delete(i),0===a.size&&e.delete(a))}return!0}};return h.registerProvider(r),r;function n(n,i,o){var a=e.get(n),u=!1;if(m(a)){if(!o)return;a=new l,e.set(n,a),u=!0}var f=a.get(i);if(m(f)){if(!o)return;if(f=new l,a.set(i,f),!t.setProvider(n,i,r))throw a.delete(i),u&&e.delete(n),new Error("Wrong provider for target.")}return f}}(h);function w(t,e,r){if(_(t,e,r))return!0;var n=z(e);return!T(n)&&w(t,n,r)}function _(t,e,r){var n=B(e,r,!1);return!m(n)&&P(n.OrdinaryHasOwnMetadata(t,e,r))}function g(t,e,r){if(_(t,e,r))return b(t,e,r);var n=z(e);return T(n)?void 0:g(t,n,r)}function b(t,e,r){var n=B(e,r,!1);if(!m(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 i=M(n,e);if(i.length<=0)return r;if(r.length<=0)return i;for(var o=new y,a=[],u=0,f=r;u<f.length;u++)o.has(l=f[u])||(o.add(l),a.push(l));for(var c=0,s=i;c<s.length;c++){var l;o.has(l=s[c])||(o.add(l),a.push(l))}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 m(t){return void 0===t}function T(t){return null===t}function j(t){return"object"==typeof t?null!==t:"function"==typeof t}function P(t){return!!t}function x(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,i);if(void 0!==e){var r=e.call(t,"string");if(j(r))throw new TypeError;return r}return function(t){var e,r,n=t.toString;if(S(n)&&!j(r=n.call(t)))return r;if(S(e=t.valueOf)&&!j(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,o);if(!S(e))throw new TypeError;var r=e.call(t);if(!j(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 i=n.constructor;return"function"!=typeof i||i===t?e:i}function B(t,e,r){var n=h.getProvider(t,e);if(!m(n))return n;if(r){if(h.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(m(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(!m(n)&&!T(n)){if(!C(n))throw new TypeError;e=n}}return e}(t,e)}if(!R(t))throw new TypeError;if(!j(e))throw new TypeError;if(!j(n)&&!m(n)&&!T(n))throw new TypeError;return T(n)&&(n=void 0),function(t,e,r,n){for(var i=t.length-1;i>=0;--i){var o=(0,t[i])(e,r,n);if(!m(o)&&!T(o)){if(!j(o))throw new TypeError;n=o}}return n}(t,e,r=x(r),n)}),t("metadata",function(t,e){return function(r,n){if(!j(r))throw new TypeError;if(!m(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(!j(r))throw new TypeError;return m(n)||(n=x(n)),O(t,e,r,n)}),t("hasMetadata",function(t,e,r){if(!j(e))throw new TypeError;return m(r)||(r=x(r)),w(t,e,r)}),t("hasOwnMetadata",function(t,e,r){if(!j(e))throw new TypeError;return m(r)||(r=x(r)),_(t,e,r)}),t("getMetadata",function(t,e,r){if(!j(e))throw new TypeError;return m(r)||(r=x(r)),g(t,e,r)}),t("getOwnMetadata",function(t,e,r){if(!j(e))throw new TypeError;return m(r)||(r=x(r)),b(t,e,r)}),t("getMetadataKeys",function(t,e){if(!j(t))throw new TypeError;return m(e)||(e=x(e)),M(t,e)}),t("getOwnMetadataKeys",function(t,e){if(!j(t))throw new TypeError;return m(e)||(e=x(e)),k(t,e)}),t("deleteMetadata",function(t,e,r){if(!j(e))throw new TypeError;if(m(r)||(r=x(r)),!j(e))throw new TypeError;m(r)||(r=x(r));var n=B(e,r,!1);return!m(n)&&n.OrdinaryDeleteMetadata(t,e,r)})}(n,e),void 0===e.Reflect&&(e.Reflect=t)}()}(e||(e={}));var n,i="injectable",o="providers",a="design:paramtypes",u="lifecycle";function f(t,e,r){if(l())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var i=new(t.bind.apply(t,n));return r&&y(i,r.prototype),i}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,y(t,e)}function l(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(l=function(){return!!t})()}function y(t,e){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},y(t,e)}function p(t){var e="function"==typeof Map?new Map:void 0;return p=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 f(t,arguments,c(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,t)},p(t)}t.LifeCycle=void 0,(n=t.LifeCycle||(t.LifeCycle={}))[n.Singleton=0]="Singleton",n[n.Transient=1]="Transient";var d=/*#__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 s(e,t),e}(/*#__PURE__*/p(Error)),h=/*#__PURE__*/function(t){function e(e){return void 0===e&&(e="Validation error occured."),t.call(this,e,400)||this}return s(e,t),e}(d),v=/*#__PURE__*/function(){function e(){}return e.get=function(r){if((Reflect.getMetadata(u,r)||t.LifeCycle.Singleton)===t.LifeCycle.Transient)return f(r,(Reflect.getMetadata(a,r)||[]).map(function(t){return e.get(t)}));if(!this.instances.has(r)){var n=f(r,(Reflect.getMetadata(a,r)||[]).map(function(t){return e.get(t)}));this.instances.set(r,n)}var i=this.instances.get(r);if(!i)throw new h("Instance for "+r.name+" not found in the container.");return i},e.loadModules=function(t){this.instances.has(t)&&((Reflect.getMetadata(o,t)||[]).forEach(function(t){e.get(t)}),this.modules.add(t))},e}();v.modules=new Set,v.instances=new Map,t.BaseException=d,t.Container=v,t.DESIGN_PARAM_TYPES=a,t.INJECTABLE=i,t.Injectable=function(e){return void 0===e&&(e={}),function(r){Reflect.defineMetadata(i,!0,r),Reflect.defineMetadata(u,e.lifeCycle||t.LifeCycle.Singleton,r)}},t.LIFE_CYCLE=u,t.Module=function(t){return function(e){Reflect.defineMetadata(o,t.providers,e)}},t.NotFoundException=h,t.PROVIDERS=o});
//# sourceMappingURL=index.umd.js.map