@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
package/index.d.ts
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import { ServiceIdentifier, LazyServiceIdentifier, Container, Newable } from 'inversify';
|
|
2
|
+
export { bindingTypeValues as BindingType, Container, ContainerModule, inject as Inject, injectable as Injectable, LazyServiceIdentifier, multiInject as MultiInject, named as Named, Newable, optional as Optional, postConstruct as PostConstruct, preDestroy as PreDestroy, bindingScopeValues as ScopeBindingType, ServiceIdentifier, tagged as Tagged } from 'inversify';
|
|
3
|
+
import { I as IInjectableDescriptor } from './lib.js';
|
|
4
|
+
|
|
5
|
+
declare function forwardRef<TInstance = unknown>(forward: () => ServiceIdentifier<TInstance>): LazyServiceIdentifier<TInstance>;
|
|
6
|
+
|
|
7
|
+
interface IBindServiceOptions {
|
|
8
|
+
isWithIgnoreLifecycle?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Registers a service class in the container with activation/deactivation logic.
|
|
12
|
+
* Ensures container references, event subscriptions, command and query handlers are managed correctly.
|
|
13
|
+
*
|
|
14
|
+
* @param container - target Inversify container
|
|
15
|
+
* @param entry - service constructor
|
|
16
|
+
* @param options - options object to control binding flow
|
|
17
|
+
*/
|
|
18
|
+
declare function bindService<T extends object>(container: Container, entry: Newable<T>, options?: IBindServiceOptions): void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options for {@link bindEntry}.
|
|
22
|
+
*/
|
|
23
|
+
interface IBindEntryOptions extends IBindServiceOptions {
|
|
24
|
+
isWithIgnoreLifecycle?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Binds a single service entry to the container, dispatching to the
|
|
28
|
+
* correct binding strategy based on the descriptor's `type` field.
|
|
29
|
+
*
|
|
30
|
+
* Supports:
|
|
31
|
+
* - Service classes (function entries) - bound as singleton
|
|
32
|
+
* - Constant values - bound via `bindConstant`
|
|
33
|
+
* - Dynamic values - bound via `toDynamicValue` with optional scope
|
|
34
|
+
* - Instance bindings - bound as generic singleton service
|
|
35
|
+
*
|
|
36
|
+
* @param container - target IOC container to bind into
|
|
37
|
+
* @param entry - entry descriptor to bind
|
|
38
|
+
* @param options - optional binding configuration
|
|
39
|
+
* @returns void
|
|
40
|
+
*/
|
|
41
|
+
declare function bindEntry<T extends object = object>(container: Container, entry: Newable<T> | IInjectableDescriptor, options?: IBindEntryOptions): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Binds a constant value to a token in the container.
|
|
45
|
+
*
|
|
46
|
+
* @param container - target Inversify container
|
|
47
|
+
* @param entry - entry descriptor to bind
|
|
48
|
+
*/
|
|
49
|
+
declare function bindConstant<T>(container: Container, entry: IInjectableDescriptor): void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns the container token for a service entry.
|
|
53
|
+
* For plain service classes the class itself is the token;
|
|
54
|
+
* for descriptors the `id` field is used.
|
|
55
|
+
*
|
|
56
|
+
* @param entry - entry descriptor to get service identifier for
|
|
57
|
+
* @returns injectable identifier token
|
|
58
|
+
*/
|
|
59
|
+
declare function getEntryToken<T extends object = object>(entry: Newable<T> | IInjectableDescriptor): ServiceIdentifier;
|
|
60
|
+
|
|
61
|
+
type TAnyObject = Record<string, any>;
|
|
62
|
+
type Optional<T> = T | null;
|
|
63
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Command identifier. Use symbols for private commands.
|
|
67
|
+
*/
|
|
68
|
+
type TCommandType = string | symbol;
|
|
69
|
+
/**
|
|
70
|
+
* Command handler signature.
|
|
71
|
+
*/
|
|
72
|
+
type TCommandHandler<D = unknown, R = unknown> = (data: D) => MaybePromise<R>;
|
|
73
|
+
/**
|
|
74
|
+
* Command calling function signature.
|
|
75
|
+
*/
|
|
76
|
+
type TCommandCaller<R = unknown, D = unknown, T extends TCommandType = TCommandType> = (type: T, data?: D) => ICommandDescriptor<R>;
|
|
77
|
+
/**
|
|
78
|
+
* Command calling function signature.
|
|
79
|
+
*/
|
|
80
|
+
type TOptionalCommandCaller<R = unknown, D = unknown, T extends TCommandType = TCommandType> = (type: T, data?: D) => Optional<ICommandDescriptor<R>>;
|
|
81
|
+
/**
|
|
82
|
+
* Removes a command handler.
|
|
83
|
+
*/
|
|
84
|
+
type TCommandUnregister = () => void;
|
|
85
|
+
/**
|
|
86
|
+
* Command execution status.
|
|
87
|
+
*/
|
|
88
|
+
declare enum ECommandStatus {
|
|
89
|
+
PENDING = "pending",
|
|
90
|
+
SETTLED = "settled",
|
|
91
|
+
ERROR = "error"
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Descriptor returned by command execution.
|
|
95
|
+
* Contains the task promise, current status, and responder with result/error.
|
|
96
|
+
*/
|
|
97
|
+
interface ICommandDescriptor<R = unknown> {
|
|
98
|
+
readonly task: Promise<R>;
|
|
99
|
+
readonly status: ECommandStatus;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Dispatches a command on the provided container.
|
|
104
|
+
*
|
|
105
|
+
* @param container - inversify container
|
|
106
|
+
* @param type - command type
|
|
107
|
+
* @param data - command data
|
|
108
|
+
* @returns command descriptor
|
|
109
|
+
*/
|
|
110
|
+
declare function command<R = unknown, D = unknown, T extends TCommandType = TCommandType>(container: Container, type: T, data?: D): ICommandDescriptor<R>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Dispatches a command on the provided container, returning null if no handler is registered.
|
|
114
|
+
*
|
|
115
|
+
* @param container - inversify container
|
|
116
|
+
* @param type - command type
|
|
117
|
+
* @param data - command data
|
|
118
|
+
* @returns command descriptor or null
|
|
119
|
+
*/
|
|
120
|
+
declare function commandOptional<R = unknown, D = unknown, T extends TCommandType = TCommandType>(container: Container, type: T, data?: D): Optional<ICommandDescriptor<R>>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Decorator for service methods that handle a command.
|
|
124
|
+
*
|
|
125
|
+
* @param type - command type identifier
|
|
126
|
+
* @returns decorator function
|
|
127
|
+
*/
|
|
128
|
+
declare function OnCommand(type: TCommandType): MethodDecorator;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Dispatches commands to handlers.
|
|
132
|
+
*
|
|
133
|
+
* Unlike queries, command execution always wraps the handler in a promise
|
|
134
|
+
* and returns a descriptor with task, status, and responder.
|
|
135
|
+
*/
|
|
136
|
+
declare class CommandBus {
|
|
137
|
+
/**
|
|
138
|
+
* Internal handler storage.
|
|
139
|
+
* Uses a stack for each command type to support shadowing.
|
|
140
|
+
*/
|
|
141
|
+
private readonly handlers;
|
|
142
|
+
/**
|
|
143
|
+
* Registers a command handler.
|
|
144
|
+
* Returns an unregister function.
|
|
145
|
+
*
|
|
146
|
+
* @param type - command type
|
|
147
|
+
* @param handler - handler function
|
|
148
|
+
* @returns unregister function
|
|
149
|
+
*/
|
|
150
|
+
register<D = unknown, R = unknown>(type: TCommandType, handler: TCommandHandler<D, R>): TCommandUnregister;
|
|
151
|
+
/**
|
|
152
|
+
* Dispatches a command to the last registered handler.
|
|
153
|
+
* Wraps the handler execution in a promise and returns a descriptor.
|
|
154
|
+
*
|
|
155
|
+
* @param type - command type
|
|
156
|
+
* @param data - command payload
|
|
157
|
+
* @returns command descriptor with task, status, and responder
|
|
158
|
+
*
|
|
159
|
+
* @throws if no handler is registered
|
|
160
|
+
*/
|
|
161
|
+
command<R = unknown, D = unknown>(type: TCommandType, data?: D): ICommandDescriptor<R>;
|
|
162
|
+
/**
|
|
163
|
+
* Dispatches a command to the last registered handler, returning null if no handler exists.
|
|
164
|
+
*
|
|
165
|
+
* @param type - command type
|
|
166
|
+
* @param data - command payload
|
|
167
|
+
* @returns command descriptor or null if no handler is registered
|
|
168
|
+
*/
|
|
169
|
+
commandOptional<R = unknown, D = unknown>(type: TCommandType, data?: D): Optional<ICommandDescriptor<R>>;
|
|
170
|
+
/**
|
|
171
|
+
* Checks if a handler is registered for the given type.
|
|
172
|
+
*
|
|
173
|
+
* @param type - command type
|
|
174
|
+
* @returns true if handler exists
|
|
175
|
+
*/
|
|
176
|
+
has(type: TCommandType): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Removes all registered handlers.
|
|
179
|
+
*/
|
|
180
|
+
clear(): void;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface ICreateIocContainerOptions {
|
|
184
|
+
/**
|
|
185
|
+
* Parent container for inheritance.
|
|
186
|
+
*/
|
|
187
|
+
readonly parent?: Container;
|
|
188
|
+
/**
|
|
189
|
+
* Optional default seed value.
|
|
190
|
+
*/
|
|
191
|
+
readonly seed?: TAnyObject;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Creates an IoC container with framework essentials.
|
|
195
|
+
*
|
|
196
|
+
* @param options - container configuration
|
|
197
|
+
* @returns new IoC container
|
|
198
|
+
*/
|
|
199
|
+
declare function createIocContainer(options?: ICreateIocContainerOptions): Container;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Event identifier.
|
|
203
|
+
*/
|
|
204
|
+
type TEventType = string | symbol;
|
|
205
|
+
/**
|
|
206
|
+
* Event object.
|
|
207
|
+
*/
|
|
208
|
+
interface IEvent<P = unknown, T extends TEventType = TEventType, F = unknown> {
|
|
209
|
+
readonly type: T;
|
|
210
|
+
readonly payload?: P;
|
|
211
|
+
readonly from?: F;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Event handler signature.
|
|
215
|
+
*/
|
|
216
|
+
type TEventHandler<E extends IEvent = IEvent> = (event: E) => void;
|
|
217
|
+
/**
|
|
218
|
+
* Unsubscribes from events, part of events subscription lifecycle.
|
|
219
|
+
*/
|
|
220
|
+
type TEventUnsubscriber = () => void;
|
|
221
|
+
/**
|
|
222
|
+
* Event emitter signature.
|
|
223
|
+
*/
|
|
224
|
+
type TEventEmitter<P = unknown, T extends TEventType = TEventType, F = unknown> = (type: T, payload?: P, from?: F) => void;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Lookup key for service seeds.
|
|
228
|
+
*/
|
|
229
|
+
type TSeedKey = Newable | string | symbol;
|
|
230
|
+
/**
|
|
231
|
+
* Service-to-seed mapping entry.
|
|
232
|
+
*/
|
|
233
|
+
type TSeedEntry<T = unknown> = readonly [TSeedKey, T];
|
|
234
|
+
/**
|
|
235
|
+
* Collection of seed entries.
|
|
236
|
+
*/
|
|
237
|
+
type TSeedEntries = ReadonlyArray<TSeedEntry>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Query identifier. Use symbols for private queries.
|
|
241
|
+
*/
|
|
242
|
+
type TQueryType = string | symbol;
|
|
243
|
+
/**
|
|
244
|
+
* Query handler signature.
|
|
245
|
+
*/
|
|
246
|
+
type TQueryHandler<D = unknown, R = unknown> = (data: D) => MaybePromise<R>;
|
|
247
|
+
/**
|
|
248
|
+
* Removes a query handler.
|
|
249
|
+
*/
|
|
250
|
+
type TQueryUnregister = () => void;
|
|
251
|
+
/**
|
|
252
|
+
* Public query responder signature.
|
|
253
|
+
*/
|
|
254
|
+
type TQueryResponder<R = unknown, D = unknown> = (data?: D) => MaybePromise<R>;
|
|
255
|
+
/**
|
|
256
|
+
* Dispatches queries and returns their result as a value or promise.
|
|
257
|
+
*/
|
|
258
|
+
type TQueryCaller = <R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D) => MaybePromise<R>;
|
|
259
|
+
/**
|
|
260
|
+
* Dispatches synchronous queries and returns their result directly.
|
|
261
|
+
*/
|
|
262
|
+
type TSyncQueryCaller = <R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D) => R;
|
|
263
|
+
/**
|
|
264
|
+
* Dispatches optional queries. Returns null when no handler is registered.
|
|
265
|
+
*/
|
|
266
|
+
type TOptionalQueryCaller = <R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D) => Optional<MaybePromise<R>>;
|
|
267
|
+
/**
|
|
268
|
+
* Dispatches optional synchronous queries. Returns null when no handler is registered.
|
|
269
|
+
*/
|
|
270
|
+
type TOptionalSyncQueryCaller = <R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D) => Optional<R>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Injectable scope providing access to wirestate buses and seeds.
|
|
274
|
+
* Each injecting service receives its own instance (transient scope).
|
|
275
|
+
* The scope is activated and deactivated automatically alongside its owner service.
|
|
276
|
+
*/
|
|
277
|
+
declare class WireScope {
|
|
278
|
+
private readonly container;
|
|
279
|
+
/**
|
|
280
|
+
* Whether the scope was deactivated and disposed from the container.
|
|
281
|
+
*/
|
|
282
|
+
readonly isDisposed: boolean;
|
|
283
|
+
constructor(container: Optional<Container>);
|
|
284
|
+
/**
|
|
285
|
+
* Access the IoC container.
|
|
286
|
+
* Available only for activated instances of scope.
|
|
287
|
+
*
|
|
288
|
+
* @returns active container
|
|
289
|
+
*
|
|
290
|
+
* @throws WirestateError if scope is not activated or already disposed
|
|
291
|
+
*/
|
|
292
|
+
getContainer(): Container;
|
|
293
|
+
/**
|
|
294
|
+
* Resolves a sibling service or injected value.
|
|
295
|
+
* Use for lazy resolution or circular dependency breaking.
|
|
296
|
+
* Available only for activated containers.
|
|
297
|
+
*
|
|
298
|
+
* @param injectionId - injection identifier
|
|
299
|
+
* @returns resolved injection, service instance, or generic value
|
|
300
|
+
*
|
|
301
|
+
* @throws WirestateError if scope is not activated
|
|
302
|
+
*/
|
|
303
|
+
resolve<T>(injectionId: ServiceIdentifier<T>): T;
|
|
304
|
+
/**
|
|
305
|
+
* Resolves a sibling service or injected value.
|
|
306
|
+
* Use for lazy resolution or circular dependency breaking.
|
|
307
|
+
* Available only for activated containers.
|
|
308
|
+
*
|
|
309
|
+
* @param injectionId - injection identifier
|
|
310
|
+
* @returns resolved injection, service instance, generic value, or null if it is not bound
|
|
311
|
+
*
|
|
312
|
+
* @throws WirestateError if scope is not activated
|
|
313
|
+
*/
|
|
314
|
+
resolveOptional<T>(injectionId: ServiceIdentifier<T>): Optional<T>;
|
|
315
|
+
/**
|
|
316
|
+
* Broadcasts an event.
|
|
317
|
+
* Available only for activated containers.
|
|
318
|
+
*
|
|
319
|
+
* @param type - type of event to emit
|
|
320
|
+
* @param payload - optional payload to send with the event
|
|
321
|
+
* @param from - optional sender of the event
|
|
322
|
+
*
|
|
323
|
+
* @throws WirestateError if scope is not activated
|
|
324
|
+
*/
|
|
325
|
+
emitEvent<P, T extends TEventType = TEventType>(type: T, payload?: P, from?: unknown): void;
|
|
326
|
+
/**
|
|
327
|
+
* Dispatches a query and returns the result.
|
|
328
|
+
* Available only for activated containers.
|
|
329
|
+
*
|
|
330
|
+
* @param type - query type
|
|
331
|
+
* @param data - query data
|
|
332
|
+
* @returns query result
|
|
333
|
+
*
|
|
334
|
+
* @throws WirestateError if scope is not activated
|
|
335
|
+
*/
|
|
336
|
+
queryData<R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D): MaybePromise<R>;
|
|
337
|
+
/**
|
|
338
|
+
* Dispatches a query and returns the result.
|
|
339
|
+
* Available only for activated containers.
|
|
340
|
+
*
|
|
341
|
+
* @param type - query type
|
|
342
|
+
* @param data - query data
|
|
343
|
+
* @returns query result or null if handler is not registered
|
|
344
|
+
*/
|
|
345
|
+
queryOptionalData<R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D): Optional<MaybePromise<R>>;
|
|
346
|
+
/**
|
|
347
|
+
* Dispatches a command and returns the descriptor.
|
|
348
|
+
* Available only for activated containers.
|
|
349
|
+
*
|
|
350
|
+
* @param type - command type
|
|
351
|
+
* @param data - command data
|
|
352
|
+
* @returns command descriptor
|
|
353
|
+
*
|
|
354
|
+
* @throws WirestateError if scope is not activated
|
|
355
|
+
*/
|
|
356
|
+
executeCommand<R = unknown, D = unknown, T extends TCommandType = TCommandType>(type: T, data?: D): ICommandDescriptor<R>;
|
|
357
|
+
/**
|
|
358
|
+
* Dispatches a command and returns the descriptor.
|
|
359
|
+
* Available only for activated containers.
|
|
360
|
+
*
|
|
361
|
+
* @param type - command type
|
|
362
|
+
* @param data - command data
|
|
363
|
+
* @returns command descriptor or null if handler is not registered
|
|
364
|
+
*/
|
|
365
|
+
executeOptionalCommand<R = unknown, D = unknown, T extends TCommandType = TCommandType>(type: T, data?: D): Optional<ICommandDescriptor<R>>;
|
|
366
|
+
getSeed<T>(): T;
|
|
367
|
+
getSeed<T>(seed?: TSeedKey): Optional<T>;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* A custom error class that contains generic error information for Wirestate-related issues.
|
|
372
|
+
*
|
|
373
|
+
* This class extends the native `Error` class and is used to represent errors specific
|
|
374
|
+
* to the Wirestate library, providing more structured error handling.
|
|
375
|
+
*/
|
|
376
|
+
declare class WirestateError extends Error {
|
|
377
|
+
/**
|
|
378
|
+
* Name or error class to help differentiate error class in minified environments.
|
|
379
|
+
*/
|
|
380
|
+
readonly name: string;
|
|
381
|
+
/**
|
|
382
|
+
* Error code describing the issue.
|
|
383
|
+
*/
|
|
384
|
+
readonly code: number;
|
|
385
|
+
/**
|
|
386
|
+
* Error message describing the issue.
|
|
387
|
+
*/
|
|
388
|
+
readonly message: string;
|
|
389
|
+
constructor(code?: number, detail?: string);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Emits events for container from outside scope.
|
|
394
|
+
*
|
|
395
|
+
* @param container - inversify container
|
|
396
|
+
* @param type - event type ot emit
|
|
397
|
+
* @param payload - event payload
|
|
398
|
+
* @param from - optional indicator of the event source
|
|
399
|
+
*/
|
|
400
|
+
declare function emitEvent<P, T extends TEventType>(container: Container, type: T, payload?: P, from?: unknown): void;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Decorator for service methods that respond to events.
|
|
404
|
+
*
|
|
405
|
+
* @param types - event type(s) to handle. If omitted, handles all events
|
|
406
|
+
* @returns decorator function
|
|
407
|
+
*/
|
|
408
|
+
declare function OnEvent(types?: TEventType | ReadonlyArray<TEventType>): MethodDecorator;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Dispatches events to subscribers.
|
|
412
|
+
*/
|
|
413
|
+
declare class EventBus {
|
|
414
|
+
private readonly handlers;
|
|
415
|
+
/**
|
|
416
|
+
* Broadcasts an event to all subscribers.
|
|
417
|
+
*
|
|
418
|
+
* @param event - event to emit
|
|
419
|
+
*/
|
|
420
|
+
emit<P = unknown, T extends TEventType = TEventType, F = unknown>(event: IEvent<P, T, F>): void;
|
|
421
|
+
/**
|
|
422
|
+
* Subscribes a handler to all events.
|
|
423
|
+
* Returns an unsubscribe function.
|
|
424
|
+
*
|
|
425
|
+
* @param handler - event handler function
|
|
426
|
+
* @returns unsubscribe function
|
|
427
|
+
*/
|
|
428
|
+
subscribe(handler: TEventHandler): TEventUnsubscriber;
|
|
429
|
+
/**
|
|
430
|
+
* Removes all registered handlers.
|
|
431
|
+
*
|
|
432
|
+
* @internal
|
|
433
|
+
*/
|
|
434
|
+
clear(): void;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Dispatches a query on the provided container.
|
|
439
|
+
*
|
|
440
|
+
* @param container - inversify container
|
|
441
|
+
* @param type - query type
|
|
442
|
+
* @param data - query data
|
|
443
|
+
* @returns query result
|
|
444
|
+
*/
|
|
445
|
+
declare function query<R = unknown, D = unknown>(container: Container, type: TQueryType, data?: D): MaybePromise<R>;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Dispatches a query on the provided container, returning null if no handler is registered.
|
|
449
|
+
*
|
|
450
|
+
* @param container - inversify container
|
|
451
|
+
* @param type - query type
|
|
452
|
+
* @param data - query data
|
|
453
|
+
* @returns query result or null
|
|
454
|
+
*/
|
|
455
|
+
declare function queryOptional<R = unknown, D = unknown>(container: Container, type: TQueryType, data?: D): Optional<MaybePromise<R>>;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Dispatches queries to handlers.
|
|
459
|
+
*/
|
|
460
|
+
declare class QueryBus {
|
|
461
|
+
/**
|
|
462
|
+
* Internal handler storage.
|
|
463
|
+
* Uses a stack for each query type to support shadowing (e.g., component-level vs service-level).
|
|
464
|
+
*/
|
|
465
|
+
private readonly handlers;
|
|
466
|
+
/**
|
|
467
|
+
* Registers a query handler.
|
|
468
|
+
* Returns an unregister function.
|
|
469
|
+
*
|
|
470
|
+
* @param type - query type
|
|
471
|
+
* @param handler - handler function
|
|
472
|
+
* @returns unregister function
|
|
473
|
+
*/
|
|
474
|
+
register<D = unknown, R = unknown>(type: TQueryType, handler: TQueryHandler<D, R>): TQueryUnregister;
|
|
475
|
+
/**
|
|
476
|
+
* Dispatches a query to the last registered handler.
|
|
477
|
+
*
|
|
478
|
+
* @param type - query type
|
|
479
|
+
* @param data - query payload
|
|
480
|
+
* @returns query result
|
|
481
|
+
*
|
|
482
|
+
* @throws if no handler is registered
|
|
483
|
+
*/
|
|
484
|
+
query<R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D): MaybePromise<R>;
|
|
485
|
+
/**
|
|
486
|
+
* Dispatches a query to the last registered handler, returning null if no handler exists.
|
|
487
|
+
*
|
|
488
|
+
* @param type - query type
|
|
489
|
+
* @param data - query payload
|
|
490
|
+
* @returns query result or null if no handler is registered
|
|
491
|
+
*/
|
|
492
|
+
queryOptional<R = unknown, D = unknown, T extends TQueryType = TQueryType>(type: T, data?: D): Optional<MaybePromise<R>>;
|
|
493
|
+
/**
|
|
494
|
+
* Checks if a handler is registered for the given type.
|
|
495
|
+
*
|
|
496
|
+
* @param type - query type
|
|
497
|
+
* @returns true if handler exists
|
|
498
|
+
*/
|
|
499
|
+
has(type: TQueryType): boolean;
|
|
500
|
+
/**
|
|
501
|
+
* Removes all registered handlers.
|
|
502
|
+
*
|
|
503
|
+
* @internal
|
|
504
|
+
*/
|
|
505
|
+
clear(): void;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Decorator for service methods that respond to a query.
|
|
510
|
+
*
|
|
511
|
+
* @param type - query type identifier
|
|
512
|
+
* @returns decorator function
|
|
513
|
+
*/
|
|
514
|
+
declare function OnQuery(type: TQueryType): MethodDecorator;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Token for the container-scoped seeds map.
|
|
518
|
+
*/
|
|
519
|
+
declare const SEEDS_TOKEN: unique symbol;
|
|
520
|
+
/**
|
|
521
|
+
* Token for the container-scoped shared seed object.
|
|
522
|
+
*/
|
|
523
|
+
declare const SEED_TOKEN: unique symbol;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Applies seeds to the container into the existing instance instead of replacing it.
|
|
527
|
+
* This allows multiple providers to co-exist without wiping each other's seeds.
|
|
528
|
+
*
|
|
529
|
+
* @param container - target container
|
|
530
|
+
* @param seeds - targeted seed entries apply
|
|
531
|
+
*/
|
|
532
|
+
declare function applySeeds(container: Container, seeds: TSeedEntries): void;
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Applies shared seed to the container.
|
|
536
|
+
*
|
|
537
|
+
* @param container - target container
|
|
538
|
+
* @param seed - shared seed object
|
|
539
|
+
*/
|
|
540
|
+
declare function applySharedSeed(container: Container, seed: TAnyObject): void;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Removes specific seeds from the container.
|
|
544
|
+
* Used during provider unmounting to clean up only the entries owned by that provider.
|
|
545
|
+
*
|
|
546
|
+
* @param container - target container
|
|
547
|
+
* @param seeds - targeted seeds to remove
|
|
548
|
+
*/
|
|
549
|
+
declare function unapplySeeds(container: Container, seeds: TSeedEntries): void;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Decorator for service methods that run after activation.
|
|
553
|
+
*
|
|
554
|
+
* @returns decorator function
|
|
555
|
+
*/
|
|
556
|
+
declare function OnActivated(): MethodDecorator;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Decorator for service methods that run before deactivation.
|
|
560
|
+
*
|
|
561
|
+
* @returns decorator function
|
|
562
|
+
*/
|
|
563
|
+
declare function OnDeactivation(): MethodDecorator;
|
|
564
|
+
|
|
565
|
+
export { CommandBus, ECommandStatus as CommandStatus, EventBus, IInjectableDescriptor as InjectableDescriptor, OnActivated, OnCommand, OnDeactivation, OnEvent, OnQuery, QueryBus, SEED_TOKEN as SEED, SEEDS_TOKEN as SEEDS, WireScope, WirestateError, applySeeds, applySharedSeed, bindConstant, bindEntry, bindService, command, commandOptional, createIocContainer, emitEvent, forwardRef, getEntryToken, query, queryOptional, unapplySeeds };
|
|
566
|
+
export type { TCommandCaller as CommandCaller, ICommandDescriptor as CommandDescriptor, TCommandHandler as CommandHandler, TCommandType as CommandType, TCommandUnregister as CommandUnregister, IEvent as Event, TEventEmitter as EventEmitter, TEventHandler as EventHandler, TEventType as EventType, TEventUnsubscriber as EventUnsubscriber, TOptionalCommandCaller as OptionalCommandCaller, TOptionalQueryCaller as OptionalQueryCaller, TOptionalSyncQueryCaller as OptionalSyncQueryCaller, TQueryCaller as QueryCaller, TQueryHandler as QueryHandler, TQueryResponder as QueryResponder, TQueryType as QueryType, TQueryUnregister as QueryUnregister, TSeedEntries as SeedEntries, TSeedEntry as SeedEntry, TSeedKey as SeedKey, TSyncQueryCaller as SyncQueryCaller };
|
package/lib.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ServiceIdentifier, bindingTypeValues, bindingScopeValues } from 'inversify';
|
|
2
|
+
|
|
3
|
+
type TBindingType = (typeof bindingTypeValues)[keyof typeof bindingTypeValues];
|
|
4
|
+
type TScopeBindingType = (typeof bindingScopeValues)[keyof typeof bindingScopeValues];
|
|
5
|
+
interface IInjectableDescriptor<T = unknown, V = unknown> {
|
|
6
|
+
id: ServiceIdentifier<T>;
|
|
7
|
+
value?: V;
|
|
8
|
+
bindingType?: TBindingType;
|
|
9
|
+
scopeBindingType?: TScopeBindingType;
|
|
10
|
+
/**
|
|
11
|
+
* Factory function for dynamic value bindings.
|
|
12
|
+
* Used when type is set to DynamicValue.
|
|
13
|
+
*/
|
|
14
|
+
factory?: () => T;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { IInjectableDescriptor as I };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wirestate/core",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Store management library core based on inversify",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"author": "Syrotenko Igor",
|
|
7
|
+
"homepage": "https://github.com/neloreck/wirestate#readme",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"main": "./cjs/development/index.js",
|
|
10
|
+
"module": "./esm/development/index.js",
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"import": {
|
|
16
|
+
"production": "./esm/production/index.js",
|
|
17
|
+
"default": "./esm/development/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"production": "./cjs/production/index.js",
|
|
21
|
+
"default": "./cjs/development/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"./test-utils": {
|
|
25
|
+
"types": "./test-utils.d.ts",
|
|
26
|
+
"require": {
|
|
27
|
+
"production": "./cjs/production/test-utils.js",
|
|
28
|
+
"default": "./cjs/development/test-utils.js"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/neloreck/wirestate.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/neloreck/wirestate/issues"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"class-based",
|
|
41
|
+
"context",
|
|
42
|
+
"declarative",
|
|
43
|
+
"management",
|
|
44
|
+
"manager",
|
|
45
|
+
"inversify",
|
|
46
|
+
"ioc",
|
|
47
|
+
"di",
|
|
48
|
+
"dependency-injection",
|
|
49
|
+
"state",
|
|
50
|
+
"store",
|
|
51
|
+
"typescript"
|
|
52
|
+
],
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"inversify": "^8.1.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"reflect-metadata": ">=0.2.0",
|
|
58
|
+
"tslib": ">=2.5.0"
|
|
59
|
+
},
|
|
60
|
+
"optionalDependencies": {}
|
|
61
|
+
}
|