@agentshouse/mdruntime 0.1.0-c2c52158b7381 → 0.1.0-c2d73b235d7d7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/README.md +24 -20
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +328 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +345 -0
  11. package/dist/adapter.d.ts +315 -122
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +4 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +33 -49
  16. package/dist/{binary.d.ts → attachment.d.ts} +8 -9
  17. package/dist/attachment.d.ts.map +1 -0
  18. package/dist/attachment.js +15 -0
  19. package/dist/authored.d.ts +88 -0
  20. package/dist/authored.d.ts.map +1 -0
  21. package/dist/authored.js +345 -0
  22. package/dist/bootstrap.d.ts +30 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +305 -140
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +12 -0
  29. package/dist/chain.d.ts.map +1 -0
  30. package/dist/chain.js +67 -0
  31. package/dist/change-set.d.ts +10 -16
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +17 -90
  34. package/dist/change.d.ts +7 -2
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +7 -2
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +53 -31
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +66 -29
  43. package/dist/collection.d.ts +33 -21
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +57 -366
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +19 -0
  50. package/dist/compile.d.ts.map +1 -0
  51. package/dist/compile.js +755 -0
  52. package/dist/connection.d.ts +6 -142
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +117 -4210
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/{chat/context.js → context.js} +2 -5
  58. package/dist/conversation-live.d.ts +150 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +260 -0
  61. package/dist/conversation-row.d.ts +55 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +82 -0
  64. package/dist/conversation.d.ts +84 -54
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1043 -823
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/discovery.d.ts +12 -0
  71. package/dist/discovery.d.ts.map +1 -0
  72. package/dist/discovery.js +175 -0
  73. package/dist/download.d.ts +6 -0
  74. package/dist/download.d.ts.map +1 -0
  75. package/dist/download.js +42 -0
  76. package/dist/durability.d.ts +20 -4
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +12 -0
  79. package/dist/entry.d.ts +30 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +135 -41
  82. package/dist/expectation.d.ts +26 -13
  83. package/dist/expectation.d.ts.map +1 -1
  84. package/dist/expectation.js +72 -19
  85. package/dist/failure.d.ts +3 -0
  86. package/dist/failure.d.ts.map +1 -1
  87. package/dist/failure.js +8 -0
  88. package/dist/figures.d.ts +49 -0
  89. package/dist/figures.d.ts.map +1 -0
  90. package/dist/figures.js +199 -0
  91. package/dist/file.d.ts +2 -11
  92. package/dist/file.d.ts.map +1 -1
  93. package/dist/file.js +7 -4
  94. package/dist/holdings.d.ts +29 -0
  95. package/dist/holdings.d.ts.map +1 -0
  96. package/dist/holdings.js +95 -0
  97. package/dist/host.d.ts +25 -8
  98. package/dist/host.d.ts.map +1 -1
  99. package/dist/host.js +157 -61
  100. package/dist/house-query.d.ts +24 -0
  101. package/dist/house-query.d.ts.map +1 -0
  102. package/dist/house-query.js +102 -0
  103. package/dist/identity.d.ts +1 -3
  104. package/dist/identity.d.ts.map +1 -1
  105. package/dist/identity.js +1 -7
  106. package/dist/index.d.ts +49 -19
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +25 -8
  109. package/dist/install.d.ts +60 -0
  110. package/dist/install.d.ts.map +1 -0
  111. package/dist/install.js +537 -0
  112. package/dist/lifecycle.d.ts +7 -0
  113. package/dist/lifecycle.d.ts.map +1 -0
  114. package/dist/lifecycle.js +292 -0
  115. package/dist/linked-file.d.ts +7 -0
  116. package/dist/linked-file.d.ts.map +1 -0
  117. package/dist/linked-file.js +16 -0
  118. package/dist/listing.d.ts +60 -0
  119. package/dist/listing.d.ts.map +1 -0
  120. package/dist/listing.js +168 -0
  121. package/dist/live.d.ts +39 -0
  122. package/dist/live.d.ts.map +1 -0
  123. package/dist/live.js +223 -0
  124. package/dist/loaded.d.ts +7 -0
  125. package/dist/loaded.d.ts.map +1 -0
  126. package/dist/loaded.js +46 -0
  127. package/dist/locks.d.ts +7 -0
  128. package/dist/locks.d.ts.map +1 -0
  129. package/dist/locks.js +34 -0
  130. package/dist/lost.d.ts +5 -0
  131. package/dist/lost.d.ts.map +1 -0
  132. package/dist/lost.js +49 -0
  133. package/dist/media.d.ts +24 -0
  134. package/dist/media.d.ts.map +1 -0
  135. package/dist/media.js +365 -0
  136. package/dist/memory.d.ts +22 -8
  137. package/dist/memory.d.ts.map +1 -1
  138. package/dist/memory.js +311 -120
  139. package/dist/messages.d.ts +67 -0
  140. package/dist/messages.d.ts.map +1 -0
  141. package/dist/messages.js +180 -0
  142. package/dist/modal.d.ts +2 -0
  143. package/dist/modal.d.ts.map +1 -0
  144. package/dist/modal.js +11 -0
  145. package/dist/model.d.ts +15 -15
  146. package/dist/model.d.ts.map +1 -1
  147. package/dist/model.js +11 -22
  148. package/dist/models.d.ts +10 -0
  149. package/dist/models.d.ts.map +1 -0
  150. package/dist/models.js +153 -0
  151. package/dist/name.d.ts +0 -1
  152. package/dist/name.d.ts.map +1 -1
  153. package/dist/name.js +3 -7
  154. package/dist/observation.d.ts +40 -10
  155. package/dist/observation.d.ts.map +1 -1
  156. package/dist/observation.js +265 -44
  157. package/dist/online.d.ts +7 -0
  158. package/dist/online.d.ts.map +1 -0
  159. package/dist/online.js +29 -0
  160. package/dist/opened.d.ts +6 -6
  161. package/dist/opened.d.ts.map +1 -1
  162. package/dist/opened.js +7 -7
  163. package/dist/opening.d.ts +4 -0
  164. package/dist/opening.d.ts.map +1 -0
  165. package/dist/opening.js +71 -0
  166. package/dist/outcome.d.ts +46 -16
  167. package/dist/outcome.d.ts.map +1 -1
  168. package/dist/outcome.js +51 -7
  169. package/dist/overlay.d.ts +24 -11
  170. package/dist/overlay.d.ts.map +1 -1
  171. package/dist/overlay.js +138 -193
  172. package/dist/page-metadata.d.ts +8 -0
  173. package/dist/page-metadata.d.ts.map +1 -0
  174. package/dist/page-metadata.js +19 -0
  175. package/dist/parts.d.ts +7 -0
  176. package/dist/parts.d.ts.map +1 -0
  177. package/dist/parts.js +36 -0
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.d.ts.map +1 -1
  180. package/dist/paths.js +26 -0
  181. package/dist/preparation.d.ts +46 -0
  182. package/dist/preparation.d.ts.map +1 -0
  183. package/dist/preparation.js +344 -0
  184. package/dist/presence.d.ts +58 -0
  185. package/dist/presence.d.ts.map +1 -0
  186. package/dist/presence.js +231 -0
  187. package/dist/queries.d.ts +16 -0
  188. package/dist/queries.d.ts.map +1 -0
  189. package/dist/queries.js +330 -0
  190. package/dist/query.d.ts +22 -209
  191. package/dist/query.d.ts.map +1 -1
  192. package/dist/query.js +3 -494
  193. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  194. package/dist/questions.d.ts.map +1 -0
  195. package/dist/{chat/questions.js → questions.js} +14 -8
  196. package/dist/queue.d.ts +40 -0
  197. package/dist/queue.d.ts.map +1 -0
  198. package/dist/queue.js +482 -0
  199. package/dist/reach.d.ts +31 -15
  200. package/dist/reach.d.ts.map +1 -1
  201. package/dist/reach.js +385 -176
  202. package/dist/react.d.ts +27 -3
  203. package/dist/react.d.ts.map +1 -1
  204. package/dist/react.js +33 -1
  205. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  206. package/dist/read.d.ts.map +1 -0
  207. package/dist/{chat/read.js → read.js} +4 -0
  208. package/dist/readiness.d.ts +36 -21
  209. package/dist/readiness.d.ts.map +1 -1
  210. package/dist/readiness.js +20 -18
  211. package/dist/reads.d.ts +38 -10
  212. package/dist/reads.d.ts.map +1 -1
  213. package/dist/reads.js +174 -83
  214. package/dist/recovery.d.ts +4 -0
  215. package/dist/recovery.d.ts.map +1 -1
  216. package/dist/recovery.js +59 -2
  217. package/dist/refresh.d.ts +18 -15
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +145 -79
  220. package/dist/refusal.d.ts +5 -0
  221. package/dist/refusal.d.ts.map +1 -0
  222. package/dist/refusal.js +55 -0
  223. package/dist/replica.d.ts +45 -38
  224. package/dist/replica.d.ts.map +1 -1
  225. package/dist/replica.js +319 -229
  226. package/dist/retried.d.ts +30 -0
  227. package/dist/retried.d.ts.map +1 -0
  228. package/dist/retried.js +72 -0
  229. package/dist/room-draft.d.ts +53 -13
  230. package/dist/room-draft.d.ts.map +1 -1
  231. package/dist/room-draft.js +405 -115
  232. package/dist/room-drafts.d.ts +24 -0
  233. package/dist/room-drafts.d.ts.map +1 -0
  234. package/dist/room-drafts.js +222 -0
  235. package/dist/room-list.d.ts +10 -0
  236. package/dist/room-list.d.ts.map +1 -0
  237. package/dist/room-list.js +47 -0
  238. package/dist/rows.d.ts +40 -32
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +72 -123
  241. package/dist/run-tables.d.ts +25 -0
  242. package/dist/run-tables.d.ts.map +1 -0
  243. package/dist/run-tables.js +98 -0
  244. package/dist/running.d.ts +5 -0
  245. package/dist/running.d.ts.map +1 -0
  246. package/dist/running.js +10 -0
  247. package/dist/runs.d.ts +27 -0
  248. package/dist/runs.d.ts.map +1 -0
  249. package/dist/runs.js +92 -0
  250. package/dist/runtime.d.ts +38 -0
  251. package/dist/runtime.d.ts.map +1 -0
  252. package/dist/runtime.js +1 -0
  253. package/dist/save.d.ts +45 -87
  254. package/dist/save.d.ts.map +1 -1
  255. package/dist/save.js +402 -286
  256. package/dist/saves.d.ts +34 -0
  257. package/dist/saves.d.ts.map +1 -0
  258. package/dist/saves.js +464 -0
  259. package/dist/search.d.ts +12 -95
  260. package/dist/search.d.ts.map +1 -1
  261. package/dist/search.js +10 -317
  262. package/dist/seed.d.ts +11 -2
  263. package/dist/seed.d.ts.map +1 -1
  264. package/dist/seed.js +71 -1
  265. package/dist/selector.d.ts +3 -0
  266. package/dist/selector.d.ts.map +1 -0
  267. package/dist/selector.js +22 -0
  268. package/dist/shared.d.ts +1 -10
  269. package/dist/shared.d.ts.map +1 -1
  270. package/dist/shared.js +13 -135
  271. package/dist/shown.d.ts +35 -0
  272. package/dist/shown.d.ts.map +1 -0
  273. package/dist/shown.js +327 -0
  274. package/dist/socket/admission.d.ts +7 -0
  275. package/dist/socket/admission.d.ts.map +1 -0
  276. package/dist/socket/admission.js +39 -0
  277. package/dist/socket/answers.d.ts +6 -0
  278. package/dist/socket/answers.d.ts.map +1 -0
  279. package/dist/socket/answers.js +20 -0
  280. package/dist/socket/lanes.d.ts +28 -0
  281. package/dist/socket/lanes.d.ts.map +1 -0
  282. package/dist/socket/lanes.js +103 -0
  283. package/dist/socket/reads.d.ts +10 -0
  284. package/dist/socket/reads.d.ts.map +1 -0
  285. package/dist/socket/reads.js +31 -0
  286. package/dist/socket/session.d.ts +41 -0
  287. package/dist/socket/session.d.ts.map +1 -0
  288. package/dist/socket/session.js +26 -0
  289. package/dist/socket.d.ts +70 -0
  290. package/dist/socket.d.ts.map +1 -0
  291. package/dist/socket.js +172 -0
  292. package/dist/source.d.ts +96 -0
  293. package/dist/source.d.ts.map +1 -0
  294. package/dist/source.js +149 -0
  295. package/dist/status.d.ts +4 -5
  296. package/dist/status.d.ts.map +1 -1
  297. package/dist/status.js +3 -7
  298. package/dist/store/installs.d.ts +30 -0
  299. package/dist/store/installs.d.ts.map +1 -0
  300. package/dist/store/installs.js +40 -0
  301. package/dist/store/readiness.d.ts +11 -0
  302. package/dist/store/readiness.d.ts.map +1 -0
  303. package/dist/store/readiness.js +68 -0
  304. package/dist/store/records.d.ts +234 -0
  305. package/dist/store/records.d.ts.map +1 -0
  306. package/dist/store/records.js +474 -0
  307. package/dist/store/room-held.d.ts +8 -0
  308. package/dist/store/room-held.d.ts.map +1 -0
  309. package/dist/store/room-held.js +17 -0
  310. package/dist/store/rooms-shown.d.ts +8 -0
  311. package/dist/store/rooms-shown.d.ts.map +1 -0
  312. package/dist/store/rooms-shown.js +13 -0
  313. package/dist/store/space.d.ts +11 -0
  314. package/dist/store/space.d.ts.map +1 -0
  315. package/dist/store/space.js +41 -0
  316. package/dist/store/watchers.d.ts +17 -0
  317. package/dist/store/watchers.d.ts.map +1 -0
  318. package/dist/store/watchers.js +56 -0
  319. package/dist/store/writes.d.ts +24 -0
  320. package/dist/store/writes.d.ts.map +1 -0
  321. package/dist/store/writes.js +125 -0
  322. package/dist/store.d.ts +115 -160
  323. package/dist/store.d.ts.map +1 -1
  324. package/dist/store.js +171 -762
  325. package/dist/stored.d.ts +181 -0
  326. package/dist/stored.d.ts.map +1 -0
  327. package/dist/stored.js +807 -0
  328. package/dist/surface.d.ts +100 -0
  329. package/dist/surface.d.ts.map +1 -0
  330. package/dist/surface.js +258 -0
  331. package/dist/sync.d.ts +21 -0
  332. package/dist/sync.d.ts.map +1 -0
  333. package/dist/sync.js +557 -0
  334. package/dist/tables.d.ts +362 -204
  335. package/dist/tables.d.ts.map +1 -1
  336. package/dist/tables.js +378 -264
  337. package/dist/tallies.d.ts +18 -0
  338. package/dist/tallies.d.ts.map +1 -0
  339. package/dist/tallies.js +128 -0
  340. package/dist/transfer.d.ts +0 -5
  341. package/dist/transfer.d.ts.map +1 -1
  342. package/dist/turn.d.ts +1 -1
  343. package/dist/turn.d.ts.map +1 -1
  344. package/dist/turn.js +28 -20
  345. package/dist/validation.d.ts +31 -0
  346. package/dist/validation.d.ts.map +1 -0
  347. package/dist/validation.js +144 -0
  348. package/dist/windows.d.ts +1 -11
  349. package/dist/windows.d.ts.map +1 -1
  350. package/dist/windows.js +2 -70
  351. package/dist/wire.d.ts +89 -17
  352. package/dist/wire.d.ts.map +1 -1
  353. package/dist/wire.js +38 -15
  354. package/package.json +16 -20
  355. package/AGENTS.md +0 -308
  356. package/dist/attempt.d.ts +0 -16
  357. package/dist/attempt.d.ts.map +0 -1
  358. package/dist/attempt.js +0 -70
  359. package/dist/binary.d.ts.map +0 -1
  360. package/dist/binary.js +0 -8
  361. package/dist/chat/acts.d.ts +0 -33
  362. package/dist/chat/acts.d.ts.map +0 -1
  363. package/dist/chat/acts.js +0 -36
  364. package/dist/chat/context.d.ts +0 -3
  365. package/dist/chat/context.d.ts.map +0 -1
  366. package/dist/chat/earlier.d.ts +0 -10
  367. package/dist/chat/earlier.d.ts.map +0 -1
  368. package/dist/chat/earlier.js +0 -54
  369. package/dist/chat/house.d.ts +0 -25
  370. package/dist/chat/house.d.ts.map +0 -1
  371. package/dist/chat/house.js +0 -38
  372. package/dist/chat/input.d.ts +0 -11
  373. package/dist/chat/input.d.ts.map +0 -1
  374. package/dist/chat/input.js +0 -92
  375. package/dist/chat/kit.d.ts +0 -61
  376. package/dist/chat/kit.d.ts.map +0 -1
  377. package/dist/chat/kit.js +0 -123
  378. package/dist/chat/lasting.d.ts +0 -6
  379. package/dist/chat/lasting.d.ts.map +0 -1
  380. package/dist/chat/lasting.js +0 -19
  381. package/dist/chat/list.d.ts +0 -28
  382. package/dist/chat/list.d.ts.map +0 -1
  383. package/dist/chat/list.js +0 -103
  384. package/dist/chat/markdown.d.ts +0 -21
  385. package/dist/chat/markdown.d.ts.map +0 -1
  386. package/dist/chat/markdown.js +0 -246
  387. package/dist/chat/message.d.ts +0 -7
  388. package/dist/chat/message.d.ts.map +0 -1
  389. package/dist/chat/message.js +0 -237
  390. package/dist/chat/messages.d.ts +0 -29
  391. package/dist/chat/messages.d.ts.map +0 -1
  392. package/dist/chat/messages.js +0 -190
  393. package/dist/chat/name.d.ts +0 -7
  394. package/dist/chat/name.d.ts.map +0 -1
  395. package/dist/chat/name.js +0 -37
  396. package/dist/chat/opened.d.ts +0 -12
  397. package/dist/chat/opened.d.ts.map +0 -1
  398. package/dist/chat/opened.js +0 -19
  399. package/dist/chat/overlay.d.ts +0 -32
  400. package/dist/chat/overlay.d.ts.map +0 -1
  401. package/dist/chat/overlay.js +0 -103
  402. package/dist/chat/parts.d.ts +0 -58
  403. package/dist/chat/parts.d.ts.map +0 -1
  404. package/dist/chat/parts.js +0 -120
  405. package/dist/chat/pieces.d.ts +0 -62
  406. package/dist/chat/pieces.d.ts.map +0 -1
  407. package/dist/chat/pieces.js +0 -1110
  408. package/dist/chat/process.d.ts +0 -20
  409. package/dist/chat/process.d.ts.map +0 -1
  410. package/dist/chat/process.js +0 -32
  411. package/dist/chat/provider.d.ts +0 -68
  412. package/dist/chat/provider.d.ts.map +0 -1
  413. package/dist/chat/provider.js +0 -619
  414. package/dist/chat/question.d.ts +0 -9
  415. package/dist/chat/question.d.ts.map +0 -1
  416. package/dist/chat/question.js +0 -69
  417. package/dist/chat/questions.d.ts.map +0 -1
  418. package/dist/chat/read.d.ts.map +0 -1
  419. package/dist/chat/ready.d.ts +0 -37
  420. package/dist/chat/ready.d.ts.map +0 -1
  421. package/dist/chat/ready.js +0 -93
  422. package/dist/chat/room-file.d.ts +0 -8
  423. package/dist/chat/room-file.d.ts.map +0 -1
  424. package/dist/chat/room-file.js +0 -72
  425. package/dist/chat/steady.d.ts +0 -3
  426. package/dist/chat/steady.d.ts.map +0 -1
  427. package/dist/chat/steady.js +0 -26
  428. package/dist/chat/style.d.ts +0 -4
  429. package/dist/chat/style.d.ts.map +0 -1
  430. package/dist/chat/style.js +0 -306
  431. package/dist/chat.d.ts +0 -15
  432. package/dist/chat.d.ts.map +0 -1
  433. package/dist/chat.js +0 -8
  434. package/dist/fence.d.ts +0 -6
  435. package/dist/fence.d.ts.map +0 -1
  436. package/dist/fence.js +0 -10
  437. package/dist/log.d.ts +0 -5
  438. package/dist/log.d.ts.map +0 -1
  439. package/dist/log.js +0 -14
  440. package/dist/read-side.d.ts +0 -27
  441. package/dist/read-side.d.ts.map +0 -1
  442. package/dist/read-side.js +0 -1179
