@agentshouse/mdruntime 0.1.0-cfe148b32e3d8 → 0.1.0-cfef69803eb1c

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 +304 -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 -4
  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 +17 -16
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +269 -158
  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 +3 -2
  29. package/dist/chain.d.ts.map +1 -1
  30. package/dist/chain.js +5 -2
  31. package/dist/change-set.d.ts +4 -0
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +6 -0
  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 +52 -29
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +65 -28
  43. package/dist/collection.d.ts +33 -7
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +50 -21
  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 +10 -7
  50. package/dist/compile.d.ts.map +1 -1
  51. package/dist/compile.js +349 -315
  52. package/dist/connection.d.ts +6 -141
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +119 -5015
  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 +1045 -825
  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 -5
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +12 -0
  79. package/dist/entry.d.ts +29 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +134 -34
  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 +155 -59
  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 -2
  104. package/dist/identity.d.ts.map +1 -1
  105. package/dist/identity.js +1 -4
  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 +23 -6
  122. package/dist/live.d.ts.map +1 -1
  123. package/dist/live.js +138 -38
  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 +21 -8
  137. package/dist/memory.d.ts.map +1 -1
  138. package/dist/memory.js +300 -110
  139. package/dist/messages.d.ts +44 -5
  140. package/dist/messages.d.ts.map +1 -1
  141. package/dist/messages.js +129 -39
  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 +31 -13
  155. package/dist/observation.d.ts.map +1 -1
  156. package/dist/observation.js +219 -82
  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 -15
  167. package/dist/outcome.d.ts.map +1 -1
  168. package/dist/outcome.js +52 -5
  169. package/dist/overlay.d.ts +24 -8
  170. package/dist/overlay.d.ts.map +1 -1
  171. package/dist/overlay.js +143 -48
  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 +20 -210
  191. package/dist/query.d.ts.map +1 -1
  192. package/dist/query.js +3 -505
  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 -13
  200. package/dist/reach.d.ts.map +1 -1
  201. package/dist/reach.js +382 -135
  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 +28 -28
  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 -85
  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 +10 -5
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +92 -34
  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 +13 -25
  224. package/dist/replica.d.ts.map +1 -1
  225. package/dist/replica.js +71 -40
  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 +28 -18
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +65 -160
  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 +37 -0
  251. package/dist/runtime.d.ts.map +1 -0
  252. package/dist/runtime.js +1 -0
  253. package/dist/save.d.ts +43 -84
  254. package/dist/save.d.ts.map +1 -1
  255. package/dist/save.js +342 -232
  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 -63
  260. package/dist/search.d.ts.map +1 -1
  261. package/dist/search.js +9 -52
  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 -7
  269. package/dist/shared.d.ts.map +1 -1
  270. package/dist/shared.js +13 -105
  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 +114 -157
  323. package/dist/store.d.ts.map +1 -1
  324. package/dist/store.js +174 -400
  325. package/dist/stored.d.ts +96 -60
  326. package/dist/stored.d.ts.map +1 -1
  327. package/dist/stored.js +531 -291
  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 +162 -104
  335. package/dist/tables.d.ts.map +1 -1
  336. package/dist/tables.js +276 -332
  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/validation.d.ts +5 -4
  343. package/dist/validation.d.ts.map +1 -1
  344. package/dist/validation.js +87 -105
  345. package/dist/windows.d.ts +1 -12
  346. package/dist/windows.d.ts.map +1 -1
  347. package/dist/windows.js +2 -75
  348. package/dist/wire.d.ts +92 -16
  349. package/dist/wire.d.ts.map +1 -1
  350. package/dist/wire.js +38 -14
  351. package/package.json +13 -19
  352. package/AGENTS.md +0 -317
  353. package/dist/attempt.d.ts +0 -16
  354. package/dist/attempt.d.ts.map +0 -1
  355. package/dist/attempt.js +0 -70
  356. package/dist/binary.d.ts.map +0 -1
  357. package/dist/binary.js +0 -8
  358. package/dist/chat/acts.d.ts +0 -33
  359. package/dist/chat/acts.d.ts.map +0 -1
  360. package/dist/chat/acts.js +0 -36
  361. package/dist/chat/context.d.ts +0 -3
  362. package/dist/chat/context.d.ts.map +0 -1
  363. package/dist/chat/earlier.d.ts +0 -10
  364. package/dist/chat/earlier.d.ts.map +0 -1
  365. package/dist/chat/earlier.js +0 -54
  366. package/dist/chat/house.d.ts +0 -25
  367. package/dist/chat/house.d.ts.map +0 -1
  368. package/dist/chat/house.js +0 -38
  369. package/dist/chat/input.d.ts +0 -11
  370. package/dist/chat/input.d.ts.map +0 -1
  371. package/dist/chat/input.js +0 -92
  372. package/dist/chat/kit.d.ts +0 -61
  373. package/dist/chat/kit.d.ts.map +0 -1
  374. package/dist/chat/kit.js +0 -123
  375. package/dist/chat/lasting.d.ts +0 -6
  376. package/dist/chat/lasting.d.ts.map +0 -1
  377. package/dist/chat/lasting.js +0 -19
  378. package/dist/chat/list.d.ts +0 -28
  379. package/dist/chat/list.d.ts.map +0 -1
  380. package/dist/chat/list.js +0 -103
  381. package/dist/chat/markdown.d.ts +0 -20
  382. package/dist/chat/markdown.d.ts.map +0 -1
  383. package/dist/chat/markdown.js +0 -229
  384. package/dist/chat/message.d.ts +0 -7
  385. package/dist/chat/message.d.ts.map +0 -1
  386. package/dist/chat/message.js +0 -254
  387. package/dist/chat/messages.d.ts +0 -35
  388. package/dist/chat/messages.d.ts.map +0 -1
  389. package/dist/chat/messages.js +0 -210
  390. package/dist/chat/name.d.ts +0 -7
  391. package/dist/chat/name.d.ts.map +0 -1
  392. package/dist/chat/name.js +0 -37
  393. package/dist/chat/opened.d.ts +0 -12
  394. package/dist/chat/opened.d.ts.map +0 -1
  395. package/dist/chat/opened.js +0 -19
  396. package/dist/chat/overlay.d.ts +0 -32
  397. package/dist/chat/overlay.d.ts.map +0 -1
  398. package/dist/chat/overlay.js +0 -103
  399. package/dist/chat/parts.d.ts +0 -58
  400. package/dist/chat/parts.d.ts.map +0 -1
  401. package/dist/chat/parts.js +0 -120
  402. package/dist/chat/pieces.d.ts +0 -62
  403. package/dist/chat/pieces.d.ts.map +0 -1
  404. package/dist/chat/pieces.js +0 -1110
  405. package/dist/chat/process.d.ts +0 -20
  406. package/dist/chat/process.d.ts.map +0 -1
  407. package/dist/chat/process.js +0 -32
  408. package/dist/chat/provider.d.ts +0 -70
  409. package/dist/chat/provider.d.ts.map +0 -1
  410. package/dist/chat/provider.js +0 -635
  411. package/dist/chat/question.d.ts +0 -9
  412. package/dist/chat/question.d.ts.map +0 -1
  413. package/dist/chat/question.js +0 -69
  414. package/dist/chat/questions.d.ts.map +0 -1
  415. package/dist/chat/read.d.ts.map +0 -1
  416. package/dist/chat/ready.d.ts +0 -37
  417. package/dist/chat/ready.d.ts.map +0 -1
  418. package/dist/chat/ready.js +0 -93
  419. package/dist/chat/room-file.d.ts +0 -8
  420. package/dist/chat/room-file.d.ts.map +0 -1
  421. package/dist/chat/room-file.js +0 -72
  422. package/dist/chat/steady.d.ts +0 -3
  423. package/dist/chat/steady.d.ts.map +0 -1
  424. package/dist/chat/steady.js +0 -26
  425. package/dist/chat/style.d.ts +0 -4
  426. package/dist/chat/style.d.ts.map +0 -1
  427. package/dist/chat/style.js +0 -307
  428. package/dist/chat.d.ts +0 -15
  429. package/dist/chat.d.ts.map +0 -1
  430. package/dist/chat.js +0 -8
  431. package/dist/fence.d.ts +0 -6
  432. package/dist/fence.d.ts.map +0 -1
  433. package/dist/fence.js +0 -10
  434. package/dist/fulltext.d.ts +0 -27
  435. package/dist/fulltext.d.ts.map +0 -1
  436. package/dist/fulltext.js +0 -368
  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/words.d.ts +0 -19
  441. package/dist/words.d.ts.map +0 -1
  442. package/dist/words.js +0 -150
