fable 3.0.39 → 3.0.41
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/.config/configstore/update-notifier-npm.json +1 -7
- package/.config/vscode-sqltools/runningInfo.json +1 -1
- package/Dockerfile_LUXURYCode +1 -1
- package/dist/fable.compatible.js +219 -119
- package/dist/fable.compatible.min.js +8 -8
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +167 -67
- package/dist/fable.min.js +8 -8
- package/dist/fable.min.js.map +1 -1
- package/package.json +3 -2
- package/source/Fable.js +1 -0
- package/source/services/Fable-Service-RestClient.js +26 -12
- package/test/Cache_tests.js +92 -0
- package/test/Manifest_tests.js +0 -3
- package/test/RestClient_test.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fable",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.41",
|
|
4
4
|
"description": "An entity behavior management and API bundling library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"test": "./node_modules/.bin/mocha -u tdd -R spec",
|
|
10
10
|
"build": "./node_modules/.bin/gulp build",
|
|
11
11
|
"build-compatible": "GULP_CUSTOM_BUILD_TARGET=compatible ./node_modules/.bin/gulp build",
|
|
12
|
-
"docker-dev-build
|
|
12
|
+
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t retold/fable:local",
|
|
13
13
|
"docker-dev-run": "docker run -it -d --name retold-fable-dev -p 30001:8080 -p 8086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/fable\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold/fable:local",
|
|
14
14
|
"docker-dev-shell": "docker exec -it retold-fable-dev /bin/bash"
|
|
15
15
|
},
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"async.eachlimit": "^0.5.2",
|
|
70
70
|
"async.waterfall": "^0.5.2",
|
|
71
|
+
"cachetrax": "^1.0.2",
|
|
71
72
|
"data-arithmatic": "^1.0.7",
|
|
72
73
|
"fable-log": "^3.0.10",
|
|
73
74
|
"fable-serviceproviderbase": "^3.0.3",
|
package/source/Fable.js
CHANGED
|
@@ -51,6 +51,7 @@ class Fable
|
|
|
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
53
|
this.serviceManager.addServiceType('Manifest', require('manyfest'));
|
|
54
|
+
this.serviceManager.addServiceType('ObjectCache', require('cachetrax'));
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
get isFable()
|
|
@@ -17,18 +17,30 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
17
17
|
this.dataFormat = this.fable.defaultServices.DataFormat;
|
|
18
18
|
|
|
19
19
|
this.serviceType = 'RestClient';
|
|
20
|
+
|
|
21
|
+
// This is a function that can be overridden, to allow the management
|
|
22
|
+
// of the request options before they are passed to the request library.
|
|
23
|
+
this.prepareRequestOptions = (pOptions) => { return pOptions; };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
preRequest(pOptions)
|
|
27
|
+
{
|
|
28
|
+
// Validate the options object
|
|
29
|
+
return this.prepareRequestOptions(pOptions);
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
executeChunkedRequest(pOptions, fCallback)
|
|
23
33
|
{
|
|
24
|
-
|
|
34
|
+
let tmpOptions = this.preRequest(pOptions);
|
|
35
|
+
|
|
36
|
+
tmpOptions.RequestStartTime = this.fable.log.getTimeStamp();
|
|
25
37
|
|
|
26
38
|
if (this.TraceLog)
|
|
27
39
|
{
|
|
28
|
-
this.fable.log.debug(`Beginning ${
|
|
40
|
+
this.fable.log.debug(`Beginning ${tmpOptions.method} request to ${tmpOptions.url} at ${tmpOptions.RequestStartTime}`);
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
return libSimpleGet(
|
|
43
|
+
return libSimpleGet(tmpOptions,
|
|
32
44
|
(pError, pResponse)=>
|
|
33
45
|
{
|
|
34
46
|
if (pError)
|
|
@@ -39,7 +51,7 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
39
51
|
if (this.TraceLog)
|
|
40
52
|
{
|
|
41
53
|
let tmpConnectTime = this.fable.log.getTimeStamp();
|
|
42
|
-
this.fable.log.debug(`--> ${
|
|
54
|
+
this.fable.log.debug(`--> ${tmpOptions.method} connected in ${this.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime, tmpConnectTime)}ms code ${pResponse.statusCode}`);
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
let tmpData = '';
|
|
@@ -50,7 +62,7 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
50
62
|
if (this.TraceLog)
|
|
51
63
|
{
|
|
52
64
|
let tmpChunkTime = this.fable.log.getTimeStamp();
|
|
53
|
-
this.fable.log.debug(`--> ${
|
|
65
|
+
this.fable.log.debug(`--> ${tmpOptions.method} data chunk size ${pChunk.length}b received in ${this.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime, tmpChunkTime)}ms`);
|
|
54
66
|
}
|
|
55
67
|
tmpData += pChunk;
|
|
56
68
|
});
|
|
@@ -60,7 +72,7 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
60
72
|
if (this.TraceLog)
|
|
61
73
|
{
|
|
62
74
|
let tmpCompletionTime = this.fable.log.getTimeStamp();
|
|
63
|
-
this.fable.log.debug(`==> ${
|
|
75
|
+
this.fable.log.debug(`==> ${tmpOptions.method} completed data size ${tmpData.length}b received in ${this.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime, tmpCompletionTime)}ms`);
|
|
64
76
|
}
|
|
65
77
|
return fCallback(pError, pResponse, tmpData);
|
|
66
78
|
});
|
|
@@ -71,14 +83,16 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
71
83
|
{
|
|
72
84
|
pOptions.json = true;
|
|
73
85
|
|
|
74
|
-
|
|
86
|
+
let tmpOptions = this.preRequest(pOptions);
|
|
87
|
+
|
|
88
|
+
tmpOptions.RequestStartTime = this.fable.log.getTimeStamp();
|
|
75
89
|
|
|
76
90
|
if (this.TraceLog)
|
|
77
91
|
{
|
|
78
|
-
this.fable.log.debug(`Beginning ${
|
|
92
|
+
this.fable.log.debug(`Beginning ${tmpOptions.method} JSON request to ${tmpOptions.url} at ${tmpOptions.RequestStartTime}`);
|
|
79
93
|
}
|
|
80
94
|
|
|
81
|
-
return libSimpleGet(
|
|
95
|
+
return libSimpleGet(tmpOptions,
|
|
82
96
|
(pError, pResponse)=>
|
|
83
97
|
{
|
|
84
98
|
if (pError)
|
|
@@ -89,7 +103,7 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
89
103
|
if (this.TraceLog)
|
|
90
104
|
{
|
|
91
105
|
let tmpConnectTime = this.fable.log.getTimeStamp();
|
|
92
|
-
this.fable.log.debug(`--> JSON ${
|
|
106
|
+
this.fable.log.debug(`--> JSON ${tmpOptions.method} connected in ${this.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime, tmpConnectTime)}ms code ${pResponse.statusCode}`);
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
pResponse.on('data', (pChunk) =>
|
|
@@ -97,7 +111,7 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
97
111
|
if (this.TraceLog)
|
|
98
112
|
{
|
|
99
113
|
let tmpChunkTime = this.fable.log.getTimeStamp();
|
|
100
|
-
this.fable.log.debug(`--> JSON ${
|
|
114
|
+
this.fable.log.debug(`--> JSON ${tmpOptions.method} data chunk size ${pChunk.length}b received in ${this.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime, tmpChunkTime)}ms`);
|
|
101
115
|
}
|
|
102
116
|
// In a JSON request, the chunk is the serialized method.
|
|
103
117
|
return fCallback(pError, pResponse, JSON.parse(pChunk));
|
|
@@ -108,7 +122,7 @@ class FableServiceRestClient extends libFableServiceBase
|
|
|
108
122
|
if (this.TraceLog)
|
|
109
123
|
{
|
|
110
124
|
let tmpCompletionTime = this.fable.log.getTimeStamp();
|
|
111
|
-
this.fable.log.debug(`==> JSON ${
|
|
125
|
+
this.fable.log.debug(`==> JSON ${tmpOptions.method} completed - received in ${this.dataFormat.formatTimeDelta(tmpOptions.RequestStartTime, tmpCompletionTime)}ms`);
|
|
112
126
|
}
|
|
113
127
|
});
|
|
114
128
|
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
'Object Cache Test',
|
|
17
|
+
function()
|
|
18
|
+
{
|
|
19
|
+
suite
|
|
20
|
+
(
|
|
21
|
+
'Basic object cache',
|
|
22
|
+
function()
|
|
23
|
+
{
|
|
24
|
+
test
|
|
25
|
+
(
|
|
26
|
+
'Leverage the object cache',
|
|
27
|
+
function(fDone)
|
|
28
|
+
{
|
|
29
|
+
let testFable = new libFable();
|
|
30
|
+
|
|
31
|
+
let testCache = testFable.serviceManager.instantiateServiceProvider('ObjectCache');
|
|
32
|
+
|
|
33
|
+
testCache.maxLength = 2;
|
|
34
|
+
|
|
35
|
+
// Cache some data
|
|
36
|
+
testCache.put('ABC', 'A');
|
|
37
|
+
testCache.put('DEF', 'D');
|
|
38
|
+
Expect(testCache._List.head.Datum).to.equal('ABC');
|
|
39
|
+
Expect(testCache._List.tail.Datum).to.equal('DEF');
|
|
40
|
+
Expect(testCache._List.length).to.equal(2);
|
|
41
|
+
|
|
42
|
+
testCache.put('GHI', 'G');
|
|
43
|
+
Expect(testCache._List.head.Datum).to.equal('DEF');
|
|
44
|
+
Expect(testCache._List.tail.Datum).to.equal('GHI');
|
|
45
|
+
Expect(testCache._List.length).to.equal(2);
|
|
46
|
+
|
|
47
|
+
testCache.put('JKL', 'J');
|
|
48
|
+
testCache.put('MNO', 'M');
|
|
49
|
+
Expect(testCache._List.head.Datum).to.equal('JKL');
|
|
50
|
+
Expect(testCache._List.tail.Datum).to.equal('MNO');
|
|
51
|
+
Expect(testCache._List.length).to.equal(2);
|
|
52
|
+
|
|
53
|
+
// Now grow the cache, allowing it to hold more items.
|
|
54
|
+
testCache.maxLength = 5
|
|
55
|
+
testCache.put('PQR', 'P');
|
|
56
|
+
testCache.put('STU', 'S');
|
|
57
|
+
Expect(testCache._List.head.Datum).to.equal('JKL');
|
|
58
|
+
Expect(testCache._List.tail.Datum).to.equal('STU');
|
|
59
|
+
Expect(testCache._List.length).to.equal(4);
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
testCache.put('VWX', 'V');
|
|
63
|
+
Expect(testCache._List.head.Datum).to.equal('JKL');
|
|
64
|
+
Expect(testCache._List.tail.Datum).to.equal('VWX');
|
|
65
|
+
Expect(testCache._List.length).to.equal(5);
|
|
66
|
+
|
|
67
|
+
testCache.put('YZ', 'Y');
|
|
68
|
+
Expect(testCache._List.head.Datum).to.equal('MNO');
|
|
69
|
+
Expect(testCache._List.tail.Datum).to.equal('YZ');
|
|
70
|
+
Expect(testCache._List.length).to.equal(5);
|
|
71
|
+
|
|
72
|
+
// Now shrink it again... the list will only maintain its length until a prune occurs
|
|
73
|
+
testCache.maxLength = 2;
|
|
74
|
+
|
|
75
|
+
testCache.put('012', '0');
|
|
76
|
+
Expect(testCache._List.head.Datum).to.equal('PQR');
|
|
77
|
+
Expect(testCache._List.tail.Datum).to.equal('012');
|
|
78
|
+
Expect(testCache._List.length).to.equal(5);
|
|
79
|
+
|
|
80
|
+
testCache.prune((pRemovedRecords)=>
|
|
81
|
+
{
|
|
82
|
+
Expect(testCache._List.head.Datum).to.equal('YZ');
|
|
83
|
+
Expect(testCache._List.tail.Datum).to.equal('012');
|
|
84
|
+
Expect(testCache._List.length).to.equal(2);
|
|
85
|
+
return fDone();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
);
|
package/test/Manifest_tests.js
CHANGED
package/test/RestClient_test.js
CHANGED
|
@@ -57,6 +57,12 @@ suite
|
|
|
57
57
|
// Instantiate the RestClient Service Provider
|
|
58
58
|
let tmpRestClient = testFable.serviceManager.instantiateServiceProvider('RestClient', {TraceLog: true}, 'RestClient-99');
|
|
59
59
|
|
|
60
|
+
tmpRestClient.prepareRequestOptions = (pOptions) =>
|
|
61
|
+
{
|
|
62
|
+
pOptions.headers = {'Content-Type':'application/json'};
|
|
63
|
+
return pOptions;
|
|
64
|
+
};
|
|
65
|
+
|
|
60
66
|
// Download the wiktionary entry for dog!
|
|
61
67
|
tmpRestClient.postJSON({url: 'http://localhost:8086/1.0/Author', body:{Name:'Test Author'}},
|
|
62
68
|
(pError, pResponse, pBody)=>
|