@ezs/basics 2.5.6 → 2.5.7

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 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`)
@@ -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 (retries === 1) {
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 (retries === 1) {
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
- } else {
92
- if (json) {
93
- const bodyOutRaw = await (0, _getStream.default)(response.body);
94
- const bodyOutArray = JSON.parse(bodyOutRaw);
95
- (0, _from.default)(bodyOutArray).pipe(output);
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.6",
4
+ "version": "2.5.7",
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": "2b6b66d47ce0e57ebadfe846c76e0990a992977d",
44
+ "gitHead": "0667dffb8743f46bdd5cfab7d1cf47801db925c3",
45
45
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
46
46
  "keywords": [
47
47
  "ezs"