@agentshouse/mdruntime 0.1.0-c210758b77baa → 0.1.0-c22b9876b9897

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 (436) 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 +341 -0
  11. package/dist/adapter.d.ts +250 -125
  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 +347 -0
  22. package/dist/bootstrap.d.ts +17 -16
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +266 -136
  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 +44 -28
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +63 -27
  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 +117 -5019
  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 +149 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +259 -0
  61. package/dist/conversation-row.d.ts +40 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +66 -0
  64. package/dist/conversation.d.ts +81 -55
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1026 -842
  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 -1
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +7 -0
  79. package/dist/entry.d.ts +28 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +120 -33
  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 +130 -54
  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 +47 -18
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +24 -7
  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 +290 -0
  115. package/dist/listing.d.ts +60 -0
  116. package/dist/listing.d.ts.map +1 -0
  117. package/dist/listing.js +168 -0
  118. package/dist/live.d.ts +23 -6
  119. package/dist/live.d.ts.map +1 -1
  120. package/dist/live.js +138 -38
  121. package/dist/loaded.d.ts +7 -0
  122. package/dist/loaded.d.ts.map +1 -0
  123. package/dist/loaded.js +46 -0
  124. package/dist/locks.d.ts +7 -0
  125. package/dist/locks.d.ts.map +1 -0
  126. package/dist/locks.js +34 -0
  127. package/dist/lost.d.ts +5 -0
  128. package/dist/lost.d.ts.map +1 -0
  129. package/dist/lost.js +49 -0
  130. package/dist/media.d.ts +24 -0
  131. package/dist/media.d.ts.map +1 -0
  132. package/dist/media.js +365 -0
  133. package/dist/memory.d.ts +21 -8
  134. package/dist/memory.d.ts.map +1 -1
  135. package/dist/memory.js +299 -110
  136. package/dist/messages.d.ts +40 -5
  137. package/dist/messages.d.ts.map +1 -1
  138. package/dist/messages.js +118 -39
  139. package/dist/modal.d.ts +2 -0
  140. package/dist/modal.d.ts.map +1 -0
  141. package/dist/modal.js +11 -0
  142. package/dist/model.d.ts +15 -15
  143. package/dist/model.d.ts.map +1 -1
  144. package/dist/model.js +11 -22
  145. package/dist/models.d.ts +10 -0
  146. package/dist/models.d.ts.map +1 -0
  147. package/dist/models.js +153 -0
  148. package/dist/name.d.ts +0 -1
  149. package/dist/name.d.ts.map +1 -1
  150. package/dist/name.js +3 -7
  151. package/dist/observation.d.ts +31 -13
  152. package/dist/observation.d.ts.map +1 -1
  153. package/dist/observation.js +219 -82
  154. package/dist/online.d.ts +7 -0
  155. package/dist/online.d.ts.map +1 -0
  156. package/dist/online.js +29 -0
  157. package/dist/opened.d.ts +6 -6
  158. package/dist/opened.d.ts.map +1 -1
  159. package/dist/opened.js +7 -7
  160. package/dist/opening.d.ts +4 -0
  161. package/dist/opening.d.ts.map +1 -0
  162. package/dist/opening.js +69 -0
  163. package/dist/outcome.d.ts +46 -15
  164. package/dist/outcome.d.ts.map +1 -1
  165. package/dist/outcome.js +52 -5
  166. package/dist/overlay.d.ts +24 -8
  167. package/dist/overlay.d.ts.map +1 -1
  168. package/dist/overlay.js +143 -48
  169. package/dist/page-metadata.d.ts +8 -0
  170. package/dist/page-metadata.d.ts.map +1 -0
  171. package/dist/page-metadata.js +19 -0
  172. package/dist/parts.d.ts +6 -0
  173. package/dist/parts.d.ts.map +1 -0
  174. package/dist/parts.js +36 -0
  175. package/dist/paths.d.ts +2 -0
  176. package/dist/paths.d.ts.map +1 -1
  177. package/dist/paths.js +26 -0
  178. package/dist/preparation.d.ts +46 -0
  179. package/dist/preparation.d.ts.map +1 -0
  180. package/dist/preparation.js +344 -0
  181. package/dist/presence.d.ts +58 -0
  182. package/dist/presence.d.ts.map +1 -0
  183. package/dist/presence.js +231 -0
  184. package/dist/queries.d.ts +16 -0
  185. package/dist/queries.d.ts.map +1 -0
  186. package/dist/queries.js +330 -0
  187. package/dist/query.d.ts +20 -210
  188. package/dist/query.d.ts.map +1 -1
  189. package/dist/query.js +3 -505
  190. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  191. package/dist/questions.d.ts.map +1 -0
  192. package/dist/{chat/questions.js → questions.js} +14 -8
  193. package/dist/queue.d.ts +40 -0
  194. package/dist/queue.d.ts.map +1 -0
  195. package/dist/queue.js +480 -0
  196. package/dist/reach.d.ts +31 -13
  197. package/dist/reach.d.ts.map +1 -1
  198. package/dist/reach.js +370 -146
  199. package/dist/react.d.ts +21 -3
  200. package/dist/react.d.ts.map +1 -1
  201. package/dist/react.js +33 -1
  202. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  203. package/dist/read.d.ts.map +1 -0
  204. package/dist/{chat/read.js → read.js} +4 -0
  205. package/dist/readiness.d.ts +26 -22
  206. package/dist/readiness.d.ts.map +1 -1
  207. package/dist/readiness.js +22 -20
  208. package/dist/reads.d.ts +38 -10
  209. package/dist/reads.d.ts.map +1 -1
  210. package/dist/reads.js +164 -85
  211. package/dist/recovery.d.ts +4 -0
  212. package/dist/recovery.d.ts.map +1 -1
  213. package/dist/recovery.js +59 -2
  214. package/dist/reference-forms.d.ts +4 -0
  215. package/dist/reference-forms.d.ts.map +1 -0
  216. package/dist/reference-forms.js +74 -0
  217. package/dist/refresh.d.ts +7 -5
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +38 -14
  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 +52 -13
  230. package/dist/room-draft.d.ts.map +1 -1
  231. package/dist/room-draft.js +372 -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 +45 -0
  238. package/dist/rows.d.ts +28 -17
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +64 -159
  241. package/dist/running.d.ts +5 -0
  242. package/dist/running.d.ts.map +1 -0
  243. package/dist/running.js +10 -0
  244. package/dist/runtime.d.ts +37 -0
  245. package/dist/runtime.d.ts.map +1 -0
  246. package/dist/runtime.js +1 -0
  247. package/dist/save.d.ts +43 -84
  248. package/dist/save.d.ts.map +1 -1
  249. package/dist/save.js +342 -232
  250. package/dist/saves.d.ts +34 -0
  251. package/dist/saves.d.ts.map +1 -0
  252. package/dist/saves.js +463 -0
  253. package/dist/search.d.ts +12 -63
  254. package/dist/search.d.ts.map +1 -1
  255. package/dist/search.js +9 -52
  256. package/dist/seed.d.ts +11 -2
  257. package/dist/seed.d.ts.map +1 -1
  258. package/dist/seed.js +71 -1
  259. package/dist/selector.d.ts +3 -0
  260. package/dist/selector.d.ts.map +1 -0
  261. package/dist/selector.js +22 -0
  262. package/dist/shared.d.ts +1 -7
  263. package/dist/shared.d.ts.map +1 -1
  264. package/dist/shared.js +13 -105
  265. package/dist/shown.d.ts +35 -0
  266. package/dist/shown.d.ts.map +1 -0
  267. package/dist/shown.js +326 -0
  268. package/dist/socket/admission.d.ts +7 -0
  269. package/dist/socket/admission.d.ts.map +1 -0
  270. package/dist/socket/admission.js +39 -0
  271. package/dist/socket/answers.d.ts +6 -0
  272. package/dist/socket/answers.d.ts.map +1 -0
  273. package/dist/socket/answers.js +20 -0
  274. package/dist/socket/lanes.d.ts +28 -0
  275. package/dist/socket/lanes.d.ts.map +1 -0
  276. package/dist/socket/lanes.js +103 -0
  277. package/dist/socket/reads.d.ts +10 -0
  278. package/dist/socket/reads.d.ts.map +1 -0
  279. package/dist/socket/reads.js +31 -0
  280. package/dist/socket/session.d.ts +41 -0
  281. package/dist/socket/session.d.ts.map +1 -0
  282. package/dist/socket/session.js +26 -0
  283. package/dist/socket.d.ts +68 -0
  284. package/dist/socket.d.ts.map +1 -0
  285. package/dist/socket.js +165 -0
  286. package/dist/source.d.ts +61 -0
  287. package/dist/source.d.ts.map +1 -0
  288. package/dist/source.js +95 -0
  289. package/dist/status.d.ts +4 -5
  290. package/dist/status.d.ts.map +1 -1
  291. package/dist/status.js +3 -7
  292. package/dist/store/installs.d.ts +30 -0
  293. package/dist/store/installs.d.ts.map +1 -0
  294. package/dist/store/installs.js +40 -0
  295. package/dist/store/readiness.d.ts +11 -0
  296. package/dist/store/readiness.d.ts.map +1 -0
  297. package/dist/store/readiness.js +68 -0
  298. package/dist/store/records.d.ts +234 -0
  299. package/dist/store/records.d.ts.map +1 -0
  300. package/dist/store/records.js +474 -0
  301. package/dist/store/room-held.d.ts +8 -0
  302. package/dist/store/room-held.d.ts.map +1 -0
  303. package/dist/store/room-held.js +17 -0
  304. package/dist/store/rooms-shown.d.ts +8 -0
  305. package/dist/store/rooms-shown.d.ts.map +1 -0
  306. package/dist/store/rooms-shown.js +13 -0
  307. package/dist/store/space.d.ts +11 -0
  308. package/dist/store/space.d.ts.map +1 -0
  309. package/dist/store/space.js +41 -0
  310. package/dist/store/watchers.d.ts +17 -0
  311. package/dist/store/watchers.d.ts.map +1 -0
  312. package/dist/store/watchers.js +56 -0
  313. package/dist/store/writes.d.ts +24 -0
  314. package/dist/store/writes.d.ts.map +1 -0
  315. package/dist/store/writes.js +125 -0
  316. package/dist/store.d.ts +114 -157
  317. package/dist/store.d.ts.map +1 -1
  318. package/dist/store.js +174 -400
  319. package/dist/stored.d.ts +96 -60
  320. package/dist/stored.d.ts.map +1 -1
  321. package/dist/stored.js +531 -291
  322. package/dist/surface.d.ts +94 -0
  323. package/dist/surface.d.ts.map +1 -0
  324. package/dist/surface.js +255 -0
  325. package/dist/sync.d.ts +21 -0
  326. package/dist/sync.d.ts.map +1 -0
  327. package/dist/sync.js +557 -0
  328. package/dist/tables.d.ts +139 -105
  329. package/dist/tables.d.ts.map +1 -1
  330. package/dist/tables.js +212 -330
  331. package/dist/tallies.d.ts +18 -0
  332. package/dist/tallies.d.ts.map +1 -0
  333. package/dist/tallies.js +128 -0
  334. package/dist/transfer.d.ts +0 -5
  335. package/dist/transfer.d.ts.map +1 -1
  336. package/dist/validation.d.ts +5 -4
  337. package/dist/validation.d.ts.map +1 -1
  338. package/dist/validation.js +87 -105
  339. package/dist/windows.d.ts +1 -12
  340. package/dist/windows.d.ts.map +1 -1
  341. package/dist/windows.js +2 -75
  342. package/dist/wire.d.ts +91 -16
  343. package/dist/wire.d.ts.map +1 -1
  344. package/dist/wire.js +37 -14
  345. package/package.json +12 -18
  346. package/AGENTS.md +0 -317
  347. package/dist/attempt.d.ts +0 -16
  348. package/dist/attempt.d.ts.map +0 -1
  349. package/dist/attempt.js +0 -70
  350. package/dist/binary.d.ts.map +0 -1
  351. package/dist/binary.js +0 -8
  352. package/dist/chat/acts.d.ts +0 -33
  353. package/dist/chat/acts.d.ts.map +0 -1
  354. package/dist/chat/acts.js +0 -36
  355. package/dist/chat/context.d.ts +0 -3
  356. package/dist/chat/context.d.ts.map +0 -1
  357. package/dist/chat/earlier.d.ts +0 -10
  358. package/dist/chat/earlier.d.ts.map +0 -1
  359. package/dist/chat/earlier.js +0 -54
  360. package/dist/chat/house.d.ts +0 -25
  361. package/dist/chat/house.d.ts.map +0 -1
  362. package/dist/chat/house.js +0 -38
  363. package/dist/chat/input.d.ts +0 -11
  364. package/dist/chat/input.d.ts.map +0 -1
  365. package/dist/chat/input.js +0 -92
  366. package/dist/chat/kit.d.ts +0 -61
  367. package/dist/chat/kit.d.ts.map +0 -1
  368. package/dist/chat/kit.js +0 -123
  369. package/dist/chat/lasting.d.ts +0 -6
  370. package/dist/chat/lasting.d.ts.map +0 -1
  371. package/dist/chat/lasting.js +0 -19
  372. package/dist/chat/list.d.ts +0 -28
  373. package/dist/chat/list.d.ts.map +0 -1
  374. package/dist/chat/list.js +0 -103
  375. package/dist/chat/markdown.d.ts +0 -20
  376. package/dist/chat/markdown.d.ts.map +0 -1
  377. package/dist/chat/markdown.js +0 -231
  378. package/dist/chat/message.d.ts +0 -7
  379. package/dist/chat/message.d.ts.map +0 -1
  380. package/dist/chat/message.js +0 -254
  381. package/dist/chat/messages.d.ts +0 -35
  382. package/dist/chat/messages.d.ts.map +0 -1
  383. package/dist/chat/messages.js +0 -210
  384. package/dist/chat/name.d.ts +0 -7
  385. package/dist/chat/name.d.ts.map +0 -1
  386. package/dist/chat/name.js +0 -37
  387. package/dist/chat/opened.d.ts +0 -12
  388. package/dist/chat/opened.d.ts.map +0 -1
  389. package/dist/chat/opened.js +0 -19
  390. package/dist/chat/overlay.d.ts +0 -32
  391. package/dist/chat/overlay.d.ts.map +0 -1
  392. package/dist/chat/overlay.js +0 -103
  393. package/dist/chat/parts.d.ts +0 -58
  394. package/dist/chat/parts.d.ts.map +0 -1
  395. package/dist/chat/parts.js +0 -120
  396. package/dist/chat/pieces.d.ts +0 -62
  397. package/dist/chat/pieces.d.ts.map +0 -1
  398. package/dist/chat/pieces.js +0 -1110
  399. package/dist/chat/process.d.ts +0 -20
  400. package/dist/chat/process.d.ts.map +0 -1
  401. package/dist/chat/process.js +0 -32
  402. package/dist/chat/provider.d.ts +0 -70
  403. package/dist/chat/provider.d.ts.map +0 -1
  404. package/dist/chat/provider.js +0 -635
  405. package/dist/chat/question.d.ts +0 -9
  406. package/dist/chat/question.d.ts.map +0 -1
  407. package/dist/chat/question.js +0 -69
  408. package/dist/chat/questions.d.ts.map +0 -1
  409. package/dist/chat/read.d.ts.map +0 -1
  410. package/dist/chat/ready.d.ts +0 -37
  411. package/dist/chat/ready.d.ts.map +0 -1
  412. package/dist/chat/ready.js +0 -93
  413. package/dist/chat/room-file.d.ts +0 -8
  414. package/dist/chat/room-file.d.ts.map +0 -1
  415. package/dist/chat/room-file.js +0 -72
  416. package/dist/chat/steady.d.ts +0 -3
  417. package/dist/chat/steady.d.ts.map +0 -1
  418. package/dist/chat/steady.js +0 -26
  419. package/dist/chat/style.d.ts +0 -4
  420. package/dist/chat/style.d.ts.map +0 -1
  421. package/dist/chat/style.js +0 -307
  422. package/dist/chat.d.ts +0 -15
  423. package/dist/chat.d.ts.map +0 -1
  424. package/dist/chat.js +0 -8
  425. package/dist/fence.d.ts +0 -6
  426. package/dist/fence.d.ts.map +0 -1
  427. package/dist/fence.js +0 -10
  428. package/dist/fulltext.d.ts +0 -27
  429. package/dist/fulltext.d.ts.map +0 -1
  430. package/dist/fulltext.js +0 -368
  431. package/dist/log.d.ts +0 -5
  432. package/dist/log.d.ts.map +0 -1
  433. package/dist/log.js +0 -14
  434. package/dist/words.d.ts +0 -19
  435. package/dist/words.d.ts.map +0 -1
  436. package/dist/words.js +0 -150
