@ezs/basics 2.1.0 → 2.1.3

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,33 @@
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
+ ## [2.1.3](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.2...@ezs/basics@2.1.3) (2023-05-30)
7
+
8
+ **Note:** Version bump only for package @ezs/basics
9
+
10
+
11
+
12
+
13
+
14
+ ## [2.1.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.1...@ezs/basics@2.1.2) (2023-05-30)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * 🐛 retry without json parse ([90e17b5](https://github.com/Inist-CNRS/ezs/commit/90e17b5ea2cbf60f18a9ecbf29b338b1395e318e))
20
+
21
+
22
+
23
+
24
+
25
+ ## [2.1.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.0...@ezs/basics@2.1.1) (2023-05-12)
26
+
27
+ **Note:** Version bump only for package @ezs/basics
28
+
29
+
30
+
31
+
32
+
6
33
  # [2.1.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.0.0...@ezs/basics@2.1.0) (2023-04-12)
7
34
 
8
35
 
package/README.md CHANGED
@@ -695,6 +695,7 @@ read to be buffered and sent to the server (n times)
695
695
  - `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
696
696
  - `noerror` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Ignore all errors (optional, default `false`)
697
697
  - `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`)
698
+ - `encoder` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The statement to encode each chunk to a string (optional, default `dump`)
698
699
 
699
700
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
700
701
 
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = OBJColumns;
7
+
8
+ /**
9
+ * Take an `Object` and flatten it to get only one level of keys.
10
+ *
11
+ * <caption>Input:</caption>
12
+ *
13
+ * ```json
14
+ * [{
15
+ * "foo": {
16
+ * "hello": "world"
17
+ * },
18
+ * "bar": "anything else",
19
+ * "baz": 1
20
+ * }]
21
+ * ```
22
+ *
23
+ * <caption>Output:</caption>
24
+ *
25
+ * ```json
26
+ * [{
27
+ * "foo": "{\"hello\":\"world\"}",
28
+ * "bar": "anything else",
29
+ * "baz": 1
30
+ * }]
31
+ * ```
32
+ *
33
+ * @name OBJColumns
34
+ * @alias flatten
35
+ * @param {undefined} none
36
+ * @returns {Object}
37
+ */
38
+ function OBJColumns(data, feed) {
39
+ if (this.isLast()) {
40
+ feed.close();
41
+ return;
42
+ }
43
+
44
+ const obj = {};
45
+ Object.keys(data).sort((x, y) => x.localeCompare(y)).forEach(key => {
46
+ if (typeof data[key] === 'object') {
47
+ obj[key] = JSON.stringify(data[key]);
48
+ } else {
49
+ obj[key] = data[key];
50
+ }
51
+ });
52
+ feed.send(obj);
53
+ }
@@ -43,6 +43,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
43
43
  * @param {Number} [timeout=1000] Timeout in milliseconds
44
44
  * @param {Boolean} [noerror=false] Ignore all errors
45
45
  * @param {Number} [retries=5] The maximum amount of times to retry the connection
46
+ * @param {String} [encoder=dump] The statement to encode each chunk to a string
46
47
  * @returns {Object}
47
48
  */
48
49
  async function URLConnect(data, feed) {
@@ -50,6 +51,7 @@ async function URLConnect(data, feed) {
50
51
  const retries = Number(this.getParam('retries', 5));
51
52
  const noerror = Boolean(this.getParam('noerror', false));
52
53
  const json = this.getParam('json', true);
54
+ const encoder = this.getParam('encoder', 'dump');
53
55
  const {
54
56
  ezs
55
57
  } = this;
@@ -61,7 +63,7 @@ async function URLConnect(data, feed) {
61
63
  const output = ezs.createStream(ezs.objectMode());
62
64
  this.whenFinish = feed.flow(output);
63
65
  (0, _streamWrite.default)(this.input, data, () => feed.end());
64
- const streamIn = this.input.pipe(ezs('dump'));
66
+ const streamIn = this.input.pipe(ezs(encoder));
65
67
  let bodyIn;
66
68
 
67
69
  if (retries === 1) {
@@ -104,9 +106,13 @@ async function URLConnect(data, feed) {
104
106
  });
105
107
  bodyOut.pipe(output);
106
108
  } else {
107
- const bodyOutRaw = await (0, _getStream.default)(response.body);
108
- const bodyOutArray = JSON.parse(bodyOutRaw);
109
- (0, _from.default)(bodyOutArray).pipe(output);
109
+ if (json) {
110
+ const bodyOutRaw = await (0, _getStream.default)(response.body);
111
+ const bodyOutArray = JSON.parse(bodyOutRaw);
112
+ (0, _from.default)(bodyOutArray).pipe(output);
113
+ } else {
114
+ response.body.pipe(output);
115
+ }
110
116
  }
111
117
  }, {
112
118
  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": "2.1.0",
4
+ "version": "2.1.3",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -40,7 +40,7 @@
40
40
  "directories": {
41
41
  "test": "test"
42
42
  },
43
- "gitHead": "433621fe2399446ce458088063b2412e40975767",
43
+ "gitHead": "2296d653ec1f8ce2ee9999ed77e6c803faa74de9",
44
44
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
45
45
  "keywords": [
46
46
  "ezs"