@camstack/system 1.1.19 → 1.1.21

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.
@@ -2,6 +2,16 @@ import { IEventBus, SystemEvent } from '@camstack/types';
2
2
  /**
3
3
  * Minimal surface the bridge requires from `LocalChildRegistry`.
4
4
  * Structurally typed so tests can provide a fake without any casts.
5
+ *
6
+ * CONTRACT: `broadcastEventToChildren` is SUBSCRIPTION-FILTERED. The registry
7
+ * fans an event only to children whose declared category-pattern set matches
8
+ * `event.category` (mirror of each child's local `SharedBusState.handlers`
9
+ * keys). A child that never declared a set (legacy/undeclared) fails OPEN and
10
+ * receives everything. The `CAMSTACK_UDS_EVENT_FANOUT` env (`filter` default /
11
+ * `shadow` / `broadcast`) is the registry-side kill-switch. The bridge itself
12
+ * needs no per-event logic change — both fan-out call sites here go through the
13
+ * filtered `broadcastEventToChildren`. `sendEventToChild` (targeted push) is
14
+ * NOT filtered — an explicit single-child send expresses intent.
5
15
  */
6
16
  export interface ChildEventBroadcaster {
7
17
  /**
@@ -22,6 +32,18 @@ export interface UdsEventBridgeDeps {
22
32
  readonly parentBus: IEventBus;
23
33
  /** This process's Moleculer node ID (e.g. `'hub'` or `'agent-a1b2c3'`). */
24
34
  readonly parentNodeId: string;
35
+ /**
36
+ * D2: subscribe the bridge's cluster/parent-local → children RELAY handler to
37
+ * the parent bus WITHOUT registering it in the node's local-interest surface
38
+ * (`subscribePassthrough` from `@camstack/system`). The bridge is a conduit to
39
+ * forked children, not a terminal local consumer — counting its wildcard `*`
40
+ * subscription would make every cross-node category appear "wanted" and defeat
41
+ * the inbound gate. When omitted (tests / legacy callers) the bridge falls
42
+ * back to `parentBus.subscribe({}, …)`, which is functionally correct but
43
+ * counts toward local interest — acceptable only where the D2 gate is not
44
+ * under test.
45
+ */
46
+ readonly subscribePassthrough?: (handler: (event: SystemEvent) => void) => () => void;
25
47
  }
26
48
  /**
27
49
  * Create the parent-side UDS ↔ Moleculer event bridge.
@@ -6,10 +6,16 @@ import { IEventBus, SystemEvent } from '@camstack/types';
6
6
  * - `emitEvent` — fire-and-forget: send a system event to the parent.
7
7
  * - `onEvent` — register the single handler for parent→child events.
8
8
  * (Only one handler is registered; calling again replaces the previous one.)
9
+ * - `updateEventPatterns` — declare this owner's live category-pattern set to
10
+ * the parent so it can subscription-filter the event fan-out. Called after
11
+ * every subscribe/unsubscribe with the CURRENT key set (full-set replace).
12
+ * Keyed by `ownerId` (the addonId) so multiple buses sharing one client
13
+ * union correctly.
9
14
  */
10
15
  export interface UdsEventChannel {
11
16
  emitEvent(event: SystemEvent): void;
12
17
  onEvent(handler: (event: SystemEvent) => void): void;
18
+ updateEventPatterns(ownerId: string, patterns: readonly string[]): void;
13
19
  }
14
20
  /**
15
21
  * Create a UDS-backed `IEventBus` for use inside a forked child process.