@context-action/core 0.7.4 β†’ 0.7.6

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.js CHANGED
@@ -50,8 +50,7 @@ async function executeSequential(context, createController) {
50
50
  try {
51
51
  if (context.aborted) break;
52
52
  if (registration.config.condition) try {
53
- const shouldExecute = registration.config.condition(context.payload);
54
- if (!shouldExecute) {
53
+ if (!registration.config.condition(context.payload)) {
55
54
  i++;
56
55
  continue;
57
56
  }
@@ -75,7 +74,6 @@ async function executeSequential(context, createController) {
75
74
  timestamp: handlerError.timestamp,
76
75
  severity: "non-blocking"
77
76
  });
78
- return void 0;
79
77
  });
80
78
  nonBlockingPromises.push(promiseWithErrorHandling);
81
79
  } else if (result !== void 0 && !context.terminated) context.results.push(result);
@@ -113,15 +111,12 @@ async function executeSequential(context, createController) {
113
111
  }
114
112
  }
115
113
  if (nonBlockingPromises.length > 0) await Promise.allSettled(nonBlockingPromises);
116
- if (errors.length > 0) {
117
- const handlerErrors = errors.map((err) => ({
118
- handlerId: err.handlerId,
119
- error: err.error,
120
- timestamp: err.timestamp,
121
- severity: "non-blocking"
122
- }));
123
- context.collectedErrors = handlerErrors;
124
- }
114
+ if (errors.length > 0) context.collectedErrors = errors.map((err) => ({
115
+ handlerId: err.handlerId,
116
+ error: err.error,
117
+ timestamp: err.timestamp,
118
+ severity: "non-blocking"
119
+ }));
125
120
  }
126
121
  /**
127
122
  * Execute handlers in parallel mode (all at once)
@@ -150,8 +145,7 @@ async function executeParallel(context, createController) {
150
145
  const controller = createController(registration, _index);
151
146
  try {
152
147
  if (registration.config.condition) try {
153
- const shouldExecute = registration.config.condition(context.payload);
154
- if (!shouldExecute) return {
148
+ if (!registration.config.condition(context.payload)) return {
155
149
  success: true,
156
150
  handlerId: registration.id,
157
151
  result: void 0,
@@ -169,10 +163,8 @@ async function executeParallel(context, createController) {
169
163
  }
170
164
  const result = registration.handler(context.payload, controller);
171
165
  let handlerResult;
172
- if (result instanceof Promise) {
173
- const resolved = await result;
174
- handlerResult = resolved;
175
- } else handlerResult = result;
166
+ if (result instanceof Promise) handlerResult = await result;
167
+ else handlerResult = result;
176
168
  /** Collect result if handler returned something and pipeline wasn't terminated */
177
169
  if (handlerResult !== void 0 && !context.terminated) context.results.push(handlerResult);
