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.
- package/.ecrc +3 -0
- package/.eslintignore +2 -0
- package/{CHANGES.md → CHANGELOG.md} +527 -527
- package/README.md +1 -1
- package/bin/noflo-cache-preheat +4 -4
- package/components/Graph.d.ts +50 -15
- package/components/Graph.js +94 -68
- package/examples/http/HelloController.js +9 -6
- package/examples/spreadsheet/parse.fbp +3 -3
- package/lib/AsCallback.d.ts +22 -9
- package/lib/AsCallback.js +69 -18
- package/lib/AsComponent.d.ts +1 -1
- package/lib/AsComponent.js +5 -3
- package/lib/BaseNetwork.d.ts +16 -6
- package/lib/BaseNetwork.js +65 -31
- package/lib/BasePort.d.ts +39 -12
- package/lib/BasePort.js +34 -6
- package/lib/Component.d.ts +8 -8
- package/lib/Component.js +23 -20
- package/lib/ComponentLoader.d.ts +3 -4
- package/lib/ComponentLoader.js +9 -10
- package/lib/IP.d.ts +12 -8
- package/lib/IP.js +6 -4
- package/lib/InPort.d.ts +64 -9
- package/lib/InPort.js +72 -13
- package/lib/InternalSocket.d.ts +53 -7
- package/lib/InternalSocket.js +51 -14
- package/lib/LegacyNetwork.d.ts +12 -2
- package/lib/LegacyNetwork.js +5 -5
- package/lib/Network.d.ts +13 -2
- package/lib/Network.js +10 -10
- package/lib/NoFlo.d.ts +48 -13
- package/lib/NoFlo.js +55 -27
- package/lib/OutPort.d.ts +64 -13
- package/lib/OutPort.js +73 -15
- package/lib/Platform.d.ts +1 -1
- package/lib/Platform.js +9 -4
- package/lib/Ports.d.ts +11 -12
- package/lib/Ports.js +8 -4
- package/lib/ProcessInput.d.ts +5 -9
- package/lib/ProcessInput.js +8 -9
- package/lib/ProcessOutput.d.ts +2 -2
- package/lib/ProcessOutput.js +5 -5
- package/lib/loader/NodeJs.d.ts +0 -1
- package/lib/loader/NodeJs.js +152 -161
- package/lib/loader/register.d.ts +1 -1
- package/lib/loader/register.js +8 -4
- package/package.json +25 -16
- package/spec/.eslintrc +5 -2
- package/spec/AsCallback.js +9 -13
- package/spec/AsComponent.js +10 -4
- package/spec/AsPromise.js +38 -0
- package/spec/CommonJS.cjs +10 -0
- package/spec/ComponentLoader.js +19 -7
- package/spec/ESModule.mjs +11 -0
- package/spec/Network.js +32 -11
- package/spec/NetworkSync.js +892 -0
- package/spec/Scoping.js +27 -42
- package/spec/Subgraph.js +6 -11
- package/spec/fixtures/componentloader/components/Output.js +1 -1
- package/spec/fixtures/componentloader/components/Repeat.ts +1 -1
- package/spec/fixtures/componentloader/components/RepeatAsync.coffee +1 -1
- package/spec/fixtures/componentloader/node_modules/example/components/Forward.js +1 -1
- package/spec/fixtures/componentloader/node_modules/example/package.json +1 -1
- package/spec/fixtures/componentloader/package.json +2 -1
- package/spec/fixtures/componentloader/spec/Repeat.yaml +1 -1
- package/spec/utils/inject.js +1 -1
- package/src/.eslintrc +9 -2
- package/src/components/Graph.js +105 -71
- package/src/lib/AsCallback.js +71 -16
- package/src/lib/AsComponent.js +5 -4
- package/src/lib/BaseNetwork.js +48 -15
- package/src/lib/BasePort.js +43 -9
- package/src/lib/Component.js +8 -8
- package/src/lib/ComponentLoader.js +3 -4
- package/src/lib/IP.js +7 -4
- package/src/lib/InPort.js +74 -13
- package/src/lib/InternalSocket.js +49 -9
- package/src/lib/LegacyNetwork.js +2 -2
- package/src/lib/Network.js +2 -2
- package/src/lib/NoFlo.js +43 -13
- package/src/lib/OutPort.js +77 -14
- package/src/lib/Platform.js +9 -4
- package/src/lib/Ports.js +6 -2
- package/src/lib/ProcessInput.js +7 -9
- package/src/lib/ProcessOutput.js +1 -1
- package/src/lib/loader/NodeJs.js +185 -178
- package/src/lib/loader/register.js +2 -2
- /package/{karma.config.js → karma.config.cjs} +0 -0
- /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
|
-
|
|
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
|
-
|
|
113
|
-
|
|
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
|
-
|
|
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) => {
|
package/lib/Component.d.ts
CHANGED
|
@@ -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
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
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
|
|
72
|
+
if (opts.inPorts instanceof Ports_js_1.InPorts) {
|
|
70
73
|
this.inPorts = opts.inPorts;
|
|
71
74
|
}
|
|
72
75
|
else {
|
|
73
|
-
this.inPorts = new
|
|
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
|
|
85
|
+
if (opts.outPorts instanceof Ports_js_1.OutPorts) {
|
|
83
86
|
this.outPorts = opts.outPorts;
|
|
84
87
|
}
|
|
85
88
|
else {
|
|
86
|
-
this.outPorts = new
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
510
|
-
const input = new
|
|
511
|
-
const output = new
|
|
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 } =
|
|
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 } =
|
|
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 } =
|
|
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
|
package/lib/ComponentLoader.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
|
|
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 |
|
|
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";
|
package/lib/ComponentLoader.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
21
|
-
owner:
|
|
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 {
|
|
34
|
+
* @param {import("./Component").Component|null} owner
|
|
34
35
|
*/
|
|
35
|
-
move(owner:
|
|
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 {
|
|
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 {
|
|
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 {
|
|
91
|
+
* @param {import("./Component").Component|null} owner
|
|
90
92
|
*/
|
|
91
93
|
move(owner) {
|
|
92
94
|
// no-op
|
package/lib/InPort.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef InPortOptions
|
|
3
|
+
* @property {any} [default]
|
|
4
|
+
* @property {Array<any>} [values]
|
|
3
5
|
* @property {boolean} [control]
|
|
4
6
|
* @property {boolean} [triggering]
|
|
5
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* @callback HasValidationCallback
|
|
10
|
+
* @param {import("./IP").default} ip
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
6
13
|
/**
|
|
7
14
|
* @typedef {import("./BasePort").BaseOptions & InPortOptions} PortOptions
|
|
8
15
|
*/
|
|
@@ -11,8 +18,18 @@ export default class InPort extends BasePort {
|
|
|
11
18
|
* @param {PortOptions} [options]
|
|
12
19
|
*/
|
|
13
20
|
constructor(options?: PortOptions);
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
33
|
hasDefault(): boolean;
|
|
17
34
|
prepareBuffer(): void;
|
|
18
35
|
/** @type {Object<string,Object<number,Array<import("./IP").default>>>} */
|
|
@@ -42,6 +59,9 @@ export default class InPort extends BasePort {
|
|
|
42
59
|
* @returns {Array<import("./IP").default>}
|
|
43
60
|
*/
|
|
44
61
|
prepareBufferForIP(ip: import("./IP").default): Array<import("./IP").default>;
|
|
62
|
+
/**
|
|
63
|
+
* @param {any} data
|
|
64
|
+
*/
|
|
45
65
|
validateData(data: any): void;
|
|
46
66
|
/**
|
|
47
67
|
* @param {string|null} scope
|
|
@@ -57,17 +77,52 @@ export default class InPort extends BasePort {
|
|
|
57
77
|
* @returns {import("./IP").default|void}
|
|
58
78
|
*/
|
|
59
79
|
getFromBuffer(scope: string | null, index: number | null, initial?: boolean): import("./IP").default | void;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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;
|
|
66
118
|
clear(): void;
|
|
67
119
|
}
|
|
68
120
|
export type InPortOptions = {
|
|
121
|
+
default?: any;
|
|
122
|
+
values?: Array<any>;
|
|
69
123
|
control?: boolean;
|
|
70
124
|
triggering?: boolean;
|
|
71
125
|
};
|
|
126
|
+
export type HasValidationCallback = (ip: import("./IP").default) => boolean;
|
|
72
127
|
export type PortOptions = import("./BasePort").BaseOptions & InPortOptions;
|
|
73
|
-
import BasePort from "./BasePort";
|
|
128
|
+
import BasePort from "./BasePort.js";
|