fable 3.0.38 → 3.0.39

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.
@@ -5,7 +5,7 @@
5
5
 
6
6
  "LibraryOutputFolder": "./dist/",
7
7
 
8
- "LibraryUniminifiedFileName": "fable.js",
8
+ "LibraryUniminifiedFileName": "fable.compatible.js",
9
9
 
10
- "LibraryMinifiedFileName": "fable.min.js"
10
+ "LibraryMinifiedFileName": "fable.compatible.min.js"
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.38",
3
+ "version": "3.0.39",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -32,7 +32,8 @@
32
32
  ]
33
33
  },
34
34
  "browser": {
35
- "./source/service/Fable-Service-EnvironmentData.js": "./source/service/Fable-Service-EnvironmentData-Web.js"
35
+ "./source/service/Fable-Service-EnvironmentData.js": "./source/service/Fable-Service-EnvironmentData-Web.js",
36
+ "./source/service/Fable-Service-FilePersistence.js": "./source/service/Fable-Service-FilePersistence-Web.js"
36
37
  },
37
38
  "repository": {
38
39
  "type": "git",
@@ -72,6 +73,7 @@
72
73
  "fable-serviceproviderbase": "^3.0.3",
73
74
  "fable-settings": "^3.0.5",
74
75
  "fable-uuid": "^3.0.5",
76
+ "manyfest": "^1.0.24",
75
77
  "precedent": "^1.0.10",
76
78
  "simple-get": "^4.0.1"
77
79
  }
package/source/Fable.js CHANGED
@@ -50,6 +50,12 @@ class Fable
50
50
  this.serviceManager.addServiceType('Operation', require('./services/Fable-Service-Operation.js'));
51
51
  this.serviceManager.addServiceType('RestClient', require('./services/Fable-Service-RestClient.js'));
52
52
  this.serviceManager.addServiceType('CSVParser', require('./services/Fable-Service-CSVParser.js'));
53
+ this.serviceManager.addServiceType('Manifest', require('manyfest'));
54
+ }
55
+
56
+ get isFable()
57
+ {
58
+ return true;
53
59
  }
54
60
 
55
61
  get settings()
@@ -85,7 +91,7 @@ class Fable
85
91
  get fable()
86
92
  {
87
93
  return this;
88
- }
94
+ };
89
95
  }
90
96
 
91
97
  // This is for backwards compatibility
