noflo 1.4.3 → 1.5.1

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.
Files changed (90) hide show
  1. package/.ecrc +3 -0
  2. package/.eslintignore +2 -0
  3. package/{CHANGES.md → CHANGELOG.md} +527 -527
  4. package/README.md +1 -1
  5. package/bin/noflo-cache-preheat +4 -4
  6. package/components/Graph.d.ts +50 -15
  7. package/components/Graph.js +94 -68
  8. package/examples/http/HelloController.js +9 -6
  9. package/examples/spreadsheet/parse.fbp +3 -3
  10. package/lib/AsCallback.d.ts +22 -9
  11. package/lib/AsCallback.js +69 -18
  12. package/lib/AsComponent.d.ts +1 -1
  13. package/lib/AsComponent.js +5 -3
  14. package/lib/BaseNetwork.d.ts +16 -6
  15. package/lib/BaseNetwork.js +65 -31
  16. package/lib/BasePort.d.ts +39 -12
  17. package/lib/BasePort.js +34 -6
  18. package/lib/Component.d.ts +8 -8
  19. package/lib/Component.js +23 -20
  20. package/lib/ComponentLoader.d.ts +3 -4
  21. package/lib/ComponentLoader.js +9 -10
  22. package/lib/IP.d.ts +12 -8
  23. package/lib/IP.js +6 -4
  24. package/lib/InPort.d.ts +64 -9
  25. package/lib/InPort.js +72 -13
  26. package/lib/InternalSocket.d.ts +53 -7
  27. package/lib/InternalSocket.js +51 -14
  28. package/lib/LegacyNetwork.d.ts +12 -2
  29. package/lib/LegacyNetwork.js +5 -5
  30. package/lib/Network.d.ts +13 -2
  31. package/lib/Network.js +10 -10
  32. package/lib/NoFlo.d.ts +48 -13
  33. package/lib/NoFlo.js +55 -27
  34. package/lib/OutPort.d.ts +64 -13
  35. package/lib/OutPort.js +73 -15
  36. package/lib/Platform.d.ts +1 -1
  37. package/lib/Platform.js +9 -4
  38. package/lib/Ports.d.ts +11 -12
  39. package/lib/Ports.js +8 -4
  40. package/lib/ProcessInput.d.ts +5 -9
  41. package/lib/ProcessInput.js +8 -9
  42. package/lib/ProcessOutput.d.ts +2 -2
  43. package/lib/ProcessOutput.js +5 -5
  44. package/lib/loader/NodeJs.d.ts +0 -1
  45. package/lib/loader/NodeJs.js +152 -161
  46. package/lib/loader/register.d.ts +1 -1
  47. package/lib/loader/register.js +8 -4
  48. package/package.json +25 -16
  49. package/spec/.eslintrc +5 -2
  50. package/spec/AsCallback.js +9 -13
  51. package/spec/AsComponent.js +10 -4
  52. package/spec/AsPromise.js +38 -0
  53. package/spec/CommonJS.cjs +10 -0
  54. package/spec/ComponentLoader.js +19 -7
  55. package/spec/ESModule.mjs +11 -0
  56. package/spec/Network.js +32 -11
  57. package/spec/NetworkSync.js +892 -0
  58. package/spec/Scoping.js +27 -42
  59. package/spec/Subgraph.js +6 -11
  60. package/spec/fixtures/componentloader/components/Output.js +1 -1
  61. package/spec/fixtures/componentloader/components/Repeat.ts +1 -1
  62. package/spec/fixtures/componentloader/components/RepeatAsync.coffee +1 -1
  63. package/spec/fixtures/componentloader/node_modules/example/components/Forward.js +1 -1
  64. package/spec/fixtures/componentloader/node_modules/example/package.json +1 -1
  65. package/spec/fixtures/componentloader/package.json +2 -1
  66. package/spec/fixtures/componentloader/spec/Repeat.yaml +1 -1
  67. package/spec/utils/inject.js +1 -1
  68. package/src/.eslintrc +9 -2
  69. package/src/components/Graph.js +105 -71
  70. package/src/lib/AsCallback.js +71 -16
  71. package/src/lib/AsComponent.js +5 -4
  72. package/src/lib/BaseNetwork.js +48 -15
  73. package/src/lib/BasePort.js +43 -9
  74. package/src/lib/Component.js +8 -8
  75. package/src/lib/ComponentLoader.js +3 -4
  76. package/src/lib/IP.js +7 -4
  77. package/src/lib/InPort.js +74 -13
  78. package/src/lib/InternalSocket.js +49 -9
  79. package/src/lib/LegacyNetwork.js +2 -2
  80. package/src/lib/Network.js +2 -2
  81. package/src/lib/NoFlo.js +43 -13
  82. package/src/lib/OutPort.js +77 -14
  83. package/src/lib/Platform.js +9 -4
  84. package/src/lib/Ports.js +6 -2
  85. package/src/lib/ProcessInput.js +7 -9
  86. package/src/lib/ProcessOutput.js +1 -1
  87. package/src/lib/loader/NodeJs.js +185 -178
  88. package/src/lib/loader/register.js +2 -2
  89. /package/{karma.config.js → karma.config.cjs} +0 -0
  90. /package/{webpack.config.js → webpack.config.cjs} +0 -0
