@wirestate/core 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/LICENSE +21 -0
- package/README.md +319 -0
- package/cjs/development/index.js +301 -0
- package/cjs/development/index.js.map +1 -0
- package/cjs/development/lib.js +1007 -0
- package/cjs/development/lib.js.map +1 -0
- package/cjs/development/test-utils.js +128 -0
- package/cjs/development/test-utils.js.map +1 -0
- package/cjs/production/index.js +1 -0
- package/cjs/production/index.js.map +1 -0
- package/cjs/production/lib.js +1 -0
- package/cjs/production/lib.js.map +1 -0
- package/cjs/production/test-utils.js +1 -0
- package/cjs/production/test-utils.js.map +1 -0
- package/esm/development/alias.js +9 -0
- package/esm/development/alias.js.map +1 -0
- package/esm/development/bind/bind-constant.js +19 -0
- package/esm/development/bind/bind-constant.js.map +1 -0
- package/esm/development/bind/bind-dynamic-value.js +28 -0
- package/esm/development/bind/bind-dynamic-value.js.map +1 -0
- package/esm/development/bind/bind-entry.js +39 -0
- package/esm/development/bind/bind-entry.js.map +1 -0
- package/esm/development/bind/bind-service.js +253 -0
- package/esm/development/bind/bind-service.js.map +1 -0
- package/esm/development/bind/get-entry-token.js +14 -0
- package/esm/development/bind/get-entry-token.js.map +1 -0
- package/esm/development/commands/command-bus.js +112 -0
- package/esm/development/commands/command-bus.js.map +1 -0
- package/esm/development/commands/command-optional.js +16 -0
- package/esm/development/commands/command-optional.js.map +1 -0
- package/esm/development/commands/command.js +16 -0
- package/esm/development/commands/command.js.map +1 -0
- package/esm/development/commands/get-command-handler-metadata.js +27 -0
- package/esm/development/commands/get-command-handler-metadata.js.map +1 -0
- package/esm/development/commands/on-command.js +26 -0
- package/esm/development/commands/on-command.js.map +1 -0
- package/esm/development/container/create-ioc-container.js +35 -0
- package/esm/development/container/create-ioc-container.js.map +1 -0
- package/esm/development/container/wire-scope.js +151 -0
- package/esm/development/container/wire-scope.js.map +1 -0
- package/esm/development/error/error-code.js +10 -0
- package/esm/development/error/error-code.js.map +1 -0
- package/esm/development/error/wirestate-error.js +29 -0
- package/esm/development/error/wirestate-error.js.map +1 -0
- package/esm/development/events/build-event-dispatcher.js +39 -0
- package/esm/development/events/build-event-dispatcher.js.map +1 -0
- package/esm/development/events/emit-event.js +20 -0
- package/esm/development/events/emit-event.js.map +1 -0
- package/esm/development/events/event-bus.js +52 -0
- package/esm/development/events/event-bus.js.map +1 -0
- package/esm/development/events/get-event-handler-metadata.js +27 -0
- package/esm/development/events/get-event-handler-metadata.js.map +1 -0
- package/esm/development/events/on-event.js +29 -0
- package/esm/development/events/on-event.js.map +1 -0
- package/esm/development/index.js +28 -0
- package/esm/development/index.js.map +1 -0
- package/esm/development/queries/get-query-handler-metadata.js +27 -0
- package/esm/development/queries/get-query-handler-metadata.js.map +1 -0
- package/esm/development/queries/on-query.js +26 -0
- package/esm/development/queries/on-query.js.map +1 -0
- package/esm/development/queries/query-bus.js +99 -0
- package/esm/development/queries/query-bus.js.map +1 -0
- package/esm/development/queries/query-optional.js +16 -0
- package/esm/development/queries/query-optional.js.map +1 -0
- package/esm/development/queries/query.js +16 -0
- package/esm/development/queries/query.js.map +1 -0
- package/esm/development/registry.js +56 -0
- package/esm/development/registry.js.map +1 -0
- package/esm/development/seeds/apply-seeds.js +21 -0
- package/esm/development/seeds/apply-seeds.js.map +1 -0
- package/esm/development/seeds/apply-shared-seed.js +14 -0
- package/esm/development/seeds/apply-shared-seed.js.map +1 -0
- package/esm/development/seeds/unapply-seeds.js +19 -0
- package/esm/development/seeds/unapply-seeds.js.map +1 -0
- package/esm/development/service/get-activated-handler-metadata.js +27 -0
- package/esm/development/service/get-activated-handler-metadata.js.map +1 -0
- package/esm/development/service/get-deactivation-handler-metadata.js +27 -0
- package/esm/development/service/get-deactivation-handler-metadata.js.map +1 -0
- package/esm/development/service/on-activated.js +21 -0
- package/esm/development/service/on-activated.js.map +1 -0
- package/esm/development/service/on-deactivation.js +21 -0
- package/esm/development/service/on-deactivation.js.map +1 -0
- package/esm/development/test-utils/mock-bind-entry.js +24 -0
- package/esm/development/test-utils/mock-bind-entry.js.map +1 -0
- package/esm/development/test-utils/mock-bind-service.js +24 -0
- package/esm/development/test-utils/mock-bind-service.js.map +1 -0
- package/esm/development/test-utils/mock-container.js +52 -0
- package/esm/development/test-utils/mock-container.js.map +1 -0
- package/esm/development/test-utils/mock-service.js +26 -0
- package/esm/development/test-utils/mock-service.js.map +1 -0
- package/esm/development/test-utils/mock-unbind-service.js +13 -0
- package/esm/development/test-utils/mock-unbind-service.js.map +1 -0
- package/esm/development/test-utils.js +6 -0
- package/esm/development/test-utils.js.map +1 -0
- package/esm/development/types/commands.js +12 -0
- package/esm/development/types/commands.js.map +1 -0
- package/esm/production/alias.js +1 -0
- package/esm/production/alias.js.map +1 -0
- package/esm/production/bind/bind-constant.js +1 -0
- package/esm/production/bind/bind-constant.js.map +1 -0
- package/esm/production/bind/bind-dynamic-value.js +1 -0
- package/esm/production/bind/bind-dynamic-value.js.map +1 -0
- package/esm/production/bind/bind-entry.js +1 -0
- package/esm/production/bind/bind-entry.js.map +1 -0
- package/esm/production/bind/bind-service.js +1 -0
- package/esm/production/bind/bind-service.js.map +1 -0
- package/esm/production/bind/get-entry-token.js +1 -0
- package/esm/production/bind/get-entry-token.js.map +1 -0
- package/esm/production/commands/command-bus.js +1 -0
- package/esm/production/commands/command-bus.js.map +1 -0
- package/esm/production/commands/command-optional.js +1 -0
- package/esm/production/commands/command-optional.js.map +1 -0
- package/esm/production/commands/command.js +1 -0
- package/esm/production/commands/command.js.map +1 -0
- package/esm/production/commands/get-command-handler-metadata.js +1 -0
- package/esm/production/commands/get-command-handler-metadata.js.map +1 -0
- package/esm/production/commands/on-command.js +1 -0
- package/esm/production/commands/on-command.js.map +1 -0
- package/esm/production/container/create-ioc-container.js +1 -0
- package/esm/production/container/create-ioc-container.js.map +1 -0
- package/esm/production/container/wire-scope.js +1 -0
- package/esm/production/container/wire-scope.js.map +1 -0
- package/esm/production/error/error-code.js +1 -0
- package/esm/production/error/error-code.js.map +1 -0
- package/esm/production/error/wirestate-error.js +1 -0
- package/esm/production/error/wirestate-error.js.map +1 -0
- package/esm/production/events/build-event-dispatcher.js +1 -0
- package/esm/production/events/build-event-dispatcher.js.map +1 -0
- package/esm/production/events/emit-event.js +1 -0
- package/esm/production/events/emit-event.js.map +1 -0
- package/esm/production/events/event-bus.js +1 -0
- package/esm/production/events/event-bus.js.map +1 -0
- package/esm/production/events/get-event-handler-metadata.js +1 -0
- package/esm/production/events/get-event-handler-metadata.js.map +1 -0
- package/esm/production/events/on-event.js +1 -0
- package/esm/production/events/on-event.js.map +1 -0
- package/esm/production/index.js +1 -0
- package/esm/production/index.js.map +1 -0
- package/esm/production/queries/get-query-handler-metadata.js +1 -0
- package/esm/production/queries/get-query-handler-metadata.js.map +1 -0
- package/esm/production/queries/on-query.js +1 -0
- package/esm/production/queries/on-query.js.map +1 -0
- package/esm/production/queries/query-bus.js +1 -0
- package/esm/production/queries/query-bus.js.map +1 -0
- package/esm/production/queries/query-optional.js +1 -0
- package/esm/production/queries/query-optional.js.map +1 -0
- package/esm/production/queries/query.js +1 -0
- package/esm/production/queries/query.js.map +1 -0
- package/esm/production/registry.js +1 -0
- package/esm/production/registry.js.map +1 -0
- package/esm/production/seeds/apply-seeds.js +1 -0
- package/esm/production/seeds/apply-seeds.js.map +1 -0
- package/esm/production/seeds/apply-shared-seed.js +1 -0
- package/esm/production/seeds/apply-shared-seed.js.map +1 -0
- package/esm/production/seeds/unapply-seeds.js +1 -0
- package/esm/production/seeds/unapply-seeds.js.map +1 -0
- package/esm/production/service/get-activated-handler-metadata.js +1 -0
- package/esm/production/service/get-activated-handler-metadata.js.map +1 -0
- package/esm/production/service/get-deactivation-handler-metadata.js +1 -0
- package/esm/production/service/get-deactivation-handler-metadata.js.map +1 -0
- package/esm/production/service/on-activated.js +1 -0
- package/esm/production/service/on-activated.js.map +1 -0
- package/esm/production/service/on-deactivation.js +1 -0
- package/esm/production/service/on-deactivation.js.map +1 -0
- package/esm/production/test-utils/mock-bind-entry.js +1 -0
- package/esm/production/test-utils/mock-bind-entry.js.map +1 -0
- package/esm/production/test-utils/mock-bind-service.js +1 -0
- package/esm/production/test-utils/mock-bind-service.js.map +1 -0
- package/esm/production/test-utils/mock-container.js +1 -0
- package/esm/production/test-utils/mock-container.js.map +1 -0
- package/esm/production/test-utils/mock-service.js +1 -0
- package/esm/production/test-utils/mock-service.js.map +1 -0
- package/esm/production/test-utils/mock-unbind-service.js +1 -0
- package/esm/production/test-utils/mock-unbind-service.js.map +1 -0
- package/esm/production/test-utils.js +1 -0
- package/esm/production/test-utils.js.map +1 -0
- package/esm/production/types/commands.js +1 -0
- package/esm/production/types/commands.js.map +1 -0
- package/index.d.ts +566 -0
- package/lib.d.ts +17 -0
- package/package.json +61 -0
- package/test-utils.d.ts +108 -0
|
@@ -0,0 +1,151 @@
|
|
|
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
|
|
@@ -0,0 +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":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __extends } from 'tslib';
|
|
2
|
+
import { ERROR_CODE_GENERIC } from './error-code.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A custom error class that contains generic error information for Wirestate-related issues.
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
var WirestateError = /** @class */function (_super) {
|
|
11
|
+
__extends(WirestateError, _super);
|
|
12
|
+
function WirestateError(code, detail) {
|
|
13
|
+
if (code === void 0) {
|
|
14
|
+
code = ERROR_CODE_GENERIC;
|
|
15
|
+
}
|
|
16
|
+
var _this = _super.call(this) || this;
|
|
17
|
+
/**
|
|
18
|
+
* Name or error class to help differentiate error class in minified environments.
|
|
19
|
+
*/
|
|
20
|
+
_this.name = "WirestateError";
|
|
21
|
+
_this.code = code;
|
|
22
|
+
_this.message = detail || "Wirestate error.";
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
return WirestateError;
|
|
26
|
+
}(Error);
|
|
27
|
+
|
|
28
|
+
export { WirestateError };
|
|
29
|
+
//# sourceMappingURL=wirestate-error.js.map
|
|
@@ -0,0 +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;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getEventHandlerMetadata } from './get-event-handler-metadata.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Composes service event handlers into a single dispatcher.
|
|
5
|
+
*
|
|
6
|
+
* @param instance - service instance
|
|
7
|
+
* @returns event handler or null if no handlers are declared
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
function buildEventDispatcher(instance) {
|
|
11
|
+
var entries = [];
|
|
12
|
+
// Register methods decorated with @OnEvent.
|
|
13
|
+
for (var _i = 0, _a = getEventHandlerMetadata(instance); _i < _a.length; _i++) {
|
|
14
|
+
var meta = _a[_i];
|
|
15
|
+
var method = instance[meta.methodName];
|
|
16
|
+
if (typeof method === "function") {
|
|
17
|
+
entries.push({
|
|
18
|
+
types: meta.types,
|
|
19
|
+
handler: method.bind(instance)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (entries.length) {
|
|
24
|
+
return function (event) {
|
|
25
|
+
// Fan out events to all matching handlers.
|
|
26
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
27
|
+
var entry = entries_1[_i];
|
|
28
|
+
if (entry.types === null || entry.types.includes(event.type)) {
|
|
29
|
+
entry.handler(event);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { buildEventDispatcher };
|
|
39
|
+
//# sourceMappingURL=build-event-dispatcher.js.map
|
|
@@ -0,0 +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":";;AAOA;;;;;;AAMG;AACG,SAAUA,oBAAoBA,CAAmBC,QAAW,EAAA;EAGhE,IAAMC,OAAO,GAA+B,EAAE;AAE9C;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,MAAwB,CAACK,IAAI,CAACZ,QAAQ;AACjD,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;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EventBus } from './event-bus.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Emits events for container from outside scope.
|
|
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
|
|
10
|
+
*/
|
|
11
|
+
function emitEvent(container, type, payload, from) {
|
|
12
|
+
container.get(EventBus).emit({
|
|
13
|
+
type: type,
|
|
14
|
+
payload: payload,
|
|
15
|
+
from: from
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { emitEvent };
|
|
20
|
+
//# sourceMappingURL=emit-event.js.map
|
|
@@ -0,0 +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":";;AAQA;;;;;;;AAOG;AACG,SAAUA,SAASA,CAA0BC,SAAoB,EAAEC,IAAO,EAAEC,OAAW,EAAEC,IAAc,EAAA;AAG3GH,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;;;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatches events to subscribers.
|
|
3
|
+
*/
|
|
4
|
+
var EventBus = /** @class */function () {
|
|
5
|
+
function EventBus() {
|
|
6
|
+
this.handlers = new Set();
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Broadcasts an event to all subscribers.
|
|
10
|
+
*
|
|
11
|
+
* @param event - event to emit
|
|
12
|
+
*/
|
|
13
|
+
EventBus.prototype.emit = function (event) {
|
|
14
|
+
// Snapshot prevents concurrent modification errors if handlers sub/unsub during emit.
|
|
15
|
+
var snapshot = Array.from(this.handlers);
|
|
16
|
+
for (var _i = 0, snapshot_1 = snapshot; _i < snapshot_1.length; _i++) {
|
|
17
|
+
var handler = snapshot_1[_i];
|
|
18
|
+
try {
|
|
19
|
+
handler(event);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// Prevent one failing listener from stalling the entire bus.
|
|
22
|
+
console.error("[wirestate] Event handler threw:", error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Subscribes a handler to all events.
|
|
28
|
+
* Returns an unsubscribe function.
|
|
29
|
+
*
|
|
30
|
+
* @param handler - event handler function
|
|
31
|
+
* @returns unsubscribe function
|
|
32
|
+
*/
|
|
33
|
+
EventBus.prototype.subscribe = function (handler) {
|
|
34
|
+
var _this = this;
|
|
35
|
+
this.handlers.add(handler);
|
|
36
|
+
return function () {
|
|
37
|
+
_this.handlers.delete(handler);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Removes all registered handlers.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
EventBus.prototype.clear = function () {
|
|
46
|
+
this.handlers.clear();
|
|
47
|
+
};
|
|
48
|
+
return EventBus;
|
|
49
|
+
}();
|
|
50
|
+
|
|
51
|
+
export { EventBus };
|
|
52
|
+
//# sourceMappingURL=event-bus.js.map
|
|
@@ -0,0 +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,GAAuB,IAAIC,GAAG,EAAE;AAsD3D,EAAA;AApDE;;;;AAIG;AACIF,EAAAA,QAAA,CAAAG,SAAA,CAAAC,IAAI,GAAX,UAAyEC,KAAsB,EAAA;AAC7F;IACA,IAAMC,QAAQ,GAAyBC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACP,QAAQ,CAAC;AAEhE,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,OAAsB,EAAA;IAAvC,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;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EVENT_HANDLER_METADATA } from '../registry.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves `@OnEvent` 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 getEventHandlerMetadata(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 = EVENT_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 { getEventHandlerMetadata };
|
|
27
|
+
//# sourceMappingURL=get-event-handler-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-event-handler-metadata.js","sources":["../../../../../../../../src/wirestate-core/events/get-event-handler-metadata.ts"],"sourcesContent":[null],"names":["getEventHandlerMetadata","instance","constructor","chain","Object","Function","prototype","own","EVENT_HANDLER_METADATA","get","length","push","getPrototypeOf","reverse","flat"],"mappings":";;AAOA;;;;;;;AAOG;AACG,SAAUA,uBAAuBA,CAACC,QAAgB,EAAA;AAGtD,EAAA,IAAIC,WAAW,GAAYD,QAAQ,CAACC,WAAW;EAE/C,IAAMC,KAAK,GAAwC,EAAE;AAErD;AACA,EAAA,OAAO,OAAOD,WAAW,KAAK,UAAU,IAAIA,WAAW,KAAKE,MAAM,IAAIF,WAAW,KAAKG,QAAQ,CAACC,SAAS,EAAE;AACxG,IAAA,IAAMC,GAAG,GAAwCC,sBAAsB,CAACC,GAAG,CAACP,WAAqB,CAAC;AAElG,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;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __spreadArray } from 'tslib';
|
|
2
|
+
import { EVENT_HANDLER_METADATA } from '../registry.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Decorator for service methods that respond to events.
|
|
6
|
+
*
|
|
7
|
+
* @param types - event type(s) to handle. If omitted, handles all events
|
|
8
|
+
* @returns decorator function
|
|
9
|
+
*/
|
|
10
|
+
function OnEvent(types) {
|
|
11
|
+
// Normalize types to an array or null for catch-all.
|
|
12
|
+
var normalized = types === undefined ? null : Array.isArray(types) ? __spreadArray([], types, true) : [types];
|
|
13
|
+
return function (target, propertyKey) {
|
|
14
|
+
var constructor = target.constructor;
|
|
15
|
+
var list = EVENT_HANDLER_METADATA.get(constructor);
|
|
16
|
+
if (!list) {
|
|
17
|
+
list = [];
|
|
18
|
+
EVENT_HANDLER_METADATA.set(constructor, list);
|
|
19
|
+
}
|
|
20
|
+
// Register handler metadata for prototype-based retrieval.
|
|
21
|
+
list.push({
|
|
22
|
+
methodName: propertyKey,
|
|
23
|
+
types: normalized
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { OnEvent };
|
|
29
|
+
//# sourceMappingURL=on-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-event.js","sources":["../../../../../../../../src/wirestate-core/events/on-event.ts"],"sourcesContent":[null],"names":["OnEvent","types","normalized","undefined","Array","isArray","__spreadArray","target","propertyKey","constructor","list","EVENT_HANDLER_METADATA","get","set","push","methodName"],"mappings":";;;AAOA;;;;;AAKG;AACG,SAAUA,OAAOA,CAACC,KAA8C,EAAA;AACpE;EACA,IAAMC,UAAU,GACdD,KAAK,KAAKE,SAAS,GACf,IAAI,GACJC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,GACnBK,aAAA,CAAA,EAAA,EAAML,KAAmC,EAAA,IAAA,CAAA,GACxC,CAACA,KAAmB,CAAC;AAE7B,EAAA,OAAO,UAACM,MAAM,EAAEC,WAAW,EAAA;AASzB,IAAA,IAAMC,WAAW,GAAGF,MAAM,CAACE,WAAW;AAEtC,IAAA,IAAIC,IAAI,GAAwCC,sBAAsB,CAACC,GAAG,CAACH,WAAW,CAAC;IAEvF,IAAI,CAACC,IAAI,EAAE;AACTA,MAAAA,IAAI,GAAG,EAAE;AACTC,MAAAA,sBAAsB,CAACE,GAAG,CAACJ,WAAW,EAAEC,IAAI,CAAC;AAC/C,IAAA;AAEA;IACAA,IAAI,CAACI,IAAI,CAAC;AAAEC,MAAAA,UAAU,EAAEP,WAAW;AAAEP,MAAAA,KAAK,EAAEC;AAAU,KAAE,CAAC;EAC3D,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { forwardRef } from './alias.js';
|
|
2
|
+
export { bindEntry } from './bind/bind-entry.js';
|
|
3
|
+
export { bindConstant } from './bind/bind-constant.js';
|
|
4
|
+
export { bindService } from './bind/bind-service.js';
|
|
5
|
+
export { getEntryToken } from './bind/get-entry-token.js';
|
|
6
|
+
export { command } from './commands/command.js';
|
|
7
|
+
export { commandOptional } from './commands/command-optional.js';
|
|
8
|
+
export { OnCommand } from './commands/on-command.js';
|
|
9
|
+
export { CommandBus } from './commands/command-bus.js';
|
|
10
|
+
export { createIocContainer } from './container/create-ioc-container.js';
|
|
11
|
+
export { WireScope } from './container/wire-scope.js';
|
|
12
|
+
export { WirestateError } from './error/wirestate-error.js';
|
|
13
|
+
export { emitEvent } from './events/emit-event.js';
|
|
14
|
+
export { OnEvent } from './events/on-event.js';
|
|
15
|
+
export { EventBus } from './events/event-bus.js';
|
|
16
|
+
export { query } from './queries/query.js';
|
|
17
|
+
export { queryOptional } from './queries/query-optional.js';
|
|
18
|
+
export { QueryBus } from './queries/query-bus.js';
|
|
19
|
+
export { OnQuery } from './queries/on-query.js';
|
|
20
|
+
export { SEED_TOKEN as SEED, SEEDS_TOKEN as SEEDS } from './registry.js';
|
|
21
|
+
export { applySeeds } from './seeds/apply-seeds.js';
|
|
22
|
+
export { applySharedSeed } from './seeds/apply-shared-seed.js';
|
|
23
|
+
export { unapplySeeds } from './seeds/unapply-seeds.js';
|
|
24
|
+
export { OnActivated } from './service/on-activated.js';
|
|
25
|
+
export { OnDeactivation } from './service/on-deactivation.js';
|
|
26
|
+
export { ECommandStatus as CommandStatus } from './types/commands.js';
|
|
27
|
+
export { bindingTypeValues as BindingType, Container, ContainerModule, inject as Inject, injectable as Injectable, LazyServiceIdentifier, multiInject as MultiInject, named as Named, optional as Optional, postConstruct as PostConstruct, preDestroy as PreDestroy, bindingScopeValues as ScopeBindingType, tagged as Tagged } from 'inversify';
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { QUERY_HANDLER_METADATA } from '../registry.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves `@OnQuery` 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 getQueryHandlerMetadata(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 = QUERY_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 { getQueryHandlerMetadata };
|
|
27
|
+
//# sourceMappingURL=get-query-handler-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-query-handler-metadata.js","sources":["../../../../../../../../src/wirestate-core/queries/get-query-handler-metadata.ts"],"sourcesContent":[null],"names":["getQueryHandlerMetadata","instance","constructor","chain","Object","Function","prototype","own","QUERY_HANDLER_METADATA","get","length","push","getPrototypeOf","reverse","flat"],"mappings":";;AAOA;;;;;;;AAOG;AACG,SAAUA,uBAAuBA,CAACC,QAAgB,EAAA;AAGtD,EAAA,IAAIC,WAAW,GAAYD,QAAQ,CAACC,WAAW;EAE/C,IAAMC,KAAK,GAAwC,EAAE;AAErD;AACA,EAAA,OAAO,OAAOD,WAAW,KAAK,UAAU,IAAIA,WAAW,KAAKE,MAAM,IAAIF,WAAW,KAAKG,QAAQ,CAACC,SAAS,EAAE;AACxG,IAAA,IAAMC,GAAG,GAAwCC,sBAAsB,CAACC,GAAG,CAACP,WAAqB,CAAC;AAElG,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;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { QUERY_HANDLER_METADATA } from '../registry.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorator for service methods that respond to a query.
|
|
5
|
+
*
|
|
6
|
+
* @param type - query type identifier
|
|
7
|
+
* @returns decorator function
|
|
8
|
+
*/
|
|
9
|
+
function OnQuery(type) {
|
|
10
|
+
return function (target, propertyKey) {
|
|
11
|
+
var constructor = target.constructor;
|
|
12
|
+
var list = QUERY_HANDLER_METADATA.get(constructor);
|
|
13
|
+
if (!list) {
|
|
14
|
+
list = [];
|
|
15
|
+
QUERY_HANDLER_METADATA.set(constructor, list);
|
|
16
|
+
}
|
|
17
|
+
// Register handler metadata for prototype-based retrieval.
|
|
18
|
+
list.push({
|
|
19
|
+
methodName: propertyKey,
|
|
20
|
+
type: type
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { OnQuery };
|
|
26
|
+
//# sourceMappingURL=on-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-query.js","sources":["../../../../../../../../src/wirestate-core/queries/on-query.ts"],"sourcesContent":[null],"names":["OnQuery","type","target","propertyKey","constructor","list","QUERY_HANDLER_METADATA","get","set","push","methodName"],"mappings":";;AAOA;;;;;AAKG;AACG,SAAUA,OAAOA,CAACC,IAAgB,EAAA;AACtC,EAAA,OAAO,UAACC,MAAM,EAAEC,WAAW,EAAA;AASzB,IAAA,IAAMC,WAAW,GAAGF,MAAM,CAACE,WAAW;AAEtC,IAAA,IAAIC,IAAI,GAAwCC,sBAAsB,CAACC,GAAG,CAACH,WAAW,CAAC;IAEvF,IAAI,CAACC,IAAI,EAAE;AACTA,MAAAA,IAAI,GAAG,EAAE;AACTC,MAAAA,sBAAsB,CAACE,GAAG,CAACJ,WAAW,EAAEC,IAAI,CAAC;AAC/C,IAAA;AAEA;IACAA,IAAI,CAACI,IAAI,CAAC;AAAEC,MAAAA,UAAU,EAAEP,WAAW;AAAEF,MAAAA,IAAI,EAAAA;AAAA,KAAE,CAAC;EAC9C,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER } from '../error/error-code.js';
|
|
2
|
+
import { WirestateError } from '../error/wirestate-error.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Dispatches queries to handlers.
|
|
6
|
+
*/
|
|
7
|
+
var QueryBus = /** @class */function () {
|
|
8
|
+
function QueryBus() {
|
|
9
|
+
/**
|
|
10
|
+
* Internal handler storage.
|
|
11
|
+
* Uses a stack for each query type to support shadowing (e.g., component-level vs service-level).
|
|
12
|
+
*/
|
|
13
|
+
this.handlers = new Map();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers a query handler.
|
|
17
|
+
* Returns an unregister function.
|
|
18
|
+
*
|
|
19
|
+
* @param type - query type
|
|
20
|
+
* @param handler - handler function
|
|
21
|
+
* @returns unregister function
|
|
22
|
+
*/
|
|
23
|
+
QueryBus.prototype.register = function (type, handler) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
var stack = this.handlers.get(type);
|
|
26
|
+
if (!stack) {
|
|
27
|
+
stack = [];
|
|
28
|
+
this.handlers.set(type, stack);
|
|
29
|
+
}
|
|
30
|
+
stack.push(handler);
|
|
31
|
+
return function () {
|
|
32
|
+
var current = _this.handlers.get(type);
|
|
33
|
+
if (!current) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var index = current.indexOf(handler);
|
|
37
|
+
if (index >= 0) {
|
|
38
|
+
current.splice(index, 1);
|
|
39
|
+
}
|
|
40
|
+
// Clean empty stacks.
|
|
41
|
+
if (current.length === 0) {
|
|
42
|
+
_this.handlers.delete(type);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Dispatches a query to the last registered handler.
|
|
48
|
+
*
|
|
49
|
+
* @param type - query type
|
|
50
|
+
* @param data - query payload
|
|
51
|
+
* @returns query result
|
|
52
|
+
*
|
|
53
|
+
* @throws if no handler is registered
|
|
54
|
+
*/
|
|
55
|
+
QueryBus.prototype.query = function (type, data) {
|
|
56
|
+
var stack = this.handlers.get(type);
|
|
57
|
+
// Always use the top of the stack (most recent registration) if handlers are available.
|
|
58
|
+
if (stack === null || stack === void 0 ? void 0 : stack.length) {
|
|
59
|
+
return stack[stack.length - 1](data);
|
|
60
|
+
}
|
|
61
|
+
throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER, "No query handler registered in container for type: '".concat(String(type), "'."));
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Dispatches a query to the last registered handler, returning null if no handler exists.
|
|
65
|
+
*
|
|
66
|
+
* @param type - query type
|
|
67
|
+
* @param data - query payload
|
|
68
|
+
* @returns query result or null if no handler is registered
|
|
69
|
+
*/
|
|
70
|
+
QueryBus.prototype.queryOptional = function (type, data) {
|
|
71
|
+
var stack = this.handlers.get(type);
|
|
72
|
+
if (stack === null || stack === void 0 ? void 0 : stack.length) {
|
|
73
|
+
return stack[stack.length - 1](data);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a handler is registered for the given type.
|
|
79
|
+
*
|
|
80
|
+
* @param type - query type
|
|
81
|
+
* @returns true if handler exists
|
|
82
|
+
*/
|
|
83
|
+
QueryBus.prototype.has = function (type) {
|
|
84
|
+
var stack = this.handlers.get(type);
|
|
85
|
+
return Boolean(stack && stack.length);
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Removes all registered handlers.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
QueryBus.prototype.clear = function () {
|
|
93
|
+
this.handlers.clear();
|
|
94
|
+
};
|
|
95
|
+
return QueryBus;
|
|
96
|
+
}();
|
|
97
|
+
|
|
98
|
+
export { QueryBus };
|
|
99
|
+
//# sourceMappingURL=query-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-bus.js","sources":["../../../../../../../../src/wirestate-core/queries/query-bus.ts"],"sourcesContent":[null],"names":["QueryBus","handlers","Map","prototype","register","type","handler","_this","stack","get","set","push","current","index","indexOf","splice","length","delete","query","data","WirestateError","ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER","concat","String","queryOptional","has","Boolean","clear"],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { QueryBus } from './query-bus.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dispatches a query on the provided container, returning null if no handler is registered.
|
|
5
|
+
*
|
|
6
|
+
* @param container - inversify container
|
|
7
|
+
* @param type - query type
|
|
8
|
+
* @param data - query data
|
|
9
|
+
* @returns query result or null
|
|
10
|
+
*/
|
|
11
|
+
function queryOptional(container, type, data) {
|
|
12
|
+
return container.get(QueryBus).queryOptional(type, data);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { queryOptional };
|
|
16
|
+
//# sourceMappingURL=query-optional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-optional.js","sources":["../../../../../../../../src/wirestate-core/queries/query-optional.ts"],"sourcesContent":[null],"names":["queryOptional","container","type","data","get","QueryBus"],"mappings":";;AASA;;;;;;;AAOG;SACaA,aAAaA,CAC3BC,SAAoB,EACpBC,IAAgB,EAChBC,IAAQ,EAAA;AAIR,EAAA,OAAOF,SAAS,CAACG,GAAG,CAACC,QAAQ,CAAC,CAACL,aAAa,CAAOE,IAAI,EAAEC,IAAI,CAAC;AAChE;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { QueryBus } from './query-bus.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dispatches a query on the provided container.
|
|
5
|
+
*
|
|
6
|
+
* @param container - inversify container
|
|
7
|
+
* @param type - query type
|
|
8
|
+
* @param data - query data
|
|
9
|
+
* @returns query result
|
|
10
|
+
*/
|
|
11
|
+
function query(container, type, data) {
|
|
12
|
+
return container.get(QueryBus).query(type, data);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { query };
|
|
16
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sources":["../../../../../../../../src/wirestate-core/queries/query.ts"],"sourcesContent":[null],"names":["query","container","type","data","get","QueryBus"],"mappings":";;AASA;;;;;;;AAOG;SACaA,KAAKA,CAA2BC,SAAoB,EAAEC,IAAgB,EAAEC,IAAQ,EAAA;AAG9F,EAAA,OAAOF,SAAS,CAACG,GAAG,CAACC,QAAQ,CAAC,CAACL,KAAK,CAAOE,IAAI,EAAEC,IAAI,CAAC;AACxD;;;;"}
|