5
5
* JSONata expressions are cached in memory.
6
6
*/
7
7
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.
9
9
const jsonata = require ( 'jsonata' ) ;
10
10
const util = require ( 'util' ) ;
11
11
12
12
module . exports = RED => {
13
- " use strict" ;
13
+ ' use strict' ;
14
14
15
15
function JsonMultiSchemaTransformerNode ( config ) {
16
16
RED . nodes . createNode ( this , config ) ;
17
17
const node = this ;
18
18
const defaultSchemaUrl = config . defaultSchemaUrl ;
19
19
20
20
let lastStatusError = true ;
21
- node . status ( { fill :'grey' , shape :'ring' , text :'Uninitialized' , } ) ;
21
+ node . status ( { fill : 'grey' , shape : 'ring' , text : 'Uninitialized' } ) ;
22
22
23
23
const jsonCache = require ( './json-cache.js' ) ( node ) ;
24
24
25
- //Cache of JSONata expressions
25
+ // Cache of JSONata expressions
26
26
const jsonatas = { } ;
27
27
28
28
/**
@@ -33,28 +33,28 @@ module.exports = RED => {
33
33
let jsonataCache = jsonatas [ transformUrl ] ;
34
34
if ( jsonataCache ) {
35
35
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
37
37
await new Promise ( ( resolve , reject ) => jsonataCache . mutexQueue . push ( resolve ) ) ;
38
38
}
39
39
jsonataExpression = jsonataCache . expression ;
40
40
} else {
41
- //Build JSONata expression for the given transformation URL
41
+ // Build JSONata expression for the given transformation URL
42
42
jsonataCache = { expression : null , mutexQueue : [ ] } ;
43
43
jsonatas [ transformUrl ] = jsonataCache ;
44
44
const transform = await jsonCache . loadAsync ( transformUrl , false ) ;
45
45
node . debug ( 'Build JSONata expression for: ' + transformUrl ) ;
46
46
jsonataExpression = jsonata ( transform ) ;
47
47
jsonataCache . expression = jsonataExpression ;
48
48
49
- //Resume tasks waiting for the same JSONata expression
49
+ // Resume tasks waiting for the same JSONata expression
50
50
let next ;
51
51
while ( ( next = jsonataCache . mutexQueue . shift ( ) ) != undefined ) {
52
- next ( ) ; //Resolve promise
52
+ next ( ) ; // Resolve promise
53
53
}
54
54
}
55
55
56
56
if ( jsonataExpression ) {
57
- //Perform transformation
57
+ // Perform transformation
58
58
return jsonataExpression . evaluate ( payload ) ;
59
59
}
60
60
@@ -77,12 +77,12 @@ module.exports = RED => {
77
77
msg . error += util . format ( 'Failed tranforming using "%s"' , msg . schemaUrl ) ;
78
78
}
79
79
if ( lastStatusError ) {
80
- node . status ( { fill :'green' , shape :'dot' , text :'OK' , } ) ;
80
+ node . status ( { fill : 'green' , shape : 'dot' , text : 'OK' } ) ;
81
81
lastStatusError = false ;
82
82
}
83
83
} catch ( ex ) {
84
84
lastStatusError = true ;
85
- node . status ( { fill :'red' , shape :'ring' , text :'Error' , } ) ;
85
+ node . status ( { fill : 'red' , shape : 'ring' , text : 'Error' } ) ;
86
86
console . error ( 'Schema2 ' + msg . schemaUrl ) ;
87
87
msg . error += util . format ( 'Error tranforming using "%s": %s' , msg . schemaUrl , ex ) ;
88
88
}
0 commit comments