package/dist/store.js CHANGED
@@ -1,410 +1,184 @@
1
- import { binaryLocalId } from './identity.js';
2
- const FILE = '\u0000file';
3
- function batchFiles(batch) {
4
- return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
5
- }
6
- function draftFiles(drafts) {
7
- return drafts.flatMap(({ parts }) => (parts.file === undefined ? [] : [parts.file.localId]));
8
- }
9
- function roomDraftRow(record) {
10
- return { path: record.path, record: JSON.stringify(record), files: draftFiles([record]) };
11
- }
12
- function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoomDrafts, accepted }, held) {
13
- return {
14
- locator,
15
- ...(queue === undefined
16
- ? {}
17
- : {
18
- order: queue.map(({ id }) => id),
19
- added: queue
20
- .filter(({ id }) => held?.has(id) !== true)
21
- .map((batch) => {
22
- const drafts = saved?.get(batch.id) ?? [];
23
- return {
24
- id: batch.id,
25
- batch: JSON.stringify(batch),
26
- state: JSON.stringify({
27
- drafts,
28
- submission: { state: 'waiting' },
29
- lost: false,
30
- }),
31
- files: [...batchFiles(batch), ...draftFiles(drafts)],
32
- };
33
- }),
34
- }),
35
- ...(founded === undefined
36
- ? {}
37
- : {
38
- founded: founded.map((batch) => ({
39
- id: batch.id,
40
- batch: JSON.stringify(batch),
41
- files: batchFiles(batch),
42
- })),
43
- }),
44
- ...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
45
- ...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
46
- ...(accepted === undefined
47
- ? {}
48
- : {
49
- amendments: accepted.map(({ id, roomVersion }) => ({
50
- id,
51
- amendment: JSON.stringify({ accepted: roomVersion }),
52
- })),
53
- }),
54
- };
55
- }
56
- function marked(value) {
57
- return typeof value === 'object' && value !== null && FILE in value;
58
- }
59
- function keyed(keys, value) {
60
- const stored = [];
61
- const files = [];
62
- const record = JSON.stringify(value, (_name, held) => {
63
- if (!(held instanceof Blob))
64
- return held;
65
- let key = keys.get(held);
66
- if (key === undefined) {
67
- key = binaryLocalId();
68
- keys.set(held, key);
69
- }
70
- stored.push({ key, blob: held });
71
- files.push(key);
72
- return { [FILE]: key, type: held.type };
1
+ import { schemaTypes } from './attached-model.js';
2
+ import { createCell } from './cell.js';
3
+ import { openedFiles } from './opened.js';
4
+ import { compositionOf } from './replica.js';
5
+ import { STARTING } from './status.js';
6
+ import { createInstalls, NO_INSTALL } from './store/installs.js';
7
+ import { openRuntimeStore, } from './store/records.js';
8
+ import { createReadinessQueue } from './store/readiness.js';
9
+ import { createRoomHeld } from './store/room-held.js';
10
+ import { createRoomsShown } from './store/rooms-shown.js';
11
+ import { createSpace } from './store/space.js';
12
+ import { createWatchers } from './store/watchers.js';
13
+ import { createWrites } from './store/writes.js';
14
+ const OPENING = 'store';
15
+ export function createStore(options) {
16
+ const writes = createWrites();
17
+ const watchers = createWatchers(options.unpublished);
18
+ const { lost } = options;
19
+ const installs = createInstalls();
20
+ const seeds = new Map();
21
+ const conflicted = createRoomHeld();
22
+ const attached = createRoomHeld();
23
+ const typesHeld = new Map();
24
+ const device = createCell({
25
+ persistence: options.persistence,
26
+ storageLoss: null,
27
+ completedWhenOpened: false,
28
+ preparing: false,
29
+ sweeping: false,
30
+ unpreparedDemand: new Set(),
31
+ unpreparable: new Set(),
32
+ establishing: new Set(),
33
+ status: STARTING,
73
34
  });
74
- return { record, files, stored };
75
- }
76
- async function filed(value, read) {
77
- if (Array.isArray(value))
78
- return Promise.all(value.map((item) => filed(item, read)));
79
- if (marked(value))
80
- return read(value[FILE], value.type);
81
- if (typeof value !== 'object' || value === null)
82
- return value;
83
- const restored = {};
84
- for (const [name, item] of Object.entries(value))
85
- restored[name] = await filed(item, read);
86
- return restored;
87
- }
88
- function json(value, fallback) {
89
- return value === undefined ? fallback : JSON.parse(value);
90
- }
91
- export function openRuntimeStore(fenced, authored) {
92
- const keys = new WeakMap();
93
- const read = async (key, type) => {
94
- const blob = await authored.ask({ kind: 'authored.file', key, type });
95
- keys.set(blob, key);
96
- return blob;
97
- };
98
- const restored = async (records) => Promise.all(records.map(async (record) => (await filed(JSON.parse(record), read))));
99
- const amend = async (locator, id, amendment) => {
100
- if (fenced(locator))
101
- return;
102
- await authored.ask({
103
- kind: 'authored.amend',
104
- locator,
105
- id,
106
- amendment: JSON.stringify(amendment),
35
+ const space = createSpace(options.database, options.spaceFreed);
36
+ const readiness = createReadinessQueue(options.deliverReadiness, options.unpublished);
37
+ let opening;
38
+ let needed = false;
39
+ function open() {
40
+ needed = true;
41
+ opening ??= options.opening(openRuntimeStore(options.database)).then((opened) => {
42
+ options.retries.succeeded('database', OPENING);
43
+ return opened;
44
+ }, (error) => {
45
+ opening = undefined;
46
+ options.retries.failed('database', OPENING, error);
47
+ throw error;
107
48
  });
108
- };
109
- const fact = (name) => authored.ask({ kind: 'authored.fact', name });
110
- const queued = new Map();
111
- const changed = new Map();
112
- const change = (key) => changed.set(key, (changed.get(key) ?? 0) + 1);
113
- const rows = (writes) => writes.map((write) => authoredRows(write, queued.get(write.locator)));
114
- const noted = (writes) => {
115
- for (const { locator, queue } of writes) {
116
- if (queue !== undefined)
117
- queued.set(locator, new Set(queue.map(({ id }) => id)));
118
- }
119
- };
49
+ return opening;
50
+ }
51
+ function prepareAgain(locator) {
52
+ const { unpreparable } = device.now();
53
+ device.set({
54
+ unpreparable: locator === undefined
55
+ ? new Set()
56
+ : new Set([...unpreparable].filter((held) => held !== locator)),
57
+ });
58
+ }
59
+ function typed(locator, persisted) {
60
+ if (persisted.status === 'unavailable')
61
+ return persisted;
62
+ const schema = persisted.snapshot.schema;
63
+ const held = typesHeld.get(locator);
64
+ if (held !== undefined && held.schema === schema)
65
+ return { ...persisted, types: held.types };
66
+ const types = schemaTypes(schema, options.roomTypes);
67
+ typesHeld.set(locator, { schema, types });
68
+ return { ...persisted, types };
69
+ }
70
+ function recordOf(stored) {
71
+ return { ...stored, model: typed(stored.locator, stored.model) };
72
+ }
73
+ async function rooms(locators) {
74
+ const held = await (await open()).rooms(locators);
75
+ return new Map(held
76
+ .filter(({ record }) => !lost(record.locator))
77
+ .map(({ record, indexed, documents }) => [
78
+ record.locator,
79
+ { record: recordOf(record), indexed, documents },
80
+ ]));
81
+ }
82
+ async function work(locator) {
83
+ if (lost(locator))
84
+ return { replica: undefined, queue: [], states: new Map() };
85
+ const { room, queue } = await (await open()).room(locator);
86
+ const batches = queue.map(({ batch }) => batch);
87
+ const states = new Map(queue.map(({ batch, state }) => [batch.id, state]));
88
+ return {
89
+ replica: room === null
90
+ ? undefined
91
+ : { record: recordOf(room.record), queue: batches, states, overlaid: room.overlaid },
92
+ queue: batches,
93
+ states,
94
+ };
95
+ }
96
+ async function drafts(locator, paths) {
97
+ const held = await (await open()).roomDrafts(locator, paths);
98
+ return held.filter((record) => !lost(record.locator));
99
+ }
120
100
  return {
121
- async opened() {
122
- const held = await authored.ask({ kind: 'replica.open' });
123
- const unindexed = new Set(held.keys.flatMap(({ key, rederiving }) => (rederiving === null ? [] : [key])));
124
- const overlaid = new Map();
125
- for (const { key, path } of held.overlaid) {
126
- const paths = overlaid.get(key) ?? new Set();
127
- paths.add(path);
128
- overlaid.set(key, paths);
129
- }
101
+ device,
102
+ roomsShown: createRoomsShown(),
103
+ space,
104
+ readiness,
105
+ ask: options.database.ask,
106
+ changed: options.changed,
107
+ open,
108
+ needed: () => needed,
109
+ durably: (work) => writes.exclusive(async () => {
110
+ const local = await open();
111
+ return work(local);
112
+ }),
113
+ exclusive: writes.exclusive,
114
+ gathered: writes.gathered,
115
+ written: writes.written,
116
+ startingWrite: writes.startingWrite,
117
+ finishingWrite: writes.finishingWrite,
118
+ ahead: writes.ahead,
119
+ rederive: writes.rederive,
120
+ refreshPage: writes.refreshPage,
121
+ stageBytes: writes.stageBytes,
122
+ deriveBytes: writes.deriveBytes,
123
+ rooms,
124
+ record: async (locator) => (await rooms([locator])).get(locator)?.record,
125
+ work,
126
+ replica: async (locator) => (await work(locator)).replica,
127
+ async covering() {
128
+ const held = await (await open()).covering();
129
+ if (!options.losing())
130
+ return held;
130
131
  return {
131
- rooms: new Map(held.rooms
132
- .filter(({ locator }) => !fenced(locator))
133
- .map(({ locator, key, record }) => [
134
- locator,
135
- { ...JSON.parse(record), key },
136
- ])),
137
- transfers: new Map(held.transfers
138
- .filter(({ locator }) => !fenced(locator))
139
- .map(({ locator, key, record }) => [
140
- locator,
141
- { ...JSON.parse(record), key },
142
- ])),
143
- unindexed,
144
- overlaid,
145
- erasing: held.erasing.length > 0,
146
- orphans: held.orphans,
147
- lastCompleted: json(held.facts.lastCompleted, null),
148
- providerLimits: json(held.facts.providerLimits, []),
149
- capabilities: json(held.facts.capabilities, []),
150
- member: json(held.facts.member, null),
151
- targets: json(held.facts.targets, {}),
152
- presentation: held.presentation.map(({ app, value }) => ({
153
- app,
154
- value: JSON.parse(value),
155
- })),
132
+ rooms: new Map([...held.rooms].filter(([locator]) => !lost(locator))),
133
+ locking: new Set([...held.locking].filter((locator) => !lost(locator))),
134
+ queues: new Map([...held.queues].filter(([locator]) => !lost(locator))),
156
135
  };
157
136
  },
158
- counts(rooms) {
159
- return authored.ask({ kind: 'replica.counts', rooms });
160
- },
161
- query(plan, rooms, budget) {
162
- return authored.ask({ kind: 'replica.query', plan, rooms, budget });
163
- },
164
- changes(keys) {
165
- return keys.reduce((total, key) => total + (changed.get(key) ?? 0), 0);
166
- },
167
- entries(key, view, paths) {
168
- return authored.ask({ kind: 'replica.entries', key, view, paths });
169
- },
170
- typed(key, view, paths) {
171
- return authored.ask({ kind: 'replica.typed', key, view, paths });
172
- },
173
- referrers(key, view, targets, kinds) {
174
- return authored.ask({ kind: 'replica.referrers', key, view, targets, kinds });
175
- },
176
- walk(key, view, after, bytes) {
177
- return authored.ask({ kind: 'replica.walk', key, view, after, bytes });
178
- },
179
- files(key, view, after, limit) {
180
- return authored.ask({ kind: 'replica.files', key, view, after, limit });
181
- },
182
- typedWithin(key, view, roots, within) {
183
- return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
184
- },
185
- search(ask) {
186
- return authored.ask({ kind: 'replica.search', ...ask });
187
- },
188
- async stage(record, composition, page, written) {
189
- if (fenced(record.locator))
190
- return null;
191
- const { key, ...kept } = record;
192
- return authored.ask({
193
- kind: 'replica.stage',
194
- locator: record.locator,
195
- transfer: record.transfer,
196
- record: JSON.stringify(kept),
197
- key,
198
- composition,
199
- entries: page.entries,
200
- folders: page.folders,
201
- ...(written === undefined ? {} : { written }),
202
- });
203
- },
204
- async transferPart(locator, token) {
205
- if (fenced(locator))
206
- return null;
207
- return authored.ask({ kind: 'replica.transferPart', locator, token });
208
- },
209
- async keepPart(locator, token, part) {
210
- if (fenced(locator))
211
- return;
212
- await authored.ask({ kind: 'replica.keepPart', locator, token, part });
213
- },
214
- async refresh(key, page) {
215
- await authored.ask({
216
- kind: 'replica.refresh',
217
- key,
218
- entries: page.entries,
219
- removals: page.removals,
220
- folders: page.folders,
221
- folderRemovals: page.folderRemovals,
222
- });
223
- },
224
- async unrefresh(key) {
225
- await authored.ask({ kind: 'replica.unrefresh', key });
226
- },
227
- async commit({ rooms, writes = [], files = [], whole = false, discards = [] }) {
228
- const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
229
- const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
230
- if (refused !== undefined) {
231
- return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
232
- }
233
- for (const room of rooms)
234
- change(room.key);
235
- const committed = await authored.ask({
236
- kind: 'replica.commit',
237
- ...(kept.length === 0 && files.length === 0 && discards.length === 0
238
- ? {}
239
- : { authored: { writes: rows(kept), files, whole, discards } }),
240
- rooms: rooms.filter(({ locator }) => !fenced(locator)),
241
- });
242
- if (committed.fenced === null || !whole)
243
- noted(kept);
244
- for (const locator of discards)
245
- queued.delete(locator);
246
- return committed;
247
- },
248
- async fence(locators) {
249
- await authored.ask({ kind: 'replica.fence', locators });
250
- for (const locator of locators)
251
- queued.delete(locator);
252
- },
253
- async erase(locator, limit) {
254
- return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
255
- },
256
- async abandon(locator, kept = false) {
257
- if (fenced(locator))
258
- return null;
259
- return authored.ask({ kind: 'replica.abandon', locator, kept });
260
- },
261
- async release(key) {
262
- await authored.ask({ kind: 'replica.release', key });
263
- },
264
- async rederive(key, limit) {
265
- change(key);
266
- return (await authored.ask({ kind: 'replica.rederive', key, limit })).done;
267
- },
268
- async fact(name, value) {
269
- await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
270
- },
271
- async queues() {
272
- const { queues, pending } = await authored.ask({ kind: 'authored.queues' });
273
- queued.clear();
274
- for (const queue of queues)
275
- queued.set(queue.locator, new Set(queue.ids));
276
- const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
277
- return queues
278
- .filter((queue) => !fenced(queue.locator))
279
- .map((queue) => ({
280
- locator: queue.locator,
281
- pending: queue.ids.map((id) => {
282
- const record = byId.get(`${queue.locator}\0${id}`);
283
- if (record === undefined)
284
- throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
285
- return {
286
- batch: JSON.parse(record.batch),
287
- state: JSON.parse(record.state),
288
- };
289
- }),
290
- }));
291
- },
292
- submit(locator, id, submission, lost) {
293
- return amend(locator, id, { submission, lost });
294
- },
295
- keepUpload(locator, id, upload) {
296
- return amend(locator, id, { upload });
297
- },
298
- async roomDrafts() {
299
- const held = await authored.ask({ kind: 'authored.roomDrafts' });
300
- return held
301
- .map((record) => JSON.parse(record))
302
- .filter((record) => !fenced(record.locator));
303
- },
304
- async present(record) {
305
- await authored.ask({
306
- kind: 'replica.present',
307
- app: record.app,
308
- value: JSON.stringify(record.value ?? null),
309
- });
310
- },
311
- conversations() {
312
- return authored.ask({ kind: 'conversation.held' });
313
- },
314
- async keepMessages(write) {
315
- await authored.ask({ kind: 'conversation.keep', ...write });
316
- },
317
- messageWindow(conversation, limit, before) {
318
- return authored.ask({ kind: 'conversation.window', conversation, limit, before });
319
- },
320
- messageCount(conversation) {
321
- return authored.ask({ kind: 'conversation.count', conversation });
322
- },
323
- turnArrived(conversation, turn) {
324
- return authored.ask({ kind: 'conversation.turn', conversation, turn });
325
- },
326
- async dropConversations(conversations) {
327
- await authored.ask({ kind: 'conversation.drop', conversations });
328
- },
329
- async chatDrafts() {
330
- const records = await authored.ask({ kind: 'authored.chatDrafts' });
331
- return records.map((record) => JSON.parse(record));
332
- },
333
- async keepChatDrafts(records) {
334
- await authored.ask({
335
- kind: 'authored.chatDraft',
336
- kept: records.map((record) => ({
337
- conversation: record.conversation,
338
- record: JSON.stringify(record),
339
- })),
340
- dropped: [],
341
- });
342
- },
343
- async dropChatDraft(conversation) {
344
- await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
345
- },
346
- async calls() {
347
- return restored(await authored.ask({ kind: 'authored.calls' }));
348
- },
349
- async keepCall(record) {
350
- const { stored, ...kept } = keyed(keys, record);
351
- await authored.ask({
352
- kind: 'authored.call',
353
- operation: record.operation,
354
- kept,
355
- files: stored,
356
- });
357
- },
358
- async dropCall(operation) {
359
- await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
360
- },
361
- async keepRoomDraft(record, files) {
362
- if (fenced(record.locator))
363
- return;
364
- const { path, ...kept } = roomDraftRow(record);
365
- await authored.ask({
366
- kind: 'authored.roomDraft',
367
- locator: record.locator,
368
- path,
369
- kept,
370
- files,
371
- });
372
- },
373
- async discardRoomDraft(locator, path) {
374
- if (fenced(locator))
375
- return;
376
- await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
377
- },
378
- fences() {
379
- return authored.ask({ kind: 'authored.fences' });
380
- },
381
- receivedHeads() {
382
- return authored.ask({ kind: 'replica.received' });
383
- },
384
- receivedParts(key, count) {
385
- return authored.ask({ kind: 'replica.receivedParts', key, count });
386
- },
387
- async keepReceived(key, head, part) {
388
- await authored.ask({
389
- kind: 'replica.receive',
390
- key,
391
- head: JSON.stringify(head),
392
- ...(part === undefined
393
- ? {}
394
- : { part: { index: part.index, value: JSON.stringify(part.value) } }),
395
- });
396
- },
397
- async dropReceived(keys) {
398
- await authored.ask({ kind: 'replica.unreceive', keys });
399
- },
400
- generation() {
401
- return fact('generation');
402
- },
403
- async rememberGeneration(value) {
404
- await authored.ask({ kind: 'authored.remember', name: 'generation', value });
137
+ async status() {
138
+ const held = await (await open()).status();
139
+ return {
140
+ queued: held.queued.filter((locator) => !lost(locator)),
141
+ lastCompleted: held.lastCompleted,
142
+ unsent: held.unsent.filter(({ room }) => !lost(room)),
143
+ resets: held.resets.filter(({ locator }) => !lost(locator)),
144
+ returned: held.returned.filter(({ locator }) => !lost(locator)),
145
+ };
405
146
  },
406
- file(key, type) {
407
- return authored.ask({ kind: 'authored.file', key, type });
147
+ queued: async () => (await (await open()).queued()).filter((locator) => !lost(locator)),
148
+ drafts,
149
+ draft: async (locator, path) => (await drafts(locator, [path]))[0],
150
+ composed: ({ model, declaration }) => compositionOf(model, declaration.typedSelection, options.builtIn, options.typedPaths),
151
+ publication: watchers.publication,
152
+ owing: watchers.owing,
153
+ watch: watchers.watch,
154
+ watching: watchers.watching,
155
+ tell: watchers.tell,
156
+ installs,
157
+ seeds: {
158
+ of: (key) => seeds.get(key),
159
+ keep(key, seed) {
160
+ seeds.set(key, seed);
161
+ },
162
+ drop(key) {
163
+ seeds.delete(key);
164
+ },
165
+ },
166
+ conflicted,
167
+ attached,
168
+ opened: openedFiles(options.database, lost),
169
+ prepareAgain,
170
+ part: (file, part) => options.database.ask({ kind: 'file.part', key: file, part }),
171
+ forget(locator) {
172
+ typesHeld.delete(locator);
173
+ conflicted.forget(locator);
174
+ attached.forget(locator);
175
+ installs.change(locator, ({ installing }) => ({ ...NO_INSTALL, installing }));
176
+ prepareAgain(locator);
177
+ },
178
+ close() {
179
+ space.stop();
180
+ readiness.close();
181
+ watchers.close();
408
182
  },
409
183
  };
410
184
  }