Skip to content

Commit e7510a7

Browse files
authored
Update dependencies (#6)
Dev dependencies update from JSHint to ESLint. Medium update of production dependencies.
1 parent f768fc0 commit e7510a7

13 files changed

+3801
-508
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
charset = utf-8
55
end_of_line = lf
66
insert_final_newline = true
7+
trim_trailing_whitespace = true
78

89
[*.html]
910
indent_style = tab

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
examples/
2+
node_modules/

.eslintrc.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"extends": [
6+
"eslint:recommended",
7+
"standard"
8+
],
9+
"rules": {
10+
"comma-dangle": ["warn", "always-multiline"],
11+
"eqeqeq": "off",
12+
"indent": ["warn", "tab", { "SwitchCase": 1 }],
13+
"linebreak-style": ["error", "unix"],
14+
"max-len": ["warn", 160],
15+
"no-tabs": "off",
16+
"semi": ["warn", "always"],
17+
"space-before-function-paren": ["warn", {
18+
"anonymous": "always",
19+
"named": "never",
20+
"asyncArrow": "always"
21+
}]
22+
},
23+
"plugins": [
24+
"html"
25+
],
26+
"settings": {
27+
"html/html-extensions": [".html"],
28+
"html/indent": "tab",
29+
"html/report-bad-indent": "warn"
30+
},
31+
"root": true
32+
}

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/* jshint esversion:8, node:true, strict:true */
2-
"use strict";
2+
'use strict';
33
/**
44
* Command-line interface for the json-multi-schema Node-RED nodes.
5-
*
5+
*
66
* Script to run our Node-RED nodes from terminal without Node-RED and using STDIN / STDOUT.
77
*
88
* @author Alexandre Alapetite <https://alexandra.dk/alexandre.alapetite>
9-
* @copyright Alexandra Institute <https://alexandra.dk> for the SynchroniCity European project <https://synchronicity-iot.eu> as a contribution to FIWARE <https://www.fiware.org>
9+
* @copyright Alexandra Institute <https://alexandra.dk> for the SynchroniCity European project <https://synchronicity-iot.eu>
10+
* as a contribution to FIWARE <https://www.fiware.org>
1011
* @license MIT
1112
* @date 2019-11-28 / 2019-12-02
1213
*/
1314

14-
//Load fake/mocked Node-RED
15+
// Load fake/mocked Node-RED
1516
const RED = require('node-red-contrib-mock-cli');
1617
const noderedNode = RED.load(require.main);
1718

json-cache.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Handles concurrency (when multiple tasks are asking the same document at the same time).
55
*/
66

7-
//Location of disk copy of retrieved JSON documents
8-
const cachePath = process.env.SCHEMAS_CACHE_PATH || '/tmp/'; //TODO: use better location for cache
7+
// Location of disk copy of retrieved JSON documents
8+
const cachePath = process.env.SCHEMAS_CACHE_PATH || '/tmp/'; // TODO: use better location for cache
99

1010
const crypto = require('crypto');
1111
const fetch = require('node-fetch');
@@ -14,14 +14,14 @@ const util = require('util');
1414
const readFileAsync = util.promisify(fs.readFile);
1515
const writeFileAsync = util.promisify(fs.writeFile);
1616

17-
//Memory copy of retrieved JSON documents
17+
// Memory copy of retrieved JSON documents
1818
const ramCaches = {};
1919

20-
//Queue of concurrent tasks waiting for the same JSON documents
20+
// Queue of concurrent tasks waiting for the same JSON documents
2121
const mutexQueue = {};
2222

