@context-action/core 0.0.4 → 0.1.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/dist/index.cjs +675 -492
- package/dist/index.d.cts +147 -589
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +147 -589
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +675 -493
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,670 +1,228 @@
|
|
|
1
|
-
import { LogLevel, Logger } from "@context-action/logger";
|
|
2
|
-
|
|
3
1
|
//#region src/types.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Base interface for defining action payload mappings
|
|
7
|
-
* @implements action-payload-map
|
|
8
|
-
* @implements type-safety
|
|
9
|
-
* @implements compile-time-validation
|
|
10
|
-
* @memberof core-concepts
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
*
|
|
13
|
-
* Maps action names to their corresponding payload types for type-safe dispatch
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* interface MyActions extends ActionPayloadMap {
|
|
18
|
-
* increment: void;
|
|
19
|
-
* setCount: number;
|
|
20
|
-
* updateUser: { id: string; name: string };
|
|
21
|
-
* deleteUser: { id: string };
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
2
|
interface ActionPayloadMap {
|
|
26
3
|
[actionName: string]: unknown;
|
|
27
4
|
}
|
|
28
|
-
|
|
29
|
-
* Controller object provided to action handlers for pipeline management
|
|
30
|
-
* @implements pipeline-controller
|
|
31
|
-
* @memberof core-concepts
|
|
32
|
-
* @since 1.0.0
|
|
33
|
-
*
|
|
34
|
-
* Provides methods for controlling pipeline flow and payload modification
|
|
35
|
-
*
|
|
36
|
-
* @template T - The type of the payload being processed
|
|
37
|
-
*/
|
|
38
|
-
interface PipelineController<T = any> {
|
|
39
|
-
/** Continue to the next handler in the pipeline */
|
|
5
|
+
interface PipelineController<T = any, R = void> {
|
|
40
6
|
next(): void;
|
|
41
|
-
/** Abort the pipeline execution with an optional reason */
|
|
42
7
|
abort(reason?: string): void;
|
|
43
|
-
/** Modify the payload that will be passed to subsequent handlers */
|
|
44
8
|
modifyPayload(modifier: (payload: T) => T): void;
|
|
45
|
-
/** Get the current payload */
|
|
46
9
|
getPayload(): T;
|
|
47
|
-
/** Jump to a specific priority level in the pipeline */
|
|
48
10
|
jumpToPriority(priority: number): void;
|
|
11
|
+
return(result: R): void;
|
|
12
|
+
setResult(result: R): void;
|
|
13
|
+
getResults(): R[];
|
|
14
|
+
mergeResult(merger: (previousResults: R[], currentResult: R) => R): void;
|
|
49
15
|
}
|
|
50
|
-
|
|
51
|
-
* Action handler function type for processing actions in the pipeline
|
|
52
|
-
* @implements action-handler
|
|
53
|
-
* @memberof core-concepts
|
|
54
|
-
* @since 1.0.0
|
|
55
|
-
*
|
|
56
|
-
* Function signature for handlers that process specific actions within the pipeline.
|
|
57
|
-
* Handlers receive the action payload and a controller for managing pipeline flow.
|
|
58
|
-
*
|
|
59
|
-
* @template T - The type of the payload this handler processes
|
|
60
|
-
* @param payload - The action payload data
|
|
61
|
-
* @param controller - Pipeline controller for flow management
|
|
62
|
-
* @returns void or Promise<void> for async operations
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const userUpdateHandler: ActionHandler<{id: string, name: string}> =
|
|
67
|
-
* async (payload, controller) => {
|
|
68
|
-
* // Validate payload
|
|
69
|
-
* if (!payload.id) {
|
|
70
|
-
* controller.abort('User ID is required');
|
|
71
|
-
* return;
|
|
72
|
-
* }
|
|
73
|
-
*
|
|
74
|
-
* // Update user store
|
|
75
|
-
* const user = userStore.getValue();
|
|
76
|
-
* userStore.setValue({ ...user, ...payload });
|
|
77
|
-
* };
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
type ActionHandler<T = any> = (payload: T, controller: PipelineController<T>) => void | Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Configuration options for action handlers
|
|
83
|
-
* @implements handler-configuration
|
|
84
|
-
* @memberof core-concepts
|
|
85
|
-
* @since 1.0.0
|
|
86
|
-
*
|
|
87
|
-
* Defines behavior and execution characteristics for action handlers in the pipeline.
|
|
88
|
-
* Supports priority-based execution, conditional execution, and performance optimizations.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const config: HandlerConfig = {
|
|
93
|
-
* priority: 10, // Higher priority runs first
|
|
94
|
-
* id: 'userValidator', // Unique identifier
|
|
95
|
-
* blocking: true, // Wait for async completion
|
|
96
|
-
* once: false, // Run multiple times
|
|
97
|
-
* condition: () => isLoggedIn(), // Conditional execution
|
|
98
|
-
* debounce: 500, // Debounce delay in ms
|
|
99
|
-
* throttle: 1000, // Throttle interval in ms
|
|
100
|
-
* validation: (payload) => payload?.id != null
|
|
101
|
-
* };
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
16
|
+
type ActionHandler<T = any, R = void> = (payload: T, controller: PipelineController<T, R>) => R | Promise<R>;
|
|
104
17
|
interface HandlerConfig {
|
|
105
|
-
/** Priority level (higher numbers execute first). Default: 0 */
|
|
106
18
|
priority?: number;
|
|
107
|
-
/** Unique identifier for the handler. Auto-generated if not provided */
|
|
108
19
|
id?: string;
|
|
109
|
-
/** Whether to wait for async handlers to complete. Default: false */
|
|
110
20
|
blocking?: boolean;
|
|
111
|
-
/** Whether this handler should run once and then be removed. Default: false */
|
|
112
21
|
once?: boolean;
|
|
113
|
-
/** Condition function to determine if handler should run */
|
|
114
22
|
condition?: () => boolean;
|
|
115
|
-
/** Debounce delay in milliseconds */
|
|
116
23
|
debounce?: number;
|
|
117
|
-
/** Throttle delay in milliseconds */
|
|
118
24
|
throttle?: number;
|
|
119
|
-
/** Validation function that must return true for handler to execute */
|
|
120
25
|
validation?: (payload: any) => boolean;
|
|
121
|
-
/** Mark this handler as middleware */
|
|
122
26
|
middleware?: boolean;
|
|
27
|
+
tags?: string[];
|
|
28
|
+
category?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
returnType?: 'value' | 'merge' | 'collect';
|
|
32
|
+
timeout?: number;
|
|
33
|
+
retries?: number;
|
|
34
|
+
dependencies?: string[];
|
|
35
|
+
conflicts?: string[];
|
|
36
|
+
environment?: 'development' | 'production' | 'test';
|
|
37
|
+
feature?: string;
|
|
38
|
+
metrics?: {
|
|
39
|
+
collectTiming?: boolean;
|
|
40
|
+
collectErrors?: boolean;
|
|
41
|
+
customMetrics?: Record<string, any>;
|
|
42
|
+
};
|
|
43
|
+
metadata?: Record<string, any>;
|
|
123
44
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
* @internal
|
|
127
|
-
*/
|
|
128
|
-
interface HandlerRegistration<T = any> {
|
|
129
|
-
handler: ActionHandler<T>;
|
|
45
|
+
interface HandlerRegistration<T = any, R = void> {
|
|
46
|
+
handler: ActionHandler<T, R>;
|
|
130
47
|
config: Required<HandlerConfig>;
|
|
131
48
|
id: string;
|
|
132
49
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Execution modes for action pipeline
|
|
135
|
-
* @implements execution-mode
|
|
136
|
-
* @memberof core-concepts
|
|
137
|
-
* @since 1.0.0
|
|
138
|
-
*
|
|
139
|
-
* Defines how handlers are executed within the action pipeline.
|
|
140
|
-
* Each mode provides different execution strategies for various use cases.
|
|
141
|
-
*
|
|
142
|
-
* - `sequential`: Execute handlers one after another (default)
|
|
143
|
-
* - `parallel`: Execute all handlers simultaneously
|
|
144
|
-
* - `race`: Execute handlers simultaneously, use first completed result
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```typescript
|
|
148
|
-
* const register = new ActionRegister({
|
|
149
|
-
* defaultExecutionMode: 'parallel'
|
|
150
|
-
* });
|
|
151
|
-
*
|
|
152
|
-
* // Or set per action
|
|
153
|
-
* register.setExecutionMode('validateUser', 'sequential');
|
|
154
|
-
* register.setExecutionMode('fetchData', 'race');
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
50
|
type ExecutionMode = 'sequential' | 'parallel' | 'race';
|
|
158
|
-
|
|
159
|
-
* Internal execution context for action pipeline processing
|
|
160
|
-
* @implements pipeline-context
|
|
161
|
-
* @memberof api-terms
|
|
162
|
-
* @internal
|
|
163
|
-
* @since 1.0.0
|
|
164
|
-
*
|
|
165
|
-
* Maintains state during action pipeline execution including current payload,
|
|
166
|
-
* handler queue, execution status, and flow control information.
|
|
167
|
-
*
|
|
168
|
-
* @template T - The type of the payload being processed
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* // Internal usage in ActionRegister
|
|
173
|
-
* const context: PipelineContext<UserPayload> = {
|
|
174
|
-
* action: 'updateUser',
|
|
175
|
-
* payload: { id: '123', name: 'John' },
|
|
176
|
-
* handlers: registeredHandlers,
|
|
177
|
-
* aborted: false,
|
|
178
|
-
* currentIndex: 0,
|
|
179
|
-
* executionMode: 'sequential'
|
|
180
|
-
* };
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
interface PipelineContext<T = any> {
|
|
51
|
+
interface PipelineContext<T = any, R = void> {
|
|
184
52
|
action: string;
|
|
185
53
|
payload: T;
|
|
186
|
-
handlers: HandlerRegistration<T>[];
|
|
54
|
+
handlers: HandlerRegistration<T, R>[];
|
|
187
55
|
aborted: boolean;
|
|
188
56
|
abortReason?: string;
|
|
189
57
|
currentIndex: number;
|
|
190
58
|
jumpToPriority?: number;
|
|
191
59
|
executionMode: ExecutionMode;
|
|
60
|
+
results: R[];
|
|
61
|
+
terminated: boolean;
|
|
62
|
+
terminationResult?: R;
|
|
192
63
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Configuration options for ActionRegister
|
|
195
|
-
* @implements actionregister-configuration
|
|
196
|
-
* @memberof api-terms
|
|
197
|
-
* @since 1.0.0
|
|
198
|
-
*
|
|
199
|
-
* Defines configuration options for ActionRegister instances, including
|
|
200
|
-
* logging setup, debugging options, and default execution behavior.
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```typescript
|
|
204
|
-
* const config: ActionRegisterConfig = {
|
|
205
|
-
* logger: createLogger(LogLevel.DEBUG),
|
|
206
|
-
* logLevel: LogLevel.INFO,
|
|
207
|
-
* name: 'UserActions',
|
|
208
|
-
* debug: true,
|
|
209
|
-
* defaultExecutionMode: 'sequential'
|
|
210
|
-
* };
|
|
211
|
-
*
|
|
212
|
-
* const actionRegister = new ActionRegister(config);
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
64
|
interface ActionRegisterConfig {
|
|
216
|
-
/** Custom logger implementation. Defaults to ConsoleLogger */
|
|
217
|
-
logger?: Logger;
|
|
218
|
-
/** Log level for filtering output. Defaults to ERROR */
|
|
219
|
-
logLevel?: LogLevel;
|
|
220
|
-
/** Name identifier for this ActionRegister instance */
|
|
221
65
|
name?: string;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Unregister function returned by register method
|
|
229
|
-
* @implements cleanup-function
|
|
230
|
-
* @memberof api-terms
|
|
231
|
-
* @since 1.0.0
|
|
232
|
-
*
|
|
233
|
-
* Function type for unregistering action handlers from the pipeline.
|
|
234
|
-
* Returned by the register method to provide cleanup capability.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```typescript
|
|
238
|
-
* const unregister = actionRegister.register('updateUser', handler);
|
|
239
|
-
*
|
|
240
|
-
* // Later, remove the handler
|
|
241
|
-
* unregister();
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
type UnregisterFunction = () => void;
|
|
245
|
-
/**
|
|
246
|
-
* Type-safe action dispatcher interface
|
|
247
|
-
* @implements action-dispatcher
|
|
248
|
-
* @memberof api-terms
|
|
249
|
-
* @since 1.0.0
|
|
250
|
-
*
|
|
251
|
-
* Provides overloaded function signatures for dispatching actions with proper
|
|
252
|
-
* type checking. Supports both actions with payloads and void actions.
|
|
253
|
-
*
|
|
254
|
-
* @template T - Action payload map defining available actions
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* ```typescript
|
|
258
|
-
* interface AppActions extends ActionPayloadMap {
|
|
259
|
-
* increment: void;
|
|
260
|
-
* setCount: number;
|
|
261
|
-
* updateUser: { id: string; name: string };
|
|
262
|
-
* }
|
|
263
|
-
*
|
|
264
|
-
* const dispatch: ActionDispatcher<AppActions> = actionRegister.dispatch;
|
|
265
|
-
*
|
|
266
|
-
* // Type-safe dispatching
|
|
267
|
-
* await dispatch('increment'); // No payload required
|
|
268
|
-
* await dispatch('setCount', 42); // Number payload required
|
|
269
|
-
* await dispatch('updateUser', { id: '1', name: 'John' }); // Object payload
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
interface ActionDispatcher<T extends ActionPayloadMap> {
|
|
273
|
-
/** Dispatch an action without payload */
|
|
274
|
-
<K extends keyof T>(action: T[K] extends void ? K : never): Promise<void>;
|
|
275
|
-
/** Dispatch an action with payload */
|
|
276
|
-
<K extends keyof T>(action: K, payload: T[K]): Promise<void>;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Performance metrics for action execution
|
|
280
|
-
* @implements action-metrics
|
|
281
|
-
* @implements performance-monitoring
|
|
282
|
-
* @memberof api-terms
|
|
283
|
-
* @since 1.0.0
|
|
284
|
-
*
|
|
285
|
-
* Provides detailed metrics for action execution performance and status.
|
|
286
|
-
* Used for monitoring, debugging, and performance optimization.
|
|
287
|
-
*
|
|
288
|
-
* @example
|
|
289
|
-
* ```typescript
|
|
290
|
-
* actionRegister.on('action:complete', ({ metrics }) => {
|
|
291
|
-
* console.log(`Action ${metrics.action} took ${metrics.executionTime}ms`);
|
|
292
|
-
* console.log(`Success: ${metrics.success}, Handlers: ${metrics.handlerCount}`);
|
|
293
|
-
* });
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
interface ActionMetrics {
|
|
297
|
-
action: string;
|
|
298
|
-
executionTime: number;
|
|
299
|
-
handlerCount: number;
|
|
300
|
-
success: boolean;
|
|
301
|
-
error?: string;
|
|
302
|
-
timestamp: number;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Event types emitted by ActionRegister
|
|
306
|
-
* @implements action-events
|
|
307
|
-
* @implements event-driven-architecture
|
|
308
|
-
* @memberof api-terms
|
|
309
|
-
* @since 1.0.0
|
|
310
|
-
*
|
|
311
|
-
* Defines all event types that can be emitted by ActionRegister instances.
|
|
312
|
-
* Enables reactive programming and monitoring of action lifecycle events.
|
|
313
|
-
*
|
|
314
|
-
* @template T - Action payload map defining available actions
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* ```typescript
|
|
318
|
-
* interface AppActions extends ActionPayloadMap {
|
|
319
|
-
* updateUser: { id: string; name: string };
|
|
320
|
-
* }
|
|
321
|
-
*
|
|
322
|
-
* const actionRegister = new ActionRegister<AppActions>();
|
|
323
|
-
*
|
|
324
|
-
* actionRegister.on('action:start', ({ action, payload }) => {
|
|
325
|
-
* console.log(`Starting action: ${action}`, payload);
|
|
326
|
-
* });
|
|
327
|
-
*
|
|
328
|
-
* actionRegister.on('action:complete', ({ action, metrics }) => {
|
|
329
|
-
* console.log(`Completed: ${action} in ${metrics.executionTime}ms`);
|
|
330
|
-
* });
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
interface ActionRegisterEvents<T extends ActionPayloadMap = ActionPayloadMap> {
|
|
334
|
-
/** Emitted before action dispatch */
|
|
335
|
-
'action:start': {
|
|
336
|
-
action: keyof T;
|
|
337
|
-
payload: any;
|
|
66
|
+
registry?: {
|
|
67
|
+
debug?: boolean;
|
|
68
|
+
autoCleanup?: boolean;
|
|
69
|
+
maxHandlers?: number;
|
|
70
|
+
defaultExecutionMode?: ExecutionMode;
|
|
338
71
|
};
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
72
|
+
}
|
|
73
|
+
interface DispatchOptions {
|
|
74
|
+
debounce?: number;
|
|
75
|
+
throttle?: number;
|
|
76
|
+
executionMode?: ExecutionMode;
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
autoAbort?: {
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
onControllerCreated?: (controller: AbortController) => void;
|
|
81
|
+
allowHandlerAbort?: boolean;
|
|
344
82
|
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
83
|
+
filter?: {
|
|
84
|
+
tags?: string[];
|
|
85
|
+
category?: string;
|
|
86
|
+
handlerIds?: string[];
|
|
87
|
+
excludeTags?: string[];
|
|
88
|
+
excludeCategory?: string;
|
|
89
|
+
excludeHandlerIds?: string[];
|
|
90
|
+
environment?: 'development' | 'production' | 'test';
|
|
91
|
+
feature?: string;
|
|
92
|
+
custom?: (config: Required<HandlerConfig>) => boolean;
|
|
350
93
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
94
|
+
result?: {
|
|
95
|
+
strategy?: 'first' | 'last' | 'all' | 'merge' | 'custom';
|
|
96
|
+
merger?: <R>(results: R[]) => R;
|
|
97
|
+
collect?: boolean;
|
|
98
|
+
timeout?: number;
|
|
99
|
+
maxResults?: number;
|
|
356
100
|
};
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
101
|
+
}
|
|
102
|
+
interface ExecutionResult<R = void> {
|
|
103
|
+
success: boolean;
|
|
104
|
+
aborted: boolean;
|
|
105
|
+
abortReason?: string;
|
|
106
|
+
terminated: boolean;
|
|
107
|
+
result?: R;
|
|
108
|
+
results: R[];
|
|
109
|
+
execution: {
|
|
110
|
+
duration: number;
|
|
111
|
+
handlersExecuted: number;
|
|
112
|
+
handlersSkipped: number;
|
|
113
|
+
handlersFailed: number;
|
|
114
|
+
startTime: number;
|
|
115
|
+
endTime: number;
|
|
362
116
|
};
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
117
|
+
handlers: Array<{
|
|
118
|
+
id: string;
|
|
119
|
+
executed: boolean;
|
|
120
|
+
duration?: number;
|
|
121
|
+
result?: R;
|
|
122
|
+
error?: Error;
|
|
123
|
+
metadata?: Record<string, any>;
|
|
124
|
+
}>;
|
|
125
|
+
errors: Array<{
|
|
366
126
|
handlerId: string;
|
|
367
|
-
|
|
127
|
+
error: Error;
|
|
128
|
+
timestamp: number;
|
|
129
|
+
}>;
|
|
368
130
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
131
|
+
type UnregisterFunction = () => void;
|
|
132
|
+
interface ActionDispatcher<T extends ActionPayloadMap> {
|
|
133
|
+
<K extends keyof T>(action: T[K] extends void ? K : never, options?: DispatchOptions): Promise<void>;
|
|
134
|
+
<K extends keyof T>(action: K, payload: T[K], options?: DispatchOptions): Promise<void>;
|
|
135
|
+
}
|
|
136
|
+
interface ActionRegistryInfo<T extends ActionPayloadMap> {
|
|
137
|
+
name: string;
|
|
138
|
+
totalActions: number;
|
|
139
|
+
totalHandlers: number;
|
|
140
|
+
registeredActions: Array<keyof T>;
|
|
141
|
+
actionExecutionModes: Map<keyof T, ExecutionMode>;
|
|
142
|
+
defaultExecutionMode: ExecutionMode;
|
|
143
|
+
}
|
|
144
|
+
interface ActionHandlerStats<T extends ActionPayloadMap> {
|
|
145
|
+
action: keyof T;
|
|
146
|
+
handlerCount: number;
|
|
147
|
+
handlersByPriority: Array<{
|
|
148
|
+
priority: number;
|
|
149
|
+
handlers: Array<{
|
|
150
|
+
id: string;
|
|
151
|
+
tags: string[];
|
|
152
|
+
category?: string;
|
|
153
|
+
description?: string;
|
|
154
|
+
version?: string;
|
|
155
|
+
}>;
|
|
156
|
+
}>;
|
|
157
|
+
executionStats?: {
|
|
158
|
+
totalExecutions: number;
|
|
159
|
+
averageDuration: number;
|
|
160
|
+
successRate: number;
|
|
161
|
+
errorCount: number;
|
|
162
|
+
};
|
|
396
163
|
}
|
|
397
|
-
//# sourceMappingURL=types.d.ts.map
|
|
398
164
|
//#endregion
|
|
399
165
|
//#region src/ActionRegister.d.ts
|
|
400
|
-
/**
|
|
401
|
-
* Central action registration and dispatch system
|
|
402
|
-
* @implements action-pipeline-system
|
|
403
|
-
* @implements actionregister
|
|
404
|
-
* @memberof core-concepts
|
|
405
|
-
*
|
|
406
|
-
* Core action pipeline management system with type-safe action dispatch
|
|
407
|
-
* @template T - Action payload map defining available actions and their payload types
|
|
408
|
-
*
|
|
409
|
-
* @example
|
|
410
|
-
* ```typescript
|
|
411
|
-
* interface AppActions extends ActionPayloadMap {
|
|
412
|
-
* increment: void;
|
|
413
|
-
* setCount: number;
|
|
414
|
-
* updateUser: { id: string; name: string };
|
|
415
|
-
* }
|
|
416
|
-
*
|
|
417
|
-
* const actionRegister = new ActionRegister<AppActions>();
|
|
418
|
-
*
|
|
419
|
-
* // Register handlers with priority and configuration
|
|
420
|
-
* actionRegister.register('increment', (_, controller) => {
|
|
421
|
-
* console.log('Incremented');
|
|
422
|
-
* controller.next();
|
|
423
|
-
* }, { priority: 10 });
|
|
424
|
-
*
|
|
425
|
-
* actionRegister.register('setCount', (count, controller) => {
|
|
426
|
-
* console.log(`Count: ${count}`);
|
|
427
|
-
* controller.next();
|
|
428
|
-
* });
|
|
429
|
-
*
|
|
430
|
-
* // Dispatch actions with type safety
|
|
431
|
-
* await actionRegister.dispatch('increment');
|
|
432
|
-
* await actionRegister.dispatch('setCount', 42);
|
|
433
|
-
* ```
|
|
434
|
-
*/
|
|
435
166
|
declare class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {
|
|
436
167
|
private pipelines;
|
|
437
168
|
private handlerCounter;
|
|
438
|
-
private readonly logger;
|
|
439
|
-
private readonly events;
|
|
440
|
-
private readonly config;
|
|
441
169
|
private readonly actionGuard;
|
|
442
170
|
private executionMode;
|
|
443
171
|
private actionExecutionModes;
|
|
172
|
+
readonly name: string;
|
|
173
|
+
private readonly registryConfig;
|
|
174
|
+
private executionStats;
|
|
444
175
|
constructor(config?: ActionRegisterConfig);
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
* @param action - The action name to handle
|
|
451
|
-
* @param handler - The handler function to execute
|
|
452
|
-
* @param config - Optional configuration for the handler
|
|
453
|
-
* @returns Unregister function to remove the handler
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* ```typescript
|
|
457
|
-
* const unregister = actionRegister.register('updateUser',
|
|
458
|
-
* async (payload, controller) => {
|
|
459
|
-
* // Validate payload
|
|
460
|
-
* if (!payload.id) {
|
|
461
|
-
* controller.abort('User ID is required');
|
|
462
|
-
* return;
|
|
463
|
-
* }
|
|
464
|
-
*
|
|
465
|
-
* // Process update
|
|
466
|
-
* await updateUserInStore(payload);
|
|
467
|
-
* controller.next();
|
|
468
|
-
* },
|
|
469
|
-
* { priority: 10, blocking: true }
|
|
470
|
-
* );
|
|
471
|
-
*
|
|
472
|
-
* // Later, remove the handler
|
|
473
|
-
* unregister();
|
|
474
|
-
* ```
|
|
475
|
-
*/
|
|
476
|
-
register<K extends keyof T>(action: K, handler: ActionHandler<T[K]>, config?: HandlerConfig): UnregisterFunction;
|
|
477
|
-
/**
|
|
478
|
-
* Dispatch action through pipeline
|
|
479
|
-
* @implements action-dispatcher
|
|
480
|
-
*
|
|
481
|
-
* Dispatch an action through the pipeline
|
|
482
|
-
* Overloaded to provide type safety for actions with and without payloads
|
|
483
|
-
*/
|
|
484
|
-
dispatch: ActionDispatcher<T>;
|
|
485
|
-
/**
|
|
486
|
-
* Execute the pipeline with proper flow control
|
|
487
|
-
* @internal
|
|
488
|
-
*/
|
|
176
|
+
register<K extends keyof T, R = void>(action: K, handler: ActionHandler<T[K], R>, config?: HandlerConfig): UnregisterFunction;
|
|
177
|
+
dispatch<K extends keyof T>(action: K, payload?: T[K], options?: DispatchOptions): Promise<void>;
|
|
178
|
+
dispatchWithResult<K extends keyof T, R = void>(action: K, payload?: T[K], options?: DispatchOptions): Promise<ExecutionResult<R>>;
|
|
179
|
+
private filterHandlers;
|
|
180
|
+
private processResults;
|
|
489
181
|
private executePipeline;
|
|
490
|
-
/**
|
|
491
|
-
* Clean up one-time handlers after pipeline execution
|
|
492
|
-
* @internal
|
|
493
|
-
*/
|
|
494
182
|
private cleanupOneTimeHandlers;
|
|
495
|
-
|
|
496
|
-
* Get the number of handlers registered for an action
|
|
497
|
-
* @param action - The action to check
|
|
498
|
-
* @returns Number of handlers registered
|
|
499
|
-
*/
|
|
183
|
+
private updateExecutionStats;
|
|
500
184
|
getHandlerCount<K extends keyof T>(action: K): number;
|
|
501
|
-
/**
|
|
502
|
-
* Check if any handlers are registered for an action
|
|
503
|
-
* @param action - The action to check
|
|
504
|
-
* @returns True if handlers are registered
|
|
505
|
-
*/
|
|
506
185
|
hasHandlers<K extends keyof T>(action: K): boolean;
|
|
507
|
-
/**
|
|
508
|
-
* Get all registered action names
|
|
509
|
-
* @returns Array of action names
|
|
510
|
-
*/
|
|
511
186
|
getRegisteredActions(): (keyof T)[];
|
|
512
|
-
/**
|
|
513
|
-
* Clear all handlers for a specific action
|
|
514
|
-
* @param action - The action to clear
|
|
515
|
-
*/
|
|
516
187
|
clearAction<K extends keyof T>(action: K): void;
|
|
517
|
-
/**
|
|
518
|
-
* Clear all handlers for all actions
|
|
519
|
-
*/
|
|
520
188
|
clearAll(): void;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* Get current configuration
|
|
536
|
-
* @returns Current ActionRegister configuration
|
|
537
|
-
*/
|
|
538
|
-
getConfig(): Readonly<Required<ActionRegisterConfig>>;
|
|
539
|
-
/**
|
|
540
|
-
* Get logger instance
|
|
541
|
-
* @returns Current logger instance
|
|
542
|
-
*/
|
|
543
|
-
getLogger(): Logger;
|
|
189
|
+
getName(): string;
|
|
190
|
+
getRegistryInfo(): ActionRegistryInfo<T>;
|
|
191
|
+
getActionStats<K extends keyof T>(action: K): ActionHandlerStats<T> | null;
|
|
192
|
+
getAllActionStats(): Array<ActionHandlerStats<T>>;
|
|
193
|
+
getHandlersByTag(tag: string): Map<keyof T, HandlerRegistration<any, any>[]>;
|
|
194
|
+
getHandlersByCategory(category: string): Map<keyof T, HandlerRegistration<any, any>[]>;
|
|
195
|
+
setActionExecutionMode<K extends keyof T>(action: K, mode: ExecutionMode): void;
|
|
196
|
+
getActionExecutionMode<K extends keyof T>(action: K): ExecutionMode;
|
|
197
|
+
removeActionExecutionMode<K extends keyof T>(action: K): void;
|
|
198
|
+
clearExecutionStats(): void;
|
|
199
|
+
clearActionExecutionStats<K extends keyof T>(action: K): void;
|
|
200
|
+
getRegistryConfig(): ActionRegisterConfig['registry'];
|
|
201
|
+
isDebugEnabled(): boolean;
|
|
544
202
|
}
|
|
545
|
-
//# sourceMappingURL=ActionRegister.d.ts.map
|
|
546
203
|
//#endregion
|
|
547
204
|
//#region src/action-guard.d.ts
|
|
548
|
-
/**
|
|
549
|
-
* Action guard state tracking
|
|
550
|
-
* @internal
|
|
551
|
-
*/
|
|
552
205
|
interface GuardState {
|
|
553
206
|
lastExecuted: number;
|
|
554
207
|
debounceTimer?: NodeJS.Timeout;
|
|
555
208
|
throttleTimer?: NodeJS.Timeout;
|
|
556
209
|
isThrottled: boolean;
|
|
557
210
|
}
|
|
558
|
-
/**
|
|
559
|
-
* Action Guard system for managing action execution timing
|
|
560
|
-
* @implements action-guard
|
|
561
|
-
* @implements performance-optimization
|
|
562
|
-
* @implements user-experience-optimization
|
|
563
|
-
* @memberof core-concepts
|
|
564
|
-
* @internal
|
|
565
|
-
* @since 1.0.0
|
|
566
|
-
*
|
|
567
|
-
* Provides debouncing, throttling, and blocking mechanisms for action execution
|
|
568
|
-
* to optimize performance and enhance user experience. Manages timing state
|
|
569
|
-
* per action to prevent unnecessary or excessive action invocations.
|
|
570
|
-
*
|
|
571
|
-
* Key Features:
|
|
572
|
-
* - Debouncing: Delay execution until activity stops
|
|
573
|
-
* - Throttling: Limit execution frequency to intervals
|
|
574
|
-
* - Per-action state management with automatic cleanup
|
|
575
|
-
* - Memory leak prevention through proper timer management
|
|
576
|
-
*
|
|
577
|
-
* @example
|
|
578
|
-
* ```typescript
|
|
579
|
-
* const guard = new ActionGuard(logger);
|
|
580
|
-
*
|
|
581
|
-
* // Debounce search input (wait 300ms after typing stops)
|
|
582
|
-
* if (await guard.debounce('search', 300)) {
|
|
583
|
-
* executeSearch();
|
|
584
|
-
* }
|
|
585
|
-
*
|
|
586
|
-
* // Throttle scroll handler (max once per 100ms)
|
|
587
|
-
* if (guard.throttle('scroll', 100)) {
|
|
588
|
-
* updateScrollPosition();
|
|
589
|
-
* }
|
|
590
|
-
* ```
|
|
591
|
-
*/
|
|
592
211
|
declare class ActionGuard {
|
|
593
212
|
private guards;
|
|
594
|
-
|
|
595
|
-
constructor(logger: Logger);
|
|
596
|
-
/**
|
|
597
|
-
* Check if action should be debounced
|
|
598
|
-
* @param actionKey - Unique key for the action
|
|
599
|
-
* @param debounceMs - Debounce delay in milliseconds
|
|
600
|
-
* @returns Promise that resolves when debounce period is complete
|
|
601
|
-
*/
|
|
213
|
+
constructor();
|
|
602
214
|
debounce(actionKey: string, debounceMs: number): Promise<boolean>;
|
|
603
|
-
/**
|
|
604
|
-
* Check if action should be throttled
|
|
605
|
-
* @param actionKey - Unique key for the action
|
|
606
|
-
* @param throttleMs - Throttle delay in milliseconds
|
|
607
|
-
* @returns True if action should proceed, false if throttled
|
|
608
|
-
*/
|
|
609
215
|
throttle(actionKey: string, throttleMs: number): boolean;
|
|
610
|
-
/**
|
|
611
|
-
* Clear all guards for an action
|
|
612
|
-
* @param actionKey - Action key to clear
|
|
613
|
-
*/
|
|
614
216
|
clearGuards(actionKey: string): void;
|
|
615
|
-
/**
|
|
616
|
-
* Clear all guards
|
|
617
|
-
*/
|
|
618
217
|
clearAll(): void;
|
|
619
|
-
/**
|
|
620
|
-
* Get current guard state for debugging
|
|
621
|
-
* @param actionKey - Action key to inspect
|
|
622
|
-
*/
|
|
623
218
|
getGuardState(actionKey: string): GuardState | undefined;
|
|
624
|
-
/**
|
|
625
|
-
* Get all active guards for debugging
|
|
626
|
-
*/
|
|
627
219
|
getAllGuardStates(): Map<string, GuardState>;
|
|
628
220
|
}
|
|
629
221
|
//#endregion
|
|
630
222
|
//#region src/execution-modes.d.ts
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
* @implements sequential-execution
|
|
635
|
-
* @memberof core-concepts
|
|
636
|
-
* @internal
|
|
637
|
-
* @since 1.0.0
|
|
638
|
-
*
|
|
639
|
-
* Executes action handlers sequentially in priority order, supporting flow control,
|
|
640
|
-
* conditional execution, and priority jumping within the pipeline.
|
|
641
|
-
*
|
|
642
|
-
* @template T - The type of the payload being processed
|
|
643
|
-
* @param context - Pipeline execution context with handlers and state
|
|
644
|
-
* @param createController - Factory function for creating pipeline controllers
|
|
645
|
-
* @param logger - Logger instance for tracing execution
|
|
646
|
-
* @returns Promise that resolves when all handlers complete or pipeline aborts
|
|
647
|
-
*
|
|
648
|
-
* Features:
|
|
649
|
-
* - Priority-based execution order (higher priority first)
|
|
650
|
-
* - Support for priority jumping within execution
|
|
651
|
-
* - Conditional handler execution (condition/validation checks)
|
|
652
|
-
* - Blocking/non-blocking handler support
|
|
653
|
-
* - Comprehensive error handling and recovery
|
|
654
|
-
*/
|
|
655
|
-
declare function executeSequential<T>(context: PipelineContext<T>, createController: (registration: HandlerRegistration<T>, index: number) => PipelineController<T>, logger: Logger): Promise<void>;
|
|
656
|
-
/**
|
|
657
|
-
* Execute handlers in parallel mode (all at once)
|
|
658
|
-
* @internal
|
|
659
|
-
*/
|
|
660
|
-
declare function executeParallel<T>(context: PipelineContext<T>, createController: (registration: HandlerRegistration<T>, index: number) => PipelineController<T>, logger: Logger): Promise<void>;
|
|
661
|
-
/**
|
|
662
|
-
* Execute handlers in race mode (first to complete wins)
|
|
663
|
-
* @internal
|
|
664
|
-
*/
|
|
665
|
-
declare function executeRace<T>(context: PipelineContext<T>, createController: (registration: HandlerRegistration<T>, index: number) => PipelineController<T>, logger: Logger): Promise<void>;
|
|
666
|
-
//# sourceMappingURL=execution-modes.d.ts.map
|
|
667
|
-
|
|
223
|
+
declare function executeSequential<T, R = void>(context: PipelineContext<T, R>, createController: (registration: HandlerRegistration<T, R>, index: number) => PipelineController<T, R>): Promise<void>;
|
|
224
|
+
declare function executeParallel<T, R = void>(context: PipelineContext<T, R>, createController: (registration: HandlerRegistration<T, R>, index: number) => PipelineController<T, R>): Promise<void>;
|
|
225
|
+
declare function executeRace<T, R = void>(context: PipelineContext<T, R>, createController: (registration: HandlerRegistration<T, R>, index: number) => PipelineController<T, R>): Promise<void>;
|
|
668
226
|
//#endregion
|
|
669
|
-
export { type ActionDispatcher, ActionGuard, type ActionHandler, type
|
|
227
|
+
export { type ActionDispatcher, ActionGuard, type ActionHandler, type ActionPayloadMap, ActionRegister, type ActionRegisterConfig, type DispatchOptions, type ExecutionMode, type ExecutionResult, type HandlerConfig, type HandlerRegistration, type PipelineContext, type PipelineController, type UnregisterFunction, executeParallel, executeRace, executeSequential };
|
|
670
228
|
//# sourceMappingURL=index.d.cts.map
|