package/lib/NoFlo.js CHANGED
@@ -52,6 +52,8 @@ const fbp_graph_1 = require("fbp-graph");
52
52
  // immediate execution
53
53
  // * `flowtrace`: (default: NULL) Flowtrace instance to create a retroactive debugging
54
54
  // trace of the network run.
55
+ // * `asyncDelivery`: (default: FALSE) Whether Information Packets should be
56
+ // delivered asynchronously.
55
57
  // * `subscribeGraph`: (default: FALSE) Whether the network should monitor the underlying
56
58
  // graph for changes
57
59
  //
@@ -61,9 +63,9 @@ const fbp_graph_1 = require("fbp-graph");
61
63
  //
62
64
  // The options object can also be used for setting ComponentLoader options in this
63
65
  // network.
64
- const Network_1 = require("./Network");
65
- const LegacyNetwork_1 = require("./LegacyNetwork");
66
- const Platform_1 = require("./Platform");
66
+ const Network_js_1 = require("./Network.js");
67
+ const LegacyNetwork_js_1 = require("./LegacyNetwork.js");
68
+ const Platform_js_1 = require("./Platform.js");
67
69
  var fbp_graph_2 = require("fbp-graph");
68
70
  Object.defineProperty(exports, "graph", { enumerable: true, get: function () { return fbp_graph_2.graph; } });
69
71
  Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return fbp_graph_2.Graph; } });
@@ -73,42 +75,48 @@ Object.defineProperty(exports, "Journal", { enumerable: true, get: function () {
73
75
  //
74
76
  // NoFlo works on both Node.js and the browser. Because some dependencies are different,
75
77
  // we need a way to detect which we're on.
76
- var Platform_2 = require("./Platform");
77
- Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return Platform_2.isBrowser; } });
78
+ var Platform_js_2 = require("./Platform.js");
79
+ Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return Platform_js_2.isBrowser; } });
78
80
  // ### Component Loader
79
81
  //
80
82
  // The [ComponentLoader](../ComponentLoader/) is responsible for finding and loading
81
83
  // NoFlo components. Component Loader uses [fbp-manifest](https://github.com/flowbased/fbp-manifest)
82
84
  // to find components and graphs by traversing the NPM dependency tree from a given root
83
85
  // directory on the file system.
84
- var ComponentLoader_1 = require("./ComponentLoader");
85
- Object.defineProperty(exports, "ComponentLoader", { enumerable: true, get: function () { return ComponentLoader_1.ComponentLoader; } });
86
+ var ComponentLoader_js_1 = require("./ComponentLoader.js");
87
+ Object.defineProperty(exports, "ComponentLoader", { enumerable: true, get: function () { return ComponentLoader_js_1.ComponentLoader; } });
88
+ const ComponentLoader_js_2 = require("./ComponentLoader.js");
86
89
  // ### Component baseclasses
87
90
  //
88
91
  // These baseclasses can be used for defining NoFlo components.
89
- var Component_1 = require("./Component");
90
- Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return Component_1.Component; } });
92
+ var Component_js_1 = require("./Component.js");
93
+ Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return Component_js_1.Component; } });
94
+ const Component_js_2 = require("./Component.js");
91
95
  // ### NoFlo ports
92
96
  //
93
97
  // These classes are used for instantiating ports on NoFlo components.
94
- var Ports_1 = require("./Ports");
95
- Object.defineProperty(exports, "InPorts", { enumerable: true, get: function () { return Ports_1.InPorts; } });
96
- Object.defineProperty(exports, "OutPorts", { enumerable: true, get: function () { return Ports_1.OutPorts; } });
97
- var InPort_1 = require("./InPort");
98
- Object.defineProperty(exports, "InPort", { enumerable: true, get: function () { return InPort_1.default; } });
99
- var OutPort_1 = require("./OutPort");
100
- Object.defineProperty(exports, "OutPort", { enumerable: true, get: function () { return OutPort_1.default; } });
98
+ var Ports_js_1 = require("./Ports.js");
99
+ Object.defineProperty(exports, "InPorts", { enumerable: true, get: function () { return Ports_js_1.InPorts; } });
100
+ Object.defineProperty(exports, "OutPorts", { enumerable: true, get: function () { return Ports_js_1.OutPorts; } });
101
+ const Ports_js_2 = require("./Ports.js");
102
+ var InPort_js_1 = require("./InPort.js");
103
+ Object.defineProperty(exports, "InPort", { enumerable: true, get: function () { return InPort_js_1.default; } });
104
+ const InPort_js_2 = require("./InPort.js");
105
+ var OutPort_js_1 = require("./OutPort.js");
106
+ Object.defineProperty(exports, "OutPort", { enumerable: true, get: function () { return OutPort_js_1.default; } });
107
+ const OutPort_js_2 = require("./OutPort.js");
101
108
  // ### NoFlo sockets
