@agentshouse/mdruntime 0.1.0-cb2e390ee7b89 → 0.1.0-cb61c07f2d10b

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 (392) hide show
  1. package/README.md +19 -16
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +299 -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 +302 -0
  11. package/dist/adapter.d.ts +163 -125
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +7 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +40 -41
  16. package/dist/binary.d.ts +0 -5
  17. package/dist/binary.d.ts.map +1 -1
  18. package/dist/binary.js +1 -1
  19. package/dist/bootstrap.d.ts +30 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +309 -113
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +12 -0
  26. package/dist/chain.d.ts.map +1 -0
  27. package/dist/chain.js +64 -0
  28. package/dist/change-set.d.ts +13 -16
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -89
  31. package/dist/change.d.ts +32 -1
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +14 -3
  34. package/dist/chat-types.d.ts +5 -0
  35. package/dist/chat-types.d.ts.map +1 -0
  36. package/dist/chat-types.js +13 -0
  37. package/dist/client.d.ts +36 -24
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +117 -22
  40. package/dist/collection.d.ts +29 -21
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +48 -290
  43. package/dist/compile.d.ts +18 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +724 -0
  46. package/dist/connection.d.ts +7 -134
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +107 -3606
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/{chat/context.js → context.js} +1 -4
  52. package/dist/conversation-live.d.ts +140 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +250 -0
  55. package/dist/conversation-row.d.ts +33 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +53 -0
  58. package/dist/conversation.d.ts +72 -49
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1014 -794
  61. package/dist/declaration.d.ts +10 -0
  62. package/dist/declaration.d.ts.map +1 -0
  63. package/dist/declaration.js +24 -0
  64. package/dist/digest.d.ts +7 -0
  65. package/dist/digest.d.ts.map +1 -0
  66. package/dist/digest.js +113 -0
  67. package/dist/discovery.d.ts +10 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +150 -0
  70. package/dist/durability.d.ts +19 -4
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +5 -0
  73. package/dist/entry.d.ts +5 -2
  74. package/dist/entry.d.ts.map +1 -1
  75. package/dist/entry.js +33 -28
  76. package/dist/expectation.d.ts +26 -13
  77. package/dist/expectation.d.ts.map +1 -1
  78. package/dist/expectation.js +72 -19
  79. package/dist/failure.d.ts +3 -0
  80. package/dist/failure.d.ts.map +1 -1
  81. package/dist/failure.js +6 -0
  82. package/dist/figures.d.ts +49 -0
  83. package/dist/figures.d.ts.map +1 -0
  84. package/dist/figures.js +197 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +7 -122
  88. package/dist/holdings.d.ts +29 -0
  89. package/dist/holdings.d.ts.map +1 -0
  90. package/dist/holdings.js +95 -0
  91. package/dist/host.d.ts +20 -11
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +112 -49
  94. package/dist/identity.d.ts +0 -2
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +0 -6
  97. package/dist/index.d.ts +39 -15
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +18 -4
  100. package/dist/install.d.ts +54 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +530 -0
  103. package/dist/lifecycle.d.ts +7 -0
  104. package/dist/lifecycle.d.ts.map +1 -0
  105. package/dist/lifecycle.js +277 -0
  106. package/dist/listing.d.ts +48 -0
  107. package/dist/listing.d.ts.map +1 -0
  108. package/dist/listing.js +139 -0
  109. package/dist/live.d.ts +23 -0
  110. package/dist/live.d.ts.map +1 -0
  111. package/dist/live.js +165 -0
  112. package/dist/locks.d.ts +7 -0
  113. package/dist/locks.d.ts.map +1 -0
  114. package/dist/locks.js +32 -0
  115. package/dist/lost.d.ts +5 -0
  116. package/dist/lost.d.ts.map +1 -0
  117. package/dist/lost.js +49 -0
  118. package/dist/media.d.ts +8 -0
  119. package/dist/media.d.ts.map +1 -0
  120. package/dist/media.js +218 -0
  121. package/dist/memory.d.ts +17 -8
  122. package/dist/memory.d.ts.map +1 -1
  123. package/dist/memory.js +273 -121
  124. package/dist/messages.d.ts +49 -0
  125. package/dist/messages.d.ts.map +1 -0
  126. package/dist/messages.js +150 -0
  127. package/dist/model.d.ts +8 -11
  128. package/dist/model.d.ts.map +1 -1
  129. package/dist/model.js +6 -23
  130. package/dist/models.d.ts +10 -0
  131. package/dist/models.d.ts.map +1 -0
  132. package/dist/models.js +153 -0
  133. package/dist/name.d.ts +4 -0
  134. package/dist/name.d.ts.map +1 -0
  135. package/dist/name.js +122 -0
  136. package/dist/observation.d.ts +15 -2
  137. package/dist/observation.d.ts.map +1 -1
  138. package/dist/observation.js +98 -14
  139. package/dist/opened.d.ts +22 -0
  140. package/dist/opened.d.ts.map +1 -0
  141. package/dist/opened.js +107 -0
  142. package/dist/opening.d.ts +4 -0
  143. package/dist/opening.d.ts.map +1 -0
  144. package/dist/opening.js +53 -0
  145. package/dist/outcome.d.ts +47 -9
  146. package/dist/outcome.d.ts.map +1 -1
  147. package/dist/outcome.js +56 -2
  148. package/dist/overlay.d.ts +7 -5
  149. package/dist/overlay.d.ts.map +1 -1
  150. package/dist/overlay.js +123 -182
  151. package/dist/page-metadata.d.ts +8 -0
  152. package/dist/page-metadata.d.ts.map +1 -0
  153. package/dist/page-metadata.js +19 -0
  154. package/dist/parts.d.ts +3 -0
  155. package/dist/parts.d.ts.map +1 -0
  156. package/dist/parts.js +10 -0
  157. package/dist/paths.d.ts +2 -0
  158. package/dist/paths.d.ts.map +1 -1
  159. package/dist/paths.js +26 -0
  160. package/dist/preparation.d.ts +20 -0
  161. package/dist/preparation.d.ts.map +1 -0
  162. package/dist/preparation.js +227 -0
  163. package/dist/presence.d.ts +52 -0
  164. package/dist/presence.d.ts.map +1 -0
  165. package/dist/presence.js +220 -0
  166. package/dist/queries.d.ts +16 -0
  167. package/dist/queries.d.ts.map +1 -0
  168. package/dist/queries.js +282 -0
  169. package/dist/query.d.ts +21 -203
  170. package/dist/query.d.ts.map +1 -1
  171. package/dist/query.js +3 -491
  172. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -7
  173. package/dist/questions.d.ts.map +1 -0
  174. package/dist/{chat/questions.js → questions.js} +11 -7
  175. package/dist/queue.d.ts +40 -0
  176. package/dist/queue.d.ts.map +1 -0
  177. package/dist/queue.js +450 -0
  178. package/dist/reach.d.ts +20 -9
  179. package/dist/reach.d.ts.map +1 -1
  180. package/dist/reach.js +341 -111
  181. package/dist/react.d.ts +16 -4
  182. package/dist/react.d.ts.map +1 -1
  183. package/dist/react.js +35 -15
  184. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  185. package/dist/read.d.ts.map +1 -0
  186. package/dist/{chat/read.js → read.js} +4 -0
  187. package/dist/readiness.d.ts +13 -17
  188. package/dist/readiness.d.ts.map +1 -1
  189. package/dist/readiness.js +2 -8
  190. package/dist/reads.d.ts +38 -10
  191. package/dist/reads.d.ts.map +1 -1
  192. package/dist/reads.js +163 -83
  193. package/dist/recovery.d.ts +5 -2
  194. package/dist/recovery.d.ts.map +1 -1
  195. package/dist/recovery.js +65 -8
  196. package/dist/refresh.d.ts +18 -15
  197. package/dist/refresh.d.ts.map +1 -1
  198. package/dist/refresh.js +145 -60
  199. package/dist/refusal.d.ts +5 -0
  200. package/dist/refusal.d.ts.map +1 -0
  201. package/dist/refusal.js +55 -0
  202. package/dist/replica.d.ts +49 -36
  203. package/dist/replica.d.ts.map +1 -1
  204. package/dist/replica.js +320 -196
  205. package/dist/retried.d.ts +30 -0
  206. package/dist/retried.d.ts.map +1 -0
  207. package/dist/retried.js +72 -0
  208. package/dist/room-draft.d.ts +28 -11
  209. package/dist/room-draft.d.ts.map +1 -1
  210. package/dist/room-draft.js +194 -118
  211. package/dist/room-drafts.d.ts +24 -0
  212. package/dist/room-drafts.d.ts.map +1 -0
  213. package/dist/room-drafts.js +217 -0
  214. package/dist/rows.d.ts +31 -30
  215. package/dist/rows.d.ts.map +1 -1
  216. package/dist/rows.js +60 -120
  217. package/dist/runtime.d.ts +34 -0
  218. package/dist/runtime.d.ts.map +1 -0
  219. package/dist/runtime.js +1 -0
  220. package/dist/save.d.ts +43 -49
  221. package/dist/save.d.ts.map +1 -1
  222. package/dist/save.js +776 -275
  223. package/dist/saves.d.ts +32 -0
  224. package/dist/saves.d.ts.map +1 -0
  225. package/dist/saves.js +410 -0
  226. package/dist/search.d.ts +12 -95
  227. package/dist/search.d.ts.map +1 -1
  228. package/dist/search.js +10 -266
  229. package/dist/seed.d.ts +11 -2
  230. package/dist/seed.d.ts.map +1 -1
  231. package/dist/seed.js +71 -1
  232. package/dist/shared.d.ts +6 -7
  233. package/dist/shared.d.ts.map +1 -1
  234. package/dist/shared.js +75 -104
  235. package/dist/shown.d.ts +32 -0
  236. package/dist/shown.d.ts.map +1 -0
  237. package/dist/shown.js +290 -0
  238. package/dist/socket/admission.d.ts +7 -0
  239. package/dist/socket/admission.d.ts.map +1 -0
  240. package/dist/socket/admission.js +39 -0
  241. package/dist/socket/answers.d.ts +6 -0
  242. package/dist/socket/answers.d.ts.map +1 -0
  243. package/dist/socket/answers.js +20 -0
  244. package/dist/socket/lanes.d.ts +28 -0
  245. package/dist/socket/lanes.d.ts.map +1 -0
  246. package/dist/socket/lanes.js +103 -0
  247. package/dist/socket/reads.d.ts +10 -0
  248. package/dist/socket/reads.d.ts.map +1 -0
  249. package/dist/socket/reads.js +31 -0
  250. package/dist/socket/session.d.ts +38 -0
  251. package/dist/socket/session.d.ts.map +1 -0
  252. package/dist/socket/session.js +23 -0
  253. package/dist/socket.d.ts +67 -0
  254. package/dist/socket.d.ts.map +1 -0
  255. package/dist/socket.js +164 -0
  256. package/dist/source.d.ts +54 -0
  257. package/dist/source.d.ts.map +1 -0
  258. package/dist/source.js +82 -0
  259. package/dist/status.d.ts +4 -5
  260. package/dist/status.d.ts.map +1 -1
  261. package/dist/status.js +3 -7
  262. package/dist/store/installs.d.ts +30 -0
  263. package/dist/store/installs.d.ts.map +1 -0
  264. package/dist/store/installs.js +34 -0
  265. package/dist/store/readiness.d.ts +10 -0
  266. package/dist/store/readiness.d.ts.map +1 -0
  267. package/dist/store/readiness.js +52 -0
  268. package/dist/store/records.d.ts +213 -0
  269. package/dist/store/records.d.ts.map +1 -0
  270. package/dist/store/records.js +431 -0
  271. package/dist/store/room-held.d.ts +8 -0
  272. package/dist/store/room-held.d.ts.map +1 -0
  273. package/dist/store/room-held.js +17 -0
  274. package/dist/store/space.d.ts +11 -0
  275. package/dist/store/space.d.ts.map +1 -0
  276. package/dist/store/space.js +41 -0
  277. package/dist/store/watchers.d.ts +17 -0
  278. package/dist/store/watchers.d.ts.map +1 -0
  279. package/dist/store/watchers.js +56 -0
  280. package/dist/store/writes.d.ts +24 -0
  281. package/dist/store/writes.d.ts.map +1 -0
  282. package/dist/store/writes.js +125 -0
  283. package/dist/store.d.ts +111 -164
  284. package/dist/store.d.ts.map +1 -1
  285. package/dist/store.js +159 -754
  286. package/dist/stored.d.ts +156 -0
  287. package/dist/stored.d.ts.map +1 -0
  288. package/dist/stored.js +649 -0
  289. package/dist/surface.d.ts +88 -0
  290. package/dist/surface.d.ts.map +1 -0
  291. package/dist/surface.js +220 -0
  292. package/dist/sync.d.ts +19 -0
  293. package/dist/sync.d.ts.map +1 -0
  294. package/dist/sync.js +535 -0
  295. package/dist/tables.d.ts +412 -0
  296. package/dist/tables.d.ts.map +1 -0
  297. package/dist/tables.js +737 -0
  298. package/dist/tallies.d.ts +18 -0
  299. package/dist/tallies.d.ts.map +1 -0
  300. package/dist/tallies.js +129 -0
  301. package/dist/transfer.d.ts +0 -5
  302. package/dist/transfer.d.ts.map +1 -1
  303. package/dist/turn.d.ts +5 -3
  304. package/dist/turn.d.ts.map +1 -1
  305. package/dist/turn.js +51 -21
  306. package/dist/validation.d.ts +29 -0
  307. package/dist/validation.d.ts.map +1 -0
  308. package/dist/validation.js +104 -0
  309. package/dist/windows.d.ts +9 -16
  310. package/dist/windows.d.ts.map +1 -1
  311. package/dist/windows.js +11 -75
  312. package/dist/wire.d.ts +89 -9
  313. package/dist/wire.d.ts.map +1 -1
  314. package/dist/wire.js +29 -6
  315. package/package.json +19 -19
  316. package/AGENTS.md +0 -299
  317. package/dist/acquisition.d.ts +0 -14
  318. package/dist/acquisition.d.ts.map +0 -1
  319. package/dist/acquisition.js +0 -24
  320. package/dist/attempt.d.ts +0 -16
  321. package/dist/attempt.d.ts.map +0 -1
  322. package/dist/attempt.js +0 -70
  323. package/dist/chat/acts.d.ts +0 -33
  324. package/dist/chat/acts.d.ts.map +0 -1
  325. package/dist/chat/acts.js +0 -36
  326. package/dist/chat/context.d.ts +0 -3
  327. package/dist/chat/context.d.ts.map +0 -1
  328. package/dist/chat/earlier.d.ts +0 -10
  329. package/dist/chat/earlier.d.ts.map +0 -1
  330. package/dist/chat/earlier.js +0 -54
  331. package/dist/chat/input.d.ts +0 -9
  332. package/dist/chat/input.d.ts.map +0 -1
  333. package/dist/chat/input.js +0 -99
  334. package/dist/chat/kit.d.ts +0 -61
  335. package/dist/chat/kit.d.ts.map +0 -1
  336. package/dist/chat/kit.js +0 -123
  337. package/dist/chat/lasting.d.ts +0 -6
  338. package/dist/chat/lasting.d.ts.map +0 -1
  339. package/dist/chat/lasting.js +0 -19
  340. package/dist/chat/list.d.ts +0 -27
  341. package/dist/chat/list.d.ts.map +0 -1
  342. package/dist/chat/list.js +0 -99
  343. package/dist/chat/markdown.d.ts +0 -20
  344. package/dist/chat/markdown.d.ts.map +0 -1
  345. package/dist/chat/markdown.js +0 -188
  346. package/dist/chat/message.d.ts +0 -6
  347. package/dist/chat/message.d.ts.map +0 -1
  348. package/dist/chat/message.js +0 -192
  349. package/dist/chat/messages.d.ts +0 -22
  350. package/dist/chat/messages.d.ts.map +0 -1
  351. package/dist/chat/messages.js +0 -155
  352. package/dist/chat/name.d.ts +0 -6
  353. package/dist/chat/name.d.ts.map +0 -1
  354. package/dist/chat/name.js +0 -37
  355. package/dist/chat/opened.d.ts +0 -11
  356. package/dist/chat/opened.d.ts.map +0 -1
  357. package/dist/chat/opened.js +0 -17
  358. package/dist/chat/overlay.d.ts +0 -31
  359. package/dist/chat/overlay.d.ts.map +0 -1
  360. package/dist/chat/overlay.js +0 -97
  361. package/dist/chat/parts.d.ts +0 -57
  362. package/dist/chat/parts.d.ts.map +0 -1
  363. package/dist/chat/parts.js +0 -119
  364. package/dist/chat/process.d.ts +0 -20
  365. package/dist/chat/process.d.ts.map +0 -1
  366. package/dist/chat/process.js +0 -32
  367. package/dist/chat/provider.d.ts +0 -63
  368. package/dist/chat/provider.d.ts.map +0 -1
  369. package/dist/chat/provider.js +0 -635
  370. package/dist/chat/question.d.ts +0 -9
  371. package/dist/chat/question.d.ts.map +0 -1
  372. package/dist/chat/question.js +0 -69
  373. package/dist/chat/questions.d.ts.map +0 -1
  374. package/dist/chat/read.d.ts.map +0 -1
  375. package/dist/chat/ready.d.ts +0 -34
  376. package/dist/chat/ready.d.ts.map +0 -1
  377. package/dist/chat/ready.js +0 -91
  378. package/dist/chat/style.d.ts +0 -4
  379. package/dist/chat/style.d.ts.map +0 -1
  380. package/dist/chat/style.js +0 -302
  381. package/dist/chat.d.ts +0 -14
  382. package/dist/chat.d.ts.map +0 -1
  383. package/dist/chat.js +0 -8
  384. package/dist/fence.d.ts +0 -6
  385. package/dist/fence.d.ts.map +0 -1
  386. package/dist/fence.js +0 -10
  387. package/dist/log.d.ts +0 -5
  388. package/dist/log.d.ts.map +0 -1
  389. package/dist/log.js +0 -14
  390. package/dist/read-side.d.ts +0 -25
  391. package/dist/read-side.d.ts.map +0 -1
  392. package/dist/read-side.js +0 -761
