fable 3.0.10 → 3.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.10",
3
+ "version": "3.0.12",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -0,0 +1,119 @@
1
+ const _OperationStatePrototype = JSON.stringify(
2
+ {
3
+ "Metadata": {
4
+ "GUID": false,
5
+ "Hash": false,
6
+
7
+ "Title": "",
8
+ "Summary": "",
9
+
10
+ "Version": 0
11
+ },
12
+ "Status": {
13
+ "Completed": false,
14
+
15
+ "CompletionProgress": 0,
16
+ "CompletionTimeElapsed": 0,
17
+
18
+ "Steps": 1,
19
+ "StepsCompleted": 0,
20
+
21
+ "StartTime": 0,
22
+ "EndTime": 0
23
+ },
24
+ "Errors": [],
25
+ "Log": []
26
+ });
27
+
28
+ class FableOperation
29
+ {
30
+ constructor(pFable, pOperationName, pOperationHash)
31
+ {
32
+ this.fable = pFable;
33
+
34
+ this.state = JSON.parse(_OperationStatePrototype);
35
+
36
+ this.state.Metadata.GUID = this.fable.getUUID();
37
+ this.state.Metadata.Hash = this.state.GUID;
38
+
39
+ if (typeof(pOperationHash) == 'string')
40
+ {
41
+ this.state.Metadata.Hash = pOperationHash;
42
+ }
43
+ }
44
+
45
+ get GUID()
46
+ {
47
+ return this.state.Metadata.GUID;
48
+ }
49
+
50
+ get Hash()
51
+ {
52
+ return this.state.Metadata.Hash;
53
+ }
54
+
55
+ get log()
56
+ {
57
+ return this;
58
+ }
59
+
60
+ writeOperationLog(pLogLevel, pLogText, pLogObject)
61
+ {
62
+ this.state.Log.push(`${new Date().toUTCString()} [${pLogLevel}]: ${pLogText}`);
63
+
64
+ if (typeof(pLogObject) == 'object')
65
+ {
66
+ this.state.Log.push(JSON.stringify(pLogObject));
67
+ }
68
+ }
69
+
70
+ writeOperationErrors(pLogText, pLogObject)
71
+ {
72
+ this.state.Errors.push(`${pLogText}`);
73
+
74
+ if (typeof(pLogObject) == 'object')
75
+ {
76
+ this.state.Errors.push(JSON.stringify(pLogObject));
77
+ }
78
+ }
79
+
80
+ trace(pLogText, pLogObject)
81
+ {
82
+ this.writeOperationLog('TRACE', pLogText, pLogObject);
83
+ this.fable.log.trace(pLogText, pLogObject);
84
+ }
85
+
86
+ debug(pLogText, pLogObject)
87
+ {
88
+ this.writeOperationLog('DEBUG', pLogText, pLogObject);
89
+ this.fable.log.debug(pLogText, pLogObject);
90
+ }
91
+
92
+ info(pLogText, pLogObject)
93
+ {
94
+ this.writeOperationLog('INFO', pLogText, pLogObject);
95
+ this.fable.log.info(pLogText, pLogObject);
96
+ }
97
+
98
+ warn(pLogText, pLogObject)
99
+ {
100
+ this.writeOperationLog('WARN', pLogText, pLogObject);
101
+ this.fable.log.warn(pLogText, pLogObject);
102
+ }
103
+
104
+ error(pLogText, pLogObject)
105
+ {
106
+ this.writeOperationLog('ERROR', pLogText, pLogObject);
107
+ this.writeOperationErrors(pLogText, pLogObject);
108
+ this.fable.log.error(pLogText, pLogObject);
109
+ }
110
+
111
+ fatal(pLogText, pLogObject)
112
+ {
113
+ this.writeOperationLog('FATAL', pLogText, pLogObject);
114
+ this.writeOperationErrors(pLogText, pLogObject);
115
+ this.fable.log.fatal(pLogText, pLogObject);
116
+ }
117
+ }
118
+
119
+ module.exports = FableOperation;
@@ -1,4 +1,5 @@
1
1
  const libFableUtilityTemplate = require('./Fable-Utility-Template.js');
2
+ // TODO: These are still pretty big -- consider the smaller polyfills
2
3
  const libAsyncWaterfall = require('async/waterfall');
3
4
  const libAsyncEachLimit = require('async/eachLimit');
4
5
 
package/source/Fable.js CHANGED
@@ -9,6 +9,8 @@ const libFableLog = require('fable-log');
9
9
 
10
10
  const libFableUtility = require('./Fable-Utility.js')
11
11
 
12
+ const libFableOperation = require('./Fable-Operation.js');
13
+
12
14
  class Fable
13
15
  {
14
16
  constructor(pSettings)
@@ -23,13 +25,17 @@ class Fable
23
25
  this.log = new libFableLog(this.settingsManager.settings);
24
26
  this.log.initialize();
25
27
 
28
+ // Built-in utility belt functions
26
29
  this.Utility = new libFableUtility(this);
27
30
 
28
- // Built-in dependencies ... more can be added here.
31
+ // Built-in dependencies
29
32
  this.Dependencies = (
30
33
  {
31
34
  precedent: libFableSettings.precedent
32
35
  });
36
+
37
+ // Location for Operation state
38
+ this.Operations = {};
33
39
  }
