noflo 1.4.2 → 1.5.0

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 (89) hide show
  1. package/.ecrc +3 -0
  2. package/.eslintignore +2 -0
  3. package/{CHANGES.md → CHANGELOG.md} +520 -523
  4. package/README.md +1 -1
  5. package/bin/noflo-cache-preheat +17 -15
  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 +81 -10
  25. package/lib/InPort.js +83 -19
  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 +13 -13
  33. package/lib/NoFlo.js +29 -27
  34. package/lib/OutPort.d.ts +74 -32
  35. package/lib/OutPort.js +79 -23
  36. package/lib/Platform.d.ts +1 -1
  37. package/lib/Platform.js +9 -4
  38. package/lib/Ports.d.ts +14 -21
  39. package/lib/Ports.js +11 -13
  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 +104 -105
  46. package/lib/loader/register.d.ts +1 -1
  47. package/lib/loader/register.js +8 -4
  48. package/package.json +16 -11
  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 +2 -38
  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 +1 -1
  66. package/spec/fixtures/componentloader/spec/Repeat.yaml +1 -1
  67. package/src/.eslintrc +9 -2
  68. package/src/components/Graph.js +105 -71
  69. package/src/lib/AsCallback.js +71 -16
  70. package/src/lib/AsComponent.js +4 -3
  71. package/src/lib/BaseNetwork.js +48 -15
  72. package/src/lib/BasePort.js +43 -9
  73. package/src/lib/Component.js +8 -8
  74. package/src/lib/ComponentLoader.js +3 -4
  75. package/src/lib/IP.js +7 -4
  76. package/src/lib/InPort.js +86 -21
  77. package/src/lib/InternalSocket.js +49 -9
  78. package/src/lib/LegacyNetwork.js +2 -2
  79. package/src/lib/Network.js +2 -2
  80. package/src/lib/NoFlo.js +15 -13
  81. package/src/lib/OutPort.js +83 -22
  82. package/src/lib/Platform.js +9 -4
  83. package/src/lib/Ports.js +9 -11
  84. package/src/lib/ProcessInput.js +7 -9
  85. package/src/lib/ProcessOutput.js +1 -1
  86. package/src/lib/loader/NodeJs.js +122 -116
  87. package/src/lib/loader/register.js +2 -2
  88. /package/{karma.config.js → karma.config.cjs} +0 -0
  89. /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,42 @@ 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; } });
86
88
  // ### Component baseclasses
87
89
  //
88
90
  // 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; } });
91
+ var Component_js_1 = require("./Component.js");
92
+ Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return Component_js_1.Component; } });
91
93
  // ### NoFlo ports
92
94
  //
93
95
  // 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; } });
96
+ var Ports_js_1 = require("./Ports.js");
97
+ Object.defineProperty(exports, "InPorts", { enumerable: true, get: function () { return Ports_js_1.InPorts; } });
98
+ Object.defineProperty(exports, "OutPorts", { enumerable: true, get: function () { return Ports_js_1.OutPorts; } });
99
+ var InPort_js_1 = require("./InPort.js");
100
+ Object.defineProperty(exports, "InPort", { enumerable: true, get: function () { return InPort_js_1.default; } });
101
+ var OutPort_js_1 = require("./OutPort.js");
102
+ Object.defineProperty(exports, "OutPort", { enumerable: true, get: function () { return OutPort_js_1.default; } });
101
103
  // ### NoFlo sockets
102
104
  //
103
105
  // The NoFlo [internalSocket](InternalSocket.html) is used for connecting ports of
104
106
  // different components together in a network.
105
- const internalSocket = require("./InternalSocket");
107
+ const internalSocket = require("./InternalSocket.js");
106
108
  exports.internalSocket = internalSocket;
107
109
  // ### Information Packets
108
110
  //
109
111
  // 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; } });
