fable 3.0.123 → 3.0.125

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 CHANGED
@@ -1,24 +1,63 @@
1
+ //let libBookstore = require('../retold-harness/bookstore-serve-meadow-endpoint-apis-run.js');
2
+ const libFable = require('../source/Fable.js');
1
3
 
4
+ let testFable = new libFable({"Product": "ProgressTrackerExample"});
2
5
 
3
- testFable.addServiceType('SimpleService', SimpleService);
4
6
 
5
- testFable.instantiateServiceProvider('SimpleService', {SomeOption: true}, 'SimpleService-123');
7
+ let tmpTestArray = [
8
+ {Name:'Jimbo', Age: 12},
9
+ {Name:'Susan', Age: 17},
10
+ {Name:'Chris', Age: 15},
11
+ {Name:'Reginald', Age: 19},
12
+ {Name:'Wendy', Age: 14},
13
+ {Name:'Dwight', Age: 16},
14
+ {Name:'Jimbo2', Age: 18},
15
+ {Name:'Susan2', Age: 13},
16
+ {Name:'Chris2', Age: 15},
17
+ {Name:'Reginald2', Age: 19}
18
+ ];
6
19
 
20
+ let tmpProgressTracker = testFable.instantiateServiceProvider('ProgressTrackerSet');
7
21
 
8
- testFable.servicesMap['SimpleService']['SimpleService-123'].doSomething();
22
+ let tmpTestIterations = 50000000;
23
+ // How many interstitial messages we want.
24
+ let tmpMessageChunkSize = tmpTestIterations / 5;
9
25
 
10
- testFable.SimpleService.doSomething();
26
+ tmpProgressTracker.createProgressTracker('ArrayFromPerformance', tmpTestIterations);
27
+ tmpProgressTracker.logProgressTrackerStatus('ArrayFromPerformance');
28
+ for (let i = 0; i < tmpTestIterations; i++)
29
+ {
30
+ let tmpArray = Array.from(tmpTestArray);
31
+ tmpArray.push({Name:'NewGuy', Age: 21});
11
32
 
12
- console.log(`Initialized Service ${testFable.servicesMap['SimpleService']['SimpleService-123'].serviceType} as UUID ${testFable.servicesMap['SimpleService']['SimpleService-123'].UUID} with hash ${testFable.servicesMap['SimpleService']['SimpleService-123'].Hash}`);
33
+ tmpProgressTracker.incrementProgressTracker('ArrayFromPerformance', 1);
13
34
 
14
- testFable.servicesMap['SimpleService']['SimpleService-123'].doSomething();
35
+ if (i % tmpMessageChunkSize == 0)
36
+ {
37
+ tmpProgressTracker.logProgressTrackerStatus('ArrayFromPerformance');
38
+ }
39
+ }
40
+ tmpProgressTracker.endProgressTracker('ArrayFromPerformance');
41
+ tmpProgressTracker.logProgressTrackerStatus('ArrayFromPerformance');
42
+
43
+ tmpProgressTracker.createProgressTracker('ForLoopPerformance', tmpTestIterations);
44
+ tmpProgressTracker.logProgressTrackerStatus('ForLoopPerformance');
45
+ for (let i = 0; i < tmpTestIterations; i++)
46
+ {
47
+ let tmpArray = [];
48
+ for (let j = 0; j < tmpTestArray.length; j++)
49
+ {
50
+ tmpArray.push(tmpTestArray[j]);
51
+ }
52
+ tmpArray.push({Name:'NewGuy', Age: 21});
15
53
 
16
- // Instantiate the RestClient Service Provider
17
- let tmpRestClient = testFable.instantiateServiceProvider('RestClient', {TraceLog: true}, 'RestClient-99');
54
+ tmpProgressTracker.incrementProgressTracker('ForLoopPerformance', 1);
18
55
 
19
- // Download the wiktionary entry for dog!
20
- tmpRestClient.getJSON('https://en.wiktionary.org/w/api.php?action=parse&prop=wikitext&format=json&page=dog',
21
- (pError, pResponse, pBody)=>
56
+ if (i % tmpMessageChunkSize == 0)
22
57
  {
23
- testFable.log.info('Response received~', pBody);
24
- });
58
+ tmpProgressTracker.logProgressTrackerStatus('ForLoopPerformance');
59
+ }
60
+ }
61
+ tmpProgressTracker.endProgressTracker('ForLoopPerformance');
62
+ tmpProgressTracker.logProgressTrackerStatus('ForLoopPerformance');
63
+
@@ -3019,12 +3019,12 @@ _this17.connectFable(_assertThisInitialized(_this17));// --> Bootstrapping of fa
3019
3019
  _this17.connectPreinitServiceProviderInstance(_this17.UUID);_this17.connectPreinitServiceProviderInstance(_this17.Logging);_this17.connectPreinitServiceProviderInstance(_this17.SettingsManager);// Initialize and instantiate the default baked-in Data Arithmatic service