102
109
  //
103
110
  // The NoFlo [internalSocket](InternalSocket.html) is used for connecting ports of
104
111
  // different components together in a network.
105
- const internalSocket = require("./InternalSocket");
112
+ const internalSocket = require("./InternalSocket.js");
106
113
  exports.internalSocket = internalSocket;
107
114
  // ### Information Packets
108
115
  //
109
116
  // NoFlo Information Packets are defined as "IP" objects.
110
- var IP_1 = require("./IP");
111
- Object.defineProperty(exports, "IP", { enumerable: true, get: function () { return IP_1.default; } });
117
+ var IP_js_1 = require("./IP.js");
118
+ Object.defineProperty(exports, "IP", { enumerable: true, get: function () { return IP_js_1.default; } });
119
+ const IP_js_2 = require("./IP.js");
112
120
  /**
113
121
  * @callback NetworkCallback
114
122
  * @param {Error | null} err
@@ -137,7 +145,7 @@ function createNetwork(graphInstance, options, callback) {
137
145
  }
138
146
  // Choose legacy or modern network based on whether graph
139
147
  // subscription is needed
140
- const NetworkType = options.subscribeGraph ? LegacyNetwork_1.LegacyNetwork : Network_1.Network;
148
+ const NetworkType = options.subscribeGraph ? LegacyNetwork_js_1.LegacyNetwork : Network_js_1.Network;
141
149
  const network = new NetworkType(graphInstance, options);
142
150
  // Ensure components are loaded before continuing
143
151
  const promise = network.loader.listComponents()
@@ -150,7 +158,7 @@ function createNetwork(graphInstance, options, callback) {
150
158
  return connected.then(() => network.start());
151
159
  });
152
160
  if (callback) {
153
- Platform_1.deprecated('Providing a callback to NoFlo.createNetwork is deprecated, use Promises');
161
+ (0, Platform_js_1.deprecated)('Providing a callback to NoFlo.createNetwork is deprecated, use Promises');
154
162
  promise.then((nw) => {
155
163
  callback(null, nw);
156
164
  }, callback);
@@ -177,7 +185,7 @@ function loadFile(file, options, callback) {
177
185
  const promise = fbp_graph_1.graph.loadFile(file)
178
186
  .then((graphInstance) => createNetwork(graphInstance, options));
179
187
  if (callback) {
180
- Platform_1.deprecated('Providing a callback to NoFlo.loadFile is deprecated, use Promises');
188
+ (0, Platform_js_1.deprecated)('Providing a callback to NoFlo.loadFile is deprecated, use Promises');
181
189
  promise.then((network) => {
182
190
  callback(null, network);
183
191
  }, callback);
@@ -213,9 +221,10 @@ exports.saveFile = saveFile;
213
221
  // // Do something with results
214
222
  // });
215
223
  //
216
- var AsCallback_1 = require("./AsCallback");
217
- Object.defineProperty(exports, "asCallback", { enumerable: true, get: function () { return AsCallback_1.asCallback; } });
218
- Object.defineProperty(exports, "asPromise", { enumerable: true, get: function () { return AsCallback_1.asPromise; } });
224
+ var AsCallback_js_1 = require("./AsCallback.js");
225
+ Object.defineProperty(exports, "asCallback", { enumerable: true, get: function () { return AsCallback_js_1.asCallback; } });
226
+ Object.defineProperty(exports, "asPromise", { enumerable: true, get: function () { return AsCallback_js_1.asPromise; } });
227
+ const AsCallback_js_2 = require("./AsCallback.js");
219
228
  // ## Generating components from JavaScript functions
220
229
  //
221
230
  // The `asComponent` helper makes it easy to expose a JavaScript function as a
@@ -228,5 +237,24 @@ Object.defineProperty(exports, "asPromise", { enumerable: true, get: function ()
228
237
  // });
229
238
  // };
230
239
  //
231
- var AsComponent_1 = require("./AsComponent");
232
- Object.defineProperty(exports, "asComponent", { enumerable: true, get: function () { return AsComponent_1.asComponent; } });
240
+ var AsComponent_js_1 = require("./AsComponent.js");
241
+ Object.defineProperty(exports, "asComponent", { enumerable: true, get: function () { return AsComponent_js_1.asComponent; } });
242
+ const AsComponent_js_2 = require("./AsComponent.js");
243
+ exports.default = {
244
+ ...fbp_graph_1.graph,
245
+ isBrowser: Platform_js_1.isBrowser,
246
+ ComponentLoader: ComponentLoader_js_2.ComponentLoader,
247
+ Component: Component_js_2.Component,
248
+ InPorts: Ports_js_2.InPorts,
249
+ OutPorts: Ports_js_2.OutPorts,
250
+ InPort: InPort_js_2.default,
251
+ OutPort: OutPort_js_2.default,
252
+ internalSocket,
253
+ IP: IP_js_2.default,
254
+ createNetwork,
255
+ loadFile,
256
+ saveFile,
257
+ asCallback: AsCallback_js_2.asCallback,
258
+ asPromise: AsCallback_js_2.asPromise,
259
+ asComponent: AsComponent_js_2.asComponent,
260
+ };
package/lib/OutPort.d.ts CHANGED
@@ -10,22 +10,73 @@ export default class OutPort extends BasePort {
10
10
  * @param {PortOptions} options - Options for the outport
11
11
  */
