@context-action/core 0.3.0 → 0.4.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 +26 -444
- package/dist/index.d.cts +0 -38
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +0 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -444
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -40,24 +40,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
40
40
|
* @param context - Pipeline execution context containing handlers and state
|
|
41
41
|
* @param createController - Factory function for creating pipeline controllers
|
|
42
42
|
*
|
|
43
|
-
* @throws {Error} When a blocking handler fails
|
|
43
|
+
* @throws {Error} When a blocking handler fails
|
|
44
44
|
*
|
|
45
|
-
* @
|
|
46
|
-
* ```typescript
|
|
47
|
-
* // This is called internally by ActionRegister.dispatch()
|
|
48
|
-
* // when executionMode is 'sequential'
|
|
49
|
-
*
|
|
50
|
-
* // Handlers execute in this order (by priority):
|
|
51
|
-
* // 1. Priority 100: Validation handler
|
|
52
|
-
* // 2. Priority 50: Business logic handler
|
|
53
|
-
* // 3. Priority 10: Logging handler
|
|
54
|
-
*
|
|
55
|
-
* await executeSequential(context, (registration, index) => ({
|
|
56
|
-
* abort: (reason) => { context.aborted = true; context.abortReason = reason },
|
|
57
|
-
* modifyPayload: (modifier) => { context.payload = modifier(context.payload) },
|
|
58
|
-
* // ... other controller methods
|
|
59
|
-
* }))
|
|
60
|
-
* ```
|
|
45
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/dispatch-patterns
|
|
61
46
|
*
|
|
62
47
|
* @public
|
|
63
48
|
*/
|
|
@@ -68,16 +53,6 @@ async function executeSequential(context, createController) {
|
|
|
68
53
|
if (context.aborted || context.terminated) break;
|
|
69
54
|
const registration = context.handlers[i];
|
|
70
55
|
context.currentIndex = i;
|
|
71
|
-
/** Check condition if provided */
|
|
72
|
-
if (registration.config.condition && !registration.config.condition()) {
|
|
73
|
-
i++;
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
/** Check validation if provided */
|
|
77
|
-
if (registration.config.validation && !registration.config.validation(context.payload)) {
|
|
78
|
-
i++;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
56
|
const controller = createController(registration, i);
|
|
82
57
|
try {
|
|
83
58
|
if (context.aborted) break;
|
|
@@ -134,46 +109,13 @@ async function executeSequential(context, createController) {
|
|
|
134
109
|
*
|
|
135
110
|
* @throws {Error} When any blocking handler fails
|
|
136
111
|
*
|
|
137
|
-
* @
|
|
138
|
-
* ```typescript
|
|
139
|
-
* // This is called internally by ActionRegister.dispatch()
|
|
140
|
-
* // when executionMode is 'parallel'
|
|
141
|
-
*
|
|
142
|
-
* // All handlers execute simultaneously:
|
|
143
|
-
* // - Analytics handler (non-blocking)
|
|
144
|
-
* // - Validation handler (blocking)
|
|
145
|
-
* // - Update handler (blocking)
|
|
146
|
-
* // - Notification handler (non-blocking)
|
|
147
|
-
*
|
|
148
|
-
* await executeParallel(context, (registration, index) => ({
|
|
149
|
-
* abort: (reason) => { context.aborted = true },
|
|
150
|
-
* setResult: (result) => { context.results.push(result) },
|
|
151
|
-
* // ... other controller methods
|
|
152
|
-
* }))
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* @example Use Case
|
|
156
|
-
* ```typescript
|
|
157
|
-
* // Perfect for independent operations
|
|
158
|
-
* register.setActionExecutionMode('logEvent', 'parallel')
|
|
159
|
-
*
|
|
160
|
-
* // These can all run simultaneously:
|
|
161
|
-
* register.register('logEvent', analyticsHandler, { blocking: false })
|
|
162
|
-
* register.register('logEvent', metricsHandler, { blocking: false })
|
|
163
|
-
* register.register('logEvent', auditHandler, { blocking: true })
|
|
164
|
-
* ```
|
|
112
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/dispatch-patterns#parallel-execution
|
|
165
113
|
*
|
|
166
114
|
* @public
|
|
167
115
|
*/
|
|
168
116
|
async function executeParallel(context, createController) {
|
|
169
|
-
/**
|
|
170
|
-
const runnableHandlers = context.handlers
|
|
171
|
-
/** Check condition */
|
|
172
|
-
if (registration.config.condition && !registration.config.condition()) return false;
|
|
173
|
-
/** Check validation */
|
|
174
|
-
if (registration.config.validation && !registration.config.validation(context.payload)) return false;
|
|
175
|
-
return true;
|
|
176
|
-
});
|
|
117
|
+
/** All handlers are runnable */
|
|
118
|
+
const runnableHandlers = context.handlers;
|
|
177
119
|
/** Create promises for all handlers */
|
|
178
120
|
const handlerPromises = runnableHandlers.map(async (registration, _index) => {
|
|
179
121
|
const controller = createController(registration, _index);
|
|
@@ -239,52 +181,13 @@ async function executeParallel(context, createController) {
|
|
|
239
181
|
*
|
|
240
182
|
* @throws {Error} When the winning handler fails and is blocking
|
|
241
183
|
*
|
|
242
|
-
* @
|
|
243
|
-
* ```typescript
|
|
244
|
-
* // This is called internally by ActionRegister.dispatch()
|
|
245
|
-
* // when executionMode is 'race'
|
|
246
|
-
*
|
|
247
|
-
* // Multiple data sources racing for fastest response:
|
|
248
|
-
* // - Database handler (might be slow)
|
|
249
|
-
* // - Cache handler (usually fast)
|
|
250
|
-
* // - API handler (variable speed)
|
|
251
|
-
* //
|
|
252
|
-
* // Whichever completes first wins
|
|
253
|
-
*
|
|
254
|
-
* await executeRace(context, (registration, index) => ({
|
|
255
|
-
* return: (result) => {
|
|
256
|
-
* context.terminated = true
|
|
257
|
-
* context.terminationResult = result
|
|
258
|
-
* },
|
|
259
|
-
* // ... other controller methods
|
|
260
|
-
* }))
|
|
261
|
-
* ```
|
|
262
|
-
*
|
|
263
|
-
* @example Use Case
|
|
264
|
-
* ```typescript
|
|
265
|
-
* // Race between multiple data sources
|
|
266
|
-
* register.setActionExecutionMode('fetchUserData', 'race')
|
|
267
|
-
*
|
|
268
|
-
* // These handlers race for fastest response:
|
|
269
|
-
* register.register('fetchUserData', cacheHandler) // Usually fastest
|
|
270
|
-
* register.register('fetchUserData', databaseHandler) // Reliable fallback
|
|
271
|
-
* register.register('fetchUserData', apiHandler) // External source
|
|
272
|
-
*
|
|
273
|
-
* // First to complete wins, others are ignored
|
|
274
|
-
* const result = await register.dispatchWithResult('fetchUserData', { id: '123' })
|
|
275
|
-
* ```
|
|
184
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/dispatch-patterns#race-execution
|
|
276
185
|
*
|
|
277
186
|
* @public
|
|
278
187
|
*/
|
|
279
188
|
async function executeRace(context, createController) {
|
|
280
|
-
/**
|
|
281
|
-
const runnableHandlers = context.handlers
|
|
282
|
-
/** Check condition */
|
|
283
|
-
if (registration.config.condition && !registration.config.condition()) return false;
|
|
284
|
-
/** Check validation */
|
|
285
|
-
if (registration.config.validation && !registration.config.validation(context.payload)) return false;
|
|
286
|
-
return true;
|
|
287
|
-
});
|
|
189
|
+
/** All handlers are runnable */
|
|
190
|
+
const runnableHandlers = context.handlers;
|
|
288
191
|
if (runnableHandlers.length === 0) return;
|
|
289
192
|
/** Create promises for all handlers */
|
|
290
193
|
const handlerPromises = runnableHandlers.map(async (registration, _index) => {
|
|
@@ -393,33 +296,9 @@ var import_defineProperty$2 = /* @__PURE__ */ __toESM(require_defineProperty(),
|
|
|
393
296
|
* debouncing and throttling mechanisms. Debouncing waits for a pause in calls
|
|
394
297
|
* before executing, while throttling limits execution frequency.
|
|
395
298
|
*
|
|
396
|
-
* @
|
|
397
|
-
* ```typescript
|
|
398
|
-
* const guard = new ActionGuard()
|
|
399
|
-
*
|
|
400
|
-
* // Wait 300ms after user stops typing before searching
|
|
401
|
-
* register.register('searchUsers', async (payload, controller) => {
|
|
402
|
-
* const query = payload.query
|
|
403
|
-
* if (query.length < 2) return
|
|
404
|
-
*
|
|
405
|
-
* const results = await userService.search(query)
|
|
406
|
-
* controller.setResult(results)
|
|
407
|
-
* }, {
|
|
408
|
-
* debounce: 300, // Built into ActionRegister via ActionGuard
|
|
409
|
-
* tags: ['search', 'user-input']
|
|
410
|
-
* })
|
|
411
|
-
* ```
|
|
299
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
412
300
|
*
|
|
413
|
-
* @
|
|
414
|
-
* ```typescript
|
|
415
|
-
* // Limit scroll position updates to once per 100ms
|
|
416
|
-
* register.register('updateScrollPosition', (payload, controller) => {
|
|
417
|
-
* scrollState.setValue(payload.position)
|
|
418
|
-
* }, {
|
|
419
|
-
* throttle: 100, // Built into ActionRegister via ActionGuard
|
|
420
|
-
* tags: ['scroll', 'performance']
|
|
421
|
-
* })
|
|
422
|
-
* ```
|
|
301
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
423
302
|
*
|
|
424
303
|
* @example Manual Usage (Advanced)
|
|
425
304
|
* ```typescript
|
|
@@ -589,7 +468,7 @@ var ActionGuard = class {
|
|
|
589
468
|
clearAll() {
|
|
590
469
|
/** Iterate through all guard states and clear their timers */
|
|
591
470
|
/** This prevents memory leaks when clearing the entire guard system */
|
|
592
|
-
|
|
471
|
+
this.guards.forEach((state) => {
|
|
593
472
|
/** Clear any active debounce timers */
|
|
594
473
|
if (state.debounceTimer) {
|
|
595
474
|
clearTimeout(state.debounceTimer);
|
|
@@ -597,7 +476,7 @@ var ActionGuard = class {
|
|
|
597
476
|
}
|
|
598
477
|
/** Clear any active throttle timers */
|
|
599
478
|
if (state.throttleTimer) clearTimeout(state.throttleTimer);
|
|
600
|
-
}
|
|
479
|
+
});
|
|
601
480
|
/** Remove all guard states from memory */
|
|
602
481
|
this.guards.clear();
|
|
603
482
|
}
|
|
@@ -748,74 +627,9 @@ var import_defineProperty = /* @__PURE__ */ __toESM(require_defineProperty(), 1)
|
|
|
748
627
|
*
|
|
749
628
|
* @template TActionMap - Action payload mapping interface extending ActionPayloadMap
|
|
750
629
|
*
|
|
751
|
-
* @
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
* updateUser: { id: string; name: string; email: string }
|
|
755
|
-
* deleteUser: { id: string }
|
|
756
|
-
* resetUser: void
|
|
757
|
-
* }
|
|
758
|
-
*
|
|
759
|
-
* const register = new ActionRegister<AppActions>({
|
|
760
|
-
* name: 'AppRegister',
|
|
761
|
-
* registry: { debug: true, maxHandlers: 10 }
|
|
762
|
-
* })
|
|
763
|
-
*
|
|
764
|
-
* // Register handler with priority
|
|
765
|
-
* register.register('updateUser', async (payload, controller) => {
|
|
766
|
-
* await userService.update(payload.id, payload)
|
|
767
|
-
* controller.setResult({ success: true, userId: payload.id })
|
|
768
|
-
* }, { priority: 10, tags: ['user', 'crud'] })
|
|
769
|
-
*
|
|
770
|
-
* // Dispatch action
|
|
771
|
-
* await register.dispatch('updateUser', {
|
|
772
|
-
* id: '123',
|
|
773
|
-
* name: 'John Doe',
|
|
774
|
-
* email: 'john@example.com'
|
|
775
|
-
* })
|
|
776
|
-
* ```
|
|
777
|
-
*
|
|
778
|
-
* @example With Multiple Handlers
|
|
779
|
-
* ```typescript
|
|
780
|
-
* // High priority validation handler
|
|
781
|
-
* register.register('updateUser', async (payload, controller) => {
|
|
782
|
-
* if (!payload.email.includes('@')) {
|
|
783
|
-
* controller.abort('Invalid email format')
|
|
784
|
-
* return
|
|
785
|
-
* }
|
|
786
|
-
* }, { priority: 100, category: 'validation' })
|
|
787
|
-
*
|
|
788
|
-
* // Lower priority update handler
|
|
789
|
-
* register.register('updateUser', async (payload, controller) => {
|
|
790
|
-
* const user = await userService.update(payload.id, payload)
|
|
791
|
-
* controller.setResult(user)
|
|
792
|
-
* }, { priority: 50, category: 'business-logic' })
|
|
793
|
-
* ```
|
|
794
|
-
*
|
|
795
|
-
* @example Advanced Configuration
|
|
796
|
-
* ```typescript
|
|
797
|
-
* const register = new ActionRegister<AppActions>({
|
|
798
|
-
* name: 'AdvancedRegister',
|
|
799
|
-
* registry: {
|
|
800
|
-
* debug: true,
|
|
801
|
-
* maxHandlers: 20,
|
|
802
|
-
* defaultExecutionMode: 'parallel',
|
|
803
|
-
* autoCleanup: true
|
|
804
|
-
* }
|
|
805
|
-
* })
|
|
806
|
-
*
|
|
807
|
-
* // Handler with debouncing and tags
|
|
808
|
-
* register.register('searchUsers', async (payload, controller) => {
|
|
809
|
-
* const results = await userService.search(payload.query)
|
|
810
|
-
* controller.setResult(results)
|
|
811
|
-
* }, {
|
|
812
|
-
* priority: 10,
|
|
813
|
-
* debounce: 300,
|
|
814
|
-
* tags: ['search', 'user'],
|
|
815
|
-
* category: 'query',
|
|
816
|
-
* once: false
|
|
817
|
-
* })
|
|
818
|
-
* ```
|
|
630
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/
|
|
631
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
632
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/register-delegation
|
|
819
633
|
*
|
|
820
634
|
* @public
|
|
821
635
|
*/
|
|
@@ -855,29 +669,7 @@ var ActionRegister = class {
|
|
|
855
669
|
*
|
|
856
670
|
* @throws {Error} When maximum handlers limit is reached
|
|
857
671
|
*
|
|
858
|
-
* @
|
|
859
|
-
* ```typescript
|
|
860
|
-
* const unregister = register.register('updateUser', async (payload, controller) => {
|
|
861
|
-
* await userService.update(payload.id, payload)
|
|
862
|
-
* })
|
|
863
|
-
*
|
|
864
|
-
* // Later remove the handler
|
|
865
|
-
* unregister()
|
|
866
|
-
* ```
|
|
867
|
-
*
|
|
868
|
-
* @example With Priority and Configuration
|
|
869
|
-
* ```typescript
|
|
870
|
-
* register.register('validateUser', async (payload, controller) => {
|
|
871
|
-
* if (!payload.email) {
|
|
872
|
-
* controller.abort('Email is required')
|
|
873
|
-
* }
|
|
874
|
-
* }, {
|
|
875
|
-
* priority: 100,
|
|
876
|
-
* tags: ['validation'],
|
|
877
|
-
* category: 'security',
|
|
878
|
-
* once: false
|
|
879
|
-
* })
|
|
880
|
-
* ```
|
|
672
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
881
673
|
*
|
|
882
674
|
* @public
|
|
883
675
|
*/
|
|
@@ -897,92 +689,8 @@ var ActionRegister = class {
|
|
|
897
689
|
id: handlerId,
|
|
898
690
|
blocking: config.blocking ?? false,
|
|
899
691
|
once: config.once ?? false,
|
|
900
|
-
condition: config.condition || (() => true),
|
|
901
|
-
debounce: config.debounce ?? void 0,
|
|
902
|
-
throttle: config.throttle ?? void 0,
|
|
903
|
-
validation: config.validation ?? void 0,
|
|
904
|
-
middleware: config.middleware ?? false,
|
|
905
|
-
tags: config.tags ?? [],
|
|
906
|
-
category: config.category ?? void 0,
|
|
907
|
-
description: config.description ?? void 0,
|
|
908
|
-
version: config.version ?? void 0,
|
|
909
|
-
returnType: config.returnType ?? "value",
|
|
910
|
-
timeout: config.timeout ?? void 0,
|
|
911
|
-
retries: config.retries ?? 0,
|
|
912
|
-
dependencies: config.dependencies ?? [],
|
|
913
|
-
conflicts: config.conflicts ?? [],
|
|
914
|
-
environment: config.environment ?? void 0,
|
|
915
|
-
feature: config.feature ?? void 0,
|
|
916
|
-
metrics: config.metrics ?? {
|
|
917
|
-
collectTiming: false,
|
|
918
|
-
collectErrors: false,
|
|
919
|
-
customMetrics: {}
|
|
920
|
-
},
|
|
921
|
-
metadata: config.metadata ?? {}
|
|
922
|
-
},
|
|
923
|
-
id: handlerId
|
|
924
|
-
};
|
|
925
|
-
if (!this.pipelines.has(action)) this.pipelines.set(action, []);
|
|
926
|
-
const pipeline = this.pipelines.get(action);
|
|
927
|
-
const existingIndex = pipeline.findIndex((reg) => reg.id === handlerId);
|
|
928
|
-
if (existingIndex !== -1) return () => {};
|
|
929
|
-
if (this.registryConfig?.maxHandlers && pipeline.length >= this.registryConfig.maxHandlers) throw new Error(`Maximum number of handlers (${this.registryConfig.maxHandlers}) reached for action '${String(action)}' in registry '${this.name}'`);
|
|
930
|
-
pipeline.push(registration);
|
|
931
|
-
pipeline.sort((a, b) => b.config.priority - a.config.priority);
|
|
932
|
-
if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 Handler registered: ${String(action)}`, {
|
|
933
|
-
handlerId,
|
|
934
|
-
priority: config.priority,
|
|
935
|
-
tags: config.tags,
|
|
936
|
-
category: config.category,
|
|
937
|
-
totalHandlers: pipeline.length,
|
|
938
|
-
registry: this.name
|
|
939
|
-
});
|
|
940
|
-
return () => {
|
|
941
|
-
const index = pipeline.findIndex((reg) => reg.id === handlerId && reg === registration);
|
|
942
|
-
if (index !== -1) {
|
|
943
|
-
pipeline.splice(index, 1);
|
|
944
|
-
if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 Handler unregistered: ${String(action)}`, {
|
|
945
|
-
handlerId,
|
|
946
|
-
remainingHandlers: pipeline.length,
|
|
947
|
-
registry: this.name
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* 🆕 실제 등록 작업 수행 (큐에서 호출됨)
|
|
954
|
-
* @deprecated Currently unused - reserved for future queue-based registration
|
|
955
|
-
*/
|
|
956
|
-
_performRegistration(action, handler, config, handlerId) {
|
|
957
|
-
const registration = {
|
|
958
|
-
handler,
|
|
959
|
-
config: {
|
|
960
|
-
priority: config.priority ?? 0,
|
|
961
|
-
id: handlerId,
|
|
962
|
-
blocking: config.blocking ?? false,
|
|
963
|
-
once: config.once ?? false,
|
|
964
|
-
condition: config.condition || (() => true),
|
|
965
692
|
debounce: config.debounce ?? void 0,
|
|
966
|
-
throttle: config.throttle ?? void 0
|
|
967
|
-
validation: config.validation ?? void 0,
|
|
968
|
-
middleware: config.middleware ?? false,
|
|
969
|
-
tags: config.tags ?? [],
|
|
970
|
-
category: config.category ?? void 0,
|
|
971
|
-
description: config.description ?? void 0,
|
|
972
|
-
version: config.version ?? void 0,
|
|
973
|
-
returnType: config.returnType ?? "value",
|
|
974
|
-
timeout: config.timeout ?? void 0,
|
|
975
|
-
retries: config.retries ?? 0,
|
|
976
|
-
dependencies: config.dependencies ?? [],
|
|
977
|
-
conflicts: config.conflicts ?? [],
|
|
978
|
-
environment: config.environment ?? void 0,
|
|
979
|
-
feature: config.feature ?? void 0,
|
|
980
|
-
metrics: config.metrics ?? {
|
|
981
|
-
collectTiming: false,
|
|
982
|
-
collectErrors: false,
|
|
983
|
-
customMetrics: {}
|
|
984
|
-
},
|
|
985
|
-
metadata: config.metadata ?? {}
|
|
693
|
+
throttle: config.throttle ?? void 0
|
|
986
694
|
},
|
|
987
695
|
id: handlerId
|
|
988
696
|
};
|
|
@@ -996,8 +704,6 @@ var ActionRegister = class {
|
|
|
996
704
|
if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 Handler registered: ${String(action)}`, {
|
|
997
705
|
handlerId,
|
|
998
706
|
priority: config.priority,
|
|
999
|
-
tags: config.tags,
|
|
1000
|
-
category: config.category,
|
|
1001
707
|
totalHandlers: pipeline.length,
|
|
1002
708
|
registry: this.name
|
|
1003
709
|
});
|
|
@@ -1024,34 +730,7 @@ var ActionRegister = class {
|
|
|
1024
730
|
*
|
|
1025
731
|
* @throws {Error} When action dispatching fails
|
|
1026
732
|
*
|
|
1027
|
-
* @
|
|
1028
|
-
* ```typescript
|
|
1029
|
-
* await register.dispatch('updateUser', {
|
|
1030
|
-
* id: '123',
|
|
1031
|
-
* name: 'John Doe',
|
|
1032
|
-
* email: 'john@example.com'
|
|
1033
|
-
* })
|
|
1034
|
-
* ```
|
|
1035
|
-
*
|
|
1036
|
-
* @example With Options
|
|
1037
|
-
* ```typescript
|
|
1038
|
-
* await register.dispatch('updateUser', payload, {
|
|
1039
|
-
* executionMode: 'parallel',
|
|
1040
|
-
* timeout: 5000,
|
|
1041
|
-
* filter: {
|
|
1042
|
-
* tags: ['validation', 'business-logic'],
|
|
1043
|
-
* excludeCategory: 'analytics'
|
|
1044
|
-
* }
|
|
1045
|
-
* })
|
|
1046
|
-
* ```
|
|
1047
|
-
*
|
|
1048
|
-
* @example With Throttling
|
|
1049
|
-
* ```typescript
|
|
1050
|
-
* await register.dispatch('searchUsers', { query: 'john' }, {
|
|
1051
|
-
* throttle: 300,
|
|
1052
|
-
* debounce: 100
|
|
1053
|
-
* })
|
|
1054
|
-
* ```
|
|
733
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1055
734
|
*
|
|
1056
735
|
* @public
|
|
1057
736
|
*/
|
|
@@ -1173,31 +852,7 @@ var ActionRegister = class {
|
|
|
1173
852
|
*
|
|
1174
853
|
* @returns Promise resolving to comprehensive execution results
|
|
1175
854
|
*
|
|
1176
|
-
* @
|
|
1177
|
-
* ```typescript
|
|
1178
|
-
* const result = await register.dispatchWithResult('updateUser', payload)
|
|
1179
|
-
*
|
|
1180
|
-
* if (result.success) {
|
|
1181
|
-
* console.log(`Executed ${result.execution.handlersExecuted} handlers`)
|
|
1182
|
-
* console.log(`Duration: ${result.execution.duration}ms`)
|
|
1183
|
-
* }
|
|
1184
|
-
* ```
|
|
1185
|
-
*
|
|
1186
|
-
* @example Advanced Result Processing
|
|
1187
|
-
* ```typescript
|
|
1188
|
-
* const result = await register.dispatchWithResult('processOrder', order, {
|
|
1189
|
-
* result: {
|
|
1190
|
-
* collect: true,
|
|
1191
|
-
* strategy: 'merge',
|
|
1192
|
-
* maxResults: 5,
|
|
1193
|
-
* merger: (results) => results.reduce((acc, curr) => ({ ...acc, ...curr }), {})
|
|
1194
|
-
* }
|
|
1195
|
-
* })
|
|
1196
|
-
*
|
|
1197
|
-
* if (result.terminated) {
|
|
1198
|
-
* console.log('Handler returned early:', result.result)
|
|
1199
|
-
* }
|
|
1200
|
-
* ```
|
|
855
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1201
856
|
*
|
|
1202
857
|
* @public
|
|
1203
858
|
*/
|
|
@@ -1378,21 +1033,9 @@ var ActionRegister = class {
|
|
|
1378
1033
|
if (!filterOptions) return handlers;
|
|
1379
1034
|
return handlers.filter((registration) => {
|
|
1380
1035
|
const config = registration.config;
|
|
1381
|
-
if (filterOptions.tags && filterOptions.tags.length > 0) {
|
|
1382
|
-
const hasMatchingTag = filterOptions.tags.some((tag) => config.tags.includes(tag));
|
|
1383
|
-
if (!hasMatchingTag) return false;
|
|
1384
|
-
}
|
|
1385
|
-
if (filterOptions.category && config.category !== filterOptions.category) return false;
|
|
1386
1036
|
if (filterOptions.handlerIds && filterOptions.handlerIds.length > 0) {
|
|
1387
1037
|
if (!filterOptions.handlerIds.includes(config.id)) return false;
|
|
1388
1038
|
}
|
|
1389
|
-
if (filterOptions.environment && config.environment !== filterOptions.environment) return false;
|
|
1390
|
-
if (filterOptions.feature && config.feature !== filterOptions.feature) return false;
|
|
1391
|
-
if (filterOptions.excludeTags && filterOptions.excludeTags.length > 0) {
|
|
1392
|
-
const hasExcludedTag = filterOptions.excludeTags.some((tag) => config.tags.includes(tag));
|
|
1393
|
-
if (hasExcludedTag) return false;
|
|
1394
|
-
}
|
|
1395
|
-
if (filterOptions.excludeCategory && config.category === filterOptions.excludeCategory) return false;
|
|
1396
1039
|
if (filterOptions.excludeHandlerIds && filterOptions.excludeHandlerIds.length > 0) {
|
|
1397
1040
|
if (filterOptions.excludeHandlerIds.includes(config.id)) return false;
|
|
1398
1041
|
}
|
|
@@ -1510,13 +1153,7 @@ var ActionRegister = class {
|
|
|
1510
1153
|
*
|
|
1511
1154
|
* @returns Number of registered handlers
|
|
1512
1155
|
*
|
|
1513
|
-
* @
|
|
1514
|
-
* ```typescript
|
|
1515
|
-
* register.register('updateUser', handler1)
|
|
1516
|
-
* register.register('updateUser', handler2)
|
|
1517
|
-
*
|
|
1518
|
-
* console.log(register.getHandlerCount('updateUser')) // 2
|
|
1519
|
-
* ```
|
|
1156
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1520
1157
|
*
|
|
1521
1158
|
* @public
|
|
1522
1159
|
*/
|
|
@@ -1531,12 +1168,7 @@ var ActionRegister = class {
|
|
|
1531
1168
|
*
|
|
1532
1169
|
* @returns True if action has handlers, false otherwise
|
|
1533
1170
|
*
|
|
1534
|
-
* @
|
|
1535
|
-
* ```typescript
|
|
1536
|
-
* if (register.hasHandlers('updateUser')) {
|
|
1537
|
-
* await register.dispatch('updateUser', userData)
|
|
1538
|
-
* }
|
|
1539
|
-
* ```
|
|
1171
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1540
1172
|
*
|
|
1541
1173
|
* @public
|
|
1542
1174
|
*/
|
|
@@ -1548,11 +1180,7 @@ var ActionRegister = class {
|
|
|
1548
1180
|
*
|
|
1549
1181
|
* @returns Array of all registered action types
|
|
1550
1182
|
*
|
|
1551
|
-
* @
|
|
1552
|
-
* ```typescript
|
|
1553
|
-
* const actions = register.getRegisteredActions()
|
|
1554
|
-
* console.log('Registered actions:', actions) // ['updateUser', 'deleteUser', 'resetUser']
|
|
1555
|
-
* ```
|
|
1183
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1556
1184
|
*
|
|
1557
1185
|
* @public
|
|
1558
1186
|
*/
|
|
@@ -1564,11 +1192,7 @@ var ActionRegister = class {
|
|
|
1564
1192
|
*
|
|
1565
1193
|
* @param action - The action type to clear handlers for
|
|
1566
1194
|
*
|
|
1567
|
-
* @
|
|
1568
|
-
* ```typescript
|
|
1569
|
-
* register.clearAction('updateUser')
|
|
1570
|
-
* console.log(register.hasHandlers('updateUser')) // false
|
|
1571
|
-
* ```
|
|
1195
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1572
1196
|
*
|
|
1573
1197
|
* @public
|
|
1574
1198
|
*/
|
|
@@ -1578,11 +1202,7 @@ var ActionRegister = class {
|
|
|
1578
1202
|
/**
|
|
1579
1203
|
* Remove all handlers for all actions
|
|
1580
1204
|
*
|
|
1581
|
-
* @
|
|
1582
|
-
* ```typescript
|
|
1583
|
-
* register.clearAll()
|
|
1584
|
-
* console.log(register.getRegisteredActions().length) // 0
|
|
1585
|
-
* ```
|
|
1205
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1586
1206
|
*
|
|
1587
1207
|
* @public
|
|
1588
1208
|
*/
|
|
@@ -1594,11 +1214,7 @@ var ActionRegister = class {
|
|
|
1594
1214
|
*
|
|
1595
1215
|
* @returns The register name
|
|
1596
1216
|
*
|
|
1597
|
-
* @
|
|
1598
|
-
* ```typescript
|
|
1599
|
-
* const register = new ActionRegister({ name: 'UserRegister' })
|
|
1600
|
-
* console.log(register.getName()) // 'UserRegister'
|
|
1601
|
-
* ```
|
|
1217
|
+
* @see https://mineclover.github.io/context-action/en/guide/patterns/action/basic-usage
|
|
1602
1218
|
*
|
|
1603
1219
|
* @public
|
|
1604
1220
|
*/
|
|
@@ -1637,13 +1253,7 @@ var ActionRegister = class {
|
|
|
1637
1253
|
});
|
|
1638
1254
|
const handlersByPriority = Array.from(priorityMap.entries()).sort(([a], [b]) => b - a).map(([priority, handlers]) => ({
|
|
1639
1255
|
priority,
|
|
1640
|
-
handlers: handlers.map((h) => ({
|
|
1641
|
-
id: h.config.id,
|
|
1642
|
-
tags: h.config.tags,
|
|
1643
|
-
category: h.config.category,
|
|
1644
|
-
description: h.config.description,
|
|
1645
|
-
version: h.config.version
|
|
1646
|
-
}))
|
|
1256
|
+
handlers: handlers.map((h) => ({ id: h.config.id }))
|
|
1647
1257
|
}));
|
|
1648
1258
|
const stats = this.executionStats.get(action);
|
|
1649
1259
|
const executionStats = stats ? {
|
|
@@ -1669,34 +1279,6 @@ var ActionRegister = class {
|
|
|
1669
1279
|
return Array.from(this.pipelines.keys()).map((action) => this.getActionStats(action)).filter((stats) => stats !== null);
|
|
1670
1280
|
}
|
|
1671
1281
|
/**
|
|
1672
|
-
* Get handlers by tag across all actions
|
|
1673
|
-
*
|
|
1674
|
-
* @param tag Tag to filter handlers by
|
|
1675
|
-
* @returns Map of actions to handlers with the specified tag
|
|
1676
|
-
*/
|
|
1677
|
-
getHandlersByTag(tag) {
|
|
1678
|
-
const result = /* @__PURE__ */ new Map();
|
|
1679
|
-
for (const [action, pipeline] of this.pipelines.entries()) {
|
|
1680
|
-
const matchingHandlers = pipeline.filter((handler) => handler.config.tags.includes(tag));
|
|
1681
|
-
if (matchingHandlers.length > 0) result.set(action, matchingHandlers);
|
|
1682
|
-
}
|
|
1683
|
-
return result;
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* Get handlers by category across all actions
|
|
1687
|
-
*
|
|
1688
|
-
* @param category Category to filter handlers by
|
|
1689
|
-
* @returns Map of actions to handlers with the specified category
|
|
1690
|
-
*/
|
|
1691
|
-
getHandlersByCategory(category) {
|
|
1692
|
-
const result = /* @__PURE__ */ new Map();
|
|
1693
|
-
for (const [action, pipeline] of this.pipelines.entries()) {
|
|
1694
|
-
const matchingHandlers = pipeline.filter((handler) => handler.config.category === category);
|
|
1695
|
-
if (matchingHandlers.length > 0) result.set(action, matchingHandlers);
|
|
1696
|
-
}
|
|
1697
|
-
return result;
|
|
1698
|
-
}
|
|
1699
|
-
/**
|
|
1700
1282
|
* Set execution mode for a specific action
|
|
1701
1283
|
*
|
|
1702
1284
|
* @param action Action name
|