fable 3.0.125 → 3.0.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/debug/Harness.js +40 -54
- package/dist/fable.compatible.js +307 -46
- package/dist/fable.compatible.min.js +2 -2
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +276 -15
- package/dist/fable.min.js +2 -2
- package/dist/fable.min.js.map +1 -1
- package/package.json +1 -1
- package/source/Fable.js +18 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Base.js +55 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-ExpressionTokenizer.js +158 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json +22 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Linter.js +180 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Postfix.js +631 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-SolvePostfixedExpression.js +125 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-TokenMap.json +75 -0
- package/source/services/Fable-Service-ExpressionParser.js +208 -0
- package/source/services/Fable-Service-Math.js +30 -1
- package/test/ExpressionParser_tests.js +187 -0
package/dist/fable.compatible.js
CHANGED
|
@@ -3017,15 +3017,15 @@ _this17.connectFable(_assertThisInitialized(_this17));// --> Bootstrapping of fa
|
|
|
3017
3017
|
// Initialization Phase 2: Map in the default services.
|
|
3018
3018
|
// They will then be available in the Default service provider set as well.
|
|
3019
3019
|
_this17.connectPreinitServiceProviderInstance(_this17.UUID);_this17.connectPreinitServiceProviderInstance(_this17.Logging);_this17.connectPreinitServiceProviderInstance(_this17.SettingsManager);// Initialize and instantiate the default baked-in Data Arithmatic service
|
|
3020
|
-
_this17.addAndInstantiateServiceType('EnvironmentData',require('./services/Fable-Service-EnvironmentData.js'));_this17.addServiceType('Template',require('./services/Fable-Service-Template.js'));_this17.addServiceType('MetaTemplate',require('./services/Fable-Service-MetaTemplate.js'));_this17.addServiceType('Anticipate',require('./services/Fable-Service-Anticipate.js'));_this17.addAndInstantiateServiceType('Dates',require('./services/Fable-Service-DateManipulation.js'));_this17.addAndInstantiateServiceType('DataFormat',require('./services/Fable-Service-DataFormat.js'));_this17.addAndInstantiateServiceType('DataGeneration',require('./services/Fable-Service-DataGeneration.js'));_this17.addAndInstantiateServiceType('Utility',require('./services/Fable-Service-Utility.js'));_this17.addAndInstantiateServiceType('Math',require('./services/Fable-Service-Math.js'));_this17.addServiceType('RestClient',require('./services/Fable-Service-RestClient.js'));_this17.addServiceType('Manifest',require('manyfest'));_this17.addServiceType('ObjectCache',require('cachetrax'));_this17.addAndInstantiateServiceType('ProgressTime',require('./services/Fable-Service-ProgressTime.js'));_this17.addServiceType('ProgressTrackerSet',require('./services/Fable-Service-ProgressTrackerSet.js'));_this17.addServiceType('Operation',require('./services/Fable-Service-Operation.js'));_this17.addServiceType('CSVParser',require('./services/Fable-Service-CSVParser.js'));_this17.addServiceType('FilePersistence',require('./services/Fable-Service-FilePersistence.js'));return _this17;}/* State Accessors */_createClass2(Fable,[{key:"isFable",get:function get(){return true;}},{key:"settings",get:function get(){return this.SettingsManager.settings;}},{key:"settingsManager",get:function get(){return this.SettingsManager;}// For backwards compatibility
|
|
3021
|
-
},{key:"getUUID",value:function getUUID(){return this.UUID.getUUID();}},{key:"newAnticipate",value:function newAnticipate(){return this.instantiateServiceProviderWithoutRegistration('Anticipate');}/* Service Manager Methods */},{key:"addServiceType",value:function addServiceType(pServiceType,pServiceClass){if(this.servicesMap.hasOwnProperty(pServiceType)){// TODO: Check if any services are running?
|
|
3020
|
+
_this17.addAndInstantiateServiceType('EnvironmentData',require('./services/Fable-Service-EnvironmentData.js'));_this17.addServiceType('Template',require('./services/Fable-Service-Template.js'));_this17.addServiceType('MetaTemplate',require('./services/Fable-Service-MetaTemplate.js'));_this17.addServiceType('Anticipate',require('./services/Fable-Service-Anticipate.js'));_this17.addAndInstantiateServiceType('Dates',require('./services/Fable-Service-DateManipulation.js'));_this17.addAndInstantiateServiceType('DataFormat',require('./services/Fable-Service-DataFormat.js'));_this17.addAndInstantiateServiceType('DataGeneration',require('./services/Fable-Service-DataGeneration.js'));_this17.addAndInstantiateServiceType('Utility',require('./services/Fable-Service-Utility.js'));_this17.addAndInstantiateServiceType('Math',require('./services/Fable-Service-Math.js'));_this17.addServiceType('ExpressionParser',require('./services/Fable-Service-ExpressionParser.js'));_this17.addServiceType('RestClient',require('./services/Fable-Service-RestClient.js'));_this17.addServiceType('Manifest',require('manyfest'));_this17.addServiceType('ObjectCache',require('cachetrax'));_this17.addAndInstantiateServiceType('ProgressTime',require('./services/Fable-Service-ProgressTime.js'));_this17.addServiceType('ProgressTrackerSet',require('./services/Fable-Service-ProgressTrackerSet.js'));_this17.addServiceType('Operation',require('./services/Fable-Service-Operation.js'));_this17.addServiceType('CSVParser',require('./services/Fable-Service-CSVParser.js'));_this17.addServiceType('FilePersistence',require('./services/Fable-Service-FilePersistence.js'));return _this17;}/* State Accessors */_createClass2(Fable,[{key:"isFable",get:function get(){return true;}},{key:"settings",get:function get(){return this.SettingsManager.settings;}},{key:"settingsManager",get:function get(){return this.SettingsManager;}// For backwards compatibility
|
|
3021
|
+
},{key:"getUUID",value:function getUUID(){return this.UUID.getUUID();}},{key:"newAnticipate",value:function newAnticipate(){return this.instantiateServiceProviderWithoutRegistration('Anticipate');}},{key:"newManyfest",value:function newManyfest(pManifestDefinition){return this.instantiateServiceProviderWithoutRegistration('Manifest',pManifestDefinition);}/* Service Manager Methods */},{key:"addServiceType",value:function addServiceType(pServiceType,pServiceClass){if(this.servicesMap.hasOwnProperty(pServiceType)){// TODO: Check if any services are running?
|
|
3022
3022
|
this.log.warn("Adding a service type [".concat(pServiceType,"] that already exists. This will change the default class prototype for this service."));}else{// Add the container for instantiated services to go in
|
|
3023
3023
|
this.servicesMap[pServiceType]={};// Add the type to the list of types
|
|
3024
3024
|
this.serviceTypes.push(pServiceType);}// Using the static member of the class is a much more reliable way to check if it is a service class than instanceof
|
|
3025
3025
|
if(typeof pServiceClass=='function'&&pServiceClass.isFableService){// Add the class to the list of classes
|
|
3026
3026
|
this.serviceClasses[pServiceType]=pServiceClass;}else{// Add the base class to the list of classes
|
|
3027
3027
|
this.log.error("Attempted to add service type [".concat(pServiceType,"] with an invalid class. Using base service class, which will not crash but won't provide meaningful services."));this.serviceClasses[pServiceType]=libFableServiceBase;}return this.serviceClasses[pServiceType];}},{key:"addServiceTypeIfNotExists",value:function addServiceTypeIfNotExists(pServiceType,pServiceClass){if(!this.servicesMap.hasOwnProperty(pServiceType)){return this.addServiceType(pServiceType,pServiceClass);}else{return this.serviceClasses[pServiceType];}}// This is for the services that are meant to run mostly single-instance so need a default at initialization
|
|
3028
|
-
},{key:"addAndInstantiateServiceType",value:function addAndInstantiateServiceType(pServiceType,pServiceClass){this.addServiceType(pServiceType,pServiceClass);return this.instantiateServiceProvider(pServiceType,{},"".concat(pServiceType,"-Default"));}// Some services expect to be overloaded / customized class.
|
|
3028
|
+
},{key:"addAndInstantiateServiceType",value:function addAndInstantiateServiceType(pServiceType,pServiceClass){this.addServiceType(pServiceType,pServiceClass);return this.instantiateServiceProvider(pServiceType,{},"".concat(pServiceType,"-Default"));}},{key:"addAndInstantiateServiceTypeIfNotExists",value:function addAndInstantiateServiceTypeIfNotExists(pServiceType,pServiceClass){if(!this.servicesMap.hasOwnProperty(pServiceType)){return this.instantiateServiceProvider(pServiceType,{},"".concat(pServiceType,"-Default"));}else{return this.serviceClasses[pServiceType];}}// Some services expect to be overloaded / customized class.
|
|
3029
3029
|
},{key:"instantiateServiceProviderFromPrototype",value:function instantiateServiceProviderFromPrototype(pServiceType,pOptions,pCustomServiceHash,pServicePrototype){// Instantiate the service
|
|
3030
3030
|
var tmpService=new pServicePrototype(this,pOptions,pCustomServiceHash);if(this.extraServiceInitialization){tmpService=this.extraServiceInitialization(tmpService);}// Add the service to the service map
|
|
3031
3031
|
this.servicesMap[pServiceType][tmpService.Hash]=tmpService;// If this is the first service of this type, make it the default
|
|
@@ -3044,7 +3044,7 @@ this.servicesMap[tmpServiceType][tmpServiceHash]=pServiceInstance;// If this is
|
|
|
3044
3044
|
if(!this.services.hasOwnProperty(tmpServiceType)){this.setDefaultServiceInstantiation(tmpServiceType,tmpServiceHash,false);}return pServiceInstance;}},{key:"setDefaultServiceInstantiation",value:function setDefaultServiceInstantiation(pServiceType,pServiceHash,pOverwriteService){// Overwrite services by default, unless told not to
|
|
3045
3045
|
var tmpOverwriteService=typeof pOverwriteService==='undefined'?true:pOverwriteService;// Make sure the service exists
|
|
3046
3046
|
if(this.servicesMap[pServiceType].hasOwnProperty(pServiceHash)){if(!this.hasOwnProperty(pServiceType)||tmpOverwriteService){this[pServiceType]=this.servicesMap[pServiceType][pServiceHash];}if(!this.services.hasOwnProperty(pServiceType)||tmpOverwriteService){this.services[pServiceType]=this.servicesMap[pServiceType][pServiceHash];}return true;}return false;}}]);return Fable;}(libFableServiceBase.CoreServiceProviderBase);// This is for backwards compatibility
|
|
3047
|
-
function autoConstruct(pSettings){return new Fable(pSettings);}module.exports=Fable;module.exports["new"]=autoConstruct;module.exports.LogProviderBase=libFableLog.LogProviderBase;module.exports.ServiceProviderBase=libFableServiceBase;module.exports.CoreServiceProviderBase=libFableServiceBase.CoreServiceProviderBase;module.exports.precedent=libFableSettings.precedent;},{"./services/Fable-Service-Anticipate.js":128,"./services/Fable-Service-CSVParser.js":129,"./services/Fable-Service-DataFormat.js":130,"./services/Fable-Service-DataGeneration.js":132,"./services/Fable-Service-DateManipulation.js":133,"./services/Fable-Service-EnvironmentData.js":134,"./services/Fable-Service-
|
|
3047
|
+
function autoConstruct(pSettings){return new Fable(pSettings);}module.exports=Fable;module.exports["new"]=autoConstruct;module.exports.LogProviderBase=libFableLog.LogProviderBase;module.exports.ServiceProviderBase=libFableServiceBase;module.exports.CoreServiceProviderBase=libFableServiceBase.CoreServiceProviderBase;module.exports.precedent=libFableSettings.precedent;},{"./services/Fable-Service-Anticipate.js":128,"./services/Fable-Service-CSVParser.js":129,"./services/Fable-Service-DataFormat.js":130,"./services/Fable-Service-DataGeneration.js":132,"./services/Fable-Service-DateManipulation.js":133,"./services/Fable-Service-EnvironmentData.js":134,"./services/Fable-Service-ExpressionParser.js":135,"./services/Fable-Service-FilePersistence.js":143,"./services/Fable-Service-Math.js":144,"./services/Fable-Service-MetaTemplate.js":145,"./services/Fable-Service-Operation.js":149,"./services/Fable-Service-ProgressTime.js":150,"./services/Fable-Service-ProgressTrackerSet.js":152,"./services/Fable-Service-RestClient.js":153,"./services/Fable-Service-Template.js":154,"./services/Fable-Service-Utility.js":155,"cachetrax":22,"fable-log":50,"fable-serviceproviderbase":51,"fable-settings":54,"fable-uuid":56,"manyfest":80}],128:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');var FableServiceAnticipate=/*#__PURE__*/function(_libFableServiceBase){_inherits(FableServiceAnticipate,_libFableServiceBase);function FableServiceAnticipate(pFable,pOptions,pServiceHash){var _this18;_classCallCheck2(this,FableServiceAnticipate);_this18=_callSuper(this,FableServiceAnticipate,[pFable,pOptions,pServiceHash]);_this18.serviceType='AsyncAnticipate';// The queue of operations waiting to run.
|
|
3048
3048
|
_this18.operationQueue=[];_this18.erroredOperations=[];_this18.executingOperationCount=0;_this18.completedOperationCount=0;_this18.callDepth=0;_this18.maxOperations=1;_this18.lastError=undefined;_this18.waitingFunctions=[];return _this18;}_createClass2(FableServiceAnticipate,[{key:"checkQueue",value:function checkQueue(){// This could be combined with the last else if stanza but the logic for errors and non-errors would be blended and more complex to follow so keeping it unrolled.
|
|
3049
3049
|
if(this.lastError){// If there are no operations left, and we have waiting functions, call them.
|
|
3050
3050
|
for(var i=0;i<this.waitingFunctions.length;i++){//this.log.trace('Calling waiting function.')
|
|
@@ -3340,8 +3340,267 @@ _this22.plugin_advancedFormat=require('dayjs/plugin/advancedFormat');_this22.day
|
|
|
3340
3340
|
// You would do the following:
|
|
3341
3341
|
// const localeDE = require('dayjs/locale/de');
|
|
3342
3342
|
// _Fable.Dates.dayJS.locale('de');
|
|
3343
|
-
return _this22;}return _createClass2(DateManipulation);}(libFableServiceProviderBase);module.exports=DateManipulation;},{"dayjs":28,"dayjs/plugin/advancedFormat":29,"dayjs/plugin/isoWeek":30,"dayjs/plugin/relativeTime":31,"dayjs/plugin/timezone":32,"dayjs/plugin/utc":33,"dayjs/plugin/weekOfYear":34,"dayjs/plugin/weekday":35,"fable-serviceproviderbase":51}],134:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');var FableServiceEnvironmentData=/*#__PURE__*/function(_libFableServiceBase3){_inherits(FableServiceEnvironmentData,_libFableServiceBase3);function FableServiceEnvironmentData(pFable,pOptions,pServiceHash){var _this23;_classCallCheck2(this,FableServiceEnvironmentData);_this23=_callSuper(this,FableServiceEnvironmentData,[pFable,pOptions,pServiceHash]);_this23.serviceType='EnvironmentData';_this23.Environment="node.js";return _this23;}return _createClass2(FableServiceEnvironmentData);}(libFableServiceBase);module.exports=FableServiceEnvironmentData;},{"fable-serviceproviderbase":51}],135:[function(require,module,exports){
|
|
3344
|
-
|
|
3343
|
+
return _this22;}return _createClass2(DateManipulation);}(libFableServiceProviderBase);module.exports=DateManipulation;},{"dayjs":28,"dayjs/plugin/advancedFormat":29,"dayjs/plugin/isoWeek":30,"dayjs/plugin/relativeTime":31,"dayjs/plugin/timezone":32,"dayjs/plugin/utc":33,"dayjs/plugin/weekOfYear":34,"dayjs/plugin/weekday":35,"fable-serviceproviderbase":51}],134:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');var FableServiceEnvironmentData=/*#__PURE__*/function(_libFableServiceBase3){_inherits(FableServiceEnvironmentData,_libFableServiceBase3);function FableServiceEnvironmentData(pFable,pOptions,pServiceHash){var _this23;_classCallCheck2(this,FableServiceEnvironmentData);_this23=_callSuper(this,FableServiceEnvironmentData,[pFable,pOptions,pServiceHash]);_this23.serviceType='EnvironmentData';_this23.Environment="node.js";return _this23;}return _createClass2(FableServiceEnvironmentData);}(libFableServiceBase);module.exports=FableServiceEnvironmentData;},{"fable-serviceproviderbase":51}],135:[function(require,module,exports){var _require3=require('big.js'),PE=_require3.PE;var libFableServiceBase=require('fable-serviceproviderbase');/* Trying a different pattern for this service ...
|
|
3344
|
+
*
|
|
3345
|
+
* This service is a simple expression parser that can handle math expressions, with magic(tm) lookup of addresses with a manifest.
|
|
3346
|
+
*
|
|
3347
|
+
* Each method works multiple ways.
|
|
3348
|
+
*
|
|
3349
|
+
* 1. You can pass in a results object, and, it will put the state for that step outcome into the results object.
|
|
3350
|
+
* 2. It always returns the state, and works without the results object.
|
|
3351
|
+
*
|
|
3352
|
+
*
|
|
3353
|
+
* Learned a lot from this npm package: https://www.npmjs.com/package/math-expression-evaluator
|
|
3354
|
+
* And its related code at github: https://github.com/bugwheels94/math-expression-evaluator
|
|
3355
|
+
*
|
|
3356
|
+
* There were two problems with the codebase...
|
|
3357
|
+
*
|
|
3358
|
+
* First, the code was very unreadable and determining it was correct or extending it
|
|
3359
|
+
* was out of the question.
|
|
3360
|
+
*
|
|
3361
|
+
* Second, and this is a larger issue, is that we need the expressions to be parsed as
|
|
3362
|
+
* arbitrary precision. When I determined that extending the library to use string-based
|
|
3363
|
+
* numbers and an arbitrary precision library as the back-end would have taken a significantly
|
|
3364
|
+
* longer amount of time than just writing the parser from scratch, et voila.
|
|
3365
|
+
*/var FableServiceExpressionParser=/*#__PURE__*/function(_libFableServiceBase4){_inherits(FableServiceExpressionParser,_libFableServiceBase4);function FableServiceExpressionParser(pFable,pOptions,pServiceHash){var _this24;_classCallCheck2(this,FableServiceExpressionParser);_this24=_callSuper(this,FableServiceExpressionParser,[pFable,pOptions,pServiceHash]);_this24.tokenMap=require('./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-TokenMap.json');// This precedence is higher than defined in our token map
|
|
3366
|
+
_this24.tokenMaxPrecedence=5;_this24.functionMap=require('./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json');_this24.serviceType='ExpressionParser';_this24.fable.addServiceTypeIfNotExists('ExpressionParser-Tokenizer',require('./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-ExpressionTokenizer.js'));_this24.fable.addServiceTypeIfNotExists('ExpressionParser-Linter',require('./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Linter.js'));_this24.fable.addServiceTypeIfNotExists('ExpressionParser-Postfix',require('./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Postfix.js'));_this24.fable.addServiceTypeIfNotExists('ExpressionParser-Solver',require('./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-SolvePostfixedExpression.js'));_this24.Tokenizer=_this24.fable.instantiateServiceProviderWithoutRegistration('ExpressionParser-Tokenizer');_this24.Linter=_this24.fable.instantiateServiceProviderWithoutRegistration('ExpressionParser-Linter');_this24.Postfix=_this24.fable.instantiateServiceProviderWithoutRegistration('ExpressionParser-Postfix');_this24.Solver=_this24.fable.instantiateServiceProviderWithoutRegistration('ExpressionParser-Solver');// Now wire each of these up. Not in love with this pattern but better than a giant file here.
|
|
3367
|
+
_this24.Tokenizer.connectExpressionParser(_assertThisInitialized(_this24));_this24.Linter.connectExpressionParser(_assertThisInitialized(_this24));_this24.Postfix.connectExpressionParser(_assertThisInitialized(_this24));_this24.Solver.connectExpressionParser(_assertThisInitialized(_this24));return _this24;}_createClass2(FableServiceExpressionParser,[{key:"substituteValuesInTokenizedObjects",value:function substituteValuesInTokenizedObjects(pTokenizedObjects,pDataSource,pResultObject,pManifest){var tmpResults=_typeof(pResultObject)==='object'?pResultObject:{ExpressionParserLog:[]};if(!Array.isArray(pTokenizedObjects)){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.substituteValuesInTokenizedObjects was passed a non-array tokenized object list.");this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return pTokenizedObjects;}if(_typeof(pDataSource)!=='object'){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.substituteValuesInTokenizedObjects either was passed no data source, or was passed a non-object data source.");this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return pTokenizedObjects;}var tmpDataSource=pDataSource;var tmpManifest=_typeof(pManifest)=='object'?pManifest:this.fable.newManyfest(pManifest);for(var i=0;i<pTokenizedObjects.length;i++){if(_typeof(pTokenizedObjects[i])!=='object'){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.substituteValuesInTokenizedObjects found a non-object tokenized object at index ".concat(i));this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);continue;}var tmpToken=pTokenizedObjects[i];if(pTokenizedObjects[i].Type==='Token.Symbol'&&!tmpToken.Resolved){// Symbols always look up values by hash first
|
|
3368
|
+
var tmpValue=tmpManifest.getValueByHash(tmpDataSource,tmpToken.Token);// if (!tmpValue)
|
|
3369
|
+
// {
|
|
3370
|
+
// // If no hash resolves, try by address.
|
|
3371
|
+
// tmpValue = tmpManifest.getValueAtAddress(tmpToken.Token, tmpDataSource);
|
|
3372
|
+
// }
|
|
3373
|
+
if(!tmpValue){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.substituteValuesInTokenizedObjects found no value for the symbol hash or address ".concat(tmpToken.Token," at index ").concat(i));this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);continue;}else{tmpResults.ExpressionParserLog.push("INFO: ExpressionParser.substituteValuesInTokenizedObjects found a value [".concat(tmpValue,"] for the state address ").concat(tmpToken.Token," at index ").concat(i));this.log.info(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);try{var tmpValueParsed=new this.fable.Utility.bigNumber(tmpValue);tmpToken.Resolved=true;tmpToken.Value=tmpValueParsed.toString();}catch(pError){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.substituteValuesInTokenizedObjects found a non-numeric value for the state address ".concat(tmpToken.Token," at index ").concat(i));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);tmpToken.Resolved=false;}}}if(pTokenizedObjects[i].Type==='Token.StateAddress'&&!tmpToken.Resolved){// Symbols are always hashes. This gracefully works for simple shallow objects because hashes default to the address in Manyfest.
|
|
3374
|
+
var _tmpValue3=tmpManifest.getValueAtAddress(tmpDataSource,tmpToken.Token);if(!_tmpValue3){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.substituteValuesInTokenizedObjects found no value for the state address ".concat(tmpToken.Token," at index ").concat(i));this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);continue;}else{tmpResults.ExpressionParserLog.push("INFO: ExpressionParser.substituteValuesInTokenizedObjects found a value [".concat(_tmpValue3,"] for the state address ").concat(tmpToken.Token," at index ").concat(i));this.log.info(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);try{var _tmpValueParsed=new this.fable.Utility.bigNumber(_tmpValue3);tmpToken.Resolved=true;tmpToken.Value=_tmpValueParsed.toString();}catch(pError){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.substituteValuesInTokenizedObjects found a non-numeric value for the state address ".concat(tmpToken.Token," at index ").concat(i));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);tmpToken.Resolved=false;}}}if(pTokenizedObjects[i].Type==='Token.Constant'&&!tmpToken.Resolved){tmpResults.ExpressionParserLog.push("INFO: ExpressionParser.substituteValuesInTokenizedObjects found a value [".concat(tmpToken.Token,"] for the constant ").concat(tmpToken.Token," at index ").concat(i));this.log.info(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);try{var _tmpValueParsed2=new this.fable.Utility.bigNumber(tmpToken.Token);tmpToken.Resolved=true;tmpToken.Value=_tmpValueParsed2.toString();}catch(pError){// This constant has the right symbols but apparently isn't a parsable number.
|
|
3375
|
+
tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.substituteValuesInTokenizedObjects found a non-numeric value for the state address ".concat(tmpToken.Token," at index ").concat(i));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);tmpToken.Resolved=false;}}}return pTokenizedObjects;}},{key:"tokenize",value:function tokenize(pExpression,pResultObject){return this.Tokenizer.tokenize(pExpression,pResultObject);}},{key:"lintTokenizedExpression",value:function lintTokenizedExpression(pTokenizedExpression,pResultObject){return this.Linter.lintTokenizedExpression(pTokenizedExpression,pResultObject);}},{key:"buildPostfixedSolveList",value:function buildPostfixedSolveList(pTokenizedExpression,pResultObject){return this.Postfix.buildPostfixedSolveList(pTokenizedExpression,pResultObject);}},{key:"solvePostfixedExpression",value:function solvePostfixedExpression(pPostfixedExpression,pDataDestinationObject,pResultObject,pManifest){return this.Solver.solvePostfixedExpression(pPostfixedExpression,pDataDestinationObject,pResultObject,pManifest);}},{key:"solve",value:function solve(pExpression,pDataSourceObject,pResultObject,pManifest,pDataDestinationObject){var tmpResultsObject=_typeof(pResultObject)==='object'?pResultObject:{};var tmpDataSourceObject=_typeof(pDataSourceObject)==='object'?pDataSourceObject:{};var tmpDataDestinationObject=_typeof(pDataDestinationObject)==='object'?pDataDestinationObject:{};this.tokenize(pExpression,tmpResultsObject);this.lintTokenizedExpression(tmpResultsObject.RawTokens,tmpResultsObject);this.buildPostfixedSolveList(tmpResultsObject.RawTokens,tmpResultsObject);this.substituteValuesInTokenizedObjects(tmpResultsObject.PostfixTokenObjects,tmpDataSourceObject,tmpResultsObject,pManifest);return this.solvePostfixedExpression(tmpResultsObject.PostfixSolveList,tmpDataDestinationObject,tmpResultsObject,pManifest);}}]);return FableServiceExpressionParser;}(libFableServiceBase);module.exports=FableServiceExpressionParser;},{"./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-ExpressionTokenizer.js":137,"./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json":138,"./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Linter.js":139,"./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Postfix.js":140,"./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-SolvePostfixedExpression.js":141,"./Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-TokenMap.json":142,"big.js":17,"fable-serviceproviderbase":51}],136:[function(require,module,exports){var libFableServiceProviderBase=require('fable-serviceproviderbase');var ExpressionParserOperationBase=/*#__PURE__*/function(_libFableServiceProvi10){_inherits(ExpressionParserOperationBase,_libFableServiceProvi10);function ExpressionParserOperationBase(pFable,pOptions,pServiceHash){var _this25;_classCallCheck2(this,ExpressionParserOperationBase);_this25=_callSuper(this,ExpressionParserOperationBase,[pFable,pOptions,pServiceHash]);_this25.serviceType='ExpressionParserOperationBase';_this25.numberTest=/^-{0,1}\d*\.{0,1}\d+$/;_this25.ExpressionParser=false;return _this25;}_createClass2(ExpressionParserOperationBase,[{key:"connectExpressionParser",value:function connectExpressionParser(pExpressionParser){this.ExpressionParser=pExpressionParser;}},{key:"getTokenType",value:function getTokenType(pToken){if(this.ExpressionParser.tokenMap.hasOwnProperty(pToken)){return"Token.".concat(this.ExpressionParser.tokenMap[pToken].Type);}else if(pToken.length>2&&pToken[0]==='{'&&pToken[pToken.length-1]==='}'){return'Token.StateAddress';}else if(this.numberTest.test(pToken)){return'Token.Constant';}else{return'Token.Symbol';}// Just for documentation sake:
|
|
3376
|
+
// There is a fifth token type, VirtualSymbol
|
|
3377
|
+
// This is a value that's added during solve and looked up by address in the VirtualSymbol object.
|
|
3378
|
+
}},{key:"getTokenContainerObject",value:function getTokenContainerObject(pToken,pTokenType){return{Token:pToken,Type:typeof pTokenType==='undefined'?this.getTokenType(pToken):pTokenType,Descriptor:this.ExpressionParser.tokenMap.hasOwnProperty(pToken)?this.ExpressionParser.tokenMap[pToken]:false};}}]);return ExpressionParserOperationBase;}(libFableServiceProviderBase);module.exports=ExpressionParserOperationBase;},{"fable-serviceproviderbase":51}],137:[function(require,module,exports){var libExpressionParserOperationBase=require('./Fable-Service-ExpressionParser-Base.js');var ExpressionTokenizer=/*#__PURE__*/function(_libExpressionParserO){_inherits(ExpressionTokenizer,_libExpressionParserO);function ExpressionTokenizer(pFable,pOptions,pServiceHash){var _this26;_classCallCheck2(this,ExpressionTokenizer);_this26=_callSuper(this,ExpressionTokenizer,[pFable,pOptions,pServiceHash]);_this26.serviceType='ExpressionParser-Tokenizer';return _this26;}_createClass2(ExpressionTokenizer,[{key:"tokenize",value:function tokenize(pExpression,pResultObject){var tmpResults=_typeof(pResultObject)==='object'?pResultObject:{ExpressionParserLog:[]};tmpResults.RawExpression=pExpression;tmpResults.RawTokens=[];tmpResults.ExpressionParserLog=[];if(typeof pExpression!=='string'){this.log.warn('ExpressionParser.tokenize was passed a non-string expression.');return tmpResults.RawTokens;}/* Tokenize the expression
|
|
3379
|
+
*
|
|
3380
|
+
* Current token types:
|
|
3381
|
+
* - Value
|
|
3382
|
+
* : could be a symbol representation e.g. "x", "depth", "Cost", etc. --- symbol representations are looked up first as manifest hashes
|
|
3383
|
+
* : could be a number e.g. "5", "3.14159", etc.
|
|
3384
|
+
* : could be a function name e.g. sin(x), sqrt(3+5) where sin or sqrt are known function names
|
|
3385
|
+
* - StateAddress
|
|
3386
|
+
* : these are always wrapped in squiggly brackets
|
|
3387
|
+
* : e.g. {Moisture.Percentage}, {Ending.Temperature.Fahrenheit}, {AppData.Download.Size}, etc.
|
|
3388
|
+
* - Token
|
|
3389
|
+
* : could be an operator e.g. "+", "-", "*", "/"
|
|
3390
|
+
* : could be a parenthesis e.g. "(", ")"
|
|
3391
|
+
*/var tmpCurrentTokenType=false;var tmpCurrentToken='';for(var i=0;i<pExpression.length;i++){var tmpCharacter=pExpression[i];// [ WHITESPACE ]
|
|
3392
|
+
// 1. Space breaks tokens except when we're in an address that's been scoped by a {}
|
|
3393
|
+
if(tmpCharacter===' '&&tmpCurrentTokenType!=='StateAddress'){if(tmpCurrentToken.length>0){tmpResults.RawTokens.push(tmpCurrentToken);}tmpCurrentToken='';tmpCurrentTokenType=false;continue;}// [ STATE ADDRESS BLOCKS ]
|
|
3394
|
+
// 2. If we're in an address, we keep going until we hit the closing brace
|
|
3395
|
+
if(tmpCurrentTokenType==='StateAddress'&&tmpCharacter!=='}'){tmpCurrentToken+=tmpCharacter;continue;}// 3. If we're in an address and we hit the closing brace, we close the token, push it and reset
|
|
3396
|
+
if(tmpCurrentTokenType==='StateAddress'&&tmpCharacter==='}'){tmpCurrentToken+=tmpCharacter;tmpResults.RawTokens.push(tmpCurrentToken);tmpCurrentToken='';tmpCurrentTokenType=false;continue;}// 4. If we're not in an address and we hit a closing brace it's a problem
|
|
3397
|
+
// TODO: Should we just ignore it? We do at the moment.
|
|
3398
|
+
if(tmpCharacter=='}'){if(tmpCurrentToken.length>0){tmpResults.RawTokens.push(tmpCurrentToken);}tmpCurrentToken='';tmpCurrentTokenType=false;tmpResults.ExpressionParserLog.push("ExpressionParser.tokenize found a closing brace without an opening brace in the expression: ".concat(pExpression," at character index ").concat(i));this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);continue;}// 5. If we're not in an address and we hit an opening brace, we start an address
|
|
3399
|
+
if(tmpCharacter=='{'){if(tmpCurrentToken.length>0){tmpResults.RawTokens.push(tmpCurrentToken);}tmpCurrentToken='';tmpCurrentTokenType='StateAddress';tmpCurrentToken=tmpCharacter;continue;}// [ TOKENS ]
|
|
3400
|
+
if(this.ExpressionParser.tokenMap.hasOwnProperty(tmpCharacter)){if(tmpCurrentToken.length>0){tmpResults.RawTokens.push(tmpCurrentToken);}tmpCurrentToken='';tmpCurrentTokenType=false;tmpResults.RawTokens.push(tmpCharacter);continue;}// If it's not an operator, it's a number or address.
|
|
3401
|
+
// At the moment we aren't going to gate it on whether it's a valid address or not
|
|
3402
|
+
// Just treat anything not a known token on its own as a value identifier
|
|
3403
|
+
/* Per this stack overflow article: https://stackoverflow.com/questions/4434076/best-way-to-alphanumeric-check-in-javascript
|
|
3404
|
+
* We could use a regex but it is slower than the charCodeAt method.
|
|
3405
|
+
* This also doesn't solve the problem of unicode characters, but we won't support those for now.
|
|
3406
|
+
*/ // if (pExpression.charAt(i) == '.')
|
|
3407
|
+
// {
|
|
3408
|
+
// console.log('Found a period')
|
|
3409
|
+
// }
|
|
3410
|
+
// let tmpCharCode = pExpression.charCodeAt(i);
|
|
3411
|
+
// // Match that the character code is any of...
|
|
3412
|
+
// if (
|
|
3413
|
+
// // Number [0-9]
|
|
3414
|
+
// (tmpCharCode > 47 && tmpCharCode < 58)
|
|
3415
|
+
// // Upper Case
|
|
3416
|
+
// || (tmpCharCode > 64 && tmpCharCode < 91)
|
|
3417
|
+
// // LOWER CASE
|
|
3418
|
+
// || (tmpCharCode > 96 && tmpCharCode < 123)
|
|
3419
|
+
// )
|
|
3420
|
+
// {
|
|
3421
|
+
// NOTE: Not having this guard makes a lot of interesting things possible.
|
|
3422
|
+
tmpCurrentTokenType='Value';tmpCurrentToken+=tmpCharacter;// continue;
|
|
3423
|
+
// }
|
|
3424
|
+
// tmpResults.ExpressionParserLog.push(`ExpressionParser.tokenize found an unknown character code ${tmpCharCode} character ${tmpCharacter} in the expression: ${pExpression} at index ${i}`);
|
|
3425
|
+
// this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
|
|
3426
|
+
}if(tmpCurrentTokenType&&tmpCurrentToken.length>0){tmpResults.RawTokens.push(tmpCurrentToken);}return tmpResults.RawTokens;}}]);return ExpressionTokenizer;}(libExpressionParserOperationBase);module.exports=ExpressionTokenizer;},{"./Fable-Service-ExpressionParser-Base.js":136}],138:[function(require,module,exports){module.exports={"sqrt":{"Name":"Square Root","Address":"fable.Math.sqrtPrecise"},"abs":{"Name":"Absolute Value","Address":"fable.Math.absPrecise"},"rad":{"Name":"Degrees to Radians","Address":"fable.Math.radPrecise"},"sin":{"Name":"Sine","Address":"fable.Math.sin"}};},{}],139:[function(require,module,exports){var libExpressionParserOperationBase=require('./Fable-Service-ExpressionParser-Base.js');var ExpressionParserLinter=/*#__PURE__*/function(_libExpressionParserO2){_inherits(ExpressionParserLinter,_libExpressionParserO2);function ExpressionParserLinter(pFable,pOptions,pServiceHash){var _this27;_classCallCheck2(this,ExpressionParserLinter);_this27=_callSuper(this,ExpressionParserLinter,[pFable,pOptions,pServiceHash]);_this27.serviceType='ExpressionParser-Linter';return _this27;}_createClass2(ExpressionParserLinter,[{key:"lintTokenizedExpression",value:function lintTokenizedExpression(pTokenizedExpression,pResultObject){var tmpResults=_typeof(pResultObject)==='object'?pResultObject:{ExpressionParserLog:[]};tmpResults.LinterResults=[];// Guard against bad data being passed in
|
|
3427
|
+
if(!Array.isArray(pTokenizedExpression)){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.lintTokenizedExpression was passed a non-array tokenized expression.");tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return pTokenizedExpression;}if(pTokenizedExpression.length<1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.lintTokenizedExpression was passed an empty tokenized expression.");tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return pTokenizedExpression;}// 1. Check for balanced parenthesis
|
|
3428
|
+
var tmpParenthesisDepth=0;// If it is in a state address, we don't care about the parenthesis
|
|
3429
|
+
// State addresses are between squiggly brackets
|
|
3430
|
+
var tmpInStateAddress=false;for(var i=0;i<pTokenizedExpression.length;i++){if(pTokenizedExpression[i]==='('&&!tmpInStateAddress){tmpParenthesisDepth++;}if(pTokenizedExpression[i]===')'&&!tmpInStateAddress){tmpParenthesisDepth--;}if(pTokenizedExpression[i]==='{'){tmpInStateAddress=true;}if(pTokenizedExpression[i]==='}'){tmpInStateAddress=false;}if(tmpParenthesisDepth<0){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.lintTokenizedExpression found an unbalanced parenthesis in the tokenized expression at token index ".concat(i));tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}}if(tmpParenthesisDepth>0){// TODO: Should we add the closing parenthesis?
|
|
3431
|
+
tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.lintTokenizedExpression found an unbalanced parenthesis in the tokenized expression (ended without closing last set of parenthesis) -- appropriate closing parenthesis will be added.");tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}// 2. Check for balanced squiggly braces
|
|
3432
|
+
tmpInStateAddress=false;for(var _i15=0;_i15<pTokenizedExpression.length;_i15++){if(pTokenizedExpression[_i15]==='{'){tmpInStateAddress=true;}if(pTokenizedExpression[_i15]==='}'&&tmpInStateAddress){tmpInStateAddress=false;}if(pTokenizedExpression[_i15]==='}'&&!tmpInStateAddress){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.lintTokenizedExpression found an unbalanced closing squiggly brace \"}\" in the tokenized expression at token index ".concat(_i15));tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}if(tmpInStateAddress){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.lintTokenizedExpression found an open squiggly brace in the tokenized expression at index ".concat(_i15));tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}}// 3. Check for an equality assignment
|
|
3433
|
+
var tmpEqualityAssignmentCount=0;var tmpEqualityAssignmentIndex=false;for(var _i16=0;_i16<pTokenizedExpression.length;_i16++){if(pTokenizedExpression[_i16]==='='){tmpEqualityAssignmentCount++;tmpEqualityAssignmentIndex=_i16;if(tmpEqualityAssignmentCount>1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.lintTokenizedExpression found multiple equality assignments in the tokenized expression; equality assignment #".concat(tmpEqualityAssignmentCount," at token index ").concat(_i16,"."));tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}}}if(tmpEqualityAssignmentCount<1){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.lintTokenizedExpression found no equality assignment in the tokenized expression. One called Result will be added automatically.");tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}// 4. Make sure the equality assignment only has a single value on the other side of it
|
|
3434
|
+
// (no, this is not a magical algebraic solver, do your own simplification)
|
|
3435
|
+
// IF there is only one equality assignment (otherwise we don't even lint this because it's syntax errors all the way down)
|
|
3436
|
+
if(tmpEqualityAssignmentCount===1){// If there are exactly three tokens, make sure at least one is an assignable-ish address
|
|
3437
|
+
// This can still fail, but we aren't linting all the way into the manifest here; just the expression
|
|
3438
|
+
if(pTokenizedExpression.length===3){if(// The first token in our expression is a potentially assignable symbol
|
|
3439
|
+
this.getTokenType(pTokenizedExpression[0])==='Token.StateAddress'||this.getTokenType(pTokenizedExpression[2])==='Token.Symbol'// NOTE: For now we are only going to support assignment to the first symbol in the expression, which seems okay.
|
|
3440
|
+
// OR the last token in our expression is a potentially assignable symbol
|
|
3441
|
+
//|| (this.getTokenType(pTokenizedExpression[2]) === 'Token.StateAddress') || (this.getTokenType(pTokenizedExpression[0]) === 'Token.Symbol')
|
|
3442
|
+
){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.lintTokenizedExpression found a single equality assignment in the tokenized expression with no assignable address on the left side of the assignment.");tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}}}// 5. Check that there are no operators adjacent to each other
|
|
3443
|
+
// This is a simple lint check, not a full-blown syntax check
|
|
3444
|
+
var tmpTokenPrevious=false;for(var _i17=0;_i17<pTokenizedExpression.length-1;_i17++){if(this.ExpressionParser.tokenMap.hasOwnProperty(pTokenizedExpression[_i17])&&this.ExpressionParser.tokenMap[pTokenizedExpression[_i17]].Type!='Parenthesis'&&!tmpTokenPrevious){tmpTokenPrevious=true;}else if(this.ExpressionParser.tokenMap.hasOwnProperty(pTokenizedExpression[_i17])&&this.ExpressionParser.tokenMap[pTokenizedExpression[_i17]].Type!='Parenthesis'){// If this isn't a + or - positivity/negativity multiplier, it's an error.
|
|
3445
|
+
if(pTokenizedExpression[_i17]!=='+'&&pTokenizedExpression[_i17]!=='-'){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.lintTokenizedExpression found an ".concat(pTokenizedExpression[_i17]," operator adjacent to another operator in the tokenized expression at token index ").concat(_i17));tmpResults.LinterResults.push(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}}else{tmpTokenPrevious=false;}}return tmpResults.LinterResults;}}]);return ExpressionParserLinter;}(libExpressionParserOperationBase);module.exports=ExpressionParserLinter;},{"./Fable-Service-ExpressionParser-Base.js":136}],140:[function(require,module,exports){var libExpressionParserOperationBase=require('./Fable-Service-ExpressionParser-Base.js');var ExpressionParserPostfix=/*#__PURE__*/function(_libExpressionParserO3){_inherits(ExpressionParserPostfix,_libExpressionParserO3);function ExpressionParserPostfix(pFable,pOptions,pServiceHash){var _this28;_classCallCheck2(this,ExpressionParserPostfix);_this28=_callSuper(this,ExpressionParserPostfix,[pFable,pOptions,pServiceHash]);_this28.serviceType='ExpressionParser-Postfix';return _this28;}_createClass2(ExpressionParserPostfix,[{key:"getPosfixSolveListOperation",value:function getPosfixSolveListOperation(pOperation,pLeftValue,pRightValue,pDepthSolveList,pDepthSolveIndex){var tmpOperation={VirtualSymbolName:pOperation.VirtualSymbolName,Operation:pOperation,LeftValue:pLeftValue,RightValue:pRightValue};var tmpDepthSolveList=Array.isArray(pDepthSolveList)?pDepthSolveList:false;// // Although we have a `Token.Type == "Parenthesis"` option to check on, keeping these explicit means the solver won't
|
|
3446
|
+
// // allow users to pass in parenthesis in the wrong order.
|
|
3447
|
+
// // The linter does blow up as does the postfix, but, just in case we'll leave these explicit.
|
|
3448
|
+
// // It really doesn't hurt anything.
|
|
3449
|
+
// if (pLeftValue.Token === ')')
|
|
3450
|
+
// {
|
|
3451
|
+
// // We have found a close parenthesis which needs to pull the proper virtual symbol for the last operation on this stack.
|
|
3452
|
+
// // This ensures we are not expressing the parenthesis virtual symbols to the solver.
|
|
3453
|
+
// pLeftValue.VirtualSymbolName = pLayerStackMap[pLeftValue.SolveLayerStack];
|
|
3454
|
+
// this.log.error(`ERROR: ExpressionParser.getPosfixSolveListOperation found a close parenthesis in the left value of an operation.`);
|
|
3455
|
+
// }
|
|
3456
|
+
// else if (pRightValue.Token === '(')
|
|
3457
|
+
// {
|
|
3458
|
+
// // We have found a close parenthesis which needs to pull the proper virtual symbol for the last operation on this stack.
|
|
3459
|
+
// // This ensures we are not expressing the parenthesis virtual symbols to the solver.
|
|
3460
|
+
// pRightValue.VirtualSymbolName = pLayerStackMap[pRightValue.SolveLayerStack];
|
|
3461
|
+
// this.log.error(`ERROR: ExpressionParser.getPosfixSolveListOperation found a close parenthesis in the left value of an operation.`);
|
|
3462
|
+
// }
|
|
3463
|
+
// // Set the layer stack map virtual symbol name to the last operation performed on this stack.
|
|
3464
|
+
// pLayerStackMap[pOperation.SolveLayerStack] = pOperation.VirtualSymbolName;
|
|
3465
|
+
/* These two if blocks are very complex -- they basically provide a
|
|
3466
|
+
* way to deal with recursion that can be expressed to the user in
|
|
3467
|
+
* a meaningful way.
|
|
3468
|
+
*
|
|
3469
|
+
* The reason we are doing it as such is to show exactly how the
|
|
3470
|
+
* solver resolves the passed-in tokens into a solvable expression.
|
|
3471
|
+
*/if(!tmpOperation.LeftValue.VirtualSymbolName){tmpOperation.LeftValue.VirtualSymbolName=tmpOperation.VirtualSymbolName;}else{// We need to set the left value to a virtual symbol instead of the looked up value if it's already used in another operation
|
|
3472
|
+
tmpOperation.LeftValue=this.getTokenContainerObject(tmpOperation.LeftValue.VirtualSymbolName,'Token.VirtualSymbol');// Now walk backwards and see if we need to update a previous symbol for a previously unparsed operator
|
|
3473
|
+
if(tmpDepthSolveList){for(var i=pDepthSolveIndex-1;i>=0;i--){if(tmpDepthSolveList[i].Type==='Token.Operator'&&!tmpDepthSolveList[i].Parsed&&// When walking backward, we only want to mutate if the .
|
|
3474
|
+
tmpDepthSolveList[i].hasOwnProperty('Descriptor')&&tmpOperation.Operation.hasOwnProperty('Descriptor')&&// Anything >3 does not have commutative properties
|
|
3475
|
+
tmpDepthSolveList[i].Descriptor.Precedence>3){// If the symbol to its right is not the same as this operation
|
|
3476
|
+
if(tmpDepthSolveList[i+1].VirtualSymbolName!==tmpOperation.VirtualSymbolName){// This is the recursive "shunting" being simulated
|
|
3477
|
+
tmpDepthSolveList[i+1].VirtualSymbolName=tmpOperation.VirtualSymbolName;}break;}}}}if(!tmpOperation.RightValue.VirtualSymbolName){tmpOperation.RightValue.VirtualSymbolName=tmpOperation.VirtualSymbolName;}else{// We need to set the right value to a virtual symbol instead of the looked up value if it's already used in another operation
|
|
3478
|
+
tmpOperation.RightValue=this.getTokenContainerObject(tmpOperation.RightValue.VirtualSymbolName,'Token.VirtualSymbol');// Now walk forwards and see if we need to update an upcoming symbol for a previously unparsed operator
|
|
3479
|
+
if(tmpDepthSolveList){for(var _i18=pDepthSolveIndex+1;_i18<tmpDepthSolveList.length;_i18++){if(tmpDepthSolveList[_i18].Type==='Token.Operator'&&!tmpDepthSolveList[_i18].Parsed&&// When walking forward, we only want to mutate if the precedence hasn't been solved.
|
|
3480
|
+
tmpDepthSolveList[_i18].hasOwnProperty('Descriptor')&&tmpOperation.Operation.hasOwnProperty('Descriptor')&&// Anything >3 does not have commutative properties
|
|
3481
|
+
tmpDepthSolveList[_i18].Descriptor.Precedence>3){// If the symbol to its right is not the same as this operation
|
|
3482
|
+
if(tmpDepthSolveList[_i18-1].VirtualSymbolName!==tmpOperation.VirtualSymbolName){// This is the recursive "shunting" being simulated
|
|
3483
|
+
tmpDepthSolveList[_i18-1].VirtualSymbolName=tmpOperation.VirtualSymbolName;}break;}else if(tmpDepthSolveList[_i18].Type==='Token.Operator'&&!tmpDepthSolveList[_i18].Parsed){break;}}}}tmpOperation.Operation.Parsed=true;return tmpOperation;}},{key:"buildPostfixedSolveList",value:function buildPostfixedSolveList(pTokenizedExpression,pResultObject){var tmpResults=_typeof(pResultObject)==='object'?pResultObject:{ExpressionParserLog:[]};tmpResults.PostfixedAssignmentAddress='Result';tmpResults.PostfixTokenObjects=[];tmpResults.PostfixSolveList=[];if(pTokenizedExpression.length<3){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList was passed a tokenized expression with less than three tokens.");this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return tmpResults.PostfixTokenObjects;}// 1. Figure out the Equality Assignment
|
|
3484
|
+
var tmpEqualsIndex=-1;for(var i=0;i<pTokenizedExpression.length;i++){if(pTokenizedExpression[i]==='='&&tmpEqualsIndex<0){tmpEqualsIndex=i;}// If there are two equality assignments, error and bail out.
|
|
3485
|
+
else if(pTokenizedExpression[i]==='='){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found multiple equality assignments in the tokenized expression; equality assignment #".concat(tmpEqualsIndex," at token index ").concat(i,"."));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return tmpResults.PostfixTokenObjects;}}if(tmpEqualsIndex==-1){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.buildPostfixedSolveList found no equality assignment in the tokenized expression; defaulting to Result");this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}else if(tmpEqualsIndex>1){tmpResults.ExpressionParserLog.push("WARNING: ExpressionParser.buildPostfixedSolveList found an equality assignment in the tokenized expression at an unexpected location (token index ".concat(tmpEqualsIndex,"); the expression cannot be parsed."));this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}else if(tmpEqualsIndex===0){// This is an implicit function -- just go to result and return the value.
|
|
3486
|
+
// That is... the user entered something like "= 5 + 3" so we should just return 8, and use the default Result quietly.
|
|
3487
|
+
}else{tmpResults.PostfixedAssignmentAddress=pTokenizedExpression[0];}// 2. Categorize tokens in the expression, put them in the "expression list" as a token object
|
|
3488
|
+
for(var _i19=tmpEqualsIndex+1;_i19<pTokenizedExpression.length;_i19++){tmpResults.PostfixTokenObjects.push(this.getTokenContainerObject(pTokenizedExpression[_i19]));}// 3. Decorate mathematical parsing depth and detect functions at the same time
|
|
3489
|
+
// Having written this a few times now, it's easier to detect functions *while* parsing depth.
|
|
3490
|
+
// Especially if we want our system to be able to communicate with the user when there is an issue.
|
|
3491
|
+
var tmpDepth=0;// The virtual symbol index is used for the abstract interim values that are generated at each step of the solve
|
|
3492
|
+
var tmpVirtualParenthesisIndex=0;var tmpSolveLayerStack=[];// Kick off the solve layer stack with the first solve set identifier
|
|
3493
|
+
tmpSolveLayerStack.push("SolveSet_".concat(tmpVirtualParenthesisIndex,"_D_").concat(tmpDepth));for(var _i20=0;_i20<tmpResults.PostfixTokenObjects.length;_i20++){// 1. If it's an open parenthesis, set the parenthesis at the current depth and increment the depth
|
|
3494
|
+
if(tmpResults.PostfixTokenObjects[_i20].Token==='('){// Set the depth of the open parenthesis to the current solution depth
|
|
3495
|
+
tmpResults.PostfixTokenObjects[_i20].Depth=tmpDepth;// Generate the virtual symbol name for user output
|
|
3496
|
+
tmpResults.PostfixTokenObjects[_i20].VirtualSymbolName="Pr_".concat(tmpVirtualParenthesisIndex,"_D_").concat(tmpDepth);// 1a. Detect if this parenthesis is signaling a function
|
|
3497
|
+
// If the previous token is a Symbol (e.g. it say sin(x) or sqrt(3+5) or something) then the parser will interpret it as a function
|
|
3498
|
+
if(_i20>0){if(tmpResults.PostfixTokenObjects[_i20-1].Type==='Token.Symbol'){// Set the type of this to be a function
|
|
3499
|
+
tmpResults.PostfixTokenObjects[_i20-1].Type='Token.Function';// tmpResults.PostfixTokenObjects[i-1].Descriptor = this.ExpressionParser.tokenMap[pTokenizedExpression[i-1]];
|
|
3500
|
+
// Rename the virtual symbol n ame to include the function
|
|
3501
|
+
// tmpResults.PostfixTokenObjects[i].VirtualSymbolName = `Fn_${tmpVirtualParenthesisIndex}_D_${tmpDepth}_${this.fable.DataFormat.cleanNonAlphaCharacters(tmpResults.PostfixTokenObjects[i-1].Token)}`;
|
|
3502
|
+
// The function and the parenthesis are at the same depth and virtual symbol
|
|
3503
|
+
// tmpResults.PostfixTokenObjects[i-1].VirtualSymbolName = tmpResults.PostfixTokenObjects[i].VirtualSymbolName;
|
|
3504
|
+
}}// Parenthesis manage the solve layer stack
|
|
3505
|
+
// For adding a new parenthesis solve layer, we put the parenthesis in the stack we are in and then make all the contained tokens be within the stack of the parenthesis
|
|
3506
|
+
tmpResults.PostfixTokenObjects[_i20].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];tmpSolveLayerStack.push(tmpResults.PostfixTokenObjects[_i20].VirtualSymbolName);tmpVirtualParenthesisIndex++;tmpDepth++;}// 2. If it's a closed parenthesis, decrease the depth
|
|
3507
|
+
else if(tmpResults.PostfixTokenObjects[_i20].Token===')'){tmpDepth--;tmpResults.PostfixTokenObjects[_i20].Depth=tmpDepth;// Check to see that the depth of the closed parenthesis is greater than 0
|
|
3508
|
+
if(tmpDepth<0){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found a closing parenthesis at token index ".concat(_i20," with no corresponding opening parenthesis."));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}// Parenthesis manage the solve layer stack
|
|
3509
|
+
// For closing parenthesis solve layer with a close paren, we put it in the same stack as the opening parenthesis.
|
|
3510
|
+
// Give the closing parenthesis the same virtual symbol name as the opening parenthesis
|
|
3511
|
+
// (do the both above at the same time)
|
|
3512
|
+
tmpResults.PostfixTokenObjects[_i20].VirtualSymbolName=tmpSolveLayerStack.pop();tmpResults.PostfixTokenObjects[_i20].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];}// 3. If it's a state address or Symbol, set depth
|
|
3513
|
+
// It was much more complex later on solving these as virtual symbols of their own.
|
|
3514
|
+
// We are saving the value resolution for the very end.
|
|
3515
|
+
else if(tmpResults.PostfixTokenObjects[_i20].Type==='Token.Symbol'){// Set the depth of the current solution depth
|
|
3516
|
+
tmpResults.PostfixTokenObjects[_i20].Depth=tmpDepth;tmpResults.PostfixTokenObjects[_i20].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];// Generate a virtual symbol name that's somewhat human readable
|
|
3517
|
+
//tmpResults.PostfixTokenObjects[i].VirtualSymbolName = `Sm_${tmpVirtualParenthesisIndex}_D_${tmpDepth}_${this.fable.DataFormat.cleanNonAlphaCharacters(tmpResults.PostfixTokenObjects[i].Token)}`;
|
|
3518
|
+
// We've used up this virtual symbol index so increment it
|
|
3519
|
+
// The reason we only use these once is to make sure if we use, say, sin(x) twice at the same depth we still have unique names for each virtual solution
|
|
3520
|
+
//tmpVirtualParenthesisIndex++;
|
|
3521
|
+
}// 4. If it's an operator or constant or comment, just set the depth
|
|
3522
|
+
else{tmpResults.PostfixTokenObjects[_i20].Depth=tmpDepth;tmpResults.PostfixTokenObjects[_i20].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];}}// 4. Walk through the decorated symbols and generate the postfix solve list
|
|
3523
|
+
// We are going to start by creating a map of the solve layers:
|
|
3524
|
+
var tmpSolveLayerMap={};var tmpSolveLayerMaxDepth=0;for(var _i21=0;_i21<tmpResults.PostfixTokenObjects.length;_i21++){if(!tmpSolveLayerMap.hasOwnProperty(tmpResults.PostfixTokenObjects[_i21].SolveLayerStack)){tmpSolveLayerMap[tmpResults.PostfixTokenObjects[_i21].SolveLayerStack]=[];}tmpSolveLayerMap[tmpResults.PostfixTokenObjects[_i21].SolveLayerStack].push(tmpResults.PostfixTokenObjects[_i21]);// See what our max depth is. This is super important to the postfix operation
|
|
3525
|
+
// The programmer in me thinks it would be funny to not track this and just use the map key length as the max size, which would work (logically impossible to have a depth > key length) but it would be quite a bit more confusing to grok the algorithm.
|
|
3526
|
+
if(tmpResults.PostfixTokenObjects[_i21].Depth>tmpSolveLayerMaxDepth){tmpSolveLayerMaxDepth=tmpResults.PostfixTokenObjects[_i21].Depth;}}var tmpSolveLayerKeys=Object.keys(tmpSolveLayerMap);// Reset the virtual symbol index -- it was used above for uniquenes when creating abstract symbols for parenthesis and layer stacks.
|
|
3527
|
+
var tmpVirtualSymbolIndex=0;tmpSolveLayerKeys.sort(// Sort the solve layers by depth.
|
|
3528
|
+
function(pLeftLayer,pRightLayer){// It is impossible to have a layer with no entries in it.
|
|
3529
|
+
// If that ever happens, the bug is actually above and we actively want this to blow up.
|
|
3530
|
+
if(tmpSolveLayerMap[pLeftLayer][0].Depth<tmpSolveLayerMap[pRightLayer][0].Depth){return 1;}if(tmpSolveLayerMap[pLeftLayer][0].Depth>tmpSolveLayerMap[pRightLayer][0].Depth){return-1;}return 0;});// 5. Generate the postfix solve list
|
|
3531
|
+
// The most important thing is going backwards in the depth order (a la reverse polish).
|
|
3532
|
+
// Specifically not using shunting yard to provide in-depth "show your work" notes
|
|
3533
|
+
// Yes it is possible to do a somewhat similar thing with shunting yard but the code is almost unreadable
|
|
3534
|
+
// 5.1 Build the Virtual Symbol Names
|
|
3535
|
+
// This maps layer stack addresses (which match parenthesis virtual symbol names) to the resultant value for that layer stack.
|
|
3536
|
+
// These values change as it solves but the last assignment is the proper assignment because math only reads forward in a line
|
|
3537
|
+
tmpResults.PostfixLayerstackMap={};for(var tmpSolveLayerIndex=0;tmpSolveLayerIndex<tmpSolveLayerKeys.length;tmpSolveLayerIndex++){var tmpSolveLayerTokens=tmpSolveLayerMap[tmpSolveLayerKeys[tmpSolveLayerIndex]];// For each precedence (this isn't strictly required here but makes the outcome for the user more readable)
|
|
3538
|
+
for(var tmpPrecedence=0;tmpPrecedence<=this.ExpressionParser.tokenMaxPrecedence;tmpPrecedence++){// Enumerate all tokens in a layer's expression.
|
|
3539
|
+
// There is a recursive way to do this, but given the short length of even the most complex equations we're favoring readability.
|
|
3540
|
+
for(var _i22=0;_i22<tmpSolveLayerTokens.length;_i22++){// If the token is an operator and at the current precedence, add it to the postfix solve list and mutate the array.
|
|
3541
|
+
if(tmpSolveLayerTokens[_i22].Type==='Token.Operator'&&tmpSolveLayerTokens[_i22].Descriptor.Precedence===tmpPrecedence){var tmpToken=tmpSolveLayerTokens[_i22];// If there is a token and nothing else in this layer, then it's an error.
|
|
3542
|
+
if(tmpSolveLayerTokens.length===1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found a single operator in a solve layer expression at token index ".concat(_i22));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return tmpResults.PostfixSolveList;}// If the token is at the beginning of the expression and not a number line orientation modifier, it's an error.
|
|
3543
|
+
else if(_i22==0&&(tmpToken.Token!='+'||tmpToken.Token!='-')){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found an operator at the beginning of a solve layer expression at token index ".concat(_i22));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return tmpResults.PostfixSolveList;}// If the token is at the end of the expression, it is an error.
|
|
3544
|
+
else if(_i22==tmpSolveLayerTokens.length-1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found an operator at the end of a solve layer expression at token index ".concat(_i22));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return tmpResults.PostfixSolveList;}// The - at the beginning of an expression is a number line orientation modifier
|
|
3545
|
+
else if(_i22==0&&tmpToken.Token=='-'){tmpToken.VirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpResults.PostfixLayerstackMap[tmpToken.SolveLayerStack]=tmpToken.VirtualSymbolName;tmpVirtualSymbolIndex++;}// The - after an operator or an open parenthesis is also a number line orientation modifier
|
|
3546
|
+
else if(_i22>0&&tmpToken.Token=='-'&&(tmpSolveLayerTokens[_i22-1].Type==='Token.Operator'||tmpSolveLayerTokens[_i22-1].Token==='(')){// The number line negation operator is a special case that generates a virtual constant (-1.0) and multiplies it by the next token
|
|
3547
|
+
tmpToken.VirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;}// The + at the beginning is also a number line orientation modifier ... THAT WE IGNORE
|
|
3548
|
+
else if(_i22==0&&tmpToken.Token=='+'){continue;}// The + after an operator or a parenthesis is also a number line orientation modifier ... THAT WE IGNORE
|
|
3549
|
+
else if(_i22>0&&tmpToken.Token=='+'&&(tmpSolveLayerTokens[_i22-1].Type==='Token.Operator'||tmpSolveLayerTokens[_i22-1].Token==='(')){continue;}// If the token is next to another operator it's a parsing error
|
|
3550
|
+
else if(tmpSolveLayerTokens[_i22-1].Type==='Token.Operator'||tmpSolveLayerTokens[_i22+1].Type==='Token.Operator'){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found an operator at token index ".concat(_i22," that is not surrounded by two values."));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return tmpResults.PostfixSolveList;}// Finally add a virtual symbol name to the dang thing.
|
|
3551
|
+
else{tmpToken.VirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpResults.PostfixLayerstackMap[tmpToken.SolveLayerStack]=tmpToken.VirtualSymbolName;tmpVirtualSymbolIndex++;}}else if(tmpSolveLayerTokens[_i22].Type==='Token.Function'&&tmpPrecedence===0){var _tmpToken=tmpSolveLayerTokens[_i22];_tmpToken.VirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;tmpResults.PostfixLayerstackMap[_tmpToken.SolveLayerStack]=_tmpToken.VirtualSymbolName;}}}}// 5.2: Decorate the Parenthesis with Virtual Symbol Names
|
|
3552
|
+
// ... this gets funny because of precedence of operations surrounding them, parenthesis and functions.
|
|
3553
|
+
var tmpParenthesisCacheLIFOStack=[];for(var _i23=0;_i23<tmpResults.PostfixTokenObjects.length;_i23++){var tmpPostfixTokenObject=tmpResults.PostfixTokenObjects[_i23];if(tmpPostfixTokenObject.Type==='Token.Parenthesis'){// This is just to track the parenthesis stack level in User feedback
|
|
3554
|
+
tmpPostfixTokenObject.ParenthesisStack=tmpPostfixTokenObject.VirtualSymbolName;if(tmpPostfixTokenObject.Token==='('){// It's an open parenthesis. If the previous token was an operator, get its precedence.
|
|
3555
|
+
if(_i23>0){if(tmpResults.PostfixTokenObjects[_i23-1].Type==='Token.Operator'){tmpPostfixTokenObject.PreviousPrecedence=tmpResults.PostfixTokenObjects[_i23-1].Descriptor.Precedence;tmpPostfixTokenObject.IsFunction=false;tmpPostfixTokenObject.PreviousVirtualSymbolName=tmpResults.PostfixTokenObjects[_i23-1].VirtualSymbolName;tmpPostfixTokenObject.VirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];}// This is a function, we will create a virtual symbol for the discrete parenthesis
|
|
3556
|
+
else if(tmpResults.PostfixTokenObjects[_i23-1].Type==='Token.Function'){tmpPostfixTokenObject.PreviousPrecedence=0;tmpPostfixTokenObject.IsFunction=true;tmpPostfixTokenObject.PreviousVirtualSymbolName=tmpResults.PostfixTokenObjects[_i23-1].VirtualSymbolName;var tmpVirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];if(!tmpVirtualSymbolName){// This is a parenthesis group with no operators in it; make a virtual symbol name.
|
|
3557
|
+
tmpVirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;}tmpPostfixTokenObject.VirtualSymbolName=tmpVirtualSymbolName;if(_i23>1){// Todo: This needs to be enhanced to deal with negations
|
|
3558
|
+
var tmpTokenBeforeFunction=tmpResults.PostfixTokenObjects[_i23-2];if(tmpTokenBeforeFunction.Type==='Token.Operator'){tmpPostfixTokenObject.PreviousVirtualSymbolName=tmpResults.PostfixTokenObjects[_i23-2].VirtualSymbolName;tmpPostfixTokenObject.PreviousPrecedence=tmpResults.PostfixTokenObjects[_i23-2].Descriptor.Precedence;}}}}else{tmpPostfixTokenObject.VirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];}tmpParenthesisCacheLIFOStack.push(tmpPostfixTokenObject);}if(tmpPostfixTokenObject.Token===')'){// There are three options for assigning this:
|
|
3559
|
+
var tmpOpenParenthesis=tmpParenthesisCacheLIFOStack.pop();// It's at the end of the tokens -- use the stack's identifier
|
|
3560
|
+
if(_i23>=tmpResults.PostfixTokenObjects.length-1){if(tmpOpenParenthesis.IsFunction){tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.PreviousVirtualSymbolName;}else{tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.VirtualSymbolName;}}else{// The next token is an operator and we're a function
|
|
3561
|
+
var tmpPeekedNextToken=tmpResults.PostfixTokenObjects[_i23+1];if(tmpPeekedNextToken.Type=='Token.Operator'&&tmpOpenParenthesis.IsFunction){// This is the most complex case -- the next token is an operator AND this is a function.
|
|
3562
|
+
// The following is just pointer math.
|
|
3563
|
+
// If the operater is at the same precedence or higher than the open parenthesis previous operator, use the previous operator's identifier
|
|
3564
|
+
// NOTE: This line of code is insanely complex
|
|
3565
|
+
//tmpPostfixTokenObject.VirtualSymbolName = tmpOpenParenthesis.PreviousVirtualSymbolName;
|
|
3566
|
+
// If the next token has higher precedence than what's before the open parenthesis, use it for the open as well
|
|
3567
|
+
if(tmpPeekedNextToken.Descriptor.Precedence<tmpOpenParenthesis.PreviousPrecedence){tmpOpenParenthesis.VirtualSymbolName=tmpPeekedNextToken.VirtualSymbolName;tmpPostfixTokenObject.VirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];}// Otherwise use this one -- it is the higher precedence. And update the previous parenthesis operator's virtual symbol to be the peeked token's virtual symbol.
|
|
3568
|
+
else{tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.PreviousVirtualSymbolName;}}// The next token is an operator and it isn't a function
|
|
3569
|
+
else if(tmpPeekedNextToken.Type=='Token.Operator'&&tmpOpenParenthesis.hasOwnProperty('PreviousPrecedence')){// This is the second most complex case -- the next token is an operator.
|
|
3570
|
+
// If the operater is at the same precedence or higher than the open parenthesis previous operator, use the previous operator's identifier
|
|
3571
|
+
// NOTE: This line of code is insanely complex
|
|
3572
|
+
if(tmpPeekedNextToken.Descriptor.Precedence<=tmpOpenParenthesis.PreviousPrecedence){tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.PreviousVirtualSymbolName;}// Otherwise use this one -- it is the higher precedence. And update the previous parenthesis operator's virtual symbol to be the peeked token's virtual symbol.
|
|
3573
|
+
else{tmpPostfixTokenObject.VirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];tmpOpenParenthesis.VirtualSymbolName=tmpPeekedNextToken.VirtualSymbolName;}}else{// If this is a function, dereference the function's previous virtual symbol name
|
|
3574
|
+
if(tmpOpenParenthesis.IsFunction){tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.PreviousVirtualSymbolName;}else{tmpPostfixTokenObject.VirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];}}}// If there isn't an operator in the layer stack, push forward the assignment
|
|
3575
|
+
if(!tmpResults.PostfixLayerstackMap[tmpOpenParenthesis.ParenthesisStack]){tmpResults.PostfixLayerstackMap[tmpOpenParenthesis.ParenthesisStack]=tmpOpenParenthesis.VirtualSymbolName;}}}}for(var _tmpSolveLayerIndex=0;_tmpSolveLayerIndex<tmpSolveLayerKeys.length;_tmpSolveLayerIndex++){var _tmpSolveLayerTokens=tmpSolveLayerMap[tmpSolveLayerKeys[_tmpSolveLayerIndex]];if(_tmpSolveLayerTokens.length===1){// This is just a simple value assignment -- use a simple addition virtual operation.
|
|
3576
|
+
// We often see these inside functions.
|
|
3577
|
+
var tmpAbstractAddToken=this.getTokenContainerObject('+');//let tmpVirtualSymbolName = tmpResults.PostfixLayerstackMap[tmpSolveLayerTokens[0].SolveLayerStack];
|
|
3578
|
+
tmpAbstractAddToken.VirtualSymbolName=tmpResults.PostfixLayerstackMap[_tmpSolveLayerTokens[0].SolveLayerStack];tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(tmpAbstractAddToken,this.getTokenContainerObject('0.0'),_tmpSolveLayerTokens[0]));}}// 5.3: Generate the Postfix Solve List
|
|
3579
|
+
for(var _tmpSolveLayerIndex2=0;_tmpSolveLayerIndex2<tmpSolveLayerKeys.length;_tmpSolveLayerIndex2++){var _tmpSolveLayerTokens2=tmpSolveLayerMap[tmpSolveLayerKeys[_tmpSolveLayerIndex2]];// For each precedence level in the layer
|
|
3580
|
+
for(var _tmpPrecedence=0;_tmpPrecedence<=this.ExpressionParser.tokenMaxPrecedence;_tmpPrecedence++){// Enumerate all tokens in a layer's expression.
|
|
3581
|
+
// There is a recursive way to do this, but given the short length of even the most complex equations we're favoring readability.
|
|
3582
|
+
for(var _i24=0;_i24<_tmpSolveLayerTokens2.length;_i24++){// If the token is an operator and at the current precedence, add it to the postfix solve list and mutate the array.
|
|
3583
|
+
if(_tmpSolveLayerTokens2[_i24].Type==='Token.Operator'&&_tmpSolveLayerTokens2[_i24].Descriptor.Precedence===_tmpPrecedence){var _tmpToken2=_tmpSolveLayerTokens2[_i24];// The - at the beginning of an expression is a number line orientation modifier
|
|
3584
|
+
if(_i24==0&&_tmpToken2.Token=='-'){// The number line negation operator is a special case that generates a virtual constant (-1.0) and multiplies it by the next token
|
|
3585
|
+
// This is an abstract operation that isn't in the expression.
|
|
3586
|
+
var tmpAbstractMultiplyToken=this.getTokenContianerObject('*');tmpAbstractMultiplyToken.VirtualSymbolName=_tmpToken2.VirtualSymbolName;tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(tmpAbstractMultiplyToken,this.getTokenContainerObject('-1.0'),_tmpSolveLayerTokens2[_i24+1]));}// The - after an operator or an open parenthesis is also a number line orientation modifier
|
|
3587
|
+
else if(_i24>0&&_tmpToken2.Token=='-'&&(_tmpSolveLayerTokens2[_i24-1].Type==='Token.Operator'||_tmpSolveLayerTokens2[_i24-1].Token==='(')){// The number line negation operator is a special case that generates a virtual constant (-1.0) and multiplies it by the next token
|
|
3588
|
+
var _tmpAbstractMultiplyToken=this.getTokenContianerObject('*');_tmpAbstractMultiplyToken.VirtualSymbolName=_tmpToken2.VirtualSymbolName;tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpAbstractMultiplyToken,this.getTokenContainerObject('-1.0'),_tmpSolveLayerTokens2[_i24+1]));}// The + at the beginning is also a number line orientation modifier ... THAT WE IGNORE
|
|
3589
|
+
else if(_i24==0&&_tmpToken2.Token=='+'){continue;}// The + after an operator or a parenthesis is also a number line orientation modifier ... THAT WE IGNORE
|
|
3590
|
+
else if(_i24>0&&_tmpToken2.Token=='+'&&(_tmpSolveLayerTokens2[_i24-1].Type==='Token.Operator'||_tmpSolveLayerTokens2[_i24-1].Token==='(')){continue;}// Finally add the dang thing.
|
|
3591
|
+
else{tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpToken2,_tmpSolveLayerTokens2[_i24-1],_tmpSolveLayerTokens2[_i24+1],_tmpSolveLayerTokens2,_i24));}}else if(_tmpSolveLayerTokens2[_i24].Type==='Token.Function'&&_tmpPrecedence===0){var _tmpToken3=_tmpSolveLayerTokens2[_i24];// Not sure what to do with the other token.
|
|
3592
|
+
tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpToken3,_tmpSolveLayerTokens2[_i24+1],this.getTokenContainerObject('0.0')));}}}}// Now set the assignment address.
|
|
3593
|
+
var tmpAssignmentInstruction=this.getPosfixSolveListOperation(this.getTokenContainerObject('Assign','Token.SolverInstruction'),this.getTokenContainerObject('DestinationHash','Token.SolverInstruction'),this.getTokenContainerObject('Resulting','Token.SolverInstruction'));tmpAssignmentInstruction.VirtualSymbolName=tmpResults.PostfixedAssignmentAddress;tmpResults.PostfixSolveList.push(tmpAssignmentInstruction);return tmpResults.PostfixSolveList;}}]);return ExpressionParserPostfix;}(libExpressionParserOperationBase);module.exports=ExpressionParserPostfix;},{"./Fable-Service-ExpressionParser-Base.js":136}],141:[function(require,module,exports){var libExpressionParserOperationBase=require('./Fable-Service-ExpressionParser-Base.js');var ExpressionParserSolver=/*#__PURE__*/function(_libExpressionParserO4){_inherits(ExpressionParserSolver,_libExpressionParserO4);function ExpressionParserSolver(pFable,pOptions,pServiceHash){var _this29;_classCallCheck2(this,ExpressionParserSolver);_this29=_callSuper(this,ExpressionParserSolver,[pFable,pOptions,pServiceHash]);_this29.serviceType='ExpressionParser-Solver';return _this29;}_createClass2(ExpressionParserSolver,[{key:"solvePostfixedExpression",value:function solvePostfixedExpression(pPostfixedExpression,pDataDestinationObject,pResultObject,pManifest){var tmpResults=_typeof(pResultObject)==='object'?pResultObject:{ExpressionParserLog:[]};var tmpManifest=_typeof(pManifest)==='object'?pManifest:this.fable.newManyfest();var tmpDataDestinationObject=_typeof(pDataDestinationObject)==='object'?pDataDestinationObject:{};// If there was a fable passed in (e.g. the results object was a service or such), we won't decorate
|
|
3594
|
+
var tmpPassedInFable=tmpResults.hasOwnProperty('fable');if(!tmpPassedInFable){tmpResults.fable=this.fable;}if(!Array.isArray(pPostfixedExpression)){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.solvePostfixedExpression was passed a non-array postfixed expression.");this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return false;}if(pPostfixedExpression.length<1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.solvePostfixedExpression was passed an empty postfixed expression.");this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return false;}// This is how the user communication magic happens.
|
|
3595
|
+
tmpResults.VirtualSymbols={};for(var i=0;i<pPostfixedExpression.length;i++){if(pPostfixedExpression[i].Operation.Type==='Token.SolverInstruction'){continue;}var tmpStepResultObject={ExpressionStep:pPostfixedExpression[i],ExpressionStepIndex:i,ResultsObject:tmpResults,Manifest:tmpManifest};// Resolve the virtual symbols to their actual values
|
|
3596
|
+
if(tmpStepResultObject.ExpressionStep.LeftValue.Type==='Token.VirtualSymbol'){tmpStepResultObject.ExpressionStep.LeftValue.Value=tmpManifest.getValueAtAddress(tmpResults.VirtualSymbols,tmpStepResultObject.ExpressionStep.LeftValue.Token);}if(tmpStepResultObject.ExpressionStep.RightValue.Type==='Token.VirtualSymbol'){tmpStepResultObject.ExpressionStep.RightValue.Value=tmpManifest.getValueAtAddress(tmpResults.VirtualSymbols,tmpStepResultObject.ExpressionStep.RightValue.Token);}// Resolve the parenthesis to their actual values
|
|
3597
|
+
if(tmpStepResultObject.ExpressionStep.LeftValue.Type==='Token.Parenthesis'){tmpStepResultObject.ExpressionStep.LeftValue.Value=tmpManifest.getValueAtAddress(tmpResults.VirtualSymbols,tmpStepResultObject.ExpressionStep.LeftValue.VirtualSymbolName);}if(tmpStepResultObject.ExpressionStep.RightValue.Type==='Token.Parenthesis'){tmpStepResultObject.ExpressionStep.RightValue.Value=tmpManifest.getValueAtAddress(tmpResults.VirtualSymbols,tmpStepResultObject.ExpressionStep.RightValue.VirtualSymbolName);}if(tmpStepResultObject.ExpressionStep.Operation.Type='Operator'){// TODO: This can be optimized. A lot. If necessary. Seems pretty fast honestly for even thousands of operations. Slowest part is arbitrary precision.
|
|
3598
|
+
// An operator always has a left and right value.
|
|
3599
|
+
var tmpFunctionAddress=false;if(this.ExpressionParser.tokenMap.hasOwnProperty(tmpStepResultObject.ExpressionStep.Operation.Token)){tmpFunctionAddress="ResultsObject.".concat(tmpStepResultObject.ExpressionStep.Operation.Descriptor.Function);}else if(this.ExpressionParser.functionMap.hasOwnProperty(tmpStepResultObject.ExpressionStep.Operation.Token.toLowerCase())){tmpFunctionAddress="ResultsObject.".concat(this.ExpressionParser.functionMap[tmpStepResultObject.ExpressionStep.Operation.Token.toLowerCase()].Address);}try{this.log.trace("Solving Step ".concat(i," [").concat(tmpStepResultObject.ExpressionStep.VirtualSymbolName,"] --> [").concat(tmpStepResultObject.ExpressionStep.Operation.Token,"]: ( ").concat(tmpStepResultObject.ExpressionStep.LeftValue.Value," , ").concat(tmpStepResultObject.ExpressionStep.RightValue.Value," )"));tmpResults.VirtualSymbols[tmpStepResultObject.ExpressionStep.VirtualSymbolName]=tmpManifest.getValueAtAddress(tmpStepResultObject,"".concat(tmpFunctionAddress,"(ExpressionStep.LeftValue.Value,ExpressionStep.RightValue.Value)"));this.log.trace(" ---> Step ".concat(i,": ").concat(tmpResults.VirtualSymbols[tmpStepResultObject.ExpressionStep.VirtualSymbolName]));}catch(pError){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.solvePostfixedExpression failed to solve step ".concat(i," with function ").concat(tmpStepResultObject.ExpressionStep.Operation.Token,"."));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return false;}// Equations don't always solve in virtual symbol order.
|
|
3600
|
+
tmpResults.SolverFinalVirtualSymbol=tmpStepResultObject.ExpressionStep.VirtualSymbolName;}}var tmpSolverResultValue=tmpManifest.getValueAtAddress(tmpResults,"VirtualSymbols.".concat(tmpResults.SolverFinalVirtualSymbol));// Now deal with final assignment
|
|
3601
|
+
for(var _i25=0;_i25<pPostfixedExpression.length;_i25++){if(pPostfixedExpression[_i25].Operation.Type==='Token.SolverInstruction'&&pPostfixedExpression[_i25].Operation.Token=='Assign'){tmpManifest.setValueAtAddress(tmpResults.VirtualSymbols,pPostfixedExpression[_i25].VirtualSymbolName,tmpSolverResultValue);tmpManifest.setValueByHash(tmpDataDestinationObject,pPostfixedExpression[_i25].VirtualSymbolName,tmpSolverResultValue);}}// Clean up the reference if we added it to the object.
|
|
3602
|
+
if(!tmpPassedInFable){delete tmpResults.fable;}return tmpSolverResultValue.toString();}}]);return ExpressionParserSolver;}(libExpressionParserOperationBase);module.exports=ExpressionParserSolver;},{"./Fable-Service-ExpressionParser-Base.js":136}],142:[function(require,module,exports){module.exports={"=":{"Name":"Equals","Token":"=","Precedence":0,"Type":"Assignment"},"(":{"Name":"Left Parenthesis","Token":"(","Precedence":0,"Type":"Parenthesis"},")":{"Name":"Right Parenthesis","Token":")","Precedence":0,"Type":"Parenthesis"},"*":{"Name":"Multiply","Token":"*","Function":"fable.Math.multiplyPrecise","Precedence":3,"Type":"Operator"},"/":{"Name":"Divide","Token":"/","Function":"fable.Math.dividePrecise","Precedence":3,"Type":"Operator"},"^":{"Name":"Exponent","Token":"^","Function":"fable.Math.powerPrecise","Precedence":1,"Type":"Operator"},"%":{"Name":"Modulus","Token":"%","Function":"fable.Math.modPrecise","Precedence":3,"Type":"Operator"},"+":{"Name":"Add","Token":"+","Function":"fable.Math.addPrecise","Precedence":4,"Type":"Operator"},"-":{"Name":"Subtract","Token":"-","Function":"fable.Math.subtractPrecise","Precedence":4,"Type":"Operator"}};},{}],143:[function(require,module,exports){(function(process){(function(){var libFableServiceBase=require('fable-serviceproviderbase');var libFS=require('fs');var libPath=require('path');var libReadline=require('readline');var FableServiceFilePersistence=/*#__PURE__*/function(_libFableServiceBase5){_inherits(FableServiceFilePersistence,_libFableServiceBase5);function FableServiceFilePersistence(pFable,pOptions,pServiceHash){var _this30;_classCallCheck2(this,FableServiceFilePersistence);_this30=_callSuper(this,FableServiceFilePersistence,[pFable,pOptions,pServiceHash]);_this30.serviceType='FilePersistence';if(!_this30.options.hasOwnProperty('Mode')){_this30.options.Mode=parseInt('0777',8)&~process.umask();}_this30.libFS=libFS;_this30.libPath=libPath;_this30.libReadline=libReadline;return _this30;}_createClass2(FableServiceFilePersistence,[{key:"joinPath",value:function joinPath(){return libPath.resolve.apply(libPath,arguments);}},{key:"existsSync",value:function existsSync(pPath){return libFS.existsSync(pPath);}},{key:"exists",value:function exists(pPath,fCallback){var tmpFileExists=this.existsSync(pPath);;return fCallback(null,tmpFileExists);}},{key:"appendFileSync",value:function appendFileSync(pFileName,pAppendContent,pOptions){var tmpOptions=typeof pOptions==='undefined'?'utf8':pOptions;return libFS.appendFileSync(pFileName,pAppendContent,tmpOptions);}},{key:"deleteFileSync",value:function deleteFileSync(pFileName){return libFS.unlinkSync(pFileName);}},{key:"deleteFolderSync",value:function deleteFolderSync(pFileName){return libFS.rmdirSync(pFileName);}},{key:"readFileSync",value:function readFileSync(pFilePath,pOptions){var tmpOptions=typeof pOptions==='undefined'?'utf8':pOptions;return libFS.readFileSync(pFilePath,tmpOptions);}},{key:"readFile",value:function readFile(pFilePath,pOptions,fCallback){var tmpOptions=typeof pOptions==='undefined'?'utf8':pOptions;return libFS.readFile(pFilePath,tmpOptions,fCallback);}},{key:"writeFileSync",value:function writeFileSync(pFileName,pFileContent,pOptions){var tmpOptions=typeof pOptions==='undefined'?'utf8':pOptions;return libFS.writeFileSync(pFileName,pFileContent,tmpOptions);}},{key:"writeFileSyncFromObject",value:function writeFileSyncFromObject(pFileName,pObject){return this.writeFileSync(pFileName,JSON.stringify(pObject,null,4));}},{key:"writeFileSyncFromArray",value:function writeFileSyncFromArray(pFileName,pFileArray){if(!Array.isArray(pFileArray)){this.log.error("File Persistence Service attempted to write ".concat(pFileName," from array but the expected array was not an array (it was a ").concat(_typeof(pFileArray),")."));return Error('Attempted to write ${pFileName} from array but the expected array was not an array (it was a ${typeof(pFileArray)}).');}else{for(var i=0;i<pFileArray.length;i++){return this.appendFileSync(pFileName,"".concat(pFileArray[i],"\n"));}}}},{key:"writeFile",value:function writeFile(pFileName,pFileContent,pOptions,fCallback){var tmpOptions=typeof pOptions==='undefined'?'utf8':pOptions;return libFS.writeFile(pFileName,pFileContent,tmpOptions,fCallback);}},{key:"lineReaderFactory",value:function lineReaderFactory(pFilePath,fOnLine,fOnComplete,fOnError){var tmpLineReader={};if(typeof pFilePath!='string'){return false;}tmpLineReader.filePath=pFilePath;tmpLineReader.fileStream=libFS.createReadStream(tmpLineReader.filePath);tmpLineReader.reader=libReadline.createInterface({input:tmpLineReader.fileStream,crlfDelay:Infinity});if(typeof fOnError==='function'){tmpLineReader.reader.on('error',fOnError);}tmpLineReader.reader.on('line',typeof fOnLine==='function'?fOnLine:function(){});if(typeof fOnComplete==='function'){tmpLineReader.reader.on('close',fOnComplete);}return tmpLineReader;}// Folder management
|
|
3603
|
+
},{key:"makeFolderRecursive",value:function makeFolderRecursive(pParameters,fCallback){var _this31=this;var tmpParameters=pParameters;if(typeof pParameters=='string'){tmpParameters={Path:pParameters};}else if(_typeof(pParameters)!=='object'){fCallback(new Error('Parameters object or string not properly passed to recursive folder create.'));return false;}if(typeof tmpParameters.Path!=='string'){fCallback(new Error('Parameters object needs a path to run the folder create operation.'));return false;}if(!tmpParameters.hasOwnProperty('Mode')){tmpParameters.Mode=this.options.Mode;}// Check if we are just starting .. if so, build the initial state for our recursive function
|
|
3345
3604
|
if(typeof tmpParameters.CurrentPathIndex==='undefined'){// Build the tools to start recursing
|
|
3346
3605
|
tmpParameters.ActualPath=libPath.normalize(tmpParameters.Path);tmpParameters.ActualPathParts=tmpParameters.ActualPath.split(libPath.sep);tmpParameters.CurrentPathIndex=0;tmpParameters.CurrentPath='';}else{// This is not our first run, so we will continue the recursion.
|
|
3347
3606
|
// Build the new base path
|
|
@@ -3349,14 +3608,14 @@ if(tmpParameters.CurrentPath==libPath.sep){tmpParameters.CurrentPath=tmpParamete
|
|
|
3349
3608
|
tmpParameters.CurrentPathIndex++;}// Check if the path is fully complete
|
|
3350
3609
|
if(tmpParameters.CurrentPathIndex>=tmpParameters.ActualPathParts.length){return fCallback(null);}// Check if the path exists (and is a folder)
|
|
3351
3610
|
libFS.open(tmpParameters.CurrentPath+libPath.sep+tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex],'r',function(pError,pFileDescriptor){if(pFileDescriptor){libFS.closeSync(pFileDescriptor);}if(pError&&pError.code=='ENOENT'){/* Path doesn't exist, create it */libFS.mkdir(tmpParameters.CurrentPath+libPath.sep+tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex],tmpParameters.Mode,function(pCreateError){if(!pCreateError){// We have now created our folder and there was no error -- continue.
|
|
3352
|
-
return
|
|
3353
|
-
return
|
|
3611
|
+
return _this31.makeFolderRecursive(tmpParameters,fCallback);}else if(pCreateError.code=='EEXIST'){// The folder exists -- our dev might be running this in parallel/async/whatnot.
|
|
3612
|
+
return _this31.makeFolderRecursive(tmpParameters,fCallback);}else{console.log(pCreateError.code);return fCallback(pCreateError);}});}else{return _this31.makeFolderRecursive(tmpParameters,fCallback);}});}}]);return FableServiceFilePersistence;}(libFableServiceBase);module.exports=FableServiceFilePersistence;}).call(this);}).call(this,require('_process'));},{"_process":87,"fable-serviceproviderbase":51,"fs":19,"path":83,"readline":19}],144:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');/**
|
|
3354
3613
|
* Arbitrary Precision Math Operations
|
|
3355
3614
|
* @author Steven Velozo <steven@velozo.com>
|
|
3356
3615
|
* @description Simple functions that perform arbitrary precision math operations and return string resultant values. Wraps big.js
|
|
3357
3616
|
* @class FableServiceMath
|
|
3358
3617
|
* @extends libFableServiceBase
|
|
3359
|
-
*/var FableServiceMath=/*#__PURE__*/function(
|
|
3618
|
+
*/var FableServiceMath=/*#__PURE__*/function(_libFableServiceBase6){_inherits(FableServiceMath,_libFableServiceBase6);function FableServiceMath(pFable,pOptions,pServiceHash){var _this32;_classCallCheck2(this,FableServiceMath);_this32=_callSuper(this,FableServiceMath,[pFable,pOptions,pServiceHash]);_this32.serviceType='Math';return _this32;}/*
|
|
3360
3619
|
Pass-through Rounding Method Constants
|
|
3361
3620
|
|
|
3362
3621
|
Property Value BigDecimal Equiv Description
|
|
@@ -3365,11 +3624,13 @@ return _this25.makeFolderRecursive(tmpParameters,fCallback);}else{console.log(pC
|
|
|
3365
3624
|
roundHalfUp 1 ROUND_HALF_UP Rounds towards nearest neighbour. (_If equidistant, rounds away from zero._)
|
|
3366
3625
|
roundHalfEven 2 ROUND_HALF_EVEN Rounds towards nearest neighbour. (_If equidistant, rounds towards even neighbour._)
|
|
3367
3626
|
roundUp 3 ROUND_UP Rounds positively away from zero. (_Always round up._)
|
|
3368
|
-
*/_createClass2(FableServiceMath,[{key:"roundDown",get:function get(){return this.fable.Utility.bigNumber.roundDown;}},{key:"roundHalfUp",get:function get(){return this.fable.Utility.bigNumber.roundHalfUp;}},{key:"roundHalfEven",get:function get(){return this.fable.Utility.bigNumber.roundHalfEven;}},{key:"roundUp",get:function get(){return this.fable.Utility.bigNumber.roundUp;}},{key:"parsePrecise",value:function parsePrecise(pValue,pNonNumberValue){var tmpNumber;try{tmpNumber=new this.fable.Utility.bigNumber(pValue);}catch(pError){this.log.warn("Error parsing number (type ".concat(_typeof(pValue),"): ").concat(pError));tmpNumber=typeof pNonNumberValue==='undefined'?"0.0":pNonNumberValue;}return tmpNumber.toString();}},{key:"percentagePrecise",value:function percentagePrecise(pIs,pOf){var tmpLeftValue=isNaN(pIs)?0:pIs;var tmpRightValue=isNaN(pOf)?0:pOf;if(tmpRightValue==0){return'0';}var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.div(tmpRightValue);tmpResult=tmpResult.times(100);return tmpResult.toString();}},{key:"roundPrecise",value:function roundPrecise(pValue,pDecimals,pRoundingMethod){var tmpValue=isNaN(pValue)?0:pValue;var tmpDecimals=isNaN(pDecimals)?0:pDecimals;var tmpRoundingMethod=typeof pRoundingMethod==='undefined'?this.roundHalfUp:pRoundingMethod;var tmpArbitraryValue=new this.fable.Utility.bigNumber(tmpValue);var tmpResult=tmpArbitraryValue.round(tmpDecimals,tmpRoundingMethod);return tmpResult.toString();}},{key:"toFixedPrecise",value:function toFixedPrecise(pValue,pDecimals,pRoundingMethod){var tmpValue=isNaN(pValue)?0:pValue;var tmpDecimals=isNaN(pDecimals)?0:pDecimals;var tmpRoundingMethod=typeof pRoundingMethod==='undefined'?this.roundHalfUp:pRoundingMethod;var tmpArbitraryValue=new this.fable.Utility.bigNumber(tmpValue);var tmpResult=tmpArbitraryValue.toFixed(tmpDecimals,tmpRoundingMethod);return tmpResult.toString();}},{key:"addPrecise",value:function addPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.plus(tmpRightValue);return tmpResult.toString();}},{key:"subtractPrecise",value:function subtractPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.minus(tmpRightValue);return tmpResult.toString();}
|
|
3627
|
+
*/_createClass2(FableServiceMath,[{key:"roundDown",get:function get(){return this.fable.Utility.bigNumber.roundDown;}},{key:"roundHalfUp",get:function get(){return this.fable.Utility.bigNumber.roundHalfUp;}},{key:"roundHalfEven",get:function get(){return this.fable.Utility.bigNumber.roundHalfEven;}},{key:"roundUp",get:function get(){return this.fable.Utility.bigNumber.roundUp;}},{key:"parsePrecise",value:function parsePrecise(pValue,pNonNumberValue){var tmpNumber;try{tmpNumber=new this.fable.Utility.bigNumber(pValue);}catch(pError){this.log.warn("Error parsing number (type ".concat(_typeof(pValue),"): ").concat(pError));tmpNumber=typeof pNonNumberValue==='undefined'?"0.0":pNonNumberValue;}return tmpNumber.toString();}},{key:"percentagePrecise",value:function percentagePrecise(pIs,pOf){var tmpLeftValue=isNaN(pIs)?0:pIs;var tmpRightValue=isNaN(pOf)?0:pOf;if(tmpRightValue==0){return'0';}var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.div(tmpRightValue);tmpResult=tmpResult.times(100);return tmpResult.toString();}},{key:"roundPrecise",value:function roundPrecise(pValue,pDecimals,pRoundingMethod){var tmpValue=isNaN(pValue)?0:pValue;var tmpDecimals=isNaN(pDecimals)?0:pDecimals;var tmpRoundingMethod=typeof pRoundingMethod==='undefined'?this.roundHalfUp:pRoundingMethod;var tmpArbitraryValue=new this.fable.Utility.bigNumber(tmpValue);var tmpResult=tmpArbitraryValue.round(tmpDecimals,tmpRoundingMethod);return tmpResult.toString();}},{key:"toFixedPrecise",value:function toFixedPrecise(pValue,pDecimals,pRoundingMethod){var tmpValue=isNaN(pValue)?0:pValue;var tmpDecimals=isNaN(pDecimals)?0:pDecimals;var tmpRoundingMethod=typeof pRoundingMethod==='undefined'?this.roundHalfUp:pRoundingMethod;var tmpArbitraryValue=new this.fable.Utility.bigNumber(tmpValue);var tmpResult=tmpArbitraryValue.toFixed(tmpDecimals,tmpRoundingMethod);return tmpResult.toString();}},{key:"addPrecise",value:function addPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.plus(tmpRightValue);return tmpResult.toString();}},{key:"subtractPrecise",value:function subtractPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.minus(tmpRightValue);return tmpResult.toString();}// Bignumber does not use precision values for power -- only javascript decimals
|
|
3628
|
+
},{key:"powerPrecise",value:function powerPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:parseInt(pRightValue);var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.pow(tmpRightValue);return tmpResult.toString();}},{key:"multiplyPrecise",value:function multiplyPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.times(tmpRightValue);return tmpResult.toString();}},{key:"dividePrecise",value:function dividePrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.div(tmpRightValue);return tmpResult.toString();}},{key:"modPrecise",value:function modPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);var tmpResult=tmpLeftArbitraryValue.mod(tmpRightValue);return tmpResult.toString();}},{key:"sqrtPrecise",value:function sqrtPrecise(pValue){var tmpValue=isNaN(pValue)?0:pValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpValue);var tmpResult=tmpLeftArbitraryValue.sqrt();return tmpResult.toString();}},{key:"absPrecise",value:function absPrecise(pValue){var tmpValue=isNaN(pValue)?0:pValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpValue);var tmpResult=tmpLeftArbitraryValue.abs();return tmpResult.toString();}},{key:"comparePrecise",value:function comparePrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);return tmpLeftArbitraryValue.cmp(tmpRightValue);}},{key:"gtPrecise",value:function gtPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);return tmpLeftArbitraryValue.gt(tmpRightValue);}},{key:"gtePrecise",value:function gtePrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);return tmpLeftArbitraryValue.gte(tmpRightValue);}},{key:"ltPrecise",value:function ltPrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);return tmpLeftArbitraryValue.lt(tmpRightValue);}},{key:"ltePrecise",value:function ltePrecise(pLeftValue,pRightValue){var tmpLeftValue=isNaN(pLeftValue)?0:pLeftValue;var tmpRightValue=isNaN(pRightValue)?0:pRightValue;var tmpLeftArbitraryValue=new this.fable.Utility.bigNumber(tmpLeftValue);return tmpLeftArbitraryValue.lt(tmpRightValue);}},{key:"radPrecise",value:function radPrecise(pDegrees){var tmpDegrees=isNaN(pDegrees)?0:pDegrees;var tmpDegreesArbitraryValue=new this.fable.Utility.bigNumber(tmpDegrees);// TODO: Const for pi in arbitrary precision?
|
|
3629
|
+
var tmpResult=tmpDegreesArbitraryValue.times(Math.PI).div(180);return tmpResult.toString();}},{key:"sin",value:function sin(pRadians){var tmpRadians=isNaN(pRadians)?0:pRadians;return Math.sin(tmpRadians);}},{key:"cos",value:function cos(pRadians){var tmpRadians=isNaN(pRadians)?0:pRadians;return Math.cos(tmpRadians);}},{key:"tan",value:function tan(pRadians){var tmpRadians=isNaN(pRadians)?0:pRadians;return Math.tan(tmpRadians);}}]);return FableServiceMath;}(libFableServiceBase);module.exports=FableServiceMath;},{"fable-serviceproviderbase":51}],145:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');/**
|
|
3369
3630
|
* Precedent Meta-Templating
|
|
3370
3631
|
* @author Steven Velozo <steven@velozo.com>
|
|
3371
3632
|
* @description Process text stream trie and postfix tree, parsing out meta-template expression functions.
|
|
3372
|
-
*/var libWordTree=require("./Fable-Service-MetaTemplate/MetaTemplate-WordTree.js");var libStringParser=require("./Fable-Service-MetaTemplate/MetaTemplate-StringParser.js");var FableServiceMetaTemplate=/*#__PURE__*/function(
|
|
3633
|
+
*/var libWordTree=require("./Fable-Service-MetaTemplate/MetaTemplate-WordTree.js");var libStringParser=require("./Fable-Service-MetaTemplate/MetaTemplate-StringParser.js");var FableServiceMetaTemplate=/*#__PURE__*/function(_libFableServiceBase7){_inherits(FableServiceMetaTemplate,_libFableServiceBase7);function FableServiceMetaTemplate(pFable,pOptions,pServiceHash){var _this33;_classCallCheck2(this,FableServiceMetaTemplate);_this33=_callSuper(this,FableServiceMetaTemplate,[pFable,pOptions,pServiceHash]);_this33.serviceType='MetaTemplate';_this33.WordTree=new libWordTree();_this33.StringParser=new libStringParser(_this33.fable);_this33.ParseTree=_this33.WordTree.ParseTree;return _this33;}/**
|
|
3373
3634
|
* Add a Pattern to the Parse Tree
|
|
3374
3635
|
* @method addPattern
|
|
3375
3636
|
* @param {Object} pTree - A node on the parse tree to push the characters into
|
|
@@ -3384,7 +3645,7 @@ return _this25.makeFolderRecursive(tmpParameters,fCallback);}else{console.log(pC
|
|
|
3384
3645
|
* @param {function} fCallback - The callback function to call when a pattern is matched
|
|
3385
3646
|
* @param {array} pDataContext - The history of data objects already passed in
|
|
3386
3647
|
* @return {string} The result from the parser
|
|
3387
|
-
*/},{key:"parseString",value:function parseString(pString,pData,fCallback,pDataContext){if(this.LogNoisiness>4){this.fable.log.trace("Metatemplate parsing template string [".concat(pString,"] where the callback is a ").concat(_typeof(fCallback)),{TemplateData:pData});}return this.StringParser.parseString(pString,this.ParseTree,pData,fCallback,pDataContext);}}]);return FableServiceMetaTemplate;}(libFableServiceBase);module.exports=FableServiceMetaTemplate;},{"./Fable-Service-MetaTemplate/MetaTemplate-StringParser.js":
|
|
3648
|
+
*/},{key:"parseString",value:function parseString(pString,pData,fCallback,pDataContext){if(this.LogNoisiness>4){this.fable.log.trace("Metatemplate parsing template string [".concat(pString,"] where the callback is a ").concat(_typeof(fCallback)),{TemplateData:pData});}return this.StringParser.parseString(pString,this.ParseTree,pData,fCallback,pDataContext);}}]);return FableServiceMetaTemplate;}(libFableServiceBase);module.exports=FableServiceMetaTemplate;},{"./Fable-Service-MetaTemplate/MetaTemplate-StringParser.js":146,"./Fable-Service-MetaTemplate/MetaTemplate-WordTree.js":147,"fable-serviceproviderbase":51}],146:[function(require,module,exports){/**
|
|
3388
3649
|
* String Parser
|
|
3389
3650
|
* @author Steven Velozo <steven@velozo.com>
|
|
3390
3651
|
* @description Parse a string, properly processing each matched token in the word tree.
|
|
@@ -3431,11 +3692,11 @@ pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.s
|
|
|
3431
3692
|
this.resetOutputBuffer(pParserState);}}// If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
|
|
3432
3693
|
if(!pParserState.PatternMatch){// This may be the start of a new pattern....
|
|
3433
3694
|
if(pParserState.ParseTree.hasOwnProperty(pCharacter)){// ... assign the root node as the matched node.
|
|
3434
|
-
this.resetOutputBuffer(pParserState);this.appendOutputBuffer(pCharacter,pParserState);pParserState.Pattern=pParserState.ParseTree[pCharacter];pParserState.PatternMatch=true;return true;}else{this.appendOutputBuffer(pCharacter,pParserState);}}return false;}},{key:"executePatternAsync",value:function executePatternAsync(pParserState,pData,fCallback,pDataContext){var
|
|
3695
|
+
this.resetOutputBuffer(pParserState);this.appendOutputBuffer(pCharacter,pParserState);pParserState.Pattern=pParserState.ParseTree[pCharacter];pParserState.PatternMatch=true;return true;}else{this.appendOutputBuffer(pCharacter,pParserState);}}return false;}},{key:"executePatternAsync",value:function executePatternAsync(pParserState,pData,fCallback,pDataContext){var _this34=this;// ... this is the end of a pattern, cut off the end tag and parse it.
|
|
3435
3696
|
// Trim the start and end tags off the output buffer now
|
|
3436
3697
|
if(pParserState.Pattern.isAsync&&!pParserState.Pattern.isBoth){// Run the function
|
|
3437
|
-
return pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){
|
|
3438
|
-
return pParserState.Pattern.ParseAsync(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){
|
|
3698
|
+
return pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){_this34.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this34.resetOutputBuffer(pParserState);return fCallback();},pDataContext);}else if(pParserState.Pattern.isAsync&&pParserState.Pattern.isBoth){// Run the function when both async and non async were provided with the pattern
|
|
3699
|
+
return pParserState.Pattern.ParseAsync(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){_this34.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this34.resetOutputBuffer(pParserState);return fCallback();},pDataContext);}else{// Run the t*mplate function
|
|
3439
3700
|
pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,pDataContext);this.resetOutputBuffer(pParserState);return fCallback();}}/**
|
|
3440
3701
|
* Parse a character in the buffer.
|
|
3441
3702
|
* @method parseCharacterAsync
|
|
@@ -3468,11 +3729,11 @@ return fCallback();}/**
|
|
|
3468
3729
|
* @param {Object} pData - The data to pass to the function as a second parameter
|
|
3469
3730
|
* @param {function} fCallback - The callback function to call when the parse is complete
|
|
3470
3731
|
* @param {array} pDataContext - The history of data objects/context already passed in
|
|
3471
|
-
*/},{key:"parseString",value:function parseString(pString,pParseTree,pData,fCallback,pDataContext){var
|
|
3732
|
+
*/},{key:"parseString",value:function parseString(pString,pParseTree,pData,fCallback,pDataContext){var _this35=this;// TODO: There is danger here if a template function attempts to functionally recurse and doesn't pass this in.
|
|
3472
3733
|
var tmpPreviousDataContext=Array.isArray(pDataContext)?pDataContext:[];var tmpDataContext=Array.from(tmpPreviousDataContext);tmpDataContext.push(pData);if(typeof fCallback!=='function'){var tmpParserState=this.newParserState(pParseTree);for(var i=0;i<pString.length;i++){// TODO: This is not fast.
|
|
3473
3734
|
this.parseCharacter(pString[i],tmpParserState,pData,tmpDataContext);}this.flushOutputBuffer(tmpParserState);return tmpParserState.Output;}else{// This is the async mode
|
|
3474
|
-
var _tmpParserState=this.newParserState(pParseTree);_tmpParserState.Asynchronous=true;var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');var _loop=function _loop(
|
|
3475
|
-
|
|
3735
|
+
var _tmpParserState=this.newParserState(pParseTree);_tmpParserState.Asynchronous=true;var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');var _loop=function _loop(_i26){tmpAnticipate.anticipate(function(fCallback){_this35.parseCharacterAsync(pString[_i26],_tmpParserState,pData,fCallback,tmpDataContext);});};for(var _i26=0;_i26<pString.length;_i26++){_loop(_i26);}tmpAnticipate.wait(function(pError){// Flush the remaining data
|
|
3736
|
+
_this35.flushOutputBuffer(_tmpParserState);return fCallback(pError,_tmpParserState.Output);});}}}]);return StringParser;}();module.exports=StringParser;},{}],147:[function(require,module,exports){/**
|
|
3476
3737
|
* Word Tree
|
|
3477
3738
|
* @author Steven Velozo <steven@velozo.com>
|
|
3478
3739
|
* @description Create a tree (directed graph) of Javascript objects, one character per object.
|
|
@@ -3499,7 +3760,7 @@ _this29.flushOutputBuffer(_tmpParserState);return fCallback(pError,_tmpParserSta
|
|
|
3499
3760
|
* @param {function} fParser - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
|
|
3500
3761
|
* @return {bool} True if adding the pattern was successful
|
|
3501
3762
|
*/},{key:"addPattern",value:function addPattern(pPatternStart,pPatternEnd,fParser){if(pPatternStart.length<1){return false;}if(typeof pPatternEnd==='string'&&pPatternEnd.length<1){return false;}var tmpLeaf=this.ParseTree;// Add the tree of leaves iteratively
|
|
3502
|
-
for(var i=0;i<pPatternStart.length;i++){tmpLeaf=this.addChild(tmpLeaf,pPatternStart[i],i);}if(!tmpLeaf.hasOwnProperty('PatternEnd')){tmpLeaf.PatternEnd={};}var tmpPatternEnd=typeof pPatternEnd==='string'?pPatternEnd:pPatternStart;for(var
|
|
3763
|
+
for(var i=0;i<pPatternStart.length;i++){tmpLeaf=this.addChild(tmpLeaf,pPatternStart[i],i);}if(!tmpLeaf.hasOwnProperty('PatternEnd')){tmpLeaf.PatternEnd={};}var tmpPatternEnd=typeof pPatternEnd==='string'?pPatternEnd:pPatternStart;for(var _i27=0;_i27<tmpPatternEnd.length;_i27++){tmpLeaf=this.addEndChild(tmpLeaf,tmpPatternEnd[_i27],_i27);}tmpLeaf.PatternStartString=pPatternStart;tmpLeaf.PatternEndString=tmpPatternEnd;tmpLeaf.Parse=typeof fParser==='function'?fParser:typeof fParser==='string'?function(){return fParser;}:function(pData){return pData;};return tmpLeaf;}/** Add a Pattern to the Parse Tree
|
|
3503
3764
|
* @method addPatternAsync
|
|
3504
3765
|
* @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
|
|
3505
3766
|
* @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
|
|
@@ -3512,13 +3773,13 @@ for(var i=0;i<pPatternStart.length;i++){tmpLeaf=this.addChild(tmpLeaf,pPatternSt
|
|
|
3512
3773
|
* @param {function} fParser - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
|
|
3513
3774
|
* @return {bool} True if adding the pattern was successful
|
|
3514
3775
|
*/},{key:"addPatternBoth",value:function addPatternBoth(pPatternStart,pPatternEnd,fParser,fParserAsync){var tmpLeaf=this.addPattern(pPatternStart,pPatternEnd,fParser);if(tmpLeaf){tmpLeaf.isAsync=true;tmpLeaf.isBoth=true;// When a leaf has both async and non-async versions of the functions, we store the async in fParserAsync.
|
|
3515
|
-
tmpLeaf.ParseAsync=fParserAsync;}}}]);return WordTree;}();module.exports=WordTree;},{}],
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
if(this.state.OverallProgressTracker.StartTimeStamp>0){return fExecutionCompleteCallback(new Error("Operation [".concat(this.state.Metadata.UUID,"] ").concat(this.state.Metadata.Name," has already been executed!")));}var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');this.progressTrackerSet.setProgressTrackerTotalOperations(this.state.OverallProgressTracker.Hash,this.state.Status.StepCount);this.progressTrackerSet.startProgressTracker(this.state.OverallProgressTracker.Hash);this.info("Operation [".concat(this.state.Metadata.UUID,"] ").concat(this.state.Metadata.Name," starting..."));var _loop2=function _loop2(i){tmpAnticipate.anticipate(function(fNext){this.fable.log.info("Step #".concat(i," [").concat(this.state.Steps[i].GUIDStep,"] ").concat(this.state.Steps[i].Name," starting..."));this.progressTrackerSet.startProgressTracker(this.state.Steps[i].ProgressTracker.Hash);return fNext();}.bind(
|
|
3520
|
-
tmpAnticipate.anticipate(
|
|
3521
|
-
tmpAnticipate.wait(function(pError){if(pError){
|
|
3776
|
+
tmpLeaf.ParseAsync=fParserAsync;}}}]);return WordTree;}();module.exports=WordTree;},{}],148:[function(require,module,exports){module.exports={"Metadata":{"UUID":false,"Hash":false,"Name":"","Summary":"","Version":0},"Status":{"Completed":false,"StepCount":0},"Steps":[],"Errors":[],"Log":[]};},{}],149:[function(require,module,exports){var _require4=require('big.js'),PE=_require4.PE;var libFableServiceBase=require('fable-serviceproviderbase');var _OperationStatePrototypeString=JSON.stringify(require('./Fable-Service-Operation-DefaultSettings.js'));var FableOperation=/*#__PURE__*/function(_libFableServiceBase8){_inherits(FableOperation,_libFableServiceBase8);function FableOperation(pFable,pOptions,pServiceHash){var _this36;_classCallCheck2(this,FableOperation);_this36=_callSuper(this,FableOperation,[pFable,pOptions,pServiceHash]);// Timestamps will just be the long ints
|
|
3777
|
+
_this36.timeStamps={};_this36.serviceType='PhasedOperation';_this36.state=JSON.parse(_OperationStatePrototypeString);_this36.stepMap={};_this36.stepFunctions={};// Match the service instantiation to the operation.
|
|
3778
|
+
_this36.state.Metadata.Hash=_this36.Hash;_this36.state.Metadata.UUID=_this36.UUID;_this36.state.Metadata.Name=typeof _this36.options.Name=='string'?_this36.options.Name:"Unnamed Operation ".concat(_this36.state.Metadata.UUID);_this36.name=_this36.state.Metadata.Name;_this36.progressTrackerSet=_this36.fable.instantiateServiceProviderWithoutRegistration('ProgressTrackerSet');_this36.state.OverallProgressTracker=_this36.progressTrackerSet.createProgressTracker("Overall-".concat(_this36.state.Metadata.UUID));// This is here to use the pass-through logging functions in the operation itself.
|
|
3779
|
+
_this36.log=_assertThisInitialized(_this36);return _this36;}_createClass2(FableOperation,[{key:"execute",value:function execute(fExecutionCompleteCallback){var _this37=this;// TODO: Should the same operation be allowed to execute more than one time?
|
|
3780
|
+
if(this.state.OverallProgressTracker.StartTimeStamp>0){return fExecutionCompleteCallback(new Error("Operation [".concat(this.state.Metadata.UUID,"] ").concat(this.state.Metadata.Name," has already been executed!")));}var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');this.progressTrackerSet.setProgressTrackerTotalOperations(this.state.OverallProgressTracker.Hash,this.state.Status.StepCount);this.progressTrackerSet.startProgressTracker(this.state.OverallProgressTracker.Hash);this.info("Operation [".concat(this.state.Metadata.UUID,"] ").concat(this.state.Metadata.Name," starting..."));var _loop2=function _loop2(i){tmpAnticipate.anticipate(function(fNext){this.fable.log.info("Step #".concat(i," [").concat(this.state.Steps[i].GUIDStep,"] ").concat(this.state.Steps[i].Name," starting..."));this.progressTrackerSet.startProgressTracker(this.state.Steps[i].ProgressTracker.Hash);return fNext();}.bind(_this37));// Steps are executed in a custom context with
|
|
3781
|
+
tmpAnticipate.anticipate(_this37.stepFunctions[_this37.state.Steps[i].GUIDStep].bind({log:_this37,fable:_this37.fable,options:_this37.state.Steps[i].Metadata,metadata:_this37.state.Steps[i].Metadata,ProgressTracker:_this37.progressTrackerSet.getProgressTracker(_this37.state.Steps[i].ProgressTracker.Hash),logProgressTrackerStatus:function(){return this.log.info("Step #".concat(i," [").concat(this.state.Steps[i].GUIDStep,"]: ").concat(this.progressTrackerSet.getProgressTrackerStatusString(this.state.Steps[i].ProgressTracker.Hash)));}.bind(_this37),OperationState:_this37.state,StepState:_this37.state.Steps[i]}));tmpAnticipate.anticipate(function(fNext){this.progressTrackerSet.endProgressTracker(this.state.Steps[i].ProgressTracker.Hash);var tmpStepTimingMessage=this.progressTrackerSet.getProgressTrackerStatusString(this.state.Steps[i].ProgressTracker.Hash);this.fable.log.info("Step #".concat(i," [").concat(this.state.Steps[i].GUIDStep,"] ").concat(this.state.Steps[i].Name," complete."));this.fable.log.info("Step #".concat(i," [").concat(this.state.Steps[i].GUIDStep,"] ").concat(this.state.Steps[i].Name," ").concat(tmpStepTimingMessage,"."));this.progressTrackerSet.incrementProgressTracker(this.state.OverallProgressTracker.Hash,1);var tmpOperationTimingMessage=this.progressTrackerSet.getProgressTrackerStatusString(this.state.OverallProgressTracker.Hash);this.fable.log.info("Operation [".concat(this.state.Metadata.UUID,"] ").concat(tmpOperationTimingMessage,"."));return fNext();}.bind(_this37));};for(var i=0;i<this.state.Steps.length;i++){_loop2(i);}// Wait for the anticipation to complete
|
|
3782
|
+
tmpAnticipate.wait(function(pError){if(pError){_this37.fable.log.error("Operation [".concat(_this37.state.Metadata.UUID,"] ").concat(_this37.state.Metadata.Name," had an error: ").concat(pError),pError);return fExecutionCompleteCallback(pError);}_this37.info("Operation [".concat(_this37.state.Metadata.UUID,"] ").concat(_this37.state.Metadata.Name," complete."));var tmpOperationTimingMessage=_this37.progressTrackerSet.getProgressTrackerStatusString(_this37.state.OverallProgressTracker.Hash);_this37.progressTrackerSet.endProgressTracker(_this37.state.OverallProgressTracker.Hash);_this37.fable.log.info("Operation [".concat(_this37.state.Metadata.UUID,"] ").concat(tmpOperationTimingMessage,"."));return fExecutionCompleteCallback();});}// There are three ways to add steps:
|
|
3522
3783
|
// 1. As a basic javascript function
|
|
3523
3784
|
// --
|
|
3524
3785
|
// This is the most basic, java"script" way to add a step. It will
|
|
@@ -3527,11 +3788,11 @@ tmpAnticipate.wait(function(pError){if(pError){_this31.fable.log.error("Operatio
|
|
|
3527
3788
|
},{key:"addStep",value:function addStep(fStepFunction,pStepMetadata,pStepName,pStepDescription,pGUIDStep){var tmpStep={};// GUID is optional
|
|
3528
3789
|
tmpStep.GUIDStep=typeof pGUIDStep!=='undefined'?pGUIDStep:"STEP-".concat(this.state.Steps.length,"-").concat(this.fable.DataGeneration.randomNumericString());// Name is optional
|
|
3529
3790
|
tmpStep.Name=typeof pStepName!=='undefined'?pStepName:"Step [".concat(tmpStep.GUIDStep,"]");tmpStep.Description=typeof pStepDescription!=='undefined'?pStepDescription:"Step execution of ".concat(tmpStep.Name,".");tmpStep.ProgressTracker=this.progressTrackerSet.createProgressTracker(tmpStep.GUIDStep);tmpStep.Metadata=_typeof(pStepMetadata)==='object'?pStepMetadata:{};// There is an array of steps, in the Operation State itself ... push a step there
|
|
3530
|
-
this.state.Steps.push(tmpStep);this.stepMap[tmpStep.GUIDStep]=tmpStep;this.stepFunctions[tmpStep.GUIDStep]=typeof fStepFunction=='function'?fStepFunction:function(fDone){return fDone();};this.state.Status.StepCount++;return tmpStep;}},{key:"setStepTotalOperations",value:function setStepTotalOperations(pGUIDStep,pTotalOperationCount){if(!this.stepMap.hasOwnProperty(pGUIDStep)){return new Error("Step [".concat(pGUIDStep,"] does not exist in operation [").concat(this.state.Metadata.UUID,"] ").concat(this.state.Metadata.Name," when attempting to set total operations to ").concat(pTotalOperationCount,"."));}this.progressTrackerSet.setProgressTrackerTotalOperations(this.stepMap[pGUIDStep].ProgressTracker.Hash,pTotalOperationCount);}},{key:"writeOperationLog",value:function writeOperationLog(pLogLevel,pLogText,pLogObject){this.state.Log.push("[".concat(new Date().toUTCString(),"]-[").concat(pLogLevel,"]: ").concat(pLogText));if(_typeof(pLogObject)=='object'){this.state.Log.push(JSON.stringify(pLogObject));}}},{key:"writeOperationErrors",value:function writeOperationErrors(pLogText,pLogObject){this.state.Errors.push("".concat(pLogText));if(_typeof(pLogObject)=='object'){this.state.Errors.push(JSON.stringify(pLogObject));}}},{key:"trace",value:function trace(pLogText,pLogObject){this.writeOperationLog('TRACE',pLogText,pLogObject);this.fable.log.trace(pLogText,pLogObject);}},{key:"debug",value:function debug(pLogText,pLogObject){this.writeOperationLog('DEBUG',pLogText,pLogObject);this.fable.log.debug(pLogText,pLogObject);}},{key:"info",value:function info(pLogText,pLogObject){this.writeOperationLog('INFO',pLogText,pLogObject);this.fable.log.info(pLogText,pLogObject);}},{key:"warn",value:function warn(pLogText,pLogObject){this.writeOperationLog('WARN',pLogText,pLogObject);this.fable.log.warn(pLogText,pLogObject);}},{key:"error",value:function error(pLogText,pLogObject){this.writeOperationLog('ERROR',pLogText,pLogObject);this.writeOperationErrors(pLogText,pLogObject);this.fable.log.error(pLogText,pLogObject);}},{key:"fatal",value:function fatal(pLogText,pLogObject){this.writeOperationLog('FATAL',pLogText,pLogObject);this.writeOperationErrors(pLogText,pLogObject);this.fable.log.fatal(pLogText,pLogObject);}}]);return FableOperation;}(libFableServiceBase);module.exports=FableOperation;},{"./Fable-Service-Operation-DefaultSettings.js":
|
|
3791
|
+
this.state.Steps.push(tmpStep);this.stepMap[tmpStep.GUIDStep]=tmpStep;this.stepFunctions[tmpStep.GUIDStep]=typeof fStepFunction=='function'?fStepFunction:function(fDone){return fDone();};this.state.Status.StepCount++;return tmpStep;}},{key:"setStepTotalOperations",value:function setStepTotalOperations(pGUIDStep,pTotalOperationCount){if(!this.stepMap.hasOwnProperty(pGUIDStep)){return new Error("Step [".concat(pGUIDStep,"] does not exist in operation [").concat(this.state.Metadata.UUID,"] ").concat(this.state.Metadata.Name," when attempting to set total operations to ").concat(pTotalOperationCount,"."));}this.progressTrackerSet.setProgressTrackerTotalOperations(this.stepMap[pGUIDStep].ProgressTracker.Hash,pTotalOperationCount);}},{key:"writeOperationLog",value:function writeOperationLog(pLogLevel,pLogText,pLogObject){this.state.Log.push("[".concat(new Date().toUTCString(),"]-[").concat(pLogLevel,"]: ").concat(pLogText));if(_typeof(pLogObject)=='object'){this.state.Log.push(JSON.stringify(pLogObject));}}},{key:"writeOperationErrors",value:function writeOperationErrors(pLogText,pLogObject){this.state.Errors.push("".concat(pLogText));if(_typeof(pLogObject)=='object'){this.state.Errors.push(JSON.stringify(pLogObject));}}},{key:"trace",value:function trace(pLogText,pLogObject){this.writeOperationLog('TRACE',pLogText,pLogObject);this.fable.log.trace(pLogText,pLogObject);}},{key:"debug",value:function debug(pLogText,pLogObject){this.writeOperationLog('DEBUG',pLogText,pLogObject);this.fable.log.debug(pLogText,pLogObject);}},{key:"info",value:function info(pLogText,pLogObject){this.writeOperationLog('INFO',pLogText,pLogObject);this.fable.log.info(pLogText,pLogObject);}},{key:"warn",value:function warn(pLogText,pLogObject){this.writeOperationLog('WARN',pLogText,pLogObject);this.fable.log.warn(pLogText,pLogObject);}},{key:"error",value:function error(pLogText,pLogObject){this.writeOperationLog('ERROR',pLogText,pLogObject);this.writeOperationErrors(pLogText,pLogObject);this.fable.log.error(pLogText,pLogObject);}},{key:"fatal",value:function fatal(pLogText,pLogObject){this.writeOperationLog('FATAL',pLogText,pLogObject);this.writeOperationErrors(pLogText,pLogObject);this.fable.log.fatal(pLogText,pLogObject);}}]);return FableOperation;}(libFableServiceBase);module.exports=FableOperation;},{"./Fable-Service-Operation-DefaultSettings.js":148,"big.js":17,"fable-serviceproviderbase":51}],150:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');var FableServiceProgressTime=/*#__PURE__*/function(_libFableServiceBase9){_inherits(FableServiceProgressTime,_libFableServiceBase9);function FableServiceProgressTime(pFable,pOptions,pServiceHash){var _this38;_classCallCheck2(this,FableServiceProgressTime);_this38=_callSuper(this,FableServiceProgressTime,[pFable,pOptions,pServiceHash]);_this38.serviceType='ProgressTime';_this38.timeStamps={};return _this38;}_createClass2(FableServiceProgressTime,[{key:"formatTimeDuration",value:function formatTimeDuration(pTimeDurationInMilliseconds){var tmpTimeDuration=typeof pTimeDurationInMilliseconds=='number'?pTimeDurationInMilliseconds:0;if(pTimeDurationInMilliseconds<0){return'unknown';}var tmpTimeDurationString='';if(tmpTimeDuration>3600000){tmpTimeDurationString+=Math.floor(tmpTimeDuration/3600000)+'h ';tmpTimeDuration=tmpTimeDuration%3600000;}if(tmpTimeDuration>60000){tmpTimeDurationString+=Math.floor(tmpTimeDuration/60000)+'m ';tmpTimeDuration=tmpTimeDuration%60000;}if(tmpTimeDuration>1000){tmpTimeDurationString+=Math.floor(tmpTimeDuration/1000)+'s ';tmpTimeDuration=tmpTimeDuration%1000;}tmpTimeDurationString+=Math.round(tmpTimeDuration)+'ms';return tmpTimeDurationString;}},{key:"createTimeStamp",value:function createTimeStamp(pTimeStampHash){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';this.timeStamps[tmpTimeStampHash]=+new Date();return this.timeStamps[tmpTimeStampHash];}},{key:"getTimeStampValue",value:function getTimeStampValue(pTimeStampHash){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';return this.timeStamps.hasOwnProperty(tmpTimeStampHash)?this.timeStamps[tmpTimeStampHash]:-1;}},{key:"updateTimeStampValue",value:function updateTimeStampValue(pTimeStampHash,pReferenceTime){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';var tmpReferenceTime=false;// This function allows the user to pass in either a reference time in ms, or, a hash of a timestamp.
|
|
3531
3792
|
if(typeof pReferenceTime=='string'){tmpReferenceTime=this.timeStamps.hasOwnProperty(tmpReference)?this.timeStamps[tmpReference]:false;}else if(typeof pReferenceTime=='number'){tmpReferenceTime=pReferenceTime;}else{tmpReferenceTime=+new Date();}if(this.timeStamps.hasOwnProperty(tmpTimeStampHash)&&tmpReferenceTime){this.timeStamps[tmpTimeStampHash]=tmpReferenceTime;return this.timeStamps[tmpTimeStampHash];}else{return-1;}}},{key:"removeTimeStamp",value:function removeTimeStamp(pTimeStampHash){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';if(this.timeStamps.hasOwnProperty(tmpTimeStampHash)){delete this.timeStamps[tmpTimeStampHash];return true;}else{return false;}}},{key:"getTimeStampDelta",value:function getTimeStampDelta(pTimeStampHash,pReferenceTime){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';var tmpReferenceTime=false;// This function allows the user to pass in either a reference time in ms, or, a hash of a timestamp.
|
|
3532
|
-
if(typeof pReferenceTime=='string'){tmpReferenceTime=this.timeStamps.hasOwnProperty(tmpReference)?this.timeStamps[tmpReference]:false;}else if(typeof pReferenceTime=='number'){tmpReferenceTime=pReferenceTime;}else{tmpReferenceTime=+new Date();}if(this.timeStamps.hasOwnProperty(tmpTimeStampHash)&&tmpReferenceTime){return tmpReferenceTime-this.timeStamps[tmpTimeStampHash];}else{return-1;}}},{key:"getDurationBetweenTimestamps",value:function getDurationBetweenTimestamps(pTimeStampHashStart,pTimeStampHashEnd){var tmpTimeStampHashStart=typeof pTimeStampHashStart=='string'?pTimeStampHashStart:'Default';var tmpTimeStampHashEnd=typeof pTimeStampHashEnd=='string'?pTimeStampHashEnd:'Default';if(this.timeStamps.hasOwnProperty(tmpTimeStampHashStart)&&this.timeStamps.hasOwnProperty(tmpTimeStampHashEnd)){return this.timeStamps[tmpTimeStampHashEnd]-this.timeStamps[tmpTimeStampHashStart];}else{return-1;}}},{key:"getTimeStampDeltaMessage",value:function getTimeStampDeltaMessage(pTimeStampHash,pMessage,pReferenceTime){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';var tmpMessage=typeof pMessage!=='undefined'?pMessage:"Elapsed for ".concat(tmpTimeStampHash,": ");var tmpOperationTime=this.getTimeStampDelta(tmpTimeStampHash,pReferenceTime);return"".concat(tmpMessage," ").concat(this.formatTimeDuration(tmpOperationTime));}},{key:"logTimeStampDelta",value:function logTimeStampDelta(pTimeStampHash,pMessage,pReferenceTime){this.fable.log.info(this.getTimeStampDeltaMessage(pTimeStampHash,pMessage,pReferenceTime));}}]);return FableServiceProgressTime;}(libFableServiceBase);module.exports=FableServiceProgressTime;},{"fable-serviceproviderbase":51}],
|
|
3533
|
-
|
|
3534
|
-
|
|
3793
|
+
if(typeof pReferenceTime=='string'){tmpReferenceTime=this.timeStamps.hasOwnProperty(tmpReference)?this.timeStamps[tmpReference]:false;}else if(typeof pReferenceTime=='number'){tmpReferenceTime=pReferenceTime;}else{tmpReferenceTime=+new Date();}if(this.timeStamps.hasOwnProperty(tmpTimeStampHash)&&tmpReferenceTime){return tmpReferenceTime-this.timeStamps[tmpTimeStampHash];}else{return-1;}}},{key:"getDurationBetweenTimestamps",value:function getDurationBetweenTimestamps(pTimeStampHashStart,pTimeStampHashEnd){var tmpTimeStampHashStart=typeof pTimeStampHashStart=='string'?pTimeStampHashStart:'Default';var tmpTimeStampHashEnd=typeof pTimeStampHashEnd=='string'?pTimeStampHashEnd:'Default';if(this.timeStamps.hasOwnProperty(tmpTimeStampHashStart)&&this.timeStamps.hasOwnProperty(tmpTimeStampHashEnd)){return this.timeStamps[tmpTimeStampHashEnd]-this.timeStamps[tmpTimeStampHashStart];}else{return-1;}}},{key:"getTimeStampDeltaMessage",value:function getTimeStampDeltaMessage(pTimeStampHash,pMessage,pReferenceTime){var tmpTimeStampHash=typeof pTimeStampHash=='string'?pTimeStampHash:'Default';var tmpMessage=typeof pMessage!=='undefined'?pMessage:"Elapsed for ".concat(tmpTimeStampHash,": ");var tmpOperationTime=this.getTimeStampDelta(tmpTimeStampHash,pReferenceTime);return"".concat(tmpMessage," ").concat(this.formatTimeDuration(tmpOperationTime));}},{key:"logTimeStampDelta",value:function logTimeStampDelta(pTimeStampHash,pMessage,pReferenceTime){this.fable.log.info(this.getTimeStampDeltaMessage(pTimeStampHash,pMessage,pReferenceTime));}}]);return FableServiceProgressTime;}(libFableServiceBase);module.exports=FableServiceProgressTime;},{"fable-serviceproviderbase":51}],151:[function(require,module,exports){var ProgressTracker=/*#__PURE__*/function(){function ProgressTracker(pProgressTrackerSet,pProgressTrackerHash){_classCallCheck2(this,ProgressTracker);this.progressTrackerSet=pProgressTrackerSet;this.progressTrackerHash=pProgressTrackerHash;this.data=this.progressTrackerSet.getProgressTrackerData(this.progressTrackerHash);}_createClass2(ProgressTracker,[{key:"updateProgressTracker",value:function updateProgressTracker(pProgressAmount){return this.progressTrackerSet.updateProgressTracker(this.progressTrackerHash,pProgressAmount);}},{key:"incrementProgressTracker",value:function incrementProgressTracker(pProgressIncrementAmount){return this.progressTrackerSet.incrementProgressTracker(this.progressTrackerHash,pProgressIncrementAmount);}},{key:"setProgressTrackerTotalOperations",value:function setProgressTrackerTotalOperations(pTotalOperationCount){return this.progressTrackerSet.setProgressTrackerTotalOperations(this.progressTrackerHash,pTotalOperationCount);}},{key:"getProgressTrackerStatusString",value:function getProgressTrackerStatusString(){return this.progressTrackerSet.getProgressTrackerStatusString(this.progressTrackerHash);}}]);return ProgressTracker;}();module.exports=ProgressTracker;},{}],152:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');var libProgressTrackerClass=require('./Fable-Service-ProgressTracker/ProgressTracker.js');var FableServiceProgressTrackerSet=/*#__PURE__*/function(_libFableServiceBase10){_inherits(FableServiceProgressTrackerSet,_libFableServiceBase10);function FableServiceProgressTrackerSet(pFable,pOptions,pServiceHash){var _this39;_classCallCheck2(this,FableServiceProgressTrackerSet);_this39=_callSuper(this,FableServiceProgressTrackerSet,[pFable,pOptions,pServiceHash]);_this39.serviceType='ProgressTrackerSet';_this39.progressTrackers={};// Create an internal PorgressTime service to track timestamps
|
|
3794
|
+
_this39.progressTimes=_this39.fable.instantiateServiceProviderWithoutRegistration('ProgressTime');// This timestamp is used and updated by *all* progress trackers.
|
|
3795
|
+
_this39.progressTimes.createTimeStamp('CurrentTime');return _this39;}_createClass2(FableServiceProgressTrackerSet,[{key:"getProgressTracker",value:function getProgressTracker(pProgressTrackerHash){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';if(!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.fable.log.warn("ProgressTracker ".concat(tmpProgressTrackerHash," does not exist! Creating a new tracker..."));this.createProgressTracker(tmpProgressTrackerHash,100);}return new libProgressTrackerClass(this,pProgressTrackerHash);}},{key:"getProgressTrackerData",value:function getProgressTrackerData(pProgressTrackerHash){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';if(!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.fable.log.warn("ProgressTracker ".concat(tmpProgressTrackerHash," does not exist! Creating a new tracker..."));this.createProgressTracker(tmpProgressTrackerHash,100);}return this.progressTrackers[tmpProgressTrackerHash];}},{key:"createProgressTracker",value:function createProgressTracker(pProgressTrackerHash,pTotalOperations){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';var tmpTotalOperations=typeof pTotalOperations=='number'?pTotalOperations:100;var tmpProgressTracker={Hash:tmpProgressTrackerHash,StartTimeHash:"".concat(tmpProgressTrackerHash,"-Start"),StartTimeStamp:-1,CurrentTimeStamp:-1,EndTimeHash:"".concat(tmpProgressTrackerHash,"-End"),EndTimeStamp:-1,PercentComplete:-1,// If this is set to true, PercentComplete will be calculated as CurrentCount / TotalCount even if it goes over 100%
|
|
3535
3796
|
AllowTruePercentComplete:false,ElapsedTime:-1,AverageOperationTime:-1,EstimatedCompletionTime:-1,TotalCount:tmpTotalOperations,CurrentCount:-1};if(this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.fable.log.warn("ProgressTracker ".concat(tmpProgressTrackerHash," already exists! Overwriting with a new tracker..."));this.progressTimes.removeTimeStamp(tmpProgressTracker.StartTimeHash);this.progressTimes.removeTimeStamp(tmpProgressTracker.EndTimeHash);}this.progressTrackers[tmpProgressTrackerHash]=tmpProgressTracker;return tmpProgressTracker;}},{key:"setProgressTrackerTotalOperations",value:function setProgressTrackerTotalOperations(pProgressTrackerHash,pTotalOperations){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';var tmpTotalOperations=typeof pTotalOperations=='number'?pTotalOperations:100;if(!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.fable.log.warn("Attempted to set the total operations of ProgressTracker ".concat(tmpProgressTrackerHash," but it does not exist! Creating a new tracker..."));this.createProgressTracker(tmpProgressTrackerHash,tmpTotalOperations);}this.progressTrackers[tmpProgressTrackerHash].TotalCount=tmpTotalOperations;return this.progressTrackers[tmpProgressTrackerHash];}},{key:"startProgressTracker",value:function startProgressTracker(pProgressTrackerHash){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';// This is the only method to lazily create ProgressTrackers now
|
|
3536
3797
|
if(!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.createProgressTracker(tmpProgressTrackerHash,100);}var tmpProgressTracker=this.progressTrackers[tmpProgressTrackerHash];this.progressTimes.createTimeStamp(this.progressTrackers[tmpProgressTrackerHash].StartTimeHash);tmpProgressTracker.StartTimeStamp=this.progressTimes.getTimeStampValue(this.progressTrackers[tmpProgressTrackerHash].StartTimeHash);if(tmpProgressTracker.CurrentCount<0){tmpProgressTracker.CurrentCount=0;}return this.solveProgressTrackerStatus(tmpProgressTrackerHash);}},{key:"endProgressTracker",value:function endProgressTracker(pProgressTrackerHash){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';if(!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.fable.log.error("Attempted to end ProgressTracker ".concat(tmpProgressTrackerHash," that does not exist!"));return false;}var tmpProgressTracker=this.progressTrackers[tmpProgressTrackerHash];this.progressTimes.createTimeStamp(this.progressTrackers[tmpProgressTrackerHash].EndTimeHash);tmpProgressTracker.EndTimeStamp=this.progressTimes.getTimeStampValue(this.progressTrackers[tmpProgressTrackerHash].EndTimeHash);return this.solveProgressTrackerStatus(tmpProgressTrackerHash);}},{key:"solveProgressTrackerStatus",value:function solveProgressTrackerStatus(pProgressTrackerHash){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';if(!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash)){this.fable.log.error("Attempted to solve ProgressTracker ".concat(tmpProgressTrackerHash," that does not exist!"));return false;}var tmpProgressTracker=this.progressTrackers[tmpProgressTrackerHash];if(tmpProgressTracker.TotalCount<1||isNaN(tmpProgressTracker.TotalCount)){this.fable.log.error("ProgressTracker ".concat(tmpProgressTracker.Hash," has an invalid total count of operations (").concat(tmpProgressTracker.TotalCount,"! Setting it to the default of 100..."));tmpProgressTracker.TotalCount=100;}// Compute the percentage of progress that is complete.
|
|
3537
3798
|
if(tmpProgressTracker.CurrentCount<1){tmpProgressTracker.PercentComplete=0;}else{tmpProgressTracker.PercentComplete=tmpProgressTracker.CurrentCount/tmpProgressTracker.TotalCount*100.0;}if(!tmpProgressTracker.AllowTruePercentComplete&&tmpProgressTracker.PercentComplete>100){tmpProgressTracker.PercentComplete=100;}// Compute the average time per operation
|
|
@@ -3552,20 +3813,20 @@ this.solveProgressTrackerStatus(tmpProgressTrackerHash);if(!this.progressTracker
|
|
|
3552
3813
|
if(tmpProgressTracker.StartTimeStamp<1){return"ProgressTracker ".concat(tmpProgressTracker.Hash," has not been started yet.");}// 2. Started, but no operations completed
|
|
3553
3814
|
if(tmpProgressTracker.CurrentCount<1&&tmpProgressTracker.EndTimeStamp<1){return"ProgressTracker ".concat(tmpProgressTracker.Hash," has no completed operations. ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.ElapsedTime)," have elapsed since it was started.");}// 3. Started, some operations completed
|
|
3554
3815
|
else if(tmpProgressTracker.EndTimeStamp<1){return"ProgressTracker ".concat(tmpProgressTracker.Hash," is ").concat(tmpProgressTracker.PercentComplete.toFixed(3),"% completed - ").concat(tmpProgressTracker.CurrentCount," / ").concat(tmpProgressTracker.TotalCount," operations over ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.ElapsedTime)," (median ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.AverageOperationTime)," per). Estimated completion: ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.EstimatedCompletionTime));}// 4. Done
|
|
3555
|
-
else{return"ProgressTracker ".concat(tmpProgressTracker.Hash," is done. ").concat(tmpProgressTracker.CurrentCount," / ").concat(tmpProgressTracker.TotalCount," operations were completed in ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.ElapsedTime)," (median ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.AverageOperationTime)," per).");}}}},{key:"logProgressTrackerStatus",value:function logProgressTrackerStatus(pProgressTrackerHash){this.fable.log.info(this.getProgressTrackerStatusString(pProgressTrackerHash));}}]);return FableServiceProgressTrackerSet;}(libFableServiceBase);module.exports=FableServiceProgressTrackerSet;},{"./Fable-Service-ProgressTracker/ProgressTracker.js":
|
|
3816
|
+
else{return"ProgressTracker ".concat(tmpProgressTracker.Hash," is done. ").concat(tmpProgressTracker.CurrentCount," / ").concat(tmpProgressTracker.TotalCount," operations were completed in ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.ElapsedTime)," (median ").concat(this.progressTimes.formatTimeDuration(tmpProgressTracker.AverageOperationTime)," per).");}}}},{key:"logProgressTrackerStatus",value:function logProgressTrackerStatus(pProgressTrackerHash){this.fable.log.info(this.getProgressTrackerStatusString(pProgressTrackerHash));}}]);return FableServiceProgressTrackerSet;}(libFableServiceBase);module.exports=FableServiceProgressTrackerSet;},{"./Fable-Service-ProgressTracker/ProgressTracker.js":151,"fable-serviceproviderbase":51}],153:[function(require,module,exports){(function(Buffer){(function(){var libFableServiceBase=require('fable-serviceproviderbase');var libSimpleGet=require('simple-get');var libCookie=require('cookie');var FableServiceRestClient=/*#__PURE__*/function(_libFableServiceBase11){_inherits(FableServiceRestClient,_libFableServiceBase11);function FableServiceRestClient(pFable,pOptions,pServiceHash){var _this40;_classCallCheck2(this,FableServiceRestClient);_this40=_callSuper(this,FableServiceRestClient,[pFable,pOptions,pServiceHash]);_this40.TraceLog=false;if(_this40.options.TraceLog||_this40.fable.TraceLog){_this40.TraceLog=true;}_this40.dataFormat=_this40.fable.services.DataFormat;_this40.serviceType='RestClient';_this40.cookie=false;// This is a function that can be overridden, to allow the management
|
|
3556
3817
|
// of the request options before they are passed to the request library.
|
|
3557
|
-
|
|
3818
|
+
_this40.prepareRequestOptions=function(pOptions){return pOptions;};return _this40;}_createClass2(FableServiceRestClient,[{key:"simpleGet",get:function get(){return libSimpleGet;}},{key:"prepareCookies",value:function prepareCookies(pRequestOptions){if(this.cookie){var tmpCookieObject=this.cookie;if(!pRequestOptions.hasOwnProperty('headers')){pRequestOptions.headers={};}var tmpCookieKeys=Object.keys(tmpCookieObject);if(tmpCookieKeys.length>0){// Only grab the first for now.
|
|
3558
3819
|
pRequestOptions.headers.cookie=libCookie.serialize(tmpCookieKeys[0],tmpCookieObject[tmpCookieKeys[0]]);}}return pRequestOptions;}},{key:"preRequest",value:function preRequest(pOptions){// Validate the options object
|
|
3559
3820
|
var tmpOptions=this.prepareCookies(pOptions);// Prepend a string to the URL if it exists in the Fable Config
|
|
3560
|
-
if(this.fable.settings.hasOwnProperty('RestClientURLPrefix')){tmpOptions.url=this.fable.settings.RestClientURLPrefix+tmpOptions.url;}return this.prepareRequestOptions(tmpOptions);}},{key:"executeChunkedRequest",value:function executeChunkedRequest(pOptions,fCallback){var
|
|
3561
|
-
if(
|
|
3562
|
-
if(
|
|
3563
|
-
if(!tmpDataBuffer){tmpDataBuffer=Buffer.from(pChunk);}else{tmpDataBuffer=Buffer.concat([tmpDataBuffer,pChunk]);}});pResponse.on('end',function(){if(
|
|
3821
|
+
if(this.fable.settings.hasOwnProperty('RestClientURLPrefix')){tmpOptions.url=this.fable.settings.RestClientURLPrefix+tmpOptions.url;}return this.prepareRequestOptions(tmpOptions);}},{key:"executeChunkedRequest",value:function executeChunkedRequest(pOptions,fCallback){var _this41=this;var tmpOptions=this.preRequest(pOptions);tmpOptions.RequestStartTime=this.fable.log.getTimeStamp();if(this.TraceLog){this.fable.log.debug("Beginning ".concat(tmpOptions.method," request to ").concat(tmpOptions.url," at ").concat(tmpOptions.RequestStartTime));}return libSimpleGet(tmpOptions,function(pError,pResponse){if(pError){return fCallback(pError,pResponse);}if(_this41.TraceLog){var tmpConnectTime=_this41.fable.log.getTimeStamp();_this41.fable.log.debug("--> ".concat(tmpOptions.method," connected in ").concat(_this41.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpConnectTime),"ms code ").concat(pResponse.statusCode));}var tmpData='';pResponse.on('data',function(pChunk){// For JSON, the chunk is the serialized object.
|
|
3822
|
+
if(_this41.TraceLog){var tmpChunkTime=_this41.fable.log.getTimeStamp();_this41.fable.log.debug("--> ".concat(tmpOptions.method," data chunk size ").concat(pChunk.length,"b received in ").concat(_this41.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpChunkTime),"ms"));}tmpData+=pChunk;});pResponse.on('end',function(){if(_this41.TraceLog){var tmpCompletionTime=_this41.fable.log.getTimeStamp();_this41.fable.log.debug("==> ".concat(tmpOptions.method," completed data size ").concat(tmpData.length,"b received in ").concat(_this41.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpCompletionTime),"ms"));}return fCallback(pError,pResponse,tmpData);});});}},{key:"executeChunkedRequestBinary",value:function executeChunkedRequestBinary(pOptions,fCallback){var _this42=this;var tmpOptions=this.preRequest(pOptions);tmpOptions.RequestStartTime=this.fable.log.getTimeStamp();if(this.TraceLog){this.fable.log.debug("Beginning ".concat(tmpOptions.method," request to ").concat(tmpOptions.url," at ").concat(tmpOptions.RequestStartTime));}tmpOptions.json=false;tmpOptions.encoding=null;return libSimpleGet(tmpOptions,function(pError,pResponse){if(pError){return fCallback(pError,pResponse);}if(_this42.TraceLog){var tmpConnectTime=_this42.fable.log.getTimeStamp();_this42.fable.log.debug("--> ".concat(tmpOptions.method," connected in ").concat(_this42.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpConnectTime),"ms code ").concat(pResponse.statusCode));}var tmpDataBuffer=false;pResponse.on('data',function(pChunk){// For JSON, the chunk is the serialized object.
|
|
3823
|
+
if(_this42.TraceLog){var tmpChunkTime=_this42.fable.log.getTimeStamp();_this42.fable.log.debug("--> ".concat(tmpOptions.method," data chunk size ").concat(pChunk.length,"b received in ").concat(_this42.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpChunkTime),"ms"));}// TODO: Potentially create a third option that streams this to a file? So it doesn't have to hold it all in memory.
|
|
3824
|
+
if(!tmpDataBuffer){tmpDataBuffer=Buffer.from(pChunk);}else{tmpDataBuffer=Buffer.concat([tmpDataBuffer,pChunk]);}});pResponse.on('end',function(){if(_this42.TraceLog){var tmpCompletionTime=_this42.fable.log.getTimeStamp();_this42.fable.log.debug("==> ".concat(tmpOptions.method," completed data size ").concat(tmpDataBuffer.length,"b received in ").concat(_this42.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpCompletionTime),"ms"));}return fCallback(pError,pResponse,tmpDataBuffer);});});}},{key:"executeJSONRequest",value:function executeJSONRequest(pOptions,fCallback){var _this43=this;pOptions.json=true;var tmpOptions=this.preRequest(pOptions);if(!tmpOptions.hasOwnProperty('headers')){tmpOptions.headers={};}/* Automated headers break some APIs
|
|
3564
3825
|
if (!tmpOptions.headers.hasOwnProperty('Content-Type'))
|
|
3565
3826
|
{
|
|
3566
3827
|
tmpOptions.headers['Content-Type'] = 'application/json';
|
|
3567
3828
|
}
|
|
3568
|
-
*/tmpOptions.RequestStartTime=this.fable.log.getTimeStamp();if(this.TraceLog){this.fable.log.debug("Beginning ".concat(tmpOptions.method," JSON request to ").concat(tmpOptions.url," at ").concat(tmpOptions.RequestStartTime));}return libSimpleGet(tmpOptions,function(pError,pResponse){if(pError){return fCallback(pError,pResponse);}if(
|
|
3829
|
+
*/tmpOptions.RequestStartTime=this.fable.log.getTimeStamp();if(this.TraceLog){this.fable.log.debug("Beginning ".concat(tmpOptions.method," JSON request to ").concat(tmpOptions.url," at ").concat(tmpOptions.RequestStartTime));}return libSimpleGet(tmpOptions,function(pError,pResponse){if(pError){return fCallback(pError,pResponse);}if(_this43.TraceLog){var tmpConnectTime=_this43.fable.log.getTimeStamp();_this43.fable.log.debug("--> JSON ".concat(tmpOptions.method," connected in ").concat(_this43.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpConnectTime),"ms code ").concat(pResponse.statusCode));}var tmpJSONData='';pResponse.on('data',function(pChunk){if(_this43.TraceLog){var tmpChunkTime=_this43.fable.log.getTimeStamp();_this43.fable.log.debug("--> JSON ".concat(tmpOptions.method," data chunk size ").concat(pChunk.length,"b received in ").concat(_this43.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpChunkTime),"ms"));}tmpJSONData+=pChunk;});pResponse.on('end',function(){if(_this43.TraceLog){var tmpCompletionTime=_this43.fable.log.getTimeStamp();_this43.fable.log.debug("==> JSON ".concat(tmpOptions.method," completed - received in ").concat(_this43.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpCompletionTime),"ms"));}return fCallback(pError,pResponse,JSON.parse(tmpJSONData));});});}},{key:"getJSON",value:function getJSON(pOptionsOrURL,fCallback){var tmpRequestOptions=_typeof(pOptionsOrURL)=='object'?pOptionsOrURL:{};if(typeof pOptionsOrURL=='string'){tmpRequestOptions.url=pOptionsOrURL;}tmpRequestOptions.method='GET';return this.executeJSONRequest(tmpRequestOptions,fCallback);}},{key:"putJSON",value:function putJSON(pOptions,fCallback){if(_typeof(pOptions.body)!='object'){return fCallback(new Error("PUT JSON Error Invalid options object"));}pOptions.method='PUT';return this.executeJSONRequest(pOptions,fCallback);}},{key:"postJSON",value:function postJSON(pOptions,fCallback){if(_typeof(pOptions.body)!='object'){return fCallback(new Error("POST JSON Error Invalid options object"));}pOptions.method='POST';return this.executeJSONRequest(pOptions,fCallback);}},{key:"patchJSON",value:function patchJSON(pOptions,fCallback){if(_typeof(pOptions.body)!='object'){return fCallback(new Error("PATCH JSON Error Invalid options object"));}pOptions.method='PATCH';return this.executeJSONRequest(pOptions,fCallback);}},{key:"headJSON",value:function headJSON(pOptions,fCallback){if(_typeof(pOptions.body)!='object'){return fCallback(new Error("HEAD JSON Error Invalid options object"));}pOptions.method='HEAD';return this.executeJSONRequest(pOptions,fCallback);}},{key:"delJSON",value:function delJSON(pOptions,fCallback){pOptions.method='DELETE';return this.executeJSONRequest(pOptions,fCallback);}},{key:"getRawText",value:function getRawText(pOptionsOrURL,fCallback){var tmpRequestOptions=_typeof(pOptionsOrURL)=='object'?pOptionsOrURL:{};if(typeof pOptionsOrURL=='string'){tmpRequestOptions.url=pOptionsOrURL;}tmpRequestOptions.method='GET';return this.executeChunkedRequest(tmpRequestOptions,fCallback);}}]);return FableServiceRestClient;}(libFableServiceBase);module.exports=FableServiceRestClient;}).call(this);}).call(this,require("buffer").Buffer);},{"buffer":20,"cookie":27,"fable-serviceproviderbase":51,"simple-get":101}],154:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');var FableServiceTemplate=/*#__PURE__*/function(_libFableServiceBase12){_inherits(FableServiceTemplate,_libFableServiceBase12);// Underscore and lodash have a behavior, _.template, which compiles a
|
|
3569
3830
|
// string-based template with code snippets into simple executable pieces,
|
|
3570
3831
|
// with the added twist of returning a precompiled function ready to go.
|
|
3571
3832
|
//
|
|
@@ -3574,19 +3835,19 @@ if(!tmpDataBuffer){tmpDataBuffer=Buffer.from(pChunk);}else{tmpDataBuffer=Buffer.
|
|
|
3574
3835
|
//
|
|
3575
3836
|
// This is an implementation of that.
|
|
3576
3837
|
// TODO: Make this use precedent, add configuration, add debugging.
|
|
3577
|
-
function FableServiceTemplate(pFable,pOptions,pServiceHash){var
|
|
3838
|
+
function FableServiceTemplate(pFable,pOptions,pServiceHash){var _this44;_classCallCheck2(this,FableServiceTemplate);_this44=_callSuper(this,FableServiceTemplate,[pFable,pOptions,pServiceHash]);_this44.serviceType='Template';// These are the exact regex's used in lodash/underscore
|
|
3578
3839
|
// TODO: Switch this to precedent
|
|
3579
|
-
|
|
3840
|
+
_this44.Matchers={Evaluate:/<%([\s\S]+?)%>/g,Interpolate:/<%=([\s\S]+?)%>/g,Escaper:/\\|'|\r|\n|\t|\u2028|\u2029/g,Unescaper:/\\(\\|'|r|n|t|u2028|u2029)/g,// This is how underscore does it, so we are keeping it for now.
|
|
3580
3841
|
GuaranteedNonMatch:/.^/};// This is a helper for the escaper and unescaper functions.
|
|
3581
3842
|
// Right now we are going to keep what underscore is doing, but, not forever.
|
|
3582
|
-
|
|
3843
|
+
_this44.templateEscapes={'\\':'\\',"'":"'",'r':'\r','\r':'r','n':'\n','\n':'n','t':'\t','\t':'t','u2028':"\u2028","\u2028":'u2028','u2029':"\u2029","\u2029":'u2029'};// This is defined as such to underscore that it is a dynamic programming
|
|
3583
3844
|
// function on this class.
|
|
3584
|
-
|
|
3845
|
+
_this44.renderFunction=false;_this44.templateString=false;return _this44;}_createClass2(FableServiceTemplate,[{key:"renderTemplate",value:function renderTemplate(pData){return this.renderFunction(pData);}},{key:"templateFunction",value:function templateFunction(){var fRenderTemplateBound=this.renderTemplate.bind(this);return fRenderTemplateBound;}},{key:"buildTemplateFunction",value:function buildTemplateFunction(pTemplateText,pData){var _this45=this;// For now this is being kept in a weird form ... this is to mimic the old
|
|
3585
3846
|
// underscore code until this is rewritten using precedent.
|
|
3586
|
-
this.TemplateSource="__p+='"+pTemplateText.replace(this.Matchers.Escaper,function(pMatch){return"\\".concat(
|
|
3847
|
+
this.TemplateSource="__p+='"+pTemplateText.replace(this.Matchers.Escaper,function(pMatch){return"\\".concat(_this45.templateEscapes[pMatch]);}).replace(this.Matchers.Interpolate||this.Matchers.GuaranteedNonMatch,function(pMatch,pCode){return"'+\n(".concat(decodeURIComponent(pCode),")+\n'");}).replace(this.Matchers.Evaluate||this.Matchers.GuaranteedNonMatch,function(pMatch,pCode){return"';\n".concat(decodeURIComponent(pCode),"\n;__p+='");})+"';\n";this.TemplateSource="with(pTemplateDataObject||{}){\n".concat(this.TemplateSource,"}\n");this.TemplateSource="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n".concat(this.TemplateSource,"return __p;\n");this.renderFunction=new Function('pTemplateDataObject',this.TemplateSource);if(typeof pData!='undefined'){return this.renderFunction(pData);}// Provide the compiled function source as a convenience for build time
|
|
3587
3848
|
// precompilation.
|
|
3588
|
-
this.TemplateSourceCompiled='function(obj){\n'+this.TemplateSource+'}';return this.templateFunction();}}]);return FableServiceTemplate;}(libFableServiceBase);module.exports=FableServiceTemplate;},{"fable-serviceproviderbase":51}],
|
|
3589
|
-
var libAsyncWaterfall=require('async.waterfall');var libAsyncEachLimit=require('async.eachlimit');var libBigNumber=require('big.js');var FableServiceUtility=/*#__PURE__*/function(
|
|
3849
|
+
this.TemplateSourceCompiled='function(obj){\n'+this.TemplateSource+'}';return this.templateFunction();}}]);return FableServiceTemplate;}(libFableServiceBase);module.exports=FableServiceTemplate;},{"fable-serviceproviderbase":51}],155:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');// TODO: These are still pretty big -- consider the smaller polyfills
|
|
3850
|
+
var libAsyncWaterfall=require('async.waterfall');var libAsyncEachLimit=require('async.eachlimit');var libBigNumber=require('big.js');var FableServiceUtility=/*#__PURE__*/function(_libFableServiceBase13){_inherits(FableServiceUtility,_libFableServiceBase13);// Underscore and lodash have a behavior, _.template, which compiles a
|
|
3590
3851
|
// string-based template with code snippets into simple executable pieces,
|
|
3591
3852
|
// with the added twist of returning a precompiled function ready to go.
|
|
3592
3853
|
//
|
|
@@ -3595,8 +3856,8 @@ var libAsyncWaterfall=require('async.waterfall');var libAsyncEachLimit=require('
|
|
|
3595
3856
|
//
|
|
3596
3857
|
// This is an implementation of that.
|
|
3597
3858
|
// TODO: Make this use precedent, add configuration, add debugging.
|
|
3598
|
-
function FableServiceUtility(pFable,pOptions,pServiceHash){var
|
|
3599
|
-
|
|
3859
|
+
function FableServiceUtility(pFable,pOptions,pServiceHash){var _this46;_classCallCheck2(this,FableServiceUtility);_this46=_callSuper(this,FableServiceUtility,[pFable,pOptions,pServiceHash]);_this46.templates={};// These two functions are used extensively throughout
|
|
3860
|
+
_this46.waterfall=libAsyncWaterfall;_this46.eachLimit=libAsyncEachLimit;_this46.bigNumber=libBigNumber;return _this46;}// Underscore and lodash have a behavior, _.extend, which merges objects.
|
|
3600
3861
|
// Now that es6 gives us this, use the native thingy.
|
|
3601
3862
|
// Nevermind, the native thing is not stable enough across environments
|
|
3602
3863
|
// Basic shallow copy
|