fable 3.0.85 → 3.0.86
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/dist/fable.compatible.js +2 -3
- package/dist/fable.compatible.min.js +2 -2
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +2 -3
- package/dist/fable.min.js +1 -1
- package/dist/fable.min.js.map +1 -1
- package/package.json +3 -2
- package/source/services/Fable-Service-FilePersistence-Web.js +16 -21
- package/source/services/Fable-Service-FilePersistence.js +28 -18
- package/source/services/Fable-Service-Operation.js +0 -1
- package/test/FilePersistence_tests.js +37 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fable",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.86",
|
|
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": "npx quack build",
|
|
11
11
|
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t fable-image:local",
|
|
12
12
|
"docker-dev-run": "docker run -it -d --name fable-dev -p 30001:8080 -p 38086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/fable\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" fable-image:local",
|
|
13
|
-
"docker-dev-shell": "docker exec -it fable-dev /bin/bash"
|
|
13
|
+
"docker-dev-shell": "docker exec -it fable-dev /bin/bash",
|
|
14
|
+
"tests": "./node_modules/mocha/bin/_mocha -u tdd --exit -R spec --grep"
|
|
14
15
|
},
|
|
15
16
|
"mocha": {
|
|
16
17
|
"diff": true,
|
|
@@ -5,33 +5,28 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
5
5
|
{
|
|
6
6
|
constructor(pFable, pOptions, pServiceHash)
|
|
7
7
|
{
|
|
8
|
-
|
|
8
|
+
super(pFable, pOptions, pServiceHash);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!this.options.hasOwnProperty('Mode'))
|
|
13
|
-
{
|
|
14
|
-
this.options.Mode = parseInt('0777', 8) & ~process.umask();
|
|
15
|
-
}
|
|
10
|
+
this.serviceType = 'FilePersistence';
|
|
16
11
|
}
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
existsSync(pPath)
|
|
14
|
+
{
|
|
15
|
+
//return libFS.existsSync(pPath);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
exists(pPath, fCallback)
|
|
20
|
+
{
|
|
21
|
+
let tmpFileExists = this.existsSync(pPath);;
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
return fCallback(null, tmpFileExists);
|
|
24
|
+
}
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
makeFolderRecursive(pParameters, fCallback)
|
|
27
|
+
{
|
|
28
|
+
return fCallback();
|
|
29
|
+
}
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
module.exports = FableServiceFilePersistence;
|
|
@@ -2,6 +2,7 @@ const libFableServiceBase = require('../Fable-ServiceManager.js').ServiceProvide
|
|
|
2
2
|
|
|
3
3
|
const libFS = require('fs');
|
|
4
4
|
const libPath = require('path');
|
|
5
|
+
const libReadline = require('readline');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class FableServiceFilePersistence extends libFableServiceBase
|
|
@@ -17,8 +18,9 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
17
18
|
this.options.Mode = parseInt('0777', 8) & ~process.umask();
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
21
|
+
this.libFS = libFS;
|
|
22
|
+
this.libPath = libPath;
|
|
23
|
+
this.libReadline = libReadline;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
joinPath(...pPathArray)
|
|
@@ -81,26 +83,34 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
getDefaultOutputPath(pFileName)
|
|
86
|
+
lineReaderFactory(pFilePath, fOnLine, fOnComplete, fOnError)
|
|
87
87
|
{
|
|
88
|
-
|
|
89
|
-
}
|
|
88
|
+
let tmpLineReader = {};
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
if (typeof(pFilePath) != 'string')
|
|
91
|
+
{
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
return this.writeFileSyncFromObject(this.getDefaultOutputPath(pFileName), pObject);
|
|
99
|
-
}
|
|
95
|
+
tmpLineReader.filePath = pFilePath;
|
|
100
96
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
tmpLineReader.fileStream = libFS.createReadStream(tmpLineReader.filePath);
|
|
98
|
+
|
|
99
|
+
tmpLineReader.reader = libReadline.createInterface({ input: tmpLineReader.fileStream, crlfDelay: Infinity });
|
|
100
|
+
|
|
101
|
+
if (typeof(fOnError) === 'function')
|
|
102
|
+
{
|
|
103
|
+
tmpLineReader.reader.on('error', fOnError);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
tmpLineReader.reader.on('line', (typeof(fOnLine) === 'function') ? fOnLine : () => {});
|
|
107
|
+
|
|
108
|
+
if (typeof(fOnComplete) === 'function')
|
|
109
|
+
{
|
|
110
|
+
tmpLineReader.reader.on('close', fOnComplete);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return tmpLineReader;
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
// Folder management
|
|
@@ -11,8 +11,6 @@ var libFable = require('../source/Fable.js');
|
|
|
11
11
|
var Chai = require("chai");
|
|
12
12
|
var Expect = Chai.expect;
|
|
13
13
|
|
|
14
|
-
// https://en.wiktionary.org/w/api.php?action=parse&prop=wikitext&format=json&page=dog
|
|
15
|
-
|
|
16
14
|
suite
|
|
17
15
|
(
|
|
18
16
|
'Fable FilePersistence',
|
|
@@ -42,6 +40,41 @@ suite
|
|
|
42
40
|
}
|
|
43
41
|
);
|
|
44
42
|
test
|
|
43
|
+
(
|
|
44
|
+
'Read a file line-by-line',
|
|
45
|
+
function(fTestComplete)
|
|
46
|
+
{
|
|
47
|
+
let testFable = new libFable();
|
|
48
|
+
let tmpFilePersistence = testFable.serviceManager.instantiateServiceProvider('FilePersistence');
|
|
49
|
+
let tmpFirstLine = 'id,book_id,best_book_id,work_id,books_count,isbn,isbn13,authors,original_publication_year,original_title,title,language_code,average_rating,ratings_count,work_ratings_count,work_text_reviews_count,ratings_1,ratings_2,ratings_3,ratings_4,ratings_5,image_url,small_image_url';
|
|
50
|
+
|
|
51
|
+
let tmpLineReader = tmpFilePersistence.lineReaderFactory(`${__dirname}/data/books.csv`,
|
|
52
|
+
(pLine) =>
|
|
53
|
+
{
|
|
54
|
+
if (tmpFirstLine)
|
|
55
|
+
{
|
|
56
|
+
Expect(pLine).to.equal(tmpFirstLine);
|
|
57
|
+
tmpFirstLine = false;
|
|
58
|
+
}
|
|
59
|
+
//console.log(pLine);
|
|
60
|
+
},
|
|
61
|
+
() =>
|
|
62
|
+
{
|
|
63
|
+
console.log('LINE-BY-LINE FILE READING COMPLETE; GOOD DAY SIR.');
|
|
64
|
+
return fTestComplete();
|
|
65
|
+
},
|
|
66
|
+
(pError) =>
|
|
67
|
+
{
|
|
68
|
+
console.log(`Error reading file line-by-line: ${pError}`);
|
|
69
|
+
});
|
|
70
|
+
if (!tmpLineReader)
|
|
71
|
+
{
|
|
72
|
+
Expect(false).to.equal(true, 'The line reader was not initialized properly!')
|
|
73
|
+
return fTestComplete();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
test
|
|
45
78
|
(
|
|
46
79
|
'Create, write, read and then delete a file.',
|
|
47
80
|
function(fTestComplete)
|
|
@@ -62,7 +95,7 @@ suite
|
|
|
62
95
|
|
|
63
96
|
// Now delete the file
|
|
64
97
|
tmpFilePersistence.deleteFileSync(tmpLogFilePath);
|
|
65
|
-
|
|
98
|
+
|
|
66
99
|
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
67
100
|
|
|
68
101
|
return fTestComplete();
|
|
@@ -139,7 +172,7 @@ suite
|
|
|
139
172
|
|
|
140
173
|
// Now delete the file
|
|
141
174
|
tmpFilePersistence.deleteFileSync(tmpLogFilePath);
|
|
142
|
-
|
|
175
|
+
|
|
143
176
|
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
144
177
|
|
|
145
178
|
return fTestComplete();
|