@agentshouse/mdruntime 0.1.0-c97456d63baba → 0.1.0-c9873d788cfb6

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