@agentshouse/mdruntime 0.1.0-cfb2ae0107054 → 0.1.0-cfb95807829be

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 (413) hide show
  1. package/README.md +24 -19
  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 +321 -0
  11. package/dist/adapter.d.ts +266 -122
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +6 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +35 -41
  16. package/dist/authored.d.ts +88 -0
  17. package/dist/authored.d.ts.map +1 -0
  18. package/dist/authored.js +345 -0
  19. package/dist/binary.d.ts +6 -7
  20. package/dist/binary.d.ts.map +1 -1
  21. package/dist/binary.js +10 -3
  22. package/dist/bootstrap.d.ts +31 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +309 -109
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +12 -0
  29. package/dist/chain.d.ts.map +1 -0
  30. package/dist/chain.js +64 -0
  31. package/dist/change-set.d.ts +13 -14
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +17 -63
  34. package/dist/change.d.ts +36 -1
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +17 -3
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +58 -30
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +105 -29
  43. package/dist/collection.d.ts +35 -9
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +56 -79
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +18 -0
  50. package/dist/compile.d.ts.map +1 -0
  51. package/dist/compile.js +721 -0
  52. package/dist/connection.d.ts +8 -117
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +115 -2599
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/{chat/context.js → context.js} +2 -5
  58. package/dist/conversation-live.d.ts +149 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +259 -0
  61. package/dist/conversation-row.d.ts +40 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +66 -0
  64. package/dist/conversation.d.ts +85 -47
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1110 -649
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/digest.d.ts +7 -0
  71. package/dist/digest.d.ts.map +1 -0
  72. package/dist/digest.js +113 -0
  73. package/dist/discovery.d.ts +12 -0
  74. package/dist/discovery.d.ts.map +1 -0
  75. package/dist/discovery.js +175 -0
  76. package/dist/download.d.ts +6 -0
  77. package/dist/download.d.ts.map +1 -0
  78. package/dist/download.js +42 -0
  79. package/dist/durability.d.ts +24 -1
  80. package/dist/durability.d.ts.map +1 -1
  81. package/dist/durability.js +12 -0
  82. package/dist/entry.d.ts +21 -4
  83. package/dist/entry.d.ts.map +1 -1
  84. package/dist/entry.js +65 -31
  85. package/dist/expectation.d.ts +26 -13
  86. package/dist/expectation.d.ts.map +1 -1
  87. package/dist/expectation.js +72 -19
  88. package/dist/failure.d.ts +3 -0
  89. package/dist/failure.d.ts.map +1 -1
  90. package/dist/failure.js +8 -0
  91. package/dist/figures.d.ts +49 -0
  92. package/dist/figures.d.ts.map +1 -0
  93. package/dist/figures.js +199 -0
  94. package/dist/file.d.ts +2 -19
  95. package/dist/file.d.ts.map +1 -1
  96. package/dist/file.js +8 -122
  97. package/dist/holdings.d.ts +29 -0
  98. package/dist/holdings.d.ts.map +1 -0
  99. package/dist/holdings.js +95 -0
  100. package/dist/host.d.ts +32 -4
  101. package/dist/host.d.ts.map +1 -1
  102. package/dist/host.js +214 -31
  103. package/dist/house-query.d.ts +18 -0
  104. package/dist/house-query.d.ts.map +1 -0
  105. package/dist/house-query.js +54 -0
  106. package/dist/index.d.ts +45 -13
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +22 -2
  109. package/dist/install.d.ts +60 -0
  110. package/dist/install.d.ts.map +1 -0
  111. package/dist/install.js +537 -0
  112. package/dist/lifecycle.d.ts +7 -0
  113. package/dist/lifecycle.d.ts.map +1 -0
  114. package/dist/lifecycle.js +290 -0
  115. package/dist/listing.d.ts +60 -0
  116. package/dist/listing.d.ts.map +1 -0
  117. package/dist/listing.js +168 -0
  118. package/dist/live.d.ts +25 -0
  119. package/dist/live.d.ts.map +1 -0
  120. package/dist/live.js +206 -0
  121. package/dist/loaded.d.ts +7 -0
  122. package/dist/loaded.d.ts.map +1 -0
  123. package/dist/loaded.js +46 -0
  124. package/dist/locks.d.ts +7 -0
  125. package/dist/locks.d.ts.map +1 -0
  126. package/dist/locks.js +34 -0
  127. package/dist/lost.d.ts +5 -0
  128. package/dist/lost.d.ts.map +1 -0
  129. package/dist/lost.js +49 -0
  130. package/dist/media.d.ts +24 -0
  131. package/dist/media.d.ts.map +1 -0
  132. package/dist/media.js +352 -0
  133. package/dist/memory.d.ts +27 -8
  134. package/dist/memory.d.ts.map +1 -1
  135. package/dist/memory.js +327 -115
  136. package/dist/messages.d.ts +63 -0
  137. package/dist/messages.d.ts.map +1 -0
  138. package/dist/messages.js +169 -0
  139. package/dist/modal.d.ts +2 -0
  140. package/dist/modal.d.ts.map +1 -0
  141. package/dist/modal.js +11 -0
  142. package/dist/model.d.ts +14 -13
  143. package/dist/model.d.ts.map +1 -1
  144. package/dist/model.js +12 -14
  145. package/dist/models.d.ts +10 -0
  146. package/dist/models.d.ts.map +1 -0
  147. package/dist/models.js +153 -0
  148. package/dist/name.d.ts +3 -0
  149. package/dist/name.d.ts.map +1 -0
  150. package/dist/name.js +118 -0
  151. package/dist/observation.d.ts +44 -9
  152. package/dist/observation.d.ts.map +1 -1
  153. package/dist/observation.js +271 -33
  154. package/dist/online.d.ts +7 -0
  155. package/dist/online.d.ts.map +1 -0
  156. package/dist/online.js +29 -0
  157. package/dist/opened.d.ts +22 -0
  158. package/dist/opened.d.ts.map +1 -0
  159. package/dist/opened.js +107 -0
  160. package/dist/opening.d.ts +4 -0
  161. package/dist/opening.d.ts.map +1 -0
  162. package/dist/opening.js +69 -0
  163. package/dist/outcome.d.ts +70 -9
  164. package/dist/outcome.d.ts.map +1 -1
  165. package/dist/outcome.js +73 -1
  166. package/dist/overlay.d.ts +11 -7
  167. package/dist/overlay.d.ts.map +1 -1
  168. package/dist/overlay.js +134 -192
  169. package/dist/page-metadata.d.ts +8 -0
  170. package/dist/page-metadata.d.ts.map +1 -0
  171. package/dist/page-metadata.js +19 -0
  172. package/dist/parts.d.ts +6 -0
  173. package/dist/parts.d.ts.map +1 -0
  174. package/dist/parts.js +36 -0
  175. package/dist/paths.d.ts +2 -0
  176. package/dist/paths.d.ts.map +1 -1
  177. package/dist/paths.js +26 -0
  178. package/dist/preparation.d.ts +46 -0
  179. package/dist/preparation.d.ts.map +1 -0
  180. package/dist/preparation.js +344 -0
  181. package/dist/presence.d.ts +58 -0
  182. package/dist/presence.d.ts.map +1 -0
  183. package/dist/presence.js +231 -0
  184. package/dist/queries.d.ts +16 -0
  185. package/dist/queries.d.ts.map +1 -0
  186. package/dist/queries.js +287 -0
  187. package/dist/query.d.ts +51 -185
  188. package/dist/query.d.ts.map +1 -1
  189. package/dist/query.js +3 -464
  190. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  191. package/dist/questions.d.ts.map +1 -0
  192. package/dist/{chat/questions.js → questions.js} +14 -8
  193. package/dist/queue.d.ts +40 -0
  194. package/dist/queue.d.ts.map +1 -0
  195. package/dist/queue.js +480 -0
  196. package/dist/reach.d.ts +30 -7
  197. package/dist/reach.d.ts.map +1 -1
  198. package/dist/reach.js +445 -101
  199. package/dist/react.d.ts +27 -7
  200. package/dist/react.d.ts.map +1 -1
  201. package/dist/react.js +40 -18
  202. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  203. package/dist/read.d.ts.map +1 -0
  204. package/dist/{chat/read.js → read.js} +4 -0
  205. package/dist/readiness.d.ts +65 -0
  206. package/dist/readiness.d.ts.map +1 -0
  207. package/dist/readiness.js +34 -0
  208. package/dist/reads.d.ts +39 -0
  209. package/dist/reads.d.ts.map +1 -0
  210. package/dist/reads.js +178 -0
  211. package/dist/recovery.d.ts +29 -0
  212. package/dist/recovery.d.ts.map +1 -0
  213. package/dist/recovery.js +255 -0
  214. package/dist/refresh.d.ts +17 -14
  215. package/dist/refresh.d.ts.map +1 -1
  216. package/dist/refresh.js +145 -53
  217. package/dist/refusal.d.ts +5 -0
  218. package/dist/refusal.d.ts.map +1 -0
  219. package/dist/refusal.js +55 -0
  220. package/dist/replica.d.ts +50 -33
  221. package/dist/replica.d.ts.map +1 -1
  222. package/dist/replica.js +341 -164
  223. package/dist/retried.d.ts +30 -0
  224. package/dist/retried.d.ts.map +1 -0
  225. package/dist/retried.js +72 -0
  226. package/dist/room-draft.d.ts +66 -12
  227. package/dist/room-draft.d.ts.map +1 -1
  228. package/dist/room-draft.js +420 -123
  229. package/dist/room-drafts.d.ts +24 -0
  230. package/dist/room-drafts.d.ts.map +1 -0
  231. package/dist/room-drafts.js +222 -0
  232. package/dist/room-list.d.ts +10 -0
  233. package/dist/room-list.d.ts.map +1 -0
  234. package/dist/room-list.js +45 -0
  235. package/dist/rows.d.ts +31 -37
  236. package/dist/rows.d.ts.map +1 -1
  237. package/dist/rows.js +60 -128
  238. package/dist/running.d.ts +5 -0
  239. package/dist/running.d.ts.map +1 -0
  240. package/dist/running.js +10 -0
  241. package/dist/runtime.d.ts +35 -0
  242. package/dist/runtime.d.ts.map +1 -0
  243. package/dist/runtime.js +1 -0
  244. package/dist/save.d.ts +44 -43
  245. package/dist/save.d.ts.map +1 -1
  246. package/dist/save.js +759 -288
  247. package/dist/saves.d.ts +34 -0
  248. package/dist/saves.d.ts.map +1 -0
  249. package/dist/saves.js +457 -0
  250. package/dist/search.d.ts +15 -55
  251. package/dist/search.d.ts.map +1 -1
  252. package/dist/search.js +10 -121
  253. package/dist/seed.d.ts +25 -0
  254. package/dist/seed.d.ts.map +1 -0
  255. package/dist/seed.js +145 -0
  256. package/dist/shared.d.ts +10 -0
  257. package/dist/shared.d.ts.map +1 -0
  258. package/dist/shared.js +339 -0
  259. package/dist/shown.d.ts +35 -0
  260. package/dist/shown.d.ts.map +1 -0
  261. package/dist/shown.js +326 -0
  262. package/dist/socket/admission.d.ts +7 -0
  263. package/dist/socket/admission.d.ts.map +1 -0
  264. package/dist/socket/admission.js +39 -0
  265. package/dist/socket/answers.d.ts +6 -0
  266. package/dist/socket/answers.d.ts.map +1 -0
  267. package/dist/socket/answers.js +20 -0
  268. package/dist/socket/lanes.d.ts +28 -0
  269. package/dist/socket/lanes.d.ts.map +1 -0
  270. package/dist/socket/lanes.js +103 -0
  271. package/dist/socket/reads.d.ts +10 -0
  272. package/dist/socket/reads.d.ts.map +1 -0
  273. package/dist/socket/reads.js +31 -0
  274. package/dist/socket/session.d.ts +41 -0
  275. package/dist/socket/session.d.ts.map +1 -0
  276. package/dist/socket/session.js +26 -0
  277. package/dist/socket.d.ts +68 -0
  278. package/dist/socket.d.ts.map +1 -0
  279. package/dist/socket.js +165 -0
  280. package/dist/source.d.ts +61 -0
  281. package/dist/source.d.ts.map +1 -0
  282. package/dist/source.js +95 -0
  283. package/dist/status.d.ts +5 -2
  284. package/dist/status.d.ts.map +1 -1
  285. package/dist/status.js +3 -7
  286. package/dist/store/installs.d.ts +30 -0
  287. package/dist/store/installs.d.ts.map +1 -0
  288. package/dist/store/installs.js +40 -0
  289. package/dist/store/readiness.d.ts +11 -0
  290. package/dist/store/readiness.d.ts.map +1 -0
  291. package/dist/store/readiness.js +68 -0
  292. package/dist/store/records.d.ts +227 -0
  293. package/dist/store/records.d.ts.map +1 -0
  294. package/dist/store/records.js +468 -0
  295. package/dist/store/room-held.d.ts +8 -0
  296. package/dist/store/room-held.d.ts.map +1 -0
  297. package/dist/store/room-held.js +17 -0
  298. package/dist/store/rooms-shown.d.ts +8 -0
  299. package/dist/store/rooms-shown.d.ts.map +1 -0
  300. package/dist/store/rooms-shown.js +13 -0
  301. package/dist/store/space.d.ts +11 -0
  302. package/dist/store/space.d.ts.map +1 -0
  303. package/dist/store/space.js +41 -0
  304. package/dist/store/watchers.d.ts +17 -0
  305. package/dist/store/watchers.d.ts.map +1 -0
  306. package/dist/store/watchers.js +56 -0
  307. package/dist/store/writes.d.ts +24 -0
  308. package/dist/store/writes.d.ts.map +1 -0
  309. package/dist/store/writes.js +125 -0
  310. package/dist/store.d.ts +115 -133
  311. package/dist/store.d.ts.map +1 -1
  312. package/dist/store.js +165 -611
  313. package/dist/stored.d.ts +174 -0
  314. package/dist/stored.d.ts.map +1 -0
  315. package/dist/stored.js +785 -0
  316. package/dist/surface.d.ts +94 -0
  317. package/dist/surface.d.ts.map +1 -0
  318. package/dist/surface.js +255 -0
  319. package/dist/sync.d.ts +21 -0
  320. package/dist/sync.d.ts.map +1 -0
  321. package/dist/sync.js +557 -0
  322. package/dist/tables.d.ts +376 -0
  323. package/dist/tables.d.ts.map +1 -0
  324. package/dist/tables.js +499 -0
  325. package/dist/tallies.d.ts +18 -0
  326. package/dist/tallies.d.ts.map +1 -0
  327. package/dist/tallies.js +128 -0
  328. package/dist/transfer.d.ts +0 -5
  329. package/dist/transfer.d.ts.map +1 -1
  330. package/dist/turn.d.ts +9 -0
  331. package/dist/turn.d.ts.map +1 -0
  332. package/dist/turn.js +75 -0
  333. package/dist/validation.d.ts +29 -0
  334. package/dist/validation.d.ts.map +1 -0
  335. package/dist/validation.js +98 -0
  336. package/dist/windows.d.ts +11 -0
  337. package/dist/windows.d.ts.map +1 -0
  338. package/dist/windows.js +16 -0
  339. package/dist/wire.d.ts +243 -36
  340. package/dist/wire.d.ts.map +1 -1
  341. package/dist/wire.js +80 -33
  342. package/package.json +19 -19
  343. package/AGENTS.md +0 -299
  344. package/dist/attempt.d.ts +0 -16
  345. package/dist/attempt.d.ts.map +0 -1
  346. package/dist/attempt.js +0 -70
  347. package/dist/chat/acts.d.ts +0 -33
  348. package/dist/chat/acts.d.ts.map +0 -1
  349. package/dist/chat/acts.js +0 -36
  350. package/dist/chat/context.d.ts +0 -3
  351. package/dist/chat/context.d.ts.map +0 -1
  352. package/dist/chat/input.d.ts +0 -9
  353. package/dist/chat/input.d.ts.map +0 -1
  354. package/dist/chat/input.js +0 -99
  355. package/dist/chat/kit.d.ts +0 -60
  356. package/dist/chat/kit.d.ts.map +0 -1
  357. package/dist/chat/kit.js +0 -123
  358. package/dist/chat/lasting.d.ts +0 -6
  359. package/dist/chat/lasting.d.ts.map +0 -1
  360. package/dist/chat/lasting.js +0 -19
  361. package/dist/chat/list.d.ts +0 -26
  362. package/dist/chat/list.d.ts.map +0 -1
  363. package/dist/chat/list.js +0 -62
  364. package/dist/chat/markdown.d.ts +0 -20
  365. package/dist/chat/markdown.d.ts.map +0 -1
  366. package/dist/chat/markdown.js +0 -188
  367. package/dist/chat/message.d.ts +0 -6
  368. package/dist/chat/message.d.ts.map +0 -1
  369. package/dist/chat/message.js +0 -192
  370. package/dist/chat/messages.d.ts +0 -21
  371. package/dist/chat/messages.d.ts.map +0 -1
  372. package/dist/chat/messages.js +0 -151
  373. package/dist/chat/name.d.ts +0 -6
  374. package/dist/chat/name.d.ts.map +0 -1
  375. package/dist/chat/name.js +0 -37
  376. package/dist/chat/opened.d.ts +0 -11
  377. package/dist/chat/opened.d.ts.map +0 -1
  378. package/dist/chat/opened.js +0 -17
  379. package/dist/chat/overlay.d.ts +0 -31
  380. package/dist/chat/overlay.d.ts.map +0 -1
  381. package/dist/chat/overlay.js +0 -97
  382. package/dist/chat/parts.d.ts +0 -57
  383. package/dist/chat/parts.d.ts.map +0 -1
  384. package/dist/chat/parts.js +0 -119
  385. package/dist/chat/process.d.ts +0 -20
  386. package/dist/chat/process.d.ts.map +0 -1
  387. package/dist/chat/process.js +0 -32
  388. package/dist/chat/provider.d.ts +0 -63
  389. package/dist/chat/provider.d.ts.map +0 -1
  390. package/dist/chat/provider.js +0 -620
  391. package/dist/chat/question.d.ts +0 -9
  392. package/dist/chat/question.d.ts.map +0 -1
  393. package/dist/chat/question.js +0 -80
  394. package/dist/chat/questions.d.ts.map +0 -1
  395. package/dist/chat/read.d.ts.map +0 -1
  396. package/dist/chat/ready.d.ts +0 -33
  397. package/dist/chat/ready.d.ts.map +0 -1
  398. package/dist/chat/ready.js +0 -91
  399. package/dist/chat/style.d.ts +0 -4
  400. package/dist/chat/style.d.ts.map +0 -1
  401. package/dist/chat/style.js +0 -302
  402. package/dist/chat.d.ts +0 -14
  403. package/dist/chat.d.ts.map +0 -1
  404. package/dist/chat.js +0 -8
  405. package/dist/fence.d.ts +0 -6
  406. package/dist/fence.d.ts.map +0 -1
  407. package/dist/fence.js +0 -10
  408. package/dist/log.d.ts +0 -5
  409. package/dist/log.d.ts.map +0 -1
  410. package/dist/log.js +0 -14
  411. package/dist/read-side.d.ts +0 -18
  412. package/dist/read-side.d.ts.map +0 -1
  413. package/dist/read-side.js +0 -440
