fable 3.0.132 → 3.0.134
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 +27 -36
- package/dist/fable.compatible.js +336 -165
- package/dist/fable.compatible.min.js +2 -2
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +277 -106
- package/dist/fable.min.js +2 -2
- package/dist/fable.min.js.map +1 -1
- package/example_applications/data/Fruit-Data.json +694 -0
- package/example_applications/data/Fruit-Manyfest.json +56 -0
- package/example_applications/mathematical_playground/AppData.json +8 -0
- package/example_applications/mathematical_playground/Equations.json +12 -0
- package/example_applications/mathematical_playground/Math-Solver-Harness.js +89 -0
- package/package.json +3 -3
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json +80 -20
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-Postfix.js +218 -200
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-SolvePostfixedExpression.js +11 -1
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-TokenMap.json +1 -0
- package/source/services/Fable-Service-ExpressionParser.js +22 -3
- package/source/services/Fable-Service-Math.js +570 -19
- package/test/ExpressionParser_tests.js +20 -1
- package/test/Math_test.js +54 -3
- package/test/data/chocodata.json +248 -0
package/dist/fable.compatible.js
CHANGED
|
@@ -1549,7 +1549,7 @@ var tmpDescriptorAddresses=Object.keys(tmpSource);tmpDescriptorAddresses.forEach
|
|
|
1549
1549
|
* @class Manyfest
|
|
1550
1550
|
*/var Manyfest=/*#__PURE__*/function(_libFableServiceProvi6){_inherits(Manyfest,_libFableServiceProvi6);function Manyfest(pFable,pManifest,pServiceHash){var _this15;_classCallCheck2(this,Manyfest);if(pFable===undefined){_this15=_callSuper(this,Manyfest,[{}]);}else{_this15=_callSuper(this,Manyfest,[pFable,pManifest,pServiceHash]);}_this15.serviceType='Manifest';// Wire in logging
|
|
1551
1551
|
_this15.logInfo=libSimpleLog;_this15.logError=libSimpleLog;// Create an object address resolver and map in the functions
|
|
1552
|
-
_this15.objectAddressCheckAddressExists=new libObjectAddressCheckAddressExists(_this15.logInfo,_this15.logError);_this15.objectAddressGetValue=new libObjectAddressGetValue(_this15.logInfo,_this15.logError);_this15.objectAddressSetValue=new libObjectAddressSetValue(_this15.logInfo,_this15.logError);_this15.objectAddressDeleteValue=new libObjectAddressDeleteValue(_this15.logInfo,_this15.logError);if(!('defaultValues'in _this15.options)){_this15.options.defaultValues={"String":"","Number":0,"Float":0.0,"Integer":0,"Boolean":false,"Binary":0,"DateTime":0,"Array":[],"Object":{},"Null":null};}if(!('strict'in _this15.options)){_this15.options.strict=false;}_this15.scope=undefined;_this15.elementAddresses=undefined;_this15.elementHashes=undefined;_this15.elementDescriptors=undefined;_this15.reset();if(_typeof(_this15.options)==='object'){_this15.loadManifest(_this15.options);}_this15.schemaManipulations=new libSchemaManipulation(_this15.logInfo,_this15.logError);_this15.objectAddressGeneration=new libObjectAddressGeneration(_this15.logInfo,_this15.logError);_this15.hashTranslations=new libHashTranslation(_this15.logInfo,_this15.logError);return _possibleConstructorReturn(_this15);}/*************************************************************************
|
|
1552
|
+
_this15.objectAddressCheckAddressExists=new libObjectAddressCheckAddressExists(_this15.logInfo,_this15.logError);_this15.objectAddressGetValue=new libObjectAddressGetValue(_this15.logInfo,_this15.logError);_this15.objectAddressSetValue=new libObjectAddressSetValue(_this15.logInfo,_this15.logError);_this15.objectAddressDeleteValue=new libObjectAddressDeleteValue(_this15.logInfo,_this15.logError);if(!('defaultValues'in _this15.options)){_this15.options.defaultValues={"String":"","Number":0,"Float":0.0,"Integer":0,"PreciseNumber":"0.0","Boolean":false,"Binary":0,"DateTime":0,"Array":[],"Object":{},"Null":null};}if(!('strict'in _this15.options)){_this15.options.strict=false;}_this15.scope=undefined;_this15.elementAddresses=undefined;_this15.elementHashes=undefined;_this15.elementDescriptors=undefined;_this15.reset();if(_typeof(_this15.options)==='object'){_this15.loadManifest(_this15.options);}_this15.schemaManipulations=new libSchemaManipulation(_this15.logInfo,_this15.logError);_this15.objectAddressGeneration=new libObjectAddressGeneration(_this15.logInfo,_this15.logError);_this15.hashTranslations=new libHashTranslation(_this15.logInfo,_this15.logError);_this15.numberRegex=/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;return _possibleConstructorReturn(_this15);}/*************************************************************************
|
|
1553
1553
|
* Schema Manifest Loading, Reading, Manipulation and Serialization Functions
|
|
1554
1554
|
*/ // Reset critical manifest properties
|
|
1555
1555
|
_createClass2(Manyfest,[{key:"reset",value:function reset(){this.scope='DEFAULT';this.elementAddresses=[];this.elementHashes={};this.elementDescriptors={};}},{key:"clone",value:function clone(){// Make a copy of the options in-place
|
|
@@ -1589,8 +1589,8 @@ tmpValue=this.getDefaultValue(this.getDescriptor(pAddress));}return tmpValue;}//
|
|
|
1589
1589
|
for(var i=0;i<this.elementAddresses.length;i++){var tmpDescriptor=this.getDescriptor(this.elementAddresses[i]);var tmpValueExists=this.checkAddressExists(pObject,tmpDescriptor.Address);var tmpValue=this.getValueAtAddress(pObject,tmpDescriptor.Address);if(typeof tmpValue=='undefined'||!tmpValueExists){// This will technically mean that `Object.Some.Value = undefined` will end up showing as "missing"
|
|
1590
1590
|
// TODO: Do we want to do a different message based on if the property exists but is undefined?
|
|
1591
1591
|
tmpValidationData.MissingElements.push(tmpDescriptor.Address);if(tmpDescriptor.Required||this.options.strict){addValidationError(tmpDescriptor.Address,'is flagged REQUIRED but is not set in the object');}}// Now see if there is a data type specified for this element
|
|
1592
|
-
if(tmpDescriptor.DataType){var tmpElementType=_typeof(tmpValue);switch(tmpDescriptor.DataType.toString().trim().toLowerCase()){case'string':if(tmpElementType!='string'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}break;case'number':if(tmpElementType!='number'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}break;case'integer':if(tmpElementType!='number'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}else{var tmpValueString=tmpValue.toString();if(tmpValueString.indexOf('.')>-1){// TODO: Is this an error?
|
|
1593
|
-
addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but has a decimal point in the number."));}}break;case'float':if(tmpElementType!='number'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}break;case'
|
|
1592
|
+
if(tmpDescriptor.DataType){var tmpElementType=_typeof(tmpValue);switch(tmpDescriptor.DataType.toString().trim().toLowerCase()){case'string':if(tmpElementType!='string'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}break;case"precisenumber":if(tmpElementType!='string'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}else if(!this.numberRegex.test(tmpValue)){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is not a valid number"));}break;case'number':if(tmpElementType!='number'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}break;case'integer':if(tmpElementType!='number'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}else{var tmpValueString=tmpValue.toString();if(tmpValueString.indexOf('.')>-1){// TODO: Is this an error?
|
|
1593
|
+
addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but has a decimal point in the number."));}}break;case'float':if(tmpElementType!='number'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is of the type ").concat(tmpElementType));}break;case'datetime':var tmpValueDate=new Date(tmpValue);if(tmpValueDate.toString()=='Invalid Date'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," but is not parsable as a Date by Javascript"));}default:// Check if this is a string, in the default case
|
|
1594
1594
|
// Note this is only when a DataType is specified and it is an unrecognized data type.
|
|
1595
1595
|
if(tmpElementType!='string'){addValidationError(tmpDescriptor.Address,"has a DataType ".concat(tmpDescriptor.DataType," (which auto-converted to String because it was unrecognized) but is of the type ").concat(tmpElementType));}break;}}}return tmpValidationData;}// Returns a default value, or, the default value for the data type (which is overridable with configuration)
|
|
1596
1596
|
},{key:"getDefaultValue",value:function getDefaultValue(pDescriptor){if(_typeof(pDescriptor)!='object'){return undefined;}if('Default'in pDescriptor){return pDescriptor.Default;}else{// Default to a null if it doesn't have a type specified.
|
|
@@ -3376,9 +3376,19 @@ var tmpValue=tmpManifest.getValueByHash(tmpDataSource,tmpToken.Token);// if (!tm
|
|
|
3376
3376
|
// // If no hash resolves, try by address.
|
|
3377
3377
|
// tmpValue = tmpManifest.getValueAtAddress(tmpToken.Token, tmpDataSource);
|
|
3378
3378
|
// }
|
|
3379
|
-
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){
|
|
3379
|
+
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){// TODO: Should we allow this to be a function? Good god the complexity and beauty of that...
|
|
3380
|
+
if(Array.isArray(tmpValue)||_typeof(tmpValue)==='object'){tmpToken.Resolved=true;tmpToken.Value=tmpValue;}else{tmpResults.ExpressionParserLog.push("INFO: ExpressionParser.substituteValuesInTokenizedObjects found a non-numeric, non-set 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.
|
|
3380
3381
|
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.
|
|
3381
|
-
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);}
|
|
3382
|
+
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);}/**
|
|
3383
|
+
* Solves the given expression using the provided data and manifest.
|
|
3384
|
+
*
|
|
3385
|
+
* @param {string} pExpression - The expression to solve.
|
|
3386
|
+
* @param {object} pDataSourceObject - (optional) The data source object (e.g. AppData).
|
|
3387
|
+
* @param {object} pResultObject - (optional) The result object containing the full postfix expression list, internal variables and solver history.
|
|
3388
|
+
* @param {object} pManifest - (optional) The manifest object for dereferencing variables.
|
|
3389
|
+
* @param {object} pDataDestinationObject - (optional) The data destination object for where to marshal the result into.
|
|
3390
|
+
* @returns {any} - The result of solving the expression.
|
|
3391
|
+
*/},{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(pToken in this.ExpressionParser.tokenMap){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:
|
|
3382
3392
|
// There is a fifth token type, VirtualSymbol
|
|
3383
3393
|
// This is a value that's added during solve and looked up by address in the VirtualSymbol object.
|
|
3384
3394
|
}},{key:"getTokenContainerObject",value:function getTokenContainerObject(pToken,pTokenType){return{Token:pToken,Type:typeof pTokenType==='undefined'?this.getTokenType(pToken):pTokenType,Descriptor:pToken in this.ExpressionParser.tokenMap?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
|
|
@@ -3429,7 +3439,7 @@ tmpCurrentTokenType='Value';tmpCurrentToken+=tmpCharacter;// continue;
|
|
|
3429
3439
|
// }
|
|
3430
3440
|
// tmpResults.ExpressionParserLog.push(`ExpressionParser.tokenize found an unknown character code ${tmpCharCode} character ${tmpCharacter} in the expression: ${pExpression} at index ${i}`);
|
|
3431
3441
|
// this.log.warn(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
|
|
3432
|
-
}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
|
|
3442
|
+
}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"},"pi":{"Name":"Pi","Address":"fable.Math.piPrecise"},"sin":{"Name":"Sine","Address":"fable.Math.sin"},"cos":{"Name":"Cosine","Address":"fable.Math.cos"},"tan":{"Name":"Tangent","Address":"fable.Math.tan"},"count":{"Name":"Count Set Elements","Address":"fable.Math.countSetElements"},"sortset":{"Name":"Sort Set","Address":"fable.Math.sortSetPrecise"},"bucketset":{"Name":"Bucket Set","Address":"fable.Math.bucketSetPrecise"},"sorthistogram":{"Name":"Sort Histogram","Address":"fable.Math.sortHistogramPrecise"},"max":{"Name":"Maximum","Address":"fable.Math.maxPrecise"},"min":{"Name":"Minimum","Address":"fable.Math.minPrecise"},"sum":{"Name":"Sum","Address":"fable.Math.sumPrecise"},"avg":{"Name":"Average","Address":"fable.Math.averagePrecise"},"mean":{"Name":"Mean","Address":"fable.Math.meanPrecise"},"median":{"Name":"Median","Address":"fable.Math.medianPrecise"},"mode":{"Name":"Mode","Address":"fable.Math.modePrecise"}};},{}],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
|
|
3433
3443
|
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
|
|
3434
3444
|
var tmpParenthesisDepth=0;// If it is in a state address, we don't care about the parenthesis
|
|
3435
3445
|
// State addresses are between squiggly brackets
|
|
@@ -3448,88 +3458,44 @@ this.getTokenType(pTokenizedExpression[0])==='Token.StateAddress'||this.getToken
|
|
|
3448
3458
|
){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
|
|
3449
3459
|
// This is a simple lint check, not a full-blown syntax check
|
|
3450
3460
|
var tmpTokenPrevious=false;for(var _i17=0;_i17<pTokenizedExpression.length-1;_i17++){if(pTokenizedExpression[_i17]in this.ExpressionParser.tokenMap&&this.ExpressionParser.tokenMap[pTokenizedExpression[_i17]].Type!='Parenthesis'&&!tmpTokenPrevious){tmpTokenPrevious=true;}else if(pTokenizedExpression[_i17]in this.ExpressionParser.tokenMap&&this.ExpressionParser.tokenMap[pTokenizedExpression[_i17]].Type!='Parenthesis'){// If this isn't a + or - positivity/negativity multiplier, it's an error.
|
|
3451
|
-
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
|
|
3452
|
-
// // allow users to pass in parenthesis in the wrong order.
|
|
3453
|
-
// // The linter does blow up as does the postfix, but, just in case we'll leave these explicit.
|
|
3454
|
-
// // It really doesn't hurt anything.
|
|
3455
|
-
// if (pLeftValue.Token === ')')
|
|
3456
|
-
// {
|
|
3457
|
-
// // We have found a close parenthesis which needs to pull the proper virtual symbol for the last operation on this stack.
|
|
3458
|
-
// // This ensures we are not expressing the parenthesis virtual symbols to the solver.
|
|
3459
|
-
// pLeftValue.VirtualSymbolName = pLayerStackMap[pLeftValue.SolveLayerStack];
|
|
3460
|
-
// this.log.error(`ERROR: ExpressionParser.getPosfixSolveListOperation found a close parenthesis in the left value of an operation.`);
|
|
3461
|
-
// }
|
|
3462
|
-
// else if (pRightValue.Token === '(')
|
|
3463
|
-
// {
|
|
3464
|
-
// // We have found a close parenthesis which needs to pull the proper virtual symbol for the last operation on this stack.
|
|
3465
|
-
// // This ensures we are not expressing the parenthesis virtual symbols to the solver.
|
|
3466
|
-
// pRightValue.VirtualSymbolName = pLayerStackMap[pRightValue.SolveLayerStack];
|
|
3467
|
-
// this.log.error(`ERROR: ExpressionParser.getPosfixSolveListOperation found a close parenthesis in the left value of an operation.`);
|
|
3468
|
-
// }
|
|
3469
|
-
// // Set the layer stack map virtual symbol name to the last operation performed on this stack.
|
|
3470
|
-
// pLayerStackMap[pOperation.SolveLayerStack] = pOperation.VirtualSymbolName;
|
|
3471
|
-
/* These two if blocks are very complex -- they basically provide a
|
|
3461
|
+
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;/* These two if blocks are very complex -- they basically provide a
|
|
3472
3462
|
* way to deal with recursion that can be expressed to the user in
|
|
3473
3463
|
* a meaningful way.
|
|
3474
3464
|
*
|
|
3475
3465
|
* The reason we are doing it as such is to show exactly how the
|
|
3476
3466
|
* solver resolves the passed-in tokens into a solvable expression.
|
|
3477
3467
|
*/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
|
|
3478
|
-
tmpOperation.LeftValue=this.getTokenContainerObject(tmpOperation.LeftValue.VirtualSymbolName,'Token.VirtualSymbol')
|
|
3479
|
-
if
|
|
3480
|
-
'
|
|
3481
|
-
tmpDepthSolveList[i].Descriptor.Precedence>3){// If the symbol to its right is not the same as this operation
|
|
3482
|
-
if(tmpDepthSolveList[i+1].VirtualSymbolName!==tmpOperation.VirtualSymbolName){// This is the recursive "shunting" being simulated
|
|
3483
|
-
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
|
|
3484
|
-
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
|
|
3485
|
-
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.
|
|
3486
|
-
'Descriptor'in tmpDepthSolveList[_i18]&&'Descriptor'in tmpOperation.Operation&&// Anything >3 does not have commutative properties
|
|
3487
|
-
tmpDepthSolveList[_i18].Descriptor.Precedence>3){// If the symbol to its right is not the same as this operation
|
|
3488
|
-
if(tmpDepthSolveList[_i18-1].VirtualSymbolName!==tmpOperation.VirtualSymbolName){// This is the recursive "shunting" being simulated
|
|
3489
|
-
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
|
|
3468
|
+
if('LeftVirtualSymbolName'in tmpOperation.Operation){tmpOperation.LeftValue=this.getTokenContainerObject(tmpOperation.Operation.LeftVirtualSymbolName,'Token.VirtualSymbol');}else{tmpOperation.LeftValue=this.getTokenContainerObject(tmpOperation.LeftValue.VirtualSymbolName,'Token.VirtualSymbol');}}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
|
|
3469
|
+
//if ('LeftVirtualSymbolName' in tmpOperation.RightValue)
|
|
3470
|
+
if('RightVirtualSymbolName'in tmpOperation.Operation){tmpOperation.RightValue=this.getTokenContainerObject(tmpOperation.Operation.RightVirtualSymbolName,'Token.VirtualSymbol');}else{tmpOperation.RightValue=this.getTokenContainerObject(tmpOperation.RightValue.VirtualSymbolName,'Token.VirtualSymbol');}}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
|
|
3490
3471
|
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.
|
|
3491
3472
|
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.
|
|
3492
3473
|
// That is... the user entered something like "= 5 + 3" so we should just return 8, and use the default Result quietly.
|
|
3493
3474
|
}else{tmpResults.PostfixedAssignmentAddress=pTokenizedExpression[0];}// 2. Categorize tokens in the expression, put them in the "expression list" as a token object
|
|
3494
|
-
for(var
|
|
3475
|
+
for(var _i18=tmpEqualsIndex+1;_i18<pTokenizedExpression.length;_i18++){tmpResults.PostfixTokenObjects.push(this.getTokenContainerObject(pTokenizedExpression[_i18]));}// 3. Decorate mathematical parsing depth and detect functions at the same time
|
|
3495
3476
|
// Having written this a few times now, it's easier to detect functions *while* parsing depth.
|
|
3496
3477
|
// Especially if we want our system to be able to communicate with the user when there is an issue.
|
|
3497
3478
|
var tmpDepth=0;// The virtual symbol index is used for the abstract interim values that are generated at each step of the solve
|
|
3498
3479
|
var tmpVirtualParenthesisIndex=0;var tmpSolveLayerStack=[];// Kick off the solve layer stack with the first solve set identifier
|
|
3499
|
-
tmpSolveLayerStack.push("SolveSet_".concat(tmpVirtualParenthesisIndex,"_D_").concat(tmpDepth));for(var
|
|
3500
|
-
if(tmpResults.PostfixTokenObjects[
|
|
3501
|
-
tmpResults.PostfixTokenObjects[
|
|
3502
|
-
tmpResults.PostfixTokenObjects[
|
|
3480
|
+
tmpSolveLayerStack.push("SolveSet_".concat(tmpVirtualParenthesisIndex,"_D_").concat(tmpDepth));for(var _i19=0;_i19<tmpResults.PostfixTokenObjects.length;_i19++){// 1. If it's an open parenthesis, set the parenthesis at the current depth and increment the depth
|
|
3481
|
+
if(tmpResults.PostfixTokenObjects[_i19].Token==='('){// Set the depth of the open parenthesis to the current solution depth
|
|
3482
|
+
tmpResults.PostfixTokenObjects[_i19].Depth=tmpDepth;// Generate the virtual symbol name for user output
|
|
3483
|
+
tmpResults.PostfixTokenObjects[_i19].VirtualSymbolName="Pr_".concat(tmpVirtualParenthesisIndex,"_D_").concat(tmpDepth);// 1a. Detect if this parenthesis is signaling a function
|
|
3503
3484
|
// 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
|
|
3504
|
-
if(
|
|
3505
|
-
tmpResults.PostfixTokenObjects[
|
|
3506
|
-
// Rename the virtual symbol n ame to include the function
|
|
3507
|
-
// tmpResults.PostfixTokenObjects[i].VirtualSymbolName = `Fn_${tmpVirtualParenthesisIndex}_D_${tmpDepth}_${this.fable.DataFormat.cleanNonAlphaCharacters(tmpResults.PostfixTokenObjects[i-1].Token)}`;
|
|
3508
|
-
// The function and the parenthesis are at the same depth and virtual symbol
|
|
3509
|
-
// tmpResults.PostfixTokenObjects[i-1].VirtualSymbolName = tmpResults.PostfixTokenObjects[i].VirtualSymbolName;
|
|
3510
|
-
}}// Parenthesis manage the solve layer stack
|
|
3485
|
+
if(_i19>0){if(tmpResults.PostfixTokenObjects[_i19-1].Type==='Token.Symbol'){// Set the type of this to be a function
|
|
3486
|
+
tmpResults.PostfixTokenObjects[_i19-1].Type='Token.Function';}}// Parenthesis manage the solve layer stack
|
|
3511
3487
|
// 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
|
|
3512
|
-
tmpResults.PostfixTokenObjects[
|
|
3513
|
-
else if(tmpResults.PostfixTokenObjects[
|
|
3514
|
-
if(tmpDepth<0){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found a closing parenthesis at token index ".concat(
|
|
3488
|
+
tmpResults.PostfixTokenObjects[_i19].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];tmpSolveLayerStack.push(tmpResults.PostfixTokenObjects[_i19].VirtualSymbolName);tmpVirtualParenthesisIndex++;tmpDepth++;}// 2. If it's a closed parenthesis, decrease the depth
|
|
3489
|
+
else if(tmpResults.PostfixTokenObjects[_i19].Token===')'){tmpDepth--;tmpResults.PostfixTokenObjects[_i19].Depth=tmpDepth;// Check to see that the depth of the closed parenthesis is greater than 0
|
|
3490
|
+
if(tmpDepth<0){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found a closing parenthesis at token index ".concat(_i19," with no corresponding opening parenthesis."));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);}// Parenthesis manage the solve layer stack
|
|
3515
3491
|
// For closing parenthesis solve layer with a close paren, we put it in the same stack as the opening parenthesis.
|
|
3516
3492
|
// Give the closing parenthesis the same virtual symbol name as the opening parenthesis
|
|
3517
3493
|
// (do the both above at the same time)
|
|
3518
|
-
tmpResults.PostfixTokenObjects[
|
|
3519
|
-
// It was much more complex later on solving these as virtual symbols of their own.
|
|
3520
|
-
// We are saving the value resolution for the very end.
|
|
3521
|
-
else if(tmpResults.PostfixTokenObjects[_i20].Type==='Token.Symbol'){// Set the depth of the current solution depth
|
|
3522
|
-
tmpResults.PostfixTokenObjects[_i20].Depth=tmpDepth;tmpResults.PostfixTokenObjects[_i20].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];// Generate a virtual symbol name that's somewhat human readable
|
|
3523
|
-
//tmpResults.PostfixTokenObjects[i].VirtualSymbolName = `Sm_${tmpVirtualParenthesisIndex}_D_${tmpDepth}_${this.fable.DataFormat.cleanNonAlphaCharacters(tmpResults.PostfixTokenObjects[i].Token)}`;
|
|
3524
|
-
// We've used up this virtual symbol index so increment it
|
|
3525
|
-
// 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
|
|
3526
|
-
//tmpVirtualParenthesisIndex++;
|
|
3527
|
-
}// 4. If it's an operator or constant or comment, just set the depth
|
|
3528
|
-
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
|
|
3494
|
+
tmpResults.PostfixTokenObjects[_i19].VirtualSymbolName=tmpSolveLayerStack.pop();tmpResults.PostfixTokenObjects[_i19].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];}else{tmpResults.PostfixTokenObjects[_i19].Depth=tmpDepth;tmpResults.PostfixTokenObjects[_i19].SolveLayerStack=tmpSolveLayerStack[tmpSolveLayerStack.length-1];}}// 4. Walk through the decorated symbols and generate the postfix solve list
|
|
3529
3495
|
// We are going to start by creating a map of the solve layers:
|
|
3530
|
-
var tmpSolveLayerMap={};var tmpSolveLayerMaxDepth=0;for(var
|
|
3496
|
+
var tmpSolveLayerMap={};var tmpSolveLayerMaxDepth=0;for(var _i20=0;_i20<tmpResults.PostfixTokenObjects.length;_i20++){if(!(tmpResults.PostfixTokenObjects[_i20].SolveLayerStack in tmpSolveLayerMap)){tmpSolveLayerMap[tmpResults.PostfixTokenObjects[_i20].SolveLayerStack]=[];}tmpSolveLayerMap[tmpResults.PostfixTokenObjects[_i20].SolveLayerStack].push(tmpResults.PostfixTokenObjects[_i20]);// See what our max depth is. This is super important to the postfix operation
|
|
3531
3497
|
// 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.
|
|
3532
|
-
if(tmpResults.PostfixTokenObjects[
|
|
3498
|
+
if(tmpResults.PostfixTokenObjects[_i20].Depth>tmpSolveLayerMaxDepth){tmpSolveLayerMaxDepth=tmpResults.PostfixTokenObjects[_i20].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.
|
|
3533
3499
|
var tmpVirtualSymbolIndex=0;tmpSolveLayerKeys.sort(// Sort the solve layers by depth.
|
|
3534
3500
|
function(pLeftLayer,pRightLayer){// It is impossible to have a layer with no entries in it.
|
|
3535
3501
|
// If that ever happens, the bug is actually above and we actively want this to blow up.
|
|
@@ -3543,69 +3509,65 @@ if(tmpSolveLayerMap[pLeftLayer][0].Depth<tmpSolveLayerMap[pRightLayer][0].Depth)
|
|
|
3543
3509
|
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)
|
|
3544
3510
|
for(var tmpPrecedence=0;tmpPrecedence<=this.ExpressionParser.tokenMaxPrecedence;tmpPrecedence++){// Enumerate all tokens in a layer's expression.
|
|
3545
3511
|
// There is a recursive way to do this, but given the short length of even the most complex equations we're favoring readability.
|
|
3546
|
-
for(var
|
|
3547
|
-
if(tmpSolveLayerTokens[
|
|
3548
|
-
if(tmpSolveLayerTokens.length===1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found a single operator in a solve layer expression at token index ".concat(
|
|
3549
|
-
else if(
|
|
3550
|
-
else if(
|
|
3551
|
-
else if(
|
|
3552
|
-
else if(
|
|
3553
|
-
tmpToken.VirtualSymbolName="
|
|
3554
|
-
else if(
|
|
3555
|
-
else if(
|
|
3556
|
-
else if(tmpSolveLayerTokens[
|
|
3557
|
-
else{tmpToken.VirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpResults.PostfixLayerstackMap[tmpToken.SolveLayerStack]=tmpToken.VirtualSymbolName;tmpVirtualSymbolIndex++;}}else if(tmpSolveLayerTokens[
|
|
3512
|
+
for(var _i21=0;_i21<tmpSolveLayerTokens.length;_i21++){// If the token is an operator and at the current precedence, add it to the postfix solve list and mutate the array.
|
|
3513
|
+
if(tmpSolveLayerTokens[_i21].Type==='Token.Operator'&&tmpSolveLayerTokens[_i21].Descriptor.Precedence===tmpPrecedence){var tmpToken=tmpSolveLayerTokens[_i21];// If there is a token and nothing else in this layer, then it's an error.
|
|
3514
|
+
if(tmpSolveLayerTokens.length===1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found a single operator in a solve layer expression at token index ".concat(_i21));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.
|
|
3515
|
+
else if(_i21==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(_i21));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.
|
|
3516
|
+
else if(_i21==tmpSolveLayerTokens.length-1){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found an operator at the end of a solve layer expression at token index ".concat(_i21));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
|
|
3517
|
+
else if(_i21==0&&tmpToken.Token=='-'){tmpToken.VirtualSymbolName="VNLO_".concat(tmpVirtualSymbolIndex);tmpResults.PostfixLayerstackMap[tmpToken.SolveLayerStack]=tmpToken.VirtualSymbolName;tmpVirtualSymbolIndex++;}// The - after an operator or an open parenthesis is also a number line orientation modifier
|
|
3518
|
+
else if(_i21>0&&tmpToken.Token=='-'&&(tmpSolveLayerTokens[_i21-1].Type==='Token.Operator'||tmpSolveLayerTokens[_i21-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
|
|
3519
|
+
tmpToken.VirtualSymbolName="VNLO_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;}// The + at the beginning is also a number line orientation modifier ... THAT WE IGNORE
|
|
3520
|
+
else if(_i21==0&&tmpToken.Token=='+'){continue;}// The + after an operator or a parenthesis is also a number line orientation modifier ... THAT WE IGNORE
|
|
3521
|
+
else if(_i21>0&&tmpToken.Token=='+'&&(tmpSolveLayerTokens[_i21-1].Type==='Token.Operator'||tmpSolveLayerTokens[_i21-1].Token==='(')){continue;}// If the token is next to another operator it's a parsing error
|
|
3522
|
+
else if(tmpSolveLayerTokens[_i21-1].Type==='Token.Operator'||tmpSolveLayerTokens[_i21+1].Type==='Token.Operator'){tmpResults.ExpressionParserLog.push("ERROR: ExpressionParser.buildPostfixedSolveList found an operator at token index ".concat(_i21," 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.
|
|
3523
|
+
else{tmpToken.VirtualSymbolName="V_".concat(tmpVirtualSymbolIndex);tmpResults.PostfixLayerstackMap[tmpToken.SolveLayerStack]=tmpToken.VirtualSymbolName;tmpVirtualSymbolIndex++;}}else if(tmpSolveLayerTokens[_i21].Type==='Token.Function'&&tmpPrecedence===0){var _tmpToken=tmpSolveLayerTokens[_i21];_tmpToken.VirtualSymbolName="VFE_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;tmpResults.PostfixLayerstackMap[_tmpToken.SolveLayerStack]=_tmpToken.VirtualSymbolName;}}}}// 5.15 Generate Virtual Symbol Clusters for Functions and Parenthesis
|
|
3558
3524
|
// ... this gets funny because of precedence of operations surrounding them, parenthesis and functions.
|
|
3559
|
-
var
|
|
3560
|
-
tmpPostfixTokenObject.ParenthesisStack=tmpPostfixTokenObject.VirtualSymbolName
|
|
3561
|
-
if(
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
var
|
|
3566
|
-
if(
|
|
3567
|
-
var
|
|
3568
|
-
//
|
|
3569
|
-
|
|
3570
|
-
//
|
|
3571
|
-
//
|
|
3572
|
-
//
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
//
|
|
3578
|
-
if(
|
|
3579
|
-
|
|
3580
|
-
if(
|
|
3581
|
-
if(!
|
|
3582
|
-
// We often see these inside functions.
|
|
3583
|
-
var tmpAbstractAddToken=this.getTokenContainerObject('+');//let tmpVirtualSymbolName = tmpResults.PostfixLayerstackMap[tmpSolveLayerTokens[0].SolveLayerStack];
|
|
3584
|
-
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
|
|
3585
|
-
for(var _tmpSolveLayerIndex2=0;_tmpSolveLayerIndex2<tmpSolveLayerKeys.length;_tmpSolveLayerIndex2++){var _tmpSolveLayerTokens2=tmpSolveLayerMap[tmpSolveLayerKeys[_tmpSolveLayerIndex2]];// For each precedence level in the layer
|
|
3525
|
+
var tmpFunctionCacheLIFOStack=[];for(var _i22=0;_i22<tmpResults.PostfixTokenObjects.length;_i22++){var tmpPostfixTokenObject=tmpResults.PostfixTokenObjects[_i22];if(tmpPostfixTokenObject.Type==='Token.Parenthesis'){// This is just to track the parenthesis stack level for User feedback
|
|
3526
|
+
tmpPostfixTokenObject.ParenthesisStack=tmpPostfixTokenObject.VirtualSymbolName;// At the beginning of the expression, this must be an open parenthesis to be legal.
|
|
3527
|
+
if(_i22==0){tmpPostfixTokenObject.IsFunction=false;var tmpVirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];if(!tmpVirtualSymbolName){// ... this parenthesis group has no operators in it; make a virtual symbol name.
|
|
3528
|
+
tmpVirtualSymbolName="VP_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;}tmpPostfixTokenObject.VirtualSymbolName=tmpVirtualSymbolName;tmpFunctionCacheLIFOStack.push(tmpPostfixTokenObject);}// If it's an open parenthesis
|
|
3529
|
+
else if(tmpPostfixTokenObject.Token==='('){// ... supporting a function
|
|
3530
|
+
if(tmpResults.PostfixTokenObjects[_i22-1].Type==='Token.Function'){tmpPostfixTokenObject.IsFunction=true;tmpPostfixTokenObject.Function=tmpResults.PostfixTokenObjects[_i22-1];var _tmpVirtualSymbolName=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];if(!_tmpVirtualSymbolName){// ... this parenthesis group has no operators in it; make a virtual symbol name.
|
|
3531
|
+
_tmpVirtualSymbolName="VFP_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;}tmpPostfixTokenObject.VirtualSymbolName=_tmpVirtualSymbolName;}else{tmpPostfixTokenObject.IsFunction=false;var _tmpVirtualSymbolName2=tmpResults.PostfixLayerstackMap[tmpPostfixTokenObject.VirtualSymbolName];if(!_tmpVirtualSymbolName2){// This is a parenthesis group with no operators in it; make a virtual symbol name.
|
|
3532
|
+
_tmpVirtualSymbolName2="VP_".concat(tmpVirtualSymbolIndex);tmpVirtualSymbolIndex++;}tmpPostfixTokenObject.VirtualSymbolName=_tmpVirtualSymbolName2;}tmpFunctionCacheLIFOStack.push(tmpPostfixTokenObject);}if(tmpPostfixTokenObject.Token===')'){var tmpOpenParenthesis=tmpFunctionCacheLIFOStack.pop();if(tmpOpenParenthesis.IsFunction){tmpPostfixTokenObject.IsFunction=true;tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.Function.VirtualSymbolName;}else{tmpPostfixTokenObject.IsFunction=false;tmpPostfixTokenObject.VirtualSymbolName=tmpOpenParenthesis.VirtualSymbolName;}}}}// X. Postprocess the parenthesis groups to ensure they respect the order of operations for their boundaries
|
|
3533
|
+
for(var _tmpSolveLayerIndex=0;_tmpSolveLayerIndex<tmpSolveLayerKeys.length;_tmpSolveLayerIndex++){var tmpParenthesisStack=[];var tmpLastOperator=false;var _tmpSolveLayerTokens=tmpSolveLayerMap[tmpSolveLayerKeys[_tmpSolveLayerIndex]];for(var _i23=0;_i23<_tmpSolveLayerTokens.length;_i23++){var _tmpPostfixTokenObject=_tmpSolveLayerTokens[_i23];// Keep track of the last operator
|
|
3534
|
+
if(_tmpPostfixTokenObject.Type==='Token.Operator'){tmpLastOperator=_tmpPostfixTokenObject;}// This is only important to do at the close parenthesis.
|
|
3535
|
+
if(_tmpPostfixTokenObject.Type==='Token.Function'){_tmpPostfixTokenObject.PreviousOperator=tmpLastOperator;}else if(_tmpPostfixTokenObject.Type==='Token.Parenthesis'&&_tmpPostfixTokenObject.Token==='('&&_tmpPostfixTokenObject.IsFunction){tmpParenthesisStack.push(_tmpPostfixTokenObject);if(_tmpPostfixTokenObject.Function.PreviousOperator){_tmpPostfixTokenObject.PreviousOperator=_tmpPostfixTokenObject.Function.PreviousOperator;}}else if(_tmpPostfixTokenObject.Type==='Token.Parenthesis'&&_tmpPostfixTokenObject.Token==='('){_tmpPostfixTokenObject.PreviousOperator=tmpLastOperator;tmpParenthesisStack.push(_tmpPostfixTokenObject);}else if(_tmpPostfixTokenObject.Type==='Token.Parenthesis'&&_tmpPostfixTokenObject.Token===')'){// This is ultra complex, and binds the order of operations logic to the open parenthesis for the group
|
|
3536
|
+
var _tmpOpenParenthesis=tmpParenthesisStack.pop();if(_i23<_tmpSolveLayerTokens.length-1){for(var j=_i23+1;j<_tmpSolveLayerTokens.length;j++){if(_tmpSolveLayerTokens[j].Type==='Token.Operator'){_tmpOpenParenthesis.NextOperator=_tmpSolveLayerTokens[j];break;}}}if(_tmpOpenParenthesis.PreviousOperator&&_tmpOpenParenthesis.NextOperator){if(_tmpOpenParenthesis.PreviousOperator.Descriptor.Precedence<=_tmpOpenParenthesis.NextOperator.Descriptor.Precedence){_tmpOpenParenthesis.NextOperator.LeftVirtualSymbolName=_tmpOpenParenthesis.PreviousOperator.VirtualSymbolName;}else{_tmpOpenParenthesis.PreviousOperator.RightVirtualSymbolName=_tmpOpenParenthesis.NextOperator.VirtualSymbolName;}}}else{if(!('SolveLayerStack'in _tmpPostfixTokenObject)){// Decorate the solve layer stack for the token
|
|
3537
|
+
if(tmpParenthesisStack.length>0){_tmpPostfixTokenObject.SolveLayerStack=tmpParenthesisStack[tmpParenthesisStack.length-1].SolveLayerStack;}else{_tmpPostfixTokenObject.SolveLayerStack='Expression_Root';}}}}}// 5.2.9: Make sure the affinity of operators is respecting order of operations.
|
|
3538
|
+
// Walk backwards and forwards, hoisting same value precedence backwards/forwards
|
|
3539
|
+
// across each layer... the precedence change needs to be decreasing to matter
|
|
3540
|
+
for(var _tmpSolveLayerIndex2=0;_tmpSolveLayerIndex2<tmpSolveLayerKeys.length;_tmpSolveLayerIndex2++){var tmpLastPrecedence=false;var tmpFinalChainToken=false;var _tmpSolveLayerTokens2=tmpSolveLayerMap[tmpSolveLayerKeys[_tmpSolveLayerIndex2]];for(var _i24=_tmpSolveLayerTokens2.length-1;_i24>=0;_i24--){var _tmpToken2=_tmpSolveLayerTokens2[_i24];if(_tmpToken2.Type==='Token.Operator'){if(!tmpFinalChainToken){tmpFinalChainToken=_tmpToken2;}else if(_tmpToken2.Descriptor.Precedence>tmpLastPrecedence){// This is less imporant than the last precedence, so hoist back the virtual value
|
|
3541
|
+
_tmpToken2.RightVirtualSymbolName=tmpFinalChainToken.VirtualSymbolName;//console.log(`Hoisting ${tmpToken.Token} back to ${tmpFinalChainToken.Token}`);
|
|
3542
|
+
tmpFinalChainToken=_tmpToken2;}else if(_tmpToken2.Descriptor.Precedence<tmpLastPrecedence){tmpFinalChainToken=_tmpToken2;}tmpLastPrecedence=_tmpToken2.Descriptor.Precedence;}}var tmpDecreasingPrecedenceStack=[];var tmpLastToken=false;for(var _i25=_tmpSolveLayerTokens2.length-1;_i25>=0;_i25--){var _tmpToken3=_tmpSolveLayerTokens2[_i25];if(_tmpToken3.Type==='Token.Operator'){if(!tmpLastToken){tmpLastToken=_tmpToken3;}else if(_tmpToken3.Descriptor.Precedence>tmpLastPrecedence){// Check and see if this needs to be resolved in the stack
|
|
3543
|
+
if(tmpDecreasingPrecedenceStack.length>0){for(var _j=tmpDecreasingPrecedenceStack.length-1;_j>=0;_j--){if(tmpDecreasingPrecedenceStack[_j].Descriptor.Precedence>=_tmpToken3.Descriptor.Precedence){//console.log(`Hoisting ${tmpDecreasingPrecedenceStack[j].Token} up to ${tmpToken.Token}`);
|
|
3544
|
+
tmpDecreasingPrecedenceStack[_j].LeftVirtualSymbolName=_tmpToken3.VirtualSymbolName;tmpDecreasingPrecedenceStack.slice(_j,1);break;}}}tmpLastToken=_tmpToken3;}else if(_tmpToken3.Descriptor.Precedence<tmpLastPrecedence){tmpDecreasingPrecedenceStack.push(tmpLastToken);tmpLastToken=_tmpToken3;}tmpLastPrecedence=_tmpToken3.Descriptor.Precedence;}}}// 5.3: Generate the Postfix Solve List
|
|
3545
|
+
for(var _tmpSolveLayerIndex3=0;_tmpSolveLayerIndex3<tmpSolveLayerKeys.length;_tmpSolveLayerIndex3++){var _tmpSolveLayerTokens3=tmpSolveLayerMap[tmpSolveLayerKeys[_tmpSolveLayerIndex3]];// If this is a layer with one value, presume it's an assignment.
|
|
3546
|
+
if(_tmpSolveLayerTokens3.length===1){var tmpAbstractAssignToken=this.getTokenContainerObject('=');tmpAbstractAssignToken.VirtualSymbolName=tmpResults.PostfixLayerstackMap[_tmpSolveLayerTokens3[0].SolveLayerStack];// If this doesn't have a matching solvelayerstack, get the virtual symbol name from the parenthesis group it's in
|
|
3547
|
+
if(!tmpAbstractAssignToken.VirtualSymbolName){for(var _i26=0;_i26<tmpResults.PostfixTokenObjects.length;_i26++){if(tmpResults.PostfixTokenObjects[_i26].ParenthesisStack===_tmpSolveLayerTokens3[0].SolveLayerStack){tmpAbstractAssignToken.VirtualSymbolName=tmpResults.PostfixTokenObjects[_i26].VirtualSymbolName;break;}}}tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(tmpAbstractAssignToken,_tmpSolveLayerTokens3[0],this.getTokenContainerObject('0.0')));continue;}// For each precedence level in the layer
|
|
3586
3548
|
for(var _tmpPrecedence=0;_tmpPrecedence<=this.ExpressionParser.tokenMaxPrecedence;_tmpPrecedence++){// Enumerate all tokens in a layer's expression.
|
|
3587
3549
|
// There is a recursive way to do this, but given the short length of even the most complex equations we're favoring readability.
|
|
3588
|
-
for(var
|
|
3589
|
-
if(
|
|
3590
|
-
if(
|
|
3550
|
+
for(var _i27=0;_i27<_tmpSolveLayerTokens3.length;_i27++){// If the token is an operator and at the current precedence, add it to the postfix solve list and mutate the array.
|
|
3551
|
+
if(_tmpSolveLayerTokens3[_i27].Type==='Token.Operator'&&_tmpSolveLayerTokens3[_i27].Descriptor.Precedence===_tmpPrecedence){var _tmpToken4=_tmpSolveLayerTokens3[_i27];// The - at the beginning of an expression is a number line orientation modifier
|
|
3552
|
+
if(_i27==0&&_tmpToken4.Token=='-'){// The number line negation operator is a special case that generates a virtual constant (-1.0) and multiplies it by the next token
|
|
3591
3553
|
// This is an abstract operation that isn't in the expression.
|
|
3592
|
-
var tmpAbstractMultiplyToken=this.
|
|
3593
|
-
else if(
|
|
3594
|
-
var _tmpAbstractMultiplyToken=this.
|
|
3595
|
-
else if(
|
|
3596
|
-
else if(
|
|
3597
|
-
else{tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(
|
|
3598
|
-
tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpToken3,_tmpSolveLayerTokens2[_i24+1],this.getTokenContainerObject('0.0')));}}}}// Now set the assignment address.
|
|
3554
|
+
var tmpAbstractMultiplyToken=this.getTokenContainerObject('*');tmpAbstractMultiplyToken.VirtualSymbolName=_tmpToken4.VirtualSymbolName;tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(tmpAbstractMultiplyToken,this.getTokenContainerObject('-1.0'),_tmpSolveLayerTokens3[_i27+1]));}// The - after an operator or an open parenthesis is also a number line orientation modifier
|
|
3555
|
+
else if(_i27>0&&_tmpToken4.Token=='-'&&(_tmpSolveLayerTokens3[_i27-1].Type==='Token.Operator'||_tmpSolveLayerTokens3[_i27-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
|
|
3556
|
+
var _tmpAbstractMultiplyToken=this.getTokenContainerObject('*');_tmpAbstractMultiplyToken.VirtualSymbolName=_tmpToken4.VirtualSymbolName;tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpAbstractMultiplyToken,this.getTokenContainerObject('-1.0'),_tmpSolveLayerTokens3[_i27+1]));}// The + at the beginning is also a number line orientation modifier ... THAT WE IGNORE
|
|
3557
|
+
else if(_i27==0&&_tmpToken4.Token=='+'){continue;}// The + after an operator or a parenthesis is also a number line orientation modifier ... THAT WE IGNORE
|
|
3558
|
+
else if(_i27>0&&_tmpToken4.Token=='+'&&(_tmpSolveLayerTokens3[_i27-1].Type==='Token.Operator'||_tmpSolveLayerTokens3[_i27-1].Token==='(')){continue;}// Finally add the dang thing.
|
|
3559
|
+
else{tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpToken4,_tmpSolveLayerTokens3[_i27-1],_tmpSolveLayerTokens3[_i27+1],_tmpSolveLayerTokens3,_i27));}}else if(_tmpSolveLayerTokens3[_i27].Type==='Token.Function'&&_tmpPrecedence===0){var _tmpToken5=_tmpSolveLayerTokens3[_i27];tmpResults.PostfixSolveList.push(this.getPosfixSolveListOperation(_tmpToken5,_tmpSolveLayerTokens3[_i27+1],this.getTokenContainerObject('0.0')));}}}}// 7. Lastly set the assignment address.
|
|
3599
3560
|
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
|
|
3600
3561
|
var tmpPassedInFable=('fable'in tmpResults);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.
|
|
3601
3562
|
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
|
|
3602
3563
|
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
|
|
3603
|
-
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);}
|
|
3564
|
+
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);}// Virtual Constants
|
|
3565
|
+
if(tmpStepResultObject.ExpressionStep.LeftValue.Type==='Token.Constant'&&!('Value'in tmpStepResultObject.ExpressionStep.LeftValue)){tmpStepResultObject.ExpressionStep.LeftValue.Value=tmpStepResultObject.ExpressionStep.LeftValue.Token;}if(tmpStepResultObject.ExpressionStep.RightValue.Type==='Token.Constant'&&!('Value'in tmpStepResultObject.ExpressionStep.RightValue)){tmpStepResultObject.ExpressionStep.RightValue.Value=tmpStepResultObject.ExpressionStep.RightValue.Token;}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.
|
|
3604
3566
|
// An operator always has a left and right value.
|
|
3605
|
-
var tmpFunctionAddress=false;if(tmpStepResultObject.ExpressionStep.Operation.Token in this.ExpressionParser.tokenMap){tmpFunctionAddress="ResultsObject.".concat(tmpStepResultObject.ExpressionStep.Operation.Descriptor.Function);}else if(tmpStepResultObject.ExpressionStep.Operation.Token.toLowerCase()in this.ExpressionParser.functionMap){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,"
|
|
3567
|
+
var tmpFunctionAddress=false;if(tmpStepResultObject.ExpressionStep.Operation.Token in this.ExpressionParser.tokenMap){tmpFunctionAddress="ResultsObject.".concat(tmpStepResultObject.ExpressionStep.Operation.Descriptor.Function);}else if(tmpStepResultObject.ExpressionStep.Operation.Token.toLowerCase()in this.ExpressionParser.functionMap){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,": ").concat(pError));this.log.error(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);return false;}// Equations don't always solve in virtual symbol order.
|
|
3606
3568
|
tmpResults.SolverFinalVirtualSymbol=tmpStepResultObject.ExpressionStep.VirtualSymbolName;}}var tmpSolverResultValue=tmpManifest.getValueAtAddress(tmpResults,"VirtualSymbols.".concat(tmpResults.SolverFinalVirtualSymbol));// Now deal with final assignment
|
|
3607
|
-
for(var
|
|
3608
|
-
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(!('Mode'in _this30.options)){_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
|
|
3569
|
+
for(var _i28=0;_i28<pPostfixedExpression.length;_i28++){if(pPostfixedExpression[_i28].Operation.Type==='Token.SolverInstruction'&&pPostfixedExpression[_i28].Operation.Token=='Assign'){tmpManifest.setValueAtAddress(tmpResults.VirtualSymbols,pPostfixedExpression[_i28].VirtualSymbolName,tmpSolverResultValue);tmpManifest.setValueByHash(tmpDataDestinationObject,pPostfixedExpression[_i28].VirtualSymbolName,tmpSolverResultValue);}}// Clean up the reference if we added it to the object.
|
|
3570
|
+
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":"=","Function":"fable.Math.assignValue","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(!('Mode'in _this30.options)){_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
|
|
3609
3571
|
},{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(!('Mode'in tmpParameters)){tmpParameters.Mode=this.options.Mode;}// Check if we are just starting .. if so, build the initial state for our recursive function
|
|
3610
3572
|
if(typeof tmpParameters.CurrentPathIndex==='undefined'){// Build the tools to start recursing
|
|
3611
3573
|
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.
|
|
@@ -3615,28 +3577,237 @@ tmpParameters.CurrentPathIndex++;}// Check if the path is fully complete
|
|
|
3615
3577
|
if(tmpParameters.CurrentPathIndex>=tmpParameters.ActualPathParts.length){return fCallback(null);}// Check if the path exists (and is a folder)
|
|
3616
3578
|
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.
|
|
3617
3579
|
return _this31.makeFolderRecursive(tmpParameters,fCallback);}else if(pCreateError.code=='EEXIST'){// The folder exists -- our dev might be running this in parallel/async/whatnot.
|
|
3618
|
-
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){
|
|
3580
|
+
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){/**
|
|
3581
|
+
* @file Fable-Service-Math.js
|
|
3582
|
+
* @description This file contains the implementation of the FableServiceMath class, which provides simple functions for performing arbitrary precision math operations.
|
|
3583
|
+
* @module FableServiceMath
|
|
3584
|
+
* @extends libFableServiceBase
|
|
3585
|
+
*/var libFableServiceBase=require('fable-serviceproviderbase');/**
|
|
3619
3586
|
* Arbitrary Precision Math Operations
|
|
3620
3587
|
* @author Steven Velozo <steven@velozo.com>
|
|
3621
3588
|
* @description Simple functions that perform arbitrary precision math operations and return string resultant values. Wraps big.js
|
|
3622
3589
|
* @class FableServiceMath
|
|
3623
3590
|
* @extends libFableServiceBase
|
|
3624
|
-
*/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;}/*
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
*/_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;}
|
|
3634
|
-
|
|
3635
|
-
|
|
3591
|
+
*/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';_this32.pi='3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679';return _this32;}/*
|
|
3592
|
+
Pass-through Rounding Method Constants
|
|
3593
|
+
|
|
3594
|
+
Property Value BigDecimal Equiv Description
|
|
3595
|
+
---------- ----- ---------------- -----------
|
|
3596
|
+
roundDown 0 ROUND_DOWN Rounds towards zero. (_I.e. truncate, no rounding._)
|
|
3597
|
+
roundHalfUp 1 ROUND_HALF_UP Rounds towards nearest neighbour. (_If equidistant, rounds away from zero._)
|
|
3598
|
+
roundHalfEven 2 ROUND_HALF_EVEN Rounds towards nearest neighbour. (_If equidistant, rounds towards even neighbour._)
|
|
3599
|
+
roundUp 3 ROUND_UP Rounds positively away from zero. (_Always round up._)
|
|
3600
|
+
*/_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;}/**
|
|
3601
|
+
* Parses a precise number value.
|
|
3602
|
+
*
|
|
3603
|
+
* @param {number} pValue - The value to parse.
|
|
3604
|
+
* @param {any} pNonNumberValue - The value to use if parsing fails.
|
|
3605
|
+
* @returns {string} - The parsed number as a string.
|
|
3606
|
+
*/},{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();}/**
|
|
3607
|
+
* Assigns the given value. For equals operations in the solver.
|
|
3608
|
+
* @param {*} pValue - The value to be assigned.
|
|
3609
|
+
* @returns {*} The assigned value.
|
|
3610
|
+
*/},{key:"assignValue",value:function assignValue(pValue){return pValue;}/**
|
|
3611
|
+
* Calculates the precise percentage of a given value compared to another value.
|
|
3612
|
+
*
|
|
3613
|
+
* @param {number} pIs - The value to calculate the percentage of.
|
|
3614
|
+
* @param {number} pOf - The value to calculate the percentage against.
|
|
3615
|
+
* @returns {string} The precise percentage as a string.
|
|
3616
|
+
*/},{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();}/**
|
|
3617
|
+
* Rounds a value to a specified number of decimal places using a specified rounding method.
|
|
3618
|
+
*
|
|
3619
|
+
* @param {number} pValue - The value to be rounded.
|
|
3620
|
+
* @param {number} pDecimals - The number of decimal places to round to.
|
|
3621
|
+
* @param {function} [pRoundingMethod] - The rounding method to use. Defaults to `this.roundHalfUp`.
|
|
3622
|
+
* @returns {string} - The rounded value as a string.
|
|
3623
|
+
*/},{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();}/**
|
|
3624
|
+
* Returns a string representation of a number with a specified number of decimals.
|
|
3625
|
+
*
|
|
3626
|
+
* @param {number} pValue - The number to be formatted.
|
|
3627
|
+
* @param {number} pDecimals - The number of decimals to include in the formatted string.
|
|
3628
|
+
* @param {string} [pRoundingMethod] - The rounding method to use. Defaults to 'roundHalfUp'.
|
|
3629
|
+
* @returns {string} - The formatted number as a string.
|
|
3630
|
+
*/},{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();}/**
|
|
3631
|
+
* Adds two values precisely.
|
|
3632
|
+
* @param {number} pLeftValue - The left value to be added.
|
|
3633
|
+
* @param {number} pRightValue - The right value to be added.
|
|
3634
|
+
* @returns {string} - The result of adding the two values as a string.
|
|
3635
|
+
*/},{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();}/**
|
|
3636
|
+
* Subtracts two values precisely.
|
|
3637
|
+
*
|
|
3638
|
+
* @param {number} pLeftValue - The left value to subtract.
|
|
3639
|
+
* @param {number} pRightValue - The right value to subtract.
|
|
3640
|
+
* @returns {string} The result of the subtraction as a string.
|
|
3641
|
+
*/},{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();}/**
|
|
3642
|
+
* Calculates the precise power of two numbers.
|
|
3643
|
+
*
|
|
3644
|
+
* @param {number} pLeftValue - The base value.
|
|
3645
|
+
* @param {number} pRightValue - The exponent value.
|
|
3646
|
+
* @returns {string} The result of raising the base value to the exponent value.
|
|
3647
|
+
*/},{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();}/**
|
|
3648
|
+
* Multiplies two values precisely.
|
|
3649
|
+
*
|
|
3650
|
+
* @param {number} pLeftValue - The left value to multiply.
|
|
3651
|
+
* @param {number} pRightValue - The right value to multiply.
|
|
3652
|
+
* @returns {string} The result of the multiplication as a string.
|
|
3653
|
+
*/},{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();}/**
|
|
3654
|
+
* Divides two values precisely.
|
|
3655
|
+
*
|
|
3656
|
+
* @param {number} pLeftValue - The left value to be divided.
|
|
3657
|
+
* @param {number} pRightValue - The right value to divide by.
|
|
3658
|
+
* @returns {string} The result of the division as a string.
|
|
3659
|
+
*/},{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();}/**
|
|
3660
|
+
* Calculates the modulus of two values with precision.
|
|
3661
|
+
*
|
|
3662
|
+
* @param {number} pLeftValue - The left value.
|
|
3663
|
+
* @param {number} pRightValue - The right value.
|
|
3664
|
+
* @returns {string} The result of the modulus operation as a string.
|
|
3665
|
+
*/},{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();}/**
|
|
3666
|
+
* Calculates the square root of a number with precise decimal places.
|
|
3667
|
+
*
|
|
3668
|
+
* @param {number} pValue - The number to calculate the square root of.
|
|
3669
|
+
* @returns {string} The square root of the input number as a string.
|
|
3670
|
+
*/},{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();}/**
|
|
3671
|
+
* Calculates the absolute value of a number precisely.
|
|
3672
|
+
*
|
|
3673
|
+
* @param {number} pValue - The number to calculate the absolute value of.
|
|
3674
|
+
* @returns {string} The absolute value of the input number as a string.
|
|
3675
|
+
*/},{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();}/**
|
|
3676
|
+
* Compares two values precisely.
|
|
3677
|
+
*
|
|
3678
|
+
* @param {number} pLeftValue - The left value to compare.
|
|
3679
|
+
* @param {number} pRightValue - The right value to compare.
|
|
3680
|
+
* @returns {number} - Returns the result of the comparison.
|
|
3681
|
+
*/},{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);}/**
|
|
3682
|
+
* Determines if the left value is greater than the right value precisely.
|
|
3683
|
+
*
|
|
3684
|
+
* @param {number} pLeftValue - The left value to compare.
|
|
3685
|
+
* @param {number} pRightValue - The right value to compare.
|
|
3686
|
+
* @returns {boolean} - Returns true if the left value is greater than the right value, otherwise returns false.
|
|
3687
|
+
*/},{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);}/**
|
|
3688
|
+
* Checks if the left value is greater than or equal to the right value.
|
|
3689
|
+
* If either value is not a number, it is treated as 0.
|
|
3690
|
+
*
|
|
3691
|
+
* @param {number} pLeftValue - The left value to compare.
|
|
3692
|
+
* @param {number} pRightValue - The right value to compare.
|
|
3693
|
+
* @returns {boolean} - True if the left value is greater than or equal to the right value, false otherwise.
|
|
3694
|
+
*/},{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);}/**
|
|
3695
|
+
* Determines if the left value is less than the right value precisely.
|
|
3696
|
+
*
|
|
3697
|
+
* @param {number} pLeftValue - The left value to compare.
|
|
3698
|
+
* @param {number} pRightValue - The right value to compare.
|
|
3699
|
+
* @returns {boolean} - Returns true if the left value is less than the right value, otherwise returns false.
|
|
3700
|
+
*/},{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);}/**
|
|
3701
|
+
* Determines if the left value is less than or equal to the right value.
|
|
3702
|
+
*
|
|
3703
|
+
* @param {number} pLeftValue - The left value to compare.
|
|
3704
|
+
* @param {number} pRightValue - The right value to compare.
|
|
3705
|
+
* @returns {boolean} - Returns true if the left value is less than or equal to the right value, otherwise returns false.
|
|
3706
|
+
*/},{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);}/**
|
|
3707
|
+
* Converts degrees to radians with arbitrary precision.
|
|
3708
|
+
*
|
|
3709
|
+
* @param {number} pDegrees - The degrees to convert to radians.
|
|
3710
|
+
* @returns {string} - The converted radians as a string.
|
|
3711
|
+
*/},{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?
|
|
3712
|
+
var tmpResult=tmpDegreesArbitraryValue.times(Math.PI).div(180);return tmpResult.toString();}/**
|
|
3713
|
+
* Calculates the value of pi with the specified precision.
|
|
3714
|
+
* If no precision is provided, returns 100 digits after the decimal.
|
|
3715
|
+
*
|
|
3716
|
+
* @param {number} [pPrecision] - The precision to use for calculating pi.
|
|
3717
|
+
* @returns {number} - The calculated value of pi.
|
|
3718
|
+
*/},{key:"piPrecise",value:function piPrecise(pPrecision){if(typeof pPrecision==='undefined'){return this.pi;}else{return this.roundPrecise(this.pi,pPrecision);}}/**
|
|
3719
|
+
* Calculates the sine of the given angle in radians.
|
|
3720
|
+
*
|
|
3721
|
+
* @param {number} pRadians - The angle in radians.
|
|
3722
|
+
* @returns {number} The sine of the angle.
|
|
3723
|
+
*/},{key:"sin",value:function sin(pRadians){var tmpRadians=isNaN(pRadians)?0:pRadians;return Math.sin(tmpRadians);}/**
|
|
3724
|
+
* Calculates the cosine of the given angle in radians.
|
|
3725
|
+
*
|
|
3726
|
+
* @param {number} pRadians - The angle in radians.
|
|
3727
|
+
* @returns {number} The cosine of the angle.
|
|
3728
|
+
*/},{key:"cos",value:function cos(pRadians){var tmpRadians=isNaN(pRadians)?0:pRadians;return Math.cos(tmpRadians);}/**
|
|
3729
|
+
* Calculates the tangent of an angle in radians.
|
|
3730
|
+
*
|
|
3731
|
+
* @param {number} pRadians - The angle in radians.
|
|
3732
|
+
* @returns {number} The tangent of the angle.
|
|
3733
|
+
*/},{key:"tan",value:function tan(pRadians){var tmpRadians=isNaN(pRadians)?0:pRadians;return Math.tan(tmpRadians);}/* * * * * * * * * * * * * * * *
|
|
3734
|
+
* Set functions
|
|
3735
|
+
* These are meant to work fine with arrays and more complex set descriptions returned by Manyfest.
|
|
3736
|
+
* Manyfest sometimes returns values as arrays and sometimes as a map of addresses with values depending
|
|
3737
|
+
* on what was requested.
|
|
3738
|
+
*
|
|
3739
|
+
* The following functions will likely be broken into their own service.
|
|
3740
|
+
*/ /**
|
|
3741
|
+
* Counts the number of elements in a set.
|
|
3742
|
+
*
|
|
3743
|
+
* @param {Array|Object|any} pValueSet - The set to count the elements of.
|
|
3744
|
+
* @returns {number} The number of elements in the set.
|
|
3745
|
+
*/},{key:"countSetElements",value:function countSetElements(pValueSet){if(Array.isArray(pValueSet)){return pValueSet.length;}else if(_typeof(pValueSet)==='object'){return Object.keys(pValueSet).length;}else if(pValueSet){// This is controversial. Discuss with colleagues!
|
|
3746
|
+
return 1;}return 0;}/**
|
|
3747
|
+
* Sorts the elements in the given value set in ascending order using the precise parsing and comparison.
|
|
3748
|
+
*
|
|
3749
|
+
* @param {Array|Object} pValueSet - The value set to be sorted.
|
|
3750
|
+
* @returns {Array} - The sorted value set.
|
|
3751
|
+
*/},{key:"sortSetPrecise",value:function sortSetPrecise(pValueSet){var _this33=this;var tmpSortedSet=[];if(Array.isArray(pValueSet)){for(var i=0;i<pValueSet.length;i++){tmpSortedSet.push(this.parsePrecise(pValueSet[i],NaN));}}else if(_typeof(pValueSet)==='object'){var tmpKeys=Object.keys(pValueSet);for(var _i29=0;_i29<tmpKeys.length;_i29++){tmpSortedSet.push(this.parsePrecise(pValueSet[tmpKeys[_i29]],NaN));}}tmpSortedSet.sort(function(pLeft,pRight){return _this33.comparePrecise(pLeft,pRight);});return tmpSortedSet;}/**
|
|
3752
|
+
* Bucketizes a set of values based on a specified bucket size.
|
|
3753
|
+
*
|
|
3754
|
+
* @param {Array|Object} pValueSet - The set of values to be bucketized.
|
|
3755
|
+
* @param {number} pBucketSize - The size of each bucket. Optional - If NaN, the values will be bucketized by their value.
|
|
3756
|
+
* @returns {Object} - The bucketized set of values.
|
|
3757
|
+
*/},{key:"bucketSetPrecise",value:function bucketSetPrecise(pValueSet,pBucketSize){var tmpBucketedSet={};var tmpBucketSize=this.parsePrecise(pBucketSize,NaN);if(Array.isArray(pValueSet)){for(var i=0;i<pValueSet.length;i++){var tmpValue=this.parsePrecise(pValueSet[i],NaN);var tmpBucket=tmpValue.toString();if(!isNaN(tmpBucketSize)){tmpBucket=this.dividePrecise(pValueSet[i],tmpBucketSize);}if(!(tmpBucket in tmpBucketedSet)){tmpBucketedSet[tmpBucket]=0;}tmpBucketedSet[tmpBucket]=tmpBucketedSet[tmpBucket]+1;}}else if(_typeof(pValueSet)==='object'){var tmpKeys=Object.keys(pValueSet);for(var _i30=0;_i30<tmpKeys.length;_i30++){var _tmpValue4=this.parsePrecise(pValueSet[tmpKeys[_i30]],NaN);var _tmpBucket=_tmpValue4.toString();if(!isNaN(tmpBucketSize)){_tmpBucket=this.dividePrecise(pValueSet[_i30],tmpBucketSize);}if(!(_tmpBucket in tmpBucketedSet)){tmpBucketedSet[_tmpBucket]=0;}tmpBucketedSet[_tmpBucket]=tmpBucketedSet[_tmpBucket]+1;}}return tmpBucketedSet;}/**
|
|
3758
|
+
* Calculates the histogram using precise bucket set for the given pValueSet.
|
|
3759
|
+
*
|
|
3760
|
+
* @param {Array<number>} pValueSet - The array of p-values.
|
|
3761
|
+
* @returns {Array<number>} The histogram of the p-values.
|
|
3762
|
+
*/},{key:"histogramPrecise",value:function histogramPrecise(pValueSet){return this.bucketSetPrecise(pValueSet);}/**
|
|
3763
|
+
* Sorts the histogram object in ascending order based on the frequencies of the buckets.
|
|
3764
|
+
*
|
|
3765
|
+
* @param {Object} pHistogram - The histogram object to be sorted.
|
|
3766
|
+
* @returns {Object} - The sorted histogram object.
|
|
3767
|
+
*/},{key:"sortHistogramPrecise",value:function sortHistogramPrecise(pHistogram){var tmpSortedHistogram={};var tmpKeys=Object.keys(pHistogram);tmpKeys.sort(function(pLeft,pRight){return pHistogram[pLeft]-pHistogram[pRight];});for(var i=0;i<tmpKeys.length;i++){tmpSortedHistogram[tmpKeys[i]]=pHistogram[tmpKeys[i]];}return tmpSortedHistogram;}/**
|
|
3768
|
+
* Finds the maximum value from a set of precise values.
|
|
3769
|
+
*
|
|
3770
|
+
* @param {Array|Object} pValueSet - The set of values to find the maximum from.
|
|
3771
|
+
* @returns {number} - The maximum value from the set.
|
|
3772
|
+
*/},{key:"maxPrecise",value:function maxPrecise(pValueSet){var tmpMaxValue=NaN;if(Array.isArray(pValueSet)){for(var i=0;i<pValueSet.length;i++){if(!tmpMaxValue){tmpMaxValue=this.parsePrecise(pValueSet[i],NaN);}else{var tmpComparisonValue=this.parsePrecise(pValueSet[i],NaN);if(this.gtPrecise(tmpComparisonValue,tmpMaxValue)){tmpMaxValue=tmpComparisonValue;}}}}else if(_typeof(pValueSet)==='object'){var tmpKeys=Object.keys(pValueSet);for(var _i31=0;_i31<tmpKeys.length;_i31++){if(!tmpMaxValue){tmpMaxValue=this.parsePrecise(pValueSet[tmpKeys[_i31]],NaN);}else{var _tmpComparisonValue=this.parsePrecise(pValueSet[tmpKeys[_i31]],NaN);if(this.gtPrecise(_tmpComparisonValue,tmpMaxValue)){tmpMaxValue=_tmpComparisonValue;}}}}return tmpMaxValue;}/**
|
|
3773
|
+
* Finds the minimum value from a set of values.
|
|
3774
|
+
*
|
|
3775
|
+
* @param {Array|Object} pValueSet - The set of values to find the minimum from.
|
|
3776
|
+
* @returns {number} The minimum value from the set.
|
|
3777
|
+
*/},{key:"minPrecise",value:function minPrecise(pValueSet){var tmpMinValue=NaN;if(Array.isArray(pValueSet)){for(var i=0;i<pValueSet.length;i++){if(!tmpMinValue){tmpMinValue=this.parsePrecise(pValueSet[i],NaN);}else{var tmpComparisonValue=this.parsePrecise(pValueSet[i],NaN);if(!isNaN(tmpComparisonValue)&&this.ltPrecise(tmpComparisonValue,tmpMinValue)){tmpMinValue=tmpComparisonValue;}}}}else if(_typeof(pValueSet)==='object'){var tmpKeys=Object.keys(pValueSet);for(var _i32=0;_i32<tmpKeys.length;_i32++){if(!tmpMinValue){tmpMinValue=this.parsePrecise(pValueSet[tmpKeys[_i32]],NaN);}else{var _tmpComparisonValue2=this.parsePrecise(pValueSet[tmpKeys[_i32]],NaN);if(!isNaN(_tmpComparisonValue2)&&this.ltPrecise(_tmpComparisonValue2,tmpMinValue)){tmpMinValue=_tmpComparisonValue2;}}}}return tmpMinValue;}/**
|
|
3778
|
+
* Calculates the precise sum of values in the given value set.
|
|
3779
|
+
*
|
|
3780
|
+
* @param {Array|Object} pValueSet - The value set to calculate the sum from.
|
|
3781
|
+
* @returns {string} The precise sum value as a string.
|
|
3782
|
+
*/},{key:"sumPrecise",value:function sumPrecise(pValueSet){var tmpSumValue="0.0";if(Array.isArray(pValueSet)){for(var i=0;i<pValueSet.length;i++){var tmpComparisonValue=this.parsePrecise(pValueSet[i],NaN);if(!isNaN(tmpComparisonValue)){tmpSumValue=this.addPrecise(tmpSumValue,tmpComparisonValue);}}}else if(_typeof(pValueSet)==='object'){var tmpKeys=Object.keys(pValueSet);for(var _i33=0;_i33<tmpKeys.length;_i33++){var _tmpComparisonValue3=this.parsePrecise(pValueSet[tmpKeys[_i33]],NaN);if(!isNaN(_tmpComparisonValue3)){tmpSumValue=this.addPrecise(tmpSumValue,_tmpComparisonValue3);}}}return tmpSumValue;}/**
|
|
3783
|
+
* Calculates the precise mean of a given value set.
|
|
3784
|
+
*
|
|
3785
|
+
* @param {Array<number>} pValueSet - The array of values to calculate the mean.
|
|
3786
|
+
* @returns {string} The precise mean value as a string.
|
|
3787
|
+
*/},{key:"meanPrecise",value:function meanPrecise(pValueSet){var tmpSumValue=this.sumPrecise(pValueSet);var tmpCount=this.countSetElements(pValueSet);if(tmpCount==0){return'0.0';}return this.dividePrecise(tmpSumValue,tmpCount);}/**
|
|
3788
|
+
* Calculates the average of an array of values precisely.
|
|
3789
|
+
*
|
|
3790
|
+
* @param {Array<number>} pValueSet - The array of values to calculate the average of.
|
|
3791
|
+
* @returns {number} The precise average of the values.
|
|
3792
|
+
*/},{key:"averagePrecise",value:function averagePrecise(pValueSet){return this.meanPrecise(pValueSet);}/**
|
|
3793
|
+
* Calculates the precise median value of a given value set.
|
|
3794
|
+
*
|
|
3795
|
+
* @param {Array<number>} pValueSet - The array of values to calculate the median from.
|
|
3796
|
+
* @returns {number|string} - The median value of the given value set. If the value set is empty, returns '0.0'.
|
|
3797
|
+
*/},{key:"medianPrecise",value:function medianPrecise(pValueSet){var tmpCount=this.countSetElements(pValueSet);// If there are no elements, return 0 ... should this be NaN?
|
|
3798
|
+
if(tmpCount==0){return'0.0';}var tmpSortedValueSet=this.sortSetPrecise(pValueSet);var tmpMiddleElement=Math.floor(tmpCount/2);// If the count is odd, return the middle element
|
|
3799
|
+
if(tmpCount%2==1){return tmpSortedValueSet[tmpMiddleElement];}// If the count is even, return the average of the two middle elements
|
|
3800
|
+
else{var tmpLeftMiddleValue=tmpSortedValueSet[tmpMiddleElement-1];var tmpRightMiddleValue=tmpSortedValueSet[tmpMiddleElement];return this.dividePrecise(this.addPrecise(tmpLeftMiddleValue,tmpRightMiddleValue),2);}}/**
|
|
3801
|
+
* Calculates the mode (most frequently occurring value) of a given value set using precise mode calculation.
|
|
3802
|
+
*
|
|
3803
|
+
* @param {Array} pValueSet - The array of values to calculate the mode from.
|
|
3804
|
+
* @returns {Array} - An array containing the mode value(s) from the given value set.
|
|
3805
|
+
*/},{key:"modePrecise",value:function modePrecise(pValueSet){var tmpHistogram=this.bucketSetPrecise(pValueSet);var tmpMaxCount=0;// Philosophical question about whether the values should be returned sorted.
|
|
3806
|
+
var tmpHistogramValueSet=Object.keys(tmpHistogram);var tmpModeValueSet=[];for(var i=0;i<tmpHistogramValueSet.length;i++){if(tmpHistogram[tmpHistogramValueSet[i]]>tmpMaxCount){tmpMaxCount=tmpHistogram[tmpHistogramValueSet[i]];tmpModeValueSet=[tmpHistogramValueSet[i]];}else if(tmpHistogram[tmpHistogramValueSet[i]]==tmpMaxCount){tmpModeValueSet.push(tmpHistogramValueSet[i]);}}return tmpModeValueSet;}}]);return FableServiceMath;}(libFableServiceBase);module.exports=FableServiceMath;},{"fable-serviceproviderbase":51}],145:[function(require,module,exports){var libFableServiceBase=require('fable-serviceproviderbase');/**
|
|
3636
3807
|
* Precedent Meta-Templating
|
|
3637
3808
|
* @author Steven Velozo <steven@velozo.com>
|
|
3638
3809
|
* @description Process text stream trie and postfix tree, parsing out meta-template expression functions.
|
|
3639
|
-
*/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
|
|
3810
|
+
*/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 _this34;_classCallCheck2(this,FableServiceMetaTemplate);_this34=_callSuper(this,FableServiceMetaTemplate,[pFable,pOptions,pServiceHash]);_this34.serviceType='MetaTemplate';_this34.WordTree=new libWordTree();_this34.StringParser=new libStringParser(_this34.fable);_this34.ParseTree=_this34.WordTree.ParseTree;return _this34;}_createClass2(FableServiceMetaTemplate,[{key:"addPattern",value:function addPattern(pPatternStart,pPatternEnd,pParser,pParserContext){return this.WordTree.addPattern(pPatternStart,pPatternEnd,pParser,pParserContext);}},{key:"addPatternBoth",value:function addPatternBoth(pPatternStart,pPatternEnd,pParser,pParserPromise,pParserContext){return this.WordTree.addPatternBoth(pPatternStart,pPatternEnd,pParser,pParserPromise,pParserContext);}/**
|
|
3640
3811
|
* Parse a string with the existing parse tree
|
|
3641
3812
|
* @method parseString
|
|
3642
3813
|
* @param {string} pString - The string to parse
|
|
@@ -3691,10 +3862,10 @@ var _tmpFunctionContext='ParserContext'in pParserState.Pattern?pParserState.Patt
|
|
|
3691
3862
|
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)....
|
|
3692
3863
|
if(!pParserState.PatternMatch){// This may be the start of a new pattern....
|
|
3693
3864
|
if(pCharacter in pParserState.ParseTree){// ... assign the root node as the matched node.
|
|
3694
|
-
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
|
|
3865
|
+
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 _this35=this;// ... this is the end of a pattern, cut off the end tag and parse it.
|
|
3695
3866
|
// Trim the start and end tags off the output buffer now
|
|
3696
3867
|
if(pParserState.Pattern.isAsync){// Run the function
|
|
3697
|
-
var tmpFunctionContext='ParserContext'in pParserState.Pattern?pParserState.Pattern.ParserContext:false;if(tmpFunctionContext){return pParserState.Pattern.ParseAsync.call(tmpFunctionContext,pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){
|
|
3868
|
+
var tmpFunctionContext='ParserContext'in pParserState.Pattern?pParserState.Pattern.ParserContext:false;if(tmpFunctionContext){return pParserState.Pattern.ParseAsync.call(tmpFunctionContext,pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){_this35.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this35.resetOutputBuffer(pParserState);return fCallback();},pDataContext);}else{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){_this35.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this35.resetOutputBuffer(pParserState);return fCallback();},pDataContext);}}else{// Run the t*mplate function
|
|
3698
3869
|
var _tmpFunctionContext2='ParserContext'in pParserState.Pattern?pParserState.Pattern.ParserContext:false;if(_tmpFunctionContext2){pParserState.OutputBuffer=pParserState.Pattern.Parse.call(_tmpFunctionContext2,pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,pDataContext);}else{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();}}/**
|
|
3699
3870
|
* Parse a character in the buffer.
|
|
3700
3871
|
* @method parseCharacterAsync
|
|
@@ -3727,11 +3898,11 @@ return fCallback();}/**
|
|
|
3727
3898
|
* @param {Object} pData - The data to pass to the function as a second parameter
|
|
3728
3899
|
* @param {function} fCallback - The callback function to call when the parse is complete
|
|
3729
3900
|
* @param {array} pDataContext - The history of data objects/context already passed in
|
|
3730
|
-
*/},{key:"parseString",value:function parseString(pString,pParseTree,pData,fCallback,pDataContext){var
|
|
3901
|
+
*/},{key:"parseString",value:function parseString(pString,pParseTree,pData,fCallback,pDataContext){var _this36=this;// TODO: There is danger here if a template function attempts to functionally recurse and doesn't pass this in.
|
|
3731
3902
|
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.
|
|
3732
3903
|
this.parseCharacter(pString[i],tmpParserState,pData,tmpDataContext);}this.flushOutputBuffer(tmpParserState);return tmpParserState.Output;}else{// This is the async mode
|
|
3733
|
-
var _tmpParserState=this.newParserState(pParseTree);_tmpParserState.Asynchronous=true;var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');var _loop=function _loop(
|
|
3734
|
-
|
|
3904
|
+
var _tmpParserState=this.newParserState(pParseTree);_tmpParserState.Asynchronous=true;var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');var _loop=function _loop(_i34){tmpAnticipate.anticipate(function(fCallback){_this36.parseCharacterAsync(pString[_i34],_tmpParserState,pData,fCallback,tmpDataContext);});};for(var _i34=0;_i34<pString.length;_i34++){_loop(_i34);}tmpAnticipate.wait(function(pError){// Flush the remaining data
|
|
3905
|
+
_this36.flushOutputBuffer(_tmpParserState);return fCallback(pError,_tmpParserState.Output);});}}}]);return StringParser;}();module.exports=StringParser;},{}],147:[function(require,module,exports){/**
|
|
3735
3906
|
* Word Tree
|
|
3736
3907
|
* @author Steven Velozo <steven@velozo.com>
|
|
3737
3908
|
* @description Create a tree (directed graph) of Javascript objects, one character per object.
|
|
@@ -3760,20 +3931,20 @@ _this35.flushOutputBuffer(_tmpParserState);return fCallback(pError,_tmpParserSta
|
|
|
3760
3931
|
* @param {Object} pParserContext - The context to pass to the parser function
|
|
3761
3932
|
* @return {Object} The leaf parser from the tree
|
|
3762
3933
|
*/},{key:"addPatternBoth",value:function addPatternBoth(pPatternStart,pPatternEnd,fParser,fParserAsync,pParserContext){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
|
|
3763
|
-
for(var i=0;i<pPatternStart.length;i++){tmpLeaf=this.addChild(tmpLeaf,pPatternStart[i],i);}if(!('PatternEnd'in tmpLeaf)){tmpLeaf.PatternEnd={};}var tmpPatternEnd=typeof pPatternEnd==='string'?pPatternEnd:pPatternStart;for(var
|
|
3934
|
+
for(var i=0;i<pPatternStart.length;i++){tmpLeaf=this.addChild(tmpLeaf,pPatternStart[i],i);}if(!('PatternEnd'in tmpLeaf)){tmpLeaf.PatternEnd={};}var tmpPatternEnd=typeof pPatternEnd==='string'?pPatternEnd:pPatternStart;for(var _i35=0;_i35<tmpPatternEnd.length;_i35++){tmpLeaf=this.addEndChild(tmpLeaf,tmpPatternEnd[_i35],_i35);}tmpLeaf.PatternStartString=pPatternStart;tmpLeaf.PatternEndString=tmpPatternEnd;tmpLeaf.Parse=typeof fParser==='function'?fParser:typeof fParser==='string'?function(pHash,pData){return fParser;}:function(pHash,pData){return pHash;};tmpLeaf.ParseAsync=typeof fParserAsync==='function'?fParserAsync:typeof fParserAsync==='string'?function(pHash,pData,fCallback){return fCallback(null,fParserAsync);}:function(pHash,pData,fCallback){return fCallback(null,tmpLeaf.Parse(pHash,pData));};// A "this" for every object
|
|
3764
3935
|
if(pParserContext){tmpLeaf.ParserContext=pParserContext;}tmpLeaf.isAsync=true;return tmpLeaf;}/** Add a Pattern to the Parse Tree with both function parameter types
|
|
3765
3936
|
* @method addPatternAll
|
|
3766
3937
|
* @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
|
|
3767
3938
|
* @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
|
|
3768
3939
|
* @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.
|
|
3769
3940
|
* @param {Object} pParserContext - The context to pass to the parser function
|
|
3770
|
-
*/},{key:"addPattern",value:function addPattern(pPatternStart,pPatternEnd,fParser,pParserContext){return this.addPatternBoth(pPatternStart,pPatternEnd,fParser,null,pParserContext);}}]);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
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
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(
|
|
3775
|
-
tmpAnticipate.anticipate(
|
|
3776
|
-
tmpAnticipate.wait(function(pError){if(pError){
|
|
3941
|
+
*/},{key:"addPattern",value:function addPattern(pPatternStart,pPatternEnd,fParser,pParserContext){return this.addPatternBoth(pPatternStart,pPatternEnd,fParser,null,pParserContext);}}]);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 _this37;_classCallCheck2(this,FableOperation);_this37=_callSuper(this,FableOperation,[pFable,pOptions,pServiceHash]);// Timestamps will just be the long ints
|
|
3942
|
+
_this37.timeStamps={};_this37.serviceType='PhasedOperation';_this37.state=JSON.parse(_OperationStatePrototypeString);_this37.stepMap={};_this37.stepFunctions={};// Match the service instantiation to the operation.
|
|
3943
|
+
_this37.state.Metadata.Hash=_this37.Hash;_this37.state.Metadata.UUID=_this37.UUID;_this37.state.Metadata.Name=typeof _this37.options.Name=='string'?_this37.options.Name:"Unnamed Operation ".concat(_this37.state.Metadata.UUID);_this37.name=_this37.state.Metadata.Name;_this37.progressTrackerSet=_this37.fable.instantiateServiceProviderWithoutRegistration('ProgressTrackerSet');_this37.state.OverallProgressTracker=_this37.progressTrackerSet.createProgressTracker("Overall-".concat(_this37.state.Metadata.UUID));// This is here to use the pass-through logging functions in the operation itself.
|
|
3944
|
+
_this37.log=_assertThisInitialized(_this37);return _this37;}_createClass2(FableOperation,[{key:"execute",value:function execute(fExecutionCompleteCallback){var _this38=this;// TODO: Should the same operation be allowed to execute more than one time?
|
|
3945
|
+
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(_this38));// Steps are executed in a custom context with
|
|
3946
|
+
tmpAnticipate.anticipate(_this38.stepFunctions[_this38.state.Steps[i].GUIDStep].bind({log:_this38,fable:_this38.fable,options:_this38.state.Steps[i].Metadata,metadata:_this38.state.Steps[i].Metadata,ProgressTracker:_this38.progressTrackerSet.getProgressTracker(_this38.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(_this38),OperationState:_this38.state,StepState:_this38.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(_this38));};for(var i=0;i<this.state.Steps.length;i++){_loop2(i);}// Wait for the anticipation to complete
|
|
3947
|
+
tmpAnticipate.wait(function(pError){if(pError){_this38.fable.log.error("Operation [".concat(_this38.state.Metadata.UUID,"] ").concat(_this38.state.Metadata.Name," had an error: ").concat(pError),pError);return fExecutionCompleteCallback(pError);}_this38.info("Operation [".concat(_this38.state.Metadata.UUID,"] ").concat(_this38.state.Metadata.Name," complete."));var tmpOperationTimingMessage=_this38.progressTrackerSet.getProgressTrackerStatusString(_this38.state.OverallProgressTracker.Hash);_this38.progressTrackerSet.endProgressTracker(_this38.state.OverallProgressTracker.Hash);_this38.fable.log.info("Operation [".concat(_this38.state.Metadata.UUID,"] ").concat(tmpOperationTimingMessage,"."));return fExecutionCompleteCallback();});}// There are three ways to add steps:
|
|
3777
3948
|
// 1. As a basic javascript function
|
|
3778
3949
|
// --
|
|
3779
3950
|
// This is the most basic, java"script" way to add a step. It will
|
|
@@ -3782,11 +3953,11 @@ tmpAnticipate.wait(function(pError){if(pError){_this37.fable.log.error("Operatio
|
|
|
3782
3953
|
},{key:"addStep",value:function addStep(fStepFunction,pStepMetadata,pStepName,pStepDescription,pGUIDStep){var tmpStep={};// GUID is optional
|
|
3783
3954
|
tmpStep.GUIDStep=typeof pGUIDStep!=='undefined'?pGUIDStep:"STEP-".concat(this.state.Steps.length,"-").concat(this.fable.DataGeneration.randomNumericString());// Name is optional
|
|
3784
3955
|
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
|
|
3785
|
-
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(!(pGUIDStep in this.stepMap)){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
|
|
3956
|
+
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(!(pGUIDStep in this.stepMap)){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 _this39;_classCallCheck2(this,FableServiceProgressTime);_this39=_callSuper(this,FableServiceProgressTime,[pFable,pOptions,pServiceHash]);_this39.serviceType='ProgressTime';_this39.timeStamps={};return _this39;}_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 tmpTimeStampHash in this.timeStamps?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.
|
|
3786
3957
|
if(typeof pReferenceTime=='string'){tmpReferenceTime=tmpReference in this.timeStamps?this.timeStamps[tmpReference]:false;}else if(typeof pReferenceTime=='number'){tmpReferenceTime=pReferenceTime;}else{tmpReferenceTime=+new Date();}if(tmpTimeStampHash in this.timeStamps&&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(tmpTimeStampHash in this.timeStamps){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.
|
|
3787
|
-
if(typeof pReferenceTime=='string'){tmpReferenceTime=tmpReference in this.timeStamps?this.timeStamps[tmpReference]:false;}else if(typeof pReferenceTime=='number'){tmpReferenceTime=pReferenceTime;}else{tmpReferenceTime=+new Date();}if(tmpTimeStampHash in this.timeStamps&&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(tmpTimeStampHashStart in this.timeStamps&&tmpTimeStampHashEnd in this.timeStamps){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
|
|
3788
|
-
|
|
3789
|
-
|
|
3958
|
+
if(typeof pReferenceTime=='string'){tmpReferenceTime=tmpReference in this.timeStamps?this.timeStamps[tmpReference]:false;}else if(typeof pReferenceTime=='number'){tmpReferenceTime=pReferenceTime;}else{tmpReferenceTime=+new Date();}if(tmpTimeStampHash in this.timeStamps&&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(tmpTimeStampHashStart in this.timeStamps&&tmpTimeStampHashEnd in this.timeStamps){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 _this40;_classCallCheck2(this,FableServiceProgressTrackerSet);_this40=_callSuper(this,FableServiceProgressTrackerSet,[pFable,pOptions,pServiceHash]);_this40.serviceType='ProgressTrackerSet';_this40.progressTrackers={};// Create an internal PorgressTime service to track timestamps
|
|
3959
|
+
_this40.progressTimes=_this40.fable.instantiateServiceProviderWithoutRegistration('ProgressTime');// This timestamp is used and updated by *all* progress trackers.
|
|
3960
|
+
_this40.progressTimes.createTimeStamp('CurrentTime');return _this40;}_createClass2(FableServiceProgressTrackerSet,[{key:"getProgressTracker",value:function getProgressTracker(pProgressTrackerHash){var tmpProgressTrackerHash=typeof pProgressTrackerHash=='string'?pProgressTrackerHash:'Default';if(!(tmpProgressTrackerHash in this.progressTrackers)){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(!(tmpProgressTrackerHash in this.progressTrackers)){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%
|
|
3790
3961
|
AllowTruePercentComplete:false,ElapsedTime:-1,AverageOperationTime:-1,EstimatedCompletionTime:-1,TotalCount:tmpTotalOperations,CurrentCount:-1};if(tmpProgressTrackerHash in this.progressTrackers){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(!(tmpProgressTrackerHash in this.progressTrackers)){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
|
|
3791
3962
|
if(!(tmpProgressTrackerHash in this.progressTrackers)){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(!(tmpProgressTrackerHash in this.progressTrackers)){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(!(tmpProgressTrackerHash in this.progressTrackers)){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.
|
|
3792
3963
|
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
|
|
@@ -3807,20 +3978,20 @@ this.solveProgressTrackerStatus(tmpProgressTrackerHash);if(!(tmpProgressTrackerH
|
|
|
3807
3978
|
if(tmpProgressTracker.StartTimeStamp<1){return"ProgressTracker ".concat(tmpProgressTracker.Hash," has not been started yet.");}// 2. Started, but no operations completed
|
|
3808
3979
|
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
|
|
3809
3980
|
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
|
|
3810
|
-
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
|
|
3981
|
+
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 _this41;_classCallCheck2(this,FableServiceRestClient);_this41=_callSuper(this,FableServiceRestClient,[pFable,pOptions,pServiceHash]);_this41.TraceLog=false;if(_this41.options.TraceLog||_this41.fable.TraceLog){_this41.TraceLog=true;}_this41.dataFormat=_this41.fable.services.DataFormat;_this41.serviceType='RestClient';_this41.cookie=false;// This is a function that can be overridden, to allow the management
|
|
3811
3982
|
// of the request options before they are passed to the request library.
|
|
3812
|
-
|
|
3983
|
+
_this41.prepareRequestOptions=function(pOptions){return pOptions;};return _this41;}_createClass2(FableServiceRestClient,[{key:"simpleGet",get:function get(){return libSimpleGet;}},{key:"prepareCookies",value:function prepareCookies(pRequestOptions){if(this.cookie){var tmpCookieObject=this.cookie;if(!('headers'in pRequestOptions)){pRequestOptions.headers={};}var tmpCookieKeys=Object.keys(tmpCookieObject);if(tmpCookieKeys.length>0){// Only grab the first for now.
|
|
3813
3984
|
pRequestOptions.headers.cookie=libCookie.serialize(tmpCookieKeys[0],tmpCookieObject[tmpCookieKeys[0]]);}}return pRequestOptions;}},{key:"preRequest",value:function preRequest(pOptions){// Validate the options object
|
|
3814
3985
|
var tmpOptions=this.prepareCookies(pOptions);// Prepend a string to the URL if it exists in the Fable Config
|
|
3815
|
-
if('RestClientURLPrefix'in this.fable.settings){tmpOptions.url=this.fable.settings.RestClientURLPrefix+tmpOptions.url;}return this.prepareRequestOptions(tmpOptions);}},{key:"executeChunkedRequest",value:function executeChunkedRequest(pOptions,fCallback){var
|
|
3816
|
-
if(
|
|
3817
|
-
if(
|
|
3818
|
-
if(!tmpDataBuffer){tmpDataBuffer=Buffer.from(pChunk);}else{tmpDataBuffer=Buffer.concat([tmpDataBuffer,pChunk]);}});pResponse.on('end',function(){if(
|
|
3986
|
+
if('RestClientURLPrefix'in this.fable.settings){tmpOptions.url=this.fable.settings.RestClientURLPrefix+tmpOptions.url;}return this.prepareRequestOptions(tmpOptions);}},{key:"executeChunkedRequest",value:function executeChunkedRequest(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));}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 tmpData='';pResponse.on('data',function(pChunk){// For JSON, the chunk is the serialized object.
|
|
3987
|
+
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"));}tmpData+=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(tmpData.length,"b received in ").concat(_this42.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpCompletionTime),"ms"));}return fCallback(pError,pResponse,tmpData);});});}},{key:"executeChunkedRequestBinary",value:function executeChunkedRequestBinary(pOptions,fCallback){var _this43=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(_this43.TraceLog){var tmpConnectTime=_this43.fable.log.getTimeStamp();_this43.fable.log.debug("--> ".concat(tmpOptions.method," connected in ").concat(_this43.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.
|
|
3988
|
+
if(_this43.TraceLog){var tmpChunkTime=_this43.fable.log.getTimeStamp();_this43.fable.log.debug("--> ".concat(tmpOptions.method," data chunk size ").concat(pChunk.length,"b received in ").concat(_this43.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.
|
|
3989
|
+
if(!tmpDataBuffer){tmpDataBuffer=Buffer.from(pChunk);}else{tmpDataBuffer=Buffer.concat([tmpDataBuffer,pChunk]);}});pResponse.on('end',function(){if(_this43.TraceLog){var tmpCompletionTime=_this43.fable.log.getTimeStamp();_this43.fable.log.debug("==> ".concat(tmpOptions.method," completed data size ").concat(tmpDataBuffer.length,"b received in ").concat(_this43.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpCompletionTime),"ms"));}return fCallback(pError,pResponse,tmpDataBuffer);});});}},{key:"executeJSONRequest",value:function executeJSONRequest(pOptions,fCallback){var _this44=this;pOptions.json=true;var tmpOptions=this.preRequest(pOptions);if(!('headers'in tmpOptions)){tmpOptions.headers={};}/* Automated headers break some APIs
|
|
3819
3990
|
if (!('Content-Type' in tmpOptions.headers))
|
|
3820
3991
|
{
|
|
3821
3992
|
tmpOptions.headers['Content-Type'] = 'application/json';
|
|
3822
3993
|
}
|
|
3823
|
-
*/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(
|
|
3994
|
+
*/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(_this44.TraceLog){var tmpConnectTime=_this44.fable.log.getTimeStamp();_this44.fable.log.debug("--> JSON ".concat(tmpOptions.method," connected in ").concat(_this44.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpConnectTime),"ms code ").concat(pResponse.statusCode));}var tmpJSONData='';pResponse.on('data',function(pChunk){if(_this44.TraceLog){var tmpChunkTime=_this44.fable.log.getTimeStamp();_this44.fable.log.debug("--> JSON ".concat(tmpOptions.method," data chunk size ").concat(pChunk.length,"b received in ").concat(_this44.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime,tmpChunkTime),"ms"));}tmpJSONData+=pChunk;});pResponse.on('end',function(){if(_this44.TraceLog){var tmpCompletionTime=_this44.fable.log.getTimeStamp();_this44.fable.log.debug("==> JSON ".concat(tmpOptions.method," completed - received in ").concat(_this44.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
|
|
3824
3995
|
// string-based template with code snippets into simple executable pieces,
|
|
3825
3996
|
// with the added twist of returning a precompiled function ready to go.
|
|
3826
3997
|
//
|
|
@@ -3829,16 +4000,16 @@ if(!tmpDataBuffer){tmpDataBuffer=Buffer.from(pChunk);}else{tmpDataBuffer=Buffer.
|
|
|
3829
4000
|
//
|
|
3830
4001
|
// This is an implementation of that.
|
|
3831
4002
|
// TODO: Make this use precedent, add configuration, add debugging.
|
|
3832
|
-
function FableServiceTemplate(pFable,pOptions,pServiceHash){var
|
|
4003
|
+
function FableServiceTemplate(pFable,pOptions,pServiceHash){var _this45;_classCallCheck2(this,FableServiceTemplate);_this45=_callSuper(this,FableServiceTemplate,[pFable,pOptions,pServiceHash]);_this45.serviceType='Template';// These are the exact regex's used in lodash/underscore
|
|
3833
4004
|
// TODO: Switch this to precedent
|
|
3834
|
-
|
|
4005
|
+
_this45.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.
|
|
3835
4006
|
GuaranteedNonMatch:/.^/};// This is a helper for the escaper and unescaper functions.
|
|
3836
4007
|
// Right now we are going to keep what underscore is doing, but, not forever.
|
|
3837
|
-
|
|
4008
|
+
_this45.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
|
|
3838
4009
|
// function on this class.
|
|
3839
|
-
|
|
4010
|
+
_this45.renderFunction=false;_this45.templateString=false;return _this45;}_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 _this46=this;// For now this is being kept in a weird form ... this is to mimic the old
|
|
3840
4011
|
// underscore code until this is rewritten using precedent.
|
|
3841
|
-
this.TemplateSource="__p+='"+pTemplateText.replace(this.Matchers.Escaper,function(pMatch){return"\\".concat(
|
|
4012
|
+
this.TemplateSource="__p+='"+pTemplateText.replace(this.Matchers.Escaper,function(pMatch){return"\\".concat(_this46.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
|
|
3842
4013
|
// precompilation.
|
|
3843
4014
|
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
|
|
3844
4015
|
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
|
|
@@ -3850,8 +4021,8 @@ var libAsyncWaterfall=require('async.waterfall');var libAsyncEachLimit=require('
|
|
|
3850
4021
|
//
|
|
3851
4022
|
// This is an implementation of that.
|
|
3852
4023
|
// TODO: Make this use precedent, add configuration, add debugging.
|
|
3853
|
-
function FableServiceUtility(pFable,pOptions,pServiceHash){var
|
|
3854
|
-
|
|
4024
|
+
function FableServiceUtility(pFable,pOptions,pServiceHash){var _this47;_classCallCheck2(this,FableServiceUtility);_this47=_callSuper(this,FableServiceUtility,[pFable,pOptions,pServiceHash]);_this47.templates={};// These two functions are used extensively throughout
|
|
4025
|
+
_this47.waterfall=libAsyncWaterfall;_this47.eachLimit=libAsyncEachLimit;_this47.bigNumber=libBigNumber;return _this47;}// Underscore and lodash have a behavior, _.extend, which merges objects.
|
|
3855
4026
|
// Now that es6 gives us this, use the native thingy.
|
|
3856
4027
|
// Nevermind, the native thing is not stable enough across environments
|
|
3857
4028
|
// Basic shallow copy
|