@ezs/basics 1.22.4 → 1.22.6
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 +19 -0
- package/README.md +1 -0
- package/lib/obj-flatten.js +1 -0
- package/lib/url-connect.js +57 -21
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.22.6](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.5...@ezs/basics@1.22.6) (2023-01-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ezs/basics
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.22.5](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.4...@ezs/basics@1.22.5) (2022-12-21)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* 🐛 timeout and retry error ([efa2cfa](https://github.com/Inist-CNRS/ezs/commit/efa2cfaab4b827700d8e89d1bc59cfb266237ec2))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [1.22.4](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.3...@ezs/basics@1.22.4) (2022-12-02)
|
|
7
26
|
|
|
8
27
|
|
package/README.md
CHANGED
|
@@ -437,6 +437,7 @@ Output:
|
|
|
437
437
|
#### Parameters
|
|
438
438
|
|
|
439
439
|
- `separator` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** choose a character to flatten keys (optional, default `"/"`)
|
|
440
|
+
- `reverse` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** unflatten instead of flatten keys (optional, default `false`)
|
|
440
441
|
- `safe` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** preserve arrays and their contents, (optional, default `false`)
|
|
441
442
|
|
|
442
443
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
package/lib/obj-flatten.js
CHANGED
|
@@ -36,6 +36,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
36
36
|
*
|
|
37
37
|
* @name OBJFlatten
|
|
38
38
|
* @param {String} [separator="/"] choose a character to flatten keys
|
|
39
|
+
* @param {Boolean} [reverse=false] unflatten instead of flatten keys
|
|
39
40
|
* @param {Boolean} [safe=false] preserve arrays and their contents,
|
|
40
41
|
* @returns {Object}
|
|
41
42
|
*/
|
package/lib/url-connect.js
CHANGED
|
@@ -19,7 +19,7 @@ var _asyncRetry = _interopRequireDefault(require("async-retry"));
|
|
|
19
19
|
|
|
20
20
|
var _getStream = _interopRequireDefault(require("get-stream"));
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _fetchWithProxy = _interopRequireDefault(require("fetch-with-proxy"));
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
@@ -55,7 +55,6 @@ async function URLConnect(data, feed) {
|
|
|
55
55
|
if (this.isFirst()) {
|
|
56
56
|
const timeout = Number(this.getParam('timeout')) || 1000;
|
|
57
57
|
const headers = (0, _parseHeaders.default)([].concat(this.getParam('header')).filter(Boolean).join('\n'));
|
|
58
|
-
const controller = new _nodeAbortController.default();
|
|
59
58
|
this.input = ezs.createStream(ezs.objectMode());
|
|
60
59
|
const output = ezs.createStream(ezs.objectMode());
|
|
61
60
|
this.whenFinish = feed.flow(output);
|
|
@@ -73,17 +72,61 @@ async function URLConnect(data, feed) {
|
|
|
73
72
|
const parameters = {
|
|
74
73
|
method: 'POST',
|
|
75
74
|
body: bodyIn,
|
|
76
|
-
|
|
77
|
-
headers,
|
|
78
|
-
signal: controller.signal
|
|
75
|
+
headers
|
|
79
76
|
};
|
|
80
|
-
const options = {
|
|
81
|
-
retries
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const onError = e => {
|
|
85
|
-
controller.abort();
|
|
86
77
|
|
|
78
|
+
try {
|
|
79
|
+
await (0, _asyncRetry.default)(async (bail, numberOfTimes) => {
|
|
80
|
+
if (numberOfTimes > 1) {
|
|
81
|
+
(0, _debug.default)('ezs')(`Attempts to reconnect (${numberOfTimes})`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
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
|
+
const response = await (0, _fetchWithProxy.default)(url, { ...parameters,
|
|
90
|
+
signal: controller.signal
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
const err = new Error(response.statusText);
|
|
95
|
+
const text = await response.text();
|
|
96
|
+
err.responseText = text;
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (retries === 1) {
|
|
101
|
+
const bodyOut = json ? response.body.pipe(_JSONStream.default.parse('*')) : response.body;
|
|
102
|
+
bodyOut.once('data', () => {
|
|
103
|
+
clearTimeout(timeoutHandle);
|
|
104
|
+
});
|
|
105
|
+
bodyOut.once('error', e => {
|
|
106
|
+
output.emit('error', e);
|
|
107
|
+
clearTimeout(timeoutHandle);
|
|
108
|
+
});
|
|
109
|
+
bodyOut.pipe(output);
|
|
110
|
+
} else {
|
|
111
|
+
const bodyOutRaw = await (0, _getStream.default)(response.body);
|
|
112
|
+
|
|
113
|
+
if (json) {
|
|
114
|
+
try {
|
|
115
|
+
const bodyOut = JSON.parse(bodyOutRaw);
|
|
116
|
+
bodyOut.forEach(item => output.write(item));
|
|
117
|
+
} catch (ee) {
|
|
118
|
+
throw ee;
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
output.write(bodyOutRaw);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
output.end();
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
retries
|
|
128
|
+
});
|
|
129
|
+
} catch (e) {
|
|
87
130
|
if (!noerror) {
|
|
88
131
|
(0, _debug.default)('ezs')(`Break item #${this.getIndex()} [URLConnect] <${e}>`);
|
|
89
132
|
feed.stop(e);
|
|
@@ -92,15 +135,6 @@ async function URLConnect(data, feed) {
|
|
|
92
135
|
}
|
|
93
136
|
|
|
94
137
|
output.end();
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const response = await (0, _asyncRetry.default)((0, _request.default)(url, parameters), options);
|
|
99
|
-
const bodyOut = json ? response.body.pipe(_JSONStream.default.parse('*')) : response.body;
|
|
100
|
-
bodyOut.once('error', onError);
|
|
101
|
-
bodyOut.pipe(output);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
onError(e);
|
|
104
138
|
}
|
|
105
139
|
|
|
106
140
|
;
|
|
@@ -109,7 +143,9 @@ async function URLConnect(data, feed) {
|
|
|
109
143
|
|
|
110
144
|
if (this.isLast()) {
|
|
111
145
|
this.input.end();
|
|
112
|
-
this.whenFinish.finally(() =>
|
|
146
|
+
this.whenFinish.finally(() => {
|
|
147
|
+
feed.close();
|
|
148
|
+
});
|
|
113
149
|
return;
|
|
114
150
|
}
|
|
115
151
|
|
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.22.
|
|
4
|
+
"version": "1.22.6",
|
|
5
5
|
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"directories": {
|
|
38
38
|
"test": "test"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "7211cce7c849f770c10ba6f32c526194e9366501",
|
|
41
41
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
42
42
|
"keywords": [
|
|
43
43
|
"ezs"
|