@@ -0,0 +1,537 @@
1
+ import { attachedModel } from './attached-model.js';
2
+ import { bootstrapRoom } from './bootstrap.js';
3
+ import { refusedForSpace } from './durability.js';
4
+ import { uncaught } from './failure.js';
5
+ import { name } from './listing.js';
6
+ import { NO_MODEL } from './model.js';
7
+ import { settle } from './queue.js';
8
+ import { advancement } from './refresh.js';
9
+ import { recoverReads } from './shown.js';
10
+ import { unconfirmed } from './transfer.js';
11
+ import { ROW_WEIGHT, yielded } from './turn.js';
12
+ // Bytes still arriving are reported at most this often, so readiness is not rebuilt for every chunk the network hands over while a slow link still moves the figure.
13
+ const ARRIVAL_REPORT_MS = 250;
14
+ const NOTHING_HELD = { bytes: 0 };
15
+ export const ERASE_BATCH = 512;
16
+ function transferGone(held) {
17
+ return {
18
+ ...held,
19
+ transfer: null,
20
+ arrived: null,
21
+ streaming: false,
22
+ underived: 0,
23
+ unindexed: [],
24
+ };
25
+ }
26
+ function amountOf(held, kept) {
27
+ if (held.transfer !== null) {
28
+ const owed = held.unindexed.reduce((sum, part) => sum + part.bytes, 0);
29
+ return {
30
+ done: held.transfer.done.bytes - Math.ceil(owed),
31
+ total: Math.max(held.arrived ?? 0, held.transfer.done.bytes),
32
+ };
33
+ }
34
+ return { done: kept, total: held.arrived ?? kept };
35
+ }
36
+ function setBack(held) {
37
+ const now = amountOf(held, NOTHING_HELD.bytes);
38
+ const earlier = held.startedOver;
39
+ return {
40
+ ...held,
41
+ startedOver: {
42
+ done: Math.max(now.done, earlier?.done ?? 0),
43
+ total: Math.max(now.total, earlier?.total ?? 0),
44
+ },
45
+ };
46
+ }
47
+ function owedIndexes(held, bytes, text) {
48
+ if (bytes <= 0 || text <= 0)
49
+ return held;
50
+ return { ...held, unindexed: [...held.unindexed, { bytes, text }] };
51
+ }
52
+ function built(held, done, text) {
53
+ const owed = [...held.unindexed];
54
+ let left = text;
55
+ while (!done && left > 0 && owed.length > 0) {
56
+ const [first] = owed;
57
+ if (left >= first.text) {
58
+ left -= first.text;
59
+ owed.shift();
60
+ continue;
61
+ }
62
+ owed[0] = {
63
+ bytes: (first.bytes * (first.text - left)) / first.text,
64
+ text: first.text - left,
65
+ };
66
+ left = 0;
67
+ }
68
+ return { ...held, unindexed: done ? [] : owed };
69
+ }
70
+ function batchEnd(entries, from, bytes) {
71
+ let end = from;
72
+ let spent = 0;
73
+ while (end < entries.length) {
74
+ const size = (entries[end].content?.length ?? 0) + ROW_WEIGHT;
75
+ if (spent + size > bytes && end > from)
76
+ break;
77
+ spent += size;
78
+ end += 1;
79
+ }
80
+ return end;
81
+ }
82
+ const UNSHARED = {
83
+ installing: false,
84
+ downloading: false,
85
+ bytes: { done: 0, total: 0 },
86
+ };
87
+ export function installShare(store, { room, state }, held) {
88
+ if (state === 'unadmitted')
89
+ return UNSHARED;
90
+ const install = store.installs.of(room);
91
+ const underway = state === 'acquiring' || (install.installing && state !== 'complete');
92
+ const kept = underway ? NOTHING_HELD.bytes : (held.get(room)?.bytes ?? NOTHING_HELD.bytes);
93
+ const now = amountOf(install, kept);
94
+ const earlier = underway ? install.startedOver : null;
95
+ return {
96
+ installing: underway,
97
+ downloading: underway && (install.streaming || install.arrived === null),
98
+ bytes: {
99
+ done: Math.max(now.done, earlier?.done ?? 0),
100
+ total: Math.max(now.total, earlier?.total ?? 0),
101
+ },
102
+ };
103
+ }
104
+ export function installationOf(installing, downloading, bytes) {
105
+ const step = installing === 0
106
+ ? null
107
+ : downloading > 0
108
+ ? 'downloading'
109
+ : bytes.done < bytes.total
110
+ ? 'writing'
111
+ : 'replaying';
112
+ return { step, bytes };
113
+ }
114
+ export function roomInFlight(store, locator) {
115
+ const { catching, transfer } = store.installs.of(locator);
116
+ return catching || transfer !== null;
117
+ }
118
+ function installing(runtime, locator) {
119
+ runtime.store.installs.change(locator, (held) => ({ ...held, installing: true }));
120
+ runtime.store.readiness.queue([locator]);
121
+ }
122
+ function installed(runtime, locator) {
123
+ if (!runtime.store.installs.of(locator).installing)
124
+ return;
125
+ runtime.store.installs.change(locator, (held) => ({ ...held, installing: false }));
126
+ runtime.store.readiness.queue([locator]);
127
+ }
128
+ export function sweep({ store, socket }) {
129
+ if (store.device.now().sweeping || socket.closed())
130
+ return;
131
+ store.device.set({ sweeping: true });
132
+ void (async () => {
133
+ try {
134
+ while (!socket.closed() && (await store.durably((local) => local.erase(null, ERASE_BATCH)))) {
135
+ await yielded();
136
+ }
137
+ }
138
+ catch (error) {
139
+ uncaught(error);
140
+ }
141
+ finally {
142
+ store.device.set({ sweeping: false });
143
+ }
144
+ })();
145
+ }
146
+ export function caughtUpTo(runtime, locator) {
147
+ if (!runtime.store.installs.of(locator).catching)
148
+ return;
149
+ runtime.store.installs.change(locator, (held) => ({ ...held, catching: false }));
150
+ recoverReads(runtime, [locator]);
151
+ }
152
+ export function catching(store, locator) {
153
+ store.installs.change(locator, (held) => ({ ...held, catching: true }));
154
+ }
155
+ export function standingAt(store, locator, held) {
156
+ return { key: held?.key ?? null, confirmed: store.installs.of(locator).confirmations };
157
+ }
158
+ function standsAt(store, locator, held, from) {
159
+ const now = standingAt(store, locator, held);
160
+ return now.key === from.key && now.confirmed === from.confirmed;
161
+ }
162
+ function shownAt({ store, socket }, locator, held) {
163
+ const raised = store.installs.of(locator).highest ?? undefined;
164
+ if (held === undefined || raised === undefined)
165
+ return held ?? raised;
166
+ return socket.reads.reached(locator, held, raised) ? held : raised;
167
+ }
168
+ export function showing(system, locator, roomVersion, held) {
169
+ const at = shownAt(system, locator, held);
170
+ if (at === undefined || !system.socket.reads.reached(locator, at, roomVersion)) {
171
+ system.store.installs.change(locator, (room) => ({ ...room, highest: roomVersion }));
172
+ }
173
+ }
174
+ export function olderThan(system, locator, roomVersion, held) {
175
+ const { store, socket } = system;
176
+ if (store.installs.of(locator).beyondHorizon)
177
+ return false;
178
+ const at = shownAt(system, locator, held);
179
+ return (at !== undefined &&
180
+ socket.reads.reached(locator, at, roomVersion) &&
181
+ !socket.reads.reached(locator, roomVersion, at));
182
+ }
183
+ async function older(runtime, locator, roomVersion) {
184
+ const { store } = runtime;
185
+ if (store.installs.of(locator).beyondHorizon)
186
+ return false;
187
+ return olderThan(runtime, locator, roomVersion, (await store.record(locator))?.roomVersion);
188
+ }
189
+ export function replaced(store, locators) {
190
+ for (const locator of locators) {
191
+ store.installs.change(locator, (held) => ({ ...held, highest: null, beyondHorizon: true }));
192
+ }
193
+ }
194
+ export async function reachedBy({ store, socket }, locator, roomVersion) {
195
+ const held = await store.record(locator);
196
+ return held !== undefined && socket.reads.reached(locator, held.roomVersion, roomVersion);
197
+ }
198
+ export async function behind({ store, socket }, room) {
199
+ const held = (await store.record(room.locator))?.roomVersion;
200
+ return held !== undefined && !socket.reads.reached(room.locator, held, room.roomVersion);
201
+ }
202
+ export async function writtenAfter({ store, socket }, locator, roomVersion, path) {
203
+ const held = await store.record(locator);
204
+ if (held === undefined)
205
+ return false;
206
+ const [entry] = await (await store.open()).entries(held.key, 'confirmed', [path]);
207
+ const written = entry?.written ?? undefined;
208
+ return (written !== undefined &&
209
+ socket.reads.reached(locator, written, roomVersion) &&
210
+ !socket.reads.reached(locator, roomVersion, written));
211
+ }
212
+ async function writtenLater(runtime, local, locator, key, paths, roomVersion, heldAt) {
213
+ if (paths.length === 0)
214
+ return new Set();
215
+ const { reached } = runtime.socket.reads;
216
+ const behindShown = heldAt === undefined
217
+ ? await older(runtime, locator, roomVersion)
218
+ : olderThan(runtime, locator, roomVersion, heldAt);
219
+ if (!behindShown)
220
+ return new Set();
221
+ const entries = await local.entries(key, 'confirmed', paths);
222
+ return new Set(entries.flatMap(({ path, written }) => written !== null &&
223
+ reached(locator, written, roomVersion) &&
224
+ !reached(locator, roomVersion, written)
225
+ ? [path]
226
+ : []));
227
+ }
228
+ function remodel(runtime, answers, held) {
229
+ const answer = answers?.collection;
230
+ if (answer === undefined)
231
+ return held;
232
+ return { collection: attachedModel(answer, runtime.roomTypes) };
233
+ }
234
+ function refreshingOf(runtime, local, locator, key, composition, liveness, replaying = false, heldAt) {
235
+ const { store } = runtime;
236
+ const write = replaying ? store.finishingWrite : store.exclusive;
237
+ return {
238
+ turn() {
239
+ if (replaying)
240
+ installing(runtime, locator);
241
+ },
242
+ prior: async (paths) => new Map((await local.entries(key, 'refreshed', paths)).map((entry) => [entry.path, entry])),
243
+ later: (paths, roomVersion) => writtenLater(runtime, local, locator, key, paths, roomVersion, heldAt),
244
+ async stage(page) {
245
+ for (let written = 0;;) {
246
+ const end = batchEnd(page.entries, written, store.stageBytes());
247
+ const last = end === page.entries.length;
248
+ const entries = page.entries.slice(written, end);
249
+ const staged = await write(async () => {
250
+ if (!liveness())
251
+ return false;
252
+ await store.refreshPage(local, key, composition, last
253
+ ? { ...page, entries }
254
+ : { entries, removals: [], folders: [], folderRemovals: [] });
255
+ return true;
256
+ });
257
+ if (!staged)
258
+ return false;
259
+ if (last)
260
+ return true;
261
+ written = end;
262
+ }
263
+ },
264
+ };
265
+ }
266
+ export async function pullRefresh(runtime, authorized, record, liveness, hold, refresh) {
267
+ if (!liveness())
268
+ return unconfirmed;
269
+ const { store } = runtime;
270
+ const from = standingAt(store, record.locator, record);
271
+ const local = await store.open();
272
+ try {
273
+ await store.exclusive(() => local.unrefresh(record.key));
274
+ const result = await advancement(async (authorization, request) => {
275
+ hold.release();
276
+ try {
277
+ return await refresh(authorization, request);
278
+ }
279
+ finally {
280
+ hold.take();
281
+ }
282
+ }, authorized, record, (models, kept) => (liveness() ? remodel(runtime, models, kept) : kept), liveness, refreshingOf(runtime, local, record.locator, record.key, store.composed(record), liveness, false, record.roomVersion));
283
+ if (result.kind !== 'advanced')
284
+ return result;
285
+ return {
286
+ kind: 'advanced',
287
+ record: result.record,
288
+ from,
289
+ remodelled: result.record.model !== record.model,
290
+ };
291
+ }
292
+ catch (error) {
293
+ if (refusedForSpace(error))
294
+ return unconfirmed;
295
+ throw error;
296
+ }
297
+ }
298
+ async function abandoned(runtime, local, locator) {
299
+ await local.abandon(locator);
300
+ runtime.store.installs.change(locator, (held) => transferGone(setBack(held)));
301
+ recoverReads(runtime, [locator]);
302
+ runtime.store.readiness.queue([locator]);
303
+ sweep(runtime);
304
+ }
305
+ function staging(runtime, local, liveness, unheld) {
306
+ const { store, socket } = runtime;
307
+ const derived = async (locator, key, composition) => {
308
+ store.installs.change(locator, (held) => ({ ...held, underived: 0 }));
309
+ for (;;) {
310
+ if (!liveness())
311
+ return false;
312
+ const done = await store.finishingWrite(async () => liveness() ? store.rederive(local, key, composition) : null);
313
+ if (done === null)
314
+ return false;
315
+ store.installs.change(locator, (held) => built(held, done.done, done.text));
316
+ runtime.store.readiness.queue([locator]);
317
+ if (done.done)
318
+ return true;
319
+ }
320
+ };
321
+ return {
322
+ held: (locator) => store.installs.of(locator).transfer,
323
+ async turn(locator, step) {
324
+ installing(runtime, locator);
325
+ return step === 'downloading' ? socket.heldStream() : () => { };
326
+ },
327
+ unqueued: socket.unqueued,
328
+ queued: socket.queued,
329
+ arriving(locator) {
330
+ let ended = false;
331
+ return {
332
+ at(bytes) {
333
+ if (ended)
334
+ return;
335
+ store.installs.change(locator, (held) => ({
336
+ ...held,
337
+ arrived: bytes,
338
+ streaming: true,
339
+ }));
340
+ const due = store.installs.arrivalsDue(locator, performance.now(), ARRIVAL_REPORT_MS);
341
+ if (due.length > 0)
342
+ runtime.store.readiness.queue(due);
343
+ },
344
+ end() {
345
+ if (ended)
346
+ return;
347
+ ended = true;
348
+ if (!store.installs.of(locator).streaming)
349
+ return;
350
+ store.installs.change(locator, (held) => ({ ...held, streaming: false }));
351
+ runtime.store.readiness.queue([locator]);
352
+ },
353
+ };
354
+ },
355
+ streamed: socket.streamed,
356
+ async stage(record, page, composition) {
357
+ const { locator } = record;
358
+ installing(runtime, locator);
359
+ if (!liveness())
360
+ return null;
361
+ const key = await store.startingWrite(async () => {
362
+ if (!liveness())
363
+ return null;
364
+ return local.stage(record, composition, page);
365
+ });
366
+ if (key === null || !liveness())
367
+ return null;
368
+ const before = store.installs.of(locator);
369
+ const prior = before.transfer?.done.bytes ?? 0;
370
+ const held = { ...record, key };
371
+ const text = page.entries.reduce((sum, entry) => sum + (entry.content?.length ?? 0), 0);
372
+ const owed = text + before.underived;
373
+ store.installs.change(locator, (room) => ({
374
+ ...owedIndexes(room, record.done.bytes - prior, text),
375
+ transfer: held,
376
+ underived: owed,
377
+ }));
378
+ installing(runtime, locator);
379
+ recoverReads(runtime, [locator]);
380
+ if (owed < store.deriveBytes())
381
+ return held;
382
+ return (await derived(locator, key, composition)) ? held : null;
383
+ },
384
+ async resume(record, parts, composition) {
385
+ const { locator } = record;
386
+ installing(runtime, locator);
387
+ if (!liveness())
388
+ return null;
389
+ const prior = unheld === undefined ? await store.record(locator) : undefined;
390
+ const published = prior !== undefined && prior.declaration.replica.selection === record.selection
391
+ ? prior.key
392
+ : null;
393
+ const kept = unheld?.staged ?? (await local.held()).staged.has(locator);
394
+ if (published === null && !kept)
395
+ return { record: null, staged: new Set() };
396
+ const resumed = await store.startingWrite(async () => {
397
+ if (!liveness())
398
+ return null;
399
+ return local.resume(record, composition, parts.map((part) => part.id), published);
400
+ });
401
+ if (resumed === null || !liveness())
402
+ return null;
403
+ const parted = new Set(resumed.staged);
404
+ if (resumed.key === null)
405
+ return { record: null, staged: parted };
406
+ const bytes = parts.reduce((sum, part) => sum + (parted.has(part.id) ? part.bytes : 0), 0);
407
+ const held = {
408
+ ...record,
409
+ transfer: resumed.transfer,
410
+ key: resumed.key,
411
+ done: { bytes },
412
+ };
413
+ store.installs.change(locator, (room) => ({ ...room, transfer: held }));
414
+ recoverReads(runtime, [locator]);
415
+ store.readiness.queue([locator]);
416
+ return { record: held, staged: parted };
417
+ },
418
+ derive: derived,
419
+ async refreshing(locator, key, composition) {
420
+ await store.exclusive(() => local.unrefresh(key));
421
+ return refreshingOf(runtime, local, locator, key, composition, liveness, true);
422
+ },
423
+ abandon: (locator) => store.exclusive(async () => {
424
+ if (liveness())
425
+ await abandoned(runtime, local, locator);
426
+ }),
427
+ setAside: async (locator) => {
428
+ if (!liveness())
429
+ return;
430
+ store.installs.change(locator, (held) => transferGone(setBack(held)));
431
+ recoverReads(runtime, [locator]);
432
+ store.readiness.queue([locator]);
433
+ },
434
+ release: (key) => store.exclusive(async () => {
435
+ await local.release(key);
436
+ sweep(runtime);
437
+ }),
438
+ };
439
+ }
440
+ export async function pullBootstrap(runtime, authorized, room, local, liveness, prior, from = runtime.socket.reads, unheld) {
441
+ if (!liveness())
442
+ return unconfirmed;
443
+ const { store } = runtime;
444
+ if (prior !== undefined) {
445
+ catching(store, room.locator);
446
+ recoverReads(runtime, [room.locator]);
447
+ }
448
+ try {
449
+ const result = await bootstrapRoom(from, authorized, room, {
450
+ collection: prior?.model ?? runtime.presence.unheldModel(room.locator) ?? NO_MODEL,
451
+ }, runtime.builtIn, runtime.typedPaths, (models, held) => (liveness() ? remodel(runtime, models, held) : held), liveness, staging(runtime, local, liveness, unheld));
452
+ if (result.kind === 'staged' &&
453
+ (await older(runtime, room.locator, result.record.roomVersion))) {
454
+ caughtUpTo(runtime, room.locator);
455
+ installed(runtime, room.locator);
456
+ await abandoned(runtime, local, room.locator);
457
+ return { kind: 'transport-uncertainty' };
458
+ }
459
+ if (result.kind !== 'staged') {
460
+ caughtUpTo(runtime, room.locator);
461
+ installed(runtime, room.locator);
462
+ }
463
+ return result;
464
+ }
465
+ catch (error) {
466
+ caughtUpTo(runtime, room.locator);
467
+ installed(runtime, room.locator);
468
+ if (refusedForSpace(error))
469
+ return unconfirmed;
470
+ throw error;
471
+ }
472
+ }
473
+ export function publish(runtime, local, room, reached, landing, live) {
474
+ const { store } = runtime;
475
+ let published = true;
476
+ const landed = settle(runtime, [room.locator], async (held) => {
477
+ if (!live()) {
478
+ caughtUpTo(runtime, room.locator);
479
+ return [];
480
+ }
481
+ const prior = held.get(room.locator)?.replica;
482
+ if (!standsAt(store, room.locator, prior?.record, landing.from)) {
483
+ published = false;
484
+ if (landing.kind === 'refreshed') {
485
+ await local.unrefresh(reached.key);
486
+ return [];
487
+ }
488
+ caughtUpTo(runtime, room.locator);
489
+ await abandoned(runtime, local, room.locator);
490
+ return [];
491
+ }
492
+ const record = landing.kind === 'refreshed' && prior !== undefined
493
+ ? {
494
+ ...prior.record,
495
+ roomVersion: reached.roomVersion,
496
+ ...(landing.remodelled ? { model: reached.model } : {}),
497
+ }
498
+ : reached;
499
+ return [
500
+ {
501
+ locator: room.locator,
502
+ record,
503
+ installed: landing.kind === 'refreshed'
504
+ ? { refreshed: true }
505
+ : {
506
+ published: { from: prior?.record.key ?? null },
507
+ ...(landing.refreshed ? { refreshed: true } : {}),
508
+ },
509
+ after() {
510
+ runtime.presence.installed(room.locator, landing.kind === 'bootstrapped');
511
+ runtime.retries.succeeded('download', room.locator);
512
+ store.prepareAgain(room.locator);
513
+ if (landing.kind === 'bootstrapped') {
514
+ store.installs.change(room.locator, (held) => ({
515
+ ...transferGone(held),
516
+ highest: null,
517
+ beyondHorizon: false,
518
+ startedOver: null,
519
+ catching: false,
520
+ }));
521
+ if (prior !== undefined && prior.record.key !== record.key)
522
+ sweep(runtime);
523
+ void name(runtime, room.locator);
524
+ }
525
+ },
526
+ },
527
+ ];
528
+ }).then(() => published, (error) => {
529
+ if (!refusedForSpace(error))
530
+ throw error;
531
+ caughtUpTo(runtime, room.locator);
532
+ return published;
533
+ });
534
+ return landing.kind === 'refreshed'
535
+ ? landed
536
+ : landed.finally(() => installed(runtime, room.locator));
537
+ }
@@ -0,0 +1,7 @@
1
+ import type { Runtime } from './runtime.js';
2
+ export declare function scheduleCurrency(runtime: Runtime): void;
3
+ export declare function spaceFreed(runtime: Runtime): void;
4
+ export declare function close({ store, socket, presence, conversations, recovery, liveQueries, figures, }: Runtime): void;
5
+ export declare function stop(runtime: Runtime): Promise<void>;
6
+ export declare function start(runtime: Runtime, signal: AbortSignal | undefined, onNeed: boolean): void;
7
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA6O5C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAOhD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,QAQ1C;AAED,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,WAAW,EACX,OAAO,GACR,EAAE,OAAO,QAST;AAED,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,iBAS1C;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,MAAM,EAAE,OAAO,QAwCvF"}