package/dist/tables.js CHANGED
@@ -1,11 +1,21 @@
1
- import { answerQuery } from './compile.js';
2
- import { searched, SEARCH_TABLES } from './fulltext.js';
3
- import { droppedMessages, forgottenMessages, heldConversations, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
4
- import { abandon, release, commit, counts, ended, entries, erase, fenceRooms, files, opened, rederive, referrers, refreshing, REPLICA_TABLES, keepPart, stage, transferPart, typed, typedWithin, unrefresh, walk, } from './stored.js';
1
+ import { sql } from '@agentshouse/mdmodel';
2
+ import { answerQuery, namedHandles } from './compile.js';
3
+ import { amended, authoredLocators, authoredPart, call, callRecords, chatDraft, chatDraftConversations, chatDraftRecord, chatDraftRecords, chatDraftsDropped, claim, fact, fenced, fencedWork, fences, FILE_PART_BYTES, authoredEmptied, heldOrder, kept, moving, pendingBatch, pendingState, queuedLocators, queueOf, queues, remember, roomDraft, roomDraftRecords, spooled, unfenced, unsent, unsentStatus, } from './authored.js';
4
+ import { count, text, texts } from './column.js';
5
+ import { conversationFacts, conversationRows, forgottenConversations, heldConversations, keptFact, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
6
+ import { keptRead, READ_TABLES, readsOfOtherBuildsForgotten, storedRead, } from './reads.js';
7
+ import { conversationTallies, roomTallies, } from './tallies.js';
8
+ import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, holders, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, tablesOf, typedWithin, unrefresh, } from './stored.js';
9
+ export { kindedRevision } from './reference-forms.js';
10
+ export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
5
11
  const STATEMENTS_HELD = 256;
6
12
  export function sqliteConnection(engine, database) {
7
13
  const decoder = new TextDecoder();
8
14
  const held = new Map();
15
+ database.createFunction(sql.HOLDS_PHRASE, sql.holdsPhrase, {
16
+ arity: 2,
17
+ deterministic: true,
18
+ });
9
19
  function prepared(sql) {
10
20
  if (sql.includes(';'))
11
21
  return null;
@@ -65,62 +75,60 @@ export function sqliteConnection(engine, database) {
65
75
  },
66
76
  };
67
77
  }
68
- export const FILE_PART_BYTES = 1_048_576;
69
78
  const PROBE_BYTES = 4 * FILE_PART_BYTES;
70
- const TABLES = [
71
- ['authored_facts', 'name TEXT PRIMARY KEY, value TEXT NOT NULL'],
72
- ['authored_queues', 'locator TEXT PRIMARY KEY, ids TEXT NOT NULL'],
73
- [
74
- 'authored_pending',
75
- 'locator TEXT NOT NULL, id TEXT NOT NULL, batch TEXT NOT NULL, state TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, id)',
76
- ],
77
- [
78
- 'authored_room_drafts',
79
- 'locator TEXT NOT NULL, path TEXT NOT NULL, record TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, path)',
80
- ],
81
- ['authored_chat_drafts', 'conversation TEXT PRIMARY KEY, record TEXT NOT NULL'],
82
- ['authored_calls', 'operation TEXT PRIMARY KEY, record TEXT NOT NULL, files TEXT NOT NULL'],
83
- ['authored_fences', 'locator TEXT PRIMARY KEY'],
84
- ];
85
79
  export const RUNTIME_TABLES = [
86
- ...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
87
- 'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
88
80
  'CREATE TABLE opened_files (key TEXT PRIMARY KEY, locator TEXT NOT NULL, path TEXT NOT NULL, revision TEXT NOT NULL, media_type TEXT NOT NULL, sha256 TEXT, byte_length INTEGER) WITHOUT ROWID',
89
81
  'CREATE INDEX opened_files_name ON opened_files (locator, path, revision)',
82
+ 'CREATE TABLE opened_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
90
83
  ...REPLICA_TABLES,
91
84
  ...MESSAGE_TABLES,
92
- ...SEARCH_TABLES,
85
+ ...READ_TABLES,
93
86
  ];
94
- const OWNERS = ['authored_pending', 'authored_room_drafts', 'authored_calls'];
95
- const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
96
- const UNOWNED_PARTS = `DELETE FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS} UNION SELECT key FROM opened_files)`;
87
+ const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
97
88
  const READS = new Set([
98
- 'authored.queues',
89
+ 'authored.status',
90
+ 'authored.moving',
91
+ 'authored.pending',
92
+ 'authored.batch',
93
+ 'authored.order',
94
+ 'authored.queued',
99
95
  'authored.roomDrafts',
96
+ 'authored.chatDraft.read',
100
97
  'authored.chatDrafts',
101
98
  'authored.calls',
102
99
  'authored.fences',
100
+ 'authored.unsent',
103
101
  'authored.fact',
104
102
  'authored.file',
105
103
  'replica.open',
104
+ 'replica.rooms',
105
+ 'replica.room',
106
+ 'replica.covering',
107
+ 'replica.offline',
108
+ 'replica.held',
109
+ 'replica.facts',
110
+ 'replica.presentation',
106
111
  'replica.query',
112
+ 'replica.named',
113
+ 'replica.tallies',
107
114
  'replica.entries',
108
115
  'replica.typed',
109
116
  'replica.referrers',
110
- 'replica.walk',
111
- 'replica.files',
117
+ 'replica.holders',
118
+ 'replica.folders',
112
119
  'replica.typedWithin',
113
- 'replica.counts',
114
- 'replica.search',
115
- 'replica.received',
116
- 'replica.receivedParts',
117
- 'replica.transferPart',
118
120
  'opened.find',
121
+ 'opened.held',
119
122
  'file.part',
120
123
  'conversation.held',
121
124
  'conversation.window',
122
125
  'conversation.count',
123
126
  'conversation.turn',
127
+ 'conversation.rows',
128
+ 'conversation.tallies',
129
+ 'conversation.facts',
130
+ 'conversation.stored',
131
+ 'read.stored',
124
132
  ]);
125
133
  const KINDS = new Set([
126
134
  ...READS,
@@ -132,27 +140,30 @@ const KINDS = new Set([
132
140
  'authored.claim',
133
141
  'authored.end',
134
142
  'replica.stage',
135
- 'replica.keepPart',
143
+ 'replica.resume',
136
144
  'replica.refresh',
137
145
  'replica.unrefresh',
138
146
  'replica.commit',
139
147
  'replica.fence',
140
148
  'replica.erase',
141
149
  'replica.abandon',
150
+ 'replica.unfence',
142
151
  'replica.release',
143
152
  'replica.rederive',
153
+ 'replica.demote',
144
154
  'replica.fact',
145
155
  'replica.present',
146
- 'replica.receive',
147
- 'replica.unreceive',
148
156
  'opened.begin',
149
157
  'opened.part',
150
158
  'opened.keep',
151
159
  'opened.drop',
152
160
  'opened.clean',
153
161
  'conversation.keep',
162
+ 'conversation.fact',
154
163
  'conversation.drop',
155
164
  'space.probe',
165
+ 'read.keep',
166
+ 'read.builds',
156
167
  ]);
157
168
  export function isRuntime(request) {
158
169
  return KINDS.has(request.kind);
@@ -160,239 +171,75 @@ export function isRuntime(request) {
160
171
  export function readsRuntime(request) {
161
172
  return READS.has(request.kind);
162
173
  }
163
- function text(value) {
164
- return typeof value === 'string' ? value : String(value);
165
- }
166
- function texts(rows, column) {
167
- return rows.map((row) => text(row[column]));
168
- }
169
- function owned(files) {
170
- return JSON.stringify([...new Set(files)]);
171
- }
172
- function fact(connection, name) {
173
- const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
174
- return held === undefined ? null : text(held.value);
175
- }
176
- function remember(connection, name, value) {
177
- connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
178
- name,
179
- value,
180
- ]);
181
- return null;
182
- }
183
- function fenced(connection, locator) {
184
- return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
185
- }
186
- function stored(connection, key) {
187
- return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
188
- }
189
- function storedPart(connection, key, part, bytes) {
190
- connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
191
- }
192
- async function storedFiles(connection, files) {
193
- for (const { key, blob } of files) {
194
- if (stored(connection, key))
195
- continue;
196
- for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
197
- const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
198
- storedPart(connection, key, part, bytes);
199
- }
200
- }
201
- }
202
- function filePart(connection, key, part) {
203
- const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
204
- key,
205
- part,
206
- ]);
207
- return held?.bytes instanceof Uint8Array ? held.bytes : null;
208
- }
209
- function* fileParts(connection, key) {
210
- for (let part = 0;; part += 1) {
211
- const bytes = filePart(connection, key, part);
212
- if (bytes === null)
213
- return;
214
- yield bytes;
215
- }
216
- }
217
- async function spooled(connection, spool, { key, type }) {
218
- for (const held of [...spool.held()]) {
219
- if (held !== key && !stored(connection, held))
220
- await spool.drop(held);
221
- }
222
- return spool.spool(key, type, fileParts(connection, key));
223
- }
224
- function unowned(connection) {
225
- connection.run(UNOWNED_PARTS);
226
- }
227
- function queued(connection) {
174
+ function heldWork(connection, locator) {
175
+ const room = heldRoom(connection, locator);
228
176
  return {
229
- queues: connection.rows('SELECT locator, ids FROM authored_queues').map((row) => ({
230
- locator: text(row.locator),
231
- ids: JSON.parse(text(row.ids)),
232
- })),
233
- pending: connection
234
- .rows('SELECT locator, id, batch, state FROM authored_pending')
235
- .map((row) => ({
236
- locator: text(row.locator),
237
- id: text(row.id),
238
- batch: text(row.batch),
239
- state: text(row.state),
240
- })),
177
+ room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
178
+ queue: queueOf(connection, locator),
241
179
  };
242
180
  }
243
- function heldOrder(connection, locator) {
244
- const [held] = connection.rows('SELECT ids FROM authored_queues WHERE locator = ?', [locator]);
245
- return held === undefined ? [] : JSON.parse(text(held.ids));
246
- }
247
- function keptRows(connection, { locator, order, added, founded, roomDrafts, consumedRoomDrafts, amendments }) {
248
- for (const { id, amendment } of amendments ?? []) {
249
- amended(connection, { kind: 'authored.amend', locator, id, amendment });
250
- }
251
- for (const path of consumedRoomDrafts ?? []) {
252
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
253
- locator,
254
- path,
255
- ]);
256
- }
257
- for (const { path, record, files } of roomDrafts ?? []) {
258
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
259
- }
260
- if (order === undefined)
261
- return;
262
- const before = new Set(heldOrder(connection, locator));
263
- const after = new Set(order);
264
- if (after.size === 0)
265
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
266
- else {
267
- connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
268
- locator,
269
- JSON.stringify([...after]),
270
- ]);
271
- }
272
- for (const id of before) {
273
- if (!after.has(id)) {
274
- connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
275
- }
276
- }
277
- for (const { id, batch, state, files } of added ?? []) {
278
- if (before.has(id) || !after.has(id))
279
- continue;
280
- connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files) VALUES (?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files)]);
281
- }
282
- for (const { id, batch, files } of founded ?? []) {
283
- const [held] = connection.rows('SELECT files FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
284
- if (held === undefined || !before.has(id))
285
- continue;
286
- connection.run('UPDATE authored_pending SET batch = ?, files = ? WHERE locator = ? AND id = ?', [batch, owned([...JSON.parse(text(held.files)), ...files]), locator, id]);
287
- }
288
- }
289
- async function kept(connection, { writes, files, whole, discards }) {
290
- const refused = writes.find(({ locator }) => fenced(connection, locator));
291
- if (refused !== undefined && whole)
292
- return refused.locator;
293
- await storedFiles(connection, files);
294
- for (const write of writes) {
295
- if (!fenced(connection, write.locator))
296
- keptRows(connection, write);
297
- }
298
- for (const locator of discards ?? [])
299
- roomWork(connection, locator);
300
- unowned(connection);
301
- return refused?.locator ?? null;
181
+ function status(connection) {
182
+ return {
183
+ ...unsentStatus(connection),
184
+ lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
185
+ };
302
186
  }
303
- function amended(connection, { locator, id, amendment }) {
304
- if (fenced(connection, locator))
305
- return null;
306
- const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
307
- if (held === undefined)
308
- return null;
309
- connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
310
- JSON.stringify({
311
- ...JSON.parse(text(held.state)),
312
- ...JSON.parse(amendment),
313
- }),
314
- locator,
315
- id,
316
- ]);
317
- return null;
187
+ function pendingOf(connection, locator, id) {
188
+ return {
189
+ state: pendingState(connection, locator, id),
190
+ room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
191
+ };
318
192
  }
