@ezs/basics 1.22.6 → 1.23.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,28 @@
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.23.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.7...@ezs/basics@1.23.0) (2023-01-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * 🎸 add new parameter to FILESave ([8fae7b8](https://github.com/Inist-CNRS/ezs/commit/8fae7b8009824d8e73c98e8277e15ffacd87d572))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.22.7](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.6...@ezs/basics@1.22.7) (2023-01-13)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * 🐛 backpresure control ([70c4a07](https://github.com/Inist-CNRS/ezs/commit/70c4a07010c0b1927bb57c95b3c5113e8aaa7552))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [1.22.6](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.5...@ezs/basics@1.22.6) (2023-01-05)
7
29
 
8
30
  **Note:** Version bump only for package @ezs/basics
package/README.md CHANGED
@@ -262,6 +262,8 @@ Output:
262
262
 
263
263
  - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
264
264
  - `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** File name
265
+ - `content` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Content to save instead of using input object
266
+ - `jsonl` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Save as json line (optional, default `false`)
265
267
  - `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
266
268
 
267
269
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
package/lib/file-save.js CHANGED
@@ -23,6 +23,9 @@ var _debug = _interopRequireDefault(require("debug"));
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
+ const eol = '\n';
27
+
28
+ const toJSONL = line => JSON.stringify(line).concat(eol);
26
29
  /**
27
30
  * Take data, convert it to buffer and append it to file
28
31
  *
@@ -55,12 +58,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
55
58
  * @name FILESave
56
59
  * @param {String} [location=TMPDIR] Directory location
57
60
  * @param {String} [identifier] File name
61
+ * @param {String} [content] Content to save instead of using input object
62
+ * @param {Boolean} [jsonl=false] Save as json line
58
63
  * @param {Boolean} [compress=false] Enable gzip compression
59
64
  * @returns {Object}
60
65
  */
61
- function FILESave(data, feed) {
62
- const buf = Buffer.from(String(data));
63
66
 
67
+
68
+ function FILESave(data, feed) {
64
69
  if (this.isFirst()) {
65
70
  const identifier = String(this.getParam('identifier'));
66
71
  const location = this.getParam('location', (0, _os.tmpdir)());
@@ -102,5 +107,9 @@ function FILESave(data, feed) {
102
107
  return this.whenFinish.then(stats => feed.write(stats)).catch(err => feed.stop(err)).finally(() => feed.close());
103
108
  }
104
109
 
110
+ const jsonl = Boolean(this.getParam('jsonl', false));
111
+ const bufContent = this.getParam('content', data);
112
+ const bufFunc = jsonl ? toJSONL : String;
113
+ const buf = Buffer.from(bufFunc(bufContent));
105
114
  (0, _streamWrite.default)(this.input, buf, () => feed.end());
106
115
  }
@@ -13,6 +13,37 @@ var _streamWrite = _interopRequireDefault(require("stream-write"));
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
+ function normalize(data, feed) {
17
+ if (this.isLast()) {
18
+ return feed.close();
19
+ }
20
+
21
+ const struct = this.getEnv();
22
+ const vv = {};
23
+ struct.forEach(k => {
24
+ if (!data[k]) {
25
+ vv[k] = '';
26
+ } else {
27
+ vv[k] = data[k];
28
+ }
29
+ });
30
+ return feed.send(vv);
31
+ }
32
+
33
+ function cleanup(data, feed) {
34
+ if (this.isLast()) {
35
+ const filename = this.getParam('filename');
36
+
37
+ if (filename) {
38
+ return _fs.default.unlink(filename, () => feed.close());
39
+ }
40
+
41
+ return feed.close();
42
+ }
43
+
44
+ return feed.send(data);
45
+ }
46
+
16
47
  function OBJStandardize(data, feed) {
17
48
  const self = this;
18
49
  const {
@@ -29,31 +60,17 @@ function OBJStandardize(data, feed) {
29
60
 
30
61
  if (self.isLast()) {
31
62
  self.tmpInput.end();
32
- self.tmpHandle.then(() => {
33
- _fs.default.createReadStream(self.tmpFile).pipe(ezs.uncompress()).pipe(ezs('unpack')).on('error', e => {
34
- throw e;
35
- }).on('data', d => {
36
- const vv = {};
37
- self.struct.forEach(k => {
38
- if (!d[k]) {
39
- vv[k] = '';
40
- } else {
41
- vv[k] = d[k];
42
- }
43
- });
44
- feed.write(vv);
45
- }).on('end', () => {
46
- _fs.default.unlink(self.tmpFile, () => feed.close());
47
- });
48
- });
49
- } else {
50
- Object.keys(data).forEach(k => {
51
- if (self.struct.indexOf(k) === -1) {
52
- self.struct.push(k);
53
- }
54
- });
55
- (0, _streamWrite.default)(self.tmpInput, data, () => feed.end());
63
+ return self.tmpHandle.then(() => feed.flow(_fs.default.createReadStream(self.tmpFile).pipe(ezs.uncompress()).pipe(ezs('unpack')).pipe(ezs(normalize, {}, self.struct)).pipe(ezs(cleanup, {
64
+ filename: self.tmpFile
65
+ })))).catch(e => feed.stop(e));
56
66
  }
67
+
68
+ Object.keys(data).forEach(k => {
69
+ if (self.struct.indexOf(k) === -1) {
70
+ self.struct.push(k);
71
+ }
72
+ });
73
+ (0, _streamWrite.default)(self.tmpInput, data, () => feed.end());
57
74
  }
58
75
  /**
59
76
  * Standardize `Object`s so that each object have the same keys.
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.6",
4
+ "version": "1.23.0",
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": "7211cce7c849f770c10ba6f32c526194e9366501",
40
+ "gitHead": "20ec5a02e63dfff4859d64e96cd5e2bb05e48504",
41
41
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
42
42
  "keywords": [
43
43
  "ezs"