12
12
  constructor(options?: PortOptions);
13
- cache: {};
14
- connect(index?: any): void;
15
- beginGroup(group: any, index?: any): void;
16
- send(data: any, index?: any): void;
17
- endGroup(index?: any): void;
18
- disconnect(index?: any): void;
19
- sendIP(type: any, data: any, options: any, index: any, autoConnect?: boolean): OutPort;
20
- openBracket(data?: any, options?: {}, index?: any): OutPort;
21
- data(data: any, options?: {}, index?: any): OutPort;
22
- closeBracket(data?: any, options?: {}, index?: any): OutPort;
23
- checkRequired(sockets: any): void;
24
- getSockets(index: any): import("./InternalSocket").InternalSocket[];
13
+ options: PortOptions;
14
+ /** @type {Object<string, IP>} */
15
+ cache: {
16
+ [x: string]: IP;
17
+ };
18
+ /**
19
+ * @param {number|null} [index]
20
+ */
21
+ connect(index?: number | null): void;
22
+ /**
23
+ * @param {string} group
24
+ * @param {number|null} [index]
25
+ */
26
+ beginGroup(group: string, index?: number | null): void;
27
+ /**
28
+ * @param {any} data
29
+ * @param {number|null} [index]
30
+ */
31
+ send(data: any, index?: number | null): void;
32
+ /**
33
+ * @param {number|null} [index]
34
+ */
35
+ endGroup(index?: number | null): void;
36
+ /**
37
+ * @param {number|null} [index]
38
+ */
39
+ disconnect(index?: number | null): void;
40
+ /**
41
+ * @param {string|IP} type
42
+ * @param {any} [data]
43
+ * @param {import("./IP").IPOptions} [options]
44
+ * @param {number|null} [index]
45
+ * @param {boolean} [autoConnect]
46
+ */
47
+ sendIP(type: string | IP, data?: any, options?: import("./IP").IPOptions, index?: number | null, autoConnect?: boolean): OutPort;
48
+ /**
49
+ * @param {string|null} data
50
+ * @param {import("./IP").IPOptions} options
51
+ * @param {number|null} [index]
52
+ */
53
+ openBracket(data?: string | null, options?: import("./IP").IPOptions, index?: number | null): OutPort;
54
+ /**
55
+ * @param {any} data
56
+ * @param {import("./IP").IPOptions} options
57
+ * @param {number|null} [index]
58
+ */
59
+ data(data: any, options?: import("./IP").IPOptions, index?: number | null): OutPort;
60
+ /**
61
+ * @param {string|null} data
62
+ * @param {import("./IP").IPOptions} options
63
+ * @param {number|null} [index]
64
+ */
65
+ closeBracket(data?: string | null, options?: import("./IP").IPOptions, index?: number | null): OutPort;
66
+ /**
67
+ * @param {Array<import("./InternalSocket").InternalSocket|void>} sockets
68
+ */
69
+ checkRequired(sockets: Array<import("./InternalSocket").InternalSocket | void>): void;
70
+ /**
71
+ * @param {number|null} index
72
+ * @returns {Array<import("./InternalSocket").InternalSocket|void>}
73
+ */
74
+ getSockets(index: number | null): Array<import("./InternalSocket").InternalSocket | void>;
25
75
  isCaching(): boolean;
