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/BasePort.js CHANGED
@@ -26,6 +26,8 @@ const validTypes = [
26
26
  /**
27
27
  * @typedef {Object} BaseOptions - Options for configuring all types of ports
28
28
  * @property {string} [description='']
29
+ * @property {boolean} [addressable=false]
30
+ * @property {boolean} [buffered=false]
29
31
  * @property {string} [datatype='all']
30
32
  * @property {string} [schema=null]
31
33
  * @property {string} [type=null]
@@ -70,13 +72,16 @@ function handleOptions(options) {
70
72
  });
71
73
  }
72
74
  class BasePort extends events_1.EventEmitter {
75
+ /**
76
+ * @param {BaseOptions} options
77
+ */
73
78
  constructor(options) {
74
79
  super();
75
80
  // Options holds all options of the current port
76
81
  this.options = handleOptions(options);
77
82
  // Sockets list contains all currently attached
78
83
  // connections to the port
79
- /** @type {Array<import("./InternalSocket").InternalSocket>} */
84
+ /** @type {Array<import("./InternalSocket").InternalSocket|void>} */
80
85
  this.sockets = [];
81
86
  // Name of the graph node this port is in
82
87
  /** @type {string|null} */
@@ -93,11 +98,18 @@ class BasePort extends events_1.EventEmitter {
93
98
  }
94
99
  return `${this.node} ${this.name.toUpperCase()}`;
95
100
  }
96
- getDataType() { return this.options.datatype; }
101
+ /**
102
+ * @returns {string}
103
+ */
104
+ getDataType() { return this.options.datatype || 'all'; }
97
105
  getSchema() { return this.options.schema || null; }
98
106
  getDescription() { return this.options.description; }
107
+ /**
108
+ * @param {import("./InternalSocket").InternalSocket} socket
109
+ * @param {number|null} [index]
110
+ */
99
111
  attach(socket, index = null) {
100
- let idx = index;
112
+ let idx = /** @type {number} */ (index);
101
113
  if (!this.isAddressable() || (index === null)) {
102
114
  idx = this.sockets.length;
103
115
  }
@@ -109,8 +121,14 @@ class BasePort extends events_1.EventEmitter {
109
121
  }
110
122
  this.emit('attach', socket);
111
123
  }
112
- // eslint-disable-next-line class-methods-use-this,no-unused-vars
113
- attachSocket(socket, index = null) { }
124
+ /**
125
+ * @param {import("./InternalSocket").InternalSocket} socket
126
+ * @param {number|null} [index]
127
+ */
128
+ attachSocket(socket, index = null) { } // eslint-disable-line class-methods-use-this,no-unused-vars,max-len
129
+ /**
130
+ * @param {import("./InternalSocket").InternalSocket} socket
131
+ */
114
132
  detach(socket) {
115
133
  const index = this.sockets.indexOf(socket);
116
134
  if (index === -1) {
@@ -141,6 +159,10 @@ class BasePort extends events_1.EventEmitter {
141
159
  }
142
160
  return false;
143
161
  }
162
+ /**
163
+ * @param {number|null} socketId
164
+ * @returns {boolean}
165
+ */
144
166
  isAttached(socketId = null) {
145
167
  if (this.isAddressable() && (socketId !== null)) {
146
168
  if (this.sockets[socketId]) {
@@ -163,6 +185,10 @@ class BasePort extends events_1.EventEmitter {
163
185
  }
164
186
  return attached;
165
187
  }
188
+ /**
189
+ * @param {number|null} socketId
190
+ * @returns {boolean}
191
+ */
166
192
  isConnected(socketId = null) {
167
193
  if (this.isAddressable()) {
168
194
  if (socketId === null) {
@@ -171,7 +197,9 @@ class BasePort extends events_1.EventEmitter {
171
197
  if (!this.sockets[socketId]) {
172
198
  throw new Error(`${this.getId()}: Socket ${socketId} not available`);
173
199
  }
174
- return this.sockets[socketId].isConnected();
200
+ // eslint-disable-next-line max-len
201
+ const socket = /** @type {import("./InternalSocket").InternalSocket} */ (this.sockets[socketId]);
202
+ return socket.isConnected();
175
203
  }
176
204
  let connected = false;
177
205
  this.sockets.forEach((socket) => {
@@ -212,11 +212,11 @@ export type ProcessResult = {
212
212
  __bracketClosingAfter?: BracketContext[];
213
213
  };
214
214
  import { EventEmitter } from "events";
215
- import { InPorts } from "./Ports";
216
- import { OutPorts } from "./Ports";
217
- import InPort from "./InPort";
218
- import OutPort from "./OutPort";
219
- import IP from "./IP";
220
- import ProcessInput from "./ProcessInput";
221
- import ProcessOutput from "./ProcessOutput";
222
- import ProcessContext from "./ProcessContext";
215
+ import { InPorts } from "./Ports.js";
216
+ import { OutPorts } from "./Ports.js";
217
+ import InPort from "./InPort.js";
218
+ import OutPort from "./OutPort.js";
219
+ import IP from "./IP.js";
220
+ import ProcessInput from "./ProcessInput.js";
221
+ import ProcessOutput from "./ProcessOutput.js";
222
+ import ProcessContext from "./ProcessContext.js";
package/lib/Component.js CHANGED
@@ -12,14 +12,17 @@ exports.Component = void 0;
12
12
  */
13
13
  const events_1 = require("events");
14
14
  const debug_1 = require("debug");
15
- const Ports_1 = require("./Ports");
16
- const Platform_1 = require("./Platform");
17
- const ProcessContext_1 = require("./ProcessContext");
18
- const ProcessInput_1 = require("./ProcessInput");
19
- const ProcessOutput_1 = require("./ProcessOutput");
20
- const debugComponent = debug_1.default('noflo:component');
21
- const debugBrackets = debug_1.default('noflo:component:brackets');
22
- const debugSend = debug_1.default('noflo:component:send');
15
+ const Ports_js_1 = require("./Ports.js");
16
+ const Platform_js_1 = require("./Platform.js");
17
+ const InPort_js_1 = require("./InPort.js"); // eslint-disable-line no-unused-vars
18
+ const OutPort_js_1 = require("./OutPort.js"); // eslint-disable-line no-unused-vars
19
+ const ProcessContext_js_1 = require("./ProcessContext.js");
20
+ const ProcessInput_js_1 = require("./ProcessInput.js");
21
+ const ProcessOutput_js_1 = require("./ProcessOutput.js");
22
+ const IP_js_1 = require("./IP.js"); // eslint-disable-line no-unused-vars
23
+ const debugComponent = (0, debug_1.default)('noflo:component');
24
+ const debugBrackets = (0, debug_1.default)('noflo:component:brackets');
25
+ const debugSend = (0, debug_1.default)('noflo:component:send');
23
26
  /**
24
27
  * @callback ProcessingFunction
25
28
  * @param {ProcessInput} input
@@ -66,11 +69,11 @@ class Component extends events_1.EventEmitter {
66
69
  if (!opts.inPorts) {
67
70
  opts.inPorts = {};
68
71
  }
69
- if (opts.inPorts instanceof Ports_1.InPorts) {
72
+ if (opts.inPorts instanceof Ports_js_1.InPorts) {
70
73
  this.inPorts = opts.inPorts;
71
74
  }
72
75
  else {
73
- this.inPorts = new Ports_1.InPorts(opts.inPorts);
76
+ this.inPorts = new Ports_js_1.InPorts(opts.inPorts);
74
77
  }
75
78
  // Prepare outports, if any were given in opts.
76
79
  // They can also be set up imperatively after component
@@ -79,11 +82,11 @@ class Component extends events_1.EventEmitter {
79
82
  if (!opts.outPorts) {
80
83
  opts.outPorts = {};
81
84
  }
82
- if (opts.outPorts instanceof Ports_1.OutPorts) {
85
+ if (opts.outPorts instanceof Ports_js_1.OutPorts) {
83
86
  this.outPorts = opts.outPorts;
84
87
  }
85
88
  else {
86
- this.outPorts = new Ports_1.OutPorts(opts.outPorts);
89
+ this.outPorts = new Ports_js_1.OutPorts(opts.outPorts);
87
90
  }
88
91
  // Set the default component icon and description
89
92
  this.icon = opts.icon ? opts.icon : '';
@@ -234,7 +237,7 @@ class Component extends events_1.EventEmitter {
234
237
  });
235
238
  }
236
239
  if (callback) {
237
- Platform_1.deprecated('Providing a callback to Component.start is deprecated, use Promises');
240
+ (0, Platform_js_1.deprecated)('Providing a callback to Component.start is deprecated, use Promises');
238
241
  promise.then(() => {
239
242
  callback(null);
240
243
  }, callback);
@@ -309,7 +312,7 @@ class Component extends events_1.EventEmitter {
309
312
  return Promise.resolve();
310
313
  });
311
314
  if (callback) {
312
- Platform_1.deprecated('Providing a callback to Component.shutdown is deprecated, use Promises');
315
+ (0, Platform_js_1.deprecated)('Providing a callback to Component.shutdown is deprecated, use Promises');
313
316
  promise.then(() => {
314
317
  callback(null);
315
318
  }, callback);
@@ -506,9 +509,9 @@ class Component extends events_1.EventEmitter {
506
509
  }
507
510
  }
508
511
  // Prepare the input/output pair
509
- const context = new ProcessContext_1.default(ip, this, port, result);
510
- const input = new ProcessInput_1.default(this.inPorts, context);
511
- const output = new ProcessOutput_1.default(this.outPorts, context);
512
+ const context = new ProcessContext_js_1.default(ip, this, port, result);
513
+ const input = new ProcessInput_js_1.default(this.inPorts, context);
514
+ const output = new ProcessOutput_js_1.default(this.outPorts, context);
512
515
  try {
513
516
  // Call the processing function
514
517
  if (!this.handle) {
@@ -543,7 +546,7 @@ class Component extends events_1.EventEmitter {
543
546
  * @param {number|null} [idx]
544
547
  */
545
548
  getBracketContext(type, port, scope, idx = null) {
546
- let { name, index } = Ports_1.normalizePortName(port);
549
+ let { name, index } = (0, Ports_js_1.normalizePortName)(port);
547
550
  if (idx != null) {
548
551
  index = `${idx}`;
549
552
  }
@@ -574,7 +577,7 @@ class Component extends events_1.EventEmitter {
574
577
  addToResult(result, port, packet, before = false) {
575
578
  const res = result;
576
579
  const ip = packet;
577
- const { name, index } = Ports_1.normalizePortName(port);
580
+ const { name, index } = (0, Ports_js_1.normalizePortName)(port);
578
581
  const method = before ? 'unshift' : 'push';
579
582
  if (this.outPorts.ports[name].isAddressable()) {
580
583
  const idx = /** @type {number} */ (index ? parseInt(index, 10) : ip.index);
@@ -597,7 +600,7 @@ class Component extends events_1.EventEmitter {
597
600
  // pair.
598
601
  /** @private */
599
602
  getForwardableContexts(inport, outport, contexts) {
600
- const { name, index } = Ports_1.normalizePortName(outport);
603
+ const { name, index } = (0, Ports_js_1.normalizePortName)(outport);
601
604
  const forwardable = [];
602
605
  contexts.forEach((ctx, idx) => {
603
606
  // No forwarding to this outport
@@ -73,13 +73,13 @@ export class ComponentLoader {
73
73
  */
74
74
  load(name: string, meta: import("fbp-graph/lib/Types").GraphNodeMetadata, cb?: any): Promise<import("./Component").Component>;
75
75
  /**
76
- * @protected
76
+ * Creates an instance of a component.
77
77
  * @param {string} name
78
78
  * @param {ComponentDefinitionWithoutGraph} component
79
79
  * @param {import("fbp-graph/lib/Types").GraphNodeMetadata} metadata
80
80
  * @returns {Promise<import("./Component").Component>}
81
81
  */
82
- protected createComponent(name: string, component: ComponentDefinitionWithoutGraph, metadata: import("fbp-graph/lib/Types").GraphNodeMetadata): Promise<import("./Component").Component>;
82
+ createComponent(name: string, component: ComponentDefinitionWithoutGraph, metadata: import("fbp-graph/lib/Types").GraphNodeMetadata): Promise<import("./Component").Component>;
83
83
  /**
84
84
  * @param {import("fbp-graph").Graph|object|string} cPath
85
85
  * @returns {boolean}
@@ -171,7 +171,7 @@ export type ComponentFactory = (metadata?: import("fbp-graph/lib/Types").GraphNo
171
171
  export type ModuleComponent = {
172
172
  getComponent: ComponentFactory;
173
173
  };
174
- export type ComponentDefinition = string | Graph | ModuleComponent | ComponentFactory;
174
+ export type ComponentDefinition = string | ModuleComponent | ComponentFactory | import("fbp-graph").Graph;
175
175
  export type ComponentDefinitionWithoutGraph = string | ModuleComponent | ComponentFactory;
176
176
  export type ComponentList = {
177
177
  [x: string]: ComponentDefinition;
@@ -190,4 +190,3 @@ export type ComponentLoaderOptions = {
190
190
  runtimes?: string[];
191
191
  manifest?: string;
192
192
  };
193
- import { Graph } from "fbp-graph";
@@ -11,8 +11,8 @@ exports.ComponentLoader = void 0;
11
11
  import/prefer-default-export,
12
12
  */
13
13
  const fbp_graph_1 = require("fbp-graph");
14
- const registerLoader = require("./loader/register");
15
- const Platform_1 = require("./Platform");
14
+ const registerLoader = require("./loader/register.js");
15
+ const Platform_js_1 = require("./Platform.js");
16
16
  /**
17
17
  * @callback ComponentFactory
18
18
  * @param {import("fbp-graph/lib/Types").GraphNodeMetadata} [metadata]
@@ -121,7 +121,7 @@ class ComponentLoader {
121
121
  this.components = {};
122
122
  this.ready = false;
123
123
  this.processing = new Promise((resolve, reject) => {
124
- Platform_1.makeAsync(() => {
124
+ (0, Platform_js_1.makeAsync)(() => {
125
125
  registerLoader.register(this, (err) => {
126
126
  if (err) {
127
127
  // We keep the failed promise here in this.processing
@@ -137,7 +137,7 @@ class ComponentLoader {
137
137
  promise = this.processing;
138
138
  }
139
139
  if (callback) {
140
- Platform_1.deprecated('Providing a callback to ComponentLoader.listComponents is deprecated, use Promises');
140
+ (0, Platform_js_1.deprecated)('Providing a callback to ComponentLoader.listComponents is deprecated, use Promises');
141
141
  promise.then((components) => {
142
142
  callback(null, components);
143
143
  }, callback);
@@ -206,23 +206,22 @@ class ComponentLoader {
206
206
  inst.componentName = name;
207
207
  }
208
208
  if (inst.isLegacy()) {
209
- Platform_1.deprecated(`Component ${name} uses legacy NoFlo APIs. Please port to Process API`);
209
+ (0, Platform_js_1.deprecated)(`Component ${name} uses legacy NoFlo APIs. Please port to Process API`);
210
210
  }
211
211
  this.setIcon(name, inst);
212
212
  return inst;
213
213
  });
214
214
  });
215
215
  if (callback) {
216
- Platform_1.deprecated('Providing a callback to ComponentLoader.load is deprecated, use Promises');
216
+ (0, Platform_js_1.deprecated)('Providing a callback to ComponentLoader.load is deprecated, use Promises');
217
217
  promise.then((instance) => {
218
218
  callback(null, instance);
219
219
  }, callback);
220
220
  }
221
221
  return promise;
222
222
  }
223
- // Creates an instance of a component.
224
223
  /**
225
- * @protected
224
+ * Creates an instance of a component.
226
225
  * @param {string} name
227
226
  * @param {ComponentDefinitionWithoutGraph} component
228
227
  * @param {import("fbp-graph/lib/Types").GraphNodeMetadata} metadata
@@ -462,7 +461,7 @@ class ComponentLoader {
462
461
  });
463
462
  }
464
463
  if (callback) {
465
- Platform_1.deprecated('Providing a callback to ComponentLoader.setSource is deprecated, use Promises');
464
+ (0, Platform_js_1.deprecated)('Providing a callback to ComponentLoader.setSource is deprecated, use Promises');
466
465
  promise.then(() => {
467
466
  callback(null);
468
467
  }, callback);
@@ -502,7 +501,7 @@ class ComponentLoader {
502
501
  });
503
502
  }
504
503
  if (callback) {
505
- Platform_1.deprecated('Providing a callback to ComponentLoader.getSource is deprecated, use Promises');
504
+ (0, Platform_js_1.deprecated)('Providing a callback to ComponentLoader.getSource is deprecated, use Promises');
506
505
  promise.then((source) => {
507
506
  callback(null, source);
508
507
  }, callback);
package/lib/IP.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @typedef {Object<string, boolean|string>} IPOptions
3
+ */
1
4
  export default class IP {
2
5
  /**
3
6
  * @param {any} obj
@@ -7,18 +10,16 @@ export default class IP {
7
10
  /**
8
11
  * @param {string} type
9
12
  * @param {any} data
10
- * @param {Object<string, boolean|string>} [options]
13
+ * @param {IPOptions} [options]
11
14
  */
12
- constructor(type: string, data?: any, options?: {
13
- [x: string]: boolean | string;
14
- });
15
+ constructor(type: string, data?: any, options?: IPOptions);
15
16
  type: string;
16
17
  data: any;
17
18
  isIP: boolean;
18
19
  /** @type {string|null} */
19
20
  scope: string | null;
20
- /** @type {string|null} */
21
- owner: string | null;
21
+ /** @type {import("./Component").Component|null} */
22
+ owner: import("./Component").Component | null;
22
23
  clonable: boolean;
23
24
  /** @type {number|null} */
24
25
  index: number | null;
@@ -30,8 +31,11 @@ export default class IP {
30
31
  */
31
32
  clone(): IP;
32
33
  /**
33
- * @param {string|null} owner
34
+ * @param {import("./Component").Component|null} owner
34
35
  */
35
- move(owner: string | null): IP;
36
+ move(owner: import("./Component").Component | null): IP;
36
37
  drop(): void;
37
38
  }
39
+ export type IPOptions = {
40
+ [x: string]: boolean | string;
41
+ };
package/lib/IP.js CHANGED
@@ -26,6 +26,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  // - 'data'
27
27
  // - 'openBracket'
28
28
  // - 'closeBracket'
29
+ /**
30
+ * @typedef {Object<string, boolean|string>} IPOptions
31
+ */
29
32
  class IP {
30
33
  // Detects if an arbitrary value is an IP
31
34
  /**
@@ -40,7 +43,7 @@ class IP {
40
43
  /**
41
44
  * @param {string} type
42
45
  * @param {any} data
43
- * @param {Object<string, boolean|string>} [options]
46
+ * @param {IPOptions} [options]
44
47
  */
45
48
  constructor(type, data = null, options = {}) {
46
49
  this.type = type || 'data';
@@ -48,7 +51,7 @@ class IP {
48
51
  this.isIP = true;
49
52
  /** @type {string|null} */
50
53
  this.scope = null; // sync scope id
51
- /** @type {string|null} */
54
+ /** @type {import("./Component").Component|null} */
52
55
  this.owner = null; // packet owner process
53
56
  this.clonable = false; // cloning safety flag
54
57
  /** @type {number|null} */
@@ -59,7 +62,6 @@ class IP {
59
62
  if (typeof options === 'object') {
60
63
  Object.keys(options).forEach((key) => { this[key] = options[key]; });
61
64
  }
62
- return this;
63
65
  }
64
66
  // Creates a new IP copying its contents by value not reference
65
67
  /**
@@ -86,7 +88,7 @@ class IP {
86
88
  }
87
89
  // Moves an IP to a different owner
88
90
  /**
89
- * @param {string|null} owner
91
+ * @param {import("./Component").Component|null} owner
90
92
  */
91
93
  move(owner) {
92
94
  // no-op
package/lib/InPort.d.ts CHANGED
@@ -1,7 +1,35 @@
1
+ /**
2
+ * @typedef InPortOptions
3
+ * @property {any} [default]
4
+ * @property {Array<any>} [values]
5
+ * @property {boolean} [control]
6
+ * @property {boolean} [triggering]
7
+ */
8
+ /**
9
+ * @callback HasValidationCallback
10
+ * @param {import("./IP").default} ip
11
+ * @returns {boolean}
12
+ */
13
+ /**
14
+ * @typedef {import("./BasePort").BaseOptions & InPortOptions} PortOptions
15
+ */
1
16
  export default class InPort extends BasePort {
2
- constructor(options?: {});
3
- handleIP(packet: any, index: any): void;
4
- handleSocketEvent(event: any, payload: any, id: any): boolean;
17
+ /**
18
+ * @param {PortOptions} [options]
19
+ */
20
+ constructor(options?: PortOptions);
21
+ options: PortOptions;
22
+ /**
23
+ * @param {import("./IP").default} packet
24
+ * @param {number|null} [index]
25
+ */
26
+ handleIP(packet: import("./IP").default, index?: number | null): void;
27
+ /**
28
+ * @param {string} event
29
+ * @param {any} payload
30
+ * @param {number} [id]
31
+ */
32
+ handleSocketEvent(event: string, payload: any, id?: number): boolean;
5
33
  hasDefault(): boolean;
6
34
  prepareBuffer(): void;
7
35
  /** @type {Object<string,Object<number,Array<import("./IP").default>>>} */
@@ -31,6 +59,9 @@ export default class InPort extends BasePort {
31
59
  * @returns {Array<import("./IP").default>}
32
60
  */
33
61
  prepareBufferForIP(ip: import("./IP").default): Array<import("./IP").default>;
62
+ /**
63
+ * @param {any} data
64
+ */
34
65
  validateData(data: any): void;
35
66
  /**
36
67
  * @param {string|null} scope
@@ -46,12 +77,52 @@ export default class InPort extends BasePort {
46
77
  * @returns {import("./IP").default|void}
47
78
  */
48
79
  getFromBuffer(scope: string | null, index: number | null, initial?: boolean): import("./IP").default | void;
49
- get(scope: any, index: any): void | import("./IP").default;
50
- hasIPinBuffer(scope: any, index: any, validate: any, initial?: boolean): boolean;
51
- hasIIP(index: any, validate: any): boolean;
52
- has(scope: any, index: any, validate: any): boolean;
53
- length(scope: any, index: any): number;
54
- ready(scope: any): boolean;
80
+ /**
81
+ * Fetches a packet from the port
82
+ * @param {string|null} scope
83
+ * @param {number|null} [index]
84
+ */
85
+ get(scope: string | null, index?: number | null): void | import("./IP").default;
86
+ /**
87
+ * Fetches a packet from the port
88
+ * @param {string|null} scope
89
+ * @param {number|null} index
90
+ * @param {HasValidationCallback} validate
91
+ * @param {boolean} [initial]
92
+ */
93
+ hasIPinBuffer(scope: string | null, index: number | null, validate: HasValidationCallback, initial?: boolean): boolean;
94
+ /**
95
+ * @param {number|null} index
96
+ * @param {HasValidationCallback} validate
97
+ */
98
+ hasIIP(index: number | null, validate: HasValidationCallback): boolean;
99
+ /**
100
+ * Returns true if port contains packet(s) matching the validator
101
+ * @param {string|null} scope
102
+ * @param {number|null|HasValidationCallback} index
103
+ * @param {HasValidationCallback} [validate]
104
+ */
105
+ has(scope: string | null, index: number | null | HasValidationCallback, validate?: HasValidationCallback): boolean;
106
+ /**
107
+ * Returns the number of data packets in an inport
108
+ * @param {string|null} scope
109
+ * @param {number|null} [index]
110
+ * @returns {number}
111
+ */
112
+ length(scope: string | null, index?: number | null): number;
113
+ /**
114
+ * Tells if buffer has packets or not
115
+ * @param {string|null} scope
116
+ */
117
+ ready(scope: string | null): boolean;
55
118
  clear(): void;
56
119
  }
57
- import BasePort from "./BasePort";
120
+ export type InPortOptions = {
121
+ default?: any;
122
+ values?: Array<any>;
123
+ control?: boolean;
124
+ triggering?: boolean;
125
+ };
126
+ export type HasValidationCallback = (ip: import("./IP").default) => boolean;
127
+ export type PortOptions = import("./BasePort").BaseOptions & InPortOptions;
128
+ import BasePort from "./BasePort.js";