@wirestate/react 0.6.1 → 0.6.2

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 (235) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/cjs/development/test-utils.js +2 -1050
  3. package/cjs/development/test-utils.js.map +1 -1
  4. package/cjs/production/test-utils.js +1 -1
  5. package/cjs/production/test-utils.js.map +1 -1
  6. package/esm/development/commands/use-command-caller.js.map +1 -0
  7. package/esm/development/commands/use-command-handler.js.map +1 -0
  8. package/esm/development/commands/use-optional-command-caller.js.map +1 -0
  9. package/esm/development/error/error-code.js.map +1 -0
  10. package/esm/development/events/use-event-emitter.js.map +1 -0
  11. package/esm/development/events/use-event.js.map +1 -0
  12. package/esm/development/events/use-events-handler.js.map +1 -0
  13. package/esm/development/events/use-events.js.map +1 -0
  14. package/esm/development/provision/create-injectables-provider.js.map +1 -0
  15. package/esm/development/provision/ioc-context.js.map +1 -0
  16. package/esm/development/provision/ioc-provider.js.map +1 -0
  17. package/esm/development/provision/use-container-revision.js.map +1 -0
  18. package/esm/development/provision/use-container.js.map +1 -0
  19. package/esm/development/provision/use-injection.js.map +1 -0
  20. package/esm/development/provision/use-ioc-context.js.map +1 -0
  21. package/esm/development/provision/use-optional-injection.js.map +1 -0
  22. package/esm/development/queries/use-optional-query-caller.js.map +1 -0
  23. package/esm/development/queries/use-optional-sync-query-caller.js.map +1 -0
  24. package/esm/development/queries/use-query-caller.js.map +1 -0
  25. package/esm/development/queries/use-query-handler.js.map +1 -0
  26. package/esm/development/queries/use-sync-query-caller.js.map +1 -0
  27. package/esm/development/{wirestate-react/test-utils → test-utils}/with-ioc-provider.js +1 -7
  28. package/esm/development/test-utils/with-ioc-provider.js.map +1 -0
  29. package/esm/production/commands/use-command-caller.js.map +1 -0
  30. package/esm/production/commands/use-command-handler.js.map +1 -0
  31. package/esm/production/commands/use-optional-command-caller.js.map +1 -0
  32. package/esm/production/error/error-code.js.map +1 -0
  33. package/esm/production/events/use-event-emitter.js.map +1 -0
  34. package/esm/production/events/use-event.js.map +1 -0
  35. package/esm/production/events/use-events-handler.js.map +1 -0
  36. package/esm/production/events/use-events.js.map +1 -0
  37. package/esm/production/provision/create-injectables-provider.js.map +1 -0
  38. package/esm/production/provision/ioc-context.js.map +1 -0
  39. package/esm/production/provision/ioc-provider.js.map +1 -0
  40. package/esm/production/provision/use-container-revision.js.map +1 -0
  41. package/esm/production/provision/use-container.js.map +1 -0
  42. package/esm/production/provision/use-injection.js.map +1 -0
  43. package/esm/production/provision/use-ioc-context.js.map +1 -0
  44. package/esm/production/provision/use-optional-injection.js.map +1 -0
  45. package/esm/production/queries/use-optional-query-caller.js.map +1 -0
  46. package/esm/production/queries/use-optional-sync-query-caller.js.map +1 -0
  47. package/esm/production/queries/use-query-caller.js.map +1 -0
  48. package/esm/production/queries/use-query-handler.js.map +1 -0
  49. package/esm/production/queries/use-sync-query-caller.js.map +1 -0
  50. package/esm/production/test-utils/with-ioc-provider.js +1 -0
  51. package/esm/production/test-utils/with-ioc-provider.js.map +1 -0
  52. package/package.json +1 -1
  53. package/esm/development/wirestate-core/bind/bind-constant.js +0 -19
  54. package/esm/development/wirestate-core/bind/bind-constant.js.map +0 -1
  55. package/esm/development/wirestate-core/bind/bind-dynamic-value.js +0 -28
  56. package/esm/development/wirestate-core/bind/bind-dynamic-value.js.map +0 -1
  57. package/esm/development/wirestate-core/bind/bind-entry.js +0 -39
  58. package/esm/development/wirestate-core/bind/bind-entry.js.map +0 -1
  59. package/esm/development/wirestate-core/bind/bind-service.js +0 -253
  60. package/esm/development/wirestate-core/bind/bind-service.js.map +0 -1
  61. package/esm/development/wirestate-core/bind/get-entry-token.js +0 -14
  62. package/esm/development/wirestate-core/bind/get-entry-token.js.map +0 -1
  63. package/esm/development/wirestate-core/commands/command-bus.js +0 -112
  64. package/esm/development/wirestate-core/commands/command-bus.js.map +0 -1
  65. package/esm/development/wirestate-core/commands/get-command-handler-metadata.js +0 -27
  66. package/esm/development/wirestate-core/commands/get-command-handler-metadata.js.map +0 -1
  67. package/esm/development/wirestate-core/container/create-ioc-container.js +0 -35
  68. package/esm/development/wirestate-core/container/create-ioc-container.js.map +0 -1
  69. package/esm/development/wirestate-core/container/wire-scope.js +0 -151
  70. package/esm/development/wirestate-core/container/wire-scope.js.map +0 -1
  71. package/esm/development/wirestate-core/error/error-code.js +0 -10
  72. package/esm/development/wirestate-core/error/error-code.js.map +0 -1
  73. package/esm/development/wirestate-core/error/wirestate-error.js +0 -29
  74. package/esm/development/wirestate-core/error/wirestate-error.js.map +0 -1
  75. package/esm/development/wirestate-core/events/build-event-dispatcher.js +0 -39
  76. package/esm/development/wirestate-core/events/build-event-dispatcher.js.map +0 -1
  77. package/esm/development/wirestate-core/events/event-bus.js +0 -52
  78. package/esm/development/wirestate-core/events/event-bus.js.map +0 -1
  79. package/esm/development/wirestate-core/events/get-event-handler-metadata.js +0 -27
  80. package/esm/development/wirestate-core/events/get-event-handler-metadata.js.map +0 -1
  81. package/esm/development/wirestate-core/queries/get-query-handler-metadata.js +0 -27
  82. package/esm/development/wirestate-core/queries/get-query-handler-metadata.js.map +0 -1
  83. package/esm/development/wirestate-core/queries/query-bus.js +0 -99
  84. package/esm/development/wirestate-core/queries/query-bus.js.map +0 -1
  85. package/esm/development/wirestate-core/registry.js +0 -56
  86. package/esm/development/wirestate-core/registry.js.map +0 -1
  87. package/esm/development/wirestate-core/service/get-activated-handler-metadata.js +0 -27
  88. package/esm/development/wirestate-core/service/get-activated-handler-metadata.js.map +0 -1
  89. package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js +0 -27
  90. package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js.map +0 -1
  91. package/esm/development/wirestate-core/test-utils/mock-bind-entry.js +0 -24
  92. package/esm/development/wirestate-core/test-utils/mock-bind-entry.js.map +0 -1
  93. package/esm/development/wirestate-core/test-utils/mock-container.js +0 -52
  94. package/esm/development/wirestate-core/test-utils/mock-container.js.map +0 -1
  95. package/esm/development/wirestate-core/types/commands.js +0 -12
  96. package/esm/development/wirestate-core/types/commands.js.map +0 -1
  97. package/esm/development/wirestate-react/commands/use-command-caller.js.map +0 -1
  98. package/esm/development/wirestate-react/commands/use-command-handler.js.map +0 -1
  99. package/esm/development/wirestate-react/commands/use-optional-command-caller.js.map +0 -1
  100. package/esm/development/wirestate-react/error/error-code.js.map +0 -1
  101. package/esm/development/wirestate-react/events/use-event-emitter.js.map +0 -1
  102. package/esm/development/wirestate-react/events/use-event.js.map +0 -1
  103. package/esm/development/wirestate-react/events/use-events-handler.js.map +0 -1
  104. package/esm/development/wirestate-react/events/use-events.js.map +0 -1
  105. package/esm/development/wirestate-react/provision/create-injectables-provider.js.map +0 -1
  106. package/esm/development/wirestate-react/provision/ioc-context.js.map +0 -1
  107. package/esm/development/wirestate-react/provision/ioc-provider.js.map +0 -1
  108. package/esm/development/wirestate-react/provision/use-container-revision.js.map +0 -1
  109. package/esm/development/wirestate-react/provision/use-container.js.map +0 -1
  110. package/esm/development/wirestate-react/provision/use-injection.js.map +0 -1
  111. package/esm/development/wirestate-react/provision/use-ioc-context.js.map +0 -1
  112. package/esm/development/wirestate-react/provision/use-optional-injection.js.map +0 -1
  113. package/esm/development/wirestate-react/queries/use-optional-query-caller.js.map +0 -1
  114. package/esm/development/wirestate-react/queries/use-optional-sync-query-caller.js.map +0 -1
  115. package/esm/development/wirestate-react/queries/use-query-caller.js.map +0 -1
  116. package/esm/development/wirestate-react/queries/use-query-handler.js.map +0 -1
  117. package/esm/development/wirestate-react/queries/use-sync-query-caller.js.map +0 -1
  118. package/esm/development/wirestate-react/test-utils/with-ioc-provider.js.map +0 -1
  119. package/esm/production/wirestate-core/bind/bind-constant.js +0 -1
  120. package/esm/production/wirestate-core/bind/bind-constant.js.map +0 -1
  121. package/esm/production/wirestate-core/bind/bind-dynamic-value.js +0 -1
  122. package/esm/production/wirestate-core/bind/bind-dynamic-value.js.map +0 -1
  123. package/esm/production/wirestate-core/bind/bind-entry.js +0 -1
  124. package/esm/production/wirestate-core/bind/bind-entry.js.map +0 -1
  125. package/esm/production/wirestate-core/bind/bind-service.js +0 -1
  126. package/esm/production/wirestate-core/bind/bind-service.js.map +0 -1
  127. package/esm/production/wirestate-core/bind/get-entry-token.js +0 -1
  128. package/esm/production/wirestate-core/bind/get-entry-token.js.map +0 -1
  129. package/esm/production/wirestate-core/commands/command-bus.js +0 -1
  130. package/esm/production/wirestate-core/commands/command-bus.js.map +0 -1
  131. package/esm/production/wirestate-core/commands/get-command-handler-metadata.js +0 -1
  132. package/esm/production/wirestate-core/commands/get-command-handler-metadata.js.map +0 -1
  133. package/esm/production/wirestate-core/container/create-ioc-container.js +0 -1
  134. package/esm/production/wirestate-core/container/create-ioc-container.js.map +0 -1
  135. package/esm/production/wirestate-core/container/wire-scope.js +0 -1
  136. package/esm/production/wirestate-core/container/wire-scope.js.map +0 -1
  137. package/esm/production/wirestate-core/error/error-code.js +0 -1
  138. package/esm/production/wirestate-core/error/error-code.js.map +0 -1
  139. package/esm/production/wirestate-core/error/wirestate-error.js +0 -1
  140. package/esm/production/wirestate-core/error/wirestate-error.js.map +0 -1
  141. package/esm/production/wirestate-core/events/build-event-dispatcher.js +0 -1
  142. package/esm/production/wirestate-core/events/build-event-dispatcher.js.map +0 -1
  143. package/esm/production/wirestate-core/events/event-bus.js +0 -1
  144. package/esm/production/wirestate-core/events/event-bus.js.map +0 -1
  145. package/esm/production/wirestate-core/events/get-event-handler-metadata.js +0 -1
  146. package/esm/production/wirestate-core/events/get-event-handler-metadata.js.map +0 -1
  147. package/esm/production/wirestate-core/queries/get-query-handler-metadata.js +0 -1
  148. package/esm/production/wirestate-core/queries/get-query-handler-metadata.js.map +0 -1
  149. package/esm/production/wirestate-core/queries/query-bus.js +0 -1
  150. package/esm/production/wirestate-core/queries/query-bus.js.map +0 -1
  151. package/esm/production/wirestate-core/registry.js +0 -1
  152. package/esm/production/wirestate-core/registry.js.map +0 -1
  153. package/esm/production/wirestate-core/service/get-activated-handler-metadata.js +0 -1
  154. package/esm/production/wirestate-core/service/get-activated-handler-metadata.js.map +0 -1
  155. package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js +0 -1
  156. package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js.map +0 -1
  157. package/esm/production/wirestate-core/test-utils/mock-bind-entry.js +0 -1
  158. package/esm/production/wirestate-core/test-utils/mock-bind-entry.js.map +0 -1
  159. package/esm/production/wirestate-core/test-utils/mock-container.js +0 -1
  160. package/esm/production/wirestate-core/test-utils/mock-container.js.map +0 -1
  161. package/esm/production/wirestate-core/types/commands.js +0 -1
  162. package/esm/production/wirestate-core/types/commands.js.map +0 -1
  163. package/esm/production/wirestate-react/commands/use-command-caller.js.map +0 -1
  164. package/esm/production/wirestate-react/commands/use-command-handler.js.map +0 -1
  165. package/esm/production/wirestate-react/commands/use-optional-command-caller.js.map +0 -1
  166. package/esm/production/wirestate-react/error/error-code.js.map +0 -1
  167. package/esm/production/wirestate-react/events/use-event-emitter.js.map +0 -1
  168. package/esm/production/wirestate-react/events/use-event.js.map +0 -1
  169. package/esm/production/wirestate-react/events/use-events-handler.js.map +0 -1
  170. package/esm/production/wirestate-react/events/use-events.js.map +0 -1
  171. package/esm/production/wirestate-react/provision/create-injectables-provider.js.map +0 -1
  172. package/esm/production/wirestate-react/provision/ioc-context.js.map +0 -1
  173. package/esm/production/wirestate-react/provision/ioc-provider.js.map +0 -1
  174. package/esm/production/wirestate-react/provision/use-container-revision.js.map +0 -1
  175. package/esm/production/wirestate-react/provision/use-container.js.map +0 -1
  176. package/esm/production/wirestate-react/provision/use-injection.js.map +0 -1
  177. package/esm/production/wirestate-react/provision/use-ioc-context.js.map +0 -1
  178. package/esm/production/wirestate-react/provision/use-optional-injection.js.map +0 -1
  179. package/esm/production/wirestate-react/queries/use-optional-query-caller.js.map +0 -1
  180. package/esm/production/wirestate-react/queries/use-optional-sync-query-caller.js.map +0 -1
  181. package/esm/production/wirestate-react/queries/use-query-caller.js.map +0 -1
  182. package/esm/production/wirestate-react/queries/use-query-handler.js.map +0 -1
  183. package/esm/production/wirestate-react/queries/use-sync-query-caller.js.map +0 -1
  184. package/esm/production/wirestate-react/test-utils/with-ioc-provider.js +0 -1
  185. package/esm/production/wirestate-react/test-utils/with-ioc-provider.js.map +0 -1
  186. /package/esm/development/{wirestate-react/commands → commands}/use-command-caller.js +0 -0
  187. /package/esm/development/{wirestate-react/commands → commands}/use-command-handler.js +0 -0
  188. /package/esm/development/{wirestate-react/commands → commands}/use-optional-command-caller.js +0 -0
  189. /package/esm/development/{wirestate-react/error → error}/error-code.js +0 -0
  190. /package/esm/development/{wirestate-react/events → events}/use-event-emitter.js +0 -0
  191. /package/esm/development/{wirestate-react/events → events}/use-event.js +0 -0
  192. /package/esm/development/{wirestate-react/events → events}/use-events-handler.js +0 -0
  193. /package/esm/development/{wirestate-react/events → events}/use-events.js +0 -0
  194. /package/esm/development/{wirestate-react/index.js → index.js} +0 -0
  195. /package/esm/development/{wirestate-react/index.js.map → index.js.map} +0 -0
  196. /package/esm/development/{wirestate-react/provision → provision}/create-injectables-provider.js +0 -0
  197. /package/esm/development/{wirestate-react/provision → provision}/ioc-context.js +0 -0
  198. /package/esm/development/{wirestate-react/provision → provision}/ioc-provider.js +0 -0
  199. /package/esm/development/{wirestate-react/provision → provision}/use-container-revision.js +0 -0
  200. /package/esm/development/{wirestate-react/provision → provision}/use-container.js +0 -0
  201. /package/esm/development/{wirestate-react/provision → provision}/use-injection.js +0 -0
  202. /package/esm/development/{wirestate-react/provision → provision}/use-ioc-context.js +0 -0
  203. /package/esm/development/{wirestate-react/provision → provision}/use-optional-injection.js +0 -0
  204. /package/esm/development/{wirestate-react/queries → queries}/use-optional-query-caller.js +0 -0
  205. /package/esm/development/{wirestate-react/queries → queries}/use-optional-sync-query-caller.js +0 -0
  206. /package/esm/development/{wirestate-react/queries → queries}/use-query-caller.js +0 -0
  207. /package/esm/development/{wirestate-react/queries → queries}/use-query-handler.js +0 -0
  208. /package/esm/development/{wirestate-react/queries → queries}/use-sync-query-caller.js +0 -0
  209. /package/esm/development/{wirestate-react/test-utils.js → test-utils.js} +0 -0
  210. /package/esm/development/{wirestate-react/test-utils.js.map → test-utils.js.map} +0 -0
  211. /package/esm/production/{wirestate-react/commands → commands}/use-command-caller.js +0 -0
  212. /package/esm/production/{wirestate-react/commands → commands}/use-command-handler.js +0 -0
  213. /package/esm/production/{wirestate-react/commands → commands}/use-optional-command-caller.js +0 -0
  214. /package/esm/production/{wirestate-react/error → error}/error-code.js +0 -0
  215. /package/esm/production/{wirestate-react/events → events}/use-event-emitter.js +0 -0
  216. /package/esm/production/{wirestate-react/events → events}/use-event.js +0 -0
  217. /package/esm/production/{wirestate-react/events → events}/use-events-handler.js +0 -0
  218. /package/esm/production/{wirestate-react/events → events}/use-events.js +0 -0
  219. /package/esm/production/{wirestate-react/index.js → index.js} +0 -0
  220. /package/esm/production/{wirestate-react/index.js.map → index.js.map} +0 -0
  221. /package/esm/production/{wirestate-react/provision → provision}/create-injectables-provider.js +0 -0
  222. /package/esm/production/{wirestate-react/provision → provision}/ioc-context.js +0 -0
  223. /package/esm/production/{wirestate-react/provision → provision}/ioc-provider.js +0 -0
  224. /package/esm/production/{wirestate-react/provision → provision}/use-container-revision.js +0 -0
  225. /package/esm/production/{wirestate-react/provision → provision}/use-container.js +0 -0
  226. /package/esm/production/{wirestate-react/provision → provision}/use-injection.js +0 -0
  227. /package/esm/production/{wirestate-react/provision → provision}/use-ioc-context.js +0 -0
  228. /package/esm/production/{wirestate-react/provision → provision}/use-optional-injection.js +0 -0
  229. /package/esm/production/{wirestate-react/queries → queries}/use-optional-query-caller.js +0 -0
  230. /package/esm/production/{wirestate-react/queries → queries}/use-optional-sync-query-caller.js +0 -0
  231. /package/esm/production/{wirestate-react/queries → queries}/use-query-caller.js +0 -0
  232. /package/esm/production/{wirestate-react/queries → queries}/use-query-handler.js +0 -0
  233. /package/esm/production/{wirestate-react/queries → queries}/use-sync-query-caller.js +0 -0
  234. /package/esm/production/{wirestate-react/test-utils.js → test-utils.js} +0 -0
  235. /package/esm/production/{wirestate-react/test-utils.js.map → test-utils.js.map} +0 -0
