@demlik/tea 0.2.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.
Files changed (196) hide show
  1. package/README.md +49 -0
  2. package/dist/agent/index.d.ts +16 -770
  3. package/dist/agent/index.js +18 -16
  4. package/dist/authed-call/index.d.ts +3 -3
  5. package/dist/authed-call/index.js +22 -36
  6. package/dist/authed-call/index.js.map +1 -1
  7. package/dist/await-terminal/index.d.ts +2 -2
  8. package/dist/await-terminal/index.js +2 -2
  9. package/dist/batch-window/index.d.ts +3 -3
  10. package/dist/batch-window/index.js +3 -3
  11. package/dist/cache/index.d.ts +2 -2
  12. package/dist/cache/index.js +5 -2
  13. package/dist/{chunk-3545BOYL.js → chunk-25LBDCBC.js} +6 -5
  14. package/dist/chunk-25LBDCBC.js.map +1 -0
  15. package/dist/{chunk-IK4S5DJN.js → chunk-2AHAR7CX.js} +7 -14
  16. package/dist/chunk-2AHAR7CX.js.map +1 -0
  17. package/dist/{chunk-IN33Q4VJ.js → chunk-2KNLKQVN.js} +3 -3
  18. package/dist/{chunk-IN33Q4VJ.js.map → chunk-2KNLKQVN.js.map} +1 -1
  19. package/dist/{chunk-VFGKTGGC.js → chunk-5W7CNAHB.js} +191 -178
  20. package/dist/chunk-5W7CNAHB.js.map +1 -0
  21. package/dist/{chunk-6GIGQT6C.js → chunk-B5RAZVXW.js} +12 -11
  22. package/dist/chunk-B5RAZVXW.js.map +1 -0
  23. package/dist/{chunk-6VDCTR7N.js → chunk-D4NJBQAH.js} +258 -151
  24. package/dist/chunk-D4NJBQAH.js.map +1 -0
  25. package/dist/{chunk-UV6UWGEO.js → chunk-D736QUGF.js} +6 -5
  26. package/dist/chunk-D736QUGF.js.map +1 -0
  27. package/dist/{chunk-EGWTT5XJ.js → chunk-ET6QQNSQ.js} +76 -95
  28. package/dist/chunk-ET6QQNSQ.js.map +1 -0
  29. package/dist/chunk-EWJP3YYP.js +21 -0
  30. package/dist/chunk-EWJP3YYP.js.map +1 -0
  31. package/dist/{chunk-M6UZT7HS.js → chunk-FCKP6N7Y.js} +6 -5
  32. package/dist/chunk-FCKP6N7Y.js.map +1 -0
  33. package/dist/{chunk-TGG26XMK.js → chunk-FV3Z5MBE.js} +10 -5
  34. package/dist/chunk-FV3Z5MBE.js.map +1 -0
  35. package/dist/chunk-G5E74IJB.js +8 -0
  36. package/dist/chunk-G5E74IJB.js.map +1 -0
  37. package/dist/{chunk-G2U7DJHL.js → chunk-JFFVBEDI.js} +3 -3
  38. package/dist/{chunk-G2U7DJHL.js.map → chunk-JFFVBEDI.js.map} +1 -1
  39. package/dist/{chunk-FOGL3TC7.js → chunk-JXYYRKD6.js} +8 -10
  40. package/dist/chunk-JXYYRKD6.js.map +1 -0
  41. package/dist/{chunk-ZDRN3YCE.js → chunk-LJJV6ZD5.js} +17 -24
  42. package/dist/chunk-LJJV6ZD5.js.map +1 -0
  43. package/dist/chunk-LYLDCIPH.js +365 -0
  44. package/dist/chunk-LYLDCIPH.js.map +1 -0
  45. package/dist/{chunk-HJO6VNQI.js → chunk-MU6MCIAC.js} +3 -3
  46. package/dist/{chunk-HJO6VNQI.js.map → chunk-MU6MCIAC.js.map} +1 -1
  47. package/dist/{chunk-UYWUVEP6.js → chunk-MUUROGIH.js} +2 -2
  48. package/dist/chunk-MUUROGIH.js.map +1 -0
  49. package/dist/{chunk-DYRKDCJI.js → chunk-PBDYW2TU.js} +41 -7
  50. package/dist/chunk-PBDYW2TU.js.map +1 -0
  51. package/dist/{chunk-5VNWZADP.js → chunk-Q2UM7BXU.js} +18 -7
  52. package/dist/chunk-Q2UM7BXU.js.map +1 -0
  53. package/dist/chunk-RMX4EOQK.js +26 -0
  54. package/dist/chunk-RMX4EOQK.js.map +1 -0
  55. package/dist/{chunk-2YOE5PIS.js → chunk-S2EGRPCM.js} +8 -6
  56. package/dist/chunk-S2EGRPCM.js.map +1 -0
  57. package/dist/{chunk-5KVHID6A.js → chunk-SPWVPIFQ.js} +4 -4
  58. package/dist/{chunk-5KVHID6A.js.map → chunk-SPWVPIFQ.js.map} +1 -1
  59. package/dist/chunk-SSHDBOXF.js +71 -0
  60. package/dist/chunk-SSHDBOXF.js.map +1 -0
  61. package/dist/{chunk-6OUDPSSG.js → chunk-TWDHNIY6.js} +3 -3
  62. package/dist/{chunk-6OUDPSSG.js.map → chunk-TWDHNIY6.js.map} +1 -1
  63. package/dist/{chunk-SC3FAFZN.js → chunk-UF4MZSLT.js} +2 -2
  64. package/dist/chunk-UF4MZSLT.js.map +1 -0
  65. package/dist/chunk-ZJ5AOYBH.js +8 -0
  66. package/dist/chunk-ZJ5AOYBH.js.map +1 -0
  67. package/dist/{chunk-LEC4U6CX.js → chunk-ZVJZ72HY.js} +3 -3
  68. package/dist/{chunk-LEC4U6CX.js.map → chunk-ZVJZ72HY.js.map} +1 -1
  69. package/dist/circuit-breaker/index.d.ts +1 -0
  70. package/dist/circuit-breaker/index.js +1 -1
  71. package/dist/{core-BmlJOvxM.d.ts → core-42kapW0n.d.ts} +96 -6
  72. package/dist/deadline/index.d.ts +77 -11
  73. package/dist/deadline/index.js +3 -3
  74. package/dist/devtools/index.js +8 -28
  75. package/dist/devtools/index.js.map +1 -1
  76. package/dist/do/index.d.ts +52 -24
  77. package/dist/do/index.js +94 -92
  78. package/dist/do/index.js.map +1 -1
  79. package/dist/{durable-effects-9LxFpmh3.d.ts → durable-effects-CFRngTNA.d.ts} +3 -3
  80. package/dist/extension/index.d.ts +25 -7
  81. package/dist/extension/index.js +4 -3
  82. package/dist/extension/index.js.map +1 -1
  83. package/dist/extension/react.js +4 -3
  84. package/dist/extension/react.js.map +1 -1
  85. package/dist/extension/subs/index.d.ts +2 -2
  86. package/dist/extension/subs/index.js +7 -10
  87. package/dist/extension/subs/index.js.map +1 -1
  88. package/dist/fan-out/index.d.ts +10 -10
  89. package/dist/fan-out/index.js +3 -3
  90. package/dist/idempotent-intake/index.d.ts +2 -2
  91. package/dist/idempotent-intake/index.js +3 -3
  92. package/dist/index.d.ts +50 -489
  93. package/dist/index.js +2 -2
  94. package/dist/llm-call/index.d.ts +3 -2
  95. package/dist/llm-call/index.js +12 -10
  96. package/dist/machine-B_BF4jij.d.ts +804 -0
  97. package/dist/machine-viz/index.d.ts +1 -1
  98. package/dist/machine-viz/index.js +2 -2
  99. package/dist/mem/index.d.ts +3 -2
  100. package/dist/mem/index.js.map +1 -1
  101. package/dist/monitored-run/index.d.ts +54 -30
  102. package/dist/monitored-run/index.js +7 -7
  103. package/dist/node/index.d.ts +3 -2
  104. package/dist/node/index.js +2 -3
  105. package/dist/node/index.js.map +1 -1
  106. package/dist/paginated-walk/index.d.ts +2 -2
  107. package/dist/paginated-walk/index.js +11 -10
  108. package/dist/parity/index.d.ts +6 -5
  109. package/dist/parity/index.js +5 -4
  110. package/dist/parity/index.js.map +1 -1
  111. package/dist/pbt/arbitraries/index.d.ts +1 -1
  112. package/dist/pbt/index.d.ts +1 -1
  113. package/dist/pbt/index.js +3 -3
  114. package/dist/pbt/index.js.map +1 -1
  115. package/dist/pbt/runners/index.d.ts +1 -1
  116. package/dist/pbt/runners/index.js +3 -3
  117. package/dist/poller/index.d.ts +59 -17
  118. package/dist/poller/index.js +56 -20
  119. package/dist/poller/index.js.map +1 -1
  120. package/dist/prediction/index.d.ts +1 -1
  121. package/dist/prediction/index.js +2 -2
  122. package/dist/pure/index.d.ts +1 -1
  123. package/dist/pure/index.js +2 -2
  124. package/dist/rate-limit/index.d.ts +2 -2
  125. package/dist/rate-limit/index.js +1 -1
  126. package/dist/react/index.d.ts +10 -3
  127. package/dist/react/index.js +2 -2
  128. package/dist/react/index.js.map +1 -1
  129. package/dist/reconciler/index.d.ts +2 -2
  130. package/dist/reconciler/index.js +13 -15
  131. package/dist/reconciler/index.js.map +1 -1
  132. package/dist/recorder/index.d.ts +20 -20
  133. package/dist/recorder/index.js +1 -1
  134. package/dist/resilient-call/index.d.ts +31 -6
  135. package/dist/resilient-call/index.js +10 -9
  136. package/dist/retry-backoff/index.d.ts +191 -14
  137. package/dist/retry-backoff/index.js +1 -1
  138. package/dist/retry-to-success/index.js +1 -1
  139. package/dist/runtime-types-CukV8kMX.d.ts +406 -0
  140. package/dist/saga/index.d.ts +3 -2
  141. package/dist/saga/index.js +2 -2
  142. package/dist/saga/index.js.map +1 -1
  143. package/dist/snapshot/index.d.ts +1 -1
  144. package/dist/snapshot/index.js +3 -3
  145. package/dist/subs/index.d.ts +372 -4
  146. package/dist/subs/index.js +4 -1
  147. package/dist/testing/index.d.ts +2 -2
  148. package/dist/testing/index.js +2 -2
  149. package/dist/throttled-input/index.d.ts +2 -2
  150. package/dist/throttled-input/index.js +14 -13
  151. package/dist/throttled-input/index.js.map +1 -1
  152. package/dist/token-refresh/index.d.ts +1 -1
  153. package/dist/token-refresh/index.js +3 -3
  154. package/dist/trace-replay/index.d.ts +12 -7
  155. package/dist/trace-replay/index.js +4 -3
  156. package/dist/{types-BoUWgwSm.d.ts → types-KbL3W1mj.d.ts} +1 -1
  157. package/dist/with-deadline/index.d.ts +1 -1
  158. package/dist/with-deadline/index.js +2 -2
  159. package/dist/with-resilience/index.d.ts +21 -2
  160. package/dist/with-resilience/index.js +12 -23
  161. package/dist/with-resilience/index.js.map +1 -1
  162. package/dist/with-telemetry/index.d.ts +1 -1
  163. package/dist/with-telemetry/index.js +2 -2
  164. package/dist/work-queue/adapter.d.ts +2 -2
  165. package/dist/work-queue/adapter.js +2 -2
  166. package/dist/work-queue/index.d.ts +3 -2
  167. package/dist/work-queue/index.js +1 -1
  168. package/dist/work-queue/index.js.map +1 -1
  169. package/dist/work-queue/ops.d.ts +2 -2
  170. package/dist/work-queue/ops.js +1 -1
  171. package/dist/workflow/index.d.ts +51 -19
  172. package/dist/workflow/index.js +71 -52
  173. package/dist/workflow/index.js.map +1 -1
  174. package/package.json +4 -1
  175. package/dist/chunk-2YOE5PIS.js.map +0 -1
  176. package/dist/chunk-3545BOYL.js.map +0 -1
  177. package/dist/chunk-5VNWZADP.js.map +0 -1
  178. package/dist/chunk-6GIGQT6C.js.map +0 -1
  179. package/dist/chunk-6VDCTR7N.js.map +0 -1
  180. package/dist/chunk-DYRKDCJI.js.map +0 -1
  181. package/dist/chunk-EGWTT5XJ.js.map +0 -1
  182. package/dist/chunk-EMJTPHI7.js +0 -91
  183. package/dist/chunk-EMJTPHI7.js.map +0 -1
  184. package/dist/chunk-FOGL3TC7.js.map +0 -1
  185. package/dist/chunk-IK4S5DJN.js.map +0 -1
  186. package/dist/chunk-M6UZT7HS.js.map +0 -1
  187. package/dist/chunk-NSDFA6M6.js +0 -198
  188. package/dist/chunk-NSDFA6M6.js.map +0 -1
  189. package/dist/chunk-SC3FAFZN.js.map +0 -1
  190. package/dist/chunk-SKAMZKTE.js +0 -20
  191. package/dist/chunk-SKAMZKTE.js.map +0 -1
  192. package/dist/chunk-TGG26XMK.js.map +0 -1
  193. package/dist/chunk-UV6UWGEO.js.map +0 -1
  194. package/dist/chunk-UYWUVEP6.js.map +0 -1
  195. package/dist/chunk-VFGKTGGC.js.map +0 -1
  196. package/dist/chunk-ZDRN3YCE.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { C as Cmd } from './core-BmlJOvxM.js';
