UNPKG

12.2 kBJavaScriptView Raw
1!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.iniettore=e()}}(function(){return function e(t,n,r){function i(a,u){if(!n[a]){if(!t[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return i(n?n:e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(s){i=!0,o=s}finally{try{!r&&u["return"]&&u["return"]()}finally{if(i)throw o}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=e("./constants"),s=e("./options"),c=e("./utils"),f=e("./createMapping"),l=r(f),p=e("./createFluentInterface"),d=r(p),g=function(){function e(t,n,r,o){i(this,e);var a;if("function"!=typeof t)throw new Error("Invalid container creation, missing contribution function");this._mappings=r||{},this._logger=n,this._resolving={},this._pending=[],this._children={},this._signalRelease=o||c.noop,this._bind(u.CONTEXT_ALIAS,this,s.VALUE,[]),a=d["default"](this._bind.bind(this)),t(a.map.bind(a)),a.done()}return a(e,[{key:"get",value:function(e){var t=this,n=e.split("."),r=o(n,2),i=r[0],a=r[1];return this._logger.log("resolving '"+i+"'",function(){if(t._resolving[i])throw new Error("Circular dependency detected while resolving '"+i+"'");if(!(i in t._mappings))throw new Error("'"+i+"' is not available. Has it ever been registered?.");t._resolving[i]=!0;try{return t._mappings[i].get(a)}catch(e){throw e.message="Failed while resolving '"+i+"' due to:\n "+e.message,e}finally{t._resolving[i]=!1}})}},{key:"using",value:function(e){var t=this;return{get:function(n){var r;for(r in e)t._bind(r,e[r],s.VALUE,[]);t.get(n);for(r in e)t._unbind(r)}}}},{key:"release",value:function(e){var t=e.split("."),n=o(t,1),r=n[0];if(r in this._mappings)try{this._mappings[r].release()}catch(i){throw i.message="Failed while releasing '"+r+"' due to:\n "+i.message,i}}},{key:"createChild",value:function(t){var n=Object.keys(this._children).length+1,r=new e(t,this._logger,Object.create(this._mappings),this._releaseChild.bind(this,n));return this._children[n]=r,r}},{key:"dispose",value:function(){this._disposeChildren(),this._disposeInstances(),this._signalRelease(),this._signalRelease=c.noop}},{key:"_disposeChildren",value:function(){var e,t=this._children;for(e in t)t.hasOwnProperty(e)&&(t[e].dispose(),this._releaseChild(e))}},{key:"_releaseChild",value:function(e){delete this._children[e]}},{key:"_disposeInstances",value:function(){var e,t=this._mappings;for(e in t)if(t.hasOwnProperty(e)){try{t[e].dispose()}catch(n){throw n.message="Failed while disposing '"+e+"' due to:\n "+n.message,n}delete t[e]}}},{key:"_bind",value:function(e,t,n,r){this._mappings[e]=l["default"](n,t,this._resolve.bind(this,r),this._release.bind(this,r)),c.isEagerSingleton(n)&&this.get(e)}},{key:"_unbind",value:function(e){this._mappings[e].dispose(),delete this._mappings[e]}},{key:"_release",value:function(e){var t=this;return e.forEach(function(e){t.release(e)})}},{key:"_resolve",value:function(e){var t=this;return e.map(function(e){return t.get(e)})}}]),e}();n["default"]=g,t.exports=n["default"]},{"./constants":3,"./createFluentInterface":4,"./createMapping":5,"./options":11,"./utils":12}],2:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(t){r(this,e),this._options=t,this._count=0,this._stack={}}return i(e,[{key:"log",value:function(e,t){return t()}},{key:"_start",value:function(e){var t=this._indent(),n=new Date;this._stack[e]=n,console.log("["+n.toISOString()+"] "+t+"Starting "+e+"...")}},{key:"_stop",value:function(e){var t=this._unindent(),n=new Date,r=n-this._stack[e];console.log("["+n.toISOString()+"] "+t+"Finished "+e+" after "+r+" ms")}},{key:"_indent",value:function(){return Array(++this._count).join(" ")}},{key:"_unindent",value:function(){return Array(this._count--).join(" ")}}]),e}();n["default"]=o,t.exports=n["default"]},{}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="$context";n.CONTEXT_ALIAS=r},{}],4:[function(e,t,n){"use strict";function r(e){return function(t){return t.createChild(e)}}function i(e,t){return function(n){return e(n).get(t)}}function o(e){var t=[];return{map:function(e){return this.done(),t.push(e),{to:function(e){return t.push(e),{as:function(){for(var e=arguments.length,n=Array(e),o=0;e>o;o++)n[o]=arguments[o];var c=a.generateMask(n);return c===u.BLUEPRINT?(n=[u.PROVIDER],t[f]=r(t[f]),t.push(a.generateMask(n)),t.push([s.CONTEXT_ALIAS]),{exports:function(e){t[f]=i(t[f],e)}}):(t.push(c),{injecting:function(){for(var e=arguments.length,n=Array(e),r=0;e>r;r++)n[r]=arguments[r];t.push(n)}})}}}}},done:function(){var n=t[p]||[];0===n.length&&(n=a.extractImplicitDependencies(t[f])),t.length>2&&(e(t[c],t[f],t[l],n),t=[])}}}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=o;var a=e("./utils"),u=e("./options"),s=e("./constants"),c=0,f=1,l=2,p=3;t.exports=n["default"]},{"./constants":3,"./options":11,"./utils":12}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t,n,r){if(!(e in v))throw new Error("Invalid flags combination. See documentation for valid flags combinations.");return d["default"](v[e],t,n,r)}Object.defineProperty(n,"__esModule",{value:!0});var a;n["default"]=o;var u=e("./utils"),s=e("./createSimpleMappingFactory"),c=r(s),f=e("./createSingletonMappingFactory"),l=r(f),p=e("./createPropertyMapper"),d=r(p),g=e("./options"),v=(a={},i(a,u.generateMask([g.VALUE]),c["default"](u.identity)),i(a,u.generateMask([g.FUNCTION]),c["default"](u.partial)),i(a,u.generateMask([g.CONSTRUCTOR]),c["default"](u.instanciate)),i(a,u.generateMask([g.PROVIDER]),c["default"](u.invoke)),i(a,u.generateMask([g.TRANSIENT,g.SINGLETON,g.PROVIDER]),l["default"](u.invoke,!0)),i(a,u.generateMask([g.TRANSIENT,g.CONSTRUCTOR,g.SINGLETON]),l["default"](u.instanciate,!0)),i(a,u.generateMask([g.LAZY,g.SINGLETON,g.PROVIDER]),l["default"](u.invoke)),i(a,u.generateMask([g.LAZY,g.SINGLETON,g.CONSTRUCTOR]),l["default"](u.instanciate)),i(a,u.generateMask([g.EAGER,g.SINGLETON,g.PROVIDER]),l["default"](u.invoke)),i(a,u.generateMask([g.EAGER,g.SINGLETON,g.CONSTRUCTOR]),l["default"](u.instanciate)),a);v[u.generateMask([g.INSTANCE])]=v[u.generateMask([g.VALUE])],t.exports=n["default"]},{"./createPropertyMapper":6,"./createSimpleMappingFactory":7,"./createSingletonMappingFactory":8,"./options":11,"./utils":12}],6:[function(e,t,n){"use strict";function r(e,t){for(var n=!0;n;){var r=e,i=t;if(n=!1,null===r)return void 0;if(l.call(r,i))return Object.getOwnPropertyDescriptor(r,i);e=Object.getPrototypeOf(r),t=i,n=!0}}function i(e,t){return function(){if(arguments.length>0)throw new Error("You cannot use a property accessor to mutate a read-only property.");return e[t]}}function o(e,t){return function(n){if(0===arguments.length)throw new Error("You cannot use a property mutator to read a write-only property.");e[t]=n}}function a(e,t){return function(n){return 0===arguments.length?e[t]:void(e[t]=n)}}function u(e,t){if(f){var n=r(e,t);if("function"==typeof n.get&&"function"==typeof n.set)return a(e,t);if("function"==typeof n.get)return i(e,t);if("function"==typeof n.set)return o(e,t)}return a(e,t)}function s(e,t){return"function"==typeof e[t]?e[t].bind(e):u(e,t)}function c(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=e.apply(null,n);return Object.create(i,{get:{value:function(e){var t=i.get();return e?s(t,e):t}}})}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=c;var f="function"==typeof Object.getOwnPropertyDescriptor,l=Object.prototype.hasOwnProperty;t.exports=n["default"]},{}],7:[function(e,t,n){"use strict";function r(e){return function(t,n){return{get:function(){return e.call(this,t,n())},release:i.noop,dispose:i.noop}}}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r;var i=e("./utils");t.exports=n["default"]},{"./utils":12}],8:[function(e,t,n){"use strict";function r(e){var t=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];return function(n,r,i){var o,a=0;return{get:function(){return"undefined"==typeof o&&(o=e.call(this,n,r())),a++,o},release:function(){a--,0==a&&t&&this.dispose()},dispose:function(){o&&(i(),"function"==typeof o.dispose&&o.dispose(),o=void 0,a=0)}}}}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r,t.exports=n["default"]},{}],9:[function(e,t,n){"use strict";function r(e){var t=e.toString().replace(a,""),n=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(u);return null===n?[]:n}function i(e){return"function"==typeof e?r(e).reduce(function(e,t){return 0===t.indexOf("$")&&(o.CONTEXT_ALIAS!==t&&(t=t.substring(1)),e.push(t)),e},[]):[]}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=i;var o=e("./constants"),a=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,u=/([^\s,]+)/g;t.exports=n["default"]},{"./constants":3}],10:[function(e,t,n){"use strict";function r(e,t){var n=t({},e);return delete n["default"],n}function i(e,t){for(var n=Object.getOwnPropertyNames(t),r=0;r<n.length;r++){var i=n[r],o=Object.getOwnPropertyDescriptor(t,i);o&&o.configurable&&void 0===e[i]&&Object.defineProperty(e,i,o)}return e}function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(n,"__esModule",{value:!0});var a=e("./Context"),u=o(a),s=e("./Logger"),c=o(s),f=e("./options");i(n,r(f,i)),n["default"]={create:function(e,t){var n;return t=t||{},n=new c["default"](t),new u["default"](e,n)}}},{"./Context":1,"./Logger":2,"./options":11}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=1;n.VALUE=r;var i=2;n.PROVIDER=i;var o=4;n.CONSTRUCTOR=o;var a=8;n.SINGLETON=a;var u=16;n.FUNCTION=u;var s=32;n.INSTANCE=s;var c=64;n.TRANSIENT=c;var f=128;n.BLUEPRINT=f;var l=256;n.LAZY=l;var p=512;n.EAGER=p},{}],12:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(e){return e}function o(e,t){return e.apply(null,t)}function a(e,t){return function(){for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];return e.apply(this,t.concat(r))}}function u(e,t){var n=Object.create(e.prototype);return e.apply(n,t),n}function s(e){return e.reduce(function(e,t){return e|t},0)}function c(e){return[g,v].indexOf(e)>-1}function f(){}Object.defineProperty(n,"__esModule",{value:!0}),n.identity=i,n.invoke=o,n.partial=a,n.instanciate=u,n.generateMask=s,n.isEagerSingleton=c,n.noop=f;var l=e("./extractImplicitDependencies"),p=r(l),d=e("./options"),g=s([d.EAGER,d.SINGLETON,d.PROVIDER]),v=s([d.EAGER,d.SINGLETON,d.CONSTRUCTOR]);n.extractImplicitDependencies=p["default"]},{"./extractImplicitDependencies":9,"./options":11}]},{},[10])(10)});
\No newline at end of file