3020
3020
  _this17.addAndInstantiateServiceType('EnvironmentData',require('./services/Fable-Service-EnvironmentData.js'));_this17.addServiceType('Template',require('./services/Fable-Service-Template.js'));_this17.addServiceType('MetaTemplate',require('./services/Fable-Service-MetaTemplate.js'));_this17.addServiceType('Anticipate',require('./services/Fable-Service-Anticipate.js'));_this17.addAndInstantiateServiceType('Dates',require('./services/Fable-Service-DateManipulation.js'));_this17.addAndInstantiateServiceType('DataFormat',require('./services/Fable-Service-DataFormat.js'));_this17.addAndInstantiateServiceType('DataGeneration',require('./services/Fable-Service-DataGeneration.js'));_this17.addAndInstantiateServiceType('Utility',require('./services/Fable-Service-Utility.js'));_this17.addAndInstantiateServiceType('Math',require('./services/Fable-Service-Math.js'));_this17.addServiceType('RestClient',require('./services/Fable-Service-RestClient.js'));_this17.addServiceType('Manifest',require('manyfest'));_this17.addServiceType('ObjectCache',require('cachetrax'));_this17.addAndInstantiateServiceType('ProgressTime',require('./services/Fable-Service-ProgressTime.js'));_this17.addServiceType('ProgressTrackerSet',require('./services/Fable-Service-ProgressTrackerSet.js'));_this17.addServiceType('Operation',require('./services/Fable-Service-Operation.js'));_this17.addServiceType('CSVParser',require('./services/Fable-Service-CSVParser.js'));_this17.addServiceType('FilePersistence',require('./services/Fable-Service-FilePersistence.js'));return _this17;}/* State Accessors */_createClass2(Fable,[{key:"isFable",get:function get(){return true;}},{key:"settings",get:function get(){return this.SettingsManager.settings;}},{key:"settingsManager",get:function get(){return this.SettingsManager;}// For backwards compatibility
3021
3021
  },{key:"getUUID",value:function getUUID(){return this.UUID.getUUID();}},{key:"newAnticipate",value:function newAnticipate(){return this.instantiateServiceProviderWithoutRegistration('Anticipate');}/* Service Manager Methods */},{key:"addServiceType",value:function addServiceType(pServiceType,pServiceClass){if(this.servicesMap.hasOwnProperty(pServiceType)){// TODO: Check if any services are running?
3022
- this.log.warn("Adding a service type [".concat(pServiceType,"] that already exists."));}else{// Add the container for instantiated services to go in
3022
+ this.log.warn("Adding a service type [".concat(pServiceType,"] that already exists. This will change the default class prototype for this service."));}else{// Add the container for instantiated services to go in
3023
3023
  this.servicesMap[pServiceType]={};// Add the type to the list of types
3024
3024
  this.serviceTypes.push(pServiceType);}// Using the static member of the class is a much more reliable way to check if it is a service class than instanceof
3025
3025
  if(typeof pServiceClass=='function'&&pServiceClass.isFableService){// Add the class to the list of classes
3026
3026
  this.serviceClasses[pServiceType]=pServiceClass;}else{// Add the base class to the list of classes
3027
- this.log.error("Attempted to add service type [".concat(pServiceType,"] with an invalid class. Using base service class, which will not crash but won't provide meaningful services."));this.serviceClasses[pServiceType]=libFableServiceBase;}}// This is for the services that are meant to run mostly single-instance so need a default at initialization
3027
+ this.log.error("Attempted to add service type [".concat(pServiceType,"] with an invalid class. Using base service class, which will not crash but won't provide meaningful services."));this.serviceClasses[pServiceType]=libFableServiceBase;}return this.serviceClasses[pServiceType];}},{key:"addServiceTypeIfNotExists",value:function addServiceTypeIfNotExists(pServiceType,pServiceClass){if(!this.servicesMap.hasOwnProperty(pServiceType)){return this.addServiceType(pServiceType,pServiceClass);}else{return this.serviceClasses[pServiceType];}}// This is for the services that are meant to run mostly single-instance so need a default at initialization
3028
3028
  },{key:"addAndInstantiateServiceType",value:function addAndInstantiateServiceType(pServiceType,pServiceClass){this.addServiceType(pServiceType,pServiceClass);return this.instantiateServiceProvider(pServiceType,{},"".concat(pServiceType,"-Default"));}// Some services expect to be overloaded / customized class.
3029
3029
  },{key:"instantiateServiceProviderFromPrototype",value:function instantiateServiceProviderFromPrototype(pServiceType,pOptions,pCustomServiceHash,pServicePrototype){// Instantiate the service
3030
3030
  var tmpService=new pServicePrototype(this,pOptions,pCustomServiceHash);if(this.extraServiceInitialization){tmpService=this.extraServiceInitialization(tmpService);}// Add the service to the service map
@@ -3032,7 +3032,7 @@ this.servicesMap[pServiceType][tmpService.Hash]=tmpService;// If this is the fir
3032
3032
  if(!this.services.hasOwnProperty(pServiceType)){this.setDefaultServiceInstantiation(pServiceType,tmpService.Hash);}return tmpService;}},{key:"instantiateServiceProvider",value:function instantiateServiceProvider(pServiceType,pOptions,pCustomServiceHash){// Instantiate the service
3033
3033
  var tmpService=this.instantiateServiceProviderWithoutRegistration(pServiceType,pOptions,pCustomServiceHash);// Add the service to the service map
3034
3034
  this.servicesMap[pServiceType][tmpService.Hash]=tmpService;// If this is the first service of this type, make it the default
3035
- if(!this.services.hasOwnProperty(pServiceType)){this.setDefaultServiceInstantiation(pServiceType,tmpService.Hash);}return tmpService;}// Create a service provider but don't register it to live forever in fable.services
3035
+ if(!this.services.hasOwnProperty(pServiceType)){this.setDefaultServiceInstantiation(pServiceType,tmpService.Hash);}return tmpService;}},{key:"instantiateServiceProviderIfNotExists",value:function instantiateServiceProviderIfNotExists(pServiceType,pOptions,pCustomServiceHash){if(this.services.hasOwnProperty(pServiceType)){return this.services[pServiceType];}else{return this.instantiateServiceProvider(pServiceType,pOptions,pCustomServiceHash);}}// Create a service provider but don't register it to live forever in fable.services
3036
3036
  },{key:"instantiateServiceProviderWithoutRegistration",value:function instantiateServiceProviderWithoutRegistration(pServiceType,pOptions,pCustomServiceHash){// Instantiate the service
3037
3037
  var tmpService=new this.serviceClasses[pServiceType](this,pOptions,pCustomServiceHash);if(this.extraServiceInitialization){tmpService=this.extraServiceInitialization(tmpService);}return tmpService;}// Connect an initialized service provider that came before Fable was initialized
3038
3038
  },{key:"connectPreinitServiceProviderInstance",value:function connectPreinitServiceProviderInstance(pServiceInstance){var tmpServiceType=pServiceInstance.serviceType;var tmpServiceHash=pServiceInstance.Hash;// The service should already be instantiated, so just connect it to fable
@@ -3381,8 +3381,10 @@ return _this25.makeFolderRecursive(tmpParameters,fCallback);}else{console.log(pC
3381
3381
  * @method parseString
3382
3382
  * @param {string} pString - The string to parse
3383
3383
  * @param {object} pData - Data to pass in as the second argument
3384
+ * @param {function} fCallback - The callback function to call when a pattern is matched
3385
+ * @param {array} pDataContext - The history of data objects already passed in
3384
3386
  * @return {string} The result from the parser
3385
- */},{key:"parseString",value:function parseString(pString,pData,fCallback){if(this.LogNoisiness>4){this.fable.log.trace("Metatemplate parsing template string [".concat(pString,"] where the callback is a ").concat(_typeof(fCallback)),{TemplateData:pData});}return this.StringParser.parseString(pString,this.ParseTree,pData,fCallback);}}]);return FableServiceMetaTemplate;}(libFableServiceBase);module.exports=FableServiceMetaTemplate;},{"./Fable-Service-MetaTemplate/MetaTemplate-StringParser.js":138,"./Fable-Service-MetaTemplate/MetaTemplate-WordTree.js":139,"fable-serviceproviderbase":51}],138:[function(require,module,exports){/**
3387
+ */},{key:"parseString",value:function parseString(pString,pData,fCallback,pDataContext){if(this.LogNoisiness>4){this.fable.log.trace("Metatemplate parsing template string [".concat(pString,"] where the callback is a ").concat(_typeof(fCallback)),{TemplateData:pData});}return this.StringParser.parseString(pString,this.ParseTree,pData,fCallback,pDataContext);}}]);return FableServiceMetaTemplate;}(libFableServiceBase);module.exports=FableServiceMetaTemplate;},{"./Fable-Service-MetaTemplate/MetaTemplate-StringParser.js":138,"./Fable-Service-MetaTemplate/MetaTemplate-WordTree.js":139,"fable-serviceproviderbase":51}],138:[function(require,module,exports){/**
3386
3388
  * String Parser
3387
3389
  * @author Steven Velozo <steven@velozo.com>
3388
3390
  * @description Parse a string, properly processing each matched token in the word tree.
@@ -3414,42 +3416,45 @@ pParserState.Pattern=false;pParserState.PatternStartNode=false;pParserState.Star
3414
3416
  * @param {string} pCharacter - The character to append
3415
3417
  * @param {Object} pParserState - The state object for the current parsing task
3416
3418
  * @private
3417
- */},{key:"parseCharacter",value:function parseCharacter(pCharacter,pParserState,pData){// If we are already in a pattern match traversal
3419
+ */},{key:"parseCharacter",value:function parseCharacter(pCharacter,pParserState,pData,pDataContext){// If we are already in a pattern match traversal
3418
3420
  if(pParserState.PatternMatch){// If the pattern is still matching the start and we haven't passed the buffer
3419
3421
  if(!pParserState.StartPatternMatchComplete&&pParserState.Pattern.hasOwnProperty(pCharacter)){pParserState.Pattern=pParserState.Pattern[pCharacter];this.appendOutputBuffer(pCharacter,pParserState);}else if(pParserState.EndPatternMatchBegan){if(pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter)){// This leaf has a PatternEnd tree, so we will wait until that end is met.
3420
3422
  pParserState.Pattern=pParserState.Pattern.PatternEnd[pCharacter];// Flush the output buffer.
3421
3423
  this.appendOutputBuffer(pCharacter,pParserState);// If this last character is the end of the pattern, parse it.
3422
3424
  if(pParserState.Pattern.hasOwnProperty('Parse')&&(!pParserState.Pattern.isAsync||pParserState.Pattern.isBoth)){// Run the function
3423
- pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData);return this.resetOutputBuffer(pParserState);}else{this.fable.log.info("MetaTemplate: The pattern ".concat(pParserState.Pattern.PatternStartString," is asynchronous and cannot be used in a synchronous parser."));return this.resetOutputBuffer(pParserState);}}else if(pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter)){// We broke out of the end -- see if this is a new start of the end.
3425
+ 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);return this.resetOutputBuffer(pParserState);}else{this.fable.log.info("MetaTemplate: The pattern ".concat(pParserState.Pattern.PatternStartString," is asynchronous and cannot be used in a synchronous parser."));return this.resetOutputBuffer(pParserState);}}else if(pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter)){// We broke out of the end -- see if this is a new start of the end.
3424
3426
  pParserState.Pattern=pParserState.PatternStartNode.PatternEnd[pCharacter];this.appendOutputBuffer(pCharacter,pParserState);}else{pParserState.EndPatternMatchBegan=false;this.appendOutputBuffer(pCharacter,pParserState);}}else if(pParserState.Pattern.hasOwnProperty('PatternEnd')){if(!pParserState.StartPatternMatchComplete){pParserState.StartPatternMatchComplete=true;pParserState.PatternStartNode=pParserState.Pattern;}this.appendOutputBuffer(pCharacter,pParserState);if(pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter)){// This is the first character of the end pattern.
3425
3427
  pParserState.EndPatternMatchBegan=true;// This leaf has a PatternEnd tree, so we will wait until that end is met.
3426
3428
  pParserState.Pattern=pParserState.Pattern.PatternEnd[pCharacter];// If this last character is the end of the pattern, parse it.
3427
3429
  if(pParserState.Pattern.hasOwnProperty('Parse')){if(pParserState.Pattern.isAsync&&!pParserState.Pattern.isBoth){this.fable.log.info("MetaTemplate: The pattern ".concat(pParserState.Pattern.PatternStartString," is asynchronous and cannot be used in a synchronous parser."));this.resetOutputBuffer(pParserState);}else{// Run the t*mplate function
3428
- pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData);return this.resetOutputBuffer(pParserState);}}}}else{// We are in a pattern start but didn't match one; reset and start trying again from this character.
3430
+ 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);return this.resetOutputBuffer(pParserState);}}}}else{// We are in a pattern start but didn't match one; reset and start trying again from this character.
3429
3431
  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)....
