Skip to content

Commit

Permalink
Merge branch 'master' into yarn-1
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Sep 8, 2023
2 parents 1b697e6 + c34d2b5 commit 9c81149
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 22 deletions.
3 changes: 2 additions & 1 deletion docs/plugin-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ Output:
#### Parameters

- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

Expand Down Expand Up @@ -1248,7 +1249,7 @@ Output:

- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `value`)
- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not) (optional, default `true`)
- `identifier` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)
- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

Expand Down
11 changes: 11 additions & 0 deletions packages/analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.2.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/[email protected]...@ezs/[email protected]) (2023-09-08)


### Features

* 🎸 add identifier parameter to [graph] ([961e201](https://github.com/Inist-CNRS/ezs/commit/961e20157816b3792ff6ee692e8fd5a6b437968c))





# [2.1.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/[email protected]...@ezs/[email protected]) (2023-08-25)


Expand Down
3 changes: 2 additions & 1 deletion packages/analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ Output:
#### Parameters

- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

Expand Down Expand Up @@ -1248,7 +1249,7 @@ Output:

- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path (optional, default `value`)
- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not) (optional, default `true`)
- `identifier` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)
- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use to set value result field (if not set or not exists, 1 is use as a default value) (optional, default `false`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ezs/analytics",
"description": "Analytics statements for EZS",
"version": "2.1.0",
"version": "2.2.0",
"author": "Nicolas Thouvenin <[email protected]>",
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
"dependencies": {
Expand Down
14 changes: 7 additions & 7 deletions packages/analytics/src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ import core from './core';
*
* @name graph
* @param {String} path
* @param {String} [identifier=false] path to use to set value result field (if not set or not exists, 1 is use as a default value)
* @returns {Object}
*/
export default function graph(data, feed) {
if (this.isLast()) {
feed.close();
return;
}
let fields = this.getParam('path', []);
if (!Array.isArray(fields)) {
fields = [fields];
}

const values = fields
const path = this.getParam('path', []);
const idt = this.getParam('identifier', false);
const weight = idt === false ? 1 : get(data, idt, 1);
const values = [].concat(path)
.map((key) => get(data, key))
.filter((x) => x)
.map((item) => (item instanceof Array ? item : [item]))
.reduce((pre, cur) => pre.concat(cur), [])
.filter(Boolean)
.sort();

values.forEach(
(v, i) => values
.slice(i + 1)
.forEach((w) => feed.write(core([v, w], 1))),
.forEach((w) => feed.write(core([v, w], weight))),
);
feed.end();
}
2 changes: 1 addition & 1 deletion packages/analytics/src/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import core from './core';
* @name segment
* @param {String} [path=value] path
* @param {Boolean} [aggregate=true] aggregate all values for all paths (or not)
* @param {Boolean} [identifier=false] path to use to set value result field (if not set or not exists, 1 is use as a default value)
* @param {String} [identifier=false] path to use to set value result field (if not set or not exists, 1 is use as a default value)
* @returns {Object}
*/
export default function segment(data, feed) {
Expand Down
26 changes: 25 additions & 1 deletion packages/analytics/test/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import statements from '../src';
ezs.addPath(__dirname);

describe('network', () => {
it('graph', (done) => {
it('graph #1', (done) => {
ezs.use(statements);
const res = [];
from([
Expand All @@ -30,6 +30,30 @@ describe('network', () => {
});
});

it('graph #2', (done) => {
ezs.use(statements);
const res = [];
from([
{ i: 'doc#1', a: ['x', 'b', 'z'] },
{ i: 'doc#2', a: ['t', 'b', 'z'] },
{ i: 'doc#3', a: ['t', 'c', 'z'] },
{ i: 'doc#4', a: ['y', 'd', 'z'] },
{ i: 'doc#5', a: ['x', 'b', 'z'] },
])
.pipe(ezs('graph', { path: 'a', identifier: 'i' }))
.pipe(ezs('reducing'))
.on('data', (chunk) => {
assert(typeof chunk === 'object');
res.push(chunk);
})
.on('end', () => {
assert.equal(10, res.length);
assert.equal(2, res[1].value.length);
done();
});
});


it('segment #3', (done) => {
ezs.use(statements);
const res = [];
Expand Down
11 changes: 11 additions & 0 deletions packages/basics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.3](https://github.com/Inist-CNRS/ezs/compare/@ezs/[email protected]...@ezs/[email protected]) (2023-08-25)


### Bug Fixes

* 🐛 tar extract freeze ([086b49f](https://github.com/Inist-CNRS/ezs/commit/086b49f7b3c24f551584514869bbe9ec135f7d0a))





## [2.5.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/[email protected]...@ezs/[email protected]) (2023-08-25)

**Note:** Version bump only for package @ezs/basics
Expand Down
Binary file added packages/basics/examples/data/test2.tar
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/basics/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ezs/basics",
"description": "Basics statements for EZS",
"version": "2.5.2",
"version": "2.5.3",
"author": "Nicolas Thouvenin <[email protected]>",
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
"dependencies": {
Expand Down
25 changes: 16 additions & 9 deletions packages/basics/src/tar-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,28 @@ export default function TARExtract(data, feed) {
this.whenEnd = new Promise((resolve, reject) => {
extract.on('entry', async (header, stream, next) => {
if (micromatch.isMatch(header.name, filesPatern)) {
const contentRaw = await getStream(stream);
if (json) {
const contentJson = JSON.parse(contentRaw);
try {
const contentRaw = await getStream(stream);
if (json) {
const contentJson = JSON.parse(contentRaw);
return writeTo(
this.output,
contentJson,
() => next(),
);
}
return writeTo(
this.output,
contentJson,
{ id: header.name, value: contentRaw },
() => next(),
);
} catch (e) {
console.warn(`WARNING: file was ignored (${header.name})`, e);
stream.resume();
return next();
}
return writeTo(
this.output,
{ id: header.name, value: contentRaw },
() => next(),
);
}
stream.resume();
return next();
});
extract.on('error', reject);
Expand Down
14 changes: 14 additions & 0 deletions packages/basics/test/tar-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,18 @@ describe('TARExtract', () => {
done();
});
});
it('should ignore Wrong JSON files', (done) => {
const result = [];
fs.createReadStream('./packages/basics/examples/data/test2.tar')
.pipe(ezs('TARExtract', { path: '**/*.json', json: true, compress: false}))
.pipe(ezs.catch())
.on('data', (chunk) => {
result.push(chunk);
})
.on('error', done)
.on('end', () => {
assert.equal(result.length, 1);
done();
});
});
});

0 comments on commit 9c81149

Please sign in to comment.