package/dist/tables.js CHANGED
@@ -1,57 +1,174 @@
1
- export const FILE_PART_BYTES = 1_048_576;
2
- const TABLES = [
3
- ['authored_facts', 'name TEXT PRIMARY KEY, value TEXT NOT NULL'],
4
- ['authored_queues', 'locator TEXT PRIMARY KEY, ids TEXT NOT NULL'],
5
- [
6
- 'authored_pending',
7
- 'locator TEXT NOT NULL, id TEXT NOT NULL, batch TEXT NOT NULL, state TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, id)',
8
- ],
9
- [
10
- 'authored_room_drafts',
11
- 'locator TEXT NOT NULL, path TEXT NOT NULL, record TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, path)',
12
- ],
13
- ['authored_chat_drafts', 'conversation TEXT PRIMARY KEY, record TEXT NOT NULL'],
14
- ['authored_calls', 'operation TEXT PRIMARY KEY, record TEXT NOT NULL, files TEXT NOT NULL'],
15
- ['authored_fences', 'locator TEXT PRIMARY KEY'],
16
- ];
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 { forgottenRuns, heldRuns, keptRuns, RUN_TABLES, runMarks, runsLeft, } from './run-tables.js';
7
+ import { keptRead, READ_TABLES, readsOfOtherBuildsForgotten, storedRead, } from './reads.js';
8
+ import { conversationTallies, roomTallies, } from './tallies.js';
9
+ 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';
10
+ export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
11
+ const STATEMENTS_HELD = 256;
12
+ export function sqliteConnection(engine, database) {
13
+ const decoder = new TextDecoder();
14
+ const held = new Map();
15
+ database.createFunction(sql.HOLDS_PHRASE, sql.holdsPhrase, {
16
+ arity: 2,
17
+ deterministic: true,
18
+ });
19
+ function prepared(sql) {
20
+ if (sql.includes(';'))
21
+ return null;
22
+ const found = held.get(sql);
23
+ held.delete(sql);
24
+ const statement = found ?? database.prepare(sql);
25
+ held.set(sql, statement);
26
+ if (held.size > STATEMENTS_HELD) {
27
+ const [oldest, evicted] = held.entries().next().value;
28
+ held.delete(oldest);
29
+ evicted.finalize();
30
+ }
31
+ return statement;
32
+ }
33
+ function stepped(statement, bind, each) {
34
+ try {
35
+ if (bind.length > 0 && statement.parameterCount > 0)
36
+ statement.bind(bind);
37
+ while (statement.step())
38
+ each();
39
+ }
40
+ finally {
41
+ statement.resetNoThrow(true);
42
+ }
43
+ }
44
+ return {
45
+ run(sql, bind = []) {
46
+ const statement = prepared(sql);
47
+ if (statement === null)
48
+ database.exec({ sql, bind });
49
+ else
50
+ stepped(statement, bind, () => { });
51
+ },
52
+ rows(sql, bind = []) {
53
+ const statement = prepared(sql);
54
+ if (statement === null) {
55
+ return database.exec({ sql, bind, rowMode: 'object', returnValue: 'resultRows' });
56
+ }
57
+ const names = statement.getColumnNames([]);
58
+ const rows = [];
59
+ stepped(statement, bind, () => {
60
+ const values = statement.get([]);
61
+ const row = Object.create(null);
62
+ for (const [index, name] of names.entries())
63
+ row[name] = values[index] ?? null;
64
+ rows.push(row);
65
+ });
66
+ return rows;
67
+ },
68
+ collate(name, compare) {
69
+ const answered = engine.capi.sqlite3_create_collation_v2(database.pointer, name, engine.capi.SQLITE_UTF8, 0, (_argument, leftLength, left, rightLength, right) => {
70
+ const heap = engine.wasm.heap8u();
71
+ return Math.sign(compare(decoder.decode(heap.subarray(left, left + leftLength)), decoder.decode(heap.subarray(right, right + rightLength))));
72
+ }, 0);
73
+ if (answered !== 0)
74
+ throw new Error(`the database refused the collation ${name}`);
75
+ },
76
+ };
77
+ }
78
+ const PROBE_BYTES = 4 * FILE_PART_BYTES;
17
79
  export const RUNTIME_TABLES = [
18
- ...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
19
- 'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
20
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',
21
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))',
83
+ ...REPLICA_TABLES,
84
+ ...MESSAGE_TABLES,
85
+ ...READ_TABLES,
86
+ ...RUN_TABLES,
22
87
  ];
