@agentshouse/mdruntime 0.1.0-c2c52158b7381 → 0.1.0-c2d73b235d7d7

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 (442) hide show
  1. package/README.md +24 -20
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +328 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +345 -0
  11. package/dist/adapter.d.ts +315 -122
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +4 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +33 -49
  16. package/dist/{binary.d.ts → attachment.d.ts} +8 -9
  17. package/dist/attachment.d.ts.map +1 -0
  18. package/dist/attachment.js +15 -0
  19. package/dist/authored.d.ts +88 -0
  20. package/dist/authored.d.ts.map +1 -0
  21. package/dist/authored.js +345 -0
  22. package/dist/bootstrap.d.ts +30 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +305 -140
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +12 -0
  29. package/dist/chain.d.ts.map +1 -0
  30. package/dist/chain.js +67 -0
  31. package/dist/change-set.d.ts +10 -16
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +17 -90
  34. package/dist/change.d.ts +7 -2
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +7 -2
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +53 -31
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +66 -29
  43. package/dist/collection.d.ts +33 -21
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +57 -366
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +19 -0
  50. package/dist/compile.d.ts.map +1 -0
  51. package/dist/compile.js +755 -0
  52. package/dist/connection.d.ts +6 -142
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +117 -4210
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/{chat/context.js → context.js} +2 -5
  58. package/dist/conversation-live.d.ts +150 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +260 -0
  61. package/dist/conversation-row.d.ts +55 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +82 -0
  64. package/dist/conversation.d.ts +84 -54
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1043 -823
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/discovery.d.ts +12 -0
  71. package/dist/discovery.d.ts.map +1 -0
  72. package/dist/discovery.js +175 -0
  73. package/dist/download.d.ts +6 -0
  74. package/dist/download.d.ts.map +1 -0
  75. package/dist/download.js +42 -0
  76. package/dist/durability.d.ts +20 -4
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +12 -0
  79. package/dist/entry.d.ts +30 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +135 -41
  82. package/dist/expectation.d.ts +26 -13
  83. package/dist/expectation.d.ts.map +1 -1
  84. package/dist/expectation.js +72 -19
  85. package/dist/failure.d.ts +3 -0
  86. package/dist/failure.d.ts.map +1 -1
  87. package/dist/failure.js +8 -0
  88. package/dist/figures.d.ts +49 -0
  89. package/dist/figures.d.ts.map +1 -0
  90. package/dist/figures.js +199 -0
  91. package/dist/file.d.ts +2 -11
  92. package/dist/file.d.ts.map +1 -1
  93. package/dist/file.js +7 -4
  94. package/dist/holdings.d.ts +29 -0
  95. package/dist/holdings.d.ts.map +1 -0
  96. package/dist/holdings.js +95 -0
  97. package/dist/host.d.ts +25 -8
  98. package/dist/host.d.ts.map +1 -1
  99. package/dist/host.js +157 -61
  100. package/dist/house-query.d.ts +24 -0
  101. package/dist/house-query.d.ts.map +1 -0
  102. package/dist/house-query.js +102 -0
  103. package/dist/identity.d.ts +1 -3
  104. package/dist/identity.d.ts.map +1 -1
  105. package/dist/identity.js +1 -7
  106. package/dist/index.d.ts +49 -19
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +25 -8
  109. package/dist/install.d.ts +60 -0
  110. package/dist/install.d.ts.map +1 -0
  111. package/dist/install.js +537 -0
  112. package/dist/lifecycle.d.ts +7 -0
  113. package/dist/lifecycle.d.ts.map +1 -0
  114. package/dist/lifecycle.js +292 -0
  115. package/dist/linked-file.d.ts +7 -0
  116. package/dist/linked-file.d.ts.map +1 -0
  117. package/dist/linked-file.js +16 -0
  118. package/dist/listing.d.ts +60 -0
  119. package/dist/listing.d.ts.map +1 -0
  120. package/dist/listing.js +168 -0
  121. package/dist/live.d.ts +39 -0
  122. package/dist/live.d.ts.map +1 -0
  123. package/dist/live.js +223 -0
  124. package/dist/loaded.d.ts +7 -0
  125. package/dist/loaded.d.ts.map +1 -0
  126. package/dist/loaded.js +46 -0
  127. package/dist/locks.d.ts +7 -0
  128. package/dist/locks.d.ts.map +1 -0
  129. package/dist/locks.js +34 -0
  130. package/dist/lost.d.ts +5 -0
  131. package/dist/lost.d.ts.map +1 -0
  132. package/dist/lost.js +49 -0
  133. package/dist/media.d.ts +24 -0
  134. package/dist/media.d.ts.map +1 -0
  135. package/dist/media.js +365 -0
  136. package/dist/memory.d.ts +22 -8
  137. package/dist/memory.d.ts.map +1 -1
  138. package/dist/memory.js +311 -120
  139. package/dist/messages.d.ts +67 -0
  140. package/dist/messages.d.ts.map +1 -0
  141. package/dist/messages.js +180 -0
  142. package/dist/modal.d.ts +2 -0
  143. package/dist/modal.d.ts.map +1 -0
  144. package/dist/modal.js +11 -0
  145. package/dist/model.d.ts +15 -15
  146. package/dist/model.d.ts.map +1 -1
  147. package/dist/model.js +11 -22
  148. package/dist/models.d.ts +10 -0
  149. package/dist/models.d.ts.map +1 -0
  150. package/dist/models.js +153 -0
  151. package/dist/name.d.ts +0 -1
  152. package/dist/name.d.ts.map +1 -1
  153. package/dist/name.js +3 -7
  154. package/dist/observation.d.ts +40 -10
  155. package/dist/observation.d.ts.map +1 -1
  156. package/dist/observation.js +265 -44
  157. package/dist/online.d.ts +7 -0
  158. package/dist/online.d.ts.map +1 -0
  159. package/dist/online.js +29 -0
  160. package/dist/opened.d.ts +6 -6
  161. package/dist/opened.d.ts.map +1 -1
  162. package/dist/opened.js +7 -7
  163. package/dist/opening.d.ts +4 -0
  164. package/dist/opening.d.ts.map +1 -0
  165. package/dist/opening.js +71 -0
  166. package/dist/outcome.d.ts +46 -16
  167. package/dist/outcome.d.ts.map +1 -1
  168. package/dist/outcome.js +51 -7
  169. package/dist/overlay.d.ts +24 -11
  170. package/dist/overlay.d.ts.map +1 -1
  171. package/dist/overlay.js +138 -193
  172. package/dist/page-metadata.d.ts +8 -0
  173. package/dist/page-metadata.d.ts.map +1 -0
  174. package/dist/page-metadata.js +19 -0
  175. package/dist/parts.d.ts +7 -0
  176. package/dist/parts.d.ts.map +1 -0
  177. package/dist/parts.js +36 -0
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.d.ts.map +1 -1
  180. package/dist/paths.js +26 -0
  181. package/dist/preparation.d.ts +46 -0
  182. package/dist/preparation.d.ts.map +1 -0
  183. package/dist/preparation.js +344 -0
  184. package/dist/presence.d.ts +58 -0
  185. package/dist/presence.d.ts.map +1 -0
  186. package/dist/presence.js +231 -0
  187. package/dist/queries.d.ts +16 -0
  188. package/dist/queries.d.ts.map +1 -0
  189. package/dist/queries.js +330 -0
  190. package/dist/query.d.ts +22 -209
  191. package/dist/query.d.ts.map +1 -1
  192. package/dist/query.js +3 -494
  193. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  194. package/dist/questions.d.ts.map +1 -0
  195. package/dist/{chat/questions.js → questions.js} +14 -8
  196. package/dist/queue.d.ts +40 -0
  197. package/dist/queue.d.ts.map +1 -0
  198. package/dist/queue.js +482 -0
  199. package/dist/reach.d.ts +31 -15
  200. package/dist/reach.d.ts.map +1 -1
  201. package/dist/reach.js +385 -176
  202. package/dist/react.d.ts +27 -3
  203. package/dist/react.d.ts.map +1 -1
  204. package/dist/react.js +33 -1
  205. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  206. package/dist/read.d.ts.map +1 -0
  207. package/dist/{chat/read.js → read.js} +4 -0
  208. package/dist/readiness.d.ts +36 -21
  209. package/dist/readiness.d.ts.map +1 -1
  210. package/dist/readiness.js +20 -18
  211. package/dist/reads.d.ts +38 -10
  212. package/dist/reads.d.ts.map +1 -1
  213. package/dist/reads.js +174 -83
  214. package/dist/recovery.d.ts +4 -0
  215. package/dist/recovery.d.ts.map +1 -1
  216. package/dist/recovery.js +59 -2
  217. package/dist/refresh.d.ts +18 -15
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +145 -79
  220. package/dist/refusal.d.ts +5 -0
  221. package/dist/refusal.d.ts.map +1 -0
  222. package/dist/refusal.js +55 -0
  223. package/dist/replica.d.ts +45 -38
  224. package/dist/replica.d.ts.map +1 -1
  225. package/dist/replica.js +319 -229
  226. package/dist/retried.d.ts +30 -0
  227. package/dist/retried.d.ts.map +1 -0
  228. package/dist/retried.js +72 -0
  229. package/dist/room-draft.d.ts +53 -13
  230. package/dist/room-draft.d.ts.map +1 -1
  231. package/dist/room-draft.js +405 -115
  232. package/dist/room-drafts.d.ts +24 -0
  233. package/dist/room-drafts.d.ts.map +1 -0
  234. package/dist/room-drafts.js +222 -0
  235. package/dist/room-list.d.ts +10 -0
  236. package/dist/room-list.d.ts.map +1 -0
  237. package/dist/room-list.js +47 -0
  238. package/dist/rows.d.ts +40 -32
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +72 -123
  241. package/dist/run-tables.d.ts +25 -0
  242. package/dist/run-tables.d.ts.map +1 -0
  243. package/dist/run-tables.js +98 -0
  244. package/dist/running.d.ts +5 -0
  245. package/dist/running.d.ts.map +1 -0
  246. package/dist/running.js +10 -0
  247. package/dist/runs.d.ts +27 -0
  248. package/dist/runs.d.ts.map +1 -0
  249. package/dist/runs.js +92 -0
  250. package/dist/runtime.d.ts +38 -0
  251. package/dist/runtime.d.ts.map +1 -0
  252. package/dist/runtime.js +1 -0
  253. package/dist/save.d.ts +45 -87
  254. package/dist/save.d.ts.map +1 -1
  255. package/dist/save.js +402 -286
  256. package/dist/saves.d.ts +34 -0
  257. package/dist/saves.d.ts.map +1 -0
  258. package/dist/saves.js +464 -0
  259. package/dist/search.d.ts +12 -95
  260. package/dist/search.d.ts.map +1 -1
  261. package/dist/search.js +10 -317
  262. package/dist/seed.d.ts +11 -2
  263. package/dist/seed.d.ts.map +1 -1
  264. package/dist/seed.js +71 -1
  265. package/dist/selector.d.ts +3 -0
  266. package/dist/selector.d.ts.map +1 -0
  267. package/dist/selector.js +22 -0
  268. package/dist/shared.d.ts +1 -10
  269. package/dist/shared.d.ts.map +1 -1
  270. package/dist/shared.js +13 -135
  271. package/dist/shown.d.ts +35 -0
  272. package/dist/shown.d.ts.map +1 -0
  273. package/dist/shown.js +327 -0
  274. package/dist/socket/admission.d.ts +7 -0
  275. package/dist/socket/admission.d.ts.map +1 -0
  276. package/dist/socket/admission.js +39 -0
  277. package/dist/socket/answers.d.ts +6 -0
  278. package/dist/socket/answers.d.ts.map +1 -0
  279. package/dist/socket/answers.js +20 -0
  280. package/dist/socket/lanes.d.ts +28 -0
  281. package/dist/socket/lanes.d.ts.map +1 -0
  282. package/dist/socket/lanes.js +103 -0
  283. package/dist/socket/reads.d.ts +10 -0
  284. package/dist/socket/reads.d.ts.map +1 -0
  285. package/dist/socket/reads.js +31 -0
  286. package/dist/socket/session.d.ts +41 -0
  287. package/dist/socket/session.d.ts.map +1 -0
  288. package/dist/socket/session.js +26 -0
  289. package/dist/socket.d.ts +70 -0
  290. package/dist/socket.d.ts.map +1 -0
  291. package/dist/socket.js +172 -0
  292. package/dist/source.d.ts +96 -0
  293. package/dist/source.d.ts.map +1 -0
  294. package/dist/source.js +149 -0
  295. package/dist/status.d.ts +4 -5
  296. package/dist/status.d.ts.map +1 -1
  297. package/dist/status.js +3 -7
  298. package/dist/store/installs.d.ts +30 -0
  299. package/dist/store/installs.d.ts.map +1 -0
  300. package/dist/store/installs.js +40 -0
  301. package/dist/store/readiness.d.ts +11 -0
  302. package/dist/store/readiness.d.ts.map +1 -0
  303. package/dist/store/readiness.js +68 -0
  304. package/dist/store/records.d.ts +234 -0
  305. package/dist/store/records.d.ts.map +1 -0
  306. package/dist/store/records.js +474 -0
  307. package/dist/store/room-held.d.ts +8 -0
  308. package/dist/store/room-held.d.ts.map +1 -0
  309. package/dist/store/room-held.js +17 -0
  310. package/dist/store/rooms-shown.d.ts +8 -0
  311. package/dist/store/rooms-shown.d.ts.map +1 -0
  312. package/dist/store/rooms-shown.js +13 -0
  313. package/dist/store/space.d.ts +11 -0
  314. package/dist/store/space.d.ts.map +1 -0
  315. package/dist/store/space.js +41 -0
  316. package/dist/store/watchers.d.ts +17 -0
  317. package/dist/store/watchers.d.ts.map +1 -0
  318. package/dist/store/watchers.js +56 -0
  319. package/dist/store/writes.d.ts +24 -0
  320. package/dist/store/writes.d.ts.map +1 -0
  321. package/dist/store/writes.js +125 -0
  322. package/dist/store.d.ts +115 -160
  323. package/dist/store.d.ts.map +1 -1
  324. package/dist/store.js +171 -762
  325. package/dist/stored.d.ts +181 -0
  326. package/dist/stored.d.ts.map +1 -0
  327. package/dist/stored.js +807 -0
  328. package/dist/surface.d.ts +100 -0
  329. package/dist/surface.d.ts.map +1 -0
  330. package/dist/surface.js +258 -0
  331. package/dist/sync.d.ts +21 -0
  332. package/dist/sync.d.ts.map +1 -0
  333. package/dist/sync.js +557 -0
  334. package/dist/tables.d.ts +362 -204
  335. package/dist/tables.d.ts.map +1 -1
  336. package/dist/tables.js +378 -264
  337. package/dist/tallies.d.ts +18 -0
  338. package/dist/tallies.d.ts.map +1 -0
  339. package/dist/tallies.js +128 -0
  340. package/dist/transfer.d.ts +0 -5
  341. package/dist/transfer.d.ts.map +1 -1
  342. package/dist/turn.d.ts +1 -1
  343. package/dist/turn.d.ts.map +1 -1
  344. package/dist/turn.js +28 -20
  345. package/dist/validation.d.ts +31 -0
  346. package/dist/validation.d.ts.map +1 -0
  347. package/dist/validation.js +144 -0
  348. package/dist/windows.d.ts +1 -11
  349. package/dist/windows.d.ts.map +1 -1
  350. package/dist/windows.js +2 -70
  351. package/dist/wire.d.ts +89 -17
  352. package/dist/wire.d.ts.map +1 -1
  353. package/dist/wire.js +38 -15
  354. package/package.json +16 -20
  355. package/AGENTS.md +0 -308
  356. package/dist/attempt.d.ts +0 -16
  357. package/dist/attempt.d.ts.map +0 -1
  358. package/dist/attempt.js +0 -70
  359. package/dist/binary.d.ts.map +0 -1
  360. package/dist/binary.js +0 -8
  361. package/dist/chat/acts.d.ts +0 -33
  362. package/dist/chat/acts.d.ts.map +0 -1
  363. package/dist/chat/acts.js +0 -36
  364. package/dist/chat/context.d.ts +0 -3
  365. package/dist/chat/context.d.ts.map +0 -1
  366. package/dist/chat/earlier.d.ts +0 -10
  367. package/dist/chat/earlier.d.ts.map +0 -1
  368. package/dist/chat/earlier.js +0 -54
  369. package/dist/chat/house.d.ts +0 -25
  370. package/dist/chat/house.d.ts.map +0 -1
  371. package/dist/chat/house.js +0 -38
  372. package/dist/chat/input.d.ts +0 -11
  373. package/dist/chat/input.d.ts.map +0 -1
  374. package/dist/chat/input.js +0 -92
  375. package/dist/chat/kit.d.ts +0 -61
  376. package/dist/chat/kit.d.ts.map +0 -1
  377. package/dist/chat/kit.js +0 -123
  378. package/dist/chat/lasting.d.ts +0 -6
  379. package/dist/chat/lasting.d.ts.map +0 -1
  380. package/dist/chat/lasting.js +0 -19
  381. package/dist/chat/list.d.ts +0 -28
  382. package/dist/chat/list.d.ts.map +0 -1
  383. package/dist/chat/list.js +0 -103
  384. package/dist/chat/markdown.d.ts +0 -21
  385. package/dist/chat/markdown.d.ts.map +0 -1
  386. package/dist/chat/markdown.js +0 -246
  387. package/dist/chat/message.d.ts +0 -7
  388. package/dist/chat/message.d.ts.map +0 -1
  389. package/dist/chat/message.js +0 -237
  390. package/dist/chat/messages.d.ts +0 -29
  391. package/dist/chat/messages.d.ts.map +0 -1
  392. package/dist/chat/messages.js +0 -190
  393. package/dist/chat/name.d.ts +0 -7
  394. package/dist/chat/name.d.ts.map +0 -1
  395. package/dist/chat/name.js +0 -37
  396. package/dist/chat/opened.d.ts +0 -12
  397. package/dist/chat/opened.d.ts.map +0 -1
  398. package/dist/chat/opened.js +0 -19
  399. package/dist/chat/overlay.d.ts +0 -32
  400. package/dist/chat/overlay.d.ts.map +0 -1
  401. package/dist/chat/overlay.js +0 -103
  402. package/dist/chat/parts.d.ts +0 -58
  403. package/dist/chat/parts.d.ts.map +0 -1
  404. package/dist/chat/parts.js +0 -120
  405. package/dist/chat/pieces.d.ts +0 -62
  406. package/dist/chat/pieces.d.ts.map +0 -1
  407. package/dist/chat/pieces.js +0 -1110
  408. package/dist/chat/process.d.ts +0 -20
  409. package/dist/chat/process.d.ts.map +0 -1
  410. package/dist/chat/process.js +0 -32
  411. package/dist/chat/provider.d.ts +0 -68
  412. package/dist/chat/provider.d.ts.map +0 -1
  413. package/dist/chat/provider.js +0 -619
  414. package/dist/chat/question.d.ts +0 -9
  415. package/dist/chat/question.d.ts.map +0 -1
  416. package/dist/chat/question.js +0 -69
  417. package/dist/chat/questions.d.ts.map +0 -1
  418. package/dist/chat/read.d.ts.map +0 -1
  419. package/dist/chat/ready.d.ts +0 -37
  420. package/dist/chat/ready.d.ts.map +0 -1
  421. package/dist/chat/ready.js +0 -93
  422. package/dist/chat/room-file.d.ts +0 -8
  423. package/dist/chat/room-file.d.ts.map +0 -1
  424. package/dist/chat/room-file.js +0 -72
  425. package/dist/chat/steady.d.ts +0 -3
  426. package/dist/chat/steady.d.ts.map +0 -1
  427. package/dist/chat/steady.js +0 -26
  428. package/dist/chat/style.d.ts +0 -4
  429. package/dist/chat/style.d.ts.map +0 -1
  430. package/dist/chat/style.js +0 -306
  431. package/dist/chat.d.ts +0 -15
  432. package/dist/chat.d.ts.map +0 -1
  433. package/dist/chat.js +0 -8
  434. package/dist/fence.d.ts +0 -6
  435. package/dist/fence.d.ts.map +0 -1
  436. package/dist/fence.js +0 -10
  437. package/dist/log.d.ts +0 -5
  438. package/dist/log.d.ts.map +0 -1
  439. package/dist/log.js +0 -14
  440. package/dist/read-side.d.ts +0 -27
  441. package/dist/read-side.d.ts.map +0 -1
  442. package/dist/read-side.js +0 -1179
