@ezs/basics 1.13.6 → 1.15.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,55 @@
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.15.3](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.15.2...@ezs/basics@1.15.3) (2022-01-31)
7
+
8
+ **Note:** Version bump only for package @ezs/basics
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.15.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.15.1...@ezs/basics@1.15.2) (2022-01-27)
15
+
16
+ **Note:** Version bump only for package @ezs/basics
17
+
18
+
19
+
20
+
21
+
22
+ ## [1.15.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.15.0...@ezs/basics@1.15.1) (2021-10-05)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * 🐛 fix wrong options + miss dep.x ([5b38d05](https://github.com/Inist-CNRS/ezs/commit/5b38d05199a9a49c73d264f4ddb9a45dd0e64c7e))
28
+
29
+
30
+
31
+
32
+
33
+ # [1.15.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.14.0...@ezs/basics@1.15.0) (2021-10-05)
34
+
35
+
36
+ ### Features
37
+
38
+ * 🎸 introduce new parser ([66a408b](https://github.com/Inist-CNRS/ezs/commit/66a408b0be2f6f2374d7193df2576e2fa383d369))
39
+
40
+
41
+
42
+
43
+
44
+ # [1.14.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.13.6...@ezs/basics@1.14.0) (2021-08-27)
45
+
46
+
47
+ ### Features
48
+
49
+ * 🎸 support http headers ([0d11b7c](https://github.com/Inist-CNRS/ezs/commit/0d11b7c46a44040c48aa0d0fcb7954611dd36658))
50
+
51
+
52
+
53
+
54
+
6
55
  ## [1.13.6](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.13.5...@ezs/basics@1.13.6) (2021-07-30)
7
56
 
8
57
  **Note:** Version bump only for package @ezs/basics
package/README.md CHANGED
@@ -284,6 +284,7 @@ Output:
284
284
  #### Parameters
285
285
 
286
286
  - `separator` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** to split at every JSONPath found (optional, default `"*"`)
287
+ - `legacy` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** use legacy or newer parser (separator should be different) (optional, default `true`)
287
288
 
288
289
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
289
290
 
package/lib/fetch.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = fetch;
7
+
8
+ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
9
+
10
+ var _proxyFromEnv = require("proxy-from-env");
11
+
12
+ var _http = _interopRequireDefault(require("http"));
13
+
14
+ var _https = _interopRequireDefault(require("https"));
15
+
16
+ var _betterHttpsProxyAgent = require("better-https-proxy-agent");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const DefaultOptions = {
21
+ keepAlive: true,
22
+ timeout: 1000,
23
+ keepAliveMsecs: 500,
24
+ maxSockets: 200,
25
+ maxFreeSockets: 5,
26
+ maxCachedSessions: 500
27
+ };
28
+
29
+ const chooseAgent = (parsedURL, options) => {
30
+ const proxyurl = (0, _proxyFromEnv.getProxyForUrl)(parsedURL.href);
31
+
32
+ if (proxyurl) {
33
+ const proxyRequestOptions = new URL(proxyurl);
34
+ return new _betterHttpsProxyAgent.Agent(options, proxyRequestOptions);
35
+ }
36
+
37
+ if (parsedURL.protocol === 'https:') {
38
+ return new _https.default.Agent(options);
39
+ }
40
+
41
+ return new _http.default.Agent(options);
42
+ };
43
+
44
+ function fetch(url, options) {
45
+ const opts = options || {};
46
+ const {
47
+ keepAlive,
48
+ timeout,
49
+ keepAliveMsecs,
50
+ maxSockets,
51
+ maxFreeSockets,
52
+ maxCachedSessions
53
+ } = { ...options,
54
+ ...DefaultOptions
55
+ };
56
+ let agent = chooseAgent(new URL(url), {
57
+ keepAlive,
58
+ timeout,
59
+ keepAliveMsecs,
60
+ maxSockets,
61
+ maxFreeSockets,
62
+ maxCachedSessions
63
+ });
64
+ opts.agent = agent;
65
+
66
+ if (opts.signal) {
67
+ opts.signal.addEventListener('abort', () => {
68
+ agent.destroy();
69
+ agent = null;
70
+ });
71
+ }
72
+
73
+ return (0, _crossFetch.default)(url, options);
74
+ }
package/lib/json-parse.js CHANGED
@@ -7,25 +7,35 @@ exports.default = void 0;
7
7
 
8
8
  var _JSONStream = _interopRequireDefault(require("JSONStream"));
9
9
 
10
+ var _stream = require("stream");
11
+
12
+ var _yajsonStream = _interopRequireDefault(require("yajson-stream"));
13
+
10
14
  var _streamWrite = _interopRequireDefault(require("stream-write"));
11
15
 
12
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
17
 
14
18
  function JSONParse(data, feed) {
15
- if (!this.handle) {
19
+ if (this.isFirst()) {
20
+ const legacy = this.getParam('legacy', true);
16
21
  const separator = this.getParam('separator', '*');
17
- this.handle = _JSONStream.default.parse(separator);
18
- this.handle.on('data', obj => feed.write(obj));
22
+
23
+ if (legacy) {
24
+ this.input = _JSONStream.default.parse(separator);
25
+ this.whenFinish = feed.flow(this.input);
26
+ } else {
27
+ this.input = new _stream.PassThrough();
28
+ const stream = this.input.pipe(this.ezs.toBuffer()).pipe((0, _yajsonStream.default)(separator)).pipe(this.ezs((d, f) => f.send(d ? d.value : d)));
29
+ this.whenFinish = feed.flow(stream);
30
+ }
19
31
  }
20
32
 
21
- if (!this.isLast()) {
22
- (0, _streamWrite.default)(this.handle, data, () => feed.end());
23
- } else {
24
- this.handle.end();
25
- process.nextTick(() => {
26
- feed.close();
27
- });
33
+ if (this.isLast()) {
34
+ this.whenFinish.finally(() => feed.close());
35
+ return this.input.end();
28
36
  }
37
+
38
+ (0, _streamWrite.default)(this.input, data, () => feed.end());
29
39
  }
30
40
  /**
31
41
  * Parse a `String` to JSON and generate objects.
@@ -69,6 +79,7 @@ function JSONParse(data, feed) {
69
79
  *
70
80
  * @name JSONParse
71
81
  * @param {String} [separator="*"] to split at every JSONPath found
82
+ * @param {String} [legacy=true] use legacy or newer parser (separator should be different)
72
83
  * @returns {Object}
73
84
  */
74
85
 
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function Concept(data, feed) {
9
+ const obj = {};
10
+ Object.keys(data).forEach(key => {
11
+ const newkey = key.replace('skos$', '');
12
+
13
+ if (Array.isArray(data[key])) {
14
+ data[key].filter(x => x.xml$lang).forEach(item => {
15
+ const localkey = newkey.concat('@').concat(item.xml$lang);
16
+ obj[localkey] = item.$t;
17
+ });
18
+ } else if (data[key].rdf$resource && !obj[newkey]) {
19
+ obj[newkey] = data[key].rdf$resource;
20
+ } else if (data[key].rdf$resource && obj[newkey]) {
21
+ obj[newkey] = [obj[newkey], data[key].rdf$resource];
22
+ } else if (data[key].$t && data[key].xml$lang) {
23
+ const localkey = newkey.concat('@').concat(data[key].xml$lang);
24
+ obj[localkey] = data[key].$t;
25
+ } else if (data[key].$t && Array.isArray(obj[newkey])) {
26
+ obj[newkey].push(data[key].$t);
27
+ } else if (data[key].$t && obj[newkey]) {
28
+ obj[newkey] = [obj[newkey], data[key].$t];
29
+ } else if (data[key].$t && !obj[newkey]) {
30
+ obj[newkey] = data[key].$t;
31
+ } else if (typeof data[key] === 'object') {
32
+ obj[newkey] = (this.getIndex().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
33
+ let counter = 0;
34
+ Object.keys(data[key]).forEach(key2 => {
35
+ if (typeof data[key][key2] === 'object') {
36
+ data[key][key2].rdf$about = obj[newkey];
37
+ Concept.call(this, data[key][key2], feed);
38
+ counter += 1;
39
+ }
40
+ });
41
+
42
+ if (counter === 0) {
43
+ delete obj[newkey];
44
+ }
45
+ } else {
46
+ obj[newkey] = data[key];
47
+ }
48
+ });
49
+ feed.write(obj);
50
+ }
51
+
52
+ function SKOSObject(data, feed) {
53
+ if (this.isLast()) {
54
+ feed.close();
55
+ } else {
56
+ Concept.call(this, data, feed);
57
+ feed.end();
58
+ }
59
+ }
60
+ /**
61
+ * Take `Object` generated by XMLMapping & SKOS data and
62
+ * create a new basic object with only keys & values
63
+ *
64
+ * @name SKOSObject
65
+ * @param {undefined} none
66
+ * @returns {Object}
67
+ */
68
+
69
+
70
+ var _default = {
71
+ SKOSObject
72
+ };
73
+ exports.default = _default;
@@ -15,6 +15,8 @@ var _nodeAbortController = _interopRequireDefault(require("node-abort-controller
15
15
 
16
16
  var _fetchWithProxy = _interopRequireDefault(require("fetch-with-proxy"));
17
17
 
18
+ var _parseHeaders = _interopRequireDefault(require("parse-headers"));
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  /**
@@ -41,6 +43,7 @@ function URLConnect(data, feed) {
41
43
 
42
44
  if (this.isFirst()) {
43
45
  const timeout = Number(this.getParam('timeout')) || 1000;
46
+ const headers = (0, _parseHeaders.default)([].concat(this.getParam('header')).filter(Boolean).join('\n'));
44
47
  const controller = new _nodeAbortController.default();
45
48
  this.input = ezs.createStream(ezs.objectMode());
46
49
  this.whenReady = (0, _fetchWithProxy.default)(url, {
package/lib/url-fetch.js CHANGED
@@ -15,6 +15,8 @@ var _nodeAbortController = _interopRequireDefault(require("node-abort-controller
15
15
 
16
16
  var _fetchWithProxy = _interopRequireDefault(require("fetch-with-proxy"));
17
17
 
18
+ var _parseHeaders = _interopRequireDefault(require("parse-headers"));
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  /**
@@ -43,12 +45,14 @@ async function URLFetch(data, feed) {
43
45
  const json = Boolean(this.getParam('json', false));
44
46
  const noerror = Boolean(this.getParam('noerror', false));
45
47
  const timeout = Number(this.getParam('timeout')) || 1000;
48
+ const headers = (0, _parseHeaders.default)([].concat(this.getParam('header')).filter(Boolean).join('\n'));
46
49
  const mimetype = String(this.getParam('mimetype', 'application/json'));
47
50
  const controller = new _nodeAbortController.default();
48
51
  const key = Array.isArray(path) ? path.shift() : path;
49
52
  const body = (0, _lodash.default)(data, key);
50
53
  const parameters = {
51
54
  timeout,
55
+ headers,
52
56
  signal: controller.signal
53
57
  };
54
58
 
package/lib/url-stream.js CHANGED
@@ -15,6 +15,8 @@ var _JSONStream = _interopRequireDefault(require("JSONStream"));
15
15
 
16
16
  var _fetchWithProxy = _interopRequireDefault(require("fetch-with-proxy"));
17
17
 
18
+ var _parseHeaders = _interopRequireDefault(require("parse-headers"));
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  /**
@@ -91,6 +93,7 @@ async function URLStream(data, feed) {
91
93
  const path = this.getParam('path', '*');
92
94
  const noerror = Boolean(this.getParam('noerror', false));
93
95
  const timeout = Number(this.getParam('timeout')) || 1000;
96
+ const headers = (0, _parseHeaders.default)([].concat(this.getParam('header')).filter(Boolean).join('\n'));
94
97
  const cURL = new _url.URL(url || data);
95
98
  const controller = new _nodeAbortController.default();
96
99
 
@@ -100,6 +103,7 @@ async function URLStream(data, feed) {
100
103
 
101
104
  try {
102
105
  const response = await (0, _fetchWithProxy.default)(cURL.href, {
106
+ headers,
103
107
  timeout,
104
108
  signal: controller.signal
105
109
  });
package/lib/utils.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.writeTo = void 0;
7
+
8
+ const writeTo = function writeTo(stream, data, cb) {
9
+ if (!stream.write(data)) {
10
+ stream.once('drain', cb);
11
+ } else {
12
+ process.nextTick(cb);
13
+ }
14
+ };
15
+
16
+ exports.writeTo = writeTo;
17
+ var _default = writeTo;
18
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezs/basics",
3
- "version": "1.13.6",
3
+ "version": "1.15.3",
4
4
  "description": "Basics statements for EZS",
5
5
  "directories": {
6
6
  "test": "test"
@@ -19,12 +19,12 @@
19
19
  },
20
20
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
21
21
  "dependencies": {
22
- "JSONStream": "~1.3.5",
22
+ "JSONStream": "1.3.5",
23
23
  "better-https-proxy-agent": "1.0.8",
24
- "csv-string": "~3.2.0",
25
- "debug": "4.1.1",
24
+ "csv-string": "3.2.0",
25
+ "debug": "4.3.2",
26
26
  "fetch-with-proxy": "3.0.1",
27
- "flat": "~5.0.2",
27
+ "flat": "5.0.2",
28
28
  "lodash.escaperegexp": "4.1.2",
29
29
  "lodash.get": "4.4.2",
30
30
  "lodash.mapkeys": "4.6.0",
@@ -33,11 +33,13 @@
33
33
  "lodash.zipobject": "4.1.3",
34
34
  "micromatch": "4.0.2",
35
35
  "node-abort-controller": "1.1.0",
36
+ "parse-headers": "2.0.4",
36
37
  "stream-write": "1.0.1",
37
38
  "tmp-filepath": "2.0.0",
38
39
  "unzipper": "0.10.11",
39
- "xml-mapping": "~1.7.1",
40
- "xml-splitter": "~1.2.1"
40
+ "xml-mapping": "1.7.1",
41
+ "xml-splitter": "1.2.1",
42
+ "yajson-stream": "1.3.3"
41
43
  },
42
44
  "main": "./lib/index.js",
43
45
  "scripts": {
@@ -52,11 +54,10 @@
52
54
  "access": "public"
53
55
  },
54
56
  "devDependencies": {
55
- "@ezs/core": "1.3.1",
56
- "pako": "~1.0.11"
57
+ "pako": "1.0.11"
57
58
  },
58
59
  "peerDependencies": {
59
- "@ezs/core": "*"
60
+ "@ezs/core": "1.27.0"
60
61
  },
61
- "gitHead": "cf443b00f83d11656a21f89e8471e5247c1c029f"
62
+ "gitHead": "2df397fbd92f852e7d7a1d434809d1b0367238c5"
62
63
  }