23
- const OWNERS = ['authored_pending', 'authored_room_drafts', 'authored_calls'];
24
- const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
25
- const UNOWNED_PARTS = `DELETE FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS} UNION SELECT key FROM opened_files)`;
88
+ const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
26
89
  const READS = new Set([
27
- 'authored.queues',
90
+ 'authored.status',
91
+ 'authored.moving',
92
+ 'authored.pending',
93
+ 'authored.batch',
94
+ 'authored.order',
95
+ 'authored.queued',
28
96
  'authored.roomDrafts',
97
+ 'authored.chatDraft.read',
29
98
  'authored.chatDrafts',
30
99
  'authored.calls',
31
100
  'authored.fences',
101
+ 'authored.unsent',
32
102
  'authored.fact',
33
103
  'authored.file',
104
+ 'replica.open',
105
+ 'replica.rooms',
106
+ 'replica.room',
107
+ 'replica.covering',
108
+ 'replica.offline',
109
+ 'replica.held',
110
+ 'replica.facts',
111
+ 'replica.presentation',
112
+ 'replica.query',
113
+ 'replica.named',
114
+ 'replica.tallies',
115
+ 'replica.entries',
116
+ 'replica.typed',
117
+ 'replica.referrers',
118
+ 'replica.holders',
119
+ 'replica.folders',
120
+ 'replica.typedWithin',
34
121
  'opened.find',
122
+ 'opened.held',
35
123
  'file.part',
124
+ 'conversation.held',
125
+ 'conversation.window',
126
+ 'conversation.count',
127
+ 'conversation.turn',
128
+ 'conversation.rows',
129
+ 'conversation.tallies',
130
+ 'conversation.facts',
131
+ 'conversation.stored',
132
+ 'read.stored',
133
+ 'run.marks',
134
+ 'run.held',
36
135
  ]);
