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/AsCallback.js CHANGED
@@ -9,10 +9,10 @@ exports.asCallback = exports.asPromise = void 0;
9
9
  import/prefer-default-export,
10
10
  */
11
11
  const fbp_graph_1 = require("fbp-graph");
12
- const ComponentLoader_1 = require("./ComponentLoader");
13
- const Network_1 = require("./Network");
14
- const IP_1 = require("./IP");
15
- const internalSocket = require("./InternalSocket");
12
+ const ComponentLoader_js_1 = require("./ComponentLoader.js");
13
+ const Network_js_1 = require("./Network.js");
14
+ const IP_js_1 = require("./IP.js");
15
+ const internalSocket = require("./InternalSocket.js");
16
16
  // ## asCallback embedding API
17
17
  //
18
18
  // asCallback is a helper for embedding NoFlo components or
@@ -46,6 +46,13 @@ const internalSocket = require("./InternalSocket");
46
46
  * @property {Object} [flowtrace] - Flowtrace instance to use for tracing this network run
47
47
  * @property {NetworkCallback} [networkCallback] - Access to Network instance
48
48
  * @property {boolean} [raw] - Whether the callback should operate on raw noflo.IP objects
49
+ * @property {boolean} [asyncDelivery] - Make Information Packet delivery asynchronous
50
+ */
51
+ /**
52
+ * @typedef {Array<Object<string, IP>>} OutputMap
53
+ */
54
+ /**
55
+ * @typedef {Object<string, Array<IP|any>>|Array<Object<string, IP|any>>} InputMap
49
56
  */
50
57
  /**
51
58
  * @param {AsCallbackOptions} options
@@ -66,11 +73,14 @@ function normalizeOptions(options, component) {
66
73
  options.baseDir = process.cwd();
67
74
  }
68
75
  if (options.baseDir && !options.loader) {
69
- options.loader = new ComponentLoader_1.ComponentLoader(options.baseDir);
76
+ options.loader = new ComponentLoader_js_1.ComponentLoader(options.baseDir);
70
77
  }
71
78
  if (!options.raw) {
72
79
  options.raw = false;
73
80
  }
81
+ if (!options.asyncDelivery) {
82
+ options.asyncDelivery = false;
83
+ }
74
84
  return options;
75
85
  }
76
86
  // ### Network preparation
@@ -87,7 +97,7 @@ function prepareNetwork(component, options) {
87
97
  // If we were given a graph instance, then just create a network
88
98
  if (typeof component === 'object') {
89
99
  // This is a graph object
90
- const network = new Network_1.Network(component, {
100
+ const network = new Network_js_1.Network(component, {
91
101
  ...options,
92
102
  componentLoader: options.loader,
93
103
  });
@@ -114,7 +124,7 @@ function prepareNetwork(component, options) {
114
124
  graph.addOutport(port, nodeName, port);
115
125
  });
116
126
  // Prepare network
117
- const network = new Network_1.Network(graph, {
127
+ const network = new Network_js_1.Network(graph, {
118
128
  ...options,
119
129
  componentLoader: options.loader,
120
130
  });
@@ -135,7 +145,7 @@ function prepareNetwork(component, options) {
135
145
  /**
136
146
  * @param {Network} network
137
147
  * @param {any} inputs
138
- * @returns {Promise<any>}
148
+ * @returns {Promise<OutputMap>}
139
149
  */
