@ezs/basics 1.17.1 → 1.20.0

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 CHANGED
@@ -3,6 +3,39 @@
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.20.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.19.0...@ezs/basics@1.20.0) (2022-06-24)
7
+
8
+
9
+ ### Features
10
+
11
+ * 🎸 add [URLPager] ([59dcbdc](https://github.com/Inist-CNRS/ezs/commit/59dcbdca0c33eaf2ebf5a195de153cec802d1bc1))
12
+
13
+
14
+
15
+
16
+
17
+ # [1.19.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.18.0...@ezs/basics@1.19.0) (2022-06-22)
18
+
19
+
20
+ ### Features
21
+
22
+ * 🎸 file save gz ([33df6cd](https://github.com/Inist-CNRS/ezs/commit/33df6cdc40af50c10511cca1449c5edb3a6878f2))
23
+
24
+
25
+
26
+
27
+
28
+ # [1.18.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.1...@ezs/basics@1.18.0) (2022-06-21)
29
+
30
+
31
+ ### Features
32
+
33
+ * 🎸 add [FILESave] ([2e7dfd7](https://github.com/Inist-CNRS/ezs/commit/2e7dfd76f769418a56f7b9b6cb23d156f37b6789))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [1.17.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.0...@ezs/basics@1.17.1) (2022-04-01)
7
40
 
8
41
 
package/README.md CHANGED
@@ -18,6 +18,7 @@ npm install @ezs/basics
18
18
  - [CSVObject](#csvobject)
19
19
  - [CSVParse](#csvparse)
20
20
  - [CSVString](#csvstring)
21
+ - [FILESave](#filesave)
21
22
  - [INIString](#inistring)
22
23
  - [JSONParse](#jsonparse)
23
24
  - [JSONString](#jsonstring)
@@ -31,7 +32,9 @@ npm install @ezs/basics
31
32
  - [TXTZip](#txtzip)
32
33
  - [URLConnect](#urlconnect)
33
34
  - [URLFetch](#urlfetch)
35
+ - [URLPagination](#urlpagination)
34
36
  - [URLParse](#urlparse)
37
+ - [URLRequest](#urlrequest)
35
38
  - [URLStream](#urlstream)
36
39
  - [URLString](#urlstring)
37
40
  - [XMLConvert](#xmlconvert)
@@ -189,6 +192,44 @@ a;b;c
189
192
 
190
193
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
191
194
 
195
+ ### FILESave
196
+
197
+ Take data, convert it to buffer and append it to file
198
+
199
+ ##### Example
200
+
201
+ Input:
202
+
203
+ ```json
204
+ [
205
+ {"a": "a"},
206
+ {"a": "b"},
207
+ {"a": "c" }
208
+ ]
209
+ ```
210
+
211
+ Script:
212
+
213
+ ```ini
214
+ [FILESave]
215
+ location = /tmp
216
+ identifier = toto
217
+ ```
218
+
219
+ Output:
220
+
221
+ ```json
222
+ [{ filename: "/tmp/toto", size: XXX, ... }]
223
+ ```
224
+
225
+ #### Parameters
226
+
227
+ - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
228
+ - `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** File name
229
+ - `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
230
+
231
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
232
+
192
233
  ### INIString
193
234
 
194
235
  Take `Object` and generate INI
@@ -571,6 +612,68 @@ Or if no target is specified, the output will be the returned content of URL.
571
612
 
572
613
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
573
614
 
615
+ ### URLPagination
616
+
617
+ Take `Object` and multiple it to make it one object per page
618
+
619
+ Input:
620
+
621
+ ```json
622
+ [{"q": "a"}]
623
+ ```
624
+
625
+ Script:
626
+
627
+ ```ini
628
+ [URLRequest]
629
+ url = https://api.search.net
630
+
631
+ [URLPagination]
632
+ total = get('total')
633
+ ```
634
+
635
+ Output:
636
+
637
+ ```json
638
+ [
639
+ {
640
+ "q": "a",
641
+ "total": 22
642
+ "offset": 0,
643
+ "pageNumber": 1,
644
+ "totalPages", 3,
645
+ "maxPages": 1000,
646
+ "limit": 10
647
+ },
648
+ {
649
+ "q": "a",
650
+ "total": 22
651
+ "offset": 10,
652
+ "pageNumber": 2,
653
+ "totalPages", 3,
654
+ "maxPages": 1000,
655
+ "limit": 10
656
+ },
657
+ {
658
+ "q": "a",
659
+ "total": 22
660
+ "offset": 20,
661
+ "pageNumber": 3,
662
+ "totalPages", 3,
663
+ "maxPages": 1000,
664
+ "limit": 10
665
+ }
666
+ ]
667
+ ```
668
+
669
+ #### Parameters
670
+
671
+ - `total` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** total to use for the pagination (optional, default `0`)
672
+ - `limit` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** limit to use to pagination (optional, default `10`)
673
+ - `maxPages` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** maxPages to use to pagination (optional, default `1000`)
674
+
675
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
676
+
574
677
  ### URLParse
575
678
 
576
679
  Take an URL `String`, parse it and return `Object`.
@@ -598,6 +701,43 @@ See:
598
701
 
599
702
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
600
703
 
704
+ ### URLRequest
705
+
706
+ Take `Object` as parameters of URL, throw each chunk from the result
707
+
708
+ Input:
709
+
710
+ ```json
711
+ [{"q": "a"}]
712
+ ```
713
+
714
+ Script:
715
+
716
+ ```ini
717
+ [URLRequest]
718
+ url = https://api.search.net
719
+ ```
720
+
721
+ Output:
722
+
723
+ ```json
724
+ [
725
+ {
726
+ "result": "a"
727
+ }
728
+ ]
729
+ ```
730
+
731
+ #### Parameters
732
+
733
+ - `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** URL to fetch
734
+ - `json` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** parse result as json (optional, default `true`)
735
+ - `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
736
+ - `noerror` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Ignore all errors, the target field will remain undefined (optional, default `false`)
737
+ - `retries` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum amount of times to retry the connection (optional, default `5`)
738
+
739
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
740
+
601
741
  ### URLStream
602
742
 
603
743
  Take `String` as URL, throw each chunk from the result or
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = FILESave;
7
+
8
+ var _fs = require("fs");
9
+
10
+ var _zlib = require("zlib");
11
+
12
+ var _path = _interopRequireDefault(require("path"));
13
+
14
+ var _os = require("os");
15
+
16
+ var _pathExists = _interopRequireDefault(require("path-exists"));
17
+
18
+ var _makeDir = _interopRequireDefault(require("make-dir"));
19
+
20
+ var _streamWrite = _interopRequireDefault(require("stream-write"));
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ /**
25
+ * Take data, convert it to buffer and append it to file
26
+ *
27
+ * #### Example
28
+ *
29
+ * Input:
30
+ *
31
+ * ```json
32
+ * [
33
+ * {"a": "a"},
34
+ * {"a": "b"},
35
+ * {"a": "c" }
36
+ * ]
37
+ * ```
38
+ *
39
+ * Script:
40
+ *
41
+ * ```ini
42
+ * [FILESave]
43
+ * location = /tmp
44
+ * identifier = toto
45
+ * ```
46
+ *
47
+ * Output:
48
+ *
49
+ * ```json
50
+ * [{ filename: "/tmp/toto", size: XXX, ... }]
51
+ * ```
52
+ *
53
+ * @name FILESave
54
+ * @param {String} [location=TMPDIR] Directory location
55
+ * @param {String} [identifier] File name
56
+ * @param {Boolean} [compress=false] Enable gzip compression
57
+ * @returns {Object}
58
+ */
59
+ async function FILESave(data, feed) {
60
+ if (!this.handle) {
61
+ const identifier = String(this.getParam('identifier'));
62
+ const location = this.getParam('location', (0, _os.tmpdir)());
63
+ const compress = this.getParam('compress', false);
64
+
65
+ if (!_pathExists.default.sync(location)) {
66
+ _makeDir.default.sync(location);
67
+ }
68
+
69
+ if (compress) {
70
+ this.filename = _path.default.resolve(location, `${identifier}.gz`);
71
+ this.handle = (0, _zlib.createGzip)();
72
+ this.handleEnd = this.handle.pipe((0, _fs.createWriteStream)(this.filename));
73
+ } else {
74
+ this.filename = _path.default.resolve(location, identifier);
75
+ this.handle = (0, _fs.createWriteStream)(this.filename);
76
+ this.handleEnd = this.handle;
77
+ }
78
+ }
79
+
80
+ if (this.isLast()) {
81
+ this.handleEnd.on('close', () => {
82
+ (0, _fs.lstat)(this.filename, (err, stat) => {
83
+ feed.write({
84
+ filename: this.filename,
85
+ ...stat
86
+ });
87
+ return feed.close();
88
+ });
89
+ });
90
+ return this.handle.end();
91
+ }
92
+
93
+ (0, _streamWrite.default)(this.handle, Buffer.from(String(data)), () => feed.end());
94
+ }
package/lib/index.js CHANGED
@@ -41,6 +41,10 @@ var _urlFetch = _interopRequireDefault(require("./url-fetch"));
41
41
 
42
42
  var _urlParse = _interopRequireDefault(require("./url-parse"));
43
43
 
44
+ var _urlRequest = _interopRequireDefault(require("./url-request"));
45
+
46
+ var _urlPagination = _interopRequireDefault(require("./url-pagination"));
47
+
44
48
  var _urlString = _interopRequireDefault(require("./url-string"));
45
49
 
46
50
  var _urlStream = _interopRequireDefault(require("./url-stream"));
@@ -53,6 +57,8 @@ var _zipExtract = _interopRequireDefault(require("./zip-extract"));
53
57
 
54
58
  var _iniString = _interopRequireDefault(require("./ini-string"));
55
59
 
60
+ var _fileSave = _interopRequireDefault(require("./file-save"));
61
+
56
62
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
63
 
58
64
  const funcs = {
@@ -73,6 +79,8 @@ const funcs = {
73
79
  JSONParse: _jsonParse.default,
74
80
  JSONString: _jsonString.default,
75
81
  URLFetch: _urlFetch.default,
82
+ URLPagination: _urlPagination.default,
83
+ URLRequest: _urlRequest.default,
76
84
  URLParse: _urlParse.default,
77
85
  URLString: _urlString.default,
78
86
  URLStream: _urlStream.default,
@@ -80,6 +88,7 @@ const funcs = {
80
88
  TXTZip: _txtZip.default,
81
89
  ZIPExtract: _zipExtract.default,
82
90
  INIString: _iniString.default,
91
+ FILESave: _fileSave.default,
83
92
  // aliases
84
93
  bufferify: _bufObject.default.BUFObject,
85
94
  concat: _txtConcat.default.TXTConcat,
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = URLPager;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ var _url = require("url");
11
+
12
+ var _nodeAbortController = _interopRequireDefault(require("node-abort-controller"));
13
+
14
+ var _lodash = _interopRequireDefault(require("lodash.get"));
15
+
16
+ var _parseHeaders = _interopRequireDefault(require("parse-headers"));
17
+
18
+ var _asyncRetry = _interopRequireDefault(require("async-retry"));
19
+
20
+ var _request = _interopRequireDefault(require("./request"));
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ /**
25
+ * Take `Object` as parameters of URL, throw each chunk from the result
26
+ *
27
+ *
28
+ * Input:
29
+ *
30
+ * ```json
31
+ * [{"q": "a"}]
32
+ * ```
33
+ *
34
+ * Script:
35
+ *
36
+ * ```ini
37
+ * [URLPager]
38
+ * url = https://api.search.net
39
+ * path = total
40
+ * ```
41
+ *
42
+ * Output:
43
+ *
44
+ * ```json
45
+ * [
46
+ * {
47
+ * "q": "a",
48
+ * "total": 22
49
+ * "offset": 0,
50
+ * "pageNumber": 1,
51
+ * "totalPages", 3,
52
+ * "maxPages": 1000,
53
+ * "limit": 10
54
+ * },
55
+ * {
56
+ * "q": "a",
57
+ * "total": 22
58
+ * "offset": 10,
59
+ * "pageNumber": 2,
60
+ * "totalPages", 3,
61
+ * "maxPages": 1000,
62
+ * "limit": 10
63
+ * },
64
+ * {
65
+ * "q": "a",
66
+ * "total": 22
67
+ * "offset": 20,
68
+ * "pageNumber": 3,
69
+ * "totalPages", 3,
70
+ * "maxPages": 1000,
71
+ * "limit": 10
72
+ * }
73
+ * ]
74
+ * ```
75
+ *
76
+ * #### Example with URLs
77
+ *
78
+ * Input:
79
+ *
80
+ * ```json
81
+ * [
82
+ * "https://httpbin.org/get?a=a",
83
+ * "https://httpbin.org/get?a=b",
84
+ * "https://httpbin.org/get?a=c"
85
+ * ]
86
+ * ```
87
+ *
88
+ * Script:
89
+ *
90
+ * ```ini
91
+ * [URLPager]
92
+ * path = .args
93
+ * ```
94
+ *
95
+ * Output:
96
+ *
97
+ * ```json
98
+ * [{"a": "a"}, {"a": "b"}, {"a": "c" }]
99
+ * ```
100
+ *
101
+ * @name URLPager
102
+ * @param {String} [url] URL to fetch (by default input string is taken)
103
+ * @param {String} [path=total] choose the path to find the number of result
104
+ * @param {Number} [timeout=1000] Timeout in milliseconds
105
+ * @param {Boolean} [noerror=false] Ignore all errors, the target field will remain undefined
106
+ * @param {Number} [retries=5] The maximum amount of times to retry the connection
107
+ * @returns {Object}
108
+ */
109
+ async function URLPager(data, feed) {
110
+ if (this.isLast()) {
111
+ return feed.close();
112
+ }
113
+
114
+ const url = this.getParam('url');
115
+ const path = this.getParam('path', 'total');
116
+ const limit = Number(this.getParam('limit', 10));
117
+ const maxPages = Number(this.getParam('maxPages', 1000));
118
+ const retries = Number(this.getParam('retries', 5));
119
+ const noerror = Boolean(this.getParam('noerror', false));
120
+ const timeout = Number(this.getParam('timeout')) || 1000;
121
+ const headers = (0, _parseHeaders.default)([].concat(this.getParam('header')).filter(Boolean).join('\n'));
122
+ const cURL = new _url.URL(url || data);
123
+ const controller = new _nodeAbortController.default();
124
+ const parameters = {
125
+ timeout,
126
+ headers,
127
+ signal: controller.signal
128
+ };
129
+ const options = {
130
+ retries
131
+ };
132
+ cURL.search = new _url.URLSearchParams(data);
133
+
134
+ const onError = e => {
135
+ controller.abort();
136
+
137
+ if (noerror) {
138
+ (0, _debug.default)('ezs')(`Ignore item #${this.getIndex()} [URLPager] <${e}>`);
139
+ return feed.send(data);
140
+ }
141
+
142
+ (0, _debug.default)('ezs')(`Break item #${this.getIndex()} [URLPager] <${e}>`);
143
+ return feed.send(e);
144
+ };
145
+
146
+ try {
147
+ const response = await (0, _asyncRetry.default)((0, _request.default)(cURL.href, parameters), options);
148
+ const json = await response.json();
149
+ const total = (0, _lodash.default)(json, path);
150
+
151
+ if (total === 0) {
152
+ return onError(new Error('No result.'));
153
+ }
154
+
155
+ if (total === undefined) {
156
+ return onError(new Error('Unexpected response.'));
157
+ }
158
+
159
+ let totalPages = Math.ceil(json.total / limit);
160
+
161
+ if (totalPages > maxPages) {
162
+ totalPages = maxPages;
163
+ }
164
+
165
+ for (let pageNumber = 1; pageNumber <= totalPages; pageNumber += 1) {
166
+ feed.write({ ...data,
167
+ offset: (pageNumber - 1) * limit,
168
+ pageNumber,
169
+ totalPages,
170
+ maxPages,
171
+ limit
172
+ });
173
+ }
174
+
175
+ feed.end();
176
+ } catch (e) {
177
+ onError(e);
178
+ }
179
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = URLPagination;
7
+
8
+ /**
9
+ * Take `Object` and multiple it to make it one object per page
10
+ *
11
+ *
12
+ * Input:
13
+ *
14
+ * ```json
15
+ * [{"q": "a"}]
16
+ * ```
17
+ *
18
+ * Script:
19
+ *
20
+ * ```ini
21
+ * [URLRequest]
22
+ * url = https://api.search.net
23
+ *
24
+ * [URLPagination]
25
+ * total = get('total')
26
+ * ```
27
+ *
28
+ * Output:
29
+ *
30
+ * ```json
31
+ * [
32
+ * {
33
+ * "q": "a",
34
+ * "total": 22
35
+ * "offset": 0,
36
+ * "pageNumber": 1,
37
+ * "totalPages", 3,
38
+ * "maxPages": 1000,
39
+ * "limit": 10
40
+ * },
41
+ * {
42
+ * "q": "a",
43
+ * "total": 22
44
+ * "offset": 10,
45
+ * "pageNumber": 2,
46
+ * "totalPages", 3,
47
+ * "maxPages": 1000,
48
+ * "limit": 10
49
+ * },
50
+ * {
51
+ * "q": "a",
52
+ * "total": 22
53
+ * "offset": 20,
54
+ * "pageNumber": 3,
55
+ * "totalPages", 3,
56
+ * "maxPages": 1000,
57
+ * "limit": 10
58
+ * }
59
+ * ]
60
+ * ```
61
+ *
62
+ *
63
+ * @name URLPagination
64
+ * @param {Number} [total=0] total to use for the pagination
65
+ * @param {Number} [limit=10] limit to use to pagination
66
+ * @param {Number} [maxPages=1000] maxPages to use to pagination
67
+ * @returns {Object}
68
+ */
69
+ function URLPagination(data, feed) {
70
+ if (this.isLast()) {
71
+ return feed.close();
72
+ }
73
+
74
+ const total = Number(this.getParam('total', 0));
75
+ const limit = Number(this.getParam('limit', 10));
76
+ const maxPages = Number(this.getParam('maxPages', 1000));
77
+
78
+ if (total === 0) {
79
+ return feed.send(new Error('No result.'));
80
+ }
81
+
82
+ if (Number.isNaN(total)) {
83
+ return feed.send(new Error('Unexpected response.'));
84
+ }
85
+
86
+ let totalPages = Math.ceil(total / limit);
87
+
88
+ if (totalPages > maxPages) {
89
+ totalPages = maxPages;
90
+ }
91
+
92
+ for (let pageNumber = 1; pageNumber <= totalPages; pageNumber += 1) {
93
+ feed.write({ ...data,
94
+ offset: (pageNumber - 1) * limit,
95
+ pageNumber,
96
+ totalPages,
97
+ maxPages,
98
+ limit
99
+ });
100
+ }
101
+
102
+ feed.end();
103
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = URLRequest;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ var _url = require("url");
11
+
12
+ var _nodeAbortController = _interopRequireDefault(require("node-abort-controller"));
13
+
14
+ var _parseHeaders = _interopRequireDefault(require("parse-headers"));
15
+
16
+ var _asyncRetry = _interopRequireDefault(require("async-retry"));
17
+
18
+ var _request = _interopRequireDefault(require("./request"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ /**
23
+ * Take `Object` as parameters of URL, throw each chunk from the result
24
+ *
25
+ *
26
+ * Input:
27
+ *
28
+ * ```json
29
+ * [{"q": "a"}]
30
+ * ```
31
+ *
32
+ * Script:
33
+ *
34
+ * ```ini
35
+ * [URLRequest]
36
+ * url = https://api.search.net
37
+ * ```
38
+ *
39
+ * Output:
40
+ *
41
+ * ```json
42
+ * [
43
+ * {
44
+ * "result": "a"
45
+ * }
46
+ * ]
47
+ * ```
48
+ *
49
+ * @name URLRequest
50
+ * @param {String} [url] URL to fetch
51
+ * @param {Boolean} [json=true] parse result as json
52
+ * @param {Number} [timeout=1000] Timeout in milliseconds
53
+ * @param {Boolean} [noerror=false] Ignore all errors, the target field will remain undefined
54
+ * @param {Number} [retries=5] The maximum amount of times to retry the connection
55
+ * @returns {Object}
56
+ */
57
+ async function URLRequest(data, feed) {
58
+ if (this.isLast()) {
59
+ return feed.close();
60
+ }
61
+
62
+ const url = this.getParam('url');
63
+ const json = Boolean(this.getParam('json', true));
64
+ const retries = Number(this.getParam('retries', 5));
65
+ const noerror = Boolean(this.getParam('noerror', false));
66
+ const timeout = Number(this.getParam('timeout')) || 1000;
67
+ const headers = (0, _parseHeaders.default)([].concat(this.getParam('header')).filter(Boolean).join('\n'));
68
+ const cURL = new _url.URL(url || data);
69
+ const controller = new _nodeAbortController.default();
70
+ const parameters = {
71
+ timeout,
72
+ headers,
73
+ signal: controller.signal
74
+ };
75
+ const options = {
76
+ retries
77
+ };
78
+ cURL.search = new _url.URLSearchParams(data);
79
+
80
+ const onError = e => {
81
+ controller.abort();
82
+
83
+ if (noerror) {
84
+ (0, _debug.default)('ezs')(`Ignore item #${this.getIndex()} [URLRequest] <${e}>`);
85
+ return feed.send(data);
86
+ }
87
+
88
+ (0, _debug.default)('ezs')(`Break item #${this.getIndex()} [URLRequest] <${e}>`);
89
+ return feed.send(e);
90
+ };
91
+
92
+ try {
93
+ const response = await (0, _asyncRetry.default)((0, _request.default)(cURL.href, parameters), options);
94
+ const func = json ? 'json' : 'text';
95
+ const value = await response[func]();
96
+ feed.send(value);
97
+ } catch (e) {
98
+ onError(e);
99
+ }
100
+ }
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.17.1",
4
+ "version": "1.20.0",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -18,9 +18,11 @@
18
18
  "lodash.mapvalues": "4.6.0",
19
19
  "lodash.set": "4.3.2",
20
20
  "lodash.zipobject": "4.1.3",
21
+ "make-dir": "3.1.0",
21
22
  "micromatch": "4.0.4",
22
23
  "node-abort-controller": "1.1.0",
23
24
  "parse-headers": "2.0.4",
25
+ "path-exists": "4.0.0",
24
26
  "stream-write": "1.0.1",
25
27
  "tmp-filepath": "2.0.0",
26
28
  "unzipper": "0.10.11",
@@ -34,7 +36,7 @@
34
36
  "directories": {
35
37
  "test": "test"
36
38
  },
37
- "gitHead": "0ccde3c9e03a451c95a20372ff41437c9ec214e7",
39
+ "gitHead": "4a9a6877830fb4a769c1aae19d798b7985783760",
38
40
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
39
41
  "keywords": [
40
42
  "ezs"