178
170
  return {
@@ -195,22 +187,15 @@ async function executeParallel(context, createController) {
195
187
  const results = await Promise.allSettled(handlerPromises);
196
188
  /** Check for any rejected blocking handlers */
197
189
  const failures = results.filter((result, index) => {
198
- if (result.status === "rejected") {
199
- const registration = runnableHandlers[index];
200
- return registration?.config.blocking ?? false;
201
- }
190
+ if (result.status === "rejected") return runnableHandlers[index]?.config.blocking ?? false;
202
191
  return false;
203
192
  });
204
- if (failures.length > 0) {
205
- const firstFailure = failures[0];
206
- throw firstFailure.reason;
207
- }
193
+ if (failures.length > 0) throw failures[0].reason;
208
194
  /** Check if any handler terminated the pipeline */
209
195
  const terminatedResults = results.filter((result) => result.status === "fulfilled" && result.value.terminated);
210
196
  if (terminatedResults.length > 0) {
211
197
  context.terminated = true;
212
- const firstTerminated = terminatedResults[0];
213
- context.terminationResult = firstTerminated.value.result;
198
+ context.terminationResult = terminatedResults[0].value.result;
214
199
  }
215
200
  }
216
201
  /**
@@ -242,8 +227,7 @@ async function executeRace(context, createController) {
242
227
  const controller = createController(registration, _index);
243
228
  try {
244
229
  if (registration.config.condition) try {
245
- const shouldExecute = registration.config.condition(context.payload);
246
- if (!shouldExecute) return {
230
+ if (!registration.config.condition(context.payload)) return {
247
231
  success: true,
248
232
  handlerId: registration.id,
249
233
  registration,
@@ -263,10 +247,8 @@ async function executeRace(context, createController) {
263
247
  }
264
248
  const result = registration.handler(context.payload, controller);
265
249
  let handlerResult;
266
- if (result instanceof Promise) {
267
- const resolved = await result;
268
- handlerResult = resolved;
269
- } else handlerResult = result;
250
+ if (result instanceof Promise) handlerResult = await result;
251
+ else handlerResult = result;
270
252
  return {
271
253
  success: true,
272
254
  handlerId: registration.id,
@@ -689,8 +671,7 @@ var OperationQueue = class {
689
671
  * πŸ†• μž‘μ—… μ™„λ£Œ μ‹ ν˜Έ - λŒ€κΈ° 쀑인 ν”„λ‘œμ„ΈμŠ€λ“€μ—κ²Œ μ•Œλ¦Ό
690
672
  */
691
673
  notifyOperationComplete() {
692
- const resolvers = this.pendingResolvers.splice(0);
693
- resolvers.forEach((resolve) => resolve());
674
+ this.pendingResolvers.splice(0).forEach((resolve) => resolve());
694
675
  }
695
676
  /**
696
677
  * πŸ†• μƒˆλ‘œμš΄ μž‘μ—… μΆ”κ°€ μ‹ ν˜Έ - processQueueμ—μ„œ 호좜
@@ -747,8 +728,7 @@ var OperationQueue = class {
747
728
  });
748
729
  this.queue = [];
749
730
  this.processingPromise = null;
750
- const resolvers = this.pendingResolvers.splice(0);
751
- resolvers.forEach((resolve) => resolve());
731
+ this.pendingResolvers.splice(0).forEach((resolve) => resolve());
752
732
  }
753
733
  /**
754
734
  * 큐 크기 쑰회
@@ -795,7 +775,7 @@ var ActionRegister = class {
795
775
  this.name = config.name || "ActionRegister";
796
776
  this.registryConfig = config.registry;
797
777
  this.maxHandlersPerAction = config.registry?.maxHandlersPerAction ?? 1e3;
798
- this.isDebugMode = Boolean(this.registryConfig?.debug && process.env.NODE_ENV === "development");
778
+ this.isDebugMode = Boolean(this.registryConfig?.debug && true);
799
779
  this.actionGuard = new ActionGuard(this.registryConfig?.autoCleanup !== false);
800
780
  if (config.registry?.useConcurrencyQueue !== false) this.dispatchQueue = new OperationQueue(`${this.name}-Dispatch`);
801
781
  if (this.registryConfig?.defaultExecutionMode) this.executionMode = this.registryConfig.defaultExecutionMode;
@@ -823,8 +803,7 @@ var ActionRegister = class {
823
803
  */
824
804
  register(action, handler, config = {}) {
825
805
  const handlerId = config.id || this.generateHandlerId(action);
826
- const unregisterFn = this._performRegistrationSync(action, handler, config, handlerId);
827
- return unregisterFn;
806
+ return this._performRegistrationSync(action, handler, config, handlerId);
828
807
  }
829
808
  /**
830
809
  * πŸ†• Unified logging method with cached debug mode check
@@ -1004,7 +983,7 @@ var ActionRegister = class {
1004
983
  options: options ? Object.keys(options) : "none",
1005
984
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
1006
985
  });
1007
- if (payload instanceof Event && process.env.NODE_ENV === "development") console.warn(`Event object passed to action "${String(action)}"`, payload.type);
986
+ if (payload instanceof Event && true) console.warn(`Event object passed to action "${String(action)}"`, payload.type);
1008
987
  const [effectiveSignal, autoAbortController, cleanup] = this.createAbortSignal(options);
1009
988
  if (options?.autoAbort?.onControllerCreated && autoAbortController) options.autoAbort.onControllerCreated(autoAbortController);
1010
989
  if (effectiveSignal?.aborted) {
@@ -1041,12 +1020,10 @@ var ActionRegister = class {
1041
1020
  }
1042
1021
  }
1043
1022
  if (debounceMs !== void 0) {
1044
- const shouldProceed = await this.actionGuard.debounce(actionKey, debounceMs);
1045
- if (!shouldProceed) return;
1023
+ if (!await this.actionGuard.debounce(actionKey, debounceMs)) return;
1046
1024
  }
1047
1025
  if (throttleMs !== void 0) {
1048
- const shouldProceed = this.actionGuard.throttle(actionKey, throttleMs);
1049
- if (!shouldProceed) return;
1026
+ if (!this.actionGuard.throttle(actionKey, throttleMs)) return;
1050
1027
  }
1051
1028
  const currentExecutionMode = options?.executionMode || this.actionExecutionModes.get(action) || this.executionMode;
1052
1029
  const context = {
@@ -1177,8 +1154,7 @@ var ActionRegister = class {
1177
1154
  let errors = [];
1178
1155
  try {
1179
1156
  await this.executePipeline(context, autoAbortController, options?.autoAbort);
1180
- const contextWithErrors = context;
1181
- errors = contextWithErrors.collectedErrors || [];
1157
+ errors = context.collectedErrors || [];
1182
1158
  const executedCount = Math.min(context.currentIndex + (context.aborted ? 0 : 1), filteredHandlers.length);
1183
1159
  for (let i = 0; i < executedCount; i++) {
1184
1160
  const handler = filteredHandlers[i];
@@ -1187,8 +1163,7 @@ var ActionRegister = class {
1187
1163
  if (handlerResult) handlerResult.executed = true;
1188
1164
  }
1189
1165
  } catch (error) {
1190
- const contextWithErrors = context;
1191
- errors = contextWithErrors.collectedErrors || [];
1166
+ errors = context.collectedErrors || [];
1192
1167
  executionError = error instanceof Error ? error : new Error(String(error));
1193
1168
  errors.push({
1194
1169
  handlerId: "pipeline",
@@ -1264,8 +1239,7 @@ var ActionRegister = class {
1264
1239
  }
1265
1240
  }
1266
1241
  if (debounceMs !== void 0) {
1267
- const shouldProceed = await this.actionGuard.debounce(actionKey, debounceMs);
1268
- if (!shouldProceed) return {
1242
+ if (!await this.actionGuard.debounce(actionKey, debounceMs)) return {
1269
1243
  success: false,
1270
1244
  aborted: true,
1271
1245
  abortReason: "Debounced execution",
@@ -1287,8 +1261,7 @@ var ActionRegister = class {
1287
1261
  };
1288
1262
  }
1289
1263
  if (throttleMs !== void 0) {
1290
- const shouldProceed = this.actionGuard.throttle(actionKey, throttleMs);
1291
- if (!shouldProceed) return {
1264
+ if (!this.actionGuard.throttle(actionKey, throttleMs)) return {
1292
1265
  success: false,
1293
1266
  aborted: true,
1294
1267
  abortReason: "Throttled execution",
@@ -1376,7 +1349,7 @@ var ActionRegister = class {
1376
1349
  if (!filterOptions) return handlers;
1377
1350
  const handlerIdSet = filterOptions.handlerIds ? new Set(filterOptions.handlerIds) : null;
1378
1351
  const excludeIdSet = filterOptions.excludeHandlerIds ? new Set(filterOptions.excludeHandlerIds) : null;
1379
- const filtered = handlers.filter((registration) => {
1352
+ return handlers.filter((registration) => {
1380
1353
  const config = registration.config;
1381
1354
  if (handlerIdSet && !handlerIdSet.has(config.id)) return false;
1382
1355
  if (excludeIdSet && excludeIdSet.has(config.id)) return false;
@@ -1388,15 +1361,14 @@ var ActionRegister = class {
1388
1361
  if (filterOptions.custom && !filterOptions.custom(config)) return false;
1389
1362
  return true;
1390
1363
  });
1391
- return filtered;
1392
1364
  }
1393
1365
  processResults(context, resultOptions) {
1394
1366
  const results = context.results;
1395
1367
  if (context.terminated && context.terminationResult !== void 0) return context.terminationResult;
1396
1368
  if (!resultOptions) return results.length > 0 ? results[results.length - 1] : void 0;
1397
- if (!resultOptions.collect && !resultOptions.strategy) return void 0;
1369
+ if (!resultOptions.collect && !resultOptions.strategy) return;
1398
1370
  const limitedResults = resultOptions.maxResults ? results.slice(0, resultOptions.maxResults) : results;
1399
- if (limitedResults.length === 0) return void 0;
1371
+ if (limitedResults.length === 0) return;
1400
1372
  switch (resultOptions.strategy) {
1401
1373
  case "first": return limitedResults[0];
1402
1374
  case "last": return limitedResults[limitedResults.length - 1];
@@ -1439,7 +1411,7 @@ var ActionRegister = class {
1439
1411
  const index = pipeline.findIndex((reg) => reg.id === registration.id);
1440
1412
  if (index !== -1) {
1441
1413
  pipeline.splice(index, 1);
1442
- if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 One-time handler removed: ${String(action)}`, {
1414
+ if (this.registryConfig?.debug && true) console.log(`🎯 One-time handler removed: ${String(action)}`, {
1443
1415
  handlerId: registration.id,
1444
1416
  remainingHandlers: pipeline.length,
1445
1417
  registry: this.name
@@ -1562,13 +1534,12 @@ var ActionRegister = class {
1562
1534
  priority,
1563
1535
  handlers: handlers.map((h) => ({ id: h.config.id }))
1564
1536
  }));
1565
- const executionStats = void 0;
1566
1537
  return {
1567
1538
  action,
1568
1539
  handlerCount: pipeline.length,
1569
1540
  totalHandlers: pipeline.length,
1570
1541
  handlersByPriority,
1571
- executionStats,
1542
+ executionStats: void 0,
1572
1543
  lastRegistered: this.lastRegisteredTimestamps.get(action)
1573
1544
  };
1574
1545
  }
@@ -1587,7 +1558,7 @@ var ActionRegister = class {
1587
1558
  */
1588
1559
  setExecutionMode(mode) {
1589
1560
  this.executionMode = mode;
1590
- if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 Global execution mode set to: ${mode}`);
1561
+ if (this.registryConfig?.debug && true) console.log(`🎯 Global execution mode set to: ${mode}`);
1591
1562
  }
1592
1563
  /**
1593
1564
  * Set execution mode for a specific action
@@ -1597,7 +1568,7 @@ var ActionRegister = class {
1597
1568
  */
1598
1569
  setActionExecutionMode(action, mode) {
1599
1570
  this.actionExecutionModes.set(action, mode);
1600
- if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 Execution mode set for action '${String(action)}': ${mode}`);
1571
+ if (this.registryConfig?.debug && true) console.log(`🎯 Execution mode set for action '${String(action)}': ${mode}`);
1601
1572
  }
1602
1573
  /**
1603
1574
  * Get execution mode for a specific action
@@ -1615,7 +1586,7 @@ var ActionRegister = class {
1615
1586
  */
1616
1587
  removeActionExecutionMode(action) {
1617
1588
  this.actionExecutionModes.delete(action);
1618
- if (this.registryConfig?.debug && process.env.NODE_ENV === "development") console.log(`🎯 Execution mode reset for action '${String(action)}' to default: ${this.executionMode}`);
1589
+ if (this.registryConfig?.debug && true) console.log(`🎯 Execution mode reset for action '${String(action)}' to default: ${this.executionMode}`);
1619
1590
  }
1620
1591
  /**
1621
1592
  * Get registry configuration (for debugging and inspection)