package/dist/store.js CHANGED
@@ -1,772 +1,177 @@
1
- import { sameBinary, sameChange } from './overlay.js';
2
- import { differing } from './shared.js';
3
- const DATABASE = 'mdruntime';
4
- const AUTHORED = 'mdruntime-authored';
5
- const FENCES = 'fences';
6
- const ROOMS = 'rooms';
7
- const DOCUMENTS = 'documents';
8
- const BINARY_FILES = 'binaryFiles';
9
- const TRANSFERS = 'transfers';
10
- const RECEIVED = 'received';
11
- const RECEIVED_PARTS = 'receivedParts';
12
- const PENDING_CHANGES = 'pendingChanges';
13
- const DECLARATIONS = 'declarations';
14
- const ROOM_DRAFTS = 'roomDrafts';
15
- const PRESENTATION = 'presentation';
16
- const CONVERSATIONS = 'conversations';
17
- const MESSAGES = 'messages';
18
- const CHAT_DRAFTS = 'chatDrafts';
19
- const CALLS = 'calls';
20
- const QUEUES = 'queues';
21
- const FACTS = 'facts';
22
- const CURRENT = 'current';
23
- const MEMBER = 'member';
24
- const TARGETS = 'targets';
25
- const GENERATION = 'generation';
26
- const HOLDER = 'holder';
27
- const BINDING = 'binding';
28
- export const STORE_SCHEMA = 25;
29
- const REPLICA_SHAPE = 23;
30
- export const AUTHORED_SCHEMA = 3;
31
- const AUTHORED_STORES = [
32
- [QUEUES, { keyPath: 'locator' }],
33
- [PENDING_CHANGES, { keyPath: ['locator', 'id'] }],
34
- [ROOM_DRAFTS, { keyPath: ['locator', 'path'] }],
35
- [CHAT_DRAFTS, { keyPath: 'conversation' }],
36
- [CALLS, { keyPath: 'operation' }],
37
- [FACTS, undefined],
38
- [FENCES, { keyPath: 'locator' }],
39
- ];
40
- const REPLICA_STORES = [
41
- [ROOMS, { keyPath: 'locator' }],
42
- [DOCUMENTS, { keyPath: ['locator', 'transfer', 'path'] }],
43
- [BINARY_FILES, { keyPath: ['locator', 'transfer', 'path'] }],
44
- [TRANSFERS, { keyPath: 'locator' }],
45
- [RECEIVED, { keyPath: 'key' }],
46
- [RECEIVED_PARTS, { keyPath: ['key', 'index'] }],
47
- [DECLARATIONS, undefined],
48
- [PRESENTATION, { keyPath: 'app' }],
49
- [CONVERSATIONS, { keyPath: 'conversation' }],
50
- [MESSAGES, { keyPath: ['conversation', 'identity'] }],
51
- ];
52
- const READ_BATCH = 256;
53
- const MESSAGE_INDEXES = [
54
- ['conversation', 'conversation'],
55
- ['position', ['conversation', 'position']],
56
- ['turn', ['conversation', 'turn']],
57
- ];
58
- function settled(request) {
59
- return new Promise((resolve, reject) => {
60
- request.onsuccess = () => resolve(request.result);
61
- request.onerror = () => reject(request.error);
1
+ import { schemaTypes } from './attached-model.js';
2
+ import { createCell } from './cell.js';
3
+ import { openedFiles } from './opened.js';
4
+ import { compositionOf } from './replica.js';
5
+ import { STARTING } from './status.js';
6
+ import { createInstalls, NO_INSTALL } from './store/installs.js';
7
+ import { openRuntimeStore, } from './store/records.js';
8
+ import { createReadinessQueue } from './store/readiness.js';
9
+ import { createRoomHeld } from './store/room-held.js';
10
+ import { createSpace } from './store/space.js';
11
+ import { createWatchers } from './store/watchers.js';
12
+ import { createWrites } from './store/writes.js';
13
+ const OPENING = 'store';
14
+ export function createStore(options) {
15
+ const writes = createWrites();
16
+ const watchers = createWatchers(options.unpublished);
17
+ const { lost } = options;
18
+ const installs = createInstalls();
19
+ const seeds = new Map();
20
+ const landed = createRoomHeld();
21
+ const attached = createRoomHeld();
22
+ const typesHeld = new Map();
23
+ const device = createCell({
24
+ persistence: options.persistence,
25
+ storageLoss: null,
26
+ heldWhenOpened: false,
27
+ preparing: false,
28
+ sweeping: false,
29
+ unpreparedDemand: new Set(),
30
+ unpreparable: new Set(),
31
+ establishing: new Set(),
32
+ status: STARTING,
33
+ roomsShown: null,
62
34
  });
63
- }
64
- function completed(transaction) {
65
- return new Promise((resolve, reject) => {
66
- transaction.oncomplete = () => resolve();
67
- transaction.onerror = () => reject(transaction.error);
68
- transaction.onabort = () => reject(transaction.error);
69
- });
70
- }
71
- const EMPTY_DECLARATIONS = {
72
- lastCompleted: null,
73
- providerLimits: [],
74
- capabilities: [],
75
- };
76
- function declaration(database) {
77
- const transaction = database.transaction(DECLARATIONS, 'readonly');
78
- return settled(transaction.objectStore(DECLARATIONS).get(CURRENT)).then((record) => record ?? EMPTY_DECLARATIONS);
79
- }
80
- function updateDeclaration(database, update) {
81
- const transaction = database.transaction(DECLARATIONS, 'readwrite');
82
- const store = transaction.objectStore(DECLARATIONS);
83
- const prior = store.get(CURRENT);
84
- prior.onsuccess = () => {
85
- store.put(update(prior.result ?? EMPTY_DECLARATIONS), CURRENT);
86
- };
87
- return completed(transaction);
88
- }
89
- function amendPending(database, locator, id, amendment) {
90
- const transaction = database.transaction(PENDING_CHANGES, 'readwrite');
91
- const pending = transaction.objectStore(PENDING_CHANGES);
92
- const request = pending.get([locator, id]);
93
- request.onsuccess = () => {
94
- const record = request.result;
95
- if (record !== undefined)
96
- pending.put({ ...record, ...amendment });
97
- };
98
- return completed(transaction);
99
- }
100
- function accepted({ conversation: _held, ...message }) {
101
- return message;
102
- }
103
- function roomRecord(record) {
104
- const { documents, binaries, revisions, fileIds, changes, written, ...room } = record;
105
- return room;
106
- }
107
- function chatDraftRecord(record) {
108
- return { ...record, revision: record.revision ?? '' };
109
- }
110
- function underTransfer(locator, transfer, after) {
111
- return after === undefined
112
- ? IDBKeyRange.bound([locator, transfer], [locator, transfer, []])
113
- : IDBKeyRange.bound([locator, transfer, after], [locator, transfer, []], true);
114
- }
115
- function underRoom(locator) {
116
- return IDBKeyRange.bound([locator], [locator, []]);
117
- }
118
- async function readTransfer(store, locator, transfer, receive) {
119
- let range = underTransfer(locator, transfer);
120
- for (;;) {
121
- const batch = await settled(store.getAll(range, READ_BATCH));
122
- for (const record of batch)
123
- receive(record);
124
- if (batch.length < READ_BATCH)
125
- return;
126
- range = underTransfer(locator, transfer, batch[batch.length - 1].path);
35
+ const space = createSpace(options.database, options.spaceFreed);
36
+ const readiness = createReadinessQueue(options.deliverReadiness, options.unpublished);
37
+ let opening;
38
+ function open() {
39
+ opening ??= options.opening(openRuntimeStore(options.database)).then((opened) => {
40
+ options.retries.succeeded('database', OPENING);
41
+ return opened;
42
+ }, (error) => {
43
+ opening = undefined;
44
+ options.retries.failed('database', OPENING, error);
45
+ throw error;
46
+ });
47
+ return opening;
127
48
  }
128
- }
129
- function emptyLayer() {
130
- return { documents: {}, binaries: {}, revisions: {}, fileIds: {}, changes: {}, written: {} };
131
- }
132
- async function readLayer(transaction, locator, transfer) {
133
- const layer = emptyLayer();
134
- const head = (held) => {
135
- if (held.revision !== null)
136
- layer.revisions[held.path] = held.revision;
137
- if (held.fileId !== null)
138
- layer.fileIds[held.path] = held.fileId;
139
- if (held.change !== null)
140
- layer.changes[held.path] = held.change;
141
- };
142
- await readTransfer(transaction.objectStore(DOCUMENTS), locator, transfer, (document) => {
143
- layer.documents[document.path] = document.content;
144
- if (document.written !== null)
145
- layer.written[document.path] = document.written;
146
- head(document);
147
- });
148
- await readTransfer(transaction.objectStore(BINARY_FILES), locator, transfer, (file) => {
149
- layer.binaries[file.path] = file.binary;
150
- head(file);
151
- });
152
- return layer;
153
- }
154
- function documentRecord(locator, transfer, layer, path) {
155
- return {
156
- locator,
157
- transfer,
158
- path,
159
- content: layer.documents[path],
160
- revision: layer.revisions[path] ?? null,
161
- fileId: layer.fileIds[path] ?? null,
162
- change: layer.changes[path] ?? null,
163
- written: layer.written[path] ?? null,
164
- };
165
- }
166
- function binaryFileRecord(locator, transfer, layer, path) {
167
- return {
168
- locator,
169
- transfer,
170
- path,
171
- revision: layer.revisions[path] ?? null,
172
- fileId: layer.fileIds[path] ?? null,
173
- change: layer.changes[path] ?? null,
174
- binary: layer.binaries[path],
175
- };
176
- }
177
- function writeLayer(transaction, locator, transfer, next, base) {
178
- const documents = transaction.objectStore(DOCUMENTS);
179
- const files = transaction.objectStore(BINARY_FILES);
180
- const paths = base === null
181
- ? new Set([...Object.keys(next.documents), ...Object.keys(next.binaries)])
182
- : new Set([
183
- ...differing(base.documents, next.documents),
184
- ...differing(base.revisions, next.revisions),
185
- ...differing(base.fileIds, next.fileIds),
186
- ...differing(base.written, next.written),
187
- ...differing(base.changes, next.changes, sameChange),
188
- ...differing(base.binaries, next.binaries, sameBinary),
189
- ]);
190
- for (const path of paths) {
191
- if (next.documents[path] !== undefined) {
192
- documents.put(documentRecord(locator, transfer, next, path));
193
- }
194
- else if (base?.documents[path] !== undefined) {
195
- documents.delete([locator, transfer, path]);
196
- }
197
- if (next.binaries[path] !== undefined) {
198
- files.put(binaryFileRecord(locator, transfer, next, path));
199
- }
200
- else if (base?.binaries[path] !== undefined) {
201
- files.delete([locator, transfer, path]);
202
- }
203
- }
204
- }
205
- function removeRoomEntries(store, locator) {
206
- const keys = store.getAllKeys();
207
- keys.onsuccess = () => {
208
- for (const key of keys.result) {
209
- if (Array.isArray(key) && key[0] === locator)
210
- store.delete(key);
211
- }
212
- };
213
- }
214
- function removeDatabase(name) {
215
- return new Promise((resolve, reject) => {
216
- const removal = indexedDB.deleteDatabase(name);
217
- removal.onsuccess = () => resolve();
218
- removal.onerror = () => reject(removal.error);
219
- });
220
- }
221
- export async function authoredHolder() {
222
- const authored = await openAuthored();
223
- try {
224
- const transaction = authored.transaction(FACTS, 'readonly');
225
- const held = transaction.objectStore(FACTS).get(HOLDER);
226
- await completed(transaction);
227
- return typeof held.result === 'string' ? held.result : null;
228
- }
229
- finally {
230
- authored.close();
231
- }
232
- }
233
- export async function authoredBy(holder) {
234
- const authored = await openAuthored();
235
- try {
236
- const transaction = authored.transaction(FACTS, 'readwrite');
237
- const facts = transaction.objectStore(FACTS);
238
- const held = facts.get(HOLDER);
239
- let owned = true;
240
- held.onsuccess = () => {
241
- if (held.result === undefined)
242
- facts.put(holder, HOLDER);
243
- else
244
- owned = held.result === holder;
245
- };
246
- await completed(transaction);
247
- return owned;
49
+ function prepareAgain(locator) {
50
+ const { unpreparable } = device.now();
51
+ device.set({
52
+ unpreparable: locator === undefined
53
+ ? new Set()
54
+ : new Set([...unpreparable].filter((held) => held !== locator)),
55
+ });
248
56
  }
249
- finally {
250
- authored.close();
57
+ function typed(locator, persisted) {
58
+ if (persisted.status === 'unavailable')
59
+ return persisted;
60
+ const schema = persisted.snapshot.schema;
61
+ const held = typesHeld.get(locator);
62
+ if (held !== undefined && held.schema === schema)
63
+ return { ...persisted, types: held.types };
64
+ const types = schemaTypes(schema, options.roomTypes);
65
+ typesHeld.set(locator, { schema, types });
66
+ return { ...persisted, types };
251
67
  }
252
- }
253
- export async function authoredBinding() {
254
- const authored = await openAuthored();
255
- try {
256
- const transaction = authored.transaction(FACTS, 'readonly');
257
- const held = transaction.objectStore(FACTS).get(BINDING);
258
- await completed(transaction);
259
- return typeof held.result === 'string' ? held.result : null;
68
+ function recordOf(stored) {
69
+ return { ...stored, model: typed(stored.locator, stored.model) };
260
70
  }
261
- finally {
262
- authored.close();
71
+ async function rooms(locators) {
72
+ const held = await (await open()).rooms(locators);
73
+ return new Map(held
74
+ .filter(({ record }) => !lost(record.locator))
75
+ .map(({ record, indexed, documents }) => [
76
+ record.locator,
77
+ { record: recordOf(record), indexed, documents },
78
+ ]));
263
79
  }
264
- }
265
- export async function bindAuthored(binding) {
266
- const authored = await openAuthored();
267
- try {
268
- const transaction = authored.transaction(FACTS, 'readwrite');
269
- transaction.objectStore(FACTS).put(binding, BINDING);
270
- await completed(transaction);
80
+ async function work(locator) {
81
+ if (lost(locator))
82
+ return { replica: undefined, queue: [], states: new Map() };
83
+ const { room, queue } = await (await open()).room(locator);
84
+ const batches = queue.map(({ batch }) => batch);
85
+ const states = new Map(queue.map(({ batch, state }) => [batch.id, state]));
86
+ return {
87
+ replica: room === null
88
+ ? undefined
89
+ : { record: recordOf(room.record), queue: batches, states, overlaid: room.overlaid },
90
+ queue: batches,
91
+ states,
92
+ };
271
93
  }
272
- finally {
273
- authored.close();
94
+ async function drafts(locator, paths) {
95
+ const held = await (await open()).roomDrafts(locator, paths);
96
+ return held.filter((record) => !lost(record.locator));
274
97
  }
275
- }
276
- export async function removeRuntimeStore(holder) {
277
- await removeDatabase(DATABASE);
278
- if (holder !== undefined && (await authoredBy(holder)))
279
- return true;
280
- await removeDatabase(AUTHORED);
281
- return false;
282
- }
283
- export function openDatabase(name, version, upgrade) {
284
- return new Promise((resolve, reject) => {
285
- const opening = indexedDB.open(name, version);
286
- opening.onupgradeneeded = (event) => upgrade(opening, event.oldVersion);
287
- opening.onsuccess = () => resolve(opening.result);
288
- opening.onerror = () => {
289
- if (opening.error?.name !== 'VersionError') {
290
- reject(opening.error);
291
- return;
292
- }
293
- removeDatabase(name)
294
- .then(() => openDatabase(name, version, upgrade))
295
- .then(resolve, reject);
296
- };
297
- });
298
- }
299
- function openReplica() {
300
- return openDatabase(DATABASE, STORE_SCHEMA, (opening, oldVersion) => {
301
- const database = opening.result;
302
- if (oldVersion < REPLICA_SHAPE) {
303
- for (const name of [...database.objectStoreNames])
304
- database.deleteObjectStore(name);
305
- }
306
- for (const [name, parameters] of REPLICA_STORES) {
307
- if (database.objectStoreNames.contains(name))
308
- continue;
309
- database.createObjectStore(name, parameters);
310
- }
311
- const messages = opening.transaction.objectStore(MESSAGES);
312
- for (const [name, keyPath] of MESSAGE_INDEXES) {
313
- if (!messages.indexNames.contains(name))
314
- messages.createIndex(name, keyPath);
315
- }
316
- });
317
- }
318
- function openAuthored() {
319
- return openDatabase(AUTHORED, AUTHORED_SCHEMA, (opening) => {
320
- const database = opening.result;
321
- for (const [name, parameters] of AUTHORED_STORES) {
322
- if (!database.objectStoreNames.contains(name))
323
- database.createObjectStore(name, parameters);
324
- }
325
- });
326
- }
327
- export async function openRuntimeStore(fenced) {
328
- const authored = await openAuthored();
329
- const database = await openReplica().catch((error) => {
330
- authored.close();
331
- throw error;
332
- });
333
98
  return {
334
- async all() {
335
- const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_FILES], 'readonly');
336
- const rooms = await settled(transaction.objectStore(ROOMS).getAll());
337
- const records = [];
338
- for (const room of rooms.filter((held) => !fenced(held.locator))) {
339
- records.push({ ...room, ...(await readLayer(transaction, room.locator, room.transfer)) });
340
- }
341
- return records;
342
- },
343
- async keepAuthored({ locator, queue, founded, saved, roomDrafts, consumedRoomDrafts }) {
344
- if (fenced(locator))
345
- return;
346
- const transaction = authored.transaction([QUEUES, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
347
- const order = transaction.objectStore(QUEUES);
348
- const pending = transaction.objectStore(PENDING_CHANGES);
349
- const held = order.get(locator);
350
- held.onsuccess = () => {
351
- const before = new Set(held.result?.order ?? []);
352
- const after = new Set(queue.map((batch) => batch.id));
353
- if (queue.length === 0)
354
- order.delete(locator);
355
- else
356
- order.put({ locator, order: [...after] });
357
- for (const id of before) {
358
- if (!after.has(id))
359
- pending.delete([locator, id]);
360
- }
361
- for (const batch of queue) {
362
- if (!before.has(batch.id)) {
363
- pending.put({
364
- locator,
365
- id: batch.id,
366
- batch,
367
- drafts: saved?.get(batch.id) ?? [],
368
- submission: { state: 'waiting' },
369
- lost: false,
370
- });
371
- }
372
- }
373
- for (const batch of founded ?? []) {
374
- if (!before.has(batch.id))
375
- continue;
376
- const stored = pending.get([locator, batch.id]);
377
- stored.onsuccess = () => {
378
- const record = stored.result;
379
- if (record !== undefined)
380
- pending.put({ ...record, batch });
381
- };
382
- }
99
+ device,
100
+ space,
101
+ readiness,
102
+ ask: options.database.ask,
103
+ changed: options.changed,
104
+ open,
105
+ durably: (work) => writes.exclusive(async () => {
106
+ const local = await open();
107
+ return work(local);
108
+ }),
109
+ exclusive: writes.exclusive,
110
+ gathered: writes.gathered,
111
+ written: writes.written,
112
+ startingWrite: writes.startingWrite,
113
+ finishingWrite: writes.finishingWrite,
114
+ ahead: writes.ahead,
115
+ rederive: writes.rederive,
116
+ refreshPage: writes.refreshPage,
117
+ stageBytes: writes.stageBytes,
118
+ deriveBytes: writes.deriveBytes,
119
+ rooms,
120
+ record: async (locator) => (await rooms([locator])).get(locator)?.record,
121
+ work,
122
+ replica: async (locator) => (await work(locator)).replica,
123
+ async covering() {
124
+ const held = await (await open()).covering();
125
+ return {
126
+ rooms: new Map([...held.rooms].filter(([locator]) => !lost(locator))),
127
+ queues: new Map([...held.queues].filter(([locator]) => !lost(locator))),
383
128
  };
384
- const draftStore = transaction.objectStore(ROOM_DRAFTS);
385
- for (const path of consumedRoomDrafts ?? [])
386
- draftStore.delete([locator, path]);
387
- for (const record of roomDrafts ?? [])
388
- draftStore.put(record);
389
- await completed(transaction);
390
- },
391
- async write({ next, previous, stored }) {
392
- if (next === previous || fenced(next.locator))
393
- return;
394
- const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_FILES, TRANSFERS], 'readwrite');
395
- transaction.objectStore(ROOMS).put(roomRecord(next));
396
- const moved = previous?.transfer !== next.transfer;
397
- if (moved && previous !== null) {
398
- const range = underTransfer(previous.locator, previous.transfer);
399
- transaction.objectStore(DOCUMENTS).delete(range);
400
- transaction.objectStore(BINARY_FILES).delete(range);
401
- }
402
- if (moved)
403
- transaction.objectStore(TRANSFERS).delete(next.locator);
404
- writeLayer(transaction, next.locator, next.transfer, next, moved ? (stored ?? null) : previous);
405
- await completed(transaction);
406
- },
407
- async revokeModels(records) {
408
- const transaction = database.transaction(ROOMS, 'readwrite');
409
- const rooms = transaction.objectStore(ROOMS);
410
- const revoked = { status: 'unavailable', reason: 'revoked' };
411
- for (const record of records) {
412
- if (fenced(record.locator))
413
- continue;
414
- rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }));
415
- }
416
- await completed(transaction);
417
- },
418
- async lastCompleted() {
419
- return (await declaration(database)).lastCompleted;
420
- },
421
- complete(at) {
422
- return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));
423
- },
424
- async providerLimits() {
425
- return (await declaration(database)).providerLimits;
426
- },
427
- async capabilities() {
428
- return (await declaration(database)).capabilities;
429
- },
430
- declare(limits, capabilities) {
431
- return updateDeclaration(database, (record) => ({
432
- ...record,
433
- providerLimits: limits,
434
- capabilities,
435
- }));
436
- },
437
- async member() {
438
- const transaction = database.transaction(DECLARATIONS, 'readonly');
439
- const held = await settled(transaction.objectStore(DECLARATIONS).get(MEMBER));
440
- return held ?? null;
441
- },
442
- async keepMember(member) {
443
- const transaction = database.transaction(DECLARATIONS, 'readwrite');
444
- transaction.objectStore(DECLARATIONS).put(member, MEMBER);
445
- await completed(transaction);
446
- },
447
- async targets() {
448
- const transaction = database.transaction(DECLARATIONS, 'readonly');
449
- const held = await settled(transaction.objectStore(DECLARATIONS).get(TARGETS));
450
- return held ?? {};
451
- },
452
- async keepTargets(targets) {
453
- const transaction = database.transaction(DECLARATIONS, 'readwrite');
454
- transaction.objectStore(DECLARATIONS).put(targets, TARGETS);
455
- await completed(transaction);
456
- },
457
- async queues() {
458
- const transaction = authored.transaction([QUEUES, PENDING_CHANGES], 'readonly');
459
- const [queues, pending] = await Promise.all([
460
- settled(transaction.objectStore(QUEUES).getAll()),
461
- settled(transaction.objectStore(PENDING_CHANGES).getAll()),
462
- ]);
463
- const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
464
- return queues
465
- .filter((queue) => !fenced(queue.locator))
466
- .map((queue) => ({
467
- locator: queue.locator,
468
- pending: queue.order.map((id) => {
469
- const record = byId.get(`${queue.locator}\0${id}`);
470
- if (record === undefined)
471
- throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
472
- const { batch, drafts, submission, lost, upload, accepted } = record;
473
- return { batch, state: { drafts, submission, lost, upload, accepted } };
474
- }),
475
- }));
476
- },
477
- async submit(locator, id, submission, lost) {
478
- if (!fenced(locator))
479
- await amendPending(authored, locator, id, { submission, lost });
480
- },
481
- async accept(locator, id, roomVersion) {
482
- if (!fenced(locator))
483
- await amendPending(authored, locator, id, { accepted: roomVersion });
484
- },
485
- async keepUpload(locator, id, upload) {
486
- if (!fenced(locator))
487
- await amendPending(authored, locator, id, { upload });
488
- },
489
- async roomDrafts() {
490
- const transaction = authored.transaction(ROOM_DRAFTS, 'readonly');
491
- const held = await settled(transaction.objectStore(ROOM_DRAFTS).getAll());
492
- return held.filter((record) => !fenced(record.locator));
493
- },
494
- async presentation() {
495
- const transaction = database.transaction(PRESENTATION, 'readonly');
496
- return settled(transaction.objectStore(PRESENTATION).getAll());
497
- },
498
- async present(record) {
499
- const transaction = database.transaction(PRESENTATION, 'readwrite');
500
- transaction.objectStore(PRESENTATION).put(record);
501
- await completed(transaction);
502
- },
503
- async conversations() {
504
- const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');
505
- const records = await settled(transaction.objectStore(CONVERSATIONS).getAll());
506
- const held = new Map(records.map(({ conversation, read, partial }) => [
507
- conversation,
508
- { conversation, read, partial: partial === true },
509
- ]));
510
- const keys = transaction.objectStore(MESSAGES).index('conversation');
511
- await new Promise((resolve, reject) => {
512
- const cursor = keys.openKeyCursor(null, 'nextunique');
513
- cursor.onerror = () => reject(cursor.error);
514
- cursor.onsuccess = () => {
515
- const at = cursor.result;
516
- if (at === null) {
517
- resolve();
518
- return;
519
- }
520
- const conversation = at.key;
521
- if (!held.has(conversation)) {
522
- held.set(conversation, { conversation, read: undefined, partial: true });
523
- }
524
- at.continue();
525
- };
526
- });
527
- return [...held.values()];
528
- },
529
- async keepMessages({ conversation, messages, read }) {
530
- const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readwrite');
531
- const stored = transaction.objectStore(MESSAGES);
532
- for (const message of messages) {
533
- stored.put({ ...message, conversation });
534
- }
535
- if (read !== undefined) {
536
- transaction.objectStore(CONVERSATIONS).put({
537
- conversation,
538
- read: read.at,
539
- ...(read.partial ? { partial: true } : {}),
540
- });
541
- }
542
- await completed(transaction);
543
- },
544
- async messageWindow(conversation, limit, before) {
545
- const transaction = database.transaction(MESSAGES, 'readonly');
546
- const index = transaction.objectStore(MESSAGES).index('position');
547
- const range = IDBKeyRange.bound([conversation], [conversation, before?.[0] ?? []]);
548
- const earlier = ({ position, identity }) => before === null || position < before[0] || (position === before[0] && identity < before[1]);
549
- if (limit === undefined) {
550
- const held = await settled(index.getAll(range));
551
- return { messages: held.filter(earlier).map(accepted), more: false };
552
- }
553
- const latest = [];
554
- let more = false;
555
- await new Promise((resolve, reject) => {
556
- const cursor = index.openCursor(range, 'prev');
557
- cursor.onerror = () => reject(cursor.error);
558
- cursor.onsuccess = () => {
559
- const at = cursor.result;
560
- if (at === null) {
561
- resolve();
562
- return;
563
- }
564
- const record = at.value;
565
- if (!earlier(record)) {
566
- at.continue();
567
- return;
568
- }
569
- if (latest.length === limit) {
570
- more = true;
571
- resolve();
572
- return;
573
- }
574
- latest.push(accepted(record));
575
- at.continue();
576
- };
577
- });
578
- return { messages: latest.reverse(), more };
579
- },
580
- async messageCount(conversation) {
581
- const transaction = database.transaction(MESSAGES, 'readonly');
582
- return settled(transaction.objectStore(MESSAGES).index('conversation').count(conversation));
583
129
  },
584
- async messagesAfter(conversation, identity) {
585
- const transaction = database.transaction(MESSAGES, 'readonly');
586
- const range = identity === null
587
- ? IDBKeyRange.bound([conversation], [conversation, []])
588
- : IDBKeyRange.bound([conversation, identity], [conversation, []], true);
589
- const held = await settled(transaction.objectStore(MESSAGES).getAll(range, READ_BATCH));
590
- return held.map(accepted);
591
- },
592
- async messageIdentities(conversation) {
593
- const transaction = database.transaction(MESSAGES, 'readonly');
594
- const keys = await settled(transaction.objectStore(MESSAGES).index('conversation').getAllKeys(conversation));
595
- return keys.map((key) => key[1]);
596
- },
597
- async turnArrived(conversation, turn) {
598
- const transaction = database.transaction(MESSAGES, 'readonly');
599
- const held = await settled(transaction.objectStore(MESSAGES).index('turn').count([conversation, turn]));
600
- return held > 0;
601
- },
602
- async dropConversations(conversations) {
603
- const drafts = authored.transaction(CHAT_DRAFTS, 'readwrite');
604
- for (const conversation of conversations)
605
- drafts.objectStore(CHAT_DRAFTS).delete(conversation);
606
- await completed(drafts);
607
- const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readwrite');
608
- const messages = transaction.objectStore(MESSAGES);
609
- for (const conversation of conversations) {
610
- transaction.objectStore(CONVERSATIONS).delete(conversation);
611
- const keys = messages.index('conversation').getAllKeys(conversation);
612
- keys.onsuccess = () => {
613
- for (const key of keys.result)
614
- messages.delete(key);
615
- };
616
- }
617
- await completed(transaction);
618
- },
619
- async chatDrafts() {
620
- const transaction = authored.transaction(CHAT_DRAFTS, 'readonly');
621
- const held = await settled(transaction.objectStore(CHAT_DRAFTS).getAll());
622
- return held.map(chatDraftRecord);
623
- },
624
- async keepChatDrafts(records) {
625
- const transaction = authored.transaction(CHAT_DRAFTS, 'readwrite');
626
- for (const record of records)
627
- transaction.objectStore(CHAT_DRAFTS).put(record);
628
- await completed(transaction);
629
- },
630
- async dropChatDraft(conversation) {
631
- const transaction = authored.transaction(CHAT_DRAFTS, 'readwrite');
632
- transaction.objectStore(CHAT_DRAFTS).delete(conversation);
633
- await completed(transaction);
634
- },
635
- async calls() {
636
- const transaction = authored.transaction(CALLS, 'readonly');
637
- return settled(transaction.objectStore(CALLS).getAll());
638
- },
639
- async keepCall(record) {
640
- const transaction = authored.transaction(CALLS, 'readwrite');
641
- transaction.objectStore(CALLS).put(record);
642
- await completed(transaction);
643
- },
644
- async dropCall(operation) {
645
- const transaction = authored.transaction(CALLS, 'readwrite');
646
- transaction.objectStore(CALLS).delete(operation);
647
- await completed(transaction);
648
- },
649
- async keepRoomDraft(record) {
650
- if (fenced(record.locator))
651
- return;
652
- const transaction = authored.transaction(ROOM_DRAFTS, 'readwrite');
653
- transaction.objectStore(ROOM_DRAFTS).put(record);
654
- await completed(transaction);
655
- },
656
- async discardRoomDraft(locator, path) {
657
- if (fenced(locator))
658
- return;
659
- const transaction = authored.transaction(ROOM_DRAFTS, 'readwrite');
660
- transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);
661
- await completed(transaction);
662
- },
663
- async fences() {
664
- const transaction = authored.transaction(FENCES, 'readonly');
665
- const held = await settled(transaction.objectStore(FENCES).getAll());
666
- return held.map((fence) => fence.locator);
667
- },
668
- async erase(locators) {
669
- const work = authored.transaction([FENCES, QUEUES, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
670
- for (const locator of locators) {
671
- work.objectStore(FENCES).put({ locator });
672
- work.objectStore(QUEUES).delete(locator);
673
- for (const name of [PENDING_CHANGES, ROOM_DRAFTS]) {
674
- removeRoomEntries(work.objectStore(name), locator);
675
- }
676
- }
677
- await completed(work);
678
- const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_FILES, TRANSFERS], 'readwrite');
679
- for (const locator of locators) {
680
- transaction.objectStore(ROOMS).delete(locator);
681
- transaction.objectStore(TRANSFERS).delete(locator);
682
- transaction.objectStore(DOCUMENTS).delete(underRoom(locator));
683
- transaction.objectStore(BINARY_FILES).delete(underRoom(locator));
684
- }
685
- await completed(transaction);
686
- const fences = authored.transaction(FENCES, 'readwrite');
687
- for (const locator of locators)
688
- fences.objectStore(FENCES).delete(locator);
689
- await completed(fences);
690
- },
691
- async discard(locator) {
692
- const transaction = authored.transaction([QUEUES, PENDING_CHANGES], 'readwrite');
693
- transaction.objectStore(QUEUES).delete(locator);
694
- removeRoomEntries(transaction.objectStore(PENDING_CHANGES), locator);
695
- await completed(transaction);
696
- },
697
- async transfers() {
698
- const transaction = database.transaction(TRANSFERS, 'readonly');
699
- const held = await settled(transaction.objectStore(TRANSFERS).getAll());
700
- return held.filter((record) => !fenced(record.locator));
701
- },
702
- staged(record) {
703
- const transaction = database.transaction([DOCUMENTS, BINARY_FILES], 'readonly');
704
- return readLayer(transaction, record.locator, record.transfer);
705
- },
706
- async stage(record, page) {
707
- if (fenced(record.locator))
708
- return;
709
- const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_FILES], 'readwrite');
710
- writeLayer(transaction, record.locator, record.transfer, page, null);
711
- transaction.objectStore(TRANSFERS).put(record);
712
- await completed(transaction);
713
- },
714
- async abandon(locator) {
715
- if (fenced(locator))
716
- return;
717
- const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_FILES], 'readwrite');
718
- const transfers = transaction.objectStore(TRANSFERS);
719
- const held = transfers.get(locator);
720
- held.onsuccess = () => {
721
- const record = held.result;
722
- if (record === undefined)
723
- return;
724
- transfers.delete(locator);
725
- const range = underTransfer(locator, record.transfer);
726
- transaction.objectStore(DOCUMENTS).delete(range);
727
- transaction.objectStore(BINARY_FILES).delete(range);
130
+ async status() {
131
+ const held = await (await open()).status();
132
+ return {
133
+ queued: held.queued.filter((locator) => !lost(locator)),
134
+ lastCompleted: held.lastCompleted,
135
+ unsent: held.unsent.filter(({ room }) => !lost(room)),
136
+ resets: held.resets.filter(({ locator }) => !lost(locator)),
137
+ returned: held.returned.filter(({ locator }) => !lost(locator)),
728
138
  };
729
- await completed(transaction);
730
- },
731
- async receivedHeads() {
732
- const transaction = database.transaction(RECEIVED, 'readonly');
733
- return settled(transaction.objectStore(RECEIVED).getAll());
734
- },
735
- async receivedParts(key, count) {
736
- const transaction = database.transaction(RECEIVED_PARTS, 'readonly');
737
- const kept = await settled(transaction
738
- .objectStore(RECEIVED_PARTS)
739
- .getAll(IDBKeyRange.bound([key, 0], [key, count], false, true)));
740
- return kept.map((part) => part.value);
741
- },
742
- async keepReceived(key, head, part) {
743
- const transaction = database.transaction([RECEIVED, RECEIVED_PARTS], 'readwrite');
744
- transaction.objectStore(RECEIVED).put({ key, head });
745
- if (part !== undefined)
746
- transaction.objectStore(RECEIVED_PARTS).put({ key, ...part });
747
- await completed(transaction);
748
- },
749
- async dropReceived(keys) {
750
- const transaction = database.transaction([RECEIVED, RECEIVED_PARTS], 'readwrite');
751
- for (const key of keys) {
752
- transaction.objectStore(RECEIVED).delete(key);
753
- transaction.objectStore(RECEIVED_PARTS).delete(IDBKeyRange.bound([key], [key, []]));
754
- }
755
- await completed(transaction);
756
- },
757
- async generation() {
758
- const transaction = authored.transaction(FACTS, 'readonly');
759
- const held = await settled(transaction.objectStore(FACTS).get(GENERATION));
760
- return held ?? null;
761
139
  },
762
- async rememberGeneration(value) {
763
- const transaction = authored.transaction(FACTS, 'readwrite');
764
- transaction.objectStore(FACTS).put(value, GENERATION);
765
- await completed(transaction);
140
+ queued: async () => (await (await open()).queued()).filter((locator) => !lost(locator)),
141
+ drafts,
142
+ draft: async (locator, path) => (await drafts(locator, [path]))[0],
143
+ composed: ({ model, declaration }) => compositionOf(model, declaration.typedSelection, options.builtIn, options.typedPaths),
144
+ publication: watchers.publication,
145
+ owing: watchers.owing,
146
+ watch: watchers.watch,
147
+ watching: watchers.watching,
148
+ tell: watchers.tell,
149
+ installs,
150
+ seeds: {
151
+ of: (key) => seeds.get(key),
152
+ keep(key, seed) {
153
+ seeds.set(key, seed);
154
+ },
155
+ drop(key) {
156
+ seeds.delete(key);
157
+ },
158
+ },
159
+ landed,
160
+ attached,
161
+ opened: openedFiles(options.database, lost),
162
+ prepareAgain,
163
+ part: (file, part) => options.database.ask({ kind: 'file.part', key: file, part }),
164
+ forget(locator) {
165
+ typesHeld.delete(locator);
166
+ landed.forget(locator);
167
+ attached.forget(locator);
168
+ installs.change(locator, ({ installing }) => ({ ...NO_INSTALL, installing }));
169
+ prepareAgain(locator);
766
170
  },
767
171
  close() {
768
- authored.close();
769
- database.close();
172
+ space.stop();
173
+ readiness.close();
174
+ watchers.close();
770
175
  },
771
176
  };
772
177
  }