112
+ var IP_js_1 = require("./IP.js");
113
+ Object.defineProperty(exports, "IP", { enumerable: true, get: function () { return IP_js_1.default; } });
112
114
  /**
113
115
  * @callback NetworkCallback
114
116
  * @param {Error | null} err
@@ -137,7 +139,7 @@ function createNetwork(graphInstance, options, callback) {
137
139
  }
138
140
  // Choose legacy or modern network based on whether graph
139
141
  // subscription is needed
140
- const NetworkType = options.subscribeGraph ? LegacyNetwork_1.LegacyNetwork : Network_1.Network;
142
+ const NetworkType = options.subscribeGraph ? LegacyNetwork_js_1.LegacyNetwork : Network_js_1.Network;
141
143
  const network = new NetworkType(graphInstance, options);
142
144
  // Ensure components are loaded before continuing
143
145
  const promise = network.loader.listComponents()
@@ -150,7 +152,7 @@ function createNetwork(graphInstance, options, callback) {
150
152
  return connected.then(() => network.start());
151
153
  });
152
154
  if (callback) {
153
- Platform_1.deprecated('Providing a callback to NoFlo.createNetwork is deprecated, use Promises');
155
+ (0, Platform_js_1.deprecated)('Providing a callback to NoFlo.createNetwork is deprecated, use Promises');
154
156
  promise.then((nw) => {
155
157
  callback(null, nw);
156
158
  }, callback);
@@ -177,7 +179,7 @@ function loadFile(file, options, callback) {
177
179
  const promise = fbp_graph_1.graph.loadFile(file)
178
180
  .then((graphInstance) => createNetwork(graphInstance, options));
179
181
  if (callback) {
180
- Platform_1.deprecated('Providing a callback to NoFlo.loadFile is deprecated, use Promises');
182
+ (0, Platform_js_1.deprecated)('Providing a callback to NoFlo.loadFile is deprecated, use Promises');
181
183
  promise.then((network) => {
182
184
  callback(null, network);
183
185
  }, callback);
@@ -213,9 +215,9 @@ exports.saveFile = saveFile;
213
215
  // // Do something with results
214
216
  // });
215
217
  //
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; } });
218
+ var AsCallback_js_1 = require("./AsCallback.js");
219
+ Object.defineProperty(exports, "asCallback", { enumerable: true, get: function () { return AsCallback_js_1.asCallback; } });
220
+ Object.defineProperty(exports, "asPromise", { enumerable: true, get: function () { return AsCallback_js_1.asPromise; } });
219
221
  // ## Generating components from JavaScript functions
220
222
  //
221
223
  // The `asComponent` helper makes it easy to expose a JavaScript function as a
@@ -228,5 +230,5 @@ Object.defineProperty(exports, "asPromise", { enumerable: true, get: function ()
228
230
  // });
229
231
  // };
230
232
  //
231
- var AsComponent_1 = require("./AsComponent");
232
- Object.defineProperty(exports, "asComponent", { enumerable: true, get: function () { return AsComponent_1.asComponent; } });
233
+ var AsComponent_js_1 = require("./AsComponent.js");
234
+ Object.defineProperty(exports, "asComponent", { enumerable: true, get: function () { return AsComponent_js_1.asComponent; } });
package/lib/OutPort.d.ts CHANGED
@@ -1,40 +1,82 @@
1
1
  /**
2
- * @typedef {Object} OutportOptions - Options for configuring outports
3
- * @property {string} [description='']
4
- * @property {string} [datatype='all']
5
- * @property {string} [schema=null]
6
- * @property {boolean} [required=false]
7
- * @property {boolean} [caching=false]
8
- * @property {boolean} [scoped=true]
2
+ * @typedef OutPortOptions
3
+ * @property {boolean} [caching]
4
+ */
5
+ /**
6
+ * @typedef {import("./BasePort").BaseOptions & OutPortOptions} PortOptions
9
7
  */
10
8
  export default class OutPort extends BasePort {
11
9
  /**
12
- * @param {OutportOptions} options - Options for the outport
13
- */
14
- constructor(options?: OutportOptions);
15
- cache: {};
16
- connect(index?: any): void;
17
- beginGroup(group: any, index?: any): void;
18
- send(data: any, index?: any): void;
19
- endGroup(index?: any): void;
20
- disconnect(index?: any): void;
21
- sendIP(type: any, data: any, options: any, index: any, autoConnect?: boolean): OutPort;
22
- openBracket(data?: any, options?: {}, index?: any): OutPort;
23
- data(data: any, options?: {}, index?: any): OutPort;
24
- closeBracket(data?: any, options?: {}, index?: any): OutPort;
25
- checkRequired(sockets: any): void;
26
- getSockets(index: any): import("./InternalSocket").InternalSocket[];
10
+ * @param {PortOptions} options - Options for the outport
11
+ */
12
+ constructor(options?: PortOptions);
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>;
27
75
  isCaching(): boolean;
28
76
  }