319
- async function roomDraft(connection, { locator, path, kept: draft, files }) {
320
- if (fenced(connection, locator))
321
- return locator;
322
- await storedFiles(connection, files);
323
- if (draft === null) {
324
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
325
- locator,
326
- path,
193
+ function storedConversations(connection, conversations) {
194
+ const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
195
+ const bound = conversations === null ? [] : [JSON.stringify(conversations)];
196
+ return [
197
+ ...new Set([
198
+ ...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
199
+ ...chatDraftConversations(connection, conversations),
200
+ ]),
201
+ ];
202
+ }
203
+ function droppedConversations(connection, conversations) {
204
+ const held = storedConversations(connection, conversations);
205
+ for (const table of tablesOf(MESSAGE_TABLES)) {
206
+ connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
207
+ JSON.stringify(conversations),
327
208
  ]);
328
209
  }
329
- else {
330
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, draft.record, owned(draft.files)]);
331
- }
332
- unowned(connection);
333
- return null;
334
- }
335
- function chatDraft(connection, { kept: drafts, dropped }) {
336
- for (const conversation of dropped) {
337
- connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
338
- }
339
- for (const { conversation, record } of drafts) {
340
- connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
341
- }
342
- return null;
343
- }
344
- async function call(connection, { operation, kept: held, files }) {
345
- await storedFiles(connection, files);
346
- if (held === null)
347
- connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
348
- else {
349
- connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
350
- }
351
- unowned(connection);
352
- return null;
210
+ chatDraftsDropped(connection, conversations);
211
+ return held;
353
212
  }
