Socket
Socket
Sign inDemoInstall

@incarnate/core

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0 to 7.1.0

src/HashMatrix.spec.ts

15

dist/core.cjs.development.js

@@ -489,3 +489,14 @@ 'use strict';

_proto.invalidate = function invalidate() {
this.setValue(INVALID);
var _this6 = this;
if (!this.preventInvalidation) {
if (typeof this.debounceInvalidationMS === 'number') {
clearTimeout(this._invalidationDebounceTimeout);
this._invalidationDebounceTimeout = setTimeout(function () {
return _this6.setValue(INVALID);
}, this.debounceInvalidationMS);
} else {
this.setValue(INVALID);
}
}
};

@@ -938,3 +949,3 @@

var name = pathArray.shift();
var name = pathArray.shift() || '';
var stringName = "" + name;

@@ -941,0 +952,0 @@ var subPath = [].concat(pathArray);

2

dist/core.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(e){void 0===e&&(e={}),Object.assign(this,e)};function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function n(e,t){if(null==e)return{};var r,n,a={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(a[r]=e[r]);return a}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var o={},s=function(e){function n(t){var r;return void 0===t&&(t={}),(r=e.call(this,t)||this)._changeHandlerMap={},r._errorHandlerMap={},"string"!=typeof r.pathDelimiter&&(r.pathDelimiter=n.DEFAULT_PATH_DELIMITER),r._setDefaultName(),r}r(n,e),n.keyIsNumeric=function(e){var t=!1;try{t=Number.isInteger(parseInt(""+e,10))}catch(e){}return t};var a=n.prototype;return a._setDefaultName=function(){this.hasOwnProperty("name")||(this.name="string"==typeof this.constructor.DEFAULT_NAME?this.constructor.DEFAULT_NAME:n.DEFAULT_NAME)},a.getChangeHandlerList=function(e){var t=this.getPathString(e);return this._changeHandlerMap[t]||[]},a.setChangeHandlerList=function(e,t){void 0===t&&(t=[]);var r=this.getPathString(e);this._changeHandlerMap[r]=t},a.addChangeHandler=function(e,t){var r=this;if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.addChangeHandler(this.getPathArray(e,this.targetPath),t);if(t){var a=this.getChangeHandlerList(e);if(-1===a.indexOf(t))return a.push(t),this.setChangeHandlerList(e,a),function(){return r.removeChangeHandler(e,t)}}},a.removeChangeHandler=function(e,t){if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.removeChangeHandler(this.getPathArray(e,this.targetPath),t);var r=this.getChangeHandlerList(e);if(-1!==r.indexOf(t)){var a=[];r.forEach((function(e){e!==t&&a.push(e)})),this.setChangeHandlerList(e,a)}},a.onChange=function(e,t){var r=this;this.getChangeHandlerList(e).forEach((function(n){return n(e,t,r)}))},a.getErrorHandlerList=function(e){var t=this.getPathString(e);return this._errorHandlerMap[t]||[]},a.setErrorHandlerList=function(e,t){void 0===t&&(t=[]);var r=this.getPathString(e);this._errorHandlerMap[r]=t},a.addErrorHandler=function(e,t){var r=this;if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.addErrorHandler(this.getPathArray(e,this.targetPath),t);if(t){var a=this.getErrorHandlerList(e);if(-1===a.indexOf(t))return a.push(t),this.setErrorHandlerList(e,a),function(){return r.removeErrorHandler(e,t)}}},a.removeErrorHandler=function(e,t){if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.removeErrorHandler(this.getPathArray(e,this.targetPath),t);var r=this.getErrorHandlerList(e);if(-1!==r.indexOf(t)){var a=[];r.forEach((function(e){e!==t&&a.push(e)})),this.setErrorHandlerList(e,a)}},a.onError=function(e,t,r){var n=this;this.getErrorHandlerList(t).forEach((function(a){return a(e,t,r,n)}))},a.getBasePathArray=function(e){return void 0===e&&(e=""),e instanceof Array?[].concat(e):""===e?[]:(""+e).split(this.pathDelimiter)},a.getPathArray=function(e,t){void 0===e&&(e=""),void 0===t&&(t="");var r=this.getBasePathArray(t),n=this.getBasePathArray(e);return[].concat(r,n)},a.getPathString=function(e,t){return this.getPathArray(e,t).join(this.pathDelimiter)},a.dispatchChanges=function(e){var t=this.getPathArray(e),r=this.getPathString(t);if(t.length)for(var n=[].concat(t);n.length;)this.onChange(this.getPathString(n),r),n.pop();this.onChange("",r)},a.dispatchErrors=function(e,t){var r=this.getPathArray(t),n=this.getPathString(r);if(r.length)for(var a=[].concat(r);a.length;)this.onError(e,this.getPathString(a),n),a.pop();this.onError(e,"",n)},a._setErrorInternal=function(e,t){if(this.hashMatrix instanceof n)return this.hashMatrix.setError(this.getPathArray(e,this.targetPath),t);this.dispatchErrors(t,e)},a.setError=function(e,t){return this._setErrorInternal(e,t)},a._getPathInternal=function(e){if(this.hashMatrix instanceof n)return this.hashMatrix.getPath(this.getPathArray(e,this.targetPath));var t=this.getPathArray(e);if(t.length){for(var r,a,o=this.hashMatrix,s=!0,h=function(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return i(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,void 0):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}(t);!(a=h()).done;){var c=a.value;try{var d;o=null===(d=o)||void 0===d?void 0:d[c]}catch(e){s=!1;break}}return s&&(r=o),r}return this.hashMatrix},a.getPath=function(e){return this._getPathInternal(e)},a._setPathInternal=function(e,r){if(this.hashMatrix instanceof n)return this.hashMatrix.setPath(this.getPathArray(e,this.targetPath),r);var a=r===o?void 0:r,i=this.getPathArray(e);if(a!==this._getPathInternal(e)){var s=t({},this.hashMatrix);if(i.length){for(var h=i.length-1,c=i[h],d=s,u=0;u<h;u++){var l=i[u];void 0===d[l]?d[l]=n.keyIsNumeric(i[u+1])?[]:{}:d[l]instanceof Array?d[l]=[].concat(d[l]):d[l]instanceof Object&&(d[l]=t({},d[l])),d=d[l]}d[c]=a,this.hashMatrix=s}else this.hashMatrix=a;this.dispatchChanges(i)}else r===o&&this.dispatchChanges(i)},a.setPath=function(e,t){return this._setPathInternal(e,t)},a.invalidatePath=function(e){this.setPath(e,o)},a.getValue=function(){return this.getPath([])},a.setValue=function(e){return this.setPath([],e)},a.invalidate=function(){this.setValue(o)},n}(e);s.DEFAULT_NAME="HashMatrix",s.DEFAULT_PATH_DELIMITER=".",s.ERRORS={INVALID_PATH_DELIMITER:"INVALID_PATH_DELIMITER"},"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var h,c=function(e){function a(t){var r,a=void 0===t?{}:t,i=a.dependencies,o=void 0===i?[]:i,h=n(a,["dependencies"]);return(r=e.call(this,h)||this).handleDependencyChange=function(){r.invalidate()},r.addDependencyChangeHandler=function(e){e instanceof s&&e.addChangeHandler("",r.handleDependencyChange)},r.removeDependencyChangeHandler=function(e){e instanceof s&&e.removeChangeHandler("",r.handleDependencyChange)},r.addDependencyMapChangeHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.addDependencyChangeHandler(e[t])}))},r.removeDependencyMapChangeHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.removeDependencyChangeHandler(e[t])}))},r.handleDependencyError=function(e,t,n,a){var i=new Error("A dependency failed to resolve.");"object"==typeof e&&(i.source={error:e,path:t,causePath:n,target:a}),r.setError([],i)},r.addDependencyErrorHandler=function(e){e instanceof s&&e.addErrorHandler("",r.handleDependencyError)},r.removeDependencyErrorHandler=function(e){e instanceof s&&e.removeErrorHandler("",r.handleDependencyError)},r.addDependencyMapErrorHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.addDependencyErrorHandler(e[t])}))},r.removeDependencyMapErrorHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.removeDependencyErrorHandler(e[t])}))},r.resolving=!1,r.dependencies=o,r}r(a,e);var i,o=a.prototype;return o.resolveDependency=function(e){if(e instanceof s)return e.getValue()},o.resolveDependencyMap=function(e){void 0===e&&(e={});var t={},r={dependencies:t,getters:this.getters,setters:this.setters,invalidators:this.invalidators,listeners:this.listeners};for(var n in e){var a=this.resolveDependency(e[n]);if(this.strict&&void 0===a)return;t[n]=a}return r},o.handleFactoryPromise=function(t){try{var r=this,n=function(){if(t){var n=function(){r.resolving=!1,e.prototype.setPath.call(r,[],a)},a=void 0,i=function(e,r){try{var n=Promise.resolve(t).then((function(e){a=e}))}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,(function(e){r.setError([],e)}));return i&&i.then?i.then(n):n()}}();return Promise.resolve(n&&n.then?n.then((function(){})):void 0)}catch(e){return Promise.reject(e)}},o.resolve=function(){var r,n;if(!this.resolving)if(this.resolving=!0,this.factory instanceof Function){var a=this.resolveDependencyMap(this.dependencies);if(void 0!==a){try{r=this.factory((void 0===(n=a)&&(n={}),!1===this.mergeDeps?n:t({},n.dependencies,n.getters,n.setters,n.invalidators,n.listeners)))}catch(e){this.setError([],e)}r instanceof Promise?this.handleFactoryPromise(r):this.resolving=!1}else r=void 0,this.resolving=!1}else r=e.prototype.getPath.call(this,[]),this.resolving=!1;return r},o.getPath=function(t){var r;if(void 0===e.prototype.getPath.call(this,[])||this.noCache){var n=this.resolve();this.resolving?r=void 0:(e.prototype.setPath.call(this,[],n),r=e.prototype.getPath.call(this,t))}else r=e.prototype.getPath.call(this,t);return r},o.getPathAsync=function(e,t){try{var r=this,n=r.getPathString(e);return Promise.resolve(new Promise((function(i,o){var s=void 0,h={remove:function(){clearTimeout(s),r.removeChangeHandler(n,h.onChange),r.removeErrorHandler(n,h.onError)},onChange:function(){try{var t=r.getPath(e);void 0!==t&&(h.remove(),i(t))}catch(t){var n=(t||{}).message;h.onError({message:void 0===n?"":n,subject:r,data:e,error:t})}},onError:function(e){h.remove(),o(e)}};r.addChangeHandler(n,h.onChange),r.addErrorHandler(n,h.onError),"number"==typeof t&&(s=setTimeout((function(){return h.onError(new Error(a.ERROR_MESSAGES.RESOLUTION_TIMEOUT))}),t)),h.onChange()})))}catch(e){return Promise.reject(e)}},o.getValueAsync=function(e){try{return Promise.resolve(this.getPathAsync([],e))}catch(e){return Promise.reject(e)}},(i=[{key:"dependencies",get:function(){return this._dependencies},set:function(e){this._dependencies&&(this.removeDependencyMapChangeHandlers(this._dependencies),this.removeDependencyMapErrorHandlers(this._dependencies)),this._dependencies=e,this._dependencies&&(this.addDependencyMapChangeHandlers(this._dependencies),this.addDependencyMapErrorHandlers(this._dependencies))}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(a.prototype,i),a}(s);c.DEFAULT_NAME="LifePod",c.ERROR_MESSAGES={RESOLUTION_TIMEOUT:"RESOLUTION_TIMEOUT"};var d={GLOBAL:"GLOBAL"},u=((h={})[d.GLOBAL]={factory:function(){return window||global}},h),l=function(e){function i(r){var n;return void 0===r&&(r={}),(n=e.call(this,r)||this)._parsedSubMap={},n.getDependency=function(e){var t;void 0===e&&(e="");var r=n.getPathArray(e),o=n.getPathString(r);if(!r.length)return a(n);var h=r.shift(),d=""+h,u=[].concat(r);!n._parsedSubMap.hasOwnProperty(d)&&(null===(t=n.subMap)||void 0===t?void 0:t.hasOwnProperty(d))&&(n._parsedSubMap[d]=n.convertDeclaration(h,n.subMap[d]));var l=n._parsedSubMap[d];return l instanceof i?l.getDependency(u):l?u.length?l instanceof c?new c({name:o,targetPath:u,hashMatrix:l,strict:n.strict}):new s({name:o,targetPath:u,hashMatrix:l}):l:new s({name:o,targetPath:[h].concat(u),hashMatrix:a(n)})},n.createGetter=function(e){return function(t){return void 0===t&&(t=[]),n.getDependency(e).getPath(t)}},n.createSetter=function(e){return function(t,r){return void 0===r&&(r=[]),n.getDependency(e).setPath(r,t)}},n.createInvalidator=function(e){return function(t){return void 0===t&&(t=[]),n.getDependency(e).invalidatePath(t)}},n.createListener=function(e){return function(t,r){return void 0===r&&(r=[]),n.getDependency(e).addChangeHandler(r,t)}},n.hashMatrix instanceof Object||(n.hashMatrix={}),n.subMap=t({},u,n.subMap),n}r(i,e);var o=i.prototype;return o.createLifePod=function(e,r){void 0===r&&(r={});var a=r.dependencies,i=void 0===a?{}:a,o=r.getters,s=void 0===o?{}:o,h=r.setters,d=void 0===h?{}:h,u=r.invalidators,l=void 0===u?{}:u,f=r.listeners,v=void 0===f?{}:f,g=r.strict,p=void 0===g?this.strict:g,y=r.pathDelimiter,E=void 0===y?this.pathDelimiter:y,P=t({},n(r,["dependencies","getters","setters","invalidators","listeners","strict","pathDelimiter"]),{name:this.getPathString(e,this.name),targetPath:e,hashMatrix:this,dependencies:this.getDependenciesFromMap(i),getters:this.createFromMap(s,this.createGetter),setters:this.createFromMap(d,this.createSetter),invalidators:this.createFromMap(l,this.createInvalidator),listeners:this.createFromMap(v,this.createListener),strict:p,pathDelimiter:E});return new c(P)},o.createIncarnate=function(e,r){var a=this;void 0===r&&(r={});var o=r.subMap,s=void 0===o?{}:o,h=r.shared,c=void 0===h?{}:h,d=r.strict,u=void 0===d?this.strict:d,l=r.pathDelimiter,f=void 0===l?this.pathDelimiter:l,v=n(r,["subMap","shared","strict","pathDelimiter"]),g=t({},s,Object.keys(c).reduce((function(e,t){return e[t]=a.getDependency(c[t]),e}),{})),p=t({},v,{name:this.getPathString(e,this.name),targetPath:e,hashMatrix:this,subMap:g,strict:u,pathDelimiter:f});for(var y in s)if(!0===s[y]&&!c.hasOwnProperty(y))throw{message:i.ERRORS.UNSATISFIED_SHARED_DEPENDENCY,data:y,subject:r,context:this};return new i(p)},o.convertDeclaration=function(e,t){return void 0===t&&(t={}),t instanceof s?t:t.subMap instanceof Object?this.createIncarnate(e,t):this.createLifePod(e,t)},o.getDependenciesFromMap=function(e){var t=this;return void 0===e&&(e={}),Object.keys(e).reduce((function(r,n){return r[n]=t.getDependency(e[n]),r}),{})},o.createFromMap=function(e,t){return void 0===e&&(e={}),Object.keys(e).reduce((function(r,n){var a=e[n];return r[n]=a instanceof Function?a:t(a),r}),{})},o.getResolvedPath=function(e){var t=this.getDependency(e);return t instanceof c?t.getValue():this.getPath(e)},o.getResolvedPathAsync=function(e,t){try{var r=this.getDependency(e);return Promise.resolve(r instanceof c?r.getValueAsync(t):this.getPath(e))}catch(e){return Promise.reject(e)}},i}(s);l.DEFAULT_NAME="Incarnate",l.STANDARD_DEPENDENCY_NAMES=d,l.ERRORS={UNSATISFIED_SHARED_DEPENDENCY:"UNSATISFIED_SHARED_DEPENDENCY"},exports.ConfigurableInstance=e,exports.HashMatrix=s,exports.Incarnate=l,exports.LifePod=c,exports.default=l;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(e){void 0===e&&(e={}),Object.assign(this,e)};function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function n(e,t){if(null==e)return{};var r,n,a={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(a[r]=e[r]);return a}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var o={},s=function(e){function n(t){var r;return void 0===t&&(t={}),(r=e.call(this,t)||this)._changeHandlerMap={},r._errorHandlerMap={},"string"!=typeof r.pathDelimiter&&(r.pathDelimiter=n.DEFAULT_PATH_DELIMITER),r._setDefaultName(),r}r(n,e),n.keyIsNumeric=function(e){var t=!1;try{t=Number.isInteger(parseInt(""+e,10))}catch(e){}return t};var a=n.prototype;return a._setDefaultName=function(){this.hasOwnProperty("name")||(this.name="string"==typeof this.constructor.DEFAULT_NAME?this.constructor.DEFAULT_NAME:n.DEFAULT_NAME)},a.getChangeHandlerList=function(e){var t=this.getPathString(e);return this._changeHandlerMap[t]||[]},a.setChangeHandlerList=function(e,t){void 0===t&&(t=[]);var r=this.getPathString(e);this._changeHandlerMap[r]=t},a.addChangeHandler=function(e,t){var r=this;if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.addChangeHandler(this.getPathArray(e,this.targetPath),t);if(t){var a=this.getChangeHandlerList(e);if(-1===a.indexOf(t))return a.push(t),this.setChangeHandlerList(e,a),function(){return r.removeChangeHandler(e,t)}}},a.removeChangeHandler=function(e,t){if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.removeChangeHandler(this.getPathArray(e,this.targetPath),t);var r=this.getChangeHandlerList(e);if(-1!==r.indexOf(t)){var a=[];r.forEach((function(e){e!==t&&a.push(e)})),this.setChangeHandlerList(e,a)}},a.onChange=function(e,t){var r=this;this.getChangeHandlerList(e).forEach((function(n){return n(e,t,r)}))},a.getErrorHandlerList=function(e){var t=this.getPathString(e);return this._errorHandlerMap[t]||[]},a.setErrorHandlerList=function(e,t){void 0===t&&(t=[]);var r=this.getPathString(e);this._errorHandlerMap[r]=t},a.addErrorHandler=function(e,t){var r=this;if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.addErrorHandler(this.getPathArray(e,this.targetPath),t);if(t){var a=this.getErrorHandlerList(e);if(-1===a.indexOf(t))return a.push(t),this.setErrorHandlerList(e,a),function(){return r.removeErrorHandler(e,t)}}},a.removeErrorHandler=function(e,t){if(void 0===e&&(e=""),this.hashMatrix instanceof n)return this.hashMatrix.removeErrorHandler(this.getPathArray(e,this.targetPath),t);var r=this.getErrorHandlerList(e);if(-1!==r.indexOf(t)){var a=[];r.forEach((function(e){e!==t&&a.push(e)})),this.setErrorHandlerList(e,a)}},a.onError=function(e,t,r){var n=this;this.getErrorHandlerList(t).forEach((function(a){return a(e,t,r,n)}))},a.getBasePathArray=function(e){return void 0===e&&(e=""),e instanceof Array?[].concat(e):""===e?[]:(""+e).split(this.pathDelimiter)},a.getPathArray=function(e,t){void 0===e&&(e=""),void 0===t&&(t="");var r=this.getBasePathArray(t),n=this.getBasePathArray(e);return[].concat(r,n)},a.getPathString=function(e,t){return this.getPathArray(e,t).join(this.pathDelimiter)},a.dispatchChanges=function(e){var t=this.getPathArray(e),r=this.getPathString(t);if(t.length)for(var n=[].concat(t);n.length;)this.onChange(this.getPathString(n),r),n.pop();this.onChange("",r)},a.dispatchErrors=function(e,t){var r=this.getPathArray(t),n=this.getPathString(r);if(r.length)for(var a=[].concat(r);a.length;)this.onError(e,this.getPathString(a),n),a.pop();this.onError(e,"",n)},a._setErrorInternal=function(e,t){if(this.hashMatrix instanceof n)return this.hashMatrix.setError(this.getPathArray(e,this.targetPath),t);this.dispatchErrors(t,e)},a.setError=function(e,t){return this._setErrorInternal(e,t)},a._getPathInternal=function(e){if(this.hashMatrix instanceof n)return this.hashMatrix.getPath(this.getPathArray(e,this.targetPath));var t=this.getPathArray(e);if(t.length){for(var r,a,o=this.hashMatrix,s=!0,h=function(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return i(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,void 0):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}(t);!(a=h()).done;){var c=a.value;try{var d;o=null===(d=o)||void 0===d?void 0:d[c]}catch(e){s=!1;break}}return s&&(r=o),r}return this.hashMatrix},a.getPath=function(e){return this._getPathInternal(e)},a._setPathInternal=function(e,r){if(this.hashMatrix instanceof n)return this.hashMatrix.setPath(this.getPathArray(e,this.targetPath),r);var a=r===o?void 0:r,i=this.getPathArray(e);if(a!==this._getPathInternal(e)){var s=t({},this.hashMatrix);if(i.length){for(var h=i.length-1,c=i[h],d=s,u=0;u<h;u++){var l=i[u];void 0===d[l]?d[l]=n.keyIsNumeric(i[u+1])?[]:{}:d[l]instanceof Array?d[l]=[].concat(d[l]):d[l]instanceof Object&&(d[l]=t({},d[l])),d=d[l]}d[c]=a,this.hashMatrix=s}else this.hashMatrix=a;this.dispatchChanges(i)}else r===o&&this.dispatchChanges(i)},a.setPath=function(e,t){return this._setPathInternal(e,t)},a.invalidatePath=function(e){this.setPath(e,o)},a.getValue=function(){return this.getPath([])},a.setValue=function(e){return this.setPath([],e)},a.invalidate=function(){var e=this;this.preventInvalidation||("number"==typeof this.debounceInvalidationMS?(clearTimeout(this._invalidationDebounceTimeout),this._invalidationDebounceTimeout=setTimeout((function(){return e.setValue(o)}),this.debounceInvalidationMS)):this.setValue(o))},n}(e);s.DEFAULT_NAME="HashMatrix",s.DEFAULT_PATH_DELIMITER=".",s.ERRORS={INVALID_PATH_DELIMITER:"INVALID_PATH_DELIMITER"},"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var h,c=function(e){function a(t){var r,a=void 0===t?{}:t,i=a.dependencies,o=void 0===i?[]:i,h=n(a,["dependencies"]);return(r=e.call(this,h)||this).handleDependencyChange=function(){r.invalidate()},r.addDependencyChangeHandler=function(e){e instanceof s&&e.addChangeHandler("",r.handleDependencyChange)},r.removeDependencyChangeHandler=function(e){e instanceof s&&e.removeChangeHandler("",r.handleDependencyChange)},r.addDependencyMapChangeHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.addDependencyChangeHandler(e[t])}))},r.removeDependencyMapChangeHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.removeDependencyChangeHandler(e[t])}))},r.handleDependencyError=function(e,t,n,a){var i=new Error("A dependency failed to resolve.");"object"==typeof e&&(i.source={error:e,path:t,causePath:n,target:a}),r.setError([],i)},r.addDependencyErrorHandler=function(e){e instanceof s&&e.addErrorHandler("",r.handleDependencyError)},r.removeDependencyErrorHandler=function(e){e instanceof s&&e.removeErrorHandler("",r.handleDependencyError)},r.addDependencyMapErrorHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.addDependencyErrorHandler(e[t])}))},r.removeDependencyMapErrorHandlers=function(e){void 0===e&&(e={}),Object.keys(e).forEach((function(t){return r.removeDependencyErrorHandler(e[t])}))},r.resolving=!1,r.dependencies=o,r}r(a,e);var i,o=a.prototype;return o.resolveDependency=function(e){if(e instanceof s)return e.getValue()},o.resolveDependencyMap=function(e){void 0===e&&(e={});var t={},r={dependencies:t,getters:this.getters,setters:this.setters,invalidators:this.invalidators,listeners:this.listeners};for(var n in e){var a=this.resolveDependency(e[n]);if(this.strict&&void 0===a)return;t[n]=a}return r},o.handleFactoryPromise=function(t){try{var r=this,n=function(){if(t){var n=function(){r.resolving=!1,e.prototype.setPath.call(r,[],a)},a=void 0,i=function(e,r){try{var n=Promise.resolve(t).then((function(e){a=e}))}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,(function(e){r.setError([],e)}));return i&&i.then?i.then(n):n()}}();return Promise.resolve(n&&n.then?n.then((function(){})):void 0)}catch(e){return Promise.reject(e)}},o.resolve=function(){var r,n;if(!this.resolving)if(this.resolving=!0,this.factory instanceof Function){var a=this.resolveDependencyMap(this.dependencies);if(void 0!==a){try{r=this.factory((void 0===(n=a)&&(n={}),!1===this.mergeDeps?n:t({},n.dependencies,n.getters,n.setters,n.invalidators,n.listeners)))}catch(e){this.setError([],e)}r instanceof Promise?this.handleFactoryPromise(r):this.resolving=!1}else r=void 0,this.resolving=!1}else r=e.prototype.getPath.call(this,[]),this.resolving=!1;return r},o.getPath=function(t){var r;if(void 0===e.prototype.getPath.call(this,[])||this.noCache){var n=this.resolve();this.resolving?r=void 0:(e.prototype.setPath.call(this,[],n),r=e.prototype.getPath.call(this,t))}else r=e.prototype.getPath.call(this,t);return r},o.getPathAsync=function(e,t){try{var r=this,n=r.getPathString(e);return Promise.resolve(new Promise((function(i,o){var s=void 0,h={remove:function(){clearTimeout(s),r.removeChangeHandler(n,h.onChange),r.removeErrorHandler(n,h.onError)},onChange:function(){try{var t=r.getPath(e);void 0!==t&&(h.remove(),i(t))}catch(t){var n=(t||{}).message;h.onError({message:void 0===n?"":n,subject:r,data:e,error:t})}},onError:function(e){h.remove(),o(e)}};r.addChangeHandler(n,h.onChange),r.addErrorHandler(n,h.onError),"number"==typeof t&&(s=setTimeout((function(){return h.onError(new Error(a.ERROR_MESSAGES.RESOLUTION_TIMEOUT))}),t)),h.onChange()})))}catch(e){return Promise.reject(e)}},o.getValueAsync=function(e){try{return Promise.resolve(this.getPathAsync([],e))}catch(e){return Promise.reject(e)}},(i=[{key:"dependencies",get:function(){return this._dependencies},set:function(e){this._dependencies&&(this.removeDependencyMapChangeHandlers(this._dependencies),this.removeDependencyMapErrorHandlers(this._dependencies)),this._dependencies=e,this._dependencies&&(this.addDependencyMapChangeHandlers(this._dependencies),this.addDependencyMapErrorHandlers(this._dependencies))}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(a.prototype,i),a}(s);c.DEFAULT_NAME="LifePod",c.ERROR_MESSAGES={RESOLUTION_TIMEOUT:"RESOLUTION_TIMEOUT"};var d={GLOBAL:"GLOBAL"},u=((h={})[d.GLOBAL]={factory:function(){return window||global}},h),l=function(e){function i(r){var n;return void 0===r&&(r={}),(n=e.call(this,r)||this)._parsedSubMap={},n.getDependency=function(e){var t;void 0===e&&(e="");var r=n.getPathArray(e),o=n.getPathString(r);if(!r.length)return a(n);var h=r.shift()||"",d=""+h,u=[].concat(r);!n._parsedSubMap.hasOwnProperty(d)&&(null===(t=n.subMap)||void 0===t?void 0:t.hasOwnProperty(d))&&(n._parsedSubMap[d]=n.convertDeclaration(h,n.subMap[d]));var l=n._parsedSubMap[d];return l instanceof i?l.getDependency(u):l?u.length?l instanceof c?new c({name:o,targetPath:u,hashMatrix:l,strict:n.strict}):new s({name:o,targetPath:u,hashMatrix:l}):l:new s({name:o,targetPath:[h].concat(u),hashMatrix:a(n)})},n.createGetter=function(e){return function(t){return void 0===t&&(t=[]),n.getDependency(e).getPath(t)}},n.createSetter=function(e){return function(t,r){return void 0===r&&(r=[]),n.getDependency(e).setPath(r,t)}},n.createInvalidator=function(e){return function(t){return void 0===t&&(t=[]),n.getDependency(e).invalidatePath(t)}},n.createListener=function(e){return function(t,r){return void 0===r&&(r=[]),n.getDependency(e).addChangeHandler(r,t)}},n.hashMatrix instanceof Object||(n.hashMatrix={}),n.subMap=t({},u,n.subMap),n}r(i,e);var o=i.prototype;return o.createLifePod=function(e,r){void 0===r&&(r={});var a=r.dependencies,i=void 0===a?{}:a,o=r.getters,s=void 0===o?{}:o,h=r.setters,d=void 0===h?{}:h,u=r.invalidators,l=void 0===u?{}:u,f=r.listeners,v=void 0===f?{}:f,g=r.strict,p=void 0===g?this.strict:g,y=r.pathDelimiter,E=void 0===y?this.pathDelimiter:y,P=t({},n(r,["dependencies","getters","setters","invalidators","listeners","strict","pathDelimiter"]),{name:this.getPathString(e,this.name),targetPath:e,hashMatrix:this,dependencies:this.getDependenciesFromMap(i),getters:this.createFromMap(s,this.createGetter),setters:this.createFromMap(d,this.createSetter),invalidators:this.createFromMap(l,this.createInvalidator),listeners:this.createFromMap(v,this.createListener),strict:p,pathDelimiter:E});return new c(P)},o.createIncarnate=function(e,r){var a=this;void 0===r&&(r={});var o=r.subMap,s=void 0===o?{}:o,h=r.shared,c=void 0===h?{}:h,d=r.strict,u=void 0===d?this.strict:d,l=r.pathDelimiter,f=void 0===l?this.pathDelimiter:l,v=n(r,["subMap","shared","strict","pathDelimiter"]),g=t({},s,Object.keys(c).reduce((function(e,t){return e[t]=a.getDependency(c[t]),e}),{})),p=t({},v,{name:this.getPathString(e,this.name),targetPath:e,hashMatrix:this,subMap:g,strict:u,pathDelimiter:f});for(var y in s)if(!0===s[y]&&!c.hasOwnProperty(y))throw{message:i.ERRORS.UNSATISFIED_SHARED_DEPENDENCY,data:y,subject:r,context:this};return new i(p)},o.convertDeclaration=function(e,t){return void 0===t&&(t={}),t instanceof s?t:t.subMap instanceof Object?this.createIncarnate(e,t):this.createLifePod(e,t)},o.getDependenciesFromMap=function(e){var t=this;return void 0===e&&(e={}),Object.keys(e).reduce((function(r,n){return r[n]=t.getDependency(e[n]),r}),{})},o.createFromMap=function(e,t){return void 0===e&&(e={}),Object.keys(e).reduce((function(r,n){var a=e[n];return r[n]=a instanceof Function?a:t(a),r}),{})},o.getResolvedPath=function(e){var t=this.getDependency(e);return t instanceof c?t.getValue():this.getPath(e)},o.getResolvedPathAsync=function(e,t){try{var r=this.getDependency(e);return Promise.resolve(r instanceof c?r.getValueAsync(t):this.getPath(e))}catch(e){return Promise.reject(e)}},i}(s);l.DEFAULT_NAME="Incarnate",l.STANDARD_DEPENDENCY_NAMES=d,l.ERRORS={UNSATISFIED_SHARED_DEPENDENCY:"UNSATISFIED_SHARED_DEPENDENCY"},exports.ConfigurableInstance=e,exports.HashMatrix=s,exports.Incarnate=l,exports.LifePod=c,exports.default=l;
//# sourceMappingURL=core.cjs.production.min.js.map

@@ -485,3 +485,14 @@ var ConfigurableInstance = function ConfigurableInstance(config) {

_proto.invalidate = function invalidate() {
this.setValue(INVALID);
var _this6 = this;
if (!this.preventInvalidation) {
if (typeof this.debounceInvalidationMS === 'number') {
clearTimeout(this._invalidationDebounceTimeout);
this._invalidationDebounceTimeout = setTimeout(function () {
return _this6.setValue(INVALID);
}, this.debounceInvalidationMS);
} else {
this.setValue(INVALID);
}
}
};

@@ -934,3 +945,3 @@

var name = pathArray.shift();
var name = pathArray.shift() || '';
var stringName = "" + name;

@@ -937,0 +948,0 @@ var subPath = [].concat(pathArray);

@@ -0,7 +1,7 @@

import { ObjectOf } from './ConfigurableInstance';
import { HashMatrixPathPartType, IHashMatrix } from './HashMatrix';
/**
* Declare an available dependency with various types of requirements.
* */
import { IConfigurableInstance, ObjectOf } from './ConfigurableInstance';
import { HashMatrixPathPartType } from './HashMatrix';
export interface DependencyDeclaration extends IConfigurableInstance {
export interface DependencyDeclaration extends IHashMatrix {
/**

@@ -8,0 +8,0 @@ * A map of named dependencies.

@@ -1,3 +0,36 @@

import ConfigurableInstance, { ObjectOf } from './ConfigurableInstance';
import ConfigurableInstance, { IConfigurableInstance, ObjectOf } from './ConfigurableInstance';
export declare type HashMatrixPathPartType = string | string[];
export interface IHashMatrix extends IConfigurableInstance {
/**
* The name of this `HashMatrix`.
* @type {string}
* */
name?: string;
/**
* The target path for a proxied `HashMatrix`.
* @type {Array|string}
* */
targetPath?: string | string[];
/**
* An automatically maintained structure that acts as the source of all values.
* If set a to a `HashMatrix`, it will be proxied.
* @type {Object.<*>|HashMatrix}
* */
hashMatrix?: any | ObjectOf<any> | HashMatrix;
/**
* The `string` used to delimit all paths.
* @type {string}
* */
pathDelimiter?: string;
/**
* An optional number of milliseconds to wait before invalidating the value of the `HashMatrix`.
* @type {number}
* */
debounceInvalidationMS?: number;
/**
* An optional flag used to prevent invalidation and keep the current value of the `HashMatrix`.
* @type {boolean}
* */
preventInvalidation?: boolean;
}
/**

@@ -36,3 +69,13 @@ * Easily manage a data structure that can be dynamically built

pathDelimiter?: string;
constructor(config?: ObjectOf<any>);
/**
* An optional number of milliseconds to wait before invalidating the value of the `HashMatrix`.
* @type {number}
* */
debounceInvalidationMS?: number;
/**
* An optional flag used to prevent invalidation and keep the current value of the `HashMatrix`.
* @type {boolean}
* */
preventInvalidation?: boolean;
constructor(config?: IHashMatrix);
_setDefaultName(): void;

@@ -63,3 +106,4 @@ getChangeHandlerList(path: HashMatrixPathPartType): Function[];

setValue(value: any): void;
_invalidationDebounceTimeout?: any;
invalidate(): void;
}

@@ -1,8 +0,8 @@

import { IConfigurableInstance, ObjectOf } from './ConfigurableInstance';
import { ObjectOf } from './ConfigurableInstance';
import { DependencyDeclaration } from './DependencyDeclaration';
import { HashMatrixPathPartType } from './HashMatrix';
import { HashMatrixPathPartType, IHashMatrix } from './HashMatrix';
/**
* Declare an available map of dependencies.
* */
export interface SubMapDeclaration extends IConfigurableInstance {
export interface SubMapDeclaration extends IHashMatrix {
/**

@@ -9,0 +9,0 @@ * The map of dependencies.

@@ -5,3 +5,3 @@ {

"private": false,
"version": "7.0.0",
"version": "7.1.0",
"license": "MIT",

@@ -20,3 +20,3 @@ "main": "dist/index.js",

"build": "tsdx build",
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' mocha --inline-diffs --require ./mocha-ts-node-compat.js --ui exports './src/**/*.spec.ts'",
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' mocha --inline-diffs --require ./mocha-ts-node-compat.js --timeout=30000 --ui exports './src/**/*.spec.ts'",
"lint": "tsdx lint",

@@ -23,0 +23,0 @@ "prepare": "tsdx build"

@@ -5,18 +5,18 @@ import expect from 'expect.js';

export default {
ConfigurableInstance: {
'should be a class': () => {
expect(ConfigurableInstance).to.be.a(Function);
},
'should assign values to itself from the config parameter': () => {
const configurableInstance: IConfigurableInstance = new ConfigurableInstance(
{
testProperty: 'Heirloom',
}
);
const { testProperty } = configurableInstance;
const suite = {
'should be a class': () => {
expect(ConfigurableInstance).to.be.a(Function);
},
'should assign values to itself from the config parameter': () => {
const configurableInstance: IConfigurableInstance = new ConfigurableInstance(
{
testProperty: 'Heirloom',
}
);
const { testProperty } = configurableInstance;
expect(testProperty).to.equal('Heirloom');
},
expect(testProperty).to.equal('Heirloom');
},
};
export { suite as ConfigurableInstance };

@@ -0,8 +1,8 @@

import { ObjectOf } from './ConfigurableInstance';
import { HashMatrixPathPartType, IHashMatrix } from './HashMatrix';
/**
* Declare an available dependency with various types of requirements.
* */
import { IConfigurableInstance, ObjectOf } from './ConfigurableInstance';
import { HashMatrixPathPartType } from './HashMatrix';
export interface DependencyDeclaration extends IConfigurableInstance {
export interface DependencyDeclaration extends IHashMatrix {
/**

@@ -9,0 +9,0 @@ * A map of named dependencies.

@@ -1,5 +0,47 @@

import ConfigurableInstance, { ObjectOf } from './ConfigurableInstance';
import ConfigurableInstance, {
IConfigurableInstance,
ObjectOf,
} from './ConfigurableInstance';
export type HashMatrixPathPartType = string | string[];
export interface IHashMatrix extends IConfigurableInstance {
/**
* The name of this `HashMatrix`.
* @type {string}
* */
name?: string;
/**
* The target path for a proxied `HashMatrix`.
* @type {Array|string}
* */
targetPath?: string | string[];
/**
* An automatically maintained structure that acts as the source of all values.
* If set a to a `HashMatrix`, it will be proxied.
* @type {Object.<*>|HashMatrix}
* */
hashMatrix?: any | ObjectOf<any> | HashMatrix;
/**
* The `string` used to delimit all paths.
* @type {string}
* */
pathDelimiter?: string;
/**
* An optional number of milliseconds to wait before invalidating the value of the `HashMatrix`.
* @type {number}
* */
debounceInvalidationMS?: number;
/**
* An optional flag used to prevent invalidation and keep the current value of the `HashMatrix`.
* @type {boolean}
* */
preventInvalidation?: boolean;
}
/**

@@ -63,3 +105,15 @@ * An object used to invalidate a path.

constructor(config: ObjectOf<any> = {}) {
/**
* An optional number of milliseconds to wait before invalidating the value of the `HashMatrix`.
* @type {number}
* */
debounceInvalidationMS?: number;
/**
* An optional flag used to prevent invalidation and keep the current value of the `HashMatrix`.
* @type {boolean}
* */
preventInvalidation?: boolean;
constructor(config: IHashMatrix = {}) {
super(config);

@@ -425,5 +479,17 @@

_invalidationDebounceTimeout?: any;
invalidate() {
this.setValue(INVALID);
if (!this.preventInvalidation) {
if (typeof this.debounceInvalidationMS === 'number') {
clearTimeout(this._invalidationDebounceTimeout);
this._invalidationDebounceTimeout = setTimeout(
() => this.setValue(INVALID),
this.debounceInvalidationMS
);
} else {
this.setValue(INVALID);
}
}
}
}

@@ -6,32 +6,71 @@ import expect from 'expect.js';

export default {
Incarnate: {
'should be a class': () => {
expect(Incarnate).to.be.a(Function);
},
'should automatically update dependants when their dependencies change': async () => {
let ok = false;
const suite = {
'should be a class': () => {
expect(Incarnate).to.be.a(Function);
},
'should automatically update dependants when their dependencies change': async () => {
let ok = false;
try {
await DemoApp();
try {
await DemoApp();
ok = true;
} catch (error) {
console.log(error);
}
ok = true;
} catch (error) {
console.log(error);
}
expect(ok).to.equal(true);
expect(ok).to.equal(true);
},
'should allow custom path delimiters': async () => {
const mockDepValue = 'MOCK_DEP_VALUE';
// IMPORTANT: Should not be '.', which is just the default.
const customPathDelimiter = '/';
const inc = new Incarnate({
pathDelimiter: customPathDelimiter,
subMap: {
level2: {
subMap: {
testDep: {
factory: () => mockDepValue,
},
},
},
},
});
const depValue = await inc.getResolvedPathAsync(
['level2', 'testDep'].join(customPathDelimiter),
500
);
expect(depValue).to.equal(mockDepValue);
},
getDependency: {
'should get a declared dependency': () => {
const inc = new Incarnate({
subMap: {
testDep: {
factory: () => 'Tomato',
},
},
});
const dep = inc.getDependency('testDep');
expect(dep).to.be.a(LifePod);
},
'should allow custom path delimiters': async () => {
const mockDepValue = 'MOCK_DEP_VALUE';
// IMPORTANT: Should not be '.', which is just the default.
const customPathDelimiter = '/';
'should get an undeclared dependency': () => {
const inc = new Incarnate({
pathDelimiter: customPathDelimiter,
subMap: {},
});
const dep = inc.getDependency('testDep');
expect(dep).to.be.a(HashMatrix);
},
},
getResolvedPath: {
'should resolve a synchronous dependency': () => {
const inc = new Incarnate({
subMap: {
level2: {
subMap: {
testDep: {
factory: () => mockDepValue,
},
testDep: {
factory: () => {
return 'Tomato';
},

@@ -41,225 +80,265 @@ },

});
const depValue = await inc.getResolvedPathAsync(
['level2', 'testDep'].join(customPathDelimiter),
500
);
const testDep = inc.getResolvedPath('testDep');
expect(depValue).to.equal(mockDepValue);
expect(testDep).to.equal('Tomato');
},
getDependency: {
'should get a declared dependency': () => {
const inc = new Incarnate({
subMap: {
testDep: {
factory: () => 'Tomato',
},
getResolvedPathAsync: {
'should resolve an asynchronous dependency': async () => {
const inc = new Incarnate({
subMap: {
testDep: {
factory: async () => {
return 'Tomato';
},
},
});
const dep = inc.getDependency('testDep');
},
});
const testDep = await inc.getResolvedPathAsync('testDep');
expect(dep).to.be.a(LifePod);
},
'should get an undeclared dependency': () => {
const inc = new Incarnate({
subMap: {},
});
const dep = inc.getDependency('testDep');
expect(dep).to.be.a(HashMatrix);
},
expect(testDep).to.equal('Tomato');
},
getResolvedPath: {
'should resolve a synchronous dependency': () => {
const inc = new Incarnate({
subMap: {
testDep: {
factory: () => {
return 'Tomato';
},
'should not hang the process when timing out': async () => {
const inc = new Incarnate({
subMap: {
dep1: {
factory: () => undefined,
},
testDep: {
dependencies: {
dep1: 'dep1',
},
strict: true,
factory: async () => {
return 'Tomato';
},
},
});
const testDep = inc.getResolvedPath('testDep');
},
});
const testDepPod = inc.getDependency('testDep');
expect(testDep).to.equal('Tomato');
},
let resError = undefined;
try {
await inc.getResolvedPathAsync('testDep', 1000);
} catch (error) {
resError = error;
}
expect(resError).to.be.an(Object);
expect(testDepPod).to.be.a(LifePod);
expect((testDepPod as LifePod).resolving).to.equal(false);
},
getResolvedPathAsync: {
'should resolve an asynchronous dependency': async () => {
const inc = new Incarnate({
subMap: {
testDep: {
factory: async () => {
return 'Tomato';
'should supply dependencies from a shared subMap': async () => {
const sharedSubMapDepValue = 'SHARED_SUBMAP_DEP_VALUE';
const inc = new Incarnate({
subMap: {
other: {
subMap: {
dep1: {
factory: () => sharedSubMapDepValue,
},
},
},
});
const testDep = await inc.getResolvedPathAsync('testDep');
expect(testDep).to.equal('Tomato');
},
'should not hang the process when timing out': async () => {
const inc = new Incarnate({
subMap: {
dep1: {
factory: () => undefined,
main: {
shared: {
other: 'other',
},
testDep: {
dependencies: {
dep1: 'dep1',
subMap: {
testDep: {
dependencies: {
dep1: 'other.dep1',
},
strict: true,
factory: async ({ dep1 }: { dep1: string }) => dep1,
},
strict: true,
factory: async () => {
return 'Tomato';
},
},
},
});
const testDepPod = inc.getDependency('testDep');
},
});
const resolvedValue = await inc.getResolvedPathAsync('main.testDep');
let resError = undefined;
try {
await inc.getResolvedPathAsync('testDep', 1000);
} catch (error) {
resError = error;
}
expect(resError).to.be.an(Object);
expect(testDepPod).to.be.a(LifePod);
expect((testDepPod as LifePod).resolving).to.equal(false);
},
'should supply dependencies from a shared subMap': async () => {
const sharedSubMapDepValue = 'SHARED_SUBMAP_DEP_VALUE';
const inc = new Incarnate({
subMap: {
other: {
subMap: {
dep1: {
factory: () => sharedSubMapDepValue,
},
expect(resolvedValue).to.equal(sharedSubMapDepValue);
},
'should supply asynchronous dependencies from a shared subMap': async () => {
const sharedSubMapDepValue = 'SHARED_SUBMAP_DEP_VALUE';
const inc = new Incarnate({
subMap: {
other: {
subMap: {
dep1: {
// IMPORTANT: Must be async.
factory: async () => sharedSubMapDepValue,
},
},
main: {
shared: {
other: 'other',
},
subMap: {
testDep: {
dependencies: {
dep1: 'other.dep1',
},
strict: true,
factory: async ({ dep1 }: { dep1: string }) => dep1,
},
main: {
shared: {
other: 'other',
},
subMap: {
testDep: {
dependencies: {
dep1: 'other.dep1',
},
strict: true,
factory: async ({ dep1 }: { dep1: string }) => dep1,
},
},
},
});
const resolvedValue = await inc.getResolvedPathAsync('main.testDep');
},
});
const resolvedValue = await inc.getResolvedPathAsync(
'main.testDep',
1000
);
expect(resolvedValue).to.equal(sharedSubMapDepValue);
},
'should supply asynchronous dependencies from a shared subMap': async () => {
const sharedSubMapDepValue = 'SHARED_SUBMAP_DEP_VALUE';
expect(resolvedValue).to.equal(sharedSubMapDepValue);
},
},
createIncarnate: {
'should throw when a required, shared dependency is not satisfied': () => {
let missingSharedDependencyError;
try {
const inc = new Incarnate({
subMap: {
other: {
needsShared: {
subMap: {
dep1: {
// IMPORTANT: Must be async.
factory: async () => sharedSubMapDepValue,
},
missing: true,
},
},
main: {
shared: {
other: 'other',
},
subMap: {
testDep: {
dependencies: {
dep1: 'other.dep1',
},
strict: true,
factory: async ({ dep1 }: { dep1: string }) => dep1,
},
},
},
},
});
const resolvedValue = await inc.getResolvedPathAsync(
'main.testDep',
1000
);
expect(resolvedValue).to.equal(sharedSubMapDepValue);
},
inc.getDependency('needsShared');
} catch (error) {
missingSharedDependencyError = error;
}
expect(missingSharedDependencyError).to.be.an(Object);
expect(missingSharedDependencyError.message).to.equal(
Incarnate.ERRORS.UNSATISFIED_SHARED_DEPENDENCY
);
expect(missingSharedDependencyError.data).to.equal('missing');
},
createIncarnate: {
'should throw when a required, shared dependency is not satisfied': () => {
let missingSharedDependencyError;
try {
const inc = new Incarnate({
},
addErrorHandler: {
'should call the handler when an asynchronous error occurs at the given path': async () => {
const asyncNestedDepError = new Error('Error from `a.b`.');
const inc = new Incarnate({
subMap: {
a: {
subMap: {
needsShared: {
subMap: {
missing: true,
b: {
factory: async () => {
throw asyncNestedDepError;
},
},
},
});
},
c: {
dependencies: {
dep: 'a.b',
},
strict: true,
factory: () => true,
},
},
});
inc.getDependency('needsShared');
} catch (error) {
missingSharedDependencyError = error;
}
try {
await inc.getResolvedPathAsync('c');
expect(missingSharedDependencyError).to.be.an(Object);
expect(missingSharedDependencyError.message).to.equal(
Incarnate.ERRORS.UNSATISFIED_SHARED_DEPENDENCY
);
expect(missingSharedDependencyError.data).to.equal('missing');
},
expect(true).to.equal(false);
} catch (error) {
const {
source: { error: sourceError },
} = error;
expect(sourceError).to.equal(asyncNestedDepError);
}
},
addErrorHandler: {
'should call the handler when an asynchronous error occurs at the given path': async () => {
const asyncNestedDepError = new Error('Error from `a.b`.');
const inc = new Incarnate({
subMap: {
a: {
subMap: {
b: {
factory: async () => {
throw asyncNestedDepError;
},
},
},
},
createSetter: {
'should create a getter function that updates the underlying hashMatrix': () => {
const depOneValue = 'DEP_ONE_VALUE';
const inc = new Incarnate({
subMap: {
depOne: {
factory: () => '',
},
depTwo: {
setters: {
setDepOne: 'depOne',
},
c: {
dependencies: {
dep: 'a.b',
},
strict: true,
factory: () => true,
factory: ({ setDepOne }) => {
setDepOne(depOneValue);
return true;
},
},
});
},
});
const d2 = inc.getDependency('depTwo');
const d2Value = d2.getValue();
const d1 = inc.getDependency('depOne');
const d1Value = d1.getValue();
try {
await inc.getResolvedPathAsync('c');
expect(d2Value).to.equal(true);
expect(d1Value).to.equal(depOneValue);
},
'should create a getter function that continues to update the underlying hashMatrix': () => {
const trackedValues: any[] = [];
const inc = new Incarnate({
subMap: {
depOne: {
factory: () => ({}),
},
depTwo: {
setters: {
setDepOne: 'depOne',
},
factory: ({ setDepOne }) => {
[...new Array(8)].forEach((_x, i) =>
setDepOne(`VALUE_${i}`, `KEY_${i}`)
);
expect(true).to.equal(false);
} catch (error) {
const {
source: { error: sourceError },
} = error;
return true;
},
},
depOneWatcher: {
dependencies: {
depOne: 'depOne',
},
factory: ({ depOne }) => {
trackedValues.push(depOne);
expect(sourceError).to.equal(asyncNestedDepError);
}
},
return true;
},
},
},
});
const d2 = inc.getDependency('depTwo');
const d1W = inc.getDependency('depOneWatcher');
const d1WChangeHandler = () => d1W.getValue();
d1W.addChangeHandler('', d1WChangeHandler);
d2.getValue();
d1W.removeChangeHandler('', d1WChangeHandler);
const [latestDepOneMap] = [...trackedValues].reverse();
const latestDepOneMapKeys = Object.keys(latestDepOneMap);
const { KEY_0: k0, KEY_7: k7 } = latestDepOneMap;
expect(trackedValues).to.have.length(8);
expect(latestDepOneMapKeys).to.have.length(8);
expect(k0).to.equal('VALUE_0');
expect(k7).to.equal('VALUE_7');
},
},
};
export { suite as Incarnate };

@@ -174,3 +174,3 @@ import HashMatrix, { HashMatrixPathPartType } from './HashMatrix';

const name = pathArray.shift();
const name = pathArray.shift() || '';
const stringName = `${name}`;

@@ -177,0 +177,0 @@ const subPath = [...pathArray];

import expect from 'expect.js';
import LifePod from './LifePod';
export default {
LifePod: {
'should be a class': () => {
expect(LifePod).to.be.a(Function);
},
getValue: {
'should resolve a synchronous value': () => {
const lifePod = new LifePod({
factory: () => {
return 'Tomato';
},
});
const testDep = lifePod.getValue();
const suite = {
'should be a class': () => {
expect(LifePod).to.be.a(Function);
},
getValue: {
'should resolve a synchronous value': () => {
const lifePod = new LifePod({
factory: () => {
return 'Tomato';
},
});
const testDep = lifePod.getValue();
expect(testDep).to.equal('Tomato');
},
expect(testDep).to.equal('Tomato');
},
getValueAsync: {
'should resolve an asynchronous value': async () => {
const lifePod = new LifePod({
factory: async () => {
return 'Tomato';
},
});
const testDep = await lifePod.getValueAsync();
},
getValueAsync: {
'should resolve an asynchronous value': async () => {
const lifePod = new LifePod({
factory: async () => {
return 'Tomato';
},
});
const testDep = await lifePod.getValueAsync();
expect(testDep).to.equal('Tomato');
},
expect(testDep).to.equal('Tomato');
},
},
};
export { suite as LifePod };

@@ -1,4 +0,4 @@

import { IConfigurableInstance, ObjectOf } from './ConfigurableInstance';
import { ObjectOf } from './ConfigurableInstance';
import { DependencyDeclaration } from './DependencyDeclaration';
import { HashMatrixPathPartType } from './HashMatrix';
import { HashMatrixPathPartType, IHashMatrix } from './HashMatrix';

@@ -8,3 +8,3 @@ /**

* */
export interface SubMapDeclaration extends IConfigurableInstance {
export interface SubMapDeclaration extends IHashMatrix {
/**

@@ -11,0 +11,0 @@ * The map of dependencies.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc