@ezs/basics 1.23.2 → 1.23.4
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/CHANGELOG.md +22 -0
- package/lib/csv-parse.js +12 -7
- package/lib/txt-parse.js +8 -1
- package/lib/url-connect.js +6 -22
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.23.4](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.3...@ezs/basics@1.23.4) (2023-03-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* 🐛 CSV.stream not support multi-byte utf8 characters ([1e15c9c](https://github.com/Inist-CNRS/ezs/commit/1e15c9c9061f8927d67bec36577e7c0d5bb15d8e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.23.3](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.2...@ezs/basics@1.23.3) (2023-02-27)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* 🐛 fetch timeout vs feed timeout ([163e0bf](https://github.com/Inist-CNRS/ezs/commit/163e0bf81df5f3d8ef7d2fedc6b8bf95ec2c8534))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [1.23.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.1...@ezs/basics@1.23.2) (2023-02-17)
|
|
7
29
|
|
|
8
30
|
|
package/lib/csv-parse.js
CHANGED
|
@@ -9,25 +9,30 @@ var _csvString = _interopRequireDefault(require("csv-string"));
|
|
|
9
9
|
|
|
10
10
|
var _streamWrite = _interopRequireDefault(require("stream-write"));
|
|
11
11
|
|
|
12
|
+
var _string_decoder = require("string_decoder");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
14
16
|
function CSVParse(data, feed) {
|
|
15
17
|
const separator = this.getParam('separator');
|
|
16
18
|
const quote = this.getParam('quote');
|
|
17
19
|
|
|
18
|
-
if (!this.
|
|
19
|
-
this.
|
|
20
|
+
if (!this.decoder) {
|
|
21
|
+
this.decoder = new _string_decoder.StringDecoder('utf8');
|
|
22
|
+
this.input = _csvString.default.createStream({
|
|
20
23
|
separator,
|
|
21
24
|
quote
|
|
22
25
|
});
|
|
23
|
-
this.
|
|
26
|
+
this.whenFinish = feed.flow(this.input);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.
|
|
29
|
+
if (this.isLast()) {
|
|
30
|
+
this.decoder.end();
|
|
31
|
+
this.whenFinish.finally(() => feed.close());
|
|
32
|
+
return this.input.end();
|
|
30
33
|
}
|
|
34
|
+
|
|
35
|
+
(0, _streamWrite.default)(this.input, Buffer.isBuffer(data) ? this.decoder.write(data) : data, () => feed.end());
|
|
31
36
|
}
|
|
32
37
|
/**
|
|
33
38
|
* Take `String` and parse it as CSV to generate arrays.
|
package/lib/txt-parse.js
CHANGED
|
@@ -5,8 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _string_decoder = require("string_decoder");
|
|
9
|
+
|
|
8
10
|
function TXTParse(data, feed) {
|
|
11
|
+
if (!this.decoder) {
|
|
12
|
+
this.decoder = new _string_decoder.StringDecoder('utf8');
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
if (this.isLast()) {
|
|
16
|
+
this.decoder.end();
|
|
10
17
|
return feed.end();
|
|
11
18
|
}
|
|
12
19
|
|
|
@@ -23,7 +30,7 @@ function TXTParse(data, feed) {
|
|
|
23
30
|
let lines;
|
|
24
31
|
|
|
25
32
|
if (Buffer.isBuffer(data)) {
|
|
26
|
-
lines =
|
|
33
|
+
lines = this.decoder.write(data).split(separator);
|
|
27
34
|
} else if (typeof data === 'string') {
|
|
28
35
|
lines = data.split(separator);
|
|
29
36
|
} else {
|
package/lib/url-connect.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.default = URLConnect;
|
|
|
7
7
|
|
|
8
8
|
var _JSONStream = _interopRequireDefault(require("JSONStream"));
|
|
9
9
|
|
|
10
|
+
var _from = _interopRequireDefault(require("from"));
|
|
11
|
+
|
|
10
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
11
13
|
|
|
12
14
|
var _streamWrite = _interopRequireDefault(require("stream-write"));
|
|
@@ -70,6 +72,7 @@ async function URLConnect(data, feed) {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
const parameters = {
|
|
75
|
+
timeout,
|
|
73
76
|
method: 'POST',
|
|
74
77
|
body: bodyIn,
|
|
75
78
|
headers
|
|
@@ -82,10 +85,6 @@ async function URLConnect(data, feed) {
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
const controller = new _nodeAbortController.default();
|
|
85
|
-
const timeoutHandle = setTimeout(() => {
|
|
86
|
-
(0, _debug.default)('ezs')(`The maximum time allowed to start sending data has been reached (${timeout} msec).`);
|
|
87
|
-
controller.abort();
|
|
88
|
-
}, timeout);
|
|
89
88
|
const response = await (0, _fetchWithProxy.default)(url, { ...parameters,
|
|
90
89
|
signal: controller.signal
|
|
91
90
|
});
|
|
@@ -99,30 +98,15 @@ async function URLConnect(data, feed) {
|
|
|
99
98
|
|
|
100
99
|
if (retries === 1) {
|
|
101
100
|
const bodyOut = json ? response.body.pipe(_JSONStream.default.parse('*')) : response.body;
|
|
102
|
-
bodyOut.once('data', () => {
|
|
103
|
-
clearTimeout(timeoutHandle);
|
|
104
|
-
});
|
|
105
101
|
bodyOut.once('error', e => {
|
|
102
|
+
controller.abort();
|
|
106
103
|
output.emit('error', e);
|
|
107
|
-
clearTimeout(timeoutHandle);
|
|
108
104
|
});
|
|
109
105
|
bodyOut.pipe(output);
|
|
110
106
|
} else {
|
|
111
107
|
const bodyOutRaw = await (0, _getStream.default)(response.body);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (json) {
|
|
115
|
-
try {
|
|
116
|
-
const bodyOut = JSON.parse(bodyOutRaw);
|
|
117
|
-
bodyOut.forEach(item => output.write(item));
|
|
118
|
-
} catch (ee) {
|
|
119
|
-
throw ee;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
output.write(bodyOutRaw);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
output.end();
|
|
108
|
+
const bodyOutArray = JSON.parse(bodyOutRaw);
|
|
109
|
+
(0, _from.default)(bodyOutArray).pipe(output);
|
|
126
110
|
}
|
|
127
111
|
}, {
|
|
128
112
|
retries
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezs/basics",
|
|
3
3
|
"description": "Basics statements for EZS",
|
|
4
|
-
"version": "1.23.
|
|
4
|
+
"version": "1.23.4",
|
|
5
5
|
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"debug": "4.3.3",
|
|
13
13
|
"fetch-with-proxy": "3.0.1",
|
|
14
14
|
"flat": "5.0.2",
|
|
15
|
+
"from": "0.1.7",
|
|
15
16
|
"get-stream": "6.0.1",
|
|
16
17
|
"higher-path": "1.0.0",
|
|
17
18
|
"lodash.escaperegexp": "4.1.2",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"directories": {
|
|
39
40
|
"test": "test"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "8da84f8d6833a91a2ae87fdb635070a811c3f9ef",
|
|
42
43
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
43
44
|
"keywords": [
|
|
44
45
|
"ezs"
|