Skip to content

Commit f768fc0

Browse files
committed
Code conventions
1 parent 19e477e commit f768fc0

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# http://EditorConfig.org
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
8+
[*.html]
9+
indent_style = tab
10+
11+
[*.js]
12+
indent_style = tab
13+
14+
[*.json]
15+
indent_size = 2
16+
indent_style = space
17+
18+
[*.md]
19+
indent_size = 4
20+
indent_style = tab
21+
22+
[*.yml]
23+
indent_size = 2
24+
indent_style = space

.markdownlint.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"default": true,
3+
"blanks-around-fences": false,
4+
"blanks-around-lists": false,
5+
"first-line-heading": false,
6+
"line-length": false,
7+
"no-hard-tabs": false,
8+
"no-inline-html": {
9+
"allowed_elements": ["br", "kbd"]
10+
},
11+
"no-multiple-blanks": {
12+
"maximum": 2
13+
},
14+
"ul-indent": false,
15+
"ul-style": {
16+
"style": "consistent"
17+
}
18+
}

README.md

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# node-red-contrib-json-multi-schema
2+
23
Generic Node-RED nodes for a JSON data pipeline, suitable for continuous/streaming input, and with dynamic configuration.
34

45
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/alexandrainst/node-red-contrib-json-multi-schema/Node%20CI?logo=github)
@@ -24,20 +25,19 @@ Here is an example of full Node-RED flow: [Node-RED_example_of_flow.json](exampl
2425

2526
![Node-RED flow](examples/Node-RED_example_of_flow.png)
2627

27-
 
2828

2929
---
3030

31-
 
32-
3331
## node-red-contrib-json-multi-schema-resolver
32+
3433
* *Context*: Node-RED node, or command line with `node ./index.js json-multi-schema-resolver --mappingsUrl='"https://..."'`
3534
* *Purpose*: Ability to determine the URL of the JSON Schema (e.g. FIWARE NGSI) or JSONata expression to use for a given JSON payload received.
3635
* *Configuration*: A Node-RED `mappingsUrl` property to indicate the URL of a file listing which JSON Schema or JSONata expression to use for which data input. (See examples below).
3736
* *Input*: A JSON observation (e.g. one of the FIWARE NGSI types) in the `msg.payload` property.
3837
* *Output*: The unmodified JSON observation in the `msg.payload` property, and the resolved schema URL in the `msg.schemaUrl` property (if any match was found), and potential resolution errors in the `msg.error` property.
3938

40-
### Example of input data
39+
### Example of input data (schema-resolver)
40+
4141
This is an example of [standard payload](https://fiware-datamodels.readthedocs.io/en/latest/Transportation/Vehicle/Vehicle/doc/spec/index.html), for which we need to look-up the [corresponding JSON Schema](https://smart-data-models.github.io/data-models/specs/Transportation/Vehicle/VehicleModel/schema.json).
4242

4343
We represent the example as a full Node-RED message, i.e. wrapped into a `{"payload":...}` structure.
@@ -119,6 +119,7 @@ In the example, this JSON file is hosted at [`examples/smart-data-transforms.jso
119119
```
120120

121121
### Example of schema resolution from command line
122+
122123
The JSON input messages must each be on one single line, and wrapped into a Node-RED structure `{"payload":...}`
123124
See the `jq` examples at the bottom on how to automatise the wrapping.
124125

@@ -163,13 +164,10 @@ Output:
163164
}
164165
```
165166

166-
 
167-
168167
---
169168

170-
 
171-
172169
## node-red-contrib-json-multi-schema-transformer
170+
173171
* *Context*: Node-RED node, or command line with `node ./index.js multi-schema-transformer`
174172
* *Purpose*: Ability to transform a JSON observation on the fly from whichever format to another format (e.g. one of the FIWARE NGSI types) using a specified JSONata URL. Schemas are automatically downloaded and cached the first time they are needed.
175173
* *Input*: A JSON observation in whichever format in the `msg.payload` property, and the corresponding JSONata URL on the `msg.schemaUrl` property (coming from json-multi-schema-resolver).
@@ -180,7 +178,7 @@ Output:
180178

181179
It is typically used with a *json-multi-schema-resolver* node in front.
182180

183-
### Example of input data
181+
### Example of input data (schema-transformer)
184182

185183
This is an example of proprietary format, which we would like to transform into another format (a standard NGSI one).
186184

@@ -231,6 +229,7 @@ In the example, this JSONata file is hosted at [`Cesva-TA120-to-NoiseLevelObserv
231229
A more advanced example of JSONata transformation can be found in [`NGSI-Normalised-to-keyValues.jsonata.js`](https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/master/examples/NGSI-Normalised-to-keyValues.jsonata.js).
232230

233231
### Example of transformation from command line
232+
234233
The JSON input messages must each be on one single line, and wrapped into a Node-RED structure `{"payload":...}`
235234

236235
```sh
@@ -241,7 +240,7 @@ jq .
241240

242241
Same example, but using a static default value for the schema URL in the corresponding property:
243242

244-
```
243+
```sh
245244
echo '{"payload":{"id":"TA120-T246177","type":"Cesva-TA120","NoiseLevelObserved":{"id":"TA120-T246177-NoiseLevelObserved-2018-09-17T07:01:09.000000Z","sonometerClass":"1","location":{"coordinates":[24.985891,60.274286],"type":"Point"},"measurand":["LAeq | 48.6 | A-weighted, equivalent, sound level"],"dateObserved":"2018-09-17T07:01:09.000000Z","LAeq":48.6,"type":"NoiseLevelObserved"}},"error":false}' | \
246245
node ./index.js json-multi-schema-transformer --defaultSchemaUrl='"https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/master/examples/Cesva-TA120-to-NoiseLevelObserved.jsonata.js"' | \
247246
jq .
@@ -270,13 +269,10 @@ Output:
270269
}
271270
```
272271

273-
 
274-
275272
---
276273

277-
 
278-
279274
## node-red-contrib-json-multi-schema-validator
275+
280276
* *Context*: Node-RED node, or command line with `node ./index.js json-multi-schema-validator`
281277
* *Purpose*: Ability to validate a JSON observation (e.g. one of the FIWARE NGSI types) on the fly against a specified JSON Schema URL. Schemas are automatically downloaded and cached the first time they are needed.
282278
* *Input*: A JSON observation (e.g. one of the FIWARE NGSI types) in the `msg.payload` property, and the corresponding JSON Schema URL on the `msg.schemaUrl` property (coming from json-multi-schema-resolver).
@@ -286,7 +282,8 @@ Output:
286282

287283
It is typically used with a *json-multi-schema-resolver* node in front.
288284

289-
### Example of input data
285+
### Example of input data (schema-validator)
286+
290287
This is an example of [standard payload](https://fiware-datamodels.readthedocs.io/en/latest/Environment/NoiseLevelObserved/doc/spec/index.html#noise-level-observed), which we want to validate against its [corresponding JSON Schema](https://smart-data-models.github.io/data-models/specs/Environment/NoiseLevelObserved/schema.json), which address is provided by the Node-RED property `msg.schemaUrl`.
291288

292289
```json
@@ -310,6 +307,7 @@ This is an example of [standard payload](https://fiware-datamodels.readthedocs.i
310307
```
311308

312309
### Example of JSON Schema validation from command line
310+
313311
The JSON input messages must each be on one single line, and wrapped into a Node-RED structure `{"payload":...}`
314312

315313
```sh
@@ -341,20 +339,19 @@ Output:
341339
}
342340
```
343341

344-
 
345-
346342
---
347343

348-
 
349-
350344
## Wiring/Piping all modules together
345+
351346
The three modules above may be used independently or in combination.
352347
Here is an example of JSON transformation, followed by a schema resolver, and finally a JSON Schema validation.
353348

354349
### Wiring in Node-RED
350+
355351
Cf. screenshot at the top of this document.
356352

357353
### Piping on command line
354+
358355
```sh
359356
printf '{"payload":{"id":"TA120-T246177","type":"Cesva-TA120","NoiseLevelObserved":{"id":"TA120-T246177-NoiseLevelObserved-2018-09-17T07:01:09.000000Z","sonometerClass":"1","location":{"coordinates":[24.985891,60.274286],"type":"Point"},"measurand":["LAeq | 48.6 | A-weighted, equivalent, sound level"],"dateObserved":"2018-09-17T07:01:09.000000Z","LAeq":48.6,"type":"NoiseLevelObserved"}}} \n {"payload":{"id":"TA120-T246183","type":"Cesva-TA120","NoiseLevelObserved":{"id":"TA120-T246183-NoiseLevelObserved-2018-09-17T07:01:15.000000Z","sonometerClass":"1","location":{"coordinates":[24.9030921,60.161804],"type":"Point"},"measurand":["LAeq | 37.6 | A-weighted, equivalent, sound level"],"dateObserved":"2018-09-17T07:01:15.000000Z","LAeq":37.6,"type":"NoiseLevelObserved"}}}' | \
360357
node ./index.js json-multi-schema-resolver --mappingsUrl='"https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/master/examples/smart-data-transforms.json"' | \
@@ -369,6 +366,7 @@ _Note_: This is the example used for `npm test`
369366
The CLI functionnality is provided by [*node-red-contrib-mock-cli*](https://github.com/alexandrainst/node-red-contrib-mock-cli).
370367

371368
### JSON in Node-RED format
369+
372370
[`jq`](https://stedolan.github.io/jq/) may be used to break down and format a standard payload into a Node-RED payload:
373371

374372
For instance if the input is a list of observations wrapped into a JSON array:
@@ -389,13 +387,8 @@ node ./index.js json-multi-schema-validator | \
389387
jq -c .
390388
```
391389

392-
393-
 
394-
395390
---
396391

397-
 
398-
399392
## Docker
400393

401394
* [![Docker](https://www.docker.com/sites/default/files/horizontal.png)](https://hub.docker.com/repository/docker/synchronicityiot/node-red-contrib-json-multi-schema)
@@ -407,6 +400,7 @@ docker build --tag synchronicityiot/node-red-contrib-json-multi-schema .
407400
```
408401

409402
### Persistant cache
403+
410404
To allow keeping a local copy of the remote JSON configuration files, transformations, and schemas.
411405

412406
```sh
@@ -432,17 +426,13 @@ docker run -i -v tmp-schemas:/tmp --rm synchronicityiot/node-red-contrib-json-mu
432426
jq -c .
433427
```
434428

435-
 
436-
437429
---
438430

439-
 
440-
441431
## Serving schemas
442432

443433
The three nodes are all expecting configuration files and corresponding schemas to be provided by HTTP.
444434

445-
While JSON Schemas are often publicly available (e.g. https://schema.org , https://smart-data-models.github.io/data-models/ ), it might not be the case for the list of JSON Schemas itself, the list of transformations, or the JSONata transformations.
435+
While JSON Schemas are often publicly available (e.g. <https://schema.org> , <https://smart-data-models.github.io/data-models/> ), it might not be the case for the list of JSON Schemas itself, the list of transformations, or the JSONata transformations.
446436

447437
Any HTTP server can be used to host those documents. This can also be done using Node-RED:
448438

@@ -458,12 +448,8 @@ In this example, the schemas are published at `http://localhost:1880/schemas/exa
458448

459449
Read more on the [Node-RED cookbook](https://cookbook.nodered.org/http/serve-json-content).
460450

461-
 
462-
463451
---
464452

465-
 
466-
467453
## Caching of schemas
468454

469455
A disk copy of the downloaded JSON and JSONata documents is kept in cache on disk.

0 commit comments

Comments
 (0)