@@ -1,1058 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var tslib = require('tslib');
4
- var inversify = require('inversify');
3
+ var testUtils = require('@wirestate/core/test-utils');
5
4
  var react = require('react');
6
5
  var iocProvider = require('./lib.js');
7
6
  require('@wirestate/core');
8
7
 
9
- var ERROR_CODE_GENERIC = 1;
10
- var ERROR_CODE_INVALID_ARGUMENTS = 51;
11
- var ERROR_CODE_BINDING_SCOPE = 52;
12
- var ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER = 101;
13
- var ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER = 102;
14
- var ERROR_CODE_ACCESS_BEFORE_ACTIVATION = 200;
15
- var ERROR_CODE_ACCESS_AFTER_DISPOSAL = 201;
16
-
17
- /**
18
- * A custom error class that contains generic error information for Wirestate-related issues.
19
- *
20
- * This class extends the native `Error` class and is used to represent errors specific
21
- * to the Wirestate library, providing more structured error handling.
22
- */
23
- var WirestateError = /** @class */function (_super) {
24
- tslib.__extends(WirestateError, _super);
25
- function WirestateError(code, detail) {
26
- if (code === void 0) {
27
- code = ERROR_CODE_GENERIC;
28
- }
29
- var _this = _super.call(this) || this;
30
- /**
31
- * Name or error class to help differentiate error class in minified environments.
32
- */
33
- _this.name = "WirestateError";
34
- _this.code = code;
35
- _this.message = detail || "Wirestate error.";
36
- return _this;
37
- }
38
- return WirestateError;
39
- }(Error);
40
-
41
- /**
42
- * Command execution status.
43
- */
44
- var CommandStatus;
45
- (function (CommandStatus) {
46
- CommandStatus["PENDING"] = "pending";
47
- CommandStatus["SETTLED"] = "settled";
48
- CommandStatus["ERROR"] = "error";
49
- })(CommandStatus || (CommandStatus = {}));
50
-
51
- /**
52
- * Dispatches commands to handlers.
53
- *
54
- * Unlike queries, command execution always wraps the handler in a promise
55
- * and returns a descriptor with task, status, and responder.
56
- */
57
- var CommandBus = /** @class */function () {
58
- function CommandBus() {
59
- /**
60
- * Internal handler storage.
61
- * Uses a stack for each command type to support shadowing.
62
- */
63
- this.handlers = new Map();
64
- }
65
- /**
66
- * Registers a command handler.
67
- * Returns an unregister function.
68
- *
69
- * @param type - command type
70
- * @param handler - handler function
71
- * @returns unregister function
72
- */
73
- CommandBus.prototype.register = function (type, handler) {
74
- var _this = this;
75
- var stack = this.handlers.get(type);
76
- if (!stack) {
77
- stack = [];
78
- this.handlers.set(type, stack);
79
- }
80
- stack.push(handler);
81
- return function () {
82
- var current = _this.handlers.get(type);
83
- if (!current) {
84
- return;
85
- }
86
- var index = current.indexOf(handler);
87
- if (index >= 0) {
88
- current.splice(index, 1);
89
- }
90
- // Clean empty stacks.
91
- if (current.length === 0) {
92
- _this.handlers.delete(type);
93
- }
94
- };
95
- };
96
- /**
97
- * Dispatches a command to the last registered handler.
98
- * Wraps the handler execution in a promise and returns a descriptor.
99
- *
100
- * @param type - command type
101
- * @param data - command payload
102
- * @returns command descriptor with task, status, and responder
103
- *
104
- * @throws if no handler is registered
105
- */
106
- CommandBus.prototype.command = function (type, data) {
107
- var stack = this.handlers.get(type);
108
- if (!(stack === null || stack === void 0 ? void 0 : stack.length)) {
109
- throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER, "No command handler registered in container for type: '".concat(String(type), "'."));
110
- }
111
- var handler = stack[stack.length - 1];
112
- var descriptor = {
113
- task: null,
114
- status: CommandStatus.PENDING
115
- };
116
- descriptor.task = Promise.resolve().then(function () {
117
- return handler(data);
118
- }).then(function (result) {
119
- descriptor.status = CommandStatus.SETTLED;
120
- return result;
121
- }).catch(function (error) {
122
- descriptor.status = CommandStatus.ERROR;
123
- throw error;
124
- });
125
- return descriptor;
126
- };
127
- /**
128
- * Dispatches a command to the last registered handler, returning null if no handler exists.
129
- *
130
- * @param type - command type
131
- * @param data - command payload
132
- * @returns command descriptor or null if no handler is registered
133
- */
134
- CommandBus.prototype.commandOptional = function (type, data) {
135
- var stack = this.handlers.get(type);
136
- return (stack === null || stack === void 0 ? void 0 : stack.length) ? this.command(type, data) : null;
137
- };
138
- /**
139
- * Checks if a handler is registered for the given type.
140
- *
141
- * @param type - command type
142
- * @returns true if handler exists
143
- */
144
- CommandBus.prototype.has = function (type) {
145
- var _a;
146
- return Boolean((_a = this.handlers.get(type)) === null || _a === void 0 ? void 0 : _a.length);
147
- };
148
- /**
149
- * Removes all registered handlers.
150
- */
151
- CommandBus.prototype.clear = function () {
152
- this.handlers.clear();
153
- };
154
- return CommandBus;
155
- }();
156
-
157
- /**
158
- * Token for the container-scoped seeds map.
159
- */
160
- var SEEDS_TOKEN = Symbol("@wirestate/seeds");
161
- /**
162
- * Token for the container-scoped shared seed object.
163
- */
164
- var SEED_TOKEN = Symbol("@wirestate/seed");
165
- /**
166
- * Map of class constructors to their declared query handlers.
167
- * Inherited via a prototype chain at resolve time.
168
- */
169
- var QUERY_HANDLER_METADATA = new WeakMap();
170
- /**
171
- * Map of class constructors to their declared command handlers.
172
- * Inherited via a prototype chain at resolve time.
173
- */
174
- var COMMAND_HANDLER_METADATA = new WeakMap();
175
- /**
176
- * Map of class constructors to their `@OnActivated`-decorated method names.
177
- * Inherited via a prototype chain at resolve time.
178
- */
179
- var ACTIVATED_HANDLER_METADATA = new WeakMap();
180
- /**
181
- * Map of class constructors to their `@OnDeactivation`-decorated method names.
182
- * Inherited via a prototype chain at resolve time.
183
- */
184
- var DEACTIVATION_HANDLER_METADATA = new WeakMap();
185
- /**
186
- * Map of class constructors for their declared event handlers.
187
- * Inherited via a prototype chain at resolve time.
188
- */
189
- var EVENT_HANDLER_METADATA = new WeakMap();
190
- /**
191
- * Private storage for service-to-container references.
192
- */
193
- var CONTAINER_REFS_BY_SERVICE = new WeakMap();
194
- /**
195
- * Private storage for injected WireScope instances per service.
196
- */
197
- var WIRE_SCOPES_BY_SERVICE = new WeakMap();
198
- /**
199
- * Private storage for service event unsubscribers.
200
- */
201
- var EVENT_UNSUBSCRIBERS_BY_SERVICE = new WeakMap();
202
- /**
203
- * Private storage for service query unregisters.
204
- */
205
- var QUERY_UNREGISTERS_BY_SERVICE = new WeakMap();
206
- /**
207
- * Private storage for service command unregisters.
208
- */
209
- var COMMAND_UNREGISTERS_BY_SERVICE = new WeakMap();
210
-
211
- /**
212
- * Retrieves `@OnCommand` metadata from the class hierarchy.
213
- * Returns handlers ordered from base to derived class.
214
- *
215
- * @param instance - service instance
216
- * @returns metadata list
217
- * @internal
218
- */
219
- function getCommandHandlerMetadata(instance) {
220
- var constructor = instance.constructor;
221
- var chain = [];
222
- // Traverse prototype chain up to Object/Function
223
- while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
224
- var own = COMMAND_HANDLER_METADATA.get(constructor);
225
- if (own && own.length > 0) {
226
- chain.push(own);
227
- }
228
- constructor = Object.getPrototypeOf(constructor);
229
- }
230
- // Reverse to ensure parent-first execution order.
231
- return chain.reverse().flat();
232
- }
233
-
234
- /**
235
- * Dispatches events to subscribers.
236
- */
237
- var EventBus = /** @class */function () {
238
- function EventBus() {
239
- this.handlers = new Set();
240
- }
241
- /**
242
- * Broadcasts an event to all subscribers.
243
- *
244
- * @param event - event to emit
245
- */
246
- EventBus.prototype.emit = function (event) {
247
- // Snapshot prevents concurrent modification errors if handlers sub/unsub during emit.
248
- var snapshot = Array.from(this.handlers);
249
- for (var _i = 0, snapshot_1 = snapshot; _i < snapshot_1.length; _i++) {
250
- var handler = snapshot_1[_i];
251
- try {
252
- handler(event);
253
- } catch (error) {
254
- // Prevent one failing listener from stalling the entire bus.
255
- console.error("[wirestate] Event handler threw:", error);
256
- }
257
- }
258
- };
259
- /**
260
- * Subscribes a handler to all events.
261
- * Returns an unsubscribe function.
262
- *
263
- * @param handler - event handler function
264
- * @returns unsubscribe function
265
- */
266
- EventBus.prototype.subscribe = function (handler) {
267
- var _this = this;
268
- this.handlers.add(handler);
269
- return function () {
270
- _this.handlers.delete(handler);
271
- };
272
- };
273
- /**
274
- * Removes all registered handlers.
275
- *
276
- * @internal
277
- */
278
- EventBus.prototype.clear = function () {
279
- this.handlers.clear();
280
- };
281
- return EventBus;
282
- }();
283
-
284
- /**
285
- * Dispatches queries to handlers.
286
- */
287
- var QueryBus = /** @class */function () {
288
- function QueryBus() {
289
- /**
290
- * Internal handler storage.
291
- * Uses a stack for each query type to support shadowing (e.g., component-level vs service-level).
292
- */
293
- this.handlers = new Map();
294
- }
295
- /**
296
- * Registers a query handler.
297
- * Returns an unregister function.
298
- *
299
- * @param type - query type
300
- * @param handler - handler function
301
- * @returns unregister function
302
- */
303
- QueryBus.prototype.register = function (type, handler) {
304
- var _this = this;
305
- var stack = this.handlers.get(type);
306
- if (!stack) {
307
- stack = [];
308
- this.handlers.set(type, stack);
309
- }
310
- stack.push(handler);
311
- return function () {
312
- var current = _this.handlers.get(type);
313
- if (!current) {
314
- return;
315
- }
316
- var index = current.indexOf(handler);
317
- if (index >= 0) {
318
- current.splice(index, 1);
319
- }
320
- // Clean empty stacks.
321
- if (current.length === 0) {
322
- _this.handlers.delete(type);
323
- }
324
- };
325
- };
326
- /**
327
- * Dispatches a query to the last registered handler.
328
- *
329
- * @param type - query type
330
- * @param data - query payload
331
- * @returns query result
332
- *
333
- * @throws if no handler is registered
334
- */
335
- QueryBus.prototype.query = function (type, data) {
336
- var stack = this.handlers.get(type);
337
- // Always use the top of the stack (most recent registration) if handlers are available.
338
- if (stack === null || stack === void 0 ? void 0 : stack.length) {
339
- return stack[stack.length - 1](data);
340
- }
341
- throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER, "No query handler registered in container for type: '".concat(String(type), "'."));
342
- };
343
- /**
344
- * Dispatches a query to the last registered handler, returning null if no handler exists.
345
- *
346
- * @param type - query type
347
- * @param data - query payload
348
- * @returns query result or null if no handler is registered
349
- */
350
- QueryBus.prototype.queryOptional = function (type, data) {
351
- var stack = this.handlers.get(type);
352
- if (stack === null || stack === void 0 ? void 0 : stack.length) {
353
- return stack[stack.length - 1](data);
354
- }
355
- return null;
356
- };
357
- /**
358
- * Checks if a handler is registered for the given type.
359
- *
360
- * @param type - query type
361
- * @returns true if handler exists
362
- */
363
- QueryBus.prototype.has = function (type) {
364
- var stack = this.handlers.get(type);
365
- return Boolean(stack && stack.length);
366
- };
367
- /**
368
- * Removes all registered handlers.
369
- *
370
- * @internal
371
- */
372
- QueryBus.prototype.clear = function () {
373
- this.handlers.clear();
374
- };
375
- return QueryBus;
376
- }();
377
-
378
- /**
379
- * Injectable scope providing access to wirestate buses and seeds.
380
- * Each injecting service receives its own instance (transient scope).
381
- * The scope is activated and deactivated automatically alongside its owner service.
382
- */
383
- var WireScope = /** @class */function () {
384
- function WireScope(container) {
385
- this.container = container;
386
- /**
387
- * Whether the scope was deactivated and disposed from the container.
388
- */
389
- this.isDisposed = false;
390
- }
391
- /**
392
- * Access the IoC container.
393
- * Available only for activated instances of scope.
394
- *
395
- * @returns active container
396
- *
397
- * @throws WirestateError if scope is not activated or already disposed
398
- */
399
- WireScope.prototype.getContainer = function () {
400
- if (this.container) {
401
- return this.container;
402
- }
403
- if (this.isDisposed) {
404
- throw new WirestateError(ERROR_CODE_ACCESS_AFTER_DISPOSAL, "WireScope::container accessed after deactivation. Ensure service is properly disposed.");
405
- } else {
406
- throw new WirestateError(ERROR_CODE_ACCESS_BEFORE_ACTIVATION, "WireScope::container accessed before activation. " + "Ensure service is bound to container and is properly resolved.");
407
- }
408
- };
409
- /**
410
- * Resolves a sibling service or injected value.
411
- * Use for lazy resolution or circular dependency breaking.
412
- * Available only for activated containers.
413
- *
414
- * @param injectionId - injection identifier
415
- * @returns resolved injection, service instance, or generic value
416
- *
417
- * @throws WirestateError if scope is not activated
418
- */
419
- WireScope.prototype.resolve = function (injectionId) {
420
- return this.getContainer().get(injectionId);
421
- };
422
- /**
423
- * Resolves a sibling service or injected value.
424
- * Use for lazy resolution or circular dependency breaking.
425
- * Available only for activated containers.
426
- *
427
- * @param injectionId - injection identifier
428
- * @returns resolved injection, service instance, generic value, or null if it is not bound
429
- *
430
- * @throws WirestateError if scope is not activated
431
- */
432
- WireScope.prototype.resolveOptional = function (injectionId) {
433
- var container = this.getContainer();
434
- return container.isBound(injectionId) ? container.get(injectionId) : null;
435
- };
436
- /**
437
- * Broadcasts an event.
438
- * Available only for activated containers.
439
- *
440
- * @param type - type of event to emit
441
- * @param payload - optional payload to send with the event
442
- * @param from - optional sender of the event
443
- *
444
- * @throws WirestateError if scope is not activated
445
- */
446
- WireScope.prototype.emitEvent = function (type, payload, from) {
447
- this.getContainer().get(EventBus).emit({
448
- type: type,
449
- payload: payload,
450
- from: from === undefined ? this : from
451
- });
452
- };
453
- /**
454
- * Dispatches a query and returns the result.
455
- * Available only for activated containers.
456
- *
457
- * @param type - query type
458
- * @param data - query data
459
- * @returns query result
460
- *
461
- * @throws WirestateError if scope is not activated
462
- */
463
- WireScope.prototype.queryData = function (type, data) {
464
- return this.getContainer().get(QueryBus).query(type, data);
465
- };
466
- /**
467
- * Dispatches a query and returns the result.
468
- * Available only for activated containers.
469
- *
470
- * @param type - query type
471
- * @param data - query data
472
- * @returns query result or null if handler is not registered
473
- */
474
- WireScope.prototype.queryOptionalData = function (type, data) {
475
- return this.getContainer().get(QueryBus).queryOptional(type, data);
476
- };
477
- /**
478
- * Dispatches a command and returns the descriptor.
479
- * Available only for activated containers.
480
- *
481
- * @param type - command type
482
- * @param data - command data
483
- * @returns command descriptor
484
- *
485
- * @throws WirestateError if scope is not activated
486
- */
487
- WireScope.prototype.executeCommand = function (type, data) {
488
- return this.getContainer().get(CommandBus).command(type, data);
489
- };
490
- /**
491
- * Dispatches a command and returns the descriptor.
492
- * Available only for activated containers.
493
- *
494
- * @param type - command type
495
- * @param data - command data
496
- * @returns command descriptor or null if handler is not registered
497
- */
498
- WireScope.prototype.executeOptionalCommand = function (type, data) {
499
- return this.getContainer().get(CommandBus).commandOptional(type, data);
500
- };
501
- /**
502
- * Reads seed for the provided injection.
503
- * Returns shared seed if parameters are not provided.
504
- * Available only for activated containers.
505
- *
506
- * @param seed - lookup key
507
- * @returns seed data or null if missing
508
- *
509
- * @throws WirestateError if context is not activated
510
- */
511
- WireScope.prototype.getSeed = function (seed) {
512
- return seed ? this.getContainer().get(SEEDS_TOKEN).get(seed) || null : this.getContainer().get(SEED_TOKEN);
513
- };
514
- WireScope = tslib.__decorate([inversify.injectable(), tslib.__metadata("design:paramtypes", [Object])], WireScope);
515
- return WireScope;
516
- }();
517
-
518
- /**
519
- * Retrieves `@OnEvent` metadata from the class hierarchy.
520
- * Returns handlers ordered from base to derived class.
521
- *
522
- * @param instance - service instance
523
- * @returns metadata list
524
- * @internal
525
- */
526
- function getEventHandlerMetadata(instance) {
527
- var constructor = instance.constructor;
528
- var chain = [];
529
- // Traverse prototype chain up to Object/Function
530
- while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
531
- var own = EVENT_HANDLER_METADATA.get(constructor);
532
- if (own && own.length > 0) {
533
- chain.push(own);
534
- }
535
- constructor = Object.getPrototypeOf(constructor);
536
- }
537
- // Reverse to ensure parent-first execution order
538
- return chain.reverse().flat();
539
- }
540
-
541
- /**
542
- * Composes service event handlers into a single dispatcher.
543
- *
544
- * @param instance - service instance
545
- * @returns event handler or null if no handlers are declared
546
- * @internal
547
- */
548
- function buildEventDispatcher(instance) {
549
- var entries = [];
550
- // Register methods decorated with @OnEvent.
551
- for (var _i = 0, _a = getEventHandlerMetadata(instance); _i < _a.length; _i++) {
552
- var meta = _a[_i];
553
- var method = instance[meta.methodName];
554
- if (typeof method === "function") {
555
- entries.push({
556
- types: meta.types,
557
- handler: method.bind(instance)
558
- });
559
- }
560
- }
561
- if (entries.length) {
562
- return function (event) {
563
- // Fan out events to all matching handlers.
564
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
565
- var entry = entries_1[_i];
566
- if (entry.types === null || entry.types.includes(event.type)) {
567
- entry.handler(event);
568
- }
569
- }
570
- };
571
- } else {
572
- return null;
573
- }
574
- }
575
-
576
- /**
577
- * Retrieves `@OnQuery` metadata from the class hierarchy.
578
- * Returns handlers ordered from base to derived class.
579
- *
580
- * @param instance - service instance
581
- * @returns metadata list
582
- * @internal
583
- */
584
- function getQueryHandlerMetadata(instance) {
585
- var constructor = instance.constructor;
586
- var chain = [];
587
- // Traverse prototype chain up to Object/Function
588
- while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
589
- var own = QUERY_HANDLER_METADATA.get(constructor);
590
- if (own && own.length > 0) {
591
- chain.push(own);
592
- }
593
- constructor = Object.getPrototypeOf(constructor);
594
- }
595
- // Reverse to ensure parent-first execution order.
596
- return chain.reverse().flat();
597
- }
598
-
599
- /**
600
- * Retrieves `@OnActivated` method names from the class hierarchy.
601
- * Returns method names ordered from base to derived class.
602
- *
603
- * @param instance - service instance
604
- * @returns list of method names
605
- * @internal
606
- */
607
- function getActivatedHandlerMetadata(instance) {
608
- var constructor = instance.constructor;
609
- var chain = [];
610
- // Traverse prototype chain up to Object/Function.
611
- while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
612
- var own = ACTIVATED_HANDLER_METADATA.get(constructor);
613
- if (own && own.length > 0) {
614
- chain.push(own);
615
- }
616
- constructor = Object.getPrototypeOf(constructor);
617
- }
618
- // Reverse to ensure parent-first execution order.
619
- return chain.reverse().flat();
620
- }
621
-
622
- /**
623
- * Retrieves `@OnDeactivation` method names from the class hierarchy.
624
- * Returns method names ordered from base to derived class.
625
- *
626
- * @param instance - service instance
627
- * @returns list of method names
628
- * @internal
629
- */
630
- function getDeactivationHandlerMetadata(instance) {
631
- var constructor = instance.constructor;
632
- var chain = [];
633
- // Traverse prototype chain up to Object/Function.
634
- while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
635
- var own = DEACTIVATION_HANDLER_METADATA.get(constructor);
636
- if (own && own.length > 0) {
637
- chain.push(own);
638
- }
639
- constructor = Object.getPrototypeOf(constructor);
640
- }
641
- // Reverse to ensure parent-first execution order.
642
- return chain.reverse().flat();
643
- }
644
-
645
- /**
646
- * Registers a service class in the container with activation/deactivation logic.
647
- * Ensures container references, event subscriptions, command and query handlers are managed correctly.
648
- *
649
- * @param container - target Inversify container
650
- * @param entry - service constructor
651
- * @param options - options object to control binding flow
652
- */
653
- function bindService(container, entry, options) {
654
- // Inversify's fluent binding API only allows a single `.onActivation` /
655
- // `.onDeactivation` call per chain, so we register them on the container
656
- // itself instead — this also works correctly if a later call rebinds the
657
- // same token.
658
- var whenBind = container.bind(entry).to(entry).inSingletonScope();
659
- whenBind.onActivation(function (context, instance) {
660
- // Ensure flag is initialized on activation.
661
- instance.IS_DISPOSED = false;
662
- CONTAINER_REFS_BY_SERVICE.set(instance, container);
663
- attachWireScopes(instance, entry);
664
- // Compose all events listeners into a single bus subscription so we only
665
- // pay one Set lookup per emitted event.
666
- var dispatcher = buildEventDispatcher(instance);
667
- if (dispatcher) {
668
- attachEventsSubscription(instance, dispatcher);
669
- }
670
- // Register every `@OnQuery` handler on the container's QueryBus, and
671
- // remember the unregister functions so we can roll them back when the
672
- // service is deactivated.
673
- var queryBus = container.get(QueryBus);
674
- for (var _i = 0, _a = getQueryHandlerMetadata(instance); _i < _a.length; _i++) {
675
- var meta = _a[_i];
676
- var method = instance[meta.methodName];
677
- if (typeof method !== "function") {
678
- continue;
679
- }
680
- var unregister = queryBus.register(meta.type, method.bind(instance));
681
- attachQueryUnregister(instance, unregister);
682
- }
683
- // Register every `@OnCommand` handler on the container's CommandBus, and
684
- // remember the unregister functions so we can roll them back when the
685
- // service is deactivated.
686
- var commandBus = container.get(CommandBus);
687
- for (var _b = 0, _c = getCommandHandlerMetadata(instance); _b < _c.length; _b++) {
688
- var meta = _c[_b];
689
- var method = instance[meta.methodName];
690
- if (typeof method !== "function") {
691
- continue;
692
- }
693
- var unregister = commandBus.register(meta.type, method.bind(instance));
694
- attachCommandUnregister(instance, unregister);
695
- }
696
- if (options === null || options === void 0 ? void 0 : options.isWithIgnoreLifecycle) ; else {
697
- var _loop_1 = function (methodName) {
698
- var method = instance[methodName];
699
- if (typeof method !== "function") {
700
- return "continue";
701
- }
702
- var result = method.call(instance);
703
- if (result && typeof result.then === "function") {
704
- result.catch(function (error) {
705
- console.error("[wirestate] @OnActivated rejected for:", entry.name, String(methodName), error);
706
- });
707
- }
708
- };
709
- // Call every `@OnActivated`-decorated method in base-to-derived order.
710
- // Fire-and-forget any async init so we stay synchronous from the
711
- // container's point of view.
712
- for (var _d = 0, _e = getActivatedHandlerMetadata(instance); _d < _e.length; _d++) {
713
- var methodName = _e[_d];
714
- _loop_1(methodName);
715
- }
716
- }
717
- return instance;
718
- });
719
- whenBind.onDeactivation(function (instance) {
720
- if (options === null || options === void 0 ? void 0 : options.isWithIgnoreLifecycle) ; else {
721
- // Call every `@OnDeactivation`-decorated method in base-to-derived order.
722
- for (var _i = 0, _a = getDeactivationHandlerMetadata(instance); _i < _a.length; _i++) {
723
- var methodName = _a[_i];
724
- var method = instance[methodName];
725
- if (typeof method === "function") {
726
- method.call(instance);
727
- }
728
- }
729
- }
730
- // Flip the public disposal flag first so any async work already in
731
- // flight (fetches awaiting in @Action methods, scheduled reactions,
732
- // etc.) can short-circuit before it mutates the about-to-die instance.
733
- // The cast is the only write-site for this `readonly` field.
734
- instance.IS_DISPOSED = true;
735
- detachWireScopes(instance);
736
- detachCommandUnregister(instance);
737
- detachQueryUnregister(instance);
738
- detachEventSubscription(instance);
739
- CONTAINER_REFS_BY_SERVICE.delete(instance);
740
- });
741
- }
742
- /**
743
- * Attaches a event subscription to a service.
744
- *
745
- * @param service - service instance
746
- * @param handler - event handler
747
- * @internal
748
- */
749
- function attachEventsSubscription(service, handler) {
750
- var _a;
751
- var bus = (_a = CONTAINER_REFS_BY_SERVICE.get(service)) === null || _a === void 0 ? void 0 : _a.get(EventBus);
752
- if (bus) {
753
- EVENT_UNSUBSCRIBERS_BY_SERVICE.set(service, bus.subscribe(handler));
754
- }
755
- }
756
- /**
757
- * Detaches the event subscription from a service.
758
- *
759
- * @param service - service instance
760
- * @internal
761
- */
762
- function detachEventSubscription(service) {
763
- var unsubscribe = EVENT_UNSUBSCRIBERS_BY_SERVICE.get(service);
764
- if (unsubscribe) {
765
- unsubscribe();
766
- EVENT_UNSUBSCRIBERS_BY_SERVICE.delete(service);
767
- }
768
- }
769
- /**
770
- * Registers a query unregister function for a service.
771
- *
772
- * @param service - service instance
773
- * @param unregister - query unregister function
774
- * @internal
775
- */
776
- function attachQueryUnregister(service, unregister) {
777
- var list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
778
- if (!list) {
779
- list = [];
780
- QUERY_UNREGISTERS_BY_SERVICE.set(service, list);
781
- }
782
- list.push(unregister);
783
- }
784
- /**
785
- * Executes and removes all query unregister functions for a service.
786
- *
787
- * @param service - service instance
788
- * @internal
789
- */
790
- function detachQueryUnregister(service) {
791
- var list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
792
- if (!list) {
793
- return;
794
- }
795
- for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
796
- var unregister = list_1[_i];
797
- unregister();
798
- }
799
- QUERY_UNREGISTERS_BY_SERVICE.delete(service);
800
- }
801
- /**
802
- * Registers a command unregister function for a service.
803
- *
804
- * @param service - service instance
805
- * @param unregister - command unregister function
806
- * @internal
807
- */
808
- function attachCommandUnregister(service, unregister) {
809
- var list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
810
- if (!list) {
811
- list = [];
812
- COMMAND_UNREGISTERS_BY_SERVICE.set(service, list);
813
- }
814
- list.push(unregister);
815
- }
816
- /**
817
- * Executes and removes all command unregister functions for a service.
818
- *
819
- * @param service - service instance
820
- * @internal
821
- */
822
- function detachCommandUnregister(service) {
823
- var list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
824
- if (!list) {
825
- return;
826
- }
827
- for (var _i = 0, list_2 = list; _i < list_2.length; _i++) {
828
- var unregister = list_2[_i];
829
- unregister();
830
- }
831
- COMMAND_UNREGISTERS_BY_SERVICE.delete(service);
832
- }
833
- /**
834
- * Reads `design:paramtypes` from the service constructor to find parameters typed as WireScope.
835
- * Property iteration happens only when the constructor metadata declares a WireScope
836
- * parameter, avoiding false positives from manually created or subclassed scopes.
837
- *
838
- * todo: Simplify this part.
839
- *
840
- * @param service - service instance
841
- * @param Service - service constructor
842
- * @internal
843
- */
844
- function attachWireScopes(service, Service) {
845
- var paramTypes = Reflect.getMetadata("design:paramtypes", Service);
846
- if (!(paramTypes === null || paramTypes === void 0 ? void 0 : paramTypes.some(function (type) {
847
- return type === WireScope;
848
- }))) {
849
- return;
850
- }
851
- var scopes = [];
852
- for (var _i = 0, _a = Object.getOwnPropertyNames(service); _i < _a.length; _i++) {
853
- var key = _a[_i];
854
- var value = service[key];
855
- if ((value === null || value === void 0 ? void 0 : value.constructor) === WireScope) {
856
- scopes.push(value);
857
- }
858
- }
859
- if (scopes.length > 0) {
860
- WIRE_SCOPES_BY_SERVICE.set(service, scopes);
861
- }
862
- }
863
- /**
864
- * Marks all injected WireScope instances for this service as disposed and removes
865
- * the stored references.
866
- *
867
- * todo: Simplify this part.
868
- *
869
- * @param service - service instance
870
- * @internal
871
- */
872
- function detachWireScopes(service) {
873
- var scopes = WIRE_SCOPES_BY_SERVICE.get(service);
874
- if (!scopes) {
875
- return;
876
- }
877
- for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
878
- var scope = scopes_1[_i];
879
- scope.isDisposed = true;
880
- scope.container = null;
881
- }
882
- WIRE_SCOPES_BY_SERVICE.delete(service);
883
- }
884
-
885
- /**
886
- * Binds a constant value to a token in the container.
887
- *
888
- * @param container - target Inversify container
889
- * @param entry - entry descriptor to bind
890
- */
891
- function bindConstant(container, entry) {
892
- if (entry.scopeBindingType && entry.scopeBindingType !== inversify.bindingScopeValues.Singleton) {
893
- throw new WirestateError(ERROR_CODE_BINDING_SCOPE, "Provided unexpected binding scope for constant value.");
894
- }
895
- container.bind(entry.id).toConstantValue(entry.value);
896
- }
897
-
898
- /**
899
- * Binds a constant value to a token in the container.
900
- *
901
- * @param container - target Inversify container
902
- * @param entry - descriptor of entry to bind
903
- */
904
- function bindDynamicValue(container, entry) {
905
- var binding = container.bind(entry.id).toDynamicValue(function () {
906
- if (entry.factory) {
907
- return entry.factory();
908
- }
909
- return entry.value;
910
- });
911
- if (!entry.scopeBindingType) {
912
- return;
913
- } else if (entry.scopeBindingType === inversify.bindingScopeValues.Transient) {
914
- binding.inTransientScope();
915
- } else if (entry.scopeBindingType === inversify.bindingScopeValues.Request) {
916
- binding.inRequestScope();
917
- } else {
918
- binding.inSingletonScope();
919
- }
920
- }
921
-
922
- /**
923
- * Binds a single service entry to the container, dispatching to the
924
- * correct binding strategy based on the descriptor's `type` field.
925
- *
926
- * Supports:
927
- * - Service classes (function entries) - bound as singleton
928
- * - Constant values - bound via `bindConstant`
929
- * - Dynamic values - bound via `toDynamicValue` with optional scope
930
- * - Instance bindings - bound as generic singleton service
931
- *
932
- * @param container - target IOC container to bind into
933
- * @param entry - entry descriptor to bind
934
- * @param options - optional binding configuration
935
- * @returns void
936
- */
937
- function bindEntry(container, entry, options) {
938
- if (options === void 0) {
939
- options = {};
940
- }
941
- if (typeof entry === "function") {
942
- return bindService(container, entry, options);
943
- }
944
- if (!entry.bindingType || entry.bindingType === inversify.bindingTypeValues.ConstantValue) {
945
- return bindConstant(container, entry);
946
- }
947
- if (entry.bindingType === inversify.bindingTypeValues.DynamicValue) {
948
- return bindDynamicValue(container, entry);
949
- }
950
- // Default: treat as class descriptor (Instance binding).
951
- return bindService(container, entry.value, options);
952
- }
953
-
954
- /**
955
- * Binds a service entry to the IoC container for testing purposes.
956
- * This utility uses {@link bindEntry} internally.
957
- * It supports both service classes and injectable descriptors (constants, dynamic values, etc.).
958
- *
959
- * @param container - the IoC container to bind the entry to
960
- * @param entry - the service class or injectable descriptor to bind
961
- * @param options - optional binding configuration
962
- * @returns void
963
- */
964
- function mockBindEntry(container, entry, options) {
965
- if (options === void 0) {
966
- options = {};
967
- }
968
- var skipLifecycle = options.skipLifecycle;
969
- return bindEntry(container, entry, {
970
- isWithIgnoreLifecycle: skipLifecycle
971
- });
972
- }
973
-
974
- /**
975
- * Returns the container token for a service entry.
976
- * For plain service classes the class itself is the token;
977
- * for descriptors the `id` field is used.
978
- *
979
- * @param entry - entry descriptor to get service identifier for
980
- * @returns injectable identifier token
981
- */
982
- function getEntryToken(entry) {
983
- return typeof entry === "function" ? entry : entry.id;
984
- }
985
-
986
- /**
987
- * Creates an IoC container with framework essentials.
988
- *
989
- * @param options - container configuration
990
- * @returns new IoC container
991
- */
992
- function createIocContainer(options) {
993
- var _a;
994
- if (options === void 0) {
995
- options = {};
996
- }
997
- var container = new inversify.Container({
998
- defaultScope: "Singleton",
999
- parent: options.parent
1000
- });
1001
- container.bind(EventBus).toConstantValue(new EventBus());
1002
- container.bind(QueryBus).toConstantValue(new QueryBus());
1003
- container.bind(CommandBus).toConstantValue(new CommandBus());
1004
- container.bind(SEEDS_TOKEN).toConstantValue(new Map());
1005
- container.bind(SEED_TOKEN).toConstantValue((_a = options.seed) !== null && _a !== void 0 ? _a : {});
1006
- container.bind(WireScope).toResolvedValue(function () {
1007
- return new WireScope(container);
1008
- }).inTransientScope();
1009
- return container;
1010
- }
1011
-
1012
- /**
1013
- * Creates and configures a mock IoC container for testing.
1014
- * This utility initializes a new container and binds the provided services or descriptors using {@link mockBindEntry}.
1015
- * It also supports optional immediate activation of services.
1016
- *
1017
- * @param options - configuration options for the mock container
1018
- * @returns a configured InversifyJS {@link Container}
1019
- *
1020
- * @throws {WirestateError} if an identifier in `activate` is not found in `services`
1021
- */
1022
- function mockContainer(options) {
1023
- if (options === void 0) {
1024
- options = {};
1025
- }
1026
- var _a = options.activate,
1027
- activate = _a === void 0 ? [] : _a,
1028
- _b = options.entries,
1029
- entries = _b === void 0 ? [] : _b,
1030
- skipLifecycle = options.skipLifecycle;
1031
- if (activate.length) {
1032
- var serviceTokens = entries.map(function (s) {
1033
- return getEntryToken(s);
1034
- });
1035
- for (var _i = 0, activate_1 = activate; _i < activate_1.length; _i++) {
1036
- var token = activate_1[_i];
1037
- if (!serviceTokens.includes(token)) {
1038
- throw new WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "Provided services for activation not matching list of services to bind.");
1039
- }
1040
- }
1041
- }
1042
- var container = createIocContainer();
1043
- for (var _c = 0, entries_1 = entries; _c < entries_1.length; _c++) {
1044
- var it_1 = entries_1[_c];
1045
- mockBindEntry(container, it_1, {
1046
- skipLifecycle: skipLifecycle
1047
- });
1048
- }
1049
- for (var _d = 0, activate_2 = activate; _d < activate_2.length; _d++) {
1050
- var it_2 = activate_2[_d];
1051
- container.get(it_2);
1052
- }
1053
- return container;
1054
- }
1055
-
1056
8
  /**
1057
9
  * Wraps a component with IocProvider for testing.
1058
10
  *
@@ -1063,7 +15,7 @@ function mockContainer(options) {
1063
15
  */
1064
16
  function withIocProvider(children, container, seed) {
1065
17
  if (container === void 0) {
1066
- container = mockContainer();
18
+ container = testUtils.mockContainer();
1067
19
  }
1068
20
  return react.createElement(iocProvider.IocProvider, {
1069
21
  container: container,