@ezs/basics 2.5.6 → 2.5.8
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/README.md +1 -5
- package/lib/csv-string.js +3 -1
- package/lib/url-connect.js +12 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -731,14 +731,10 @@ The output will be the returned content of URL.
|
|
|
731
731
|
|
|
732
732
|
Useful to send JSON data to an API and get results.
|
|
733
733
|
|
|
734
|
-
Warning :
|
|
735
|
-
if retries === 1, it will directly use the stream
|
|
736
|
-
to connect to the server otherwise the stream will be fully
|
|
737
|
-
read to be buffered and sent to the server (n times)
|
|
738
|
-
|
|
739
734
|
#### Parameters
|
|
740
735
|
|
|
741
736
|
- `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** URL to fetch
|
|
737
|
+
- `streaming` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Direct connection to the Object Stream server (disables the retries setting) (optional, default `false`)
|
|
742
738
|
- `json` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Parse as JSON the content of URL (optional, default `false`)
|
|
743
739
|
- `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
|
|
744
740
|
- `noerror` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Ignore all errors (optional, default `false`)
|
package/lib/csv-string.js
CHANGED
|
@@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _csvString = _interopRequireDefault(require("csv-string"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
const isNullOrUndefined = value => value === undefined || value === null;
|
|
9
10
|
function strict(data, sep) {
|
|
10
11
|
const q = new RegExp('"', 'g');
|
|
11
12
|
let line = '';
|
|
12
13
|
let s = '';
|
|
13
14
|
Object.keys(data).forEach(key => {
|
|
14
|
-
|
|
15
|
+
const cell = isNullOrUndefined(data[key]) ? '' : data[key];
|
|
16
|
+
line = line.concat(s.concat('"').concat(String(cell).replace(q, '""')).concat('"'));
|
|
15
17
|
s = sep;
|
|
16
18
|
});
|
|
17
19
|
return line.concat('\r\n');
|
package/lib/url-connect.js
CHANGED
|
@@ -21,13 +21,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
*
|
|
22
22
|
* Useful to send JSON data to an API and get results.
|
|
23
23
|
*
|
|
24
|
-
* Warning :
|
|
25
|
-
* if retries === 1, it will directly use the stream
|
|
26
|
-
* to connect to the server otherwise the stream will be fully
|
|
27
|
-
* read to be buffered and sent to the server (n times)
|
|
28
|
-
*
|
|
29
24
|
* @name URLConnect
|
|
30
25
|
* @param {String} [url] URL to fetch
|
|
26
|
+
* @param {String} [streaming=false] Direct connection to the Object Stream server (disables the retries setting)
|
|
31
27
|
* @param {String} [json=false] Parse as JSON the content of URL
|
|
32
28
|
* @param {Number} [timeout=1000] Timeout in milliseconds
|
|
33
29
|
* @param {Boolean} [noerror=false] Ignore all errors
|
|
@@ -37,6 +33,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
37
33
|
*/
|
|
38
34
|
async function URLConnect(data, feed) {
|
|
39
35
|
const url = this.getParam('url');
|
|
36
|
+
const streaming = Boolean(this.getParam('streaming', false));
|
|
40
37
|
const retries = Number(this.getParam('retries', 5));
|
|
41
38
|
const noerror = Boolean(this.getParam('noerror', false));
|
|
42
39
|
const json = this.getParam('json', true);
|
|
@@ -53,7 +50,7 @@ async function URLConnect(data, feed) {
|
|
|
53
50
|
(0, _streamWrite.default)(this.input, data, () => feed.end());
|
|
54
51
|
const streamIn = this.input.pipe(ezs(encoder));
|
|
55
52
|
let bodyIn;
|
|
56
|
-
if (
|
|
53
|
+
if (streaming) {
|
|
57
54
|
bodyIn = streamIn.pipe(ezs.toBuffer());
|
|
58
55
|
} else {
|
|
59
56
|
bodyIn = await (0, _getStream.default)(streamIn);
|
|
@@ -81,24 +78,22 @@ async function URLConnect(data, feed) {
|
|
|
81
78
|
err.responseText = text;
|
|
82
79
|
throw err;
|
|
83
80
|
}
|
|
84
|
-
if (
|
|
81
|
+
if (streaming) {
|
|
85
82
|
const bodyOut = json ? response.body.pipe(_JSONStream.default.parse('*')) : response.body;
|
|
86
83
|
bodyOut.once('error', e => {
|
|
87
84
|
controller.abort();
|
|
88
85
|
output.emit('error', e);
|
|
89
86
|
});
|
|
90
|
-
bodyOut.pipe(output);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} else {
|
|
97
|
-
response.body.pipe(output);
|
|
98
|
-
}
|
|
87
|
+
return bodyOut.pipe(output);
|
|
88
|
+
}
|
|
89
|
+
if (json) {
|
|
90
|
+
const bodyOutRaw = await (0, _getStream.default)(response.body);
|
|
91
|
+
const bodyOutArray = JSON.parse(bodyOutRaw);
|
|
92
|
+
return (0, _from.default)(bodyOutArray).pipe(output);
|
|
99
93
|
}
|
|
94
|
+
return response.body.pipe(output);
|
|
100
95
|
}, {
|
|
101
|
-
retries
|
|
96
|
+
retries: streaming ? 0 : retries
|
|
102
97
|
});
|
|
103
98
|
} catch (e) {
|
|
104
99
|
if (!noerror) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezs/basics",
|
|
3
3
|
"description": "Basics statements for EZS",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.8",
|
|
5
5
|
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"directories": {
|
|
42
42
|
"test": "test"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "8240602a9eb82e247626908cb578087b180b6d2a",
|
|
45
45
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
46
46
|
"keywords": [
|
|
47
47
|
"ezs"
|