2323
module.exports = node => {
24-
"use strict";
24+
'use strict';
2525
node.debug('Disk cache path: ' + cachePath);
2626

2727
/**
@@ -50,7 +50,7 @@ module.exports = node => {
5050
}
5151

5252
if (mutexQueue[url]) {
53-
//Wait for another task to be done loading the same URL, so that we can use its cache
53+
// Wait for another task to be done loading the same URL, so that we can use its cache
5454
await new Promise((resolve, reject) => mutexQueue[url].push(resolve));
5555

5656
result = ramCache(url, parse);
@@ -98,10 +98,10 @@ module.exports = node => {
9898
}
9999
}
100100

101-
//Resume tasks waiting for the same URL
101+
// Resume tasks waiting for the same URL
102102
let next;
103103
while ((next = mutexQueue[url].shift()) != undefined) {
104-
next(); //Resolve promise
104+
next(); // Resolve promise
105105
}
106106
delete mutexQueue[url];
107107

json-multi-schema-resolver.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script>
2+
/* global RED:false */
23
RED.nodes.registerType('json-multi-schema-resolver', {
34
category: 'function',
45
color: '#00B4FF',
56
defaults: {
6-
name: { value: '', },
7-
mappingsUrl: { value: '', },
7+
name: { value: '' },
8+
mappingsUrl: { value: '' },
89
},
910
inputs: 1,
1011
outputs: 1,

json-multi-schema-resolver.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const jsonata = require('jsonata');
88
const util = require('util');
99

1010
module.exports = RED => {
11-
"use strict";
11+
'use strict';
1212

1313
function JsonMultiSchemaResolverNode(config) {
1414
RED.nodes.createNode(this, config);
1515
const node = this;
1616
const mappingsUrl = config.mappingsUrl;
1717

1818
let lastStatusError = true;
19-
node.status({ fill:'grey', shape:'ring', text:'Uninitialized', });
19+
node.status({ fill: 'grey', shape: 'ring', text: 'Uninitialized' });
2020

2121
const jsonCache = require('./json-cache.js')(node);
2222

@@ -26,14 +26,14 @@ module.exports = RED => {
2626
async function resolveAsync(payload) {
2727
const mappings = await jsonCache.loadAsync(mappingsUrl);
2828
let schemaUrl = '';
29-
for (let mapping of mappings) {
29+
for (const mapping of mappings) {
3030
if (mapping.query && mapping.cases) {
3131
const expression = jsonata(mapping.query);
3232
let match = expression.evaluate(payload);
3333
if (match) {
3434
if (match === true) {
35-
//Special case for boolean
36-
match = "true";
35+
// Special case for boolean
36+
match = 'true';
3737
}
3838
const result = mapping.cases[match];
3939
if (result) {
@@ -55,12 +55,12 @@ module.exports = RED => {
5555
msg.error = msg.error ? msg.error : false;
5656
}
5757
if (lastStatusError) {
58-
node.status({ fill:'green', shape:'dot', text:'OK', });
58+
node.status({ fill: 'green', shape: 'dot', text: 'OK' });
5959
lastStatusError = false;
6060
}
6161
} catch (ex) {
6262
lastStatusError = true;
63-
node.status({ fill:'red', shape:'ring', text:'Error', });
63+
node.status({ fill: 'red', shape: 'ring', text: 'Error' });
6464
msg.error = msg.error ? msg.error + ' ; ' : '';
6565
msg.error += util.format('Error resolving schema using "%s": %s', mappingsUrl, ex);
6666
}

json-multi-schema-transformer.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script>
2+
/* global RED:false */
23
RED.nodes.registerType('json-multi-schema-transformer', {
34
category: 'function',
45
color: '#00B4FF',
56
defaults: {
6-
name: { value: '', },
7-
defaultSchemaUrl: { value: '', },
7+
name: { value: '' },
8+
defaultSchemaUrl: { value: '' },
89
},
910
inputs: 1,
1011
outputs: 1,

json-multi-schema-transformer.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
* JSONata expressions are cached in memory.
66
*/
77

8-
//JSONata: A declarative open-source query and transformation language for JSON data.
8+
// JSONata: A declarative open-source query and transformation language for JSON data.
99
const jsonata = require('jsonata');
1010
const util = require('util');
1111

1212
module.exports = RED => {
13-
"use strict";
13+
'use strict';
1414

1515
function JsonMultiSchemaTransformerNode(config) {
1616
RED.nodes.createNode(this, config);
1717
const node = this;
1818
const defaultSchemaUrl = config.defaultSchemaUrl;
1919

2020
let lastStatusError = true;
21-
node.status({ fill:'grey', shape:'ring', text:'Uninitialized', });
21+
node.status({ fill: 'grey', shape: 'ring', text: 'Uninitialized' });
2222

2323
const jsonCache = require('./json-cache.js')(node);
2424

25-
//Cache of JSONata expressions
25+
// Cache of JSONata expressions
2626
const jsonatas = {};
2727

2828
/**
@@ -33,28 +33,28 @@ module.exports = RED => {
3333
let jsonataCache = jsonatas[transformUrl];
3434
if (jsonataCache) {
3535
if (jsonataCache.expression === null) {
36-
//Wait for another task to be done building the same JSONata, so that we can use its cache
36+
// Wait for another task to be done building the same JSONata, so that we can use its cache
3737
await new Promise((resolve, reject) => jsonataCache.mutexQueue.push(resolve));
3838
}
3939
jsonataExpression = jsonataCache.expression;
4040
} else {
41-
//Build JSONata expression for the given transformation URL
41+
// Build JSONata expression for the given transformation URL
4242
jsonataCache = { expression: null, mutexQueue: [] };
4343
jsonatas[transformUrl] = jsonataCache;
4444
const transform = await jsonCache.loadAsync(transformUrl, false);
4545
node.debug('Build JSONata expression for: ' + transformUrl);
4646
jsonataExpression = jsonata(transform);
4747
jsonataCache.expression = jsonataExpression;
4848

49-
//Resume tasks waiting for the same JSONata expression
49+
// Resume tasks waiting for the same JSONata expression
5050
let next;
5151
while ((next = jsonataCache.mutexQueue.shift()) != undefined) {
52-
next(); //Resolve promise
52+
next(); // Resolve promise
5353
}
5454
}
5555

5656
if (jsonataExpression) {
57-
//Perform transformation
57+
// Perform transformation
5858
return jsonataExpression.evaluate(payload);
5959
}
6060

@@ -77,12 +77,12 @@ module.exports = RED => {
7777
msg.error += util.format('Failed tranforming using "%s"', msg.schemaUrl);
7878
}
7979
if (lastStatusError) {
80-
node.status({ fill:'green', shape:'dot', text:'OK', });
80+
node.status({ fill: 'green', shape: 'dot', text: 'OK' });
8181
lastStatusError = false;
8282
}
8383
} catch (ex) {
8484
lastStatusError = true;
85-
node.status({ fill:'red', shape:'ring', text:'Error', });
85+
node.status({ fill: 'red', shape: 'ring', text: 'Error' });
8686
console.error('Schema2 ' + msg.schemaUrl);
8787
msg.error += util.format('Error tranforming using "%s": %s', msg.schemaUrl, ex);
8888
}

json-multi-schema-validator.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script>
2+
/* global RED:false */
23
RED.nodes.registerType('json-multi-schema-validator', {
34
category: 'function',
45
color: '#00B4FF',
56
defaults: {
6-
name: { value: '', },
7+
name: { value: '' },
78
},
89
inputs: 1,
910
outputs: 1,

0 commit comments

Comments
 (0)