@wirestate/core 0.6.3 → 0.7.0-experimental.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 (167) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +48 -37
  3. package/cjs/development/index.js +325 -91
  4. package/cjs/development/index.js.map +1 -1
  5. package/cjs/development/lib.js +1033 -248
  6. package/cjs/development/lib.js.map +1 -1
  7. package/cjs/development/test-utils.js +95 -32
  8. package/cjs/development/test-utils.js.map +1 -1
  9. package/cjs/production/index.js +1 -1
  10. package/cjs/production/index.js.map +1 -1
  11. package/cjs/production/lib.js +1 -1
  12. package/cjs/production/lib.js.map +1 -1
  13. package/cjs/production/test-utils.js +1 -1
  14. package/cjs/production/test-utils.js.map +1 -1
  15. package/esm/development/alias.js +10 -1
  16. package/esm/development/alias.js.map +1 -1
  17. package/esm/development/bind/bind-constant.js +25 -4
  18. package/esm/development/bind/bind-constant.js.map +1 -1
  19. package/esm/development/bind/bind-dynamic-value.js +27 -7
  20. package/esm/development/bind/bind-dynamic-value.js.map +1 -1
  21. package/esm/development/bind/bind-entry.js +50 -17
  22. package/esm/development/bind/bind-entry.js.map +1 -1
  23. package/esm/development/bind/bind-service.js +71 -19
  24. package/esm/development/bind/bind-service.js.map +1 -1
  25. package/esm/development/bind/get-entry-token.js +21 -5
  26. package/esm/development/bind/get-entry-token.js.map +1 -1
  27. package/esm/development/commands/command-bus.js +93 -46
  28. package/esm/development/commands/command-bus.js.map +1 -1
  29. package/esm/development/commands/command-optional.js +28 -5
  30. package/esm/development/commands/command-optional.js.map +1 -1
  31. package/esm/development/commands/command.js +26 -5
  32. package/esm/development/commands/command.js.map +1 -1
  33. package/esm/development/commands/get-command-handler-metadata.js +8 -3
  34. package/esm/development/commands/get-command-handler-metadata.js.map +1 -1
  35. package/esm/development/commands/on-command.js +19 -3
  36. package/esm/development/commands/on-command.js.map +1 -1
  37. package/esm/development/container/create-base-container.js +57 -0
  38. package/esm/development/container/create-base-container.js.map +1 -0
  39. package/esm/development/container/create-container.js +78 -0
  40. package/esm/development/container/create-container.js.map +1 -0
  41. package/esm/development/container/wire-scope.js +236 -54
  42. package/esm/development/container/wire-scope.js.map +1 -1
  43. package/esm/development/error/error-code.js +2 -1
  44. package/esm/development/error/error-code.js.map +1 -1
  45. package/esm/development/error/wirestate-error.js +25 -4
  46. package/esm/development/error/wirestate-error.js.map +1 -1
  47. package/esm/development/events/build-event-dispatcher.js +20 -2
  48. package/esm/development/events/build-event-dispatcher.js.map +1 -1
  49. package/esm/development/events/emit-event.js +18 -5
  50. package/esm/development/events/emit-event.js.map +1 -1
  51. package/esm/development/events/event-bus.js +58 -9
  52. package/esm/development/events/event-bus.js.map +1 -1
  53. package/esm/development/events/get-event-handler-metadata.js +19 -4
  54. package/esm/development/events/get-event-handler-metadata.js.map +1 -1
  55. package/esm/development/events/on-event.js +31 -2
  56. package/esm/development/events/on-event.js.map +1 -1
  57. package/esm/development/index.js +5 -4
  58. package/esm/development/index.js.map +1 -1
  59. package/esm/development/queries/get-query-handler-metadata.js +20 -4
  60. package/esm/development/queries/get-query-handler-metadata.js.map +1 -1
  61. package/esm/development/queries/on-query.js +24 -2
  62. package/esm/development/queries/on-query.js.map +1 -1
  63. package/esm/development/queries/query-bus.js +82 -31
  64. package/esm/development/queries/query-bus.js.map +1 -1
  65. package/esm/development/queries/query-optional.js +19 -5
  66. package/esm/development/queries/query-optional.js.map +1 -1
  67. package/esm/development/queries/query.js +25 -5
  68. package/esm/development/queries/query.js.map +1 -1
  69. package/esm/development/registry.js +81 -24
  70. package/esm/development/registry.js.map +1 -1
  71. package/esm/development/seeds/apply-seeds.js +19 -5
  72. package/esm/development/seeds/apply-seeds.js.map +1 -1
  73. package/esm/development/seeds/apply-shared-seed.js +16 -4
  74. package/esm/development/seeds/apply-shared-seed.js.map +1 -1
  75. package/esm/development/seeds/tokens.js +31 -0
  76. package/esm/development/seeds/tokens.js.map +1 -0
  77. package/esm/development/seeds/unapply-seeds.js +16 -5
  78. package/esm/development/seeds/unapply-seeds.js.map +1 -1
  79. package/esm/development/service/get-activated-handler-metadata.js +16 -4
  80. package/esm/development/service/get-activated-handler-metadata.js.map +1 -1
  81. package/esm/development/service/get-deactivation-handler-metadata.js +16 -4
  82. package/esm/development/service/get-deactivation-handler-metadata.js.map +1 -1
  83. package/esm/development/service/on-activated.js +22 -2
  84. package/esm/development/service/on-activated.js.map +1 -1
  85. package/esm/development/service/on-deactivation.js +22 -2
  86. package/esm/development/service/on-deactivation.js.map +1 -1
  87. package/esm/development/test-utils/mock-bind-entry.js +17 -7
  88. package/esm/development/test-utils/mock-bind-entry.js.map +1 -1
  89. package/esm/development/test-utils/mock-bind-service.js +17 -7
  90. package/esm/development/test-utils/mock-bind-service.js.map +1 -1
  91. package/esm/development/test-utils/mock-container.js +25 -8
  92. package/esm/development/test-utils/mock-container.js.map +1 -1
  93. package/esm/development/test-utils/mock-service.js +18 -5
  94. package/esm/development/test-utils/mock-service.js.map +1 -1
  95. package/esm/development/test-utils/mock-unbind-service.js +16 -3
  96. package/esm/development/test-utils/mock-unbind-service.js.map +1 -1
  97. package/esm/development/types/commands.js +6 -1
  98. package/esm/development/types/commands.js.map +1 -1
  99. package/esm/production/alias.js +1 -1
  100. package/esm/production/alias.js.map +1 -1
  101. package/esm/production/bind/bind-constant.js +1 -1
  102. package/esm/production/bind/bind-constant.js.map +1 -1
  103. package/esm/production/bind/bind-dynamic-value.js +1 -1
  104. package/esm/production/bind/bind-dynamic-value.js.map +1 -1
  105. package/esm/production/bind/bind-entry.js +1 -1
  106. package/esm/production/bind/bind-entry.js.map +1 -1
  107. package/esm/production/bind/bind-service.js.map +1 -1
  108. package/esm/production/bind/get-entry-token.js.map +1 -1
  109. package/esm/production/commands/command-bus.js +1 -1
  110. package/esm/production/commands/command-bus.js.map +1 -1
  111. package/esm/production/commands/command-optional.js.map +1 -1
  112. package/esm/production/commands/command.js.map +1 -1
  113. package/esm/production/commands/get-command-handler-metadata.js.map +1 -1
  114. package/esm/production/commands/on-command.js.map +1 -1
  115. package/esm/production/container/create-base-container.js +1 -0
  116. package/esm/production/container/create-base-container.js.map +1 -0
  117. package/esm/production/container/create-container.js +1 -0
  118. package/esm/production/container/create-container.js.map +1 -0
  119. package/esm/production/container/wire-scope.js +1 -1
  120. package/esm/production/container/wire-scope.js.map +1 -1
  121. package/esm/production/error/error-code.js +1 -1
  122. package/esm/production/error/error-code.js.map +1 -1
  123. package/esm/production/error/wirestate-error.js.map +1 -1
  124. package/esm/production/events/build-event-dispatcher.js.map +1 -1
  125. package/esm/production/events/emit-event.js.map +1 -1
  126. package/esm/production/events/event-bus.js +1 -1
  127. package/esm/production/events/event-bus.js.map +1 -1
  128. package/esm/production/events/get-event-handler-metadata.js.map +1 -1
  129. package/esm/production/events/on-event.js.map +1 -1
  130. package/esm/production/index.js +1 -1
  131. package/esm/production/queries/get-query-handler-metadata.js.map +1 -1
  132. package/esm/production/queries/on-query.js.map +1 -1
  133. package/esm/production/queries/query-bus.js +1 -1
  134. package/esm/production/queries/query-bus.js.map +1 -1
  135. package/esm/production/queries/query-optional.js.map +1 -1
  136. package/esm/production/queries/query.js.map +1 -1
  137. package/esm/production/registry.js +1 -1
  138. package/esm/production/registry.js.map +1 -1
  139. package/esm/production/seeds/apply-seeds.js +1 -1
  140. package/esm/production/seeds/apply-seeds.js.map +1 -1
  141. package/esm/production/seeds/apply-shared-seed.js +1 -1
  142. package/esm/production/seeds/apply-shared-seed.js.map +1 -1
  143. package/esm/production/seeds/tokens.js +1 -0
  144. package/esm/production/seeds/tokens.js.map +1 -0
  145. package/esm/production/seeds/unapply-seeds.js +1 -1
  146. package/esm/production/seeds/unapply-seeds.js.map +1 -1
  147. package/esm/production/service/get-activated-handler-metadata.js.map +1 -1
  148. package/esm/production/service/get-deactivation-handler-metadata.js.map +1 -1
  149. package/esm/production/service/on-activated.js.map +1 -1
  150. package/esm/production/service/on-deactivation.js.map +1 -1
  151. package/esm/production/test-utils/mock-bind-entry.js +1 -1
  152. package/esm/production/test-utils/mock-bind-entry.js.map +1 -1
  153. package/esm/production/test-utils/mock-bind-service.js +1 -1
  154. package/esm/production/test-utils/mock-bind-service.js.map +1 -1
  155. package/esm/production/test-utils/mock-container.js +1 -1
  156. package/esm/production/test-utils/mock-container.js.map +1 -1
  157. package/esm/production/test-utils/mock-service.js.map +1 -1
  158. package/esm/production/test-utils/mock-unbind-service.js.map +1 -1
  159. package/esm/production/types/commands.js.map +1 -1
  160. package/index.d.ts +1159 -229
  161. package/lib.d.ts +128 -9
  162. package/package.json +1 -2
  163. package/test-utils.d.ts +140 -40
  164. package/esm/development/container/create-ioc-container.js +0 -35
  165. package/esm/development/container/create-ioc-container.js.map +0 -1
  166. package/esm/production/container/create-ioc-container.js +0 -1
  167. package/esm/production/container/create-ioc-container.js.map +0 -1