@@ -0,0 +1,474 @@
1
+ import { composedOf } from '../collection.js';
2
+ import { attachmentLocalId } from '../identity.js';
3
+ import { lockingMode } from '../presence.js';
4
+ import { readsRuntime } from '../tables.js';
5
+ const FILE = '\u0000file';
6
+ const UNSTATED = {
7
+ lastCompleted: null,
8
+ providerLimits: [],
9
+ capabilities: [],
10
+ member: null,
11
+ timeZone: null,
12
+ targets: {},
13
+ conversationList: null,
14
+ agentList: null,
15
+ conversationCursor: null,
16
+ chatPins: [],
17
+ readUntil: null,
18
+ roomList: null,
19
+ queriesOnly: [],
20
+ };
21
+ function batchFacts(batch) {
22
+ return { paths: batch.changes.map(({ path }) => path), moving: batch.between !== undefined };
23
+ }
24
+ function batchFiles(batch) {
25
+ return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
26
+ }
27
+ function draftFiles(drafts) {
28
+ return drafts.flatMap(({ parts }) => (parts.file === undefined ? [] : [parts.file.localId]));
29
+ }
30
+ function roomDraftRow(record) {
31
+ return { path: record.path, record: JSON.stringify(record), files: draftFiles([record]) };
32
+ }
33
+ function authoredRows({ locator, queue, stored, founded, saved, roomDrafts, consumedRoomDrafts, }) {
34
+ const held = new Set((stored ?? []).map(({ id }) => id));
35
+ return {
36
+ locator,
37
+ ...(queue === undefined
38
+ ? {}
39
+ : {
40
+ order: queue.map(({ id }) => id),
41
+ added: queue
42
+ .filter(({ id }) => !held.has(id))
43
+ .map((batch) => {
44
+ const drafts = saved?.get(batch.id) ?? [];
45
+ return {
46
+ id: batch.id,
47
+ batch: JSON.stringify(batch),
48
+ state: JSON.stringify({
49
+ drafts,
50
+ submission: { state: 'waiting' },
51
+ lost: false,
52
+ }),
53
+ files: [...batchFiles(batch), ...draftFiles(drafts)],
54
+ ...batchFacts(batch),
55
+ };
56
+ }),
57
+ }),
58
+ ...(founded === undefined
59
+ ? {}
60
+ : {
61
+ founded: founded.map((batch) => ({
62
+ id: batch.id,
63
+ batch: JSON.stringify(batch),
64
+ files: batchFiles(batch),
65
+ ...batchFacts(batch),
66
+ })),
67
+ }),
68
+ ...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
69
+ ...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
70
+ };
71
+ }
72
+ function marked(value) {
73
+ return typeof value === 'object' && value !== null && FILE in value;
74
+ }
75
+ function keyed(keys, value) {
76
+ const stored = [];
77
+ const files = [];
78
+ const record = JSON.stringify(value, (_name, held) => {
79
+ if (!(held instanceof Blob))
80
+ return held;
81
+ let key = keys.get(held);
82
+ if (key === undefined) {
83
+ key = attachmentLocalId();
84
+ keys.set(held, key);
85
+ }
86
+ stored.push({ key, blob: held });
87
+ files.push(key);
88
+ return { [FILE]: key, type: held.type };
89
+ });
90
+ return { record, files, stored };
91
+ }
92
+ async function filed(value, read) {
93
+ if (Array.isArray(value))
94
+ return Promise.all(value.map((item) => filed(item, read)));
95
+ if (marked(value))
96
+ return read(value[FILE], value.type);
97
+ if (typeof value !== 'object' || value === null)
98
+ return value;
99
+ const restored = {};
100
+ for (const [name, item] of Object.entries(value))
101
+ restored[name] = await filed(item, read);
102
+ return restored;
103
+ }
104
+ function roomOf(row) {
105
+ return {
106
+ record: { ...JSON.parse(row.record), key: row.key },
107
+ indexed: row.indexed,
108
+ documents: row.documents,
109
+ };
110
+ }
111
+ function json(value, fallback) {
112
+ return value === undefined ? fallback : JSON.parse(value);
113
+ }
114
+ function coverOf(kept, answer) {
115
+ const { log, whole, rooms, removed, queues } = answer;
116
+ const queued = new Map(queues.map(({ locator, ids }) => [locator, ids]));
117
+ const fresh = whole || kept === null || kept.log.token !== log.token;
118
+ if (!fresh && log.at < kept.log.at)
119
+ return kept;
120
+ const held = fresh ? { rooms: new Map(), locking: new Set() } : kept;
121
+ for (const locator of removed) {
122
+ held.rooms.delete(locator);
123
+ held.locking.delete(locator);
124
+ }
125
+ for (const { locator, ...room } of rooms) {
126
+ held.rooms.set(locator, room);
127
+ if (lockingMode(room.offline))
128
+ held.locking.add(locator);
129
+ else
130
+ held.locking.delete(locator);
131
+ }
132
+ return { log, rooms: held.rooms, locking: held.locking, queues: queued };
133
+ }
134
+ export function openRuntimeStore(database) {
135
+ let written = 0;
136
+ let covered = null;
137
+ let kept = null;
138
+ const authored = {
139
+ ask(request) {
140
+ if (!readsRuntime(request))
141
+ written += 1;
142
+ return database.ask(request);
143
+ },
144
+ };
145
+ const keys = new WeakMap();
146
+ const read = async (key, type) => {
147
+ const blob = await authored.ask({ kind: 'authored.file', key, type });
148
+ keys.set(blob, key);
149
+ return blob;
150
+ };
151
+ const restored = async (records) => Promise.all(records.map(async (record) => (await filed(JSON.parse(record), read))));
152
+ const amend = async (locator, id, amendment) => {
153
+ await authored.ask({
154
+ kind: 'authored.amend',
155
+ locator,
156
+ id,
157
+ amendment: JSON.stringify(amendment),
158
+ });
159
+ };
160
+ const fact = (name) => authored.ask({ kind: 'authored.fact', name });
161
+ const changed = new Map();
162
+ const change = (key) => changed.set(key, (changed.get(key) ?? 0) + 1);
163
+ return {
164
+ opened() {
165
+ return authored.ask({ kind: 'replica.open' });
166
+ },
167
+ async rooms(locators) {
168
+ const held = await authored.ask({ kind: 'replica.rooms', locators: locators ?? null });
169
+ return held.map(roomOf);
170
+ },
171
+ async room(locator) {
172
+ const { room, queue } = await authored.ask({ kind: 'replica.room', locator });
173
+ return {
174
+ room: room === null ? null : { ...roomOf(room), overlaid: new Set(room.overlaid) },
175
+ queue: queue.map(({ batch, state }) => ({
176
+ batch: JSON.parse(batch),
177
+ state: JSON.parse(state),
178
+ })),
179
+ };
180
+ },
181
+ covering() {
182
+ if (covered?.at === written)
183
+ return covered.cover;
184
+ const held = {
185
+ at: written,
186
+ cover: authored
187
+ .ask({ kind: 'replica.covering', since: kept?.log ?? null })
188
+ .then((answer) => {
189
+ kept = coverOf(kept, answer);
190
+ return kept;
191
+ }),
192
+ };
193
+ covered = held;
194
+ held.cover.catch(() => {
195
+ if (covered === held)
196
+ covered = null;
197
+ });
198
+ return held.cover;
199
+ },
200
+ offline(locator) {
201
+ return authored.ask({ kind: 'replica.offline', locator });
202
+ },
203
+ async held() {
204
+ const { held, staged } = await authored.ask({ kind: 'replica.held' });
205
+ return { held: new Set(held), staged: new Set(staged) };
206
+ },
207
+ async status() {
208
+ const { queued, lastCompleted, changes, resets, returned } = await authored.ask({
209
+ kind: 'authored.status',
210
+ });
211
+ return {
212
+ queued,
213
+ lastCompleted: json(lastCompleted ?? undefined, null),
214
+ unsent: changes.map(({ locator, path }) => ({ room: locator, path })),
215
+ resets,
216
+ returned: returned.map((record) => JSON.parse(record)),
217
+ };
218
+ },
219
+ async batch(locator, id) {
220
+ const held = await authored.ask({ kind: 'authored.batch', locator, id });
221
+ return held === null ? null : JSON.parse(held);
222
+ },
223
+ order(locator) {
224
+ return authored.ask({ kind: 'authored.order', locator });
225
+ },
226
+ queued() {
227
+ return authored.ask({ kind: 'authored.queued' });
228
+ },
229
+ async moving() {
230
+ const { queues, pending } = await authored.ask({ kind: 'authored.moving' });
231
+ return {
232
+ queued: new Map(queues.map(({ locator, ids }) => [locator, ids])),
233
+ moving: pending.map(({ locator, batch, state }) => ({
234
+ locator,
235
+ batch: JSON.parse(batch),
236
+ state: JSON.parse(state),
237
+ })),
238
+ };
239
+ },
240
+ async pending(locator, id) {
241
+ const { state, room } = await authored.ask({ kind: 'authored.pending', locator, id });
242
+ return { state: state === null ? undefined : JSON.parse(state), room };
243
+ },
244
+ facts: (async (names) => {
245
+ const held = await authored.ask({ kind: 'replica.facts', names: names ?? null });
246
+ return Object.fromEntries((names ?? Object.keys(UNSTATED)).map((name) => [
247
+ name,
248
+ json(held[name], UNSTATED[name]),
249
+ ]));
250
+ }),
251
+ async presentation(app) {
252
+ const held = await authored.ask({ kind: 'replica.presentation', app });
253
+ return held === null ? undefined : JSON.parse(held);
254
+ },
255
+ async demote() {
256
+ await authored.ask({ kind: 'replica.demote' });
257
+ },
258
+ query(plan, rooms, follows, budget) {
259
+ return authored.ask({ kind: 'replica.query', plan, rooms, follows, budget });
260
+ },
261
+ named(plan, rooms, handles) {
262
+ return authored.ask({ kind: 'replica.named', plan, rooms, handles });
263
+ },
264
+ changes(keys) {
265
+ return keys.reduce((total, key) => total + (changed.get(key) ?? 0), 0);
266
+ },
267
+ entries(key, view, paths) {
268
+ return authored.ask({ kind: 'replica.entries', key, view, paths });
269
+ },
270
+ typed(key, view, paths) {
271
+ return authored.ask({ kind: 'replica.typed', key, view, paths });
272
+ },
273
+ referrers(key, view, targets) {
274
+ return authored.ask({ kind: 'replica.referrers', key, view, targets });
275
+ },
276
+ holders(key, view, sought) {
277
+ return authored.ask({ kind: 'replica.holders', key, view, sought });
278
+ },
279
+ folders(key, paths) {
280
+ return authored.ask({ kind: 'replica.folders', key, paths });
281
+ },
282
+ typedWithin(key, view, roots, within) {
283
+ return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
284
+ },
285
+ stage(record, composition, page) {
286
+ return authored.ask({
287
+ kind: 'replica.stage',
288
+ locator: record.locator,
289
+ transfer: record.transfer,
290
+ key: record.key,
291
+ fingerprint: composedOf(composition).fingerprint,
292
+ entries: page.entries,
293
+ folders: page.folders,
294
+ part: page.part ?? null,
295
+ });
296
+ },
297
+ resume(record, composition, parts, published) {
298
+ return authored.ask({
299
+ kind: 'replica.resume',
300
+ locator: record.locator,
301
+ transfer: record.transfer,
302
+ fingerprint: composedOf(composition).fingerprint,
303
+ parts,
304
+ published,
305
+ });
306
+ },
307
+ async refresh(key, composition, page) {
308
+ await authored.ask({
309
+ kind: 'replica.refresh',
310
+ key,
311
+ composed: composedOf(composition),
312
+ entries: page.entries,
313
+ removals: page.removals,
314
+ folders: page.folders,
315
+ folderRemovals: page.folderRemovals,
316
+ });
317
+ },
318
+ async unrefresh(key) {
319
+ await authored.ask({ kind: 'replica.unrefresh', key });
320
+ },
321
+ commit({ rooms, writes = [], files = [], whole = false }) {
322
+ for (const room of rooms)
323
+ change(room.key);
324
+ return authored.ask({
325
+ kind: 'replica.commit',
326
+ ...(writes.length === 0 && files.length === 0
327
+ ? {}
328
+ : { authored: { writes: writes.map(authoredRows), files, whole } }),
329
+ rooms,
330
+ });
331
+ },
332
+ async fence(locators) {
333
+ await authored.ask({ kind: 'replica.fence', locators });
334
+ },
335
+ async erase(locator, limit) {
336
+ return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
337
+ },
338
+ async abandon(locator) {
339
+ await authored.ask({ kind: 'replica.abandon', locator });
340
+ },
341
+ async unfence(locators) {
342
+ return new Set(await authored.ask({ kind: 'replica.unfence', locators }));
343
+ },
344
+ async release(key) {
345
+ await authored.ask({ kind: 'replica.release', key });
346
+ },
347
+ async rederive(key, composition, bytes, ms, floor) {
348
+ change(key);
349
+ return authored.ask({
350
+ kind: 'replica.rederive',
351
+ key,
352
+ composed: composedOf(composition),
353
+ bytes,
354
+ ms,
355
+ floor,
356
+ });
357
+ },
358
+ async fact(name, value) {
359
+ await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
360
+ },
361
+ submit(locator, id, submission, lost) {
362
+ return amend(locator, id, { submission, lost });
363
+ },
364
+ keepUpload(locator, id, upload) {
365
+ return amend(locator, id, { upload });
366
+ },
367
+ async roomDrafts(locator, paths) {
368
+ const held = await authored.ask({
369
+ kind: 'authored.roomDrafts',
370
+ locator: locator ?? null,
371
+ paths: paths ?? null,
372
+ });
373
+ return held.map((record) => JSON.parse(record));
374
+ },
375
+ async present(record) {
376
+ await authored.ask({
377
+ kind: 'replica.present',
378
+ app: record.app,
379
+ value: JSON.stringify(record.value ?? null),
380
+ });
381
+ },
382
+ conversations(conversations) {
383
+ return authored.ask({ kind: 'conversation.held', conversations: conversations ?? null });
384
+ },
385
+ async keepMessages(write) {
386
+ await authored.ask({ kind: 'conversation.keep', ...write });
387
+ },
388
+ messageWindow(conversation, limit, before, phrase = null) {
389
+ return authored.ask({ kind: 'conversation.window', conversation, limit, before, phrase });
390
+ },
391
+ messageCount(conversation, phrase = null) {
392
+ return authored.ask({ kind: 'conversation.count', conversation, phrase });
393
+ },
394
+ turnArrived(conversation, turn) {
395
+ return authored.ask({ kind: 'conversation.turn', conversation, turn });
396
+ },
397
+ conversationRows(conversations) {
398
+ return authored.ask({ kind: 'conversation.rows', conversations });
399
+ },
400
+ conversationFacts() {
401
+ return authored.ask({ kind: 'conversation.facts' });
402
+ },
403
+ async keepConversationFact(fact) {
404
+ await authored.ask({ kind: 'conversation.fact', ...fact });
405
+ },
406
+ storedConversations() {
407
+ return authored.ask({ kind: 'conversation.stored' });
408
+ },
409
+ dropConversations(conversations) {
410
+ return authored.ask({ kind: 'conversation.drop', conversations });
411
+ },
412
+ async chatDrafts() {
413
+ const records = await authored.ask({ kind: 'authored.chatDrafts' });
414
+ return records.map((record) => JSON.parse(record));
415
+ },
416
+ async chatDraft(conversation) {
417
+ const record = await authored.ask({ kind: 'authored.chatDraft.read', conversation });
418
+ return record === null ? null : JSON.parse(record);
419
+ },
420
+ async keepChatDrafts(records) {
421
+ await authored.ask({
422
+ kind: 'authored.chatDraft',
423
+ kept: records.map((record) => ({
424
+ conversation: record.conversation,
425
+ record: JSON.stringify(record),
426
+ })),
427
+ dropped: [],
428
+ });
429
+ },
430
+ async dropChatDraft(conversation) {
431
+ await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
432
+ },
433
+ async calls() {
434
+ return restored(await authored.ask({ kind: 'authored.calls' }));
435
+ },
436
+ async keepCall(record) {
437
+ const { stored, ...kept } = keyed(keys, record);
438
+ await authored.ask({
439
+ kind: 'authored.call',
440
+ operation: record.operation,
441
+ kept,
442
+ files: stored,
443
+ });
444
+ },
445
+ async dropCall(operation) {
446
+ await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
447
+ },
448
+ async keepRoomDraft(record, files) {
449
+ const { path, ...kept } = roomDraftRow(record);
450
+ await authored.ask({
451
+ kind: 'authored.roomDraft',
452
+ locator: record.locator,
453
+ path,
454
+ kept,
455
+ files,
456
+ });
457
+ },
458
+ async discardRoomDraft(locator, path) {
459
+ await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
460
+ },
461
+ fences() {
462
+ return authored.ask({ kind: 'authored.fences' });
463
+ },
464
+ generation() {
465
+ return fact('generation');
466
+ },
467
+ async rememberGeneration(value) {
468
+ await authored.ask({ kind: 'authored.remember', name: 'generation', value });
469
+ },
470
+ file(key, type) {
471
+ return authored.ask({ kind: 'authored.file', key, type });
472
+ },
473
+ };
474
+ }
@@ -0,0 +1,8 @@
1
+ export type RoomHeld<T> = {
2
+ of(locator: string, key: string): T | undefined;
3
+ hold(locator: string, key: string, value: T): void;
4
+ drop(locator: string, key: string): void;
5
+ forget(locator: string): void;
6
+ };
7
+ export declare function createRoomHeld<T>(): RoomHeld<T>;
8
+ //# sourceMappingURL=room-held.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-held.d.ts","sourceRoot":"","sources":["../../src/store/room-held.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACnD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,cAAc,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAgB/C"}
@@ -0,0 +1,17 @@
1
+ export function createRoomHeld() {
2
+ const rooms = new Map();
3
+ return {
4
+ of: (locator, key) => rooms.get(locator)?.get(key),
5
+ hold(locator, key, value) {
6
+ const room = rooms.get(locator) ?? new Map();
7
+ room.set(key, value);
8
+ rooms.set(locator, room);
9
+ },
10
+ drop(locator, key) {
11
+ rooms.get(locator)?.delete(key);
12
+ },
13
+ forget(locator) {
14
+ rooms.delete(locator);
15
+ },
16
+ };
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { ListedEntry, Listing } from '../listing.js';
2
+ export type RoomsShown = {
3
+ now(): Listing | null;
4
+ show(listing: Listing | null): void;
5
+ patch(entries: readonly ListedEntry[]): void;
6
+ };
7
+ export declare function createRoomsShown(): RoomsShown;
8
+ //# sourceMappingURL=rooms-shown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rooms-shown.d.ts","sourceRoot":"","sources":["../../src/store/rooms-shown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF,wBAAgB,gBAAgB,IAAI,UAAU,CAW7C"}
@@ -0,0 +1,13 @@
1
+ export function createRoomsShown() {
2
+ let shown = null;
3
+ return {
4
+ now: () => shown,
5
+ show(listing) {
6
+ shown = listing === null ? null : new Map(listing);
7
+ },
8
+ patch(entries) {
9
+ for (const entry of entries)
10
+ shown?.set(entry.locator, entry);
11
+ },
12
+ };
13
+ }
@@ -0,0 +1,11 @@
1
+ import type { RuntimeDatabase } from '../tables.js';
2
+ export type Space = {
3
+ full(): boolean;
4
+ fill(): boolean;
5
+ probing(): boolean;
6
+ probeEachMinute(): void;
7
+ probe(): Promise<void>;
8
+ stop(): void;
9
+ };
10
+ export declare function createSpace(database: RuntimeDatabase, freed: () => void): Space;
11
+ //# sourceMappingURL=space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../src/store/space.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,IAAI,OAAO,CAAC;IAChB,IAAI,IAAI,OAAO,CAAC;IAChB,OAAO,IAAI,OAAO,CAAC;IACnB,eAAe,IAAI,IAAI,CAAC;IACxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,IAAI,CAAC;CACd,CAAC;AAEF,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,KAAK,CA0C/E"}
@@ -0,0 +1,41 @@
1
+ export function createSpace(database, freed) {
2
+ let full = false;
3
+ let probing = null;
4
+ let testing = null;
5
+ function probe() {
6
+ testing ??= database.ask({ kind: 'space.probe' }).then(() => {
7
+ testing = null;
8
+ if (full) {
9
+ full = false;
10
+ if (probing !== null)
11
+ clearInterval(probing);
12
+ probing = null;
13
+ freed();
14
+ }
15
+ }, () => {
16
+ testing = null;
17
+ });
18
+ return testing;
19
+ }
20
+ return {
21
+ full: () => full,
22
+ fill() {
23
+ if (full)
24
+ return false;
25
+ full = true;
26
+ return true;
27
+ },
28
+ probing: () => probing !== null,
29
+ probeEachMinute() {
30
+ // A device whose storage filled after its install tries a write each minute, so space freed elsewhere ends its read-only mode without a Retry.
31
+ probing = setInterval(() => {
32
+ void probe();
33
+ }, 60_000);
34
+ },
35
+ probe,
36
+ stop() {
37
+ if (probing !== null)
38
+ clearInterval(probing);
39
+ },
40
+ };
41
+ }
@@ -0,0 +1,17 @@
1
+ export type Watcher = {
2
+ held(): boolean;
3
+ stop(): void;
4
+ answer(value: unknown): void;
5
+ };
6
+ export type Watching = 'all' | 'waiting' | 'ready';
7
+ type Watchers = {
8
+ publication(work: () => Promise<void>): Promise<void>;
9
+ owing<T>(topic: string, add: (owed: T | undefined) => T, work: (owed: T) => Promise<void>): Promise<void>;
10
+ watch(topic: string, notify: (value: unknown) => void): Watcher;
11
+ watching(topic: string, which?: Watching): readonly Watcher[];
12
+ tell(topic: string, value: unknown): void;
13
+ close(): void;
14
+ };
15
+ export declare function createWatchers(unpublished: (error: unknown) => void): Watchers;
16
+ export {};
17
+ //# sourceMappingURL=watchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchers.d.ts","sourceRoot":"","sources":["../../src/store/watchers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,IAAI,OAAO,CAAC;IAChB,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC;AAMnD,KAAK,QAAQ,GAAG;IACd,WAAW,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,KAAK,CAAC,CAAC,EACL,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,OAAO,EAAE,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1C,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,wBAAgB,cAAc,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,QAAQ,CA6D9E"}
@@ -0,0 +1,56 @@
1
+ export function createWatchers(unpublished) {
2
+ let published = Promise.resolve();
3
+ const topics = new Map();
4
+ const owed = new Map();
5
+ function publication(work) {
6
+ published = published.then(work).catch(unpublished);
7
+ return published;
8
+ }
9
+ return {
10
+ publication,
11
+ owing(topic, add, work) {
12
+ const held = owed.get(topic);
13
+ if (held !== undefined) {
14
+ held.value = add(held.value);
15
+ return held.shown;
16
+ }
17
+ const owing = { value: add(undefined), shown: Promise.resolve() };
18
+ owed.set(topic, owing);
19
+ owing.shown = publication(async () => {
20
+ owed.delete(topic);
21
+ await work(owing.value);
22
+ });
23
+ return owing.shown;
24
+ },
25
+ watch(topic, notify) {
26
+ const held = topics.get(topic) ?? new Set();
27
+ topics.set(topic, held);
28
+ const watcher = {
29
+ ready: false,
30
+ held: () => topics.get(topic)?.has(watcher) === true,
31
+ stop() {
32
+ const on = topics.get(topic);
33
+ on?.delete(watcher);
34
+ if (on?.size === 0)
35
+ topics.delete(topic);
36
+ },
37
+ answer(value) {
38
+ watcher.ready = true;
39
+ notify(value);
40
+ },
41
+ };
42
+ held.add(watcher);
43
+ return watcher;
44
+ },
45
+ watching(topic, which = 'all') {
46
+ return [...(topics.get(topic) ?? [])].filter(({ ready }) => which === 'all' || ready === (which === 'ready'));
47
+ },
48
+ tell(topic, value) {
49
+ for (const watcher of topics.get(topic) ?? [])
50
+ watcher.answer(value);
51
+ },
52
+ close() {
53
+ topics.clear();
54
+ },
55
+ };
56
+ }