354
- function roomWork(connection, locator) {
355
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
356
- connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
213
+ function unopened(connection) {
214
+ connection.run(UNOPENED_PARTS);
357
215
  }
358
216
  function fence(connection, locators) {
217
+ fencedWork(connection, locators);
359
218
  for (const locator of locators) {
360
- connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
361
- roomWork(connection, locator);
362
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
363
219
  connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
364
220
  }
365
- unowned(connection);
221
+ unopened(connection);
366
222
  return fenceRooms(connection, locators);
367
223
  }
368
224
  function erased(connection, { locator, limit }) {
369
- const done = erase(connection, locator, limit);
370
- if (locator !== null && !done.remaining) {
371
- connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
372
- }
373
- return done;
225
+ return erase(connection, locator, limit);
374
226
  }
375
- function claim(connection, holder) {
376
- const held = fact(connection, 'holder');
377
- if (held !== null)
378
- return held === holder;
379
- remember(connection, 'holder', holder);
380
- return true;
227
+ function unfencedRooms(connection, locators) {
228
+ const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
229
+ .length === 0);
230
+ unfenced(connection, erased);
231
+ return erased;
381
232
  }
382
233
  function end(connection, holder) {
383
234
  ended(connection);
384
- forgottenMessages(connection);
235
+ forgottenConversations(connection);
385
236
  if (holder !== null && claim(connection, holder))
386
237
  return true;
387
- for (const [table] of TABLES)
388
- connection.run(`DELETE FROM ${table}`);
238
+ authoredEmptied(connection);
389
239
  connection.run('DELETE FROM opened_files');
390
- connection.run('DELETE FROM file_parts');
240
+ connection.run('DELETE FROM opened_parts');
391
241
  return false;
392
242
  }
393
- function count(value) {
394
- return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
395
- }
396
243
  function openedFile(connection, { locator, path, revision }) {
397
244
  const [held] = connection.rows('SELECT key, media_type, byte_length FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NOT NULL', [locator, path, revision]);
398
245
  return held === undefined
@@ -407,7 +254,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
407
254
  if (fenced(connection, locator))
408
255
  return false;
409
256
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
410
- unowned(connection);
257
+ unopened(connection);
411
258
  connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
412
259
  return true;
413
260
  }
@@ -420,22 +267,26 @@ function fetching(connection, key) {
420
267
  function openedPart(connection, { key, part, bytes }) {
421
268
  if (fetching(connection, key) === null)
422
269
  return false;
423
- storedPart(connection, key, part, bytes);
270
+ connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
271
+ key,
272
+ part,
273
+ bytes,
274
+ ]);
424
275
  return true;
425
276
  }