29
- /**
30
- * - Options for configuring outports
31
- */
32
- export type OutportOptions = {
33
- description?: string;
34
- datatype?: string;
35
- schema?: string;
36
- required?: boolean;
77
+ export type OutPortOptions = {
37
78
  caching?: boolean;
38
- scoped?: boolean;
39
79
  };
40
- import BasePort from "./BasePort";
80
+ export type PortOptions = import("./BasePort").BaseOptions & OutPortOptions;
81
+ import BasePort from "./BasePort.js";
82
+ import IP from "./IP.js";
package/lib/OutPort.js CHANGED
@@ -3,24 +3,22 @@ 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.
11
11
  // These ports are the way a component sends Information Packets.
12
12
  /**
13
- * @typedef {Object} OutportOptions - Options for configuring outports
14
- * @property {string} [description='']
15
- * @property {string} [datatype='all']
16
- * @property {string} [schema=null]
17
- * @property {boolean} [required=false]
18
- * @property {boolean} [caching=false]
19
- * @property {boolean} [scoped=true]
13
+ * @typedef OutPortOptions
14
+ * @property {boolean} [caching]
20
15
  */
21
- class OutPort extends BasePort_1.default {
16
+ /**
17
+ * @typedef {import("./BasePort").BaseOptions & OutPortOptions} PortOptions
18
+ */
19
+ class OutPort extends BasePort_js_1.default {
22
20
  /**
23
- * @param {OutportOptions} options - Options for the outport
21
+ * @param {PortOptions} options - Options for the outport
24
22
  */
25
23
  constructor(options = {}) {
26
24
  const opts = options;
@@ -31,14 +29,24 @@ class OutPort extends BasePort_1.default {
31
29
  opts.caching = false;
32
30
  }
33
31
  super(opts);
32
+ const baseOptions = this.options;
33
+ this.options = /** @type {PortOptions} */ (baseOptions);
34
+ /** @type {Object<string, IP>} */
34
35
  this.cache = {};
35
36
  }
37
+ /**
38
+ * @param {import("./InternalSocket").InternalSocket} socket
39
+ * @param {number|null} [index]
40
+ */
36
41
  attach(socket, index = null) {
37
42
  super.attach(socket, index);
38
- if (this.isCaching() && (this.cache[index] != null)) {
39
- this.send(this.cache[index], index);
43
+ if (this.isCaching() && (this.cache[`${index}`] != null)) {
44
+ this.send(this.cache[`${index}`], index);
40
45
  }
41
46
  }
47
+ /**
48
+ * @param {number|null} [index]
49
+ */
42
50
  connect(index = null) {
43
51
  const sockets = this.getSockets(index);
44
52
  this.checkRequired(sockets);
@@ -49,6 +57,10 @@ class OutPort extends BasePort_1.default {
49
57
  socket.connect();
50
58
  });
51
59
  }
60
+ /**
61
+ * @param {string} group
62
+ * @param {number|null} [index]
63
+ */
52
64
  beginGroup(group, index = null) {
53
65
  const sockets = this.getSockets(index);
54
66
  this.checkRequired(sockets);
@@ -59,11 +71,15 @@ class OutPort extends BasePort_1.default {
59
71
  socket.beginGroup(group);
60
72
  });
61
73
  }
74
+ /**
75
+ * @param {any} data
76
+ * @param {number|null} [index]
77
+ */
62
78
  send(data, index = null) {
63
79
  const sockets = this.getSockets(index);
64
80
  this.checkRequired(sockets);
65
- if (this.isCaching() && (data !== this.cache[index])) {
66
- this.cache[index] = data;
81
+ if (this.isCaching() && (data !== this.cache[`${index}`])) {
82
+ this.cache[`${index}`] = data;
67
83
  }
68
84
  sockets.forEach((socket) => {
69
85
  if (!socket) {
@@ -72,6 +88,9 @@ class OutPort extends BasePort_1.default {
72
88
  socket.send(data);
73
89
  });
74
90
  }
91
+ /**
92
+ * @param {number|null} [index]
93
+ */
75
94
  endGroup(index = null) {
76
95
  const sockets = this.getSockets(index);
77
96
  this.checkRequired(sockets);
@@ -82,6 +101,9 @@ class OutPort extends BasePort_1.default {
82
101
  socket.endGroup();
83
102
  });
84
103
  }
104
+ /**
105
+ * @param {number|null} [index]
106
+ */
85
107
  disconnect(index = null) {
86
108
  const sockets = this.getSockets(index);
87
109
  this.checkRequired(sockets);
@@ -92,15 +114,26 @@ class OutPort extends BasePort_1.default {
92
114
  socket.disconnect();
93
115
  });
94
116
  }
95
- 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} */
96
126
  let ip;
97
127
  let idx = index;
98
- if (IP_1.default.isIP(type)) {
99
- ip = type;
128
+ if (IP_js_1.default.isIP(type)) {
129
+ ip = /** @type {IP} */ (type);
100
130
  idx = ip.index;
101
131
  }
132
+ else if (typeof type === 'string') {
133
+ ip = new IP_js_1.default(type, data, options);
134
+ }
102
135
  else {
103
- ip = new IP_1.default(type, data, options);
136
+ throw new Error('Unknown type for IP type');
104
137
  }
105
138
  const sockets = this.getSockets(idx);
106
139
  this.checkRequired(sockets);
@@ -112,9 +145,9 @@ class OutPort extends BasePort_1.default {
112
145
  // Stamp non-specific IP objects with port schema
113
146
  ip.schema = this.getSchema();
114
147
  }
115
- const cachedData = this.cache[idx] != null ? this.cache[idx].data : undefined;
148
+ const cachedData = this.cache[`${idx}`] != null ? this.cache[`${idx}`].data : undefined;
116
149
  if (this.isCaching() && data !== cachedData) {
117
- this.cache[idx] = ip;
150
+ this.cache[`${idx}`] = ip;
118
151
  }
119
152
  let pristine = true;
120
153
  sockets.forEach((socket) => {
@@ -134,30 +167,53 @@ class OutPort extends BasePort_1.default {
134
167
  });
135
168
  return this;
136
169
  }
170
+ /**
171
+ * @param {string|null} data
172
+ * @param {import("./IP").IPOptions} options
173
+ * @param {number|null} [index]
174
+ */
137
175
  openBracket(data = null, options = {}, index = null) {
138
176
  return this.sendIP('openBracket', data, options, index);
139
177
  }
178
+ /**
179
+ * @param {any} data
180
+ * @param {import("./IP").IPOptions} options
181
+ * @param {number|null} [index]
182
+ */
140
183
  data(data, options = {}, index = null) {
141
184
  return this.sendIP('data', data, options, index);
142
185
  }
186
+ /**
187
+ * @param {string|null} data
188
+ * @param {import("./IP").IPOptions} options
189
+ * @param {number|null} [index]
190
+ */
143
191
  closeBracket(data = null, options = {}, index = null) {
144
192
  return this.sendIP('closeBracket', data, options, index);
145
193
  }
194
+ /**
195
+ * @param {Array<import("./InternalSocket").InternalSocket|void>} sockets
196
+ */
146
197
  checkRequired(sockets) {
147
198
  if ((sockets.length === 0) && this.isRequired()) {
148
199
  throw new Error(`${this.getId()}: No connections available`);
149
200
  }
150
201
  }
202
+ /**
203
+ * @param {number|null} index
204
+ * @returns {Array<import("./InternalSocket").InternalSocket|void>}
205
+ */
151
206
  getSockets(index) {
152
207
  // Addressable sockets affect only one connection at time
153
208
  if (this.isAddressable()) {
154
209
  if (index === null) {
155
210
  throw new Error(`${this.getId()} Socket ID required`);
156
211
  }
157
- if (!this.sockets[index]) {
212
+ const idx = /** @type {number} */ (index);
213
+ if (!this.sockets[idx]) {
158
214
  return [];
159
215
  }
160
- return [this.sockets[index]];
216
+ return [this.sockets[idx]];
161
217
  }
162
218
  // Regular sockets affect all outbound connections
163
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
@@ -7,50 +7,43 @@ export function normalizePortName(name: string): {
7
7
  index?: string;
8
8
  };
9
9
  /**
10
- * @typedef {{ [key: string]: InPort|PortOptions }} InPortsOptions
10
+ * @typedef {{ [key: string]: InPort|import("./InPort").PortOptions }} InPortsOptions
11
11
  */
12
12
  export class InPorts extends Ports {
13
13
  /**
14
14
  * @param {InPortsOptions} [ports]
15
15
  */
16
16
  constructor(ports?: InPortsOptions);
17
+ ports: {
18
+ [x: string]: InPort;
19
+ };
17
20
  }
18
21
  /**
19
- * @typedef {{ [key: string]: OutPort|PortOptions }} OutPortsOptions
22
+ * @typedef {{ [key: string]: OutPort|import("./OutPort").PortOptions }} OutPortsOptions
20
23
  */
21
24
  export class OutPorts extends Ports {
22
25
  /**
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]: InPort | PortOptions;
40
+ [key: string]: import("./InPort.js").PortOptions | InPort;
42
41
  };
43
42
  export type OutPortsOptions = {
44
- [key: string]: OutPort | PortOptions;
43
+ [key: string]: import("./OutPort.js").PortOptions | OutPort;
45
44
  };
46
45
  /**
47
- * @typedef PortOptions
48
- * @property {string} [description='']
49
- * @property {string} [datatype='all']
50
- * @property {string} [schema=null]
51
- * @property {string} [type=null]
52
- * @property {boolean} [required=false]
53
- * @property {boolean} [scoped=true]
46
+ * @typedef {import("./BasePort").BaseOptions} PortOptions
54
47
  */
55
48
  declare class Ports extends EventEmitter {
56
49
  /**
@@ -75,7 +68,7 @@ declare class Ports extends EventEmitter {
75
68
  */
76
69
  remove(name: string): Ports;
77
70
  }
78
- import InPort from "./InPort";
79
- import OutPort from "./OutPort";
71
+ import InPort from "./InPort.js";
72
+ import OutPort from "./OutPort.js";
80
73
  import { EventEmitter } from "events";
81
74
  export {};
package/lib/Ports.js CHANGED
@@ -6,16 +6,10 @@ 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
- * @typedef PortOptions
13
- * @property {string} [description='']
14
- * @property {string} [datatype='all']
15
- * @property {string} [schema=null]
16
- * @property {string} [type=null]
17
- * @property {boolean} [required=false]
18
- * @property {boolean} [scoped=true]
12
+ * @typedef {import("./BasePort").BaseOptions} PortOptions
19
13
  */
20
14
  // NoFlo ports collections
21
15
  //
@@ -81,26 +75,30 @@ class Ports extends events_1.EventEmitter {
81
75
  }
82
76
  }
83
77
  /**
84
- * @typedef {{ [key: string]: InPort|PortOptions }} InPortsOptions
78
+ * @typedef {{ [key: string]: InPort|import("./InPort").PortOptions }} InPortsOptions
85
79
  */
86
80
  class InPorts extends Ports {
87
81
  /**
88
82
  * @param {InPortsOptions} [ports]
89
83
  */
90
84
  constructor(ports = {}) {
91
- 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);
92
88
  }
93
89
  }
94
90
  exports.InPorts = InPorts;
95
91
  /**
96
- * @typedef {{ [key: string]: OutPort|PortOptions }} OutPortsOptions
92
+ * @typedef {{ [key: string]: OutPort|import("./OutPort").PortOptions }} OutPortsOptions
97
93
  */
98
94
  class OutPorts extends Ports {
99
95
  /**
100
96
  * @param {OutPortsOptions} [ports]
101
97
  */
102
98
  constructor(ports = {}) {
103
- 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);
104
102
  }
105
103
  connect(name, socketId) {
106
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";