@wirestate/core 0.7.0-experimental.1 → 0.7.0-experimental.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +2 -2
- package/cjs/development/index.js +28 -26
- package/cjs/development/index.js.map +1 -1
- package/cjs/development/lib.js +234 -288
- package/cjs/development/lib.js.map +1 -1
- package/cjs/development/test-utils.js +22 -38
- package/cjs/development/test-utils.js.map +1 -1
- package/cjs/production/index.js +1 -1
- package/cjs/production/index.js.map +1 -1
- package/cjs/production/lib.js +1 -1
- package/cjs/production/lib.js.map +1 -1
- package/cjs/production/test-utils.js +1 -1
- package/cjs/production/test-utils.js.map +1 -1
- package/esm/development/bind/bind-dynamic-value.js +1 -1
- package/esm/development/bind/bind-dynamic-value.js.map +1 -1
- package/esm/development/bind/bind-entry.js +1 -4
- package/esm/development/bind/bind-entry.js.map +1 -1
- package/esm/development/bind/bind-service.js +40 -54
- package/esm/development/bind/bind-service.js.map +1 -1
- package/esm/development/commands/command-bus.js +33 -42
- package/esm/development/commands/command-bus.js.map +1 -1
- package/esm/development/commands/get-command-handler-metadata.js +3 -3
- package/esm/development/commands/get-command-handler-metadata.js.map +1 -1
- package/esm/development/commands/on-command.js +4 -4
- package/esm/development/commands/on-command.js.map +1 -1
- package/esm/development/container/create-base-container.js +2 -3
- package/esm/development/container/create-base-container.js.map +1 -1
- package/esm/development/container/create-container.js +10 -19
- package/esm/development/container/create-container.js.map +1 -1
- package/esm/development/container/wire-scope.js +41 -42
- package/esm/development/container/wire-scope.js.map +1 -1
- package/esm/development/error/error-code.js +8 -8
- package/esm/development/error/error-code.js.map +1 -1
- package/esm/development/error/wirestate-error.js +18 -17
- package/esm/development/error/wirestate-error.js.map +1 -1
- package/esm/development/events/build-event-dispatcher.js +5 -7
- package/esm/development/events/build-event-dispatcher.js.map +1 -1
- package/esm/development/events/emit-event.js +3 -3
- package/esm/development/events/emit-event.js.map +1 -1
- package/esm/development/events/event-bus.js +16 -23
- package/esm/development/events/event-bus.js.map +1 -1
- package/esm/development/events/get-event-handler-metadata.js +3 -3
- package/esm/development/events/get-event-handler-metadata.js.map +1 -1
- package/esm/development/events/on-event.js +4 -5
- package/esm/development/events/on-event.js.map +1 -1
- package/esm/development/queries/get-query-handler-metadata.js +3 -3
- package/esm/development/queries/get-query-handler-metadata.js.map +1 -1
- package/esm/development/queries/on-query.js +4 -4
- package/esm/development/queries/on-query.js.map +1 -1
- package/esm/development/queries/query-bus.js +29 -35
- package/esm/development/queries/query-bus.js.map +1 -1
- package/esm/development/registry.js +10 -10
- package/esm/development/registry.js.map +1 -1
- package/esm/development/seeds/apply-seeds.js +2 -5
- package/esm/development/seeds/apply-seeds.js.map +1 -1
- package/esm/development/seeds/tokens.js +2 -2
- package/esm/development/seeds/tokens.js.map +1 -1
- package/esm/development/seeds/unapply-seeds.js +2 -3
- package/esm/development/seeds/unapply-seeds.js.map +1 -1
- package/esm/development/service/get-activated-handler-metadata.js +3 -3
- package/esm/development/service/get-activated-handler-metadata.js.map +1 -1
- package/esm/development/service/get-deactivation-handler-metadata.js +3 -3
- package/esm/development/service/get-deactivation-handler-metadata.js.map +1 -1
- package/esm/development/service/on-activated.js +3 -3
- package/esm/development/service/on-activated.js.map +1 -1
- package/esm/development/service/on-deactivation.js +3 -3
- package/esm/development/service/on-deactivation.js.map +1 -1
- package/esm/development/test-utils/mock-bind-entry.js +4 -5
- package/esm/development/test-utils/mock-bind-entry.js.map +1 -1
- package/esm/development/test-utils/mock-bind-service.js +4 -5
- package/esm/development/test-utils/mock-bind-service.js.map +1 -1
- package/esm/development/test-utils/mock-container.js +13 -21
- package/esm/development/test-utils/mock-container.js.map +1 -1
- package/esm/development/test-utils/mock-service.js +1 -7
- package/esm/development/test-utils/mock-service.js.map +1 -1
- package/esm/production/bind/bind-dynamic-value.js +1 -1
- package/esm/production/bind/bind-dynamic-value.js.map +1 -1
- package/esm/production/bind/bind-entry.js +1 -1
- package/esm/production/bind/bind-entry.js.map +1 -1
- package/esm/production/bind/bind-service.js +1 -1
- package/esm/production/bind/bind-service.js.map +1 -1
- package/esm/production/commands/command-bus.js +1 -1
- package/esm/production/commands/command-bus.js.map +1 -1
- package/esm/production/commands/get-command-handler-metadata.js +1 -1
- package/esm/production/commands/get-command-handler-metadata.js.map +1 -1
- package/esm/production/commands/on-command.js +1 -1
- package/esm/production/commands/on-command.js.map +1 -1
- package/esm/production/container/create-base-container.js +1 -1
- package/esm/production/container/create-base-container.js.map +1 -1
- package/esm/production/container/create-container.js +1 -1
- package/esm/production/container/create-container.js.map +1 -1
- package/esm/production/container/wire-scope.js +1 -1
- package/esm/production/container/wire-scope.js.map +1 -1
- package/esm/production/error/error-code.js +1 -1
- package/esm/production/error/error-code.js.map +1 -1
- package/esm/production/error/wirestate-error.js +1 -1
- package/esm/production/error/wirestate-error.js.map +1 -1
- package/esm/production/events/build-event-dispatcher.js +1 -1
- package/esm/production/events/build-event-dispatcher.js.map +1 -1
- package/esm/production/events/emit-event.js.map +1 -1
- package/esm/production/events/event-bus.js +1 -1
- package/esm/production/events/event-bus.js.map +1 -1
- package/esm/production/events/get-event-handler-metadata.js +1 -1
- package/esm/production/events/get-event-handler-metadata.js.map +1 -1
- package/esm/production/events/on-event.js +1 -1
- package/esm/production/events/on-event.js.map +1 -1
- package/esm/production/queries/get-query-handler-metadata.js +1 -1
- package/esm/production/queries/get-query-handler-metadata.js.map +1 -1
- package/esm/production/queries/on-query.js +1 -1
- package/esm/production/queries/on-query.js.map +1 -1
- package/esm/production/queries/query-bus.js +1 -1
- package/esm/production/queries/query-bus.js.map +1 -1
- package/esm/production/registry.js +1 -1
- package/esm/production/registry.js.map +1 -1
- package/esm/production/seeds/apply-seeds.js +1 -1
- package/esm/production/seeds/apply-seeds.js.map +1 -1
- package/esm/production/seeds/tokens.js +1 -1
- package/esm/production/seeds/tokens.js.map +1 -1
- package/esm/production/seeds/unapply-seeds.js +1 -1
- package/esm/production/seeds/unapply-seeds.js.map +1 -1
- package/esm/production/service/get-activated-handler-metadata.js +1 -1
- package/esm/production/service/get-activated-handler-metadata.js.map +1 -1
- package/esm/production/service/get-deactivation-handler-metadata.js +1 -1
- package/esm/production/service/get-deactivation-handler-metadata.js.map +1 -1
- package/esm/production/service/on-activated.js +1 -1
- package/esm/production/service/on-activated.js.map +1 -1
- package/esm/production/service/on-deactivation.js +1 -1
- package/esm/production/service/on-deactivation.js.map +1 -1
- package/esm/production/test-utils/mock-bind-entry.js +1 -1
- package/esm/production/test-utils/mock-bind-entry.js.map +1 -1
- package/esm/production/test-utils/mock-bind-service.js +1 -1
- package/esm/production/test-utils/mock-bind-service.js.map +1 -1
- package/esm/production/test-utils/mock-container.js +1 -1
- package/esm/production/test-utils/mock-container.js.map +1 -1
- package/esm/production/test-utils/mock-service.js +1 -1
- package/esm/production/test-utils/mock-service.js.map +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -66,73 +66,66 @@ function bindService(container, entry, options) {
|
|
|
66
66
|
// `.onDeactivation` call per chain, so we register them on the container
|
|
67
67
|
// itself instead — this also works correctly if a later call rebinds the
|
|
68
68
|
// same token.
|
|
69
|
-
|
|
70
|
-
whenBind.onActivation(
|
|
69
|
+
const whenBind = container.bind(entry).to(entry).inSingletonScope();
|
|
70
|
+
whenBind.onActivation((context, instance) => {
|
|
71
71
|
// Ensure flag is initialized on activation.
|
|
72
72
|
instance.IS_DISPOSED = false;
|
|
73
73
|
CONTAINER_REFS_BY_SERVICE.set(instance, container);
|
|
74
74
|
attachWireScopes(instance, entry);
|
|
75
75
|
// Compose all events listeners into a single bus subscription so we only
|
|
76
76
|
// pay one Set lookup per emitted event.
|
|
77
|
-
|
|
77
|
+
const dispatcher = buildEventDispatcher(instance);
|
|
78
78
|
if (dispatcher) {
|
|
79
79
|
attachEventsSubscription(instance, dispatcher);
|
|
80
80
|
}
|
|
81
81
|
// Register every `@OnQuery` handler on the container's QueryBus, and
|
|
82
82
|
// remember the unregister functions so we can roll them back when the
|
|
83
83
|
// service is deactivated.
|
|
84
|
-
|
|
85
|
-
for (
|
|
86
|
-
|
|
87
|
-
var method = instance[meta.methodName];
|
|
84
|
+
const queryBus = container.get(QueryBus);
|
|
85
|
+
for (const meta of getQueryHandlerMetadata(instance)) {
|
|
86
|
+
const method = instance[meta.methodName];
|
|
88
87
|
if (typeof method !== "function") {
|
|
89
88
|
continue;
|
|
90
89
|
}
|
|
91
|
-
|
|
90
|
+
const unregister = queryBus.register(meta.type, method.bind(instance));
|
|
92
91
|
attachQueryUnregister(instance, unregister);
|
|
93
92
|
}
|
|
94
93
|
// Register every `@OnCommand` handler on the container's CommandBus, and
|
|
95
94
|
// remember the unregister functions so we can roll them back when the
|
|
96
95
|
// service is deactivated.
|
|
97
|
-
|
|
98
|
-
for (
|
|
99
|
-
|
|
100
|
-
var method = instance[meta.methodName];
|
|
96
|
+
const commandBus = container.get(CommandBus);
|
|
97
|
+
for (const meta of getCommandHandlerMetadata(instance)) {
|
|
98
|
+
const method = instance[meta.methodName];
|
|
101
99
|
if (typeof method !== "function") {
|
|
102
100
|
continue;
|
|
103
101
|
}
|
|
104
|
-
|
|
102
|
+
const unregister = commandBus.register(meta.type, method.bind(instance));
|
|
105
103
|
attachCommandUnregister(instance, unregister);
|
|
106
104
|
}
|
|
107
|
-
if (options
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
if (options?.isWithIgnoreLifecycle) ; else {
|
|
106
|
+
// Call every `@OnActivated`-decorated method in base-to-derived order.
|
|
107
|
+
// Fire-and-forget any async init so we stay synchronous from the
|
|
108
|
+
// container's point of view.
|
|
109
|
+
for (const methodName of getActivatedHandlerMetadata(instance)) {
|
|
110
|
+
const method = instance[methodName];
|
|
110
111
|
if (typeof method !== "function") {
|
|
111
|
-
|
|
112
|
+
continue;
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
const result = method.call(instance);
|
|
114
115
|
if (result && typeof result.then === "function") {
|
|
115
|
-
result.catch(
|
|
116
|
+
result.catch(error => {
|
|
116
117
|
console.error("[wirestate] @OnActivated rejected for:", entry.name, String(methodName), error);
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
|
-
};
|
|
120
|
-
// Call every `@OnActivated`-decorated method in base-to-derived order.
|
|
121
|
-
// Fire-and-forget any async init so we stay synchronous from the
|
|
122
|
-
// container's point of view.
|
|
123
|
-
for (var _d = 0, _e = getActivatedHandlerMetadata(instance); _d < _e.length; _d++) {
|
|
124
|
-
var methodName = _e[_d];
|
|
125
|
-
_loop_1(methodName);
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
return instance;
|
|
129
123
|
});
|
|
130
|
-
whenBind.onDeactivation(
|
|
131
|
-
if (options
|
|
124
|
+
whenBind.onDeactivation(instance => {
|
|
125
|
+
if (options?.isWithIgnoreLifecycle) ; else {
|
|
132
126
|
// Call every `@OnDeactivation`-decorated method in base-to-derived order.
|
|
133
|
-
for (
|
|
134
|
-
|
|
135
|
-
var method = instance[methodName];
|
|
127
|
+
for (const methodName of getDeactivationHandlerMetadata(instance)) {
|
|
128
|
+
const method = instance[methodName];
|
|
136
129
|
if (typeof method === "function") {
|
|
137
130
|
method.call(instance);
|
|
138
131
|
}
|
|
@@ -159,8 +152,7 @@ function bindService(container, entry, options) {
|
|
|
159
152
|
* @param handler - Event handler.
|
|
160
153
|
*/
|
|
161
154
|
function attachEventsSubscription(service, handler) {
|
|
162
|
-
|
|
163
|
-
var bus = (_a = CONTAINER_REFS_BY_SERVICE.get(service)) === null || _a === void 0 ? void 0 : _a.get(EventBus);
|
|
155
|
+
const bus = CONTAINER_REFS_BY_SERVICE.get(service)?.get(EventBus);
|
|
164
156
|
if (bus) {
|
|
165
157
|
EVENT_UNSUBSCRIBERS_BY_SERVICE.set(service, bus.subscribe(handler));
|
|
166
158
|
}
|
|
@@ -173,7 +165,7 @@ function attachEventsSubscription(service, handler) {
|
|
|
173
165
|
* @param service - Service instance.
|
|
174
166
|
*/
|
|
175
167
|
function detachEventSubscription(service) {
|
|
176
|
-
|
|
168
|
+
const unsubscribe = EVENT_UNSUBSCRIBERS_BY_SERVICE.get(service);
|
|
177
169
|
if (unsubscribe) {
|
|
178
170
|
unsubscribe();
|
|
179
171
|
EVENT_UNSUBSCRIBERS_BY_SERVICE.delete(service);
|
|
@@ -188,7 +180,7 @@ function detachEventSubscription(service) {
|
|
|
188
180
|
* @param unregister - Query unregister function.
|
|
189
181
|
*/
|
|
190
182
|
function attachQueryUnregister(service, unregister) {
|
|
191
|
-
|
|
183
|
+
let list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
|
|
192
184
|
if (!list) {
|
|
193
185
|
list = [];
|
|
194
186
|
QUERY_UNREGISTERS_BY_SERVICE.set(service, list);
|
|
@@ -203,12 +195,11 @@ function attachQueryUnregister(service, unregister) {
|
|
|
203
195
|
* @param service - Service instance.
|
|
204
196
|
*/
|
|
205
197
|
function detachQueryUnregister(service) {
|
|
206
|
-
|
|
198
|
+
const list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
|
|
207
199
|
if (!list) {
|
|
208
200
|
return;
|
|
209
201
|
}
|
|
210
|
-
for (
|
|
211
|
-
var unregister = list_1[_i];
|
|
202
|
+
for (const unregister of list) {
|
|
212
203
|
unregister();
|
|
213
204
|
}
|
|
214
205
|
QUERY_UNREGISTERS_BY_SERVICE.delete(service);
|
|
@@ -222,7 +213,7 @@ function detachQueryUnregister(service) {
|
|
|
222
213
|
* @param unregister - Command unregister function.
|
|
223
214
|
*/
|
|
224
215
|
function attachCommandUnregister(service, unregister) {
|
|
225
|
-
|
|
216
|
+
let list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
|
|
226
217
|
if (!list) {
|
|
227
218
|
list = [];
|
|
228
219
|
COMMAND_UNREGISTERS_BY_SERVICE.set(service, list);
|
|
@@ -237,12 +228,11 @@ function attachCommandUnregister(service, unregister) {
|
|
|
237
228
|
* @param service - Service instance.
|
|
238
229
|
*/
|
|
239
230
|
function detachCommandUnregister(service) {
|
|
240
|
-
|
|
231
|
+
const list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
|
|
241
232
|
if (!list) {
|
|
242
233
|
return;
|
|
243
234
|
}
|
|
244
|
-
for (
|
|
245
|
-
var unregister = list_2[_i];
|
|
235
|
+
for (const unregister of list) {
|
|
246
236
|
unregister();
|
|
247
237
|
}
|
|
248
238
|
COMMAND_UNREGISTERS_BY_SERVICE.delete(service);
|
|
@@ -260,17 +250,14 @@ function detachCommandUnregister(service) {
|
|
|
260
250
|
* @param Service - Service constructor.
|
|
261
251
|
*/
|
|
262
252
|
function attachWireScopes(service, Service) {
|
|
263
|
-
|
|
264
|
-
if (!(
|
|
265
|
-
return type === WireScope;
|
|
266
|
-
}))) {
|
|
253
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", Service);
|
|
254
|
+
if (!paramTypes?.some(type => type === WireScope)) {
|
|
267
255
|
return;
|
|
268
256
|
}
|
|
269
|
-
|
|
270
|
-
for (
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if ((value === null || value === void 0 ? void 0 : value.constructor) === WireScope) {
|
|
257
|
+
const scopes = [];
|
|
258
|
+
for (const key of Object.getOwnPropertyNames(service)) {
|
|
259
|
+
const value = service[key];
|
|
260
|
+
if (value?.constructor === WireScope) {
|
|
274
261
|
scopes.push(value);
|
|
275
262
|
}
|
|
276
263
|
}
|
|
@@ -289,12 +276,11 @@ function attachWireScopes(service, Service) {
|
|
|
289
276
|
* @param service - Service instance.
|
|
290
277
|
*/
|
|
291
278
|
function detachWireScopes(service) {
|
|
292
|
-
|
|
279
|
+
const scopes = WIRE_SCOPES_BY_SERVICE.get(service);
|
|
293
280
|
if (!scopes) {
|
|
294
281
|
return;
|
|
295
282
|
}
|
|
296
|
-
for (
|
|
297
|
-
var scope = scopes_1[_i];
|
|
283
|
+
for (const scope of scopes) {
|
|
298
284
|
scope.isDisposed = true;
|
|
299
285
|
scope.container = null;
|
|
300
286
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-service.js","sources":["../../../../../../../../src/wirestate-core/bind/bind-service.ts"],"sourcesContent":[null],"names":["bindService","container","entry","options","whenBind","bind","to","inSingletonScope","onActivation","context","instance","IS_DISPOSED","CONTAINER_REFS_BY_SERVICE","set","attachWireScopes","dispatcher","buildEventDispatcher","attachEventsSubscription","queryBus","get","QueryBus","
|
|
1
|
+
{"version":3,"file":"bind-service.js","sources":["../../../../../../../../src/wirestate-core/bind/bind-service.ts"],"sourcesContent":[null],"names":["bindService","container","entry","options","whenBind","bind","to","inSingletonScope","onActivation","context","instance","IS_DISPOSED","CONTAINER_REFS_BY_SERVICE","set","attachWireScopes","dispatcher","buildEventDispatcher","attachEventsSubscription","queryBus","get","QueryBus","meta","getQueryHandlerMetadata","method","methodName","unregister","register","type","attachQueryUnregister","commandBus","CommandBus","getCommandHandlerMetadata","attachCommandUnregister","isWithIgnoreLifecycle","getActivatedHandlerMetadata","result","call","then","catch","error","console","name","String","onDeactivation","getDeactivationHandlerMetadata","detachWireScopes","detachCommandUnregister","detachQueryUnregister","detachEventSubscription","delete","service","handler","bus","EventBus","EVENT_UNSUBSCRIBERS_BY_SERVICE","subscribe","unsubscribe","list","QUERY_UNREGISTERS_BY_SERVICE","push","COMMAND_UNREGISTERS_BY_SERVICE","Service","paramTypes","Reflect","getMetadata","some","WireScope","scopes","key","Object","getOwnPropertyNames","value","constructor","length","WIRE_SCOPES_BY_SERVICE","scope","isDisposed"],"mappings":";;;;;;;;;;;AAyCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDG;SACaA,WAAWA,CACzBC,SAAoB,EACpBC,KAAiB,EACjBC,OAA4B,EAAA;AAS5B;AACA;AACA;AACA;AACA,EAAA,MAAMC,QAAQ,GAA8BH,SAAS,CAACI,IAAI,CAAIH,KAAK,CAAC,CAACI,EAAE,CAACJ,KAAK,CAAC,CAACK,gBAAgB,EAAE;AAEjGH,EAAAA,QAAQ,CAACI,YAAY,CAA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O,CAA+B;EAElG,IAAI,CAACC,UAAU,EAAEG,IAAI,CAAEtC,IAAI,IAAKA,IAAI,KAAKuC,SAAS,CAAC,EAAE;AACnD,IAAA;AACF,EAAA;EAEA,MAAMC,MAAM,GAAqB,EAAE;EAEnC,KAAK,MAAMC,GAAG,IAAIC,MAAM,CAACC,mBAAmB,CAACpB,OAAO,CAAC,EAAE;AACrD,IAAA,MAAMqB,KAAK,GAAIrB,OAAmC,CAACkB,GAAG,CAAC;AAEvD,IAAA,IAAKG,KAA0B,EAAEC,WAAW,KAAKN,SAAS,EAAE;AAC1DC,MAAAA,MAAM,CAACR,IAAI,CAACY,KAAkB,CAAC;AACjC,IAAA;AACF,EAAA;AAEA,EAAA,IAAIJ,MAAM,CAACM,MAAM,GAAG,CAAC,EAAE;AACrBC,IAAAA,sBAAsB,CAAC7D,GAAG,CAACqC,OAAO,EAAEiB,MAAM,CAAC;AAC7C,EAAA;AACF;AAEA;;;;;;;;;AASG;AACH,SAAStB,gBAAgBA,CAAmBK,OAAU,EAAA;AACpD,EAAA,MAAMiB,MAAM,GAA4BO,sBAAsB,CAACvD,GAAG,CAAC+B,OAAO,CAAC;EAE3E,IAAI,CAACiB,MAAM,EAAE;AACX,IAAA;AACF,EAAA;AAEA,EAAA,KAAK,MAAMQ,KAAK,IAAIR,MAAM,EAAE;IACzBQ,KAAiC,CAACC,UAAU,GAAG,IAAI;IACnDD,KAAuD,CAAC1E,SAAS,GAAG,IAAI;AAC3E,EAAA;AAEAyE,EAAAA,sBAAsB,CAACzB,MAAM,CAACC,OAAO,CAAC;AACxC;;;;"}
|
|
@@ -12,20 +12,18 @@ import { CommandStatus } from '../types/commands.js';
|
|
|
12
12
|
*
|
|
13
13
|
* @group Commands
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.handlers = new Map();
|
|
22
|
-
}
|
|
15
|
+
class CommandBus {
|
|
16
|
+
/**
|
|
17
|
+
* Internal handler storage.
|
|
18
|
+
* Uses a stack for each command type to support shadowing.
|
|
19
|
+
*/
|
|
20
|
+
handlers = new Map();
|
|
23
21
|
/**
|
|
24
22
|
* Removes all registered command handlers from the bus.
|
|
25
23
|
*/
|
|
26
|
-
|
|
24
|
+
clear() {
|
|
27
25
|
this.handlers.clear();
|
|
28
|
-
}
|
|
26
|
+
}
|
|
29
27
|
/**
|
|
30
28
|
* Dispatches a command to the last registered handler.
|
|
31
29
|
*
|
|
@@ -48,27 +46,25 @@ var CommandBus = /** @class */function () {
|
|
|
48
46
|
* const user: User = await descriptor.task;
|
|
49
47
|
* ```
|
|
50
48
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!
|
|
54
|
-
throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER,
|
|
49
|
+
command(type, data) {
|
|
50
|
+
const stack = this.handlers.get(type);
|
|
51
|
+
if (!stack?.length) {
|
|
52
|
+
throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER, `No command handler registered in container for type: '${String(type)}'.`);
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const handler = stack[stack.length - 1];
|
|
55
|
+
const descriptor = {
|
|
58
56
|
task: null,
|
|
59
57
|
status: CommandStatus.PENDING
|
|
60
58
|
};
|
|
61
|
-
descriptor.task = Promise.resolve().then(
|
|
62
|
-
return handler(data);
|
|
63
|
-
}).then(function (result) {
|
|
59
|
+
descriptor.task = Promise.resolve().then(() => handler(data)).then(result => {
|
|
64
60
|
descriptor.status = CommandStatus.SETTLED;
|
|
65
61
|
return result;
|
|
66
|
-
}).catch(
|
|
62
|
+
}).catch(error => {
|
|
67
63
|
descriptor.status = CommandStatus.ERROR;
|
|
68
64
|
throw error;
|
|
69
65
|
});
|
|
70
66
|
return descriptor;
|
|
71
|
-
}
|
|
67
|
+
}
|
|
72
68
|
/**
|
|
73
69
|
* Dispatches a command if a handler exists, otherwise returns null.
|
|
74
70
|
*
|
|
@@ -79,20 +75,19 @@ var CommandBus = /** @class */function () {
|
|
|
79
75
|
* @param data - Optional payload for the handler.
|
|
80
76
|
* @returns A command descriptor, or `null` if no handler is found.
|
|
81
77
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
}
|
|
78
|
+
commandOptional(type, data) {
|
|
79
|
+
const stack = this.handlers.get(type);
|
|
80
|
+
return stack?.length ? this.command(type, data) : null;
|
|
81
|
+
}
|
|
86
82
|
/**
|
|
87
83
|
* Checks if at least one handler is registered for the given command type.
|
|
88
84
|
*
|
|
89
85
|
* @param type - Command identifier.
|
|
90
86
|
* @returns `true` if a handler is available, `false` otherwise.
|
|
91
87
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
88
|
+
has(type) {
|
|
89
|
+
return Boolean(this.handlers.get(type)?.length);
|
|
90
|
+
}
|
|
96
91
|
/**
|
|
97
92
|
* Registers a handler for a specific command type.
|
|
98
93
|
*
|
|
@@ -114,18 +109,15 @@ var CommandBus = /** @class */function () {
|
|
|
114
109
|
* });
|
|
115
110
|
* ```
|
|
116
111
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
var stack = this.handlers.get(type);
|
|
112
|
+
register(type, handler) {
|
|
113
|
+
let stack = this.handlers.get(type);
|
|
120
114
|
if (!stack) {
|
|
121
115
|
stack = [];
|
|
122
116
|
this.handlers.set(type, stack);
|
|
123
117
|
}
|
|
124
118
|
stack.push(handler);
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
};
|
|
128
|
-
};
|
|
119
|
+
return () => this.unregister(type, handler);
|
|
120
|
+
}
|
|
129
121
|
/**
|
|
130
122
|
* Removes a previously registered command handler.
|
|
131
123
|
*
|
|
@@ -138,12 +130,12 @@ var CommandBus = /** @class */function () {
|
|
|
138
130
|
* @param type - Command identifier.
|
|
139
131
|
* @param handler - The handler function instance to remove.
|
|
140
132
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
unregister(type, handler) {
|
|
134
|
+
const current = this.handlers.get(type);
|
|
143
135
|
if (!current) {
|
|
144
136
|
return;
|
|
145
137
|
}
|
|
146
|
-
|
|
138
|
+
const index = current.indexOf(handler);
|
|
147
139
|
if (index >= 0) {
|
|
148
140
|
current.splice(index, 1);
|
|
149
141
|
}
|
|
@@ -151,9 +143,8 @@ var CommandBus = /** @class */function () {
|
|
|
151
143
|
if (current.length === 0) {
|
|
152
144
|
this.handlers.delete(type);
|
|
153
145
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
}();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
157
148
|
|
|
158
149
|
export { CommandBus };
|
|
159
150
|
//# sourceMappingURL=command-bus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-bus.js","sources":["../../../../../../../../src/wirestate-core/commands/command-bus.ts"],"sourcesContent":[null],"names":["CommandBus","handlers","Map","
|
|
1
|
+
{"version":3,"file":"command-bus.js","sources":["../../../../../../../../src/wirestate-core/commands/command-bus.ts"],"sourcesContent":[null],"names":["CommandBus","handlers","Map","clear","command","type","data","stack","get","length","WirestateError","ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER","String","handler","descriptor","task","status","CommandStatus","PENDING","Promise","resolve","then","result","SETTLED","catch","error","ERROR","commandOptional","has","Boolean","register","set","push","unregister","current","index","indexOf","splice","delete"],"mappings":";;;;AAcA;;;;;;;;;AASG;MACUA,UAAU,CAAA;AACrB;;;AAGG;AACcC,EAAAA,QAAQ,GAA4C,IAAIC,GAAG,EAAE;AAE9E;;AAEG;AACIC,EAAAA,KAAKA,GAAA;AACV,IAAA,IAAI,CAACF,QAAQ,CAACE,KAAK,EAAE;AACvB,EAAA;AAEA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACIC,EAAAA,OAAOA,CAA2BC,IAAiB,EAAEC,IAAQ,EAAA;IAClE,MAAMC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,CAAC5B,QAAQ,CAACO,GAAG,CAACH,IAAI,CAAC,EAAEI,MAAM,CAAC;AACjD,EAAA;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACIqB,EAAAA,QAAQA,CAA2BzB,IAAiB,EAAEQ,OAA6B,EAAA;IAOxF,IAAIN,KAAK,GAAiC,IAAI,CAACN,QAAQ,CAACO,GAAG,CAACH,IAAI,CAAC;IAEjE,IAAI,CAACE,KAAK,EAAE;AACVA,MAAAA,KAAK,GAAG,EAAE;MACV,IAAI,CAACN,QAAQ,CAAC8B,GAAG,CAAC1B,IAAI,EAAEE,KAAK,CAAC;AAChC,IAAA;AAEAA,IAAAA,KAAK,CAACyB,IAAI,CAACnB,OAAyB,CAAC;IAErC,OAAO,MAAM,IAAI,CAACoB,UAAU,CAAC5B,IAAI,EAAEQ,OAAyB,CAAC;AAC/D,EAAA;AAEA;;;;;;;;;;;AAWG;AACIoB,EAAAA,UAAUA,CAA2B5B,IAAiB,EAAEQ,OAA6B,EAAA;IAO1F,MAAMqB,OAAO,GAAiC,IAAI,CAACjC,QAAQ,CAACO,GAAG,CAACH,IAAI,CAAC;IAErE,IAAI,CAAC6B,OAAO,EAAE;AACZ,MAAA;AACF,IAAA;AAEA,IAAA,MAAMC,KAAK,GAAWD,OAAO,CAACE,OAAO,CAACvB,OAAyB,CAAC;IAEhE,IAAIsB,KAAK,IAAI,CAAC,EAAE;AACdD,MAAAA,OAAO,CAACG,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;AAC1B,IAAA;AAEA;AACA,IAAA,IAAID,OAAO,CAACzB,MAAM,KAAK,CAAC,EAAE;AACxB,MAAA,IAAI,CAACR,QAAQ,CAACqC,MAAM,CAACjC,IAAI,CAAC;AAC5B,IAAA;AACF,EAAA;AACD;;;;"}
|
|
@@ -14,11 +14,11 @@ import { COMMAND_HANDLER_METADATA } from '../registry.js';
|
|
|
14
14
|
* @returns A read-only array of metadata for all discovered command handlers.
|
|
15
15
|
*/
|
|
16
16
|
function getCommandHandlerMetadata(instance) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
let constructor = instance.constructor;
|
|
18
|
+
const chain = [];
|
|
19
19
|
// Traverse prototype chain up to Object/Function
|
|
20
20
|
while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
|
|
21
|
-
|
|
21
|
+
const own = COMMAND_HANDLER_METADATA.get(constructor);
|
|
22
22
|
if (own && own.length > 0) {
|
|
23
23
|
chain.push(own);
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-command-handler-metadata.js","sources":["../../../../../../../../src/wirestate-core/commands/get-command-handler-metadata.ts"],"sourcesContent":[null],"names":["getCommandHandlerMetadata","instance","constructor","chain","Object","Function","prototype","own","COMMAND_HANDLER_METADATA","get","length","push","getPrototypeOf","reverse","flat"],"mappings":";;AAOA;;;;;;;;;;;;AAYG;AACG,SAAUA,yBAAyBA,CAACC,QAAgB,EAAA;AAMxD,EAAA,IAAIC,WAAW,GAAYD,QAAQ,CAACC,WAAW;EAE/C,
|
|
1
|
+
{"version":3,"file":"get-command-handler-metadata.js","sources":["../../../../../../../../src/wirestate-core/commands/get-command-handler-metadata.ts"],"sourcesContent":[null],"names":["getCommandHandlerMetadata","instance","constructor","chain","Object","Function","prototype","own","COMMAND_HANDLER_METADATA","get","length","push","getPrototypeOf","reverse","flat"],"mappings":";;AAOA;;;;;;;;;;;;AAYG;AACG,SAAUA,yBAAyBA,CAACC,QAAgB,EAAA;AAMxD,EAAA,IAAIC,WAAW,GAAYD,QAAQ,CAACC,WAAW;EAE/C,MAAMC,KAAK,GAAyC,EAAE;AAEtD;AACA,EAAA,OAAO,OAAOD,WAAW,KAAK,UAAU,IAAIA,WAAW,KAAKE,MAAM,IAAIF,WAAW,KAAKG,QAAQ,CAACC,SAAS,EAAE;AACxG,IAAA,MAAMC,GAAG,GAAyCC,wBAAwB,CAACC,GAAG,CAACP,WAAqB,CAAC;AAErG,IAAA,IAAIK,GAAG,IAAIA,GAAG,CAACG,MAAM,GAAG,CAAC,EAAE;AACzBP,MAAAA,KAAK,CAACQ,IAAI,CAACJ,GAAG,CAAC;AACjB,IAAA;AAEAL,IAAAA,WAAW,GAAGE,MAAM,CAACQ,cAAc,CAACV,WAAW,CAAC;AAClD,EAAA;AAQA;EACA,OAAOC,KAAK,CAACU,OAAO,EAAE,CAACC,IAAI,EAAE;AAC/B;;;;"}
|
|
@@ -23,9 +23,9 @@ import { COMMAND_HANDLER_METADATA } from '../registry.js';
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
function OnCommand(type) {
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
return (target, propertyKey) => {
|
|
27
|
+
const constructor = target.constructor;
|
|
28
|
+
let list = COMMAND_HANDLER_METADATA.get(constructor);
|
|
29
29
|
if (!list) {
|
|
30
30
|
list = [];
|
|
31
31
|
COMMAND_HANDLER_METADATA.set(constructor, list);
|
|
@@ -33,7 +33,7 @@ function OnCommand(type) {
|
|
|
33
33
|
// Register handler metadata for prototype-based retrieval.
|
|
34
34
|
list.push({
|
|
35
35
|
methodName: propertyKey,
|
|
36
|
-
type
|
|
36
|
+
type
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-command.js","sources":["../../../../../../../../src/wirestate-core/commands/on-command.ts"],"sourcesContent":[null],"names":["OnCommand","type","target","propertyKey","constructor","list","COMMAND_HANDLER_METADATA","get","set","push","methodName"],"mappings":";;AAOA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACG,SAAUA,SAASA,CAACC,IAAiB,EAAA;AACzC,EAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"on-command.js","sources":["../../../../../../../../src/wirestate-core/commands/on-command.ts"],"sourcesContent":[null],"names":["OnCommand","type","target","propertyKey","constructor","list","COMMAND_HANDLER_METADATA","get","set","push","methodName"],"mappings":";;AAOA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACG,SAAUA,SAASA,CAACC,IAAiB,EAAA;AACzC,EAAA,OAAO,CAACC,MAAM,EAAEC,WAAW,KAAI;AAS7B,IAAA,MAAMC,WAAW,GAAGF,MAAM,CAACE,WAAW;AAEtC,IAAA,IAAIC,IAAI,GAAyCC,wBAAwB,CAACC,GAAG,CAACH,WAAW,CAAC;IAE1F,IAAI,CAACC,IAAI,EAAE;AACTA,MAAAA,IAAI,GAAG,EAAE;AACTC,MAAAA,wBAAwB,CAACE,GAAG,CAACJ,WAAW,EAAEC,IAAI,CAAC;AACjD,IAAA;AAEA;IACAA,IAAI,CAACI,IAAI,CAAC;AAAEC,MAAAA,UAAU,EAAEP,WAAW;AAAEF,MAAAA;AAAI,KAAE,CAAC;EAC9C,CAAC;AACH;;;;"}
|
|
@@ -37,8 +37,7 @@ import { SEEDS_TOKEN, SEED_TOKEN } from '../seeds/tokens.js';
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
function createBaseContainer(options) {
|
|
40
|
-
|
|
41
|
-
var container = new Container({
|
|
40
|
+
const container = new Container({
|
|
42
41
|
parent: options.parent,
|
|
43
42
|
defaultScope: "Singleton"
|
|
44
43
|
});
|
|
@@ -46,7 +45,7 @@ function createBaseContainer(options) {
|
|
|
46
45
|
container.bind(QueryBus).toConstantValue(new QueryBus());
|
|
47
46
|
container.bind(CommandBus).toConstantValue(new CommandBus());
|
|
48
47
|
container.bind(SEEDS_TOKEN).toConstantValue(new Map());
|
|
49
|
-
container.bind(SEED_TOKEN).toConstantValue(
|
|
48
|
+
container.bind(SEED_TOKEN).toConstantValue(options.seed ?? {});
|
|
50
49
|
if (options.seeds) {
|
|
51
50
|
applySeeds(container, options.seeds);
|
|
52
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-base-container.js","sources":["../../../../../../../../src/wirestate-core/container/create-base-container.ts"],"sourcesContent":[null],"names":["createBaseContainer","options","container","Container","parent","defaultScope","bind","EventBus","toConstantValue","QueryBus","CommandBus","SEEDS_TOKEN","Map","SEED_TOKEN","
|
|
1
|
+
{"version":3,"file":"create-base-container.js","sources":["../../../../../../../../src/wirestate-core/container/create-base-container.ts"],"sourcesContent":[null],"names":["createBaseContainer","options","container","Container","parent","defaultScope","bind","EventBus","toConstantValue","QueryBus","CommandBus","SEEDS_TOKEN","Map","SEED_TOKEN","seed","seeds","applySeeds"],"mappings":";;;;;;;AAmCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACG,SAAUA,mBAAmBA,CAACC,OAAmC,EAAA;AACrE,EAAA,MAAMC,SAAS,GAAc,IAAIC,SAAS,CAAC;IACzCC,MAAM,EAAEH,OAAO,CAACG,MAAM;AACtBC,IAAAA,YAAY,EAAE;AACf,GAAA,CAAC;AAEFH,EAAAA,SAAS,CAACI,IAAI,CAACC,QAAQ,CAAC,CAACC,eAAe,CAAC,IAAID,QAAQ,EAAE,CAAC;AACxDL,EAAAA,SAAS,CAACI,IAAI,CAACG,QAAQ,CAAC,CAACD,eAAe,CAAC,IAAIC,QAAQ,EAAE,CAAC;AACxDP,EAAAA,SAAS,CAACI,IAAI,CAACI,UAAU,CAAC,CAACF,eAAe,CAAC,IAAIE,UAAU,EAAE,CAAC;AAE5DR,EAAAA,SAAS,CAACI,IAAI,CAACK,WAAW,CAAC,CAACH,eAAe,CAAC,IAAII,GAAG,EAAc,CAAC;AAClEV,EAAAA,SAAS,CAACI,IAAI,CAACO,UAAU,CAAC,CAACL,eAAe,CAACP,OAAO,CAACa,IAAI,IAAI,EAAE,CAAC;EAE9D,IAAIb,OAAO,CAACc,KAAK,EAAE;AACjBC,IAAAA,UAAU,CAACd,SAAS,EAAED,OAAO,CAACc,KAAK,CAAC;AACtC,EAAA;AAEA,EAAA,OAAOb,SAAS;AAClB;;;;"}
|
|
@@ -23,7 +23,7 @@ import { WirestateError } from '../error/wirestate-error.js';
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
|
-
* const container: Container =
|
|
26
|
+
* const container: Container = createContainer({
|
|
27
27
|
* seeds: [
|
|
28
28
|
* [CounterService, { count: 1000 }],
|
|
29
29
|
* ["SOME_KEY", "VALUE"],
|
|
@@ -35,39 +35,30 @@ import { WirestateError } from '../error/wirestate-error.js';
|
|
|
35
35
|
* bindService(container, MyService);
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
function createContainer(options) {
|
|
39
|
-
var _a;
|
|
40
|
-
if (options === void 0) {
|
|
41
|
-
options = {};
|
|
42
|
-
}
|
|
38
|
+
function createContainer(options = {}) {
|
|
43
39
|
if (options.activate && options.activate.length) {
|
|
44
|
-
if (!
|
|
40
|
+
if (!options.entries?.length) {
|
|
45
41
|
throw new WirestateError(ERROR_CODE_VALIDATION_ERROR, "Supplied activation list while entries for binding are not provided.");
|
|
46
42
|
}
|
|
47
|
-
|
|
48
|
-
for (
|
|
49
|
-
var eager = _b[_i];
|
|
43
|
+
const entryTokens = options.entries.map(getEntryToken);
|
|
44
|
+
for (const eager of options.activate) {
|
|
50
45
|
if (!entryTokens.includes(eager)) {
|
|
51
|
-
throw new WirestateError(ERROR_CODE_VALIDATION_ERROR,
|
|
46
|
+
throw new WirestateError(ERROR_CODE_VALIDATION_ERROR, `createInjectablesProvider: '${String(eager)}' is listed in 'activate' but was not provided in 'entries'.`);
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
49
|
}
|
|
55
|
-
|
|
50
|
+
const container = new Container({
|
|
56
51
|
defaultScope: "Singleton",
|
|
57
52
|
parent: createBaseContainer(options)
|
|
58
53
|
});
|
|
59
|
-
container.bind(WireScope).toResolvedValue(
|
|
60
|
-
return new WireScope(container);
|
|
61
|
-
}).inTransientScope();
|
|
54
|
+
container.bind(WireScope).toResolvedValue(() => new WireScope(container)).inTransientScope();
|
|
62
55
|
if (options.entries) {
|
|
63
|
-
for (
|
|
64
|
-
var entry = _d[_c];
|
|
56
|
+
for (const entry of options.entries) {
|
|
65
57
|
bindEntry(container, entry);
|
|
66
58
|
}
|
|
67
59
|
}
|
|
68
60
|
if (options.activate) {
|
|
69
|
-
for (
|
|
70
|
-
var entry = _f[_e];
|
|
61
|
+
for (const entry of options.activate) {
|
|
71
62
|
container.get(entry);
|
|
72
63
|
}
|
|
73
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-container.js","sources":["../../../../../../../../src/wirestate-core/container/create-container.ts"],"sourcesContent":[null],"names":["createContainer","options","activate","length","
|
|
1
|
+
{"version":3,"file":"create-container.js","sources":["../../../../../../../../src/wirestate-core/container/create-container.ts"],"sourcesContent":[null],"names":["createContainer","options","activate","length","entries","WirestateError","ERROR_CODE_VALIDATION_ERROR","entryTokens","map","getEntryToken","eager","includes","String","container","Container","defaultScope","parent","createBaseContainer","bind","WireScope","toResolvedValue","inTransientScope","entry","bindEntry","get"],"mappings":";;;;;;;;AAuDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACG,SAAUA,eAAeA,CAACC,OAAA,GAAkC,EAAE,EAAA;EAGlE,IAAIA,OAAO,CAACC,QAAQ,IAAID,OAAO,CAACC,QAAQ,CAACC,MAAM,EAAE;AAC/C,IAAA,IAAI,CAACF,OAAO,CAACG,OAAO,EAAED,MAAM,EAAE;AAC5B,MAAA,MAAM,IAAIE,cAAc,CACtBC,2BAA2B,EAC3B,sEAAsE,CACvE;AACH,IAAA;IAEA,MAAMC,WAAW,GAAqCN,OAAO,CAACG,OAAO,CAACI,GAAG,CAACC,aAAa,CAAC;AAExF,IAAA,KAAK,MAAMC,KAAK,IAAIT,OAAO,CAACC,QAAQ,EAAE;AACpC,MAAA,IAAI,CAACK,WAAW,CAACI,QAAQ,CAACD,KAAK,CAAC,EAAE;QAChC,MAAM,IAAIL,cAAc,CACtBC,2BAA2B,EAC3B,CAAA,4BAAA,EAA+BM,MAAM,CAACF,KAAK,CAAC,CAAA,4DAAA,CAA8D,CAC3G;AACH,MAAA;AACF,IA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