1
+ import { C as Cmd } from './core-42kapW0n.js';
2
2
 
3
3
  /**
4
4
  * @demlik/tea/do — the durable pending-effects ledger (substrate primitive #1).
@@ -47,8 +47,8 @@ import { C as Cmd } from './core-BmlJOvxM.js';
47
47
  * - Re-firing every historical effect during replay. Only `survivingEffects`
48
48
  * (post-fold) re-emits.
49
49
  * - Assuming the receiver gets each effect exactly once. At-least-once: dedup
50
- * by `id` at the receiver (`hasOwed` / `isConfirmed` here are the sender's
51
- * view; the receiver owns its own dedup).
50
+ * by `id` at the receiver (`isOwed` here is the sender's view; the receiver
51
+ * owns its own dedup).
52
52
  */
53
53
 
54
54
  /** Monotonic, gap-free delivery id — the single correlation + dedup key. */
@@ -1,5 +1,5 @@
1
- import { Runtime, Store } from '../index.js';
2
- import '../core-BmlJOvxM.js';
1
+ import { R as Runtime, S as Store } from '../runtime-types-CukV8kMX.js';
2
+ import '../core-42kapW0n.js';
3
3
 
4
4
  /**
5
5
  * Runtime bridge — expose a `@demlik/tea` runtime running in one chrome context
@@ -32,8 +32,22 @@ import '../core-BmlJOvxM.js';
32
32
  * delivery guarantees should layer their own retry, not bake it here.
33
33
  */
34
34
 