@@ -5,12 +5,18 @@ import { ERROR_CODE_ACCESS_AFTER_DISPOSAL, ERROR_CODE_ACCESS_BEFORE_ACTIVATION }
5
5
  import { WirestateError } from '../error/wirestate-error.js';
6
6
  import { EventBus } from '../events/event-bus.js';
7
7
  import { QueryBus } from '../queries/query-bus.js';
8
- import { SEEDS_TOKEN, SEED_TOKEN } from '../registry.js';
8
+ import { SEEDS_TOKEN, SEED_TOKEN } from '../seeds/tokens.js';
9
9
 
10
10
  /**
11
- * Injectable scope providing access to wirestate buses and seeds.
12
- * Each injecting service receives its own instance (transient scope).
13
- * The scope is activated and deactivated automatically alongside its owner service.
11
+ * A transient bridge providing services with access to Wirestate buses, lazy resolution, and seeds.
12
+ *
13
+ * @remarks
14
+ * Every service bound via {@link bindService} receives its own unique `WireScope` instance.
15
+ * It acts as a facade to the IoC container while enforcing lifecycle safety.
16
+ *
17
+ * Methods are available only while the scope is "active" (after service activation and before deactivation).
18
+ *
19
+ * @group Container
14
20
  */
15
21
  var WireScope = /** @class */function () {
16
22
  function WireScope(container) {
@@ -21,12 +27,18 @@ var WireScope = /** @class */function () {
21
27
  this.isDisposed = false;
22
28
  }
23
29
  /**
24
- * Access the IoC container.
25
- * Available only for activated instances of scope.
30
+ * Provides direct access to the underlying Inversify {@link Container}.
26
31
  *
27
- * @returns active container
32
+ * @returns The active {@link Container}.
28
33
  *
29
- * @throws WirestateError if scope is not activated or already disposed
34
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const container: Container = scope.getContainer();
39
+ *
40
+ * container.bind("TOKEN").toConstantValue(42);
41
+ * ```
30
42
  */
31
43
  WireScope.prototype.getContainer = function () {
32
44
  if (this.container) {
@@ -39,41 +51,64 @@ var WireScope = /** @class */function () {
39
51
  }
40
52
  };
41
53
  /**
42
- * Resolves a sibling service or injected value.
43
- * Use for lazy resolution or circular dependency breaking.
44
- * Available only for activated containers.
54
+ * Lazily resolves a service or value from the container.
55
+ *
56
+ * @remarks
57
+ * Use this to break circular dependencies or for services that are not needed immediately.
58
+ *
59
+ * @template T - Type of the service or value to resolve.
45
60
  *
46
- * @param injectionId - injection identifier
47
- * @returns resolved injection, service instance, or generic value
61
+ * @param injectionId - Service token (class constructor, symbol, or string).
62
+ * @returns The resolved instance or value.
48
63
  *
49
- * @throws WirestateError if scope is not activated
64
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
65
+ * @throws {Error} If the service cannot be resolved from the container.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const service: MyService = scope.resolve(MyService);
70
+ * ```
50
71
  */
51
72
  WireScope.prototype.resolve = function (injectionId) {
52
73
  return this.getContainer().get(injectionId);
53
74
  };
54
75
  /**
55
- * Resolves a sibling service or injected value.
56
- * Use for lazy resolution or circular dependency breaking.
57
- * Available only for activated containers.
76
+ * Lazily resolves a service if it is bound, otherwise returns null.
77
+ *
78
+ * @template T - Type of the service or value to resolve.
79
+ *
80
+ * @param injectionId - Service token (class constructor, symbol, or string).
81
+ * @returns The resolved instance, value, or `null` if not bound.
82
+ *
83
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
58
84
  *
59
- * @param injectionId - injection identifier
60
- * @returns resolved injection, service instance, generic value, or null if it is not bound
85
+ * @example
86
+ * ```typescript
87
+ * const logger: Logger | null = scope.resolveOptional(Logger);
61
88
  *
62
- * @throws WirestateError if scope is not activated
89
+ * logger?.info("Resolved optionally");
90
+ * ```
63
91
  */
64
92
  WireScope.prototype.resolveOptional = function (injectionId) {
65
93
  var container = this.getContainer();
66
94
  return container.isBound(injectionId) ? container.get(injectionId) : null;
67
95
  };
68
96
  /**
69
- * Broadcasts an event.
70
- * Available only for activated containers.
97
+ * Dispatches an event to the {@link EventBus}.
71
98
  *
72
- * @param type - type of event to emit
73
- * @param payload - optional payload to send with the event
74
- * @param from - optional sender of the event
99
+ * @template P - Type of the event payload.
100
+ * @template T - Type of the event identifier.
75
101
  *
76
- * @throws WirestateError if scope is not activated
102
+ * @param type - Event identifier.
103
+ * @param payload - Optional data associated with the event.
104
+ * @param from - Optional source identifier (defaults to current scope).
105
+ *
106
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * scope.emitEvent("VALUE_CHANGED", { value: "abcd" });
111
+ * ```
77
112
  */
78
113
  WireScope.prototype.emitEvent = function (type, payload, from) {
79
114
  this.getContainer().get(EventBus).emit({
@@ -83,63 +118,210 @@ var WireScope = /** @class */function () {
83
118
  });
84
119
  };
85
120
  /**
86
- * Dispatches a query and returns the result.
87
- * Available only for activated containers.
121
+ * Subscribes to all events on the {@link EventBus}.
88
122
  *
89
- * @param type - query type
90
- * @param data - query data
91
- * @returns query result
123
+ * @param handler - Function called for every emitted event.
124
+ * @returns A function to unsubscribe.
92
125
  *
93
- * @throws WirestateError if scope is not activated
126
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const unsubscribe: EventUnsubscriber = scope.subscribeToEvent((event) => {
131
+ * console.log("Event received:", event);
132
+ * });
133
+ * ```
134
+ */
135
+ WireScope.prototype.subscribeToEvent = function (handler) {
136
+ return this.getContainer().get(EventBus).subscribe(handler);
137
+ };
138
+ /**
139
+ * Unsubscribes a specific handler from the {@link EventBus}.
140
+ *
141
+ * @param handler - The handler instance to remove.
142
+ *
143
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * scope.unsubscribeFromEvent(this.onEvent);
148
+ * ```
149
+ */
150
+ WireScope.prototype.unsubscribeFromEvent = function (handler) {
151
+ this.getContainer().get(EventBus).unsubscribe(handler);
152
+ };
153
+ /**
154
+ * Dispatches a query and waits for the result.
155
+ *
156
+ * @template R - Type of the query result.
157
+ * @template D - Type of the query data (payload).
158
+ * @template T - Type of the query identifier.
159
+ *
160
+ * @param type - Query identifier.
161
+ * @param data - Input data for the query handler.
162
+ * @returns The query result (can be a Promise).
163
+ *
164
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
165
+ * @throws {@link WirestateError} If no query handler is registered.
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const user: User = await scope.queryData("GET_USER", { id: 1 });
170
+ * ```
94
171
  */
95
172
  WireScope.prototype.queryData = function (type, data) {
96
173
  return this.getContainer().get(QueryBus).query(type, data);
97
174
  };
98
175
  /**
99
- * Dispatches a query and returns the result.
100
- * Available only for activated containers.
176
+ * Dispatches a query and returns the result, or null if no handler is registered.
177
+ *
178
+ * @template R - Type of the query result.
179
+ * @template D - Type of the query data (payload).
180
+ * @template T - Type of the query identifier.
181
+ *
182
+ * @param type - Query identifier.
183
+ * @param data - Input data for the query handler.
184
+ * @returns The query result or `null`.
101
185
  *
102
- * @param type - query type
103
- * @param data - query data
104
- * @returns query result or null if handler is not registered
186
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const config: Config | null = await scope.queryOptionalData("GET_CONFIG");
191
+ * ```
105
192
  */
106
193
  WireScope.prototype.queryOptionalData = function (type, data) {
107
194
  return this.getContainer().get(QueryBus).queryOptional(type, data);
108
195
  };
109
196
  /**
110
- * Dispatches a command and returns the descriptor.
111
- * Available only for activated containers.
197
+ * Registers a handler for a specific query type.
198
+ *
199
+ * @template D - Type of the query data (payload).
200
+ * @template R - Type of the query result.
201
+ *
202
+ * @param type - Query identifier.
203
+ * @param handler - The handler function.
204
+ * @returns A function to unregister the handler.
205
+ *
206
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * scope.registerQueryHandler("GET_DATE_NOW", () => new Date());
211
+ * ```
212
+ */
213
+ WireScope.prototype.registerQueryHandler = function (type, handler) {
214
+ return this.getContainer().get(QueryBus).register(type, handler);
215
+ };
216
+ /**
217
+ * Removes a specific query handler registration.
218
+ *
219
+ * @template D - Type of the query data (payload).
220
+ * @template R - Type of the query result.
221
+ *
222
+ * @param type - Query identifier.
223
+ * @param handler - The handler instance to remove.
224
+ *
225
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * scope.unregisterQueryHandler("GET_DATE_NOW", this.onGetDateNow);
230
+ * ```
231
+ */
232
+ WireScope.prototype.unregisterQueryHandler = function (type, handler) {
233
+ this.getContainer().get(QueryBus).unregister(type, handler);
234
+ };
235
+ /**
236
+ * Dispatches a command and returns a descriptor to track its progress.
237
+ *
238
+ * @template R - Type of the command result.
239
+ * @template D - Type of the command payload.
240
+ * @template T - Type of the command identifier.
241
+ *
242
+ * @param type - Command identifier.
243
+ * @param data - Payload for the command.
244
+ * @returns A {@link CommandDescriptor}.
245
+ *
246
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
247
+ * @throws {@link WirestateError} If no command handler is registered.
112
248
  *
113
- * @param type - command type
114
- * @param data - command data
115
- * @returns command descriptor
249
+ * @example
250
+ * ```typescript
251
+ * const descriptor: CommandDescriptor = scope.executeCommand("LOGOUT");
116
252
  *
117
- * @throws WirestateError if scope is not activated
253
+ * await descriptor.task;
254
+ * ```
118
255
  */
119
256
  WireScope.prototype.executeCommand = function (type, data) {
120
257
  return this.getContainer().get(CommandBus).command(type, data);
121
258
  };
122
259
  /**
123
- * Dispatches a command and returns the descriptor.
124
- * Available only for activated containers.
260
+ * Dispatches a command if a handler is registered, otherwise returns null.
125
261
  *
126
- * @param type - command type
127
- * @param data - command data
128
- * @returns command descriptor or null if handler is not registered
262
+ * @template R - Type of the command result.
263
+ * @template D - Type of the command payload.
264
+ * @template T - Type of the command identifier.
265
+ *
266
+ * @param type - Command identifier.
267
+ * @param data - Payload for the command.
268
+ * @returns A {@link CommandDescriptor} or `null`.
269
+ *
270
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const descriptor: CommandDescriptor | null = scope.executeOptionalCommand("CLEANUP_CACHE");
275
+ *
276
+ * if (descriptor) {
277
+ * await descriptor.task;
278
+ * }
279
+ * ```
129
280
  */
130
281
  WireScope.prototype.executeOptionalCommand = function (type, data) {
131
282
  return this.getContainer().get(CommandBus).commandOptional(type, data);
132
283
  };
133
284
  /**
134
- * Reads seed for the provided injection.
135
- * Returns shared seed if parameters are not provided.
136
- * Available only for activated containers.
285
+ * Registers a handler for a specific command type.
286
+ *
287
+ * @template D - Type of the command payload.
288
+ * @template R - Type of the command result.
289
+ *
290
+ * @param type - Command identifier.
291
+ * @param handler - The handler function.
292
+ * @returns A function to unregister the handler.
293
+ *
294
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * scope.registerCommandHandler("LOG_ERROR", (error) => {
299
+ * console.error(error);
300
+ * });
301
+ * ```
302
+ */
303
+ WireScope.prototype.registerCommandHandler = function (type, handler) {
304
+ return this.getContainer().get(CommandBus).register(type, handler);
305
+ };
306
+ /**
307
+ * Removes a specific command handler registration.
137
308
  *
138
- * @param seed - lookup key
139
- * @returns seed data or null if missing
309
+ * @template D - Type of the command payload.
310
+ * @template R - Type of the command result.
140
311
  *
141
- * @throws WirestateError if context is not activated
312
+ * @param type - Command identifier.
313
+ * @param handler - The handler instance to remove.
314
+ *
315
+ * @throws {@link WirestateError} If accessed before activation or after disposal.
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * scope.unregisterCommandHandler("LOG_ERROR", this.handleLogError);
320
+ * ```
142
321
  */
322
+ WireScope.prototype.unregisterCommandHandler = function (type, handler) {
323
+ this.getContainer().get(CommandBus).unregister(type, handler);
324
+ };
143
325
  WireScope.prototype.getSeed = function (seed) {
144
326
  return seed ? this.getContainer().get(SEEDS_TOKEN).get(seed) || null : this.getContainer().get(SEED_TOKEN);
145
327
  };
@@ -1 +1 @@
1
- {"version":3,"file":"wire-scope.js","sources":["../../../../../../../../src/wirestate-core/container/wire-scope.ts"],"sourcesContent":[null],"names":["WireScope","container","isDisposed","prototype","getContainer","WirestateError","ERROR_CODE_ACCESS_AFTER_DISPOSAL","ERROR_CODE_ACCESS_BEFORE_ACTIVATION","resolve","injectionId","get","resolveOptional","isBound","emitEvent","type","payload","from","EventBus","emit","undefined","queryData","data","QueryBus","query","queryOptionalData","queryOptional","executeCommand","CommandBus","command","executeOptionalCommand","commandOptional","getSeed","seed","SEEDS_TOKEN","SEED_TOKEN","__decorate","injectable"],"mappings":";;;;;;;;;AAiBA;;;;AAIG;AAEH,IAAAA,SAAA,gBAAA,YAAA;EAME,SAAAA,SAAAA,CAAoCC,SAA8B,EAAA;IAA9B,IAAA,CAAAA,SAAS,GAATA,SAAS;AAL7C;;AAEG;IACa,IAAA,CAAAC,UAAU,GAAY,KAAK;AAE0B,EAAA;AAErE;;;;;;;AAOG;AACIF,EAAAA,SAAA,CAAAG,SAAA,CAAAC,YAAY,GAAnB,YAAA;IACE,IAAI,IAAI,CAACH,SAAS,EAAE;MAClB,OAAO,IAAI,CAACA,SAAS;AACvB,IAAA;IAEA,IAAI,IAAI,CAACC,UAAU,EAAE;AACnB,MAAA,MAAM,IAAIG,cAAc,CACtBC,gCAAgC,EAChC,wFAAwF,CACzF;AACH,IAAA,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IAAQ,EAAA;AAIR,IAAA,OAAO,IAAI,CAACjB,YAAY,EAAE,CAACM,GAAG,CAACY,QAAQ,CAAC,CAACG,aAAa,CAAOX,IAAI,EAAEO,IAAI,CAAC;EAC1E,CAAC;AAED;;;;;;;;;AASG;EACIrB,SAAA,CAAAG,SAAA,CAAAuB,cAAc,GAArB,UACEZ,IAAO,EACPO,IAAQ,EAAA;AAIR,IAAA,OAAO,IAAI,CAACjB,YAAY,EAAE,CAACM,GAAG,CAACiB,UAAU,CAAC,CAACC,OAAO,CAAOd,IAAI,EAAEO,IAAI,CAAC;EACtE,CAAC;AAED;;;;;;;AAOG;EACIrB,SAAA,CAAAG,SAAA,CAAA0B,sBAAsB,GAA7B,UACEf,IAAO,EACPO,IAAQ,EAAA;AAIR,IAAA,OAAO,IAAI,CAACjB,YAAY,EAAE,CAACM,GAAG,CAACiB,UAAU,CAAC,CAACG,eAAe,CAAOhB,IAAI,EAAEO,IAAI,CAAC;EAC9E,CAAC;AAKD;;;;;;;;;AASG;AACIrB,EAAAA,SAAA,CAAAG,SAAA,CAAA4B,OAAO,GAAd,UAAoCC,IAAc,EAAA;AAKhD,IAAA,OAAOA,IAAI,GACN,IAAI,CAAC5B,YAAY,EAAE,CAACM,GAAG,CAAWuB,WAAW,CAAC,CAACvB,GAAG,CAACsB,IAAI,CAAO,IAAI,IAAI,GACvE,IAAI,CAAC5B,YAAY,EAAE,CAACM,GAAG,CAAIwB,UAAU,CAAC;EAC5C,CAAC;AA/LUlC,EAAAA,SAAS,GAAAmC,UAAA,CAAA,CADrBC,UAAU,EAAE,4CACA,EAAApC,SAAS,CAgMrB;AAAD,EAAA,OAAAA,SAAC;AAAA,CAjMD;;;;"}
1
+ {"version":3,"file":"wire-scope.js","sources":["../../../../../../../../src/wirestate-core/container/wire-scope.ts"],"sourcesContent":[null],"names":["WireScope","container","isDisposed","prototype","getContainer","WirestateError","ERROR_CODE_ACCESS_AFTER_DISPOSAL","ERROR_CODE_ACCESS_BEFORE_ACTIVATION","resolve","injectionId","get","resolveOptional","isBound","emitEvent","type","payload","from","EventBus","emit","undefined","subscribeToEvent","handler","subscribe","unsubscribeFromEvent","unsubscribe","queryData","data","QueryBus","query","queryOptionalData","queryOptional","registerQueryHandler","register","unregisterQueryHandler","unregister","executeCommand","CommandBus","command","executeOptionalCommand","commandOptional","registerCommandHandler","unregisterCommandHandler","getSeed","seed","SEEDS_TOKEN","SEED_TOKEN","__decorate","injectable"],"mappings":";;;;;;;;;AAiBA;;;;;;;;;;AAUG;AAEH,IAAAA,SAAA,gBAAA,YAAA;EAME,SAAAA,SAAAA,CAAoCC,SAA8B,EAAA;IAA9B,IAAA,CAAAA,SAAS,GAATA,SAAS;AAL7C;;AAEG;IACa,IAAA,CAAAC,UAAU,GAAY,KAAK;AAE0B,EAAA;AAErE;;;;;;;;;;;;;AAaG;AACIF,EAAAA,SAAA,CAAAG,SAAA,CAAAC,YAAY,GAAnB,YAAA;IACE,IAAI,IAAI,CAACH,SAAS,EAAE;MAClB,OAAO,IAAI,CAACA,SAAS;AACvB,IAAA;IAEA,IAAI,IAAI,CAACC,UAAU,EAAE;AACnB,MAAA,MAAM,IAAIG,cAAc,CACtBC,gCAAgC,EAChC,wFAAwF,CACzF;AACH,IAAA,CAAC,MAAM;MACL,MAAM,IAAID,cAAc,CACtBE,mCAAmC,EACnC,mDAAmD,GACjD,gEAAgE,CACnE;AACH,IAAA;EACF,CAAC;AAED;;;;;;;;;;;;;;;;;;AAkBG;AACIP,EAAAA,SAAA,CAAAG,SAAA,CAAAK,OAAO,GAAd,UAAkBC,WAAiC,EAAA;IAMjD,OAAO,IAAI,CAACL,YAAY,EAAE,CAACM,GAAG,CAAID,WAAW,CAAC;EAChD,CAAC;AAED;;;;;;;;;;;;;;;;AAgBG;AACIT,EAAAA,SAAA,CAAAG,SAAA,CAAAQ,eAAe,GAAtB,UAA0BF,WAAiC,EAAA;AAMzD,IAAA,IAAMR,SAAS,GAAc,IAAI,CAACG,YAAY,EAAE;AAE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AAAG,SAAA,CAAAqC,sBAAsB,GAA7B,UACE1B,IAAiB,EACjBO,OAA6B,EAAA;AAI7B,IAAA,OAAO,IAAI,CAACjB,YAAY,EAAE,CAACM,GAAG,CAAC0B,UAAU,CAAC,CAACJ,QAAQ,CAAClB,IAAI,EAAEO,OAAO,CAAC;EACpE,CAAC;AAED;;;;;;;;;;;;;;;AAeG;EACIrB,SAAA,CAAAG,SAAA,CAAAsC,wBAAwB,GAA/B,UAA0D3B,IAAiB,EAAEO,OAA6B,EAAA;AAGxG,IAAA,IAAI,CAACjB,YAAY,EAAE,CAACM,GAAG,CAAC0B,UAAU,CAAC,CAACF,UAAU,CAACpB,IAAI,EAAEO,OAAO,CAAC;EAC/D,CAAC;AA2CMrB,EAAAA,SAAA,CAAAG,SAAA,CAAAuC,OAAO,GAAd,UAAkBC,IAAc,EAAA;AAK9B,IAAA,OAAOA,IAAI,GACN,IAAI,CAACvC,YAAY,EAAE,CAACM,GAAG,CAAWkC,WAAW,CAAC,CAAClC,GAAG,CAACiC,IAAI,CAAO,IAAI,IAAI,GACvE,IAAI,CAACvC,YAAY,EAAE,CAACM,GAAG,CAAImC,UAAU,CAAC;EAC5C,CAAC;AA1aU7C,EAAAA,SAAS,GAAA8C,UAAA,CAAA,CADrBC,UAAU,EAAE,4CACA,EAAA/C,SAAS,CA2arB;AAAD,EAAA,OAAAA,SAAC;AAAA,CA5aD;;;;"}
@@ -1,4 +1,5 @@
1
1
  var ERROR_CODE_GENERIC = 1;
2
+ var ERROR_CODE_VALIDATION_ERROR = 50;
2
3
  var ERROR_CODE_INVALID_ARGUMENTS = 51;
3
4
  var ERROR_CODE_BINDING_SCOPE = 52;
4
5
  var ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER = 101;
@@ -6,5 +7,5 @@ var ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER = 102;
6
7
  var ERROR_CODE_ACCESS_BEFORE_ACTIVATION = 200;
7
8
  var ERROR_CODE_ACCESS_AFTER_DISPOSAL = 201;
8
9
 
9
- export { ERROR_CODE_ACCESS_AFTER_DISPOSAL, ERROR_CODE_ACCESS_BEFORE_ACTIVATION, ERROR_CODE_BINDING_SCOPE, ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER, ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER, ERROR_CODE_GENERIC, ERROR_CODE_INVALID_ARGUMENTS };
10
+ export { ERROR_CODE_ACCESS_AFTER_DISPOSAL, ERROR_CODE_ACCESS_BEFORE_ACTIVATION, ERROR_CODE_BINDING_SCOPE, ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER, ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER, ERROR_CODE_GENERIC, ERROR_CODE_INVALID_ARGUMENTS, ERROR_CODE_VALIDATION_ERROR };
10
11
  //# sourceMappingURL=error-code.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-code.js","sources":["../../../../../../../../src/wirestate-core/error/error-code.ts"],"sourcesContent":[null],"names":["ERROR_CODE_GENERIC","ERROR_CODE_INVALID_ARGUMENTS","ERROR_CODE_BINDING_SCOPE","ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER","ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER","ERROR_CODE_ACCESS_BEFORE_ACTIVATION","ERROR_CODE_ACCESS_AFTER_DISPOSAL"],"mappings":"AAAO,IAAMA,kBAAkB,GAAW;AAGnC,IAAMC,4BAA4B,GAAW;AAC7C,IAAMC,wBAAwB,GAAW;AAGzC,IAAMC,0CAA0C,GAAW;AAC3D,IAAMC,4CAA4C,GAAW;AAE7D,IAAMC,mCAAmC,GAAW;AACpD,IAAMC,gCAAgC,GAAW;;;;"}
1
+ {"version":3,"file":"error-code.js","sources":["../../../../../../../../src/wirestate-core/error/error-code.ts"],"sourcesContent":[null],"names":["ERROR_CODE_GENERIC","ERROR_CODE_VALIDATION_ERROR","ERROR_CODE_INVALID_ARGUMENTS","ERROR_CODE_BINDING_SCOPE","ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER","ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER","ERROR_CODE_ACCESS_BEFORE_ACTIVATION","ERROR_CODE_ACCESS_AFTER_DISPOSAL"],"mappings":"AAAO,IAAMA,kBAAkB,GAAW;AAEnC,IAAMC,2BAA2B,GAAW;AAC5C,IAAMC,4BAA4B,GAAW;AAC7C,IAAMC,wBAAwB,GAAW;AAGzC,IAAMC,0CAA0C,GAAW;AAC3D,IAAMC,4CAA4C,GAAW;AAE7D,IAAMC,mCAAmC,GAAW;AACpD,IAAMC,gCAAgC,GAAW;;;;"}
@@ -2,20 +2,41 @@ import { __extends } from 'tslib';
2
2
  import { ERROR_CODE_GENERIC } from './error-code.js';
3
3
 
4
4
  /**
5
- * A custom error class that contains generic error information for Wirestate-related issues.
5
+ * Base error class for all Wirestate-related exceptions.
6
6
  *
7
- * This class extends the native `Error` class and is used to represent errors specific
8
- * to the Wirestate library, providing more structured error handling.
7
+ * @remarks
8
+ * `WirestateError` provides structured error information, including a numeric error code
9
+ * and a descriptive message. It is used throughout the library to signal lifecycle
10
+ * violations, messaging failures, and configuration issues.
11
+ *
12
+ * @group Error
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * try {
17
+ * scope.getContainer();
18
+ * } catch (error) {
19
+ * if (error instanceof WirestateError) {
20
+ * console.error(`Error code: ${error.code}`);
21
+ * }
22
+ * }
23
+ * ```
9
24
  */
10
25
  var WirestateError = /** @class */function (_super) {
11
26
  __extends(WirestateError, _super);
27
+ /**
28
+ * Creates a new instance of WirestateError.
29
+ *
30
+ * @param code - Numeric identifier for the error (defaults to ERROR_CODE_GENERIC).
31
+ * @param detail - Optional descriptive message.
32
+ */
12
33
  function WirestateError(code, detail) {
13
34
  if (code === void 0) {
14
35
  code = ERROR_CODE_GENERIC;
15
36
  }
16
37
  var _this = _super.call(this) || this;
17
38
  /**
18
- * Name or error class to help differentiate error class in minified environments.
39
+ * The name of the error class, useful for identification in minified environments.
19
40
  */
20
41
  _this.name = "WirestateError";
21
42
  _this.code = code;
@@ -1 +1 @@
1
- {"version":3,"file":"wirestate-error.js","sources":["../../../../../../../../src/wirestate-core/error/wirestate-error.ts"],"sourcesContent":[null],"names":["WirestateError","_super","__extends","code","detail","ERROR_CODE_GENERIC","_this","name","message","Error"],"mappings":";;;AAEA;;;;;AAKG;AACH,IAAAA,cAAA,gBAAA,UAAAC,MAAA,EAAA;AAAoCC,EAAAA,SAAA,CAAAF,cAAA,EAAAC,MAAA,CAAA;AAclC,EAAA,SAAAD,cAAAA,CAAmBG,IAAiC,EAAEC,MAAe,EAAA;AAAlD,IAAA,IAAAD,IAAA,KAAA,MAAA,EAAA;AAAAA,MAAAA,IAAA,GAAAE,kBAAiC;AAAA,IAAA;IAClD,IAAAC,KAAA,GAAAL,MAAK,WAAE,IAAA,IAAA;AAdT;;AAEG;IACaK,KAAA,CAAAC,IAAI,GAAW,gBAAgB;IAa7CD,KAAI,CAACH,IAAI,GAAGA,IAAI;AAChBG,IAAAA,KAAI,CAACE,OAAO,GAAGJ,MAAM,IAAI,kBAAkB;;AAC7C,EAAA;AACF,EAAA,OAAAJ,cAAC;AAAD,CApBA,CAAoCS,KAAK;;;;"}
1
+ {"version":3,"file":"wirestate-error.js","sources":["../../../../../../../../src/wirestate-core/error/wirestate-error.ts"],"sourcesContent":[null],"names":["WirestateError","_super","__extends","code","detail","ERROR_CODE_GENERIC","_this","name","message","Error"],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACH,IAAAA,cAAA,gBAAA,UAAAC,MAAA,EAAA;AAAoCC,EAAAA,SAAA,CAAAF,cAAA,EAAAC,MAAA,CAAA;AAclC;;;;;AAKG;AACH,EAAA,SAAAD,cAAAA,CAAmBG,IAAiC,EAAEC,MAAe,EAAA;AAAlD,IAAA,IAAAD,IAAA,KAAA,MAAA,EAAA;AAAAA,MAAAA,IAAA,GAAAE,kBAAiC;AAAA,IAAA;IAClD,IAAAC,KAAA,GAAAL,MAAK,WAAE,IAAA,IAAA;AApBT;;AAEG;IACaK,KAAA,CAAAC,IAAI,GAAW,gBAAgB;IAmB7CD,KAAI,CAACH,IAAI,GAAGA,IAAI;AAChBG,IAAAA,KAAI,CAACE,OAAO,GAAGJ,MAAM,IAAI,kBAAkB;;AAC7C,EAAA;AACF,EAAA,OAAAJ,cAAC;AAAD,CA1BA,CAAoCS,KAAK;;;;"}
@@ -3,9 +3,27 @@ import { getEventHandlerMetadata } from './get-event-handler-metadata.js';
3
3
  /**
4
4
  * Composes service event handlers into a single dispatcher.
5
5
  *
6
- * @param instance - service instance
7
- * @returns event handler or null if no handlers are declared
6
+ * @remarks
7
+ * Scans the provided instance for methods decorated with {@link OnEvent}.
8
+ * If handlers are found, it returns a fan-out function that dispatches events
9
+ * to all matching methods based on their registered event types.
10
+ *
11
+ * @group Events
8
12
  * @internal
13
+ *
14
+ * @template T - Type of the service instance.
15
+ *
16
+ * @param instance - Service instance to scan for handlers.
17
+ * @returns A unified event handler, or `null` if no handlers are declared.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const dispatcher = buildEventDispatcher(myServiceInstance);
22
+ *
23
+ * if (dispatcher) {
24
+ * dispatcher({ type: "SOME_EVENT", payload: { data: 123 } });
25
+ * }
26
+ * ```
9
27
  */
10
28
  function buildEventDispatcher(instance) {
11
29
  var entries = [];
@@ -1 +1 @@
1
- {"version":3,"file":"build-event-dispatcher.js","sources":["../../../../../../../../src/wirestate-core/events/build-event-dispatcher.ts"],"sourcesContent":[null],"names":["buildEventDispatcher","instance","entries","_i","_a","getEventHandlerMetadata","length","meta","method","methodName","push","types","handler","bind","event","entries_1","entry","includes","type"],"mappings":";;AAQA;;;;;;AAMG;AACG,SAAUA,oBAAoBA,CAAmBC,QAAW,EAAA;EAGhE,IAAMC,OAAO,GAA8B,EAAE;AAE7C;EACA,KAAmB,IAAAC,EAAA,GAAA,CAAiC,EAAjCC,EAAA,GAAAC,uBAAuB,CAACJ,QAAQ,CAAC,EAAjCE,EAAA,GAAAC,EAAA,CAAAE,MAAiC,EAAjCH,EAAA,EAAiC,EAAE;AAAjD,IAAA,IAAMI,IAAI,GAAAH,EAAA,CAAAD,EAAA,CAAA;AACb,IAAA,IAAMK,MAAM,GAAIP,QAAwD,CAACM,IAAI,CAACE,UAAU,CAAC;AAEzF,IAAA,IAAI,OAAOD,MAAM,KAAK,UAAU,EAAE;MAChCN,OAAO,CAACQ,IAAI,CAAC;QACXC,KAAK,EAAEJ,IAAI,CAACI,KAAK;AACjBC,QAAAA,OAAO,EAAGJ,MAAuB,CAACK,IAAI,CAACZ,QAAQ;AAChD,OAAA,CAAC;AACJ,IAAA;AACF,EAAA;EAEA,IAAIC,OAAO,CAACI,MAAM,EAAE;IAOlB,OAAO,UAACQ,KAAK,EAAA;AACX;AACA,MAAA,KAAoB,IAAAX,EAAA,GAAA,CAAO,EAAPY,SAAA,GAAAb,OAAO,EAAPC,qBAAO,EAAPA,EAAA,EAAO,EAAE;AAAxB,QAAA,IAAMa,KAAK,GAAAD,SAAA,CAAAZ,EAAA,CAAA;AACd,QAAA,IAAIa,KAAK,CAACL,KAAK,KAAK,IAAI,IAAIK,KAAK,CAACL,KAAK,CAACM,QAAQ,CAACH,KAAK,CAACI,IAAI,CAAC,EAAE;AAC5DF,UAAAA,KAAK,CAACJ,OAAO,CAACE,KAAK,CAAC;AACtB,QAAA;AACF,MAAA;IACF,CAAC;AACH,EAAA,CAAC,MAAM;AAOL,IAAA,OAAO,IAAI;AACb,EAAA;AACF;;;;"}
1
+ {"version":3,"file":"build-event-dispatcher.js","sources":["../../../../../../../../src/wirestate-core/events/build-event-dispatcher.ts"],"sourcesContent":[null],"names":["buildEventDispatcher","instance","entries","_i","_a","getEventHandlerMetadata","length","meta","method","methodName","push","types","handler","bind","event","entries_1","entry","includes","type"],"mappings":";;AAQA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,SAAUA,oBAAoBA,CAAmBC,QAAW,EAAA;EAGhE,IAAMC,OAAO,GAA8B,EAAE;AAE7C;EACA,KAAmB,IAAAC,EAAA,GAAA,CAAiC,EAAjCC,EAAA,GAAAC,uBAAuB,CAACJ,QAAQ,CAAC,EAAjCE,EAAA,GAAAC,EAAA,CAAAE,MAAiC,EAAjCH,EAAA,EAAiC,EAAE;AAAjD,IAAA,IAAMI,IAAI,GAAAH,EAAA,CAAAD,EAAA,CAAA;AACb,IAAA,IAAMK,MAAM,GAAIP,QAAwD,CAACM,IAAI,CAACE,UAAU,CAAC;AAEzF,IAAA,IAAI,OAAOD,MAAM,KAAK,UAAU,EAAE;MAChCN,OAAO,CAACQ,IAAI,CAAC;QACXC,KAAK,EAAEJ,IAAI,CAACI,KAAK;AACjBC,QAAAA,OAAO,EAAGJ,MAAuB,CAACK,IAAI,CAACZ,QAAQ;AAChD,OAAA,CAAC;AACJ,IAAA;AACF,EAAA;EAEA,IAAIC,OAAO,CAACI,MAAM,EAAE;IAOlB,OAAO,UAACQ,KAAK,EAAA;AACX;AACA,MAAA,KAAoB,IAAAX,EAAA,GAAA,CAAO,EAAPY,SAAA,GAAAb,OAAO,EAAPC,qBAAO,EAAPA,EAAA,EAAO,EAAE;AAAxB,QAAA,IAAMa,KAAK,GAAAD,SAAA,CAAAZ,EAAA,CAAA;AACd,QAAA,IAAIa,KAAK,CAACL,KAAK,KAAK,IAAI,IAAIK,KAAK,CAACL,KAAK,CAACM,QAAQ,CAACH,KAAK,CAACI,IAAI,CAAC,EAAE;AAC5DF,UAAAA,KAAK,CAACJ,OAAO,CAACE,KAAK,CAAC;AACtB,QAAA;AACF,MAAA;IACF,CAAC;AACH,EAAA,CAAC,MAAM;AAOL,IAAA,OAAO,IAAI;AACb,EAAA;AACF;;;;"}
@@ -1,12 +1,25 @@
1
1
  import { EventBus } from './event-bus.js';
2
2
 
3
3
  /**
4
- * Emits events for container from outside scope.
4
+ * Broadcasts an event to all subscribers via the {@link EventBus} resolved from the container.
5
5
  *
6
- * @param container - inversify container
7
- * @param type - event type ot emit
8
- * @param payload - event payload
9
- * @param from - optional indicator of the event source
6
+ * @remarks
7
+ * Use this utility to emit events from outside a service's {@link WireScope} (e.g., from a bootstrap script or external controller).
8
+ *
9
+ * @group Events
10
+ *
11
+ * @template P - Type of the event payload.
12
+ * @template T - Type of the event identifier.
13
+ *
14
+ * @param container - Inversify {@link Container} to resolve the {@link EventBus} from.
15
+ * @param type - Unique event identifier.
16
+ * @param payload - Optional data associated with the event.
17
+ * @param from - Optional source identifier.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * emitEvent(container, "SYSTEM_READY", { version: "1.0.0" });
22
+ * ```
10
23
  */
11
24
  function emitEvent(container, type, payload, from) {
12
25
  container.get(EventBus).emit({
@@ -1 +1 @@
1
- {"version":3,"file":"emit-event.js","sources":["../../../../../../../../src/wirestate-core/events/emit-event.ts"],"sourcesContent":[null],"names":["emitEvent","container","type","payload","from","get","EventBus","emit"],"mappings":";;AASA;;;;;;;AAOG;AACG,SAAUA,SAASA,CAAyBC,SAAoB,EAAEC,IAAO,EAAEC,OAAW,EAAEC,IAAc,EAAA;AAG1GH,EAAAA,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,IAAI,CAAC;AAAEL,IAAAA,IAAI,EAAAA,IAAA;AAAEC,IAAAA,OAAO,EAAAA,OAAA;AAAEC,IAAAA,IAAI,EAAAA;AAAA,GAAE,CAAC;AACvD;;;;"}
1
+ {"version":3,"file":"emit-event.js","sources":["../../../../../../../../src/wirestate-core/events/emit-event.ts"],"sourcesContent":[null],"names":["emitEvent","container","type","payload","from","get","EventBus","emit"],"mappings":";;AASA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAUA,SAASA,CAAyBC,SAAoB,EAAEC,IAAO,EAAEC,OAAW,EAAEC,IAAc,EAAA;AAG1GH,EAAAA,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,IAAI,CAAC;AAAEL,IAAAA,IAAI,EAAAA,IAAA;AAAEC,IAAAA,OAAO,EAAAA,OAAA;AAAEC,IAAAA,IAAI,EAAAA;AAAA,GAAE,CAAC;AACvD;;;;"}
@@ -1,14 +1,38 @@
1
1
  /**
2
- * Dispatches events to subscribers.
2
+ * Orchestrates event broadcasting to multiple subscribers.
3
+ *
4
+ * @remarks
5
+ * The `EventBus` facilitates decoupled, many-to-many communication.
6
+ * Unlike commands or queries, which are dispatched to a single handler,
7
+ * events are broadcast to all registered subscribers.
8
+ *
9
+ * @group Events
3
10
  */
4
11
  var EventBus = /** @class */function () {
5
12
  function EventBus() {
6
13
  this.handlers = new Set();
7
14
  }
8
15
  /**
9
- * Broadcasts an event to all subscribers.
16
+ * Broadcasts an event to all registered subscribers.
10
17
  *
11
- * @param event - event to emit
18
+ * @remarks
19
+ * Handlers are executed in a try-catch block to ensure that a single
20
+ * failing subscriber does not prevent others from receiving the event.
21
+ *
22
+ * @template P - Type of the event payload.
23
+ * @template T - Type of the event identifier.
24
+ * @template F - Type of the event source.
25
+ *
26
+ * @param event - The event object to broadcast.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * eventBus.emit({
31
+ * type: "USER_LOGGED_IN",
32
+ * payload: { userId: "123" },
33
+ * from: AuthService
34
+ * });
35
+ * ```
12
36
  */
13
37
  EventBus.prototype.emit = function (event) {
14
38
  // Snapshot prevents concurrent modification errors if handlers sub/unsub during emit.
@@ -24,21 +48,46 @@ var EventBus = /** @class */function () {
24
48
  }
25
49
  };
26
50
  /**
27
- * Subscribes a handler to all events.
28
- * Returns an unsubscribe function.
51
+ * Registers a handler to receive all broadcasted events.
52
+ *
53
+ * @param handler - Function invoked for every emitted event.
54
+ * @returns An {@link EventUnsubscriber} function to remove the subscription.
29
55
  *
30
- * @param handler - event handler function
31
- * @returns unsubscribe function
56
+ * @example
57
+ * ```typescript
58
+ * const unsubscribe: EventUnsubscriber = eventBus.subscribe((event) => {
59
+ * console.log('Received event:', event);
60
+ * });
61
+ * ```
32
62
  */
33
63
  EventBus.prototype.subscribe = function (handler) {
34
64
  var _this = this;
35
65
  this.handlers.add(handler);
36
66
  return function () {
37
- _this.handlers.delete(handler);
67
+ return _this.unsubscribe(handler);
38
68
  };
39
69
  };
40
70
  /**
41
- * Removes all registered handlers.
71
+ * Removes a previously registered event handler.
72
+ *
73
+ * @remarks
74
+ * If the handler was not subscribed, this operation does nothing.
75
+ *
76
+ * @param handler - The handler function instance to remove.
77
+ */
78
+ EventBus.prototype.unsubscribe = function (handler) {
79
+ this.handlers.delete(handler);
80
+ };
81
+ /**
82
+ * Checks if the bus has any active subscribers.
83
+ *
84
+ * @returns `true` if at least one handler is registered, `false` otherwise.
85
+ */
86
+ EventBus.prototype.has = function () {
87
+ return this.handlers.size > 0;
88
+ };
89
+ /**
90
+ * Removes all registered handlers from the bus.
42
91
  *
43
92
  * @internal
44
93
  */
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.js","sources":["../../../../../../../../src/wirestate-core/events/event-bus.ts"],"sourcesContent":[null],"names":["EventBus","handlers","Set","prototype","emit","event","snapshot","Array","from","_i","snapshot_1","handler","error","console","subscribe","_this","add","delete","clear"],"mappings":"AAKA;;AAEG;AACH,IAAAA,QAAA,gBAAA,YAAA;EAAA,SAAAA,QAAAA,GAAA;AACmB,IAAA,IAAA,CAAAC,QAAQ,GAAsB,IAAIC,GAAG,EAAE;AAsD1D,EAAA;AApDE;;;;AAIG;AACIF,EAAAA,QAAA,CAAAG,SAAA,CAAAC,IAAI,GAAX,UAAuEC,KAAqB,EAAA;AAC1F;IACA,IAAMC,QAAQ,GAAwBC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACP,QAAQ,CAAC;AAE/D,IAAA,KAAsB,IAAAQ,EAAA,GAAA,CAAQ,EAARC,UAAA,GAAAJ,QAAQ,EAARG,sBAAQ,EAARA,EAAA,EAAQ,EAAE;AAA3B,MAAA,IAAME,OAAO,GAAAD,UAAA,CAAAD,EAAA,CAAA;MAChB,IAAI;QACFE,OAAO,CAACN,KAAK,CAAC;MAChB,CAAC,CAAC,OAAOO,KAAK,EAAE;AACd;AACAC,QAAAA,OAAO,CAACD,KAAK,CAAC,kCAAkC,EAAEA,KAAK,CAAC;AAC1D,MAAA;AACF,IAAA;EACF,CAAC;AAED;;;;;;AAMG;AACIZ,EAAAA,QAAA,CAAAG,SAAA,CAAAW,SAAS,GAAhB,UAAiBH,OAAqB,EAAA;IAAtC,IAAAI,KAAA,GAAA,IAAA;AAME,IAAA,IAAI,CAACd,QAAQ,CAACe,GAAG,CAACL,OAAO,CAAC;AAE1B,IAAA,OAAO,YAAA;AAMLI,MAAAA,KAAI,CAACd,QAAQ,CAACgB,MAAM,CAACN,OAAO,CAAC;IAC/B,CAAC;EACH,CAAC;AAED;;;;AAIG;AACIX,EAAAA,QAAA,CAAAG,SAAA,CAAAe,KAAK,GAAZ,YAAA;AACE,IAAA,IAAI,CAACjB,QAAQ,CAACiB,KAAK,EAAE;EACvB,CAAC;AACH,EAAA,OAAAlB,QAAC;AAAD,CAAC;;;;"}
1
+ {"version":3,"file":"event-bus.js","sources":["../../../../../../../../src/wirestate-core/events/event-bus.ts"],"sourcesContent":[null],"names":["EventBus","handlers","Set","prototype","emit","event","snapshot","Array","from","_i","snapshot_1","handler","error","console","subscribe","_this","add","unsubscribe","delete","has","size","clear"],"mappings":"AAKA;;;;;;;;;AASG;AACH,IAAAA,QAAA,gBAAA,YAAA;EAAA,SAAAA,QAAAA,GAAA;AACmB,IAAA,IAAA,CAAAC,QAAQ,GAAsB,IAAIC,GAAG,EAAE;AAgG1D,EAAA;AA9FE;;;;;;;;;;;;;;;;;;;;;AAqBG;AACIF,EAAAA,QAAA,CAAAG,SAAA,CAAAC,IAAI,GAAX,UAAuEC,KAAqB,EAAA;AAC1F;IACA,IAAMC,QAAQ,GAAwBC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACP,QAAQ,CAAC;AAE/D,IAAA,KAAsB,IAAAQ,EAAA,GAAA,CAAQ,EAARC,UAAA,GAAAJ,QAAQ,EAARG,sBA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