@weave-js/core 0.10.0 → 0.11.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/lib/ExtendableError.js +33 -0
- package/lib/broker/context.js +12 -0
- package/lib/broker/{default-options.js → defaultOptions.js} +22 -4
- package/lib/broker/index.js +218 -192
- package/lib/{build-runtime.js → buildRuntime.js} +16 -16
- package/lib/cache/base.js +33 -28
- package/lib/cache/inMemory.js +140 -0
- package/lib/cache/index.js +1 -1
- package/lib/cache/lock.js +21 -4
- package/lib/constants.js +7 -4
- package/lib/{error-handler.js → errorHandler.js} +0 -0
- package/lib/errors.js +16 -9
- package/lib/helper/{define-action.js → defineAction.js} +3 -1
- package/lib/helper/{define-broker-options.js → defineBrokerOptions.js} +2 -0
- package/lib/helper/{define-service.js → defineService.js} +4 -1
- package/lib/index.js +13 -9
- package/lib/logger/format/asHumanReadable.js +4 -3
- package/lib/logger/index.js +4 -1
- package/lib/logger/levels.js +2 -1
- package/lib/logger/tools.js +4 -0
- package/lib/logger/utils/format.js +18 -4
- package/lib/metrics/constants.js +1 -1
- package/lib/metrics/types/gauge.js +1 -1
- package/lib/middlewares/action-hooks/index.js +59 -11
- package/lib/middlewares/bulkhead/index.js +2 -1
- package/lib/middlewares/cache/index.js +80 -0
- package/lib/middlewares/circuit-breaker/index.js +38 -13
- package/lib/middlewares/index.js +1 -0
- package/lib/middlewares/metrics/index.js +1 -1
- package/lib/middlewares/timeout/index.js +2 -2
- package/lib/middlewares/tracing/index.js +24 -11
- package/lib/middlewares/tracing/tags.js +43 -0
- package/lib/middlewares/validator/index.js +1 -1
- package/lib/registry/{action-endpoint.js → actionEndpoint.js} +0 -0
- package/lib/registry/collections/{action-collection.js → actionCollection.js} +1 -1
- package/lib/registry/collections/{endpoint-collection.js → endpointCollection.js} +2 -3
- package/lib/registry/collections/{event-collection.js → eventCollection.js} +4 -8
- package/lib/registry/collections/{node-collection.js → nodeCollection.js} +0 -0
- package/lib/registry/collections/{service-collection.js → serviceCollection.js} +1 -1
- package/lib/registry/{event-endpoint.js → eventEndpoint.js} +0 -0
- package/lib/registry/registry.js +9 -22
- package/lib/registry/service/service.js +2 -2
- package/lib/registry/{service-item.js → serviceItem.js} +0 -0
- package/lib/runtime/{init-action-invoker.js → initActionInvoker.js} +1 -1
- package/lib/runtime/{init-cache.js → initCache.js} +0 -0
- package/lib/runtime/{init-context-factory.js → initContextFactory.js} +0 -0
- package/lib/runtime/{init-eventbus.js → initEventbus.js} +8 -7
- package/lib/runtime/{init-logger.js → initLogger.js} +0 -0
- package/lib/runtime/{init-metrics.js → initMetrics.js} +11 -10
- package/lib/runtime/{init-middleware-manager.js → initMiddlewareManager.js} +0 -0
- package/lib/runtime/{init-registry.js → initRegistry.js} +0 -0
- package/lib/runtime/{init-service-manager.js → initServiceManager.js} +0 -0
- package/lib/runtime/{init-tracing.js → initTracing.js} +2 -1
- package/lib/runtime/{init-transport.js → initTransport.js} +0 -0
- package/lib/runtime/{init-uuid-factory.js → initUuidFactory.js} +0 -0
- package/lib/runtime/{init-validator.js → initValidator.js} +0 -0
- package/lib/tracing/collectors/base.js +11 -19
- package/lib/tracing/collectors/event.js +2 -2
- package/lib/tracing/collectors/index.js +2 -2
- package/lib/tracing/span.js +8 -6
- package/lib/transport/InboundTransformStream.js +75 -0
- package/lib/transport/adapters/{adapter-base.js → adapteBase.js} +15 -0
- package/lib/transport/adapters/adapters.js +1 -1
- package/lib/transport/adapters/dummy/index.js +2 -2
- package/lib/transport/adapters/tcp/discovery/index.js +45 -31
- package/lib/transport/adapters/tcp/index.js +20 -13
- package/lib/transport/adapters/tcp/tcpReader.js +1 -0
- package/lib/transport/adapters/tcp/tcpWriteStream.js +1 -1
- package/lib/transport/adapters/tcp/tcpWriter.js +2 -2
- package/lib/transport/createMessage.js +11 -0
- package/lib/transport/createTransport.js +214 -171
- package/lib/transport/errorPayloadFactory.js +18 -0
- package/lib/transport/{message-handlers.js → messageHandlers.js} +91 -22
- package/lib/transport/messageTypes.js +23 -0
- package/lib/types.js +49 -49
- package/lib/utils/options.js +4 -2
- package/lib/utils/{restore-error.js → restoreError.js} +1 -1
- package/package.json +6 -12
- package/CHANGELOG.md +0 -1334
- package/lib/cache/memory.js +0 -121
- package/lib/middlewares/tracing/buildTags.js +0 -17
- package/lib/new-errors.js +0 -25
- package/lib/tracing/collectors/console.js +0 -34
- package/lib/tracing/index.js +0 -3
- package/lib/tracing/tracer.js +0 -64
- package/lib/transport/message-types.js +0 -59
- package/lib/transport/message.js +0 -16
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* Copyright 2021 Fachwerk
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { InboundTransformStream } = require('./InboundTransformStream')
|
|
8
8
|
const { WeaveError, restoreError } = require('../errors')
|
|
9
9
|
const { createContext } = require('../broker/context')
|
|
10
|
-
const
|
|
10
|
+
const { createMessage } = require('./createMessage')
|
|
11
|
+
const MessageTypes = require('./messageTypes')
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @typedef {import('../types').Transport} Transport
|
|
@@ -66,13 +67,25 @@ module.exports = (runtime, transport) => {
|
|
|
66
67
|
|
|
67
68
|
if (!stream) {
|
|
68
69
|
isNew = true
|
|
69
|
-
stream = new
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return done()
|
|
70
|
+
stream = new InboundTransformStream(
|
|
71
|
+
payload.sender,
|
|
72
|
+
payload.id, {
|
|
73
|
+
objectMode: payload.meta && payload.meta.$isObjectModeStream
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
// handle backpressure
|
|
78
|
+
if (runtime.options.transport.streams.handleBackpressure) {
|
|
79
|
+
stream.on('backpressure', async ({ sender, requestId }) => {
|
|
80
|
+
const message = createMessage(MessageTypes.MESSAGE_REQUEST_STREAM_BACKPRESSURE, sender, { id: requestId })
|
|
81
|
+
await transport.send(message)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
stream.on('resume_backpressure', async ({ sender, requestId }) => {
|
|
85
|
+
const message = createMessage(MessageTypes.MESSAGE_REQUEST_STREAM_RESUME, sender, { id: requestId })
|
|
86
|
+
await transport.send(message)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
76
89
|
|
|
77
90
|
stream.$prevSeq = -1
|
|
78
91
|
stream.$pool = new Map()
|
|
@@ -126,13 +139,25 @@ module.exports = (runtime, transport) => {
|
|
|
126
139
|
if (!stream) {
|
|
127
140
|
transport.log.debug(`New stream from node ${payload.sender} received. Seq: ${payload.sequence}`)
|
|
128
141
|
|
|
129
|
-
stream = new
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return done()
|
|
142
|
+
stream = new InboundTransformStream(
|
|
143
|
+
payload.sender,
|
|
144
|
+
payload.id, {
|
|
145
|
+
objectMode: payload.meta && payload.meta.$isObjectModeStream
|
|
134
146
|
}
|
|
135
|
-
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
// handle backpressure
|
|
150
|
+
if (runtime.options.transport.streams.handleBackpressure) {
|
|
151
|
+
stream.on('backpressure', async ({ sender, requestId }) => {
|
|
152
|
+
const message = createMessage(MessageTypes.MESSAGE_RESPONSE_STREAM_BACKPRESSURE, sender, { id: requestId })
|
|
153
|
+
await transport.send(message)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
stream.on('resume_backpressure', async ({ sender, requestId }) => {
|
|
157
|
+
const message = createMessage(MessageTypes.MESSAGE_RESPONSE_STREAM_RESUME, sender, { id: requestId })
|
|
158
|
+
await transport.send(message)
|
|
159
|
+
})
|
|
160
|
+
}
|
|
136
161
|
|
|
137
162
|
stream.$prevSeq = -1
|
|
138
163
|
stream.$pool = new Map()
|
|
@@ -232,10 +257,10 @@ module.exports = (runtime, transport) => {
|
|
|
232
257
|
}
|
|
233
258
|
|
|
234
259
|
return localRequestProxy(context)
|
|
235
|
-
.then(data => transport.
|
|
236
|
-
.catch(error => transport.
|
|
260
|
+
.then(data => transport.sendResponse(sender, payload.id, data, context.meta, null))
|
|
261
|
+
.catch(error => transport.sendResponse(sender, payload.id, null, context.meta, error))
|
|
237
262
|
} catch (error) {
|
|
238
|
-
return transport.
|
|
263
|
+
return transport.sendResponse(sender, payload.id, null, payload.meta, error)
|
|
239
264
|
}
|
|
240
265
|
}
|
|
241
266
|
|
|
@@ -244,7 +269,7 @@ module.exports = (runtime, transport) => {
|
|
|
244
269
|
* @param {any} payload - Payload
|
|
245
270
|
* @returns {Promise} Promise
|
|
246
271
|
*/
|
|
247
|
-
const onResponse = payload => {
|
|
272
|
+
const onResponse = (payload) => {
|
|
248
273
|
const id = payload.id
|
|
249
274
|
const request = transport.pending.requests.get(id)
|
|
250
275
|
|
|
@@ -295,7 +320,7 @@ module.exports = (runtime, transport) => {
|
|
|
295
320
|
* @returns {Promise} Promise
|
|
296
321
|
*/
|
|
297
322
|
const onPing = payload => {
|
|
298
|
-
const message =
|
|
323
|
+
const message = createMessage(MessageTypes.MESSAGE_PONG, payload.sender, {
|
|
299
324
|
dispatchTime: payload.dispatchTime,
|
|
300
325
|
arrivalTime: Date.now()
|
|
301
326
|
})
|
|
@@ -388,6 +413,38 @@ module.exports = (runtime, transport) => {
|
|
|
388
413
|
}
|
|
389
414
|
}
|
|
390
415
|
|
|
416
|
+
const onResponseStreamBackpressure = (payload) => {
|
|
417
|
+
const stream = transport.pending.outboundResponseStreams.get(payload.id)
|
|
418
|
+
|
|
419
|
+
if (stream) {
|
|
420
|
+
stream.pause()
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const onResponseStreamResume = (payload) => {
|
|
425
|
+
const stream = transport.pending.outboundResponseStreams.get(payload.id)
|
|
426
|
+
|
|
427
|
+
if (stream) {
|
|
428
|
+
stream.resume()
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const onRequestStreamBackpressure = (payload) => {
|
|
433
|
+
const stream = transport.pending.outboundRequestStreams.get(payload.id)
|
|
434
|
+
|
|
435
|
+
if (stream) {
|
|
436
|
+
stream.pause()
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const onRequestStreamResume = (payload) => {
|
|
441
|
+
const stream = transport.pending.outboundRequestStreams.get(payload.id)
|
|
442
|
+
|
|
443
|
+
if (stream) {
|
|
444
|
+
stream.resume()
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
391
448
|
return (type, data) => {
|
|
392
449
|
try {
|
|
393
450
|
if (data === null) {
|
|
@@ -403,9 +460,9 @@ module.exports = (runtime, transport) => {
|
|
|
403
460
|
// todo: check protocol version
|
|
404
461
|
// todo: check node ID conflict
|
|
405
462
|
|
|
406
|
-
// if (payload.sender ===
|
|
407
|
-
// if (type === MessageTypes.MESSAGE_INFO && payload.instanceId !==
|
|
408
|
-
// return
|
|
463
|
+
// if (payload.sender === runtime.nodeId) {
|
|
464
|
+
// if (type === MessageTypes.MESSAGE_INFO && payload.instanceId !== runtime.state.instanceId) {
|
|
465
|
+
// return runtime.fatalError('Weave broker has detected a node ID conflict. "nodeId" of broker needs to be unique. Broker will be stopped.')
|
|
409
466
|
// }
|
|
410
467
|
// }
|
|
411
468
|
|
|
@@ -437,6 +494,18 @@ module.exports = (runtime, transport) => {
|
|
|
437
494
|
case MessageTypes.MESSAGE_EVENT:
|
|
438
495
|
onEvent(payload)
|
|
439
496
|
break
|
|
497
|
+
case MessageTypes.MESSAGE_RESPONSE_STREAM_BACKPRESSURE:
|
|
498
|
+
onResponseStreamBackpressure(payload)
|
|
499
|
+
break
|
|
500
|
+
case MessageTypes.MESSAGE_RESPONSE_STREAM_RESUME:
|
|
501
|
+
onResponseStreamResume(payload)
|
|
502
|
+
break
|
|
503
|
+
case MessageTypes.MESSAGE_REQUEST_STREAM_BACKPRESSURE:
|
|
504
|
+
onRequestStreamBackpressure(payload)
|
|
505
|
+
break
|
|
506
|
+
case MessageTypes.MESSAGE_REQUEST_STREAM_RESUME:
|
|
507
|
+
onRequestStreamResume(payload)
|
|
508
|
+
break
|
|
440
509
|
}
|
|
441
510
|
|
|
442
511
|
return true
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Author: Kevin Ries (kevin@fachw3rk.de)
|
|
3
|
+
* -----
|
|
4
|
+
* Copyright 2021 Fachwerk
|
|
5
|
+
*/
|
|
6
|
+
exports.MESSAGE_UNKNOWN = 'unknown'
|
|
7
|
+
exports.MESSAGE_DISCOVERY = 'discovery'
|
|
8
|
+
exports.MESSAGE_INFO = 'info'
|
|
9
|
+
exports.MESSAGE_REQUEST = 'request'
|
|
10
|
+
exports.MESSAGE_RESPONSE = 'response'
|
|
11
|
+
exports.MESSAGE_PING = 'ping'
|
|
12
|
+
exports.MESSAGE_PONG = 'pong'
|
|
13
|
+
exports.MESSAGE_DISCONNECT = 'disconnect'
|
|
14
|
+
exports.MESSAGE_HEARTBEAT = 'heartbeat'
|
|
15
|
+
exports.MESSAGE_EVENT = 'event'
|
|
16
|
+
exports.MESSAGE_GOSSIP_HELLO = 'gossip_hello'
|
|
17
|
+
exports.MESSAGE_GOSSIP_RESPONSE = 'gossip_response'
|
|
18
|
+
exports.MESSAGE_GOSSIP_REQUEST = 'gossip_request'
|
|
19
|
+
exports.MESSAGE_EVENT_ACK = 'event_ack'
|
|
20
|
+
exports.MESSAGE_RESPONSE_STREAM_BACKPRESSURE = 'response_stream_backpressure'
|
|
21
|
+
exports.MESSAGE_RESPONSE_STREAM_RESUME = 'response_stream_resume'
|
|
22
|
+
exports.MESSAGE_REQUEST_STREAM_BACKPRESSURE = 'request_stream_backpressure'
|
|
23
|
+
exports.MESSAGE_REQUEST_STREAM_RESUME = 'request_stream_resume'
|
package/lib/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// eslint-disable-next-line no-unused-vars
|
|
2
|
-
const { EventEmitter2 } = require('eventemitter2')
|
|
2
|
+
const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {import('stream').Stream} Stream
|
|
@@ -58,8 +58,8 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
58
58
|
/**
|
|
59
59
|
* ActionInvoker
|
|
60
60
|
* @typedef {object} ActionInvoker
|
|
61
|
-
* @property {function(string, object, ActionOptions):Promise<any>} call -
|
|
62
|
-
* @property {function(string, object, ActionOptions):Promise<any>}
|
|
61
|
+
* @property {function(string, object, ActionOptions):Promise<any>} call - Call a
|
|
62
|
+
* @property {function(string, object, ActionOptions):Promise<any>} multiCall - Service changed delegate
|
|
63
63
|
*/
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -76,7 +76,7 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
76
76
|
* @property {string} version - Weave version of the broker.
|
|
77
77
|
* @property {ActionInvoker} actionInvoker - Action invoker
|
|
78
78
|
* @property {EventBus} [eventBus] - Service event bus
|
|
79
|
-
* @property {
|
|
79
|
+
* @property {EventEmitter} bus - Instance event bus
|
|
80
80
|
* @property {Broker} [broker] - Broker reference.
|
|
81
81
|
* @property {BrokerOptions} options - options
|
|
82
82
|
* @property {RuntimeInstanceState} state - Instance state
|
|
@@ -111,11 +111,11 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
111
111
|
* @property {function():Promise<any>} start - Start the broker.
|
|
112
112
|
* @property {function():Promise<any>} stop - Stop the broker
|
|
113
113
|
* @property {function(ServiceSchema):Service} createService - Create a new service with a service schema object.
|
|
114
|
-
* @property {function():void} loadService - Load a service from a given path.
|
|
115
|
-
* @property {function():void} loadServices - Load all services from a given directory.
|
|
114
|
+
* @property {function(string):void} loadService - Load a service from a given path.
|
|
115
|
+
* @property {function(string=, string=):void} loadServices - Load all services from a given directory.
|
|
116
116
|
* @property {ContextFactory} contextFactory - contextFactory
|
|
117
117
|
* @property {Logger} log - Logger instance
|
|
118
|
-
* @property {function():Logger} createLogger - Create a new logger instace.
|
|
118
|
+
* @property {function(string, any):Logger} createLogger - Create a new logger instace.
|
|
119
119
|
* @property {Cache} [cache] - Cache
|
|
120
120
|
* @property {function():string} getUUID - Create a new from the UUID factory.
|
|
121
121
|
* @property {Registry} registry - Service registry reference
|
|
@@ -128,11 +128,16 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
128
128
|
* @property {function(string, any, any=):Promise<any>} broadcast broadcast
|
|
129
129
|
* @property {function(string, any, any=):Promise<any>} broadcastLocal broadcastLocal
|
|
130
130
|
* @property {function(string):Promise<any>} waitForServices waitForServices
|
|
131
|
-
* @property {Promise<PingResult>} ping ping
|
|
132
|
-
* @property {function(Error)} handleError handleError
|
|
133
|
-
* @property {void} fatalError fatalError
|
|
131
|
+
* @property {function(string, number=):Promise<PingResult>} ping ping
|
|
132
|
+
* @property {function(Error):void} handleError handleError
|
|
133
|
+
* @property {function():void} fatalError fatalError
|
|
134
134
|
*/
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Ping result
|
|
138
|
+
* @typedef {Object<string, number>} PingResult
|
|
139
|
+
*/
|
|
140
|
+
|
|
136
141
|
/**
|
|
137
142
|
* Configuration object for weave service broker.
|
|
138
143
|
* @typedef {Object} BulkheadOptions
|
|
@@ -151,12 +156,20 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
151
156
|
* @property {Array<Number>} defaultBuckets Default buckets for histograms.
|
|
152
157
|
*/
|
|
153
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Configuration object for weave service broker.
|
|
161
|
+
* @typedef {Object} TracingErrorOptions
|
|
162
|
+
* @property {Array<string>} fields - Fields of errors, that should be included in spans.
|
|
163
|
+
* @property {Boolean} stackTrace - Include stacktrace in spans
|
|
164
|
+
*/
|
|
165
|
+
|
|
154
166
|
/**
|
|
155
167
|
* Configuration object for weave service broker.
|
|
156
168
|
* @typedef {Object} TracingOptions
|
|
157
169
|
* @property {Boolean} enabled - Enable tracing middleware. (default = false)
|
|
158
170
|
* @property {Number} samplingRate - Rate of traced actions. (default = 1.0)
|
|
159
171
|
* @property {Array<String|Object>} collectors - Array of tracing collectors.
|
|
172
|
+
* @property {TracingErrorOptions} errors - Settings for tracing errors.
|
|
160
173
|
*/
|
|
161
174
|
|
|
162
175
|
/**
|
|
@@ -184,6 +197,12 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
184
197
|
* @property {Number} retries Number of attempts before the action call gets rejected. (default = 5)
|
|
185
198
|
*/
|
|
186
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Configuration object for weave service broker.
|
|
202
|
+
* @typedef {Object} TransportStreamOptions
|
|
203
|
+
* @property {Boolean} handleBackpressure Handle stream backpressure. (default = true)
|
|
204
|
+
*/
|
|
205
|
+
|
|
187
206
|
/**
|
|
188
207
|
* Configuration object for weave service broker.
|
|
189
208
|
* @typedef {Object} TransportOptions
|
|
@@ -195,6 +214,7 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
195
214
|
* @property {Number} offlineNodeCheckInterval - Interval in milliseconds to check and remove not offline nodes. (default = 30000ms)
|
|
196
215
|
* @property {Number} maxOfflineTime - Maximum time a node can be offline before it is removed from the registry. (default = 600000ms)
|
|
197
216
|
* @property {Number} maxChunkSize - Maximum chunk size for streams. (default = 256 * 1024 Bits)
|
|
217
|
+
* @property {TransportStreamOptions} streams - Transport stream options.
|
|
198
218
|
*/
|
|
199
219
|
|
|
200
220
|
/**
|
|
@@ -264,26 +284,6 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
264
284
|
* @typedef {Object.<string, *>}
|
|
265
285
|
*/
|
|
266
286
|
|
|
267
|
-
// Cache
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Cache interface
|
|
271
|
-
* @typedef Cache
|
|
272
|
-
* @property {string} [name] name
|
|
273
|
-
* @property {LoggerOptions} options options
|
|
274
|
-
* @property {void} init init
|
|
275
|
-
* @property {Logger} log log
|
|
276
|
-
* @property {Promise<any>} set set
|
|
277
|
-
* @property {Promise<any>} get get
|
|
278
|
-
* @property {Promise<any>} remove remove
|
|
279
|
-
* @property {Promise<any>} clear clear
|
|
280
|
-
* @property {string} getCachingHash getCachingHash
|
|
281
|
-
* @property {Middleware} createMiddleware createMiddleware
|
|
282
|
-
* @property {Promise<any>} stop stop
|
|
283
|
-
*/
|
|
284
|
-
|
|
285
|
-
// Context
|
|
286
|
-
|
|
287
287
|
/**
|
|
288
288
|
* @export
|
|
289
289
|
* @typedef ContextFactory
|
|
@@ -329,11 +329,11 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
329
329
|
* @property {any} [metrics] metrics
|
|
330
330
|
* @property {function(any):void} setData - Set data object.
|
|
331
331
|
* @property {function(string, any, ActionOptions):ContextPromise} call - Call a service action
|
|
332
|
-
* @property {
|
|
332
|
+
* @property {function(string, object):Promise<any>} emit emit
|
|
333
333
|
* @property {Stream} [stream] - Stream
|
|
334
|
-
* @property {
|
|
335
|
-
* @property {
|
|
336
|
-
* @property {
|
|
334
|
+
* @property {function(string, any):Promise<any>} broadcast Broadcast an event to all listener.
|
|
335
|
+
* @property {function():void} startSpan startSpan
|
|
336
|
+
* @property {function():void} finishSpan finishSpan
|
|
337
337
|
* @property {function():Context} copy - Copy the current context.
|
|
338
338
|
* @property {function(Stream):void} setStream - Set the context data stream.
|
|
339
339
|
* @property {function(Endpoint):void} setEndpoint - Set data object.
|
|
@@ -351,8 +351,8 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
351
351
|
* @property {Promise<any>} remove remove
|
|
352
352
|
* @property {Promise<any>} clear clear
|
|
353
353
|
* @property {string} getCachingHash getCachingHash
|
|
354
|
-
* @property {Middleware} createMiddleware createMiddleware
|
|
355
|
-
* @property {Promise<any>} stop stop
|
|
354
|
+
* @property {function():Middleware} createMiddleware createMiddleware
|
|
355
|
+
* @property {function():Promise<any>} stop stop
|
|
356
356
|
*/
|
|
357
357
|
|
|
358
358
|
// Transport
|
|
@@ -368,9 +368,9 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
368
368
|
* @property {PendingStore} pending pending
|
|
369
369
|
* @property {Function} resolveConnect resolveConnect
|
|
370
370
|
* @property {string} adapterName adapterName
|
|
371
|
-
* @property {Promise<any>} connect connect
|
|
372
|
-
* @property {Promise<any>} disconnect disconnect
|
|
373
|
-
* @property {
|
|
371
|
+
* @property {function():Promise<any>} connect connect
|
|
372
|
+
* @property {function():Promise<any>} disconnect disconnect
|
|
373
|
+
* @property {function():Promise<any>} setReady setReady
|
|
374
374
|
* @property {function(TransportMessage):Promise<any>} send send
|
|
375
375
|
* @property {any} sendNodeInfo sendNodeInfo
|
|
376
376
|
* @property {function():Promise<any>} sendPing sendPing
|
|
@@ -475,14 +475,14 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
475
475
|
* @property {Endpoint | WeaveError} getNextAvailableActionEndpoint getNextAvailableActionEndpoint
|
|
476
476
|
* @property {function(ServiceActionCollectionListFilterParams=):Array<any>} getActionList getActionList
|
|
477
477
|
* @property {function(string): void} deregisterServiceByNodeId deregisterServiceByNodeId
|
|
478
|
-
* @property {function(string, number,
|
|
478
|
+
* @property {function(string, number, string):boolean} hasService hasService
|
|
479
479
|
* @property {function(string, string):Endpoint} getActionEndpointByNodeId getActionEndpointByNodeId
|
|
480
480
|
* @property {function(string):EndpointCollection} getActionEndpoints getActionEndpoints
|
|
481
481
|
* @property {function(ServiceAction):Endpoint} createPrivateActionEndpoint createPrivateActionEndpoint
|
|
482
482
|
* @property {function(string):Endpoint} getLocalActionEndpoint getLocalActionEndpoint
|
|
483
|
-
* @property {NodeInfo} getNodeInfo getNodeInfo
|
|
484
|
-
* @property {NodeInfo} getLocalNodeInfo getLocalNodeInfo
|
|
485
|
-
* @property {NodeInfo} generateLocalNodeInfo generateLocalNodeInfo
|
|
483
|
+
* @property {function():NodeInfo} getNodeInfo getNodeInfo
|
|
484
|
+
* @property {function():NodeInfo} getLocalNodeInfo getLocalNodeInfo
|
|
485
|
+
* @property {function():NodeInfo} generateLocalNodeInfo generateLocalNodeInfo
|
|
486
486
|
* @property {*} processNodeInfo processNodeInfo
|
|
487
487
|
* @property {function(string, boolean):void} nodeDisconnected nodeDisconnected
|
|
488
488
|
* @property {function(string):void} removeNode removeNode
|
|
@@ -534,7 +534,6 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
534
534
|
|
|
535
535
|
/**
|
|
536
536
|
* Endpoint
|
|
537
|
-
*
|
|
538
537
|
* @typedef Endpoint
|
|
539
538
|
* @property {Node} node node
|
|
540
539
|
* @property {Service} service service
|
|
@@ -549,7 +548,7 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
549
548
|
/**
|
|
550
549
|
* Event colleciton
|
|
551
550
|
* @typedef EventCollection
|
|
552
|
-
* @property {function(Node, Service,
|
|
551
|
+
* @property {function(Node, Service, EventCollection):Endpoint} add add
|
|
553
552
|
* @property {Endpoint} get get
|
|
554
553
|
* @property {function(string, Node):void} remove remove
|
|
555
554
|
* @property {function(Service):void} removeByService removeByService
|
|
@@ -593,8 +592,8 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
593
592
|
* @typedef ServiceActionCollection
|
|
594
593
|
* @property {*} add add
|
|
595
594
|
* @property {function(string):EndpointCollection} get get
|
|
596
|
-
* @property {function(
|
|
597
|
-
* @property {function(string, Node)} remove remove
|
|
595
|
+
* @property {function(Service):void} removeByService removeByService
|
|
596
|
+
* @property {function(string, Node):void} remove remove
|
|
598
597
|
* @property {function(ServiceActionCollectionListFilterParams):Array<any>} list list
|
|
599
598
|
*/
|
|
600
599
|
|
|
@@ -622,7 +621,7 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
622
621
|
* @property {boolean} [withEvents=false] Include events in result.
|
|
623
622
|
* @property {boolean} [withNodeService=false] Include node service.
|
|
624
623
|
* @property {boolean} [withSettings=false] Include service settings.
|
|
625
|
-
|
|
624
|
+
*/
|
|
626
625
|
|
|
627
626
|
/**
|
|
628
627
|
* Service collection
|
|
@@ -725,6 +724,7 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
725
724
|
* @property {void} timer timer
|
|
726
725
|
* @property {Metric} getMetric getMetric
|
|
727
726
|
* @property {any} list list
|
|
727
|
+
* @property {function():Promise<any>} stop list
|
|
728
728
|
*/
|
|
729
729
|
|
|
730
730
|
// Midlewares
|
|
@@ -734,7 +734,7 @@ const { EventEmitter2 } = require('eventemitter2')
|
|
|
734
734
|
* @export
|
|
735
735
|
* @typedef MiddlewareHandler
|
|
736
736
|
* @property {void} init init
|
|
737
|
-
* @property {
|
|
737
|
+
* @property {function(Middleware)} add add
|
|
738
738
|
* @property {any} wrapMethod wrapMethod
|
|
739
739
|
* @property {any} wrapHandler wrapHandler
|
|
740
740
|
* @property {any} callHandlersAsync callHandlersAsync
|
package/lib/utils/options.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
const {
|
|
3
2
|
clone,
|
|
4
3
|
compact,
|
|
@@ -38,6 +37,7 @@ function mergeActions (source, targetSchema) {
|
|
|
38
37
|
return targetSchema
|
|
39
38
|
}
|
|
40
39
|
|
|
40
|
+
// Merge events
|
|
41
41
|
function mergeEvents (source, targetSchema) {
|
|
42
42
|
Object.keys(source).map(key => {
|
|
43
43
|
const sourceEvent = wrapHandler(source[key])
|
|
@@ -78,7 +78,7 @@ function mergeLifecicleHooks (source, targetSchema) {
|
|
|
78
78
|
return compact(flatten([targetSchema, source]))
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
function mergeSchemas (mixin, targetSchema) {
|
|
82
82
|
const mixinSchema = clone(mixin)
|
|
83
83
|
const resultSchema = clone(targetSchema)
|
|
84
84
|
|
|
@@ -112,3 +112,5 @@ exports.mergeSchemas = (mixin, targetSchema) => {
|
|
|
112
112
|
|
|
113
113
|
return mixinSchema
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
module.exports = { mergeSchemas }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-js/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "The core package of weave",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Weave",
|
|
@@ -40,20 +40,14 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@weave-js/errors": "^0.9.1",
|
|
43
|
-
"@weave-js/utils": "^0.
|
|
44
|
-
"@weave-js/validator": "^0.
|
|
45
|
-
"eventemitter2": "^6.4.
|
|
46
|
-
"glob": "^7.
|
|
47
|
-
"node-fetch": "^2.6.1"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"eslint": "^7.30.0",
|
|
51
|
-
"jest": "^27.0.6",
|
|
52
|
-
"jest-cli": "^27.0.6"
|
|
43
|
+
"@weave-js/utils": "^0.10.0",
|
|
44
|
+
"@weave-js/validator": "^0.11.0",
|
|
45
|
+
"eventemitter2": "^6.4.5",
|
|
46
|
+
"glob": "^7.2.0"
|
|
53
47
|
},
|
|
54
48
|
"directories": {
|
|
55
49
|
"lib": "lib",
|
|
56
50
|
"test": "test"
|
|
57
51
|
},
|
|
58
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "84fd5e4af3af96e8c004bcfba40bb3cb35f23fa7"
|
|
59
53
|
}
|