426
277
  function dropped(connection, key) {
427
278
  connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
428
- connection.run('DELETE FROM file_parts WHERE key = ?', [key]);
279
+ connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
429
280
  return null;
430
281
  }
431
282
  function keptOpened(connection, { key, sha256, byteLength, parts }) {
432
283
  const fetched = fetching(connection, key);
433
284
  if (fetched === null)
434
285
  return false;
435
- const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key = ?', [key]);
436
- const whole = count(held?.parts) === parts &&
437
- count(held?.bytes) === byteLength &&
438
- (parts === 0 || (count(held?.first) === 0 && count(held?.last) === parts - 1));
286
+ const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts WHERE key = ?', [key]);
287
+ const whole = count(held.parts) === parts &&
288
+ count(held.bytes) === byteLength &&
289
+ (parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
439
290
  if (!whole) {
440
291
  dropped(connection, key);
441
292
  return false;
@@ -446,71 +297,82 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
446
297
  key,
447
298
  ]);
448
299
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
449
- unowned(connection);
300
+ unopened(connection);
450
301
  return true;
451
302
  }
303
+ function heldPart(connection, key, part) {
304
+ const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
305
+ key,
306
+ part,
307
+ ]);
308
+ return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
309
+ }
310
+ function cleanable(connection) {
311
+ const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
312
+ return count(held.bytes);
313
+ }
452
314
  function cleaned(connection) {
453
315
  connection.run('DELETE FROM opened_files');
454
- const [freed] = connection.rows(`SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS})`);
455
- unowned(connection);
456
- return count(freed?.bytes);
316
+ const freed = cleanable(connection);
317
+ unopened(connection);
318
+ return freed;
319
+ }
320
+ function openedHeld(connection) {
321
+ return {
322
+ rooms: connection
323
+ .rows('SELECT locator, count(*) AS files, sum(byte_length) AS bytes FROM opened_files WHERE byte_length IS NOT NULL GROUP BY locator ORDER BY locator')
324
+ .map((row) => ({ room: text(row.locator), count: count(row.files), size: count(row.bytes) })),
325
+ cleanable: cleanable(connection),
326
+ };
457
327
  }
