@canmertinyo/fast-di
Version:
A LIGHTWEIGHT DEPENDENCY INJECTION LIB
3 lines (2 loc) • 13.5 kB
JavaScript
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=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!==r.Reflect&&(n=i(r.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,s={create:a?function(){return H(Object.create(null))}:u?function(){return H({__proto__:null})}:function(){return H({})},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]}},c=Object.getPrototypeOf(Function),h="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--,A(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(!A(this._cacheKey,t)){this._cacheIndex=-1;for(var r=0;r<this._keys.length;r++)if(A(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]}}(),d="function"==typeof Set&&"function"==typeof Set.prototype.entries?Set:function(){function t(){this._map=new h}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}(),l="function"==typeof WeakMap?WeakMap:function(){var t=16,e=s.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&&s.has(e,this._key)},t.prototype.get=function(t){var e=o(t,!1);return void 0!==e?s.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(s.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:s.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}}(),y=n?Symbol.for("@reflect-metadata:registry"):void 0,p=function(){var t;return!E(y)&&j(e.Reflect)&&Object.isExtensible(e.Reflect)&&(t=e.Reflect[y]),E(t)&&(t=function(){var t,r,n,i,o,a,u,f,s,c,p;E(y)||void 0===e.Reflect||y in e.Reflect||"function"!=typeof e.Reflect.defineMetadata||(a=(o=e.Reflect).defineMetadata,u=o.hasOwnMetadata,f=o.getOwnMetadata,s=o.getOwnMetadataKeys,c=o.deleteMetadata,p=new l,t={isProviderFor:function(t,e){var r=p.get(t);return!(E(r)||!r.has(e))||!!s(t,e).length&&(E(r)&&(r=new d,p.set(t,r)),r.add(e),!0)},OrdinaryDefineOwnMetadata:a,OrdinaryHasOwnMetadata:u,OrdinaryGetOwnMetadata:f,OrdinaryOwnMetadataKeys:s,OrdinaryDeleteMetadata:c});var v=new l,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 E(r):r=e;break;case r===e:break;case E(n):n=e;break;case n===e:break;default:void 0===i&&(i=new d),i.add(e)}},getProvider:_,setProvider:function(t,e,o){if(!function(t){if(E(t))throw new TypeError;return r===t||n===t||!E(i)&&i.has(t)}(o))throw new Error("Metadata provider not registered.");var a=_(t,e);if(a!==o){if(!E(a))return!1;var u=v.get(t);E(u)&&(u=new h,v.set(t,u)),u.set(e,o)}return!0}};return w;function _(e,o){var a,u=v.get(e);return E(u)||(a=u.get(o)),E(a)?(E(a=function(e,o){if(!E(r)){if(r.isProviderFor(e,o))return r;if(!E(n)){if(n.isProviderFor(e,o))return r;if(!E(i))for(var a=F(i);;){var u=z(a);if(!u)return;var f=C(u);if(f.isProviderFor(e,o))return D(a),f}}}if(!E(t)&&t.isProviderFor(e,o))return t}(e,o))||(E(u)&&(u=new h,v.set(e,u)),u.set(o,a)),a):a}}()),!E(y)&&j(e.Reflect)&&Object.isExtensible(e.Reflect)&&Object.defineProperty(e.Reflect,y,{enumerable:!1,configurable:!1,writable:!1,value:t}),t}(),v=function(t){var e=new l,r={isProviderFor:function(t,r){var n=e.get(t);return!E(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!E(i)&&P(i.has(t))},OrdinaryGetOwnMetadata:function(t,e,r){var i=n(e,r,!1);if(!E(i))return i.get(t)},OrdinaryOwnMetadataKeys:function(t,e){var r=[],i=n(t,e,!1);if(E(i))return r;for(var o=F(i.keys()),a=0;;){var u=z(o);if(!u)return r.length=a,r;var f=C(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(E(o))return!1;if(!o.delete(t))return!1;if(0===o.size){var a=e.get(r);E(a)||(a.delete(i),0===a.size&&e.delete(a))}return!0}};return p.registerProvider(r),r;function n(n,i,o){var a=e.get(n),u=!1;if(E(a)){if(!o)return;a=new h,e.set(n,a),u=!0}var f=a.get(i);if(E(f)){if(!o)return;if(f=new h,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}}(p);function w(t,e,r){if(_(t,e,r))return!0;var n=W(e);return!T(n)&&w(t,n,r)}function _(t,e,r){var n=G(e,r,!1);return!E(n)&&P(n.OrdinaryHasOwnMetadata(t,e,r))}function g(t,e,r){if(_(t,e,r))return b(t,e,r);var n=W(e);return T(n)?void 0:g(t,n,r)}function b(t,e,r){var n=G(e,r,!1);if(!E(n))return n.OrdinaryGetOwnMetadata(t,e,r)}function O(t,e,r,n){G(r,n,!0).OrdinaryDefineOwnMetadata(t,e,r,n)}function M(t,e){var r=k(t,e),n=W(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 d,a=[],u=0,f=r;u<f.length;u++)o.has(h=f[u])||(o.add(h),a.push(h));for(var s=0,c=i;s<c.length;s++){var h;o.has(h=c[s])||(o.add(h),a.push(h))}return a}function k(t,e){var r=G(t,e,!1);return r?r.OrdinaryOwnMetadataKeys(t,e):[]}function m(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 E(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(m(t)){case 0:case 1:case 2:case 3:case 4:case 5:return t}var e=I(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 K(t){return"function"==typeof t}function A(t,e){return t===e||t!=t&&e!=e}function I(t,e){var r=t[e];if(null!=r){if(!S(r))throw new TypeError;return r}}function F(t){var e=I(t,o);if(!S(e))throw new TypeError;var r=e.call(t);if(!j(r))throw new TypeError;return r}function C(t){return t.value}function z(t){var e=t.next();return!e.done&&e}function D(t){var e=t.return;e&&e.call(t)}function W(t){var e=Object.getPrototypeOf(t);if("function"!=typeof t||t===c)return e;if(e!==c)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 G(t,e,r){var n=p.getProvider(t,e);if(!E(n))return n;if(r){if(p.setProvider(t,e,v))return v;throw new Error("Illegal state.")}}function H(t){return t.__=void 0,delete t.__,t}t("decorate",function(t,e,r,n){if(E(r)){if(!R(t))throw new TypeError;if(!K(e))throw new TypeError;return function(t,e){for(var r=t.length-1;r>=0;--r){var n=(0,t[r])(e);if(!E(n)&&!T(n)){if(!K(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)&&!E(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(!E(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(!E(n)&&!function(t){switch(m(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 E(n)||(n=x(n)),O(t,e,r,n)}),t("hasMetadata",function(t,e,r){if(!j(e))throw new TypeError;return E(r)||(r=x(r)),w(t,e,r)}),t("hasOwnMetadata",function(t,e,r){if(!j(e))throw new TypeError;return E(r)||(r=x(r)),_(t,e,r)}),t("getMetadata",function(t,e,r){if(!j(e))throw new TypeError;return E(r)||(r=x(r)),g(t,e,r)}),t("getOwnMetadata",function(t,e,r){if(!j(e))throw new TypeError;return E(r)||(r=x(r)),b(t,e,r)}),t("getMetadataKeys",function(t,e){if(!j(t))throw new TypeError;return E(e)||(e=x(e)),M(t,e)}),t("getOwnMetadataKeys",function(t,e){if(!j(t))throw new TypeError;return E(e)||(e=x(e)),k(t,e)}),t("deleteMetadata",function(t,e,r){if(!j(e))throw new TypeError;if(E(r)||(r=x(r)),!j(e))throw new TypeError;E(r)||(r=x(r));var n=G(e,r,!1);return!E(n)&&n.OrdinaryDeleteMetadata(t,e,r)})}(n,r),void 0===r.Reflect&&(r.Reflect=t)}()}(t||(t={}));const r="injectable",n="providers",i="design:paramtypes",o="lifecycle";var a;!function(t){t[t.Singleton=0]="Singleton",t[t.Transient=1]="Transient"}(a||(a={}));class u extends Error{constructor(t,e){super(t),this.statusCode=void 0,this.statusCode=e,Error.captureStackTrace(this,this.constructor)}}class f extends u{constructor(t="Validation error occured."){super(t,400)}}class s{static get(t){if((Reflect.getMetadata(o,t)||a.Singleton)===a.Transient)return new t(...(Reflect.getMetadata(i,t)||[]).map(t=>s.get(t)));if(!this.instances.has(t)){const e=new t(...(Reflect.getMetadata(i,t)||[]).map(t=>s.get(t)));this.instances.set(t,e)}const e=this.instances.get(t);if(!e)throw new f(`Instance for ${t.name} not found in the container.`);return e}static loadModules(t){this.instances.has(t)&&((Reflect.getMetadata(n,t)||[]).forEach(t=>{s.get(t)}),this.modules.add(t))}}function c(t={}){return e=>{Reflect.defineMetadata(r,!0,e),Reflect.defineMetadata(o,t.lifeCycle||a.Singleton,e)}}function h(t){return e=>{Reflect.defineMetadata(n,t.providers,e)}}s.modules=new Set,s.instances=new Map;export{u as BaseException,s as Container,i as DESIGN_PARAM_TYPES,r as INJECTABLE,c as Injectable,o as LIFE_CYCLE,a as LifeCycle,h as Module,f as NotFoundException,n as PROVIDERS};
//# sourceMappingURL=index.modern.mjs.map