140
150
  function runNetwork(network, inputs) {
141
151
  return new Promise((resolve, reject) => {
@@ -154,9 +164,11 @@ function runNetwork(network, inputs) {
154
164
  if (!process || !process.component) {
155
165
  return;
156
166
  }
157
- outSockets[outport] = internalSocket.createSocket();
167
+ outSockets[outport] = internalSocket.createSocket({}, {
168
+ debug: false,
169
+ });
158
170
  network.subscribeSocket(outSockets[outport]);
159
- process.component.outPorts[portDef.port].attach(outSockets[outport]);
171
+ process.component.outPorts.ports[portDef.port].attach(outSockets[outport]);
160
172
  outSockets[outport].from = {
161
173
  process,
162
174
  port: portDef.port,
@@ -169,9 +181,19 @@ function runNetwork(network, inputs) {
169
181
  });
170
182
  });
171
183
  // Subscribe to process errors
172
- let onEnd = null;
173
- let onError = null;
174
- onError = (err) => {
184
+ /**
185
+ * @callback EndListener
186
+ * @returns {void}
187
+ */
188
+ /**
189
+ * @callback ErrorListener
190
+ * @param {import("./InternalSocket").SocketError} err
191
+ * @returns {void}
192
+ */
193
+ /** @type {EndListener} */
194
+ let onEnd;
195
+ /** @type {ErrorListener} */
196
+ const onError = (err) => {
175
197
  reject(err.error);
176
198
  network.removeListener('end', onEnd);
177
199
  };
@@ -210,20 +232,22 @@ function runNetwork(network, inputs) {
210
232
  reject(new Error(`Process ${portDef.process} for port ${port} not available in the graph`));
211
233
  return;
212
234
  }
213
- inSockets[port] = internalSocket.createSocket();
235
+ inSockets[port] = internalSocket.createSocket({}, {
236
+ debug: false,
237
+ });
214
238
  network.subscribeSocket(inSockets[port]);
215
239
  inSockets[port].to = {
216
240
  process,
217
241
  port,
218
242
  };
219
- process.component.inPorts[portDef.port].attach(inSockets[port]);
243
+ process.component.inPorts.ports[portDef.port].attach(inSockets[port]);
220
244
  }
221
245
  try {
222
- if (IP_1.default.isIP(value)) {
246
+ if (IP_js_1.default.isIP(value)) {
223
247
  inSockets[port].post(value);
224
248
  }
225
249
  else {
226
- inSockets[port].post(new IP_1.default('data', value));
250
+ inSockets[port].post(new IP_js_1.default('data', value));
227
251
  }
228
252
  }
229
253
  catch (e) {
@@ -237,6 +261,11 @@ function runNetwork(network, inputs) {
237
261
  }, reject);
238
262
  });
239
263
  }
