fable 3.0.26 → 3.0.27
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 +3 -2
- package/source/Fable-PreinitServiceProviderBase.js +36 -0
- package/source/Fable-ServiceManager.js +27 -0
- package/source/Fable.js +12 -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 -1
- package/test/FableServiceManager_tests.js +64 -0
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.27",
|
|
4
4
|
"description": "An entity behavior management and API bundling library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"fable-log": "^3.0.7",
|
|
68
68
|
"fable-settings": "^3.0.3",
|
|
69
69
|
"fable-uuid": "^3.0.2",
|
|
70
|
-
"precedent": "^1.0.10"
|
|
70
|
+
"precedent": "^1.0.10",
|
|
71
|
+
"simple-get": "^4.0.1"
|
|
71
72
|
}
|
|
72
73
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fable Core Pre-initialization Service Base
|
|
3
|
+
*
|
|
4
|
+
* For a couple services, we need to be able to instantiate them before the Fable object is fully initialized.
|
|
5
|
+
* This is a base class for those services.
|
|
6
|
+
*
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @author <steven@velozo.com>
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
class FablePreinitServiceProviderBase
|
|
12
|
+
{
|
|
13
|
+
constructor(pOptions, pServiceHash)
|
|
14
|
+
{
|
|
15
|
+
this.fable = false;
|
|
16
|
+
|
|
17
|
+
this.options = (typeof(pOptions) === 'object') ? pOptions : {};
|
|
18
|
+
|
|
19
|
+
this.serviceType = 'Unknown';
|
|
20
|
+
|
|
21
|
+
// The hash will be a non-standard UUID ... the UUID service uses this base class!
|
|
22
|
+
this.UUID = `CORESVC-${Math.floor((Math.random() * (99999 - 10000)) + 10000)}`;
|
|
23
|
+
|
|
24
|
+
this.Hash = (typeof(pServiceHash) === 'string') ? pServiceHash : `${this.UUID}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// After fable is initialized, it would be expected to be wired in as a normal service.
|
|
28
|
+
connectFable(pFable)
|
|
29
|
+
{
|
|
30
|
+
this.fable = pFable;
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = FablePreinitServiceProviderBase;
|
|
@@ -69,6 +69,33 @@ class FableService
|
|
|
69
69
|
return tmpService;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// Connect an initialized service provider that came before Fable was initialized
|
|
73
|
+
connectPreinitServiceProviderInstance(pServiceInstance)
|
|
74
|
+
{
|
|
75
|
+
let tmpServiceType = pServiceInstance.serviceType;
|
|
76
|
+
let tmpServiceHash = pServiceInstance.Hash;
|
|
77
|
+
|
|
78
|
+
// The service should already be instantiated, so just connect it to fable
|
|
79
|
+
pServiceInstance.connectFable(this.fable);
|
|
80
|
+
|
|
81
|
+
if (!this.services.hasOwnProperty(tmpServiceType))
|
|
82
|
+
{
|
|
83
|
+
// If the core service hasn't registered itself yet, create the service container for it.
|
|
84
|
+
// This means you couldn't register another with this type unless it was later registered with a constructor class.
|
|
85
|
+
this.services[tmpServiceType] = {};
|
|
86
|
+
}
|
|
87
|
+
// Add the service to the service map
|
|
88
|
+
this.services[tmpServiceType][tmpServiceHash] = pServiceInstance;
|
|
89
|
+
|
|
90
|
+
// If this is the first service of this type, make it the default
|
|
91
|
+
if (!this.defaultServices.hasOwnProperty(tmpServiceType))
|
|
92
|
+
{
|
|
93
|
+
this.defaultServices[tmpServiceType] = pServiceInstance;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return pServiceInstance;
|
|
97
|
+
}
|
|
98
|
+
|
|
72
99
|
setDefaultServiceInstantiation(pServiceType, pServiceHash)
|
|
73
100
|
{
|
|
74
101
|
if (this.services[pServiceType].hasOwnProperty(pServiceHash))
|
package/source/Fable.js
CHANGED
|
@@ -3,16 +3,20 @@
|
|
|
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
|
|
|
11
|
+
const libFablePreinitServiceProviderBase = require('./Fable-PreinitServiceProviderBase.js');
|
|
10
12
|
const libFableServiceManager = require('./Fable-ServiceManager.js');
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const libFableServiceMetaTemplate = require('./Fable-Service-MetaTemplate.js');
|
|
15
|
-
const
|
|
14
|
+
// Services
|
|
15
|
+
const libFableServiceDataArithmatic = require('./services/Fable-Service-DataArithmatic.js');
|
|
16
|
+
const libFableServiceMetaTemplate = require('./services/Fable-Service-MetaTemplate.js');
|
|
17
|
+
const libFableServiceRestClient = require('./services/Fable-Service-RestClient.js');
|
|
18
|
+
const libFableServiceTemplate = require('./services/Fable-Service-Template.js');
|
|
19
|
+
const libFableServiceUtility = require('./services/Fable-Service-Utility.js');
|
|
16
20
|
|
|
17
21
|
const libFableOperation = require('./Fable-Operation.js');
|
|
18
22
|
|
|
@@ -58,6 +62,9 @@ class Fable
|
|
|
58
62
|
this.fable.serviceManager.instantiateServiceProvider('Utility', {}, 'Default-Service-Utility');
|
|
59
63
|
this.Utility = this.serviceManager.defaultServices.Utility;
|
|
60
64
|
|
|
65
|
+
// Add the REST Client service type
|
|
66
|
+
this.serviceManager.addServiceType('RestClient', libFableServiceRestClient);
|
|
67
|
+
|
|
61
68
|
this.services = this.serviceManager.services;
|
|
62
69
|
this.defaultServices = this.serviceManager.defaultServices;
|
|
63
70
|
}
|
|
@@ -118,5 +125,6 @@ module.exports.new = autoConstruct;
|
|
|
118
125
|
|
|
119
126
|
module.exports.LogProviderBase = libFableLog.LogProviderBase;
|
|
120
127
|
module.exports.ServiceProviderBase = libFableServiceManager.ServiceProviderBase;
|
|
128
|
+
module.exports.PreinitServiceProviderBase = libFablePreinitServiceProviderBase;
|
|
121
129
|
|
|
122
130
|
module.exports.precedent = libFableSettings.precedent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const libFableServiceBase = require('../Fable-ServiceProviderBase.js');
|
|
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;
|
|
@@ -46,6 +46,22 @@ class MockDatabaseService extends libFable.ServiceProviderBase
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
class MockCoreService extends libFable.PreinitServiceProviderBase
|
|
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',
|