26
76
  }
27
77
  export type OutPortOptions = {
28
78
  caching?: boolean;
29
79
  };
30
80
  export type PortOptions = import("./BasePort").BaseOptions & OutPortOptions;
31
- import BasePort from "./BasePort";
81
+ import BasePort from "./BasePort.js";
82
+ import IP from "./IP.js";
package/lib/OutPort.js CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // NoFlo - Flow-Based Programming for JavaScript
4
4
  // (c) 2014-2017 Flowhub UG
5
5
  // NoFlo may be freely distributed under the MIT license
6
- const BasePort_1 = require("./BasePort");
7
- const IP_1 = require("./IP");
6
+ const BasePort_js_1 = require("./BasePort.js");
7
+ const IP_js_1 = require("./IP.js");
8
8
  // ## NoFlo outport
9
9
  //
10
10
  // Outport Port (outport) implementation for NoFlo components.
@@ -16,7 +16,7 @@ const IP_1 = require("./IP");
16
16
  /**
17
17
  * @typedef {import("./BasePort").BaseOptions & OutPortOptions} PortOptions
18
18
  */
19
- class OutPort extends BasePort_1.default {
19
+ class OutPort extends BasePort_js_1.default {
20
20
  /**
21
21
  * @param {PortOptions} options - Options for the outport
22
22
  */
@@ -29,14 +29,24 @@ class OutPort extends BasePort_1.default {
29
29
  opts.caching = false;
30
30
  }
31
31
  super(opts);
32
+ const baseOptions = this.options;
33
+ this.options = /** @type {PortOptions} */ (baseOptions);
34
+ /** @type {Object<string, IP>} */
32
35
  this.cache = {};
33
36
  }
37
+ /**
38
+ * @param {import("./InternalSocket").InternalSocket} socket
39
+ * @param {number|null} [index]
40
+ */
34
41
  attach(socket, index = null) {
35
42
  super.attach(socket, index);
36
- if (this.isCaching() && (this.cache[index] != null)) {
37
- this.send(this.cache[index], index);
43
+ if (this.isCaching() && (this.cache[`${index}`] != null)) {
44
+ this.send(this.cache[`${index}`], index);
38
45
  }
39
46
  }
47
+ /**
48
+ * @param {number|null} [index]
49
+ */
40
50
  connect(index = null) {
41
51
  const sockets = this.getSockets(index);
42
52
  this.checkRequired(sockets);
@@ -47,6 +57,10 @@ class OutPort extends BasePort_1.default {
47
57
  socket.connect();
48
58
  });
49
59
  }
60
+ /**
61
+ * @param {string} group
62
+ * @param {number|null} [index]
63
+ */
50
64
  beginGroup(group, index = null) {
51
65
  const sockets = this.getSockets(index);
52
66
  this.checkRequired(sockets);
@@ -57,11 +71,15 @@ class OutPort extends BasePort_1.default {
57
71
  socket.beginGroup(group);
58
72
  });
59
73
  }