@@ -0,0 +1,36 @@
1
+ const libFableServiceBase = require('../Fable-ServiceManager.js').ServiceProviderBase;
2
+
3
+ class FableServiceFilePersistence extends libFableServiceBase
4
+ {
5
+ constructor(pFable, pOptions, pServiceHash)
6
+ {
7
+ super(pFable, pOptions, pServiceHash);
8
+
9
+ this.serviceType = 'FilePersistence';
10
+
11
+ if (!this.options.hasOwnProperty('Mode'))
12
+ {
13
+ this.options.Mode = parseInt('0777', 8) & ~process.umask();
14
+ }
15
+ }
16
+
17
+ existsSync(pPath)
18
+ {
19
+ //return libFS.existsSync(pPath);
20
+ return false;
21
+ }
22
+
23
+ exists(pPath, fCallback)
24
+ {
25
+ let tmpFileExists = this.existsSync(pPath);;
26
+
27
+ return fCallback(null, tmpFileExists);
28
+ }
29
+
30
+ makeFolderRecursive (pParameters, fCallback)
31
+ {
32
+ return fCallback();
33
+ }
34
+ }
35
+
36
+ module.exports = FableServiceFilePersistence;
@@ -0,0 +1,127 @@
1
+ const libFableServiceBase = require('../Fable-ServiceManager.js').ServiceProviderBase;
2
+
3
+ const libFS = require('fs');
4
+ const libPath = require('path');
5
+
6
+
7
+ class FableServiceFilePersistence extends libFableServiceBase
8
+ {
9
+ constructor(pFable, pOptions, pServiceHash)
10
+ {
11
+ super(pFable, pOptions, pServiceHash);
12
+
13
+ this.serviceType = 'FilePersistence';
14
+
15
+ if (!this.options.hasOwnProperty('Mode'))
16
+ {
17
+ this.options.Mode = parseInt('0777', 8) & ~process.umask();
18
+ }
19
+ }
20
+
21
+ existsSync(pPath)
22
+ {
23
+ return libFS.existsSync(pPath);
24
+ }
25
+
26
+ exists(pPath, fCallback)
27
+ {
28
+ let tmpFileExists = this.existsSync(pPath);;
29
+
30
+ return fCallback(null, tmpFileExists);
31
+ }
32
+
33
+ makeFolderRecursive (pParameters, fCallback)
34
+ {
35
+ let tmpParameters = pParameters;
36
+
37
+ if (typeof(pParameters) == 'string')
38
+ {
39
+ tmpParameters = { Path: pParameters };
40
+ }
41
+ else if (typeof(pParameters) !== 'object')
42
+ {
43
+ fCallback(new Error('Parameters object or string not properly passed to recursive folder create.'));
44
+ return false;
45
+ }
46
+
47
+ if ((typeof(tmpParameters.Path) !== 'string'))
48
+ {
49
+ fCallback(new Error('Parameters object needs a path to run the folder create operation.'));
50
+ return false;
51
+ }
52
+
53
+ if (!tmpParameters.hasOwnProperty('Mode'))
54
+ {
55
+ tmpParameters.Mode = this.options.Mode;
56
+ }
57
+
58
+ // Check if we are just starting .. if so, build the initial state for our recursive function
59
+ if (typeof(tmpParameters.CurrentPathIndex) === 'undefined')
60
+ {
61
+ // Build the tools to start recursing
62
+ tmpParameters.ActualPath = libPath.normalize(tmpParameters.Path);
63
+ tmpParameters.ActualPathParts = tmpParameters.ActualPath.split(libPath.sep);
64
+ tmpParameters.CurrentPathIndex = 0;
65
+ tmpParameters.CurrentPath = '';
66
+ }
67
+ else
68
+ {
69
+ // This is not our first run, so we will continue the recursion.
70
+ // Build the new base path
71
+ if (tmpParameters.CurrentPath == libPath.sep)
72
+ {
73
+ tmpParameters.CurrentPath = tmpParameters.CurrentPath + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex];
74
+ }
75
+ else
76
+ {
77
+ tmpParameters.CurrentPath = tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex];
78
+ }
79
+
80
+ // Increment the path index
81
+ tmpParameters.CurrentPathIndex++;
82
+ }
83
+
84
+ // Check if the path is fully complete
85
+ if (tmpParameters.CurrentPathIndex >= tmpParameters.ActualPathParts.length)
86
+ {
87
+ fCallback(null);
88
+ return true;
89
+ }
90
+
91
+ // Check if the path exists
92
+ libFS.open(tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex], 'r',
93
+ function(pError, pFileDescriptor)
94
+ {
95
+ if (pFileDescriptor)
96
+ {
97
+ libFS.closeSync(pFileDescriptor);
98
+ }
99
+
100
+ if (pError && pError.code=='ENOENT')
101
+ {
102
+ /* Path doesn't exist, create it */
103
+ libFS.mkdir(tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex], tmpParameters.Mode,
104
+ (pCreateError) =>
105
+ {
106
+ if (!pCreateError)
107
+ {
108
+ // We have now created our folder and there was no error -- continue.
109
+ return this.makeFolderRecursive(tmpParameters, fCallback);
110
+ }
111
+ else
112
+ {
113
+ fCallback(pCreateError);
114
+ return false;
115
+ }
116
+ });
117
+ }
118
+ else
119
+ {
120
+ return this.makeFolderRecursive(tmpParameters, fCallback);
121
+ }
122
+ }
123
+ );
124
+ }
125
+ }
126
+
127
+ module.exports = FableServiceFilePersistence;
@@ -85,8 +85,9 @@ class FableServiceUtility extends libFableServiceBase
85
85
  // and: 1986-06-11T09:34:46.012Z+0200
86
86
  // ... and converts them into javascript timestamps, following the directions of the timezone stuff.