35
- interface BridgeRuntimeOpts<S, V = S> {
35
+ interface BridgeRuntimeOpts<S, M, V = S> {
36
36
  channel: string;
37
+ /**
38
+ * REQUIRED parse for inbound `msg` payloads on `:dispatch` envelopes.
39
+ * Chrome runtime messages are an `unknown` boundary (Inv 8) — the same
40
+ * JSON/chrome serialization seam the symmetric client side parses via
41
+ * `BridgeClientOpts.parseMsg`. An untrusted surface can drive the host
42
+ * reducer with an arbitrary `M`, so the host parses too — never casts. A
43
+ * `msg` that parses to `null` is dropped: the dispatch never reaches the
44
+ * reducer and the surface's `dispatch()` rejects with `{ ok: false }`.
45
+ *
46
+ * Hosts that trust the dispatch channel and treat the msg as opaque opt
47
+ * out EXPLICITLY by passing the {@link passThroughMsg} helper — the unsound
48
+ * cast is then a visible call-site decision, not a silent default.
49
+ */
50
+ parseMsg: (raw: unknown) => M | null;
37
51
  /**
38
52
  * Optional projection from the runtime's live state `S` to a JSON-safe
39
53
  * view `V` that goes over the wire (broadcast + hydrate). Required when
@@ -86,13 +100,16 @@ interface BridgeRuntimeOpts<S, V = S> {
86
100
  * is mid-boot (store load not yet resolved), `getState()` throws — we
87
101
  * swallow and reply with `state: null`; surfaces should treat null as
88
102
  * "not ready yet" and wait for the first broadcast.
89
- * - **Dispatch:** `{ type: ":dispatch", msg }` routes to `runtime.dispatch`.
90
- * Returns `true` from the listener so chrome keeps the message channel
91
- * open until dispatch's promise settles (we ack with `{ ok: true }`).
103
+ * - **Dispatch:** `{ type: ":dispatch", msg }` is parsed through `parseMsg`
104
+ * (Inv 8 — inbound msgs are an `unknown` boundary) and, if non-null, routes
105
+ * to `runtime.dispatch`. Returns `true` from the listener so chrome keeps the
106
+ * message channel open until dispatch's promise settles (we ack with
107
+ * `{ ok: true }`). A msg that fails the parse is dropped — the reducer never
108
+ * sees it and we reply `{ ok: false }`.
92
109
  */
93
110
  declare function bridgeRuntime<S, M extends {
94
111
  type: string;
95
- }, V = S>(runtime: Runtime<S, M>, { channel, serialize, historySize }: BridgeRuntimeOpts<S, V>): () => void;
112
+ }, V = S>(runtime: Runtime<S, M>, { channel, parseMsg, serialize, historySize }: BridgeRuntimeOpts<S, M, V>): () => void;
96
113
  /**
97
114
  * The explicit opt-out of inbound msg parsing: an identity pass-through that
98
115
  * casts the raw `unknown` to `M`. Surfaces that gate only on state and treat
@@ -188,6 +205,7 @@ declare function bridgeTabClient<S, M extends {
188
205
  }>({ tabId, channel, parseState, parseMsg, }: BridgeTabClientOpts<S, M>): BridgeClient<S, M>;
189
206
 
190
207
  /**
208
+ * @packageDocumentation
191
209
  * @demlik/tea/extension — Chrome service-worker host adapter for @demlik/tea.
192
210
  *
193
211
  * Substrate-level companion to @demlik/tea/do (Durable Objects) and
@@ -1,6 +1,7 @@
1
- export { bridgeClient, bridgeRuntime, bridgeTabClient, passThroughMsg } from '../chunk-EGWTT5XJ.js';
2
- import '../chunk-6VDCTR7N.js';
3
- import '../chunk-DYRKDCJI.js';
1
+ export { bridgeClient, bridgeRuntime, bridgeTabClient, passThroughMsg } from '../chunk-ET6QQNSQ.js';
2
+ import '../chunk-G5E74IJB.js';
3
+ import '../chunk-D4NJBQAH.js';
4
+ import '../chunk-PBDYW2TU.js';
4
5
 
5
6
  // src/extension/index.ts
6
7
  var MALFORMED = "chromeStorageStore: stored value is not a string";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/extension/index.ts"],"names":[],"mappings":";;;;;AAkCA,IAAM,SAAA,GAAY,kDAAA;AAqBX,SAAS,mBACd,GAAA,EACA,KAAA,EACA,IAAA,GAAmC,MAAA,CAAO,QAAQ,KAAA,EACxC;AACV,EAAA,OAAO;AAAA,IACL,MAAM,IAAA,GAAyB;AAC7B,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA;AACjC,MAAA,MAAM,GAAA,GAAO,OAAmC,GAAG,CAAA;AACnD,MAAA,IAAI,GAAA,KAAQ,MAAA,IAAa,GAAA,KAAQ,IAAA,EAAM,OAAO,IAAA;AAC9C,MAAA,IAAI,OAAO,GAAA,KAAQ,QAAA;AACjB,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,SAAA,EAAY,GAAG,CAAA,CAAA,CAAG,CAAA;AAKhD,MAAA,OAAO,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,IACvB,CAAA;AAAA,IACA,MAAM,KAAK,KAAA,EAAyB;AAClC,MAAA,MAAM,IAAA,CAAK,GAAA,CAAI,EAAE,CAAC,GAAG,GAAG,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA,EAAG,CAAA;AAAA,IACjD,CAAA;AAAA,IACA,QAAQ,GAAA,EAAwB;AAC9B,MAAA,OAAO,MAAM,GAAG,CAAA;AAAA,IAClB;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * @demlik/tea/extension — Chrome service-worker host adapter for @demlik/tea.\n *\n * Substrate-level companion to @demlik/tea/do (Durable Objects) and\n * @demlik/tea/react (React). Lets a chrome service worker run a @demlik/tea\n * machine with persistence backed by chrome.storage.\n *\n * Single export: chromeStorageStore<S>(key, area?). Apps register chrome.*\n * listeners themselves and call runtime.dispatch from inside the handler —\n * those wiring patterns are app-specific (different extensions register\n * different listener sets, with different Msg adapters), so we don't\n * abstract them here until the shape stabilizes across consumers.\n */\n\nimport type { Store } from \"../index\";\n\nexport type {\n BridgeClient,\n BridgeClientOpts,\n BridgeRuntimeOpts,\n BridgeTabClientOpts,\n} from \"./bridge\";\n// Re-export the wire-envelope types — surfaces that test against the\n// bridge can pin the shapes without round-tripping through the runtime.\n// Re-export the runtime bridge primitives. The React adapter lives at\n// `@demlik/tea/extension/react` so the main entry stays react-free for the\n// background service-worker side.\nexport {\n bridgeClient,\n bridgeRuntime,\n bridgeTabClient,\n passThroughMsg,\n} from \"./bridge\";\n\nconst MALFORMED = \"chromeStorageStore: stored value is not a string\";\n\n/**\n * `Store<S>` backed by `chrome.storage.local` (or any compatible\n * `StorageArea`). JSON.stringify on save, JSON.parse on load. Returns `null`\n * (typed as `unknown` per `Store<S>.load` contract) when the key is absent.\n *\n * Throws on the structural layer if the stored value is malformed (non-string\n * at the key, or unparseable JSON) — matches @demlik/tea/do's \"throw at boot via\n * store.load\" contract so tea's `run()` surfaces it predictably. The\n * `parse` callback handles the semantic layer (shape mismatch → return\n * `null`); it must NOT throw, per the `Store<S>.migrate` contract.\n *\n * `parse` is REQUIRED because chrome.storage is a real serialization boundary\n * — JSON to disk, then back — and the structural type of what comes back is\n * `unknown`. The caller (extension code that knows `S`) is the only party\n * with enough information to write the parse. There is no honest default.\n *\n * `area` defaults to `chrome.storage.local` for production. Tests pass a\n * `fakeChrome().storage.local` in.\n */\nexport function chromeStorageStore<S>(\n key: string,\n parse: (raw: unknown) => S | null,\n area: chrome.storage.StorageArea = chrome.storage.local,\n): Store<S> {\n return {\n async load(): Promise<unknown> {\n const result = await area.get(key);\n const raw = (result as Record<string, unknown>)[key];\n if (raw === undefined || raw === null) return null;\n if (typeof raw !== \"string\")\n throw new Error(`${MALFORMED} at key \"${key}\"`);\n // JSON.parse throws on malformed — propagate per @demlik/tea/do parity.\n // The decoded value is intentionally returned as `unknown`; the\n // substrate's `migrate` callback (forwarded from `parse`) is the\n // boundary parse that turns it into `S | null`.\n return JSON.parse(raw);\n },\n async save(state: S): Promise<void> {\n await area.set({ [key]: JSON.stringify(state) });\n },\n migrate(raw: unknown): S | null {\n return parse(raw);\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/extension/index.ts"],"names":[],"mappings":";;;;;;AAmCA,IAAM,SAAA,GAAY,kDAAA;AAqBX,SAAS,mBACd,GAAA,EACA,KAAA,EACA,IAAA,GAAmC,MAAA,CAAO,QAAQ,KAAA,EACxC;AACV,EAAA,OAAO;AAAA,IACL,MAAM,IAAA,GAAyB;AAC7B,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA;AACjC,MAAA,MAAM,GAAA,GAAO,OAAmC,GAAG,CAAA;AACnD,MAAA,IAAI,GAAA,KAAQ,MAAA,IAAa,GAAA,KAAQ,IAAA,EAAM,OAAO,IAAA;AAC9C,MAAA,IAAI,OAAO,GAAA,KAAQ,QAAA;AACjB,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,SAAA,EAAY,GAAG,CAAA,CAAA,CAAG,CAAA;AAKhD,MAAA,OAAO,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,IACvB,CAAA;AAAA,IACA,MAAM,KAAK,KAAA,EAAyB;AAClC,MAAA,MAAM,IAAA,CAAK,GAAA,CAAI,EAAE,CAAC,GAAG,GAAG,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA,EAAG,CAAA;AAAA,IACjD,CAAA;AAAA,IACA,QAAQ,GAAA,EAAwB;AAC9B,MAAA,OAAO,MAAM,GAAG,CAAA;AAAA,IAClB;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * @packageDocumentation\n * @demlik/tea/extension — Chrome service-worker host adapter for @demlik/tea.\n *\n * Substrate-level companion to @demlik/tea/do (Durable Objects) and\n * @demlik/tea/react (React). Lets a chrome service worker run a @demlik/tea\n * machine with persistence backed by chrome.storage.\n *\n * Single export: chromeStorageStore<S>(key, area?). Apps register chrome.*\n * listeners themselves and call runtime.dispatch from inside the handler —\n * those wiring patterns are app-specific (different extensions register\n * different listener sets, with different Msg adapters), so we don't\n * abstract them here until the shape stabilizes across consumers.\n */\n\nimport type { Store } from \"../index\";\n\nexport type {\n BridgeClient,\n BridgeClientOpts,\n BridgeRuntimeOpts,\n BridgeTabClientOpts,\n} from \"./bridge\";\n// Re-export the wire-envelope types — surfaces that test against the\n// bridge can pin the shapes without round-tripping through the runtime.\n// Re-export the runtime bridge primitives. The React adapter lives at\n// `@demlik/tea/extension/react` so the main entry stays react-free for the\n// background service-worker side.\nexport {\n bridgeClient,\n bridgeRuntime,\n bridgeTabClient,\n passThroughMsg,\n} from \"./bridge\";\n\nconst MALFORMED = \"chromeStorageStore: stored value is not a string\";\n\n/**\n * `Store<S>` backed by `chrome.storage.local` (or any compatible\n * `StorageArea`). JSON.stringify on save, JSON.parse on load. Returns `null`\n * (typed as `unknown` per `Store<S>.load` contract) when the key is absent.\n *\n * Throws on the structural layer if the stored value is malformed (non-string\n * at the key, or unparseable JSON) — matches @demlik/tea/do's \"throw at boot via\n * store.load\" contract so tea's `run()` surfaces it predictably. The\n * `parse` callback handles the semantic layer (shape mismatch → return\n * `null`); it must NOT throw, per the `Store<S>.migrate` contract.\n *\n * `parse` is REQUIRED because chrome.storage is a real serialization boundary\n * — JSON to disk, then back — and the structural type of what comes back is\n * `unknown`. The caller (extension code that knows `S`) is the only party\n * with enough information to write the parse. There is no honest default.\n *\n * `area` defaults to `chrome.storage.local` for production. Tests pass a\n * `fakeChrome().storage.local` in.\n */\nexport function chromeStorageStore<S>(\n key: string,\n parse: (raw: unknown) => S | null,\n area: chrome.storage.StorageArea = chrome.storage.local,\n): Store<S> {\n return {\n async load(): Promise<unknown> {\n const result = await area.get(key);\n const raw = (result as Record<string, unknown>)[key];\n if (raw === undefined || raw === null) return null;\n if (typeof raw !== \"string\")\n throw new Error(`${MALFORMED} at key \"${key}\"`);\n // JSON.parse throws on malformed — propagate per @demlik/tea/do parity.\n // The decoded value is intentionally returned as `unknown`; the\n // substrate's `migrate` callback (forwarded from `parse`) is the\n // boundary parse that turns it into `S | null`.\n return JSON.parse(raw);\n },\n async save(state: S): Promise<void> {\n await area.set({ [key]: JSON.stringify(state) });\n },\n migrate(raw: unknown): S | null {\n return parse(raw);\n },\n };\n}\n"]}
@@ -1,6 +1,7 @@
1
- import { bridgeClient, passThroughMsg } from '../chunk-EGWTT5XJ.js';
2
- import '../chunk-6VDCTR7N.js';
3
- import '../chunk-DYRKDCJI.js';
1
+ import { bridgeClient, passThroughMsg } from '../chunk-ET6QQNSQ.js';
2
+ import '../chunk-G5E74IJB.js';
3
+ import '../chunk-D4NJBQAH.js';
4
+ import '../chunk-PBDYW2TU.js';
4
5
  import { useRef, useSyncExternalStore, useEffect, useCallback, createContext, useMemo, useContext } from 'react';
5
6
  import { jsx } from 'react/jsx-runtime';
