fable 3.0.37 → 3.0.38
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/.config/vscode-sqltools/runningInfo.json +1 -1
- package/dist/fable.js +38 -8
- package/dist/fable.min.js +55 -3
- package/dist/fable.min.js.map +1 -1
- package/gulpfile-config.json +2 -2
- package/package.json +3 -2
- package/retold-harness/bookstore-serve-meadow-endpoint-apis.js +2 -4
- package/retold-harness/package.json +3 -3
- package/source/Fable.js +8 -17
- package/source/services/Fable-Service-CSVParser.js +199 -0
- package/source/services/Fable-Service-DataFormat.js +0 -3
- package/test/CSVParser_tests.js +66 -0
- package/test/RestClient_test.js +1 -1
- package/test/data/books.csv +10001 -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.38",
|
|
4
4
|
"description": "An entity behavior management and API bundling library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"build": "./node_modules/.bin/gulp build",
|
|
11
11
|
"build-compatible": "GULP_CUSTOM_BUILD_TARGET=compatible ./node_modules/.bin/gulp build",
|
|
12
12
|
"docker-dev-build-image": "docker build ./ -f Dockerfile_LUXURYCode -t retold/fable:local",
|
|
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"
|
|
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
|
+
"docker-dev-shell": "docker exec -it retold-fable-dev /bin/bash"
|
|
14
15
|
},
|
|
15
16
|
"mocha": {
|
|
16
17
|
"diff": true,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
+
* @license MIT
|
|
6
7
|
* @author <steven@velozo.com>
|
|
7
8
|
*/
|
|
8
9
|
|
|
@@ -74,16 +75,13 @@ let fStartServiceServer = (fInitializeCallback) =>
|
|
|
74
75
|
_MeadowEndpoints[tmpDALEntityName].connectRoutes(_Orator.webServer);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
let tmpNames = Object.keys(_MeadowEndpoints.Book);
|
|
78
|
-
console.log(JSON.stringify(tmpNames));
|
|
79
|
-
|
|
80
78
|
// 100. Add a post processing hook to the Book DAL on single reads
|
|
81
79
|
/*
|
|
82
80
|
This post processing step will look for all book author joins then
|
|
83
81
|
load all appropriate authors and stuff them in the book record before
|
|
84
82
|
returning it.
|
|
85
83
|
*/
|
|
86
|
-
_MeadowEndpoints.Book.
|
|
84
|
+
_MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior('Read-PostOperation',
|
|
87
85
|
(pRequest, pRequestState, fComplete) =>
|
|
88
86
|
{
|
|
89
87
|
// Get the join records
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"async": "^3.2.4",
|
|
14
|
-
"fable": "^3.0.
|
|
14
|
+
"fable": "^3.0.37",
|
|
15
15
|
"meadow": "^2.0.4",
|
|
16
|
-
"meadow-endpoints": "^
|
|
17
|
-
"mysql2": "^3.3.
|
|
16
|
+
"meadow-endpoints": "^4.0.2",
|
|
17
|
+
"mysql2": "^3.3.1",
|
|
18
18
|
"orator": "^3.0.11",
|
|
19
19
|
"orator-serviceserver-restify": "^1.0.4",
|
|
20
20
|
"papaparse": "^5.4.1"
|
package/source/Fable.js
CHANGED
|
@@ -9,15 +9,6 @@ const libFableLog = require('fable-log');
|
|
|
9
9
|
|
|
10
10
|
const libFableServiceManager = require('./Fable-ServiceManager.js');
|
|
11
11
|
|
|
12
|
-
// Default Services
|
|
13
|
-
const libFableServiceEnvironmentData = require('./services/Fable-Service-EnvironmentData.js');
|
|
14
|
-
const libFableServiceDataFormat = require('./services/Fable-Service-DataFormat.js');
|
|
15
|
-
const libFableServiceMetaTemplate = require('./services/Fable-Service-MetaTemplate.js');
|
|
16
|
-
const libFableServiceOperation = require('./services/Fable-Service-Operation.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');
|
|
20
|
-
|
|
21
12
|
class Fable
|
|
22
13
|
{
|
|
23
14
|
constructor(pSettings)
|
|
@@ -51,14 +42,14 @@ class Fable
|
|
|
51
42
|
this.serviceManager.connectPreinitServiceProviderInstance(this._coreServices.SettingsManager);
|
|
52
43
|
|
|
53
44
|
// Initialize and instantiate the default baked-in Data Arithmatic service
|
|
54
|
-
this.serviceManager.addAndInstantiateServiceType('EnvironmentData',
|
|
55
|
-
this.serviceManager.addServiceType('Template',
|
|
56
|
-
this.serviceManager.addServiceType('MetaTemplate',
|
|
57
|
-
this.serviceManager.addAndInstantiateServiceType('DataFormat',
|
|
58
|
-
this.serviceManager.addAndInstantiateServiceType('Utility',
|
|
59
|
-
this.serviceManager.addServiceType('Operation',
|
|
60
|
-
this.serviceManager.addServiceType('RestClient',
|
|
61
|
-
|
|
45
|
+
this.serviceManager.addAndInstantiateServiceType('EnvironmentData', require('./services/Fable-Service-EnvironmentData.js'));
|
|
46
|
+
this.serviceManager.addServiceType('Template', require('./services/Fable-Service-Template.js'));
|
|
47
|
+
this.serviceManager.addServiceType('MetaTemplate', require('./services/Fable-Service-MetaTemplate.js'));
|
|
48
|
+
this.serviceManager.addAndInstantiateServiceType('DataFormat', require('./services/Fable-Service-DataFormat.js'));
|
|
49
|
+
this.serviceManager.addAndInstantiateServiceType('Utility', require('./services/Fable-Service-Utility.js'));
|
|
50
|
+
this.serviceManager.addServiceType('Operation', require('./services/Fable-Service-Operation.js'));
|
|
51
|
+
this.serviceManager.addServiceType('RestClient', require('./services/Fable-Service-RestClient.js'));
|
|
52
|
+
this.serviceManager.addServiceType('CSVParser', require('./services/Fable-Service-CSVParser.js'));
|
|
62
53
|
}
|
|
63
54
|
|
|
64
55
|
get settings()
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const libFableServiceProviderBase = require('fable-serviceproviderbase');
|
|
2
|
+
/**
|
|
3
|
+
* Parsing CSVs. Why? Because it's a thing that needs to be done.
|
|
4
|
+
*
|
|
5
|
+
* 1. And the other node CSV parsers had issues with the really messy files we had.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* 2. None of the CSV parsers dealt with and multi-line quoted string columns
|
|
9
|
+
* which are apparently a-ok according to the official spec.
|
|
10
|
+
* Plus a lot of them are asynchronous because apparently that's the best way to
|
|
11
|
+
* do anything; unfortunately some files have a sequence issue with that.
|
|
12
|
+
*
|
|
13
|
+
* @class CSVParser
|
|
14
|
+
*/
|
|
15
|
+
class CSVParser extends libFableServiceProviderBase
|
|
16
|
+
{
|
|
17
|
+
constructor(pFable, pOptions, pServiceHash)
|
|
18
|
+
{
|
|
19
|
+
super(pFable, pOptions, pServiceHash);
|
|
20
|
+
|
|
21
|
+
this.serviceType = 'CSVParser';
|
|
22
|
+
|
|
23
|
+
this.Header = [];
|
|
24
|
+
this.HeaderFieldNames = [];
|
|
25
|
+
|
|
26
|
+
this.Delimiter = ',';
|
|
27
|
+
this.QuoteCharacter = '"';
|
|
28
|
+
|
|
29
|
+
this.CleanCharacters = ['\r'];
|
|
30
|
+
|
|
31
|
+
this.HeaderLineIndex = 0;
|
|
32
|
+
this.HasHeader = true;
|
|
33
|
+
this.HasSetHeader = false;
|
|
34
|
+
this.EmitHeader = false;
|
|
35
|
+
|
|
36
|
+
this.EmitJSON = true;
|
|
37
|
+
|
|
38
|
+
this.EscapedQuoteString = '"';
|
|
39
|
+
|
|
40
|
+
// Current Line Parsing State
|
|
41
|
+
this.CurrentLine = '';
|
|
42
|
+
this.CurrentRecord = [];
|
|
43
|
+
|
|
44
|
+
this.InQuote = false;
|
|
45
|
+
this.InEscapedQuote = false;
|
|
46
|
+
|
|
47
|
+
this.LinesParsed = 0;
|
|
48
|
+
this.RowsEmitted = 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
marshalRowToJSON(pRowArray)
|
|
52
|
+
{
|
|
53
|
+
if (!Array.isArray(pRowArray))
|
|
54
|
+
{
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (let i = this.HeaderFieldNames.length; i < pRowArray.length; i++)
|
|
59
|
+
{
|
|
60
|
+
this.HeaderFieldNames[i] = `${i}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let tmpObject = {};
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < pRowArray.length; i++)
|
|
66
|
+
{
|
|
67
|
+
tmpObject[this.HeaderFieldNames[i]] = pRowArray[i];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return tmpObject;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Set the header data, for use in marshalling to JSON.
|
|
74
|
+
setHeader (pHeaderArray)
|
|
75
|
+
{
|
|
76
|
+
this.Header = pHeaderArray;
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < this.Header.length; i++)
|
|
79
|
+
{
|
|
80
|
+
if (typeof(this.Header[i]) == 'undefined')
|
|
81
|
+
{
|
|
82
|
+
this.HeaderFieldNames[i] = `${i}`;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
{
|
|
86
|
+
this.HeaderFieldNames[i] = this.Header[i].toString();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
resetRowState()
|
|
92
|
+
{
|
|
93
|
+
this.CurrentRecord = [];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pushLine()
|
|
97
|
+
{
|
|
98
|
+
for (let i = 0; i < this.CleanCharacters.length; i++)
|
|
99
|
+
{
|
|
100
|
+
this.CurrentLine = this.CurrentLine.replace(this.CleanCharacters[i],'');
|
|
101
|
+
}
|
|
102
|
+
this.CurrentRecord.push(this.CurrentLine);
|
|
103
|
+
this.CurrentLine = '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
emitRow(pFormatAsJSON)
|
|
107
|
+
{
|
|
108
|
+
let tmpFormatAsJSON = (typeof(pFormatAsJSON) == 'undefined') ? this.EmitJSON : pFormatAsJSON;
|
|
109
|
+
|
|
110
|
+
this.RowsEmitted++;
|
|
111
|
+
let tmpCompletedRecord = this.CurrentRecord;
|
|
112
|
+
this.CurrentRecord = [];
|
|
113
|
+
|
|
114
|
+
if (tmpFormatAsJSON)
|
|
115
|
+
{
|
|
116
|
+
return this.marshalRowToJSON(tmpCompletedRecord);
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
{
|
|
120
|
+
return tmpCompletedRecord;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
parseCSVLine (pLineString)
|
|
125
|
+
{
|
|
126
|
+
this.LinesParsed++;
|
|
127
|
+
|
|
128
|
+
for (let i = 0; i < pLineString.length; i++)
|
|
129
|
+
{
|
|
130
|
+
if ((!this.InQuote) && (pLineString[i] == this.Delimiter))
|
|
131
|
+
{
|
|
132
|
+
this.pushLine();
|
|
133
|
+
}
|
|
134
|
+
else if (pLineString[i] == this.QuoteCharacter)
|
|
135
|
+
{
|
|
136
|
+
// If we are in the second part of an escaped quote, ignore it.
|
|
137
|
+
if (this.InEscapedQuote)
|
|
138
|
+
{
|
|
139
|
+
this.InEscapedQuote = false;
|
|
140
|
+
}
|
|
141
|
+
// If we aren't in a quote, enter quote
|
|
142
|
+
else if (!this.InQuote)
|
|
143
|
+
{
|
|
144
|
+
this.InQuote = true;
|
|
145
|
+
}
|
|
146
|
+
// We are in a quote, so peek forward to see if this is an "escaped" quote pair
|
|
147
|
+
else if ((i < pLineString.length) && (pLineString[i+1] == this.QuoteCharacter))
|
|
148
|
+
{
|
|
149
|
+
this.CurrentLine += this.EscapedQuoteString;
|
|
150
|
+
this.InEscapedQuote = true;
|
|
151
|
+
}
|
|
152
|
+
// We are in a quote, this isn't an "escaped" quote pair, so go out of quote mode
|
|
153
|
+
else
|
|
154
|
+
{
|
|
155
|
+
this.InQuote = false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else
|
|
159
|
+
{
|
|
160
|
+
this.CurrentLine += pLineString[i];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// See if we are in a multiline quoted entry -- if not, emit the row.
|
|
165
|
+
if (!this.InQuote)
|
|
166
|
+
{
|
|
167
|
+
// Push the last remaining column from the buffer to the current line.
|
|
168
|
+
this.pushLine();
|
|
169
|
+
|
|
170
|
+
// Check to see if there is a header -- and if so, if this is the header row
|
|
171
|
+
if (this.HasHeader && !this.HasSetHeader && (this.RowsEmitted == this.HeaderLineIndex))
|
|
172
|
+
{
|
|
173
|
+
this.HasSetHeader = true;
|
|
174
|
+
// Override the format as json bit
|
|
175
|
+
this.setHeader(this.emitRow(false));
|
|
176
|
+
|
|
177
|
+
// No matter what, formatting this as JSON is silly and we don't want to go there anyway.
|
|
178
|
+
if (this.EmitHeader)
|
|
179
|
+
{
|
|
180
|
+
return this.Header;
|
|
181
|
+
}
|
|
182
|
+
else
|
|
183
|
+
{
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
{
|
|
189
|
+
return this.emitRow();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else
|
|
193
|
+
{
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = CSVParser;
|
|
@@ -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
|
+
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
|
+
'CSV Parser',
|
|
20
|
+
function()
|
|
21
|
+
{
|
|
22
|
+
suite
|
|
23
|
+
(
|
|
24
|
+
'Parse CSV',
|
|
25
|
+
function()
|
|
26
|
+
{
|
|
27
|
+
test
|
|
28
|
+
(
|
|
29
|
+
'Pull CSV Data',
|
|
30
|
+
function(fDone)
|
|
31
|
+
{
|
|
32
|
+
let testFable = new libFable();
|
|
33
|
+
let tmpCSVParser = testFable.serviceManager.instantiateServiceProvider('CSVParser', {Name: 'Big Complex Integration Operation'}, 'CSV Parser-123');
|
|
34
|
+
let tmpRecords = [];
|
|
35
|
+
|
|
36
|
+
const tmpReadline = libReadline.createInterface(
|
|
37
|
+
{
|
|
38
|
+
input: libFS.createReadStream(`${__dirname}/data/books.csv`),
|
|
39
|
+
crlfDelay: Infinity
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
tmpReadline.on('line',
|
|
43
|
+
(pLine) =>
|
|
44
|
+
{
|
|
45
|
+
let tmpRecord = tmpCSVParser.parseCSVLine(pLine);
|
|
46
|
+
if (tmpRecord)
|
|
47
|
+
{
|
|
48
|
+
tmpRecords.push(tmpRecord);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
tmpReadline.on('close',
|
|
53
|
+
() =>
|
|
54
|
+
{
|
|
55
|
+
console.log(`Readline closed... testing import!`);
|
|
56
|
+
Expect(tmpRecords.length).to.equal(10000);
|
|
57
|
+
Expect(tmpRecords[0].authors).to.equal('Suzanne Collins');
|
|
58
|
+
return fDone();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
);
|
package/test/RestClient_test.js
CHANGED