264
+ /**
265
+ * @param {any} inputs
266
+ * @param {Network} network
267
+ * @returns {string}
268
+ */
240
269
  function getType(inputs, network) {
241
270
  // Scalar values are always simple inputs
242
271
  if (typeof inputs !== 'object' || !inputs) {
@@ -264,6 +293,12 @@ function getType(inputs, network) {
264
293
  }
265
294
  return 'map';
266
295
  }
296
+ /**
297
+ * @param {any} inputs
298
+ * @param {string} inputType
299
+ * @param {Network} network
300
+ * @returns {InputMap}
301
+ */
267
302
  function prepareInputMap(inputs, inputType, network) {
268
303
  // Sequence we can use as-is
269
304
  if (inputType === 'sequence') {
@@ -282,15 +317,23 @@ function prepareInputMap(inputs, inputType, network) {
282
317
  if (network.graph.inports.in) {
283
318
  inPort = 'in';
284
319
  }
320
+ /** @type {InputMap} */
285
321
  const map = {};
286
322
  map[inPort] = inputs;
287
323
  return [map];
288
324
  }
325
+ /**
326
+ * @param {Array<IP>} values
327
+ * @param {AsCallbackOptions} options
328
+ * @returns {Array<any>}
329
+ */
289
330
  function normalizeOutput(values, options) {
290
331
  if (options.raw) {
291
332
  return values;
292
333
  }
334
+ /** @type {Array<any>} */
293
335
  const result = [];
336
+ /** @type {Array<any>|null} */
294
337
  let previous = null;
295
338
  let current = result;
296
339
  values.forEach((packet) => {
@@ -303,7 +346,7 @@ function normalizeOutput(values, options) {
303
346
  current.push(packet.data);
304
347
  }
305
348
  if (packet.type === 'closeBracket') {
306
- current = previous;
349
+ current = /** @type {Array<any>} */ (previous);
307
350
  }
308
351
  });
309
352
  if (result.length === 1) {
@@ -311,6 +354,11 @@ function normalizeOutput(values, options) {
311
354
  }
312
355
  return result;
313
356
  }
357
+ /**
358
+ * @param {OutputMap} outputs
359
+ * @param {string} resultType
360
+ * @param {AsCallbackOptions} options
361
+ */
314
362
  function sendOutputMap(outputs, resultType, options) {
315
363
  // First check if the output sequence contains errors
316
364
  const errors = outputs.filter((map) => map.error != null).map((map) => map.error);
@@ -319,6 +367,7 @@ function sendOutputMap(outputs, resultType, options) {
319
367
  }
320
368
  if (resultType === 'sequence') {
321
369
  return Promise.resolve(outputs.map((map) => {
370
+ /** @type {Object<string, any|IP>} */
322
371
  const res = {};
323
372
  Object.keys(map).forEach((key) => {
324
373
  const val = map[key];
@@ -332,6 +381,7 @@ function sendOutputMap(outputs, resultType, options) {
332
381
  }));
333
382
  }
334
383
  // Flatten the sequence
384
+ /** @type {Object<string, Array<any|IP>>} */
335
385
  const mappedOutputs = {};
336
386
  outputs.forEach((map) => {
337
387
  Object.keys(map).forEach((key) => {
@@ -352,6 +402,7 @@ function sendOutputMap(outputs, resultType, options) {
352
402
  // Single outport
353
403
  return Promise.resolve(normalizeOutput(mappedOutputs[withValue[0]], options));
354
404
  }
405
+ /** @type {Object<string, any|IP>} */
355
406
  const result = {};
356
407
  Object.keys(mappedOutputs).forEach((port) => {
357
408
  const packets = mappedOutputs[port];
@@ -35,4 +35,4 @@ export type PortOptions = {
35
35
  scoped?: boolean;
36
36
  default?: any;
37
37
  };
38
- import { Component } from "./Component";
38
+ import { Component } from "./Component.js";
@@ -8,7 +8,7 @@ exports.asComponent = void 0;
8
8
  import/prefer-default-export,
9
9
  */
10
10
  const getParams = require("get-function-params");
11
- const Component_1 = require("./Component");
11
+ const Component_js_1 = require("./Component.js");
12
12
  /**
13
13
  * @typedef FuncParam
14
14
  * @property {string} param
@@ -91,7 +91,7 @@ function asComponent(func, options) {
91
91
  hasCallback = true;
92
92
  return false;
93
93
  });
94
- const c = new Component_1.Component(options);
94
+ const c = new Component_js_1.Component(options);
95
95
  params.forEach((p) => {
96
96
  /** @type {PortOptions} */
97
97
  const portOptions = { required: true };
@@ -103,7 +103,9 @@ function asComponent(func, options) {
103
103
  c.forwardBrackets[p.param] = ['out', 'error'];
104
104
  });
105
105
  if (!params.length) {
106
- c.inPorts.add('in', { datatype: 'bang' });
106
+ c.inPorts.add('in', {
107
+ datatype: 'bang',
108
+ });
107
109
  }
108
110
  c.outPorts.add('out');
109
111
  c.outPorts.add('error');
@@ -3,6 +3,7 @@
3
3
  * @property {string} [baseDir] - Project base directory for component loading
4
4
  * @property {ComponentLoader} [componentLoader] - Component loader instance to use, if any
5
5
  * @property {Object} [flowtrace] - Flowtrace instance to use for tracing this network run
6
+ * @property {boolean} [asyncDelivery] - Make Information Packet delivery asynchronous
6
7
  */
7
8
  /**
8
9
  * @typedef { NetworkOwnOptions & import("./ComponentLoader").ComponentLoaderOptions} NetworkOptions
@@ -30,10 +31,11 @@ export class BaseNetwork extends EventEmitter {
30
31
  nextInitials: Array<NetworkIIP>;
31
32
  /** @type {Array<import("./InternalSocket").InternalSocket>} */
32
33
  defaults: Array<import("./InternalSocket").InternalSocket>;
33
- graph: import("fbp-graph/lib/Graph").Graph;
34
+ graph: import("fbp-graph/lib/Graph.js").Graph;
34
35
  started: boolean;
35
36
  stopped: boolean;
36
37
  debug: boolean;
38
+ asyncDelivery: boolean;
37
39
  /** @type {Array<NetworkEvent>} */
38
40
  eventBuffer: Array<NetworkEvent>;
39
41
  baseDir: any;
@@ -115,7 +117,7 @@ export class BaseNetwork extends EventEmitter {
115
117
  * @param {ErrorableCallback} [callback]
116
118
  * @returns {Promise<this>}
117
119
  */
118
- connect(callback?: (err?: Error | null) => void): Promise<this>;
120
+ connect(callback?: (err?: Error | null) => void): Promise<BaseNetwork>;
119
121
  /**
120
122
  * @private
121
123
  * @param {NetworkProcess} node
@@ -196,12 +198,12 @@ export class BaseNetwork extends EventEmitter {
196
198
  * @param {ErrorableCallback} [callback]
197
199
  * @returns {Promise<this>}
198
200
  */
199
- start(callback?: (err?: Error | null) => void): Promise<this>;
201
+ start(callback?: (err?: Error | null) => void): Promise<BaseNetwork>;
200
202
  /**
201
203
  * @param {ErrorableCallback} [callback]
202
204
  * @returns {Promise<this>}
203
205
  */
204
- stop(callback?: (err?: Error | null) => void): Promise<this>;
206
+ stop(callback?: (err?: Error | null) => void): Promise<BaseNetwork>;
205
207
  /**
206
208
  * @param {boolean} started
207
209
  */
@@ -213,6 +215,10 @@ export class BaseNetwork extends EventEmitter {
213
215
  * @param {boolean} active
214
216
  */
215
217
  setDebug(active: boolean): void;
218
+ /**
219
+ * @param {boolean} active
220
+ */
221
+ setAsyncDelivery(active: boolean): void;
216
222
  /**
217
223
  * @param {Object|null} flowtrace
218
224
  * @param {string|null} [name]
@@ -247,8 +253,12 @@ export type NetworkOwnOptions = {
247
253
  * - Flowtrace instance to use for tracing this network run
248
254
  */
249
255
  flowtrace?: any;
256
+ /**
257
+ * - Make Information Packet delivery asynchronous
258
+ */
259
+ asyncDelivery?: boolean;
250
260
  };
251
261
  export type NetworkOptions = NetworkOwnOptions & import("./ComponentLoader").ComponentLoaderOptions;
252
262
  import { EventEmitter } from "events";
253
- import * as internalSocket from "./InternalSocket";
254
- import { ComponentLoader } from "./ComponentLoader";
263
+ import * as internalSocket from "./InternalSocket.js";
264
+ import { ComponentLoader } from "./ComponentLoader.js";
@@ -11,11 +11,11 @@ exports.BaseNetwork = void 0;
11
11
  import/prefer-default-export,
12
12
  */
13
13
  const events_1 = require("events");
14
- const internalSocket = require("./InternalSocket");
15
- const ComponentLoader_1 = require("./ComponentLoader");
16
- const Utils_1 = require("./Utils");
17
- const IP_1 = require("./IP");
18
- const Platform_1 = require("./Platform");
14
+ const internalSocket = require("./InternalSocket.js");
15
+ const ComponentLoader_js_1 = require("./ComponentLoader.js");
16
+ const Utils_js_1 = require("./Utils.js");
17
+ const IP_js_1 = require("./IP.js");
18
+ const Platform_js_1 = require("./Platform.js");
19
19
  /**
20
20
  * @typedef NetworkProcess
21
21
  * @property {string} id
@@ -36,7 +36,7 @@ const Platform_1 = require("./Platform");
36
36
  * @param {internalSocket.InternalSocket} socket
37
37
  * @param {NetworkProcess} process
38
38
  * @param {string} port
39
- * @param {number|void} index
39
+ * @param {number|null} index
40
40
  * @param {boolean} inbound
41
41
  * @returns {Promise<internalSocket.InternalSocket>}
42
42
  */
@@ -81,6 +81,7 @@ function connectPort(socket, process, port, index, inbound) {
81
81
  * @property {string} [baseDir] - Project base directory for component loading
82
82
  * @property {ComponentLoader} [componentLoader] - Component loader instance to use, if any
83
83
  * @property {Object} [flowtrace] - Flowtrace instance to use for tracing this network run
84
+ * @property {boolean} [asyncDelivery] - Make Information Packet delivery asynchronous
84
85
  */
85
86
  /**
86
87
  * @typedef { NetworkOwnOptions & import("./ComponentLoader").ComponentLoaderOptions} NetworkOptions
@@ -125,15 +126,16 @@ class BaseNetwork extends events_1.EventEmitter {
125
126
  this.started = false;
126
127
  this.stopped = true;
127
128
  this.debug = true;
129
+ this.asyncDelivery = options.asyncDelivery || false;
128
130
  /** @type {Array<NetworkEvent>} */
129
131
  this.eventBuffer = [];
130
132
  // On Node.js we default the baseDir for component loading to
131
133
  // the current working directory
132
134
  if (graph.properties.baseDir && !options.baseDir) {
133
- Platform_1.deprecated('Passing baseDir via Graph properties is deprecated, pass via Network options instead');
135
+ (0, Platform_js_1.deprecated)('Passing baseDir via Graph properties is deprecated, pass via Network options instead');
134
136
  }
135
137
  this.baseDir = null;
136
- if (!Platform_1.isBrowser()) {
138
+ if (!(0, Platform_js_1.isBrowser)()) {
137
139
  this.baseDir = options.baseDir || graph.properties.baseDir || process.cwd();
138
140
  // On browser we default the baseDir to the Component loading
139
141
  // root
@@ -152,13 +154,13 @@ class BaseNetwork extends events_1.EventEmitter {
152
154
  this.loader = options.componentLoader;
153
155
  }
154
156
  else if (graph.properties.componentLoader) {
155
- Platform_1.deprecated('Passing componentLoader via Graph properties is deprecated, pass via Network options instead');
157
+ (0, Platform_js_1.deprecated)('Passing componentLoader via Graph properties is deprecated, pass via Network options instead');
156
158
  /** @type {ComponentLoader} */
157
159
  this.loader = graph.properties.componentLoader;
158
160
  }
159
161
  else {
160
162
  /** @type {ComponentLoader} */
161
- this.loader = new ComponentLoader_1.ComponentLoader(this.baseDir, this.options);
163
+ this.loader = new ComponentLoader_js_1.ComponentLoader(this.baseDir, this.options);
162
164
  }
163
165
  // Enable Flowtrace for this network, when available
164
166
  this.flowtraceName = null;
@@ -321,7 +323,7 @@ class BaseNetwork extends events_1.EventEmitter {
321
323
  load(component, metadata, callback) {
322
324
  const promise = this.loader.load(component, metadata);
323
325
  if (callback) {
324
- Platform_1.deprecated('Providing a callback to Network.load is deprecated, use Promises');
326
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.load is deprecated, use Promises');
325
327
  promise.then((instance) => {
326
328
  callback(null, instance);
327
329
  }, callback);
@@ -400,7 +402,7 @@ class BaseNetwork extends events_1.EventEmitter {
400
402
  }
401
403
  }
402
404
  if (callback) {
403
- Platform_1.deprecated('Providing a callback to Network.addNode is deprecated, use Promises');
405
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.addNode is deprecated, use Promises');
404
406
  promise.then((process) => {
405
407
  callback(null, process);
406
408
  }, callback);
@@ -430,7 +432,7 @@ class BaseNetwork extends events_1.EventEmitter {
430
432
  });
431
433
  }
432
434
  if (callback) {
433
- Platform_1.deprecated('Providing a callback to Network.removeNode is deprecated, use Promises');
435
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.removeNode is deprecated, use Promises');
434
436
  promise.then(() => {
435
437
  callback(null);
436
438
  }, callback);
@@ -476,7 +478,7 @@ class BaseNetwork extends events_1.EventEmitter {
476
478
  promise = Promise.resolve();
477
479
  }
478
480
  if (callback) {
479
- Platform_1.deprecated('Providing a callback to Network.renameNode is deprecated, use Promises');
481
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.renameNode is deprecated, use Promises');
480
482
  promise.then(() => {
481
483
  callback(null);
482
484
  }, callback);
@@ -518,7 +520,7 @@ class BaseNetwork extends events_1.EventEmitter {
518
520
  .then(() => handleAll('nodes', 'addDefaults'))
519
521
  .then(() => this);
520
522
  if (callback) {
521
- Platform_1.deprecated('Providing a callback to Network.connect is deprecated, use Promises');
523
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.connect is deprecated, use Promises');
522
524
  promise.then(() => {
523
525
  callback(null);
524
526
  }, callback);
@@ -544,6 +546,7 @@ class BaseNetwork extends events_1.EventEmitter {
544
546
  return;
545
547
  }
546
548
  instance.network.setDebug(this.debug);
549
+ instance.network.setAsyncDelivery(this.asyncDelivery);
547
550
  if (this.flowtrace) {
548
551
  instance.network.setFlowtrace(this.flowtrace, node.componentName, false);
549
552
  }
@@ -702,8 +705,10 @@ class BaseNetwork extends events_1.EventEmitter {
702
705
  }
703
706
  const promise = this.ensureNode(edge.from.node, 'outbound')
704
707
  .then((from) => {
705
- const socket = internalSocket.createSocket(edge.metadata);
706
- socket.setDebug(this.debug);
708
+ const socket = internalSocket.createSocket(edge.metadata, {
709
+ debug: this.debug,
710
+ async: this.asyncDelivery,
711
+ });
707
712
  return this.ensureNode(edge.to.node, 'inbound')
708
713
  .then((to) => {
709
714
  // Subscribe to events from the socket
@@ -717,7 +722,7 @@ class BaseNetwork extends events_1.EventEmitter {
717
722
  });
718
723
  });
719
724
  if (callback) {
720
- Platform_1.deprecated('Providing a callback to Network.addEdge is deprecated, use Promises');
725
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.addEdge is deprecated, use Promises');
721
726
  promise.then((socket) => {
722
727
  callback(null, socket);
723
728
  }, callback);
@@ -748,7 +753,7 @@ class BaseNetwork extends events_1.EventEmitter {
748
753
  this.connections.splice(this.connections.indexOf(connection), 1);
749
754
  });
750
755
  if (callback) {
751
- Platform_1.deprecated('Providing a callback to Network.removeEdge is deprecated, use Promises');
756
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.removeEdge is deprecated, use Promises');
752
757
  callback(null);
753
758
  }
754
759
  return Promise.resolve();
@@ -766,8 +771,10 @@ class BaseNetwork extends events_1.EventEmitter {
766
771
  if (!port.hasDefault() || port.isAttached()) {
767
772
  return Promise.resolve();
768
773
  }
769
- const socket = internalSocket.createSocket();
770
- socket.setDebug(this.debug);
774
+ const socket = internalSocket.createSocket({}, {
775
+ debug: this.debug,
776
+ async: this.asyncDelivery,
777
+ });
771
778
  // Subscribe to events from the socket
772
779
  this.subscribeSocket(socket);
773
780
  return connectPort(socket, process, key, undefined, true)
@@ -791,8 +798,10 @@ class BaseNetwork extends events_1.EventEmitter {
791
798
  }
792
799
  const promise = this.ensureNode(initializer.to.node, 'inbound')
793
800
  .then((to) => {
794
- const socket = internalSocket.createSocket(initializer.metadata);
795
- socket.setDebug(this.debug);
801
+ const socket = internalSocket.createSocket(initializer.metadata, {
802
+ debug: this.debug,
803
+ async: this.asyncDelivery,
804
+ });
796
805
  // Subscribe to events from the socket
797
806
  this.subscribeSocket(socket);
798
807
  return connectPort(socket, to, initializer.to.port, initializer.to.index, true);
@@ -818,7 +827,7 @@ class BaseNetwork extends events_1.EventEmitter {
818
827
  return socket;
819
828
  });
820
829
  if (callback) {
821
- Platform_1.deprecated('Providing a callback to Network.addInitial is deprecated, use Promises');
830
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.addInitial is deprecated, use Promises');
822
831
  promise.then((socket) => {
823
832
  callback(null, socket);
824
833
  }, callback);
@@ -863,7 +872,7 @@ class BaseNetwork extends events_1.EventEmitter {
863
872
  }
864
873
  });
865
874
  if (callback) {
866
- Platform_1.deprecated('Providing a callback to Network.removeInitial is deprecated, use Promises');
875
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.removeInitial is deprecated, use Promises');
867
876
  callback(null);
868
877
  }
869
878
  return Promise.resolve();
@@ -873,11 +882,11 @@ class BaseNetwork extends events_1.EventEmitter {
873
882
  */
874
883
  sendInitials() {
875
884
  return new Promise((resolve) => {
876
- Platform_1.makeAsync(resolve);
885
+ (0, Platform_js_1.makeAsync)(resolve, true);
877
886
  })
878
887
  .then(() => this.initials.reduce((chain, initial) => chain
879
888
  .then(() => {
880
- initial.socket.post(new IP_1.default('data', initial.data, {
889
+ initial.socket.post(new IP_js_1.default('data', initial.data, {
881
890
  initial: true,
882
891
  }));
883
892
  return Promise.resolve();
@@ -959,7 +968,7 @@ class BaseNetwork extends events_1.EventEmitter {
959
968
  });
960
969
  }
961
970
  if (callback) {
962
- Platform_1.deprecated('Providing a callback to Network.start is deprecated, use Promises');
971
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.start is deprecated, use Promises');
963
972
  promise.then(() => {
964
973
  callback(null);
965
974
  }, callback);
@@ -1012,7 +1021,7 @@ class BaseNetwork extends events_1.EventEmitter {
1012
1021
  }
1013
1022
  }
1014
1023
  if (callback) {
1015
- Platform_1.deprecated('Providing a callback to Network.stop is deprecated, use Promises');
1024
+ (0, Platform_js_1.deprecated)('Providing a callback to Network.stop is deprecated, use Promises');
1016
1025
  promise.then(() => {
1017
1026
  callback(null);
1018
1027
  }, callback);
@@ -1042,7 +1051,9 @@ class BaseNetwork extends events_1.EventEmitter {
1042
1051
  }
1043
1052
  this.started = true;
1044
1053
  this.stopped = false;
1045
- this.bufferedEmit('start', { start: this.startupDate });
1054
+ this.bufferedEmit('start', {
1055
+ start: this.startupDate,
1056
+ });
1046
1057
  }
1047
1058
  checkIfFinished() {
1048
1059
  if (this.isRunning()) {
@@ -1050,7 +1061,7 @@ class BaseNetwork extends events_1.EventEmitter {
1050
1061
  }
1051
1062
  delete this.abortDebounce;
1052
1063
  if (!this.debouncedEnd) {
1053
- this.debouncedEnd = Utils_1.debounce(() => {
1064
+ this.debouncedEnd = (0, Utils_js_1.debounce)(() => {
1054
1065
  if (this.abortDebounce) {
1055
1066
  return;
1056
1067
  }
@@ -1088,6 +1099,29 @@ class BaseNetwork extends events_1.EventEmitter {
1088
1099
  }
1089
1100
  });
1090
1101
  }
1102
+ /**
1103
+ * @param {boolean} active
1104
+ */
1105
+ setAsyncDelivery(active) {
1106
+ if (active === this.asyncDelivery) {
1107
+ return;
1108
+ }
1109
+ this.asyncDelivery = active;
1110
+ this.connections.forEach((socket) => {
1111
+ socket.async = this.asyncDelivery;
1112
+ });
1113
+ Object.keys(this.processes).forEach((processId) => {
1114
+ const process = this.processes[processId];
1115
+ if (!process.component) {
1116
+ return;
1117
+ }
1118
+ const instance = process.component;
1119
+ if (instance.isSubgraph()) {
1120
+ const inst = /** @type {import("../components/Graph").Graph} */ (instance);
1121
+ inst.network.setAsyncDelivery(active);
1122
+ }
1123
+ });
1124
+ }
1091
1125
  /**
1092
1126
  * @param {Object|null} flowtrace
1093
1127
  * @param {string|null} [name]
package/lib/BasePort.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  export default class BasePort extends EventEmitter {
2
- constructor(options: any);
3
- options: any;
4
- /** @type {Array<import("./InternalSocket").InternalSocket>} */
5
- sockets: Array<import("./InternalSocket").InternalSocket>;
2
+ /**
3
+ * @param {BaseOptions} options
4
+ */
5
+ constructor(options: BaseOptions);
6
+ options: BaseOptions;
7
+ /** @type {Array<import("./InternalSocket").InternalSocket|void>} */
8
+ sockets: Array<import("./InternalSocket").InternalSocket | void>;
6
9
  /** @type {string|null} */
7
10
  node: string | null;
8
11
  /** @type {import("./Component").Component|null} */
@@ -10,18 +13,40 @@ export default class BasePort extends EventEmitter {
10
13
  /** @type {string|null} */
11
14
  name: string | null;
12
15
  getId(): string;
13
- getDataType(): any;
14
- getSchema(): any;
15
- getDescription(): any;
16
- attach(socket: any, index?: any): void;
17
- attachSocket(socket: any, index?: any): void;
18
- detach(socket: any): void;
16
+ /**
17
+ * @returns {string}
18
+ */
19
+ getDataType(): string;
20
+ getSchema(): string;
21
+ getDescription(): string;
22
+ /**
23
+ * @param {import("./InternalSocket").InternalSocket} socket
24
+ * @param {number|null} [index]
25
+ */
26
+ attach(socket: import("./InternalSocket").InternalSocket, index?: number | null): void;
27
+ /**
28
+ * @param {import("./InternalSocket").InternalSocket} socket
29
+ * @param {number|null} [index]
30
+ */
31
+ attachSocket(socket: import("./InternalSocket").InternalSocket, index?: number | null): void;
32
+ /**
33
+ * @param {import("./InternalSocket").InternalSocket} socket
34
+ */
35
+ detach(socket: import("./InternalSocket").InternalSocket): void;
19
36
  isAddressable(): boolean;
20
37
  isBuffered(): boolean;
21
38
  isRequired(): boolean;
22
- isAttached(socketId?: any): boolean;
39
+ /**
40
+ * @param {number|null} socketId
41
+ * @returns {boolean}
42
+ */
43
+ isAttached(socketId?: number | null): boolean;
23
44
  listAttached(): number[];
24
- isConnected(socketId?: any): boolean;
45
+ /**
46
+ * @param {number|null} socketId
47
+ * @returns {boolean}
48
+ */
49
+ isConnected(socketId?: number | null): boolean;
25
50
  canAttach(): boolean;
26
51
  }
27
52
  /**
@@ -29,6 +54,8 @@ export default class BasePort extends EventEmitter {
29
54
  */
30
55
  export type BaseOptions = {
31
56
  description?: string;
57
+ addressable?: boolean;
58
+ buffered?: boolean;
32
59
  datatype?: string;
33
60
  schema?: string;
34
61
  type?: string;