@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
|
@@ -1,23 +1,23 @@
|
|
|
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
|
-
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'
|
|
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: EventEmitter } = require('eventemitter2')
|
|
2
|
+
const { EventEmitter2: EventEmitter } = require('eventemitter2');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {import('stream').Stream} Stream
|
|
@@ -268,7 +268,6 @@ const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
|
268
268
|
* @property {RetryPolicyOptions} [retryPolicy] - Retry policy
|
|
269
269
|
* @property {ValidatorOptions} [validatorOptions] Validator options.
|
|
270
270
|
* @property {boolean} [validateActionParams] validateActionParams.
|
|
271
|
-
* @property {boolean} [watchServices] watchServices.
|
|
272
271
|
* @property {number} [waitForServiceInterval] waitForServiceInterval.
|
|
273
272
|
* @property {function():string} [beforeRegisterMiddlewares] beforeRegisterMiddlewares.
|
|
274
273
|
* @property {function(Runtime):string} [uuidFactory] uuidFactory.
|
|
@@ -592,9 +591,9 @@ const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
|
592
591
|
|
|
593
592
|
/**
|
|
594
593
|
* @typedef {Object} ServiceActionCollectionListFilterParams
|
|
595
|
-
* @property {boolean} [
|
|
596
|
-
* @property {boolean} [skipInternals] Shows only local service actions
|
|
597
|
-
* @property {boolean} [withEndpoints] Shows only local service actions
|
|
594
|
+
* @property {boolean} [onlyLocals=false] Shows only local service actions
|
|
595
|
+
* @property {boolean} [skipInternals=false] Shows only local service actions
|
|
596
|
+
* @property {boolean} [withEndpoints=false] Shows only local service actions
|
|
598
597
|
*/
|
|
599
598
|
|
|
600
599
|
/**
|
|
@@ -663,7 +662,7 @@ const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
|
663
662
|
* @property {function(Action):void} addAction addAction
|
|
664
663
|
* @property {function(Event):void} addEvent addEvent
|
|
665
664
|
* @property {function(string, number, string=): boolean} equals equals
|
|
666
|
-
* @property {function(any)} update update
|
|
665
|
+
* @property {function(any):void} update update
|
|
667
666
|
*/
|
|
668
667
|
|
|
669
668
|
/**
|
|
@@ -757,13 +756,27 @@ const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
|
757
756
|
* @typedef Middleware
|
|
758
757
|
* @property {() => any} [created] created
|
|
759
758
|
* @property {function(Broker):void} [started] started
|
|
760
|
-
* @property {function(
|
|
761
|
-
* @property {(
|
|
762
|
-
* @property {function(
|
|
763
|
-
* @property {(
|
|
764
|
-
* @property {(
|
|
765
|
-
* @property {(
|
|
766
|
-
* @property {()
|
|
759
|
+
* @property {function(Broker):void} [stopping] stopped
|
|
760
|
+
* @property {function(Broker):void} [createService] stopped
|
|
761
|
+
* @property {function(Broker):void} [loadService] stopped
|
|
762
|
+
* @property {function(Broker):void} [loadServices] stopped
|
|
763
|
+
* @property {function(Broker):void} [stopping] stopped
|
|
764
|
+
* @property {function(Broker):void} [ping] stopped
|
|
765
|
+
* @property {function(Broker):void} [call] stopped
|
|
766
|
+
* @property {function(Broker):void} [multiCall] stopped
|
|
767
|
+
* @property {function(Broker):void} [emit] stopped
|
|
768
|
+
* @property {function(Broker):void} [broadcast] stopped
|
|
769
|
+
* @property {function(Broker):void} [broadcastLocal] stopped
|
|
770
|
+
* @property {function(Broker):void} [serviceCreating] stopped
|
|
771
|
+
* @property {function(Broker):void} [serviceCreated] stopped
|
|
772
|
+
* @property {function(Broker):void} [serviceStopping] stopped
|
|
773
|
+
* @property {function(Broker):void} [serviceStopped] stopped
|
|
774
|
+
* @property {function(Broker):void} [localAction] stopped
|
|
775
|
+
* @property {function(Broker):void} [localEvent] stopped
|
|
776
|
+
* @property {function(Broker):void} [remoteAction] stopped
|
|
777
|
+
* @property {function(Broker):void} [remoteEvent] stopped
|
|
778
|
+
* @property {function(Broker):void} [transportSend] stopped
|
|
779
|
+
* @property {function(Broker):void} [transportMessageHandler] stopped
|
|
767
780
|
*/
|
|
768
781
|
|
|
769
782
|
// Validator
|
|
@@ -779,7 +792,7 @@ const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
|
779
792
|
* Tracer instance
|
|
780
793
|
* @typedef Tracer
|
|
781
794
|
* @property {void} init init
|
|
782
|
-
* @property {Promise<any>} stop stop
|
|
795
|
+
* @property {function():Promise<any>} stop stop
|
|
783
796
|
* @property {boolean} shouldSample shouldSample
|
|
784
797
|
* @property {function():void} invokeCollectorMethod invokeCollectorMethod
|
|
785
798
|
* @property {function(string, object):Span} startSpan startSpan
|
|
@@ -834,4 +847,4 @@ const { EventEmitter2: EventEmitter } = require('eventemitter2')
|
|
|
834
847
|
* @param {object} data - Payload
|
|
835
848
|
*/
|
|
836
849
|
|
|
837
|
-
module.exports = {}
|
|
850
|
+
module.exports = {};
|
package/lib/utils/index.js
CHANGED
package/lib/utils/options.js
CHANGED
|
@@ -6,111 +6,111 @@ const {
|
|
|
6
6
|
flatten,
|
|
7
7
|
wrapHandler,
|
|
8
8
|
wrapInArray
|
|
9
|
-
} = require('@weave-js/utils')
|
|
9
|
+
} = require('@weave-js/utils');
|
|
10
10
|
|
|
11
11
|
function mergeSettings (source, targetSchema) {
|
|
12
|
-
return defaultsDeep(source, targetSchema)
|
|
12
|
+
return defaultsDeep(source, targetSchema);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function mergeMeta (source, targetSchema) {
|
|
16
|
-
return defaultsDeep(source, targetSchema)
|
|
16
|
+
return defaultsDeep(source, targetSchema);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function mergeUniqueArrays (source, targetSchema) {
|
|
20
|
-
return compact(flatten([targetSchema, source]))
|
|
20
|
+
return compact(flatten([targetSchema, source]));
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function mergeActions (source, targetSchema) {
|
|
24
24
|
Object.keys(source).map(key => {
|
|
25
25
|
// prevent action merge
|
|
26
26
|
if (source[key] === false && targetSchema[key]) {
|
|
27
|
-
delete targetSchema[key]
|
|
28
|
-
return
|
|
27
|
+
delete targetSchema[key];
|
|
28
|
+
return;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const sourceAction = wrapHandler(source[key])
|
|
32
|
-
const targetSchemaAction = wrapHandler(targetSchema[key])
|
|
31
|
+
const sourceAction = wrapHandler(source[key]);
|
|
32
|
+
const targetSchemaAction = wrapHandler(targetSchema[key]);
|
|
33
33
|
|
|
34
|
-
targetSchema[key] = deepMerge(sourceAction, targetSchemaAction)
|
|
35
|
-
})
|
|
34
|
+
targetSchema[key] = deepMerge(sourceAction, targetSchemaAction);
|
|
35
|
+
});
|
|
36
36
|
|
|
37
|
-
return targetSchema
|
|
37
|
+
return targetSchema;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Merge events
|
|
41
41
|
function mergeEvents (source, targetSchema) {
|
|
42
42
|
Object.keys(source).map(key => {
|
|
43
|
-
const sourceEvent = wrapHandler(source[key])
|
|
44
|
-
const targetEvent = wrapHandler(targetSchema[key])
|
|
43
|
+
const sourceEvent = wrapHandler(source[key]);
|
|
44
|
+
const targetEvent = wrapHandler(targetSchema[key]);
|
|
45
45
|
|
|
46
|
-
let handler = compact(flatten([sourceEvent ? sourceEvent.handler : null, targetEvent ? targetEvent.handler : null]))
|
|
46
|
+
let handler = compact(flatten([sourceEvent ? sourceEvent.handler : null, targetEvent ? targetEvent.handler : null]));
|
|
47
47
|
if (handler.length === 1) {
|
|
48
|
-
handler = handler[0]
|
|
48
|
+
handler = handler[0];
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
targetSchema[key] = deepMerge(sourceEvent, targetEvent)
|
|
52
|
-
targetSchema[key].handler = handler
|
|
53
|
-
})
|
|
54
|
-
return targetSchema
|
|
51
|
+
targetSchema[key] = deepMerge(sourceEvent, targetEvent);
|
|
52
|
+
targetSchema[key].handler = handler;
|
|
53
|
+
});
|
|
54
|
+
return targetSchema;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function mergeMethods (source, targetSchema) {
|
|
58
|
-
return Object.assign(source, targetSchema)
|
|
58
|
+
return Object.assign(source, targetSchema);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function mergeActionHooks (source, target) {
|
|
62
62
|
Object.keys(source).map(hookName => {
|
|
63
63
|
if (!target[hookName]) {
|
|
64
|
-
target[hookName] = {}
|
|
64
|
+
target[hookName] = {};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
Object.keys(source[hookName]).map(actionName => {
|
|
68
|
-
const sourceHookAction = wrapInArray(source[hookName][actionName])
|
|
69
|
-
const targetHookAction = wrapInArray(target[hookName][actionName])
|
|
70
|
-
target[hookName][actionName] = compact(flatten([sourceHookAction, targetHookAction]))
|
|
71
|
-
})
|
|
72
|
-
})
|
|
68
|
+
const sourceHookAction = wrapInArray(source[hookName][actionName]);
|
|
69
|
+
const targetHookAction = wrapInArray(target[hookName][actionName]);
|
|
70
|
+
target[hookName][actionName] = compact(flatten([sourceHookAction, targetHookAction]));
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
73
|
|
|
74
|
-
return target
|
|
74
|
+
return target;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function mergeLifecicleHooks (source, targetSchema) {
|
|
78
|
-
return compact(flatten([targetSchema, source]))
|
|
78
|
+
return compact(flatten([targetSchema, source]));
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function mergeSchemas (mixin, targetSchema) {
|
|
82
|
-
const mixinSchema = clone(mixin)
|
|
83
|
-
const resultSchema = clone(targetSchema)
|
|
82
|
+
const mixinSchema = clone(mixin);
|
|
83
|
+
const resultSchema = clone(targetSchema);
|
|
84
84
|
|
|
85
85
|
Object.keys(resultSchema).forEach(key => {
|
|
86
86
|
if (['name', 'version'].includes(key)) {
|
|
87
87
|
// override value
|
|
88
|
-
mixinSchema[key] = resultSchema[key]
|
|
88
|
+
mixinSchema[key] = resultSchema[key];
|
|
89
89
|
} else if (key === 'dependencies') {
|
|
90
|
-
mixinSchema[key] = mergeUniqueArrays(resultSchema[key], mixinSchema[key])
|
|
90
|
+
mixinSchema[key] = mergeUniqueArrays(resultSchema[key], mixinSchema[key]);
|
|
91
91
|
} else if (key === 'mixins') {
|
|
92
|
-
mixinSchema[key] = mergeUniqueArrays(resultSchema[key], mixinSchema[key] || {})
|
|
92
|
+
mixinSchema[key] = mergeUniqueArrays(resultSchema[key], mixinSchema[key] || {});
|
|
93
93
|
} else if (key === 'settings') {
|
|
94
|
-
mixinSchema[key] = mergeSettings(resultSchema[key], mixinSchema[key])
|
|
94
|
+
mixinSchema[key] = mergeSettings(resultSchema[key], mixinSchema[key]);
|
|
95
95
|
} else if (key === 'meta') {
|
|
96
|
-
mixinSchema[key] = mergeMeta(resultSchema[key], mixinSchema[key])
|
|
96
|
+
mixinSchema[key] = mergeMeta(resultSchema[key], mixinSchema[key]);
|
|
97
97
|
} else if (key === 'actions') {
|
|
98
|
-
mixinSchema[key] = mergeActions(resultSchema[key], mixinSchema[key] || {})
|
|
98
|
+
mixinSchema[key] = mergeActions(resultSchema[key], mixinSchema[key] || {});
|
|
99
99
|
} else if (key === 'hooks') {
|
|
100
|
-
mixinSchema[key] = mergeActionHooks(resultSchema[key], mixinSchema[key] || {})
|
|
100
|
+
mixinSchema[key] = mergeActionHooks(resultSchema[key], mixinSchema[key] || {});
|
|
101
101
|
} else if (key === 'events') {
|
|
102
|
-
mixinSchema[key] = mergeEvents(resultSchema[key], mixinSchema[key] || {})
|
|
102
|
+
mixinSchema[key] = mergeEvents(resultSchema[key], mixinSchema[key] || {});
|
|
103
103
|
} else if (key === 'methods') {
|
|
104
|
-
mixinSchema[key] = mergeMethods(resultSchema[key], mixinSchema[key] || {})
|
|
104
|
+
mixinSchema[key] = mergeMethods(resultSchema[key], mixinSchema[key] || {});
|
|
105
105
|
} else if (['afterSchemasMerged', 'created', 'started', 'stopped'].includes(key)) {
|
|
106
|
-
mixinSchema[key] = mergeLifecicleHooks(resultSchema[key], mixinSchema[key])
|
|
106
|
+
mixinSchema[key] = mergeLifecicleHooks(resultSchema[key], mixinSchema[key]);
|
|
107
107
|
} else {
|
|
108
108
|
// default action for properties
|
|
109
|
-
mixinSchema[key] = resultSchema[key]
|
|
109
|
+
mixinSchema[key] = resultSchema[key];
|
|
110
110
|
}
|
|
111
|
-
})
|
|
111
|
+
});
|
|
112
112
|
|
|
113
|
-
return mixinSchema
|
|
113
|
+
return mixinSchema;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
module.exports = { mergeSchemas }
|
|
116
|
+
module.exports = { mergeSchemas };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const errors = require('../errors')
|
|
1
|
+
const errors = require('../errors');
|
|
2
2
|
|
|
3
3
|
exports.restoreError = (error) => {
|
|
4
|
-
const ErrorClass = errors[error.name]
|
|
4
|
+
const ErrorClass = errors[error.name];
|
|
5
5
|
|
|
6
6
|
if (ErrorClass) {
|
|
7
7
|
switch (error.name) {
|
|
8
8
|
case 'WeaveError':
|
|
9
|
-
return new ErrorClass(error.message, error.code, error.type, error.data)
|
|
9
|
+
return new ErrorClass(error.message, error.code, error.type, error.data);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
}
|
|
12
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-js/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The core package of weave",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Weave",
|
|
@@ -40,8 +40,8 @@
|
|
|
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.
|
|
43
|
+
"@weave-js/utils": "^0.11.0",
|
|
44
|
+
"@weave-js/validator": "^0.12.0",
|
|
45
45
|
"eventemitter2": "^6.4.5",
|
|
46
46
|
"glob": "^7.2.0"
|
|
47
47
|
},
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"lib": "lib",
|
|
50
50
|
"test": "test"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "406e96b1f3017cc1d22de6693f61a2265506c239"
|
|
53
53
|
}
|
package/lib/cache/base.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Author: Kevin Ries (kevin@fachw3rk.de)
|
|
3
|
-
* -----
|
|
4
|
-
* Copyright 2021 Fachwerk
|
|
5
|
-
*/
|
|
6
|
-
const crypto = require('crypto')
|
|
7
|
-
const { isObject, dotGet, isString } = require('@weave-js/utils')
|
|
8
|
-
const Constants = require('../metrics/constants')
|
|
9
|
-
const { WeaveError } = require('../errors')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get property from data or metadata object.
|
|
13
|
-
* @param {any} data data object
|
|
14
|
-
* @param {object} metadata metadata object
|
|
15
|
-
* @param {string} key key
|
|
16
|
-
* @returns {any} Result
|
|
17
|
-
*/
|
|
18
|
-
function getPropertyFromDataOrMetadata (data, metadata, key) {
|
|
19
|
-
// if a key starts with ":", the property is picked from metadata
|
|
20
|
-
if (key.startsWith(':')) {
|
|
21
|
-
// remove ':' from key.
|
|
22
|
-
key = key.replace(':', '')
|
|
23
|
-
return dotGet(metadata, key)
|
|
24
|
-
}
|
|
25
|
-
return dotGet(data, key)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getCacheKeyByObject (val) {
|
|
29
|
-
if (Array.isArray(val)) {
|
|
30
|
-
return val.map(object => getCacheKeyByObject(object)).join('/')
|
|
31
|
-
} else if (isObject(val)) {
|
|
32
|
-
return Object.keys(val).map(key => {
|
|
33
|
-
return [key, getCacheKeyByObject(val[key])].join('/')
|
|
34
|
-
}).join('/')
|
|
35
|
-
} else if (val !== null) {
|
|
36
|
-
return val.toString()
|
|
37
|
-
} else {
|
|
38
|
-
return 'null'
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function generateHash (key) {
|
|
43
|
-
return crypto
|
|
44
|
-
.createHash('sha1')
|
|
45
|
-
.update(key)
|
|
46
|
-
.digest('base64')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function registerCacheMetrics (metrics) {
|
|
50
|
-
metrics.register({ type: 'counter', name: Constants.CACHE_GET_TOTAL })
|
|
51
|
-
metrics.register({ type: 'counter', name: Constants.CACHE_SET_TOTAL })
|
|
52
|
-
metrics.register({ type: 'counter', name: Constants.CACHE_FOUND_TOTAL })
|
|
53
|
-
metrics.register({ type: 'counter', name: Constants.CACHE_EXPIRED_TOTAL })
|
|
54
|
-
metrics.register({ type: 'counter', name: Constants.CACHE_DELETED_TOTAL })
|
|
55
|
-
metrics.register({ type: 'counter', name: Constants.CACHE_CLEANED_TOTAL })
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
exports.createCacheBase = (name, runtime, options) => {
|
|
59
|
-
if (!isString(name)) {
|
|
60
|
-
throw new WeaveError('Name needs to be a string.')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const cache = {
|
|
64
|
-
name,
|
|
65
|
-
isConnected: false,
|
|
66
|
-
runtime,
|
|
67
|
-
options: Object.assign({
|
|
68
|
-
ttl: null
|
|
69
|
-
}, options),
|
|
70
|
-
init () {
|
|
71
|
-
// register metrics
|
|
72
|
-
if (runtime.metrics) {
|
|
73
|
-
this.metrics = runtime.metrics
|
|
74
|
-
registerCacheMetrics(runtime.metrics)
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
log: runtime.createLogger('CACHER'),
|
|
78
|
-
set (/* hashKey, result, ttl */) {
|
|
79
|
-
/* istanbul ignore next */
|
|
80
|
-
runtime.handleError(new Error('Method not implemented.'))
|
|
81
|
-
},
|
|
82
|
-
get (/* hashKey */) {
|
|
83
|
-
/* istanbul ignore next */
|
|
84
|
-
runtime.handleError(new Error('Method not implemented.'))
|
|
85
|
-
},
|
|
86
|
-
remove () {
|
|
87
|
-
/* istanbul ignore next */
|
|
88
|
-
runtime.handleError(new Error('Method not implemented.'))
|
|
89
|
-
},
|
|
90
|
-
clear () {
|
|
91
|
-
/* istanbul ignore next */
|
|
92
|
-
runtime.handleError(new Error('Method not implemented.'))
|
|
93
|
-
},
|
|
94
|
-
stop () {
|
|
95
|
-
/* istanbul ignore next */
|
|
96
|
-
return Promise.resolve()
|
|
97
|
-
},
|
|
98
|
-
getCachingKey (actionName, data, metadata, keys) {
|
|
99
|
-
if (data || metadata) {
|
|
100
|
-
const prefix = actionName + ':'
|
|
101
|
-
|
|
102
|
-
if (keys) {
|
|
103
|
-
// fast path for single keys
|
|
104
|
-
if (keys.length === 1) {
|
|
105
|
-
const value = getPropertyFromDataOrMetadata(data, metadata, keys[0])
|
|
106
|
-
const key = getCacheKeyByObject(value)
|
|
107
|
-
return prefix + (isObject(value) ? key : value)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Handle data cache keys
|
|
111
|
-
if (keys.length > 0) {
|
|
112
|
-
const res = keys.reduce((pre, property, index) => {
|
|
113
|
-
const value = getPropertyFromDataOrMetadata(data, metadata, property)
|
|
114
|
-
let hash
|
|
115
|
-
if (isObject(value)) {
|
|
116
|
-
const key = getCacheKeyByObject(value)
|
|
117
|
-
hash = generateHash(key)
|
|
118
|
-
} else {
|
|
119
|
-
hash = value
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return pre + (index > 0 ? '|' : '') + hash
|
|
123
|
-
}, prefix)
|
|
124
|
-
return res
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
return prefix + generateHash(getCacheKeyByObject(data))
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return actionName
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return cache
|
|
136
|
-
}
|