@weave-js/core 0.11.1 → 0.12.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.
- package/.eslintrc.js +1 -1
- package/jest.config.js +1 -1
- package/lib/ExtendableError.js +7 -7
- package/lib/broker/context.js +49 -49
- package/lib/broker/defaultOptions.js +8 -9
- package/lib/broker/index.js +160 -164
- package/lib/buildRuntime.js +34 -34
- package/lib/cache/adapters/base.js +50 -74
- package/lib/cache/adapters/inMemory.js +58 -58
- package/lib/cache/adapters/inMemoryLru.js +57 -57
- package/lib/cache/adapters/index.js +3 -39
- package/lib/cache/getCacheKeyByObject.js +31 -0
- package/lib/cache/getPropertyFromDataOrMetadata.js +20 -0
- package/lib/cache/lock.js +30 -24
- package/lib/constants.js +5 -5
- package/lib/errorHandler.js +8 -8
- package/lib/errors.js +35 -35
- package/lib/helper/defineAction.js +2 -2
- package/lib/helper/defineBrokerOptions.js +2 -2
- package/lib/helper/defineService.js +2 -2
- package/lib/index.js +21 -21
- package/lib/logger/base.js +38 -29
- package/lib/logger/format/asHumanReadable.js +15 -15
- package/lib/logger/format/asJson.js +10 -10
- package/lib/logger/format/index.js +3 -3
- package/lib/logger/index.js +24 -24
- package/lib/logger/levels.js +21 -21
- package/lib/logger/tools.js +15 -15
- package/lib/logger/utils/colorize.js +23 -23
- package/lib/logger/utils/format.js +75 -65
- package/lib/metrics/common.js +47 -47
- package/lib/metrics/constants.js +44 -44
- package/lib/metrics/exporter/base.js +8 -8
- package/lib/metrics/exporter/event.js +20 -20
- package/lib/metrics/exporter/index.js +15 -15
- package/lib/metrics/index.js +2 -2
- package/lib/metrics/types/base.js +20 -20
- package/lib/metrics/types/counter.js +6 -6
- package/lib/metrics/types/gauge.js +24 -24
- package/lib/metrics/types/histogram.js +26 -26
- package/lib/metrics/types/index.js +6 -6
- package/lib/metrics/types/info.js +17 -17
- package/lib/middlewares/action-hooks/index.js +38 -38
- package/lib/middlewares/bulkhead/index.js +34 -34
- package/lib/middlewares/cache/index.js +37 -37
- package/lib/middlewares/circuit-breaker/index.js +62 -62
- package/lib/middlewares/context-tracker/index.js +39 -39
- package/lib/middlewares/error-handler/index.js +14 -14
- package/lib/middlewares/index.js +2 -2
- package/lib/middlewares/metrics/getMiddlewareWrapper.js +17 -17
- package/lib/middlewares/metrics/index.js +29 -29
- package/lib/middlewares/retry/index.js +15 -15
- package/lib/middlewares/timeout/index.js +16 -16
- package/lib/middlewares/tracing/index.js +37 -37
- package/lib/middlewares/tracing/tags.js +6 -6
- package/lib/middlewares/validator/index.js +31 -31
- package/lib/registry/actionEndpoint.js +8 -8
- package/lib/registry/collections/actionCollection.js +39 -35
- package/lib/registry/collections/endpointCollection.js +63 -63
- package/lib/registry/collections/eventCollection.js +62 -62
- package/lib/registry/collections/nodeCollection.js +45 -45
- package/lib/registry/collections/serviceCollection.js +61 -55
- package/lib/registry/eventEndpoint.js +14 -14
- package/lib/registry/load-balancer/base.js +3 -3
- package/lib/registry/load-balancer/index.js +7 -7
- package/lib/registry/node.js +27 -27
- package/lib/registry/registry.js +139 -136
- package/lib/registry/service/parseAction.js +16 -16
- package/lib/registry/service/parseEvent.js +18 -18
- package/lib/registry/service/reduceMixins.js +10 -10
- package/lib/registry/service/service.js +72 -72
- package/lib/registry/serviceItem.js +21 -21
- package/lib/runtime/initActionInvoker.js +21 -21
- package/lib/runtime/initCache.js +7 -7
- package/lib/runtime/initContextFactory.js +22 -22
- package/lib/runtime/initEventbus.js +49 -49
- package/lib/runtime/initLogger.js +11 -11
- package/lib/runtime/initMetrics.js +54 -54
- package/lib/runtime/initMiddlewareManager.js +21 -21
- package/lib/runtime/initRegistry.js +6 -6
- package/lib/runtime/initServiceManager.js +85 -68
- package/lib/runtime/initTracing.js +23 -23
- package/lib/runtime/initTransport.js +5 -5
- package/lib/runtime/initUuidFactory.js +4 -4
- package/lib/runtime/initValidator.js +5 -5
- package/lib/tracing/collectors/base.js +22 -22
- package/lib/tracing/collectors/event.js +33 -33
- package/lib/tracing/collectors/index.js +15 -15
- package/lib/tracing/span.js +26 -26
- package/lib/tracing/time.js +8 -8
- package/lib/transport/InboundTransformStream.js +26 -26
- package/lib/transport/adapters/adapteBase.js +30 -30
- package/lib/transport/adapters/adapters.js +4 -4
- package/lib/transport/adapters/dummy/index.js +18 -18
- package/lib/transport/adapters/fromURI.js +13 -13
- package/lib/transport/adapters/getAdapterByName.js +5 -5
- package/lib/transport/adapters/index.js +12 -12
- package/lib/transport/adapters/tcp/discovery/codec.js +4 -4
- package/lib/transport/adapters/tcp/discovery/index.js +62 -62
- package/lib/transport/adapters/tcp/index.js +169 -171
- package/lib/transport/adapters/tcp/tcp-messagetypes.js +7 -7
- package/lib/transport/adapters/tcp/tcpReader.js +39 -39
- package/lib/transport/adapters/tcp/tcpWriteStream.js +26 -26
- package/lib/transport/adapters/tcp/tcpWriter.js +57 -57
- package/lib/transport/adapters/tcp/utils.js +12 -12
- package/lib/transport/createMessage.js +4 -4
- package/lib/transport/createTransport.js +254 -254
- package/lib/transport/errorPayloadFactory.js +14 -17
- package/lib/transport/messageHandlers.js +200 -200
- package/lib/transport/messageTypes.js +19 -19
- package/lib/types.js +28 -15
- package/lib/utils/index.js +1 -1
- package/lib/utils/options.js +44 -44
- package/lib/utils/restoreError.js +4 -4
- package/package.json +4 -4
- package/lib/cache/base.js +0 -136
package/lib/tracing/span.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const hrTime = require('./time')
|
|
1
|
+
const hrTime = require('./time');
|
|
2
2
|
|
|
3
3
|
exports.createSpan = (tracer, name, options) => {
|
|
4
4
|
const span = Object.assign({}, {
|
|
@@ -10,54 +10,54 @@ exports.createSpan = (tracer, name, options) => {
|
|
|
10
10
|
sampled: options.sampled || tracer.shouldSample(),
|
|
11
11
|
service: options.service,
|
|
12
12
|
tags: {}
|
|
13
|
-
})
|
|
13
|
+
});
|
|
14
14
|
|
|
15
15
|
if (options.service) {
|
|
16
16
|
span.service = {
|
|
17
17
|
name: options.service.name,
|
|
18
18
|
version: options.service.version,
|
|
19
19
|
fullyQualifiedName: options.service.fullyQualifiedName
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
span.addTags = (tags) => {
|
|
24
|
-
Object.assign(span.tags, tags)
|
|
25
|
-
return span
|
|
26
|
-
}
|
|
24
|
+
Object.assign(span.tags, tags);
|
|
25
|
+
return span;
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
span.start = (time) => {
|
|
29
|
-
span.startTime = time || hrTime()
|
|
30
|
-
tracer.invokeCollectorMethod('startedSpan', [span])
|
|
31
|
-
return span
|
|
32
|
-
}
|
|
29
|
+
span.startTime = time || hrTime();
|
|
30
|
+
tracer.invokeCollectorMethod('startedSpan', [span]);
|
|
31
|
+
return span;
|
|
32
|
+
};
|
|
33
33
|
|
|
34
34
|
span.startChildSpan = (name, options) => {
|
|
35
35
|
const parentOptions = {
|
|
36
36
|
parentId: options.parentId,
|
|
37
37
|
sampled: options.sampled
|
|
38
|
-
}
|
|
39
|
-
return tracer.startSpan(name, Object.assign(parentOptions, options))
|
|
40
|
-
}
|
|
38
|
+
};
|
|
39
|
+
return tracer.startSpan(name, Object.assign(parentOptions, options));
|
|
40
|
+
};
|
|
41
41
|
|
|
42
42
|
span.finish = (time) => {
|
|
43
|
-
span.finishTime = time || hrTime()
|
|
44
|
-
span.duration = span.finishTime - span.startTime
|
|
45
|
-
tracer.log.debug('Span finished')
|
|
46
|
-
tracer.invokeCollectorMethod('finishedSpan', [span])
|
|
43
|
+
span.finishTime = time || hrTime();
|
|
44
|
+
span.duration = span.finishTime - span.startTime;
|
|
45
|
+
tracer.log.debug('Span finished');
|
|
46
|
+
tracer.invokeCollectorMethod('finishedSpan', [span]);
|
|
47
47
|
|
|
48
|
-
return span
|
|
49
|
-
}
|
|
48
|
+
return span;
|
|
49
|
+
};
|
|
50
50
|
|
|
51
|
-
span.isActive = () => span.finishTime !== null
|
|
51
|
+
span.isActive = () => span.finishTime !== null;
|
|
52
52
|
|
|
53
53
|
span.setError = (error) => {
|
|
54
|
-
span.error = error
|
|
55
|
-
return span
|
|
56
|
-
}
|
|
54
|
+
span.error = error;
|
|
55
|
+
return span;
|
|
56
|
+
};
|
|
57
57
|
|
|
58
58
|
if (options.tags) {
|
|
59
|
-
span.addTags(options.tags)
|
|
59
|
+
span.addTags(options.tags);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
return span
|
|
63
|
-
}
|
|
62
|
+
return span;
|
|
63
|
+
};
|
package/lib/tracing/time.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
const loadTime = getNanoSeconds()
|
|
2
|
-
const nodeLoadTime = loadTime - process.uptime() * 1e9
|
|
1
|
+
const loadTime = getNanoSeconds();
|
|
2
|
+
const nodeLoadTime = loadTime - process.uptime() * 1e9;
|
|
3
3
|
|
|
4
4
|
function getNanoSeconds () {
|
|
5
|
-
const time = process.hrtime()
|
|
6
|
-
return time[0] * 1e9 + time[1]
|
|
5
|
+
const time = process.hrtime();
|
|
6
|
+
return time[0] * 1e9 + time[1];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function now () {
|
|
10
|
-
return (getNanoSeconds() - nodeLoadTime) / 1e6
|
|
10
|
+
return (getNanoSeconds() - nodeLoadTime) / 1e6;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const loadNs = now()
|
|
14
|
-
const loadMs = Date.now()
|
|
13
|
+
const loadNs = now();
|
|
14
|
+
const loadMs = Date.now();
|
|
15
15
|
|
|
16
|
-
module.exports = () => loadMs + now() - loadNs
|
|
16
|
+
module.exports = () => loadMs + now() - loadNs;
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
const { Transform } = require('stream')
|
|
1
|
+
const { Transform } = require('stream');
|
|
2
2
|
|
|
3
3
|
const pushWithBackpressure = (stream, chunks, encoding, callback = null, $index = 0) => {
|
|
4
4
|
if (!(stream instanceof Transform)) {
|
|
5
|
-
throw new TypeError('Argument "stream" must be an instance of Duplex')
|
|
5
|
+
throw new TypeError('Argument "stream" must be an instance of Duplex');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
chunks = [].concat(chunks).filter(x => x !== undefined)
|
|
8
|
+
chunks = [].concat(chunks).filter(x => x !== undefined);
|
|
9
9
|
|
|
10
10
|
if (typeof encoding === 'function') {
|
|
11
|
-
callback = encoding
|
|
12
|
-
encoding = undefined
|
|
11
|
+
callback = encoding;
|
|
12
|
+
encoding = undefined;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if ($index >= chunks.length) {
|
|
16
16
|
if (typeof callback === 'function') {
|
|
17
|
-
callback()
|
|
17
|
+
callback();
|
|
18
18
|
}
|
|
19
|
-
return stream
|
|
19
|
+
return stream;
|
|
20
20
|
} else if (!stream.push(chunks[$index], ...([encoding].filter(Boolean)))) {
|
|
21
21
|
stream.emit('backpressure', {
|
|
22
22
|
sender: stream.sender,
|
|
23
23
|
requestId: stream.requestId
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
|
|
26
26
|
const pipedStreams = [].concat(
|
|
27
27
|
(stream._readableState || {}).pipes || stream
|
|
28
|
-
).filter(Boolean)
|
|
28
|
+
).filter(Boolean);
|
|
29
29
|
|
|
30
|
-
let listenerCalled = false
|
|
30
|
+
let listenerCalled = false;
|
|
31
31
|
|
|
32
32
|
const drainListener = () => {
|
|
33
33
|
stream.emit('resume_backpressure', {
|
|
34
34
|
sender: stream.sender,
|
|
35
35
|
requestId: stream.requestId
|
|
36
|
-
})
|
|
36
|
+
});
|
|
37
37
|
|
|
38
38
|
if (listenerCalled) {
|
|
39
|
-
return
|
|
39
|
+
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
listenerCalled = true
|
|
42
|
+
listenerCalled = true;
|
|
43
43
|
|
|
44
44
|
for (const stream of pipedStreams) {
|
|
45
|
-
stream.removeListener('drain', drainListener)
|
|
45
|
+
stream.removeListener('drain', drainListener);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
pushWithBackpressure(stream, chunks, encoding, callback, $index + 1)
|
|
49
|
-
}
|
|
48
|
+
pushWithBackpressure(stream, chunks, encoding, callback, $index + 1);
|
|
49
|
+
};
|
|
50
50
|
|
|
51
51
|
for (const stream of pipedStreams) {
|
|
52
|
-
stream.once('drain', drainListener)
|
|
52
|
+
stream.once('drain', drainListener);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
return stream
|
|
55
|
+
return stream;
|
|
56
56
|
}
|
|
57
|
-
return pushWithBackpressure(stream, chunks, encoding, callback, $index + 1)
|
|
58
|
-
}
|
|
57
|
+
return pushWithBackpressure(stream, chunks, encoding, callback, $index + 1);
|
|
58
|
+
};
|
|
59
59
|
class InboundTransformStream extends Transform {
|
|
60
60
|
constructor (sender, requestId, options) {
|
|
61
|
-
super(options)
|
|
62
|
-
this.sender = sender
|
|
63
|
-
this.requestId = requestId
|
|
61
|
+
super(options);
|
|
62
|
+
this.sender = sender;
|
|
63
|
+
this.requestId = requestId;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
_transform (chunk, encoding, callback) {
|
|
67
|
-
pushWithBackpressure(this, chunk, encoding, callback)
|
|
67
|
+
pushWithBackpressure(this, chunk, encoding, callback);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
_flush (callback) {
|
|
71
|
-
return callback()
|
|
71
|
+
return callback();
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
module.exports = { InboundTransformStream }
|
|
75
|
+
module.exports = { InboundTransformStream };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Author: Kevin Ries (kevin@
|
|
2
|
+
* Author: Kevin Ries (kevin.ries@fachwerk.io)
|
|
3
3
|
* -----
|
|
4
4
|
* Copyright 2021 Fachwerk
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const EventEmitter = require('events').EventEmitter
|
|
7
|
+
const EventEmitter = require('events').EventEmitter;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {Object} AdapterBase
|
|
@@ -22,7 +22,7 @@ const EventEmitter = require('events').EventEmitter
|
|
|
22
22
|
* @returns {AdapterBase} Adapter base object
|
|
23
23
|
*/
|
|
24
24
|
const createTransportBase = () => {
|
|
25
|
-
let prefix = 'weave'
|
|
25
|
+
let prefix = 'weave';
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
name: null,
|
|
@@ -32,23 +32,23 @@ const createTransportBase = () => {
|
|
|
32
32
|
interruptCounter: 0,
|
|
33
33
|
repeatAttemptCounter: 0,
|
|
34
34
|
init (broker, transport, messageHandler) {
|
|
35
|
-
this.broker = broker
|
|
36
|
-
this.transport = transport
|
|
37
|
-
this.log = transport.log
|
|
38
|
-
this.messageHandler = messageHandler
|
|
35
|
+
this.broker = broker;
|
|
36
|
+
this.transport = transport;
|
|
37
|
+
this.log = transport.log;
|
|
38
|
+
this.messageHandler = messageHandler;
|
|
39
39
|
|
|
40
40
|
if (broker.options.namespace) {
|
|
41
|
-
prefix = `${prefix}-${broker.options.namespace}
|
|
41
|
+
prefix = `${prefix}-${broker.options.namespace}`;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (this.afterInit) {
|
|
45
|
-
this.afterInit()
|
|
45
|
+
this.afterInit();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return Promise.resolve()
|
|
48
|
+
return Promise.resolve();
|
|
49
49
|
},
|
|
50
50
|
subscribe () {
|
|
51
|
-
return Promise.resolve()
|
|
51
|
+
return Promise.resolve();
|
|
52
52
|
},
|
|
53
53
|
/**
|
|
54
54
|
*
|
|
@@ -59,49 +59,49 @@ const createTransportBase = () => {
|
|
|
59
59
|
* @returns {void}
|
|
60
60
|
*/
|
|
61
61
|
connected (connectionEventParams = {}) {
|
|
62
|
-
this.bus.emit('$adapter.connected', connectionEventParams)
|
|
62
|
+
this.bus.emit('$adapter.connected', connectionEventParams);
|
|
63
63
|
},
|
|
64
64
|
disconnected () {
|
|
65
|
-
this.bus.emit('$adapter.disconnected')
|
|
65
|
+
this.bus.emit('$adapter.disconnected');
|
|
66
66
|
},
|
|
67
67
|
getTopic (cmd, nodeId) {
|
|
68
|
-
const topic = prefix + '.' + cmd + (nodeId ? '.' + nodeId : '')
|
|
69
|
-
return topic
|
|
68
|
+
const topic = prefix + '.' + cmd + (nodeId ? '.' + nodeId : '');
|
|
69
|
+
return topic;
|
|
70
70
|
},
|
|
71
71
|
preSend (packet) {
|
|
72
|
-
return this.send(packet)
|
|
72
|
+
return this.send(packet);
|
|
73
73
|
},
|
|
74
74
|
send (/* message*/) {
|
|
75
|
-
this.broker.handleError(new Error('Method "send" not implemented.'))
|
|
75
|
+
this.broker.handleError(new Error('Method "send" not implemented.'));
|
|
76
76
|
},
|
|
77
77
|
incomingMessage (messageType, message) {
|
|
78
|
-
const data = this.deserialize(message)
|
|
79
|
-
this.updateStatisticReceived(message.length)
|
|
80
|
-
this.bus.emit('$adapter.message', messageType, data)
|
|
78
|
+
const data = this.deserialize(message);
|
|
79
|
+
this.updateStatisticReceived(message.length);
|
|
80
|
+
this.bus.emit('$adapter.message', messageType, data);
|
|
81
81
|
},
|
|
82
82
|
serialize (packet) {
|
|
83
83
|
try {
|
|
84
84
|
// Add the sender to each outgoing message
|
|
85
|
-
packet.payload.sender = this.broker.nodeId
|
|
86
|
-
return Buffer.from(JSON.stringify(packet))
|
|
85
|
+
packet.payload.sender = this.broker.nodeId;
|
|
86
|
+
return Buffer.from(JSON.stringify(packet));
|
|
87
87
|
} catch (error) {
|
|
88
|
-
this.broker.handleError(error)
|
|
88
|
+
this.broker.handleError(error);
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
deserialize (packet) {
|
|
92
92
|
try {
|
|
93
|
-
return JSON.parse(packet)
|
|
93
|
+
return JSON.parse(packet);
|
|
94
94
|
} catch (error) {
|
|
95
|
-
this.broker.handleError(error)
|
|
95
|
+
this.broker.handleError(error);
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
updateStatisticReceived (length) {
|
|
99
|
-
this.transport.statistics.received.packages += length
|
|
99
|
+
this.transport.statistics.received.packages += length;
|
|
100
100
|
},
|
|
101
101
|
updateStatisticSent (length) {
|
|
102
|
-
this.transport.statistics.sent.packages += length
|
|
102
|
+
this.transport.statistics.sent.packages += length;
|
|
103
103
|
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
106
|
|
|
107
|
-
module.exports = createTransportBase
|
|
107
|
+
module.exports = createTransportBase;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Author: Kevin Ries (kevin@
|
|
2
|
+
* Author: Kevin Ries (kevin.ries@fachwerk.io)
|
|
3
3
|
* -----
|
|
4
4
|
* Copyright 2019 Fachwerk
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
exports.BaseAdapter = require('./adapteBase')
|
|
8
|
-
exports.Dummy = require('./dummy')
|
|
9
|
-
exports.TCP = require('./tcp')
|
|
7
|
+
exports.BaseAdapter = require('./adapteBase');
|
|
8
|
+
exports.Dummy = require('./dummy');
|
|
9
|
+
exports.TCP = require('./tcp');
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Author: Kevin Ries (kevin@
|
|
2
|
+
* Author: Kevin Ries (kevin.ries@fachwerk.io)
|
|
3
3
|
* -----
|
|
4
4
|
* Copyright 2021 Fachwerk
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const TransportBase = require('../adapteBase')
|
|
8
|
-
const EventEmitter = require('eventemitter2').EventEmitter2
|
|
7
|
+
const TransportBase = require('../adapteBase');
|
|
8
|
+
const EventEmitter = require('eventemitter2').EventEmitter2;
|
|
9
9
|
|
|
10
10
|
// create a global eventbus to pass messages between weave service brokers.
|
|
11
11
|
global.bus = new EventEmitter({
|
|
12
12
|
wildcard: true,
|
|
13
13
|
maxListeners: 100
|
|
14
|
-
})
|
|
14
|
+
});
|
|
15
15
|
|
|
16
16
|
const DummyTransportAdapter = (adapterOptions) => {
|
|
17
|
-
const messageBus = global.bus
|
|
17
|
+
const messageBus = global.bus;
|
|
18
18
|
|
|
19
19
|
return Object.assign(TransportBase(adapterOptions), {
|
|
20
20
|
name: 'Dummy',
|
|
21
21
|
connect () {
|
|
22
|
-
this.bus.emit('$adapter.connected', false)
|
|
23
|
-
this.log.info('Dummy transport client connected.')
|
|
24
|
-
return Promise.resolve()
|
|
22
|
+
this.bus.emit('$adapter.connected', false);
|
|
23
|
+
this.log.info('Dummy transport client connected.');
|
|
24
|
+
return Promise.resolve();
|
|
25
25
|
},
|
|
26
26
|
close () {
|
|
27
|
-
return Promise.resolve()
|
|
27
|
+
return Promise.resolve();
|
|
28
28
|
},
|
|
29
29
|
send (message) {
|
|
30
|
-
const data = this.serialize(message)
|
|
31
|
-
const topic = this.getTopic(message.type, message.targetNodeId)
|
|
32
|
-
messageBus.emit(topic, data)
|
|
33
|
-
return Promise.resolve()
|
|
30
|
+
const data = this.serialize(message);
|
|
31
|
+
const topic = this.getTopic(message.type, message.targetNodeId);
|
|
32
|
+
messageBus.emit(topic, data);
|
|
33
|
+
return Promise.resolve();
|
|
34
34
|
},
|
|
35
35
|
subscribe (type, nodeId) {
|
|
36
|
-
const topic = this.getTopic(type, nodeId)
|
|
37
|
-
messageBus.on(topic, message => this.incomingMessage(type, message))
|
|
36
|
+
const topic = this.getTopic(type, nodeId);
|
|
37
|
+
messageBus.on(topic, message => this.incomingMessage(type, message));
|
|
38
38
|
}
|
|
39
|
-
})
|
|
40
|
-
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
41
|
|
|
42
|
-
module.exports = DummyTransportAdapter
|
|
42
|
+
module.exports = DummyTransportAdapter;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Author: Kevin Ries (kevin@
|
|
2
|
+
* Author: Kevin Ries (kevin.ries@fachwerk.io)
|
|
3
3
|
* -----
|
|
4
4
|
* Copyright 2019 Fachwerk
|
|
5
5
|
*/
|
|
6
|
-
const { parse } = require('url')
|
|
7
|
-
const getAdapterByName = require('./getAdapterByName')
|
|
6
|
+
const { parse } = require('url');
|
|
7
|
+
const getAdapterByName = require('./getAdapterByName');
|
|
8
8
|
|
|
9
9
|
function fromURI (uri) {
|
|
10
10
|
if (typeof uri !== 'string') {
|
|
11
|
-
throw new Error('URI needs to be a string.')
|
|
11
|
+
throw new Error('URI needs to be a string.');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const urlObject = parse(uri)
|
|
14
|
+
const urlObject = parse(uri);
|
|
15
15
|
|
|
16
16
|
if (!urlObject.protocol) {
|
|
17
|
-
throw new Error('Protocol is missing.')
|
|
17
|
+
throw new Error('Protocol is missing.');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const name = urlObject.protocol.slice(0, -1).toLowerCase()
|
|
20
|
+
const name = urlObject.protocol.slice(0, -1).toLowerCase();
|
|
21
21
|
|
|
22
|
-
const AdapterFactory = getAdapterByName(name)
|
|
22
|
+
const AdapterFactory = getAdapterByName(name);
|
|
23
23
|
|
|
24
24
|
if (!AdapterFactory) {
|
|
25
|
-
throw new Error('No adapter found.')
|
|
25
|
+
throw new Error('No adapter found.');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
let config = null
|
|
28
|
+
let config = null;
|
|
29
29
|
if (AdapterFactory.uriToConfig) {
|
|
30
|
-
config = AdapterFactory.uriToConfig(urlObject)
|
|
30
|
+
config = AdapterFactory.uriToConfig(urlObject);
|
|
31
31
|
}
|
|
32
|
-
return AdapterFactory(config)
|
|
32
|
+
return AdapterFactory(config);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
module.exports = fromURI
|
|
35
|
+
module.exports = fromURI;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const adapters = require('./adapters')
|
|
1
|
+
const adapters = require('./adapters');
|
|
2
2
|
|
|
3
3
|
module.exports = name => {
|
|
4
4
|
if (!name) {
|
|
5
|
-
return
|
|
5
|
+
return;
|
|
6
6
|
}
|
|
7
|
-
const foundAdapterName = Object.keys(adapters).find(adapter => adapter.toLowerCase() === name.toLowerCase())
|
|
7
|
+
const foundAdapterName = Object.keys(adapters).find(adapter => adapter.toLowerCase() === name.toLowerCase());
|
|
8
8
|
if (foundAdapterName) {
|
|
9
|
-
return adapters[foundAdapterName]
|
|
9
|
+
return adapters[foundAdapterName];
|
|
10
10
|
}
|
|
11
|
-
}
|
|
11
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Author: Kevin Ries (kevin@
|
|
2
|
+
* Author: Kevin Ries (kevin.ries@fachwerk.io)
|
|
3
3
|
* -----
|
|
4
4
|
* Copyright 2021 Fachwerk
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { WeaveBrokerOptionsError } = require('../../errors')
|
|
8
|
-
const fromURI = require('./fromURI')
|
|
9
|
-
const getAdapterByName = require('./getAdapterByName')
|
|
10
|
-
const adapters = require('./adapters')
|
|
7
|
+
const { WeaveBrokerOptionsError } = require('../../errors');
|
|
8
|
+
const fromURI = require('./fromURI');
|
|
9
|
+
const getAdapterByName = require('./getAdapterByName');
|
|
10
|
+
const adapters = require('./adapters');
|
|
11
11
|
|
|
12
12
|
const resolve = (broker, options) => {
|
|
13
13
|
if (typeof options === 'object') {
|
|
14
14
|
if (typeof options.adapter === 'string') {
|
|
15
|
-
const Adapter = getAdapterByName(options.adapter)
|
|
15
|
+
const Adapter = getAdapterByName(options.adapter);
|
|
16
16
|
|
|
17
17
|
if (Adapter) {
|
|
18
|
-
return Adapter(options.options)
|
|
18
|
+
return Adapter(options.options);
|
|
19
19
|
} else {
|
|
20
|
-
broker.handleError(new WeaveBrokerOptionsError(`Invalid transport settings: ${options.adapter}`))
|
|
20
|
+
broker.handleError(new WeaveBrokerOptionsError(`Invalid transport settings: ${options.adapter}`));
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
return options.adapter
|
|
23
|
+
return options.adapter;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return null
|
|
27
|
-
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
28
|
|
|
29
|
-
module.exports = Object.assign({ resolve, fromURI }, adapters)
|
|
29
|
+
module.exports = Object.assign({ resolve, fromURI }, adapters);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module.exports = function createCodec (options) {
|
|
2
2
|
return {
|
|
3
3
|
encode (object) {
|
|
4
|
-
return Buffer.from(JSON.stringify(object))
|
|
4
|
+
return Buffer.from(JSON.stringify(object));
|
|
5
5
|
},
|
|
6
6
|
decode (buffer) {
|
|
7
|
-
return JSON.parse(buffer.toString())
|
|
7
|
+
return JSON.parse(buffer.toString());
|
|
8
8
|
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
9
|
+
};
|
|
10
|
+
};
|