@weave-js/core 0.15.4 → 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.
Files changed (64) hide show
  1. package/index.mjs +0 -0
  2. package/lib/broker/context.js +4 -11
  3. package/lib/broker/defaultOptions.js +3 -2
  4. package/lib/broker/index.js +80 -26
  5. package/lib/broker/public.d.ts +2 -1
  6. package/lib/buildRuntime.js +30 -13
  7. package/lib/cache/adapters/index.js +14 -0
  8. package/lib/cache/lock.js +17 -0
  9. package/lib/errorHandler.js +27 -2
  10. package/lib/errors.js +11 -1
  11. package/lib/helper/defineAction.js +22 -7
  12. package/lib/helper/defineBrokerOptions.js +26 -8
  13. package/lib/helper/defineService.js +29 -5
  14. package/lib/index.js +69 -19
  15. package/lib/logger/format/asHumanReadable.js +4 -4
  16. package/lib/metrics/common.js +1 -1
  17. package/lib/metrics/exporter/base.js +2 -2
  18. package/lib/metrics/exporter/event.js +15 -13
  19. package/lib/metrics/exporter/index.js +1 -1
  20. package/lib/metrics/index.js +28 -0
  21. package/lib/middlewares/bulkhead/index.js +3 -3
  22. package/lib/middlewares/cache/index.js +6 -5
  23. package/lib/middlewares/context-tracker/index.js +12 -5
  24. package/lib/middlewares/index.js +18 -0
  25. package/lib/middlewares/tracing/tags.js +2 -2
  26. package/lib/middlewares/validator/index.js +2 -2
  27. package/lib/registry/actionEndpoint.js +5 -5
  28. package/lib/registry/collections/actionCollection.js +2 -2
  29. package/lib/registry/collections/endpointCollection.js +5 -5
  30. package/lib/registry/collections/eventCollection.js +5 -5
  31. package/lib/registry/collections/nodeCollection.js +2 -2
  32. package/lib/registry/collections/serviceCollection.js +2 -2
  33. package/lib/registry/node.js +1 -1
  34. package/lib/registry/registry.js +24 -15
  35. package/lib/registry/service/parseAction.js +11 -2
  36. package/lib/registry/service/parseEvent.js +2 -1
  37. package/lib/registry/service/service.js +29 -8
  38. package/lib/registry/serviceItem.js +2 -2
  39. package/lib/runtime/initActionInvoker.js +5 -1
  40. package/lib/runtime/initCache.js +4 -0
  41. package/lib/runtime/initContextFactory.js +6 -15
  42. package/lib/runtime/initEventbus.js +25 -4
  43. package/lib/runtime/initLogger.js +30 -10
  44. package/lib/runtime/initMetrics.js +18 -8
  45. package/lib/runtime/initRegistry.js +1 -1
  46. package/lib/runtime/initServiceManager.js +4 -0
  47. package/lib/runtime/initTracing.js +4 -0
  48. package/lib/runtime/initTransport.js +1 -1
  49. package/lib/runtime/initUuidFactory.js +1 -5
  50. package/lib/runtime/initValidator.js +1 -6
  51. package/lib/tracing/collectors/base.js +21 -3
  52. package/lib/tracing/collectors/event.js +10 -0
  53. package/lib/tracing/collectors/index.js +34 -1
  54. package/lib/transport/adapters/adapterBase.js +14 -4
  55. package/lib/transport/adapters/fromURI.js +31 -23
  56. package/lib/transport/createTransport.js +30 -13
  57. package/lib/transport/messageHandlers.js +3 -3
  58. package/lib/utils/index.js +17 -1
  59. package/lib/utils/options.js +70 -2
  60. package/lib/utils/restoreError.js +25 -0
  61. package/lib/utils/wrap-handler.js +22 -0
  62. package/package.json +2 -1
  63. package/types/index.d.ts +958 -0
  64. /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.15.4",
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",