@ezs/core v3.11.2
core
Ce plugin propose une série d'instructions natives. Elles sont constamment disponibles car chargées automatiquement.
installation
npm install @ezs/coredétails
Plusieurs instructions permettent de créer des sous-flux (sub pipeline), à partir d'un fichier d’instructions ou d'instructions imbriquées. Si elles s'utilisent toutes de la même manière (avec les mêmes paramètres) certaines peuvent apparaître comme similaires mais leur fonctionnement est différent :
[delegate]: 1 sous-flux pour tous les éléments[swing]: 1 sous-flux pour tous les éléments filtrés selon une condition[spawn]: 1 sous-flux par élément[loop]: 1 sous-flux par élément[expand]: 1 sous-flux pour N éléments (N = size), seul le champ sélectionné est envoyé dans le pipeline[combine]: 1 sous-flux pour tous les éléments, seul le champ sélectionné est comparé avec le résultat du sous-flux[singleton]: 1 sous-flux pour le premier élément
usage
Table of Contents
- assign
- combine
- concat
- debug
- dedupe
- delegate
- delegate
- dispatch
- dump
- env
- exchange
- expand
- extract
- fork
- group
- identify
- ignore
- keep
- loop
- map
- metrics
- overturn
- pack
- parallel
- pop
- remove
- replace
- shift
- shuffle
- singleton
- spawn
- swing
- throttle
- time
- tracer
- transit
- truncate
- ungroup
- unpack
- use
- validate
assign
- See: exchange
Affecte une valeur à un champ de l'objet courant. Si le champ existe déjà, sa valeur est écrasée, sinon il est créé
Entrée:
[{
"nom": "un",
"valeur": 1
},
{
"nom": "deux",
"valeur": 2
},
{
"nom": "trois",
"valeur": 3
},
{
"nom": "quatre",
"valeur": 4
}]Script:
[assign]
path = valeur
value = get("valeur").multiply(2)Output:
[{
"nom": "un",
"valeur": 2
},
{
"nom": "deux",
"valeur": 4
},
{
"nom": "trois",
"valeur": 6
},
{
"nom": "quatre",
"valeur": 8
}]Le path peut être le nom simple d'un champ présent à la racine de l'élément
traité, ou un chemin en notation
pointée, en utilisant
une syntaxe proche de celle de la fonction
get de Lodash.
Parameters
Returns Object
combine
Takes an Object and substitute a field with the corresponding value found in a external pipeline
the internal pipeline must produce a stream of special object (id, value)
[
{ year: 2000, dept: 54 },
{ year: 2001, dept: 55 },
{ year: 2003, dept: 54 },
]Script:
[use]
plugin = analytics
[combine]
path = dept
file = ./departement.iniOutput:
[
{ year: 2000, dept: { id: 54, value: 'Meurthe et moselle' } },
{ year: 2001, dept: { id: 55, value: 'Meuse' } },
{ year: 2003, dept: { id: 54, value: 'Meurthe et moselle' } },
]Parameters
pathString? the path to substitutedefaultString? value if no substitution (otherwise value stay unchanged)primerString Data to send to the external pipeline (optional, defaultn/a)fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errorscacheNameString? Enable cache, with dedicated name
Returns Object
concat
Take all String, concat them and throw just one.
[
"a",
"b",
"c"
]Script:
[concat]
beginWith = <
joinWith = |
endWith = >Output:
[
"<a|b|c>"
]Parameters
beginWithString? Add value at the beginjoinWithString? use value to join 2 chunkendWithString? Add value at the end
Returns String
debug
Take Object, print it (with its index number), and throw the same object.
Parameters
levelString DEBUG ezs level (depends of DEBUG env variable, see cli parameters) (optional, defaultinfo)textString text before the dump (optional, defaultvalueOf)pathString? path of field to print
Returns Object
dedupe
Take Object, and check that the object identifier has not already been used previously
Parameters
datafeedpathString path containing the object Identifier (optional, defaulturi)ignoreBoolean Just ignore duplicate object (optional, defaultfalse)
Returns Object
delegate
Break the stream if the control file cannot be checked
Parameters
fusibleString? file to check
Returns Object
delegate
Delegate processing to an external pipeline.
Note: works like spawn, but each chunk share the same external pipeline.
Parameters
fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errors
Returns Object
dispatch
Dispatch processing to an external pipeline on one or more servers.
Parameters
fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like command
Returns Object
dump
Take all Objects and generate a JSON array
[
{ "a": 1 },
{ "a": 2 },
{ "a": 3 },
{ "a": 4 },
{ "a": 5 }
]Script:
[dump]
indent = trueOutput:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}
]Parameters
indentboolean indent JSON (optional, defaultfalse)
Returns String
env
Crée une variable d'environnement globale à tout le script.
On l'utilise en général au début du script (après [use]).
Pour utiliser la variable, il faut employer la fonction env().
Entrée:
[{
"nom": "un",
"valeur": 1
},
{
"nom": "deux",
"valeur": 2
}]Script:
[use]
plugin = basics
[env]
path = nom
value = NOM GÉNÉRIQUE
[JSONParse]
[assign]
path = nom
value = env("nom")
[dump]
indent = trueSortie:
[{
"nom": "NOM GÉNÉRIQUE",
"valeur": 1
},
{
"nom": "NOM GÉNÉRIQUE",
"valeur": 2
}]Parameters
Returns Object
exchange
Remplace tout un objet par un autre (au sens JSON).
Entrée:
[{
"nom": "un",
"valeur": 1
},
{
"nom": "deux",
"valeur": 2
}]
Script:
```ini
[use] plugin = basics
[JSONParse]
[exchange] value = get("nom")
[dump]Sortie:
["un","deux"]Ici, 'objet {"nom":"un","valeur":1} a été remplacé par l'« objet » (au sens
JSON, une chaîne de caractères, tout autant qu'un nombre, constitue un objet)
"un".
Note: assign ne permet pas de remplacer tout l'objet, mais seulement une de
ses propriétés.
Entrée:
[{
"a": "abcdefg", "b": "1234567", "c": "XXXXXXX"
},
{
"a": "abcdefg", "b": "1234567", "c": "XXXXXXX"
}]Script:
[exchange]
value = omit('c')Output:
[{
"a": "abcdefg",
"b": "1234567"
},
{
"a": "abcdefg",
"b": "1234567"
}]Ici, on a remplacé un objet avec trois propriétés par le même objet sans la
propriété c (voir la function
omit de Lodash).
Parameters
valueString? la valeur de remplacement de l'objet courant
Returns Object
expand
Takes an Object and substitute a field with the corresponding value found in a external pipeline
the internal pipeline receive a special object { id, value } id is the item identifier & value is the item path value
The internal pipeline can expand value with another
[
{ year: 2000, dept: 54 },
{ year: 2001, dept: 55 },
{ year: 2003, dept: 54 },
]Script:
[use]
plugin = analytics
[expand]
path = dept
file = ./departement.iniOutput:
[
{ year: 2000, dept: { id: 54, value: 'Meurthe et moselle' } },
{ year: 2001, dept: { id: 55, value: 'Meuse' } },
{ year: 2003, dept: { id: 54, value: 'Meurthe et moselle' } },
]Parameters
pathString? the path to substitutesizeNumber How many chunk for sending to the external pipeline (optional, default1)fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errorscacheNameString? Enable cache, with dedicated nametokenString? add token values in the subpipeline (optional)
Returns Object
extract
Extrait de l'objet courant les valeurs de certains champs, et renvoie directement les valeurs dans le flux de sortie.
Note:
extractne peut pas fournir des valeursundefinedounull.
Entrée:
[{
"nom": "un",
"valeur": 1,
"important": false
},
{
"nom": "deux",
"valeur": 2,
"important": true
}]Script:
[use]
plugin = basics
[JSONParse]
[extract]
path = valeur
path = nom
[dump]Sortie:
[[1,"un"],[2,"deux"]]Parameters
pathString? chemin d'un champ à extraire
Returns Object
fork
fork the current pipeline
Note: but each chunk is sent to the same external pipeline.
Parameters
standaloneBoolean The current pipeline will be able to end without waiting for the end of the external pipeline (optional, defaultfalse)fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errorstargetString choose the key to set with the forked request identifier (optional, defaultx-request-id)
Returns Object
group
Take all chunks, and throw them grouped by length.
See also ungroup.
[
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h"
]Script:
[group]
length = 3Output:
[
[ "a", "b", "c" ],
[ "d", "e", "f" ],
[ "g", "h" ]
]Parameters
lengthNumber? Size of each partition
Returns String
identify
Take Object, and compute & add an identifier
Parameters
datafeedschemeString scheme to use (uid or sha) (optional, defaultuid)pathString path containing the object Identifier (optional, defaulturi)
Returns String
ignore
Takes all the chunks, and ignore the firtst N chunk
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]Script:
[ignore]
length = 3Output:
[{
"a": 4
},
{
"a": 5
}]Parameters
lengthNumber? Length of the feed to ignore
Returns any
keep
Throw input Object but keep only specific fields.
Input file:
[{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
},
{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
}]Script:
[keep]
path = a
path = bOutput:
[{
"a": "abcdefg",
"b": "1234567"
},
{
"a": "abcdefg",
"b": "1234567"
}]Parameters
pathString? path of field to keep
Returns Object
loop
Loop on external pipeline, until test will be true
Note: works like delegate, but each chunk use its own external pipeline
Parameters
testString? if test is truereverseBoolean to reverse the test (optional, defaultfalse)maxDepthNumber to limit the number of loops (optional, default100000)fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in an objectcommandString? the external pipeline is described in an URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errorsfusibleString? Can be set with the ezs server fusible see env('request.fusible')
Returns Object
map
From an array field delegate processing of each items to an external pipeline
Note: works like delegate, but each chunk use its own external pipeline
Parameters
pathString? the path to substitutefileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in an objectcommandString? the external pipeline is described in an URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errors
Returns Object
metrics
- See: ../server/knownPipeline.js
Take Object, and throw the same object.
This statement will only be used if :
- EZS_METRICS is enabled
- ezs is running in server mode
WARNING: avoid setting bucket to "input" or "output", as these labels are used by ezs. If you do, you risk distorting the associated metrics.
Parameters
pathNameString to identify the script (optional, defaultauto)bucketString to identify the moment of measurement (optional, defaultunknow)
Returns Object
overturn
Takes an Object and substitute twice a field with the corresponding value found in a external pipeline
the internal pipeline receive a special object { id, value, token } :
- id is the item identifier
- value is the item path value,
- token is an array containing stream id and an number (0 for first time, 1 for the second tme The internal pipeline can overturn value with another.
It's work like [expand] but the second call starts only when all the values of the stream have been sent once
[
{ year: 2000, dept: 'Meuse' },
{ year: 2001, dept: 'Moselle' },
{ year: 2003, dept: 'Vosges'},
]Script #1:
[overturn]
path = dept
[overturn/assign]
path = value
value = get('value').split('').reverse().join('')Output:
[
{ year: 2000, dept: 'Meuse' },
{ year: 2001, dept: 'Moselle' },
{ year: 2003, dept: 'Vosges' },
]Script #2:
[overturn]
path = dept
[overturn/drop]
path = token.1
if = 0
[overturn/assign]
path = value
value = get('value').split('').reverse().join('')Output:
[
{ year: 2000, dept: 'esueM' },
{ year: 2001, dept: 'ellesoM' },
{ year: 2003, dept: 'segsoV' },
]Parameters
pathString? the path to overturnsizeNumber How many chunk for sending to the external pipeline (optional, default1)fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like command
Returns Object
pack
Take all Object, throw encoded String
Returns String
parallel
Takes an Object delegate processing to X internal pipelines
Parameters
fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errors
Returns Object
pop
- See: shift
Return the last Object and close the feed
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]Script:
[shift]Output:
[{
"a": 5
}]Returns Object
remove
Take Object and remove it from the feed if test is true
Input file:
[{
a: "a"
},
{
a: 2
},
{
a: "b"
},
{
a: 4
},
{
a: "c"
}]Script:
[remove]
test = get('a).isInteger()
reverse = trueOutput:
[
{
a: 2
},
{
a: 4
}
]Parameters
Returns Object
replace
Take Object and replace it with a new object with some fields.
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]Script:
[replace]
path = b.c
value = 'X'Output:
[{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
}]Parameters
Returns Object
shift
Return the first Object and close the feed
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]Script:
[shift]Output:
[{
"a": 1
}]Returns Object
shuffle
Take Object, shuffle data of the whole object or only some fields specified by path
Input file:
[{
"a": "abcdefg",
"b": "1234567"
},
{
"a": "abcdefg",
"b": "1234567"
}]Script:
[shuffle]
path = aOutput:
[{
"a": "cadbefg",
"b": "1234567"
},
{
"a": "dcaegbf",
"b": "1234567"
}]Parameters
pathString? path of field to shuffle
Returns Object
singleton
Takes only the first Object delegate processing to a external pipeline
Parameters
fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in a objectcommandString? the external pipeline is described in a URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errors
Returns Object
spawn
Delegate processing to an external pipeline, throw each chunk from the result.
Note: works like delegate, but each chunk use its own external pipeline
Parameters
fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in an objectcommandString? the external pipeline is described in an URL-like commandloggerString? A dedicaded pipeline described in a file to trap or log errorscacheString? Use a specific ezs statement to run commands (advanced)
Returns Object
swing
Delegate processing to an external pipeline under specifics conditions
Note: works like spawn, but each chunk shares the same external pipeline.
Parameters
testString? if test is truereverseString reverse the test (optional, defaultfalse)fileString? the external pipeline is described in a filescriptString? the external pipeline is described in a string of characterscommandsString? the external pipeline is described in an objectcommandString? the external pipeline is described in an URL-likeloggerString? A dedicaded pipeline described in a file to trap or log errors command
Returns Object
throttle
Take Object and return the same object
[{
{ id: 'x', value: 2 },
{ id: 't', value: 2 },
}]Script:
[use]
plugin = analytics
[throttle]
bySecond = 2Output:
[
{ id: 'x', value: 2 },
{ id: 't', value: 2 },
]Parameters
bySecondNumber Number of object by second (optional, default1)
Returns Object
time
Measure the execution time of a script, on each chunk of input.
Parameters
scriptstring?
Examples
Input
[1]Program
const script = `
[transit]
`;
from([1])
.pipe(ezs('time', { script }))Output
[{
data: 1,
time: 15 // milliseconds
}]Returns object
tracer
Take Object, print a character and throw the same object.
Useful to see the progress in the stream.
Parameters
printString character to print at each object (optional, default.)lastString character to print at last call (optional, default.)firstString character to print at first call (optional, default.)
Returns Object
transit
Take Object and throw the same object again.
Input file:
[{
"a": 1
},
{
"a": 2
}]Script:
[transit]Output:
[{
"a": 1
},
{
"a": 2
}]Returns Object
truncate
Takes all the chunks, and closes the feed when the total length is equal to the parameter.
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]Script:
[truncate]
length = 3Output:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
}]Parameters
lengthNumber? Length of the feed
Returns any
ungroup
Take all chunks, and throw one item for every chunk.
See also group.
[
[ "a", "b", "c" ],
[ "d", "e", "f" ],
[ "g", "h" ]
]Script:
[ungroup]Output:
[
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h"
]Returns Array\
unpack
Take Strings or Buffers and throw Object builded by JSON.parse on each line.
Returns object
use
Take all String, concat them and throw just one.
Script:
[use]
plugin = basics
plugin = analyticsParameters
beginWithString? Add value at the beginjoinWithString? use value to join 2 chunkendWithString? Add value at the end
Returns String
validate
From an Object, throw the same object if all rules pass
See
Input file:
[{
"a": 1,
"b": "titi"
},
{
"a": 2,
"b": "toto"
},
{
"a": false
},
]Script:
[validate]
path = a
rule = required|number
path = a
rule = required|stringOutput:
[{
"a": 1,
"b": "titi"
},
{
"a": 2,
"b": "toto"
}]Parameters
Returns Object
11 months ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
10 months ago
6 months ago
9 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago