fable 3.0.26 → 3.0.28
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/.browserslistrc +1 -1
- package/dist/fable.js +1940 -2975
- package/dist/fable.min.js +32 -14
- package/dist/fable.min.js.map +1 -1
- package/gulpfile-config.json +2 -2
- package/package.json +4 -2
- package/source/Fable-ServiceManager.js +31 -2
- package/source/Fable.js +11 -4
- package/source/{Fable-Service-DataArithmatic.js → services/Fable-Service-DataArithmatic.js} +2 -1
- package/source/{Fable-Service-MetaTemplate.js → services/Fable-Service-MetaTemplate.js} +1 -1
- package/source/services/Fable-Service-RestClient.js +17 -0
- package/source/{Fable-Service-Template.js → services/Fable-Service-Template.js} +1 -1
- package/source/{Fable-Service-Utility.js → services/Fable-Service-Utility.js} +1 -2
- package/test/FableServiceManager_tests.js +64 -0
- package/source/Fable-ServiceProviderBase.js +0 -23
package/gulpfile-config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fable",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.28",
|
|
4
4
|
"description": "An entity behavior management and API bundling library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -65,8 +65,10 @@
|
|
|
65
65
|
"async.waterfall": "^0.5.2",
|
|
66
66
|
"data-arithmatic": "^1.0.4",
|
|
67
67
|
"fable-log": "^3.0.7",
|
|
68
|
+
"fable-serviceproviderbase": "^3.0.0",
|
|
68
69
|
"fable-settings": "^3.0.3",
|
|
69
70
|
"fable-uuid": "^3.0.2",
|
|
70
|
-
"precedent": "^1.0.10"
|
|
71
|
+
"precedent": "^1.0.10",
|
|
72
|
+
"simple-get": "^4.0.1"
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const libFableServiceBase = require('
|
|
7
|
+
const libFableServiceBase = require('fable-serviceproviderbase');
|
|
8
8
|
|
|
9
9
|
class FableService
|
|
10
10
|
{
|
|
@@ -40,6 +40,7 @@ class FableService
|
|
|
40
40
|
else
|
|
41
41
|
{
|
|
42
42
|
// Add the base class to the list of classes
|
|
43
|
+
this.fable.log.error(`Attempted to add service type [${pServiceType}] with an invalid class. Using base service class, which will not crash but won't provide meaningful services.`);
|
|
43
44
|
this.serviceClasses[pServiceType] = libFableServiceBase;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -69,6 +70,33 @@ class FableService
|
|
|
69
70
|
return tmpService;
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
// Connect an initialized service provider that came before Fable was initialized
|
|
74
|
+
connectPreinitServiceProviderInstance(pServiceInstance)
|
|
75
|
+
{
|
|
76
|
+
let tmpServiceType = pServiceInstance.serviceType;
|
|
77
|
+
let tmpServiceHash = pServiceInstance.Hash;
|
|
78
|
+
|
|
79
|
+
// The service should already be instantiated, so just connect it to fable
|
|
80
|
+
pServiceInstance.connectFable(this.fable);
|
|
81
|
+
|
|
82
|
+
if (!this.services.hasOwnProperty(tmpServiceType))
|
|
83
|
+
{
|
|
84
|
+
// If the core service hasn't registered itself yet, create the service container for it.
|
|
85
|
+
// This means you couldn't register another with this type unless it was later registered with a constructor class.
|
|
86
|
+
this.services[tmpServiceType] = {};
|
|
87
|
+
}
|
|
88
|
+
// Add the service to the service map
|
|
89
|
+
this.services[tmpServiceType][tmpServiceHash] = pServiceInstance;
|
|
90
|
+
|
|
91
|
+
// If this is the first service of this type, make it the default
|
|
92
|
+
if (!this.defaultServices.hasOwnProperty(tmpServiceType))
|
|
93
|
+
{
|
|
94
|
+
this.defaultServices[tmpServiceType] = pServiceInstance;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return pServiceInstance;
|
|
98
|
+
}
|
|
99
|
+
|
|
72
100
|
setDefaultServiceInstantiation(pServiceType, pServiceHash)
|
|
73
101
|
{
|
|
74
102
|
if (this.services[pServiceType].hasOwnProperty(pServiceHash))
|
|
@@ -83,4 +111,5 @@ class FableService
|
|
|
83
111
|
|
|
84
112
|
module.exports = FableService;
|
|
85
113
|
|
|
86
|
-
module.exports.ServiceProviderBase = libFableServiceBase;
|
|
114
|
+
module.exports.ServiceProviderBase = libFableServiceBase;
|
|
115
|
+
module.exports.CoreServiceProviderBase = libFableServiceBase.CoreServiceProviderBase;
|
package/source/Fable.js
CHANGED
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
+
// Pre-init services
|
|
6
7
|
const libFableSettings = require('fable-settings');
|
|
7
8
|
const libFableUUID = require('fable-uuid');
|
|
8
9
|
const libFableLog = require('fable-log');
|
|
9
10
|
|
|
10
11
|
const libFableServiceManager = require('./Fable-ServiceManager.js');
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const libFableServiceMetaTemplate = require('./Fable-Service-MetaTemplate.js');
|
|
15
|
-
const
|
|
13
|
+
// Services
|
|
14
|
+
const libFableServiceDataArithmatic = require('./services/Fable-Service-DataArithmatic.js');
|
|
15
|
+
const libFableServiceMetaTemplate = require('./services/Fable-Service-MetaTemplate.js');
|
|
16
|
+
const libFableServiceRestClient = require('./services/Fable-Service-RestClient.js');
|
|
17
|
+
const libFableServiceTemplate = require('./services/Fable-Service-Template.js');
|
|
18
|
+
const libFableServiceUtility = require('./services/Fable-Service-Utility.js');
|
|
16
19
|
|
|
17
20
|
const libFableOperation = require('./Fable-Operation.js');
|
|
18
21
|
|
|
@@ -58,6 +61,9 @@ class Fable
|
|
|
58
61
|
this.fable.serviceManager.instantiateServiceProvider('Utility', {}, 'Default-Service-Utility');
|
|
59
62
|
this.Utility = this.serviceManager.defaultServices.Utility;
|
|
60
63
|
|
|
64
|
+
// Add the REST Client service type
|
|
65
|
+
this.serviceManager.addServiceType('RestClient', libFableServiceRestClient);
|
|
66
|
+
|
|
61
67
|
this.services = this.serviceManager.services;
|
|
62
68
|
this.defaultServices = this.serviceManager.defaultServices;
|
|
63
69
|
}
|
|
@@ -118,5 +124,6 @@ module.exports.new = autoConstruct;
|
|
|
118
124
|
|
|
119
125
|
module.exports.LogProviderBase = libFableLog.LogProviderBase;
|
|
120
126
|
module.exports.ServiceProviderBase = libFableServiceManager.ServiceProviderBase;
|
|
127
|
+
module.exports.CoreServiceProviderBase = libFableServiceManager.CoreServiceProviderBase;
|
|
121
128
|
|
|
122
129
|
module.exports.precedent = libFableSettings.precedent;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const libFableServiceBase = require('
|
|
1
|
+
const libFableServiceBase = require('../Fable-ServiceManager.js').ServiceProviderBase;
|
|
2
|
+
|
|
2
3
|
const libDataArithmatic = require('data-arithmatic');
|
|
3
4
|
|
|
4
5
|
class FableServiceDataArithmatic extends libFableServiceBase
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const libFableServiceBase = require('../Fable-ServiceManager.js').ServiceProviderBase;
|
|
2
|
+
|
|
3
|
+
const libSimpleGet = require('simple-get');
|
|
4
|
+
|
|
5
|
+
class FableServiceRestClient extends libFableServiceBase
|
|
6
|
+
{
|
|
7
|
+
constructor(pFable, pOptions, pServiceHash)
|
|
8
|
+
{
|
|
9
|
+
super(pFable, pOptions, pServiceHash);
|
|
10
|
+
|
|
11
|
+
this.serviceType = 'RestClient';
|
|
12
|
+
|
|
13
|
+
this._SimpleGet = new libSimpleGet();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = FableServiceRestClient;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const libFableServiceBase = require('
|
|
2
|
-
|
|
1
|
+
const libFableServiceBase = require('../Fable-ServiceManager.js').ServiceProviderBase;
|
|
3
2
|
|
|
4
3
|
// TODO: These are still pretty big -- consider the smaller polyfills
|
|
5
4
|
const libAsyncWaterfall = require('async.waterfall');
|
|
@@ -46,6 +46,22 @@ class MockDatabaseService extends libFable.ServiceProviderBase
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
class MockCoreService extends libFable.CoreServiceProviderBase
|
|
50
|
+
{
|
|
51
|
+
constructor(pOptions, pServiceHash)
|
|
52
|
+
{
|
|
53
|
+
super(pOptions, pServiceHash);
|
|
54
|
+
|
|
55
|
+
this.serviceType = 'MockCoreService';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Core services should be able to provide their behaviors before the Fable object is fully initialized.
|
|
59
|
+
magicBehavior(pData)
|
|
60
|
+
{
|
|
61
|
+
console.log(`MockCoreService ${this.UUID}::${this.Hash} is doing something magical with ${pData}.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
suite
|
|
50
66
|
(
|
|
51
67
|
'Fable Service Manager',
|
|
@@ -162,6 +178,54 @@ suite
|
|
|
162
178
|
}
|
|
163
179
|
);
|
|
164
180
|
|
|
181
|
+
test
|
|
182
|
+
(
|
|
183
|
+
'Construct a core service before Fable is initialized',
|
|
184
|
+
function()
|
|
185
|
+
{
|
|
186
|
+
let tmpCoreService = new MockCoreService({SomeOption: true});
|
|
187
|
+
|
|
188
|
+
Expect(tmpCoreService).to.be.an('object');
|
|
189
|
+
|
|
190
|
+
tmpCoreService.magicBehavior('MAGICTESTDATA');
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
test
|
|
194
|
+
(
|
|
195
|
+
'Construct a core service with a hash before Fable is initialized',
|
|
196
|
+
function()
|
|
197
|
+
{
|
|
198
|
+
let tmpCoreService = new MockCoreService({SomeOption: true}, 'MockCoreService-1');
|
|
199
|
+
|
|
200
|
+
Expect(tmpCoreService).to.be.an('object');
|
|
201
|
+
Expect(tmpCoreService.Hash).to.equal('MockCoreService-1');
|
|
202
|
+
|
|
203
|
+
tmpCoreService.magicBehavior('MAGICTESTDATA');
|
|
204
|
+
}
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
test
|
|
208
|
+
(
|
|
209
|
+
'Construct a core service and attach it to Fable after Fable is initialized',
|
|
210
|
+
function()
|
|
211
|
+
{
|
|
212
|
+
|
|
213
|
+
let tmpCoreService = new MockCoreService({SomeOption: true}, 'MockCoreService-2');
|
|
214
|
+
|
|
215
|
+
Expect(tmpCoreService).to.be.an('object');
|
|
216
|
+
Expect(tmpCoreService.Hash).to.equal('MockCoreService-2');
|
|
217
|
+
|
|
218
|
+
let testFable = new libFable({});
|
|
219
|
+
|
|
220
|
+
testFable.serviceManager.connectPreinitServiceProviderInstance(tmpCoreService);
|
|
221
|
+
|
|
222
|
+
Expect(testFable.services.MockCoreService['MockCoreService-2']).to.be.an('object');
|
|
223
|
+
Expect(testFable.defaultServices.MockCoreService).to.be.an('object');
|
|
224
|
+
|
|
225
|
+
Expect(testFable.defaultServices.MockCoreService.fable.log).to.be.an('object');
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
|
|
165
229
|
test
|
|
166
230
|
(
|
|
167
231
|
'Attempt to change the default service provider to a nonexistant provider',
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fable Service Base
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author <steven@velozo.com>
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
class FableServiceProviderBase
|
|
8
|
-
{
|
|
9
|
-
constructor(pFable, pOptions, pServiceHash)
|
|
10
|
-
{
|
|
11
|
-
this.fable = pFable;
|
|
12
|
-
|
|
13
|
-
this.options = (typeof(pOptions) === 'object') ? pOptions : {};
|
|
14
|
-
|
|
15
|
-
this.serviceType = 'Unknown';
|
|
16
|
-
|
|
17
|
-
this.UUID = pFable.getUUID();
|
|
18
|
-
|
|
19
|
-
this.Hash = (typeof(pServiceHash) === 'string') ? pServiceHash : `${this.UUID}`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = FableServiceProviderBase;
|