37
136
  const KINDS = new Set([
38
137
  ...READS,
39
- 'authored.keep',
40
138
  'authored.amend',
41
139
  'authored.roomDraft',
42
140
  'authored.chatDraft',
43
141
  'authored.call',
44
- 'authored.fence',
45
- 'authored.unfence',
46
- 'authored.discard',
47
142
  'authored.remember',
48
143
  'authored.claim',
49
144
  'authored.end',
145
+ 'replica.stage',
146
+ 'replica.resume',
147
+ 'replica.refresh',
148
+ 'replica.unrefresh',
149
+ 'replica.commit',
150
+ 'replica.fence',
151
+ 'replica.erase',
152
+ 'replica.abandon',
153
+ 'replica.unfence',
154
+ 'replica.release',
155
+ 'replica.rederive',
156
+ 'replica.demote',
157
+ 'replica.fact',
158
+ 'replica.present',
50
159
  'opened.begin',
51
160
  'opened.part',
52
161
  'opened.keep',
53
162
  'opened.drop',
54
163
  'opened.clean',
164
+ 'conversation.keep',
165
+ 'conversation.fact',
166
+ 'conversation.drop',
167
+ 'space.probe',
168
+ 'read.keep',
169
+ 'read.builds',
170
+ 'run.keep',
171
+ 'run.left',
55
172
  ]);
