@weave-js/core 0.15.3 → 0.16.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/index.mjs +0 -0
- package/lib/broker/context.js +4 -11
- package/lib/broker/defaultOptions.js +3 -2
- package/lib/broker/index.js +80 -26
- package/lib/broker/public.d.ts +2 -1
- package/lib/buildRuntime.js +30 -13
- package/lib/cache/adapters/index.js +14 -0
- package/lib/cache/lock.js +17 -0
- package/lib/errorHandler.js +27 -2
- package/lib/errors.js +11 -1
- package/lib/helper/defineAction.js +22 -7
- package/lib/helper/defineBrokerOptions.js +26 -8
- package/lib/helper/defineService.js +29 -5
- package/lib/index.js +69 -19
- package/lib/logger/format/asHumanReadable.js +4 -4
- package/lib/metrics/common.js +1 -1
- package/lib/metrics/exporter/base.js +2 -2
- package/lib/metrics/exporter/event.js +15 -13
- package/lib/metrics/exporter/index.js +1 -1
- package/lib/metrics/index.js +28 -0
- package/lib/middlewares/bulkhead/index.js +3 -3
- package/lib/middlewares/cache/index.js +6 -5
- package/lib/middlewares/context-tracker/index.js +12 -5
- package/lib/middlewares/index.js +18 -0
- package/lib/middlewares/tracing/tags.js +2 -2
- package/lib/middlewares/validator/index.js +2 -2
- package/lib/registry/actionEndpoint.js +5 -5
- package/lib/registry/collections/actionCollection.js +2 -2
- package/lib/registry/collections/endpointCollection.js +5 -5
- package/lib/registry/collections/eventCollection.js +5 -5
- package/lib/registry/collections/nodeCollection.js +2 -2
- package/lib/registry/collections/serviceCollection.js +2 -2
- package/lib/registry/node.js +1 -1
- package/lib/registry/registry.js +24 -15
- package/lib/registry/service/parseAction.js +11 -2
- package/lib/registry/service/parseEvent.js +2 -1
- package/lib/registry/service/service.js +29 -8
- package/lib/registry/serviceItem.js +2 -2
- package/lib/runtime/initActionInvoker.js +5 -1
- package/lib/runtime/initCache.js +4 -0
- package/lib/runtime/initContextFactory.js +6 -15
- package/lib/runtime/initEventbus.js +25 -4
- package/lib/runtime/initLogger.js +30 -10
- package/lib/runtime/initMetrics.js +18 -8
- package/lib/runtime/initRegistry.js +1 -1
- package/lib/runtime/initServiceManager.js +4 -0
- package/lib/runtime/initTracing.js +5 -1
- package/lib/runtime/initTransport.js +1 -1
- package/lib/runtime/initUuidFactory.js +1 -5
- package/lib/runtime/initValidator.js +1 -6
- package/lib/tracing/collectors/base.js +21 -3
- package/lib/tracing/collectors/event.js +10 -0
- package/lib/tracing/collectors/index.js +34 -1
- package/lib/transport/adapters/adapterBase.js +14 -4
- package/lib/transport/adapters/fromURI.js +31 -23
- package/lib/transport/createTransport.js +30 -13
- package/lib/transport/messageHandlers.js +3 -3
- package/lib/utils/index.js +17 -1
- package/lib/utils/options.js +70 -2
- package/lib/utils/restoreError.js +25 -0
- package/lib/utils/wrap-handler.js +22 -0
- package/package.json +2 -1
- package/types/index.d.ts +958 -0
- /package/lib/{types.js → types.__js} +0 -0
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
const errors = require('../errors');
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Restore a Weave error from a serialized error payload
|
|
5
|
+
*
|
|
6
|
+
* Reconstructs proper error instances from serialized error data received
|
|
7
|
+
* over the network. Handles all Weave-specific error types with their
|
|
8
|
+
* specific constructor signatures and fallback to generic Error for
|
|
9
|
+
* unknown error types.
|
|
10
|
+
*
|
|
11
|
+
* Supported error types:
|
|
12
|
+
* - WeaveError, WeaveRetryableError: Standard errors with message and options
|
|
13
|
+
* - WeaveParameterValidationError, WeaveBrokerOptionsError: Validation errors
|
|
14
|
+
* - WeaveServiceNotFoundError, WeaveServiceNotAvailableError: Service errors
|
|
15
|
+
* - WeaveQueueSizeExceededError, WeaveMaxCallLevelError: Resource errors
|
|
16
|
+
* - WeaveRequestTimeoutError: Timeout-specific errors with action/node context
|
|
17
|
+
* - WeaveGracefulStopTimeoutError: Shutdown timeout errors
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} errorPayload Serialized error payload from network transport
|
|
20
|
+
* @param {string} errorPayload.name Error class name
|
|
21
|
+
* @param {string} errorPayload.message Error message
|
|
22
|
+
* @param {Object} [errorPayload.data] Error-specific data
|
|
23
|
+
* @param {string} [errorPayload.stack] Original stack trace
|
|
24
|
+
* @param {string} [errorPayload.code] Error code
|
|
25
|
+
* @param {string} [errorPayload.nodeId] Node ID where error occurred
|
|
26
|
+
* @returns {Error} Restored error instance with proper type and properties
|
|
27
|
+
*/
|
|
3
28
|
const restoreError = (errorPayload) => {
|
|
4
29
|
const ErrorClass = errors[errorPayload.name];
|
|
5
30
|
let error;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { isFunction } = require('@weave-js/utils/lib/is-function');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrap a function or handler object into a standardized handler format
|
|
5
|
+
*
|
|
6
|
+
* Normalizes action and event handlers to ensure consistent structure.
|
|
7
|
+
* Functions are wrapped into objects with a 'handler' property, while
|
|
8
|
+
* existing handler objects are passed through unchanged.
|
|
9
|
+
*
|
|
10
|
+
* This allows handlers to be defined as either simple functions or
|
|
11
|
+
* objects with additional properties (middleware, validation, etc).
|
|
12
|
+
*
|
|
13
|
+
* @param {Function | import('@weave-js/utils').Handler} action Action function or handler object
|
|
14
|
+
* @returns {import('@weave-js/utils').Handler} Normalized handler object with 'handler' property
|
|
15
|
+
* @example
|
|
16
|
+
* // Function input
|
|
17
|
+
* wrapHandler((ctx) => { ... }) // Returns: { handler: (ctx) => { ... } }
|
|
18
|
+
*
|
|
19
|
+
* // Object input
|
|
20
|
+
* wrapHandler({ handler: (ctx) => { ... }, cache: true }) // Returns: { handler: (ctx) => { ... }, cache: true }
|
|
21
|
+
*/
|
|
22
|
+
exports.wrapHandler = (action) => isFunction(action) ? { handler: action } : action;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-js/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "The core package of weave",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Weave",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"Micro"
|
|
19
19
|
],
|
|
20
20
|
"main": "./lib/index.js",
|
|
21
|
+
"types": "./types/index.d.ts",
|
|
21
22
|
"scripts": {
|
|
22
23
|
"ci": "jest --watch",
|
|
23
24
|
"test": "NODE_ENV=test jest --no-cache --runInBand",
|