3430
3432
  if(!pParserState.PatternMatch){// This may be the start of a new pattern....
3431
3433
  if(pParserState.ParseTree.hasOwnProperty(pCharacter)){// ... assign the root node as the matched node.
3432
- 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){var _this28=this;// ... this is the end of a pattern, cut off the end tag and parse it.
3434
+ this.resetOutputBuffer(pParserState);this.appendOutputBuffer(pCharacter,pParserState);pParserState.Pattern=pParserState.ParseTree[pCharacter];pParserState.PatternMatch=true;return true;}else{this.appendOutputBuffer(pCharacter,pParserState);}}return false;}},{key:"executePatternAsync",value:function executePatternAsync(pParserState,pData,fCallback,pDataContext){var _this28=this;// ... this is the end of a pattern, cut off the end tag and parse it.
3433
3435
  // Trim the start and end tags off the output buffer now
3434
3436
  if(pParserState.Pattern.isAsync&&!pParserState.Pattern.isBoth){// Run the function
3435
- return pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){_this28.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this28.resetOutputBuffer(pParserState);return fCallback();});}else if(pParserState.Pattern.isAsync&&pParserState.Pattern.isBoth){// Run the function when both async and non async were provided with the pattern
3436
- 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){_this28.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this28.resetOutputBuffer(pParserState);return fCallback();});}else{// Run the t*mplate function
3437
- pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData);this.resetOutputBuffer(pParserState);return fCallback();}}/**
3437
+ return pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){_this28.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this28.resetOutputBuffer(pParserState);return fCallback();},pDataContext);}else if(pParserState.Pattern.isAsync&&pParserState.Pattern.isBoth){// Run the function when both async and non async were provided with the pattern
3438
+ return pParserState.Pattern.ParseAsync(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)),pData,function(pError,pAsyncOutput){if(pError){_this28.fable.log.info("Precedent ERROR: Async template error happened parsing ".concat(pParserState.Pattern.PatternStart," ... ").concat(pParserState.Pattern.PatternEnd,": ").concat(pError));}pParserState.OutputBuffer=pAsyncOutput;_this28.resetOutputBuffer(pParserState);return fCallback();},pDataContext);}else{// Run the t*mplate function
3439
+ 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();}}/**
3438
3440
  * Parse a character in the buffer.
3439
- * @method parseCharacter
3441
+ * @method parseCharacterAsync
3440
3442
  * @param {string} pCharacter - The character to append
3441
3443
  * @param {Object} pParserState - The state object for the current parsing task
3444
+ * @param {Object} pData - The data to pass to the function as a second parameter
3445
+ * @param {function} fCallback - The callback function to call when the parse is complete
3446
+ * @param {array} pDataContext - The history of data objects/context already passed in
3442
3447
  * @private
3443
- */},{key:"parseCharacterAsync",value:function parseCharacterAsync(pCharacter,pParserState,pData,fCallback){// If we are already in a pattern match traversal
3448
+ */},{key:"parseCharacterAsync",value:function parseCharacterAsync(pCharacter,pParserState,pData,fCallback,pDataContext){// If we are already in a pattern match traversal
3444
3449
  if(pParserState.PatternMatch){// If the pattern is still matching the start and we haven't passed the buffer
3445
3450
  if(!pParserState.StartPatternMatchComplete&&pParserState.Pattern.hasOwnProperty(pCharacter)){pParserState.Pattern=pParserState.Pattern[pCharacter];this.appendOutputBuffer(pCharacter,pParserState);}else if(pParserState.EndPatternMatchBegan){if(pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter)){// This leaf has a PatternEnd tree, so we will wait until that end is met.
3446
3451
  pParserState.Pattern=pParserState.Pattern.PatternEnd[pCharacter];// Flush the output buffer.
3447
3452
  this.appendOutputBuffer(pCharacter,pParserState);// If this last character is the end of the pattern, parse it.
3448
- if(pParserState.Pattern.hasOwnProperty('Parse')){return this.executePatternAsync(pParserState,pData,fCallback);}}else if(pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter)){// We broke out of the end -- see if this is a new start of the end.
3453
+ if(pParserState.Pattern.hasOwnProperty('Parse')){return this.executePatternAsync(pParserState,pData,fCallback,pDataContext);}}else if(pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter)){// We broke out of the end -- see if this is a new start of the end.
3449
3454
  pParserState.Pattern=pParserState.PatternStartNode.PatternEnd[pCharacter];this.appendOutputBuffer(pCharacter,pParserState);}else{pParserState.EndPatternMatchBegan=false;this.appendOutputBuffer(pCharacter,pParserState);}}else if(pParserState.Pattern.hasOwnProperty('PatternEnd')){if(!pParserState.StartPatternMatchComplete){pParserState.StartPatternMatchComplete=true;pParserState.PatternStartNode=pParserState.Pattern;}this.appendOutputBuffer(pCharacter,pParserState);if(pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter)){// This is the first character of the end pattern.
3450
3455
  pParserState.EndPatternMatchBegan=true;// This leaf has a PatternEnd tree, so we will wait until that end is met.
3451
3456
  pParserState.Pattern=pParserState.Pattern.PatternEnd[pCharacter];// If this last character is the end of the pattern, parse it.
3452
- if(pParserState.Pattern.hasOwnProperty('Parse')){return this.executePatternAsync(pParserState,pData,fCallback);}}}else{// We are in a pattern start but didn't match one; reset and start trying again from this character.
3457
+ if(pParserState.Pattern.hasOwnProperty('Parse')){return this.executePatternAsync(pParserState,pData,fCallback,pDataContext);}}}else{// We are in a pattern start but didn't match one; reset and start trying again from this character.
3453
3458
  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)....