56
173
  export function isRuntime(request) {
57
174
  return KINDS.has(request.kind);
@@ -59,235 +176,76 @@ export function isRuntime(request) {
59
176
  export function readsRuntime(request) {
60
177
  return READS.has(request.kind);
61
178
  }
62
- function text(value) {
63
- return typeof value === 'string' ? value : String(value);
64
- }
65
- function texts(rows, column) {
66
- return rows.map((row) => text(row[column]));
67
- }
68
- function owned(files) {
69
- return JSON.stringify([...new Set(files)]);
70
- }
71
- function fact(connection, name) {
72
- const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
73
- return held === undefined ? null : text(held.value);
74
- }
75
- function remember(connection, name, value) {
76
- connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
77
- name,
78
- value,
79
- ]);
80
- return null;
81
- }
82
- function fenced(connection, locator) {
83
- return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
84
- }
85
- function stored(connection, key) {
86
- return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
87
- }
88
- function storedPart(connection, key, part, bytes) {
89
- connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
90
- }
91
- async function storedFiles(connection, files) {
92
- for (const { key, blob } of files) {
93
- if (stored(connection, key))
94
- continue;
95
- for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
96
- const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
97
- storedPart(connection, key, part, bytes);
98
- }
99
- }
100
- }
101
- function filePart(connection, key, part) {
102
- const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
103
- key,
104
- part,
105
- ]);
106
- return held?.bytes instanceof Uint8Array ? held.bytes : null;
107
- }
108
- function* fileParts(connection, key) {
109
- for (let part = 0;; part += 1) {
110
- const bytes = filePart(connection, key, part);
111
- if (bytes === null)
112
- return;
113
- yield bytes;
114
- }
115
- }
116
- async function spooled(connection, spool, { key, type }) {
117
- for (const held of [...spool.held()]) {
118
- if (held !== key && !stored(connection, held))
119
- await spool.drop(held);
120
- }
121
- return spool.spool(key, type, fileParts(connection, key));
122
- }
123
- function unowned(connection) {
124
- connection.run(UNOWNED_PARTS);
125
- }
126
- function queued(connection) {
179
+ function heldWork(connection, locator) {
180
+ const room = heldRoom(connection, locator);
127
181
  return {
128
- queues: connection.rows('SELECT locator, ids FROM authored_queues').map((row) => ({
129
- locator: text(row.locator),
130
- ids: JSON.parse(text(row.ids)),
131
- })),
132
- pending: connection
133
- .rows('SELECT locator, id, batch, state FROM authored_pending')
134
- .map((row) => ({
135
- locator: text(row.locator),
136
- id: text(row.id),
137
- batch: text(row.batch),
138
- state: text(row.state),
139
- })),
182
+ room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
183
+ queue: queueOf(connection, locator),
140
184
  };
141
185
  }
142
- function heldOrder(connection, locator) {
143
- const [held] = connection.rows('SELECT ids FROM authored_queues WHERE locator = ?', [locator]);
144
- return held === undefined ? [] : JSON.parse(text(held.ids));
145
- }
146
- function keptRows(connection, { locator, order, added, founded, roomDrafts, consumedRoomDrafts }) {
147
- for (const path of consumedRoomDrafts ?? []) {
148
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
149
- locator,
150
- path,
151
- ]);
152
- }
153
- for (const { path, record, files } of roomDrafts ?? []) {
154
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
155
- }
156
- if (order === undefined)
157
- return;
158
- const before = new Set(heldOrder(connection, locator));
159
- const after = new Set(order);
160
- if (after.size === 0)
161
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
162
- else {
163
- connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
164
- locator,
165
- JSON.stringify([...after]),
166
- ]);
167
- }
168
- for (const id of before) {
169
- if (!after.has(id)) {
170
- connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
171
- }
172
- }
173
- for (const { id, batch, state, files } of added ?? []) {
174
- if (before.has(id) || !after.has(id))
175
- continue;
176
- connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files) VALUES (?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files)]);
177
- }
178
- for (const { id, batch, files } of founded ?? []) {
179
- if (!before.has(id))
180
- continue;
181
- connection.run('UPDATE authored_pending SET batch = ?, files = ? WHERE locator = ? AND id = ?', [batch, owned(files), locator, id]);
182
- }
183
- }
184
- async function kept(connection, { writes, files, whole }) {
185
- const refused = writes.find(({ locator }) => fenced(connection, locator));
186
- if (refused !== undefined && whole)
187
- return refused.locator;
188
- await storedFiles(connection, files);
189
- for (const write of writes) {
190
- if (!fenced(connection, write.locator))
191
- keptRows(connection, write);
192
- }
193
- unowned(connection);
194
- return refused?.locator ?? null;
186
+ function status(connection) {
187
+ return {
188
+ ...unsentStatus(connection),
189
+ lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
190
+ };
195
191
  }
196
- function amended(connection, { locator, id, amendment }) {
197
- if (fenced(connection, locator))
198
- return null;
199
- const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
200
- if (held === undefined)
201
- return null;
202
- connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
203
- JSON.stringify({
204
- ...JSON.parse(text(held.state)),
205
- ...JSON.parse(amendment),
206
- }),
207
- locator,
208
- id,
209
- ]);
210
- return null;
192
+ function pendingOf(connection, locator, id) {
193
+ return {
194
+ state: pendingState(connection, locator, id),
195
+ room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
196
+ };
211
197
  }
