@cadenza.io/core 3.18.2 → 3.19.1

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.d.mts CHANGED
@@ -1468,6 +1468,12 @@ interface EmitOptions {
1468
1468
  schedule?: boolean;
1469
1469
  exactDateTime?: Date | null;
1470
1470
  throttleBatch?: number;
1471
+ flushStrategy?: string;
1472
+ }
1473
+ type FlushStrategyName = string;
1474
+ interface FlushStrategy {
1475
+ intervalMs: number;
1476
+ maxBatchSize: number;
1471
1477
  }
1472
1478
  /**
1473
1479
  * This class manages signals and observers, enabling communication across different parts of an application.
@@ -1480,21 +1486,8 @@ declare class SignalBroker {
1480
1486
  verbose: boolean;
1481
1487
  setDebug(value: boolean): void;
1482
1488
  setVerbose(value: boolean): void;
1483
- /**
1484
- * Validates the provided signal name string to ensure it adheres to specific formatting rules.
1485
- * Throws an error if any of the validation checks fail.
1486
- *
1487
- * @param {string} signalName - The signal name to be validated.
1488
- * @return {void} - Returns nothing if the signal name is valid.
1489
- * @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
1490
- * contains backslashes, or contains uppercase letters in restricted parts of the name.
1491
- */
1492
- validateSignalName(signalName: string): void;
1493
1489
  runner: GraphRunner | undefined;
1494
1490
  metaRunner: GraphRunner | undefined;
1495
- debouncedEmitters: Map<string, any>;
1496
- squashedEmitters: Map<string, any>;
1497
- squashedContexts: Map<string, any[]>;
1498
1491
  throttleEmitters: Map<string, any>;
1499
1492
  throttleQueues: Map<string, any>;
1500
1493
  getSignalsTask: Task | undefined;
@@ -1505,7 +1498,22 @@ declare class SignalBroker {
1505
1498
  registered: boolean;
1506
1499
  }>;
1507
1500
  emittedSignalsRegistry: Set<string>;
1501
+ private flushStrategies;
1502
+ private strategyData;
1503
+ private strategyTimers;
1504
+ private isStrategyFlushing;
1505
+ private readonly defaultStrategyName;
1508
1506
  constructor();
1507
+ /**
1508
+ * Validates the provided signal name string to ensure it adheres to specific formatting rules.
1509
+ * Throws an error if any of the validation checks fail.
1510
+ *
1511
+ * @param {string} signalName - The signal name to be validated.
1512
+ * @return {void} - Returns nothing if the signal name is valid.
1513
+ * @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
1514
+ * contains backslashes, or contains uppercase letters in restricted parts of the name.
1515
+ */
1516
+ validateSignalName(signalName: string): void;
1509
1517
  /**
1510
1518
  * Initializes with runners.
1511
1519
  * @param runner Standard runner for user signals.
@@ -1518,30 +1526,28 @@ declare class SignalBroker {
1518
1526
  * @return {void} This method does not return a value.
1519
1527
  */
1520
1528
  init(): void;
1521
- /**
1522
- * Observes a signal with a routine/task.
1523
- * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards).
1524
- * @param routineOrTask The observer.
1525
- * @edge Duplicates ignored; supports wildcards for broad listening.
1526
- */
1527
- observe(signal: string, routineOrTask: Task | GraphRoutine): void;
1528
- registerEmittedSignal(signal: string): void;
1529
- /**
1530
- * Unsubscribes a routine/task from a signal.
1531
- * @param signal The signal.
1532
- * @param routineOrTask The observer.
1533
- * @edge Removes all instances if duplicate; deletes if empty.
1534
- */
1535
- unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
1536
- /**
1537
- * Schedules a signal to be emitted after a specified delay or at an exact date and time.
1538
- *
1539
- * @param {string} signal - The name of the signal to be emitted.
1540
- * @param {AnyObject} context - The context to be passed along with the signal.
1541
- * @param options
1542
- * @return {AbortController} An AbortController instance that can be used to cancel the scheduled signal emission.
1543
- */
1529
+ setFlushStrategy(name: FlushStrategyName, config: {
1530
+ intervalMs: number;
1531
+ maxBatchSize?: number;
1532
+ }): void;
1533
+ updateFlushStrategy(name: FlushStrategyName, config: FlushStrategy): void;
1534
+ removeFlushStrategy(name: FlushStrategyName): void;
1535
+ getFlushStrategies(): Record<FlushStrategyName, FlushStrategy>;
1536
+ private readonly MAX_FLUSH_DURATION_MS;
1537
+ squash(signal: string, context: AnyObject, options?: EmitOptions): void;
1538
+ private flushGroup;
1539
+ private flushStrategy;
1540
+ clearSquashState(): void;
1541
+ private scheduledBuckets;
1542
+ private scheduleTimer;
1544
1543
  schedule(signal: string, context: AnyObject, options?: EmitOptions): AbortController;