74
+ /**
75
+ * @param {any} data
76
+ * @param {number|null} [index]
77
+ */
60
78
  send(data, index = null) {
61
79
  const sockets = this.getSockets(index);
62
80
  this.checkRequired(sockets);
63
- if (this.isCaching() && (data !== this.cache[index])) {
64
- this.cache[index] = data;
81
+ if (this.isCaching() && (data !== this.cache[`${index}`])) {
82
+ this.cache[`${index}`] = data;
65
83
  }
66
84
  sockets.forEach((socket) => {
67
85
  if (!socket) {
@@ -70,6 +88,9 @@ class OutPort extends BasePort_1.default {
70
88
  socket.send(data);
71
89
  });
72
90
  }
91
+ /**
92
+ * @param {number|null} [index]
93
+ */
73
94
  endGroup(index = null) {
74
95
  const sockets = this.getSockets(index);
75
96
  this.checkRequired(sockets);
@@ -80,6 +101,9 @@ class OutPort extends BasePort_1.default {
80
101
  socket.endGroup();
81
102
  });
82
103
  }
104
+ /**
105
+ * @param {number|null} [index]
106
+ */
83
107
  disconnect(index = null) {
84
108
  const sockets = this.getSockets(index);
85
109
  this.checkRequired(sockets);
@@ -90,15 +114,26 @@ class OutPort extends BasePort_1.default {
90
114
  socket.disconnect();
91
115
  });
92
116
  }
93
- sendIP(type, data, options, index, autoConnect = true) {
117
+ /**
118
+ * @param {string|IP} type
119
+ * @param {any} [data]
120
+ * @param {import("./IP").IPOptions} [options]
121
+ * @param {number|null} [index]
122
+ * @param {boolean} [autoConnect]
123
+ */
124
+ sendIP(type, data, options, index = null, autoConnect = true) {
125
+ /** @type {IP} */
94
126
  let ip;
95
127
  let idx = index;
96
- if (IP_1.default.isIP(type)) {
97
- ip = type;
128
+ if (IP_js_1.default.isIP(type)) {
129
+ ip = /** @type {IP} */ (type);
98
130
  idx = ip.index;
99
131
  }
132
+ else if (typeof type === 'string') {
133
+ ip = new IP_js_1.default(type, data, options);
134
+ }
100
135
  else {
101
- ip = new IP_1.default(type, data, options);
136
+ throw new Error('Unknown type for IP type');
102
137
  }
103
138
  const sockets = this.getSockets(idx);
104
139
  this.checkRequired(sockets);
@@ -110,9 +145,9 @@ class OutPort extends BasePort_1.default {
110
145
  // Stamp non-specific IP objects with port schema
111
146
  ip.schema = this.getSchema();
112
147
  }
113
- const cachedData = this.cache[idx] != null ? this.cache[idx].data : undefined;
148
+ const cachedData = this.cache[`${idx}`] != null ? this.cache[`${idx}`].data : undefined;
114
149
  if (this.isCaching() && data !== cachedData) {
115
- this.cache[idx] = ip;
150
+ this.cache[`${idx}`] = ip;
116
151
  }
117
152
  let pristine = true;
118
153
  sockets.forEach((socket) => {
@@ -132,30 +167,53 @@ class OutPort extends BasePort_1.default {
132
167
  });
133
168
  return this;
134
169
  }
170
+ /**
171
+ * @param {string|null} data
172
+ * @param {import("./IP").IPOptions} options
173
+ * @param {number|null} [index]
174
+ */
135
175
  openBracket(data = null, options = {}, index = null) {
136
176
  return this.sendIP('openBracket', data, options, index);
137
177
  }
178
+ /**
179
+ * @param {any} data
180
+ * @param {import("./IP").IPOptions} options
181
+ * @param {number|null} [index]
182
+ */
138
183
  data(data, options = {}, index = null) {
139
184
  return this.sendIP('data', data, options, index);
140
185
  }
186
+ /**
187
+ * @param {string|null} data
188
+ * @param {import("./IP").IPOptions} options
189
+ * @param {number|null} [index]
190
+ */
141
191
  closeBracket(data = null, options = {}, index = null) {
142
192
  return this.sendIP('closeBracket', data, options, index);
143
193
  }
194
+ /**
195
+ * @param {Array<import("./InternalSocket").InternalSocket|void>} sockets
196
+ */
144
197
  checkRequired(sockets) {
145
198
  if ((sockets.length === 0) && this.isRequired()) {
146
199
  throw new Error(`${this.getId()}: No connections available`);
147
200
  }
148
201
  }
202
+ /**
203
+ * @param {number|null} index
204
+ * @returns {Array<import("./InternalSocket").InternalSocket|void>}
205
+ */
149
206
  getSockets(index) {
150
207
  // Addressable sockets affect only one connection at time
151
208
  if (this.isAddressable()) {
152
209
  if (index === null) {
153
210
  throw new Error(`${this.getId()} Socket ID required`);
154
211
  }
155
- if (!this.sockets[index]) {
212
+ const idx = /** @type {number} */ (index);
213
+ if (!this.sockets[idx]) {
156
214
  return [];
157
215
  }
158
- return [this.sockets[index]];
216
+ return [this.sockets[idx]];
159
217
  }
160
218
  // Regular sockets affect all outbound connections
161
219
  return this.sockets;
package/lib/Platform.d.ts CHANGED
@@ -11,4 +11,4 @@ export function deprecated(message: string): void;
11
11
  * @param {Function} func
12
12
  * @returns {void}
13
13
  */
14
- export function makeAsync(func: Function): void;
14
+ export function makeAsync(func: Function, sameLoop?: boolean): void;
package/lib/Platform.js CHANGED
@@ -42,13 +42,18 @@ exports.deprecated = deprecated;
42
42
  * @param {Function} func
43
43
  * @returns {void}
44
44
  */
45
- function makeAsync(func) {
45
+ function makeAsync(func, sameLoop = false) {
46
46
  if (isBrowser()) {
47
+ // FIXME: Browsers don't have setImmediate yet so can't do same loop
47
48
  setTimeout(func, 0);
48
49
  return;
49
50
  }
50
- setImmediate(() => {
51
- func();
52
- });
51
+ if (sameLoop) {
52
+ setImmediate(() => {
53
+ func();
54
+ });
55
+ return;
56
+ }
57
+ process.nextTick(func);
53
58
  }
54
59
  exports.makeAsync = makeAsync;
package/lib/Ports.d.ts CHANGED
@@ -14,6 +14,9 @@ export class InPorts extends Ports {
14
14
  * @param {InPortsOptions} [ports]
15
15
  */
16
16
  constructor(ports?: InPortsOptions);
17
+ ports: {
18
+ [x: string]: InPort;
19
+ };
17
20
  }
18
21
  /**
19
22
  * @typedef {{ [key: string]: OutPort|import("./OutPort").PortOptions }} OutPortsOptions
@@ -23,25 +26,21 @@ export class OutPorts extends Ports {
23
26
  * @param {OutPortsOptions} [ports]
24
27
  */
25
28
  constructor(ports?: OutPortsOptions);
29
+ ports: {
30
+ [x: string]: OutPort;
31
+ };
26
32
  connect(name: any, socketId: any): void;
27
33
  beginGroup(name: any, group: any, socketId: any): void;
28
34
  send(name: any, data: any, socketId: any): void;
29
35
  endGroup(name: any, socketId: any): void;
30
36
  disconnect(name: any, socketId: any): void;
31
37
  }
32
- export type PortOptions = {
33
- description?: string;
34
- datatype?: string;
35
- schema?: string;
36
- type?: string;
37
- required?: boolean;
38
- scoped?: boolean;
39
- };
38
+ export type PortOptions = import("./BasePort").BaseOptions;
40
39
  export type InPortsOptions = {
41
- [key: string]: import("./InPort").PortOptions | InPort;
40
+ [key: string]: import("./InPort.js").PortOptions | InPort;
42
41
  };
43
42
  export type OutPortsOptions = {
44
- [key: string]: import("./OutPort").PortOptions | OutPort;
43
+ [key: string]: import("./OutPort.js").PortOptions | OutPort;
45
44
  };
46
45
  /**
47
46
  * @typedef {import("./BasePort").BaseOptions} PortOptions
@@ -69,7 +68,7 @@ declare class Ports extends EventEmitter {
69
68
  */
70
69
  remove(name: string): Ports;
71
70
  }
72
- import InPort from "./InPort";
73
- import OutPort from "./OutPort";
71
+ import InPort from "./InPort.js";
72
+ import OutPort from "./OutPort.js";
74
73
  import { EventEmitter } from "events";
75
74
  export {};
package/lib/Ports.js CHANGED
@@ -6,8 +6,8 @@ exports.normalizePortName = exports.OutPorts = exports.InPorts = void 0;
6
6
  // (c) 2014-2017 Flowhub UG
7
7
  // NoFlo may be freely distributed under the MIT license
8
8
  const events_1 = require("events");
9
- const InPort_1 = require("./InPort");
10
- const OutPort_1 = require("./OutPort");
9
+ const InPort_js_1 = require("./InPort.js");
10
+ const OutPort_js_1 = require("./OutPort.js");
11
11
  /**
12
12
  * @typedef {import("./BasePort").BaseOptions} PortOptions
13
13
  */
@@ -82,7 +82,9 @@ class InPorts extends Ports {
82
82
  * @param {InPortsOptions} [ports]
83
83
  */
84
84
  constructor(ports = {}) {
85
- super(ports, InPort_1.default);
85
+ super(ports, InPort_js_1.default);
86
+ const basePorts = this.ports;
87
+ this.ports = /** @type {Object<string, InPort>} */ (basePorts);
86
88
  }
87
89
  }
88
90
  exports.InPorts = InPorts;
@@ -94,7 +96,9 @@ class OutPorts extends Ports {
94
96
  * @param {OutPortsOptions} [ports]
95
97
  */
96
98
  constructor(ports = {}) {
97
- super(ports, OutPort_1.default);
99
+ super(ports, OutPort_js_1.default);
100
+ const basePorts = this.ports;
101
+ this.ports = /** @type {Object<string, OutPort>} */ (basePorts);
98
102
  }
99
103
  connect(name, socketId) {
100
104
  const port = /** @type {OutPort} */ (this.ports[name]);
@@ -6,7 +6,7 @@ export default class ProcessInput {
6
6
  constructor(ports: import("./Ports").InPorts, context: import("./ProcessContext").default);
7
7
  ports: import("./Ports").InPorts;
8
8
  context: import("./ProcessContext").default;
9
- nodeInstance: import("./Component").Component;
9
+ nodeInstance: import("./Component.js").Component;
10
10
  ip: IP;
11
11
  port: import("./InPort").default;
12
12
  result: {
@@ -19,13 +19,9 @@ export default class ProcessInput {
19
19
  * @returns {Array<number> | Array<Array<number>>}
20
20
  */
21
21
  attached(...params: string[]): Array<number> | Array<Array<number>>;
22
- /**
23
- * @callback HasValidationCallback
24
- * @param {IP} ip
25
- * @returns {boolean}
26
- */
27
22
  /**
28
23
  * @typedef {string|Array<string|number>} GetArgument
24
+ * @typedef {import("./InPort").HasValidationCallback} HasValidationCallback
29
25
  */
30
26
  /**
31
27
  * @typedef {GetArgument|HasValidationCallback} HasArgument
@@ -33,7 +29,7 @@ export default class ProcessInput {
33
29
  /**
34
30
  * @param {...HasArgument} params
35
31
  */
36
- has(...params: (string | (string | number)[] | ((ip: IP) => boolean))[]): boolean;
32
+ has(...params: (import("./InPort").HasValidationCallback | (string | (string | number)[]))[]): boolean;
37
33
  /**
38
34
  * @param {...string} params - Port names to check for data packets
39
35
  * @returns {boolean}
@@ -43,7 +39,7 @@ export default class ProcessInput {
43
39
  * @param {...HasArgument} params - Port names to check for streams
44
40
  * @returns {boolean}
45
41
  */
46
- hasStream(...params: (string | (string | number)[] | ((ip: IP) => boolean))[]): boolean;
42
+ hasStream(...params: (import("./InPort").HasValidationCallback | (string | (string | number)[]))[]): boolean;
47
43
  /**
48
44
  * @param {...GetArgument} params
49
45
  * @returns {void|IP|Array<IP|void>}
@@ -67,4 +63,4 @@ export default class ProcessInput {
67
63
  */
68
64
  getStream(...params: (string | (string | number)[])[]): void | Array<IP> | Array<void | Array<IP>>;
69
65
  }
70
- import IP from "./IP";
66
+ import IP from "./IP.js";
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  // NoFlo may be freely distributed under the MIT license
7
7
  /* eslint-disable no-underscore-dangle */
8
8
  const debug_1 = require("debug");
9
- const debugComponent = debug_1.default('noflo:component');
9
+ const IP_js_1 = require("./IP.js"); // eslint-disable-line no-unused-vars
10
+ const debugComponent = (0, debug_1.default)('noflo:component');
10
11
  class ProcessInput {
11
12
  /**
12
13
  * @param {import("./Ports").InPorts} ports - Component inports
@@ -71,13 +72,9 @@ class ProcessInput {
71
72
  // Returns true if a port (or ports joined by logical AND) has a new IP
72
73
  // Passing a validation callback as a last argument allows more selective
73
74
  // checking of packets.
74
- /**
75
- * @callback HasValidationCallback
76
- * @param {IP} ip
77
- * @returns {boolean}
78
- */
79
75
  /**
80
76
  * @typedef {string|Array<string|number>} GetArgument
77
+ * @typedef {import("./InPort").HasValidationCallback} HasValidationCallback
81
78
  */
82
79
  /**
83
80
  * @typedef {GetArgument|HasValidationCallback} HasArgument
@@ -86,13 +83,14 @@ class ProcessInput {
86
83
  * @param {...HasArgument} params
87
84
  */
88
85
  has(...params) {
86
+ /** @type {HasValidationCallback} */
89
87
  let validate;
90
88
  let args = params.filter((p) => typeof p !== 'function');
91
89
  if (!args.length) {
92
90
  args = ['in'];
93
91
  }
94
92
  if (typeof params[params.length - 1] === 'function') {
95
- validate = params[params.length - 1];
93
+ validate = /** @type {HasValidationCallback} */ (params[params.length - 1]);
96
94
  }
97
95
  else {
98
96
  validate = () => true;
@@ -107,7 +105,8 @@ class ProcessInput {
107
105
  if (!portImpl.isAddressable()) {
108
106
  throw new Error(`Non-addressable ports, access must be with string ${port[0]}`);
109
107
  }
110
- if (!portImpl.has(this.scope, port[1], validate)) {
108
+ const portIdx = (typeof port[1] === 'string') ? parseInt(port[1], 10) : port[1];
109
+ if (!portImpl.has(this.scope, portIdx, validate)) {
111
110
  return false;
112
111
  }
113
112
  }
@@ -248,7 +247,7 @@ class ProcessInput {
248
247
  }
249
248
  else {
250
249
  const portImpl = /** @type {import("./InPort").default} */ (this.ports.ports[name]);
251
- ip = portImpl.get(this.scope, idx);
250
+ ip = portImpl.get(this.scope, idxName);
252
251
  res.push(ip);
253
252
  }
254
253
  }