34
40
 
35
41
  get settings()
@@ -46,6 +52,35 @@ class Fable
46
52
  {
47
53
  return this.libUUID.getUUID();
48
54
  }
55
+
56
+ createOperation(pOperationName, pOperationHash)
57
+ {
58
+ let tmpOperation = new libFableOperation(this, pOperationName, pOperationHash);
59
+
60
+ if (this.Operations.hasOwnProperty(tmpOperation.Hash))
61
+ {
62
+ // Uh Oh ...... Operation Hash Collision!
63
+ // TODO: What to do?!
64
+ }
65
+ else
66
+ {
67
+ this.Operations[tmpOperation.Hash] = tmpOperation;
68
+ }
69
+
70
+ return tmpOperation;
71
+ }
72
+
73
+ getOperation(pOperationHash)
74
+ {
75
+ if (!this.Operations.hasOwnProperty(pOperationHash))
76
+ {
77
+ return false;
78
+ }
79
+ else
80
+ {
81
+ return this.pOperations[pOperationHash];
82
+ }
83
+ }
49
84
  }
50
85
 
51
86
  // This is for backwards compatibility
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Unit tests for Fable
3
+ *
4
+ * @license MIT
5
+ *
6
+ * @author Steven Velozo <steven@velozo.com>
7
+ */
8
+
9
+ var libFable = require('../source/Fable.js');
10
+
11
+ var Chai = require("chai");
12
+ var Expect = Chai.expect;
13
+ var Assert = Chai.assert;
14
+
15
+ suite
16
+ (
17
+ 'Fable Operations',
18
+ function()
19
+ {
20
+ suite
21
+ (
22
+ 'Utility',
23
+ function()
24
+ {
25
+ test
26
+ (
27
+ 'Create a basic Integration Operation',
28
+ function()
29
+ {
30
+ let testFable = new libFable();
31
+ let tmpOperation = testFable.createOperation('Big Complex Integration Operation', 'INTEGRATION-123');
32
+ Expect(tmpOperation).to.be.an('object');
33
+ Expect(testFable.Operations.hasOwnProperty('INTEGRATION-123')).to.equal(true);
34
+ tmpOperation.log.info('Test 123');
35
+ Expect(tmpOperation.state.Log.length).to.equal(1);
36
+ Expect(tmpOperation.state.Log[0]).to.contain('Test 123');
37
+ }
38
+ );
39
+ test
40
+ (
41
+ 'Create a basic Integration Operation without a Hash',
42
+ function()
43
+ {
44
+ let testFable = new libFable();
45
+ let tmpOperation = testFable.createOperation('Another Big Complex Integration Operation');
46
+ Expect(tmpOperation).to.be.an('object');
47
+ Expect(testFable.Operations.hasOwnProperty(tmpOperation.Hash)).to.equal(true);
48
+ Expect(tmpOperation.state.Log.length).to.equal(0);
49
+ let tmpText = `Operation ${tmpOperation.Hash} starting up...`;
50
+ tmpOperation.log.info(tmpText);
51
+ Expect(tmpOperation.state.Log.length).to.equal(1);
52
+ Expect(tmpOperation.state.Log[0]).to.contain(tmpText);
53
+ tmpOperation.log.trace('And the traces are gone...');
54
+ tmpOperation.log.debug('Debug something.', {TestData:'Ignition Complete'});
55
+ tmpOperation.log.warn('Something was almost bad.');
56
+ tmpOperation.log.error('This was an error!');
57
+ tmpOperation.log.fatal('It was fatal.');
58
+ Expect(tmpOperation.state.Log.length).to.equal(7);
59
+ Expect(tmpOperation.state.Log[3]).to.equal('{"TestData":"Ignition Complete"}')
60
+ Expect(tmpOperation.state.Errors.length).to.equal(2);
61
+ }
62
+ );
63
+ }
64
+ );
65
+ }
66
+ );
@@ -14,7 +14,7 @@ var Assert = Chai.assert;
14
14
 
15
15
  suite
16
16
  (
17
- 'FableUtility',
17
+ 'Fable Utility',
18
18
  function()
19
19
  {
20
20
  var testFable = false;
@@ -195,7 +195,8 @@ suite
195
195
  fDone();
196
196
  })
197
197
  }
198
- ); }
198
+ );
199
+ }
199
200
  );
200
201
  }
201
202
  );
@@ -40,11 +40,11 @@ suite
40
40
  // Instantiate the logger
41
41
  Expect(testFable).to.be.an('object', 'Fable should initialize as an object directly from the require statement.');
42
42
  Expect(testFable).to.have.a.property('log')
43
- .that.is.a('object');
43
+ .that.is.a('object');
44
44
  Expect(testFable).to.have.a.property('settings')
45
- .that.is.a('object');
45
+ .that.is.a('object');
46
46
  Expect(testFable).to.have.a.property('fable')
47
- .that.is.a('object');
47
+ .that.is.a('object');
48
48
  Expect(testFable.settings.Product)
49
49
  .to.equal('ApplicationNameHere')
50
50
  }