212
- async function roomDraft(connection, { locator, path, kept: draft, files }) {
213
- if (fenced(connection, locator))
214
- return locator;
215
- await storedFiles(connection, files);
216
- if (draft === null) {
217
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
218
- locator,
219
- path,
198
+ function storedConversations(connection, conversations) {
199
+ const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
200
+ const bound = conversations === null ? [] : [JSON.stringify(conversations)];
201
+ return [
202
+ ...new Set([
203
+ ...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
204
+ ...chatDraftConversations(connection, conversations),
205
+ ]),
206
+ ];
207
+ }
208
+ function droppedConversations(connection, conversations) {
209
+ const held = storedConversations(connection, conversations);
210
+ for (const table of tablesOf(MESSAGE_TABLES)) {
211
+ connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
212
+ JSON.stringify(conversations),
220
213
  ]);
221
214
  }
222
- else {
223
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, draft.record, owned(draft.files)]);
224
- }
225
- unowned(connection);
226
- return null;
227
- }
228
- function chatDraft(connection, { kept: drafts, dropped }) {
229
- for (const conversation of dropped) {
230
- connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
231
- }
232
- for (const { conversation, record } of drafts) {
233
- connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
234
- }
235
- return null;
236
- }
237
- async function call(connection, { operation, kept: held, files }) {
238
- await storedFiles(connection, files);
239
- if (held === null)
240
- connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
241
- else {
242
- connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
243
- }
244
- unowned(connection);
245
- return null;
215
+ chatDraftsDropped(connection, conversations);
216
+ return held;
246
217
  }
247
- function roomWork(connection, locator) {
248
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
249
- connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
218
+ function unopened(connection) {
219
+ connection.run(UNOPENED_PARTS);
250
220
  }
251
221
  function fence(connection, locators) {
222
+ fencedWork(connection, locators);
252
223
  for (const locator of locators) {
253
- connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
254
- roomWork(connection, locator);
255
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
256
224
  connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
257
225
  }
258
- unowned(connection);
259
- return null;
226
+ unopened(connection);
227
+ return fenceRooms(connection, locators);
260
228
  }
261
- function unfence(connection, locators) {
262
- for (const locator of locators) {
263
- connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
264
- }
265
- return null;
229
+ function erased(connection, { locator, limit }) {
230
+ return erase(connection, locator, limit);
266
231
  }
267
- function discard(connection, locator) {
268
- roomWork(connection, locator);
269
- unowned(connection);
270
- return null;
271
- }
272
- function claim(connection, holder) {
273
- const held = fact(connection, 'holder');
274
- if (held !== null)
275
- return held === holder;
276
- remember(connection, 'holder', holder);
277
- return true;
232
+ function unfencedRooms(connection, locators) {
233
+ const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
234
+ .length === 0);
235
+ unfenced(connection, erased);
236
+ return erased;
278
237
  }
279
238
  function end(connection, holder) {
239
+ ended(connection);
240
+ forgottenConversations(connection);
241
+ forgottenRuns(connection);
280
242
  if (holder !== null && claim(connection, holder))
281
243
  return true;
282
- for (const [table] of TABLES)
283
- connection.run(`DELETE FROM ${table}`);
244
+ authoredEmptied(connection);
284
245
  connection.run('DELETE FROM opened_files');
285
- connection.run('DELETE FROM file_parts');
246
+ connection.run('DELETE FROM opened_parts');
286
247
  return false;
287
248
  }
288
- function count(value) {
289
- return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
290
- }
291
249
  function openedFile(connection, { locator, path, revision }) {
292
250
  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]);
293
251
  return held === undefined
@@ -302,7 +260,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
302
260
  if (fenced(connection, locator))
303
261
  return false;
304
262
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
305
- unowned(connection);
263
+ unopened(connection);
306
264
  connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
307
265
  return true;
308
266
  }