6
7
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/extension/react.tsx"],"names":[],"mappings":";;;;;;AAoFO,SAAS,oBAAA,CAAoD;AAAA,EAClE,OAAA;AAAA,EACA;AACF,CAAA,EAAkE;AAIhE,EAAA,MAAM,SAAA,GAAY,OAAqD,IAAI,CAAA;AAC3E,EAAA,IAAI,SAAA,CAAU,YAAY,IAAA,EAAM;AAI9B,IAAA,SAAA,CAAU,UAAU,YAAA,CAAmB;AAAA,MACrC,OAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA,EAAU;AAAA,KACX,CAAA;AAAA,EACH;AACA,EAAA,MAAM,SAAS,SAAA,CAAU,OAAA;AAEzB,EAAA,MAAM,KAAA,GAAQ,oBAAA;AAAA,IACZ,MAAA,CAAO,SAAA;AAAA,IACP,MAAA,CAAO,WAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AAQA,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAA,CAAO,OAAA,EAAQ,CAAE,KAAA,CAAM,MAAM;AAAA,IAE7B,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,MAAM,QAAA,GAAW,WAAA;AAAA,IACf,OAAO,GAAA,KAA0B;AAC/B,MAAA,MAAM,MAAA,CAAO,SAAS,GAAG,CAAA;AAAA,IAC3B,CAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B;AA6DA,IAAM,cAAA,GACJ,+HAAA;AAEK,SAAS,8BAAA,GAGoB;AAIlC,EAAA,MAAM,GAAA,GAAM,cAAuD,IAAI,CAAA;AAEvE,EAAA,SAAS,QAAA,CAAS;AAAA,IAChB,IAAA;AAAA,IACA;AAAA,GACF,EAGc;AACZ,IAAA,MAAM,MAAA,GAAS,qBAA2B,IAAI,CAAA;AAO9C,IAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,MACZ,OAAO,EAAE,KAAA,EAAO,OAAO,KAAA,EAAO,QAAA,EAAU,OAAO,QAAA,EAAS,CAAA;AAAA,MACxD,CAAC,MAAA,CAAO,KAAA,EAAO,MAAA,CAAO,QAAQ;AAAA,KAChC;AACA,IAAA,uBAAO,GAAA,CAAC,GAAA,CAAI,QAAA,EAAJ,EAAa,OAAe,QAAA,EAAS,CAAA;AAAA,EAC/C;AAEA,EAAA,SAAS,UAAA,GAA+C;AACtD,IAAA,MAAM,GAAA,GAAM,WAAW,GAAG,CAAA;AAC1B,IAAA,IAAI,GAAA,KAAQ,IAAA,EAAM,MAAM,IAAI,MAAM,cAAc,CAAA;AAChD,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,SAAS,WAAA,GAAyC;AAChD,IAAA,OAAO,YAAW,CAAE,QAAA;AAAA,EACtB;AAOA,EAAA,SAAS,aAAgB,QAAA,EAAmD;AAC1E,IAAA,MAAM,EAAE,KAAA,EAAM,GAAI,UAAA,EAAW;AAC7B,IAAA,IAAI,QAAA,KAAa,QAAW,OAAO,KAAA;AACnC,IAAA,OAAO,SAAS,KAAK,CAAA;AAAA,EACvB;AAEA,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA,EAAU,YAAA;AAAA,IACV;AAAA,GACF;AACF","file":"react.js","sourcesContent":["/**\n * React adapters for the background TEA runtime.\n *\n * Two layers, both built on the same `bridgeClient`:\n *\n * 1. `useBackgroundRuntime(opts)` — direct hook. One bridge client per\n * call. Surfaces that only have a single consumer mount it inline.\n *\n * 2. `createBackgroundRuntimeContext<S, M>()` → `{ Provider, useDispatch,\n * useState, useRuntime }` — factory-style React context. Mounts the\n * bridge client ONCE inside the Provider; child hooks read `state` /\n * `dispatch` from context. Surfaces that drill `dispatch` through\n * multiple component layers, or mount `useBackgroundRuntime` more\n * than once for the same channel, should use this instead.\n *\n * Why a factory (not a single global context):\n * - Type safety: each app types it against its own `S` / `M`.\n * - Tests can mount fresh contexts per test (no module-level state to\n * reset).\n * - Multiple-runtimes case: an app COULD theoretically have two\n * background-shaped runtimes (e.g. one per channel); the factory\n * pattern doesn't preclude it.\n *\n * Hook lifecycle (`useBackgroundRuntime`) — preserved from the prior\n * single-export module:\n * 1. `useSyncExternalStore` subscribes to broadcasts via\n * `bridgeClient.subscribe`, reading the latest state via\n * `bridgeClient.getSnapshot`. Reference stability is owned by the\n * bridge — `getSnapshot` returns the SAME `S` until a new broadcast\n * overwrites it, so React doesn't loop.\n * 2. A one-shot `hydrate()` call seeds `latestState` before the first\n * broadcast arrives. The hydrate side-effect runs in an effect so the\n * first render shows `null` and the subsequent render flips to the\n * hydrated snapshot (or stays null if the host is still booting).\n * 3. `dispatch(msg)` sends `:dispatch` envelopes.\n *\n * On unmount: `useSyncExternalStore` removes the listener; the host's\n * bridge stays installed.\n *\n * Canon §3.1: React adapters use `useSyncExternalStore`, not\n * `useState + useEffect`. `useMachine` and `useRuntime` already follow this\n * — `useBackgroundRuntime` (and by extension the Provider) does too. One\n * Way to Do Each Thing.\n *\n * NOTE: This is a separate entry from the main `index.ts` so apps that\n * never need React don't drag react into their type graph. The React\n * adapter peer-depends on react (you must have it installed in the app).\n */\n\n\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport { bridgeClient, passThroughMsg } from \"./bridge\";\n\nexport interface UseBackgroundRuntimeOpts<S> {\n channel: string;\n /**\n * REQUIRED parse for inbound `state` payloads. Forwarded to\n * `bridgeClient` — see `BridgeClientOpts.parseState`. Surfaces own this\n * because the chrome.runtime boundary is `unknown` (Inv 8). Returning\n * `null` drops the payload silently.\n */\n parseState: (raw: unknown) => S | null;\n}\n\nexport interface UseBackgroundRuntimeResult<S, M> {\n /** Latest snapshot from the host. `null` until the first hydrate response\n * or the first broadcast arrives. Surfaces SHOULD render a placeholder\n * for the null window. */\n state: S | null;\n /** Send a msg to the host runtime. Resolves once the host's dispatch\n * settles. */\n dispatch(msg: M): Promise<void>;\n}\n\nexport function useBackgroundRuntime<S, M extends { type: string }>({\n channel,\n parseState,\n}: UseBackgroundRuntimeOpts<S>): UseBackgroundRuntimeResult<S, M> {\n // Pin the client across renders. Identity must be stable because\n // `useSyncExternalStore` deduplicates subscribe by reference; rebuilding\n // the client every render would re-register listeners every render too.\n const clientRef = useRef<ReturnType<typeof bridgeClient<S, M>> | null>(null);\n if (clientRef.current === null) {\n // This hook surfaces only `state`; the broadcast msg is unused, so it\n // explicitly opts out of msg parsing via `passThroughMsg`. Same behavior\n // as the former optional-`parseMsg` default, now a visible decision.\n clientRef.current = bridgeClient<S, M>({\n channel,\n parseState,\n parseMsg: passThroughMsg,\n });\n }\n const client = clientRef.current;\n\n const state = useSyncExternalStore<S | null>(\n client.subscribe,\n client.getSnapshot,\n client.getSnapshot,\n );\n\n // One-shot hydrate on mount. The hydrate response primes `getSnapshot`\n // before the first broadcast lands so newly-opened surfaces show the\n // right view immediately. We don't read its return value — the hook\n // re-renders when `useSyncExternalStore` notices the snapshot change.\n // Hydrate failures (host not present yet) are swallowed; surfaces wait\n // for the next broadcast.\n useEffect(() => {\n client.hydrate().catch(() => {\n // No host yet. Surfaces fall back to broadcasts.\n });\n }, [client]);\n\n const dispatch = useCallback(\n async (msg: M): Promise<void> => {\n await client.dispatch(msg);\n },\n [client],\n );\n\n return { state, dispatch };\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider + consumer hooks — factory-style React context.\n//\n// `createBackgroundRuntimeContext<S, M>()` returns a `{ Provider, useDispatch,\n// useState, useRuntime }` tuple bound to the caller's `S` / `M`. The\n// Provider mounts `useBackgroundRuntime(opts)` ONCE internally and shares\n// the `{ state, dispatch }` pair via context. Child consumers (anywhere in\n// the tree) read the slice they need — no prop drilling, single bridge\n// client per channel per Provider mount.\n//\n// The factory is generic; the returned hooks throw a clear error if used\n// outside the Provider so the failure mode is \"loud and obvious\" rather\n// than \"silently returns null state forever\".\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface BackgroundRuntimeContext<S, M> {\n /**\n * Wrap a subtree to share a single background-runtime bridge client.\n * `opts` is forwarded verbatim to `useBackgroundRuntime` — same channel,\n * same parse contract.\n */\n Provider: (props: {\n opts: UseBackgroundRuntimeOpts<S>;\n children: ReactNode;\n }) => ReactNode;\n /**\n * Returns the dispatch function bound to this Provider's bridge client.\n * Reference is stable across renders (per `useBackgroundRuntime`'s\n * `useCallback`), so passing it to memoized children won't churn them.\n */\n useDispatch: () => (msg: M) => Promise<void>;\n /**\n * Returns a slice of the latest state. `selector` defaults to identity\n * (returns the whole `S | null` snapshot). Selectors run on every state\n * change — surfaces with expensive transforms should memoize the\n * selector at call site.\n *\n * Returns `null` until the first hydrate / broadcast lands when the\n * selector is identity; for non-identity selectors the return type is\n * `T` and the caller's selector decides how to handle the pre-hydrate\n * `null` snapshot.\n */\n useState: {\n (): S | null;\n <T>(selector: (state: S | null) => T): T;\n };\n /**\n * Escape hatch — returns the full `{ state, dispatch }` pair as-is.\n * Useful for consumers that want both the snapshot and the dispatch\n * fn in a single hook call (e.g. effects that read state THEN\n * dispatch in response).\n *\n * Not a `@demlik/tea` `Runtime<S, M>` — the bridge surface is a thinner\n * client. This hook returns the same shape as `useBackgroundRuntime`,\n * just sourced from context instead of mounting a fresh client.\n */\n useRuntime: () => UseBackgroundRuntimeResult<S, M>;\n}\n\nconst PROVIDER_ERROR =\n \"createBackgroundRuntimeContext: hook used outside its Provider. Wrap the consumer in <BackgroundRuntime.Provider opts={...}>.\";\n\nexport function createBackgroundRuntimeContext<\n S,\n M extends { type: string },\n>(): BackgroundRuntimeContext<S, M> {\n // `null` is the \"not inside a Provider\" sentinel — the hooks below\n // throw on read. Distinct from `state: null` (pre-hydrate), which IS a\n // valid context value.\n const Ctx = createContext<UseBackgroundRuntimeResult<S, M> | null>(null);\n\n function Provider({\n opts,\n children,\n }: {\n opts: UseBackgroundRuntimeOpts<S>;\n children: ReactNode;\n }): ReactNode {\n const result = useBackgroundRuntime<S, M>(opts);\n // Stabilize the context value reference so consumers that subscribe via\n // `useContext` don't re-render unless `state` or `dispatch` actually\n // changes. `state` is reference-stable (bridge's `getSnapshot` returns\n // the same `S` until a new broadcast). `dispatch` is stable per\n // `useBackgroundRuntime`'s `useCallback`. So `useMemo` keyed on both\n // gives a stable value object across renders.\n const value = useMemo<UseBackgroundRuntimeResult<S, M>>(\n () => ({ state: result.state, dispatch: result.dispatch }),\n [result.state, result.dispatch],\n );\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n function useRuntime(): UseBackgroundRuntimeResult<S, M> {\n const ctx = useContext(Ctx);\n if (ctx === null) throw new Error(PROVIDER_ERROR);\n return ctx;\n }\n\n function useDispatch(): (msg: M) => Promise<void> {\n return useRuntime().dispatch;\n }\n\n // Two-overload `useState` so callers see `S | null` without passing a\n // selector and `T` when they do. The runtime body collapses them — if\n // `selector` is omitted we pass identity through.\n function useStateHook(): S | null;\n function useStateHook<T>(selector: (state: S | null) => T): T;\n function useStateHook<T>(selector?: (state: S | null) => T): T | (S | null) {\n const { state } = useRuntime();\n if (selector === undefined) return state;\n return selector(state);\n }\n\n return {\n Provider,\n useDispatch,\n useState: useStateHook,\n useRuntime,\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/extension/react.tsx"],"names":[],"mappings":";;;;;;;AAoFO,SAAS,oBAAA,CAAoD;AAAA,EAClE,OAAA;AAAA,EACA;AACF,CAAA,EAAkE;AAIhE,EAAA,MAAM,SAAA,GAAY,OAAqD,IAAI,CAAA;AAC3E,EAAA,IAAI,SAAA,CAAU,YAAY,IAAA,EAAM;AAI9B,IAAA,SAAA,CAAU,UAAU,YAAA,CAAmB;AAAA,MACrC,OAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA,EAAU;AAAA,KACX,CAAA;AAAA,EACH;AACA,EAAA,MAAM,SAAS,SAAA,CAAU,OAAA;AAEzB,EAAA,MAAM,KAAA,GAAQ,oBAAA;AAAA,IACZ,MAAA,CAAO,SAAA;AAAA,IACP,MAAA,CAAO,WAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AAQA,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAA,CAAO,OAAA,EAAQ,CAAE,KAAA,CAAM,MAAM;AAAA,IAE7B,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,MAAM,QAAA,GAAW,WAAA;AAAA,IACf,OAAO,GAAA,KAA0B;AAC/B,MAAA,MAAM,MAAA,CAAO,SAAS,GAAG,CAAA;AAAA,IAC3B,CAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B;AA6DA,IAAM,cAAA,GACJ,+HAAA;AAEK,SAAS,8BAAA,GAGoB;AAIlC,EAAA,MAAM,GAAA,GAAM,cAAuD,IAAI,CAAA;AAEvE,EAAA,SAAS,QAAA,CAAS;AAAA,IAChB,IAAA;AAAA,IACA;AAAA,GACF,EAGc;AACZ,IAAA,MAAM,MAAA,GAAS,qBAA2B,IAAI,CAAA;AAO9C,IAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,MACZ,OAAO,EAAE,KAAA,EAAO,OAAO,KAAA,EAAO,QAAA,EAAU,OAAO,QAAA,EAAS,CAAA;AAAA,MACxD,CAAC,MAAA,CAAO,KAAA,EAAO,MAAA,CAAO,QAAQ;AAAA,KAChC;AACA,IAAA,uBAAO,GAAA,CAAC,GAAA,CAAI,QAAA,EAAJ,EAAa,OAAe,QAAA,EAAS,CAAA;AAAA,EAC/C;AAEA,EAAA,SAAS,UAAA,GAA+C;AACtD,IAAA,MAAM,GAAA,GAAM,WAAW,GAAG,CAAA;AAC1B,IAAA,IAAI,GAAA,KAAQ,IAAA,EAAM,MAAM,IAAI,MAAM,cAAc,CAAA;AAChD,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,SAAS,WAAA,GAAyC;AAChD,IAAA,OAAO,YAAW,CAAE,QAAA;AAAA,EACtB;AAOA,EAAA,SAAS,aAAgB,QAAA,EAAmD;AAC1E,IAAA,MAAM,EAAE,KAAA,EAAM,GAAI,UAAA,EAAW;AAC7B,IAAA,IAAI,QAAA,KAAa,QAAW,OAAO,KAAA;AACnC,IAAA,OAAO,SAAS,KAAK,CAAA;AAAA,EACvB;AAEA,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA,EAAU,YAAA;AAAA,IACV;AAAA,GACF;AACF","file":"react.js","sourcesContent":["/**\n * React adapters for the background TEA runtime.\n *\n * Two layers, both built on the same `bridgeClient`:\n *\n * 1. `useBackgroundRuntime(opts)` — direct hook. One bridge client per\n * call. Surfaces that only have a single consumer mount it inline.\n *\n * 2. `createBackgroundRuntimeContext<S, M>()` → `{ Provider, useDispatch,\n * useState, useRuntime }` — factory-style React context. Mounts the\n * bridge client ONCE inside the Provider; child hooks read `state` /\n * `dispatch` from context. Surfaces that drill `dispatch` through\n * multiple component layers, or mount `useBackgroundRuntime` more\n * than once for the same channel, should use this instead.\n *\n * Why a factory (not a single global context):\n * - Type safety: each app types it against its own `S` / `M`.\n * - Tests can mount fresh contexts per test (no module-level state to\n * reset).\n * - Multiple-runtimes case: an app COULD theoretically have two\n * background-shaped runtimes (e.g. one per channel); the factory\n * pattern doesn't preclude it.\n *\n * Hook lifecycle (`useBackgroundRuntime`) — preserved from the prior\n * single-export module:\n * 1. `useSyncExternalStore` subscribes to broadcasts via\n * `bridgeClient.subscribe`, reading the latest state via\n * `bridgeClient.getSnapshot`. Reference stability is owned by the\n * bridge — `getSnapshot` returns the SAME `S` until a new broadcast\n * overwrites it, so React doesn't loop.\n * 2. A one-shot `hydrate()` call seeds `latestState` before the first\n * broadcast arrives. The hydrate side-effect runs in an effect so the\n * first render shows `null` and the subsequent render flips to the\n * hydrated snapshot (or stays null if the host is still booting).\n * 3. `dispatch(msg)` sends `:dispatch` envelopes.\n *\n * On unmount: `useSyncExternalStore` removes the listener; the host's\n * bridge stays installed.\n *\n * Canon §3.1: React adapters use `useSyncExternalStore`, not\n * `useState + useEffect`. `useMachine` and `useRuntime` already follow this\n * — `useBackgroundRuntime` (and by extension the Provider) does too. One\n * Way to Do Each Thing.\n *\n * NOTE: This is a separate entry from the main `index.ts` so apps that\n * never need React don't drag react into their type graph. The React\n * adapter peer-depends on react (you must have it installed in the app).\n */\n\n\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport { bridgeClient, passThroughMsg } from \"./bridge\";\n\nexport interface UseBackgroundRuntimeOpts<S> {\n channel: string;\n /**\n * REQUIRED parse for inbound `state` payloads. Forwarded to\n * `bridgeClient` — see `BridgeClientOpts.parseState`. Surfaces own this\n * because the chrome.runtime boundary is `unknown` (Inv 8). Returning\n * `null` drops the payload silently.\n */\n parseState: (raw: unknown) => S | null;\n}\n\nexport interface UseBackgroundRuntimeResult<S, M> {\n /** Latest snapshot from the host. `null` until the first hydrate response\n * or the first broadcast arrives. Surfaces SHOULD render a placeholder\n * for the null window. */\n state: S | null;\n /** Send a msg to the host runtime. Resolves once the host's dispatch\n * settles. */\n dispatch(msg: M): Promise<void>;\n}\n\nexport function useBackgroundRuntime<S, M extends { type: string }>({\n channel,\n parseState,\n}: UseBackgroundRuntimeOpts<S>): UseBackgroundRuntimeResult<S, M> {\n // Pin the client across renders. Identity must be stable because\n // `useSyncExternalStore` deduplicates subscribe by reference; rebuilding\n // the client every render would re-register listeners every render too.\n const clientRef = useRef<ReturnType<typeof bridgeClient<S, M>> | null>(null);\n if (clientRef.current === null) {\n // This hook surfaces only `state`; the broadcast msg is unused, so it\n // explicitly opts out of msg parsing via `passThroughMsg`. Same behavior\n // as the former optional-`parseMsg` default, now a visible decision.\n clientRef.current = bridgeClient<S, M>({\n channel,\n parseState,\n parseMsg: passThroughMsg,\n });\n }\n const client = clientRef.current;\n\n const state = useSyncExternalStore<S | null>(\n client.subscribe,\n client.getSnapshot,\n client.getSnapshot,\n );\n\n // One-shot hydrate on mount. The hydrate response primes `getSnapshot`\n // before the first broadcast lands so newly-opened surfaces show the\n // right view immediately. We don't read its return value — the hook\n // re-renders when `useSyncExternalStore` notices the snapshot change.\n // Hydrate failures (host not present yet) are swallowed; surfaces wait\n // for the next broadcast.\n useEffect(() => {\n client.hydrate().catch(() => {\n // No host yet. Surfaces fall back to broadcasts.\n });\n }, [client]);\n\n const dispatch = useCallback(\n async (msg: M): Promise<void> => {\n await client.dispatch(msg);\n },\n [client],\n );\n\n return { state, dispatch };\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider + consumer hooks — factory-style React context.\n//\n// `createBackgroundRuntimeContext<S, M>()` returns a `{ Provider, useDispatch,\n// useState, useRuntime }` tuple bound to the caller's `S` / `M`. The\n// Provider mounts `useBackgroundRuntime(opts)` ONCE internally and shares\n// the `{ state, dispatch }` pair via context. Child consumers (anywhere in\n// the tree) read the slice they need — no prop drilling, single bridge\n// client per channel per Provider mount.\n//\n// The factory is generic; the returned hooks throw a clear error if used\n// outside the Provider so the failure mode is \"loud and obvious\" rather\n// than \"silently returns null state forever\".\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface BackgroundRuntimeContext<S, M> {\n /**\n * Wrap a subtree to share a single background-runtime bridge client.\n * `opts` is forwarded verbatim to `useBackgroundRuntime` — same channel,\n * same parse contract.\n */\n Provider: (props: {\n opts: UseBackgroundRuntimeOpts<S>;\n children: ReactNode;\n }) => ReactNode;\n /**\n * Returns the dispatch function bound to this Provider's bridge client.\n * Reference is stable across renders (per `useBackgroundRuntime`'s\n * `useCallback`), so passing it to memoized children won't churn them.\n */\n useDispatch: () => (msg: M) => Promise<void>;\n /**\n * Returns a slice of the latest state. `selector` defaults to identity\n * (returns the whole `S | null` snapshot). Selectors run on every state\n * change — surfaces with expensive transforms should memoize the\n * selector at call site.\n *\n * Returns `null` until the first hydrate / broadcast lands when the\n * selector is identity; for non-identity selectors the return type is\n * `T` and the caller's selector decides how to handle the pre-hydrate\n * `null` snapshot.\n */\n useState: {\n (): S | null;\n <T>(selector: (state: S | null) => T): T;\n };\n /**\n * Escape hatch — returns the full `{ state, dispatch }` pair as-is.\n * Useful for consumers that want both the snapshot and the dispatch\n * fn in a single hook call (e.g. effects that read state THEN\n * dispatch in response).\n *\n * Not a `@demlik/tea` `Runtime<S, M>` — the bridge surface is a thinner\n * client. This hook returns the same shape as `useBackgroundRuntime`,\n * just sourced from context instead of mounting a fresh client.\n */\n useRuntime: () => UseBackgroundRuntimeResult<S, M>;\n}\n\nconst PROVIDER_ERROR =\n \"createBackgroundRuntimeContext: hook used outside its Provider. Wrap the consumer in <BackgroundRuntime.Provider opts={...}>.\";\n\nexport function createBackgroundRuntimeContext<\n S,\n M extends { type: string },\n>(): BackgroundRuntimeContext<S, M> {\n // `null` is the \"not inside a Provider\" sentinel — the hooks below\n // throw on read. Distinct from `state: null` (pre-hydrate), which IS a\n // valid context value.\n const Ctx = createContext<UseBackgroundRuntimeResult<S, M> | null>(null);\n\n function Provider({\n opts,\n children,\n }: {\n opts: UseBackgroundRuntimeOpts<S>;\n children: ReactNode;\n }): ReactNode {\n const result = useBackgroundRuntime<S, M>(opts);\n // Stabilize the context value reference so consumers that subscribe via\n // `useContext` don't re-render unless `state` or `dispatch` actually\n // changes. `state` is reference-stable (bridge's `getSnapshot` returns\n // the same `S` until a new broadcast). `dispatch` is stable per\n // `useBackgroundRuntime`'s `useCallback`. So `useMemo` keyed on both\n // gives a stable value object across renders.\n const value = useMemo<UseBackgroundRuntimeResult<S, M>>(\n () => ({ state: result.state, dispatch: result.dispatch }),\n [result.state, result.dispatch],\n );\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n function useRuntime(): UseBackgroundRuntimeResult<S, M> {\n const ctx = useContext(Ctx);\n if (ctx === null) throw new Error(PROVIDER_ERROR);\n return ctx;\n }\n\n function useDispatch(): (msg: M) => Promise<void> {\n return useRuntime().dispatch;\n }\n\n // Two-overload `useState` so callers see `S | null` without passing a\n // selector and `T` when they do. The runtime body collapses them — if\n // `selector` is omitted we pass identity through.\n function useStateHook(): S | null;\n function useStateHook<T>(selector: (state: S | null) => T): T;\n function useStateHook<T>(selector?: (state: S | null) => T): T | (S | null) {\n const { state } = useRuntime();\n if (selector === undefined) return state;\n return selector(state);\n }\n\n return {\n Provider,\n useDispatch,\n useState: useStateHook,\n useRuntime,\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { S as Sub } from '../../core-BmlJOvxM.js';
2
- import { S as SubscribeHandler } from '../../types-BoUWgwSm.js';
1
+ import { S as Sub } from '../../core-42kapW0n.js';
2
+ import { S as SubscribeHandler } from '../../types-KbL3W1mj.js';
3
3
 
4
4
  type AlarmSubData = {
5
5
  alarmName: string;
@@ -1,10 +1,11 @@
1
+ import { dispatchIfPresent } from '../../chunk-ZJ5AOYBH.js';
2
+
1
3
  // src/extension/subs/from-chrome-alarm.ts
2
4
  function fromChromeAlarm(msgFn) {
3
5
  return (sub, _ctx, dispatch) => {
4
6
  const listener = (alarm) => {
5
7
  if (alarm.name !== sub.alarmName) return;
6
- const msg = msgFn(alarm, sub);
7
- if (msg !== null) dispatch(msg);
8
+ dispatchIfPresent(dispatch, msgFn(alarm, sub));
8
9
  };
9
10
  chrome.alarms.onAlarm.addListener(listener);
10
11
  return () => chrome.alarms.onAlarm.removeListener(listener);
@@ -16,8 +17,7 @@ function fromChromeMessage(opts) {
16
17
  return (sub, _ctx, dispatch) => {
17
18
  const listener = (message, sender, _sendResponse) => {
18
19
  if (opts.filter !== void 0 && !opts.filter(message)) return;
19
- const msg = opts.msgFn(message, sender, sub);
20
- if (msg !== null) dispatch(msg);
20
+ dispatchIfPresent(dispatch, opts.msgFn(message, sender, sub));
21
21
  };
22
22
  chrome.runtime.onMessage.addListener(listener);
23
23
  return () => {
@@ -42,8 +42,7 @@ function fromChromeStorageChange(opts) {
42
42
  }
43
43
  if (!overlap) return;
44
44
  }
45
- const msg = opts.msgFn(changes, sub);
46
- if (msg !== null) dispatch(msg);
45
+ dispatchIfPresent(dispatch, opts.msgFn(changes, sub));
47
46
  };
48
47
  chrome.storage.onChanged.addListener(listener);
49
48
  return () => {
@@ -57,8 +56,7 @@ function fromChromeTabsEvent(opts) {
57
56
  return (sub, _ctx, dispatch) => {
58
57
  const installed = [];
59
58
  const listener = () => {
60
- const msg = opts.msgFn(sub);
61
- if (msg !== null) dispatch(msg);
59
+ dispatchIfPresent(dispatch, opts.msgFn(sub));
62
60
  };
63
61
  for (const event of opts.events) {
64
62
  const emitter = chrome.tabs[event];
@@ -66,8 +64,7 @@ function fromChromeTabsEvent(opts) {
66
64
  installed.push(event);
67
65
  }
68
66
  if (opts.fireOnMount === true) {
69
- const msg = opts.msgFn(sub);
70
- if (msg !== null) dispatch(msg);
67
+ dispatchIfPresent(dispatch, opts.msgFn(sub));
71
68
  }
72
69
  return () => {
73
70
  for (const event of installed) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/extension/subs/from-chrome-alarm.ts","../../../src/extension/subs/from-chrome-message.ts","../../../src/extension/subs/from-chrome-storage-change.ts","../../../src/extension/subs/from-chrome-tabs-event.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["// ---------------------------------------------------------------------------\n// fromChromeAlarm — pure observer for `chrome.alarms.onAlarm`.\n//\n// chrome.alarms is a PERSISTENT resource (the alarm registry survives MV3\n// service-worker restarts — that's the whole reason it exists). Modeling\n// alarm CREATION inside `Sub.subscribe` conflates two concerns:\n//\n// - Persistent-resource lifecycle (create/clear) — caller's responsibility,\n// expressed as Cmds (typically `ensure_alarm` on boot, `clear_alarm`\n// when retiring). Cmds run through `interpret`, where async is the\n// contract.\n// - Event observation — the Sub's responsibility. `SubscribeHandler` is\n// SYNC: `(sub, ctx, dispatch) => () => void`. Mixing in a check-then-\n// create await chain forces a `void (async () => …)()` wrapper that\n// hides errors and breaks test ordering.\n//\n// World B: the Sub is pure listener. It carries `alarmName` only,\n// addListener + filter on mount, removeListener on cleanup. The Cmd\n// vocabulary in the consumer machine (`ensure_alarm`, `clear_alarm`) owns\n// the create/clear lifecycle.\n//\n// Cites invariant 3 (effects describe via Cmd, not perform inside Sub) and\n// invariant 4 (external events enter as Subs — observation only).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\n\ntype AlarmSubData = { alarmName: string };\n\nexport function fromChromeAlarm<S extends Sub & AlarmSubData, M>(\n msgFn: (alarm: chrome.alarms.Alarm, sub: S) => M | null,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const listener = (alarm: chrome.alarms.Alarm): void => {\n // Filter by name — onAlarm fires for EVERY alarm registered in the\n // extension, not just ours. Without this filter, two Subs with\n // different alarmName values would cross-dispatch.\n if (alarm.name !== sub.alarmName) return;\n const msg = msgFn(alarm, sub);\n if (msg !== null) dispatch(msg);\n };\n chrome.alarms.onAlarm.addListener(listener);\n return () => chrome.alarms.onAlarm.removeListener(listener);\n };\n}\n","// ---------------------------------------------------------------------------\n// fromChromeMessage — universal `chrome.runtime.onMessage`-shaped Sub\n// factory.\n//\n// `chrome.runtime.onMessage` is the extension's intra-process message bus:\n// the service worker receives broadcasts from popup, options, content\n// scripts, and the WebApp's `chrome.runtime.sendMessage` calls. Every\n// listener wakes for every message; consumers filter by shape (the message\n// is `unknown` to chrome — only the participants share a schema).\n//\n// Shape choices:\n//\n// - `filter?: (message: unknown) => boolean` — optional pre-filter that\n// runs BEFORE `msgFn`. The factory drops the dispatch when `filter`\n// returns false. Use this for cheap discriminant checks (e.g.\n// `message.type === \"ping\"`) that short-circuit before the more\n// expensive Msg construction.\n//\n// - `msgFn(message, sender, sub)` — both the message AND the sender\n// are forwarded. `sender` carries `tab.id` for content-script sends\n// and `id` for cross-extension sends; consumers that route by sender\n// (e.g. \"only accept from this tab\") need it. Returns `M | null`;\n// null drops the dispatch.\n//\n// What this factory deliberately does NOT do:\n//\n// - It does not call `sendResponse` or return `true` from the listener\n// — that's the request/response shape, not the broadcast shape. A\n// factory that supports both would have to commit to a Promise<M>\n// return path, which couples to async-Cmd plumbing that's not in\n// scope for a Sub. Use a one-shot Cmd handler for request/response.\n//\n// Strengthens invariant 9 (named, small surface) and invariant 2 (the\n// reducer never sees chrome.runtime.onMessage).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\n\nexport interface ChromeMessageOpts<S extends Sub, M> {\n /**\n * Pre-filter — when provided, the factory only dispatches when this\n * returns `true`. Cheap discriminant checks belong here.\n */\n filter?: (message: unknown) => boolean;\n msgFn: (\n message: unknown,\n sender: chrome.runtime.MessageSender,\n sub: S,\n ) => M | null;\n}\n\nexport function fromChromeMessage<S extends Sub, M>(\n opts: ChromeMessageOpts<S, M>,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const listener = (\n message: unknown,\n sender: chrome.runtime.MessageSender,\n _sendResponse: (response: unknown) => void,\n ): void => {\n if (opts.filter !== undefined && !opts.filter(message)) return;\n const msg = opts.msgFn(message, sender, sub);\n if (msg !== null) dispatch(msg);\n // We intentionally do not return `true` here — that's the\n // request/response posture, not the broadcast posture. See the\n // module comment for the rationale.\n };\n chrome.runtime.onMessage.addListener(listener);\n return () => {\n chrome.runtime.onMessage.removeListener(listener);\n };\n };\n}\n","// ---------------------------------------------------------------------------\n// fromChromeStorageChange — universal `chrome.storage.onChanged`-shaped Sub\n// factory.\n//\n// `chrome.storage.onChanged` is the top-level event that fires for every\n// area (`local`, `sync`, `session`, `managed`) — the listener receives\n// `(changes, areaName)`. Consumers typically care about ONE area and often\n// only a subset of keys; without a filter, every listener wakes for every\n// change anywhere in the extension's storage. The factory absorbs the\n// addListener/removeListener pair PLUS the standard area/key filter.\n//\n// Shape choices:\n//\n// - `area: chrome.storage.AreaName` — required. Chrome's typing covers\n// \"local\" | \"sync\" | \"session\" | \"managed\". The factory drops every\n// fire where `areaName !== opts.area`.\n//\n// - `keys?: readonly string[]` — optional intersection filter. When\n// provided, the factory drops fires where none of the changed keys\n// overlaps with the requested set. Omitting means \"any key in the\n// area\". The filter is `O(keys × changes)` per fire — acceptable for\n// small key lists (typical: 1-5 keys per Sub).\n//\n// - `msgFn` may return `null` — drops the dispatch even after the\n// area/keys filters pass. Gives the caller a final hook for\n// state-aware filtering (e.g. \"only when the new value is\n// truthy\").\n//\n// Strengthens invariant 9 (named, small surface) and invariant 2 (the\n// reducer never sees chrome.storage; the factory owns the wiring).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\n\nexport interface ChromeStorageChangeOpts<S extends Sub, M> {\n area: chrome.storage.AreaName;\n /**\n * If provided, only dispatch when at least one of the changed keys\n * overlaps with this set. Omitting means \"any key in the area\".\n */\n keys?: readonly string[];\n msgFn: (\n changes: Record<string, chrome.storage.StorageChange>,\n sub: S,\n ) => M | null;\n}\n\nexport function fromChromeStorageChange<S extends Sub, M>(\n opts: ChromeStorageChangeOpts<S, M>,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const listener = (\n changes: Record<string, chrome.storage.StorageChange>,\n areaName: chrome.storage.AreaName,\n ): void => {\n if (areaName !== opts.area) return;\n if (opts.keys !== undefined) {\n // Intersect — at least one changed key must be in opts.keys.\n // Using a small list scan over Object.keys(changes) avoids\n // allocating a Set per fire for the typical 1-5 key case.\n const changedKeys = Object.keys(changes);\n let overlap = false;\n for (const k of opts.keys) {\n if (changedKeys.includes(k)) {\n overlap = true;\n break;\n }\n }\n if (!overlap) return;\n }\n const msg = opts.msgFn(changes, sub);\n if (msg !== null) dispatch(msg);\n };\n chrome.storage.onChanged.addListener(listener);\n return () => {\n chrome.storage.onChanged.removeListener(listener);\n };\n };\n}\n","// ---------------------------------------------------------------------------\n// fromChromeTabsEvent — universal `chrome.tabs.on*`-shaped Sub factory.\n//\n// chrome.tabs exposes a small set of lifecycle events (`onActivated`,\n// `onUpdated`, `onRemoved`) with different listener signatures but the\n// same wiring shape: register listener, dispatch on fire, remove on\n// cleanup. Most consumers subscribe to a SET of these events and treat\n// every fire the same way (e.g. \"tabs changed, please re-query\"). The\n// recurring ~20-line `addListener` × N + `removeListener` × N + optional\n// mount-time refresh is what this factory absorbs.\n//\n// Three shape choices worth flagging:\n//\n// - `events: readonly TabsEventName[]` — a SET (semantically), passed\n// as a tuple so the caller can be terse. The factory registers a\n// single listener per event name. The listener fires `msgFn(sub)`;\n// event-specific payloads (`activeInfo`, `tabId`, `changeInfo`,\n// `removeInfo`) are NOT forwarded — consumers that care about which\n// event fired model that as separate Subs with different ids.\n//\n// - `fireOnMount?: boolean` — synthetic immediate dispatch at subscribe\n// time. Most \"watch tabs\" subscriptions need the first emission to\n// populate state without waiting for the first chrome event; this is\n// the named, opt-in form of the otherwise-recurring `void refresh()`\n// line at the top of every chrome-tabs subscribe cell. Default\n// `false` matches the surprise principle (no synthetic dispatch\n// unless the caller asks for one).\n//\n// - `msgFn` may return `null` — drops the dispatch. The event fired,\n// the factory called `msgFn`, the caller decided \"this event is not\n// interesting given current state.\" No dispatch is made; listeners\n// stay armed for the next fire.\n//\n// Cleanup removes listeners from every event the factory installed —\n// not from the full `events` list, since a future edit could expand the\n// list mid-Sub. Captured the resolved set at subscribe time.\n//\n// Strengthens invariant 9 (named, small surface) and invariant 2 (the\n// reducer never sees chrome.tabs; the factory owns the wiring).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\n\nexport type TabsEventName = \"onActivated\" | \"onUpdated\" | \"onRemoved\";\n\nexport interface ChromeTabsEventOpts<S extends Sub, M> {\n events: readonly TabsEventName[];\n /**\n * If `true`, the factory dispatches a synthetic `msgFn(sub)` once at\n * subscribe time — useful for \"populate tab list on mount\" patterns\n * where the first emission must not wait for chrome to fire an event.\n * Default `false`.\n */\n fireOnMount?: boolean;\n msgFn: (sub: S) => M | null;\n}\n\n// The chrome.tabs.on* events have different listener signatures\n// (`activeInfo`, `(tabId, changeInfo, tab)`, `(tabId, removeInfo)`). We\n// type the listener as accepting unknown args because the factory does\n// not forward the event payload — every event collapses to `msgFn(sub)`.\ntype AnyTabsListener = (...args: unknown[]) => void;\n\nexport function fromChromeTabsEvent<S extends Sub, M>(\n opts: ChromeTabsEventOpts<S, M>,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const installed: TabsEventName[] = [];\n const listener: AnyTabsListener = () => {\n const msg = opts.msgFn(sub);\n if (msg !== null) dispatch(msg);\n };\n\n for (const event of opts.events) {\n // Each chrome.tabs.onX is a typed EventEmitter — addListener takes\n // a callback whose signature matches the event. Cast at the chrome\n // boundary since the factory collapses every payload shape into a\n // single `msgFn(sub)` call.\n const emitter = chrome.tabs[\n event\n ] as chrome.events.Event<AnyTabsListener>;\n emitter.addListener(listener);\n installed.push(event);\n }\n\n if (opts.fireOnMount === true) {\n const msg = opts.msgFn(sub);\n if (msg !== null) dispatch(msg);\n }\n\n return () => {\n for (const event of installed) {\n const emitter = chrome.tabs[\n event\n ] as chrome.events.Event<AnyTabsListener>;\n emitter.removeListener(listener);\n }\n };\n };\n}\n"]}
1
+ {"version":3,"sources":["../../../src/extension/subs/from-chrome-alarm.ts","../../../src/extension/subs/from-chrome-message.ts","../../../src/extension/subs/from-chrome-storage-change.ts","../../../src/extension/subs/from-chrome-tabs-event.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["// ---------------------------------------------------------------------------\n// fromChromeAlarm — pure observer for `chrome.alarms.onAlarm`.\n//\n// chrome.alarms is a PERSISTENT resource (the alarm registry survives MV3\n// service-worker restarts — that's the whole reason it exists). Modeling\n// alarm CREATION inside `Sub.subscribe` conflates two concerns:\n//\n// - Persistent-resource lifecycle (create/clear) — caller's responsibility,\n// expressed as Cmds (typically `ensure_alarm` on boot, `clear_alarm`\n// when retiring). Cmds run through `interpret`, where async is the\n// contract.\n// - Event observation — the Sub's responsibility. `SubscribeHandler` is\n// SYNC: `(sub, ctx, dispatch) => () => void`. Mixing in a check-then-\n// create await chain forces a `void (async () => …)()` wrapper that\n// hides errors and breaks test ordering.\n//\n// World B: the Sub is pure listener. It carries `alarmName` only,\n// addListener + filter on mount, removeListener on cleanup. The Cmd\n// vocabulary in the consumer machine (`ensure_alarm`, `clear_alarm`) owns\n// the create/clear lifecycle.\n//\n// Cites invariant 3 (effects describe via Cmd, not perform inside Sub) and\n// invariant 4 (external events enter as Subs — observation only).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\nimport { dispatchIfPresent } from \"../../subs/types\";\n\ntype AlarmSubData = { alarmName: string };\n\nexport function fromChromeAlarm<S extends Sub & AlarmSubData, M>(\n msgFn: (alarm: chrome.alarms.Alarm, sub: S) => M | null,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const listener = (alarm: chrome.alarms.Alarm): void => {\n // Filter by name — onAlarm fires for EVERY alarm registered in the\n // extension, not just ours. Without this filter, two Subs with\n // different alarmName values would cross-dispatch.\n if (alarm.name !== sub.alarmName) return;\n dispatchIfPresent(dispatch, msgFn(alarm, sub));\n };\n chrome.alarms.onAlarm.addListener(listener);\n return () => chrome.alarms.onAlarm.removeListener(listener);\n };\n}\n","// ---------------------------------------------------------------------------\n// fromChromeMessage — universal `chrome.runtime.onMessage`-shaped Sub\n// factory.\n//\n// `chrome.runtime.onMessage` is the extension's intra-process message bus:\n// the service worker receives broadcasts from popup, options, content\n// scripts, and the WebApp's `chrome.runtime.sendMessage` calls. Every\n// listener wakes for every message; consumers filter by shape (the message\n// is `unknown` to chrome — only the participants share a schema).\n//\n// Shape choices:\n//\n// - `filter?: (message: unknown) => boolean` — optional pre-filter that\n// runs BEFORE `msgFn`. The factory drops the dispatch when `filter`\n// returns false. Use this for cheap discriminant checks (e.g.\n// `message.type === \"ping\"`) that short-circuit before the more\n// expensive Msg construction.\n//\n// - `msgFn(message, sender, sub)` — both the message AND the sender\n// are forwarded. `sender` carries `tab.id` for content-script sends\n// and `id` for cross-extension sends; consumers that route by sender\n// (e.g. \"only accept from this tab\") need it. Returns `M | null`;\n// null drops the dispatch.\n//\n// What this factory deliberately does NOT do:\n//\n// - It does not call `sendResponse` or return `true` from the listener\n// — that's the request/response shape, not the broadcast shape. A\n// factory that supports both would have to commit to a Promise<M>\n// return path, which couples to async-Cmd plumbing that's not in\n// scope for a Sub. Use a one-shot Cmd handler for request/response.\n//\n// Strengthens invariant 9 (named, small surface) and invariant 2 (the\n// reducer never sees chrome.runtime.onMessage).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\nimport { dispatchIfPresent } from \"../../subs/types\";\n\nexport interface ChromeMessageOpts<S extends Sub, M> {\n /**\n * Pre-filter — when provided, the factory only dispatches when this\n * returns `true`. Cheap discriminant checks belong here.\n */\n filter?: (message: unknown) => boolean;\n msgFn: (\n message: unknown,\n sender: chrome.runtime.MessageSender,\n sub: S,\n ) => M | null;\n}\n\nexport function fromChromeMessage<S extends Sub, M>(\n opts: ChromeMessageOpts<S, M>,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const listener = (\n message: unknown,\n sender: chrome.runtime.MessageSender,\n _sendResponse: (response: unknown) => void,\n ): void => {\n if (opts.filter !== undefined && !opts.filter(message)) return;\n dispatchIfPresent(dispatch, opts.msgFn(message, sender, sub));\n // We intentionally do not return `true` here — that's the\n // request/response posture, not the broadcast posture. See the\n // module comment for the rationale.\n };\n chrome.runtime.onMessage.addListener(listener);\n return () => {\n chrome.runtime.onMessage.removeListener(listener);\n };\n };\n}\n","// ---------------------------------------------------------------------------\n// fromChromeStorageChange — universal `chrome.storage.onChanged`-shaped Sub\n// factory.\n//\n// `chrome.storage.onChanged` is the top-level event that fires for every\n// area (`local`, `sync`, `session`, `managed`) — the listener receives\n// `(changes, areaName)`. Consumers typically care about ONE area and often\n// only a subset of keys; without a filter, every listener wakes for every\n// change anywhere in the extension's storage. The factory absorbs the\n// addListener/removeListener pair PLUS the standard area/key filter.\n//\n// Shape choices:\n//\n// - `area: chrome.storage.AreaName` — required. Chrome's typing covers\n// \"local\" | \"sync\" | \"session\" | \"managed\". The factory drops every\n// fire where `areaName !== opts.area`.\n//\n// - `keys?: readonly string[]` — optional intersection filter. When\n// provided, the factory drops fires where none of the changed keys\n// overlaps with the requested set. Omitting means \"any key in the\n// area\". The filter is `O(keys × changes)` per fire — acceptable for\n// small key lists (typical: 1-5 keys per Sub).\n//\n// - `msgFn` may return `null` — drops the dispatch even after the\n// area/keys filters pass. Gives the caller a final hook for\n// state-aware filtering (e.g. \"only when the new value is\n// truthy\").\n//\n// Strengthens invariant 9 (named, small surface) and invariant 2 (the\n// reducer never sees chrome.storage; the factory owns the wiring).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\nimport { dispatchIfPresent } from \"../../subs/types\";\n\nexport interface ChromeStorageChangeOpts<S extends Sub, M> {\n area: chrome.storage.AreaName;\n /**\n * If provided, only dispatch when at least one of the changed keys\n * overlaps with this set. Omitting means \"any key in the area\".\n */\n keys?: readonly string[];\n msgFn: (\n changes: Record<string, chrome.storage.StorageChange>,\n sub: S,\n ) => M | null;\n}\n\nexport function fromChromeStorageChange<S extends Sub, M>(\n opts: ChromeStorageChangeOpts<S, M>,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const listener = (\n changes: Record<string, chrome.storage.StorageChange>,\n areaName: chrome.storage.AreaName,\n ): void => {\n if (areaName !== opts.area) return;\n if (opts.keys !== undefined) {\n // Intersect — at least one changed key must be in opts.keys.\n // Using a small list scan over Object.keys(changes) avoids\n // allocating a Set per fire for the typical 1-5 key case.\n const changedKeys = Object.keys(changes);\n let overlap = false;\n for (const k of opts.keys) {\n if (changedKeys.includes(k)) {\n overlap = true;\n break;\n }\n }\n if (!overlap) return;\n }\n dispatchIfPresent(dispatch, opts.msgFn(changes, sub));\n };\n chrome.storage.onChanged.addListener(listener);\n return () => {\n chrome.storage.onChanged.removeListener(listener);\n };\n };\n}\n","// ---------------------------------------------------------------------------\n// fromChromeTabsEvent — universal `chrome.tabs.on*`-shaped Sub factory.\n//\n// chrome.tabs exposes a small set of lifecycle events (`onActivated`,\n// `onUpdated`, `onRemoved`) with different listener signatures but the\n// same wiring shape: register listener, dispatch on fire, remove on\n// cleanup. Most consumers subscribe to a SET of these events and treat\n// every fire the same way (e.g. \"tabs changed, please re-query\"). The\n// recurring ~20-line `addListener` × N + `removeListener` × N + optional\n// mount-time refresh is what this factory absorbs.\n//\n// Three shape choices worth flagging:\n//\n// - `events: readonly TabsEventName[]` — a SET (semantically), passed\n// as a tuple so the caller can be terse. The factory registers a\n// single listener per event name. The listener fires `msgFn(sub)`;\n// event-specific payloads (`activeInfo`, `tabId`, `changeInfo`,\n// `removeInfo`) are NOT forwarded — consumers that care about which\n// event fired model that as separate Subs with different ids.\n//\n// - `fireOnMount?: boolean` — synthetic immediate dispatch at subscribe\n// time. Most \"watch tabs\" subscriptions need the first emission to\n// populate state without waiting for the first chrome event; this is\n// the named, opt-in form of the otherwise-recurring `void refresh()`\n// line at the top of every chrome-tabs subscribe cell. Default\n// `false` matches the surprise principle (no synthetic dispatch\n// unless the caller asks for one).\n//\n// - `msgFn` may return `null` — drops the dispatch. The event fired,\n// the factory called `msgFn`, the caller decided \"this event is not\n// interesting given current state.\" No dispatch is made; listeners\n// stay armed for the next fire.\n//\n// Cleanup removes listeners from every event the factory installed —\n// not from the full `events` list, since a future edit could expand the\n// list mid-Sub. Captured the resolved set at subscribe time.\n//\n// Strengthens invariant 9 (named, small surface) and invariant 2 (the\n// reducer never sees chrome.tabs; the factory owns the wiring).\n// ---------------------------------------------------------------------------\n\nimport type { Sub } from \"../../index\";\nimport type { SubscribeHandler } from \"../../subs/index\";\nimport { dispatchIfPresent } from \"../../subs/types\";\n\nexport type TabsEventName = \"onActivated\" | \"onUpdated\" | \"onRemoved\";\n\nexport interface ChromeTabsEventOpts<S extends Sub, M> {\n events: readonly TabsEventName[];\n /**\n * If `true`, the factory dispatches a synthetic `msgFn(sub)` once at\n * subscribe time — useful for \"populate tab list on mount\" patterns\n * where the first emission must not wait for chrome to fire an event.\n * Default `false`.\n */\n fireOnMount?: boolean;\n msgFn: (sub: S) => M | null;\n}\n\n// The chrome.tabs.on* events have different listener signatures\n// (`activeInfo`, `(tabId, changeInfo, tab)`, `(tabId, removeInfo)`). We\n// type the listener as accepting unknown args because the factory does\n// not forward the event payload — every event collapses to `msgFn(sub)`.\ntype AnyTabsListener = (...args: unknown[]) => void;\n\nexport function fromChromeTabsEvent<S extends Sub, M>(\n opts: ChromeTabsEventOpts<S, M>,\n): SubscribeHandler<S, M, unknown> {\n return (sub, _ctx, dispatch) => {\n const installed: TabsEventName[] = [];\n const listener: AnyTabsListener = () => {\n dispatchIfPresent(dispatch, opts.msgFn(sub));\n };\n\n for (const event of opts.events) {\n // Each chrome.tabs.onX is a typed EventEmitter — addListener takes\n // a callback whose signature matches the event. Cast at the chrome\n // boundary since the factory collapses every payload shape into a\n // single `msgFn(sub)` call.\n const emitter = chrome.tabs[\n event\n ] as chrome.events.Event<AnyTabsListener>;\n emitter.addListener(listener);\n installed.push(event);\n }\n\n if (opts.fireOnMount === true) {\n dispatchIfPresent(dispatch, opts.msgFn(sub));\n }\n\n return () => {\n for (const event of installed) {\n const emitter = chrome.tabs[\n event\n ] as chrome.events.Event<AnyTabsListener>;\n emitter.removeListener(listener);\n }\n };\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { C as Cmd, P as Port } from '../core-BmlJOvxM.js';
1
+ import { C as Cmd, P as Port } from '../core-42kapW0n.js';
2
2
  import { QueueItem } from '../work-queue/index.js';
3
- import '../index.js';
3
+ import '../runtime-types-CukV8kMX.js';
4
4
 
5
5
  /**
6
6
  * @demlik/tea/fan-out — scatter-gather over a bounded-concurrency work list.
@@ -18,19 +18,19 @@ import '../index.js';
18
18
  * partitions over that one lifecycle, so the work-queue's status taxonomy
19
19
  * is the substrate rather than a parallel invention. We reuse its
20
20
  * `QueueItem<I>` / `QueueItemStatus` TYPES and delegate the ledger
21
- * transitions to its BLESSED pure ops (`@demlik/tea/work-queue/ops`):
22
- * `scatter` mints each pending record with `enqueueOp`, and `launchUpTo`
23
- * flips `pending → running` with `claimNextOp` (one positional claim per
21
+ * transitions to the `QueueAdapter` verbs (`../work-queue/adapter`):
22
+ * `scatter` mints each pending record with `queue.enqueue`, and `launchUpTo`
23
+ * flips `pending → running` with `queue.claim` (one positional claim per
24
24
  * launch). The lone exception is `settleOne`'s `running → done|failed`
25
25
  * flip — it must match "first id-match that is still `running`" to settle
26
- * exactly one of a DUPLICATE id, a status predicate the ops surface can't
26
+ * exactly one of a DUPLICATE id, a status predicate the adapter verbs can't
27
27
  * express, so fan-out owns that one index (see `settleOne`). The async
28
28
  * `createQueue(store)` adapter is NOT used here because its `load → mutate
29
29
  * → save` reads the clock and lives at an I/O boundary, while a combinator's
30
- * verbs must be pure (invariant 2) — fan-out reaches the underlying ops
31
- * directly instead, the same route `monitored-run` / `idempotent-intake`
32
- * take. The slice lives in the Model instead — durable + replayable, the
33
- * two non-negotiables every knob preserves.
30
+ * verbs must be pure (invariant 2) — fan-out binds the pure `QueueAdapter`
31
+ * to its in-Model ledger instead, the same route `monitored-run` /
32
+ * `idempotent-intake` / `saga` take. The slice lives in the Model instead —
33
+ * durable + replayable, the two non-negotiables every knob preserves.
34
34
  *
35
35
  * Typical wiring (combinator form — splice the hooks into your machine):
36
36
  *
@@ -1,5 +1,5 @@
1
- export { createFanOut, initFanOut, isComplete } from '../chunk-UV6UWGEO.js';
2
- import '../chunk-HJO6VNQI.js';
3
- import '../chunk-TGG26XMK.js';
1
+ export { createFanOut, initFanOut, isComplete } from '../chunk-D736QUGF.js';
2
+ import '../chunk-MU6MCIAC.js';
3
+ import '../chunk-FV3Z5MBE.js';
4
4
  //# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  import { IdempotencyStore } from '../idempotency/index.js';
2
- import { C as Cmd } from '../core-BmlJOvxM.js';
2
+ import { C as Cmd } from '../core-42kapW0n.js';
3
3
  import { QueueItem } from '../work-queue/index.js';
4
- import '../index.js';
4
+ import '../runtime-types-CukV8kMX.js';
5
5
 
6
6
  /**
7
7
  * @demlik/tea/idempotent-intake — receive-once intake for webhooks / queue
@@ -1,7 +1,7 @@
1
- export { createIntake } from '../chunk-LEC4U6CX.js';
1
+ export { createIntake } from '../chunk-ZVJZ72HY.js';
2
2
  import '../chunk-BYQUGDD3.js';
3
3
  import '../chunk-K575PT4S.js';
4
- import '../chunk-HJO6VNQI.js';
5
- import '../chunk-TGG26XMK.js';
4
+ import '../chunk-MU6MCIAC.js';
5
+ import '../chunk-FV3Z5MBE.js';
6
6
  //# sourceMappingURL=index.js.map
7
7
  //# sourceMappingURL=index.js.map