3454
3459
  else{// This may be the start of a new pattern....
3455
3460
  if(pParserState.ParseTree.hasOwnProperty(pCharacter)){// ... assign the root node as the matched node.
@@ -3462,9 +3467,11 @@ return fCallback();}/**
3462
3467
  * @param {Object} pParseTree - The parse tree to begin parsing from (usually root)
3463
3468
  * @param {Object} pData - The data to pass to the function as a second parameter
3464
3469
  * @param {function} fCallback - The callback function to call when the parse is complete
3465
- */},{key:"parseString",value:function parseString(pString,pParseTree,pData,fCallback){var _this29=this;if(typeof fCallback!=='function'){var tmpParserState=this.newParserState(pParseTree);for(var i=0;i<pString.length;i++){// TODO: This is not fast.
3466
- this.parseCharacter(pString[i],tmpParserState,pData,fCallback);}this.flushOutputBuffer(tmpParserState);return tmpParserState.Output;}else{// This is the async mode
3467
- var _tmpParserState=this.newParserState(pParseTree);_tmpParserState.Asynchronous=true;var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');var _loop=function _loop(_i15){tmpAnticipate.anticipate(function(fCallback){_this29.parseCharacterAsync(pString[_i15],_tmpParserState,pData,fCallback);});};for(var _i15=0;_i15<pString.length;_i15++){_loop(_i15);}tmpAnticipate.wait(function(pError){// Flush the remaining data
3470
+ * @param {array} pDataContext - The history of data objects/context already passed in
3471
+ */},{key:"parseString",value:function parseString(pString,pParseTree,pData,fCallback,pDataContext){var _this29=this;// TODO: There is danger here if a template function attempts to functionally recurse and doesn't pass this in.
3472
+ var tmpPreviousDataContext=Array.isArray(pDataContext)?pDataContext:[];var tmpDataContext=Array.from(tmpPreviousDataContext);tmpDataContext.push(pData);if(typeof fCallback!=='function'){var tmpParserState=this.newParserState(pParseTree);for(var i=0;i<pString.length;i++){// TODO: This is not fast.
3473
+ this.parseCharacter(pString[i],tmpParserState,pData,tmpDataContext);}this.flushOutputBuffer(tmpParserState);return tmpParserState.Output;}else{// This is the async mode
3474
+ var _tmpParserState=this.newParserState(pParseTree);_tmpParserState.Asynchronous=true;var tmpAnticipate=this.fable.instantiateServiceProviderWithoutRegistration('Anticipate');var _loop=function _loop(_i15){tmpAnticipate.anticipate(function(fCallback){_this29.parseCharacterAsync(pString[_i15],_tmpParserState,pData,fCallback,tmpDataContext);});};for(var _i15=0;_i15<pString.length;_i15++){_loop(_i15);}tmpAnticipate.wait(function(pError){// Flush the remaining data
3468
3475
  _this29.flushOutputBuffer(_tmpParserState);return fCallback(pError,_tmpParserState.Output);});}}}]);return StringParser;}();module.exports=StringParser;},{}],139:[function(require,module,exports){/**
3469
3476
  * Word Tree
3470
3477
  * @author Steven Velozo <steven@velozo.com>
@@ -3574,7 +3581,7 @@ GuaranteedNonMatch:/.^/};// This is a helper for the escaper and unescaper funct
3574
3581
  // Right now we are going to keep what underscore is doing, but, not forever.
3575
3582
  _this38.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
3576
3583
  // function on this class.
3577
- _this38.renderFunction=false;_this38.templateString=false;return _this38;}_createClass2(FableServiceTemplate,[{key:"renderTemplate",value:function renderTemplate(pData){return this.renderFunction(pData);}},{key:"templateFunction",value:function templateFunction(pData){var fRenderTemplateBound=this.renderTemplate.bind(this);return fRenderTemplateBound;}},{key:"buildTemplateFunction",value:function buildTemplateFunction(pTemplateText,pData){var _this39=this;// For now this is being kept in a weird form ... this is to mimic the old
3584
+ _this38.renderFunction=false;_this38.templateString=false;return _this38;}_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 _this39=this;// For now this is being kept in a weird form ... this is to mimic the old
3578
3585
  // underscore code until this is rewritten using precedent.
3579
3586
  this.TemplateSource="__p+='"+pTemplateText.replace(this.Matchers.Escaper,function(pMatch){return"\\".concat(_this39.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
3580
3587
  // precompilation.