@@ -315,22 +273,26 @@ function fetching(connection, key) {
315
273
  function openedPart(connection, { key, part, bytes }) {
316
274
  if (fetching(connection, key) === null)
317
275
  return false;
318
- storedPart(connection, key, part, bytes);
276
+ connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
277
+ key,
278
+ part,
279
+ bytes,
280
+ ]);
319
281
  return true;
320
282
  }
321
283
  function dropped(connection, key) {
322
284
  connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
323
- connection.run('DELETE FROM file_parts WHERE key = ?', [key]);
285
+ connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
324
286
  return null;
325
287
  }
326
288
  function keptOpened(connection, { key, sha256, byteLength, parts }) {
327
289
  const fetched = fetching(connection, key);
328
290
  if (fetched === null)
329
291
  return false;
330
- 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]);
331
- const whole = count(held?.parts) === parts &&
332
- count(held?.bytes) === byteLength &&
333
- (parts === 0 || (count(held?.first) === 0 && count(held?.last) === parts - 1));
292
+ 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]);
293
+ const whole = count(held.parts) === parts &&
294
+ count(held.bytes) === byteLength &&
295
+ (parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
334
296
  if (!whole) {
335
297
  dropped(connection, key);
336
298
  return false;
@@ -341,53 +303,161 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
341
303
  key,
342
304
  ]);
343
305
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
344
- unowned(connection);
306
+ unopened(connection);
345
307
  return true;
346
308
  }
309
+ function heldPart(connection, key, part) {
310
+ const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
311
+ key,
312
+ part,
313
+ ]);
314
+ return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
315
+ }
316
+ function cleanable(connection) {
317
+ const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
318
+ return count(held.bytes);
319
+ }
347
320
  function cleaned(connection) {
348
321
  connection.run('DELETE FROM opened_files');
349
- const [freed] = connection.rows(`SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS})`);
350
- unowned(connection);
351
- return count(freed?.bytes);
322
+ const freed = cleanable(connection);
323
+ unopened(connection);
324
+ return freed;
325
+ }
326
+ function openedHeld(connection) {
327
+ return {
328
+ rooms: connection
329
+ .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')
330
+ .map((row) => ({ room: text(row.locator), count: count(row.files), size: count(row.bytes) })),
331
+ cleanable: cleanable(connection),
332
+ };
333
+ }
334
+ async function committed(connection, { authored, rooms }) {
335
+ const refused = authored === undefined ? null : await kept(connection, authored);
336
+ if (refused !== null && authored?.whole === true) {
337
+ return { fenced: refused, changed: {}, indexed: {} };
338
+ }
339
+ return {
340
+ fenced: refused,
341
+ ...commit(connection, rooms.filter(({ locator }) => !fenced(connection, locator))),
342
+ };
352
343
  }
