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