@wirestate/react 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 +395 -0
- package/cjs/development/index.js.map +1 -0
- package/cjs/development/lib.js +64 -0
- package/cjs/development/lib.js.map +1 -0
- package/cjs/development/test-utils.js +1075 -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/wirestate-core/bind/bind-constant.js +19 -0
- package/esm/development/wirestate-core/bind/bind-constant.js.map +1 -0
- package/esm/development/wirestate-core/bind/bind-dynamic-value.js +28 -0
- package/esm/development/wirestate-core/bind/bind-dynamic-value.js.map +1 -0
- package/esm/development/wirestate-core/bind/bind-entry.js +39 -0
- package/esm/development/wirestate-core/bind/bind-entry.js.map +1 -0
- package/esm/development/wirestate-core/bind/bind-service.js +253 -0
- package/esm/development/wirestate-core/bind/bind-service.js.map +1 -0
- package/esm/development/wirestate-core/bind/get-entry-token.js +14 -0
- package/esm/development/wirestate-core/bind/get-entry-token.js.map +1 -0
- package/esm/development/wirestate-core/commands/command-bus.js +112 -0
- package/esm/development/wirestate-core/commands/command-bus.js.map +1 -0
- package/esm/development/wirestate-core/commands/get-command-handler-metadata.js +27 -0
- package/esm/development/wirestate-core/commands/get-command-handler-metadata.js.map +1 -0
- package/esm/development/wirestate-core/container/create-ioc-container.js +35 -0
- package/esm/development/wirestate-core/container/create-ioc-container.js.map +1 -0
- package/esm/development/wirestate-core/container/wire-scope.js +151 -0
- package/esm/development/wirestate-core/container/wire-scope.js.map +1 -0
- package/esm/development/wirestate-core/error/error-code.js +10 -0
- package/esm/development/wirestate-core/error/error-code.js.map +1 -0
- package/esm/development/wirestate-core/error/wirestate-error.js +29 -0
- package/esm/development/wirestate-core/error/wirestate-error.js.map +1 -0
- package/esm/development/wirestate-core/events/build-event-dispatcher.js +39 -0
- package/esm/development/wirestate-core/events/build-event-dispatcher.js.map +1 -0
- package/esm/development/wirestate-core/events/event-bus.js +52 -0
- package/esm/development/wirestate-core/events/event-bus.js.map +1 -0
- package/esm/development/wirestate-core/events/get-event-handler-metadata.js +27 -0
- package/esm/development/wirestate-core/events/get-event-handler-metadata.js.map +1 -0
- package/esm/development/wirestate-core/queries/get-query-handler-metadata.js +27 -0
- package/esm/development/wirestate-core/queries/get-query-handler-metadata.js.map +1 -0
- package/esm/development/wirestate-core/queries/query-bus.js +99 -0
- package/esm/development/wirestate-core/queries/query-bus.js.map +1 -0
- package/esm/development/wirestate-core/registry.js +56 -0
- package/esm/development/wirestate-core/registry.js.map +1 -0
- package/esm/development/wirestate-core/service/get-activated-handler-metadata.js +27 -0
- package/esm/development/wirestate-core/service/get-activated-handler-metadata.js.map +1 -0
- package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js +27 -0
- package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js.map +1 -0
- package/esm/development/wirestate-core/test-utils/mock-bind-entry.js +24 -0
- package/esm/development/wirestate-core/test-utils/mock-bind-entry.js.map +1 -0
- package/esm/development/wirestate-core/test-utils/mock-container.js +52 -0
- package/esm/development/wirestate-core/test-utils/mock-container.js.map +1 -0
- package/esm/development/wirestate-core/types/commands.js +12 -0
- package/esm/development/wirestate-core/types/commands.js.map +1 -0
- package/esm/development/wirestate-react/commands/use-command-caller.js +18 -0
- package/esm/development/wirestate-react/commands/use-command-caller.js.map +1 -0
- package/esm/development/wirestate-react/commands/use-command-handler.js +28 -0
- package/esm/development/wirestate-react/commands/use-command-handler.js.map +1 -0
- package/esm/development/wirestate-react/commands/use-optional-command-caller.js +19 -0
- package/esm/development/wirestate-react/commands/use-optional-command-caller.js.map +1 -0
- package/esm/development/wirestate-react/error/error-code.js +6 -0
- package/esm/development/wirestate-react/error/error-code.js.map +1 -0
- package/esm/development/wirestate-react/events/use-event-emitter.js +22 -0
- package/esm/development/wirestate-react/events/use-event-emitter.js.map +1 -0
- package/esm/development/wirestate-react/events/use-event.js +30 -0
- package/esm/development/wirestate-react/events/use-event.js.map +1 -0
- package/esm/development/wirestate-react/events/use-events-handler.js +25 -0
- package/esm/development/wirestate-react/events/use-events-handler.js.map +1 -0
- package/esm/development/wirestate-react/events/use-events.js +31 -0
- package/esm/development/wirestate-react/events/use-events.js.map +1 -0
- package/esm/development/wirestate-react/index.js +19 -0
- package/esm/development/wirestate-react/index.js.map +1 -0
- package/esm/development/wirestate-react/provision/create-injectables-provider.js +101 -0
- package/esm/development/wirestate-react/provision/create-injectables-provider.js.map +1 -0
- package/esm/development/wirestate-react/provision/ioc-context.js +11 -0
- package/esm/development/wirestate-react/provision/ioc-context.js.map +1 -0
- package/esm/development/wirestate-react/provision/ioc-provider.js +50 -0
- package/esm/development/wirestate-react/provision/ioc-provider.js.map +1 -0
- package/esm/development/wirestate-react/provision/use-container-revision.js +13 -0
- package/esm/development/wirestate-react/provision/use-container-revision.js.map +1 -0
- package/esm/development/wirestate-react/provision/use-container.js +13 -0
- package/esm/development/wirestate-react/provision/use-container.js.map +1 -0
- package/esm/development/wirestate-react/provision/use-injection.js +22 -0
- package/esm/development/wirestate-react/provision/use-injection.js.map +1 -0
- package/esm/development/wirestate-react/provision/use-ioc-context.js +21 -0
- package/esm/development/wirestate-react/provision/use-ioc-context.js.map +1 -0
- package/esm/development/wirestate-react/provision/use-optional-injection.js +29 -0
- package/esm/development/wirestate-react/provision/use-optional-injection.js.map +1 -0
- package/esm/development/wirestate-react/queries/use-optional-query-caller.js +19 -0
- package/esm/development/wirestate-react/queries/use-optional-query-caller.js.map +1 -0
- package/esm/development/wirestate-react/queries/use-optional-sync-query-caller.js +19 -0
- package/esm/development/wirestate-react/queries/use-optional-sync-query-caller.js.map +1 -0
- package/esm/development/wirestate-react/queries/use-query-caller.js +18 -0
- package/esm/development/wirestate-react/queries/use-query-caller.js.map +1 -0
- package/esm/development/wirestate-react/queries/use-query-handler.js +27 -0
- package/esm/development/wirestate-react/queries/use-query-handler.js.map +1 -0
- package/esm/development/wirestate-react/queries/use-sync-query-caller.js +20 -0
- package/esm/development/wirestate-react/queries/use-sync-query-caller.js.map +1 -0
- package/esm/development/wirestate-react/test-utils/with-ioc-provider.js +30 -0
- package/esm/development/wirestate-react/test-utils/with-ioc-provider.js.map +1 -0
- package/esm/development/wirestate-react/test-utils.js +2 -0
- package/esm/development/wirestate-react/test-utils.js.map +1 -0
- package/esm/production/wirestate-core/bind/bind-constant.js +1 -0
- package/esm/production/wirestate-core/bind/bind-constant.js.map +1 -0
- package/esm/production/wirestate-core/bind/bind-dynamic-value.js +1 -0
- package/esm/production/wirestate-core/bind/bind-dynamic-value.js.map +1 -0
- package/esm/production/wirestate-core/bind/bind-entry.js +1 -0
- package/esm/production/wirestate-core/bind/bind-entry.js.map +1 -0
- package/esm/production/wirestate-core/bind/bind-service.js +1 -0
- package/esm/production/wirestate-core/bind/bind-service.js.map +1 -0
- package/esm/production/wirestate-core/bind/get-entry-token.js +1 -0
- package/esm/production/wirestate-core/bind/get-entry-token.js.map +1 -0
- package/esm/production/wirestate-core/commands/command-bus.js +1 -0
- package/esm/production/wirestate-core/commands/command-bus.js.map +1 -0
- package/esm/production/wirestate-core/commands/get-command-handler-metadata.js +1 -0
- package/esm/production/wirestate-core/commands/get-command-handler-metadata.js.map +1 -0
- package/esm/production/wirestate-core/container/create-ioc-container.js +1 -0
- package/esm/production/wirestate-core/container/create-ioc-container.js.map +1 -0
- package/esm/production/wirestate-core/container/wire-scope.js +1 -0
- package/esm/production/wirestate-core/container/wire-scope.js.map +1 -0
- package/esm/production/wirestate-core/error/error-code.js +1 -0
- package/esm/production/wirestate-core/error/error-code.js.map +1 -0
- package/esm/production/wirestate-core/error/wirestate-error.js +1 -0
- package/esm/production/wirestate-core/error/wirestate-error.js.map +1 -0
- package/esm/production/wirestate-core/events/build-event-dispatcher.js +1 -0
- package/esm/production/wirestate-core/events/build-event-dispatcher.js.map +1 -0
- package/esm/production/wirestate-core/events/event-bus.js +1 -0
- package/esm/production/wirestate-core/events/event-bus.js.map +1 -0
- package/esm/production/wirestate-core/events/get-event-handler-metadata.js +1 -0
- package/esm/production/wirestate-core/events/get-event-handler-metadata.js.map +1 -0
- package/esm/production/wirestate-core/queries/get-query-handler-metadata.js +1 -0
- package/esm/production/wirestate-core/queries/get-query-handler-metadata.js.map +1 -0
- package/esm/production/wirestate-core/queries/query-bus.js +1 -0
- package/esm/production/wirestate-core/queries/query-bus.js.map +1 -0
- package/esm/production/wirestate-core/registry.js +1 -0
- package/esm/production/wirestate-core/registry.js.map +1 -0
- package/esm/production/wirestate-core/service/get-activated-handler-metadata.js +1 -0
- package/esm/production/wirestate-core/service/get-activated-handler-metadata.js.map +1 -0
- package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js +1 -0
- package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js.map +1 -0
- package/esm/production/wirestate-core/test-utils/mock-bind-entry.js +1 -0
- package/esm/production/wirestate-core/test-utils/mock-bind-entry.js.map +1 -0
- package/esm/production/wirestate-core/test-utils/mock-container.js +1 -0
- package/esm/production/wirestate-core/test-utils/mock-container.js.map +1 -0
- package/esm/production/wirestate-core/types/commands.js +1 -0
- package/esm/production/wirestate-core/types/commands.js.map +1 -0
- package/esm/production/wirestate-react/commands/use-command-caller.js +1 -0
- package/esm/production/wirestate-react/commands/use-command-caller.js.map +1 -0
- package/esm/production/wirestate-react/commands/use-command-handler.js +1 -0
- package/esm/production/wirestate-react/commands/use-command-handler.js.map +1 -0
- package/esm/production/wirestate-react/commands/use-optional-command-caller.js +1 -0
- package/esm/production/wirestate-react/commands/use-optional-command-caller.js.map +1 -0
- package/esm/production/wirestate-react/error/error-code.js +1 -0
- package/esm/production/wirestate-react/error/error-code.js.map +1 -0
- package/esm/production/wirestate-react/events/use-event-emitter.js +1 -0
- package/esm/production/wirestate-react/events/use-event-emitter.js.map +1 -0
- package/esm/production/wirestate-react/events/use-event.js +1 -0
- package/esm/production/wirestate-react/events/use-event.js.map +1 -0
- package/esm/production/wirestate-react/events/use-events-handler.js +1 -0
- package/esm/production/wirestate-react/events/use-events-handler.js.map +1 -0
- package/esm/production/wirestate-react/events/use-events.js +1 -0
- package/esm/production/wirestate-react/events/use-events.js.map +1 -0
- package/esm/production/wirestate-react/index.js +1 -0
- package/esm/production/wirestate-react/index.js.map +1 -0
- package/esm/production/wirestate-react/provision/create-injectables-provider.js +1 -0
- package/esm/production/wirestate-react/provision/create-injectables-provider.js.map +1 -0
- package/esm/production/wirestate-react/provision/ioc-context.js +1 -0
- package/esm/production/wirestate-react/provision/ioc-context.js.map +1 -0
- package/esm/production/wirestate-react/provision/ioc-provider.js +1 -0
- package/esm/production/wirestate-react/provision/ioc-provider.js.map +1 -0
- package/esm/production/wirestate-react/provision/use-container-revision.js +1 -0
- package/esm/production/wirestate-react/provision/use-container-revision.js.map +1 -0
- package/esm/production/wirestate-react/provision/use-container.js +1 -0
- package/esm/production/wirestate-react/provision/use-container.js.map +1 -0
- package/esm/production/wirestate-react/provision/use-injection.js +1 -0
- package/esm/production/wirestate-react/provision/use-injection.js.map +1 -0
- package/esm/production/wirestate-react/provision/use-ioc-context.js +1 -0
- package/esm/production/wirestate-react/provision/use-ioc-context.js.map +1 -0
- package/esm/production/wirestate-react/provision/use-optional-injection.js +1 -0
- package/esm/production/wirestate-react/provision/use-optional-injection.js.map +1 -0
- package/esm/production/wirestate-react/queries/use-optional-query-caller.js +1 -0
- package/esm/production/wirestate-react/queries/use-optional-query-caller.js.map +1 -0
- package/esm/production/wirestate-react/queries/use-optional-sync-query-caller.js +1 -0
- package/esm/production/wirestate-react/queries/use-optional-sync-query-caller.js.map +1 -0
- package/esm/production/wirestate-react/queries/use-query-caller.js +1 -0
- package/esm/production/wirestate-react/queries/use-query-caller.js.map +1 -0
- package/esm/production/wirestate-react/queries/use-query-handler.js +1 -0
- package/esm/production/wirestate-react/queries/use-query-handler.js.map +1 -0
- package/esm/production/wirestate-react/queries/use-sync-query-caller.js +1 -0
- package/esm/production/wirestate-react/queries/use-sync-query-caller.js.map +1 -0
- package/esm/production/wirestate-react/test-utils/with-ioc-provider.js +1 -0
- package/esm/production/wirestate-react/test-utils/with-ioc-provider.js.map +1 -0
- package/esm/production/wirestate-react/test-utils.js +1 -0
- package/esm/production/wirestate-react/test-utils.js.map +1 -0
- package/index.d.ts +218 -0
- package/package.json +62 -0
- package/test-utils.d.ts +18 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER } from '../error/error-code.js';
|
|
2
|
+
import { WirestateError } from '../error/wirestate-error.js';
|
|
3
|
+
import { ECommandStatus } 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: ECommandStatus.PENDING
|
|
69
|
+
};
|
|
70
|
+
descriptor.task = Promise.resolve().then(function () {
|
|
71
|
+
return handler(data);
|
|
72
|
+
}).then(function (result) {
|
|
73
|
+
descriptor.status = ECommandStatus.SETTLED;
|
|
74
|
+
return result;
|
|
75
|
+
}).catch(function (error) {
|
|
76
|
+
descriptor.status = ECommandStatus.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
|
|
@@ -0,0 +1 @@
|
|
|
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","ECommandStatus","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,GAA8C,IAAIC,GAAG,EAA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AOkC,OAAO,CAAC,CAAAC,EAAA,GAAA,IAAI,CAACvC,QAAQ,CAACQ,GAAG,CAACJ,IAAI,CAAC,MAAA,IAAA,IAAAmC,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAExB,MAAM,CAAC;EACjD,CAAC;AAED;;AAEG;AACIhB,EAAAA,UAAA,CAAAG,SAAA,CAAAsC,KAAK,GAAZ,YAAA;AACE,IAAA,IAAI,CAACxC,QAAQ,CAACwC,KAAK,EAAE;EACvB,CAAC;AACH,EAAA,OAAAzC,UAAC;AAAD,CAAC;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-command-handler-metadata.js","sources":["../../../../../../../../../src/wirestate-core/commands/get-command-handler-metadata.ts"],"sourcesContent":[null],"names":["getCommandHandlerMetadata","instance","constructor","chain","Object","Function","prototype","own","COMMAND_HANDLER_METADATA","get","length","push","getPrototypeOf","reverse","flat"],"mappings":";;AAOA;;;;;;;AAOG;AACG,SAAUA,yBAAyBA,CAACC,QAAgB,EAAA;AAMxD,EAAA,IAAIC,WAAW,GAAYD,QAAQ,CAACC,WAAW;EAE/C,IAAMC,KAAK,GAA0C,EAAE;AAEvD;AACA,EAAA,OAAO,OAAOD,WAAW,KAAK,UAAU,IAAIA,WAAW,KAAKE,MAAM,IAAIF,WAAW,KAAKG,QAAQ,CAACC,SAAS,EAAE;AACxG,IAAA,IAAMC,GAAG,GAA0CC,wBAAwB,CAACC,GAAG,CAACP,WAAqB,CAAC;AAEtG,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,35 @@
|
|
|
1
|
+
import { Container } from 'inversify';
|
|
2
|
+
import { CommandBus } from '../commands/command-bus.js';
|
|
3
|
+
import { WireScope } from './wire-scope.js';
|
|
4
|
+
import { EventBus } from '../events/event-bus.js';
|
|
5
|
+
import { QueryBus } from '../queries/query-bus.js';
|
|
6
|
+
import { SEEDS_TOKEN, SEED_TOKEN } from '../registry.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
|
|
@@ -0,0 +1 @@
|
|
|
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":";;;;;;;AAwBA;;;;;AAKG;AACG,SAAUA,kBAAkBA,CAACC,OAAwC,EAAA;;AAAxC,EAAA,IAAAA,OAAA,KAAA,MAAA,EAAA;IAAAA,OAAA,GAAA,EAAwC;AAAA,EAAA;AAGzE,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,EAAe,CAAC;EACnEV,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;;;;"}
|
|
@@ -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":";;;;;;;;;AAoBA;;;;AAIG;AAEH,IAAAA,SAAA,gBAAA,YAAA;EAME,SAAAA,SAAAA,CAAoCC,SAA8B,EAAA;IAA9B,IAAA,CAAAA,SAAS,GAATA,SAAS;AAL7C;;AAEG;IACa,IAAA,CAAAC,UAAU,GAAY,KAAK;AAE0B,EAAA;AAErE;;;;;;;AAOG;AACIF,EAAAA,SAAA,CAAAG,SAAA,CAAAC,YAAY,GAAnB,YAAA;IACE,IAAI,IAAI,CAACH,SAAS,EAAE;MAClB,OAAO,IAAI,CAACA,SAAS;AACvB,IAAA;IAEA,IAAI,IAAI,CAACC,UAAU,EAAE;AACnB,MAAA,MAAM,IAAIG,cAAc,CACtBC,gCAAgC,EAChC,wFAAwF,CACzF;AACH,IAAA,CAAC,MAAM;MACL,MAAM,IAAID,cAAc,CACtBE,mCAAmC,EACnC,mDAAmD,GACjD,gEAAgE,CACnE;AACH,IAAA;EACF,CAAC;AAED;;;;;;;;;AASG;AACIP,EAAAA,SAAA,CAAAG,SAAA,CAAAK,OAAO,GAAd,UAAkBC,WAAiC,EAAA;IAMjD,OAAO,IAAI,CAACL,YAAY,EAAE,CAACM,GAAG,CAAID,WAAW,CAAC;EAChD,CAAC;AAED;;;;;;;;;AASG;AACIT,EAAAA,SAAA,CAAAG,SAAA,CAAAQ,eAAe,GAAtB,UAA0BF,WAAiC,EAAA;AAMzD,IAAA,IAAMR,SAAS,GAAc,IAAI,CAACG,YAAY,EAAE;AAEhD,IAAA,OAAOH,SAAS,CAACW,OAAO,CAACH,WAAW,CAAC,GAAGR,SAAS,CAACS,GAAG,CAAID,WAAW,CAAC,GAAG,IAAI;EAC9E,CAAC;AAED;;;;;;;;;AASG;EACIT,SAAA,CAA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AAC;EAC9E,CAAC;AAKD;;;;;;;;;AASG;AACIrB,EAAAA,SAAA,CAAAG,SAAA,CAAA4B,OAAO,GAAd,UAAqCC,IAAe,EAAA;AAKlD,IAAA,OAAOA,IAAI,GACN,IAAI,CAAC5B,YAAY,EAAE,CAACM,GAAG,CAAYuB,WAAW,CAAC,CAACvB,GAAG,CAACsB,IAAI,CAAO,IAAI,IAAI,GACxE,IAAI,CAAC5B,YAAY,EAAE,CAACM,GAAG,CAAIwB,UAAU,CAAC;EAC5C,CAAC;AA/LUlC,EAAAA,SAAS,GAAAmC,UAAA,CAAA,CADrBC,UAAU,EAAE,4CACA,EAAApC,SAAS,CAgMrB;AAAD,EAAA,OAAAA,SAAC;AAAA,CAjMD;;;;"}
|
|
@@ -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,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,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;;;;"}
|