87
87
  //
88
- // This is not meant to replace the more complex libraries.
89
- // This *is* meant to be a simple, small, and fast way to convert ISO strings to dates in engines with limited JS capabilities.
88
+ // This is not meant to replace the more complex libraries such as moment or luxon.
89
+ // This *is* meant to be a simple, small, and fast way to convert ISO strings to dates in engines
90
+ // with ultra limited JS capabilities where those don't work.
90
91
  isoStringToDate (pISOString)
91
92
  {
92
93
 
@@ -0,0 +1,37 @@
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
+
14
+ suite
15
+ (
16
+ 'File Persistence',
17
+ function()
18
+ {
19
+ suite
20
+ (
21
+ 'Work with Files',
22
+ function()
23
+ {
24
+ test
25
+ (
26
+ 'Recursively Create a Folder',
27
+ function(fDone)
28
+ {
29
+ let testFable = new libFable();
30
+
31
+ return fDone();
32
+ }
33
+ );
34
+ }
35
+ );
36
+ }
37
+ );
@@ -0,0 +1,79 @@
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
+ const libFS = require('fs');
12
+ const libReadline = require('readline');
13
+
14
+ var Chai = require("chai");
15
+ var Expect = Chai.expect;
16
+
17
+ suite
18
+ (
19
+ 'Manyfest Object Address Resolution',
20
+ function()
21
+ {
22
+ suite
23
+ (
24
+ 'Manifiesta',
25
+ function()
26
+ {
27
+ test
28
+ (
29
+ 'Basic object reading and writing',
30
+ function(fDone)
31
+ {
32
+ let testFable = new libFable();
33
+
34
+ let animalManyfest = testFable.serviceManager.instantiateServiceProvider('Manifest',
35
+ {
36
+ "Scope": "Animal",
37
+ "Descriptors":
38
+ {
39
+ "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
40
+ "Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
41
+ "Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." },
42
+ "MedicalStats":
43
+ {
44
+ "Name":"Medical Statistics", "Description":"Basic medical statistics for this animal"
45
+ },
46
+ "MedicalStats.Temps.MinET": { "Name":"Minimum Environmental Temperature", "NameShort":"MinET", "Description":"Safest minimum temperature for this animal to survive in."},
47
+ "MedicalStats.Temps.MaxET": { "Name":"Maximum Environmental Temperature", "NameShort":"MaxET", "Description":"Safest maximum temperature for this animal to survive in."},
48
+ "MedicalStats.Temps.CET":
49
+ {
50
+ "Name":"Comfortable Environmental Temperature",
51
+ "NameShort":"Comf Env Temp",
52
+ "Hash":"ComfET",
53
+ "Description":"The most comfortable temperature for this animal to survive in.",
54
+ "Default": "96.8"
55
+ }
56
+ }
57
+ });
58
+
59
+ Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'ComfET')).to.equal(200);
60
+ Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'ComfET')).to.equal('96.8');
61
+ Expect(animalManyfest.getValueByHash({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'CurrentTemperature')).to.equal(undefined);
62
+
63
+ // Now change the comfortable environmental temperature for the Froggy to be 200
64
+ let tmpRecord = {MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'};
65
+ animalManyfest.setValueByHash(tmpRecord, 'ComfET', 200);
66
+ Expect(animalManyfest.getValueByHash(tmpRecord, 'ComfET')).to.equal(200);
67
+
68
+ Expect(animalManyfest.getValueAtAddress({MedicalStats: { Temps: { CET:200 }},Name:'Froggy'}, 'MedicalStats.Temps.CET')).to.equal(200);
69
+ Expect(animalManyfest.getValueAtAddress({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'MedicalStats.Temps.CET')).to.equal('96.8');
70
+ Expect(animalManyfest.getValueAtAddress({MedicalStats: { Temps: { MinET:200 }},Name:'Froggy'}, 'MedicalStats.Temps.HighET')).to.equal(undefined);
71
+
72
+
73
+ return fDone();
74
+ }
75
+ );
76
+ }
77
+ );
78
+ }
79
+ );