@lensmcp/core 1.16.33 → 1.17.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.
@@ -7,6 +7,25 @@ export interface EventBusOptions {
7
7
  capacity?: number;
8
8
  /** Optional hook fired when one or more events are dropped. */
9
9
  onDrop?: (droppedCount: number) => void;
10
+ /**
11
+ * Applied to every event ONCE, before any subscriber sees it — the single
12
+ * choke point for admission policy.
13
+ *
14
+ * WHY here and not at `Session`'s storage subscription: reducers subscribe
15
+ * to this bus DIRECTLY, so they are SIBLINGS of storage, not downstream of
16
+ * it. A payload-size policy applied at the storage subscription would leave
17
+ * all 16 reducers holding the untrimmed object — and they do hold it
18
+ * (`apps/flow` + `apps/graph` retain whole events, `apps/runtime` retains
19
+ * `event.raw` verbatim, `apps/valtio` + `apps/react` + `apps/visual` retain
20
+ * raw sub-objects by reference). `publish` is the only point upstream of
21
+ * every holder, so that is where the ingest clamp goes; `Session` installs
22
+ * it.
23
+ *
24
+ * Must be cheap and must not throw — it runs per event at high frequency.
25
+ * Returning the input unchanged is the expected fast path. Event ORDER is
26
+ * unaffected: this is a 1:1 map, never a filter.
27
+ */
28
+ transform?: (event: BaseEvent) => BaseEvent;
10
29
  }
11
30
  /**
12
31
  * In-process, single-threaded, bounded event bus. Subscribers are notified
@@ -19,6 +38,7 @@ export interface EventBusOptions {
19
38
  export declare class EventBus {
20
39
  readonly capacity: number;
21
40
  private readonly onDrop?;
41
+ private readonly transform?;
22
42
  private readonly subs;
23
43
  private dropped;
24
44
  constructor(opts?: EventBusOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/lib/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,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,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;CAC7C;AAOD;;;;;;;GAOG;AACH,qBAAa,QAAQ;IACnB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAkC;IAC7D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;IAChD,OAAO,CAAC,OAAO,CAAK;gBAER,IAAI,GAAE,eAAoB;IAMtC,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IA+B/B,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW;IAQnE,mDAAmD;IACnD,YAAY,IAAI,MAAM;IAItB,kDAAkD;IAClD,eAAe,IAAI,MAAM;CAG1B"}
package/lib/event-bus.js CHANGED
@@ -12,6 +12,7 @@ export class EventBus {
12
12
  this.dropped = 0;
13
13
  this.capacity = opts.capacity ?? 10_000;
14
14
  this.onDrop = opts.onDrop;
15
+ this.transform = opts.transform;
15
16
  }
16
17
  publish(event) {
17
18
  if (this.subs.size > this.capacity) {
@@ -19,11 +20,22 @@ export class EventBus {
19
20
  this.onDrop?.(1);
20
21
  return;
21
22
  }
23
+ let delivered = event;
24
+ if (this.transform) {
25
+ try {
26
+ delivered = this.transform(event) ?? event;
27
+ }
28
+ catch {
29
+ // A misbehaving transform must never swallow an event: fall back to
30
+ // the original rather than dropping observability on the floor.
31
+ delivered = event;
32
+ }
33
+ }
22
34
  for (const sub of this.subs) {
23
- if (sub.filter && !sub.filter(event))
35
+ if (sub.filter && !sub.filter(delivered))
24
36
  continue;
25
37
  try {
26
- const ret = sub.handler(event);
38
+ const ret = sub.handler(delivered);
27
39
  if (ret && typeof ret.then === 'function') {
28
40
  ret.catch(() => {
29
41
  /* swallow async handler errors; reducers must not affect bus */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/core",
3
- "version": "1.16.33",
3
+ "version": "1.17.1",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@lensmcp/protocol-types": "1.16.33",
17
+ "@lensmcp/protocol-types": "1.17.1",
18
18
  "tslib": "^2.3.0"
19
19
  },
20
20
  "license": "Apache-2.0",