@wirestate/react 0.6.1 → 0.6.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 -0
- package/README.md +114 -234
- package/cjs/development/test-utils.js +2 -1050
- package/cjs/development/test-utils.js.map +1 -1
- package/cjs/production/test-utils.js +1 -1
- package/cjs/production/test-utils.js.map +1 -1
- package/esm/development/commands/use-command-caller.js.map +1 -0
- package/esm/development/commands/use-command-handler.js.map +1 -0
- package/esm/development/commands/use-optional-command-caller.js.map +1 -0
- package/esm/development/error/error-code.js.map +1 -0
- package/esm/development/events/use-event-emitter.js.map +1 -0
- package/esm/development/events/use-event.js.map +1 -0
- package/esm/development/events/use-events-handler.js.map +1 -0
- package/esm/development/events/use-events.js.map +1 -0
- package/esm/development/provision/create-injectables-provider.js.map +1 -0
- package/esm/development/provision/ioc-context.js.map +1 -0
- package/esm/development/provision/ioc-provider.js.map +1 -0
- package/esm/development/provision/use-container-revision.js.map +1 -0
- package/esm/development/provision/use-container.js.map +1 -0
- package/esm/development/provision/use-injection.js.map +1 -0
- package/esm/development/provision/use-ioc-context.js.map +1 -0
- package/esm/development/provision/use-optional-injection.js.map +1 -0
- package/esm/development/queries/use-optional-query-caller.js.map +1 -0
- package/esm/development/queries/use-optional-sync-query-caller.js.map +1 -0
- package/esm/development/queries/use-query-caller.js.map +1 -0
- package/esm/development/queries/use-query-handler.js.map +1 -0
- package/esm/development/queries/use-sync-query-caller.js.map +1 -0
- package/esm/development/{wirestate-react/test-utils → test-utils}/with-ioc-provider.js +1 -7
- package/esm/development/test-utils/with-ioc-provider.js.map +1 -0
- package/esm/production/commands/use-command-caller.js.map +1 -0
- package/esm/production/commands/use-command-handler.js.map +1 -0
- package/esm/production/commands/use-optional-command-caller.js.map +1 -0
- package/esm/production/error/error-code.js.map +1 -0
- package/esm/production/events/use-event-emitter.js.map +1 -0
- package/esm/production/events/use-event.js.map +1 -0
- package/esm/production/events/use-events-handler.js.map +1 -0
- package/esm/production/events/use-events.js.map +1 -0
- package/esm/production/provision/create-injectables-provider.js.map +1 -0
- package/esm/production/provision/ioc-context.js.map +1 -0
- package/esm/production/provision/ioc-provider.js.map +1 -0
- package/esm/production/provision/use-container-revision.js.map +1 -0
- package/esm/production/provision/use-container.js.map +1 -0
- package/esm/production/provision/use-injection.js.map +1 -0
- package/esm/production/provision/use-ioc-context.js.map +1 -0
- package/esm/production/provision/use-optional-injection.js.map +1 -0
- package/esm/production/queries/use-optional-query-caller.js.map +1 -0
- package/esm/production/queries/use-optional-sync-query-caller.js.map +1 -0
- package/esm/production/queries/use-query-caller.js.map +1 -0
- package/esm/production/queries/use-query-handler.js.map +1 -0
- package/esm/production/queries/use-sync-query-caller.js.map +1 -0
- package/esm/production/test-utils/with-ioc-provider.js +1 -0
- package/esm/production/test-utils/with-ioc-provider.js.map +1 -0
- package/package.json +1 -1
- package/esm/development/wirestate-core/bind/bind-constant.js +0 -19
- package/esm/development/wirestate-core/bind/bind-constant.js.map +0 -1
- package/esm/development/wirestate-core/bind/bind-dynamic-value.js +0 -28
- package/esm/development/wirestate-core/bind/bind-dynamic-value.js.map +0 -1
- package/esm/development/wirestate-core/bind/bind-entry.js +0 -39
- package/esm/development/wirestate-core/bind/bind-entry.js.map +0 -1
- package/esm/development/wirestate-core/bind/bind-service.js +0 -253
- package/esm/development/wirestate-core/bind/bind-service.js.map +0 -1
- package/esm/development/wirestate-core/bind/get-entry-token.js +0 -14
- package/esm/development/wirestate-core/bind/get-entry-token.js.map +0 -1
- package/esm/development/wirestate-core/commands/command-bus.js +0 -112
- package/esm/development/wirestate-core/commands/command-bus.js.map +0 -1
- package/esm/development/wirestate-core/commands/get-command-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/commands/get-command-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/container/create-ioc-container.js +0 -35
- package/esm/development/wirestate-core/container/create-ioc-container.js.map +0 -1
- package/esm/development/wirestate-core/container/wire-scope.js +0 -151
- package/esm/development/wirestate-core/container/wire-scope.js.map +0 -1
- package/esm/development/wirestate-core/error/error-code.js +0 -10
- package/esm/development/wirestate-core/error/error-code.js.map +0 -1
- package/esm/development/wirestate-core/error/wirestate-error.js +0 -29
- package/esm/development/wirestate-core/error/wirestate-error.js.map +0 -1
- package/esm/development/wirestate-core/events/build-event-dispatcher.js +0 -39
- package/esm/development/wirestate-core/events/build-event-dispatcher.js.map +0 -1
- package/esm/development/wirestate-core/events/event-bus.js +0 -52
- package/esm/development/wirestate-core/events/event-bus.js.map +0 -1
- package/esm/development/wirestate-core/events/get-event-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/events/get-event-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/queries/get-query-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/queries/get-query-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/queries/query-bus.js +0 -99
- package/esm/development/wirestate-core/queries/query-bus.js.map +0 -1
- package/esm/development/wirestate-core/registry.js +0 -56
- package/esm/development/wirestate-core/registry.js.map +0 -1
- package/esm/development/wirestate-core/service/get-activated-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/service/get-activated-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/test-utils/mock-bind-entry.js +0 -24
- package/esm/development/wirestate-core/test-utils/mock-bind-entry.js.map +0 -1
- package/esm/development/wirestate-core/test-utils/mock-container.js +0 -52
- package/esm/development/wirestate-core/test-utils/mock-container.js.map +0 -1
- package/esm/development/wirestate-core/types/commands.js +0 -12
- package/esm/development/wirestate-core/types/commands.js.map +0 -1
- package/esm/development/wirestate-react/commands/use-command-caller.js.map +0 -1
- package/esm/development/wirestate-react/commands/use-command-handler.js.map +0 -1
- package/esm/development/wirestate-react/commands/use-optional-command-caller.js.map +0 -1
- package/esm/development/wirestate-react/error/error-code.js.map +0 -1
- package/esm/development/wirestate-react/events/use-event-emitter.js.map +0 -1
- package/esm/development/wirestate-react/events/use-event.js.map +0 -1
- package/esm/development/wirestate-react/events/use-events-handler.js.map +0 -1
- package/esm/development/wirestate-react/events/use-events.js.map +0 -1
- package/esm/development/wirestate-react/provision/create-injectables-provider.js.map +0 -1
- package/esm/development/wirestate-react/provision/ioc-context.js.map +0 -1
- package/esm/development/wirestate-react/provision/ioc-provider.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-container-revision.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-container.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-injection.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-ioc-context.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-optional-injection.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-optional-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-optional-sync-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-query-handler.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-sync-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/test-utils/with-ioc-provider.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-constant.js +0 -1
- package/esm/production/wirestate-core/bind/bind-constant.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-dynamic-value.js +0 -1
- package/esm/production/wirestate-core/bind/bind-dynamic-value.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-entry.js +0 -1
- package/esm/production/wirestate-core/bind/bind-entry.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-service.js +0 -1
- package/esm/production/wirestate-core/bind/bind-service.js.map +0 -1
- package/esm/production/wirestate-core/bind/get-entry-token.js +0 -1
- package/esm/production/wirestate-core/bind/get-entry-token.js.map +0 -1
- package/esm/production/wirestate-core/commands/command-bus.js +0 -1
- package/esm/production/wirestate-core/commands/command-bus.js.map +0 -1
- package/esm/production/wirestate-core/commands/get-command-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/commands/get-command-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/container/create-ioc-container.js +0 -1
- package/esm/production/wirestate-core/container/create-ioc-container.js.map +0 -1
- package/esm/production/wirestate-core/container/wire-scope.js +0 -1
- package/esm/production/wirestate-core/container/wire-scope.js.map +0 -1
- package/esm/production/wirestate-core/error/error-code.js +0 -1
- package/esm/production/wirestate-core/error/error-code.js.map +0 -1
- package/esm/production/wirestate-core/error/wirestate-error.js +0 -1
- package/esm/production/wirestate-core/error/wirestate-error.js.map +0 -1
- package/esm/production/wirestate-core/events/build-event-dispatcher.js +0 -1
- package/esm/production/wirestate-core/events/build-event-dispatcher.js.map +0 -1
- package/esm/production/wirestate-core/events/event-bus.js +0 -1
- package/esm/production/wirestate-core/events/event-bus.js.map +0 -1
- package/esm/production/wirestate-core/events/get-event-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/events/get-event-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/queries/get-query-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/queries/get-query-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/queries/query-bus.js +0 -1
- package/esm/production/wirestate-core/queries/query-bus.js.map +0 -1
- package/esm/production/wirestate-core/registry.js +0 -1
- package/esm/production/wirestate-core/registry.js.map +0 -1
- package/esm/production/wirestate-core/service/get-activated-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/service/get-activated-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/test-utils/mock-bind-entry.js +0 -1
- package/esm/production/wirestate-core/test-utils/mock-bind-entry.js.map +0 -1
- package/esm/production/wirestate-core/test-utils/mock-container.js +0 -1
- package/esm/production/wirestate-core/test-utils/mock-container.js.map +0 -1
- package/esm/production/wirestate-core/types/commands.js +0 -1
- package/esm/production/wirestate-core/types/commands.js.map +0 -1
- package/esm/production/wirestate-react/commands/use-command-caller.js.map +0 -1
- package/esm/production/wirestate-react/commands/use-command-handler.js.map +0 -1
- package/esm/production/wirestate-react/commands/use-optional-command-caller.js.map +0 -1
- package/esm/production/wirestate-react/error/error-code.js.map +0 -1
- package/esm/production/wirestate-react/events/use-event-emitter.js.map +0 -1
- package/esm/production/wirestate-react/events/use-event.js.map +0 -1
- package/esm/production/wirestate-react/events/use-events-handler.js.map +0 -1
- package/esm/production/wirestate-react/events/use-events.js.map +0 -1
- package/esm/production/wirestate-react/provision/create-injectables-provider.js.map +0 -1
- package/esm/production/wirestate-react/provision/ioc-context.js.map +0 -1
- package/esm/production/wirestate-react/provision/ioc-provider.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-container-revision.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-container.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-injection.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-ioc-context.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-optional-injection.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-optional-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-optional-sync-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-query-handler.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-sync-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/test-utils/with-ioc-provider.js +0 -1
- package/esm/production/wirestate-react/test-utils/with-ioc-provider.js.map +0 -1
- /package/esm/development/{wirestate-react/commands → commands}/use-command-caller.js +0 -0
- /package/esm/development/{wirestate-react/commands → commands}/use-command-handler.js +0 -0
- /package/esm/development/{wirestate-react/commands → commands}/use-optional-command-caller.js +0 -0
- /package/esm/development/{wirestate-react/error → error}/error-code.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-event-emitter.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-event.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-events-handler.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-events.js +0 -0
- /package/esm/development/{wirestate-react/index.js → index.js} +0 -0
- /package/esm/development/{wirestate-react/index.js.map → index.js.map} +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/create-injectables-provider.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/ioc-context.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/ioc-provider.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-container-revision.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-container.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-injection.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-ioc-context.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-optional-injection.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-optional-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-optional-sync-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-query-handler.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-sync-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/test-utils.js → test-utils.js} +0 -0
- /package/esm/development/{wirestate-react/test-utils.js.map → test-utils.js.map} +0 -0
- /package/esm/production/{wirestate-react/commands → commands}/use-command-caller.js +0 -0
- /package/esm/production/{wirestate-react/commands → commands}/use-command-handler.js +0 -0
- /package/esm/production/{wirestate-react/commands → commands}/use-optional-command-caller.js +0 -0
- /package/esm/production/{wirestate-react/error → error}/error-code.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-event-emitter.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-event.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-events-handler.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-events.js +0 -0
- /package/esm/production/{wirestate-react/index.js → index.js} +0 -0
- /package/esm/production/{wirestate-react/index.js.map → index.js.map} +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/create-injectables-provider.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/ioc-context.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/ioc-provider.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-container-revision.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-container.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-injection.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-ioc-context.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-optional-injection.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-optional-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-optional-sync-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-query-handler.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-sync-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/test-utils.js → test-utils.js} +0 -0
- /package/esm/production/{wirestate-react/test-utils.js.map → test-utils.js.map} +0 -0
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { CommandBus } from '../commands/command-bus.js';
|
|
2
|
-
import { getCommandHandlerMetadata } from '../commands/get-command-handler-metadata.js';
|
|
3
|
-
import { WireScope } from '../container/wire-scope.js';
|
|
4
|
-
import { buildEventDispatcher } from '../events/build-event-dispatcher.js';
|
|
5
|
-
import { EventBus } from '../events/event-bus.js';
|
|
6
|
-
import { getQueryHandlerMetadata } from '../queries/get-query-handler-metadata.js';
|
|
7
|
-
import { QueryBus } from '../queries/query-bus.js';
|
|
8
|
-
import { CONTAINER_REFS_BY_SERVICE, WIRE_SCOPES_BY_SERVICE, EVENT_UNSUBSCRIBERS_BY_SERVICE, QUERY_UNREGISTERS_BY_SERVICE, COMMAND_UNREGISTERS_BY_SERVICE } from '../registry.js';
|
|
9
|
-
import { getActivatedHandlerMetadata } from '../service/get-activated-handler-metadata.js';
|
|
10
|
-
import { getDeactivationHandlerMetadata } from '../service/get-deactivation-handler-metadata.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Registers a service class in the container with activation/deactivation logic.
|
|
14
|
-
* Ensures container references, event subscriptions, command and query handlers are managed correctly.
|
|
15
|
-
*
|
|
16
|
-
* @param container - target Inversify container
|
|
17
|
-
* @param entry - service constructor
|
|
18
|
-
* @param options - options object to control binding flow
|
|
19
|
-
*/
|
|
20
|
-
function bindService(container, entry, options) {
|
|
21
|
-
// Inversify's fluent binding API only allows a single `.onActivation` /
|
|
22
|
-
// `.onDeactivation` call per chain, so we register them on the container
|
|
23
|
-
// itself instead — this also works correctly if a later call rebinds the
|
|
24
|
-
// same token.
|
|
25
|
-
var whenBind = container.bind(entry).to(entry).inSingletonScope();
|
|
26
|
-
whenBind.onActivation(function (context, instance) {
|
|
27
|
-
// Ensure flag is initialized on activation.
|
|
28
|
-
instance.IS_DISPOSED = false;
|
|
29
|
-
CONTAINER_REFS_BY_SERVICE.set(instance, container);
|
|
30
|
-
attachWireScopes(instance, entry);
|
|
31
|
-
// Compose all events listeners into a single bus subscription so we only
|
|
32
|
-
// pay one Set lookup per emitted event.
|
|
33
|
-
var dispatcher = buildEventDispatcher(instance);
|
|
34
|
-
if (dispatcher) {
|
|
35
|
-
attachEventsSubscription(instance, dispatcher);
|
|
36
|
-
}
|
|
37
|
-
// Register every `@OnQuery` handler on the container's QueryBus, and
|
|
38
|
-
// remember the unregister functions so we can roll them back when the
|
|
39
|
-
// service is deactivated.
|
|
40
|
-
var queryBus = container.get(QueryBus);
|
|
41
|
-
for (var _i = 0, _a = getQueryHandlerMetadata(instance); _i < _a.length; _i++) {
|
|
42
|
-
var meta = _a[_i];
|
|
43
|
-
var method = instance[meta.methodName];
|
|
44
|
-
if (typeof method !== "function") {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
var unregister = queryBus.register(meta.type, method.bind(instance));
|
|
48
|
-
attachQueryUnregister(instance, unregister);
|
|
49
|
-
}
|
|
50
|
-
// Register every `@OnCommand` handler on the container's CommandBus, and
|
|
51
|
-
// remember the unregister functions so we can roll them back when the
|
|
52
|
-
// service is deactivated.
|
|
53
|
-
var commandBus = container.get(CommandBus);
|
|
54
|
-
for (var _b = 0, _c = getCommandHandlerMetadata(instance); _b < _c.length; _b++) {
|
|
55
|
-
var meta = _c[_b];
|
|
56
|
-
var method = instance[meta.methodName];
|
|
57
|
-
if (typeof method !== "function") {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
var unregister = commandBus.register(meta.type, method.bind(instance));
|
|
61
|
-
attachCommandUnregister(instance, unregister);
|
|
62
|
-
}
|
|
63
|
-
if (options === null || options === void 0 ? void 0 : options.isWithIgnoreLifecycle) ; else {
|
|
64
|
-
var _loop_1 = function (methodName) {
|
|
65
|
-
var method = instance[methodName];
|
|
66
|
-
if (typeof method !== "function") {
|
|
67
|
-
return "continue";
|
|
68
|
-
}
|
|
69
|
-
var result = method.call(instance);
|
|
70
|
-
if (result && typeof result.then === "function") {
|
|
71
|
-
result.catch(function (error) {
|
|
72
|
-
console.error("[wirestate] @OnActivated rejected for:", entry.name, String(methodName), error);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
// Call every `@OnActivated`-decorated method in base-to-derived order.
|
|
77
|
-
// Fire-and-forget any async init so we stay synchronous from the
|
|
78
|
-
// container's point of view.
|
|
79
|
-
for (var _d = 0, _e = getActivatedHandlerMetadata(instance); _d < _e.length; _d++) {
|
|
80
|
-
var methodName = _e[_d];
|
|
81
|
-
_loop_1(methodName);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return instance;
|
|
85
|
-
});
|
|
86
|
-
whenBind.onDeactivation(function (instance) {
|
|
87
|
-
if (options === null || options === void 0 ? void 0 : options.isWithIgnoreLifecycle) ; else {
|
|
88
|
-
// Call every `@OnDeactivation`-decorated method in base-to-derived order.
|
|
89
|
-
for (var _i = 0, _a = getDeactivationHandlerMetadata(instance); _i < _a.length; _i++) {
|
|
90
|
-
var methodName = _a[_i];
|
|
91
|
-
var method = instance[methodName];
|
|
92
|
-
if (typeof method === "function") {
|
|
93
|
-
method.call(instance);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// Flip the public disposal flag first so any async work already in
|
|
98
|
-
// flight (fetches awaiting in @Action methods, scheduled reactions,
|
|
99
|
-
// etc.) can short-circuit before it mutates the about-to-die instance.
|
|
100
|
-
// The cast is the only write-site for this `readonly` field.
|
|
101
|
-
instance.IS_DISPOSED = true;
|
|
102
|
-
detachWireScopes(instance);
|
|
103
|
-
detachCommandUnregister(instance);
|
|
104
|
-
detachQueryUnregister(instance);
|
|
105
|
-
detachEventSubscription(instance);
|
|
106
|
-
CONTAINER_REFS_BY_SERVICE.delete(instance);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Attaches a event subscription to a service.
|
|
111
|
-
*
|
|
112
|
-
* @param service - service instance
|
|
113
|
-
* @param handler - event handler
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
function attachEventsSubscription(service, handler) {
|
|
117
|
-
var _a;
|
|
118
|
-
var bus = (_a = CONTAINER_REFS_BY_SERVICE.get(service)) === null || _a === void 0 ? void 0 : _a.get(EventBus);
|
|
119
|
-
if (bus) {
|
|
120
|
-
EVENT_UNSUBSCRIBERS_BY_SERVICE.set(service, bus.subscribe(handler));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Detaches the event subscription from a service.
|
|
125
|
-
*
|
|
126
|
-
* @param service - service instance
|
|
127
|
-
* @internal
|
|
128
|
-
*/
|
|
129
|
-
function detachEventSubscription(service) {
|
|
130
|
-
var unsubscribe = EVENT_UNSUBSCRIBERS_BY_SERVICE.get(service);
|
|
131
|
-
if (unsubscribe) {
|
|
132
|
-
unsubscribe();
|
|
133
|
-
EVENT_UNSUBSCRIBERS_BY_SERVICE.delete(service);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Registers a query unregister function for a service.
|
|
138
|
-
*
|
|
139
|
-
* @param service - service instance
|
|
140
|
-
* @param unregister - query unregister function
|
|
141
|
-
* @internal
|
|
142
|
-
*/
|
|
143
|
-
function attachQueryUnregister(service, unregister) {
|
|
144
|
-
var list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
|
|
145
|
-
if (!list) {
|
|
146
|
-
list = [];
|
|
147
|
-
QUERY_UNREGISTERS_BY_SERVICE.set(service, list);
|
|
148
|
-
}
|
|
149
|
-
list.push(unregister);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Executes and removes all query unregister functions for a service.
|
|
153
|
-
*
|
|
154
|
-
* @param service - service instance
|
|
155
|
-
* @internal
|
|
156
|
-
*/
|
|
157
|
-
function detachQueryUnregister(service) {
|
|
158
|
-
var list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
|
|
159
|
-
if (!list) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
163
|
-
var unregister = list_1[_i];
|
|
164
|
-
unregister();
|
|
165
|
-
}
|
|
166
|
-
QUERY_UNREGISTERS_BY_SERVICE.delete(service);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Registers a command unregister function for a service.
|
|
170
|
-
*
|
|
171
|
-
* @param service - service instance
|
|
172
|
-
* @param unregister - command unregister function
|
|
173
|
-
* @internal
|
|
174
|
-
*/
|
|
175
|
-
function attachCommandUnregister(service, unregister) {
|
|
176
|
-
var list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
|
|
177
|
-
if (!list) {
|
|
178
|
-
list = [];
|
|
179
|
-
COMMAND_UNREGISTERS_BY_SERVICE.set(service, list);
|
|
180
|
-
}
|
|
181
|
-
list.push(unregister);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Executes and removes all command unregister functions for a service.
|
|
185
|
-
*
|
|
186
|
-
* @param service - service instance
|
|
187
|
-
* @internal
|
|
188
|
-
*/
|
|
189
|
-
function detachCommandUnregister(service) {
|
|
190
|
-
var list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
|
|
191
|
-
if (!list) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
for (var _i = 0, list_2 = list; _i < list_2.length; _i++) {
|
|
195
|
-
var unregister = list_2[_i];
|
|
196
|
-
unregister();
|
|
197
|
-
}
|
|
198
|
-
COMMAND_UNREGISTERS_BY_SERVICE.delete(service);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Reads `design:paramtypes` from the service constructor to find parameters typed as WireScope.
|
|
202
|
-
* Property iteration happens only when the constructor metadata declares a WireScope
|
|
203
|
-
* parameter, avoiding false positives from manually created or subclassed scopes.
|
|
204
|
-
*
|
|
205
|
-
* todo: Simplify this part.
|
|
206
|
-
*
|
|
207
|
-
* @param service - service instance
|
|
208
|
-
* @param Service - service constructor
|
|
209
|
-
* @internal
|
|
210
|
-
*/
|
|
211
|
-
function attachWireScopes(service, Service) {
|
|
212
|
-
var paramTypes = Reflect.getMetadata("design:paramtypes", Service);
|
|
213
|
-
if (!(paramTypes === null || paramTypes === void 0 ? void 0 : paramTypes.some(function (type) {
|
|
214
|
-
return type === WireScope;
|
|
215
|
-
}))) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
var scopes = [];
|
|
219
|
-
for (var _i = 0, _a = Object.getOwnPropertyNames(service); _i < _a.length; _i++) {
|
|
220
|
-
var key = _a[_i];
|
|
221
|
-
var value = service[key];
|
|
222
|
-
if ((value === null || value === void 0 ? void 0 : value.constructor) === WireScope) {
|
|
223
|
-
scopes.push(value);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (scopes.length > 0) {
|
|
227
|
-
WIRE_SCOPES_BY_SERVICE.set(service, scopes);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Marks all injected WireScope instances for this service as disposed and removes
|
|
232
|
-
* the stored references.
|
|
233
|
-
*
|
|
234
|
-
* todo: Simplify this part.
|
|
235
|
-
*
|
|
236
|
-
* @param service - service instance
|
|
237
|
-
* @internal
|
|
238
|
-
*/
|
|
239
|
-
function detachWireScopes(service) {
|
|
240
|
-
var scopes = WIRE_SCOPES_BY_SERVICE.get(service);
|
|
241
|
-
if (!scopes) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
|
|
245
|
-
var scope = scopes_1[_i];
|
|
246
|
-
scope.isDisposed = true;
|
|
247
|
-
scope.container = null;
|
|
248
|
-
}
|
|
249
|
-
WIRE_SCOPES_BY_SERVICE.delete(service);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export { bindService };
|
|
253
|
-
//# sourceMappingURL=bind-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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","_i","_a","getQueryHandlerMetadata","length","meta","method","methodName","unregister","register","type","attachQueryUnregister","commandBus","CommandBus","_b","_c","getCommandHandlerMetadata","attachCommandUnregister","isWithIgnoreLifecycle","result","call","then","catch","error","console","name","String","_d","_e","getActivatedHandlerMetadata","onDeactivation","getDeactivationHandlerMetadata","detachWireScopes","detachCommandUnregister","detachQueryUnregister","detachEventSubscription","delete","service","handler","bus","EventBus","EVENT_UNSUBSCRIBERS_BY_SERVICE","subscribe","unsubscribe","list","QUERY_UNREGISTERS_BY_SERVICE","push","list_1","COMMAND_UNREGISTERS_BY_SERVICE","list_2","Service","paramTypes","Reflect","getMetadata","some","WireScope","scopes","Object","getOwnPropertyNames","key","value","constructor","WIRE_SCOPES_BY_SERVICE","scopes_1","scope","isDisposed"],"mappings":";;;;;;;;;;;AA8BA;;;;;;;AAOG;SACaA,WAAWA,CACzBC,SAAoB,EACpBC,KAAiB,EACjBC,OAA4B,EAAA;AAS5B;AACA;AACA;AACA;AACA,EAAA,IAAMC,QAAQ,GAA8BH,SAAS,CAACI,IAAI,CAAIH,KAAK,CAAC,CAACI,EAAE,CAACJ,KAAK,CAAC,CAACK,gBAAgB,EAAE;AAEjGH,EAAAA,QAAQ,CAACI,YAAY,CAAC,UAACC,OAAO,EAAEC,QAAQ,EAAA;AAUtC;IACCA,QAAqC,CAACC,WAAW,GAAG,KAAK;AAE1DC,IAAAA,yBAAyB,CAACC,GAAG,CAACH,QAAQ,EAAET,SAAS,CAAC;AAClDa,IAAAA,gBAAgB,CAACJ,QAAQ,EAAER,KAAK,CAAC;AAEjC;AACA;AACA,IAAA,IAAMa,UAAU,GAA2BC,oBAAoB,CAACN,QAAQ,CAAC;AAEzE,IAAA,IAAIK,UAAU,EAAE;AACdE,MAAAA,wBAAwB,CAACP,QAAQ,EAAEK,UAAU,CAAC;AAChD,IAAA;AAEA;AACA;AACA;AACA,IAAA,IAAMG,QAAQ,GAAajB,SAAS,CAACkB,GAAG,CAACC,QAAQ,CAAC;IAElD,KAAmB,IAAAC,EAAA,GAAA,CAAiC,EAAjCC,EAAA,GAAAC,uBAAuB,CAACb,QAAQ,CAAC,EAAjCW,EAAA,GAAAC,EAAA,CAAAE,MAAiC,EAAjCH,EAAA,EAAiC,EAAE;AAAjD,MAAA,IAAMI,IAAI,GAAAH,EAAA,CAAAD,EAAA,CAAA;AACb,MAAA,IAAMK,MAAM,GAAIhB,QAAwD,CAACe,IAAI,CAACE,UAAU,CAAC;AAEz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;AAEA;;;;;;;;AAQG;AACH,SAASxB,gBAAgBA,CAAmBK,OAAU,EAAA;AACpD,EAAA,IAAMmB,MAAM,GAA4BM,sBAAsB,CAAC/D,GAAG,CAACsC,OAAO,CAAC;EAE3E,IAAI,CAACmB,MAAM,EAAE;AACX,IAAA;AACF,EAAA;AAEA,EAAA,KAAoB,IAAAvD,EAAA,GAAA,CAAM,EAAN8D,QAAA,GAAAP,MAAM,EAANvD,oBAAM,EAANA,EAAA,EAAM,EAAE;AAAvB,IAAA,IAAM+D,KAAK,GAAAD,QAAA,CAAA9D,EAAA,CAAA;IACb+D,KAAiC,CAACC,UAAU,GAAG,IAAI;IACnDD,KAAuD,CAACnF,SAAS,GAAG,IAAI;AAC3E,EAAA;AAEAiF,EAAAA,sBAAsB,CAAC1B,MAAM,CAACC,OAAO,CAAC;AACxC;;;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the container token for a service entry.
|
|
3
|
-
* For plain service classes the class itself is the token;
|
|
4
|
-
* for descriptors the `id` field is used.
|
|
5
|
-
*
|
|
6
|
-
* @param entry - entry descriptor to get service identifier for
|
|
7
|
-
* @returns injectable identifier token
|
|
8
|
-
*/
|
|
9
|
-
function getEntryToken(entry) {
|
|
10
|
-
return typeof entry === "function" ? entry : entry.id;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { getEntryToken };
|
|
14
|
-
//# sourceMappingURL=get-entry-token.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-entry-token.js","sources":["../../../../../../../../../src/wirestate-core/bind/get-entry-token.ts"],"sourcesContent":[null],"names":["getEntryToken","entry","id"],"mappings":"AAIA;;;;;;;AAOG;AACG,SAAUA,aAAaA,CAA4BC,KAAwC,EAAA;EAC/F,OAAO,OAAOA,KAAK,KAAK,UAAU,GAAGA,KAAK,GAAGA,KAAK,CAACC,EAAE;AACvD;;;;"}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER } from '../error/error-code.js';
|
|
2
|
-
import { WirestateError } from '../error/wirestate-error.js';
|
|
3
|
-
import { CommandStatus } from '../types/commands.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Dispatches commands to handlers.
|
|
7
|
-
*
|
|
8
|
-
* Unlike queries, command execution always wraps the handler in a promise
|
|
9
|
-
* and returns a descriptor with task, status, and responder.
|
|
10
|
-
*/
|
|
11
|
-
var CommandBus = /** @class */function () {
|
|
12
|
-
function CommandBus() {
|
|
13
|
-
/**
|
|
14
|
-
* Internal handler storage.
|
|
15
|
-
* Uses a stack for each command type to support shadowing.
|
|
16
|
-
*/
|
|
17
|
-
this.handlers = new Map();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Registers a command handler.
|
|
21
|
-
* Returns an unregister function.
|
|
22
|
-
*
|
|
23
|
-
* @param type - command type
|
|
24
|
-
* @param handler - handler function
|
|
25
|
-
* @returns unregister function
|
|
26
|
-
*/
|
|
27
|
-
CommandBus.prototype.register = function (type, handler) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
var stack = this.handlers.get(type);
|
|
30
|
-
if (!stack) {
|
|
31
|
-
stack = [];
|
|
32
|
-
this.handlers.set(type, stack);
|
|
33
|
-
}
|
|
34
|
-
stack.push(handler);
|
|
35
|
-
return function () {
|
|
36
|
-
var current = _this.handlers.get(type);
|
|
37
|
-
if (!current) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
var index = current.indexOf(handler);
|
|
41
|
-
if (index >= 0) {
|
|
42
|
-
current.splice(index, 1);
|
|
43
|
-
}
|
|
44
|
-
// Clean empty stacks.
|
|
45
|
-
if (current.length === 0) {
|
|
46
|
-
_this.handlers.delete(type);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Dispatches a command to the last registered handler.
|
|
52
|
-
* Wraps the handler execution in a promise and returns a descriptor.
|
|
53
|
-
*
|
|
54
|
-
* @param type - command type
|
|
55
|
-
* @param data - command payload
|
|
56
|
-
* @returns command descriptor with task, status, and responder
|
|
57
|
-
*
|
|
58
|
-
* @throws if no handler is registered
|
|
59
|
-
*/
|
|
60
|
-
CommandBus.prototype.command = function (type, data) {
|
|
61
|
-
var stack = this.handlers.get(type);
|
|
62
|
-
if (!(stack === null || stack === void 0 ? void 0 : stack.length)) {
|
|
63
|
-
throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER, "No command handler registered in container for type: '".concat(String(type), "'."));
|
|
64
|
-
}
|
|
65
|
-
var handler = stack[stack.length - 1];
|
|
66
|
-
var descriptor = {
|
|
67
|
-
task: null,
|
|
68
|
-
status: CommandStatus.PENDING
|
|
69
|
-
};
|
|
70
|
-
descriptor.task = Promise.resolve().then(function () {
|
|
71
|
-
return handler(data);
|
|
72
|
-
}).then(function (result) {
|
|
73
|
-
descriptor.status = CommandStatus.SETTLED;
|
|
74
|
-
return result;
|
|
75
|
-
}).catch(function (error) {
|
|
76
|
-
descriptor.status = CommandStatus.ERROR;
|
|
77
|
-
throw error;
|
|
78
|
-
});
|
|
79
|
-
return descriptor;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Dispatches a command to the last registered handler, returning null if no handler exists.
|
|
83
|
-
*
|
|
84
|
-
* @param type - command type
|
|
85
|
-
* @param data - command payload
|
|
86
|
-
* @returns command descriptor or null if no handler is registered
|
|
87
|
-
*/
|
|
88
|
-
CommandBus.prototype.commandOptional = function (type, data) {
|
|
89
|
-
var stack = this.handlers.get(type);
|
|
90
|
-
return (stack === null || stack === void 0 ? void 0 : stack.length) ? this.command(type, data) : null;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Checks if a handler is registered for the given type.
|
|
94
|
-
*
|
|
95
|
-
* @param type - command type
|
|
96
|
-
* @returns true if handler exists
|
|
97
|
-
*/
|
|
98
|
-
CommandBus.prototype.has = function (type) {
|
|
99
|
-
var _a;
|
|
100
|
-
return Boolean((_a = this.handlers.get(type)) === null || _a === void 0 ? void 0 : _a.length);
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Removes all registered handlers.
|
|
104
|
-
*/
|
|
105
|
-
CommandBus.prototype.clear = function () {
|
|
106
|
-
this.handlers.clear();
|
|
107
|
-
};
|
|
108
|
-
return CommandBus;
|
|
109
|
-
}();
|
|
110
|
-
|
|
111
|
-
export { CommandBus };
|
|
112
|
-
//# sourceMappingURL=command-bus.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-bus.js","sources":["../../../../../../../../../src/wirestate-core/commands/command-bus.ts"],"sourcesContent":[null],"names":["CommandBus","handlers","Map","prototype","register","type","handler","_this","stack","get","set","push","current","index","indexOf","splice","length","delete","command","data","WirestateError","ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER","concat","String","descriptor","task","status","CommandStatus","PENDING","Promise","resolve","then","result","SETTLED","catch","error","ERROR","commandOptional","has","Boolean","_a","clear"],"mappings":";;;;AAcA;;;;;AAKG;AACH,IAAAA,UAAA,gBAAA,YAAA;EAAA,SAAAA,UAAAA,GAAA;AACE;;;AAGG;AACc,IAAA,IAAA,CAAAC,QAAQ,GAA4C,IAAIC,GAAG,EAAE;AA4HhF,EAAA;AA1HE;;;;;;;AAOG;EACIF,UAAA,CAAAG,SAAA,CAAAC,QAAQ,GAAf,UAA0CC,IAAiB,EAAEC,OAA6B,EAAA;IAA1F,IAAAC,KAAA,GAAA,IAAA;IAOE,IAAIC,KAAK,GAAiC,IAAI,CAACP,QAAQ,CAACQ,GAAG,CAACJ,IAAI,CAAC;IAEjE,IAAI,CAACG,KAAK,EAAE;AACVA,MAAAA,KAAK,GAAG,EAAE;MACV,IAAI,CAACP,QAAQ,CAACS,GAAG,CAACL,IAAI,EAAEG,KAAK,CAAC;AAChC,IAAA;AAEAA,IAAAA,KAAK,CAACG,IAAI,C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COMMAND_HANDLER_METADATA } from '../registry.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Retrieves `@OnCommand` metadata from the class hierarchy.
|
|
5
|
-
* Returns handlers ordered from base to derived class.
|
|
6
|
-
*
|
|
7
|
-
* @param instance - service instance
|
|
8
|
-
* @returns metadata list
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
function getCommandHandlerMetadata(instance) {
|
|
12
|
-
var constructor = instance.constructor;
|
|
13
|
-
var chain = [];
|
|
14
|
-
// Traverse prototype chain up to Object/Function
|
|
15
|
-
while (typeof constructor === "function" && constructor !== Object && constructor !== Function.prototype) {
|
|
16
|
-
var own = COMMAND_HANDLER_METADATA.get(constructor);
|
|
17
|
-
if (own && own.length > 0) {
|
|
18
|
-
chain.push(own);
|
|
19
|
-
}
|
|
20
|
-
constructor = Object.getPrototypeOf(constructor);
|
|
21
|
-
}
|
|
22
|
-
// Reverse to ensure parent-first execution order.
|
|
23
|
-
return chain.reverse().flat();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { getCommandHandlerMetadata };
|
|
27
|
-
//# sourceMappingURL=get-command-handler-metadata.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;;;;AAOG;AACG,SAAUA,yBAAyBA,CAACC,QAAgB,EAAA;AAMxD,EAAA,IAAIC,WAAW,GAAYD,QAAQ,CAACC,WAAW;EAE/C,IAAMC,KAAK,GAAyC,EAAE;AAEtD;AACA,EAAA,OAAO,OAAOD,WAAW,KAAK,UAAU,IAAIA,WAAW,KAAKE,MAAM,IAAIF,WAAW,KAAKG,QAAQ,CAACC,SAAS,EAAE;AACxG,IAAA,IAAMC,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;;;;"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Container } from 'inversify';
|
|
2
|
-
import { CommandBus } from '../commands/command-bus.js';
|
|
3
|
-
import { EventBus } from '../events/event-bus.js';
|
|
4
|
-
import { QueryBus } from '../queries/query-bus.js';
|
|
5
|
-
import { SEEDS_TOKEN, SEED_TOKEN } from '../registry.js';
|
|
6
|
-
import { WireScope } from './wire-scope.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Creates an IoC container with framework essentials.
|
|
10
|
-
*
|
|
11
|
-
* @param options - container configuration
|
|
12
|
-
* @returns new IoC container
|
|
13
|
-
*/
|
|
14
|
-
function createIocContainer(options) {
|
|
15
|
-
var _a;
|
|
16
|
-
if (options === void 0) {
|
|
17
|
-
options = {};
|
|
18
|
-
}
|
|
19
|
-
var container = new Container({
|
|
20
|
-
defaultScope: "Singleton",
|
|
21
|
-
parent: options.parent
|
|
22
|
-
});
|
|
23
|
-
container.bind(EventBus).toConstantValue(new EventBus());
|
|
24
|
-
container.bind(QueryBus).toConstantValue(new QueryBus());
|
|
25
|
-
container.bind(CommandBus).toConstantValue(new CommandBus());
|
|
26
|
-
container.bind(SEEDS_TOKEN).toConstantValue(new Map());
|
|
27
|
-
container.bind(SEED_TOKEN).toConstantValue((_a = options.seed) !== null && _a !== void 0 ? _a : {});
|
|
28
|
-
container.bind(WireScope).toResolvedValue(function () {
|
|
29
|
-
return new WireScope(container);
|
|
30
|
-
}).inTransientScope();
|
|
31
|
-
return container;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { createIocContainer };
|
|
35
|
-
//# sourceMappingURL=create-ioc-container.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-ioc-container.js","sources":["../../../../../../../../../src/wirestate-core/container/create-ioc-container.ts"],"sourcesContent":[null],"names":["createIocContainer","options","container","Container","defaultScope","parent","bind","EventBus","toConstantValue","QueryBus","CommandBus","SEEDS_TOKEN","Map","SEED_TOKEN","_a","seed","WireScope","toResolvedValue","inTransientScope"],"mappings":";;;;;;;AAyBA;;;;;AAKG;AACG,SAAUA,kBAAkBA,CAACC,OAAuC,EAAA;;AAAvC,EAAA,IAAAA,OAAA,KAAA,MAAA,EAAA;IAAAA,OAAA,GAAA,EAAuC;AAAA,EAAA;AAGxE,EAAA,IAAMC,SAAS,GAAc,IAAIC,SAAS,CAAC;AACzCC,IAAAA,YAAY,EAAE,WAAW;IACzBC,MAAM,EAAEJ,OAAO,CAACI;AACjB,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;AAC5DR,EAAAA,SAAS,CAACI,IAAI,CAACK,WAAW,CAAC,CAACH,eAAe,CAAC,IAAII,GAAG,EAAc,CAAC;EAClEV,SAAS,CAACI,IAAI,CAACO,UAAU,CAAC,CAACL,eAAe,CAAC,CAAAM,EAAA,GAAAb,OAAO,CAACc,IAAI,MAAA,IAAA,IAAAD,EAAA,KAAA,MAAA,GAAAA,EAAA,GAAI,EAAE,CAAC;EAE9DZ,SAAS,CACNI,IAAI,CAACU,SAAS,CAAC,CACfC,eAAe,CAAC,YAAA;AAAiB,IAAA,OAAA,IAAID,SAAS,CAACd,SAAS,CAAC;AAAxB,EAAA,CAAwB,CAAC,CAC1DgB,gBAAgB,EAAE;AAIrB,EAAA,OAAOhB,SAAS;AAClB;;;;"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { injectable } from 'inversify';
|
|
3
|
-
import { CommandBus } from '../commands/command-bus.js';
|
|
4
|
-
import { ERROR_CODE_ACCESS_AFTER_DISPOSAL, ERROR_CODE_ACCESS_BEFORE_ACTIVATION } from '../error/error-code.js';
|
|
5
|
-
import { WirestateError } from '../error/wirestate-error.js';
|
|
6
|
-
import { EventBus } from '../events/event-bus.js';
|
|
7
|
-
import { QueryBus } from '../queries/query-bus.js';
|
|
8
|
-
import { SEEDS_TOKEN, SEED_TOKEN } from '../registry.js';
|
|
9
|
-
|
|
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.
|
|
14
|
-
*/
|
|
15
|
-
var WireScope = /** @class */function () {
|
|
16
|
-
function WireScope(container) {
|
|
17
|
-
this.container = container;
|
|
18
|
-
/**
|
|
19
|
-
* Whether the scope was deactivated and disposed from the container.
|
|
20
|
-
*/
|
|
21
|
-
this.isDisposed = false;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Access the IoC container.
|
|
25
|
-
* Available only for activated instances of scope.
|
|
26
|
-
*
|
|
27
|
-
* @returns active container
|
|
28
|
-
*
|
|
29
|
-
* @throws WirestateError if scope is not activated or already disposed
|
|
30
|
-
*/
|
|
31
|
-
WireScope.prototype.getContainer = function () {
|
|
32
|
-
if (this.container) {
|
|
33
|
-
return this.container;
|
|
34
|
-
}
|
|
35
|
-
if (this.isDisposed) {
|
|
36
|
-
throw new WirestateError(ERROR_CODE_ACCESS_AFTER_DISPOSAL, "WireScope::container accessed after deactivation. Ensure service is properly disposed.");
|
|
37
|
-
} else {
|
|
38
|
-
throw new WirestateError(ERROR_CODE_ACCESS_BEFORE_ACTIVATION, "WireScope::container accessed before activation. " + "Ensure service is bound to container and is properly resolved.");
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Resolves a sibling service or injected value.
|
|
43
|
-
* Use for lazy resolution or circular dependency breaking.
|
|
44
|
-
* Available only for activated containers.
|
|
45
|
-
*
|
|
46
|
-
* @param injectionId - injection identifier
|
|
47
|
-
* @returns resolved injection, service instance, or generic value
|
|
48
|
-
*
|
|
49
|
-
* @throws WirestateError if scope is not activated
|
|
50
|
-
*/
|
|
51
|
-
WireScope.prototype.resolve = function (injectionId) {
|
|
52
|
-
return this.getContainer().get(injectionId);
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Resolves a sibling service or injected value.
|
|
56
|
-
* Use for lazy resolution or circular dependency breaking.
|
|
57
|
-
* Available only for activated containers.
|
|
58
|
-
*
|
|
59
|
-
* @param injectionId - injection identifier
|
|
60
|
-
* @returns resolved injection, service instance, generic value, or null if it is not bound
|
|
61
|
-
*
|
|
62
|
-
* @throws WirestateError if scope is not activated
|
|
63
|
-
*/
|
|
64
|
-
WireScope.prototype.resolveOptional = function (injectionId) {
|
|
65
|
-
var container = this.getContainer();
|
|
66
|
-
return container.isBound(injectionId) ? container.get(injectionId) : null;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Broadcasts an event.
|
|
70
|
-
* Available only for activated containers.
|
|
71
|
-
*
|
|
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
|
|
75
|
-
*
|
|
76
|
-
* @throws WirestateError if scope is not activated
|
|
77
|
-
*/
|
|
78
|
-
WireScope.prototype.emitEvent = function (type, payload, from) {
|
|
79
|
-
this.getContainer().get(EventBus).emit({
|
|
80
|
-
type: type,
|
|
81
|
-
payload: payload,
|
|
82
|
-
from: from === undefined ? this : from
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Dispatches a query and returns the result.
|
|
87
|
-
* Available only for activated containers.
|
|
88
|
-
*
|
|
89
|
-
* @param type - query type
|
|
90
|
-
* @param data - query data
|
|
91
|
-
* @returns query result
|
|
92
|
-
*
|
|
93
|
-
* @throws WirestateError if scope is not activated
|
|
94
|
-
*/
|
|
95
|
-
WireScope.prototype.queryData = function (type, data) {
|
|
96
|
-
return this.getContainer().get(QueryBus).query(type, data);
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Dispatches a query and returns the result.
|
|
100
|
-
* Available only for activated containers.
|
|
101
|
-
*
|
|
102
|
-
* @param type - query type
|
|
103
|
-
* @param data - query data
|
|
104
|
-
* @returns query result or null if handler is not registered
|
|
105
|
-
*/
|
|
106
|
-
WireScope.prototype.queryOptionalData = function (type, data) {
|
|
107
|
-
return this.getContainer().get(QueryBus).queryOptional(type, data);
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Dispatches a command and returns the descriptor.
|
|
111
|
-
* Available only for activated containers.
|
|
112
|
-
*
|
|
113
|
-
* @param type - command type
|
|
114
|
-
* @param data - command data
|
|
115
|
-
* @returns command descriptor
|
|
116
|
-
*
|
|
117
|
-
* @throws WirestateError if scope is not activated
|
|
118
|
-
*/
|
|
119
|
-
WireScope.prototype.executeCommand = function (type, data) {
|
|
120
|
-
return this.getContainer().get(CommandBus).command(type, data);
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Dispatches a command and returns the descriptor.
|
|
124
|
-
* Available only for activated containers.
|
|
125
|
-
*
|
|
126
|
-
* @param type - command type
|
|
127
|
-
* @param data - command data
|
|
128
|
-
* @returns command descriptor or null if handler is not registered
|
|
129
|
-
*/
|
|
130
|
-
WireScope.prototype.executeOptionalCommand = function (type, data) {
|
|
131
|
-
return this.getContainer().get(CommandBus).commandOptional(type, data);
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Reads seed for the provided injection.
|
|
135
|
-
* Returns shared seed if parameters are not provided.
|
|
136
|
-
* Available only for activated containers.
|
|
137
|
-
*
|
|
138
|
-
* @param seed - lookup key
|
|
139
|
-
* @returns seed data or null if missing
|
|
140
|
-
*
|
|
141
|
-
* @throws WirestateError if context is not activated
|
|
142
|
-
*/
|
|
143
|
-
WireScope.prototype.getSeed = function (seed) {
|
|
144
|
-
return seed ? this.getContainer().get(SEEDS_TOKEN).get(seed) || null : this.getContainer().get(SEED_TOKEN);
|
|
145
|
-
};
|
|
146
|
-
WireScope = __decorate([injectable(), __metadata("design:paramtypes", [Object])], WireScope);
|
|
147
|
-
return WireScope;
|
|
148
|
-
}();
|
|
149
|
-
|
|
150
|
-
export { WireScope };
|
|
151
|
-
//# sourceMappingURL=wire-scope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,SAA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CAgMrB;AAAD,EAAA,OAAAA,SAAC;AAAA,CAjMD;;;;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var ERROR_CODE_GENERIC = 1;
|
|
2
|
-
var ERROR_CODE_INVALID_ARGUMENTS = 51;
|
|
3
|
-
var ERROR_CODE_BINDING_SCOPE = 52;
|
|
4
|
-
var ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER = 101;
|
|
5
|
-
var ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER = 102;
|
|
6
|
-
var ERROR_CODE_ACCESS_BEFORE_ACTIVATION = 200;
|
|
7
|
-
var ERROR_CODE_ACCESS_AFTER_DISPOSAL = 201;
|
|
8
|
-
|
|
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
|
-
//# sourceMappingURL=error-code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|