(optional, default `10`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### sort
-Sort incomming object base on the value of the given path
+Sort incomming object base on the value of the given path.
-Trier les objets entrants sur la base de la valeur du chemin donné
+Trier les objets entrants sur la base de la valeur du chemin donné.
#### Example / Exemple
@@ -1360,9 +1385,9 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### statistics
-Analyse and create statistics from given fields
+Analyse and create statistics from given fields.
-Analisse et créer des statistiques a partir des champs donnée
+Analisse et créer des statistiques a partir des champs donnée.
#### Example / Exemple
@@ -1472,9 +1497,9 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### summing
-Create an id, value pair from two given path and apply a sum to the value
+Create an id, value pair from two given path and apply a sum to the value.
-Créer un couple id, value à partir de chemin et applique un somme sur la valeur
+Créer un couple id, value à partir de chemin et applique un somme sur la valeur.
#### Example / Exemple
@@ -1536,9 +1561,9 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### tune
-Create and replace the id with a unify id that can be used with [sort](#sort)
+Create and replace the id with a unify id that can be used with [sort](#sort).
-Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort)
+Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
#### Example / Exemple
@@ -1612,9 +1637,9 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### value
-Create a new object from the value of the given path
+Create a new object from the value of the given path.
-Créer un nouvel objet à partir de la valeur d'un chemin donnée
+Créer un nouvel objet à partir de la valeur d'un chemin donnée.
#### Example / Exemple
diff --git a/packages/analytics/README.md b/packages/analytics/README.md
index e2b2818fe..047833c4e 100644
--- a/packages/analytics/README.md
+++ b/packages/analytics/README.md
@@ -1255,52 +1255,77 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### slice
-Take `Object` and throw the same object only if it is in the section of the
-stream between start and start + size. stream is numbered from 1
+Returns a copy of a section of a stream.
-```json
-[{
- { id: 2000, value: 1 },
- { id: 2001, value: 2 },
- { id: 2003, value: 3 },
- { id: 2005, value: 4 },
- { id: 2007, value: 5 },
- { id: 2009, value: 6 },
- { id: 2011, value: 7 },
- { id: 2013, value: 8 },
-}]
-```
+Renvoie une copie d'une section d'un flux.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use slice
+; Importation du plugin analytique nécessaire pour utiliser slice
[use]
plugin = analytics
-[drop]
+; Using "slice" with default settings
+; Utilisation de "slice" avec les paramètres par défaut
+[slice]
+; start = 1
+; size = 10
```
-Output:
+##### Input / Entrée
```json
-[
-{ "id": 2001, "value": 2 },
-{ "id": 2003, "value": 3 },
-]
+ [
+ { "id": 2023, "value": 12 },
+ { "id": 2021, "value": 11 },
+ { "id": 2019, "value": 10 },
+ { "id": 2017, "value": 9 },
+ { "id": 2013, "value": 8 },
+ { "id": 2011, "value": 7 },
+ { "id": 2009, "value": 6 },
+ { "id": 2007, "value": 5 },
+ { "id": 2005, "value": 4 },
+ { "id": 2003, "value": 3 },
+ { "id": 2001, "value": 2 },
+ { "id": 2000, "value": 1 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": 2023, "value": 12 },
+ { "id": 2021, "value": 11 },
+ { "id": 2019, "value": 10 },
+ { "id": 2017, "value": 9 },
+ { "id": 2013, "value": 8 },
+ { "id": 2011, "value": 7 },
+ { "id": 2009, "value": 6 },
+ { "id": 2007, "value": 5 },
+ { "id": 2005, "value": 4 },
+ { "id": 2003, "value": 3 }
+ ]
```
#### Parameters
-- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the slice (optional, default `0`)
-- `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** size of the slice (optional, default `10`)
+- `start` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
the beginning index of the specified portion of the stream
(optional, default `10`)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### sort
-Sort incomming object base on the value of the given path
+Sort incomming object base on the value of the given path.
-Trier les objets entrants sur la base de la valeur du chemin donné
+Trier les objets entrants sur la base de la valeur du chemin donné.
#### Example / Exemple
@@ -1360,9 +1385,9 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### statistics
-Analyse and create statistics from given fields
+Analyse and create statistics from given fields.
-Analisse et créer des statistiques a partir des champs donnée
+Analisse et créer des statistiques a partir des champs donnée.
#### Example / Exemple
@@ -1472,9 +1497,9 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### summing
-Create an id, value pair from two given path and apply a sum to the value
+Create an id, value pair from two given path and apply a sum to the value.
-Créer un couple id, value à partir de chemin et applique un somme sur la valeur
+Créer un couple id, value à partir de chemin et applique un somme sur la valeur.
#### Example / Exemple
@@ -1536,9 +1561,9 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### tune
-Create and replace the id with a unify id that can be used with [sort](#sort)
+Create and replace the id with a unify id that can be used with [sort](#sort).
-Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort)
+Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
#### Example / Exemple
@@ -1612,9 +1637,9 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### value
-Create a new object from the value of the given path
+Create a new object from the value of the given path.
-Créer un nouvel objet à partir de la valeur d'un chemin donnée
+Créer un nouvel objet à partir de la valeur d'un chemin donnée.
#### Example / Exemple
diff --git a/packages/analytics/src/slice.js b/packages/analytics/src/slice.js
index e3a005bb5..134e5fc80 100644
--- a/packages/analytics/src/slice.js
+++ b/packages/analytics/src/slice.js
@@ -1,60 +1,99 @@
+
/**
- * Take `Object` and throw the same object only if it is in the section of the
- * stream between start and start + size. stream is numbered from 1
+ * Slice function see documentation at the end.
+ * This part of the doc is use for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx
+ */
+const slice = (data, feed, ctx) => {
+ if (ctx.isLast()) {
+ feed.close();
+ return;
+ }
+ const start = Number(ctx.getParam('start')) || 1;
+ const size = Number(ctx.getParam('size')) || 10;
+ const stop = start + size;
+ const index = Number(ctx.getIndex());
+
+ if (index >= stop) {
+ feed.close();
+ } else {
+ if (index >= start) {
+ feed.write(data);
+ }
+ feed.end();
+ }
+ [].slice();
+};
+
+/**
+ * Returns a copy of a section of a stream.
*
- * ```json
- * [{
- * { id: 2000, value: 1 },
- * { id: 2001, value: 2 },
- * { id: 2003, value: 3 },
- * { id: 2005, value: 4 },
- * { id: 2007, value: 5 },
- * { id: 2009, value: 6 },
- * { id: 2011, value: 7 },
- * { id: 2013, value: 8 },
- * }]
- * ```
+ * Renvoie une copie d'une section d'un flux.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use slice
+ * ; Importation du plugin analytique nécessaire pour utiliser slice
* [use]
* plugin = analytics
*
- * [drop]
+ * ; Using "slice" with default settings
+ * ; Utilisation de "slice" avec les paramètres par défaut
+ * [slice]
+ * ; start = 1
+ * ; size = 10
+ *
+ * ```
*
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * { "id": 2023, "value": 12 },
+ * { "id": 2021, "value": 11 },
+ * { "id": 2019, "value": 10 },
+ * { "id": 2017, "value": 9 },
+ * { "id": 2013, "value": 8 },
+ * { "id": 2011, "value": 7 },
+ * { "id": 2009, "value": 6 },
+ * { "id": 2007, "value": 5 },
+ * { "id": 2005, "value": 4 },
+ * { "id": 2003, "value": 3 },
+ * { "id": 2001, "value": 2 },
+ * { "id": 2000, "value": 1 }
+ * ]
* ```
*
- * Output:
+ * #### Output / Sortie
*
* ```json
- * [
- * { "id": 2001, "value": 2 },
- * { "id": 2003, "value": 3 },
- * ]
+ * [
+ * { "id": 2023, "value": 12 },
+ * { "id": 2021, "value": 11 },
+ * { "id": 2019, "value": 10 },
+ * { "id": 2017, "value": 9 },
+ * { "id": 2013, "value": 8 },
+ * { "id": 2011, "value": 7 },
+ * { "id": 2009, "value": 6 },
+ * { "id": 2007, "value": 5 },
+ * { "id": 2005, "value": 4 },
+ * { "id": 2003, "value": 3 }
+ * ]
* ```
*
* @name slice
- * @param {Number} [start=0] start of the slice
- * @param {Number} [size=10] size of the slice
+ * @param {Number} [start=1]
+ *
the beginning index of the specified portion of the stream
+ *
l'indice de début de la partie spécifiée du flux
+ * @param {Number} [size=10]
+ *
the size of the specified portion of the stream
+ *
la taille de début de la partie spécifiée du flux
* @returns {Object}
*/
-export default function slice(data, feed) {
- if (this.isLast()) {
- feed.close();
- return;
- }
- const start = Number(this.getParam('start')) || 1;
- const size = Number(this.getParam('size')) || 10;
- const stop = start + size;
- const index = Number(this.getIndex());
-
- if (index >= stop) {
- feed.close();
- } else {
- if (index >= start) {
- feed.write(data);
- }
- feed.end();
- }
-}
+export default slice;
diff --git a/packages/analytics/src/sort.js b/packages/analytics/src/sort.js
index 2e616e979..92686bccf 100644
--- a/packages/analytics/src/sort.js
+++ b/packages/analytics/src/sort.js
@@ -59,9 +59,9 @@ const sort = async (data, feed, ctx) => {
};
/**
- * Sort incomming object base on the value of the given path
+ * Sort incomming object base on the value of the given path.
*
- * Trier les objets entrants sur la base de la valeur du chemin donné
+ * Trier les objets entrants sur la base de la valeur du chemin donné.
*
* ### Example / Exemple
*
diff --git a/packages/analytics/src/statistics.js b/packages/analytics/src/statistics.js
index 241ad2f34..c709d0019 100644
--- a/packages/analytics/src/statistics.js
+++ b/packages/analytics/src/statistics.js
@@ -120,9 +120,9 @@ const statistics = async (data, feed, ctx) => {
};
/**
- * Analyse and create statistics from given fields
+ * Analyse and create statistics from given fields.
*
- * Analisse et créer des statistiques a partir des champs donnée
+ * Analisse et créer des statistiques a partir des champs donnée.
*
* ### Example / Exemple
*
diff --git a/packages/analytics/src/summing.js b/packages/analytics/src/summing.js
index dfa0b08c1..877347623 100644
--- a/packages/analytics/src/summing.js
+++ b/packages/analytics/src/summing.js
@@ -28,9 +28,9 @@ const summing = (data, feed, ctx) => {
};
/**
- * Create an id, value pair from two given path and apply a sum to the value
+ * Create an id, value pair from two given path and apply a sum to the value.
*
- * Créer un couple id, value à partir de chemin et applique un somme sur la valeur
+ * Créer un couple id, value à partir de chemin et applique un somme sur la valeur.
*
* ### Example / Exemple
*
diff --git a/packages/analytics/src/tune.js b/packages/analytics/src/tune.js
index b13a2566a..fc55f90f2 100644
--- a/packages/analytics/src/tune.js
+++ b/packages/analytics/src/tune.js
@@ -87,9 +87,9 @@ const tune = (data, feed, ctx) => {
};
/**
- * Create and replace the id with a unify id that can be used with [sort](#sort)
+ * Create and replace the id with a unify id that can be used with [sort](#sort).
*
- * Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort)
+ * Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
*
* ### Example / Exemple
*
diff --git a/packages/analytics/src/value.js b/packages/analytics/src/value.js
index bdf43eeef..7a98ff86f 100644
--- a/packages/analytics/src/value.js
+++ b/packages/analytics/src/value.js
@@ -26,9 +26,9 @@ const value = (data, feed, ctx) => {
};
/**
- * Create a new object from the value of the given path
+ * Create a new object from the value of the given path.
*
- * Créer un nouvel objet à partir de la valeur d'un chemin donnée
+ * Créer un nouvel objet à partir de la valeur d'un chemin donnée.
*
* ### Example / Exemple
*
From d0f5093ade920c01d49bbba5fdea0e243abae978 Mon Sep 17 00:00:00 2001
From: AlasDiablo <25723276+AlasDiablo@users.noreply.github.com>
Date: Mon, 29 Jan 2024 08:45:22 +0100
Subject: [PATCH 16/26] docs: add Engine scope jsdoc type
---
packages/analytics/src/slice.js | 2 +-
packages/analytics/src/sort.js | 6 +++---
packages/analytics/src/statistics.js | 2 +-
packages/analytics/src/summing.js | 2 +-
packages/analytics/src/tune.js | 2 +-
packages/analytics/src/value.js | 2 +-
packages/core/src/engine.js | 20 ++++++++++++++++++++
7 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/packages/analytics/src/slice.js b/packages/analytics/src/slice.js
index 134e5fc80..f1777450d 100644
--- a/packages/analytics/src/slice.js
+++ b/packages/analytics/src/slice.js
@@ -5,7 +5,7 @@
* @private
* @param data {unknown}
* @param feed {Feed}
- * @param ctx
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
const slice = (data, feed, ctx) => {
if (ctx.isLast()) {
diff --git a/packages/analytics/src/sort.js b/packages/analytics/src/sort.js
index 92686bccf..fa791266f 100644
--- a/packages/analytics/src/sort.js
+++ b/packages/analytics/src/sort.js
@@ -17,7 +17,7 @@ const sorting = (arr, reverse = false) => {
* @private
* @param data {unknown}
* @param feed {Feed}
- * @param ctx
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
const sort = async (data, feed, ctx) => {
if (!ctx.store) {
@@ -68,7 +68,7 @@ const sort = async (data, feed, ctx) => {
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use tune
+ * ; Import analytics plugin required to use sort
* ; Importation du plugin analytique nécessaire pour utiliser sort
* [use]
* plugin = analytics
@@ -107,7 +107,7 @@ const sort = async (data, feed, ctx) => {
* { "id": 2007, "value": 5 },
* { "id": 2009, "value": 6 },
* { "id": 2011, "value": 7 },
- * { "id": 2013, "value": 8 },
+ * { "id": 2013, "value": 8 }
* ]
* ```
*
diff --git a/packages/analytics/src/statistics.js b/packages/analytics/src/statistics.js
index c709d0019..fba7ac207 100644
--- a/packages/analytics/src/statistics.js
+++ b/packages/analytics/src/statistics.js
@@ -34,7 +34,7 @@ const calculating = (values) => {
* @private
* @param data {unknown}
* @param feed {Feed}
- * @param ctx
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
const statistics = async (data, feed, ctx) => {
const path = ctx.getParam('path', 'value');
diff --git a/packages/analytics/src/summing.js b/packages/analytics/src/summing.js
index 877347623..0c88c7155 100644
--- a/packages/analytics/src/summing.js
+++ b/packages/analytics/src/summing.js
@@ -7,7 +7,7 @@ import core from './core';
* @private
* @param data {unknown}
* @param feed {Feed}
- * @param ctx
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
const summing = (data, feed, ctx) => {
if (ctx.isLast()) {
diff --git a/packages/analytics/src/tune.js b/packages/analytics/src/tune.js
index fc55f90f2..909be559b 100644
--- a/packages/analytics/src/tune.js
+++ b/packages/analytics/src/tune.js
@@ -46,7 +46,7 @@ const allMethods = Object.keys(methods).join(',');
* @private
* @param data {unknown}
* @param feed {Feed}
- * @param ctx
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
const tune = (data, feed, ctx) => {
if (ctx.isLast()) {
diff --git a/packages/analytics/src/value.js b/packages/analytics/src/value.js
index 7a98ff86f..3ba9d023d 100644
--- a/packages/analytics/src/value.js
+++ b/packages/analytics/src/value.js
@@ -6,7 +6,7 @@ import get from 'lodash.get';
* @private
* @param data {unknown}
* @param feed {Feed}
- * @param ctx
+ * @param ctx {import('../../core/src/engine').EngineScope}
*/
const value = (data, feed, ctx) => {
if (ctx.isLast()) {
diff --git a/packages/core/src/engine.js b/packages/core/src/engine.js
index 2b4e6b295..af451f552 100644
--- a/packages/core/src/engine.js
+++ b/packages/core/src/engine.js
@@ -9,6 +9,23 @@ import Shell from './shell';
import SafeTransform from './SafeTransform';
+/**
+ * Engine scope object type
+ * @private
+ * @typedef {Object} EngineScope
+ *
+ * @property {Engine} ezs
+ * @property {(d: unknown, c: unknown) => void} emit
+ * @property {() => any} getParams
+ * @property {() => boolean} isFirst
+ * @property {() => number} getIndex
+ * @property {() => boolean} isLast
+ * @property {() => string} getCumulativeTime
+ * @property {() => number} getCumulativeTimeMS
+ * @property {() => number} getCounter
+ * @property {(name: string, defval?: string | string[], chunk?: unknown) => string | string[] | undefined} getParam
+ */
+
const nanoZero = () => BigInt(0);
const nano2sec = (ns) => {
@@ -72,6 +89,9 @@ export default class Engine extends SafeTransform {
eos(this, decreaseCounter);
this.shell = new Shell(ezs, this.environment);
this.chunk = {};
+ /**
+ * @type {EngineScope}
+ */
this.scope = {};
this.scope.getEnv = (name) => (name === undefined ? this.environment : this.environment[name]);
this.scope.ezs = this.ezs;
From edb6743bccb1b563b220bc2df379bbe20671a7ed Mon Sep 17 00:00:00 2001
From: AlasDiablo <25723276+AlasDiablo@users.noreply.github.com>
Date: Mon, 29 Jan 2024 10:32:39 +0100
Subject: [PATCH 17/26] docs (analytics): reformat segment doc
---
docs/plugin-analytics.md | 148 ++++++++++++----------
packages/analytics/README.md | 148 ++++++++++++----------
packages/analytics/src/segment.js | 202 +++++++++++++++++-------------
3 files changed, 283 insertions(+), 215 deletions(-)
diff --git a/docs/plugin-analytics.md b/docs/plugin-analytics.md
index 047833c4e..d46f79ebb 100644
--- a/docs/plugin-analytics.md
+++ b/docs/plugin-analytics.md
@@ -1172,86 +1172,104 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### segment
-Take `Object` object getting some fields with json path, and throw segment of
-value. Ex: get `[a,b,c]` and throw `[a,b], [b,c]`
+Returns an object containing a segmentation of the input.
-```json
-[{
- {
- id: 'doc#1',
- value: [
- 1,
- 2,
- 3,
- 4,
- ],
- },
- {
- id: 'doc#2',
- value: [
- 4,
- 5,
- 6,
- ],
- },
- {
- id: 'doc#3',
- value: [
- 6,
- 7,
- ]
- },
- {
- id: 'doc#4',
- value: [
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- ]
- }
-}]
-```
+- `[a,b,c]` will be returned as `[a,b], [b,c]`
-Script:
+Renvoie un objet contenant une segmentation de l'entrée.
+
+- `[a,b,c]` sera retourné sous la forme `[a,b], [b,c]`
+
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use segment
+; Importation du plugin analytique nécessaire pour utiliser segment
[use]
plugin = analytics
+; Using "segment" with default settings
+; Utilisation de "segment" avec les paramètres par défaut
[segment]
-path = value
+; aggregate = true
+; identifier = false
+; path = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: [ 1, 2 ], value: 1 }
- { id: [ 2, 3 ], value: 1 }
- { id: [ 3, 4 ], value: 1 }
- { id: [ 4, 5 ], value: 1 }
- { id: [ 5, 6 ], value: 1 }
- { id: [ 6, 7 ], value: 1 }
- { id: [ 1, 2 ], value: 1 }
- { id: [ 2, 3 ], value: 1 }
- { id: [ 3, 4 ], value: 1 }
- { id: [ 4, 5 ], value: 1 }
- { id: [ 5, 6 ], value: 1 }
- { id: [ 6, 7 ], value: 1 }
-]
+ [
+ {
+ "id": "doc#1",
+ "value": [
+ 1,
+ 2,
+ 3,
+ 4
+ ]
+ },
+ {
+ "id": "doc#2",
+ "value": [
+ 4,
+ 5,
+ 6
+ ]
+ },
+ {
+ "id": "doc#3",
+ "value": [
+ 6,
+ 7
+ ]
+ },
+ {
+ "id": "doc#4",
+ "value": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7
+ ]
+ }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": [ 1, 2 ], "value": 1 },
+ { "id": [ 2, 3 ], "value": 1 },
+ { "id": [ 3, 4 ], "value": 1 },
+ { "id": [ 4, 5 ], "value": 1 },
+ { "id": [ 5, 6 ], "value": 1 },
+ { "id": [ 6, 7 ], "value": 1 },
+ { "id": [ 1, 2 ], "value": 1 },
+ { "id": [ 2, 3 ], "value": 1 },
+ { "id": [ 3, 4 ], "value": 1 },
+ { "id": [ 4, 5 ], "value": 1 },
+ { "id": [ 5, 6 ], "value": 1 },
+ { "id": [ 6, 7 ], "value": 1 }
+ ]
```
#### Parameters
-- `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` **[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`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
path of the element who need to be segmented
+
chemin de l'élément qui doit être segmentés
(optional, default `value`)
+- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not)
aggregate all segmented value in one element (work if you have multiple path)
+
agréger toutes les valeurs segmentées en un seul élément (fonctionne si vous avez plusieurs chemins)
(optional, default `value`)
+- `aggregate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** aggregate all values for all paths (or not)
aggregate all segmented value in one element (work if you have multiple path)
+
agréger toutes les valeurs segmentées en un seul élément (fonctionne si vous avez plusieurs chemins)
(optional, default `false`)
@@ -1405,15 +1405,15 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
Analyse and create statistics from given fields.
-Analisse et créer des statistiques a partir des champs donnée.
+Analyse et crée des statistiques à partir des champs donnés.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use statistics
-; Importation du plugin analytique nécessaire pour utiliser statistics
+; Import analytics plugin required to use "statistics"
+; Importation du plugin analytique nécessaire pour utiliser "statistics"
[use]
plugin = analytics
@@ -1507,7 +1507,7 @@ plugin = analytics
#### Parameters
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
path of the element used to create the statistics
-
chemin de l'élément utilisé pour créer les statistics
(optional, default `value`)
+
chemin de l'élément utilisé pour créer les statistiques
(optional, default `_statistics`)
@@ -1515,17 +1515,17 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### summing
-Create an id, value pair from two given path and apply a sum to the value.
+Create an `id`, `value` pair from two given paths and apply a sum to the value.
-Créer un couple id, value à partir de chemin et applique un somme sur la valeur.
+Créer un couple id, value à partir de chemins et applique une somme sur `value`.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use summing
-; Importation du plugin analytique nécessaire pour utiliser summing
+; Import analytics plugin required to use "summing"
+; Importation du plugin analytique nécessaire pour utiliser "summing"
[use]
plugin = analytics
@@ -1579,7 +1579,7 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### tune
-Create and replace the id with a unify id that can be used with [sort](#sort).
+Create and replace the id with a unified id that can be used with [sort](#sort).
Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
@@ -1588,8 +1588,8 @@ Créer et remplacer l'identifiant par un identifiant unifié qui peut être util
##### Script / Scénario
```ini
-; Import analytics plugin required to use tune
-; Importation du plugin analytique nécessaire pour utiliser tune
+; Import analytics plugin required to use "tune"
+; Importation du plugin analytique nécessaire pour utiliser "tune"
[use]
plugin = analytics
@@ -1657,15 +1657,15 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
Create a new object from the value of the given path.
-Créer un nouvel objet à partir de la valeur d'un chemin donnée.
+Créer un nouvel objet à partir du chemin donné dans `path`.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use value
-; Importation du plugin analytique nécessaire pour utiliser value
+; Import analytics plugin required to use "value"
+; Importation du plugin analytique nécessaire pour utiliser "value"
[use]
plugin = analytics
@@ -1677,7 +1677,7 @@ plugin = analytics
##### Input / Entrée
-###### Dataset 1 / Jeu de donnée 1
+###### Dataset 1 / Jeu de données 1
```json
[
@@ -1692,7 +1692,7 @@ plugin = analytics
]
```
-###### Dataset 2 / Jeu de donnée 2
+###### Dataset 2 / Jeu de données 2
```json
[
@@ -1719,7 +1719,7 @@ plugin = analytics
##### Output / Sortie
-###### Dataset 1 / Jeu de donnée 1
+###### Dataset 1 / Jeu de données 1
```json
[
@@ -1734,7 +1734,7 @@ plugin = analytics
]
```
-###### Dataset 2 / Jeu de donnée 2
+###### Dataset 2 / Jeu de données 2
```json
[
diff --git a/packages/analytics/README.md b/packages/analytics/README.md
index d46f79ebb..e0e71c452 100644
--- a/packages/analytics/README.md
+++ b/packages/analytics/README.md
@@ -1185,8 +1185,8 @@ Renvoie un objet contenant une segmentation de l'entrée.
##### Script / Scénario
```ini
-; Import analytics plugin required to use segment
-; Importation du plugin analytique nécessaire pour utiliser segment
+; Import analytics plugin required to use "segment"
+; Importation du plugin analytique nécessaire pour utiliser "segment"
[use]
plugin = analytics
@@ -1282,8 +1282,8 @@ Renvoie une copie d'une section d'un flux.
##### Script / Scénario
```ini
-; Import analytics plugin required to use slice
-; Importation du plugin analytique nécessaire pour utiliser slice
+; Import analytics plugin required to use "slice"
+; Importation du plugin analytique nécessaire pour utiliser "slice"
[use]
plugin = analytics
@@ -1341,17 +1341,17 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### sort
-Sort incomming object base on the value of the given path.
+Sort incomming objects based on the value of the given path.
-Trier les objets entrants sur la base de la valeur du chemin donné.
+Trie les objets entrants en fonction de la valeur du champ donné par `path`.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use sort
-; Importation du plugin analytique nécessaire pour utiliser sort
+; Import analytics plugin required to use "sort"
+; Importation du plugin analytique nécessaire pour utiliser "sort"
[use]
plugin = analytics
@@ -1395,7 +1395,7 @@ plugin = analytics
#### Parameters
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
path of the element used to as reference for the sort
-
chemin de l'élément utilisé comme reference pour le trie
(optional, default `id`)
+
chemin de l'élément utilisé comme référence pour le tri
(optional, default `false`)
@@ -1405,15 +1405,15 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
Analyse and create statistics from given fields.
-Analisse et créer des statistiques a partir des champs donnée.
+Analyse et crée des statistiques à partir des champs donnés.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use statistics
-; Importation du plugin analytique nécessaire pour utiliser statistics
+; Import analytics plugin required to use "statistics"
+; Importation du plugin analytique nécessaire pour utiliser "statistics"
[use]
plugin = analytics
@@ -1507,7 +1507,7 @@ plugin = analytics
#### Parameters
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
path of the element used to create the statistics
-
chemin de l'élément utilisé pour créer les statistics
(optional, default `value`)
+
chemin de l'élément utilisé pour créer les statistiques
(optional, default `_statistics`)
@@ -1515,17 +1515,17 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### summing
-Create an id, value pair from two given path and apply a sum to the value.
+Create an `id`, `value` pair from two given paths and apply a sum to the value.
-Créer un couple id, value à partir de chemin et applique un somme sur la valeur.
+Créer un couple id, value à partir de chemins et applique une somme sur `value`.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use summing
-; Importation du plugin analytique nécessaire pour utiliser summing
+; Import analytics plugin required to use "summing"
+; Importation du plugin analytique nécessaire pour utiliser "summing"
[use]
plugin = analytics
@@ -1579,7 +1579,7 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### tune
-Create and replace the id with a unify id that can be used with [sort](#sort).
+Create and replace the id with a unified id that can be used with [sort](#sort).
Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
@@ -1588,8 +1588,8 @@ Créer et remplacer l'identifiant par un identifiant unifié qui peut être util
##### Script / Scénario
```ini
-; Import analytics plugin required to use tune
-; Importation du plugin analytique nécessaire pour utiliser tune
+; Import analytics plugin required to use "tune"
+; Importation du plugin analytique nécessaire pour utiliser "tune"
[use]
plugin = analytics
@@ -1657,15 +1657,15 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
Create a new object from the value of the given path.
-Créer un nouvel objet à partir de la valeur d'un chemin donnée.
+Créer un nouvel objet à partir du chemin donné dans `path`.
#### Example / Exemple
##### Script / Scénario
```ini
-; Import analytics plugin required to use value
-; Importation du plugin analytique nécessaire pour utiliser value
+; Import analytics plugin required to use "value"
+; Importation du plugin analytique nécessaire pour utiliser "value"
[use]
plugin = analytics
@@ -1677,7 +1677,7 @@ plugin = analytics
##### Input / Entrée
-###### Dataset 1 / Jeu de donnée 1
+###### Dataset 1 / Jeu de données 1
```json
[
@@ -1692,7 +1692,7 @@ plugin = analytics
]
```
-###### Dataset 2 / Jeu de donnée 2
+###### Dataset 2 / Jeu de données 2
```json
[
@@ -1719,7 +1719,7 @@ plugin = analytics
##### Output / Sortie
-###### Dataset 1 / Jeu de donnée 1
+###### Dataset 1 / Jeu de données 1
```json
[
@@ -1734,7 +1734,7 @@ plugin = analytics
]
```
-###### Dataset 2 / Jeu de donnée 2
+###### Dataset 2 / Jeu de données 2
```json
[
diff --git a/packages/analytics/src/segment.js b/packages/analytics/src/segment.js
index bab5a2c8c..0f7c09965 100644
--- a/packages/analytics/src/segment.js
+++ b/packages/analytics/src/segment.js
@@ -4,7 +4,7 @@ import core from './core';
/**
* Segment function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -61,8 +61,8 @@ const segment = (data, feed, ctx) => {
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use segment
- * ; Importation du plugin analytique nécessaire pour utiliser segment
+ * ; Import analytics plugin required to use "segment"
+ * ; Importation du plugin analytique nécessaire pour utiliser "segment"
* [use]
* plugin = analytics
*
diff --git a/packages/analytics/src/slice.js b/packages/analytics/src/slice.js
index f1777450d..db4497be4 100644
--- a/packages/analytics/src/slice.js
+++ b/packages/analytics/src/slice.js
@@ -1,7 +1,7 @@
/**
* Slice function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -38,8 +38,8 @@ const slice = (data, feed, ctx) => {
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use slice
- * ; Importation du plugin analytique nécessaire pour utiliser slice
+ * ; Import analytics plugin required to use "slice"
+ * ; Importation du plugin analytique nécessaire pour utiliser "slice"
* [use]
* plugin = analytics
*
diff --git a/packages/analytics/src/sort.js b/packages/analytics/src/sort.js
index fa791266f..b05c71c15 100644
--- a/packages/analytics/src/sort.js
+++ b/packages/analytics/src/sort.js
@@ -13,7 +13,7 @@ const sorting = (arr, reverse = false) => {
/**
* Sort function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -59,17 +59,17 @@ const sort = async (data, feed, ctx) => {
};
/**
- * Sort incomming object base on the value of the given path.
+ * Sort incomming objects based on the value of the given path.
*
- * Trier les objets entrants sur la base de la valeur du chemin donné.
+ * Trie les objets entrants en fonction de la valeur du champ donné par `path`.
*
* ### Example / Exemple
*
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use sort
- * ; Importation du plugin analytique nécessaire pour utiliser sort
+ * ; Import analytics plugin required to use "sort"
+ * ; Importation du plugin analytique nécessaire pour utiliser "sort"
* [use]
* plugin = analytics
*
@@ -114,7 +114,7 @@ const sort = async (data, feed, ctx) => {
* @name sort
* @param {String} [path=id]
*
path of the element used to as reference for the sort
- *
chemin de l'élément utilisé comme reference pour le trie
+ *
chemin de l'élément utilisé comme référence pour le tri
* @param {boolean} [reverse=false]
*
sort in ascending or descending order
*
trier par ordre croissant ou décroissant
diff --git a/packages/analytics/src/statistics.js b/packages/analytics/src/statistics.js
index fba7ac207..35a7ec2ab 100644
--- a/packages/analytics/src/statistics.js
+++ b/packages/analytics/src/statistics.js
@@ -30,7 +30,7 @@ const calculating = (values) => {
/**
* Statistics function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -122,14 +122,14 @@ const statistics = async (data, feed, ctx) => {
/**
* Analyse and create statistics from given fields.
*
- * Analisse et créer des statistiques a partir des champs donnée.
+ * Analyse et crée des statistiques à partir des champs donnés.
*
* ### Example / Exemple
*
* #### Script / Scénario
* ```ini
- * ; Import analytics plugin required to use statistics
- * ; Importation du plugin analytique nécessaire pour utiliser statistics
+ * ; Import analytics plugin required to use "statistics"
+ * ; Importation du plugin analytique nécessaire pour utiliser "statistics"
* [use]
* plugin = analytics
*
@@ -223,7 +223,7 @@ const statistics = async (data, feed, ctx) => {
* @name statistics
* @param {String} [path=value]
*
path of the element used to create the statistics
- *
chemin de l'élément utilisé pour créer les statistics
+ *
chemin de l'élément utilisé pour créer les statistiques
* @param {String} [target=_statistics]
*
path of the statistics in the returned object
*
chemin des stastistiques dans l'objet retourné
diff --git a/packages/analytics/src/summing.js b/packages/analytics/src/summing.js
index 0c88c7155..a011101d3 100644
--- a/packages/analytics/src/summing.js
+++ b/packages/analytics/src/summing.js
@@ -3,7 +3,7 @@ import core from './core';
/**
* Summing function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -28,17 +28,17 @@ const summing = (data, feed, ctx) => {
};
/**
- * Create an id, value pair from two given path and apply a sum to the value.
+ * Create an `id`, `value` pair from two given paths and apply a sum to the value.
*
- * Créer un couple id, value à partir de chemin et applique un somme sur la valeur.
+ * Créer un couple id, value à partir de chemins et applique une somme sur `value`.
*
* ### Example / Exemple
*
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use summing
- * ; Importation du plugin analytique nécessaire pour utiliser summing
+ * ; Import analytics plugin required to use "summing"
+ * ; Importation du plugin analytique nécessaire pour utiliser "summing"
* [use]
* plugin = analytics
*
diff --git a/packages/analytics/src/tune.js b/packages/analytics/src/tune.js
index 909be559b..da8035c82 100644
--- a/packages/analytics/src/tune.js
+++ b/packages/analytics/src/tune.js
@@ -42,7 +42,7 @@ const allMethods = Object.keys(methods).join(',');
/**
* Tune function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -87,7 +87,7 @@ const tune = (data, feed, ctx) => {
};
/**
- * Create and replace the id with a unify id that can be used with [sort](#sort).
+ * Create and replace the id with a unified id that can be used with [sort](#sort).
*
* Créer et remplacer l'identifiant par un identifiant unifié qui peut être utilisé avec [sort](#sort).
*
@@ -96,8 +96,8 @@ const tune = (data, feed, ctx) => {
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use tune
- * ; Importation du plugin analytique nécessaire pour utiliser tune
+ * ; Import analytics plugin required to use "tune"
+ * ; Importation du plugin analytique nécessaire pour utiliser "tune"
* [use]
* plugin = analytics
*
diff --git a/packages/analytics/src/value.js b/packages/analytics/src/value.js
index 3ba9d023d..16b0e0db6 100644
--- a/packages/analytics/src/value.js
+++ b/packages/analytics/src/value.js
@@ -2,7 +2,7 @@ import get from 'lodash.get';
/**
* Value function see documentation at the end.
- * This part of the doc is use for jsdoc typing
+ * This part of the doc is used for jsdoc typing
* @private
* @param data {unknown}
* @param feed {Feed}
@@ -28,15 +28,15 @@ const value = (data, feed, ctx) => {
/**
* Create a new object from the value of the given path.
*
- * Créer un nouvel objet à partir de la valeur d'un chemin donnée.
+ * Créer un nouvel objet à partir du chemin donné dans `path`.
*
* ### Example / Exemple
*
* #### Script / Scénario
*
* ```ini
- * ; Import analytics plugin required to use value
- * ; Importation du plugin analytique nécessaire pour utiliser value
+ * ; Import analytics plugin required to use "value"
+ * ; Importation du plugin analytique nécessaire pour utiliser "value"
* [use]
* plugin = analytics
*
@@ -49,7 +49,7 @@ const value = (data, feed, ctx) => {
*
* #### Input / Entrée
*
- * ##### Dataset 1 / Jeu de donnée 1
+ * ##### Dataset 1 / Jeu de données 1
*
* ```json
* [
@@ -64,7 +64,7 @@ const value = (data, feed, ctx) => {
* ]
* ```
*
- * ##### Dataset 2 / Jeu de donnée 2
+ * ##### Dataset 2 / Jeu de données 2
*
* ```json
* [
@@ -91,7 +91,7 @@ const value = (data, feed, ctx) => {
*
* #### Output / Sortie
*
- * ##### Dataset 1 / Jeu de donnée 1
+ * ##### Dataset 1 / Jeu de données 1
*
* ```json
* [
@@ -106,7 +106,7 @@ const value = (data, feed, ctx) => {
* ]
* ```
*
- * ##### Dataset 2 / Jeu de donnée 2
+ * ##### Dataset 2 / Jeu de données 2
*
* ```json
* [
diff --git a/packages/analytics/test-utils/runEzs.js b/packages/analytics/test-utils/runEzs.js
index bb72bd07b..4c55cebb6 100644
--- a/packages/analytics/test-utils/runEzs.js
+++ b/packages/analytics/test-utils/runEzs.js
@@ -1,7 +1,7 @@
import from from 'from';
/**
- * Helper function use to call ezs in each tests
+ * Helper function used to call ezs in each test
* @param ezsRuntime {(name: string, options: any, environment?: unknown) => NodeJS.WritableStream}
* @param dataSet {Array}
* @param functionName {string}
diff --git a/packages/analytics/test/summing.spec.js b/packages/analytics/test/summing.spec.js
index c90a1daf4..a6f761773 100644
--- a/packages/analytics/test/summing.spec.js
+++ b/packages/analytics/test/summing.spec.js
@@ -41,13 +41,13 @@ describe('summing', () => {
}
];
- it('should return no result when input contains undefined', async () => {
+ it('should return no result when input contains only undefined', async () => {
const result = await runEzs(ezs, undefinedData, 'summing');
expect(result).toHaveLength(0);
});
- it.skip('should return no result when input contains null', async () => {
+ it.skip('should return no result when input contains only null', async () => {
const result = await runEzs(ezs, nullData, 'summing');
expect(result).toHaveLength(0);
@@ -86,15 +86,11 @@ describe('summing', () => {
expect(result).toHaveLength(2);
expect(result[0]).not.toBeNull();
- expect(result[0].id).not.toBeNull();
expect(result[0].id).toStrictEqual(1);
- expect(result[0].value).not.toBeNull();
expect(result[0].value).toStrictEqual(3);
expect(result[1]).not.toBeNull();
- expect(result[1].id).not.toBeNull();
expect(result[1].id).toStrictEqual(2);
- expect(result[1].value).not.toBeNull();
expect(result[1].value).toStrictEqual(6);
});
@@ -109,15 +105,11 @@ describe('summing', () => {
expect(result).toHaveLength(2);
expect(result[0]).not.toBeNull();
- expect(result[0].id).not.toBeNull();
expect(result[0].id).toStrictEqual([1, 1, 1]);
- expect(result[0].value).not.toBeNull();
expect(result[0].value).toStrictEqual(1);
expect(result[1]).not.toBeNull();
- expect(result[1].id).not.toBeNull();
expect(result[1].id).toStrictEqual([2, 2, 2]);
- expect(result[1].value).not.toBeNull();
expect(result[1].value).toStrictEqual(2);
});
});
@@ -144,16 +136,12 @@ describe('summing', () => {
expect(result).toHaveLength(2);
expect(result[0]).not.toBeNull();
- expect(result[0].id).not.toBeNull();
expect(result[0].id).toStrictEqual(2);
- expect(result[0].value).not.toBeNull();
expect(result[0].value).toStrictEqual(30);
expect(result[0]).not.toHaveProperty('hello');
expect(result[1]).not.toBeNull();
- expect(result[1].id).not.toBeNull();
expect(result[1].id).toStrictEqual(4);
- expect(result[1].value).not.toBeNull();
expect(result[1].value).toStrictEqual(60);
expect(result[1]).not.toHaveProperty('hello');
});
@@ -169,16 +157,12 @@ describe('summing', () => {
expect(result).toHaveLength(2);
expect(result[0]).not.toBeNull();
- expect(result[0].id).not.toBeNull();
expect(result[0].id).toStrictEqual([10, 10, 10]);
- expect(result[0].value).not.toBeNull();
expect(result[0].value).toStrictEqual(2);
expect(result[0]).not.toHaveProperty('hello');
expect(result[1]).not.toBeNull();
- expect(result[1].id).not.toBeNull();
expect(result[1].id).toStrictEqual([20, 20, 20]);
- expect(result[1].value).not.toBeNull();
expect(result[1].value).toStrictEqual(4);
expect(result[1]).not.toHaveProperty('hello');
});
diff --git a/packages/analytics/test/tune.spec.js b/packages/analytics/test/tune.spec.js
index 84ed593b3..f4788a56e 100644
--- a/packages/analytics/test/tune.spec.js
+++ b/packages/analytics/test/tune.spec.js
@@ -41,13 +41,13 @@ describe('tune', () => {
}
];
- it.skip('should return no result when input contains undefined', async () => {
+ it.skip('should return no result when input contains only undefined', async () => {
const result = await runEzs(ezs, undefinedData, 'tune');
expect(result).toHaveLength(0);
});
- it.skip('should return no result when input contains null', async () => {
+ it.skip('should return no result when input contains only null', async () => {
const result = await runEzs(ezs, nullData, 'tune');
expect(result).toHaveLength(0);
@@ -59,10 +59,22 @@ describe('tune', () => {
expect(result).toHaveLength(0);
});
- it.skip('should return no result when input contains wrong key', async () => {
+ it('should return no result when input contains wrong key', async () => {
const result = await runEzs(ezs, wrongKeyData, 'tune');
- expect(result).toHaveLength(0);
+ expect(result).toHaveLength(2);
+
+ expect(result[0]).not.toBeNull();
+ expect(result[0].id).toStrictEqual('undefined');
+ expect(result[0].value).toStrictEqual({
+ 'hello': 'world',
+ });
+
+ expect(result[1]).not.toBeNull();
+ expect(result[1].id).toStrictEqual('undefined');
+ expect(result[1].value).toStrictEqual({
+ 'hello': 'world',
+ });
});
});
From 164c1190c784319573d400ab610ce82aea2aae50 Mon Sep 17 00:00:00 2001
From: AlasDiablo <25723276+AlasDiablo@users.noreply.github.com>
Date: Tue, 30 Jan 2024 08:29:41 +0100
Subject: [PATCH 20/26] docs (analytics): typo
---
docs/plugin-analytics.md | 4 ++--
packages/analytics/README.md | 4 ++--
packages/analytics/src/summing.js | 2 +-
packages/analytics/src/value.js | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/plugin-analytics.md b/docs/plugin-analytics.md
index e0e71c452..a5f20b762 100644
--- a/docs/plugin-analytics.md
+++ b/docs/plugin-analytics.md
@@ -1517,7 +1517,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
Create an `id`, `value` pair from two given paths and apply a sum to the value.
-Créer un couple id, value à partir de chemins et applique une somme sur `value`.
+Créer un couple `id`, `value` à partir de chemins et applique une somme sur `value`.
#### Example / Exemple
@@ -1655,7 +1655,7 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### value
-Create a new object from the value of the given path.
+Create a new object from the value of the given `path`.
Créer un nouvel objet à partir du chemin donné dans `path`.
diff --git a/packages/analytics/README.md b/packages/analytics/README.md
index e0e71c452..a5f20b762 100644
--- a/packages/analytics/README.md
+++ b/packages/analytics/README.md
@@ -1517,7 +1517,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
Create an `id`, `value` pair from two given paths and apply a sum to the value.
-Créer un couple id, value à partir de chemins et applique une somme sur `value`.
+Créer un couple `id`, `value` à partir de chemins et applique une somme sur `value`.
#### Example / Exemple
@@ -1655,7 +1655,7 @@ Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Refere
### value
-Create a new object from the value of the given path.
+Create a new object from the value of the given `path`.
Créer un nouvel objet à partir du chemin donné dans `path`.
diff --git a/packages/analytics/src/summing.js b/packages/analytics/src/summing.js
index a011101d3..128adf8d3 100644
--- a/packages/analytics/src/summing.js
+++ b/packages/analytics/src/summing.js
@@ -30,7 +30,7 @@ const summing = (data, feed, ctx) => {
/**
* Create an `id`, `value` pair from two given paths and apply a sum to the value.
*
- * Créer un couple id, value à partir de chemins et applique une somme sur `value`.
+ * Créer un couple `id`, `value` à partir de chemins et applique une somme sur `value`.
*
* ### Example / Exemple
*
diff --git a/packages/analytics/src/value.js b/packages/analytics/src/value.js
index 16b0e0db6..ccc8d6662 100644
--- a/packages/analytics/src/value.js
+++ b/packages/analytics/src/value.js
@@ -26,7 +26,7 @@ const value = (data, feed, ctx) => {
};
/**
- * Create a new object from the value of the given path.
+ * Create a new object from the value of the given `path`.
*
* Créer un nouvel objet à partir du chemin donné dans `path`.
*
From e0c1920965dbe46ccb081cb2c2cae2163d7d02f6 Mon Sep 17 00:00:00 2001
From: AlasDiablo <25723276+AlasDiablo@users.noreply.github.com>
Date: Tue, 30 Jan 2024 13:33:19 +0100
Subject: [PATCH 21/26] docs (analytics): add reducing documentation
---
docs/plugin-analytics.md | 42 +++++++++-----
packages/analytics/README.md | 42 +++++++++-----
packages/analytics/src/reducing.js | 91 ++++++++++++++++++------------
3 files changed, 110 insertions(+), 65 deletions(-)
diff --git a/docs/plugin-analytics.md b/docs/plugin-analytics.md
index a5f20b762..3de4331e2 100644
--- a/docs/plugin-analytics.md
+++ b/docs/plugin-analytics.md
@@ -1134,33 +1134,45 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### reducing
-Take `Object` group value of `{ id, value }` objectpath
+Merges the `id`, `value` pairs into a new pair, associating the identifier with the values.
-```json
-[{
- { id: 'x', value: 2 },
- { id: 't', value: 2 },
- { id: 'x', value: 3 },
- { id: 'x', value: 5 },
-}]
-```
+Fusionne les couple `id`, `value`, en un nouveau couple associent l'identifient au valeurs.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "reducing"
+; Importation du plugin analytique nécessaire pour utiliser "reducing"
[use]
plugin = analytics
+; Using "reducing" with default settings
+; Utilisation de "reducing" avec les paramètres par défaut
[reducing]
+; id = id
+; value = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: 'x', value: [2, 3, 5] },
- { id: 't', value: [2] },
-]
+ [
+ { "id": "x", "value": 2 },
+ { "id": "t", "value": 2 },
+ { "id": "x", "value": 3 },
+ { "id": "x", "value": 5 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": "x", "value": [2, 3, 5] },
+ { "id": "t", "value": [2] }
+ ]
```
#### Parameters
diff --git a/packages/analytics/README.md b/packages/analytics/README.md
index a5f20b762..3de4331e2 100644
--- a/packages/analytics/README.md
+++ b/packages/analytics/README.md
@@ -1134,33 +1134,45 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### reducing
-Take `Object` group value of `{ id, value }` objectpath
+Merges the `id`, `value` pairs into a new pair, associating the identifier with the values.
-```json
-[{
- { id: 'x', value: 2 },
- { id: 't', value: 2 },
- { id: 'x', value: 3 },
- { id: 'x', value: 5 },
-}]
-```
+Fusionne les couple `id`, `value`, en un nouveau couple associent l'identifient au valeurs.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "reducing"
+; Importation du plugin analytique nécessaire pour utiliser "reducing"
[use]
plugin = analytics
+; Using "reducing" with default settings
+; Utilisation de "reducing" avec les paramètres par défaut
[reducing]
+; id = id
+; value = value
```
-Output:
+##### Input / Entrée
```json
-[
- { id: 'x', value: [2, 3, 5] },
- { id: 't', value: [2] },
-]
+ [
+ { "id": "x", "value": 2 },
+ { "id": "t", "value": 2 },
+ { "id": "x", "value": 3 },
+ { "id": "x", "value": 5 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": "x", "value": [2, 3, 5] },
+ { "id": "t", "value": [2] }
+ ]
```
#### Parameters
diff --git a/packages/analytics/src/reducing.js b/packages/analytics/src/reducing.js
index c41cb50ad..3b5b13d6a 100644
--- a/packages/analytics/src/reducing.js
+++ b/packages/analytics/src/reducing.js
@@ -2,34 +2,74 @@ import get from 'lodash.get';
import { createStore } from '@ezs/store';
/**
- * Take `Object` group value of `{ id, value }` objectpath
+ * Reducing function see documentation at the end.
+ * This part of the doc is used for jsdoc typing
+ * @private
+ * @param data {unknown}
+ * @param feed {Feed}
+ * @param ctx {import('../../core/src/engine').EngineScope}
+ */
+const reducing = async (data, feed, ctx) => {
+ if (!ctx.store) {
+ const location = ctx.getParam('location');
+ ctx.store = createStore(ctx.ezs, 'reducing', location);
+ }
+ if (ctx.isLast()) {
+ const stream = await ctx.store.empty();
+ stream
+ .on('data', (item) => feed.write(item))
+ .on('end', async () => {
+ await ctx.store.close();
+ feed.close();
+ });
+ } else {
+ const id = get(data, ctx.getParam('id', 'id')) || ctx.getIndex();
+ const value = get(data, ctx.getParam('value', 'value'));
+ await ctx.store.add(id, value);
+ feed.end();
+ }
+};
+
+/**
+ * Merges the `id`, `value` pairs into a new pair, associating the identifier with the values.
*
- * ```json
- * [{
- * { id: 'x', value: 2 },
- * { id: 't', value: 2 },
- * { id: 'x', value: 3 },
- * { id: 'x', value: 5 },
- * }]
- * ```
+ * Fusionne les couple `id`, `value`, en un nouveau couple associent l'identifient au valeurs.
*
- * Script:
+ * ### Example / Exemple
+ *
+ * #### Script / Scénario
*
* ```ini
+ * ; Import analytics plugin required to use "reducing"
+ * ; Importation du plugin analytique nécessaire pour utiliser "reducing"
* [use]
* plugin = analytics
*
+ * ; Using "reducing" with default settings
+ * ; Utilisation de "reducing" avec les paramètres par défaut
* [reducing]
+ * ; id = id
+ * ; value = value
*
* ```
*
- * Output:
+ * #### Input / Entrée
+ *
+ * ```json
+ * [
+ * { "id": "x", "value": 2 },
+ * { "id": "t", "value": 2 },
+ * { "id": "x", "value": 3 },
+ * { "id": "x", "value": 5 }
+ * ]
+ * ```
+ * #### Output / Sortie
*
* ```json
- * [
- * { id: 'x', value: [2, 3, 5] },
- * { id: 't', value: [2] },
- * ]
+ * [
+ * { "id": "x", "value": [2, 3, 5] },
+ * { "id": "t", "value": [2] }
+ * ]
* ```
*
* @name reducing
@@ -37,23 +77,4 @@ import { createStore } from '@ezs/store';
* @param {String} [value=value] path to use for value
* @returns {Object}
*/
-export default async function reducing(data, feed) {
- if (!this.store) {
- const location = this.getParam('location');
- this.store = createStore(this.ezs, 'reducing', location);
- }
- if (this.isLast()) {
- const stream = await this.store.empty();
- stream
- .on('data', (item) => feed.write(item))
- .on('end', async () => {
- await this.store.close();
- feed.close();
- });
- } else {
- const id = get(data, this.getParam('id', 'id')) || this.getIndex();
- const value = get(data, this.getParam('value', 'value'));
- await this.store.add(id, value)
- feed.end();
- }
-}
+export default reducing;
From cff6018b0526a742a5df35231618712b9d03070b Mon Sep 17 00:00:00 2001
From: AlasDiablo <25723276+AlasDiablo@users.noreply.github.com>
Date: Wed, 31 Jan 2024 08:45:32 +0100
Subject: [PATCH 22/26] docs (analytics): reformat pluck doc and fix reducing
doc
---
docs/plugin-analytics.md | 76 ++++++++++--------
packages/analytics/README.md | 76 ++++++++++--------
packages/analytics/src/pluck.js | 121 ++++++++++++++++++-----------
packages/analytics/src/reducing.js | 13 +++-
4 files changed, 174 insertions(+), 112 deletions(-)
diff --git a/docs/plugin-analytics.md b/docs/plugin-analytics.md
index 3de4331e2..6ea00cf97 100644
--- a/docs/plugin-analytics.md
+++ b/docs/plugin-analytics.md
@@ -1085,52 +1085,64 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### pluck
-Take `Object` object getting value of fields (with json `path`) and throws an
-object for each value
+Extract the value of a given `path` and create a pair with the `path` as the `id`
+and `path` value as the `value`.
-```json
-[
- { city: 'tokyo', year: 2000, count: 1 },
- { city: 'paris', year: 2001, count: 2 },
- { city: 'london', year: 2003, count: 3 },
- { city: 'nancy', year: 2005, count: 4 },
- { city: 'berlin', year: 2007, count: 5 },
- { city: 'madrid', year: 2009, count: 6 },
- { city: 'stockholm', year: 2011, count: 7 },
- { city: 'bruxelles', year: 2013, count: 8 },
-]
-```
+Extrais la valeur d'un `path` donnée et créer un couple avec pour identifient le `path`
+et comme `value` la valeur du `path`.
-Script:
+#### Example / Exemple
+
+##### Script / Scénario
```ini
+; Import analytics plugin required to use "pluck"
+; Importation du plugin analytique nécessaire pour utiliser "pluck"
[use]
plugin = analytics
+; Using "pluck" with 'year' as path setttings instead of 'id' how is the default value
+; Utilisation de "pluck" avec 'year' comme paramètres de path au lieux de la valeur par defaut qui et 'id'
[pluck]
path = year
```
-Output:
+##### Input / Entrée
```json
-[
-{ "id": "year", "value": 2000 },
-{ "id": "year", "value": 2001 },
-{ "id": "year", "value": 2003 },
-{ "id": "year", "value": 2005 },
-{ "id": "year", "value": 2007 },
-{ "id": "year", "value": 2009 },
-{ "id": "year", "value": 2011 },
-{ "id": "year", "value": 2013 }
-]
+ [
+ { "city": "tokyo", "year": 2000, "count": 1 },
+ { "city": "paris", "year": 2001, "count": 2 },
+ { "city": "london", "year": 2003, "count": 3 },
+ { "city": "nancy", "year": 2005, "count": 4 },
+ { "city": "berlin", "year": 2007, "count": 5 },
+ { "city": "madrid", "year": 2009, "count": 6 },
+ { "city": "stockholm", "year": 2011, "count": 7 },
+ { "city": "bruxelles", "year": 2013, "count": 8 }
+ ]
+```
+
+##### Output / Sortie
+
+```json
+ [
+ { "id": "year", "value": 2000 },
+ { "id": "year", "value": 2001 },
+ { "id": "year", "value": 2003 },
+ { "id": "year", "value": 2005 },
+ { "id": "year", "value": 2007 },
+ { "id": "year", "value": 2009 },
+ { "id": "year", "value": 2011 },
+ { "id": "year", "value": 2013 }
+ ]
```
#### Parameters
-- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use form group by (optional, default `id`)
+- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
path of the element who need to be extrated
+
chemin de l'élément qui doit être extrais
(optional, default `id`)
-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
+Returns **{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)}**
### reducing
@@ -1177,10 +1189,12 @@ plugin = analytics
#### Parameters
-- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for id (optional, default `id`)
-- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to use for value (optional, default `value`)
+- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
path of the element who will be use as the key
+
chemin de l'élément qui vas être utilisé comme clé