353
344
  export function answerRuntime(connection, request, spool) {
354
345
  switch (request.kind) {
355
- case 'authored.queues':
356
- return queued(connection);
346
+ case 'authored.status':
347
+ return status(connection);
348
+ case 'authored.moving':
349
+ return moving(connection);
350
+ case 'authored.pending':
351
+ return pendingOf(connection, request.locator, request.id);
352
+ case 'authored.batch':
353
+ return pendingBatch(connection, request.locator, request.id);
354
+ case 'authored.order':
355
+ return heldOrder(connection, request.locator);
356
+ case 'authored.queued':
357
+ return queuedLocators(connection);
357
358
  case 'authored.roomDrafts':
358
- return texts(connection.rows('SELECT record FROM authored_room_drafts'), 'record');
359
+ return roomDraftRecords(connection, request.locator, request.paths);
360
+ case 'authored.chatDraft.read':
361
+ return chatDraftRecord(connection, request.conversation);
359
362
  case 'authored.chatDrafts':
360
- return texts(connection.rows('SELECT record FROM authored_chat_drafts'), 'record');
363
+ return chatDraftRecords(connection);
361
364
  case 'authored.calls':
362
- return texts(connection.rows('SELECT record FROM authored_calls'), 'record');
365
+ return callRecords(connection);
363
366
  case 'authored.fences':
364
- return texts(connection.rows('SELECT locator FROM authored_fences'), 'locator');
367
+ return fences(connection);
368
+ case 'authored.unsent':
369
+ return unsent(connection);
365
370
  case 'authored.fact':
366
371
  return fact(connection, request.name);
367
372
  case 'authored.file':
368
- return spooled(connection, spool, request);
369
- case 'authored.keep':
370
- return kept(connection, request);
373
+ return spooled(connection, spool, request.key, request.type);
371
374
  case 'authored.amend':
372
- return amended(connection, request);
375
+ return amended(connection, request.locator, request.id, request.amendment);
373
376
  case 'authored.roomDraft':
374
- return roomDraft(connection, request);
377
+ return roomDraft(connection, request.locator, request.path, request.kept, request.files);
375
378
  case 'authored.chatDraft':
376
- return chatDraft(connection, request);
379
+ return chatDraft(connection, request.kept, request.dropped);
377
380
  case 'authored.call':
378
- return call(connection, request);
379
- case 'authored.fence':
380
- return fence(connection, request.locators);
381
- case 'authored.unfence':
382
- return unfence(connection, request.locators);
383
- case 'authored.discard':
384
- return discard(connection, request.locator);
381
+ return call(connection, request.operation, request.kept, request.files);
385
382
  case 'authored.remember':
386
383
  return remember(connection, request.name, request.value);
387
384
  case 'authored.claim':
388
385
  return claim(connection, request.holder);
389
386
  case 'authored.end':
390
387
  return end(connection, request.holder);
388
+ case 'replica.open':
389
+ return opened(connection);
390
+ case 'replica.rooms':
391
+ return heldRooms(connection, request.locators);
392
+ case 'replica.room':
393
+ return heldWork(connection, request.locator);
394
+ case 'replica.covering':
395
+ return { ...covering(connection, request.since), queues: queues(connection) };
396
+ case 'replica.offline':
397
+ return offlineMode(connection, request.locator);
398
+ case 'replica.held':
399
+ return {
400
+ held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
401
+ staged: stagedLocators(connection),
402
+ };
403
+ case 'replica.demote':
404
+ return demoted(connection);
405
+ case 'replica.facts':
406
+ return facts(connection, request.names);
407
+ case 'replica.presentation':
408
+ return presentation(connection, request.app);
409
+ case 'replica.query':
410
+ return answerQuery(connection, request.plan, request.rooms, request.budget, request.follows);
411
+ case 'replica.named':
412
+ return namedHandles(connection, request.plan, request.rooms, request.handles);
413
+ case 'replica.tallies':
414
+ return roomTallies(connection, request.totals, request.rooms, request.since);
415
+ case 'replica.entries':
416
+ return entries(connection, request.key, request.view, request.paths);
417
+ case 'replica.typed':
418
+ return typed(connection, request.key, request.view, request.paths);
419
+ case 'replica.referrers':
420
+ return referrers(connection, request.key, request.view, request.targets);
421
+ case 'replica.holders':
422
+ return holders(connection, request.key, request.view, request.sought);
423
+ case 'replica.folders':
424
+ return folders(connection, request.key, request.paths);
425
+ case 'replica.typedWithin':
426
+ return typedWithin(connection, request.key, request.view, request.roots, request.within);
427
+ case 'replica.stage':
428
+ return fenced(connection, request.locator) ? null : stage(connection, request);
429
+ case 'replica.resume':
430
+ return fenced(connection, request.locator) ? null : resume(connection, request);
431
+ case 'replica.refresh':
432
+ return refreshing(connection, request);
433
+ case 'replica.unrefresh':
434
+ return unrefresh(connection, request.key);
435
+ case 'replica.commit':
436
+ return committed(connection, request);
437
+ case 'replica.fence':
438
+ return fence(connection, request.locators);
439
+ case 'replica.erase':
440
+ return erased(connection, request);
441
+ case 'replica.abandon':
442
+ return abandon(connection, request.locator);
443
+ case 'replica.unfence':
444
+ return unfencedRooms(connection, request.locators);
445
+ case 'replica.release':
446
+ return release(connection, request.key);
447
+ case 'replica.rederive':
448
+ return rederive(connection, request.key, request.composed, request.bytes, request.ms, request.floor);
449
+ case 'replica.fact':
450
+ connection.run('INSERT OR REPLACE INTO replica_facts (name, value) VALUES (?, ?)', [
451
+ request.name,
452
+ request.value,
453
+ ]);
454
+ return null;
455
+ case 'replica.present':
456
+ connection.run('INSERT OR REPLACE INTO replica_presentation (app, value) VALUES (?, ?)', [
457
+ request.app,
458
+ request.value,
459
+ ]);
460
+ return null;
391
461
  case 'opened.find':
392
462
  return openedFile(connection, request);
393
463
  case 'opened.begin':
@@ -400,7 +470,51 @@ export function answerRuntime(connection, request, spool) {
400
470
  return dropped(connection, request.key);
401
471
  case 'opened.clean':
402
472
  return cleaned(connection);
473
+ case 'opened.held':
474
+ return openedHeld(connection);
403
475
  case 'file.part':
404
- return filePart(connection, request.key, request.part);
476
+ return heldPart(connection, request.key, request.part);
477
+ case 'conversation.held':
478
+ return heldConversations(connection, request.conversations);
479
+ case 'conversation.keep': {
480
+ const { kind: _kind, ...write } = request;
481
+ return keptMessages(connection, write);
482
+ }
483
+ case 'conversation.window':
484
+ return messageWindow(connection, request.conversation, request.limit, request.before, request.phrase);
485
+ case 'conversation.count':
486
+ return messageCount(connection, request.conversation, request.phrase);
487
+ case 'conversation.turn':
488
+ return turnArrived(connection, request.conversation, request.turn);
489
+ case 'conversation.rows':
490
+ return conversationRows(connection, request.conversations);
491
+ case 'conversation.tallies':
492
+ return conversationTallies(connection, request.conversations, request.since);
493
+ case 'conversation.facts':
494
+ return conversationFacts(connection);
495
+ case 'conversation.fact': {
496
+ const { kind: _kind, ...fact } = request;
497
+ return keptFact(connection, fact);
498
+ }
499
+ case 'conversation.stored':
500
+ return storedConversations(connection, null);
501
+ case 'conversation.drop':
502
+ return droppedConversations(connection, request.conversations);
503
+ case 'space.probe':
504
+ return spool.probe(PROBE_BYTES).then(() => null);
505
+ case 'read.stored':
506
+ return storedRead(connection, request);
507
+ case 'read.keep':
508
+ return keptRead(connection, request, request.answer);
509
+ case 'read.builds':
510
+ return readsOfOtherBuildsForgotten(connection, request.build);
511
+ case 'run.marks':
512
+ return runMarks(connection);
513
+ case 'run.held':
514
+ return heldRuns(connection, request.asked, request.sight);
515
+ case 'run.keep':
516
+ return keptRuns(connection, request.event);
517
+ case 'run.left':
518
+ return runsLeft(connection, request.sight);
405
519
  }
406
520
  }