Skip to content

Commit f8463b8

Browse files
committed
First release
1 parent 37bf730 commit f8463b8

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Set of generic JSON data pipeline tools, suitable for continuous/streaming input
33

44
Three distinct nodes allow transforming, resolving schemas, and validating different types of JSON inputs.
55

6-
The nodes are made for [Node-RED](https://nodered.org) but can alternatively be run from command-line using standard input/output.
6+
The nodes are made for [Node-RED](https://nodered.org) but can alternatively be [run from command-line](https://github.com/alexandrainst/node-red-contrib-mock-cli) using standard input/output.
77
Matching rules and transformation rules are written in [JSONata](http://jsonata.org) (JSON query and transformation language), in external files.
88

99
Appropriate e.g. for working with [FIWARE](https://www.fiware.org/developers/data-models/)’s [Smart Data Models](https://smart-data-models.github.io/data-models/),
@@ -352,6 +352,8 @@ jq .
352352

353353
_Note_: This is the example used for `npm test`
354354

355+
The CLI functionnality is provided by [*node-red-contrib-mock-cli*](https://github.com/alexandrainst/node-red-contrib-mock-cli).
356+
355357
### JSON in Node-RED format
356358
[`jq`](https://stedolan.github.io/jq/) may be used to break down and format a standard payload into a Node-RED payload:
357359

@@ -450,6 +452,6 @@ Read more on the [Node-RED cookbook](https://cookbook.nodered.org/http/serve-jso
450452

451453
A disk copy of the downloaded JSON and JSONata documents is kept in cache on disk.
452454
By default, the cache path is `/tmp/` but that can be changed with the environment variable `SCHEMAS_CACHE_PATH`
453-
Cached files have a `*.tmp.js` suffix.
455+
Cached files have a `schema.[URL hash].[Node ID].tmp.js` format.
454456

455457
If schemas are updated without changing their URL, it is possible to either purge the local cache manually, or add a version number at the end of their URL, such as `https://example.net/a-schema.json?v2`

json-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = node => {
6464

6565
let text, json, hash;
6666
if (cachePath) {
67-
hash = cachePath + crypto.createHash('sha256').update(url).digest('hex') + '.tmp.js';
67+
hash = cachePath + 'schema.' + crypto.createHash('sha256').update(url).digest('hex') + '.' + node.id + '.tmp.js';
6868
try {
6969
text = await readFileAsync(hash, 'utf8');
7070
node.debug('Load JSON from disk cache: ' + url);

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-json-multi-schema",
3-
"version": "0.5.2",
3+
"version": "1.0.0",
44
"description": "Generic JSON data pipeline tools, with dynamic transformation (using JSONata rules), resolving JSON Schema (using JSONata rules), and then validation (using JSON Schema). For Node-RED and for command-line.",
55
"main": "index.js",
66
"readmeFilename": "readme.md",
@@ -32,7 +32,7 @@
3232
"ajv": "^6.10.2",
3333
"jsonata": "^1.7.0",
3434
"node-fetch": "^2.6.0",
35-
"node-red-contrib-mock-cli": "https://github.com/alexandrainst/node-red-contrib-mock-cli.git#7dd9eaafb8d5f3293793d7b778c8d4ae72fb3c14"
35+
"node-red-contrib-mock-cli": "^1.0.0"
3636
},
3737
"devDependencies": {
3838
"jshint": "^2.10.3"
@@ -47,6 +47,6 @@
4747
"start": "node ./index.js",
4848
"lint": "node ./node_modules/.bin/jshint *.js",
4949
"pretest": "npm run-script lint",
50-
"test": "rm /tmp/*.tmp.js ; 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\"}}}' | 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\"' | node ./index.js json-multi-schema-transformer | node ./index.js json-multi-schema-resolver --mappingsUrl='\"https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/master/examples/smart-data-models.json\"' | node ./index.js json-multi-schema-validator"
50+
"test": "rm /tmp/schema.*.tmp.js ; 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\"}}}' | 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\"' | node ./index.js json-multi-schema-transformer | node ./index.js json-multi-schema-resolver --mappingsUrl='\"https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/master/examples/smart-data-models.json\"' | node ./index.js json-multi-schema-validator"
5151
}
5252
}

0 commit comments

Comments
 (0)