458
328
  async function committed(connection, { authored, rooms }) {
459
329
  const refused = authored === undefined ? null : await kept(connection, authored);
460
330
  if (refused !== null && authored?.whole === true) {
461
- return { fenced: refused, counts: {}, changed: {}, indexed: {} };
331
+ return { fenced: refused, changed: {}, indexed: {} };
462
332
  }
463
333
  return {
464
334
  fenced: refused,
465
335
  ...commit(connection, rooms.filter(({ locator }) => !fenced(connection, locator))),
466
336
  };
467
337
  }
468
- function receivedParts(connection, key, count) {
469
- return connection
470
- .rows('SELECT value FROM replica_received_parts WHERE key = ? AND part < ? ORDER BY part', [
471
- key,
472
- count,
473
- ])
474
- .map((row) => JSON.parse(text(row.value)));
475
- }
476
- function receive(connection, { key, head, part }) {
477
- connection.run('INSERT OR REPLACE INTO replica_received (key, head) VALUES (?, ?)', [key, head]);
478
- if (part !== undefined) {
479
- connection.run('INSERT OR REPLACE INTO replica_received_parts (key, part, value) VALUES (?, ?, ?)', [key, part.index, part.value]);
480
- }
481
- return null;
482
- }
483
- function unreceive(connection, keys) {
484
- for (const key of keys) {
485
- connection.run('DELETE FROM replica_received WHERE key = ?', [key]);
486
- connection.run('DELETE FROM replica_received_parts WHERE key = ?', [key]);
487
- }
488
- return null;
489
- }
490
338
  export function answerRuntime(connection, request, spool) {
491
339
  switch (request.kind) {
492
- case 'authored.queues':
493
- return queued(connection);
340
+ case 'authored.status':
341
+ return status(connection);
342
+ case 'authored.moving':
343
+ return moving(connection);
344
+ case 'authored.pending':
345
+ return pendingOf(connection, request.locator, request.id);
346
+ case 'authored.batch':
347
+ return pendingBatch(connection, request.locator, request.id);
348
+ case 'authored.order':
349
+ return heldOrder(connection, request.locator);
350
+ case 'authored.queued':
351
+ return queuedLocators(connection);
494
352
  case 'authored.roomDrafts':
495
- return texts(connection.rows('SELECT record FROM authored_room_drafts'), 'record');
353
+ return roomDraftRecords(connection, request.locator, request.paths);
354
+ case 'authored.chatDraft.read':
355
+ return chatDraftRecord(connection, request.conversation);
496
356
  case 'authored.chatDrafts':
497
- return texts(connection.rows('SELECT record FROM authored_chat_drafts'), 'record');
357
+ return chatDraftRecords(connection);
498
358
  case 'authored.calls':
499
- return texts(connection.rows('SELECT record FROM authored_calls'), 'record');
359
+ return callRecords(connection);
500
360
  case 'authored.fences':
501
- return texts(connection.rows('SELECT locator FROM authored_fences'), 'locator');
361
+ return fences(connection);
362
+ case 'authored.unsent':
363
+ return unsent(connection);
502
364
  case 'authored.fact':
503
365
  return fact(connection, request.name);
504
366
  case 'authored.file':
505
- return spooled(connection, spool, request);
367
+ return spooled(connection, spool, request.key, request.type);
506
368
  case 'authored.amend':
507
- return amended(connection, request);
369
+ return amended(connection, request.locator, request.id, request.amendment);
508
370
  case 'authored.roomDraft':
509
- return roomDraft(connection, request);
371
+ return roomDraft(connection, request.locator, request.path, request.kept, request.files);
510
372
  case 'authored.chatDraft':
511
- return chatDraft(connection, request);
373
+ return chatDraft(connection, request.kept, request.dropped);
512
374
  case 'authored.call':
513
- return call(connection, request);
375
+ return call(connection, request.operation, request.kept, request.files);
514
376
  case 'authored.remember':
515
377
  return remember(connection, request.name, request.value);
516
378
  case 'authored.claim':
@@ -519,39 +381,47 @@ export function answerRuntime(connection, request, spool) {
519
381
  return end(connection, request.holder);
520
382
  case 'replica.open':
521
383
  return opened(connection);
384
+ case 'replica.rooms':
385
+ return heldRooms(connection, request.locators);
386
+ case 'replica.room':
387
+ return heldWork(connection, request.locator);
388
+ case 'replica.covering':
389
+ return { ...covering(connection, request.since), queues: queues(connection) };
390
+ case 'replica.offline':
391
+ return offlineMode(connection, request.locator);
392
+ case 'replica.held':
393
+ return {
394
+ held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
395
+ staged: stagedLocators(connection),
396
+ };
397
+ case 'replica.demote':
398
+ return demoted(connection);
399
+ case 'replica.facts':
400
+ return facts(connection, request.names);
401
+ case 'replica.presentation':
402
+ return presentation(connection, request.app);
522
403
  case 'replica.query':
523
- return answerQuery(connection, request.plan, request.rooms, request.budget);
404
+ return answerQuery(connection, request.plan, request.rooms, request.budget, request.follows);
405
+ case 'replica.named':
406
+ return namedHandles(connection, request.plan, request.rooms, request.handles);
407
+ case 'replica.tallies':
408
+ return roomTallies(connection, request.totals, request.rooms, request.since);
524
409
  case 'replica.entries':
525
410
  return entries(connection, request.key, request.view, request.paths);
526
411
  case 'replica.typed':
527
412
  return typed(connection, request.key, request.view, request.paths);
528
413
  case 'replica.referrers':
529
- return referrers(connection, request.key, request.view, request.targets, request.kinds);
530
- case 'replica.walk':
531
- return walk(connection, request.key, request.view, request.after, request.bytes);
532
- case 'replica.files':
533
- return files(connection, request.key, request.view, request.after, request.limit);
414
+ return referrers(connection, request.key, request.view, request.targets);
415
+ case 'replica.holders':
416
+ return holders(connection, request.key, request.view, request.sought);
417
+ case 'replica.folders':
418
+ return folders(connection, request.key, request.paths);
534
419
  case 'replica.typedWithin':
535
420
  return typedWithin(connection, request.key, request.view, request.roots, request.within);
536
- case 'replica.counts':
537
- return counts(connection, request.rooms);
538
- case 'replica.search': {
539
- const { kind: _kind, ...ask } = request;
540
- return searched(connection, ask);
541
- }
542
- case 'replica.received':
543
- return connection.rows('SELECT key, head FROM replica_received').map((row) => ({
544
- key: text(row.key),
545
- head: JSON.parse(text(row.head)),
546
- }));
547
- case 'replica.receivedParts':
548
- return receivedParts(connection, request.key, request.count);
549
421
  case 'replica.stage':
550
422
  return fenced(connection, request.locator) ? null : stage(connection, request);
551
- case 'replica.transferPart':
552
- return transferPart(connection, request.locator, request.token);
553
- case 'replica.keepPart':
554
- return fenced(connection, request.locator) ? null : keepPart(connection, request);
423
+ case 'replica.resume':
424
+ return fenced(connection, request.locator) ? null : resume(connection, request);
555
425
  case 'replica.refresh':
556
426
  return refreshing(connection, request);
557
427
  case 'replica.unrefresh':
@@ -563,11 +433,13 @@ export function answerRuntime(connection, request, spool) {
563
433
  case 'replica.erase':
564
434
  return erased(connection, request);
565
435
  case 'replica.abandon':
566
- return abandon(connection, request.locator, request.kept);
436
+ return abandon(connection, request.locator);
437
+ case 'replica.unfence':
438
+ return unfencedRooms(connection, request.locators);
567
439
  case 'replica.release':
568
440
  return release(connection, request.key);
569
441
  case 'replica.rederive':
570
- return rederive(connection, request.key, request.limit);
442
+ return rederive(connection, request.key, request.composed, request.bytes, request.ms, request.floor);
571
443
  case 'replica.fact':
572
444
  connection.run('INSERT OR REPLACE INTO replica_facts (name, value) VALUES (?, ?)', [
573
445
  request.name,
@@ -580,10 +452,6 @@ export function answerRuntime(connection, request, spool) {
580
452
  request.value,
581
453
  ]);
582
454
  return null;
583
- case 'replica.receive':
584
- return receive(connection, request);
585
- case 'replica.unreceive':
586
- return unreceive(connection, request.keys);
587
455
  case 'opened.find':
588
456
  return openedFile(connection, request);
589
457
  case 'opened.begin':
@@ -596,29 +464,43 @@ export function answerRuntime(connection, request, spool) {
596
464
  return dropped(connection, request.key);
597
465
  case 'opened.clean':
598
466
  return cleaned(connection);
467
+ case 'opened.held':
468
+ return openedHeld(connection);
599
469
  case 'file.part':
600
- return filePart(connection, request.key, request.part);
470
+ return heldPart(connection, request.key, request.part);
601
471
  case 'conversation.held':
602
- return heldConversations(connection);
472
+ return heldConversations(connection, request.conversations);
603
473
  case 'conversation.keep': {
604
474
  const { kind: _kind, ...write } = request;
605
475
  return keptMessages(connection, write);
606
476
  }
607
477
  case 'conversation.window':
608
- return messageWindow(connection, request.conversation, request.limit, request.before);
478
+ return messageWindow(connection, request.conversation, request.limit, request.before, request.phrase);
609
479
  case 'conversation.count':
610
- return messageCount(connection, request.conversation);
480
+ return messageCount(connection, request.conversation, request.phrase);
611
481
  case 'conversation.turn':
612
482
  return turnArrived(connection, request.conversation, request.turn);
483
+ case 'conversation.rows':
484
+ return conversationRows(connection, request.conversations);
485
+ case 'conversation.tallies':
486
+ return conversationTallies(connection, request.conversations, request.since);
487
+ case 'conversation.facts':
488
+ return conversationFacts(connection);
489
+ case 'conversation.fact': {
490
+ const { kind: _kind, ...fact } = request;
491
+ return keptFact(connection, fact);
492
+ }
493
+ case 'conversation.stored':
494
+ return storedConversations(connection, null);
613
495
  case 'conversation.drop':
614
- chatDraft(connection, {
615
- kind: 'authored.chatDraft',
616
- kept: [],
617
- dropped: request.conversations,
618
- });
619
- droppedMessages(connection, request.conversations);
620
- return null;
496
+ return droppedConversations(connection, request.conversations);
621
497
  case 'space.probe':
622
498
  return spool.probe(PROBE_BYTES).then(() => null);
499
+ case 'read.stored':
500
+ return storedRead(connection, request);
501
+ case 'read.keep':
502
+ return keptRead(connection, request, request.answer);
503
+ case 'read.builds':
504
+ return readsOfOtherBuildsForgotten(connection, request.build);
623
505
  }
624
506
  }