@node-red/runtime 4.0.8 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,7 +96,11 @@ var api = module.exports = {
96
96
  } else if (scope === 'node') {
97
97
  var node = runtime.nodes.getNode(id);
98
98
  if (node) {
99
- ctx = node.context();
99
+ if (/^subflow:/.test(node.type)) {
100
+ ctx = runtime.nodes.getContext(node.id);
101
+ } else {
102
+ ctx = node.context();
103
+ }
100
104
  }
101
105
  }
102
106
  if (ctx) {
@@ -104,13 +108,25 @@ var api = module.exports = {
104
108
  store = store || availableStores.default;
105
109
  ctx.get(key,store,function(err, v) {
106
110
  if (opts.keysOnly) {
111
+ const result = {}
107
112
  if (Array.isArray(v)) {
108
- resolve({ [store]: { format: `array[${v.length}]`}})
113
+ result.format = `array[${v.length}]`
109
114
  } else if (typeof v === 'object') {
110
- resolve({ [store]: { keys: Object.keys(v), format: 'Object' } })
115
+ result.keys = Object.keys(v).map(k => {
116
+ if (Array.isArray(v[k])) {
117
+ return { key: k, format: `array[${v[k].length}]`, length: v[k].length }
118
+ } else if (typeof v[k] === 'object') {
119
+ return { key: k, format: 'object' }
120
+ } else {
121
+ return { key: k }
122
+ }
123
+ })
124
+ result.format = 'object'
111
125
  } else {
112
- resolve({ [store]: { keys: [] }})
126
+ result.keys = []
113
127
  }
128
+ resolve({ [store]: result })
129
+ return
114
130
  }
115
131
  var encoded = util.encodeObject({msg:v});
116
132
  if (store !== availableStores.default) {
@@ -147,7 +163,7 @@ var api = module.exports = {
147
163
  }
148
164
  return
149
165
  }
150
- result[store] = { keys }
166
+ result[store] = { keys: keys.map(key => { return { key }}) }
151
167
  c--;
152
168
  if (c === 0) {
153
169
  if (!errorReported) {
package/lib/flows/Flow.js CHANGED
@@ -719,6 +719,14 @@ class Flow {
719
719
  });
720
720
  }
721
721
 
722
+ getContext(scope) {
723
+ if (scope === 'flow') {
724
+ return this.context
725
+ } else if (scope === 'global') {
726
+ return context.get('global')
727
+ }
728
+ }
729
+
722
730
  dump() {
723
731
  console.log("==================")
724
732
  console.log(this.TYPE, this.id);
@@ -49,6 +49,14 @@ class Group {
49
49
  }
50
50
  return this.parent.getSetting(key);
51
51
  }
52
+
53
+ error(msg) {
54
+ this.parent.error(msg);
55
+ }
56
+
57
+ getContext(scope) {
58
+ return this.parent.getContext(scope);
59
+ }
52
60
  }
53
61
 
54
62
  module.exports = {
package/lib/flows/util.js CHANGED
@@ -100,7 +100,24 @@ async function evaluateEnvProperties(flow, env, credentials) {
100
100
  }
101
101
  } else if (type ==='jsonata') {
102
102
  pendingEvaluations.push(new Promise((resolve, _) => {
103
- redUtil.evaluateNodeProperty(value, 'jsonata', {_flow: flow}, null, (err, result) => {
103
+ redUtil.evaluateNodeProperty(value, 'jsonata',{
104
+ // Fake a node object to provide access to _flow and context
105
+ _flow: flow,
106
+ context: () => {
107
+ return {
108
+ flow: {
109
+ get: (value, store, callback) => {
110
+ return flow.getContext('flow').get(value, store, callback)
111
+ }
112
+ },
113
+ global: {
114
+ get: (value, store, callback) => {
115
+ return flow.getContext('global').get(value, store, callback)
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }, null, (err, result) => {
104
121
  if (!err) {
105
122
  if (typeof result === 'object') {
106
123
  result = { value: result, __clone__: true}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/runtime",
3
- "version": "4.0.8",
3
+ "version": "4.0.9",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,8 +16,8 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/registry": "4.0.8",
20
- "@node-red/util": "4.0.8",
19
+ "@node-red/registry": "4.0.9",
20
+ "@node-red/util": "4.0.9",
21
21
  "async-mutex": "0.5.0",
22
22
  "clone": "2.1.2",
23
23
  "express": "4.21.2",