1544
+ private flushScheduled;
1545
+ private debouncedEmitters;
1546
+ private readonly MAX_DEBOUNCERS;
1547
+ debounce(signal: string, context: any, options?: {
1548
+ delayMs: number;
1549
+ }): void;
1550
+ throttle(signal: string, context: any, options?: EmitOptions): void;
1545
1551
  /**
1546
1552
  * Emits `signal` repeatedly with a fixed interval.
1547
1553
  *
@@ -1553,22 +1559,6 @@ declare class SignalBroker {
1553
1559
  * @returns a handle with `clear()` to stop the loop.
1554
1560
  */
1555
1561
  interval(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
1556
- debounce(signal: string, context: any, options?: {
1557
- delayMs: number;
1558
- }): void;
1559
- throttle(signal: string, context: any, options?: EmitOptions): void;
1560
- /**
1561
- * Aggregates and debounces multiple events with the same identifier to minimize redundant operations.
1562
- *
1563
- * @param {string} signal - The identifier for the event being emitted.
1564
- * @param {AnyObject} context - The context data associated with the event.
1565
- * @param {Object} [options] - Configuration options for handling the squashed event.
1566
- * @param {boolean} [options.squash=true] - Whether the event should be squashed.
1567
- * @param {string|null} [options.squashId=null] - A unique identifier for the squashed group of events. Defaults to the signal if null.
1568
- * @param {function|null} [options.mergeFunction=null] - A custom merge function that combines old and new contexts. If null, a default merge is used.
1569
- * @return {void} Does not return a value.
1570
- */
1571
- squash(signal: string, context: AnyObject, options?: EmitOptions): void;
1572
1562
  /**
1573
1563
  * Emits a signal with the specified context, triggering any associated handlers for that signal.
1574
1564
  *
@@ -1609,6 +1599,21 @@ declare class SignalBroker {
1609
1599
  * @return {void} This method does not return any value.
1610
1600
  */
1611
1601
  addSignal(signal: string): void;
1602
+ /**
1603
+ * Observes a signal with a routine/task.
1604
+ * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards).
1605
+ * @param routineOrTask The observer.
1606
+ * @edge Duplicates ignored; supports wildcards for broad listening.
1607
+ */
1608
+ observe(signal: string, routineOrTask: Task | GraphRoutine): void;
1609
+ registerEmittedSignal(signal: string): void;
1610
+ /**
1611
+ * Unsubscribes a routine/task from a signal.
1612
+ * @param signal The signal.
1613
+ * @param routineOrTask The observer.
1614
+ * @edge Removes all instances if duplicate; deletes if empty.
1615
+ */
1616
+ unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
1612
1617
  /**
1613
1618
  * Lists all observed signals.
1614
1619
  * @returns Array of signals.
@@ -1616,6 +1621,7 @@ declare class SignalBroker {
1616
1621
  listObservedSignals(): string[];
1617
1622
  listEmittedSignals(): string[];
1618
1623
  reset(): void;
1624
+ shutdown(): void;
1619
1625
  }
1620
1626
 
1621
1627
  /**
package/dist/index.d.ts CHANGED
@@ -1468,6 +1468,12 @@ interface EmitOptions {
1468
1468
  schedule?: boolean;
1469
1469
  exactDateTime?: Date | null;
1470
1470
  throttleBatch?: number;
1471
+ flushStrategy?: string;
1472
+ }
1473
+ type FlushStrategyName = string;
1474
+ interface FlushStrategy {
1475
+ intervalMs: number;
1476
+ maxBatchSize: number;
1471
1477
  }
1472
1478
  /**
1473
1479
  * This class manages signals and observers, enabling communication across different parts of an application.
@@ -1480,21 +1486,8 @@ declare class SignalBroker {
1480
1486
  verbose: boolean;
1481
1487
  setDebug(value: boolean): void;
1482
1488
  setVerbose(value: boolean): void;
1483
- /**
1484
- * Validates the provided signal name string to ensure it adheres to specific formatting rules.
1485
- * Throws an error if any of the validation checks fail.
1486
- *
1487
- * @param {string} signalName - The signal name to be validated.
1488
- * @return {void} - Returns nothing if the signal name is valid.
1489
- * @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
1490
- * contains backslashes, or contains uppercase letters in restricted parts of the name.
1491
- */
1492
- validateSignalName(signalName: string): void;
1493
1489
  runner: GraphRunner | undefined;
1494
1490
  metaRunner: GraphRunner | undefined;
1495
- debouncedEmitters: Map<string, any>;
1496
- squashedEmitters: Map<string, any>;
1497
- squashedContexts: Map<string, any[]>;
1498
1491
  throttleEmitters: Map<string, any>;
1499
1492
  throttleQueues: Map<string, any>;
1500
1493
  getSignalsTask: Task | undefined;
@@ -1505,7 +1498,22 @@ declare class SignalBroker {
1505
1498
  registered: boolean;
1506
1499
  }>;
1507
1500
  emittedSignalsRegistry: Set<string>;
1501
+ private flushStrategies;
1502
+ private strategyData;
1503
+ private strategyTimers;
1504
+ private isStrategyFlushing;
1505
+ private readonly defaultStrategyName;
1508
1506
  constructor();
1507
+ /**
1508
+ * Validates the provided signal name string to ensure it adheres to specific formatting rules.
1509
+ * Throws an error if any of the validation checks fail.
1510
+ *
1511
+ * @param {string} signalName - The signal name to be validated.
1512
+ * @return {void} - Returns nothing if the signal name is valid.
1513
+ * @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
1514
+ * contains backslashes, or contains uppercase letters in restricted parts of the name.
1515
+ */
1516
+ validateSignalName(signalName: string): void;
1509
1517
  /**
1510
1518
  * Initializes with runners.
1511
1519
  * @param runner Standard runner for user signals.
@@ -1518,30 +1526,28 @@ declare class SignalBroker {
1518
1526
  * @return {void} This method does not return a value.
1519
1527
  */
1520
1528
  init(): void;
1521
- /**
1522
- * Observes a signal with a routine/task.
1523
- * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards).
1524
- * @param routineOrTask The observer.
1525
- * @edge Duplicates ignored; supports wildcards for broad listening.
1526
- */
1527
- observe(signal: string, routineOrTask: Task | GraphRoutine): void;
1528
- registerEmittedSignal(signal: string): void;
1529
- /**
1530
- * Unsubscribes a routine/task from a signal.
1531
- * @param signal The signal.
1532
- * @param routineOrTask The observer.
1533
- * @edge Removes all instances if duplicate; deletes if empty.
1534
- */
1535
- unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
1536
- /**
1537
- * Schedules a signal to be emitted after a specified delay or at an exact date and time.
1538
- *
1539
- * @param {string} signal - The name of the signal to be emitted.
1540
- * @param {AnyObject} context - The context to be passed along with the signal.
1541
- * @param options
1542
- * @return {AbortController} An AbortController instance that can be used to cancel the scheduled signal emission.
1543
- */
1529
+ setFlushStrategy(name: FlushStrategyName, config: {
1530
+ intervalMs: number;
1531
+ maxBatchSize?: number;
1532
+ }): void;
1533
+ updateFlushStrategy(name: FlushStrategyName, config: FlushStrategy): void;
1534
+ removeFlushStrategy(name: FlushStrategyName): void;
1535
+ getFlushStrategies(): Record<FlushStrategyName, FlushStrategy>;
1536
+ private readonly MAX_FLUSH_DURATION_MS;
1537
+ squash(signal: string, context: AnyObject, options?: EmitOptions): void;
1538
+ private flushGroup;
1539
+ private flushStrategy;
1540
+ clearSquashState(): void;
1541
+ private scheduledBuckets;
1542
+ private scheduleTimer;
1544
1543
  schedule(signal: string, context: AnyObject, options?: EmitOptions): AbortController;
1544
+ private flushScheduled;
1545
+ private debouncedEmitters;
1546
+ private readonly MAX_DEBOUNCERS;
1547
+ debounce(signal: string, context: any, options?: {
1548
+ delayMs: number;
1549
+ }): void;
1550
+ throttle(signal: string, context: any, options?: EmitOptions): void;
1545
1551
  /**
1546
1552
  * Emits `signal` repeatedly with a fixed interval.
1547
1553
  *
@@ -1553,22 +1559,6 @@ declare class SignalBroker {
1553
1559
  * @returns a handle with `clear()` to stop the loop.
1554
1560
  */
1555
1561
  interval(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
1556
- debounce(signal: string, context: any, options?: {
1557
- delayMs: number;
1558
- }): void;
1559
- throttle(signal: string, context: any, options?: EmitOptions): void;
1560
- /**
1561
- * Aggregates and debounces multiple events with the same identifier to minimize redundant operations.
1562
- *
1563
- * @param {string} signal - The identifier for the event being emitted.
1564
- * @param {AnyObject} context - The context data associated with the event.
1565
- * @param {Object} [options] - Configuration options for handling the squashed event.
1566
- * @param {boolean} [options.squash=true] - Whether the event should be squashed.
1567
- * @param {string|null} [options.squashId=null] - A unique identifier for the squashed group of events. Defaults to the signal if null.
1568
- * @param {function|null} [options.mergeFunction=null] - A custom merge function that combines old and new contexts. If null, a default merge is used.
1569
- * @return {void} Does not return a value.
1570
- */
1571
- squash(signal: string, context: AnyObject, options?: EmitOptions): void;
1572
1562
  /**
1573
1563
  * Emits a signal with the specified context, triggering any associated handlers for that signal.
1574
1564
  *
@@ -1609,6 +1599,21 @@ declare class SignalBroker {
1609
1599
  * @return {void} This method does not return any value.
1610
1600
  */
1611
1601
  addSignal(signal: string): void;
1602
+ /**
1603
+ * Observes a signal with a routine/task.
1604
+ * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards).
1605
+ * @param routineOrTask The observer.
1606
+ * @edge Duplicates ignored; supports wildcards for broad listening.
1607
+ */
1608
+ observe(signal: string, routineOrTask: Task | GraphRoutine): void;
1609
+ registerEmittedSignal(signal: string): void;
1610
+ /**
1611
+ * Unsubscribes a routine/task from a signal.
1612
+ * @param signal The signal.
1613
+ * @param routineOrTask The observer.
1614
+ * @edge Removes all instances if duplicate; deletes if empty.
1615
+ */
1616
+ unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
1612
1617
  /**
1613
1618
  * Lists all observed signals.
1614
1619
  * @returns Array of signals.
@@ -1616,6 +1621,7 @@ declare class SignalBroker {
1616
1621
  listObservedSignals(): string[];
1617
1622
  listEmittedSignals(): string[];
1618
1623
  reset(): void;
1624
+ shutdown(): void;
1619
1625
  }
1620
1626
 
1621
1627
  /**